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.

252522 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_USE_XCURSOR
  187. #define JUCE_USE_XCURSOR 1
  188. #endif
  189. #ifndef JUCE_PLUGINHOST_VST
  190. // #define JUCE_PLUGINHOST_VST 1
  191. #endif
  192. #ifndef JUCE_PLUGINHOST_AU
  193. // #define JUCE_PLUGINHOST_AU 1
  194. #endif
  195. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  196. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  197. #endif
  198. #ifndef JUCE_WEB_BROWSER
  199. #define JUCE_WEB_BROWSER 0
  200. #endif
  201. #ifndef JUCE_SUPPORT_CARBON
  202. #define JUCE_SUPPORT_CARBON 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_ZLIB_CODE
  205. #define JUCE_INCLUDE_ZLIB_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_FLAC_CODE
  208. #define JUCE_INCLUDE_FLAC_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  211. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  212. #endif
  213. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  214. #define JUCE_INCLUDE_PNGLIB_CODE 1
  215. #endif
  216. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  217. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  218. #endif
  219. #ifndef JUCE_CHECK_MEMORY_LEAKS
  220. #define JUCE_CHECK_MEMORY_LEAKS 1
  221. #endif
  222. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  223. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  224. #endif
  225. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  226. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  227. #undef JUCE_QUICKTIME
  228. #define JUCE_QUICKTIME 0
  229. #undef JUCE_OPENGL
  230. #define JUCE_OPENGL 0
  231. #undef JUCE_USE_CDBURNER
  232. #define JUCE_USE_CDBURNER 0
  233. #undef JUCE_USE_CDREADER
  234. #define JUCE_USE_CDREADER 0
  235. #undef JUCE_WEB_BROWSER
  236. #define JUCE_WEB_BROWSER 0
  237. #undef JUCE_PLUGINHOST_AU
  238. #define JUCE_PLUGINHOST_AU 0
  239. #undef JUCE_PLUGINHOST_VST
  240. #define JUCE_PLUGINHOST_VST 0
  241. #endif
  242. #endif
  243. /*** End of inlined file: juce_Config.h ***/
  244. // FORCE_AMALGAMATOR_INCLUDE
  245. #ifndef JUCE_BUILD_CORE
  246. #define JUCE_BUILD_CORE 1
  247. #endif
  248. #ifndef JUCE_BUILD_MISC
  249. #define JUCE_BUILD_MISC 1
  250. #endif
  251. #ifndef JUCE_BUILD_GUI
  252. #define JUCE_BUILD_GUI 1
  253. #endif
  254. #ifndef JUCE_BUILD_NATIVE
  255. #define JUCE_BUILD_NATIVE 1
  256. #endif
  257. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  258. #undef JUCE_BUILD_MISC
  259. #undef JUCE_BUILD_GUI
  260. #endif
  261. //==============================================================================
  262. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  263. #if JUCE_WINDOWS
  264. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  265. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  266. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  267. #ifndef STRICT
  268. #define STRICT 1
  269. #endif
  270. #undef WIN32_LEAN_AND_MEAN
  271. #define WIN32_LEAN_AND_MEAN 1
  272. #ifdef _MSC_VER
  273. #pragma warning (push)
  274. #pragma warning (disable : 4100 4201 4514 4312 4995)
  275. #endif
  276. #define _WIN32_WINNT 0x0500
  277. #define _UNICODE 1
  278. #define UNICODE 1
  279. #ifndef _WIN32_IE
  280. #define _WIN32_IE 0x0400
  281. #endif
  282. #include <windows.h>
  283. #include <windowsx.h>
  284. #include <commdlg.h>
  285. #include <shellapi.h>
  286. #include <mmsystem.h>
  287. #include <vfw.h>
  288. #include <tchar.h>
  289. #include <stddef.h>
  290. #include <ctime>
  291. #include <wininet.h>
  292. #include <nb30.h>
  293. #include <iphlpapi.h>
  294. #include <mapi.h>
  295. #include <float.h>
  296. #include <process.h>
  297. #include <Exdisp.h>
  298. #include <exdispid.h>
  299. #include <shlobj.h>
  300. #if ! JUCE_MINGW
  301. #include <crtdbg.h>
  302. #include <comutil.h>
  303. #endif
  304. #if JUCE_OPENGL
  305. #include <gl/gl.h>
  306. #endif
  307. #undef PACKED
  308. #if JUCE_ASIO
  309. #include "iasiodrv.h"
  310. #endif
  311. #if JUCE_USE_CDBURNER
  312. #include <imapi.h>
  313. #include <imapierror.h>
  314. #endif
  315. #if JUCE_USE_CAMERA
  316. #include <dshow.h>
  317. #include <qedit.h>
  318. #include <dshowasf.h>
  319. #endif
  320. #if JUCE_WASAPI
  321. #include <MMReg.h>
  322. #include <mmdeviceapi.h>
  323. #include <Audioclient.h>
  324. #include <Avrt.h>
  325. #include <functiondiscoverykeys.h>
  326. #endif
  327. #if JUCE_QUICKTIME
  328. #include <Movies.h>
  329. #include <QTML.h>
  330. #include <QuickTimeComponents.h>
  331. #include <MediaHandlers.h>
  332. #include <ImageCodec.h>
  333. #import <QTOLibrary.dll>
  334. #import <QTOControl.dll>
  335. #endif
  336. #ifdef _MSC_VER
  337. #pragma warning (pop)
  338. #endif
  339. template <class T>
  340. class ComSmartPtr
  341. {
  342. public:
  343. ComSmartPtr() throw() : p (0) {}
  344. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  345. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  346. ~ComSmartPtr() { if (p != 0) p->Release(); }
  347. operator T*() const throw() { return p; }
  348. T& operator*() const throw() { return *p; }
  349. T** operator&() throw() { return &p; }
  350. T* operator->() const throw() { return p; }
  351. T* operator= (T* const newP)
  352. {
  353. if (newP != 0)
  354. newP->AddRef();
  355. if (p != 0)
  356. p->Release();
  357. p = newP;
  358. return newP;
  359. }
  360. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  361. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  362. {
  363. #ifndef __MINGW32__
  364. operator= (0);
  365. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  366. #else
  367. return S_FALSE;
  368. #endif
  369. }
  370. T* p;
  371. };
  372. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  373. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  374. #elif JUCE_LINUX
  375. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  376. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  377. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  378. #include <sched.h>
  379. #include <pthread.h>
  380. #include <sys/time.h>
  381. #include <errno.h>
  382. #include <sys/stat.h>
  383. #include <sys/dir.h>
  384. #include <sys/ptrace.h>
  385. #include <sys/vfs.h>
  386. #include <sys/wait.h>
  387. #include <fnmatch.h>
  388. #include <utime.h>
  389. #include <pwd.h>
  390. #include <fcntl.h>
  391. #include <dlfcn.h>
  392. #include <netdb.h>
  393. #include <arpa/inet.h>
  394. #include <netinet/in.h>
  395. #include <sys/types.h>
  396. #include <sys/ioctl.h>
  397. #include <sys/socket.h>
  398. #include <linux/if.h>
  399. #include <sys/sysinfo.h>
  400. #include <sys/file.h>
  401. #include <signal.h>
  402. #include <ft2build.h>
  403. #include FT_FREETYPE_H
  404. #include <X11/Xlib.h>
  405. #include <X11/Xatom.h>
  406. #include <X11/Xresource.h>
  407. #include <X11/Xutil.h>
  408. #include <X11/Xmd.h>
  409. #include <X11/keysym.h>
  410. #include <X11/cursorfont.h>
  411. #if JUCE_USE_XINERAMA
  412. #include <X11/extensions/Xinerama.h>
  413. #endif
  414. #if JUCE_USE_XSHM
  415. #include <X11/extensions/XShm.h>
  416. #include <sys/shm.h>
  417. #include <sys/ipc.h>
  418. #endif
  419. #if JUCE_USE_XRENDER
  420. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  421. #include <X11/extensions/Xrender.h>
  422. #include <X11/extensions/Xcomposite.h>
  423. #endif
  424. #if JUCE_USE_XCURSOR
  425. // If you're missing this header, try installing the libxcursor-dev package
  426. #include <X11/Xcursor/Xcursor.h>
  427. #endif
  428. #if JUCE_OPENGL
  429. #include <GL/glx.h>
  430. #endif
  431. #undef KeyPress
  432. #if JUCE_ALSA
  433. #include <alsa/asoundlib.h>
  434. #endif
  435. #if JUCE_JACK
  436. #include <jack/jack.h>
  437. //#include <jack/transport.h>
  438. #endif
  439. #undef SIZEOF
  440. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  441. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  442. #elif JUCE_MAC || JUCE_IPHONE
  443. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  444. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  445. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  446. #define USE_COREGRAPHICS_RENDERING 1
  447. #if JUCE_IPHONE
  448. #import <Foundation/Foundation.h>
  449. #import <UIKit/UIKit.h>
  450. #import <AudioToolbox/AudioToolbox.h>
  451. #import <AVFoundation/AVFoundation.h>
  452. #import <CoreData/CoreData.h>
  453. #import <MobileCoreServices/MobileCoreServices.h>
  454. #import <QuartzCore/QuartzCore.h>
  455. #include <sys/fcntl.h>
  456. #if JUCE_OPENGL
  457. #include <OpenGLES/ES1/gl.h>
  458. #include <OpenGLES/ES1/glext.h>
  459. #endif
  460. #else
  461. #import <Cocoa/Cocoa.h>
  462. #import <CoreAudio/HostTime.h>
  463. #import <CoreAudio/AudioHardware.h>
  464. #import <CoreMIDI/MIDIServices.h>
  465. #import <QTKit/QTKit.h>
  466. #import <WebKit/WebKit.h>
  467. #import <DiscRecording/DiscRecording.h>
  468. #import <IOKit/IOKitLib.h>
  469. #import <IOKit/IOCFPlugIn.h>
  470. #import <IOKit/hid/IOHIDLib.h>
  471. #import <IOKit/hid/IOHIDKeys.h>
  472. #import <IOKit/pwr_mgt/IOPMLib.h>
  473. #include <Carbon/Carbon.h>
  474. #include <sys/dir.h>
  475. #endif
  476. #include <sys/socket.h>
  477. #include <sys/sysctl.h>
  478. #include <sys/stat.h>
  479. #include <sys/param.h>
  480. #include <sys/mount.h>
  481. #include <fnmatch.h>
  482. #include <utime.h>
  483. #include <dlfcn.h>
  484. #include <ifaddrs.h>
  485. #include <net/if_dl.h>
  486. #include <mach/mach_time.h>
  487. #if MACOS_10_4_OR_EARLIER
  488. #include <GLUT/glut.h>
  489. #endif
  490. #if ! CGFLOAT_DEFINED
  491. #define CGFloat float
  492. #endif
  493. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  494. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  495. #else
  496. #error "Unknown platform!"
  497. #endif
  498. #endif
  499. //==============================================================================
  500. #define DONT_SET_USING_JUCE_NAMESPACE 1
  501. #undef max
  502. #undef min
  503. #define NO_DUMMY_DECL
  504. #if JUCE_BUILD_NATIVE
  505. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  506. #endif
  507. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  508. #pragma warning (disable: 4309 4305)
  509. #endif
  510. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  511. BEGIN_JUCE_NAMESPACE
  512. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  513. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  514. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  515. class CarbonViewWrapperComponent : public Component,
  516. public ComponentMovementWatcher,
  517. public Timer
  518. {
  519. public:
  520. CarbonViewWrapperComponent()
  521. : ComponentMovementWatcher (this),
  522. wrapperWindow (0),
  523. embeddedView (0),
  524. recursiveResize (false)
  525. {
  526. }
  527. virtual ~CarbonViewWrapperComponent()
  528. {
  529. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  530. }
  531. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  532. virtual void removeView (HIViewRef embeddedView) = 0;
  533. virtual void mouseDown (int x, int y) {}
  534. virtual void paint() {}
  535. virtual bool getEmbeddedViewSize (int& w, int& h)
  536. {
  537. if (embeddedView == 0)
  538. return false;
  539. HIRect bounds;
  540. HIViewGetBounds (embeddedView, &bounds);
  541. w = jmax (1, roundToInt (bounds.size.width));
  542. h = jmax (1, roundToInt (bounds.size.height));
  543. return true;
  544. }
  545. void createWindow()
  546. {
  547. if (wrapperWindow == 0)
  548. {
  549. Rect r;
  550. r.left = getScreenX();
  551. r.top = getScreenY();
  552. r.right = r.left + getWidth();
  553. r.bottom = r.top + getHeight();
  554. CreateNewWindow (kDocumentWindowClass,
  555. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  556. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  557. &r, &wrapperWindow);
  558. jassert (wrapperWindow != 0);
  559. if (wrapperWindow == 0)
  560. return;
  561. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  562. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  563. [ownerWindow addChildWindow: carbonWindow
  564. ordered: NSWindowAbove];
  565. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  566. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  567. { kEventClassWindow, kEventWindowHandleDeactivate } };
  568. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  569. InstallWindowEventHandler (wrapperWindow, upp,
  570. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  571. windowEventTypes, this, &eventHandlerRef);
  572. setOurSizeToEmbeddedViewSize();
  573. setEmbeddedWindowToOurSize();
  574. creationTime = Time::getCurrentTime();
  575. }
  576. }
  577. void deleteWindow()
  578. {
  579. removeView (embeddedView);
  580. embeddedView = 0;
  581. if (wrapperWindow != 0)
  582. {
  583. RemoveEventHandler (eventHandlerRef);
  584. DisposeWindow (wrapperWindow);
  585. wrapperWindow = 0;
  586. }
  587. }
  588. void setOurSizeToEmbeddedViewSize()
  589. {
  590. int w, h;
  591. if (getEmbeddedViewSize (w, h))
  592. {
  593. if (w != getWidth() || h != getHeight())
  594. {
  595. startTimer (50);
  596. setSize (w, h);
  597. if (getParentComponent() != 0)
  598. getParentComponent()->setSize (w, h);
  599. }
  600. else
  601. {
  602. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  603. }
  604. }
  605. else
  606. {
  607. stopTimer();
  608. }
  609. }
  610. void setEmbeddedWindowToOurSize()
  611. {
  612. if (! recursiveResize)
  613. {
  614. recursiveResize = true;
  615. if (embeddedView != 0)
  616. {
  617. HIRect r;
  618. r.origin.x = 0;
  619. r.origin.y = 0;
  620. r.size.width = (float) getWidth();
  621. r.size.height = (float) getHeight();
  622. HIViewSetFrame (embeddedView, &r);
  623. }
  624. if (wrapperWindow != 0)
  625. {
  626. Rect wr;
  627. wr.left = getScreenX();
  628. wr.top = getScreenY();
  629. wr.right = wr.left + getWidth();
  630. wr.bottom = wr.top + getHeight();
  631. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  632. ShowWindow (wrapperWindow);
  633. }
  634. recursiveResize = false;
  635. }
  636. }
  637. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  638. {
  639. setEmbeddedWindowToOurSize();
  640. }
  641. void componentPeerChanged()
  642. {
  643. deleteWindow();
  644. createWindow();
  645. }
  646. void componentVisibilityChanged (Component&)
  647. {
  648. if (isShowing())
  649. createWindow();
  650. else
  651. deleteWindow();
  652. setEmbeddedWindowToOurSize();
  653. }
  654. static void recursiveHIViewRepaint (HIViewRef view)
  655. {
  656. HIViewSetNeedsDisplay (view, true);
  657. HIViewRef child = HIViewGetFirstSubview (view);
  658. while (child != 0)
  659. {
  660. recursiveHIViewRepaint (child);
  661. child = HIViewGetNextView (child);
  662. }
  663. }
  664. void timerCallback()
  665. {
  666. setOurSizeToEmbeddedViewSize();
  667. // To avoid strange overpainting problems when the UI is first opened, we'll
  668. // repaint it a few times during the first second that it's on-screen..
  669. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  670. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  671. }
  672. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  673. EventRef event)
  674. {
  675. switch (GetEventKind (event))
  676. {
  677. case kEventWindowHandleDeactivate:
  678. ActivateWindow (wrapperWindow, TRUE);
  679. break;
  680. case kEventWindowGetClickActivation:
  681. {
  682. getTopLevelComponent()->toFront (false);
  683. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  684. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  685. sizeof (ClickActivationResult), &howToHandleClick);
  686. HIViewSetNeedsDisplay (embeddedView, true);
  687. }
  688. break;
  689. }
  690. return noErr;
  691. }
  692. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  693. EventRef event, void* userData)
  694. {
  695. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  696. }
  697. protected:
  698. WindowRef wrapperWindow;
  699. HIViewRef embeddedView;
  700. bool recursiveResize;
  701. Time creationTime;
  702. EventHandlerRef eventHandlerRef;
  703. };
  704. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  705. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  706. END_JUCE_NAMESPACE
  707. #endif
  708. #define JUCE_AMALGAMATED_TEMPLATE 1
  709. //==============================================================================
  710. #if JUCE_BUILD_CORE
  711. /*** Start of inlined file: juce_FileLogger.cpp ***/
  712. BEGIN_JUCE_NAMESPACE
  713. FileLogger::FileLogger (const File& logFile_,
  714. const String& welcomeMessage,
  715. const int maxInitialFileSizeBytes)
  716. : logFile (logFile_)
  717. {
  718. if (maxInitialFileSizeBytes >= 0)
  719. trimFileSize (maxInitialFileSizeBytes);
  720. if (! logFile_.exists())
  721. {
  722. // do this so that the parent directories get created..
  723. logFile_.create();
  724. }
  725. logStream = logFile_.createOutputStream (256);
  726. jassert (logStream != 0);
  727. String welcome;
  728. welcome << "\r\n**********************************************************\r\n"
  729. << welcomeMessage
  730. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  731. << "\r\n";
  732. logMessage (welcome);
  733. }
  734. FileLogger::~FileLogger()
  735. {
  736. }
  737. void FileLogger::logMessage (const String& message)
  738. {
  739. if (logStream != 0)
  740. {
  741. DBG (message);
  742. const ScopedLock sl (logLock);
  743. (*logStream) << message << "\r\n";
  744. logStream->flush();
  745. }
  746. }
  747. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  748. {
  749. if (maxFileSizeBytes <= 0)
  750. {
  751. logFile.deleteFile();
  752. }
  753. else
  754. {
  755. const int64 fileSize = logFile.getSize();
  756. if (fileSize > maxFileSizeBytes)
  757. {
  758. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  759. jassert (in != 0);
  760. if (in != 0)
  761. {
  762. in->setPosition (fileSize - maxFileSizeBytes);
  763. String content;
  764. {
  765. MemoryBlock contentToSave;
  766. contentToSave.setSize (maxFileSizeBytes + 4);
  767. contentToSave.fillWith (0);
  768. in->read (contentToSave.getData(), maxFileSizeBytes);
  769. in = 0;
  770. content = contentToSave.toString();
  771. }
  772. int newStart = 0;
  773. while (newStart < fileSize
  774. && content[newStart] != '\n'
  775. && content[newStart] != '\r')
  776. ++newStart;
  777. logFile.deleteFile();
  778. logFile.appendText (content.substring (newStart), false, false);
  779. }
  780. }
  781. }
  782. }
  783. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  784. const String& logFileName,
  785. const String& welcomeMessage,
  786. const int maxInitialFileSizeBytes)
  787. {
  788. #if JUCE_MAC
  789. File logFile ("~/Library/Logs");
  790. logFile = logFile.getChildFile (logFileSubDirectoryName)
  791. .getChildFile (logFileName);
  792. #else
  793. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  794. if (logFile.isDirectory())
  795. {
  796. logFile = logFile.getChildFile (logFileSubDirectoryName)
  797. .getChildFile (logFileName);
  798. }
  799. #endif
  800. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  801. }
  802. END_JUCE_NAMESPACE
  803. /*** End of inlined file: juce_FileLogger.cpp ***/
  804. /*** Start of inlined file: juce_Logger.cpp ***/
  805. BEGIN_JUCE_NAMESPACE
  806. Logger::Logger()
  807. {
  808. }
  809. Logger::~Logger()
  810. {
  811. }
  812. static Logger* currentLogger = 0;
  813. void Logger::setCurrentLogger (Logger* const newLogger,
  814. const bool deleteOldLogger)
  815. {
  816. Logger* const oldLogger = currentLogger;
  817. currentLogger = newLogger;
  818. if (deleteOldLogger)
  819. delete oldLogger;
  820. }
  821. void Logger::writeToLog (const String& message)
  822. {
  823. if (currentLogger != 0)
  824. currentLogger->logMessage (message);
  825. else
  826. outputDebugString (message);
  827. }
  828. #if JUCE_LOG_ASSERTIONS
  829. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  830. {
  831. String m ("JUCE Assertion failure in ");
  832. m << filename << ", line " << lineNum;
  833. Logger::writeToLog (m);
  834. }
  835. #endif
  836. END_JUCE_NAMESPACE
  837. /*** End of inlined file: juce_Logger.cpp ***/
  838. /*** Start of inlined file: juce_Random.cpp ***/
  839. BEGIN_JUCE_NAMESPACE
  840. Random::Random (const int64 seedValue) throw()
  841. : seed (seedValue)
  842. {
  843. }
  844. Random::~Random() throw()
  845. {
  846. }
  847. void Random::setSeed (const int64 newSeed) throw()
  848. {
  849. seed = newSeed;
  850. }
  851. void Random::combineSeed (const int64 seedValue) throw()
  852. {
  853. seed ^= nextInt64() ^ seedValue;
  854. }
  855. void Random::setSeedRandomly()
  856. {
  857. combineSeed ((int64) (pointer_sized_int) this);
  858. combineSeed (Time::getMillisecondCounter());
  859. combineSeed (Time::getHighResolutionTicks());
  860. combineSeed (Time::getHighResolutionTicksPerSecond());
  861. combineSeed (Time::currentTimeMillis());
  862. }
  863. int Random::nextInt() throw()
  864. {
  865. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  866. return (int) (seed >> 16);
  867. }
  868. int Random::nextInt (const int maxValue) throw()
  869. {
  870. jassert (maxValue > 0);
  871. return (nextInt() & 0x7fffffff) % maxValue;
  872. }
  873. int64 Random::nextInt64() throw()
  874. {
  875. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  876. }
  877. bool Random::nextBool() throw()
  878. {
  879. return (nextInt() & 0x80000000) != 0;
  880. }
  881. float Random::nextFloat() throw()
  882. {
  883. return static_cast <uint32> (nextInt()) / (float) 0xffffffff;
  884. }
  885. double Random::nextDouble() throw()
  886. {
  887. return static_cast <uint32> (nextInt()) / (double) 0xffffffff;
  888. }
  889. const BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
  890. {
  891. BigInteger n;
  892. do
  893. {
  894. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  895. }
  896. while (n >= maximumValue);
  897. return n;
  898. }
  899. void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits)
  900. {
  901. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  902. while ((startBit & 31) != 0 && numBits > 0)
  903. {
  904. arrayToChange.setBit (startBit++, nextBool());
  905. --numBits;
  906. }
  907. while (numBits >= 32)
  908. {
  909. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  910. startBit += 32;
  911. numBits -= 32;
  912. }
  913. while (--numBits >= 0)
  914. arrayToChange.setBit (startBit + numBits, nextBool());
  915. }
  916. Random& Random::getSystemRandom() throw()
  917. {
  918. static Random sysRand (1);
  919. return sysRand;
  920. }
  921. END_JUCE_NAMESPACE
  922. /*** End of inlined file: juce_Random.cpp ***/
  923. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  924. BEGIN_JUCE_NAMESPACE
  925. RelativeTime::RelativeTime (const double seconds_) throw()
  926. : seconds (seconds_)
  927. {
  928. }
  929. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  930. : seconds (other.seconds)
  931. {
  932. }
  933. RelativeTime::~RelativeTime() throw()
  934. {
  935. }
  936. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  937. {
  938. return RelativeTime (milliseconds * 0.001);
  939. }
  940. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  941. {
  942. return RelativeTime (milliseconds * 0.001);
  943. }
  944. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  945. {
  946. return RelativeTime (numberOfMinutes * 60.0);
  947. }
  948. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  949. {
  950. return RelativeTime (numberOfHours * (60.0 * 60.0));
  951. }
  952. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  953. {
  954. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  955. }
  956. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  957. {
  958. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  959. }
  960. int64 RelativeTime::inMilliseconds() const throw()
  961. {
  962. return (int64)(seconds * 1000.0);
  963. }
  964. double RelativeTime::inMinutes() const throw()
  965. {
  966. return seconds / 60.0;
  967. }
  968. double RelativeTime::inHours() const throw()
  969. {
  970. return seconds / (60.0 * 60.0);
  971. }
  972. double RelativeTime::inDays() const throw()
  973. {
  974. return seconds / (60.0 * 60.0 * 24.0);
  975. }
  976. double RelativeTime::inWeeks() const throw()
  977. {
  978. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  979. }
  980. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  981. {
  982. if (seconds < 0.001 && seconds > -0.001)
  983. return returnValueForZeroTime;
  984. String result;
  985. if (seconds < 0)
  986. result = "-";
  987. int fieldsShown = 0;
  988. int n = abs ((int) inWeeks());
  989. if (n > 0)
  990. {
  991. result << n << ((n == 1) ? TRANS(" week ")
  992. : TRANS(" weeks "));
  993. ++fieldsShown;
  994. }
  995. n = abs ((int) inDays()) % 7;
  996. if (n > 0)
  997. {
  998. result << n << ((n == 1) ? TRANS(" day ")
  999. : TRANS(" days "));
  1000. ++fieldsShown;
  1001. }
  1002. if (fieldsShown < 2)
  1003. {
  1004. n = abs ((int) inHours()) % 24;
  1005. if (n > 0)
  1006. {
  1007. result << n << ((n == 1) ? TRANS(" hr ")
  1008. : TRANS(" hrs "));
  1009. ++fieldsShown;
  1010. }
  1011. if (fieldsShown < 2)
  1012. {
  1013. n = abs ((int) inMinutes()) % 60;
  1014. if (n > 0)
  1015. {
  1016. result << n << ((n == 1) ? TRANS(" min ")
  1017. : TRANS(" mins "));
  1018. ++fieldsShown;
  1019. }
  1020. if (fieldsShown < 2)
  1021. {
  1022. n = abs ((int) inSeconds()) % 60;
  1023. if (n > 0)
  1024. {
  1025. result << n << ((n == 1) ? TRANS(" sec ")
  1026. : TRANS(" secs "));
  1027. ++fieldsShown;
  1028. }
  1029. if (fieldsShown < 1)
  1030. {
  1031. n = abs ((int) inMilliseconds()) % 1000;
  1032. if (n > 0)
  1033. {
  1034. result << n << TRANS(" ms");
  1035. ++fieldsShown;
  1036. }
  1037. }
  1038. }
  1039. }
  1040. }
  1041. return result.trimEnd();
  1042. }
  1043. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1044. {
  1045. seconds = other.seconds;
  1046. return *this;
  1047. }
  1048. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1049. {
  1050. return seconds == other.seconds;
  1051. }
  1052. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1053. {
  1054. return seconds != other.seconds;
  1055. }
  1056. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1057. {
  1058. return seconds > other.seconds;
  1059. }
  1060. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1061. {
  1062. return seconds < other.seconds;
  1063. }
  1064. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1065. {
  1066. return seconds >= other.seconds;
  1067. }
  1068. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1069. {
  1070. return seconds <= other.seconds;
  1071. }
  1072. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1073. {
  1074. return RelativeTime (seconds + timeToAdd.seconds);
  1075. }
  1076. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1077. {
  1078. return RelativeTime (seconds - timeToSubtract.seconds);
  1079. }
  1080. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1081. {
  1082. return RelativeTime (seconds + secondsToAdd);
  1083. }
  1084. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1085. {
  1086. return RelativeTime (seconds - secondsToSubtract);
  1087. }
  1088. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1089. {
  1090. seconds += timeToAdd.seconds;
  1091. return *this;
  1092. }
  1093. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1094. {
  1095. seconds -= timeToSubtract.seconds;
  1096. return *this;
  1097. }
  1098. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1099. {
  1100. seconds += secondsToAdd;
  1101. return *this;
  1102. }
  1103. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1104. {
  1105. seconds -= secondsToSubtract;
  1106. return *this;
  1107. }
  1108. END_JUCE_NAMESPACE
  1109. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1110. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1111. BEGIN_JUCE_NAMESPACE
  1112. const String SystemStats::getJUCEVersion() throw()
  1113. {
  1114. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1115. + "." + String (JUCE_MINOR_VERSION)
  1116. + "." + String (JUCE_BUILDNUMBER);
  1117. }
  1118. const StringArray SystemStats::getMACAddressStrings()
  1119. {
  1120. int64 macAddresses [16];
  1121. const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
  1122. StringArray s;
  1123. for (int i = 0; i < numAddresses; ++i)
  1124. {
  1125. s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
  1126. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
  1127. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
  1128. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
  1129. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
  1130. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
  1131. }
  1132. return s;
  1133. }
  1134. static bool juceInitialisedNonGUI = false;
  1135. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1136. {
  1137. if (! juceInitialisedNonGUI)
  1138. {
  1139. #if JUCE_MAC || JUCE_IPHONE
  1140. const ScopedAutoReleasePool pool;
  1141. #endif
  1142. #ifdef JUCE_DEBUG
  1143. {
  1144. // Some simple test code to keep an eye on things and make sure these functions
  1145. // work ok on all platforms. Let me know if any of these assertions fail!
  1146. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1147. static_jassert (sizeof (int8) == 1);
  1148. static_jassert (sizeof (uint8) == 1);
  1149. static_jassert (sizeof (int16) == 2);
  1150. static_jassert (sizeof (uint16) == 2);
  1151. static_jassert (sizeof (int32) == 4);
  1152. static_jassert (sizeof (uint32) == 4);
  1153. static_jassert (sizeof (int64) == 8);
  1154. static_jassert (sizeof (uint64) == 8);
  1155. char a1[7];
  1156. jassert (numElementsInArray(a1) == 7);
  1157. int a2[3];
  1158. jassert (numElementsInArray(a2) == 3);
  1159. int n = 1;
  1160. Atomic::increment (n);
  1161. jassert (Atomic::incrementAndReturn (n) == 3);
  1162. Atomic::decrement (n);
  1163. jassert (Atomic::decrementAndReturn (n) == 1);
  1164. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1165. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1166. // Some quick stream tests..
  1167. int randomInt = Random::getSystemRandom().nextInt();
  1168. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1169. double randomDouble = Random::getSystemRandom().nextDouble();
  1170. String randomString;
  1171. for (int i = 50; --i >= 0;)
  1172. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1173. MemoryOutputStream mo;
  1174. mo.writeInt (randomInt);
  1175. mo.writeIntBigEndian (randomInt);
  1176. mo.writeCompressedInt (randomInt);
  1177. mo.writeString (randomString);
  1178. mo.writeInt64 (randomInt64);
  1179. mo.writeInt64BigEndian (randomInt64);
  1180. mo.writeDouble (randomDouble);
  1181. mo.writeDoubleBigEndian (randomDouble);
  1182. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1183. jassert (mi.readInt() == randomInt);
  1184. jassert (mi.readIntBigEndian() == randomInt);
  1185. jassert (mi.readCompressedInt() == randomInt);
  1186. jassert (mi.readString() == randomString);
  1187. jassert (mi.readInt64() == randomInt64);
  1188. jassert (mi.readInt64BigEndian() == randomInt64);
  1189. jassert (mi.readDouble() == randomDouble);
  1190. jassert (mi.readDoubleBigEndian() == randomDouble);
  1191. }
  1192. #endif
  1193. // Now the real initialisation..
  1194. juceInitialisedNonGUI = true;
  1195. DBG (SystemStats::getJUCEVersion());
  1196. SystemStats::initialiseStats();
  1197. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1198. }
  1199. }
  1200. #if JUCE_WINDOWS
  1201. // This is imported from the sockets code..
  1202. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1203. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1204. #endif
  1205. #if JUCE_DEBUG
  1206. extern void juce_CheckForDanglingStreams();
  1207. #endif
  1208. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1209. {
  1210. if (juceInitialisedNonGUI)
  1211. {
  1212. #if JUCE_MAC || JUCE_IPHONE
  1213. const ScopedAutoReleasePool pool;
  1214. #endif
  1215. #if JUCE_WINDOWS
  1216. // need to shut down sockets if they were used..
  1217. if (juce_CloseWin32SocketLib != 0)
  1218. (*juce_CloseWin32SocketLib)();
  1219. #endif
  1220. LocalisedStrings::setCurrentMappings (0);
  1221. Thread::stopAllThreads (3000);
  1222. #if JUCE_DEBUG
  1223. juce_CheckForDanglingStreams();
  1224. #endif
  1225. juceInitialisedNonGUI = false;
  1226. }
  1227. }
  1228. #ifdef JUCE_DLL
  1229. void* juce_Malloc (const int size)
  1230. {
  1231. return malloc (size);
  1232. }
  1233. void* juce_Calloc (const int size)
  1234. {
  1235. return calloc (1, size);
  1236. }
  1237. void* juce_Realloc (void* const block, const int size)
  1238. {
  1239. return realloc (block, size);
  1240. }
  1241. void juce_Free (void* const block)
  1242. {
  1243. free (block);
  1244. }
  1245. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1246. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1247. {
  1248. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1249. }
  1250. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1251. {
  1252. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1253. }
  1254. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1255. {
  1256. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1257. }
  1258. void juce_DebugFree (void* const block)
  1259. {
  1260. _free_dbg (block, _NORMAL_BLOCK);
  1261. }
  1262. #endif
  1263. #endif
  1264. END_JUCE_NAMESPACE
  1265. /*** End of inlined file: juce_SystemStats.cpp ***/
  1266. /*** Start of inlined file: juce_Time.cpp ***/
  1267. #ifdef _MSC_VER
  1268. #pragma warning (disable: 4514)
  1269. #pragma warning (push)
  1270. #endif
  1271. #ifndef JUCE_WINDOWS
  1272. #include <sys/time.h>
  1273. #else
  1274. #include <ctime>
  1275. #endif
  1276. #include <sys/timeb.h>
  1277. BEGIN_JUCE_NAMESPACE
  1278. #ifdef _MSC_VER
  1279. #pragma warning (pop)
  1280. #ifdef _INC_TIME_INL
  1281. #define USE_NEW_SECURE_TIME_FNS
  1282. #endif
  1283. #endif
  1284. namespace TimeHelpers
  1285. {
  1286. static struct tm millisToLocal (const int64 millis) throw()
  1287. {
  1288. struct tm result;
  1289. const int64 seconds = millis / 1000;
  1290. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1291. {
  1292. // use extended maths for dates beyond 1970 to 2037..
  1293. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1294. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1295. const int days = (int) (jdm / literal64bit (86400));
  1296. const int a = 32044 + days;
  1297. const int b = (4 * a + 3) / 146097;
  1298. const int c = a - (b * 146097) / 4;
  1299. const int d = (4 * c + 3) / 1461;
  1300. const int e = c - (d * 1461) / 4;
  1301. const int m = (5 * e + 2) / 153;
  1302. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1303. result.tm_mon = m + 2 - 12 * (m / 10);
  1304. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1305. result.tm_wday = (days + 1) % 7;
  1306. result.tm_yday = -1;
  1307. int t = (int) (jdm % literal64bit (86400));
  1308. result.tm_hour = t / 3600;
  1309. t %= 3600;
  1310. result.tm_min = t / 60;
  1311. result.tm_sec = t % 60;
  1312. result.tm_isdst = -1;
  1313. }
  1314. else
  1315. {
  1316. time_t now = static_cast <time_t> (seconds);
  1317. #if JUCE_WINDOWS
  1318. #ifdef USE_NEW_SECURE_TIME_FNS
  1319. if (now >= 0 && now <= 0x793406fff)
  1320. localtime_s (&result, &now);
  1321. else
  1322. zeromem (&result, sizeof (result));
  1323. #else
  1324. result = *localtime (&now);
  1325. #endif
  1326. #else
  1327. // more thread-safe
  1328. localtime_r (&now, &result);
  1329. #endif
  1330. }
  1331. return result;
  1332. }
  1333. static int extendedModulo (const int64 value, const int modulo) throw()
  1334. {
  1335. return (int) (value >= 0 ? (value % modulo)
  1336. : (value - ((value / modulo) + 1) * modulo));
  1337. }
  1338. static uint32 lastMSCounterValue = 0;
  1339. }
  1340. Time::Time() throw()
  1341. : millisSinceEpoch (0)
  1342. {
  1343. }
  1344. Time::Time (const Time& other) throw()
  1345. : millisSinceEpoch (other.millisSinceEpoch)
  1346. {
  1347. }
  1348. Time::Time (const int64 ms) throw()
  1349. : millisSinceEpoch (ms)
  1350. {
  1351. }
  1352. Time::Time (const int year,
  1353. const int month,
  1354. const int day,
  1355. const int hours,
  1356. const int minutes,
  1357. const int seconds,
  1358. const int milliseconds,
  1359. const bool useLocalTime) throw()
  1360. {
  1361. jassert (year > 100); // year must be a 4-digit version
  1362. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1363. {
  1364. // use extended maths for dates beyond 1970 to 2037..
  1365. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1366. : 0;
  1367. const int a = (13 - month) / 12;
  1368. const int y = year + 4800 - a;
  1369. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1370. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1371. - 32045;
  1372. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1373. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1374. + milliseconds;
  1375. }
  1376. else
  1377. {
  1378. struct tm t;
  1379. t.tm_year = year - 1900;
  1380. t.tm_mon = month;
  1381. t.tm_mday = day;
  1382. t.tm_hour = hours;
  1383. t.tm_min = minutes;
  1384. t.tm_sec = seconds;
  1385. t.tm_isdst = -1;
  1386. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1387. if (millisSinceEpoch < 0)
  1388. millisSinceEpoch = 0;
  1389. else
  1390. millisSinceEpoch += milliseconds;
  1391. }
  1392. }
  1393. Time::~Time() throw()
  1394. {
  1395. }
  1396. Time& Time::operator= (const Time& other) throw()
  1397. {
  1398. millisSinceEpoch = other.millisSinceEpoch;
  1399. return *this;
  1400. }
  1401. int64 Time::currentTimeMillis() throw()
  1402. {
  1403. static uint32 lastCounterResult = 0xffffffff;
  1404. static int64 correction = 0;
  1405. const uint32 now = getMillisecondCounter();
  1406. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1407. if (now < lastCounterResult)
  1408. {
  1409. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1410. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1411. {
  1412. // get the time once using normal library calls, and store the difference needed to
  1413. // turn the millisecond counter into a real time.
  1414. #if JUCE_WINDOWS
  1415. struct _timeb t;
  1416. #ifdef USE_NEW_SECURE_TIME_FNS
  1417. _ftime_s (&t);
  1418. #else
  1419. _ftime (&t);
  1420. #endif
  1421. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1422. #else
  1423. struct timeval tv;
  1424. struct timezone tz;
  1425. gettimeofday (&tv, &tz);
  1426. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1427. #endif
  1428. }
  1429. }
  1430. lastCounterResult = now;
  1431. return correction + now;
  1432. }
  1433. uint32 juce_millisecondsSinceStartup() throw();
  1434. uint32 Time::getMillisecondCounter() throw()
  1435. {
  1436. const uint32 now = juce_millisecondsSinceStartup();
  1437. if (now < TimeHelpers::lastMSCounterValue)
  1438. {
  1439. // in multi-threaded apps this might be called concurrently, so
  1440. // make sure that our last counter value only increases and doesn't
  1441. // go backwards..
  1442. if (now < TimeHelpers::lastMSCounterValue - 1000)
  1443. TimeHelpers::lastMSCounterValue = now;
  1444. }
  1445. else
  1446. {
  1447. TimeHelpers::lastMSCounterValue = now;
  1448. }
  1449. return now;
  1450. }
  1451. uint32 Time::getApproximateMillisecondCounter() throw()
  1452. {
  1453. jassert (TimeHelpers::lastMSCounterValue != 0);
  1454. return TimeHelpers::lastMSCounterValue;
  1455. }
  1456. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1457. {
  1458. for (;;)
  1459. {
  1460. const uint32 now = getMillisecondCounter();
  1461. if (now >= targetTime)
  1462. break;
  1463. const int toWait = targetTime - now;
  1464. if (toWait > 2)
  1465. {
  1466. Thread::sleep (jmin (20, toWait >> 1));
  1467. }
  1468. else
  1469. {
  1470. // xxx should consider using mutex_pause on the mac as it apparently
  1471. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1472. for (int i = 10; --i >= 0;)
  1473. Thread::yield();
  1474. }
  1475. }
  1476. }
  1477. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1478. {
  1479. return ticks / (double) getHighResolutionTicksPerSecond();
  1480. }
  1481. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1482. {
  1483. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1484. }
  1485. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1486. {
  1487. return Time (currentTimeMillis());
  1488. }
  1489. const String Time::toString (const bool includeDate,
  1490. const bool includeTime,
  1491. const bool includeSeconds,
  1492. const bool use24HourClock) const throw()
  1493. {
  1494. String result;
  1495. if (includeDate)
  1496. {
  1497. result << getDayOfMonth() << ' '
  1498. << getMonthName (true) << ' '
  1499. << getYear();
  1500. if (includeTime)
  1501. result << ' ';
  1502. }
  1503. if (includeTime)
  1504. {
  1505. const int mins = getMinutes();
  1506. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1507. << (mins < 10 ? ":0" : ":") << mins;
  1508. if (includeSeconds)
  1509. {
  1510. const int secs = getSeconds();
  1511. result << (secs < 10 ? ":0" : ":") << secs;
  1512. }
  1513. if (! use24HourClock)
  1514. result << (isAfternoon() ? "pm" : "am");
  1515. }
  1516. return result.trimEnd();
  1517. }
  1518. const String Time::formatted (const juce_wchar* const format) const throw()
  1519. {
  1520. String buffer;
  1521. int bufferSize = 128;
  1522. buffer.preallocateStorage (bufferSize);
  1523. struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  1524. while (CharacterFunctions::ftime (static_cast <juce_wchar*> (buffer), bufferSize, format, &t) <= 0)
  1525. {
  1526. bufferSize += 128;
  1527. buffer.preallocateStorage (bufferSize);
  1528. }
  1529. return buffer;
  1530. }
  1531. int Time::getYear() const throw()
  1532. {
  1533. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900;
  1534. }
  1535. int Time::getMonth() const throw()
  1536. {
  1537. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon;
  1538. }
  1539. int Time::getDayOfMonth() const throw()
  1540. {
  1541. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday;
  1542. }
  1543. int Time::getDayOfWeek() const throw()
  1544. {
  1545. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday;
  1546. }
  1547. int Time::getHours() const throw()
  1548. {
  1549. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour;
  1550. }
  1551. int Time::getHoursInAmPmFormat() const throw()
  1552. {
  1553. const int hours = getHours();
  1554. if (hours == 0)
  1555. return 12;
  1556. else if (hours <= 12)
  1557. return hours;
  1558. else
  1559. return hours - 12;
  1560. }
  1561. bool Time::isAfternoon() const throw()
  1562. {
  1563. return getHours() >= 12;
  1564. }
  1565. int Time::getMinutes() const throw()
  1566. {
  1567. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min;
  1568. }
  1569. int Time::getSeconds() const throw()
  1570. {
  1571. return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60);
  1572. }
  1573. int Time::getMilliseconds() const throw()
  1574. {
  1575. return TimeHelpers::extendedModulo (millisSinceEpoch, 1000);
  1576. }
  1577. bool Time::isDaylightSavingTime() const throw()
  1578. {
  1579. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  1580. }
  1581. const String Time::getTimeZone() const throw()
  1582. {
  1583. String zone[2];
  1584. #if JUCE_WINDOWS
  1585. _tzset();
  1586. #ifdef USE_NEW_SECURE_TIME_FNS
  1587. {
  1588. char name [128];
  1589. size_t length;
  1590. for (int i = 0; i < 2; ++i)
  1591. {
  1592. zeromem (name, sizeof (name));
  1593. _get_tzname (&length, name, 127, i);
  1594. zone[i] = name;
  1595. }
  1596. }
  1597. #else
  1598. const char** const zonePtr = (const char**) _tzname;
  1599. zone[0] = zonePtr[0];
  1600. zone[1] = zonePtr[1];
  1601. #endif
  1602. #else
  1603. tzset();
  1604. const char** const zonePtr = (const char**) tzname;
  1605. zone[0] = zonePtr[0];
  1606. zone[1] = zonePtr[1];
  1607. #endif
  1608. if (isDaylightSavingTime())
  1609. {
  1610. zone[0] = zone[1];
  1611. if (zone[0].length() > 3
  1612. && zone[0].containsIgnoreCase ("daylight")
  1613. && zone[0].contains ("GMT"))
  1614. zone[0] = "BST";
  1615. }
  1616. return zone[0].substring (0, 3);
  1617. }
  1618. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1619. {
  1620. return getMonthName (getMonth(), threeLetterVersion);
  1621. }
  1622. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1623. {
  1624. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1625. }
  1626. const String Time::getMonthName (int monthNumber, const bool threeLetterVersion) throw()
  1627. {
  1628. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1629. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1630. monthNumber %= 12;
  1631. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1632. : longMonthNames [monthNumber]);
  1633. }
  1634. const String Time::getWeekdayName (int day, const bool threeLetterVersion) throw()
  1635. {
  1636. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1637. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1638. day %= 7;
  1639. return TRANS (threeLetterVersion ? shortDayNames [day]
  1640. : longDayNames [day]);
  1641. }
  1642. END_JUCE_NAMESPACE
  1643. /*** End of inlined file: juce_Time.cpp ***/
  1644. /*** Start of inlined file: juce_BitArray.cpp ***/
  1645. BEGIN_JUCE_NAMESPACE
  1646. BigInteger::BigInteger()
  1647. : numValues (4),
  1648. highestBit (-1),
  1649. negative (false)
  1650. {
  1651. values.calloc (numValues + 1);
  1652. }
  1653. BigInteger::BigInteger (const int value)
  1654. : numValues (4),
  1655. highestBit (31),
  1656. negative (value < 0)
  1657. {
  1658. values.calloc (numValues + 1);
  1659. values[0] = abs (value);
  1660. highestBit = getHighestBit();
  1661. }
  1662. BigInteger::BigInteger (int64 value)
  1663. : numValues (4),
  1664. highestBit (63),
  1665. negative (value < 0)
  1666. {
  1667. values.calloc (numValues + 1);
  1668. if (value < 0)
  1669. value = -value;
  1670. values[0] = (unsigned int) value;
  1671. values[1] = (unsigned int) (value >> 32);
  1672. highestBit = getHighestBit();
  1673. }
  1674. BigInteger::BigInteger (const unsigned int value)
  1675. : numValues (4),
  1676. highestBit (31),
  1677. negative (false)
  1678. {
  1679. values.calloc (numValues + 1);
  1680. values[0] = value;
  1681. highestBit = getHighestBit();
  1682. }
  1683. BigInteger::BigInteger (const BigInteger& other)
  1684. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1685. highestBit (other.getHighestBit()),
  1686. negative (other.negative)
  1687. {
  1688. values.malloc (numValues + 1);
  1689. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1690. }
  1691. BigInteger::~BigInteger()
  1692. {
  1693. }
  1694. void BigInteger::swapWith (BigInteger& other) throw()
  1695. {
  1696. values.swapWith (other.values);
  1697. swapVariables (numValues, other.numValues);
  1698. swapVariables (highestBit, other.highestBit);
  1699. swapVariables (negative, other.negative);
  1700. }
  1701. BigInteger& BigInteger::operator= (const BigInteger& other)
  1702. {
  1703. if (this != &other)
  1704. {
  1705. highestBit = other.getHighestBit();
  1706. numValues = jmax (4, (highestBit >> 5) + 1);
  1707. negative = other.negative;
  1708. values.malloc (numValues + 1);
  1709. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1710. }
  1711. return *this;
  1712. }
  1713. void BigInteger::ensureSize (const int numVals)
  1714. {
  1715. if (numVals + 2 >= numValues)
  1716. {
  1717. int oldSize = numValues;
  1718. numValues = ((numVals + 2) * 3) / 2;
  1719. values.realloc (numValues + 1);
  1720. while (oldSize < numValues)
  1721. values [oldSize++] = 0;
  1722. }
  1723. }
  1724. bool BigInteger::operator[] (const int bit) const throw()
  1725. {
  1726. return bit <= highestBit && bit >= 0
  1727. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1728. }
  1729. int BigInteger::toInteger() const throw()
  1730. {
  1731. const int n = (int) (values[0] & 0x7fffffff);
  1732. return negative ? -n : n;
  1733. }
  1734. const BigInteger BigInteger::getBitRange (int startBit, int numBits) const
  1735. {
  1736. BigInteger r;
  1737. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  1738. r.ensureSize (numBits >> 5);
  1739. r.highestBit = numBits;
  1740. int i = 0;
  1741. while (numBits > 0)
  1742. {
  1743. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  1744. numBits -= 32;
  1745. startBit += 32;
  1746. }
  1747. r.highestBit = r.getHighestBit();
  1748. return r;
  1749. }
  1750. int BigInteger::getBitRangeAsInt (const int startBit, int numBits) const throw()
  1751. {
  1752. if (numBits > 32)
  1753. {
  1754. jassertfalse // use getBitRange() if you need more than 32 bits..
  1755. numBits = 32;
  1756. }
  1757. numBits = jmin (numBits, highestBit + 1 - startBit);
  1758. if (numBits <= 0)
  1759. return 0;
  1760. const int pos = startBit >> 5;
  1761. const int offset = startBit & 31;
  1762. const int endSpace = 32 - numBits;
  1763. uint32 n = ((uint32) values [pos]) >> offset;
  1764. if (offset > endSpace)
  1765. n |= ((uint32) values [pos + 1]) << (32 - offset);
  1766. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  1767. }
  1768. void BigInteger::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet)
  1769. {
  1770. if (numBits > 32)
  1771. {
  1772. jassertfalse
  1773. numBits = 32;
  1774. }
  1775. for (int i = 0; i < numBits; ++i)
  1776. {
  1777. setBit (startBit + i, (valueToSet & 1) != 0);
  1778. valueToSet >>= 1;
  1779. }
  1780. }
  1781. void BigInteger::clear()
  1782. {
  1783. if (numValues > 16)
  1784. {
  1785. numValues = 4;
  1786. values.calloc (numValues + 1);
  1787. }
  1788. else
  1789. {
  1790. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1791. }
  1792. highestBit = -1;
  1793. negative = false;
  1794. }
  1795. void BigInteger::setBit (const int bit)
  1796. {
  1797. if (bit >= 0)
  1798. {
  1799. if (bit > highestBit)
  1800. {
  1801. ensureSize (bit >> 5);
  1802. highestBit = bit;
  1803. }
  1804. values [bit >> 5] |= (1 << (bit & 31));
  1805. }
  1806. }
  1807. void BigInteger::setBit (const int bit, const bool shouldBeSet)
  1808. {
  1809. if (shouldBeSet)
  1810. setBit (bit);
  1811. else
  1812. clearBit (bit);
  1813. }
  1814. void BigInteger::clearBit (const int bit) throw()
  1815. {
  1816. if (bit >= 0 && bit <= highestBit)
  1817. values [bit >> 5] &= ~(1 << (bit & 31));
  1818. }
  1819. void BigInteger::setRange (int startBit, int numBits, const bool shouldBeSet)
  1820. {
  1821. while (--numBits >= 0)
  1822. setBit (startBit++, shouldBeSet);
  1823. }
  1824. void BigInteger::insertBit (const int bit, const bool shouldBeSet)
  1825. {
  1826. if (bit >= 0)
  1827. shiftBits (1, bit);
  1828. setBit (bit, shouldBeSet);
  1829. }
  1830. bool BigInteger::isZero() const throw()
  1831. {
  1832. return getHighestBit() < 0;
  1833. }
  1834. bool BigInteger::isOne() const throw()
  1835. {
  1836. return getHighestBit() == 0 && ! negative;
  1837. }
  1838. bool BigInteger::isNegative() const throw()
  1839. {
  1840. return negative && ! isZero();
  1841. }
  1842. void BigInteger::setNegative (const bool neg) throw()
  1843. {
  1844. negative = neg;
  1845. }
  1846. void BigInteger::negate() throw()
  1847. {
  1848. negative = (! negative) && ! isZero();
  1849. }
  1850. int BigInteger::countNumberOfSetBits() const throw()
  1851. {
  1852. int total = 0;
  1853. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  1854. {
  1855. unsigned int n = values[i];
  1856. if (n == 0xffffffff)
  1857. {
  1858. total += 32;
  1859. }
  1860. else
  1861. {
  1862. while (n != 0)
  1863. {
  1864. total += (n & 1);
  1865. n >>= 1;
  1866. }
  1867. }
  1868. }
  1869. return total;
  1870. }
  1871. int BigInteger::getHighestBit() const throw()
  1872. {
  1873. for (int i = highestBit + 1; --i >= 0;)
  1874. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1875. return i;
  1876. return -1;
  1877. }
  1878. int BigInteger::findNextSetBit (int i) const throw()
  1879. {
  1880. for (; i <= highestBit; ++i)
  1881. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1882. return i;
  1883. return -1;
  1884. }
  1885. int BigInteger::findNextClearBit (int i) const throw()
  1886. {
  1887. for (; i <= highestBit; ++i)
  1888. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  1889. break;
  1890. return i;
  1891. }
  1892. BigInteger& BigInteger::operator+= (const BigInteger& other)
  1893. {
  1894. if (other.isNegative())
  1895. return operator-= (-other);
  1896. if (isNegative())
  1897. {
  1898. if (compareAbsolute (other) < 0)
  1899. {
  1900. BigInteger temp (*this);
  1901. temp.negate();
  1902. *this = other;
  1903. operator-= (temp);
  1904. }
  1905. else
  1906. {
  1907. negate();
  1908. operator-= (other);
  1909. negate();
  1910. }
  1911. }
  1912. else
  1913. {
  1914. if (other.highestBit > highestBit)
  1915. highestBit = other.highestBit;
  1916. ++highestBit;
  1917. const int numInts = (highestBit >> 5) + 1;
  1918. ensureSize (numInts);
  1919. int64 remainder = 0;
  1920. for (int i = 0; i <= numInts; ++i)
  1921. {
  1922. if (i < numValues)
  1923. remainder += values[i];
  1924. if (i < other.numValues)
  1925. remainder += other.values[i];
  1926. values[i] = (unsigned int) remainder;
  1927. remainder >>= 32;
  1928. }
  1929. jassert (remainder == 0);
  1930. highestBit = getHighestBit();
  1931. }
  1932. return *this;
  1933. }
  1934. BigInteger& BigInteger::operator-= (const BigInteger& other)
  1935. {
  1936. if (other.isNegative())
  1937. return operator+= (-other);
  1938. if (! isNegative())
  1939. {
  1940. if (compareAbsolute (other) < 0)
  1941. {
  1942. BigInteger temp (other);
  1943. swapWith (temp);
  1944. operator-= (temp);
  1945. negate();
  1946. return *this;
  1947. }
  1948. }
  1949. else
  1950. {
  1951. negate();
  1952. operator+= (other);
  1953. negate();
  1954. return *this;
  1955. }
  1956. const int numInts = (highestBit >> 5) + 1;
  1957. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1958. int64 amountToSubtract = 0;
  1959. for (int i = 0; i <= numInts; ++i)
  1960. {
  1961. if (i <= maxOtherInts)
  1962. amountToSubtract += (int64) other.values[i];
  1963. if (values[i] >= amountToSubtract)
  1964. {
  1965. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1966. amountToSubtract = 0;
  1967. }
  1968. else
  1969. {
  1970. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1971. values[i] = (unsigned int) n;
  1972. amountToSubtract = 1;
  1973. }
  1974. }
  1975. return *this;
  1976. }
  1977. BigInteger& BigInteger::operator*= (const BigInteger& other)
  1978. {
  1979. BigInteger total;
  1980. highestBit = getHighestBit();
  1981. const bool wasNegative = isNegative();
  1982. setNegative (false);
  1983. for (int i = 0; i <= highestBit; ++i)
  1984. {
  1985. if (operator[](i))
  1986. {
  1987. BigInteger n (other);
  1988. n.setNegative (false);
  1989. n <<= i;
  1990. total += n;
  1991. }
  1992. }
  1993. total.setNegative (wasNegative ^ other.isNegative());
  1994. swapWith (total);
  1995. return *this;
  1996. }
  1997. void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
  1998. {
  1999. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  2000. const int divHB = divisor.getHighestBit();
  2001. const int ourHB = getHighestBit();
  2002. if (divHB < 0 || ourHB < 0)
  2003. {
  2004. // division by zero
  2005. remainder.clear();
  2006. clear();
  2007. }
  2008. else
  2009. {
  2010. const bool wasNegative = isNegative();
  2011. swapWith (remainder);
  2012. remainder.setNegative (false);
  2013. clear();
  2014. BigInteger temp (divisor);
  2015. temp.setNegative (false);
  2016. int leftShift = ourHB - divHB;
  2017. temp <<= leftShift;
  2018. while (leftShift >= 0)
  2019. {
  2020. if (remainder.compareAbsolute (temp) >= 0)
  2021. {
  2022. remainder -= temp;
  2023. setBit (leftShift);
  2024. }
  2025. if (--leftShift >= 0)
  2026. temp >>= 1;
  2027. }
  2028. negative = wasNegative ^ divisor.isNegative();
  2029. remainder.setNegative (wasNegative);
  2030. }
  2031. }
  2032. BigInteger& BigInteger::operator/= (const BigInteger& other)
  2033. {
  2034. BigInteger remainder;
  2035. divideBy (other, remainder);
  2036. return *this;
  2037. }
  2038. BigInteger& BigInteger::operator|= (const BigInteger& other)
  2039. {
  2040. // this operation doesn't take into account negative values..
  2041. jassert (isNegative() == other.isNegative());
  2042. if (other.highestBit >= 0)
  2043. {
  2044. ensureSize (other.highestBit >> 5);
  2045. int n = (other.highestBit >> 5) + 1;
  2046. while (--n >= 0)
  2047. values[n] |= other.values[n];
  2048. if (other.highestBit > highestBit)
  2049. highestBit = other.highestBit;
  2050. highestBit = getHighestBit();
  2051. }
  2052. return *this;
  2053. }
  2054. BigInteger& BigInteger::operator&= (const BigInteger& other)
  2055. {
  2056. // this operation doesn't take into account negative values..
  2057. jassert (isNegative() == other.isNegative());
  2058. int n = numValues;
  2059. while (n > other.numValues)
  2060. values[--n] = 0;
  2061. while (--n >= 0)
  2062. values[n] &= other.values[n];
  2063. if (other.highestBit < highestBit)
  2064. highestBit = other.highestBit;
  2065. highestBit = getHighestBit();
  2066. return *this;
  2067. }
  2068. BigInteger& BigInteger::operator^= (const BigInteger& other)
  2069. {
  2070. // this operation will only work with the absolute values
  2071. jassert (isNegative() == other.isNegative());
  2072. if (other.highestBit >= 0)
  2073. {
  2074. ensureSize (other.highestBit >> 5);
  2075. int n = (other.highestBit >> 5) + 1;
  2076. while (--n >= 0)
  2077. values[n] ^= other.values[n];
  2078. if (other.highestBit > highestBit)
  2079. highestBit = other.highestBit;
  2080. highestBit = getHighestBit();
  2081. }
  2082. return *this;
  2083. }
  2084. BigInteger& BigInteger::operator%= (const BigInteger& divisor)
  2085. {
  2086. BigInteger remainder;
  2087. divideBy (divisor, remainder);
  2088. swapWith (remainder);
  2089. return *this;
  2090. }
  2091. BigInteger& BigInteger::operator<<= (int numBitsToShift)
  2092. {
  2093. shiftBits (numBitsToShift, 0);
  2094. return *this;
  2095. }
  2096. BigInteger& BigInteger::operator>>= (int numBitsToShift)
  2097. {
  2098. return operator<<= (-numBitsToShift);
  2099. }
  2100. BigInteger& BigInteger::operator++() { return operator+= (1); }
  2101. BigInteger& BigInteger::operator--() { return operator-= (1); }
  2102. const BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
  2103. const BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
  2104. const BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
  2105. const BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
  2106. const BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
  2107. const BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
  2108. const BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
  2109. const BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
  2110. const BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
  2111. const BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
  2112. const BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
  2113. const BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
  2114. const BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
  2115. int BigInteger::compare (const BigInteger& other) const throw()
  2116. {
  2117. if (isNegative() == other.isNegative())
  2118. {
  2119. const int absComp = compareAbsolute (other);
  2120. return isNegative() ? -absComp : absComp;
  2121. }
  2122. else
  2123. {
  2124. return isNegative() ? -1 : 1;
  2125. }
  2126. }
  2127. int BigInteger::compareAbsolute (const BigInteger& other) const throw()
  2128. {
  2129. const int h1 = getHighestBit();
  2130. const int h2 = other.getHighestBit();
  2131. if (h1 > h2)
  2132. return 1;
  2133. else if (h1 < h2)
  2134. return -1;
  2135. for (int i = (h1 >> 5) + 1; --i >= 0;)
  2136. if (values[i] != other.values[i])
  2137. return (values[i] > other.values[i]) ? 1 : -1;
  2138. return 0;
  2139. }
  2140. bool BigInteger::operator== (const BigInteger& other) const throw() { return compare (other) == 0; }
  2141. bool BigInteger::operator!= (const BigInteger& other) const throw() { return compare (other) != 0; }
  2142. bool BigInteger::operator< (const BigInteger& other) const throw() { return compare (other) < 0; }
  2143. bool BigInteger::operator<= (const BigInteger& other) const throw() { return compare (other) <= 0; }
  2144. bool BigInteger::operator> (const BigInteger& other) const throw() { return compare (other) > 0; }
  2145. bool BigInteger::operator>= (const BigInteger& other) const throw() { return compare (other) >= 0; }
  2146. void BigInteger::shiftBits (int bits, const int startBit)
  2147. {
  2148. if (highestBit < 0)
  2149. return;
  2150. if (startBit > 0)
  2151. {
  2152. if (bits < 0)
  2153. {
  2154. // right shift
  2155. for (int i = startBit; i <= highestBit; ++i)
  2156. setBit (i, operator[] (i - bits));
  2157. highestBit = getHighestBit();
  2158. }
  2159. else if (bits > 0)
  2160. {
  2161. // left shift
  2162. for (int i = highestBit + 1; --i >= startBit;)
  2163. setBit (i + bits, operator[] (i));
  2164. while (--bits >= 0)
  2165. clearBit (bits + startBit);
  2166. }
  2167. }
  2168. else
  2169. {
  2170. if (bits < 0)
  2171. {
  2172. // right shift
  2173. bits = -bits;
  2174. if (bits > highestBit)
  2175. {
  2176. clear();
  2177. }
  2178. else
  2179. {
  2180. const int wordsToMove = bits >> 5;
  2181. int top = 1 + (highestBit >> 5) - wordsToMove;
  2182. highestBit -= bits;
  2183. if (wordsToMove > 0)
  2184. {
  2185. int i;
  2186. for (i = 0; i < top; ++i)
  2187. values [i] = values [i + wordsToMove];
  2188. for (i = 0; i < wordsToMove; ++i)
  2189. values [top + i] = 0;
  2190. bits &= 31;
  2191. }
  2192. if (bits != 0)
  2193. {
  2194. const int invBits = 32 - bits;
  2195. --top;
  2196. for (int i = 0; i < top; ++i)
  2197. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2198. values[top] = (values[top] >> bits);
  2199. }
  2200. highestBit = getHighestBit();
  2201. }
  2202. }
  2203. else if (bits > 0)
  2204. {
  2205. // left shift
  2206. ensureSize (((highestBit + bits) >> 5) + 1);
  2207. const int wordsToMove = bits >> 5;
  2208. int top = 1 + (highestBit >> 5);
  2209. highestBit += bits;
  2210. if (wordsToMove > 0)
  2211. {
  2212. int i;
  2213. for (i = top; --i >= 0;)
  2214. values [i + wordsToMove] = values [i];
  2215. for (i = 0; i < wordsToMove; ++i)
  2216. values [i] = 0;
  2217. bits &= 31;
  2218. }
  2219. if (bits != 0)
  2220. {
  2221. const int invBits = 32 - bits;
  2222. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2223. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2224. values [wordsToMove] = values [wordsToMove] << bits;
  2225. }
  2226. highestBit = getHighestBit();
  2227. }
  2228. }
  2229. }
  2230. const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
  2231. {
  2232. while (! m->isZero())
  2233. {
  2234. if (n->compareAbsolute (*m) > 0)
  2235. swapVariables (m, n);
  2236. *m -= *n;
  2237. }
  2238. return *n;
  2239. }
  2240. const BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
  2241. {
  2242. BigInteger m (*this);
  2243. while (! n.isZero())
  2244. {
  2245. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2246. return simpleGCD (&m, &n);
  2247. BigInteger temp1 (m), temp2;
  2248. temp1.divideBy (n, temp2);
  2249. m = n;
  2250. n = temp2;
  2251. }
  2252. return m;
  2253. }
  2254. void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
  2255. {
  2256. BigInteger exp (exponent);
  2257. exp %= modulus;
  2258. BigInteger value (1);
  2259. swapWith (value);
  2260. value %= modulus;
  2261. while (! exp.isZero())
  2262. {
  2263. if (exp [0])
  2264. {
  2265. operator*= (value);
  2266. operator%= (modulus);
  2267. }
  2268. value *= value;
  2269. value %= modulus;
  2270. exp >>= 1;
  2271. }
  2272. }
  2273. void BigInteger::inverseModulo (const BigInteger& modulus)
  2274. {
  2275. if (modulus.isOne() || modulus.isNegative())
  2276. {
  2277. clear();
  2278. return;
  2279. }
  2280. if (isNegative() || compareAbsolute (modulus) >= 0)
  2281. operator%= (modulus);
  2282. if (isOne())
  2283. return;
  2284. if (! (*this)[0])
  2285. {
  2286. // not invertible
  2287. clear();
  2288. return;
  2289. }
  2290. BigInteger a1 (modulus);
  2291. BigInteger a2 (*this);
  2292. BigInteger b1 (modulus);
  2293. BigInteger b2 (1);
  2294. while (! a2.isOne())
  2295. {
  2296. BigInteger temp1, temp2, multiplier (a1);
  2297. multiplier.divideBy (a2, temp1);
  2298. temp1 = a2;
  2299. temp1 *= multiplier;
  2300. temp2 = a1;
  2301. temp2 -= temp1;
  2302. a1 = a2;
  2303. a2 = temp2;
  2304. temp1 = b2;
  2305. temp1 *= multiplier;
  2306. temp2 = b1;
  2307. temp2 -= temp1;
  2308. b1 = b2;
  2309. b2 = temp2;
  2310. }
  2311. while (b2.isNegative())
  2312. b2 += modulus;
  2313. b2 %= modulus;
  2314. swapWith (b2);
  2315. }
  2316. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value)
  2317. {
  2318. return stream << value.toString (10);
  2319. }
  2320. const String BigInteger::toString (const int base, const int minimumNumCharacters) const
  2321. {
  2322. String s;
  2323. BigInteger v (*this);
  2324. if (base == 2 || base == 8 || base == 16)
  2325. {
  2326. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2327. static const char* const hexDigits = "0123456789abcdef";
  2328. for (;;)
  2329. {
  2330. const int remainder = v.getBitRangeAsInt (0, bits);
  2331. v >>= bits;
  2332. if (remainder == 0 && v.isZero())
  2333. break;
  2334. s = String::charToString (hexDigits [remainder]) + s;
  2335. }
  2336. }
  2337. else if (base == 10)
  2338. {
  2339. const BigInteger ten (10);
  2340. BigInteger remainder;
  2341. for (;;)
  2342. {
  2343. v.divideBy (ten, remainder);
  2344. if (remainder.isZero() && v.isZero())
  2345. break;
  2346. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2347. }
  2348. }
  2349. else
  2350. {
  2351. jassertfalse // can't do the specified base!
  2352. return String::empty;
  2353. }
  2354. s = s.paddedLeft ('0', minimumNumCharacters);
  2355. return isNegative() ? "-" + s : s;
  2356. }
  2357. void BigInteger::parseString (const String& text, const int base)
  2358. {
  2359. clear();
  2360. const juce_wchar* t = text;
  2361. if (base == 2 || base == 8 || base == 16)
  2362. {
  2363. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2364. for (;;)
  2365. {
  2366. const juce_wchar c = *t++;
  2367. const int digit = CharacterFunctions::getHexDigitValue (c);
  2368. if (((unsigned int) digit) < (unsigned int) base)
  2369. {
  2370. operator<<= (bits);
  2371. operator+= (digit);
  2372. }
  2373. else if (c == 0)
  2374. {
  2375. break;
  2376. }
  2377. }
  2378. }
  2379. else if (base == 10)
  2380. {
  2381. const BigInteger ten ((unsigned int) 10);
  2382. for (;;)
  2383. {
  2384. const juce_wchar c = *t++;
  2385. if (c >= '0' && c <= '9')
  2386. {
  2387. operator*= (ten);
  2388. operator+= ((int) (c - '0'));
  2389. }
  2390. else if (c == 0)
  2391. {
  2392. break;
  2393. }
  2394. }
  2395. }
  2396. setNegative (text.trimStart().startsWithChar ('-'));
  2397. }
  2398. const MemoryBlock BigInteger::toMemoryBlock() const
  2399. {
  2400. const int numBytes = (getHighestBit() + 8) >> 3;
  2401. MemoryBlock mb ((size_t) numBytes);
  2402. for (int i = 0; i < numBytes; ++i)
  2403. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2404. return mb;
  2405. }
  2406. void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
  2407. {
  2408. clear();
  2409. for (int i = (int) data.getSize(); --i >= 0;)
  2410. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2411. }
  2412. END_JUCE_NAMESPACE
  2413. /*** End of inlined file: juce_BitArray.cpp ***/
  2414. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2415. BEGIN_JUCE_NAMESPACE
  2416. MemoryBlock::MemoryBlock() throw()
  2417. : size (0)
  2418. {
  2419. }
  2420. MemoryBlock::MemoryBlock (const size_t initialSize,
  2421. const bool initialiseToZero) throw()
  2422. {
  2423. if (initialSize > 0)
  2424. {
  2425. size = initialSize;
  2426. data.allocate (initialSize, initialiseToZero);
  2427. }
  2428. else
  2429. {
  2430. size = 0;
  2431. }
  2432. }
  2433. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2434. : size (other.size)
  2435. {
  2436. if (size > 0)
  2437. {
  2438. jassert (other.data != 0);
  2439. data.malloc (size);
  2440. memcpy (data, other.data, size);
  2441. }
  2442. }
  2443. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2444. const size_t sizeInBytes) throw()
  2445. : size (jmax ((size_t) 0, sizeInBytes))
  2446. {
  2447. jassert (sizeInBytes >= 0);
  2448. if (size > 0)
  2449. {
  2450. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2451. data.malloc (size);
  2452. if (dataToInitialiseFrom != 0)
  2453. memcpy (data, dataToInitialiseFrom, size);
  2454. }
  2455. }
  2456. MemoryBlock::~MemoryBlock() throw()
  2457. {
  2458. jassert (size >= 0); // should never happen
  2459. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2460. }
  2461. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2462. {
  2463. if (this != &other)
  2464. {
  2465. setSize (other.size, false);
  2466. memcpy (data, other.data, size);
  2467. }
  2468. return *this;
  2469. }
  2470. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2471. {
  2472. return matches (other.data, other.size);
  2473. }
  2474. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2475. {
  2476. return ! operator== (other);
  2477. }
  2478. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2479. {
  2480. return size == dataSize
  2481. && memcmp (data, dataToCompare, size) == 0;
  2482. }
  2483. // this will resize the block to this size
  2484. void MemoryBlock::setSize (const size_t newSize,
  2485. const bool initialiseToZero) throw()
  2486. {
  2487. if (size != newSize)
  2488. {
  2489. if (newSize <= 0)
  2490. {
  2491. data.free();
  2492. size = 0;
  2493. }
  2494. else
  2495. {
  2496. if (data != 0)
  2497. {
  2498. data.realloc (newSize);
  2499. if (initialiseToZero && (newSize > size))
  2500. zeromem (data + size, newSize - size);
  2501. }
  2502. else
  2503. {
  2504. data.allocate (newSize, initialiseToZero);
  2505. }
  2506. size = newSize;
  2507. }
  2508. }
  2509. }
  2510. void MemoryBlock::ensureSize (const size_t minimumSize,
  2511. const bool initialiseToZero) throw()
  2512. {
  2513. if (size < minimumSize)
  2514. setSize (minimumSize, initialiseToZero);
  2515. }
  2516. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2517. {
  2518. swapVariables (size, other.size);
  2519. data.swapWith (other.data);
  2520. }
  2521. void MemoryBlock::fillWith (const uint8 value) throw()
  2522. {
  2523. memset (data, (int) value, size);
  2524. }
  2525. void MemoryBlock::append (const void* const srcData,
  2526. const size_t numBytes) throw()
  2527. {
  2528. if (numBytes > 0)
  2529. {
  2530. const size_t oldSize = size;
  2531. setSize (size + numBytes);
  2532. memcpy (data + oldSize, srcData, numBytes);
  2533. }
  2534. }
  2535. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2536. {
  2537. const char* d = static_cast<const char*> (src);
  2538. if (offset < 0)
  2539. {
  2540. d -= offset;
  2541. num -= offset;
  2542. offset = 0;
  2543. }
  2544. if (offset + num > size)
  2545. num = size - offset;
  2546. if (num > 0)
  2547. memcpy (data + offset, d, num);
  2548. }
  2549. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2550. {
  2551. char* d = static_cast<char*> (dst);
  2552. if (offset < 0)
  2553. {
  2554. zeromem (d, -offset);
  2555. d -= offset;
  2556. num += offset;
  2557. offset = 0;
  2558. }
  2559. if (offset + num > size)
  2560. {
  2561. const size_t newNum = size - offset;
  2562. zeromem (d + newNum, num - newNum);
  2563. num = newNum;
  2564. }
  2565. if (num > 0)
  2566. memcpy (d, data + offset, num);
  2567. }
  2568. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2569. {
  2570. if (startByte < 0)
  2571. {
  2572. numBytesToRemove += startByte;
  2573. startByte = 0;
  2574. }
  2575. if (startByte + numBytesToRemove >= size)
  2576. {
  2577. setSize (startByte);
  2578. }
  2579. else if (numBytesToRemove > 0)
  2580. {
  2581. memmove (data + startByte,
  2582. data + startByte + numBytesToRemove,
  2583. size - (startByte + numBytesToRemove));
  2584. setSize (size - numBytesToRemove);
  2585. }
  2586. }
  2587. const String MemoryBlock::toString() const throw()
  2588. {
  2589. return String (static_cast <const char*> (getData()), size);
  2590. }
  2591. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2592. {
  2593. int res = 0;
  2594. size_t byte = bitRangeStart >> 3;
  2595. int offsetInByte = (int) bitRangeStart & 7;
  2596. size_t bitsSoFar = 0;
  2597. while (numBits > 0 && (size_t) byte < size)
  2598. {
  2599. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2600. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2601. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2602. bitsSoFar += bitsThisTime;
  2603. numBits -= bitsThisTime;
  2604. ++byte;
  2605. offsetInByte = 0;
  2606. }
  2607. return res;
  2608. }
  2609. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2610. {
  2611. size_t byte = bitRangeStart >> 3;
  2612. int offsetInByte = (int) bitRangeStart & 7;
  2613. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2614. while (numBits > 0 && (size_t) byte < size)
  2615. {
  2616. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2617. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2618. const unsigned int tempBits = bitsToSet << offsetInByte;
  2619. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2620. ++byte;
  2621. numBits -= bitsThisTime;
  2622. bitsToSet >>= bitsThisTime;
  2623. mask >>= bitsThisTime;
  2624. offsetInByte = 0;
  2625. }
  2626. }
  2627. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2628. {
  2629. ensureSize (hex.length() >> 1);
  2630. char* dest = data;
  2631. int i = 0;
  2632. for (;;)
  2633. {
  2634. int byte = 0;
  2635. for (int loop = 2; --loop >= 0;)
  2636. {
  2637. byte <<= 4;
  2638. for (;;)
  2639. {
  2640. const juce_wchar c = hex [i++];
  2641. if (c >= '0' && c <= '9')
  2642. {
  2643. byte |= c - '0';
  2644. break;
  2645. }
  2646. else if (c >= 'a' && c <= 'z')
  2647. {
  2648. byte |= c - ('a' - 10);
  2649. break;
  2650. }
  2651. else if (c >= 'A' && c <= 'Z')
  2652. {
  2653. byte |= c - ('A' - 10);
  2654. break;
  2655. }
  2656. else if (c == 0)
  2657. {
  2658. setSize (static_cast <size_t> (dest - data));
  2659. return;
  2660. }
  2661. }
  2662. }
  2663. *dest++ = (char) byte;
  2664. }
  2665. }
  2666. static const char* const encodingTable
  2667. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2668. const String MemoryBlock::toBase64Encoding() const throw()
  2669. {
  2670. const size_t numChars = ((size << 3) + 5) / 6;
  2671. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2672. const int initialLen = destString.length();
  2673. destString.preallocateStorage (initialLen + 2 + numChars);
  2674. juce_wchar* d = destString;
  2675. d += initialLen;
  2676. *d++ = '.';
  2677. for (size_t i = 0; i < numChars; ++i)
  2678. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2679. *d++ = 0;
  2680. return destString;
  2681. }
  2682. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2683. {
  2684. const int startPos = s.indexOfChar ('.') + 1;
  2685. if (startPos <= 0)
  2686. return false;
  2687. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2688. setSize (numBytesNeeded, true);
  2689. const int numChars = s.length() - startPos;
  2690. const juce_wchar* srcChars = s;
  2691. srcChars += startPos;
  2692. int pos = 0;
  2693. for (int i = 0; i < numChars; ++i)
  2694. {
  2695. const char c = (char) srcChars[i];
  2696. for (int j = 0; j < 64; ++j)
  2697. {
  2698. if (encodingTable[j] == c)
  2699. {
  2700. setBitRange (pos, 6, j);
  2701. pos += 6;
  2702. break;
  2703. }
  2704. }
  2705. }
  2706. return true;
  2707. }
  2708. END_JUCE_NAMESPACE
  2709. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2710. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2711. BEGIN_JUCE_NAMESPACE
  2712. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2713. : properties (ignoreCaseOfKeyNames),
  2714. fallbackProperties (0),
  2715. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2716. {
  2717. }
  2718. PropertySet::PropertySet (const PropertySet& other) throw()
  2719. : properties (other.properties),
  2720. fallbackProperties (other.fallbackProperties),
  2721. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2722. {
  2723. }
  2724. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2725. {
  2726. properties = other.properties;
  2727. fallbackProperties = other.fallbackProperties;
  2728. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2729. propertyChanged();
  2730. return *this;
  2731. }
  2732. PropertySet::~PropertySet()
  2733. {
  2734. }
  2735. void PropertySet::clear()
  2736. {
  2737. const ScopedLock sl (lock);
  2738. if (properties.size() > 0)
  2739. {
  2740. properties.clear();
  2741. propertyChanged();
  2742. }
  2743. }
  2744. const String PropertySet::getValue (const String& keyName,
  2745. const String& defaultValue) const throw()
  2746. {
  2747. const ScopedLock sl (lock);
  2748. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2749. if (index >= 0)
  2750. return properties.getAllValues() [index];
  2751. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2752. : defaultValue;
  2753. }
  2754. int PropertySet::getIntValue (const String& keyName,
  2755. const int defaultValue) const throw()
  2756. {
  2757. const ScopedLock sl (lock);
  2758. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2759. if (index >= 0)
  2760. return properties.getAllValues() [index].getIntValue();
  2761. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2762. : defaultValue;
  2763. }
  2764. double PropertySet::getDoubleValue (const String& keyName,
  2765. const double defaultValue) const throw()
  2766. {
  2767. const ScopedLock sl (lock);
  2768. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2769. if (index >= 0)
  2770. return properties.getAllValues()[index].getDoubleValue();
  2771. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2772. : defaultValue;
  2773. }
  2774. bool PropertySet::getBoolValue (const String& keyName,
  2775. const bool defaultValue) const throw()
  2776. {
  2777. const ScopedLock sl (lock);
  2778. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2779. if (index >= 0)
  2780. return properties.getAllValues() [index].getIntValue() != 0;
  2781. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2782. : defaultValue;
  2783. }
  2784. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2785. {
  2786. XmlDocument doc (getValue (keyName));
  2787. return doc.getDocumentElement();
  2788. }
  2789. void PropertySet::setValue (const String& keyName,
  2790. const String& value) throw()
  2791. {
  2792. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2793. if (keyName.isNotEmpty())
  2794. {
  2795. const ScopedLock sl (lock);
  2796. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2797. if (index < 0 || properties.getAllValues() [index] != value)
  2798. {
  2799. properties.set (keyName, value);
  2800. propertyChanged();
  2801. }
  2802. }
  2803. }
  2804. void PropertySet::removeValue (const String& keyName) throw()
  2805. {
  2806. if (keyName.isNotEmpty())
  2807. {
  2808. const ScopedLock sl (lock);
  2809. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2810. if (index >= 0)
  2811. {
  2812. properties.remove (keyName);
  2813. propertyChanged();
  2814. }
  2815. }
  2816. }
  2817. void PropertySet::setValue (const String& keyName, const int value) throw()
  2818. {
  2819. setValue (keyName, String (value));
  2820. }
  2821. void PropertySet::setValue (const String& keyName, const double value) throw()
  2822. {
  2823. setValue (keyName, String (value));
  2824. }
  2825. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2826. {
  2827. setValue (keyName, String (value ? "1" : "0"));
  2828. }
  2829. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2830. {
  2831. setValue (keyName, (xml == 0) ? String::empty
  2832. : xml->createDocument (String::empty, true));
  2833. }
  2834. bool PropertySet::containsKey (const String& keyName) const throw()
  2835. {
  2836. const ScopedLock sl (lock);
  2837. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2838. }
  2839. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2840. {
  2841. const ScopedLock sl (lock);
  2842. fallbackProperties = fallbackProperties_;
  2843. }
  2844. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2845. {
  2846. const ScopedLock sl (lock);
  2847. XmlElement* const xml = new XmlElement (nodeName);
  2848. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2849. {
  2850. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2851. e->setAttribute ("name", properties.getAllKeys()[i]);
  2852. e->setAttribute ("val", properties.getAllValues()[i]);
  2853. }
  2854. return xml;
  2855. }
  2856. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2857. {
  2858. const ScopedLock sl (lock);
  2859. clear();
  2860. forEachXmlChildElementWithTagName (xml, e, "VALUE")
  2861. {
  2862. if (e->hasAttribute ("name")
  2863. && e->hasAttribute ("val"))
  2864. {
  2865. properties.set (e->getStringAttribute ("name"),
  2866. e->getStringAttribute ("val"));
  2867. }
  2868. }
  2869. if (properties.size() > 0)
  2870. propertyChanged();
  2871. }
  2872. void PropertySet::propertyChanged()
  2873. {
  2874. }
  2875. END_JUCE_NAMESPACE
  2876. /*** End of inlined file: juce_PropertySet.cpp ***/
  2877. /*** Start of inlined file: juce_Variant.cpp ***/
  2878. BEGIN_JUCE_NAMESPACE
  2879. var::var() throw()
  2880. : type (voidType)
  2881. {
  2882. value.doubleValue = 0;
  2883. }
  2884. var::~var() throw()
  2885. {
  2886. if (type == stringType)
  2887. delete value.stringValue;
  2888. else if (type == objectType && value.objectValue != 0)
  2889. value.objectValue->decReferenceCount();
  2890. }
  2891. const var var::null;
  2892. var::var (const var& valueToCopy)
  2893. : type (valueToCopy.type),
  2894. value (valueToCopy.value)
  2895. {
  2896. if (type == stringType)
  2897. value.stringValue = new String (*(value.stringValue));
  2898. else if (type == objectType && value.objectValue != 0)
  2899. value.objectValue->incReferenceCount();
  2900. }
  2901. var::var (const int value_) throw()
  2902. : type (intType)
  2903. {
  2904. value.intValue = value_;
  2905. }
  2906. var::var (const bool value_) throw()
  2907. : type (boolType)
  2908. {
  2909. value.boolValue = value_;
  2910. }
  2911. var::var (const double value_) throw()
  2912. : type (doubleType)
  2913. {
  2914. value.doubleValue = value_;
  2915. }
  2916. var::var (const String& value_)
  2917. : type (stringType)
  2918. {
  2919. value.stringValue = new String (value_);
  2920. }
  2921. var::var (const char* const value_)
  2922. : type (stringType)
  2923. {
  2924. value.stringValue = new String (value_);
  2925. }
  2926. var::var (const juce_wchar* const value_)
  2927. : type (stringType)
  2928. {
  2929. value.stringValue = new String (value_);
  2930. }
  2931. var::var (DynamicObject* const object)
  2932. : type (objectType)
  2933. {
  2934. value.objectValue = object;
  2935. if (object != 0)
  2936. object->incReferenceCount();
  2937. }
  2938. var::var (MethodFunction method_) throw()
  2939. : type (methodType)
  2940. {
  2941. value.methodValue = method_;
  2942. }
  2943. void var::swapWith (var& other) throw()
  2944. {
  2945. swapVariables (type, other.type);
  2946. swapVariables (value, other.value);
  2947. }
  2948. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2949. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2950. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2951. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2952. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2953. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2954. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2955. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2956. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2957. var::operator int() const
  2958. {
  2959. switch (type)
  2960. {
  2961. case voidType: break;
  2962. case intType: return value.intValue;
  2963. case boolType: return value.boolValue ? 1 : 0;
  2964. case doubleType: return static_cast <int> (value.doubleValue);
  2965. case stringType: return value.stringValue->getIntValue();
  2966. case objectType: break;
  2967. default: jassertfalse; break;
  2968. }
  2969. return 0;
  2970. }
  2971. var::operator bool() const
  2972. {
  2973. switch (type)
  2974. {
  2975. case voidType: break;
  2976. case intType: return value.intValue != 0;
  2977. case boolType: return value.boolValue;
  2978. case doubleType: return value.doubleValue != 0;
  2979. case stringType: return value.stringValue->getIntValue() != 0
  2980. || value.stringValue->trim().equalsIgnoreCase ("true")
  2981. || value.stringValue->trim().equalsIgnoreCase ("yes");
  2982. case objectType: return value.objectValue != 0;
  2983. default: jassertfalse; break;
  2984. }
  2985. return false;
  2986. }
  2987. var::operator float() const
  2988. {
  2989. return (float) operator double();
  2990. }
  2991. var::operator double() const
  2992. {
  2993. switch (type)
  2994. {
  2995. case voidType: break;
  2996. case intType: return value.intValue;
  2997. case boolType: return value.boolValue ? 1.0 : 0.0;
  2998. case doubleType: return value.doubleValue;
  2999. case stringType: return value.stringValue->getDoubleValue();
  3000. case objectType: break;
  3001. default: jassertfalse; break;
  3002. }
  3003. return 0.0;
  3004. }
  3005. const String var::toString() const
  3006. {
  3007. switch (type)
  3008. {
  3009. case voidType: return String::empty;
  3010. case intType: return String (value.intValue);
  3011. case boolType: return String::charToString (value.boolValue ? '1' : '0');
  3012. case doubleType: return String (value.doubleValue);
  3013. case stringType: return *(value.stringValue);
  3014. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  3015. case methodType: return "Method";
  3016. default: jassertfalse; break;
  3017. }
  3018. return String::empty;
  3019. }
  3020. var::operator const String() const
  3021. {
  3022. return toString();
  3023. }
  3024. DynamicObject* var::getObject() const
  3025. {
  3026. return type == objectType ? value.objectValue : 0;
  3027. }
  3028. bool var::equals (const var& other) const throw()
  3029. {
  3030. switch (type)
  3031. {
  3032. case voidType: return other.isVoid();
  3033. case intType: return value.intValue == static_cast <int> (other);
  3034. case boolType: return value.boolValue == static_cast <bool> (other);
  3035. case doubleType: return value.doubleValue == static_cast <double> (other);
  3036. case stringType: return (*(value.stringValue)) == other.toString();
  3037. case objectType: return value.objectValue == other.getObject();
  3038. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  3039. default: jassertfalse; break;
  3040. }
  3041. return false;
  3042. }
  3043. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  3044. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  3045. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  3046. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3047. void var::writeToStream (OutputStream& output) const
  3048. {
  3049. switch (type)
  3050. {
  3051. case voidType: output.writeCompressedInt (0); break;
  3052. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3053. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3054. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3055. case stringType:
  3056. {
  3057. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3058. output.writeCompressedInt (len + 1);
  3059. output.writeByte (5);
  3060. HeapBlock<char> temp (len);
  3061. value.stringValue->copyToUTF8 (temp, len);
  3062. output.write (temp, len);
  3063. break;
  3064. }
  3065. case objectType:
  3066. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3067. default: jassertfalse; break; // Is this a corrupted object?
  3068. }
  3069. }
  3070. const var var::readFromStream (InputStream& input)
  3071. {
  3072. const int numBytes = input.readCompressedInt();
  3073. if (numBytes > 0)
  3074. {
  3075. switch (input.readByte())
  3076. {
  3077. case 1: return var (input.readInt());
  3078. case 2: return var (true);
  3079. case 3: return var (false);
  3080. case 4: return var (input.readDouble());
  3081. case 5:
  3082. {
  3083. MemoryBlock mb;
  3084. input.readIntoMemoryBlock (mb, numBytes - 1);
  3085. return var (String::fromUTF8 (static_cast <const char*> (mb.getData()), (int) mb.getSize()));
  3086. }
  3087. default: input.skipNextBytes (numBytes - 1); break;
  3088. }
  3089. }
  3090. return var::null;
  3091. }
  3092. const var var::operator[] (const var::identifier& propertyName) const
  3093. {
  3094. if (type == objectType && value.objectValue != 0)
  3095. return value.objectValue->getProperty (propertyName);
  3096. return var::null;
  3097. }
  3098. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3099. {
  3100. if (type == objectType && value.objectValue != 0)
  3101. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3102. return var::null;
  3103. }
  3104. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3105. {
  3106. if (isMethod())
  3107. {
  3108. DynamicObject* const target = targetObject.getObject();
  3109. if (target != 0)
  3110. return (target->*(value.methodValue)) (arguments, numArguments);
  3111. }
  3112. return var::null;
  3113. }
  3114. const var var::call (const var::identifier& method) const
  3115. {
  3116. return invoke (method, 0, 0);
  3117. }
  3118. const var var::call (const var::identifier& method, const var& arg1) const
  3119. {
  3120. return invoke (method, &arg1, 1);
  3121. }
  3122. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3123. {
  3124. var args[] = { arg1, arg2 };
  3125. return invoke (method, args, 2);
  3126. }
  3127. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3128. {
  3129. var args[] = { arg1, arg2, arg3 };
  3130. return invoke (method, args, 3);
  3131. }
  3132. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3133. {
  3134. var args[] = { arg1, arg2, arg3, arg4 };
  3135. return invoke (method, args, 4);
  3136. }
  3137. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3138. {
  3139. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3140. return invoke (method, args, 5);
  3141. }
  3142. var::identifier::identifier() throw()
  3143. : hashCode (0)
  3144. {
  3145. }
  3146. var::identifier::identifier (const String& name_)
  3147. : name (name_),
  3148. hashCode (name_.hashCode())
  3149. {
  3150. /* An identifier string must be suitable for use as a script variable or XML
  3151. attribute, so it can only contain this limited set of characters.. */
  3152. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3153. }
  3154. var::identifier::identifier (const char* const name_)
  3155. : name (name_),
  3156. hashCode (name.hashCode())
  3157. {
  3158. /* An identifier string must be suitable for use as a script variable or XML
  3159. attribute, so it can only contain this limited set of characters.. */
  3160. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3161. }
  3162. var::identifier::~identifier()
  3163. {
  3164. }
  3165. END_JUCE_NAMESPACE
  3166. /*** End of inlined file: juce_Variant.cpp ***/
  3167. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3168. BEGIN_JUCE_NAMESPACE
  3169. NamedValueSet::NamedValue::NamedValue() throw()
  3170. {
  3171. }
  3172. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3173. : name (name_), value (value_)
  3174. {
  3175. }
  3176. NamedValueSet::NamedValueSet() throw()
  3177. {
  3178. }
  3179. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3180. : values (other.values)
  3181. {
  3182. }
  3183. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3184. {
  3185. values = other.values;
  3186. return *this;
  3187. }
  3188. NamedValueSet::~NamedValueSet()
  3189. {
  3190. }
  3191. int NamedValueSet::size() const throw()
  3192. {
  3193. return values.size();
  3194. }
  3195. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3196. {
  3197. for (int i = values.size(); --i >= 0;)
  3198. {
  3199. const NamedValue& v = values.getReference(i);
  3200. if (v.name == name)
  3201. return v.value;
  3202. }
  3203. return var::null;
  3204. }
  3205. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3206. {
  3207. const var* v = getItem (name);
  3208. return v != 0 ? *v : defaultReturnValue;
  3209. }
  3210. var* NamedValueSet::getItem (const var::identifier& name) const
  3211. {
  3212. for (int i = values.size(); --i >= 0;)
  3213. {
  3214. NamedValue& v = values.getReference(i);
  3215. if (v.name == name)
  3216. return &(v.value);
  3217. }
  3218. return 0;
  3219. }
  3220. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3221. {
  3222. for (int i = values.size(); --i >= 0;)
  3223. {
  3224. NamedValue& v = values.getReference(i);
  3225. if (v.name == name)
  3226. {
  3227. if (v.value == newValue)
  3228. return false;
  3229. v.value = newValue;
  3230. return true;
  3231. }
  3232. }
  3233. values.add (NamedValue (name, newValue));
  3234. return true;
  3235. }
  3236. bool NamedValueSet::contains (const var::identifier& name) const
  3237. {
  3238. return getItem (name) != 0;
  3239. }
  3240. bool NamedValueSet::remove (const var::identifier& name)
  3241. {
  3242. for (int i = values.size(); --i >= 0;)
  3243. {
  3244. if (values.getReference(i).name == name)
  3245. {
  3246. values.remove (i);
  3247. return true;
  3248. }
  3249. }
  3250. return false;
  3251. }
  3252. const var::identifier NamedValueSet::getName (int index) const
  3253. {
  3254. jassert (((unsigned int) index) < (unsigned int) values.size());
  3255. return values [index].name;
  3256. }
  3257. void NamedValueSet::clear()
  3258. {
  3259. values.clear();
  3260. }
  3261. END_JUCE_NAMESPACE
  3262. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3263. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3264. BEGIN_JUCE_NAMESPACE
  3265. DynamicObject::DynamicObject()
  3266. {
  3267. }
  3268. DynamicObject::~DynamicObject()
  3269. {
  3270. }
  3271. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3272. {
  3273. var* const v = properties.getItem (propertyName);
  3274. return v != 0 && ! v->isMethod();
  3275. }
  3276. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3277. {
  3278. return properties [propertyName];
  3279. }
  3280. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3281. {
  3282. properties.set (propertyName, newValue);
  3283. }
  3284. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3285. {
  3286. properties.remove (propertyName);
  3287. }
  3288. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3289. {
  3290. return getProperty (methodName).isMethod();
  3291. }
  3292. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3293. const var* parameters,
  3294. int numParameters)
  3295. {
  3296. return properties [methodName].invoke (var (this), parameters, numParameters);
  3297. }
  3298. void DynamicObject::setMethod (const var::identifier& name,
  3299. var::MethodFunction methodFunction)
  3300. {
  3301. properties.set (name, var (methodFunction));
  3302. }
  3303. void DynamicObject::clear()
  3304. {
  3305. properties.clear();
  3306. }
  3307. END_JUCE_NAMESPACE
  3308. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3309. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3310. BEGIN_JUCE_NAMESPACE
  3311. BlowFish::BlowFish (const void* const keyData, const int keyBytes)
  3312. {
  3313. jassert (keyData != 0);
  3314. jassert (keyBytes > 0);
  3315. static const uint32 initialPValues [18] =
  3316. {
  3317. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3318. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3319. 0x9216d5d9, 0x8979fb1b
  3320. };
  3321. static const uint32 initialSValues [4 * 256] =
  3322. {
  3323. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3324. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3325. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3326. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3327. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3328. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3329. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3330. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3331. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3332. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3333. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3334. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3335. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3336. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3337. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3338. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3339. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3340. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3341. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3342. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3343. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3344. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3345. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3346. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3347. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3348. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3349. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3350. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3351. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3352. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3353. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3354. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3355. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3356. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3357. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3358. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3359. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3360. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3361. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3362. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3363. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3364. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3365. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3366. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3367. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3368. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3369. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3370. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3371. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3372. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3373. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3374. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3375. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3376. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3377. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3378. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3379. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3380. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3381. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3382. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3383. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3384. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3385. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3386. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3387. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3388. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3389. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3390. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3391. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3392. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3393. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3394. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3395. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3396. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3397. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3398. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3399. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3400. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3401. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3402. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3403. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3404. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3405. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3406. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3407. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3408. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3409. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3410. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3411. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3412. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3413. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3414. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3415. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3416. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3417. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3418. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3419. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3420. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3421. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3422. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3423. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3424. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3425. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3426. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3427. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3428. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3429. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3430. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3431. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3432. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3433. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3434. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3435. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3436. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3437. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3438. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3439. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3440. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3441. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3442. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3443. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3444. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3445. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3446. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3447. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3448. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3449. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3450. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3451. };
  3452. memcpy (p, initialPValues, sizeof (p));
  3453. int i, j = 0;
  3454. for (i = 4; --i >= 0;)
  3455. {
  3456. s[i].malloc (256);
  3457. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3458. }
  3459. for (i = 0; i < 18; ++i)
  3460. {
  3461. uint32 d = 0;
  3462. for (int k = 0; k < 4; ++k)
  3463. {
  3464. d = (d << 8) | static_cast <const uint8*> (keyData)[j];
  3465. if (++j >= keyBytes)
  3466. j = 0;
  3467. }
  3468. p[i] = initialPValues[i] ^ d;
  3469. }
  3470. uint32 l = 0, r = 0;
  3471. for (i = 0; i < 18; i += 2)
  3472. {
  3473. encrypt (l, r);
  3474. p[i] = l;
  3475. p[i + 1] = r;
  3476. }
  3477. for (i = 0; i < 4; ++i)
  3478. {
  3479. for (j = 0; j < 256; j += 2)
  3480. {
  3481. encrypt (l, r);
  3482. s[i][j] = l;
  3483. s[i][j + 1] = r;
  3484. }
  3485. }
  3486. }
  3487. BlowFish::BlowFish (const BlowFish& other)
  3488. {
  3489. for (int i = 4; --i >= 0;)
  3490. s[i].malloc (256);
  3491. operator= (other);
  3492. }
  3493. BlowFish& BlowFish::operator= (const BlowFish& other)
  3494. {
  3495. memcpy (p, other.p, sizeof (p));
  3496. for (int i = 4; --i >= 0;)
  3497. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3498. return *this;
  3499. }
  3500. BlowFish::~BlowFish()
  3501. {
  3502. }
  3503. uint32 BlowFish::F (const uint32 x) const throw()
  3504. {
  3505. return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff])
  3506. ^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff];
  3507. }
  3508. void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
  3509. {
  3510. uint32 l = data1;
  3511. uint32 r = data2;
  3512. for (int i = 0; i < 16; ++i)
  3513. {
  3514. l ^= p[i];
  3515. r ^= F(l);
  3516. swapVariables (l, r);
  3517. }
  3518. data1 = r ^ p[17];
  3519. data2 = l ^ p[16];
  3520. }
  3521. void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
  3522. {
  3523. uint32 l = data1;
  3524. uint32 r = data2;
  3525. for (int i = 17; i > 1; --i)
  3526. {
  3527. l ^= p[i];
  3528. r ^= F(l);
  3529. swapVariables (l, r);
  3530. }
  3531. data1 = r ^ p[0];
  3532. data2 = l ^ p[1];
  3533. }
  3534. END_JUCE_NAMESPACE
  3535. /*** End of inlined file: juce_BlowFish.cpp ***/
  3536. /*** Start of inlined file: juce_MD5.cpp ***/
  3537. BEGIN_JUCE_NAMESPACE
  3538. MD5::MD5()
  3539. {
  3540. zerostruct (result);
  3541. }
  3542. MD5::MD5 (const MD5& other)
  3543. {
  3544. memcpy (result, other.result, sizeof (result));
  3545. }
  3546. MD5& MD5::operator= (const MD5& other)
  3547. {
  3548. memcpy (result, other.result, sizeof (result));
  3549. return *this;
  3550. }
  3551. MD5::MD5 (const MemoryBlock& data)
  3552. {
  3553. ProcessContext context;
  3554. context.processBlock (data.getData(), data.getSize());
  3555. context.finish (result);
  3556. }
  3557. MD5::MD5 (const void* data, const size_t numBytes)
  3558. {
  3559. ProcessContext context;
  3560. context.processBlock (data, numBytes);
  3561. context.finish (result);
  3562. }
  3563. MD5::MD5 (const String& text)
  3564. {
  3565. ProcessContext context;
  3566. const int len = text.length();
  3567. const juce_wchar* const t = text;
  3568. for (int i = 0; i < len; ++i)
  3569. {
  3570. // force the string into integer-sized unicode characters, to try to make it
  3571. // get the same results on all platforms + compilers.
  3572. uint32 unicodeChar = ByteOrder::swapIfBigEndian ((uint32) t[i]);
  3573. context.processBlock (&unicodeChar, sizeof (unicodeChar));
  3574. }
  3575. context.finish (result);
  3576. }
  3577. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3578. {
  3579. ProcessContext context;
  3580. if (numBytesToRead < 0)
  3581. numBytesToRead = std::numeric_limits<int64>::max();
  3582. while (numBytesToRead > 0)
  3583. {
  3584. uint8 tempBuffer [512];
  3585. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3586. if (bytesRead <= 0)
  3587. break;
  3588. numBytesToRead -= bytesRead;
  3589. context.processBlock (tempBuffer, bytesRead);
  3590. }
  3591. context.finish (result);
  3592. }
  3593. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3594. {
  3595. processStream (input, numBytesToRead);
  3596. }
  3597. MD5::MD5 (const File& file)
  3598. {
  3599. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3600. if (fin != 0)
  3601. processStream (*fin, -1);
  3602. else
  3603. zerostruct (result);
  3604. }
  3605. MD5::~MD5()
  3606. {
  3607. }
  3608. namespace MD5Functions
  3609. {
  3610. static void encode (void* const output, const void* const input, const int numBytes) throw()
  3611. {
  3612. for (int i = 0; i < (numBytes >> 2); ++i)
  3613. static_cast<uint32*> (output)[i] = ByteOrder::swapIfBigEndian (static_cast<const uint32*> (input) [i]);
  3614. }
  3615. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3616. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3617. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3618. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3619. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3620. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3621. {
  3622. a += F (b, c, d) + x + ac;
  3623. a = rotateLeft (a, s) + b;
  3624. }
  3625. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3626. {
  3627. a += G (b, c, d) + x + ac;
  3628. a = rotateLeft (a, s) + b;
  3629. }
  3630. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3631. {
  3632. a += H (b, c, d) + x + ac;
  3633. a = rotateLeft (a, s) + b;
  3634. }
  3635. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3636. {
  3637. a += I (b, c, d) + x + ac;
  3638. a = rotateLeft (a, s) + b;
  3639. }
  3640. }
  3641. MD5::ProcessContext::ProcessContext()
  3642. {
  3643. state[0] = 0x67452301;
  3644. state[1] = 0xefcdab89;
  3645. state[2] = 0x98badcfe;
  3646. state[3] = 0x10325476;
  3647. count[0] = 0;
  3648. count[1] = 0;
  3649. }
  3650. void MD5::ProcessContext::processBlock (const void* const data, const size_t dataSize)
  3651. {
  3652. int bufferPos = ((count[0] >> 3) & 0x3F);
  3653. count[0] += (uint32) (dataSize << 3);
  3654. if (count[0] < ((uint32) dataSize << 3))
  3655. count[1]++;
  3656. count[1] += (uint32) (dataSize >> 29);
  3657. const size_t spaceLeft = 64 - bufferPos;
  3658. size_t i = 0;
  3659. if (dataSize >= spaceLeft)
  3660. {
  3661. memcpy (buffer + bufferPos, data, spaceLeft);
  3662. transform (buffer);
  3663. for (i = spaceLeft; i + 64 <= dataSize; i += 64)
  3664. transform (static_cast <const char*> (data) + i);
  3665. bufferPos = 0;
  3666. }
  3667. memcpy (buffer + bufferPos, static_cast <const char*> (data) + i, dataSize - i);
  3668. }
  3669. void MD5::ProcessContext::finish (void* const result)
  3670. {
  3671. unsigned char encodedLength[8];
  3672. MD5Functions::encode (encodedLength, count, 8);
  3673. // Pad out to 56 mod 64.
  3674. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3675. const int paddingLength = (index < 56) ? (56 - index)
  3676. : (120 - index);
  3677. uint8 paddingBuffer [64];
  3678. zeromem (paddingBuffer, paddingLength);
  3679. paddingBuffer [0] = 0x80;
  3680. processBlock (paddingBuffer, paddingLength);
  3681. processBlock (encodedLength, 8);
  3682. MD5Functions::encode (result, state, 16);
  3683. zerostruct (buffer);
  3684. }
  3685. void MD5::ProcessContext::transform (const void* const bufferToTransform)
  3686. {
  3687. using namespace MD5Functions;
  3688. uint32 a = state[0];
  3689. uint32 b = state[1];
  3690. uint32 c = state[2];
  3691. uint32 d = state[3];
  3692. uint32 x[16];
  3693. encode (x, bufferToTransform, 64);
  3694. enum Constants
  3695. {
  3696. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3697. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3698. };
  3699. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); FF (d, a, b, c, x[ 1], S12, 0xe8c7b756);
  3700. FF (c, d, a, b, x[ 2], S13, 0x242070db); FF (b, c, d, a, x[ 3], S14, 0xc1bdceee);
  3701. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); FF (d, a, b, c, x[ 5], S12, 0x4787c62a);
  3702. FF (c, d, a, b, x[ 6], S13, 0xa8304613); FF (b, c, d, a, x[ 7], S14, 0xfd469501);
  3703. FF (a, b, c, d, x[ 8], S11, 0x698098d8); FF (d, a, b, c, x[ 9], S12, 0x8b44f7af);
  3704. FF (c, d, a, b, x[10], S13, 0xffff5bb1); FF (b, c, d, a, x[11], S14, 0x895cd7be);
  3705. FF (a, b, c, d, x[12], S11, 0x6b901122); FF (d, a, b, c, x[13], S12, 0xfd987193);
  3706. FF (c, d, a, b, x[14], S13, 0xa679438e); FF (b, c, d, a, x[15], S14, 0x49b40821);
  3707. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); GG (d, a, b, c, x[ 6], S22, 0xc040b340);
  3708. GG (c, d, a, b, x[11], S23, 0x265e5a51); GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa);
  3709. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); GG (d, a, b, c, x[10], S22, 0x02441453);
  3710. GG (c, d, a, b, x[15], S23, 0xd8a1e681); GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8);
  3711. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); GG (d, a, b, c, x[14], S22, 0xc33707d6);
  3712. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); GG (b, c, d, a, x[ 8], S24, 0x455a14ed);
  3713. GG (a, b, c, d, x[13], S21, 0xa9e3e905); GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8);
  3714. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); GG (b, c, d, a, x[12], S24, 0x8d2a4c8a);
  3715. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); HH (d, a, b, c, x[ 8], S32, 0x8771f681);
  3716. HH (c, d, a, b, x[11], S33, 0x6d9d6122); HH (b, c, d, a, x[14], S34, 0xfde5380c);
  3717. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9);
  3718. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); HH (b, c, d, a, x[10], S34, 0xbebfbc70);
  3719. HH (a, b, c, d, x[13], S31, 0x289b7ec6); HH (d, a, b, c, x[ 0], S32, 0xeaa127fa);
  3720. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); HH (b, c, d, a, x[ 6], S34, 0x04881d05);
  3721. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); HH (d, a, b, c, x[12], S32, 0xe6db99e5);
  3722. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); HH (b, c, d, a, x[ 2], S34, 0xc4ac5665);
  3723. II (a, b, c, d, x[ 0], S41, 0xf4292244); II (d, a, b, c, x[ 7], S42, 0x432aff97);
  3724. II (c, d, a, b, x[14], S43, 0xab9423a7); II (b, c, d, a, x[ 5], S44, 0xfc93a039);
  3725. II (a, b, c, d, x[12], S41, 0x655b59c3); II (d, a, b, c, x[ 3], S42, 0x8f0ccc92);
  3726. II (c, d, a, b, x[10], S43, 0xffeff47d); II (b, c, d, a, x[ 1], S44, 0x85845dd1);
  3727. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); II (d, a, b, c, x[15], S42, 0xfe2ce6e0);
  3728. II (c, d, a, b, x[ 6], S43, 0xa3014314); II (b, c, d, a, x[13], S44, 0x4e0811a1);
  3729. II (a, b, c, d, x[ 4], S41, 0xf7537e82); II (d, a, b, c, x[11], S42, 0xbd3af235);
  3730. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); II (b, c, d, a, x[ 9], S44, 0xeb86d391);
  3731. state[0] += a;
  3732. state[1] += b;
  3733. state[2] += c;
  3734. state[3] += d;
  3735. zerostruct (x);
  3736. }
  3737. const MemoryBlock MD5::getRawChecksumData() const
  3738. {
  3739. return MemoryBlock (result, sizeof (result));
  3740. }
  3741. const String MD5::toHexString() const
  3742. {
  3743. return String::toHexString (result, sizeof (result), 0);
  3744. }
  3745. bool MD5::operator== (const MD5& other) const
  3746. {
  3747. return memcmp (result, other.result, sizeof (result)) == 0;
  3748. }
  3749. bool MD5::operator!= (const MD5& other) const
  3750. {
  3751. return ! operator== (other);
  3752. }
  3753. END_JUCE_NAMESPACE
  3754. /*** End of inlined file: juce_MD5.cpp ***/
  3755. /*** Start of inlined file: juce_Primes.cpp ***/
  3756. BEGIN_JUCE_NAMESPACE
  3757. namespace PrimesHelpers
  3758. {
  3759. static void createSmallSieve (const int numBits, BigInteger& result)
  3760. {
  3761. result.setBit (numBits);
  3762. result.clearBit (numBits); // to enlarge the array
  3763. result.setBit (0);
  3764. int n = 2;
  3765. do
  3766. {
  3767. for (int i = n + n; i < numBits; i += n)
  3768. result.setBit (i);
  3769. n = result.findNextClearBit (n + 1);
  3770. }
  3771. while (n <= (numBits >> 1));
  3772. }
  3773. static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
  3774. const BigInteger& smallSieve, const int smallSieveSize)
  3775. {
  3776. jassert (! base[0]); // must be even!
  3777. result.setBit (numBits);
  3778. result.clearBit (numBits); // to enlarge the array
  3779. int index = smallSieve.findNextClearBit (0);
  3780. do
  3781. {
  3782. const int prime = (index << 1) + 1;
  3783. BigInteger r (base), remainder;
  3784. r.divideBy (prime, remainder);
  3785. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3786. if (r.isZero())
  3787. i += prime;
  3788. if ((i & 1) == 0)
  3789. i += prime;
  3790. i = (i - 1) >> 1;
  3791. while (i < numBits)
  3792. {
  3793. result.setBit (i);
  3794. i += prime;
  3795. }
  3796. index = smallSieve.findNextClearBit (index + 1);
  3797. }
  3798. while (index < smallSieveSize);
  3799. }
  3800. static bool findCandidate (const BigInteger& base, const BigInteger& sieve,
  3801. const int numBits, BigInteger& result, const int certainty)
  3802. {
  3803. for (int i = 0; i < numBits; ++i)
  3804. {
  3805. if (! sieve[i])
  3806. {
  3807. result = base + (unsigned int) ((i << 1) + 1);
  3808. if (Primes::isProbablyPrime (result, certainty))
  3809. return true;
  3810. }
  3811. }
  3812. return false;
  3813. }
  3814. static bool passesMillerRabin (const BigInteger& n, int iterations)
  3815. {
  3816. const BigInteger one (1), two (2);
  3817. const BigInteger nMinusOne (n - one);
  3818. BigInteger d (nMinusOne);
  3819. const int s = d.findNextSetBit (0);
  3820. d >>= s;
  3821. BigInteger smallPrimes;
  3822. int numBitsInSmallPrimes = 0;
  3823. for (;;)
  3824. {
  3825. numBitsInSmallPrimes += 256;
  3826. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3827. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3828. if (numPrimesFound > iterations + 1)
  3829. break;
  3830. }
  3831. int smallPrime = 2;
  3832. while (--iterations >= 0)
  3833. {
  3834. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3835. BigInteger r (smallPrime);
  3836. r.exponentModulo (d, n);
  3837. if (r != one && r != nMinusOne)
  3838. {
  3839. for (int j = 0; j < s; ++j)
  3840. {
  3841. r.exponentModulo (two, n);
  3842. if (r == nMinusOne)
  3843. break;
  3844. }
  3845. if (r != nMinusOne)
  3846. return false;
  3847. }
  3848. }
  3849. return true;
  3850. }
  3851. }
  3852. const BigInteger Primes::createProbablePrime (const int bitLength,
  3853. const int certainty,
  3854. const int* randomSeeds,
  3855. int numRandomSeeds)
  3856. {
  3857. using namespace PrimesHelpers;
  3858. int defaultSeeds [16];
  3859. if (numRandomSeeds <= 0)
  3860. {
  3861. randomSeeds = defaultSeeds;
  3862. numRandomSeeds = numElementsInArray (defaultSeeds);
  3863. Random r (0);
  3864. for (int j = 10; --j >= 0;)
  3865. {
  3866. r.setSeedRandomly();
  3867. for (int i = numRandomSeeds; --i >= 0;)
  3868. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3869. }
  3870. }
  3871. BigInteger smallSieve;
  3872. const int smallSieveSize = 15000;
  3873. createSmallSieve (smallSieveSize, smallSieve);
  3874. BigInteger p;
  3875. for (int i = numRandomSeeds; --i >= 0;)
  3876. {
  3877. BigInteger p2;
  3878. Random r (randomSeeds[i]);
  3879. r.fillBitsRandomly (p2, 0, bitLength);
  3880. p ^= p2;
  3881. }
  3882. p.setBit (bitLength - 1);
  3883. p.clearBit (0);
  3884. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3885. while (p.getHighestBit() < bitLength)
  3886. {
  3887. p += 2 * searchLen;
  3888. BigInteger sieve;
  3889. bigSieve (p, searchLen, sieve,
  3890. smallSieve, smallSieveSize);
  3891. BigInteger candidate;
  3892. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3893. return candidate;
  3894. }
  3895. jassertfalse
  3896. return BigInteger();
  3897. }
  3898. bool Primes::isProbablyPrime (const BigInteger& number, const int certainty)
  3899. {
  3900. using namespace PrimesHelpers;
  3901. if (! number[0])
  3902. return false;
  3903. if (number.getHighestBit() <= 10)
  3904. {
  3905. const int num = number.getBitRangeAsInt (0, 10);
  3906. for (int i = num / 2; --i > 1;)
  3907. if (num % i == 0)
  3908. return false;
  3909. return true;
  3910. }
  3911. else
  3912. {
  3913. if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1)
  3914. return false;
  3915. return passesMillerRabin (number, certainty);
  3916. }
  3917. }
  3918. END_JUCE_NAMESPACE
  3919. /*** End of inlined file: juce_Primes.cpp ***/
  3920. /*** Start of inlined file: juce_RSAKey.cpp ***/
  3921. BEGIN_JUCE_NAMESPACE
  3922. RSAKey::RSAKey()
  3923. {
  3924. }
  3925. RSAKey::RSAKey (const String& s)
  3926. {
  3927. if (s.containsChar (','))
  3928. {
  3929. part1.parseString (s.upToFirstOccurrenceOf (",", false, false), 16);
  3930. part2.parseString (s.fromFirstOccurrenceOf (",", false, false), 16);
  3931. }
  3932. else
  3933. {
  3934. // the string needs to be two hex numbers, comma-separated..
  3935. jassertfalse;
  3936. }
  3937. }
  3938. RSAKey::~RSAKey()
  3939. {
  3940. }
  3941. const String RSAKey::toString() const
  3942. {
  3943. return part1.toString (16) + "," + part2.toString (16);
  3944. }
  3945. bool RSAKey::applyToValue (BigInteger& value) const
  3946. {
  3947. if (part1.isZero() || part2.isZero() || value <= 0)
  3948. {
  3949. jassertfalse // using an uninitialised key
  3950. value.clear();
  3951. return false;
  3952. }
  3953. BigInteger result;
  3954. while (! value.isZero())
  3955. {
  3956. result *= part2;
  3957. BigInteger remainder;
  3958. value.divideBy (part2, remainder);
  3959. remainder.exponentModulo (part1, part2);
  3960. result += remainder;
  3961. }
  3962. value.swapWith (result);
  3963. return true;
  3964. }
  3965. static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q)
  3966. {
  3967. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3968. // are fast to divide + multiply
  3969. for (int i = 2; i <= 65536; i *= 2)
  3970. {
  3971. const BigInteger e (1 + i);
  3972. if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())
  3973. return e;
  3974. }
  3975. BigInteger e (4);
  3976. while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()))
  3977. ++e;
  3978. return e;
  3979. }
  3980. void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey,
  3981. const int numBits, const int* randomSeeds, const int numRandomSeeds)
  3982. {
  3983. jassert (numBits > 16); // not much point using less than this..
  3984. BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  3985. BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  3986. const BigInteger n (p * q);
  3987. const BigInteger m (--p * --q);
  3988. const BigInteger e (findBestCommonDivisor (p, q));
  3989. BigInteger d (e);
  3990. d.inverseModulo (m);
  3991. publicKey.part1 = e;
  3992. publicKey.part2 = n;
  3993. privateKey.part1 = d;
  3994. privateKey.part2 = n;
  3995. }
  3996. END_JUCE_NAMESPACE
  3997. /*** End of inlined file: juce_RSAKey.cpp ***/
  3998. /*** Start of inlined file: juce_InputStream.cpp ***/
  3999. BEGIN_JUCE_NAMESPACE
  4000. char InputStream::readByte()
  4001. {
  4002. char temp = 0;
  4003. read (&temp, 1);
  4004. return temp;
  4005. }
  4006. bool InputStream::readBool()
  4007. {
  4008. return readByte() != 0;
  4009. }
  4010. short InputStream::readShort()
  4011. {
  4012. char temp[2];
  4013. if (read (temp, 2) == 2)
  4014. return (short) ByteOrder::littleEndianShort (temp);
  4015. return 0;
  4016. }
  4017. short InputStream::readShortBigEndian()
  4018. {
  4019. char temp[2];
  4020. if (read (temp, 2) == 2)
  4021. return (short) ByteOrder::bigEndianShort (temp);
  4022. return 0;
  4023. }
  4024. int InputStream::readInt()
  4025. {
  4026. char temp[4];
  4027. if (read (temp, 4) == 4)
  4028. return (int) ByteOrder::littleEndianInt (temp);
  4029. return 0;
  4030. }
  4031. int InputStream::readIntBigEndian()
  4032. {
  4033. char temp[4];
  4034. if (read (temp, 4) == 4)
  4035. return (int) ByteOrder::bigEndianInt (temp);
  4036. return 0;
  4037. }
  4038. int InputStream::readCompressedInt()
  4039. {
  4040. const unsigned char sizeByte = readByte();
  4041. if (sizeByte == 0)
  4042. return 0;
  4043. const int numBytes = (sizeByte & 0x7f);
  4044. if (numBytes > 4)
  4045. {
  4046. jassertfalse // trying to read corrupt data - this method must only be used
  4047. // to read data that was written by OutputStream::writeCompressedInt()
  4048. return 0;
  4049. }
  4050. char bytes[4] = { 0, 0, 0, 0 };
  4051. if (read (bytes, numBytes) != numBytes)
  4052. return 0;
  4053. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4054. return (sizeByte >> 7) ? -num : num;
  4055. }
  4056. int64 InputStream::readInt64()
  4057. {
  4058. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4059. if (read (n.asBytes, 8) == 8)
  4060. return (int64) ByteOrder::swapIfBigEndian (n.asInt64);
  4061. return 0;
  4062. }
  4063. int64 InputStream::readInt64BigEndian()
  4064. {
  4065. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4066. if (read (n.asBytes, 8) == 8)
  4067. return (int64) ByteOrder::swapIfLittleEndian (n.asInt64);
  4068. return 0;
  4069. }
  4070. float InputStream::readFloat()
  4071. {
  4072. // the union below relies on these types being the same size...
  4073. static_jassert (sizeof (int32) == sizeof (float));
  4074. union { int32 asInt; float asFloat; } n;
  4075. n.asInt = (int32) readInt();
  4076. return n.asFloat;
  4077. }
  4078. float InputStream::readFloatBigEndian()
  4079. {
  4080. union { int32 asInt; float asFloat; } n;
  4081. n.asInt = (int32) readIntBigEndian();
  4082. return n.asFloat;
  4083. }
  4084. double InputStream::readDouble()
  4085. {
  4086. union { int64 asInt; double asDouble; } n;
  4087. n.asInt = readInt64();
  4088. return n.asDouble;
  4089. }
  4090. double InputStream::readDoubleBigEndian()
  4091. {
  4092. union { int64 asInt; double asDouble; } n;
  4093. n.asInt = readInt64BigEndian();
  4094. return n.asDouble;
  4095. }
  4096. const String InputStream::readString()
  4097. {
  4098. MemoryBlock buffer (256);
  4099. char* data = static_cast<char*> (buffer.getData());
  4100. size_t i = 0;
  4101. while ((data[i] = readByte()) != 0)
  4102. {
  4103. if (++i >= buffer.getSize())
  4104. {
  4105. buffer.setSize (buffer.getSize() + 512);
  4106. data = static_cast<char*> (buffer.getData());
  4107. }
  4108. }
  4109. return String::fromUTF8 (data, (int) i);
  4110. }
  4111. const String InputStream::readNextLine()
  4112. {
  4113. MemoryBlock buffer (256);
  4114. char* data = static_cast<char*> (buffer.getData());
  4115. size_t i = 0;
  4116. while ((data[i] = readByte()) != 0)
  4117. {
  4118. if (data[i] == '\n')
  4119. break;
  4120. if (data[i] == '\r')
  4121. {
  4122. const int64 lastPos = getPosition();
  4123. if (readByte() != '\n')
  4124. setPosition (lastPos);
  4125. break;
  4126. }
  4127. if (++i >= buffer.getSize())
  4128. {
  4129. buffer.setSize (buffer.getSize() + 512);
  4130. data = static_cast<char*> (buffer.getData());
  4131. }
  4132. }
  4133. return String::fromUTF8 (data, (int) i);
  4134. }
  4135. int InputStream::readIntoMemoryBlock (MemoryBlock& block, int numBytes)
  4136. {
  4137. const int64 totalLength = getTotalLength();
  4138. if (totalLength >= 0)
  4139. {
  4140. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4141. totalLength - getPosition());
  4142. if (numBytes < 0)
  4143. numBytes = totalBytesRemaining;
  4144. else if (numBytes > 0)
  4145. numBytes = jmin (numBytes, totalBytesRemaining);
  4146. else
  4147. return 0;
  4148. }
  4149. const size_t originalBlockSize = block.getSize();
  4150. int totalBytesRead = 0;
  4151. if (numBytes > 0)
  4152. {
  4153. // know how many bytes we want, so we can resize the block first..
  4154. block.setSize (originalBlockSize + numBytes, false);
  4155. totalBytesRead = read (static_cast<char*> (block.getData()) + originalBlockSize, numBytes);
  4156. }
  4157. else
  4158. {
  4159. // read until end of stram..
  4160. const int chunkSize = 32768;
  4161. for (;;)
  4162. {
  4163. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4164. const int bytesJustIn = read (static_cast<char*> (block.getData())
  4165. + originalBlockSize
  4166. + totalBytesRead,
  4167. chunkSize);
  4168. if (bytesJustIn == 0)
  4169. break;
  4170. totalBytesRead += bytesJustIn;
  4171. }
  4172. }
  4173. // trim off any excess left at the end
  4174. block.setSize (originalBlockSize + totalBytesRead, false);
  4175. return totalBytesRead;
  4176. }
  4177. const String InputStream::readEntireStreamAsString()
  4178. {
  4179. MemoryBlock mb;
  4180. const int size = readIntoMemoryBlock (mb);
  4181. return String::createStringFromData (static_cast<const char*> (mb.getData()), size);
  4182. }
  4183. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4184. {
  4185. if (numBytesToSkip > 0)
  4186. {
  4187. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4188. HeapBlock<char> temp (skipBufferSize);
  4189. while (numBytesToSkip > 0 && ! isExhausted())
  4190. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4191. }
  4192. }
  4193. END_JUCE_NAMESPACE
  4194. /*** End of inlined file: juce_InputStream.cpp ***/
  4195. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4196. BEGIN_JUCE_NAMESPACE
  4197. #if JUCE_DEBUG
  4198. static CriticalSection activeStreamLock;
  4199. static VoidArray activeStreams;
  4200. void juce_CheckForDanglingStreams()
  4201. {
  4202. /*
  4203. It's always a bad idea to leak any object, but if you're leaking output
  4204. streams, then there's a good chance that you're failing to flush a file
  4205. to disk properly, which could result in corrupted data and other similar
  4206. nastiness..
  4207. */
  4208. jassert (activeStreams.size() == 0);
  4209. };
  4210. #endif
  4211. OutputStream::OutputStream()
  4212. {
  4213. #if JUCE_DEBUG
  4214. const ScopedLock sl (activeStreamLock);
  4215. activeStreams.add (this);
  4216. #endif
  4217. }
  4218. OutputStream::~OutputStream()
  4219. {
  4220. #if JUCE_DEBUG
  4221. const ScopedLock sl (activeStreamLock);
  4222. activeStreams.removeValue (this);
  4223. #endif
  4224. }
  4225. void OutputStream::writeBool (const bool b)
  4226. {
  4227. writeByte (b ? (char) 1
  4228. : (char) 0);
  4229. }
  4230. void OutputStream::writeByte (char byte)
  4231. {
  4232. write (&byte, 1);
  4233. }
  4234. void OutputStream::writeShort (short value)
  4235. {
  4236. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4237. write (&v, 2);
  4238. }
  4239. void OutputStream::writeShortBigEndian (short value)
  4240. {
  4241. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4242. write (&v, 2);
  4243. }
  4244. void OutputStream::writeInt (int value)
  4245. {
  4246. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4247. write (&v, 4);
  4248. }
  4249. void OutputStream::writeIntBigEndian (int value)
  4250. {
  4251. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4252. write (&v, 4);
  4253. }
  4254. void OutputStream::writeCompressedInt (int value)
  4255. {
  4256. unsigned int un = (value < 0) ? (unsigned int) -value
  4257. : (unsigned int) value;
  4258. uint8 data[5];
  4259. int num = 0;
  4260. while (un > 0)
  4261. {
  4262. data[++num] = (uint8) un;
  4263. un >>= 8;
  4264. }
  4265. data[0] = (uint8) num;
  4266. if (value < 0)
  4267. data[0] |= 0x80;
  4268. write (data, num + 1);
  4269. }
  4270. void OutputStream::writeInt64 (int64 value)
  4271. {
  4272. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4273. write (&v, 8);
  4274. }
  4275. void OutputStream::writeInt64BigEndian (int64 value)
  4276. {
  4277. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4278. write (&v, 8);
  4279. }
  4280. void OutputStream::writeFloat (float value)
  4281. {
  4282. union { int asInt; float asFloat; } n;
  4283. n.asFloat = value;
  4284. writeInt (n.asInt);
  4285. }
  4286. void OutputStream::writeFloatBigEndian (float value)
  4287. {
  4288. union { int asInt; float asFloat; } n;
  4289. n.asFloat = value;
  4290. writeIntBigEndian (n.asInt);
  4291. }
  4292. void OutputStream::writeDouble (double value)
  4293. {
  4294. union { int64 asInt; double asDouble; } n;
  4295. n.asDouble = value;
  4296. writeInt64 (n.asInt);
  4297. }
  4298. void OutputStream::writeDoubleBigEndian (double value)
  4299. {
  4300. union { int64 asInt; double asDouble; } n;
  4301. n.asDouble = value;
  4302. writeInt64BigEndian (n.asInt);
  4303. }
  4304. void OutputStream::writeString (const String& text)
  4305. {
  4306. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4307. // if lots of large, persistent strings were to be written to streams).
  4308. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4309. HeapBlock<char> temp (numBytes);
  4310. text.copyToUTF8 (temp, numBytes);
  4311. write (temp, numBytes);
  4312. }
  4313. void OutputStream::writeText (const String& text, const bool asUnicode,
  4314. const bool writeUnicodeHeaderBytes)
  4315. {
  4316. if (asUnicode)
  4317. {
  4318. if (writeUnicodeHeaderBytes)
  4319. write ("\x0ff\x0fe", 2);
  4320. const juce_wchar* src = text;
  4321. bool lastCharWasReturn = false;
  4322. while (*src != 0)
  4323. {
  4324. if (*src == L'\n' && ! lastCharWasReturn)
  4325. writeShort ((short) L'\r');
  4326. lastCharWasReturn = (*src == L'\r');
  4327. writeShort ((short) *src++);
  4328. }
  4329. }
  4330. else
  4331. {
  4332. const char* src = text.toUTF8();
  4333. const char* t = src;
  4334. for (;;)
  4335. {
  4336. if (*t == '\n')
  4337. {
  4338. if (t > src)
  4339. write (src, (int) (t - src));
  4340. write ("\r\n", 2);
  4341. src = t + 1;
  4342. }
  4343. else if (*t == '\r')
  4344. {
  4345. if (t[1] == '\n')
  4346. ++t;
  4347. }
  4348. else if (*t == 0)
  4349. {
  4350. if (t > src)
  4351. write (src, (int) (t - src));
  4352. break;
  4353. }
  4354. ++t;
  4355. }
  4356. }
  4357. }
  4358. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4359. {
  4360. if (numBytesToWrite < 0)
  4361. numBytesToWrite = 0x7fffffff;
  4362. int numWritten = 0;
  4363. while (numBytesToWrite > 0 && ! source.isExhausted())
  4364. {
  4365. char buffer [8192];
  4366. const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4367. if (num == 0)
  4368. break;
  4369. write (buffer, num);
  4370. numBytesToWrite -= num;
  4371. numWritten += num;
  4372. }
  4373. return numWritten;
  4374. }
  4375. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4376. {
  4377. return stream << String (number);
  4378. }
  4379. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4380. {
  4381. return stream << String (number);
  4382. }
  4383. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4384. {
  4385. stream.writeByte (character);
  4386. return stream;
  4387. }
  4388. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4389. {
  4390. stream.write (text, (int) strlen (text));
  4391. return stream;
  4392. }
  4393. END_JUCE_NAMESPACE
  4394. /*** End of inlined file: juce_OutputStream.cpp ***/
  4395. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4396. BEGIN_JUCE_NAMESPACE
  4397. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4398. bool* isDirectory, bool* isHidden, int64* fileSize,
  4399. Time* modTime, Time* creationTime, bool* isReadOnly);
  4400. bool juce_findFileNext (void* handle, String& resultFile,
  4401. bool* isDirectory, bool* isHidden, int64* fileSize,
  4402. Time* modTime, Time* creationTime, bool* isReadOnly);
  4403. void juce_findFileClose (void* handle);
  4404. DirectoryIterator::DirectoryIterator (const File& directory,
  4405. bool isRecursive,
  4406. const String& wc,
  4407. const int whatToLookFor_)
  4408. : wildCard (wc),
  4409. index (-1),
  4410. whatToLookFor (whatToLookFor_)
  4411. {
  4412. // you have to specify the type of files you're looking for!
  4413. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4414. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4415. String path (directory.getFullPathName());
  4416. if (! path.endsWithChar (File::separator))
  4417. path += File::separator;
  4418. String filename;
  4419. bool isDirectory, isHidden;
  4420. void* const handle = juce_findFileStart (path,
  4421. isRecursive ? "*" : wc,
  4422. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4423. if (handle != 0)
  4424. {
  4425. do
  4426. {
  4427. if (! filename.containsOnly ("."))
  4428. {
  4429. bool addToList = false;
  4430. if (isDirectory)
  4431. {
  4432. if (isRecursive
  4433. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4434. || ! isHidden))
  4435. {
  4436. dirsFound.add (File (path + filename, 0));
  4437. }
  4438. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4439. }
  4440. else
  4441. {
  4442. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4443. }
  4444. // if it's recursive, we're not relying on the OS iterator
  4445. // to do the wildcard match, so do it now..
  4446. if (isRecursive && addToList)
  4447. addToList = filename.matchesWildcard (wc, true);
  4448. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4449. addToList = ! isHidden;
  4450. if (addToList)
  4451. filesFound.add (File (path + filename, 0));
  4452. }
  4453. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4454. juce_findFileClose (handle);
  4455. }
  4456. }
  4457. DirectoryIterator::~DirectoryIterator()
  4458. {
  4459. }
  4460. bool DirectoryIterator::next()
  4461. {
  4462. if (subIterator != 0)
  4463. {
  4464. if (subIterator->next())
  4465. return true;
  4466. subIterator = 0;
  4467. }
  4468. if (index >= filesFound.size() + dirsFound.size() - 1)
  4469. return false;
  4470. ++index;
  4471. if (index >= filesFound.size())
  4472. {
  4473. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4474. true, wildCard, whatToLookFor);
  4475. return next();
  4476. }
  4477. return true;
  4478. }
  4479. const File DirectoryIterator::getFile() const
  4480. {
  4481. if (subIterator != 0)
  4482. return subIterator->getFile();
  4483. return filesFound [index];
  4484. }
  4485. float DirectoryIterator::getEstimatedProgress() const
  4486. {
  4487. if (filesFound.size() + dirsFound.size() == 0)
  4488. {
  4489. return 0.0f;
  4490. }
  4491. else
  4492. {
  4493. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4494. : (float) index;
  4495. return detailedIndex / (filesFound.size() + dirsFound.size());
  4496. }
  4497. }
  4498. END_JUCE_NAMESPACE
  4499. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4500. /*** Start of inlined file: juce_File.cpp ***/
  4501. #ifdef _MSC_VER
  4502. #pragma warning (disable: 4514)
  4503. #pragma warning (push)
  4504. #endif
  4505. #if ! JUCE_WINDOWS
  4506. #include <pwd.h>
  4507. #endif
  4508. BEGIN_JUCE_NAMESPACE
  4509. #ifdef _MSC_VER
  4510. #pragma warning (pop)
  4511. #endif
  4512. void* juce_fileOpen (const String& path, bool forWriting);
  4513. void juce_fileClose (void* handle);
  4514. int juce_fileWrite (void* handle, const void* buffer, int size);
  4515. int64 juce_fileGetPosition (void* handle);
  4516. int64 juce_fileSetPosition (void* handle, int64 pos);
  4517. void juce_fileFlush (void* handle);
  4518. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4519. bool juce_isDirectory (const String& fileName);
  4520. int64 juce_getFileSize (const String& fileName);
  4521. bool juce_canWriteToFile (const String& fileName);
  4522. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4523. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4524. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4525. bool juce_deleteFile (const String& fileName);
  4526. bool juce_copyFile (const String& source, const String& dest);
  4527. bool juce_moveFile (const String& source, const String& dest);
  4528. // this must also create all paths involved in the directory.
  4529. void juce_createDirectory (const String& fileName);
  4530. bool juce_launchFile (const String& fileName, const String& parameters);
  4531. const StringArray juce_getFileSystemRoots();
  4532. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4533. // starts a directory search operation with a wildcard, returning a handle for
  4534. // use in calls to juce_findFileNext.
  4535. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4536. // the other pointers, if non-null, are set based on the properties of the file.
  4537. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4538. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4539. Time* creationTime, bool* isReadOnly);
  4540. // returns false when no more files are found
  4541. bool juce_findFileNext (void* handle, String& resultFile,
  4542. bool* isDirectory, bool* isHidden, int64* fileSize,
  4543. Time* modTime, Time* creationTime, bool* isReadOnly);
  4544. void juce_findFileClose (void* handle);
  4545. static const String juce_addTrailingSeparator (const String& path)
  4546. {
  4547. return path.endsWithChar (File::separator) ? path
  4548. : path + File::separator;
  4549. }
  4550. static const String parseAbsolutePath (String path)
  4551. {
  4552. if (path.isEmpty())
  4553. return String::empty;
  4554. #if JUCE_WINDOWS
  4555. // Windows..
  4556. path = path.replaceCharacter ('/', '\\');
  4557. if (path.startsWithChar (File::separator))
  4558. {
  4559. if (path[1] != File::separator)
  4560. {
  4561. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4562. If you're trying to parse a string that may be either a relative path or an absolute path,
  4563. you MUST provide a context against which the partial path can be evaluated - you can do
  4564. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4565. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4566. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4567. */
  4568. jassertfalse
  4569. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4570. }
  4571. }
  4572. else if (path.indexOfChar (':') < 0)
  4573. {
  4574. if (path.isEmpty())
  4575. return String::empty;
  4576. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4577. If you're trying to parse a string that may be either a relative path or an absolute path,
  4578. you MUST provide a context against which the partial path can be evaluated - you can do
  4579. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4580. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4581. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4582. */
  4583. jassertfalse
  4584. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4585. }
  4586. #else
  4587. // Mac or Linux..
  4588. path = path.replaceCharacter ('\\', '/');
  4589. if (path.startsWithChar ('~'))
  4590. {
  4591. const char* homeDir = 0;
  4592. if (path[1] == File::separator || path[1] == 0)
  4593. {
  4594. // expand a name of the form "~/abc"
  4595. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4596. + path.substring (1);
  4597. }
  4598. else
  4599. {
  4600. // expand a name of type "~dave/abc"
  4601. const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false));
  4602. struct passwd* const pw = getpwnam (userName.toUTF8());
  4603. if (pw != 0)
  4604. {
  4605. String home (homeDir);
  4606. if (home.endsWithChar (File::separator))
  4607. home [home.length() - 1] = 0;
  4608. path = String (pw->pw_dir)
  4609. + path.substring (userName.length());
  4610. }
  4611. }
  4612. }
  4613. else if (! path.startsWithChar (File::separator))
  4614. {
  4615. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4616. If you're trying to parse a string that may be either a relative path or an absolute path,
  4617. you MUST provide a context against which the partial path can be evaluated - you can do
  4618. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4619. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4620. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4621. */
  4622. jassert (path.startsWith ("./") || path.startsWith ("../")); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4623. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4624. }
  4625. #endif
  4626. int len = path.length();
  4627. while (--len > 0 && path [len] == File::separator)
  4628. path [len] = 0;
  4629. return path;
  4630. }
  4631. const File File::nonexistent;
  4632. File::File (const String& fullPathName)
  4633. : fullPath (parseAbsolutePath (fullPathName))
  4634. {
  4635. }
  4636. File::File (const String& path, int)
  4637. : fullPath (path)
  4638. {
  4639. }
  4640. const File File::createFileWithoutCheckingPath (const String& path)
  4641. {
  4642. return File (path, 0);
  4643. }
  4644. File::File (const File& other)
  4645. : fullPath (other.fullPath)
  4646. {
  4647. }
  4648. File& File::operator= (const String& newPath)
  4649. {
  4650. fullPath = parseAbsolutePath (newPath);
  4651. return *this;
  4652. }
  4653. File& File::operator= (const File& other)
  4654. {
  4655. fullPath = other.fullPath;
  4656. return *this;
  4657. }
  4658. #if JUCE_LINUX
  4659. #define NAMES_ARE_CASE_SENSITIVE 1
  4660. #endif
  4661. bool File::areFileNamesCaseSensitive()
  4662. {
  4663. #if NAMES_ARE_CASE_SENSITIVE
  4664. return true;
  4665. #else
  4666. return false;
  4667. #endif
  4668. }
  4669. bool File::operator== (const File& other) const
  4670. {
  4671. // case-insensitive on Windows, but not on linux.
  4672. #if NAMES_ARE_CASE_SENSITIVE
  4673. return fullPath == other.fullPath;
  4674. #else
  4675. return fullPath.equalsIgnoreCase (other.fullPath);
  4676. #endif
  4677. }
  4678. bool File::operator!= (const File& other) const
  4679. {
  4680. return ! operator== (other);
  4681. }
  4682. bool File::exists() const
  4683. {
  4684. return juce_fileExists (fullPath, false);
  4685. }
  4686. bool File::existsAsFile() const
  4687. {
  4688. return juce_fileExists (fullPath, true);
  4689. }
  4690. bool File::isDirectory() const
  4691. {
  4692. return juce_isDirectory (fullPath);
  4693. }
  4694. bool File::hasWriteAccess() const
  4695. {
  4696. if (exists())
  4697. return juce_canWriteToFile (fullPath);
  4698. #if ! JUCE_WINDOWS
  4699. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4700. return getParentDirectory().hasWriteAccess();
  4701. else
  4702. return false;
  4703. #else
  4704. // on windows, it seems that even read-only directories can still be written into,
  4705. // so checking the parent directory's permissions would return the wrong result..
  4706. else
  4707. return true;
  4708. #endif
  4709. }
  4710. bool File::setReadOnly (const bool shouldBeReadOnly,
  4711. const bool applyRecursively) const
  4712. {
  4713. bool worked = true;
  4714. if (applyRecursively && isDirectory())
  4715. {
  4716. Array <File> subFiles;
  4717. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4718. for (int i = subFiles.size(); --i >= 0;)
  4719. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4720. }
  4721. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4722. }
  4723. bool File::deleteFile() const
  4724. {
  4725. return (! exists())
  4726. || juce_deleteFile (fullPath);
  4727. }
  4728. bool File::deleteRecursively() const
  4729. {
  4730. bool worked = true;
  4731. if (isDirectory())
  4732. {
  4733. Array<File> subFiles;
  4734. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4735. for (int i = subFiles.size(); --i >= 0;)
  4736. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4737. }
  4738. return deleteFile() && worked;
  4739. }
  4740. bool File::moveFileTo (const File& newFile) const
  4741. {
  4742. if (newFile.fullPath == fullPath)
  4743. return true;
  4744. #if ! NAMES_ARE_CASE_SENSITIVE
  4745. if (*this != newFile)
  4746. #endif
  4747. if (! newFile.deleteFile())
  4748. return false;
  4749. return juce_moveFile (fullPath, newFile.fullPath);
  4750. }
  4751. bool File::copyFileTo (const File& newFile) const
  4752. {
  4753. if (*this == newFile)
  4754. return true;
  4755. if (! newFile.deleteFile())
  4756. return false;
  4757. return juce_copyFile (fullPath, newFile.fullPath);
  4758. }
  4759. bool File::copyDirectoryTo (const File& newDirectory) const
  4760. {
  4761. if (isDirectory() && newDirectory.createDirectory())
  4762. {
  4763. Array<File> subFiles;
  4764. findChildFiles (subFiles, File::findFiles, false);
  4765. int i;
  4766. for (i = 0; i < subFiles.size(); ++i)
  4767. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4768. return false;
  4769. subFiles.clear();
  4770. findChildFiles (subFiles, File::findDirectories, false);
  4771. for (i = 0; i < subFiles.size(); ++i)
  4772. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4773. return false;
  4774. return true;
  4775. }
  4776. return false;
  4777. }
  4778. const String File::getPathUpToLastSlash() const
  4779. {
  4780. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4781. if (lastSlash > 0)
  4782. return fullPath.substring (0, lastSlash);
  4783. else if (lastSlash == 0)
  4784. return separatorString;
  4785. else
  4786. return fullPath;
  4787. }
  4788. const File File::getParentDirectory() const
  4789. {
  4790. return File (getPathUpToLastSlash());
  4791. }
  4792. const String File::getFileName() const
  4793. {
  4794. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4795. }
  4796. int File::hashCode() const
  4797. {
  4798. return fullPath.hashCode();
  4799. }
  4800. int64 File::hashCode64() const
  4801. {
  4802. return fullPath.hashCode64();
  4803. }
  4804. const String File::getFileNameWithoutExtension() const
  4805. {
  4806. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4807. const int lastDot = fullPath.lastIndexOfChar ('.');
  4808. if (lastDot > lastSlash)
  4809. return fullPath.substring (lastSlash, lastDot);
  4810. else
  4811. return fullPath.substring (lastSlash);
  4812. }
  4813. bool File::isAChildOf (const File& potentialParent) const
  4814. {
  4815. if (potentialParent == File::nonexistent)
  4816. return false;
  4817. const String ourPath (getPathUpToLastSlash());
  4818. #if NAMES_ARE_CASE_SENSITIVE
  4819. if (potentialParent.fullPath == ourPath)
  4820. #else
  4821. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4822. #endif
  4823. {
  4824. return true;
  4825. }
  4826. else if (potentialParent.fullPath.length() >= ourPath.length())
  4827. {
  4828. return false;
  4829. }
  4830. else
  4831. {
  4832. return getParentDirectory().isAChildOf (potentialParent);
  4833. }
  4834. }
  4835. bool File::isAbsolutePath (const String& path)
  4836. {
  4837. return path.startsWithChar ('/') || path.startsWithChar ('\\')
  4838. #if JUCE_WINDOWS
  4839. || (path.isNotEmpty() && path[1] == ':');
  4840. #else
  4841. || path.startsWithChar ('~');
  4842. #endif
  4843. }
  4844. const File File::getChildFile (String relativePath) const
  4845. {
  4846. if (isAbsolutePath (relativePath))
  4847. {
  4848. // the path is really absolute..
  4849. return File (relativePath);
  4850. }
  4851. else
  4852. {
  4853. // it's relative, so remove any ../ or ./ bits at the start.
  4854. String path (fullPath);
  4855. if (relativePath[0] == '.')
  4856. {
  4857. #if JUCE_WINDOWS
  4858. relativePath = relativePath.replaceCharacter ('/', '\\').trimStart();
  4859. #else
  4860. relativePath = relativePath.replaceCharacter ('\\', '/').trimStart();
  4861. #endif
  4862. while (relativePath[0] == '.')
  4863. {
  4864. if (relativePath[1] == '.')
  4865. {
  4866. if (relativePath [2] == 0 || relativePath[2] == separator)
  4867. {
  4868. const int lastSlash = path.lastIndexOfChar (separator);
  4869. if (lastSlash >= 0)
  4870. path = path.substring (0, lastSlash);
  4871. relativePath = relativePath.substring (3);
  4872. }
  4873. else
  4874. {
  4875. break;
  4876. }
  4877. }
  4878. else if (relativePath[1] == separator)
  4879. {
  4880. relativePath = relativePath.substring (2);
  4881. }
  4882. else
  4883. {
  4884. break;
  4885. }
  4886. }
  4887. }
  4888. return File (juce_addTrailingSeparator (path) + relativePath);
  4889. }
  4890. }
  4891. const File File::getSiblingFile (const String& fileName) const
  4892. {
  4893. return getParentDirectory().getChildFile (fileName);
  4894. }
  4895. int64 File::getSize() const
  4896. {
  4897. return juce_getFileSize (fullPath);
  4898. }
  4899. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4900. {
  4901. if (bytes == 1)
  4902. {
  4903. return "1 byte";
  4904. }
  4905. else if (bytes < 1024)
  4906. {
  4907. return String ((int) bytes) + " bytes";
  4908. }
  4909. else if (bytes < 1024 * 1024)
  4910. {
  4911. return String (bytes / 1024.0, 1) + " KB";
  4912. }
  4913. else if (bytes < 1024 * 1024 * 1024)
  4914. {
  4915. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4916. }
  4917. else
  4918. {
  4919. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4920. }
  4921. }
  4922. bool File::create() const
  4923. {
  4924. if (! exists())
  4925. {
  4926. const File parentDir (getParentDirectory());
  4927. if (parentDir == *this || ! parentDir.createDirectory())
  4928. return false;
  4929. void* const fh = juce_fileOpen (fullPath, true);
  4930. if (fh == 0)
  4931. return false;
  4932. juce_fileClose (fh);
  4933. }
  4934. return true;
  4935. }
  4936. bool File::createDirectory() const
  4937. {
  4938. if (! isDirectory())
  4939. {
  4940. const File parentDir (getParentDirectory());
  4941. if (parentDir == *this || ! parentDir.createDirectory())
  4942. return false;
  4943. String dir (fullPath);
  4944. while (dir.endsWithChar (separator))
  4945. dir [dir.length() - 1] = 0;
  4946. juce_createDirectory (dir);
  4947. return isDirectory();
  4948. }
  4949. return true;
  4950. }
  4951. const Time File::getCreationTime() const
  4952. {
  4953. int64 m, a, c;
  4954. juce_getFileTimes (fullPath, m, a, c);
  4955. return Time (c);
  4956. }
  4957. bool File::setCreationTime (const Time& t) const
  4958. {
  4959. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  4960. }
  4961. const Time File::getLastModificationTime() const
  4962. {
  4963. int64 m, a, c;
  4964. juce_getFileTimes (fullPath, m, a, c);
  4965. return Time (m);
  4966. }
  4967. bool File::setLastModificationTime (const Time& t) const
  4968. {
  4969. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  4970. }
  4971. const Time File::getLastAccessTime() const
  4972. {
  4973. int64 m, a, c;
  4974. juce_getFileTimes (fullPath, m, a, c);
  4975. return Time (a);
  4976. }
  4977. bool File::setLastAccessTime (const Time& t) const
  4978. {
  4979. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  4980. }
  4981. bool File::loadFileAsData (MemoryBlock& destBlock) const
  4982. {
  4983. if (! existsAsFile())
  4984. return false;
  4985. FileInputStream in (*this);
  4986. return getSize() == in.readIntoMemoryBlock (destBlock);
  4987. }
  4988. const String File::loadFileAsString() const
  4989. {
  4990. if (! existsAsFile())
  4991. return String::empty;
  4992. FileInputStream in (*this);
  4993. return in.readEntireStreamAsString();
  4994. }
  4995. static inline bool fileTypeMatches (const int whatToLookFor,
  4996. const bool isDir,
  4997. const bool isHidden)
  4998. {
  4999. return (whatToLookFor & (isDir ? File::findDirectories
  5000. : File::findFiles)) != 0
  5001. && ((! isHidden)
  5002. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5003. }
  5004. int File::findChildFiles (Array<File>& results,
  5005. const int whatToLookFor,
  5006. const bool searchRecursively,
  5007. const String& wildCardPattern) const
  5008. {
  5009. // you have to specify the type of files you're looking for!
  5010. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5011. int total = 0;
  5012. // find child files or directories in this directory first..
  5013. if (isDirectory())
  5014. {
  5015. const String path (juce_addTrailingSeparator (fullPath));
  5016. String filename;
  5017. bool itemIsDirectory, itemIsHidden;
  5018. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5019. &itemIsDirectory, &itemIsHidden,
  5020. 0, 0, 0, 0);
  5021. if (handle != 0)
  5022. {
  5023. do
  5024. {
  5025. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5026. && ! filename.containsOnly ("."))
  5027. {
  5028. results.add (File (path + filename, 0));
  5029. ++total;
  5030. }
  5031. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5032. juce_findFileClose (handle);
  5033. }
  5034. }
  5035. else
  5036. {
  5037. // trying to search for files inside a non-directory?
  5038. //jassertfalse
  5039. }
  5040. // and recurse down if required.
  5041. if (searchRecursively)
  5042. {
  5043. Array<File> subDirectories;
  5044. findChildFiles (subDirectories, File::findDirectories, false);
  5045. for (int i = 0; i < subDirectories.size(); ++i)
  5046. {
  5047. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5048. true, wildCardPattern);
  5049. }
  5050. }
  5051. return total;
  5052. }
  5053. int File::getNumberOfChildFiles (const int whatToLookFor,
  5054. const String& wildCardPattern) const
  5055. {
  5056. // you have to specify the type of files you're looking for!
  5057. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5058. int count = 0;
  5059. if (isDirectory())
  5060. {
  5061. String filename;
  5062. bool itemIsDirectory, itemIsHidden;
  5063. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5064. &itemIsDirectory, &itemIsHidden,
  5065. 0, 0, 0, 0);
  5066. if (handle != 0)
  5067. {
  5068. do
  5069. {
  5070. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5071. && ! filename.containsOnly ("."))
  5072. {
  5073. ++count;
  5074. }
  5075. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5076. juce_findFileClose (handle);
  5077. }
  5078. }
  5079. else
  5080. {
  5081. // trying to search for files inside a non-directory?
  5082. jassertfalse
  5083. }
  5084. return count;
  5085. }
  5086. bool File::containsSubDirectories() const
  5087. {
  5088. bool result = false;
  5089. if (isDirectory())
  5090. {
  5091. String filename;
  5092. bool itemIsDirectory, itemIsHidden;
  5093. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5094. "*", filename,
  5095. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5096. if (handle != 0)
  5097. {
  5098. do
  5099. {
  5100. if (itemIsDirectory)
  5101. {
  5102. result = true;
  5103. break;
  5104. }
  5105. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5106. juce_findFileClose (handle);
  5107. }
  5108. }
  5109. return result;
  5110. }
  5111. const File File::getNonexistentChildFile (const String& prefix_,
  5112. const String& suffix,
  5113. bool putNumbersInBrackets) const
  5114. {
  5115. File f (getChildFile (prefix_ + suffix));
  5116. if (f.exists())
  5117. {
  5118. int num = 2;
  5119. String prefix (prefix_);
  5120. // remove any bracketed numbers that may already be on the end..
  5121. if (prefix.trim().endsWithChar (')'))
  5122. {
  5123. putNumbersInBrackets = true;
  5124. const int openBracks = prefix.lastIndexOfChar ('(');
  5125. const int closeBracks = prefix.lastIndexOfChar (')');
  5126. if (openBracks > 0
  5127. && closeBracks > openBracks
  5128. && prefix.substring (openBracks + 1, closeBracks).containsOnly ("0123456789"))
  5129. {
  5130. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5131. prefix = prefix.substring (0, openBracks);
  5132. }
  5133. }
  5134. // also use brackets if it ends in a digit.
  5135. putNumbersInBrackets = putNumbersInBrackets
  5136. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5137. do
  5138. {
  5139. if (putNumbersInBrackets)
  5140. f = getChildFile (prefix + '(' + String (num++) + ')' + suffix);
  5141. else
  5142. f = getChildFile (prefix + String (num++) + suffix);
  5143. } while (f.exists());
  5144. }
  5145. return f;
  5146. }
  5147. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5148. {
  5149. if (exists())
  5150. {
  5151. return getParentDirectory()
  5152. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5153. getFileExtension(),
  5154. putNumbersInBrackets);
  5155. }
  5156. else
  5157. {
  5158. return *this;
  5159. }
  5160. }
  5161. const String File::getFileExtension() const
  5162. {
  5163. String ext;
  5164. if (! isDirectory())
  5165. {
  5166. const int indexOfDot = fullPath.lastIndexOfChar ('.');
  5167. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5168. ext = fullPath.substring (indexOfDot);
  5169. }
  5170. return ext;
  5171. }
  5172. bool File::hasFileExtension (const String& possibleSuffix) const
  5173. {
  5174. if (possibleSuffix.isEmpty())
  5175. return fullPath.lastIndexOfChar ('.') <= fullPath.lastIndexOfChar (separator);
  5176. const int semicolon = possibleSuffix.indexOfChar (0, ';');
  5177. if (semicolon >= 0)
  5178. {
  5179. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5180. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5181. }
  5182. else
  5183. {
  5184. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5185. {
  5186. if (possibleSuffix.startsWithChar ('.'))
  5187. return true;
  5188. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5189. if (dotPos >= 0)
  5190. return fullPath [dotPos] == '.';
  5191. }
  5192. }
  5193. return false;
  5194. }
  5195. const File File::withFileExtension (const String& newExtension) const
  5196. {
  5197. if (fullPath.isEmpty())
  5198. return File::nonexistent;
  5199. String filePart (getFileName());
  5200. int i = filePart.lastIndexOfChar ('.');
  5201. if (i >= 0)
  5202. filePart = filePart.substring (0, i);
  5203. if (newExtension.isNotEmpty() && ! newExtension.startsWithChar ('.'))
  5204. filePart << '.';
  5205. return getSiblingFile (filePart + newExtension);
  5206. }
  5207. bool File::startAsProcess (const String& parameters) const
  5208. {
  5209. return exists() && juce_launchFile (fullPath, parameters);
  5210. }
  5211. FileInputStream* File::createInputStream() const
  5212. {
  5213. if (existsAsFile())
  5214. return new FileInputStream (*this);
  5215. return 0;
  5216. }
  5217. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5218. {
  5219. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5220. if (out->failedToOpen())
  5221. return 0;
  5222. return out.release();
  5223. }
  5224. bool File::appendData (const void* const dataToAppend,
  5225. const int numberOfBytes) const
  5226. {
  5227. if (numberOfBytes > 0)
  5228. {
  5229. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5230. if (out == 0)
  5231. return false;
  5232. out->write (dataToAppend, numberOfBytes);
  5233. }
  5234. return true;
  5235. }
  5236. bool File::replaceWithData (const void* const dataToWrite,
  5237. const int numberOfBytes) const
  5238. {
  5239. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5240. if (numberOfBytes <= 0)
  5241. return deleteFile();
  5242. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5243. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5244. return tempFile.overwriteTargetFileWithTemporary();
  5245. }
  5246. bool File::appendText (const String& text,
  5247. const bool asUnicode,
  5248. const bool writeUnicodeHeaderBytes) const
  5249. {
  5250. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5251. if (out != 0)
  5252. {
  5253. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5254. return true;
  5255. }
  5256. return false;
  5257. }
  5258. bool File::replaceWithText (const String& textToWrite,
  5259. const bool asUnicode,
  5260. const bool writeUnicodeHeaderBytes) const
  5261. {
  5262. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5263. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5264. return tempFile.overwriteTargetFileWithTemporary();
  5265. }
  5266. const String File::createLegalPathName (const String& original)
  5267. {
  5268. String s (original);
  5269. String start;
  5270. if (s[1] == ':')
  5271. {
  5272. start = s.substring (0, 2);
  5273. s = s.substring (2);
  5274. }
  5275. return start + s.removeCharacters ("\"#@,;:<>*^|?")
  5276. .substring (0, 1024);
  5277. }
  5278. const String File::createLegalFileName (const String& original)
  5279. {
  5280. String s (original.removeCharacters ("\"#@,;:<>*^|?\\/"));
  5281. const int maxLength = 128; // only the length of the filename, not the whole path
  5282. const int len = s.length();
  5283. if (len > maxLength)
  5284. {
  5285. const int lastDot = s.lastIndexOfChar ('.');
  5286. if (lastDot > jmax (0, len - 12))
  5287. {
  5288. s = s.substring (0, maxLength - (len - lastDot))
  5289. + s.substring (lastDot);
  5290. }
  5291. else
  5292. {
  5293. s = s.substring (0, maxLength);
  5294. }
  5295. }
  5296. return s;
  5297. }
  5298. const String File::getRelativePathFrom (const File& dir) const
  5299. {
  5300. String thisPath (fullPath);
  5301. {
  5302. int len = thisPath.length();
  5303. while (--len >= 0 && thisPath [len] == File::separator)
  5304. thisPath [len] = 0;
  5305. }
  5306. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5307. : dir.fullPath));
  5308. const int len = jmin (thisPath.length(), dirPath.length());
  5309. int commonBitLength = 0;
  5310. for (int i = 0; i < len; ++i)
  5311. {
  5312. #if NAMES_ARE_CASE_SENSITIVE
  5313. if (thisPath[i] != dirPath[i])
  5314. #else
  5315. if (CharacterFunctions::toLowerCase (thisPath[i])
  5316. != CharacterFunctions::toLowerCase (dirPath[i]))
  5317. #endif
  5318. {
  5319. break;
  5320. }
  5321. ++commonBitLength;
  5322. }
  5323. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5324. --commonBitLength;
  5325. // if the only common bit is the root, then just return the full path..
  5326. if (commonBitLength <= 0
  5327. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5328. return fullPath;
  5329. thisPath = thisPath.substring (commonBitLength);
  5330. dirPath = dirPath.substring (commonBitLength);
  5331. while (dirPath.isNotEmpty())
  5332. {
  5333. #if JUCE_WINDOWS
  5334. thisPath = "..\\" + thisPath;
  5335. #else
  5336. thisPath = "../" + thisPath;
  5337. #endif
  5338. const int sep = dirPath.indexOfChar (separator);
  5339. if (sep >= 0)
  5340. dirPath = dirPath.substring (sep + 1);
  5341. else
  5342. dirPath = String::empty;
  5343. }
  5344. return thisPath;
  5345. }
  5346. void File::findFileSystemRoots (Array<File>& destArray)
  5347. {
  5348. const StringArray roots (juce_getFileSystemRoots());
  5349. for (int i = 0; i < roots.size(); ++i)
  5350. destArray.add (File (roots[i]));
  5351. }
  5352. const String File::getVolumeLabel() const
  5353. {
  5354. int serialNum;
  5355. return juce_getVolumeLabel (fullPath, serialNum);
  5356. }
  5357. int File::getVolumeSerialNumber() const
  5358. {
  5359. int serialNum;
  5360. juce_getVolumeLabel (fullPath, serialNum);
  5361. return serialNum;
  5362. }
  5363. const File File::createTempFile (const String& fileNameEnding)
  5364. {
  5365. const File tempFile (getSpecialLocation (tempDirectory)
  5366. .getChildFile ("temp_" + String (Random::getSystemRandom().nextInt()))
  5367. .withFileExtension (fileNameEnding));
  5368. if (tempFile.exists())
  5369. return createTempFile (fileNameEnding);
  5370. else
  5371. return tempFile;
  5372. }
  5373. END_JUCE_NAMESPACE
  5374. /*** End of inlined file: juce_File.cpp ***/
  5375. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5376. BEGIN_JUCE_NAMESPACE
  5377. void* juce_fileOpen (const String& path, bool forWriting);
  5378. void juce_fileClose (void* handle);
  5379. int juce_fileRead (void* handle, void* buffer, int size);
  5380. int64 juce_fileSetPosition (void* handle, int64 pos);
  5381. FileInputStream::FileInputStream (const File& f)
  5382. : file (f),
  5383. currentPosition (0),
  5384. needToSeek (true)
  5385. {
  5386. totalSize = f.getSize();
  5387. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5388. }
  5389. FileInputStream::~FileInputStream()
  5390. {
  5391. juce_fileClose (fileHandle);
  5392. }
  5393. int64 FileInputStream::getTotalLength()
  5394. {
  5395. return totalSize;
  5396. }
  5397. int FileInputStream::read (void* buffer, int bytesToRead)
  5398. {
  5399. int num = 0;
  5400. if (needToSeek)
  5401. {
  5402. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5403. return 0;
  5404. needToSeek = false;
  5405. }
  5406. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5407. currentPosition += num;
  5408. return num;
  5409. }
  5410. bool FileInputStream::isExhausted()
  5411. {
  5412. return currentPosition >= totalSize;
  5413. }
  5414. int64 FileInputStream::getPosition()
  5415. {
  5416. return currentPosition;
  5417. }
  5418. bool FileInputStream::setPosition (int64 pos)
  5419. {
  5420. pos = jlimit ((int64) 0, totalSize, pos);
  5421. needToSeek |= (currentPosition != pos);
  5422. currentPosition = pos;
  5423. return true;
  5424. }
  5425. END_JUCE_NAMESPACE
  5426. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5427. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5428. BEGIN_JUCE_NAMESPACE
  5429. void* juce_fileOpen (const String& path, bool forWriting);
  5430. void juce_fileClose (void* handle);
  5431. int juce_fileWrite (void* handle, const void* buffer, int size);
  5432. void juce_fileFlush (void* handle);
  5433. int64 juce_fileGetPosition (void* handle);
  5434. int64 juce_fileSetPosition (void* handle, int64 pos);
  5435. FileOutputStream::FileOutputStream (const File& f,
  5436. const int bufferSize_)
  5437. : file (f),
  5438. bufferSize (bufferSize_),
  5439. bytesInBuffer (0)
  5440. {
  5441. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5442. if (fileHandle != 0)
  5443. {
  5444. currentPosition = juce_fileGetPosition (fileHandle);
  5445. if (currentPosition < 0)
  5446. {
  5447. jassertfalse
  5448. juce_fileClose (fileHandle);
  5449. fileHandle = 0;
  5450. }
  5451. }
  5452. buffer.malloc (jmax (bufferSize_, 16));
  5453. }
  5454. FileOutputStream::~FileOutputStream()
  5455. {
  5456. flush();
  5457. juce_fileClose (fileHandle);
  5458. }
  5459. int64 FileOutputStream::getPosition()
  5460. {
  5461. return currentPosition;
  5462. }
  5463. bool FileOutputStream::setPosition (int64 newPosition)
  5464. {
  5465. if (newPosition != currentPosition)
  5466. {
  5467. flush();
  5468. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5469. }
  5470. return newPosition == currentPosition;
  5471. }
  5472. void FileOutputStream::flush()
  5473. {
  5474. if (bytesInBuffer > 0)
  5475. {
  5476. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5477. bytesInBuffer = 0;
  5478. }
  5479. juce_fileFlush (fileHandle);
  5480. }
  5481. bool FileOutputStream::write (const void* const src, const int numBytes)
  5482. {
  5483. if (bytesInBuffer + numBytes < bufferSize)
  5484. {
  5485. memcpy (buffer + bytesInBuffer, src, numBytes);
  5486. bytesInBuffer += numBytes;
  5487. currentPosition += numBytes;
  5488. }
  5489. else
  5490. {
  5491. if (bytesInBuffer > 0)
  5492. {
  5493. // flush the reservoir
  5494. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5495. bytesInBuffer = 0;
  5496. if (! wroteOk)
  5497. return false;
  5498. }
  5499. if (numBytes < bufferSize)
  5500. {
  5501. memcpy (buffer + bytesInBuffer, src, numBytes);
  5502. bytesInBuffer += numBytes;
  5503. currentPosition += numBytes;
  5504. }
  5505. else
  5506. {
  5507. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5508. currentPosition += bytesWritten;
  5509. return bytesWritten == numBytes;
  5510. }
  5511. }
  5512. return true;
  5513. }
  5514. END_JUCE_NAMESPACE
  5515. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5516. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5517. BEGIN_JUCE_NAMESPACE
  5518. FileSearchPath::FileSearchPath()
  5519. {
  5520. }
  5521. FileSearchPath::FileSearchPath (const String& path)
  5522. {
  5523. init (path);
  5524. }
  5525. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5526. : directories (other.directories)
  5527. {
  5528. }
  5529. FileSearchPath::~FileSearchPath()
  5530. {
  5531. }
  5532. FileSearchPath& FileSearchPath::operator= (const String& path)
  5533. {
  5534. init (path);
  5535. return *this;
  5536. }
  5537. void FileSearchPath::init (const String& path)
  5538. {
  5539. directories.clear();
  5540. directories.addTokens (path, ";", "\"");
  5541. directories.trim();
  5542. directories.removeEmptyStrings();
  5543. for (int i = directories.size(); --i >= 0;)
  5544. directories.set (i, directories[i].unquoted());
  5545. }
  5546. int FileSearchPath::getNumPaths() const
  5547. {
  5548. return directories.size();
  5549. }
  5550. const File FileSearchPath::operator[] (const int index) const
  5551. {
  5552. return File (directories [index]);
  5553. }
  5554. const String FileSearchPath::toString() const
  5555. {
  5556. StringArray directories2 (directories);
  5557. for (int i = directories2.size(); --i >= 0;)
  5558. if (directories2[i].containsChar (';'))
  5559. directories2.set (i, directories2[i].quoted());
  5560. return directories2.joinIntoString (";");
  5561. }
  5562. void FileSearchPath::add (const File& dir, const int insertIndex)
  5563. {
  5564. directories.insert (insertIndex, dir.getFullPathName());
  5565. }
  5566. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5567. {
  5568. for (int i = 0; i < directories.size(); ++i)
  5569. if (File (directories[i]) == dir)
  5570. return;
  5571. add (dir);
  5572. }
  5573. void FileSearchPath::remove (const int index)
  5574. {
  5575. directories.remove (index);
  5576. }
  5577. void FileSearchPath::addPath (const FileSearchPath& other)
  5578. {
  5579. for (int i = 0; i < other.getNumPaths(); ++i)
  5580. addIfNotAlreadyThere (other[i]);
  5581. }
  5582. void FileSearchPath::removeRedundantPaths()
  5583. {
  5584. for (int i = directories.size(); --i >= 0;)
  5585. {
  5586. const File d1 (directories[i]);
  5587. for (int j = directories.size(); --j >= 0;)
  5588. {
  5589. const File d2 (directories[j]);
  5590. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5591. {
  5592. directories.remove (i);
  5593. break;
  5594. }
  5595. }
  5596. }
  5597. }
  5598. void FileSearchPath::removeNonExistentPaths()
  5599. {
  5600. for (int i = directories.size(); --i >= 0;)
  5601. if (! File (directories[i]).isDirectory())
  5602. directories.remove (i);
  5603. }
  5604. int FileSearchPath::findChildFiles (Array<File>& results,
  5605. const int whatToLookFor,
  5606. const bool searchRecursively,
  5607. const String& wildCardPattern) const
  5608. {
  5609. int total = 0;
  5610. for (int i = 0; i < directories.size(); ++i)
  5611. total += operator[] (i).findChildFiles (results,
  5612. whatToLookFor,
  5613. searchRecursively,
  5614. wildCardPattern);
  5615. return total;
  5616. }
  5617. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5618. const bool checkRecursively) const
  5619. {
  5620. for (int i = directories.size(); --i >= 0;)
  5621. {
  5622. const File d (directories[i]);
  5623. if (checkRecursively)
  5624. {
  5625. if (fileToCheck.isAChildOf (d))
  5626. return true;
  5627. }
  5628. else
  5629. {
  5630. if (fileToCheck.getParentDirectory() == d)
  5631. return true;
  5632. }
  5633. }
  5634. return false;
  5635. }
  5636. END_JUCE_NAMESPACE
  5637. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5638. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5639. BEGIN_JUCE_NAMESPACE
  5640. NamedPipe::NamedPipe()
  5641. : internal (0)
  5642. {
  5643. }
  5644. NamedPipe::~NamedPipe()
  5645. {
  5646. close();
  5647. }
  5648. bool NamedPipe::openExisting (const String& pipeName)
  5649. {
  5650. currentPipeName = pipeName;
  5651. return openInternal (pipeName, false);
  5652. }
  5653. bool NamedPipe::createNewPipe (const String& pipeName)
  5654. {
  5655. currentPipeName = pipeName;
  5656. return openInternal (pipeName, true);
  5657. }
  5658. bool NamedPipe::isOpen() const
  5659. {
  5660. return internal != 0;
  5661. }
  5662. const String NamedPipe::getName() const
  5663. {
  5664. return currentPipeName;
  5665. }
  5666. // other methods for this class are implemented in the platform-specific files
  5667. END_JUCE_NAMESPACE
  5668. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5669. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5670. BEGIN_JUCE_NAMESPACE
  5671. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5672. {
  5673. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5674. "temp_" + String (Random::getSystemRandom().nextInt()),
  5675. suffix,
  5676. optionFlags);
  5677. }
  5678. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5679. : targetFile (targetFile_)
  5680. {
  5681. // If you use this constructor, you need to give it a valid target file!
  5682. jassert (targetFile != File::nonexistent);
  5683. createTempFile (targetFile.getParentDirectory(),
  5684. targetFile.getFileNameWithoutExtension() + "_temp" + String (Random::getSystemRandom().nextInt()),
  5685. targetFile.getFileExtension(),
  5686. optionFlags);
  5687. }
  5688. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5689. const String& suffix, const int optionFlags)
  5690. {
  5691. if ((optionFlags & useHiddenFile) != 0)
  5692. name = "." + name;
  5693. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5694. }
  5695. TemporaryFile::~TemporaryFile()
  5696. {
  5697. // Have a few attempts at deleting the file before giving up..
  5698. for (int i = 5; --i >= 0;)
  5699. {
  5700. if (temporaryFile.deleteFile())
  5701. return;
  5702. Thread::sleep (50);
  5703. }
  5704. // Failed to delete our temporary file! Check that you've deleted all the
  5705. // file output streams that were using it!
  5706. jassertfalse;
  5707. }
  5708. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5709. {
  5710. // This method only works if you created this object with the constructor
  5711. // that takes a target file!
  5712. jassert (targetFile != File::nonexistent);
  5713. if (temporaryFile.exists())
  5714. {
  5715. // Have a few attempts at overwriting the file before giving up..
  5716. for (int i = 5; --i >= 0;)
  5717. {
  5718. if (temporaryFile.moveFileTo (targetFile))
  5719. return true;
  5720. Thread::sleep (100);
  5721. }
  5722. }
  5723. else
  5724. {
  5725. // There's no temporary file to use. If your write failed, you should
  5726. // probably check, and not bother calling this method.
  5727. jassertfalse
  5728. }
  5729. return false;
  5730. }
  5731. END_JUCE_NAMESPACE
  5732. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5733. /*** Start of inlined file: juce_Socket.cpp ***/
  5734. #if JUCE_WINDOWS
  5735. #include <winsock2.h>
  5736. #ifdef _MSC_VER
  5737. #pragma warning (disable : 4127 4389 4018)
  5738. #endif
  5739. #else
  5740. #if JUCE_LINUX
  5741. #include <sys/types.h>
  5742. #include <sys/socket.h>
  5743. #include <sys/errno.h>
  5744. #include <unistd.h>
  5745. #include <netinet/in.h>
  5746. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5747. #include <CoreServices/CoreServices.h>
  5748. #endif
  5749. #include <fcntl.h>
  5750. #include <netdb.h>
  5751. #include <arpa/inet.h>
  5752. #include <netinet/tcp.h>
  5753. #endif
  5754. BEGIN_JUCE_NAMESPACE
  5755. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5756. typedef socklen_t juce_socklen_t;
  5757. #else
  5758. typedef int juce_socklen_t;
  5759. #endif
  5760. #if JUCE_WINDOWS
  5761. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5762. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5763. static void initWin32Sockets()
  5764. {
  5765. static CriticalSection lock;
  5766. const ScopedLock sl (lock);
  5767. if (juce_CloseWin32SocketLib == 0)
  5768. {
  5769. WSADATA wsaData;
  5770. const WORD wVersionRequested = MAKEWORD (1, 1);
  5771. WSAStartup (wVersionRequested, &wsaData);
  5772. juce_CloseWin32SocketLib = &WSACleanup;
  5773. }
  5774. }
  5775. #endif
  5776. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5777. {
  5778. const int sndBufSize = 65536;
  5779. const int rcvBufSize = 65536;
  5780. const int one = 1;
  5781. return handle > 0
  5782. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5783. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5784. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5785. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5786. }
  5787. static bool bindSocketToPort (const int handle, const int port) throw()
  5788. {
  5789. if (handle <= 0 || port <= 0)
  5790. return false;
  5791. struct sockaddr_in servTmpAddr;
  5792. zerostruct (servTmpAddr);
  5793. servTmpAddr.sin_family = PF_INET;
  5794. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5795. servTmpAddr.sin_port = htons ((uint16) port);
  5796. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5797. }
  5798. static int readSocket (const int handle,
  5799. void* const destBuffer, const int maxBytesToRead,
  5800. bool volatile& connected,
  5801. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5802. {
  5803. int bytesRead = 0;
  5804. while (bytesRead < maxBytesToRead)
  5805. {
  5806. int bytesThisTime;
  5807. #if JUCE_WINDOWS
  5808. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5809. #else
  5810. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5811. && errno == EINTR
  5812. && connected)
  5813. {
  5814. }
  5815. #endif
  5816. if (bytesThisTime <= 0 || ! connected)
  5817. {
  5818. if (bytesRead == 0)
  5819. bytesRead = -1;
  5820. break;
  5821. }
  5822. bytesRead += bytesThisTime;
  5823. if (! blockUntilSpecifiedAmountHasArrived)
  5824. break;
  5825. }
  5826. return bytesRead;
  5827. }
  5828. static int waitForReadiness (const int handle, const bool forReading,
  5829. const int timeoutMsecs) throw()
  5830. {
  5831. struct timeval timeout;
  5832. struct timeval* timeoutp;
  5833. if (timeoutMsecs >= 0)
  5834. {
  5835. timeout.tv_sec = timeoutMsecs / 1000;
  5836. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5837. timeoutp = &timeout;
  5838. }
  5839. else
  5840. {
  5841. timeoutp = 0;
  5842. }
  5843. fd_set rset, wset;
  5844. FD_ZERO (&rset);
  5845. FD_SET (handle, &rset);
  5846. FD_ZERO (&wset);
  5847. FD_SET (handle, &wset);
  5848. fd_set* const prset = forReading ? &rset : 0;
  5849. fd_set* const pwset = forReading ? 0 : &wset;
  5850. #if JUCE_WINDOWS
  5851. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5852. return -1;
  5853. #else
  5854. {
  5855. int result;
  5856. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5857. && errno == EINTR)
  5858. {
  5859. }
  5860. if (result < 0)
  5861. return -1;
  5862. }
  5863. #endif
  5864. {
  5865. int opt;
  5866. juce_socklen_t len = sizeof (opt);
  5867. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5868. || opt != 0)
  5869. return -1;
  5870. }
  5871. if ((forReading && FD_ISSET (handle, &rset))
  5872. || ((! forReading) && FD_ISSET (handle, &wset)))
  5873. return 1;
  5874. return 0;
  5875. }
  5876. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5877. {
  5878. #if JUCE_WINDOWS
  5879. u_long nonBlocking = shouldBlock ? 0 : 1;
  5880. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5881. return false;
  5882. #else
  5883. int socketFlags = fcntl (handle, F_GETFL, 0);
  5884. if (socketFlags == -1)
  5885. return false;
  5886. if (shouldBlock)
  5887. socketFlags &= ~O_NONBLOCK;
  5888. else
  5889. socketFlags |= O_NONBLOCK;
  5890. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5891. return false;
  5892. #endif
  5893. return true;
  5894. }
  5895. static bool connectSocket (int volatile& handle,
  5896. const bool isDatagram,
  5897. void** serverAddress,
  5898. const String& hostName,
  5899. const int portNumber,
  5900. const int timeOutMillisecs) throw()
  5901. {
  5902. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  5903. if (hostEnt == 0)
  5904. return false;
  5905. struct in_addr targetAddress;
  5906. memcpy (&targetAddress.s_addr,
  5907. *(hostEnt->h_addr_list),
  5908. sizeof (targetAddress.s_addr));
  5909. struct sockaddr_in servTmpAddr;
  5910. zerostruct (servTmpAddr);
  5911. servTmpAddr.sin_family = PF_INET;
  5912. servTmpAddr.sin_addr = targetAddress;
  5913. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5914. if (handle < 0)
  5915. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5916. if (handle < 0)
  5917. return false;
  5918. if (isDatagram)
  5919. {
  5920. *serverAddress = new struct sockaddr_in();
  5921. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5922. return true;
  5923. }
  5924. setSocketBlockingState (handle, false);
  5925. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  5926. if (result < 0)
  5927. {
  5928. #if JUCE_WINDOWS
  5929. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  5930. #else
  5931. if (errno == EINPROGRESS)
  5932. #endif
  5933. {
  5934. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  5935. {
  5936. setSocketBlockingState (handle, true);
  5937. return false;
  5938. }
  5939. }
  5940. }
  5941. setSocketBlockingState (handle, true);
  5942. resetSocketOptions (handle, false, false);
  5943. return true;
  5944. }
  5945. StreamingSocket::StreamingSocket()
  5946. : portNumber (0),
  5947. handle (-1),
  5948. connected (false),
  5949. isListener (false)
  5950. {
  5951. #if JUCE_WINDOWS
  5952. initWin32Sockets();
  5953. #endif
  5954. }
  5955. StreamingSocket::StreamingSocket (const String& hostName_,
  5956. const int portNumber_,
  5957. const int handle_)
  5958. : hostName (hostName_),
  5959. portNumber (portNumber_),
  5960. handle (handle_),
  5961. connected (true),
  5962. isListener (false)
  5963. {
  5964. #if JUCE_WINDOWS
  5965. initWin32Sockets();
  5966. #endif
  5967. resetSocketOptions (handle_, false, false);
  5968. }
  5969. StreamingSocket::~StreamingSocket()
  5970. {
  5971. close();
  5972. }
  5973. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  5974. {
  5975. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  5976. : -1;
  5977. }
  5978. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  5979. {
  5980. if (isListener || ! connected)
  5981. return -1;
  5982. #if JUCE_WINDOWS
  5983. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  5984. #else
  5985. int result;
  5986. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  5987. && errno == EINTR)
  5988. {
  5989. }
  5990. return result;
  5991. #endif
  5992. }
  5993. int StreamingSocket::waitUntilReady (const bool readyForReading,
  5994. const int timeoutMsecs) const
  5995. {
  5996. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  5997. : -1;
  5998. }
  5999. bool StreamingSocket::bindToPort (const int port)
  6000. {
  6001. return bindSocketToPort (handle, port);
  6002. }
  6003. bool StreamingSocket::connect (const String& remoteHostName,
  6004. const int remotePortNumber,
  6005. const int timeOutMillisecs)
  6006. {
  6007. if (isListener)
  6008. {
  6009. jassertfalse // a listener socket can't connect to another one!
  6010. return false;
  6011. }
  6012. if (connected)
  6013. close();
  6014. hostName = remoteHostName;
  6015. portNumber = remotePortNumber;
  6016. isListener = false;
  6017. connected = connectSocket (handle, false, 0, remoteHostName,
  6018. remotePortNumber, timeOutMillisecs);
  6019. if (! (connected && resetSocketOptions (handle, false, false)))
  6020. {
  6021. close();
  6022. return false;
  6023. }
  6024. return true;
  6025. }
  6026. void StreamingSocket::close()
  6027. {
  6028. #if JUCE_WINDOWS
  6029. if (handle != SOCKET_ERROR || connected)
  6030. closesocket (handle);
  6031. connected = false;
  6032. #else
  6033. if (connected)
  6034. {
  6035. connected = false;
  6036. if (isListener)
  6037. {
  6038. // need to do this to interrupt the accept() function..
  6039. StreamingSocket temp;
  6040. temp.connect ("localhost", portNumber, 1000);
  6041. }
  6042. }
  6043. if (handle != -1)
  6044. ::close (handle);
  6045. #endif
  6046. hostName = String::empty;
  6047. portNumber = 0;
  6048. handle = -1;
  6049. isListener = false;
  6050. }
  6051. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6052. {
  6053. if (connected)
  6054. close();
  6055. hostName = "listener";
  6056. portNumber = newPortNumber;
  6057. isListener = true;
  6058. struct sockaddr_in servTmpAddr;
  6059. zerostruct (servTmpAddr);
  6060. servTmpAddr.sin_family = PF_INET;
  6061. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6062. if (localHostName.isNotEmpty())
  6063. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6064. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6065. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6066. if (handle < 0)
  6067. return false;
  6068. const int reuse = 1;
  6069. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6070. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6071. || listen (handle, SOMAXCONN) < 0)
  6072. {
  6073. close();
  6074. return false;
  6075. }
  6076. connected = true;
  6077. return true;
  6078. }
  6079. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6080. {
  6081. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6082. // prepare this socket as a listener.
  6083. if (connected && isListener)
  6084. {
  6085. struct sockaddr address;
  6086. juce_socklen_t len = sizeof (sockaddr);
  6087. const int newSocket = (int) accept (handle, &address, &len);
  6088. if (newSocket >= 0 && connected)
  6089. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6090. portNumber, newSocket);
  6091. }
  6092. return 0;
  6093. }
  6094. bool StreamingSocket::isLocal() const throw()
  6095. {
  6096. return hostName == "127.0.0.1";
  6097. }
  6098. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6099. : portNumber (0),
  6100. handle (-1),
  6101. connected (true),
  6102. allowBroadcast (allowBroadcast_),
  6103. serverAddress (0)
  6104. {
  6105. #if JUCE_WINDOWS
  6106. initWin32Sockets();
  6107. #endif
  6108. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6109. bindToPort (localPortNumber);
  6110. }
  6111. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6112. const int handle_, const int localPortNumber)
  6113. : hostName (hostName_),
  6114. portNumber (portNumber_),
  6115. handle (handle_),
  6116. connected (true),
  6117. allowBroadcast (false),
  6118. serverAddress (0)
  6119. {
  6120. #if JUCE_WINDOWS
  6121. initWin32Sockets();
  6122. #endif
  6123. resetSocketOptions (handle_, true, allowBroadcast);
  6124. bindToPort (localPortNumber);
  6125. }
  6126. DatagramSocket::~DatagramSocket()
  6127. {
  6128. close();
  6129. delete ((struct sockaddr_in*) serverAddress);
  6130. serverAddress = 0;
  6131. }
  6132. void DatagramSocket::close()
  6133. {
  6134. #if JUCE_WINDOWS
  6135. closesocket (handle);
  6136. connected = false;
  6137. #else
  6138. connected = false;
  6139. ::close (handle);
  6140. #endif
  6141. hostName = String::empty;
  6142. portNumber = 0;
  6143. handle = -1;
  6144. }
  6145. bool DatagramSocket::bindToPort (const int port)
  6146. {
  6147. return bindSocketToPort (handle, port);
  6148. }
  6149. bool DatagramSocket::connect (const String& remoteHostName,
  6150. const int remotePortNumber,
  6151. const int timeOutMillisecs)
  6152. {
  6153. if (connected)
  6154. close();
  6155. hostName = remoteHostName;
  6156. portNumber = remotePortNumber;
  6157. connected = connectSocket (handle, true, &serverAddress,
  6158. remoteHostName, remotePortNumber,
  6159. timeOutMillisecs);
  6160. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6161. {
  6162. close();
  6163. return false;
  6164. }
  6165. return true;
  6166. }
  6167. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6168. {
  6169. struct sockaddr address;
  6170. juce_socklen_t len = sizeof (sockaddr);
  6171. while (waitUntilReady (true, -1) == 1)
  6172. {
  6173. char buf[1];
  6174. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6175. {
  6176. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6177. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6178. -1, -1);
  6179. }
  6180. }
  6181. return 0;
  6182. }
  6183. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6184. const int timeoutMsecs) const
  6185. {
  6186. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6187. : -1;
  6188. }
  6189. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6190. {
  6191. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6192. : -1;
  6193. }
  6194. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6195. {
  6196. // You need to call connect() first to set the server address..
  6197. jassert (serverAddress != 0 && connected);
  6198. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6199. numBytesToWrite, 0,
  6200. (const struct sockaddr*) serverAddress,
  6201. sizeof (struct sockaddr_in))
  6202. : -1;
  6203. }
  6204. bool DatagramSocket::isLocal() const throw()
  6205. {
  6206. return hostName == "127.0.0.1";
  6207. }
  6208. END_JUCE_NAMESPACE
  6209. /*** End of inlined file: juce_Socket.cpp ***/
  6210. /*** Start of inlined file: juce_URL.cpp ***/
  6211. BEGIN_JUCE_NAMESPACE
  6212. URL::URL()
  6213. {
  6214. }
  6215. URL::URL (const String& url_)
  6216. : url (url_)
  6217. {
  6218. int i = url.indexOfChar ('?');
  6219. if (i >= 0)
  6220. {
  6221. do
  6222. {
  6223. const int nextAmp = url.indexOfChar (i + 1, '&');
  6224. const int equalsPos = url.indexOfChar (i + 1, '=');
  6225. if (equalsPos > i + 1)
  6226. {
  6227. if (nextAmp < 0)
  6228. {
  6229. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6230. removeEscapeChars (url.substring (equalsPos + 1)));
  6231. }
  6232. else if (nextAmp > 0 && equalsPos < nextAmp)
  6233. {
  6234. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6235. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6236. }
  6237. }
  6238. i = nextAmp;
  6239. }
  6240. while (i >= 0);
  6241. url = url.upToFirstOccurrenceOf ("?", false, false);
  6242. }
  6243. }
  6244. URL::URL (const URL& other)
  6245. : url (other.url),
  6246. postData (other.postData),
  6247. parameters (other.parameters),
  6248. filesToUpload (other.filesToUpload),
  6249. mimeTypes (other.mimeTypes)
  6250. {
  6251. }
  6252. URL& URL::operator= (const URL& other)
  6253. {
  6254. url = other.url;
  6255. postData = other.postData;
  6256. parameters = other.parameters;
  6257. filesToUpload = other.filesToUpload;
  6258. mimeTypes = other.mimeTypes;
  6259. return *this;
  6260. }
  6261. URL::~URL()
  6262. {
  6263. }
  6264. static const String getMangledParameters (const StringPairArray& parameters)
  6265. {
  6266. String p;
  6267. for (int i = 0; i < parameters.size(); ++i)
  6268. {
  6269. if (i > 0)
  6270. p += '&';
  6271. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6272. << '='
  6273. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6274. }
  6275. return p;
  6276. }
  6277. const String URL::toString (const bool includeGetParameters) const
  6278. {
  6279. if (includeGetParameters && parameters.size() > 0)
  6280. return url + "?" + getMangledParameters (parameters);
  6281. else
  6282. return url;
  6283. }
  6284. bool URL::isWellFormed() const
  6285. {
  6286. //xxx TODO
  6287. return url.isNotEmpty();
  6288. }
  6289. static int findStartOfDomain (const String& url)
  6290. {
  6291. int i = 0;
  6292. while (CharacterFunctions::isLetterOrDigit (url[i])
  6293. || CharacterFunctions::indexOfChar (L"+-.", url[i], false) >= 0)
  6294. ++i;
  6295. return url[i] == ':' ? i + 1 : 0;
  6296. }
  6297. const String URL::getDomain() const
  6298. {
  6299. int start = findStartOfDomain (url);
  6300. while (url[start] == '/')
  6301. ++start;
  6302. const int end1 = url.indexOfChar (start, '/');
  6303. const int end2 = url.indexOfChar (start, ':');
  6304. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6305. : jmin (end1, end2);
  6306. return url.substring (start, end);
  6307. }
  6308. const String URL::getSubPath() const
  6309. {
  6310. int start = findStartOfDomain (url);
  6311. while (url[start] == '/')
  6312. ++start;
  6313. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6314. return startOfPath <= 0 ? String::empty
  6315. : url.substring (startOfPath);
  6316. }
  6317. const String URL::getScheme() const
  6318. {
  6319. return url.substring (0, findStartOfDomain (url) - 1);
  6320. }
  6321. const URL URL::withNewSubPath (const String& newPath) const
  6322. {
  6323. int start = findStartOfDomain (url);
  6324. while (url[start] == '/')
  6325. ++start;
  6326. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6327. URL u (*this);
  6328. if (startOfPath > 0)
  6329. u.url = url.substring (0, startOfPath);
  6330. if (! u.url.endsWithChar ('/'))
  6331. u.url << '/';
  6332. if (newPath.startsWithChar ('/'))
  6333. u.url << newPath.substring (1);
  6334. else
  6335. u.url << newPath;
  6336. return u;
  6337. }
  6338. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6339. {
  6340. if (possibleURL.startsWithIgnoreCase ("http:")
  6341. || possibleURL.startsWithIgnoreCase ("ftp:"))
  6342. return true;
  6343. if (possibleURL.startsWithIgnoreCase ("file:")
  6344. || possibleURL.containsChar ('@')
  6345. || possibleURL.endsWithChar ('.')
  6346. || (! possibleURL.containsChar ('.')))
  6347. return false;
  6348. if (possibleURL.startsWithIgnoreCase ("www.")
  6349. && possibleURL.substring (5).containsChar ('.'))
  6350. return true;
  6351. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6352. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6353. if ((possibleURL + "/").containsIgnoreCase ("." + String (commonTLDs[i]) + "/"))
  6354. return true;
  6355. return false;
  6356. }
  6357. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6358. {
  6359. const int atSign = possibleEmailAddress.indexOfChar ('@');
  6360. return atSign > 0
  6361. && possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1)
  6362. && (! possibleEmailAddress.endsWithChar ('.'));
  6363. }
  6364. void* juce_openInternetFile (const String& url,
  6365. const String& headers,
  6366. const MemoryBlock& optionalPostData,
  6367. const bool isPost,
  6368. URL::OpenStreamProgressCallback* callback,
  6369. void* callbackContext,
  6370. int timeOutMs);
  6371. void juce_closeInternetFile (void* handle);
  6372. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6373. int juce_seekInInternetFile (void* handle, int newPosition);
  6374. int64 juce_getInternetFileContentLength (void* handle);
  6375. class WebInputStream : public InputStream
  6376. {
  6377. public:
  6378. WebInputStream (const URL& url,
  6379. const bool isPost_,
  6380. URL::OpenStreamProgressCallback* const progressCallback_,
  6381. void* const progressCallbackContext_,
  6382. const String& extraHeaders,
  6383. int timeOutMs_)
  6384. : position (0),
  6385. finished (false),
  6386. isPost (isPost_),
  6387. progressCallback (progressCallback_),
  6388. progressCallbackContext (progressCallbackContext_),
  6389. timeOutMs (timeOutMs_)
  6390. {
  6391. server = url.toString (! isPost);
  6392. if (isPost_)
  6393. createHeadersAndPostData (url);
  6394. headers += extraHeaders;
  6395. if (! headers.endsWithChar ('\n'))
  6396. headers << "\r\n";
  6397. handle = juce_openInternetFile (server, headers, postData, isPost,
  6398. progressCallback_, progressCallbackContext_,
  6399. timeOutMs);
  6400. }
  6401. ~WebInputStream()
  6402. {
  6403. juce_closeInternetFile (handle);
  6404. }
  6405. bool isError() const
  6406. {
  6407. return handle == 0;
  6408. }
  6409. int64 getTotalLength()
  6410. {
  6411. return juce_getInternetFileContentLength (handle);
  6412. }
  6413. bool isExhausted()
  6414. {
  6415. return finished;
  6416. }
  6417. int read (void* dest, int bytes)
  6418. {
  6419. if (finished || isError())
  6420. {
  6421. return 0;
  6422. }
  6423. else
  6424. {
  6425. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6426. position += bytesRead;
  6427. if (bytesRead == 0)
  6428. finished = true;
  6429. return bytesRead;
  6430. }
  6431. }
  6432. int64 getPosition()
  6433. {
  6434. return position;
  6435. }
  6436. bool setPosition (int64 wantedPos)
  6437. {
  6438. if (wantedPos != position)
  6439. {
  6440. finished = false;
  6441. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6442. if (actualPos == wantedPos)
  6443. {
  6444. position = wantedPos;
  6445. }
  6446. else
  6447. {
  6448. if (wantedPos < position)
  6449. {
  6450. juce_closeInternetFile (handle);
  6451. position = 0;
  6452. finished = false;
  6453. handle = juce_openInternetFile (server, headers, postData, isPost,
  6454. progressCallback, progressCallbackContext,
  6455. timeOutMs);
  6456. }
  6457. skipNextBytes (wantedPos - position);
  6458. }
  6459. }
  6460. return true;
  6461. }
  6462. juce_UseDebuggingNewOperator
  6463. private:
  6464. String server, headers;
  6465. MemoryBlock postData;
  6466. int64 position;
  6467. bool finished;
  6468. const bool isPost;
  6469. void* handle;
  6470. URL::OpenStreamProgressCallback* const progressCallback;
  6471. void* const progressCallbackContext;
  6472. const int timeOutMs;
  6473. void createHeadersAndPostData (const URL& url)
  6474. {
  6475. if (url.getFilesToUpload().size() > 0)
  6476. {
  6477. // need to upload some files, so do it as multi-part...
  6478. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6479. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6480. appendUTF8ToPostData ("--" + boundary);
  6481. int i;
  6482. for (i = 0; i < url.getParameters().size(); ++i)
  6483. {
  6484. String s;
  6485. s << "\r\nContent-Disposition: form-data; name=\""
  6486. << url.getParameters().getAllKeys() [i]
  6487. << "\"\r\n\r\n"
  6488. << url.getParameters().getAllValues() [i]
  6489. << "\r\n--"
  6490. << boundary;
  6491. appendUTF8ToPostData (s);
  6492. }
  6493. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6494. {
  6495. const File f (url.getFilesToUpload().getAllValues() [i]);
  6496. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6497. String s;
  6498. s << "\r\nContent-Disposition: form-data; name=\""
  6499. << paramName
  6500. << "\"; filename=\""
  6501. << f.getFileName()
  6502. << "\"\r\n";
  6503. const String mimeType (url.getMimeTypesOfUploadFiles()
  6504. .getValue (paramName, String::empty));
  6505. if (mimeType.isNotEmpty())
  6506. s << "Content-Type: " << mimeType << "\r\n";
  6507. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6508. appendUTF8ToPostData (s);
  6509. f.loadFileAsData (postData);
  6510. s = "\r\n--" + boundary;
  6511. appendUTF8ToPostData (s);
  6512. }
  6513. appendUTF8ToPostData ("--\r\n");
  6514. }
  6515. else
  6516. {
  6517. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6518. appendUTF8ToPostData (url.getPostData());
  6519. // just a short text attachment, so use simple url encoding..
  6520. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6521. + String ((unsigned int) postData.getSize())
  6522. + "\r\n";
  6523. }
  6524. }
  6525. void appendUTF8ToPostData (const String& text)
  6526. {
  6527. postData.append (text.toUTF8(),
  6528. (int) strlen (text.toUTF8()));
  6529. }
  6530. WebInputStream (const WebInputStream&);
  6531. WebInputStream& operator= (const WebInputStream&);
  6532. };
  6533. InputStream* URL::createInputStream (const bool usePostCommand,
  6534. OpenStreamProgressCallback* const progressCallback,
  6535. void* const progressCallbackContext,
  6536. const String& extraHeaders,
  6537. const int timeOutMs) const
  6538. {
  6539. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6540. progressCallback, progressCallbackContext,
  6541. extraHeaders,
  6542. timeOutMs));
  6543. return wi->isError() ? 0 : wi.release();
  6544. }
  6545. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6546. const bool usePostCommand) const
  6547. {
  6548. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6549. if (in != 0)
  6550. {
  6551. in->readIntoMemoryBlock (destData, -1);
  6552. return true;
  6553. }
  6554. return false;
  6555. }
  6556. const String URL::readEntireTextStream (const bool usePostCommand) const
  6557. {
  6558. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6559. if (in != 0)
  6560. return in->readEntireStreamAsString();
  6561. return String::empty;
  6562. }
  6563. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6564. {
  6565. XmlDocument doc (readEntireTextStream (usePostCommand));
  6566. return doc.getDocumentElement();
  6567. }
  6568. const URL URL::withParameter (const String& parameterName,
  6569. const String& parameterValue) const
  6570. {
  6571. URL u (*this);
  6572. u.parameters.set (parameterName, parameterValue);
  6573. return u;
  6574. }
  6575. const URL URL::withFileToUpload (const String& parameterName,
  6576. const File& fileToUpload,
  6577. const String& mimeType) const
  6578. {
  6579. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6580. URL u (*this);
  6581. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6582. u.mimeTypes.set (parameterName, mimeType);
  6583. return u;
  6584. }
  6585. const URL URL::withPOSTData (const String& postData_) const
  6586. {
  6587. URL u (*this);
  6588. u.postData = postData_;
  6589. return u;
  6590. }
  6591. const StringPairArray& URL::getParameters() const
  6592. {
  6593. return parameters;
  6594. }
  6595. const StringPairArray& URL::getFilesToUpload() const
  6596. {
  6597. return filesToUpload;
  6598. }
  6599. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6600. {
  6601. return mimeTypes;
  6602. }
  6603. const String URL::removeEscapeChars (const String& s)
  6604. {
  6605. String result (s.replaceCharacter ('+', ' '));
  6606. int nextPercent = 0;
  6607. for (;;)
  6608. {
  6609. nextPercent = result.indexOfChar (nextPercent, '%');
  6610. if (nextPercent < 0)
  6611. break;
  6612. juce_wchar replacementChar = (juce_wchar) result.substring (nextPercent + 1, nextPercent + 3).getHexValue32();
  6613. result = result.replaceSection (nextPercent, 3, String::charToString (replacementChar));
  6614. ++nextPercent;
  6615. }
  6616. return result;
  6617. }
  6618. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6619. {
  6620. String result;
  6621. result.preallocateStorage (s.length() + 8);
  6622. const char* utf8 = s.toUTF8();
  6623. const char* legalChars = isParameter ? "_-.*!'()"
  6624. : "_-$.*!'(),";
  6625. while (*utf8 != 0)
  6626. {
  6627. const char c = *utf8++;
  6628. if (CharacterFunctions::isLetterOrDigit (c)
  6629. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6630. {
  6631. result << c;
  6632. }
  6633. else
  6634. {
  6635. const int v = (int) (uint8) c;
  6636. result << (v < 0x10 ? "%0" : "%") << String::toHexString (v);
  6637. }
  6638. }
  6639. return result;
  6640. }
  6641. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6642. bool URL::launchInDefaultBrowser() const
  6643. {
  6644. String u (toString (true));
  6645. if (u.containsChar ('@') && ! u.containsChar (':'))
  6646. u = "mailto:" + u;
  6647. return juce_launchFile (u, String::empty);
  6648. }
  6649. END_JUCE_NAMESPACE
  6650. /*** End of inlined file: juce_URL.cpp ***/
  6651. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6652. BEGIN_JUCE_NAMESPACE
  6653. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6654. const int bufferSize_,
  6655. const bool deleteSourceWhenDestroyed)
  6656. : source (source_),
  6657. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6658. bufferSize (jmax (256, bufferSize_)),
  6659. position (source_->getPosition()),
  6660. lastReadPos (0),
  6661. bufferOverlap (128)
  6662. {
  6663. const int sourceSize = (int) source_->getTotalLength();
  6664. if (sourceSize >= 0)
  6665. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6666. bufferStart = position;
  6667. buffer.malloc (bufferSize);
  6668. }
  6669. BufferedInputStream::~BufferedInputStream()
  6670. {
  6671. }
  6672. int64 BufferedInputStream::getTotalLength()
  6673. {
  6674. return source->getTotalLength();
  6675. }
  6676. int64 BufferedInputStream::getPosition()
  6677. {
  6678. return position;
  6679. }
  6680. bool BufferedInputStream::setPosition (int64 newPosition)
  6681. {
  6682. position = jmax ((int64) 0, newPosition);
  6683. return true;
  6684. }
  6685. bool BufferedInputStream::isExhausted()
  6686. {
  6687. return (position >= lastReadPos)
  6688. && source->isExhausted();
  6689. }
  6690. void BufferedInputStream::ensureBuffered()
  6691. {
  6692. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6693. if (position < bufferStart || position >= bufferEndOverlap)
  6694. {
  6695. int bytesRead;
  6696. if (position < lastReadPos
  6697. && position >= bufferEndOverlap
  6698. && position >= bufferStart)
  6699. {
  6700. const int bytesToKeep = (int) (lastReadPos - position);
  6701. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6702. bufferStart = position;
  6703. bytesRead = source->read (buffer + bytesToKeep,
  6704. bufferSize - bytesToKeep);
  6705. lastReadPos += bytesRead;
  6706. bytesRead += bytesToKeep;
  6707. }
  6708. else
  6709. {
  6710. bufferStart = position;
  6711. source->setPosition (bufferStart);
  6712. bytesRead = source->read (buffer, bufferSize);
  6713. lastReadPos = bufferStart + bytesRead;
  6714. }
  6715. while (bytesRead < bufferSize)
  6716. buffer [bytesRead++] = 0;
  6717. }
  6718. }
  6719. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6720. {
  6721. if (position >= bufferStart
  6722. && position + maxBytesToRead <= lastReadPos)
  6723. {
  6724. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6725. position += maxBytesToRead;
  6726. return maxBytesToRead;
  6727. }
  6728. else
  6729. {
  6730. if (position < bufferStart || position >= lastReadPos)
  6731. ensureBuffered();
  6732. int bytesRead = 0;
  6733. while (maxBytesToRead > 0)
  6734. {
  6735. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6736. if (bytesAvailable > 0)
  6737. {
  6738. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6739. maxBytesToRead -= bytesAvailable;
  6740. bytesRead += bytesAvailable;
  6741. position += bytesAvailable;
  6742. destBuffer = static_cast <char*> (destBuffer) + bytesAvailable;
  6743. }
  6744. const int64 oldLastReadPos = lastReadPos;
  6745. ensureBuffered();
  6746. if (oldLastReadPos == lastReadPos)
  6747. break; // if ensureBuffered() failed to read any more data, bail out
  6748. if (isExhausted())
  6749. break;
  6750. }
  6751. return bytesRead;
  6752. }
  6753. }
  6754. const String BufferedInputStream::readString()
  6755. {
  6756. if (position >= bufferStart
  6757. && position < lastReadPos)
  6758. {
  6759. const int maxChars = (int) (lastReadPos - position);
  6760. const char* const src = buffer + (int) (position - bufferStart);
  6761. for (int i = 0; i < maxChars; ++i)
  6762. {
  6763. if (src[i] == 0)
  6764. {
  6765. position += i + 1;
  6766. return String::fromUTF8 (src, i);
  6767. }
  6768. }
  6769. }
  6770. return InputStream::readString();
  6771. }
  6772. END_JUCE_NAMESPACE
  6773. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6774. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6775. BEGIN_JUCE_NAMESPACE
  6776. FileInputSource::FileInputSource (const File& file_)
  6777. : file (file_)
  6778. {
  6779. }
  6780. FileInputSource::~FileInputSource()
  6781. {
  6782. }
  6783. InputStream* FileInputSource::createInputStream()
  6784. {
  6785. return file.createInputStream();
  6786. }
  6787. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6788. {
  6789. return file.getSiblingFile (relatedItemPath).createInputStream();
  6790. }
  6791. int64 FileInputSource::hashCode() const
  6792. {
  6793. return file.hashCode();
  6794. }
  6795. END_JUCE_NAMESPACE
  6796. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6797. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6798. BEGIN_JUCE_NAMESPACE
  6799. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6800. const size_t sourceDataSize,
  6801. const bool keepInternalCopy)
  6802. : data (static_cast <const char*> (sourceData)),
  6803. dataSize (sourceDataSize),
  6804. position (0)
  6805. {
  6806. if (keepInternalCopy)
  6807. {
  6808. internalCopy.append (data, sourceDataSize);
  6809. data = static_cast <const char*> (internalCopy.getData());
  6810. }
  6811. }
  6812. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  6813. const bool keepInternalCopy)
  6814. : data (static_cast <const char*> (sourceData.getData())),
  6815. dataSize (sourceData.getSize()),
  6816. position (0)
  6817. {
  6818. if (keepInternalCopy)
  6819. {
  6820. internalCopy = sourceData;
  6821. data = static_cast <const char*> (internalCopy.getData());
  6822. }
  6823. }
  6824. MemoryInputStream::~MemoryInputStream()
  6825. {
  6826. }
  6827. int64 MemoryInputStream::getTotalLength()
  6828. {
  6829. return dataSize;
  6830. }
  6831. int MemoryInputStream::read (void* const buffer, const int howMany)
  6832. {
  6833. jassert (howMany >= 0);
  6834. const int num = jmin (howMany, (int) (dataSize - position));
  6835. memcpy (buffer, data + position, num);
  6836. position += num;
  6837. return (int) num;
  6838. }
  6839. bool MemoryInputStream::isExhausted()
  6840. {
  6841. return (position >= dataSize);
  6842. }
  6843. bool MemoryInputStream::setPosition (const int64 pos)
  6844. {
  6845. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6846. return true;
  6847. }
  6848. int64 MemoryInputStream::getPosition()
  6849. {
  6850. return position;
  6851. }
  6852. END_JUCE_NAMESPACE
  6853. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  6854. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  6855. BEGIN_JUCE_NAMESPACE
  6856. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6857. const size_t blockSizeToIncreaseBy,
  6858. MemoryBlock* const memoryBlockToWriteTo)
  6859. : data (memoryBlockToWriteTo),
  6860. position (0),
  6861. size (0),
  6862. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6863. {
  6864. if (data == 0)
  6865. dataToDelete = data = new MemoryBlock (initialSize);
  6866. else
  6867. data->setSize (initialSize, false);
  6868. }
  6869. MemoryOutputStream::~MemoryOutputStream()
  6870. {
  6871. flush();
  6872. }
  6873. void MemoryOutputStream::flush()
  6874. {
  6875. if (dataToDelete == 0)
  6876. data->setSize (size, false);
  6877. }
  6878. void MemoryOutputStream::reset() throw()
  6879. {
  6880. position = 0;
  6881. size = 0;
  6882. }
  6883. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  6884. {
  6885. if (howMany > 0)
  6886. {
  6887. size_t storageNeeded = position + howMany;
  6888. if (storageNeeded >= data->getSize())
  6889. {
  6890. // if we need more space, increase the block by at least 10%..
  6891. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6892. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6893. data->ensureSize (storageNeeded);
  6894. }
  6895. data->copyFrom (buffer, (int) position, howMany);
  6896. position += howMany;
  6897. size = jmax (size, position);
  6898. }
  6899. return true;
  6900. }
  6901. const char* MemoryOutputStream::getData() const throw()
  6902. {
  6903. char* const d = static_cast <char*> (data->getData());
  6904. if (data->getSize() > size)
  6905. d [size] = 0;
  6906. return d;
  6907. }
  6908. bool MemoryOutputStream::setPosition (int64 newPosition)
  6909. {
  6910. if (newPosition <= (int64) size)
  6911. {
  6912. // ok to seek backwards
  6913. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6914. return true;
  6915. }
  6916. else
  6917. {
  6918. // trying to make it bigger isn't a good thing to do..
  6919. return false;
  6920. }
  6921. }
  6922. const String MemoryOutputStream::toUTF8() const
  6923. {
  6924. return String (getData(), getDataSize());
  6925. }
  6926. END_JUCE_NAMESPACE
  6927. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  6928. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  6929. BEGIN_JUCE_NAMESPACE
  6930. SubregionStream::SubregionStream (InputStream* const sourceStream,
  6931. const int64 startPositionInSourceStream_,
  6932. const int64 lengthOfSourceStream_,
  6933. const bool deleteSourceWhenDestroyed) throw()
  6934. : source (sourceStream),
  6935. startPositionInSourceStream (startPositionInSourceStream_),
  6936. lengthOfSourceStream (lengthOfSourceStream_)
  6937. {
  6938. if (deleteSourceWhenDestroyed)
  6939. sourceToDelete = source;
  6940. setPosition (0);
  6941. }
  6942. SubregionStream::~SubregionStream() throw()
  6943. {
  6944. }
  6945. int64 SubregionStream::getTotalLength()
  6946. {
  6947. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  6948. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  6949. : srcLen;
  6950. }
  6951. int64 SubregionStream::getPosition()
  6952. {
  6953. return source->getPosition() - startPositionInSourceStream;
  6954. }
  6955. bool SubregionStream::setPosition (int64 newPosition)
  6956. {
  6957. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  6958. }
  6959. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  6960. {
  6961. if (lengthOfSourceStream < 0)
  6962. {
  6963. return source->read (destBuffer, maxBytesToRead);
  6964. }
  6965. else
  6966. {
  6967. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  6968. if (maxBytesToRead <= 0)
  6969. return 0;
  6970. return source->read (destBuffer, maxBytesToRead);
  6971. }
  6972. }
  6973. bool SubregionStream::isExhausted()
  6974. {
  6975. if (lengthOfSourceStream >= 0)
  6976. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  6977. else
  6978. return source->isExhausted();
  6979. }
  6980. END_JUCE_NAMESPACE
  6981. /*** End of inlined file: juce_SubregionStream.cpp ***/
  6982. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  6983. BEGIN_JUCE_NAMESPACE
  6984. PerformanceCounter::PerformanceCounter (const String& name_,
  6985. int runsPerPrintout,
  6986. const File& loggingFile)
  6987. : name (name_),
  6988. numRuns (0),
  6989. runsPerPrint (runsPerPrintout),
  6990. totalTime (0),
  6991. outputFile (loggingFile)
  6992. {
  6993. if (outputFile != File::nonexistent)
  6994. {
  6995. String s ("**** Counter for \"");
  6996. s << name_ << "\" started at: "
  6997. << Time::getCurrentTime().toString (true, true)
  6998. << "\r\n";
  6999. outputFile.appendText (s, false, false);
  7000. }
  7001. }
  7002. PerformanceCounter::~PerformanceCounter()
  7003. {
  7004. printStatistics();
  7005. }
  7006. void PerformanceCounter::start()
  7007. {
  7008. started = Time::getHighResolutionTicks();
  7009. }
  7010. void PerformanceCounter::stop()
  7011. {
  7012. const int64 now = Time::getHighResolutionTicks();
  7013. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7014. if (++numRuns == runsPerPrint)
  7015. printStatistics();
  7016. }
  7017. void PerformanceCounter::printStatistics()
  7018. {
  7019. if (numRuns > 0)
  7020. {
  7021. String s ("Performance count for \"");
  7022. s << name << "\" - average over " << numRuns << " run(s) = ";
  7023. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7024. if (micros > 10000)
  7025. s << (micros/1000) << " millisecs";
  7026. else
  7027. s << micros << " microsecs";
  7028. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7029. Logger::outputDebugString (s);
  7030. s << "\r\n";
  7031. if (outputFile != File::nonexistent)
  7032. outputFile.appendText (s, false, false);
  7033. numRuns = 0;
  7034. totalTime = 0;
  7035. }
  7036. }
  7037. END_JUCE_NAMESPACE
  7038. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7039. /*** Start of inlined file: juce_Uuid.cpp ***/
  7040. BEGIN_JUCE_NAMESPACE
  7041. Uuid::Uuid()
  7042. {
  7043. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7044. // to make it very very unlikely that two UUIDs will ever be the same..
  7045. static int64 macAddresses[2];
  7046. static bool hasCheckedMacAddresses = false;
  7047. if (! hasCheckedMacAddresses)
  7048. {
  7049. hasCheckedMacAddresses = true;
  7050. SystemStats::getMACAddresses (macAddresses, 2);
  7051. }
  7052. value.asInt64[0] = macAddresses[0];
  7053. value.asInt64[1] = macAddresses[1];
  7054. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7055. // whose seed will carry over between calls to this method.
  7056. Random r (macAddresses[0] ^ macAddresses[1]
  7057. ^ Random::getSystemRandom().nextInt64());
  7058. for (int i = 4; --i >= 0;)
  7059. {
  7060. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7061. value.asInt[i] ^= r.nextInt();
  7062. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7063. }
  7064. }
  7065. Uuid::~Uuid() throw()
  7066. {
  7067. }
  7068. Uuid::Uuid (const Uuid& other)
  7069. : value (other.value)
  7070. {
  7071. }
  7072. Uuid& Uuid::operator= (const Uuid& other)
  7073. {
  7074. value = other.value;
  7075. return *this;
  7076. }
  7077. bool Uuid::operator== (const Uuid& other) const
  7078. {
  7079. return value.asInt64[0] == other.value.asInt64[0]
  7080. && value.asInt64[1] == other.value.asInt64[1];
  7081. }
  7082. bool Uuid::operator!= (const Uuid& other) const
  7083. {
  7084. return ! operator== (other);
  7085. }
  7086. bool Uuid::isNull() const throw()
  7087. {
  7088. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7089. }
  7090. const String Uuid::toString() const
  7091. {
  7092. return String::toHexString (value.asBytes, sizeof (value.asBytes), 0);
  7093. }
  7094. Uuid::Uuid (const String& uuidString)
  7095. {
  7096. operator= (uuidString);
  7097. }
  7098. Uuid& Uuid::operator= (const String& uuidString)
  7099. {
  7100. MemoryBlock mb;
  7101. mb.loadFromHexString (uuidString);
  7102. mb.ensureSize (sizeof (value.asBytes), true);
  7103. mb.copyTo (value.asBytes, 0, sizeof (value.asBytes));
  7104. return *this;
  7105. }
  7106. Uuid::Uuid (const uint8* const rawData)
  7107. {
  7108. operator= (rawData);
  7109. }
  7110. Uuid& Uuid::operator= (const uint8* const rawData)
  7111. {
  7112. if (rawData != 0)
  7113. memcpy (value.asBytes, rawData, sizeof (value.asBytes));
  7114. else
  7115. zeromem (value.asBytes, sizeof (value.asBytes));
  7116. return *this;
  7117. }
  7118. END_JUCE_NAMESPACE
  7119. /*** End of inlined file: juce_Uuid.cpp ***/
  7120. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7121. BEGIN_JUCE_NAMESPACE
  7122. class ZipFile::ZipEntryInfo
  7123. {
  7124. public:
  7125. ZipFile::ZipEntry entry;
  7126. int streamOffset;
  7127. int compressedSize;
  7128. bool compressed;
  7129. };
  7130. class ZipFile::ZipInputStream : public InputStream
  7131. {
  7132. public:
  7133. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7134. : file (file_),
  7135. zipEntryInfo (zei),
  7136. pos (0),
  7137. headerSize (0),
  7138. inputStream (0)
  7139. {
  7140. inputStream = file_.inputStream;
  7141. if (file_.inputSource != 0)
  7142. {
  7143. inputStream = file.inputSource->createInputStream();
  7144. }
  7145. else
  7146. {
  7147. #ifdef JUCE_DEBUG
  7148. file_.numOpenStreams++;
  7149. #endif
  7150. }
  7151. char buffer [30];
  7152. if (inputStream != 0
  7153. && inputStream->setPosition (zei.streamOffset)
  7154. && inputStream->read (buffer, 30) == 30
  7155. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7156. {
  7157. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7158. + ByteOrder::littleEndianShort (buffer + 28);
  7159. }
  7160. }
  7161. ~ZipInputStream() throw()
  7162. {
  7163. #ifdef JUCE_DEBUG
  7164. if (inputStream != 0 && inputStream == file.inputStream)
  7165. file.numOpenStreams--;
  7166. #endif
  7167. if (inputStream != file.inputStream)
  7168. delete inputStream;
  7169. }
  7170. int64 getTotalLength() throw()
  7171. {
  7172. return zipEntryInfo.compressedSize;
  7173. }
  7174. int read (void* buffer, int howMany) throw()
  7175. {
  7176. if (headerSize <= 0)
  7177. return 0;
  7178. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7179. if (inputStream == 0)
  7180. return 0;
  7181. int num;
  7182. if (inputStream == file.inputStream)
  7183. {
  7184. const ScopedLock sl (file.lock);
  7185. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7186. num = inputStream->read (buffer, howMany);
  7187. }
  7188. else
  7189. {
  7190. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7191. num = inputStream->read (buffer, howMany);
  7192. }
  7193. pos += num;
  7194. return num;
  7195. }
  7196. bool isExhausted() throw()
  7197. {
  7198. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7199. }
  7200. int64 getPosition() throw()
  7201. {
  7202. return pos;
  7203. }
  7204. bool setPosition (int64 newPos) throw()
  7205. {
  7206. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7207. return true;
  7208. }
  7209. private:
  7210. ZipFile& file;
  7211. ZipEntryInfo zipEntryInfo;
  7212. int64 pos;
  7213. int headerSize;
  7214. InputStream* inputStream;
  7215. ZipInputStream (const ZipInputStream&);
  7216. ZipInputStream& operator= (const ZipInputStream&);
  7217. };
  7218. ZipFile::ZipFile (InputStream* const source_,
  7219. const bool deleteStreamWhenDestroyed) throw()
  7220. : inputStream (source_)
  7221. #ifdef JUCE_DEBUG
  7222. , numOpenStreams (0)
  7223. #endif
  7224. {
  7225. if (deleteStreamWhenDestroyed)
  7226. streamToDelete = inputStream;
  7227. init();
  7228. }
  7229. ZipFile::ZipFile (const File& file)
  7230. : inputStream (0)
  7231. #ifdef JUCE_DEBUG
  7232. , numOpenStreams (0)
  7233. #endif
  7234. {
  7235. inputSource = new FileInputSource (file);
  7236. init();
  7237. }
  7238. ZipFile::ZipFile (InputSource* const inputSource_)
  7239. : inputStream (0),
  7240. inputSource (inputSource_)
  7241. #ifdef JUCE_DEBUG
  7242. , numOpenStreams (0)
  7243. #endif
  7244. {
  7245. init();
  7246. }
  7247. ZipFile::~ZipFile() throw()
  7248. {
  7249. #ifdef JUCE_DEBUG
  7250. entries.clear();
  7251. // If you hit this assertion, it means you've created a stream to read
  7252. // one of the items in the zipfile, but you've forgotten to delete that
  7253. // stream object before deleting the file.. Streams can't be kept open
  7254. // after the file is deleted because they need to share the input
  7255. // stream that the file uses to read itself.
  7256. jassert (numOpenStreams == 0);
  7257. #endif
  7258. }
  7259. int ZipFile::getNumEntries() const throw()
  7260. {
  7261. return entries.size();
  7262. }
  7263. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7264. {
  7265. ZipEntryInfo* const zei = entries [index];
  7266. return zei != 0 ? &(zei->entry) : 0;
  7267. }
  7268. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7269. {
  7270. for (int i = 0; i < entries.size(); ++i)
  7271. if (entries.getUnchecked (i)->entry.filename == fileName)
  7272. return i;
  7273. return -1;
  7274. }
  7275. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7276. {
  7277. return getEntry (getIndexOfFileName (fileName));
  7278. }
  7279. InputStream* ZipFile::createStreamForEntry (const int index)
  7280. {
  7281. ZipEntryInfo* const zei = entries[index];
  7282. InputStream* stream = 0;
  7283. if (zei != 0)
  7284. {
  7285. stream = new ZipInputStream (*this, *zei);
  7286. if (zei->compressed)
  7287. {
  7288. stream = new GZIPDecompressorInputStream (stream, true, true,
  7289. zei->entry.uncompressedSize);
  7290. // (much faster to unzip in big blocks using a buffer..)
  7291. stream = new BufferedInputStream (stream, 32768, true);
  7292. }
  7293. }
  7294. return stream;
  7295. }
  7296. class ZipFile::ZipFilenameComparator
  7297. {
  7298. public:
  7299. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7300. {
  7301. return first->entry.filename.compare (second->entry.filename);
  7302. }
  7303. };
  7304. void ZipFile::sortEntriesByFilename()
  7305. {
  7306. ZipFilenameComparator sorter;
  7307. entries.sort (sorter);
  7308. }
  7309. void ZipFile::init()
  7310. {
  7311. ScopedPointer <InputStream> toDelete;
  7312. InputStream* in = inputStream;
  7313. if (inputSource != 0)
  7314. {
  7315. in = inputSource->createInputStream();
  7316. toDelete = in;
  7317. }
  7318. if (in != 0)
  7319. {
  7320. int numEntries = 0;
  7321. int pos = findEndOfZipEntryTable (in, numEntries);
  7322. if (pos >= 0 && pos < in->getTotalLength())
  7323. {
  7324. const int size = (int) (in->getTotalLength() - pos);
  7325. in->setPosition (pos);
  7326. MemoryBlock headerData;
  7327. if (in->readIntoMemoryBlock (headerData, size) == size)
  7328. {
  7329. pos = 0;
  7330. for (int i = 0; i < numEntries; ++i)
  7331. {
  7332. if (pos + 46 > size)
  7333. break;
  7334. const char* const buffer = static_cast <const char*> (headerData.getData()) + pos;
  7335. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7336. if (pos + 46 + fileNameLen > size)
  7337. break;
  7338. ZipEntryInfo* const zei = new ZipEntryInfo();
  7339. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7340. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7341. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7342. const int year = 1980 + (date >> 9);
  7343. const int month = ((date >> 5) & 15) - 1;
  7344. const int day = date & 31;
  7345. const int hours = time >> 11;
  7346. const int minutes = (time >> 5) & 63;
  7347. const int seconds = (time & 31) << 1;
  7348. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7349. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7350. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7351. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7352. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7353. entries.add (zei);
  7354. pos += 46 + fileNameLen
  7355. + ByteOrder::littleEndianShort (buffer + 30)
  7356. + ByteOrder::littleEndianShort (buffer + 32);
  7357. }
  7358. }
  7359. }
  7360. }
  7361. }
  7362. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7363. {
  7364. BufferedInputStream in (input, 8192, false);
  7365. in.setPosition (in.getTotalLength());
  7366. int64 pos = in.getPosition();
  7367. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7368. char buffer [32];
  7369. zeromem (buffer, sizeof (buffer));
  7370. while (pos > lowestPos)
  7371. {
  7372. in.setPosition (pos - 22);
  7373. pos = in.getPosition();
  7374. memcpy (buffer + 22, buffer, 4);
  7375. if (in.read (buffer, 22) != 22)
  7376. return 0;
  7377. for (int i = 0; i < 22; ++i)
  7378. {
  7379. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7380. {
  7381. in.setPosition (pos + i);
  7382. in.read (buffer, 22);
  7383. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7384. return ByteOrder::littleEndianInt (buffer + 16);
  7385. }
  7386. }
  7387. }
  7388. return 0;
  7389. }
  7390. void ZipFile::uncompressTo (const File& targetDirectory,
  7391. const bool shouldOverwriteFiles)
  7392. {
  7393. for (int i = 0; i < entries.size(); ++i)
  7394. {
  7395. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7396. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7397. if (zei.filename.endsWithChar ('/'))
  7398. {
  7399. targetFile.createDirectory(); // (entry is a directory, not a file)
  7400. }
  7401. else
  7402. {
  7403. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7404. if (in != 0)
  7405. {
  7406. if (shouldOverwriteFiles)
  7407. targetFile.deleteFile();
  7408. if ((! targetFile.exists())
  7409. && targetFile.getParentDirectory().createDirectory())
  7410. {
  7411. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7412. if (out != 0)
  7413. {
  7414. out->writeFromInputStream (*in, -1);
  7415. out = 0;
  7416. targetFile.setCreationTime (zei.fileTime);
  7417. targetFile.setLastModificationTime (zei.fileTime);
  7418. targetFile.setLastAccessTime (zei.fileTime);
  7419. }
  7420. }
  7421. }
  7422. }
  7423. }
  7424. }
  7425. END_JUCE_NAMESPACE
  7426. /*** End of inlined file: juce_ZipFile.cpp ***/
  7427. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7428. #ifdef _MSC_VER
  7429. #pragma warning (disable: 4514 4996)
  7430. #pragma warning (push)
  7431. #endif
  7432. #include <cwctype>
  7433. #include <cctype>
  7434. #include <ctime>
  7435. #ifdef _MSC_VER
  7436. #pragma warning (pop)
  7437. #endif
  7438. BEGIN_JUCE_NAMESPACE
  7439. int CharacterFunctions::length (const char* const s) throw()
  7440. {
  7441. return (int) strlen (s);
  7442. }
  7443. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7444. {
  7445. return (int) wcslen (s);
  7446. }
  7447. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7448. {
  7449. strncpy (dest, src, maxChars);
  7450. }
  7451. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7452. {
  7453. wcsncpy (dest, src, maxChars);
  7454. }
  7455. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7456. {
  7457. mbstowcs (dest, src, maxChars);
  7458. }
  7459. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7460. {
  7461. wcstombs (dest, src, maxChars);
  7462. }
  7463. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7464. {
  7465. return (int) wcstombs (0, src, 0);
  7466. }
  7467. void CharacterFunctions::append (char* dest, const char* src) throw()
  7468. {
  7469. strcat (dest, src);
  7470. }
  7471. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7472. {
  7473. wcscat (dest, src);
  7474. }
  7475. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7476. {
  7477. return strcmp (s1, s2);
  7478. }
  7479. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7480. {
  7481. jassert (s1 != 0 && s2 != 0);
  7482. return wcscmp (s1, s2);
  7483. }
  7484. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7485. {
  7486. jassert (s1 != 0 && s2 != 0);
  7487. return strncmp (s1, s2, maxChars);
  7488. }
  7489. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7490. {
  7491. jassert (s1 != 0 && s2 != 0);
  7492. return wcsncmp (s1, s2, maxChars);
  7493. }
  7494. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7495. {
  7496. jassert (s1 != 0 && s2 != 0);
  7497. for (;;)
  7498. {
  7499. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7500. if (diff != 0)
  7501. return diff;
  7502. else if (*s1 == 0)
  7503. break;
  7504. ++s1;
  7505. ++s2;
  7506. }
  7507. return 0;
  7508. }
  7509. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7510. {
  7511. return -compare (s2, s1);
  7512. }
  7513. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7514. {
  7515. jassert (s1 != 0 && s2 != 0);
  7516. #if JUCE_WIN32
  7517. return stricmp (s1, s2);
  7518. #else
  7519. return strcasecmp (s1, s2);
  7520. #endif
  7521. }
  7522. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7523. {
  7524. jassert (s1 != 0 && s2 != 0);
  7525. #if JUCE_WIN32
  7526. return _wcsicmp (s1, s2);
  7527. #else
  7528. for (;;)
  7529. {
  7530. if (*s1 != *s2)
  7531. {
  7532. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7533. if (diff != 0)
  7534. return diff < 0 ? -1 : 1;
  7535. }
  7536. else if (*s1 == 0)
  7537. break;
  7538. ++s1;
  7539. ++s2;
  7540. }
  7541. return 0;
  7542. #endif
  7543. }
  7544. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const char* s2) throw()
  7545. {
  7546. jassert (s1 != 0 && s2 != 0);
  7547. for (;;)
  7548. {
  7549. if (*s1 != *s2)
  7550. {
  7551. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7552. if (diff != 0)
  7553. return diff < 0 ? -1 : 1;
  7554. }
  7555. else if (*s1 == 0)
  7556. break;
  7557. ++s1;
  7558. ++s2;
  7559. }
  7560. return 0;
  7561. }
  7562. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7563. {
  7564. jassert (s1 != 0 && s2 != 0);
  7565. #if JUCE_WIN32
  7566. return strnicmp (s1, s2, maxChars);
  7567. #else
  7568. return strncasecmp (s1, s2, maxChars);
  7569. #endif
  7570. }
  7571. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7572. {
  7573. jassert (s1 != 0 && s2 != 0);
  7574. #if JUCE_WIN32
  7575. return _wcsnicmp (s1, s2, maxChars);
  7576. #else
  7577. while (--maxChars >= 0)
  7578. {
  7579. if (*s1 != *s2)
  7580. {
  7581. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7582. if (diff != 0)
  7583. return diff < 0 ? -1 : 1;
  7584. }
  7585. else if (*s1 == 0)
  7586. break;
  7587. ++s1;
  7588. ++s2;
  7589. }
  7590. return 0;
  7591. #endif
  7592. }
  7593. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7594. {
  7595. return strstr (haystack, needle);
  7596. }
  7597. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7598. {
  7599. return wcsstr (haystack, needle);
  7600. }
  7601. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7602. {
  7603. if (haystack != 0)
  7604. {
  7605. int i = 0;
  7606. if (ignoreCase)
  7607. {
  7608. const char n1 = toLowerCase (needle);
  7609. const char n2 = toUpperCase (needle);
  7610. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7611. {
  7612. while (haystack[i] != 0)
  7613. {
  7614. if (haystack[i] == n1 || haystack[i] == n2)
  7615. return i;
  7616. ++i;
  7617. }
  7618. return -1;
  7619. }
  7620. jassert (n1 == needle);
  7621. }
  7622. while (haystack[i] != 0)
  7623. {
  7624. if (haystack[i] == needle)
  7625. return i;
  7626. ++i;
  7627. }
  7628. }
  7629. return -1;
  7630. }
  7631. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7632. {
  7633. if (haystack != 0)
  7634. {
  7635. int i = 0;
  7636. if (ignoreCase)
  7637. {
  7638. const juce_wchar n1 = toLowerCase (needle);
  7639. const juce_wchar n2 = toUpperCase (needle);
  7640. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7641. {
  7642. while (haystack[i] != 0)
  7643. {
  7644. if (haystack[i] == n1 || haystack[i] == n2)
  7645. return i;
  7646. ++i;
  7647. }
  7648. return -1;
  7649. }
  7650. jassert (n1 == needle);
  7651. }
  7652. while (haystack[i] != 0)
  7653. {
  7654. if (haystack[i] == needle)
  7655. return i;
  7656. ++i;
  7657. }
  7658. }
  7659. return -1;
  7660. }
  7661. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7662. {
  7663. jassert (haystack != 0);
  7664. int i = 0;
  7665. while (haystack[i] != 0)
  7666. {
  7667. if (haystack[i] == needle)
  7668. return i;
  7669. ++i;
  7670. }
  7671. return -1;
  7672. }
  7673. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7674. {
  7675. jassert (haystack != 0);
  7676. int i = 0;
  7677. while (haystack[i] != 0)
  7678. {
  7679. if (haystack[i] == needle)
  7680. return i;
  7681. ++i;
  7682. }
  7683. return -1;
  7684. }
  7685. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7686. {
  7687. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7688. }
  7689. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7690. {
  7691. if (allowedChars == 0)
  7692. return 0;
  7693. int i = 0;
  7694. for (;;)
  7695. {
  7696. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7697. break;
  7698. ++i;
  7699. }
  7700. return i;
  7701. }
  7702. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7703. {
  7704. return (int) strftime (dest, maxChars, format, tm);
  7705. }
  7706. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7707. {
  7708. return (int) wcsftime (dest, maxChars, format, tm);
  7709. }
  7710. int CharacterFunctions::getIntValue (const char* const s) throw()
  7711. {
  7712. return atoi (s);
  7713. }
  7714. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7715. {
  7716. #if JUCE_WIN32
  7717. return _wtoi (s);
  7718. #else
  7719. int v = 0;
  7720. while (isWhitespace (*s))
  7721. ++s;
  7722. const bool isNeg = *s == '-';
  7723. if (isNeg)
  7724. ++s;
  7725. for (;;)
  7726. {
  7727. const wchar_t c = *s++;
  7728. if (c >= '0' && c <= '9')
  7729. v = v * 10 + (int) (c - '0');
  7730. else
  7731. break;
  7732. }
  7733. return isNeg ? -v : v;
  7734. #endif
  7735. }
  7736. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7737. {
  7738. #if JUCE_LINUX
  7739. return atoll (s);
  7740. #elif defined (JUCE_WIN32)
  7741. return _atoi64 (s);
  7742. #else
  7743. int64 v = 0;
  7744. while (isWhitespace (*s))
  7745. ++s;
  7746. const bool isNeg = *s == '-';
  7747. if (isNeg)
  7748. ++s;
  7749. for (;;)
  7750. {
  7751. const char c = *s++;
  7752. if (c >= '0' && c <= '9')
  7753. v = v * 10 + (int64) (c - '0');
  7754. else
  7755. break;
  7756. }
  7757. return isNeg ? -v : v;
  7758. #endif
  7759. }
  7760. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7761. {
  7762. #if JUCE_WIN32
  7763. return _wtoi64 (s);
  7764. #else
  7765. int64 v = 0;
  7766. while (isWhitespace (*s))
  7767. ++s;
  7768. const bool isNeg = *s == '-';
  7769. if (isNeg)
  7770. ++s;
  7771. for (;;)
  7772. {
  7773. const juce_wchar c = *s++;
  7774. if (c >= '0' && c <= '9')
  7775. v = v * 10 + (int64) (c - '0');
  7776. else
  7777. break;
  7778. }
  7779. return isNeg ? -v : v;
  7780. #endif
  7781. }
  7782. static double juce_mulexp10 (const double value, int exponent) throw()
  7783. {
  7784. if (exponent == 0)
  7785. return value;
  7786. if (value == 0)
  7787. return 0;
  7788. const bool negative = (exponent < 0);
  7789. if (negative)
  7790. exponent = -exponent;
  7791. double result = 1.0, power = 10.0;
  7792. for (int bit = 1; exponent != 0; bit <<= 1)
  7793. {
  7794. if ((exponent & bit) != 0)
  7795. {
  7796. exponent ^= bit;
  7797. result *= power;
  7798. if (exponent == 0)
  7799. break;
  7800. }
  7801. power *= power;
  7802. }
  7803. return negative ? (value / result) : (value * result);
  7804. }
  7805. template <class CharType>
  7806. double juce_atof (const CharType* const original) throw()
  7807. {
  7808. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7809. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7810. int exponent = 0, decPointIndex = 0, digit = 0;
  7811. int lastDigit = 0, numSignificantDigits = 0;
  7812. bool isNegative = false, digitsFound = false;
  7813. const int maxSignificantDigits = 15 + 2;
  7814. const CharType* s = original;
  7815. while (CharacterFunctions::isWhitespace (*s))
  7816. ++s;
  7817. switch (*s)
  7818. {
  7819. case '-': isNegative = true; // fall-through..
  7820. case '+': ++s;
  7821. }
  7822. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7823. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  7824. for (;;)
  7825. {
  7826. if (CharacterFunctions::isDigit (*s))
  7827. {
  7828. lastDigit = digit;
  7829. digit = *s++ - '0';
  7830. digitsFound = true;
  7831. if (decPointIndex != 0)
  7832. exponentAdjustment[1]++;
  7833. if (numSignificantDigits == 0 && digit == 0)
  7834. continue;
  7835. if (++numSignificantDigits > maxSignificantDigits)
  7836. {
  7837. if (digit > 5)
  7838. ++accumulator [decPointIndex];
  7839. else if (digit == 5 && (lastDigit & 1) != 0)
  7840. ++accumulator [decPointIndex];
  7841. if (decPointIndex > 0)
  7842. exponentAdjustment[1]--;
  7843. else
  7844. exponentAdjustment[0]++;
  7845. while (CharacterFunctions::isDigit (*s))
  7846. {
  7847. ++s;
  7848. if (decPointIndex == 0)
  7849. exponentAdjustment[0]++;
  7850. }
  7851. }
  7852. else
  7853. {
  7854. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  7855. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7856. {
  7857. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7858. + accumulator [decPointIndex];
  7859. accumulator [decPointIndex] = 0;
  7860. exponentAccumulator [decPointIndex] = 0;
  7861. }
  7862. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7863. exponentAccumulator [decPointIndex]++;
  7864. }
  7865. }
  7866. else if (decPointIndex == 0 && *s == '.')
  7867. {
  7868. ++s;
  7869. decPointIndex = 1;
  7870. if (numSignificantDigits > maxSignificantDigits)
  7871. {
  7872. while (CharacterFunctions::isDigit (*s))
  7873. ++s;
  7874. break;
  7875. }
  7876. }
  7877. else
  7878. {
  7879. break;
  7880. }
  7881. }
  7882. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7883. if (decPointIndex != 0)
  7884. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7885. if ((*s == 'e' || *s == 'E') && digitsFound)
  7886. {
  7887. bool negativeExponent = false;
  7888. switch (*++s)
  7889. {
  7890. case '-': negativeExponent = true; // fall-through..
  7891. case '+': ++s;
  7892. }
  7893. while (CharacterFunctions::isDigit (*s))
  7894. exponent = (exponent * 10) + (*s++ - '0');
  7895. if (negativeExponent)
  7896. exponent = -exponent;
  7897. }
  7898. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7899. if (decPointIndex != 0)
  7900. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7901. return isNegative ? -r : r;
  7902. }
  7903. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7904. {
  7905. return juce_atof <char> (s);
  7906. }
  7907. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7908. {
  7909. return juce_atof <juce_wchar> (s);
  7910. }
  7911. char CharacterFunctions::toUpperCase (const char character) throw()
  7912. {
  7913. return (char) toupper (character);
  7914. }
  7915. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7916. {
  7917. return towupper (character);
  7918. }
  7919. void CharacterFunctions::toUpperCase (char* s) throw()
  7920. {
  7921. #if JUCE_WIN32
  7922. strupr (s);
  7923. #else
  7924. while (*s != 0)
  7925. {
  7926. *s = toUpperCase (*s);
  7927. ++s;
  7928. }
  7929. #endif
  7930. }
  7931. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  7932. {
  7933. #if JUCE_WIN32
  7934. _wcsupr (s);
  7935. #else
  7936. while (*s != 0)
  7937. {
  7938. *s = toUpperCase (*s);
  7939. ++s;
  7940. }
  7941. #endif
  7942. }
  7943. bool CharacterFunctions::isUpperCase (const char character) throw()
  7944. {
  7945. return isupper (character) != 0;
  7946. }
  7947. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  7948. {
  7949. #if JUCE_WIN32
  7950. return iswupper (character) != 0;
  7951. #else
  7952. return toLowerCase (character) != character;
  7953. #endif
  7954. }
  7955. char CharacterFunctions::toLowerCase (const char character) throw()
  7956. {
  7957. return (char) tolower (character);
  7958. }
  7959. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  7960. {
  7961. return towlower (character);
  7962. }
  7963. void CharacterFunctions::toLowerCase (char* s) throw()
  7964. {
  7965. #if JUCE_WIN32
  7966. strlwr (s);
  7967. #else
  7968. while (*s != 0)
  7969. {
  7970. *s = toLowerCase (*s);
  7971. ++s;
  7972. }
  7973. #endif
  7974. }
  7975. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  7976. {
  7977. #if JUCE_WIN32
  7978. _wcslwr (s);
  7979. #else
  7980. while (*s != 0)
  7981. {
  7982. *s = toLowerCase (*s);
  7983. ++s;
  7984. }
  7985. #endif
  7986. }
  7987. bool CharacterFunctions::isLowerCase (const char character) throw()
  7988. {
  7989. return islower (character) != 0;
  7990. }
  7991. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  7992. {
  7993. #if JUCE_WIN32
  7994. return iswlower (character) != 0;
  7995. #else
  7996. return toUpperCase (character) != character;
  7997. #endif
  7998. }
  7999. bool CharacterFunctions::isWhitespace (const char character) throw()
  8000. {
  8001. return character == ' ' || (character <= 13 && character >= 9);
  8002. }
  8003. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8004. {
  8005. return iswspace (character) != 0;
  8006. }
  8007. bool CharacterFunctions::isDigit (const char character) throw()
  8008. {
  8009. return (character >= '0' && character <= '9');
  8010. }
  8011. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8012. {
  8013. return iswdigit (character) != 0;
  8014. }
  8015. bool CharacterFunctions::isLetter (const char character) throw()
  8016. {
  8017. return (character >= 'a' && character <= 'z')
  8018. || (character >= 'A' && character <= 'Z');
  8019. }
  8020. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8021. {
  8022. return iswalpha (character) != 0;
  8023. }
  8024. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8025. {
  8026. return (character >= 'a' && character <= 'z')
  8027. || (character >= 'A' && character <= 'Z')
  8028. || (character >= '0' && character <= '9');
  8029. }
  8030. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8031. {
  8032. return iswalnum (character) != 0;
  8033. }
  8034. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8035. {
  8036. if (digit >= '0' && digit <= '9')
  8037. return digit - '0';
  8038. else if (digit >= 'a' && digit <= 'f')
  8039. return digit - ('a' - 10);
  8040. else if (digit >= 'A' && digit <= 'F')
  8041. return digit - ('A' - 10);
  8042. return -1;
  8043. }
  8044. END_JUCE_NAMESPACE
  8045. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8046. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8047. BEGIN_JUCE_NAMESPACE
  8048. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8049. {
  8050. loadFromText (fileContents);
  8051. }
  8052. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8053. {
  8054. loadFromText (fileToLoad.loadFileAsString());
  8055. }
  8056. LocalisedStrings::~LocalisedStrings()
  8057. {
  8058. }
  8059. const String LocalisedStrings::translate (const String& text) const
  8060. {
  8061. return translations.getValue (text, text);
  8062. }
  8063. static int findCloseQuote (const String& text, int startPos)
  8064. {
  8065. juce_wchar lastChar = 0;
  8066. for (;;)
  8067. {
  8068. const juce_wchar c = text [startPos];
  8069. if (c == 0 || (c == '"' && lastChar != '\\'))
  8070. break;
  8071. lastChar = c;
  8072. ++startPos;
  8073. }
  8074. return startPos;
  8075. }
  8076. static const String unescapeString (const String& s)
  8077. {
  8078. return s.replace ("\\\"", "\"")
  8079. .replace ("\\\'", "\'")
  8080. .replace ("\\t", "\t")
  8081. .replace ("\\r", "\r")
  8082. .replace ("\\n", "\n");
  8083. }
  8084. void LocalisedStrings::loadFromText (const String& fileContents)
  8085. {
  8086. StringArray lines;
  8087. lines.addLines (fileContents);
  8088. for (int i = 0; i < lines.size(); ++i)
  8089. {
  8090. String line (lines[i].trim());
  8091. if (line.startsWithChar ('"'))
  8092. {
  8093. int closeQuote = findCloseQuote (line, 1);
  8094. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8095. if (originalText.isNotEmpty())
  8096. {
  8097. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8098. closeQuote = findCloseQuote (line, openingQuote + 1);
  8099. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8100. if (newText.isNotEmpty())
  8101. translations.set (originalText, newText);
  8102. }
  8103. }
  8104. else if (line.startsWithIgnoreCase ("language:"))
  8105. {
  8106. languageName = line.substring (9).trim();
  8107. }
  8108. else if (line.startsWithIgnoreCase ("countries:"))
  8109. {
  8110. countryCodes.addTokens (line.substring (10).trim(), true);
  8111. countryCodes.trim();
  8112. countryCodes.removeEmptyStrings();
  8113. }
  8114. }
  8115. }
  8116. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8117. {
  8118. translations.setIgnoresCase (shouldIgnoreCase);
  8119. }
  8120. static CriticalSection currentMappingsLock;
  8121. static LocalisedStrings* currentMappings = 0;
  8122. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8123. {
  8124. const ScopedLock sl (currentMappingsLock);
  8125. delete currentMappings;
  8126. currentMappings = newTranslations;
  8127. }
  8128. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8129. {
  8130. return currentMappings;
  8131. }
  8132. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8133. {
  8134. const ScopedLock sl (currentMappingsLock);
  8135. if (currentMappings != 0)
  8136. return currentMappings->translate (text);
  8137. return text;
  8138. }
  8139. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8140. {
  8141. return translateWithCurrentMappings (String (text));
  8142. }
  8143. END_JUCE_NAMESPACE
  8144. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8145. /*** Start of inlined file: juce_String.cpp ***/
  8146. #ifdef _MSC_VER
  8147. #pragma warning (push)
  8148. #pragma warning (disable: 4514)
  8149. #endif
  8150. #include <locale>
  8151. #if JUCE_MSVC
  8152. #include <float.h>
  8153. #endif
  8154. BEGIN_JUCE_NAMESPACE
  8155. #ifdef _MSC_VER
  8156. #pragma warning (pop)
  8157. #endif
  8158. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8159. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8160. #endif
  8161. class StringHolder
  8162. {
  8163. public:
  8164. StringHolder()
  8165. : refCount (0x3fffffff), allocatedNumChars (0)
  8166. {
  8167. text[0] = 0;
  8168. }
  8169. static juce_wchar* createUninitialised (const size_t numChars)
  8170. {
  8171. StringHolder* const s = reinterpret_cast <StringHolder*> (new char [sizeof (StringHolder) + numChars * sizeof (juce_wchar)]);
  8172. s->refCount = 0;
  8173. s->allocatedNumChars = numChars;
  8174. return &(s->text[0]);
  8175. }
  8176. static juce_wchar* createCopy (const juce_wchar* const src, const size_t numChars)
  8177. {
  8178. juce_wchar* const dest = createUninitialised (numChars);
  8179. copyChars (dest, src, numChars);
  8180. return dest;
  8181. }
  8182. static juce_wchar* createCopy (const char* const src, const size_t numChars)
  8183. {
  8184. juce_wchar* const dest = createUninitialised (numChars);
  8185. CharacterFunctions::copy (dest, src, numChars);
  8186. dest [numChars] = 0;
  8187. return dest;
  8188. }
  8189. static inline juce_wchar* getEmpty() throw()
  8190. {
  8191. return &(empty.text[0]);
  8192. }
  8193. static void retain (juce_wchar* const text) throw()
  8194. {
  8195. Atomic::increment (bufferFromText (text)->refCount);
  8196. }
  8197. static inline void release (StringHolder* const b) throw()
  8198. {
  8199. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8200. delete[] reinterpret_cast <char*> (b);
  8201. }
  8202. static void release (juce_wchar* const text) throw()
  8203. {
  8204. release (bufferFromText (text));
  8205. }
  8206. static juce_wchar* makeUnique (juce_wchar* const text)
  8207. {
  8208. StringHolder* const b = bufferFromText (text);
  8209. if (b->refCount <= 0)
  8210. return text;
  8211. juce_wchar* const newText = createCopy (text, b->allocatedNumChars);
  8212. release (b);
  8213. return newText;
  8214. }
  8215. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8216. {
  8217. StringHolder* const b = bufferFromText (text);
  8218. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8219. return text;
  8220. juce_wchar* const newText = createUninitialised (jmax (b->allocatedNumChars, numChars));
  8221. copyChars (newText, text, b->allocatedNumChars);
  8222. release (b);
  8223. return newText;
  8224. }
  8225. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8226. {
  8227. return bufferFromText (text)->allocatedNumChars;
  8228. }
  8229. static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw()
  8230. {
  8231. memcpy (dest, src, numChars * sizeof (juce_wchar));
  8232. dest [numChars] = 0;
  8233. }
  8234. int refCount;
  8235. size_t allocatedNumChars;
  8236. juce_wchar text[1];
  8237. static StringHolder empty;
  8238. private:
  8239. static inline StringHolder* bufferFromText (void* const text) throw()
  8240. {
  8241. // (Can't use offsetof() here because of warnings about this not being a POD)
  8242. return reinterpret_cast <StringHolder*> (static_cast <char*> (text)
  8243. - (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
  8244. }
  8245. };
  8246. StringHolder StringHolder::empty;
  8247. const String String::empty;
  8248. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8249. {
  8250. jassert (t[numChars] == 0); // must have a null terminator
  8251. text = StringHolder::createCopy (t, numChars);
  8252. }
  8253. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8254. {
  8255. if (numExtraChars > 0)
  8256. {
  8257. const int oldLen = length();
  8258. const int newTotalLen = oldLen + numExtraChars;
  8259. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8260. StringHolder::copyChars (text + oldLen, newText, numExtraChars);
  8261. }
  8262. }
  8263. void String::preallocateStorage (const size_t numChars)
  8264. {
  8265. text = StringHolder::makeUniqueWithSize (text, numChars);
  8266. }
  8267. String::String() throw()
  8268. : text (StringHolder::getEmpty())
  8269. {
  8270. }
  8271. String::~String() throw()
  8272. {
  8273. StringHolder::release (text);
  8274. }
  8275. String::String (const String& other) throw()
  8276. : text (other.text)
  8277. {
  8278. StringHolder::retain (text);
  8279. }
  8280. void String::swapWith (String& other) throw()
  8281. {
  8282. swapVariables (text, other.text);
  8283. }
  8284. String& String::operator= (const String& other) throw()
  8285. {
  8286. juce_wchar* const newText = other.text;
  8287. StringHolder::retain (newText);
  8288. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8289. return *this;
  8290. }
  8291. String::String (const size_t numChars, const int /*dummyVariable*/)
  8292. : text (StringHolder::createUninitialised (numChars))
  8293. {
  8294. }
  8295. String::String (const String& stringToCopy, const size_t charsToAllocate)
  8296. {
  8297. const size_t otherSize = StringHolder::getAllocatedNumChars (stringToCopy.text);
  8298. text = StringHolder::createUninitialised (jmax (charsToAllocate, otherSize));
  8299. StringHolder::copyChars (text, stringToCopy.text, otherSize);
  8300. }
  8301. String::String (const char* const t)
  8302. {
  8303. if (t != 0 && *t != 0)
  8304. text = StringHolder::createCopy (t, CharacterFunctions::length (t));
  8305. else
  8306. text = StringHolder::getEmpty();
  8307. }
  8308. String::String (const juce_wchar* const t)
  8309. {
  8310. if (t != 0 && *t != 0)
  8311. text = StringHolder::createCopy (t, CharacterFunctions::length (t));
  8312. else
  8313. text = StringHolder::getEmpty();
  8314. }
  8315. String::String (const char* const t, const size_t maxChars)
  8316. {
  8317. int i;
  8318. for (i = 0; (size_t) i < maxChars; ++i)
  8319. if (t[i] == 0)
  8320. break;
  8321. if (i > 0)
  8322. text = StringHolder::createCopy (t, i);
  8323. else
  8324. text = StringHolder::getEmpty();
  8325. }
  8326. String::String (const juce_wchar* const t, const size_t maxChars)
  8327. {
  8328. int i;
  8329. for (i = 0; (size_t) i < maxChars; ++i)
  8330. if (t[i] == 0)
  8331. break;
  8332. if (i > 0)
  8333. text = StringHolder::createCopy (t, i);
  8334. else
  8335. text = StringHolder::getEmpty();
  8336. }
  8337. const String String::charToString (const juce_wchar character)
  8338. {
  8339. String result ((size_t) 1, (int) 0);
  8340. result.text[0] = character;
  8341. result.text[1] = 0;
  8342. return result;
  8343. }
  8344. namespace NumberToStringConverters
  8345. {
  8346. // pass in a pointer to the END of a buffer..
  8347. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8348. {
  8349. *--t = 0;
  8350. int64 v = (n >= 0) ? n : -n;
  8351. do
  8352. {
  8353. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8354. v /= 10;
  8355. } while (v > 0);
  8356. if (n < 0)
  8357. *--t = '-';
  8358. return t;
  8359. }
  8360. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8361. {
  8362. *--t = 0;
  8363. do
  8364. {
  8365. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8366. v /= 10;
  8367. } while (v > 0);
  8368. return t;
  8369. }
  8370. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8371. {
  8372. if (n == (int) 0x80000000) // (would cause an overflow)
  8373. return int64ToString (t, n);
  8374. *--t = 0;
  8375. int v = abs (n);
  8376. do
  8377. {
  8378. *--t = (juce_wchar) ('0' + (v % 10));
  8379. v /= 10;
  8380. } while (v > 0);
  8381. if (n < 0)
  8382. *--t = '-';
  8383. return t;
  8384. }
  8385. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8386. {
  8387. *--t = 0;
  8388. do
  8389. {
  8390. *--t = (juce_wchar) ('0' + (v % 10));
  8391. v /= 10;
  8392. } while (v > 0);
  8393. return t;
  8394. }
  8395. static juce_wchar getDecimalPoint()
  8396. {
  8397. #if JUCE_WINDOWS && _MSC_VER < 1400
  8398. static juce_wchar dp = std::_USE (std::locale(), std::numpunct <wchar_t>).decimal_point();
  8399. #else
  8400. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8401. #endif
  8402. return dp;
  8403. }
  8404. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8405. {
  8406. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8407. {
  8408. juce_wchar* const end = buffer + numChars;
  8409. juce_wchar* t = end;
  8410. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8411. *--t = (juce_wchar) 0;
  8412. while (numDecPlaces >= 0 || v > 0)
  8413. {
  8414. if (numDecPlaces == 0)
  8415. *--t = getDecimalPoint();
  8416. *--t = (juce_wchar) ('0' + (v % 10));
  8417. v /= 10;
  8418. --numDecPlaces;
  8419. }
  8420. if (n < 0)
  8421. *--t = '-';
  8422. len = end - t - 1;
  8423. return t;
  8424. }
  8425. else
  8426. {
  8427. #if JUCE_WIN32
  8428. #if _MSC_VER <= 1400
  8429. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8430. #else
  8431. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8432. #endif
  8433. #else
  8434. len = swprintf (buffer, numChars, L"%.9g", n);
  8435. #endif
  8436. return buffer;
  8437. }
  8438. }
  8439. }
  8440. String::String (const int number)
  8441. {
  8442. juce_wchar buffer [16];
  8443. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8444. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8445. createInternal (start, end - start - 1);
  8446. }
  8447. String::String (const unsigned int number)
  8448. {
  8449. juce_wchar buffer [16];
  8450. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8451. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8452. createInternal (start, end - start - 1);
  8453. }
  8454. String::String (const short number)
  8455. {
  8456. juce_wchar buffer [16];
  8457. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8458. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8459. createInternal (start, end - start - 1);
  8460. }
  8461. String::String (const unsigned short number)
  8462. {
  8463. juce_wchar buffer [16];
  8464. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8465. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8466. createInternal (start, end - start - 1);
  8467. }
  8468. String::String (const int64 number)
  8469. {
  8470. juce_wchar buffer [32];
  8471. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8472. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8473. createInternal (start, end - start - 1);
  8474. }
  8475. String::String (const uint64 number)
  8476. {
  8477. juce_wchar buffer [32];
  8478. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8479. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8480. createInternal (start, end - start - 1);
  8481. }
  8482. String::String (const float number, const int numberOfDecimalPlaces)
  8483. {
  8484. juce_wchar buffer [48];
  8485. size_t len;
  8486. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8487. createInternal (start, len);
  8488. }
  8489. String::String (const double number, const int numberOfDecimalPlaces)
  8490. {
  8491. juce_wchar buffer [48];
  8492. size_t len;
  8493. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8494. createInternal (start, len);
  8495. }
  8496. int String::length() const throw()
  8497. {
  8498. return CharacterFunctions::length (text);
  8499. }
  8500. int String::hashCode() const throw()
  8501. {
  8502. const juce_wchar* t = text;
  8503. int result = 0;
  8504. while (*t != (juce_wchar) 0)
  8505. result = 31 * result + *t++;
  8506. return result;
  8507. }
  8508. int64 String::hashCode64() const throw()
  8509. {
  8510. const juce_wchar* t = text;
  8511. int64 result = 0;
  8512. while (*t != (juce_wchar) 0)
  8513. result = 101 * result + *t++;
  8514. return result;
  8515. }
  8516. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8517. {
  8518. return string1.compare (string2) == 0;
  8519. }
  8520. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8521. {
  8522. return string1.compare (string2) == 0;
  8523. }
  8524. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8525. {
  8526. return string1.compare (string2) == 0;
  8527. }
  8528. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8529. {
  8530. return string1.compare (string2) != 0;
  8531. }
  8532. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8533. {
  8534. return string1.compare (string2) != 0;
  8535. }
  8536. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8537. {
  8538. return string1.compare (string2) != 0;
  8539. }
  8540. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8541. {
  8542. return string1.compare (string2) > 0;
  8543. }
  8544. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8545. {
  8546. return string1.compare (string2) < 0;
  8547. }
  8548. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8549. {
  8550. return string1.compare (string2) >= 0;
  8551. }
  8552. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8553. {
  8554. return string1.compare (string2) <= 0;
  8555. }
  8556. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8557. {
  8558. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8559. : isEmpty();
  8560. }
  8561. bool String::equalsIgnoreCase (const char* t) const throw()
  8562. {
  8563. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8564. : isEmpty();
  8565. }
  8566. bool String::equalsIgnoreCase (const String& other) const throw()
  8567. {
  8568. return text == other.text
  8569. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8570. }
  8571. int String::compare (const String& other) const throw()
  8572. {
  8573. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8574. }
  8575. int String::compare (const char* other) const throw()
  8576. {
  8577. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8578. }
  8579. int String::compare (const juce_wchar* other) const throw()
  8580. {
  8581. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8582. }
  8583. int String::compareIgnoreCase (const String& other) const throw()
  8584. {
  8585. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8586. }
  8587. int String::compareLexicographically (const String& other) const throw()
  8588. {
  8589. const juce_wchar* s1 = text;
  8590. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8591. ++s1;
  8592. const juce_wchar* s2 = other.text;
  8593. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8594. ++s2;
  8595. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8596. }
  8597. String& String::operator+= (const juce_wchar* const t)
  8598. {
  8599. if (t != 0)
  8600. appendInternal (t, CharacterFunctions::length (t));
  8601. return *this;
  8602. }
  8603. String& String::operator+= (const String& other)
  8604. {
  8605. if (isEmpty())
  8606. operator= (other);
  8607. else
  8608. appendInternal (other.text, other.length());
  8609. return *this;
  8610. }
  8611. String& String::operator+= (const char ch)
  8612. {
  8613. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8614. return operator+= (static_cast <const juce_wchar*> (asString));
  8615. }
  8616. String& String::operator+= (const juce_wchar ch)
  8617. {
  8618. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8619. return operator+= (static_cast <const juce_wchar*> (asString));
  8620. }
  8621. String& String::operator+= (const int number)
  8622. {
  8623. juce_wchar buffer [16];
  8624. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8625. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8626. appendInternal (start, (int) (end - start));
  8627. return *this;
  8628. }
  8629. String& String::operator+= (const unsigned int number)
  8630. {
  8631. juce_wchar buffer [16];
  8632. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8633. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8634. appendInternal (start, (int) (end - start));
  8635. return *this;
  8636. }
  8637. void String::append (const juce_wchar* const other, const int howMany)
  8638. {
  8639. if (howMany > 0)
  8640. {
  8641. int i;
  8642. for (i = 0; i < howMany; ++i)
  8643. if (other[i] == 0)
  8644. break;
  8645. appendInternal (other, i);
  8646. }
  8647. }
  8648. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8649. {
  8650. String s (string1);
  8651. return s += string2;
  8652. }
  8653. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8654. {
  8655. String s (string1);
  8656. return s += string2;
  8657. }
  8658. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8659. {
  8660. return String::charToString (string1) + string2;
  8661. }
  8662. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8663. {
  8664. return String::charToString (string1) + string2;
  8665. }
  8666. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8667. {
  8668. return string1 += string2;
  8669. }
  8670. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8671. {
  8672. return string1 += string2;
  8673. }
  8674. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8675. {
  8676. return string1 += string2;
  8677. }
  8678. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8679. {
  8680. return string1 += string2;
  8681. }
  8682. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8683. {
  8684. return string1 += string2;
  8685. }
  8686. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8687. {
  8688. return string1 += characterToAppend;
  8689. }
  8690. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8691. {
  8692. return string1 += characterToAppend;
  8693. }
  8694. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8695. {
  8696. return string1 += string2;
  8697. }
  8698. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8699. {
  8700. return string1 += string2;
  8701. }
  8702. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8703. {
  8704. return string1 += string2;
  8705. }
  8706. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8707. {
  8708. return string1 += (int) number;
  8709. }
  8710. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8711. {
  8712. return string1 += number;
  8713. }
  8714. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8715. {
  8716. return string1 += number;
  8717. }
  8718. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8719. {
  8720. return string1 += (int) number;
  8721. }
  8722. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8723. {
  8724. return string1 += (unsigned int) number;
  8725. }
  8726. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8727. {
  8728. return string1 += String (number);
  8729. }
  8730. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8731. {
  8732. return string1 += String (number);
  8733. }
  8734. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8735. {
  8736. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8737. // if lots of large, persistent strings were to be written to streams).
  8738. const int numBytes = text.getNumBytesAsUTF8();
  8739. HeapBlock<char> temp (numBytes + 1);
  8740. text.copyToUTF8 (temp, numBytes + 1);
  8741. stream.write (temp, numBytes);
  8742. return stream;
  8743. }
  8744. int String::indexOfChar (const juce_wchar character) const throw()
  8745. {
  8746. const juce_wchar* t = text;
  8747. for (;;)
  8748. {
  8749. if (*t == character)
  8750. return (int) (t - text);
  8751. if (*t++ == 0)
  8752. return -1;
  8753. }
  8754. }
  8755. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8756. {
  8757. for (int i = length(); --i >= 0;)
  8758. if (text[i] == character)
  8759. return i;
  8760. return -1;
  8761. }
  8762. int String::indexOf (const String& t) const throw()
  8763. {
  8764. const juce_wchar* const r = CharacterFunctions::find (text, t.text);
  8765. return r == 0 ? -1 : (int) (r - text);
  8766. }
  8767. int String::indexOfChar (const int startIndex,
  8768. const juce_wchar character) const throw()
  8769. {
  8770. if (startIndex > 0 && startIndex >= length())
  8771. return -1;
  8772. const juce_wchar* t = text + jmax (0, startIndex);
  8773. for (;;)
  8774. {
  8775. if (*t == character)
  8776. return (int) (t - text);
  8777. if (*t == 0)
  8778. return -1;
  8779. ++t;
  8780. }
  8781. }
  8782. int String::indexOfAnyOf (const String& charactersToLookFor,
  8783. const int startIndex,
  8784. const bool ignoreCase) const throw()
  8785. {
  8786. if (startIndex > 0 && startIndex >= length())
  8787. return -1;
  8788. const juce_wchar* t = text + jmax (0, startIndex);
  8789. while (*t != 0)
  8790. {
  8791. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, *t, ignoreCase) >= 0)
  8792. return (int) (t - text);
  8793. ++t;
  8794. }
  8795. return -1;
  8796. }
  8797. int String::indexOf (const int startIndex, const String& other) const throw()
  8798. {
  8799. if (startIndex > 0 && startIndex >= length())
  8800. return -1;
  8801. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other.text);
  8802. return found == 0 ? -1 : (int) (found - text);
  8803. }
  8804. int String::indexOfIgnoreCase (const String& other) const throw()
  8805. {
  8806. if (other.isNotEmpty())
  8807. {
  8808. const int len = other.length();
  8809. const int end = length() - len;
  8810. for (int i = 0; i <= end; ++i)
  8811. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8812. return i;
  8813. }
  8814. return -1;
  8815. }
  8816. int String::indexOfIgnoreCase (const int startIndex, const String& other) const throw()
  8817. {
  8818. if (other.isNotEmpty())
  8819. {
  8820. const int len = other.length();
  8821. const int end = length() - len;
  8822. for (int i = jmax (0, startIndex); i <= end; ++i)
  8823. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8824. return i;
  8825. }
  8826. return -1;
  8827. }
  8828. int String::lastIndexOf (const String& other) const throw()
  8829. {
  8830. if (other.isNotEmpty())
  8831. {
  8832. const int len = other.length();
  8833. int i = length() - len;
  8834. if (i >= 0)
  8835. {
  8836. const juce_wchar* n = text + i;
  8837. while (i >= 0)
  8838. {
  8839. if (CharacterFunctions::compare (n--, other.text, len) == 0)
  8840. return i;
  8841. --i;
  8842. }
  8843. }
  8844. }
  8845. return -1;
  8846. }
  8847. int String::lastIndexOfIgnoreCase (const String& other) const throw()
  8848. {
  8849. if (other.isNotEmpty())
  8850. {
  8851. const int len = other.length();
  8852. int i = length() - len;
  8853. if (i >= 0)
  8854. {
  8855. const juce_wchar* n = text + i;
  8856. while (i >= 0)
  8857. {
  8858. if (CharacterFunctions::compareIgnoreCase (n--, other.text, len) == 0)
  8859. return i;
  8860. --i;
  8861. }
  8862. }
  8863. }
  8864. return -1;
  8865. }
  8866. int String::lastIndexOfAnyOf (const String& charactersToLookFor, const bool ignoreCase) const throw()
  8867. {
  8868. for (int i = length(); --i >= 0;)
  8869. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, text[i], ignoreCase) >= 0)
  8870. return i;
  8871. return -1;
  8872. }
  8873. bool String::contains (const String& other) const throw()
  8874. {
  8875. return indexOf (other) >= 0;
  8876. }
  8877. bool String::containsChar (const juce_wchar character) const throw()
  8878. {
  8879. const juce_wchar* t = text;
  8880. for (;;)
  8881. {
  8882. if (*t == 0)
  8883. return false;
  8884. if (*t == character)
  8885. return true;
  8886. ++t;
  8887. }
  8888. }
  8889. bool String::containsIgnoreCase (const String& t) const throw()
  8890. {
  8891. return indexOfIgnoreCase (t) >= 0;
  8892. }
  8893. int String::indexOfWholeWord (const String& word) const throw()
  8894. {
  8895. if (word.isNotEmpty())
  8896. {
  8897. const int wordLen = word.length();
  8898. const int end = length() - wordLen;
  8899. const juce_wchar* t = text;
  8900. for (int i = 0; i <= end; ++i)
  8901. {
  8902. if (CharacterFunctions::compare (t, word.text, wordLen) == 0
  8903. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8904. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8905. {
  8906. return i;
  8907. }
  8908. ++t;
  8909. }
  8910. }
  8911. return -1;
  8912. }
  8913. int String::indexOfWholeWordIgnoreCase (const String& word) const throw()
  8914. {
  8915. if (word.isNotEmpty())
  8916. {
  8917. const int wordLen = word.length();
  8918. const int end = length() - wordLen;
  8919. const juce_wchar* t = text;
  8920. for (int i = 0; i <= end; ++i)
  8921. {
  8922. if (CharacterFunctions::compareIgnoreCase (t, word.text, wordLen) == 0
  8923. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8924. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8925. {
  8926. return i;
  8927. }
  8928. ++t;
  8929. }
  8930. }
  8931. return -1;
  8932. }
  8933. bool String::containsWholeWord (const String& wordToLookFor) const throw()
  8934. {
  8935. return indexOfWholeWord (wordToLookFor) >= 0;
  8936. }
  8937. bool String::containsWholeWordIgnoreCase (const String& wordToLookFor) const throw()
  8938. {
  8939. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  8940. }
  8941. static int indexOfMatch (const juce_wchar* const wildcard,
  8942. const juce_wchar* const test,
  8943. const bool ignoreCase) throw()
  8944. {
  8945. int start = 0;
  8946. while (test [start] != 0)
  8947. {
  8948. int i = 0;
  8949. for (;;)
  8950. {
  8951. const juce_wchar wc = wildcard [i];
  8952. const juce_wchar c = test [i + start];
  8953. if (wc == c
  8954. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  8955. || (wc == '?' && c != 0))
  8956. {
  8957. if (wc == 0)
  8958. return start;
  8959. ++i;
  8960. }
  8961. else
  8962. {
  8963. if (wc == '*' && (wildcard [i + 1] == 0
  8964. || indexOfMatch (wildcard + i + 1,
  8965. test + start + i,
  8966. ignoreCase) >= 0))
  8967. {
  8968. return start;
  8969. }
  8970. break;
  8971. }
  8972. }
  8973. ++start;
  8974. }
  8975. return -1;
  8976. }
  8977. bool String::matchesWildcard (const String& wildcard, const bool ignoreCase) const throw()
  8978. {
  8979. int i = 0;
  8980. for (;;)
  8981. {
  8982. const juce_wchar wc = wildcard.text [i];
  8983. const juce_wchar c = text [i];
  8984. if (wc == c
  8985. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  8986. || (wc == '?' && c != 0))
  8987. {
  8988. if (wc == 0)
  8989. return true;
  8990. ++i;
  8991. }
  8992. else
  8993. {
  8994. return wc == '*' && (wildcard [i + 1] == 0
  8995. || indexOfMatch (wildcard.text + i + 1,
  8996. text + i,
  8997. ignoreCase) >= 0);
  8998. }
  8999. }
  9000. }
  9001. const String String::repeatedString (const String& stringToRepeat, int numberOfTimesToRepeat)
  9002. {
  9003. const int len = stringToRepeat.length();
  9004. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  9005. juce_wchar* n = result.text;
  9006. *n = 0;
  9007. while (--numberOfTimesToRepeat >= 0)
  9008. {
  9009. StringHolder::copyChars (n, stringToRepeat.text, len);
  9010. n += len;
  9011. }
  9012. return result;
  9013. }
  9014. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9015. {
  9016. jassert (padCharacter != 0);
  9017. const int len = length();
  9018. if (len >= minimumLength || padCharacter == 0)
  9019. return *this;
  9020. String result ((size_t) minimumLength + 1, (int) 0);
  9021. juce_wchar* n = result.text;
  9022. minimumLength -= len;
  9023. while (--minimumLength >= 0)
  9024. *n++ = padCharacter;
  9025. StringHolder::copyChars (n, text, len);
  9026. return result;
  9027. }
  9028. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9029. {
  9030. jassert (padCharacter != 0);
  9031. const int len = length();
  9032. if (len >= minimumLength || padCharacter == 0)
  9033. return *this;
  9034. String result (*this, (size_t) minimumLength);
  9035. juce_wchar* n = result.text + len;
  9036. minimumLength -= len;
  9037. while (--minimumLength >= 0)
  9038. *n++ = padCharacter;
  9039. *n = 0;
  9040. return result;
  9041. }
  9042. const String String::replaceSection (int index, int numCharsToReplace, const String& stringToInsert) const
  9043. {
  9044. if (index < 0)
  9045. {
  9046. // a negative index to replace from?
  9047. jassertfalse
  9048. index = 0;
  9049. }
  9050. if (numCharsToReplace < 0)
  9051. {
  9052. // replacing a negative number of characters?
  9053. numCharsToReplace = 0;
  9054. jassertfalse;
  9055. }
  9056. const int len = length();
  9057. if (index + numCharsToReplace > len)
  9058. {
  9059. if (index > len)
  9060. {
  9061. // replacing beyond the end of the string?
  9062. index = len;
  9063. jassertfalse
  9064. }
  9065. numCharsToReplace = len - index;
  9066. }
  9067. const int newStringLen = stringToInsert.length();
  9068. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9069. if (newTotalLen <= 0)
  9070. return String::empty;
  9071. String result ((size_t) newTotalLen, (int) 0);
  9072. StringHolder::copyChars (result.text, text, index);
  9073. if (newStringLen > 0)
  9074. StringHolder::copyChars (result.text + index, stringToInsert.text, newStringLen);
  9075. const int endStringLen = newTotalLen - (index + newStringLen);
  9076. if (endStringLen > 0)
  9077. StringHolder::copyChars (result.text + (index + newStringLen),
  9078. text + (index + numCharsToReplace),
  9079. endStringLen);
  9080. return result;
  9081. }
  9082. const String String::replace (const String& stringToReplace, const String& stringToInsert, const bool ignoreCase) const
  9083. {
  9084. const int stringToReplaceLen = stringToReplace.length();
  9085. const int stringToInsertLen = stringToInsert.length();
  9086. int i = 0;
  9087. String result (*this);
  9088. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9089. : result.indexOf (i, stringToReplace))) >= 0)
  9090. {
  9091. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9092. i += stringToInsertLen;
  9093. }
  9094. return result;
  9095. }
  9096. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  9097. {
  9098. const int index = indexOfChar (charToReplace);
  9099. if (index < 0)
  9100. return *this;
  9101. String result (*this, size_t());
  9102. juce_wchar* t = result.text + index;
  9103. while (*t != 0)
  9104. {
  9105. if (*t == charToReplace)
  9106. *t = charToInsert;
  9107. ++t;
  9108. }
  9109. return result;
  9110. }
  9111. const String String::replaceCharacters (const String& charactersToReplace,
  9112. const String& charactersToInsertInstead) const
  9113. {
  9114. String result (*this, size_t());
  9115. juce_wchar* t = result.text;
  9116. const int len2 = charactersToInsertInstead.length();
  9117. // the two strings passed in are supposed to be the same length!
  9118. jassert (len2 == charactersToReplace.length());
  9119. while (*t != 0)
  9120. {
  9121. const int index = charactersToReplace.indexOfChar (*t);
  9122. if (((unsigned int) index) < (unsigned int) len2)
  9123. *t = charactersToInsertInstead [index];
  9124. ++t;
  9125. }
  9126. return result;
  9127. }
  9128. bool String::startsWith (const String& other) const throw()
  9129. {
  9130. return CharacterFunctions::compare (text, other.text, other.length()) == 0;
  9131. }
  9132. bool String::startsWithIgnoreCase (const String& other) const throw()
  9133. {
  9134. return CharacterFunctions::compareIgnoreCase (text, other.text, other.length()) == 0;
  9135. }
  9136. bool String::startsWithChar (const juce_wchar character) const throw()
  9137. {
  9138. jassert (character != 0); // strings can't contain a null character!
  9139. return text[0] == character;
  9140. }
  9141. bool String::endsWithChar (const juce_wchar character) const throw()
  9142. {
  9143. jassert (character != 0); // strings can't contain a null character!
  9144. return text[0] != 0
  9145. && text [length() - 1] == character;
  9146. }
  9147. bool String::endsWith (const String& other) const throw()
  9148. {
  9149. const int thisLen = length();
  9150. const int otherLen = other.length();
  9151. return thisLen >= otherLen
  9152. && CharacterFunctions::compare (text + thisLen - otherLen, other.text) == 0;
  9153. }
  9154. bool String::endsWithIgnoreCase (const String& other) const throw()
  9155. {
  9156. const int thisLen = length();
  9157. const int otherLen = other.length();
  9158. return thisLen >= otherLen
  9159. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other.text) == 0;
  9160. }
  9161. const String String::toUpperCase() const
  9162. {
  9163. String result (*this, size_t());
  9164. CharacterFunctions::toUpperCase (result.text);
  9165. return result;
  9166. }
  9167. const String String::toLowerCase() const
  9168. {
  9169. String result (*this, size_t());
  9170. CharacterFunctions::toLowerCase (result.text);
  9171. return result;
  9172. }
  9173. juce_wchar& String::operator[] (const int index)
  9174. {
  9175. jassert (((unsigned int) index) <= (unsigned int) length());
  9176. text = StringHolder::makeUnique (text);
  9177. return text [index];
  9178. }
  9179. juce_wchar String::getLastCharacter() const throw()
  9180. {
  9181. return isEmpty() ? juce_wchar() : text [length() - 1];
  9182. }
  9183. const String String::substring (int start, int end) const
  9184. {
  9185. if (start < 0)
  9186. start = 0;
  9187. else if (end <= start)
  9188. return empty;
  9189. int len = 0;
  9190. while (len <= end && text [len] != 0)
  9191. ++len;
  9192. if (end >= len)
  9193. {
  9194. if (start == 0)
  9195. return *this;
  9196. end = len;
  9197. }
  9198. return String (text + start, end - start);
  9199. }
  9200. const String String::substring (const int start) const
  9201. {
  9202. if (start <= 0)
  9203. return *this;
  9204. const int len = length();
  9205. if (start >= len)
  9206. return empty;
  9207. return String (text + start, len - start);
  9208. }
  9209. const String String::dropLastCharacters (const int numberToDrop) const
  9210. {
  9211. return String (text, jmax (0, length() - numberToDrop));
  9212. }
  9213. const String String::getLastCharacters (const int numCharacters) const
  9214. {
  9215. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9216. }
  9217. const String String::fromFirstOccurrenceOf (const String& sub,
  9218. const bool includeSubString,
  9219. const bool ignoreCase) const
  9220. {
  9221. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9222. : indexOf (sub);
  9223. if (i < 0)
  9224. return empty;
  9225. return substring (includeSubString ? i : i + sub.length());
  9226. }
  9227. const String String::fromLastOccurrenceOf (const String& sub,
  9228. const bool includeSubString,
  9229. const bool ignoreCase) const
  9230. {
  9231. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9232. : lastIndexOf (sub);
  9233. if (i < 0)
  9234. return *this;
  9235. return substring (includeSubString ? i : i + sub.length());
  9236. }
  9237. const String String::upToFirstOccurrenceOf (const String& sub,
  9238. const bool includeSubString,
  9239. const bool ignoreCase) const
  9240. {
  9241. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9242. : indexOf (sub);
  9243. if (i < 0)
  9244. return *this;
  9245. return substring (0, includeSubString ? i + sub.length() : i);
  9246. }
  9247. const String String::upToLastOccurrenceOf (const String& sub,
  9248. const bool includeSubString,
  9249. const bool ignoreCase) const
  9250. {
  9251. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9252. : lastIndexOf (sub);
  9253. if (i < 0)
  9254. return *this;
  9255. return substring (0, includeSubString ? i + sub.length() : i);
  9256. }
  9257. bool String::isQuotedString() const
  9258. {
  9259. const String trimmed (trimStart());
  9260. return trimmed[0] == '"'
  9261. || trimmed[0] == '\'';
  9262. }
  9263. const String String::unquoted() const
  9264. {
  9265. String s (*this);
  9266. if (s.text[0] == '"' || s.text[0] == '\'')
  9267. s = s.substring (1);
  9268. const int lastCharIndex = s.length() - 1;
  9269. if (lastCharIndex >= 0
  9270. && (s [lastCharIndex] == '"' || s[lastCharIndex] == '\''))
  9271. s [lastCharIndex] = 0;
  9272. return s;
  9273. }
  9274. const String String::quoted (const juce_wchar quoteCharacter) const
  9275. {
  9276. if (isEmpty())
  9277. return charToString (quoteCharacter) + quoteCharacter;
  9278. String t (*this);
  9279. if (! t.startsWithChar (quoteCharacter))
  9280. t = charToString (quoteCharacter) + t;
  9281. if (! t.endsWithChar (quoteCharacter))
  9282. t += quoteCharacter;
  9283. return t;
  9284. }
  9285. const String String::trim() const
  9286. {
  9287. if (isEmpty())
  9288. return empty;
  9289. int start = 0;
  9290. while (CharacterFunctions::isWhitespace (text [start]))
  9291. ++start;
  9292. const int len = length();
  9293. int end = len - 1;
  9294. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9295. --end;
  9296. ++end;
  9297. if (end <= start)
  9298. return empty;
  9299. else if (start > 0 || end < len)
  9300. return String (text + start, end - start);
  9301. return *this;
  9302. }
  9303. const String String::trimStart() const
  9304. {
  9305. if (isEmpty())
  9306. return empty;
  9307. const juce_wchar* t = text;
  9308. while (CharacterFunctions::isWhitespace (*t))
  9309. ++t;
  9310. if (t == text)
  9311. return *this;
  9312. return String (t);
  9313. }
  9314. const String String::trimEnd() const
  9315. {
  9316. if (isEmpty())
  9317. return empty;
  9318. const juce_wchar* endT = text + (length() - 1);
  9319. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9320. --endT;
  9321. return String (text, (int) (++endT - text));
  9322. }
  9323. const String String::trimCharactersAtStart (const String& charactersToTrim) const
  9324. {
  9325. const juce_wchar* t = text;
  9326. while (charactersToTrim.containsChar (*t))
  9327. ++t;
  9328. if (t == text)
  9329. return *this;
  9330. return String (t);
  9331. }
  9332. const String String::trimCharactersAtEnd (const String& charactersToTrim) const
  9333. {
  9334. if (isEmpty())
  9335. return empty;
  9336. const juce_wchar* endT = text + (length() - 1);
  9337. while (endT >= text && charactersToTrim.containsChar (*endT))
  9338. --endT;
  9339. return String (text, (int) (++endT - text));
  9340. }
  9341. const String String::retainCharacters (const String& charactersToRetain) const
  9342. {
  9343. if (isEmpty())
  9344. return empty;
  9345. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9346. juce_wchar* dst = result.text;
  9347. const juce_wchar* src = text;
  9348. while (*src != 0)
  9349. {
  9350. if (charactersToRetain.containsChar (*src))
  9351. *dst++ = *src;
  9352. ++src;
  9353. }
  9354. *dst = 0;
  9355. return result;
  9356. }
  9357. const String String::removeCharacters (const String& charactersToRemove) const
  9358. {
  9359. if (isEmpty())
  9360. return empty;
  9361. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9362. juce_wchar* dst = result.text;
  9363. const juce_wchar* src = text;
  9364. while (*src != 0)
  9365. {
  9366. if (! charactersToRemove.containsChar (*src))
  9367. *dst++ = *src;
  9368. ++src;
  9369. }
  9370. *dst = 0;
  9371. return result;
  9372. }
  9373. const String String::initialSectionContainingOnly (const String& permittedCharacters) const
  9374. {
  9375. int i = 0;
  9376. for (;;)
  9377. {
  9378. if (! permittedCharacters.containsChar (text[i]))
  9379. break;
  9380. ++i;
  9381. }
  9382. return substring (0, i);
  9383. }
  9384. const String String::initialSectionNotContaining (const String& charactersToStopAt) const
  9385. {
  9386. const juce_wchar* const t = text;
  9387. int i = 0;
  9388. while (t[i] != 0)
  9389. {
  9390. if (charactersToStopAt.containsChar (t[i]))
  9391. return String (text, i);
  9392. ++i;
  9393. }
  9394. return empty;
  9395. }
  9396. bool String::containsOnly (const String& chars) const throw()
  9397. {
  9398. const juce_wchar* t = text;
  9399. while (*t != 0)
  9400. if (! chars.containsChar (*t++))
  9401. return false;
  9402. return true;
  9403. }
  9404. bool String::containsAnyOf (const String& chars) const throw()
  9405. {
  9406. const juce_wchar* t = text;
  9407. while (*t != 0)
  9408. if (chars.containsChar (*t++))
  9409. return true;
  9410. return false;
  9411. }
  9412. bool String::containsNonWhitespaceChars() const throw()
  9413. {
  9414. const juce_wchar* t = text;
  9415. while (*t != 0)
  9416. if (! CharacterFunctions::isWhitespace (*t++))
  9417. return true;
  9418. return false;
  9419. }
  9420. const String String::formatted (const juce_wchar* const pf, ... )
  9421. {
  9422. jassert (pf != 0);
  9423. va_list args;
  9424. va_start (args, pf);
  9425. size_t bufferSize = 256;
  9426. String result (bufferSize, (int) 0);
  9427. result.text[0] = 0;
  9428. for (;;)
  9429. {
  9430. #if JUCE_LINUX && JUCE_64BIT
  9431. va_list tempArgs;
  9432. va_copy (tempArgs, args);
  9433. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, tempArgs);
  9434. va_end (tempArgs);
  9435. #elif JUCE_WINDOWS
  9436. #ifdef _MSC_VER
  9437. #pragma warning (push)
  9438. #pragma warning (disable: 4996)
  9439. #endif
  9440. const int num = (int) _vsnwprintf (result.text, bufferSize - 1, pf, args);
  9441. #ifdef _MSC_VER
  9442. #pragma warning (pop)
  9443. #endif
  9444. #else
  9445. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, args);
  9446. #endif
  9447. if (num > 0)
  9448. return result;
  9449. bufferSize += 256;
  9450. if (num == 0 || bufferSize > 65536) // the upper limit is a sanity check to avoid situations where vprintf repeatedly
  9451. break; // returns -1 because of an error rather than because it needs more space.
  9452. result.preallocateStorage (bufferSize);
  9453. }
  9454. return empty;
  9455. }
  9456. int String::getIntValue() const throw()
  9457. {
  9458. return CharacterFunctions::getIntValue (text);
  9459. }
  9460. int String::getTrailingIntValue() const throw()
  9461. {
  9462. int n = 0;
  9463. int mult = 1;
  9464. const juce_wchar* t = text + length();
  9465. while (--t >= text)
  9466. {
  9467. const juce_wchar c = *t;
  9468. if (! CharacterFunctions::isDigit (c))
  9469. {
  9470. if (c == '-')
  9471. n = -n;
  9472. break;
  9473. }
  9474. n += mult * (c - '0');
  9475. mult *= 10;
  9476. }
  9477. return n;
  9478. }
  9479. int64 String::getLargeIntValue() const throw()
  9480. {
  9481. return CharacterFunctions::getInt64Value (text);
  9482. }
  9483. float String::getFloatValue() const throw()
  9484. {
  9485. return (float) CharacterFunctions::getDoubleValue (text);
  9486. }
  9487. double String::getDoubleValue() const throw()
  9488. {
  9489. return CharacterFunctions::getDoubleValue (text);
  9490. }
  9491. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9492. const String String::toHexString (const int number)
  9493. {
  9494. juce_wchar buffer[32];
  9495. juce_wchar* const end = buffer + 32;
  9496. juce_wchar* t = end;
  9497. *--t = 0;
  9498. unsigned int v = (unsigned int) number;
  9499. do
  9500. {
  9501. *--t = hexDigits [v & 15];
  9502. v >>= 4;
  9503. } while (v != 0);
  9504. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9505. }
  9506. const String String::toHexString (const int64 number)
  9507. {
  9508. juce_wchar buffer[32];
  9509. juce_wchar* const end = buffer + 32;
  9510. juce_wchar* t = end;
  9511. *--t = 0;
  9512. uint64 v = (uint64) number;
  9513. do
  9514. {
  9515. *--t = hexDigits [(int) (v & 15)];
  9516. v >>= 4;
  9517. } while (v != 0);
  9518. return String (t, (int) (((char*) end) - (char*) t));
  9519. }
  9520. const String String::toHexString (const short number)
  9521. {
  9522. return toHexString ((int) (unsigned short) number);
  9523. }
  9524. const String String::toHexString (const unsigned char* data,
  9525. const int size,
  9526. const int groupSize)
  9527. {
  9528. if (size <= 0)
  9529. return empty;
  9530. int numChars = (size * 2) + 2;
  9531. if (groupSize > 0)
  9532. numChars += size / groupSize;
  9533. String s ((size_t) numChars, (int) 0);
  9534. juce_wchar* d = s.text;
  9535. for (int i = 0; i < size; ++i)
  9536. {
  9537. *d++ = hexDigits [(*data) >> 4];
  9538. *d++ = hexDigits [(*data) & 0xf];
  9539. ++data;
  9540. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9541. *d++ = ' ';
  9542. }
  9543. *d = 0;
  9544. return s;
  9545. }
  9546. int String::getHexValue32() const throw()
  9547. {
  9548. int result = 0;
  9549. const juce_wchar* c = text;
  9550. for (;;)
  9551. {
  9552. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9553. if (hexValue >= 0)
  9554. result = (result << 4) | hexValue;
  9555. else if (*c == 0)
  9556. break;
  9557. ++c;
  9558. }
  9559. return result;
  9560. }
  9561. int64 String::getHexValue64() const throw()
  9562. {
  9563. int64 result = 0;
  9564. const juce_wchar* c = text;
  9565. for (;;)
  9566. {
  9567. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9568. if (hexValue >= 0)
  9569. result = (result << 4) | hexValue;
  9570. else if (*c == 0)
  9571. break;
  9572. ++c;
  9573. }
  9574. return result;
  9575. }
  9576. const String String::createStringFromData (const void* const data_, const int size)
  9577. {
  9578. const char* const data = static_cast <const char*> (data_);
  9579. if (size <= 0 || data == 0)
  9580. {
  9581. return empty;
  9582. }
  9583. else if (size < 2)
  9584. {
  9585. return charToString (data[0]);
  9586. }
  9587. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9588. || (data[0] == (char)-1 && data[1] == (char)-2))
  9589. {
  9590. // assume it's 16-bit unicode
  9591. const bool bigEndian = (data[0] == (char)-2);
  9592. const int numChars = size / 2 - 1;
  9593. String result;
  9594. result.preallocateStorage (numChars + 2);
  9595. const uint16* const src = (const uint16*) (data + 2);
  9596. juce_wchar* const dst = const_cast <juce_wchar*> (static_cast <const juce_wchar*> (result));
  9597. if (bigEndian)
  9598. {
  9599. for (int i = 0; i < numChars; ++i)
  9600. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9601. }
  9602. else
  9603. {
  9604. for (int i = 0; i < numChars; ++i)
  9605. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9606. }
  9607. dst [numChars] = 0;
  9608. return result;
  9609. }
  9610. else
  9611. {
  9612. return String::fromUTF8 (data, size);
  9613. }
  9614. }
  9615. const char* String::toUTF8() const
  9616. {
  9617. if (isEmpty())
  9618. {
  9619. return reinterpret_cast <const char*> (text);
  9620. }
  9621. else
  9622. {
  9623. const int currentLen = length() + 1;
  9624. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9625. String* const mutableThis = const_cast <String*> (this);
  9626. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9627. char* const otherCopy = reinterpret_cast <char*> (mutableThis->text + currentLen);
  9628. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9629. return otherCopy;
  9630. }
  9631. }
  9632. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9633. {
  9634. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9635. int num = 0, index = 0;
  9636. for (;;)
  9637. {
  9638. const uint32 c = (uint32) text [index++];
  9639. if (c >= 0x80)
  9640. {
  9641. int numExtraBytes = 1;
  9642. if (c >= 0x800)
  9643. {
  9644. ++numExtraBytes;
  9645. if (c >= 0x10000)
  9646. {
  9647. ++numExtraBytes;
  9648. if (c >= 0x200000)
  9649. {
  9650. ++numExtraBytes;
  9651. if (c >= 0x4000000)
  9652. ++numExtraBytes;
  9653. }
  9654. }
  9655. }
  9656. if (buffer != 0)
  9657. {
  9658. if (num + numExtraBytes >= maxBufferSizeBytes)
  9659. {
  9660. buffer [num++] = 0;
  9661. break;
  9662. }
  9663. else
  9664. {
  9665. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9666. while (--numExtraBytes >= 0)
  9667. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9668. }
  9669. }
  9670. else
  9671. {
  9672. num += numExtraBytes + 1;
  9673. }
  9674. }
  9675. else
  9676. {
  9677. if (buffer != 0)
  9678. {
  9679. if (num + 1 >= maxBufferSizeBytes)
  9680. {
  9681. buffer [num++] = 0;
  9682. break;
  9683. }
  9684. buffer [num] = (uint8) c;
  9685. }
  9686. ++num;
  9687. }
  9688. if (c == 0)
  9689. break;
  9690. }
  9691. return num;
  9692. }
  9693. int String::getNumBytesAsUTF8() const throw()
  9694. {
  9695. int num = 0;
  9696. const juce_wchar* t = text;
  9697. for (;;)
  9698. {
  9699. const uint32 c = (uint32) *t;
  9700. if (c >= 0x80)
  9701. {
  9702. ++num;
  9703. if (c >= 0x800)
  9704. {
  9705. ++num;
  9706. if (c >= 0x10000)
  9707. {
  9708. ++num;
  9709. if (c >= 0x200000)
  9710. {
  9711. ++num;
  9712. if (c >= 0x4000000)
  9713. ++num;
  9714. }
  9715. }
  9716. }
  9717. }
  9718. else if (c == 0)
  9719. break;
  9720. ++num;
  9721. ++t;
  9722. }
  9723. return num;
  9724. }
  9725. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9726. {
  9727. if (buffer == 0)
  9728. return empty;
  9729. if (bufferSizeBytes < 0)
  9730. bufferSizeBytes = std::numeric_limits<int>::max();
  9731. size_t numBytes;
  9732. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9733. if (buffer [numBytes] == 0)
  9734. break;
  9735. String result ((size_t) numBytes + 1, (int) 0);
  9736. juce_wchar* dest = result.text;
  9737. size_t i = 0;
  9738. while (i < numBytes)
  9739. {
  9740. const char c = buffer [i++];
  9741. if (c < 0)
  9742. {
  9743. unsigned int mask = 0x7f;
  9744. int bit = 0x40;
  9745. int numExtraValues = 0;
  9746. while (bit != 0 && (c & bit) != 0)
  9747. {
  9748. bit >>= 1;
  9749. mask >>= 1;
  9750. ++numExtraValues;
  9751. }
  9752. int n = (mask & (unsigned char) c);
  9753. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9754. {
  9755. const char nextByte = buffer[i];
  9756. if ((nextByte & 0xc0) != 0x80)
  9757. break;
  9758. n <<= 6;
  9759. n |= (nextByte & 0x3f);
  9760. ++i;
  9761. }
  9762. *dest++ = (juce_wchar) n;
  9763. }
  9764. else
  9765. {
  9766. *dest++ = (juce_wchar) c;
  9767. }
  9768. }
  9769. *dest = 0;
  9770. return result;
  9771. }
  9772. const char* String::toCString() const
  9773. {
  9774. if (isEmpty())
  9775. {
  9776. return reinterpret_cast <const char*> (text);
  9777. }
  9778. else
  9779. {
  9780. const int len = length();
  9781. String* const mutableThis = const_cast <String*> (this);
  9782. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9783. char* otherCopy = reinterpret_cast <char*> (mutableThis->text + len + 1);
  9784. CharacterFunctions::copy (otherCopy, text, len);
  9785. otherCopy [len] = 0;
  9786. return otherCopy;
  9787. }
  9788. }
  9789. #ifdef _MSC_VER
  9790. #pragma warning (disable: 4514 4996)
  9791. #pragma warning (push)
  9792. #endif
  9793. int String::getNumBytesAsCString() const throw()
  9794. {
  9795. return (int) wcstombs (0, text, 0);
  9796. }
  9797. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9798. {
  9799. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9800. if (destBuffer != 0 && numBytes >= 0)
  9801. destBuffer [numBytes] = 0;
  9802. return numBytes;
  9803. }
  9804. #ifdef _MSC_VER
  9805. #pragma warning (pop)
  9806. #endif
  9807. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  9808. {
  9809. StringHolder::copyChars (destBuffer, text, jmin (maxCharsToCopy, length()));
  9810. }
  9811. String::Concatenator::Concatenator (String& stringToAppendTo)
  9812. : result (stringToAppendTo),
  9813. nextIndex (stringToAppendTo.length())
  9814. {
  9815. }
  9816. String::Concatenator::~Concatenator()
  9817. {
  9818. }
  9819. void String::Concatenator::append (const String& s)
  9820. {
  9821. const int len = s.length();
  9822. if (len > 0)
  9823. {
  9824. result.preallocateStorage (nextIndex + len);
  9825. s.copyToUnicode (static_cast <juce_wchar*> (result) + nextIndex, len);
  9826. nextIndex += len;
  9827. }
  9828. }
  9829. END_JUCE_NAMESPACE
  9830. /*** End of inlined file: juce_String.cpp ***/
  9831. /*** Start of inlined file: juce_StringArray.cpp ***/
  9832. BEGIN_JUCE_NAMESPACE
  9833. StringArray::StringArray() throw()
  9834. {
  9835. }
  9836. StringArray::StringArray (const StringArray& other)
  9837. : strings (other.strings)
  9838. {
  9839. }
  9840. StringArray::StringArray (const String& firstValue)
  9841. {
  9842. strings.add (firstValue);
  9843. }
  9844. StringArray::StringArray (const juce_wchar** const initialStrings,
  9845. const int numberOfStrings)
  9846. {
  9847. for (int i = 0; i < numberOfStrings; ++i)
  9848. strings.add (initialStrings [i]);
  9849. }
  9850. StringArray::StringArray (const char** const initialStrings,
  9851. const int numberOfStrings)
  9852. {
  9853. for (int i = 0; i < numberOfStrings; ++i)
  9854. strings.add (initialStrings [i]);
  9855. }
  9856. StringArray::StringArray (const juce_wchar** const initialStrings)
  9857. {
  9858. int i = 0;
  9859. while (initialStrings[i] != 0)
  9860. strings.add (initialStrings [i++]);
  9861. }
  9862. StringArray::StringArray (const char** const initialStrings)
  9863. {
  9864. int i = 0;
  9865. while (initialStrings[i] != 0)
  9866. strings.add (initialStrings [i++]);
  9867. }
  9868. StringArray& StringArray::operator= (const StringArray& other)
  9869. {
  9870. strings = other.strings;
  9871. return *this;
  9872. }
  9873. StringArray::~StringArray()
  9874. {
  9875. }
  9876. bool StringArray::operator== (const StringArray& other) const throw()
  9877. {
  9878. if (other.size() != size())
  9879. return false;
  9880. for (int i = size(); --i >= 0;)
  9881. if (other.strings.getReference(i) != strings.getReference(i))
  9882. return false;
  9883. return true;
  9884. }
  9885. bool StringArray::operator!= (const StringArray& other) const throw()
  9886. {
  9887. return ! operator== (other);
  9888. }
  9889. void StringArray::clear()
  9890. {
  9891. strings.clear();
  9892. }
  9893. const String& StringArray::operator[] (const int index) const throw()
  9894. {
  9895. if (((unsigned int) index) < (unsigned int) strings.size())
  9896. return strings.getReference (index);
  9897. return String::empty;
  9898. }
  9899. void StringArray::add (const String& newString)
  9900. {
  9901. strings.add (newString);
  9902. }
  9903. void StringArray::insert (const int index, const String& newString)
  9904. {
  9905. strings.insert (index, newString);
  9906. }
  9907. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  9908. {
  9909. if (! contains (newString, ignoreCase))
  9910. add (newString);
  9911. }
  9912. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  9913. {
  9914. if (startIndex < 0)
  9915. {
  9916. jassertfalse
  9917. startIndex = 0;
  9918. }
  9919. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  9920. numElementsToAdd = otherArray.size() - startIndex;
  9921. while (--numElementsToAdd >= 0)
  9922. strings.add (otherArray.strings.getReference (startIndex++));
  9923. }
  9924. void StringArray::set (const int index, const String& newString)
  9925. {
  9926. strings.set (index, newString);
  9927. }
  9928. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  9929. {
  9930. if (ignoreCase)
  9931. {
  9932. for (int i = size(); --i >= 0;)
  9933. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  9934. return true;
  9935. }
  9936. else
  9937. {
  9938. for (int i = size(); --i >= 0;)
  9939. if (stringToLookFor == strings.getReference(i))
  9940. return true;
  9941. }
  9942. return false;
  9943. }
  9944. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  9945. {
  9946. if (i < 0)
  9947. i = 0;
  9948. const int numElements = size();
  9949. if (ignoreCase)
  9950. {
  9951. while (i < numElements)
  9952. {
  9953. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  9954. return i;
  9955. ++i;
  9956. }
  9957. }
  9958. else
  9959. {
  9960. while (i < numElements)
  9961. {
  9962. if (stringToLookFor == strings.getReference (i))
  9963. return i;
  9964. ++i;
  9965. }
  9966. }
  9967. return -1;
  9968. }
  9969. void StringArray::remove (const int index)
  9970. {
  9971. strings.remove (index);
  9972. }
  9973. void StringArray::removeString (const String& stringToRemove,
  9974. const bool ignoreCase)
  9975. {
  9976. if (ignoreCase)
  9977. {
  9978. for (int i = size(); --i >= 0;)
  9979. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  9980. strings.remove (i);
  9981. }
  9982. else
  9983. {
  9984. for (int i = size(); --i >= 0;)
  9985. if (stringToRemove == strings.getReference (i))
  9986. strings.remove (i);
  9987. }
  9988. }
  9989. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  9990. {
  9991. if (removeWhitespaceStrings)
  9992. {
  9993. for (int i = size(); --i >= 0;)
  9994. if (! strings.getReference(i).containsNonWhitespaceChars())
  9995. strings.remove (i);
  9996. }
  9997. else
  9998. {
  9999. for (int i = size(); --i >= 0;)
  10000. if (strings.getReference(i).isEmpty())
  10001. strings.remove (i);
  10002. }
  10003. }
  10004. void StringArray::trim()
  10005. {
  10006. for (int i = size(); --i >= 0;)
  10007. {
  10008. String& s = strings.getReference(i);
  10009. s = s.trim();
  10010. }
  10011. }
  10012. class InternalStringArrayComparator_CaseSensitive
  10013. {
  10014. public:
  10015. static int compareElements (String& first, String& second) { return first.compare (second); }
  10016. };
  10017. class InternalStringArrayComparator_CaseInsensitive
  10018. {
  10019. public:
  10020. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10021. };
  10022. void StringArray::sort (const bool ignoreCase)
  10023. {
  10024. if (ignoreCase)
  10025. {
  10026. InternalStringArrayComparator_CaseInsensitive comp;
  10027. strings.sort (comp);
  10028. }
  10029. else
  10030. {
  10031. InternalStringArrayComparator_CaseSensitive comp;
  10032. strings.sort (comp);
  10033. }
  10034. }
  10035. void StringArray::move (const int currentIndex, int newIndex) throw()
  10036. {
  10037. strings.move (currentIndex, newIndex);
  10038. }
  10039. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10040. {
  10041. const int last = (numberToJoin < 0) ? size()
  10042. : jmin (size(), start + numberToJoin);
  10043. if (start < 0)
  10044. start = 0;
  10045. if (start >= last)
  10046. return String::empty;
  10047. if (start == last - 1)
  10048. return strings.getReference (start);
  10049. const int separatorLen = separator.length();
  10050. int charsNeeded = separatorLen * (last - start - 1);
  10051. for (int i = start; i < last; ++i)
  10052. charsNeeded += strings.getReference(i).length();
  10053. String result;
  10054. result.preallocateStorage (charsNeeded);
  10055. juce_wchar* dest = result;
  10056. while (start < last)
  10057. {
  10058. const String& s = strings.getReference (start);
  10059. const int len = s.length();
  10060. if (len > 0)
  10061. {
  10062. s.copyToUnicode (dest, len);
  10063. dest += len;
  10064. }
  10065. if (++start < last && separatorLen > 0)
  10066. {
  10067. separator.copyToUnicode (dest, separatorLen);
  10068. dest += separatorLen;
  10069. }
  10070. }
  10071. *dest = 0;
  10072. return result;
  10073. }
  10074. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  10075. {
  10076. return addTokens (text, " \n\r\t", preserveQuotedStrings ? "\"" : "");
  10077. }
  10078. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  10079. {
  10080. int num = 0;
  10081. if (text.isNotEmpty())
  10082. {
  10083. bool insideQuotes = false;
  10084. juce_wchar currentQuoteChar = 0;
  10085. int i = 0;
  10086. int tokenStart = 0;
  10087. for (;;)
  10088. {
  10089. const juce_wchar c = text[i];
  10090. const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c));
  10091. if (! isBreak)
  10092. {
  10093. if (quoteCharacters.containsChar (c))
  10094. {
  10095. if (insideQuotes)
  10096. {
  10097. // only break out of quotes-mode if we find a matching quote to the
  10098. // one that we opened with..
  10099. if (currentQuoteChar == c)
  10100. insideQuotes = false;
  10101. }
  10102. else
  10103. {
  10104. insideQuotes = true;
  10105. currentQuoteChar = c;
  10106. }
  10107. }
  10108. }
  10109. else
  10110. {
  10111. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  10112. ++num;
  10113. tokenStart = i + 1;
  10114. }
  10115. if (c == 0)
  10116. break;
  10117. ++i;
  10118. }
  10119. }
  10120. return num;
  10121. }
  10122. int StringArray::addLines (const String& sourceText)
  10123. {
  10124. int numLines = 0;
  10125. const juce_wchar* text = sourceText;
  10126. while (*text != 0)
  10127. {
  10128. const juce_wchar* const startOfLine = text;
  10129. while (*text != 0)
  10130. {
  10131. if (*text == '\r')
  10132. {
  10133. ++text;
  10134. if (*text == '\n')
  10135. ++text;
  10136. break;
  10137. }
  10138. if (*text == '\n')
  10139. {
  10140. ++text;
  10141. break;
  10142. }
  10143. ++text;
  10144. }
  10145. const juce_wchar* endOfLine = text;
  10146. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10147. --endOfLine;
  10148. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10149. --endOfLine;
  10150. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10151. ++numLines;
  10152. }
  10153. return numLines;
  10154. }
  10155. void StringArray::removeDuplicates (const bool ignoreCase)
  10156. {
  10157. for (int i = 0; i < size() - 1; ++i)
  10158. {
  10159. const String s (strings.getReference(i));
  10160. int nextIndex = i + 1;
  10161. for (;;)
  10162. {
  10163. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10164. if (nextIndex < 0)
  10165. break;
  10166. strings.remove (nextIndex);
  10167. }
  10168. }
  10169. }
  10170. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10171. const bool appendNumberToFirstInstance,
  10172. const juce_wchar* preNumberString,
  10173. const juce_wchar* postNumberString)
  10174. {
  10175. if (preNumberString == 0)
  10176. preNumberString = T(" (");
  10177. if (postNumberString == 0)
  10178. postNumberString = T(")");
  10179. for (int i = 0; i < size() - 1; ++i)
  10180. {
  10181. String& s = strings.getReference(i);
  10182. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10183. if (nextIndex >= 0)
  10184. {
  10185. const String original (s);
  10186. int number = 0;
  10187. if (appendNumberToFirstInstance)
  10188. s = original + preNumberString + String (++number) + postNumberString;
  10189. else
  10190. ++number;
  10191. while (nextIndex >= 0)
  10192. {
  10193. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10194. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10195. }
  10196. }
  10197. }
  10198. }
  10199. void StringArray::minimiseStorageOverheads()
  10200. {
  10201. strings.minimiseStorageOverheads();
  10202. }
  10203. END_JUCE_NAMESPACE
  10204. /*** End of inlined file: juce_StringArray.cpp ***/
  10205. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10206. BEGIN_JUCE_NAMESPACE
  10207. StringPairArray::StringPairArray (const bool ignoreCase_)
  10208. : ignoreCase (ignoreCase_)
  10209. {
  10210. }
  10211. StringPairArray::StringPairArray (const StringPairArray& other)
  10212. : keys (other.keys),
  10213. values (other.values),
  10214. ignoreCase (other.ignoreCase)
  10215. {
  10216. }
  10217. StringPairArray::~StringPairArray()
  10218. {
  10219. }
  10220. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  10221. {
  10222. keys = other.keys;
  10223. values = other.values;
  10224. return *this;
  10225. }
  10226. bool StringPairArray::operator== (const StringPairArray& other) const
  10227. {
  10228. for (int i = keys.size(); --i >= 0;)
  10229. if (other [keys[i]] != values[i])
  10230. return false;
  10231. return true;
  10232. }
  10233. bool StringPairArray::operator!= (const StringPairArray& other) const
  10234. {
  10235. return ! operator== (other);
  10236. }
  10237. const String& StringPairArray::operator[] (const String& key) const
  10238. {
  10239. return values [keys.indexOf (key, ignoreCase)];
  10240. }
  10241. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10242. {
  10243. const int i = keys.indexOf (key, ignoreCase);
  10244. if (i >= 0)
  10245. return values[i];
  10246. return defaultReturnValue;
  10247. }
  10248. void StringPairArray::set (const String& key, const String& value)
  10249. {
  10250. const int i = keys.indexOf (key, ignoreCase);
  10251. if (i >= 0)
  10252. {
  10253. values.set (i, value);
  10254. }
  10255. else
  10256. {
  10257. keys.add (key);
  10258. values.add (value);
  10259. }
  10260. }
  10261. void StringPairArray::addArray (const StringPairArray& other)
  10262. {
  10263. for (int i = 0; i < other.size(); ++i)
  10264. set (other.keys[i], other.values[i]);
  10265. }
  10266. void StringPairArray::clear()
  10267. {
  10268. keys.clear();
  10269. values.clear();
  10270. }
  10271. void StringPairArray::remove (const String& key)
  10272. {
  10273. remove (keys.indexOf (key, ignoreCase));
  10274. }
  10275. void StringPairArray::remove (const int index)
  10276. {
  10277. keys.remove (index);
  10278. values.remove (index);
  10279. }
  10280. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  10281. {
  10282. ignoreCase = shouldIgnoreCase;
  10283. }
  10284. const String StringPairArray::getDescription() const
  10285. {
  10286. String s;
  10287. for (int i = 0; i < keys.size(); ++i)
  10288. {
  10289. s << keys[i] << " = " << values[i];
  10290. if (i < keys.size())
  10291. s << ", ";
  10292. }
  10293. return s;
  10294. }
  10295. void StringPairArray::minimiseStorageOverheads()
  10296. {
  10297. keys.minimiseStorageOverheads();
  10298. values.minimiseStorageOverheads();
  10299. }
  10300. END_JUCE_NAMESPACE
  10301. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10302. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10303. BEGIN_JUCE_NAMESPACE
  10304. XmlDocument::XmlDocument (const String& documentText)
  10305. : originalText (documentText),
  10306. ignoreEmptyTextElements (true)
  10307. {
  10308. }
  10309. XmlDocument::XmlDocument (const File& file)
  10310. : ignoreEmptyTextElements (true)
  10311. {
  10312. inputSource = new FileInputSource (file);
  10313. }
  10314. XmlDocument::~XmlDocument()
  10315. {
  10316. }
  10317. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10318. {
  10319. inputSource = newSource;
  10320. }
  10321. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10322. {
  10323. ignoreEmptyTextElements = shouldBeIgnored;
  10324. }
  10325. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10326. {
  10327. return CharacterFunctions::isLetterOrDigit (c)
  10328. || c == '_' || c == '-' || c == ':' || c == '.';
  10329. }
  10330. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10331. {
  10332. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10333. : isXmlIdentifierCharSlow (c);
  10334. }
  10335. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10336. {
  10337. String textToParse (originalText);
  10338. if (textToParse.isEmpty() && inputSource != 0)
  10339. {
  10340. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10341. if (in != 0)
  10342. {
  10343. MemoryBlock data;
  10344. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10345. if (data.getSize() >= 2
  10346. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10347. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10348. {
  10349. textToParse = String::createStringFromData (static_cast <const char*> (data.getData()), (int) data.getSize());
  10350. }
  10351. else
  10352. {
  10353. textToParse = String::fromUTF8 (static_cast <const char*> (data.getData()), (int) data.getSize());
  10354. }
  10355. if (! onlyReadOuterDocumentElement)
  10356. originalText = textToParse;
  10357. }
  10358. }
  10359. input = textToParse;
  10360. lastError = String::empty;
  10361. errorOccurred = false;
  10362. outOfData = false;
  10363. needToLoadDTD = true;
  10364. for (int i = 0; i < 128; ++i)
  10365. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10366. if (textToParse.isEmpty())
  10367. {
  10368. lastError = "not enough input";
  10369. }
  10370. else
  10371. {
  10372. skipHeader();
  10373. if (input != 0)
  10374. {
  10375. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10376. if (! errorOccurred)
  10377. return result.release();
  10378. }
  10379. else
  10380. {
  10381. lastError = "incorrect xml header";
  10382. }
  10383. }
  10384. return 0;
  10385. }
  10386. const String& XmlDocument::getLastParseError() const throw()
  10387. {
  10388. return lastError;
  10389. }
  10390. void XmlDocument::setLastError (const String& desc, const bool carryOn)
  10391. {
  10392. lastError = desc;
  10393. errorOccurred = ! carryOn;
  10394. }
  10395. const String XmlDocument::getFileContents (const String& filename) const
  10396. {
  10397. if (inputSource != 0)
  10398. {
  10399. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10400. if (in != 0)
  10401. return in->readEntireStreamAsString();
  10402. }
  10403. return String::empty;
  10404. }
  10405. juce_wchar XmlDocument::readNextChar() throw()
  10406. {
  10407. if (*input != 0)
  10408. {
  10409. return *input++;
  10410. }
  10411. else
  10412. {
  10413. outOfData = true;
  10414. return 0;
  10415. }
  10416. }
  10417. int XmlDocument::findNextTokenLength() throw()
  10418. {
  10419. int len = 0;
  10420. juce_wchar c = *input;
  10421. while (isXmlIdentifierChar (c))
  10422. c = input [++len];
  10423. return len;
  10424. }
  10425. void XmlDocument::skipHeader()
  10426. {
  10427. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10428. if (found != 0)
  10429. {
  10430. input = found;
  10431. input = CharacterFunctions::find (input, T("?>"));
  10432. if (input == 0)
  10433. return;
  10434. input += 2;
  10435. }
  10436. skipNextWhiteSpace();
  10437. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10438. if (docType == 0)
  10439. return;
  10440. input = docType + 9;
  10441. int n = 1;
  10442. while (n > 0)
  10443. {
  10444. const juce_wchar c = readNextChar();
  10445. if (outOfData)
  10446. return;
  10447. if (c == '<')
  10448. ++n;
  10449. else if (c == '>')
  10450. --n;
  10451. }
  10452. docType += 9;
  10453. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10454. }
  10455. void XmlDocument::skipNextWhiteSpace()
  10456. {
  10457. for (;;)
  10458. {
  10459. juce_wchar c = *input;
  10460. while (CharacterFunctions::isWhitespace (c))
  10461. c = *++input;
  10462. if (c == 0)
  10463. {
  10464. outOfData = true;
  10465. break;
  10466. }
  10467. else if (c == '<')
  10468. {
  10469. if (input[1] == '!'
  10470. && input[2] == '-'
  10471. && input[3] == '-')
  10472. {
  10473. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10474. if (closeComment == 0)
  10475. {
  10476. outOfData = true;
  10477. break;
  10478. }
  10479. input = closeComment + 3;
  10480. continue;
  10481. }
  10482. else if (input[1] == '?')
  10483. {
  10484. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10485. if (closeBracket == 0)
  10486. {
  10487. outOfData = true;
  10488. break;
  10489. }
  10490. input = closeBracket + 2;
  10491. continue;
  10492. }
  10493. }
  10494. break;
  10495. }
  10496. }
  10497. void XmlDocument::readQuotedString (String& result)
  10498. {
  10499. const juce_wchar quote = readNextChar();
  10500. while (! outOfData)
  10501. {
  10502. const juce_wchar c = readNextChar();
  10503. if (c == quote)
  10504. break;
  10505. if (c == '&')
  10506. {
  10507. --input;
  10508. readEntity (result);
  10509. }
  10510. else
  10511. {
  10512. --input;
  10513. const juce_wchar* const start = input;
  10514. for (;;)
  10515. {
  10516. const juce_wchar character = *input;
  10517. if (character == quote)
  10518. {
  10519. result.append (start, (int) (input - start));
  10520. ++input;
  10521. return;
  10522. }
  10523. else if (character == '&')
  10524. {
  10525. result.append (start, (int) (input - start));
  10526. break;
  10527. }
  10528. else if (character == 0)
  10529. {
  10530. outOfData = true;
  10531. setLastError ("unmatched quotes", false);
  10532. break;
  10533. }
  10534. ++input;
  10535. }
  10536. }
  10537. }
  10538. }
  10539. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
  10540. {
  10541. XmlElement* node = 0;
  10542. skipNextWhiteSpace();
  10543. if (outOfData)
  10544. return 0;
  10545. input = CharacterFunctions::find (input, T("<"));
  10546. if (input != 0)
  10547. {
  10548. ++input;
  10549. int tagLen = findNextTokenLength();
  10550. if (tagLen == 0)
  10551. {
  10552. // no tag name - but allow for a gap after the '<' before giving an error
  10553. skipNextWhiteSpace();
  10554. tagLen = findNextTokenLength();
  10555. if (tagLen == 0)
  10556. {
  10557. setLastError ("tag name missing", false);
  10558. return node;
  10559. }
  10560. }
  10561. node = new XmlElement (String (input, tagLen));
  10562. input += tagLen;
  10563. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10564. // look for attributes
  10565. for (;;)
  10566. {
  10567. skipNextWhiteSpace();
  10568. const juce_wchar c = *input;
  10569. // empty tag..
  10570. if (c == '/' && input[1] == '>')
  10571. {
  10572. input += 2;
  10573. break;
  10574. }
  10575. // parse the guts of the element..
  10576. if (c == '>')
  10577. {
  10578. ++input;
  10579. skipNextWhiteSpace();
  10580. if (alsoParseSubElements)
  10581. readChildElements (node);
  10582. break;
  10583. }
  10584. // get an attribute..
  10585. if (isXmlIdentifierChar (c))
  10586. {
  10587. const int attNameLen = findNextTokenLength();
  10588. if (attNameLen > 0)
  10589. {
  10590. const juce_wchar* attNameStart = input;
  10591. input += attNameLen;
  10592. skipNextWhiteSpace();
  10593. if (readNextChar() == '=')
  10594. {
  10595. skipNextWhiteSpace();
  10596. const juce_wchar nextChar = *input;
  10597. if (nextChar == '"' || nextChar == '\'')
  10598. {
  10599. XmlElement::XmlAttributeNode* const newAtt
  10600. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10601. String::empty);
  10602. readQuotedString (newAtt->value);
  10603. if (lastAttribute == 0)
  10604. node->attributes = newAtt;
  10605. else
  10606. lastAttribute->next = newAtt;
  10607. lastAttribute = newAtt;
  10608. continue;
  10609. }
  10610. }
  10611. }
  10612. }
  10613. else
  10614. {
  10615. if (! outOfData)
  10616. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10617. }
  10618. break;
  10619. }
  10620. }
  10621. return node;
  10622. }
  10623. void XmlDocument::readChildElements (XmlElement* parent)
  10624. {
  10625. XmlElement* lastChildNode = 0;
  10626. for (;;)
  10627. {
  10628. skipNextWhiteSpace();
  10629. if (outOfData)
  10630. {
  10631. setLastError ("unmatched tags", false);
  10632. break;
  10633. }
  10634. if (*input == '<')
  10635. {
  10636. if (input[1] == '/')
  10637. {
  10638. // our close tag..
  10639. input = CharacterFunctions::find (input, T(">"));
  10640. ++input;
  10641. break;
  10642. }
  10643. else if (input[1] == '!'
  10644. && input[2] == '['
  10645. && input[3] == 'C'
  10646. && input[4] == 'D'
  10647. && input[5] == 'A'
  10648. && input[6] == 'T'
  10649. && input[7] == 'A'
  10650. && input[8] == '[')
  10651. {
  10652. input += 9;
  10653. const juce_wchar* const inputStart = input;
  10654. int len = 0;
  10655. for (;;)
  10656. {
  10657. if (*input == 0)
  10658. {
  10659. setLastError ("unterminated CDATA section", false);
  10660. outOfData = true;
  10661. break;
  10662. }
  10663. else if (input[0] == ']'
  10664. && input[1] == ']'
  10665. && input[2] == '>')
  10666. {
  10667. input += 3;
  10668. break;
  10669. }
  10670. ++input;
  10671. ++len;
  10672. }
  10673. XmlElement* const e = new XmlElement ((int) 0);
  10674. e->setText (String (inputStart, len));
  10675. if (lastChildNode != 0)
  10676. lastChildNode->nextElement = e;
  10677. else
  10678. parent->addChildElement (e);
  10679. lastChildNode = e;
  10680. }
  10681. else
  10682. {
  10683. // this is some other element, so parse and add it..
  10684. XmlElement* const n = readNextElement (true);
  10685. if (n != 0)
  10686. {
  10687. if (lastChildNode == 0)
  10688. parent->addChildElement (n);
  10689. else
  10690. lastChildNode->nextElement = n;
  10691. lastChildNode = n;
  10692. }
  10693. else
  10694. {
  10695. return;
  10696. }
  10697. }
  10698. }
  10699. else
  10700. {
  10701. // read character block..
  10702. XmlElement* const e = new XmlElement ((int)0);
  10703. if (lastChildNode != 0)
  10704. lastChildNode->nextElement = e;
  10705. else
  10706. parent->addChildElement (e);
  10707. lastChildNode = e;
  10708. String textElementContent;
  10709. for (;;)
  10710. {
  10711. const juce_wchar c = *input;
  10712. if (c == '<')
  10713. break;
  10714. if (c == 0)
  10715. {
  10716. setLastError ("unmatched tags", false);
  10717. outOfData = true;
  10718. return;
  10719. }
  10720. if (c == '&')
  10721. {
  10722. String entity;
  10723. readEntity (entity);
  10724. if (entity.startsWithChar ('<') && entity [1] != 0)
  10725. {
  10726. const juce_wchar* const oldInput = input;
  10727. const bool oldOutOfData = outOfData;
  10728. input = entity;
  10729. outOfData = false;
  10730. for (;;)
  10731. {
  10732. XmlElement* const n = readNextElement (true);
  10733. if (n == 0)
  10734. break;
  10735. if (lastChildNode == 0)
  10736. parent->addChildElement (n);
  10737. else
  10738. lastChildNode->nextElement = n;
  10739. lastChildNode = n;
  10740. }
  10741. input = oldInput;
  10742. outOfData = oldOutOfData;
  10743. }
  10744. else
  10745. {
  10746. textElementContent += entity;
  10747. }
  10748. }
  10749. else
  10750. {
  10751. const juce_wchar* start = input;
  10752. int len = 0;
  10753. for (;;)
  10754. {
  10755. const juce_wchar nextChar = *input;
  10756. if (nextChar == '<' || nextChar == '&')
  10757. {
  10758. break;
  10759. }
  10760. else if (nextChar == 0)
  10761. {
  10762. setLastError ("unmatched tags", false);
  10763. outOfData = true;
  10764. return;
  10765. }
  10766. ++input;
  10767. ++len;
  10768. }
  10769. textElementContent.append (start, len);
  10770. }
  10771. }
  10772. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10773. : textElementContent.isNotEmpty())
  10774. e->setText (textElementContent);
  10775. }
  10776. }
  10777. }
  10778. void XmlDocument::readEntity (String& result)
  10779. {
  10780. // skip over the ampersand
  10781. ++input;
  10782. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10783. {
  10784. input += 4;
  10785. result += '&';
  10786. }
  10787. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10788. {
  10789. input += 5;
  10790. result += '"';
  10791. }
  10792. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  10793. {
  10794. input += 5;
  10795. result += '\'';
  10796. }
  10797. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  10798. {
  10799. input += 3;
  10800. result += '<';
  10801. }
  10802. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  10803. {
  10804. input += 3;
  10805. result += '>';
  10806. }
  10807. else if (*input == '#')
  10808. {
  10809. int charCode = 0;
  10810. ++input;
  10811. if (*input == 'x' || *input == 'X')
  10812. {
  10813. ++input;
  10814. int numChars = 0;
  10815. while (input[0] != ';')
  10816. {
  10817. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  10818. if (hexValue < 0 || ++numChars > 8)
  10819. {
  10820. setLastError ("illegal escape sequence", true);
  10821. break;
  10822. }
  10823. charCode = (charCode << 4) | hexValue;
  10824. ++input;
  10825. }
  10826. ++input;
  10827. }
  10828. else if (input[0] >= '0' && input[0] <= '9')
  10829. {
  10830. int numChars = 0;
  10831. while (input[0] != ';')
  10832. {
  10833. if (++numChars > 12)
  10834. {
  10835. setLastError ("illegal escape sequence", true);
  10836. break;
  10837. }
  10838. charCode = charCode * 10 + (input[0] - '0');
  10839. ++input;
  10840. }
  10841. ++input;
  10842. }
  10843. else
  10844. {
  10845. setLastError ("illegal escape sequence", true);
  10846. result += '&';
  10847. return;
  10848. }
  10849. result << (juce_wchar) charCode;
  10850. }
  10851. else
  10852. {
  10853. const juce_wchar* const entityNameStart = input;
  10854. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  10855. if (closingSemiColon == 0)
  10856. {
  10857. outOfData = true;
  10858. result += '&';
  10859. }
  10860. else
  10861. {
  10862. input = closingSemiColon + 1;
  10863. result += expandExternalEntity (String (entityNameStart,
  10864. (int) (closingSemiColon - entityNameStart)));
  10865. }
  10866. }
  10867. }
  10868. const String XmlDocument::expandEntity (const String& ent)
  10869. {
  10870. if (ent.equalsIgnoreCase ("amp"))
  10871. return String::charToString ('&');
  10872. if (ent.equalsIgnoreCase ("quot"))
  10873. return String::charToString ('"');
  10874. if (ent.equalsIgnoreCase ("apos"))
  10875. return String::charToString ('\'');
  10876. if (ent.equalsIgnoreCase ("lt"))
  10877. return String::charToString ('<');
  10878. if (ent.equalsIgnoreCase ("gt"))
  10879. return String::charToString ('>');
  10880. if (ent[0] == '#')
  10881. {
  10882. if (ent[1] == 'x' || ent[1] == 'X')
  10883. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  10884. if (ent[1] >= '0' && ent[1] <= '9')
  10885. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  10886. setLastError ("illegal escape sequence", false);
  10887. return String::charToString ('&');
  10888. }
  10889. return expandExternalEntity (ent);
  10890. }
  10891. const String XmlDocument::expandExternalEntity (const String& entity)
  10892. {
  10893. if (needToLoadDTD)
  10894. {
  10895. if (dtdText.isNotEmpty())
  10896. {
  10897. while (dtdText.endsWithChar ('>'))
  10898. dtdText = dtdText.dropLastCharacters (1);
  10899. tokenisedDTD.addTokens (dtdText, true);
  10900. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase ("system")
  10901. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  10902. {
  10903. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  10904. tokenisedDTD.clear();
  10905. tokenisedDTD.addTokens (getFileContents (fn), true);
  10906. }
  10907. else
  10908. {
  10909. tokenisedDTD.clear();
  10910. const int openBracket = dtdText.indexOfChar ('[');
  10911. if (openBracket > 0)
  10912. {
  10913. const int closeBracket = dtdText.lastIndexOfChar (']');
  10914. if (closeBracket > openBracket)
  10915. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  10916. closeBracket), true);
  10917. }
  10918. }
  10919. for (int i = tokenisedDTD.size(); --i >= 0;)
  10920. {
  10921. if (tokenisedDTD[i].startsWithChar ('%')
  10922. && tokenisedDTD[i].endsWithChar (';'))
  10923. {
  10924. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  10925. StringArray newToks;
  10926. newToks.addTokens (parsed, true);
  10927. tokenisedDTD.remove (i);
  10928. for (int j = newToks.size(); --j >= 0;)
  10929. tokenisedDTD.insert (i, newToks[j]);
  10930. }
  10931. }
  10932. }
  10933. needToLoadDTD = false;
  10934. }
  10935. for (int i = 0; i < tokenisedDTD.size(); ++i)
  10936. {
  10937. if (tokenisedDTD[i] == entity)
  10938. {
  10939. if (tokenisedDTD[i - 1].equalsIgnoreCase ("<!entity"))
  10940. {
  10941. String ent (tokenisedDTD [i + 1]);
  10942. while (ent.endsWithChar ('>'))
  10943. ent = ent.dropLastCharacters (1);
  10944. ent = ent.trim().unquoted();
  10945. // check for sub-entities..
  10946. int ampersand = ent.indexOfChar ('&');
  10947. while (ampersand >= 0)
  10948. {
  10949. const int semiColon = ent.indexOf (i + 1, ";");
  10950. if (semiColon < 0)
  10951. {
  10952. setLastError ("entity without terminating semi-colon", false);
  10953. break;
  10954. }
  10955. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  10956. ent = ent.substring (0, ampersand)
  10957. + resolved
  10958. + ent.substring (semiColon + 1);
  10959. ampersand = ent.indexOfChar (semiColon + 1, '&');
  10960. }
  10961. return ent;
  10962. }
  10963. }
  10964. }
  10965. setLastError ("unknown entity", true);
  10966. return entity;
  10967. }
  10968. const String XmlDocument::getParameterEntity (const String& entity)
  10969. {
  10970. for (int i = 0; i < tokenisedDTD.size(); ++i)
  10971. {
  10972. if (tokenisedDTD[i] == entity)
  10973. {
  10974. if (tokenisedDTD [i - 1] == "%"
  10975. && tokenisedDTD [i - 2].equalsIgnoreCase ("<!entity"))
  10976. {
  10977. String ent (tokenisedDTD [i + 1]);
  10978. while (ent.endsWithChar ('>'))
  10979. ent = ent.dropLastCharacters (1);
  10980. if (ent.equalsIgnoreCase ("system"))
  10981. {
  10982. String filename (tokenisedDTD [i + 2]);
  10983. while (filename.endsWithChar ('>'))
  10984. filename = filename.dropLastCharacters (1);
  10985. return getFileContents (filename);
  10986. }
  10987. else
  10988. {
  10989. return ent.trim().unquoted();
  10990. }
  10991. }
  10992. }
  10993. }
  10994. return entity;
  10995. }
  10996. END_JUCE_NAMESPACE
  10997. /*** End of inlined file: juce_XmlDocument.cpp ***/
  10998. /*** Start of inlined file: juce_XmlElement.cpp ***/
  10999. BEGIN_JUCE_NAMESPACE
  11000. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11001. : name (other.name),
  11002. value (other.value),
  11003. next (0)
  11004. {
  11005. }
  11006. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_, const String& value_) throw()
  11007. : name (name_),
  11008. value (value_),
  11009. next (0)
  11010. {
  11011. }
  11012. XmlElement::XmlElement (const String& tagName_) throw()
  11013. : tagName (tagName_),
  11014. firstChildElement (0),
  11015. nextElement (0),
  11016. attributes (0)
  11017. {
  11018. // the tag name mustn't be empty, or it'll look like a text element!
  11019. jassert (tagName_.containsNonWhitespaceChars())
  11020. // The tag can't contain spaces or other characters that would create invalid XML!
  11021. jassert (! tagName_.containsAnyOf (" <>/&"));
  11022. }
  11023. XmlElement::XmlElement (int /*dummy*/) throw()
  11024. : firstChildElement (0),
  11025. nextElement (0),
  11026. attributes (0)
  11027. {
  11028. }
  11029. XmlElement::XmlElement (const XmlElement& other) throw()
  11030. : tagName (other.tagName),
  11031. firstChildElement (0),
  11032. nextElement (0),
  11033. attributes (0)
  11034. {
  11035. copyChildrenAndAttributesFrom (other);
  11036. }
  11037. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11038. {
  11039. if (this != &other)
  11040. {
  11041. removeAllAttributes();
  11042. deleteAllChildElements();
  11043. tagName = other.tagName;
  11044. copyChildrenAndAttributesFrom (other);
  11045. }
  11046. return *this;
  11047. }
  11048. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11049. {
  11050. XmlElement* child = other.firstChildElement;
  11051. XmlElement* lastChild = 0;
  11052. while (child != 0)
  11053. {
  11054. XmlElement* const copiedChild = new XmlElement (*child);
  11055. if (lastChild != 0)
  11056. lastChild->nextElement = copiedChild;
  11057. else
  11058. firstChildElement = copiedChild;
  11059. lastChild = copiedChild;
  11060. child = child->nextElement;
  11061. }
  11062. const XmlAttributeNode* att = other.attributes;
  11063. XmlAttributeNode* lastAtt = 0;
  11064. while (att != 0)
  11065. {
  11066. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11067. if (lastAtt != 0)
  11068. lastAtt->next = newAtt;
  11069. else
  11070. attributes = newAtt;
  11071. lastAtt = newAtt;
  11072. att = att->next;
  11073. }
  11074. }
  11075. XmlElement::~XmlElement() throw()
  11076. {
  11077. XmlElement* child = firstChildElement;
  11078. while (child != 0)
  11079. {
  11080. XmlElement* const nextChild = child->nextElement;
  11081. delete child;
  11082. child = nextChild;
  11083. }
  11084. XmlAttributeNode* att = attributes;
  11085. while (att != 0)
  11086. {
  11087. XmlAttributeNode* const nextAtt = att->next;
  11088. delete att;
  11089. att = nextAtt;
  11090. }
  11091. }
  11092. namespace XmlOutputFunctions
  11093. {
  11094. static bool isLegalXmlChar (const uint32 c) throw()
  11095. {
  11096. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11097. return c < sizeof (legalChars) * 8
  11098. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11099. }
  11100. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11101. {
  11102. const juce_wchar* t = text;
  11103. for (;;)
  11104. {
  11105. const juce_wchar character = *t++;
  11106. if (character == 0)
  11107. {
  11108. break;
  11109. }
  11110. else if (isLegalXmlChar ((uint32) character))
  11111. {
  11112. outputStream << (char) character;
  11113. }
  11114. else
  11115. {
  11116. switch (character)
  11117. {
  11118. case '&': outputStream << "&amp;"; break;
  11119. case '"': outputStream << "&quot;"; break;
  11120. case '>': outputStream << "&gt;"; break;
  11121. case '<': outputStream << "&lt;"; break;
  11122. case '\n':
  11123. if (changeNewLines)
  11124. outputStream << "&#10;";
  11125. else
  11126. outputStream << (char) character;
  11127. break;
  11128. case '\r':
  11129. if (changeNewLines)
  11130. outputStream << "&#13;";
  11131. else
  11132. outputStream << (char) character;
  11133. break;
  11134. default:
  11135. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11136. break;
  11137. }
  11138. }
  11139. }
  11140. }
  11141. static void writeSpaces (OutputStream& out, int numSpaces)
  11142. {
  11143. if (numSpaces > 0)
  11144. {
  11145. const char* const blanks = " ";
  11146. const int blankSize = (int) sizeof (blanks) - 1;
  11147. while (numSpaces > blankSize)
  11148. {
  11149. out.write (blanks, blankSize);
  11150. numSpaces -= blankSize;
  11151. }
  11152. out.write (blanks, numSpaces);
  11153. }
  11154. }
  11155. }
  11156. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11157. const int indentationLevel,
  11158. const int lineWrapLength) const
  11159. {
  11160. using namespace XmlOutputFunctions;
  11161. writeSpaces (outputStream, indentationLevel);
  11162. if (! isTextElement())
  11163. {
  11164. outputStream.writeByte ('<');
  11165. outputStream << tagName;
  11166. const int attIndent = indentationLevel + tagName.length() + 1;
  11167. int lineLen = 0;
  11168. const XmlAttributeNode* att = attributes;
  11169. while (att != 0)
  11170. {
  11171. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11172. {
  11173. outputStream.write ("\r\n", 2);
  11174. writeSpaces (outputStream, attIndent);
  11175. lineLen = 0;
  11176. }
  11177. const int64 startPos = outputStream.getPosition();
  11178. outputStream.writeByte (' ');
  11179. outputStream << att->name;
  11180. outputStream.write ("=\"", 2);
  11181. escapeIllegalXmlChars (outputStream, att->value, true);
  11182. outputStream.writeByte ('"');
  11183. lineLen += (int) (outputStream.getPosition() - startPos);
  11184. att = att->next;
  11185. }
  11186. if (firstChildElement != 0)
  11187. {
  11188. XmlElement* child = firstChildElement;
  11189. if (child->nextElement == 0 && child->isTextElement())
  11190. {
  11191. outputStream.writeByte ('>');
  11192. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11193. }
  11194. else
  11195. {
  11196. if (indentationLevel >= 0)
  11197. outputStream.write (">\r\n", 3);
  11198. else
  11199. outputStream.writeByte ('>');
  11200. bool lastWasTextNode = false;
  11201. while (child != 0)
  11202. {
  11203. if (child->isTextElement())
  11204. {
  11205. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11206. writeSpaces (outputStream, indentationLevel + 2);
  11207. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11208. lastWasTextNode = true;
  11209. }
  11210. else
  11211. {
  11212. if (indentationLevel >= 0)
  11213. {
  11214. if (lastWasTextNode)
  11215. outputStream.write ("\r\n", 2);
  11216. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11217. }
  11218. else
  11219. {
  11220. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11221. }
  11222. lastWasTextNode = false;
  11223. }
  11224. child = child->nextElement;
  11225. }
  11226. if (indentationLevel >= 0)
  11227. {
  11228. if (lastWasTextNode)
  11229. outputStream.write ("\r\n", 2);
  11230. writeSpaces (outputStream, indentationLevel);
  11231. }
  11232. }
  11233. outputStream.write ("</", 2);
  11234. outputStream << tagName;
  11235. if (indentationLevel >= 0)
  11236. outputStream.write (">\r\n", 3);
  11237. else
  11238. outputStream.writeByte ('>');
  11239. }
  11240. else
  11241. {
  11242. if (indentationLevel >= 0)
  11243. outputStream.write ("/>\r\n", 4);
  11244. else
  11245. outputStream.write ("/>", 2);
  11246. }
  11247. }
  11248. else
  11249. {
  11250. if (indentationLevel >= 0)
  11251. writeSpaces (outputStream, indentationLevel + 2);
  11252. escapeIllegalXmlChars (outputStream, getText(), false);
  11253. }
  11254. }
  11255. const String XmlElement::createDocument (const String& dtdToUse,
  11256. const bool allOnOneLine,
  11257. const bool includeXmlHeader,
  11258. const String& encodingType,
  11259. const int lineWrapLength) const
  11260. {
  11261. MemoryOutputStream mem (2048, 4096);
  11262. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11263. return mem.toUTF8();
  11264. }
  11265. void XmlElement::writeToStream (OutputStream& output,
  11266. const String& dtdToUse,
  11267. const bool allOnOneLine,
  11268. const bool includeXmlHeader,
  11269. const String& encodingType,
  11270. const int lineWrapLength) const
  11271. {
  11272. if (includeXmlHeader)
  11273. output << "<?xml version=\"1.0\" encoding=\"" << encodingType
  11274. << (allOnOneLine ? "\"?> " : "\"?>\r\n\r\n");
  11275. if (dtdToUse.isNotEmpty())
  11276. output << dtdToUse << (allOnOneLine ? " " : "\r\n");
  11277. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11278. }
  11279. bool XmlElement::writeToFile (const File& file,
  11280. const String& dtdToUse,
  11281. const String& encodingType,
  11282. const int lineWrapLength) const
  11283. {
  11284. if (file.hasWriteAccess())
  11285. {
  11286. TemporaryFile tempFile (file);
  11287. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11288. if (out != 0)
  11289. {
  11290. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11291. out = 0;
  11292. return tempFile.overwriteTargetFileWithTemporary();
  11293. }
  11294. }
  11295. return false;
  11296. }
  11297. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11298. {
  11299. #ifdef JUCE_DEBUG
  11300. // if debugging, check that the case is actually the same, because
  11301. // valid xml is case-sensitive, and although this lets it pass, it's
  11302. // better not to..
  11303. if (tagName.equalsIgnoreCase (tagNameWanted))
  11304. {
  11305. jassert (tagName == tagNameWanted);
  11306. return true;
  11307. }
  11308. else
  11309. {
  11310. return false;
  11311. }
  11312. #else
  11313. return tagName.equalsIgnoreCase (tagNameWanted);
  11314. #endif
  11315. }
  11316. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11317. {
  11318. XmlElement* e = nextElement;
  11319. while (e != 0 && ! e->hasTagName (requiredTagName))
  11320. e = e->nextElement;
  11321. return e;
  11322. }
  11323. int XmlElement::getNumAttributes() const throw()
  11324. {
  11325. const XmlAttributeNode* att = attributes;
  11326. int count = 0;
  11327. while (att != 0)
  11328. {
  11329. att = att->next;
  11330. ++count;
  11331. }
  11332. return count;
  11333. }
  11334. const String& XmlElement::getAttributeName (const int index) const throw()
  11335. {
  11336. const XmlAttributeNode* att = attributes;
  11337. int count = 0;
  11338. while (att != 0)
  11339. {
  11340. if (count == index)
  11341. return att->name;
  11342. att = att->next;
  11343. ++count;
  11344. }
  11345. return String::empty;
  11346. }
  11347. const String& XmlElement::getAttributeValue (const int index) const throw()
  11348. {
  11349. const XmlAttributeNode* att = attributes;
  11350. int count = 0;
  11351. while (att != 0)
  11352. {
  11353. if (count == index)
  11354. return att->value;
  11355. att = att->next;
  11356. ++count;
  11357. }
  11358. return String::empty;
  11359. }
  11360. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11361. {
  11362. const XmlAttributeNode* att = attributes;
  11363. while (att != 0)
  11364. {
  11365. if (att->name.equalsIgnoreCase (attributeName))
  11366. return true;
  11367. att = att->next;
  11368. }
  11369. return false;
  11370. }
  11371. const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
  11372. {
  11373. const XmlAttributeNode* att = attributes;
  11374. while (att != 0)
  11375. {
  11376. if (att->name.equalsIgnoreCase (attributeName))
  11377. return att->value;
  11378. att = att->next;
  11379. }
  11380. return String::empty;
  11381. }
  11382. const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
  11383. {
  11384. const XmlAttributeNode* att = attributes;
  11385. while (att != 0)
  11386. {
  11387. if (att->name.equalsIgnoreCase (attributeName))
  11388. return att->value;
  11389. att = att->next;
  11390. }
  11391. return defaultReturnValue;
  11392. }
  11393. int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
  11394. {
  11395. const XmlAttributeNode* att = attributes;
  11396. while (att != 0)
  11397. {
  11398. if (att->name.equalsIgnoreCase (attributeName))
  11399. return att->value.getIntValue();
  11400. att = att->next;
  11401. }
  11402. return defaultReturnValue;
  11403. }
  11404. double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
  11405. {
  11406. const XmlAttributeNode* att = attributes;
  11407. while (att != 0)
  11408. {
  11409. if (att->name.equalsIgnoreCase (attributeName))
  11410. return att->value.getDoubleValue();
  11411. att = att->next;
  11412. }
  11413. return defaultReturnValue;
  11414. }
  11415. bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
  11416. {
  11417. const XmlAttributeNode* att = attributes;
  11418. while (att != 0)
  11419. {
  11420. if (att->name.equalsIgnoreCase (attributeName))
  11421. {
  11422. juce_wchar firstChar = att->value[0];
  11423. if (CharacterFunctions::isWhitespace (firstChar))
  11424. firstChar = att->value.trimStart() [0];
  11425. return firstChar == '1'
  11426. || firstChar == 't'
  11427. || firstChar == 'y'
  11428. || firstChar == 'T'
  11429. || firstChar == 'Y';
  11430. }
  11431. att = att->next;
  11432. }
  11433. return defaultReturnValue;
  11434. }
  11435. bool XmlElement::compareAttribute (const String& attributeName,
  11436. const String& stringToCompareAgainst,
  11437. const bool ignoreCase) const throw()
  11438. {
  11439. const XmlAttributeNode* att = attributes;
  11440. while (att != 0)
  11441. {
  11442. if (att->name.equalsIgnoreCase (attributeName))
  11443. {
  11444. if (ignoreCase)
  11445. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11446. else
  11447. return att->value == stringToCompareAgainst;
  11448. }
  11449. att = att->next;
  11450. }
  11451. return false;
  11452. }
  11453. void XmlElement::setAttribute (const String& attributeName, const String& value)
  11454. {
  11455. #ifdef JUCE_DEBUG
  11456. // check the identifier being passed in is legal..
  11457. const juce_wchar* t = attributeName;
  11458. while (*t != 0)
  11459. {
  11460. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11461. || *t == '_'
  11462. || *t == '-'
  11463. || *t == ':');
  11464. ++t;
  11465. }
  11466. #endif
  11467. if (attributes == 0)
  11468. {
  11469. attributes = new XmlAttributeNode (attributeName, value);
  11470. }
  11471. else
  11472. {
  11473. XmlAttributeNode* att = attributes;
  11474. for (;;)
  11475. {
  11476. if (att->name.equalsIgnoreCase (attributeName))
  11477. {
  11478. att->value = value;
  11479. break;
  11480. }
  11481. else if (att->next == 0)
  11482. {
  11483. att->next = new XmlAttributeNode (attributeName, value);
  11484. break;
  11485. }
  11486. att = att->next;
  11487. }
  11488. }
  11489. }
  11490. void XmlElement::setAttribute (const String& attributeName, const int number)
  11491. {
  11492. setAttribute (attributeName, String (number));
  11493. }
  11494. void XmlElement::setAttribute (const String& attributeName, const double number)
  11495. {
  11496. setAttribute (attributeName, String (number));
  11497. }
  11498. void XmlElement::removeAttribute (const String& attributeName) throw()
  11499. {
  11500. XmlAttributeNode* att = attributes;
  11501. XmlAttributeNode* lastAtt = 0;
  11502. while (att != 0)
  11503. {
  11504. if (att->name.equalsIgnoreCase (attributeName))
  11505. {
  11506. if (lastAtt == 0)
  11507. attributes = att->next;
  11508. else
  11509. lastAtt->next = att->next;
  11510. delete att;
  11511. break;
  11512. }
  11513. lastAtt = att;
  11514. att = att->next;
  11515. }
  11516. }
  11517. void XmlElement::removeAllAttributes() throw()
  11518. {
  11519. while (attributes != 0)
  11520. {
  11521. XmlAttributeNode* const nextAtt = attributes->next;
  11522. delete attributes;
  11523. attributes = nextAtt;
  11524. }
  11525. }
  11526. int XmlElement::getNumChildElements() const throw()
  11527. {
  11528. int count = 0;
  11529. const XmlElement* child = firstChildElement;
  11530. while (child != 0)
  11531. {
  11532. ++count;
  11533. child = child->nextElement;
  11534. }
  11535. return count;
  11536. }
  11537. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11538. {
  11539. int count = 0;
  11540. XmlElement* child = firstChildElement;
  11541. while (child != 0 && count < index)
  11542. {
  11543. child = child->nextElement;
  11544. ++count;
  11545. }
  11546. return child;
  11547. }
  11548. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11549. {
  11550. XmlElement* child = firstChildElement;
  11551. while (child != 0)
  11552. {
  11553. if (child->hasTagName (childName))
  11554. break;
  11555. child = child->nextElement;
  11556. }
  11557. return child;
  11558. }
  11559. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11560. {
  11561. if (newNode != 0)
  11562. {
  11563. if (firstChildElement == 0)
  11564. {
  11565. firstChildElement = newNode;
  11566. }
  11567. else
  11568. {
  11569. XmlElement* child = firstChildElement;
  11570. while (child->nextElement != 0)
  11571. child = child->nextElement;
  11572. child->nextElement = newNode;
  11573. // if this is non-zero, then something's probably
  11574. // gone wrong..
  11575. jassert (newNode->nextElement == 0);
  11576. }
  11577. }
  11578. }
  11579. void XmlElement::insertChildElement (XmlElement* const newNode,
  11580. int indexToInsertAt) throw()
  11581. {
  11582. if (newNode != 0)
  11583. {
  11584. removeChildElement (newNode, false);
  11585. if (indexToInsertAt == 0)
  11586. {
  11587. newNode->nextElement = firstChildElement;
  11588. firstChildElement = newNode;
  11589. }
  11590. else
  11591. {
  11592. if (firstChildElement == 0)
  11593. {
  11594. firstChildElement = newNode;
  11595. }
  11596. else
  11597. {
  11598. if (indexToInsertAt < 0)
  11599. indexToInsertAt = std::numeric_limits<int>::max();
  11600. XmlElement* child = firstChildElement;
  11601. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11602. child = child->nextElement;
  11603. newNode->nextElement = child->nextElement;
  11604. child->nextElement = newNode;
  11605. }
  11606. }
  11607. }
  11608. }
  11609. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11610. {
  11611. XmlElement* const newElement = new XmlElement (tagName);
  11612. addChildElement (newElement);
  11613. return newElement;
  11614. }
  11615. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11616. XmlElement* const newNode) throw()
  11617. {
  11618. if (newNode != 0)
  11619. {
  11620. XmlElement* child = firstChildElement;
  11621. XmlElement* previousNode = 0;
  11622. while (child != 0)
  11623. {
  11624. if (child == currentChildElement)
  11625. {
  11626. if (child != newNode)
  11627. {
  11628. if (previousNode == 0)
  11629. firstChildElement = newNode;
  11630. else
  11631. previousNode->nextElement = newNode;
  11632. newNode->nextElement = child->nextElement;
  11633. delete child;
  11634. }
  11635. return true;
  11636. }
  11637. previousNode = child;
  11638. child = child->nextElement;
  11639. }
  11640. }
  11641. return false;
  11642. }
  11643. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11644. const bool shouldDeleteTheChild) throw()
  11645. {
  11646. if (childToRemove != 0)
  11647. {
  11648. if (firstChildElement == childToRemove)
  11649. {
  11650. firstChildElement = childToRemove->nextElement;
  11651. childToRemove->nextElement = 0;
  11652. }
  11653. else
  11654. {
  11655. XmlElement* child = firstChildElement;
  11656. XmlElement* last = 0;
  11657. while (child != 0)
  11658. {
  11659. if (child == childToRemove)
  11660. {
  11661. if (last == 0)
  11662. firstChildElement = child->nextElement;
  11663. else
  11664. last->nextElement = child->nextElement;
  11665. childToRemove->nextElement = 0;
  11666. break;
  11667. }
  11668. last = child;
  11669. child = child->nextElement;
  11670. }
  11671. }
  11672. if (shouldDeleteTheChild)
  11673. delete childToRemove;
  11674. }
  11675. }
  11676. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11677. const bool ignoreOrderOfAttributes) const throw()
  11678. {
  11679. if (this != other)
  11680. {
  11681. if (other == 0 || tagName != other->tagName)
  11682. {
  11683. return false;
  11684. }
  11685. if (ignoreOrderOfAttributes)
  11686. {
  11687. int totalAtts = 0;
  11688. const XmlAttributeNode* att = attributes;
  11689. while (att != 0)
  11690. {
  11691. if (! other->compareAttribute (att->name, att->value))
  11692. return false;
  11693. att = att->next;
  11694. ++totalAtts;
  11695. }
  11696. if (totalAtts != other->getNumAttributes())
  11697. return false;
  11698. }
  11699. else
  11700. {
  11701. const XmlAttributeNode* thisAtt = attributes;
  11702. const XmlAttributeNode* otherAtt = other->attributes;
  11703. for (;;)
  11704. {
  11705. if (thisAtt == 0 || otherAtt == 0)
  11706. {
  11707. if (thisAtt == otherAtt) // both 0, so it's a match
  11708. break;
  11709. return false;
  11710. }
  11711. if (thisAtt->name != otherAtt->name
  11712. || thisAtt->value != otherAtt->value)
  11713. {
  11714. return false;
  11715. }
  11716. thisAtt = thisAtt->next;
  11717. otherAtt = otherAtt->next;
  11718. }
  11719. }
  11720. const XmlElement* thisChild = firstChildElement;
  11721. const XmlElement* otherChild = other->firstChildElement;
  11722. for (;;)
  11723. {
  11724. if (thisChild == 0 || otherChild == 0)
  11725. {
  11726. if (thisChild == otherChild) // both 0, so it's a match
  11727. break;
  11728. return false;
  11729. }
  11730. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11731. return false;
  11732. thisChild = thisChild->nextElement;
  11733. otherChild = otherChild->nextElement;
  11734. }
  11735. }
  11736. return true;
  11737. }
  11738. void XmlElement::deleteAllChildElements() throw()
  11739. {
  11740. while (firstChildElement != 0)
  11741. {
  11742. XmlElement* const nextChild = firstChildElement->nextElement;
  11743. delete firstChildElement;
  11744. firstChildElement = nextChild;
  11745. }
  11746. }
  11747. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11748. {
  11749. XmlElement* child = firstChildElement;
  11750. while (child != 0)
  11751. {
  11752. if (child->hasTagName (name))
  11753. {
  11754. XmlElement* const nextChild = child->nextElement;
  11755. removeChildElement (child, true);
  11756. child = nextChild;
  11757. }
  11758. else
  11759. {
  11760. child = child->nextElement;
  11761. }
  11762. }
  11763. }
  11764. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  11765. {
  11766. const XmlElement* child = firstChildElement;
  11767. while (child != 0)
  11768. {
  11769. if (child == possibleChild)
  11770. return true;
  11771. child = child->nextElement;
  11772. }
  11773. return false;
  11774. }
  11775. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  11776. {
  11777. if (this == elementToLookFor || elementToLookFor == 0)
  11778. return 0;
  11779. XmlElement* child = firstChildElement;
  11780. while (child != 0)
  11781. {
  11782. if (elementToLookFor == child)
  11783. return this;
  11784. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  11785. if (found != 0)
  11786. return found;
  11787. child = child->nextElement;
  11788. }
  11789. return 0;
  11790. }
  11791. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  11792. {
  11793. XmlElement* e = firstChildElement;
  11794. while (e != 0)
  11795. {
  11796. *elems++ = e;
  11797. e = e->nextElement;
  11798. }
  11799. }
  11800. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  11801. {
  11802. XmlElement* e = firstChildElement = elems[0];
  11803. for (int i = 1; i < num; ++i)
  11804. {
  11805. e->nextElement = elems[i];
  11806. e = e->nextElement;
  11807. }
  11808. e->nextElement = 0;
  11809. }
  11810. bool XmlElement::isTextElement() const throw()
  11811. {
  11812. return tagName.isEmpty();
  11813. }
  11814. static const juce_wchar* const juce_xmltextContentAttributeName = T("text");
  11815. const String XmlElement::getText() const throw()
  11816. {
  11817. jassert (isTextElement()); // you're trying to get the text from an element that
  11818. // isn't actually a text element.. If this contains text sub-nodes, you
  11819. // probably want to use getAllSubText instead.
  11820. return getStringAttribute (juce_xmltextContentAttributeName);
  11821. }
  11822. void XmlElement::setText (const String& newText) throw()
  11823. {
  11824. if (isTextElement())
  11825. {
  11826. setAttribute (juce_xmltextContentAttributeName, newText);
  11827. }
  11828. else
  11829. {
  11830. jassertfalse // you can only change the text in a text element, not a normal one.
  11831. }
  11832. }
  11833. const String XmlElement::getAllSubText() const throw()
  11834. {
  11835. String result;
  11836. String::Concatenator concatenator (result);
  11837. const XmlElement* child = firstChildElement;
  11838. while (child != 0)
  11839. {
  11840. if (child->isTextElement())
  11841. concatenator.append (child->getText());
  11842. child = child->nextElement;
  11843. }
  11844. return result;
  11845. }
  11846. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  11847. const String& defaultReturnValue) const throw()
  11848. {
  11849. const XmlElement* const child = getChildByName (childTagName);
  11850. if (child != 0)
  11851. return child->getAllSubText();
  11852. return defaultReturnValue;
  11853. }
  11854. XmlElement* XmlElement::createTextElement (const String& text) throw()
  11855. {
  11856. XmlElement* const e = new XmlElement ((int) 0);
  11857. e->setAttribute (juce_xmltextContentAttributeName, text);
  11858. return e;
  11859. }
  11860. void XmlElement::addTextElement (const String& text) throw()
  11861. {
  11862. addChildElement (createTextElement (text));
  11863. }
  11864. void XmlElement::deleteAllTextElements() throw()
  11865. {
  11866. XmlElement* child = firstChildElement;
  11867. while (child != 0)
  11868. {
  11869. XmlElement* const next = child->nextElement;
  11870. if (child->isTextElement())
  11871. removeChildElement (child, true);
  11872. child = next;
  11873. }
  11874. }
  11875. END_JUCE_NAMESPACE
  11876. /*** End of inlined file: juce_XmlElement.cpp ***/
  11877. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  11878. BEGIN_JUCE_NAMESPACE
  11879. ReadWriteLock::ReadWriteLock() throw()
  11880. : numWaitingWriters (0),
  11881. numWriters (0),
  11882. writerThreadId (0)
  11883. {
  11884. }
  11885. ReadWriteLock::~ReadWriteLock() throw()
  11886. {
  11887. jassert (readerThreads.size() == 0);
  11888. jassert (numWriters == 0);
  11889. }
  11890. void ReadWriteLock::enterRead() const throw()
  11891. {
  11892. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11893. const ScopedLock sl (accessLock);
  11894. for (;;)
  11895. {
  11896. jassert (readerThreads.size() % 2 == 0);
  11897. int i;
  11898. for (i = 0; i < readerThreads.size(); i += 2)
  11899. if (readerThreads.getUnchecked(i) == threadId)
  11900. break;
  11901. if (i < readerThreads.size()
  11902. || numWriters + numWaitingWriters == 0
  11903. || (threadId == writerThreadId && numWriters > 0))
  11904. {
  11905. if (i < readerThreads.size())
  11906. {
  11907. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  11908. }
  11909. else
  11910. {
  11911. readerThreads.add (threadId);
  11912. readerThreads.add ((Thread::ThreadID) 1);
  11913. }
  11914. return;
  11915. }
  11916. const ScopedUnlock ul (accessLock);
  11917. waitEvent.wait (100);
  11918. }
  11919. }
  11920. void ReadWriteLock::exitRead() const throw()
  11921. {
  11922. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11923. const ScopedLock sl (accessLock);
  11924. for (int i = 0; i < readerThreads.size(); i += 2)
  11925. {
  11926. if (readerThreads.getUnchecked(i) == threadId)
  11927. {
  11928. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  11929. if (newCount == 0)
  11930. {
  11931. readerThreads.removeRange (i, 2);
  11932. waitEvent.signal();
  11933. }
  11934. else
  11935. {
  11936. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  11937. }
  11938. return;
  11939. }
  11940. }
  11941. jassertfalse // unlocking a lock that wasn't locked..
  11942. }
  11943. void ReadWriteLock::enterWrite() const throw()
  11944. {
  11945. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11946. const ScopedLock sl (accessLock);
  11947. for (;;)
  11948. {
  11949. if (readerThreads.size() + numWriters == 0
  11950. || threadId == writerThreadId
  11951. || (readerThreads.size() == 2
  11952. && readerThreads.getUnchecked(0) == threadId))
  11953. {
  11954. writerThreadId = threadId;
  11955. ++numWriters;
  11956. break;
  11957. }
  11958. ++numWaitingWriters;
  11959. accessLock.exit();
  11960. waitEvent.wait (100);
  11961. accessLock.enter();
  11962. --numWaitingWriters;
  11963. }
  11964. }
  11965. bool ReadWriteLock::tryEnterWrite() const throw()
  11966. {
  11967. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11968. const ScopedLock sl (accessLock);
  11969. if (readerThreads.size() + numWriters == 0
  11970. || threadId == writerThreadId
  11971. || (readerThreads.size() == 2
  11972. && readerThreads.getUnchecked(0) == threadId))
  11973. {
  11974. writerThreadId = threadId;
  11975. ++numWriters;
  11976. return true;
  11977. }
  11978. return false;
  11979. }
  11980. void ReadWriteLock::exitWrite() const throw()
  11981. {
  11982. const ScopedLock sl (accessLock);
  11983. // check this thread actually had the lock..
  11984. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  11985. if (--numWriters == 0)
  11986. {
  11987. writerThreadId = 0;
  11988. waitEvent.signal();
  11989. }
  11990. }
  11991. END_JUCE_NAMESPACE
  11992. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  11993. /*** Start of inlined file: juce_Thread.cpp ***/
  11994. BEGIN_JUCE_NAMESPACE
  11995. // these functions are implemented in the platform-specific code.
  11996. void* juce_createThread (void* userData);
  11997. void juce_killThread (void* handle);
  11998. bool juce_setThreadPriority (void* handle, int priority);
  11999. void juce_setCurrentThreadName (const String& name);
  12000. #if JUCE_WIN32
  12001. void juce_CloseThreadHandle (void* handle);
  12002. #endif
  12003. void Thread::threadEntryPoint (Thread* const thread)
  12004. {
  12005. {
  12006. const ScopedLock sl (runningThreadsLock);
  12007. runningThreads.add (thread);
  12008. }
  12009. JUCE_TRY
  12010. {
  12011. thread->threadId_ = Thread::getCurrentThreadId();
  12012. if (thread->threadName_.isNotEmpty())
  12013. juce_setCurrentThreadName (thread->threadName_);
  12014. if (thread->startSuspensionEvent_.wait (10000))
  12015. {
  12016. if (thread->affinityMask_ != 0)
  12017. setCurrentThreadAffinityMask (thread->affinityMask_);
  12018. thread->run();
  12019. }
  12020. }
  12021. JUCE_CATCH_ALL_ASSERT
  12022. {
  12023. const ScopedLock sl (runningThreadsLock);
  12024. jassert (runningThreads.contains (thread));
  12025. runningThreads.removeValue (thread);
  12026. }
  12027. #if JUCE_WIN32
  12028. juce_CloseThreadHandle (thread->threadHandle_);
  12029. #endif
  12030. thread->threadHandle_ = 0;
  12031. thread->threadId_ = 0;
  12032. }
  12033. // used to wrap the incoming call from the platform-specific code
  12034. void JUCE_API juce_threadEntryPoint (void* userData)
  12035. {
  12036. Thread::threadEntryPoint (static_cast <Thread*> (userData));
  12037. }
  12038. Thread::Thread (const String& threadName)
  12039. : threadName_ (threadName),
  12040. threadHandle_ (0),
  12041. threadPriority_ (5),
  12042. threadId_ (0),
  12043. affinityMask_ (0),
  12044. threadShouldExit_ (false)
  12045. {
  12046. }
  12047. Thread::~Thread()
  12048. {
  12049. stopThread (100);
  12050. }
  12051. void Thread::startThread()
  12052. {
  12053. const ScopedLock sl (startStopLock);
  12054. threadShouldExit_ = false;
  12055. if (threadHandle_ == 0)
  12056. {
  12057. threadHandle_ = juce_createThread (this);
  12058. juce_setThreadPriority (threadHandle_, threadPriority_);
  12059. startSuspensionEvent_.signal();
  12060. }
  12061. }
  12062. void Thread::startThread (const int priority)
  12063. {
  12064. const ScopedLock sl (startStopLock);
  12065. if (threadHandle_ == 0)
  12066. {
  12067. threadPriority_ = priority;
  12068. startThread();
  12069. }
  12070. else
  12071. {
  12072. setPriority (priority);
  12073. }
  12074. }
  12075. bool Thread::isThreadRunning() const
  12076. {
  12077. return threadHandle_ != 0;
  12078. }
  12079. void Thread::signalThreadShouldExit()
  12080. {
  12081. threadShouldExit_ = true;
  12082. }
  12083. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12084. {
  12085. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12086. jassert (getThreadId() != getCurrentThreadId());
  12087. const int sleepMsPerIteration = 5;
  12088. int count = timeOutMilliseconds / sleepMsPerIteration;
  12089. while (isThreadRunning())
  12090. {
  12091. if (timeOutMilliseconds > 0 && --count < 0)
  12092. return false;
  12093. sleep (sleepMsPerIteration);
  12094. }
  12095. return true;
  12096. }
  12097. void Thread::stopThread (const int timeOutMilliseconds)
  12098. {
  12099. // agh! You can't stop the thread that's calling this method! How on earth
  12100. // would that work??
  12101. jassert (getCurrentThreadId() != getThreadId());
  12102. const ScopedLock sl (startStopLock);
  12103. if (isThreadRunning())
  12104. {
  12105. signalThreadShouldExit();
  12106. notify();
  12107. if (timeOutMilliseconds != 0)
  12108. waitForThreadToExit (timeOutMilliseconds);
  12109. if (isThreadRunning())
  12110. {
  12111. // very bad karma if this point is reached, as
  12112. // there are bound to be locks and events left in
  12113. // silly states when a thread is killed by force..
  12114. jassertfalse
  12115. Logger::writeToLog ("!! killing thread by force !!");
  12116. juce_killThread (threadHandle_);
  12117. threadHandle_ = 0;
  12118. threadId_ = 0;
  12119. const ScopedLock sl2 (runningThreadsLock);
  12120. runningThreads.removeValue (this);
  12121. }
  12122. }
  12123. }
  12124. bool Thread::setPriority (const int priority)
  12125. {
  12126. const ScopedLock sl (startStopLock);
  12127. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12128. if (worked)
  12129. threadPriority_ = priority;
  12130. return worked;
  12131. }
  12132. bool Thread::setCurrentThreadPriority (const int priority)
  12133. {
  12134. return juce_setThreadPriority (0, priority);
  12135. }
  12136. void Thread::setAffinityMask (const uint32 affinityMask)
  12137. {
  12138. affinityMask_ = affinityMask;
  12139. }
  12140. bool Thread::wait (const int timeOutMilliseconds) const
  12141. {
  12142. return defaultEvent_.wait (timeOutMilliseconds);
  12143. }
  12144. void Thread::notify() const
  12145. {
  12146. defaultEvent_.signal();
  12147. }
  12148. int Thread::getNumRunningThreads()
  12149. {
  12150. return runningThreads.size();
  12151. }
  12152. Thread* Thread::getCurrentThread()
  12153. {
  12154. const ThreadID thisId = getCurrentThreadId();
  12155. const ScopedLock sl (runningThreadsLock);
  12156. for (int i = runningThreads.size(); --i >= 0;)
  12157. {
  12158. Thread* const t = runningThreads.getUnchecked(i);
  12159. if (t->threadId_ == thisId)
  12160. return t;
  12161. }
  12162. return 0;
  12163. }
  12164. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12165. {
  12166. {
  12167. const ScopedLock sl (runningThreadsLock);
  12168. for (int i = runningThreads.size(); --i >= 0;)
  12169. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12170. }
  12171. for (;;)
  12172. {
  12173. Thread* firstThread;
  12174. {
  12175. const ScopedLock sl (runningThreadsLock);
  12176. firstThread = runningThreads.getFirst();
  12177. }
  12178. if (firstThread == 0)
  12179. break;
  12180. firstThread->stopThread (timeOutMilliseconds);
  12181. }
  12182. }
  12183. Array<Thread*> Thread::runningThreads;
  12184. CriticalSection Thread::runningThreadsLock;
  12185. END_JUCE_NAMESPACE
  12186. /*** End of inlined file: juce_Thread.cpp ***/
  12187. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12188. BEGIN_JUCE_NAMESPACE
  12189. ThreadPoolJob::ThreadPoolJob (const String& name)
  12190. : jobName (name),
  12191. pool (0),
  12192. shouldStop (false),
  12193. isActive (false),
  12194. shouldBeDeleted (false)
  12195. {
  12196. }
  12197. ThreadPoolJob::~ThreadPoolJob()
  12198. {
  12199. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12200. // to remove it first!
  12201. jassert (pool == 0 || ! pool->contains (this));
  12202. }
  12203. const String ThreadPoolJob::getJobName() const
  12204. {
  12205. return jobName;
  12206. }
  12207. void ThreadPoolJob::setJobName (const String& newName)
  12208. {
  12209. jobName = newName;
  12210. }
  12211. void ThreadPoolJob::signalJobShouldExit()
  12212. {
  12213. shouldStop = true;
  12214. }
  12215. class ThreadPool::ThreadPoolThread : public Thread
  12216. {
  12217. public:
  12218. ThreadPoolThread (ThreadPool& pool_)
  12219. : Thread ("Pool"),
  12220. pool (pool_),
  12221. busy (false)
  12222. {
  12223. }
  12224. ~ThreadPoolThread()
  12225. {
  12226. }
  12227. void run()
  12228. {
  12229. while (! threadShouldExit())
  12230. {
  12231. if (! pool.runNextJob())
  12232. wait (500);
  12233. }
  12234. }
  12235. private:
  12236. ThreadPool& pool;
  12237. bool volatile busy;
  12238. ThreadPoolThread (const ThreadPoolThread&);
  12239. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12240. };
  12241. ThreadPool::ThreadPool (const int numThreads,
  12242. const bool startThreadsOnlyWhenNeeded,
  12243. const int stopThreadsWhenNotUsedTimeoutMs)
  12244. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12245. priority (5)
  12246. {
  12247. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12248. for (int i = jmax (1, numThreads); --i >= 0;)
  12249. threads.add (new ThreadPoolThread (*this));
  12250. if (! startThreadsOnlyWhenNeeded)
  12251. for (int i = threads.size(); --i >= 0;)
  12252. threads.getUnchecked(i)->startThread (priority);
  12253. }
  12254. ThreadPool::~ThreadPool()
  12255. {
  12256. removeAllJobs (true, 4000);
  12257. int i;
  12258. for (i = threads.size(); --i >= 0;)
  12259. threads.getUnchecked(i)->signalThreadShouldExit();
  12260. for (i = threads.size(); --i >= 0;)
  12261. threads.getUnchecked(i)->stopThread (500);
  12262. }
  12263. void ThreadPool::addJob (ThreadPoolJob* const job)
  12264. {
  12265. jassert (job != 0);
  12266. jassert (job->pool == 0);
  12267. if (job->pool == 0)
  12268. {
  12269. job->pool = this;
  12270. job->shouldStop = false;
  12271. job->isActive = false;
  12272. {
  12273. const ScopedLock sl (lock);
  12274. jobs.add (job);
  12275. int numRunning = 0;
  12276. for (int i = threads.size(); --i >= 0;)
  12277. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12278. ++numRunning;
  12279. if (numRunning < threads.size())
  12280. {
  12281. bool startedOne = false;
  12282. int n = 1000;
  12283. while (--n >= 0 && ! startedOne)
  12284. {
  12285. for (int i = threads.size(); --i >= 0;)
  12286. {
  12287. if (! threads.getUnchecked(i)->isThreadRunning())
  12288. {
  12289. threads.getUnchecked(i)->startThread (priority);
  12290. startedOne = true;
  12291. break;
  12292. }
  12293. }
  12294. if (! startedOne)
  12295. Thread::sleep (2);
  12296. }
  12297. }
  12298. }
  12299. for (int i = threads.size(); --i >= 0;)
  12300. threads.getUnchecked(i)->notify();
  12301. }
  12302. }
  12303. int ThreadPool::getNumJobs() const
  12304. {
  12305. return jobs.size();
  12306. }
  12307. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12308. {
  12309. const ScopedLock sl (lock);
  12310. return jobs [index];
  12311. }
  12312. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12313. {
  12314. const ScopedLock sl (lock);
  12315. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12316. }
  12317. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12318. {
  12319. const ScopedLock sl (lock);
  12320. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12321. }
  12322. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12323. const int timeOutMs) const
  12324. {
  12325. if (job != 0)
  12326. {
  12327. const uint32 start = Time::getMillisecondCounter();
  12328. while (contains (job))
  12329. {
  12330. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12331. return false;
  12332. jobFinishedSignal.wait (2);
  12333. }
  12334. }
  12335. return true;
  12336. }
  12337. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12338. const bool interruptIfRunning,
  12339. const int timeOutMs)
  12340. {
  12341. bool dontWait = true;
  12342. if (job != 0)
  12343. {
  12344. const ScopedLock sl (lock);
  12345. if (jobs.contains (job))
  12346. {
  12347. if (job->isActive)
  12348. {
  12349. if (interruptIfRunning)
  12350. job->signalJobShouldExit();
  12351. dontWait = false;
  12352. }
  12353. else
  12354. {
  12355. jobs.removeValue (job);
  12356. }
  12357. }
  12358. }
  12359. return dontWait || waitForJobToFinish (job, timeOutMs);
  12360. }
  12361. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12362. const int timeOutMs,
  12363. const bool deleteInactiveJobs,
  12364. ThreadPool::JobSelector* selectedJobsToRemove)
  12365. {
  12366. Array <ThreadPoolJob*> jobsToWaitFor;
  12367. {
  12368. const ScopedLock sl (lock);
  12369. for (int i = jobs.size(); --i >= 0;)
  12370. {
  12371. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12372. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12373. {
  12374. if (job->isActive)
  12375. {
  12376. jobsToWaitFor.add (job);
  12377. if (interruptRunningJobs)
  12378. job->signalJobShouldExit();
  12379. }
  12380. else
  12381. {
  12382. jobs.remove (i);
  12383. if (deleteInactiveJobs)
  12384. delete job;
  12385. }
  12386. }
  12387. }
  12388. }
  12389. const uint32 start = Time::getMillisecondCounter();
  12390. for (;;)
  12391. {
  12392. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12393. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12394. jobsToWaitFor.remove (i);
  12395. if (jobsToWaitFor.size() == 0)
  12396. break;
  12397. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12398. return false;
  12399. jobFinishedSignal.wait (20);
  12400. }
  12401. return true;
  12402. }
  12403. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12404. {
  12405. StringArray s;
  12406. const ScopedLock sl (lock);
  12407. for (int i = 0; i < jobs.size(); ++i)
  12408. {
  12409. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12410. if (job->isActive || ! onlyReturnActiveJobs)
  12411. s.add (job->getJobName());
  12412. }
  12413. return s;
  12414. }
  12415. bool ThreadPool::setThreadPriorities (const int newPriority)
  12416. {
  12417. bool ok = true;
  12418. if (priority != newPriority)
  12419. {
  12420. priority = newPriority;
  12421. for (int i = threads.size(); --i >= 0;)
  12422. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12423. ok = false;
  12424. }
  12425. return ok;
  12426. }
  12427. bool ThreadPool::runNextJob()
  12428. {
  12429. ThreadPoolJob* job = 0;
  12430. {
  12431. const ScopedLock sl (lock);
  12432. for (int i = 0; i < jobs.size(); ++i)
  12433. {
  12434. job = jobs[i];
  12435. if (job != 0 && ! (job->isActive || job->shouldStop))
  12436. break;
  12437. job = 0;
  12438. }
  12439. if (job != 0)
  12440. job->isActive = true;
  12441. }
  12442. if (job != 0)
  12443. {
  12444. JUCE_TRY
  12445. {
  12446. ThreadPoolJob::JobStatus result = job->runJob();
  12447. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12448. const ScopedLock sl (lock);
  12449. if (jobs.contains (job))
  12450. {
  12451. job->isActive = false;
  12452. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12453. {
  12454. job->pool = 0;
  12455. job->shouldStop = true;
  12456. jobs.removeValue (job);
  12457. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12458. delete job;
  12459. jobFinishedSignal.signal();
  12460. }
  12461. else
  12462. {
  12463. // move the job to the end of the queue if it wants another go
  12464. jobs.move (jobs.indexOf (job), -1);
  12465. }
  12466. }
  12467. }
  12468. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12469. catch (...)
  12470. {
  12471. const ScopedLock sl (lock);
  12472. jobs.removeValue (job);
  12473. }
  12474. #endif
  12475. }
  12476. else
  12477. {
  12478. if (threadStopTimeout > 0
  12479. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12480. {
  12481. const ScopedLock sl (lock);
  12482. if (jobs.size() == 0)
  12483. for (int i = threads.size(); --i >= 0;)
  12484. threads.getUnchecked(i)->signalThreadShouldExit();
  12485. }
  12486. else
  12487. {
  12488. return false;
  12489. }
  12490. }
  12491. return true;
  12492. }
  12493. END_JUCE_NAMESPACE
  12494. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12495. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12496. BEGIN_JUCE_NAMESPACE
  12497. TimeSliceThread::TimeSliceThread (const String& threadName)
  12498. : Thread (threadName),
  12499. index (0),
  12500. clientBeingCalled (0),
  12501. clientsChanged (false)
  12502. {
  12503. }
  12504. TimeSliceThread::~TimeSliceThread()
  12505. {
  12506. stopThread (2000);
  12507. }
  12508. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12509. {
  12510. const ScopedLock sl (listLock);
  12511. clients.addIfNotAlreadyThere (client);
  12512. clientsChanged = true;
  12513. notify();
  12514. }
  12515. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12516. {
  12517. const ScopedLock sl1 (listLock);
  12518. clientsChanged = true;
  12519. // if there's a chance we're in the middle of calling this client, we need to
  12520. // also lock the outer lock..
  12521. if (clientBeingCalled == client)
  12522. {
  12523. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12524. const ScopedLock sl2 (callbackLock);
  12525. const ScopedLock sl3 (listLock);
  12526. clients.removeValue (client);
  12527. }
  12528. else
  12529. {
  12530. clients.removeValue (client);
  12531. }
  12532. }
  12533. int TimeSliceThread::getNumClients() const
  12534. {
  12535. return clients.size();
  12536. }
  12537. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12538. {
  12539. const ScopedLock sl (listLock);
  12540. return clients [i];
  12541. }
  12542. void TimeSliceThread::run()
  12543. {
  12544. int numCallsSinceBusy = 0;
  12545. while (! threadShouldExit())
  12546. {
  12547. int timeToWait = 500;
  12548. {
  12549. const ScopedLock sl (callbackLock);
  12550. {
  12551. const ScopedLock sl2 (listLock);
  12552. if (clients.size() > 0)
  12553. {
  12554. index = (index + 1) % clients.size();
  12555. clientBeingCalled = clients [index];
  12556. }
  12557. else
  12558. {
  12559. index = 0;
  12560. clientBeingCalled = 0;
  12561. }
  12562. if (clientsChanged)
  12563. {
  12564. clientsChanged = false;
  12565. numCallsSinceBusy = 0;
  12566. }
  12567. }
  12568. if (clientBeingCalled != 0)
  12569. {
  12570. if (clientBeingCalled->useTimeSlice())
  12571. numCallsSinceBusy = 0;
  12572. else
  12573. ++numCallsSinceBusy;
  12574. if (numCallsSinceBusy >= clients.size())
  12575. timeToWait = 500;
  12576. else if (index == 0)
  12577. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12578. else
  12579. timeToWait = 0;
  12580. }
  12581. }
  12582. if (timeToWait > 0)
  12583. wait (timeToWait);
  12584. }
  12585. }
  12586. END_JUCE_NAMESPACE
  12587. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12588. #endif
  12589. #if JUCE_BUILD_MISC
  12590. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12591. BEGIN_JUCE_NAMESPACE
  12592. class ValueTree::SetPropertyAction : public UndoableAction
  12593. {
  12594. public:
  12595. SetPropertyAction (const SharedObjectPtr& target_, const var::identifier& name_,
  12596. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12597. : target (target_), name (name_), newValue (newValue_),
  12598. isAddingNewProperty (isAddingNewProperty_),
  12599. isDeletingProperty (isDeletingProperty_)
  12600. {
  12601. if (! isAddingNewProperty)
  12602. oldValue = target_->getProperty (name_);
  12603. }
  12604. ~SetPropertyAction() {}
  12605. bool perform()
  12606. {
  12607. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12608. if (isDeletingProperty)
  12609. target->removeProperty (name, 0);
  12610. else
  12611. target->setProperty (name, newValue, 0);
  12612. return true;
  12613. }
  12614. bool undo()
  12615. {
  12616. if (isAddingNewProperty)
  12617. target->removeProperty (name, 0);
  12618. else
  12619. target->setProperty (name, oldValue, 0);
  12620. return true;
  12621. }
  12622. int getSizeInUnits()
  12623. {
  12624. return (int) sizeof (*this); //xxx should be more accurate
  12625. }
  12626. private:
  12627. const SharedObjectPtr target;
  12628. const var::identifier name;
  12629. const var newValue;
  12630. var oldValue;
  12631. const bool isAddingNewProperty, isDeletingProperty;
  12632. SetPropertyAction (const SetPropertyAction&);
  12633. SetPropertyAction& operator= (const SetPropertyAction&);
  12634. };
  12635. class ValueTree::AddOrRemoveChildAction : public UndoableAction
  12636. {
  12637. public:
  12638. AddOrRemoveChildAction (const SharedObjectPtr& target_, const int childIndex_,
  12639. const SharedObjectPtr& newChild_)
  12640. : target (target_),
  12641. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12642. childIndex (childIndex_),
  12643. isDeleting (newChild_ == 0)
  12644. {
  12645. jassert (child != 0);
  12646. }
  12647. ~AddOrRemoveChildAction() {}
  12648. bool perform()
  12649. {
  12650. if (isDeleting)
  12651. target->removeChild (childIndex, 0);
  12652. else
  12653. target->addChild (child, childIndex, 0);
  12654. return true;
  12655. }
  12656. bool undo()
  12657. {
  12658. if (isDeleting)
  12659. {
  12660. target->addChild (child, childIndex, 0);
  12661. }
  12662. else
  12663. {
  12664. // If you hit this, it seems that your object's state is getting confused - probably
  12665. // because you've interleaved some undoable and non-undoable operations?
  12666. jassert (childIndex < target->children.size());
  12667. target->removeChild (childIndex, 0);
  12668. }
  12669. return true;
  12670. }
  12671. int getSizeInUnits()
  12672. {
  12673. return (int) sizeof (*this); //xxx should be more accurate
  12674. }
  12675. private:
  12676. const SharedObjectPtr target, child;
  12677. const int childIndex;
  12678. const bool isDeleting;
  12679. AddOrRemoveChildAction (const AddOrRemoveChildAction&);
  12680. AddOrRemoveChildAction& operator= (const AddOrRemoveChildAction&);
  12681. };
  12682. class ValueTree::MoveChildAction : public UndoableAction
  12683. {
  12684. public:
  12685. MoveChildAction (const SharedObjectPtr& target_,
  12686. const int startIndex_, const int endIndex_)
  12687. : target (target_),
  12688. startIndex (startIndex_),
  12689. endIndex (endIndex_)
  12690. {
  12691. }
  12692. ~MoveChildAction() {}
  12693. bool perform()
  12694. {
  12695. target->moveChild (startIndex, endIndex, 0);
  12696. return true;
  12697. }
  12698. bool undo()
  12699. {
  12700. target->moveChild (endIndex, startIndex, 0);
  12701. return true;
  12702. }
  12703. int getSizeInUnits()
  12704. {
  12705. return (int) sizeof (*this); //xxx should be more accurate
  12706. }
  12707. private:
  12708. const SharedObjectPtr target, child;
  12709. const int startIndex, endIndex;
  12710. MoveChildAction (const MoveChildAction&);
  12711. MoveChildAction& operator= (const MoveChildAction&);
  12712. };
  12713. ValueTree::SharedObject::SharedObject (const String& type_)
  12714. : type (type_), parent (0)
  12715. {
  12716. }
  12717. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12718. : type (other.type), properties (other.properties), parent (0)
  12719. {
  12720. for (int i = 0; i < other.children.size(); ++i)
  12721. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12722. }
  12723. ValueTree::SharedObject::~SharedObject()
  12724. {
  12725. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12726. for (int i = children.size(); --i >= 0;)
  12727. {
  12728. const SharedObjectPtr c (children.getUnchecked(i));
  12729. c->parent = 0;
  12730. children.remove (i);
  12731. c->sendParentChangeMessage();
  12732. }
  12733. }
  12734. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12735. {
  12736. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12737. {
  12738. ValueTree* const v = valueTreesWithListeners[i];
  12739. if (v != 0)
  12740. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12741. }
  12742. }
  12743. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12744. {
  12745. ValueTree tree (this);
  12746. ValueTree::SharedObject* t = this;
  12747. while (t != 0)
  12748. {
  12749. t->sendPropertyChangeMessage (tree, property);
  12750. t = t->parent;
  12751. }
  12752. }
  12753. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12754. {
  12755. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12756. {
  12757. ValueTree* const v = valueTreesWithListeners[i];
  12758. if (v != 0)
  12759. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12760. }
  12761. }
  12762. void ValueTree::SharedObject::sendChildChangeMessage()
  12763. {
  12764. ValueTree tree (this);
  12765. ValueTree::SharedObject* t = this;
  12766. while (t != 0)
  12767. {
  12768. t->sendChildChangeMessage (tree);
  12769. t = t->parent;
  12770. }
  12771. }
  12772. void ValueTree::SharedObject::sendParentChangeMessage()
  12773. {
  12774. ValueTree tree (this);
  12775. int i;
  12776. for (i = children.size(); --i >= 0;)
  12777. {
  12778. SharedObject* const t = children[i];
  12779. if (t != 0)
  12780. t->sendParentChangeMessage();
  12781. }
  12782. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12783. {
  12784. ValueTree* const v = valueTreesWithListeners[i];
  12785. if (v != 0)
  12786. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12787. }
  12788. }
  12789. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12790. {
  12791. return properties [name];
  12792. }
  12793. const var ValueTree::SharedObject::getProperty (const var::identifier& name, const var& defaultReturnValue) const
  12794. {
  12795. return properties.getWithDefault (name, defaultReturnValue);
  12796. }
  12797. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12798. {
  12799. if (undoManager == 0)
  12800. {
  12801. if (properties.set (name, newValue))
  12802. sendPropertyChangeMessage (name);
  12803. }
  12804. else
  12805. {
  12806. var* const existingValue = properties.getItem (name);
  12807. if (existingValue != 0)
  12808. {
  12809. if (*existingValue != newValue)
  12810. undoManager->perform (new SetPropertyAction (this, name, newValue, false, false));
  12811. }
  12812. else
  12813. {
  12814. undoManager->perform (new SetPropertyAction (this, name, newValue, true, false));
  12815. }
  12816. }
  12817. }
  12818. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12819. {
  12820. return properties.contains (name);
  12821. }
  12822. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12823. {
  12824. if (undoManager == 0)
  12825. {
  12826. if (properties.remove (name))
  12827. sendPropertyChangeMessage (name);
  12828. }
  12829. else
  12830. {
  12831. if (properties.contains (name))
  12832. undoManager->perform (new SetPropertyAction (this, name, var::null, false, true));
  12833. }
  12834. }
  12835. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12836. {
  12837. if (undoManager == 0)
  12838. {
  12839. while (properties.size() > 0)
  12840. {
  12841. const var::identifier name (properties.getName (properties.size() - 1));
  12842. properties.remove (name);
  12843. sendPropertyChangeMessage (name);
  12844. }
  12845. }
  12846. else
  12847. {
  12848. for (int i = properties.size(); --i >= 0;)
  12849. undoManager->perform (new SetPropertyAction (this, properties.getName(i), var::null, false, true));
  12850. }
  12851. }
  12852. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12853. {
  12854. for (int i = 0; i < children.size(); ++i)
  12855. if (children.getUnchecked(i)->type == typeToMatch)
  12856. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12857. return ValueTree::invalid;
  12858. }
  12859. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12860. {
  12861. for (int i = 0; i < children.size(); ++i)
  12862. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12863. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12864. return ValueTree::invalid;
  12865. }
  12866. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12867. {
  12868. const SharedObject* p = parent;
  12869. while (p != 0)
  12870. {
  12871. if (p == possibleParent)
  12872. return true;
  12873. p = p->parent;
  12874. }
  12875. return false;
  12876. }
  12877. int ValueTree::SharedObject::indexOf (const ValueTree& child) const
  12878. {
  12879. return children.indexOf (child.object);
  12880. }
  12881. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12882. {
  12883. if (child != 0 && child->parent != this)
  12884. {
  12885. if (child != this && ! isAChildOf (child))
  12886. {
  12887. // You should always make sure that a child is removed from its previous parent before
  12888. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12889. // undomanager should be used when removing it from its current parent..
  12890. jassert (child->parent == 0);
  12891. if (child->parent != 0)
  12892. {
  12893. jassert (child->parent->children.indexOf (child) >= 0);
  12894. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12895. }
  12896. if (undoManager == 0)
  12897. {
  12898. children.insert (index, child);
  12899. child->parent = this;
  12900. sendChildChangeMessage();
  12901. child->sendParentChangeMessage();
  12902. }
  12903. else
  12904. {
  12905. if (index < 0)
  12906. index = children.size();
  12907. undoManager->perform (new AddOrRemoveChildAction (this, index, child));
  12908. }
  12909. }
  12910. else
  12911. {
  12912. // You're attempting to create a recursive loop! A node
  12913. // can't be a child of one of its own children!
  12914. jassertfalse
  12915. }
  12916. }
  12917. }
  12918. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12919. {
  12920. const SharedObjectPtr child (children [childIndex]);
  12921. if (child != 0)
  12922. {
  12923. if (undoManager == 0)
  12924. {
  12925. children.remove (childIndex);
  12926. child->parent = 0;
  12927. sendChildChangeMessage();
  12928. child->sendParentChangeMessage();
  12929. }
  12930. else
  12931. {
  12932. undoManager->perform (new AddOrRemoveChildAction (this, childIndex, 0));
  12933. }
  12934. }
  12935. }
  12936. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  12937. {
  12938. while (children.size() > 0)
  12939. removeChild (children.size() - 1, undoManager);
  12940. }
  12941. void ValueTree::SharedObject::moveChild (int currentIndex, int newIndex, UndoManager* undoManager)
  12942. {
  12943. // The source index must be a valid index!
  12944. jassert (((unsigned int) currentIndex) < (unsigned int) children.size());
  12945. if (currentIndex != newIndex
  12946. && ((unsigned int) currentIndex) < (unsigned int) children.size())
  12947. {
  12948. if (undoManager == 0)
  12949. {
  12950. children.move (currentIndex, newIndex);
  12951. sendChildChangeMessage();
  12952. }
  12953. else
  12954. {
  12955. if (((unsigned int) newIndex) >= (unsigned int) children.size())
  12956. newIndex = children.size() - 1;
  12957. undoManager->perform (new MoveChildAction (this, currentIndex, newIndex));
  12958. }
  12959. }
  12960. }
  12961. ValueTree::ValueTree() throw()
  12962. : object (0)
  12963. {
  12964. }
  12965. const ValueTree ValueTree::invalid;
  12966. ValueTree::ValueTree (const String& type_)
  12967. : object (new ValueTree::SharedObject (type_))
  12968. {
  12969. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  12970. }
  12971. ValueTree::ValueTree (SharedObject* const object_)
  12972. : object (object_)
  12973. {
  12974. }
  12975. ValueTree::ValueTree (const ValueTree& other)
  12976. : object (other.object)
  12977. {
  12978. }
  12979. ValueTree& ValueTree::operator= (const ValueTree& other)
  12980. {
  12981. if (listeners.size() > 0)
  12982. {
  12983. if (object != 0)
  12984. object->valueTreesWithListeners.removeValue (this);
  12985. if (other.object != 0)
  12986. other.object->valueTreesWithListeners.add (this);
  12987. }
  12988. object = other.object;
  12989. return *this;
  12990. }
  12991. ValueTree::~ValueTree()
  12992. {
  12993. if (listeners.size() > 0 && object != 0)
  12994. object->valueTreesWithListeners.removeValue (this);
  12995. }
  12996. bool ValueTree::operator== (const ValueTree& other) const
  12997. {
  12998. return object == other.object;
  12999. }
  13000. bool ValueTree::operator!= (const ValueTree& other) const
  13001. {
  13002. return object != other.object;
  13003. }
  13004. ValueTree ValueTree::createCopy() const
  13005. {
  13006. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13007. }
  13008. bool ValueTree::hasType (const String& typeName) const
  13009. {
  13010. return object != 0 && object->type == typeName;
  13011. }
  13012. const String ValueTree::getType() const
  13013. {
  13014. return object != 0 ? object->type : String::empty;
  13015. }
  13016. ValueTree ValueTree::getParent() const
  13017. {
  13018. return ValueTree (object != 0 ? object->parent : (SharedObject*) 0);
  13019. }
  13020. const var& ValueTree::operator[] (const var::identifier& name) const
  13021. {
  13022. return object == 0 ? var::null : object->getProperty (name);
  13023. }
  13024. const var& ValueTree::getProperty (const var::identifier& name) const
  13025. {
  13026. return object == 0 ? var::null : object->getProperty (name);
  13027. }
  13028. const var ValueTree::getProperty (const var::identifier& name, const var& defaultReturnValue) const
  13029. {
  13030. return object == 0 ? defaultReturnValue : object->getProperty (name, defaultReturnValue);
  13031. }
  13032. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13033. {
  13034. jassert (name.name.isNotEmpty());
  13035. if (object != 0 && name.name.isNotEmpty())
  13036. object->setProperty (name, newValue, undoManager);
  13037. }
  13038. bool ValueTree::hasProperty (const var::identifier& name) const
  13039. {
  13040. return object != 0 && object->hasProperty (name);
  13041. }
  13042. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13043. {
  13044. if (object != 0)
  13045. object->removeProperty (name, undoManager);
  13046. }
  13047. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13048. {
  13049. if (object != 0)
  13050. object->removeAllProperties (undoManager);
  13051. }
  13052. int ValueTree::getNumProperties() const
  13053. {
  13054. return object == 0 ? 0 : object->properties.size();
  13055. }
  13056. const var::identifier ValueTree::getPropertyName (const int index) const
  13057. {
  13058. return object == 0 ? var::identifier()
  13059. : object->properties.getName (index);
  13060. }
  13061. class ValueTreePropertyValueSource : public Value::ValueSource,
  13062. public ValueTree::Listener
  13063. {
  13064. public:
  13065. ValueTreePropertyValueSource (const ValueTree& tree_,
  13066. const var::identifier& property_,
  13067. UndoManager* const undoManager_)
  13068. : tree (tree_),
  13069. property (property_),
  13070. undoManager (undoManager_)
  13071. {
  13072. tree.addListener (this);
  13073. }
  13074. ~ValueTreePropertyValueSource()
  13075. {
  13076. tree.removeListener (this);
  13077. }
  13078. const var getValue() const
  13079. {
  13080. return tree [property];
  13081. }
  13082. void setValue (const var& newValue)
  13083. {
  13084. tree.setProperty (property, newValue, undoManager);
  13085. }
  13086. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13087. {
  13088. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13089. sendChangeMessage (false);
  13090. }
  13091. void valueTreeChildrenChanged (ValueTree&) {}
  13092. void valueTreeParentChanged (ValueTree&) {}
  13093. private:
  13094. ValueTree tree;
  13095. const var::identifier property;
  13096. UndoManager* const undoManager;
  13097. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13098. };
  13099. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13100. {
  13101. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13102. }
  13103. int ValueTree::getNumChildren() const
  13104. {
  13105. return object == 0 ? 0 : object->children.size();
  13106. }
  13107. ValueTree ValueTree::getChild (int index) const
  13108. {
  13109. return ValueTree (object != 0 ? (SharedObject*) object->children [index] : (SharedObject*) 0);
  13110. }
  13111. ValueTree ValueTree::getChildWithName (const String& type) const
  13112. {
  13113. return object != 0 ? object->getChildWithName (type) : ValueTree::invalid;
  13114. }
  13115. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13116. {
  13117. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree::invalid;
  13118. }
  13119. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13120. {
  13121. return object != 0 && object->isAChildOf (possibleParent.object);
  13122. }
  13123. int ValueTree::indexOf (const ValueTree& child) const
  13124. {
  13125. return object != 0 ? object->indexOf (child) : -1;
  13126. }
  13127. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13128. {
  13129. if (object != 0)
  13130. object->addChild (child.object, index, undoManager);
  13131. }
  13132. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13133. {
  13134. if (object != 0)
  13135. object->removeChild (childIndex, undoManager);
  13136. }
  13137. void ValueTree::removeChild (const ValueTree& child, UndoManager* const undoManager)
  13138. {
  13139. if (object != 0)
  13140. object->removeChild (object->children.indexOf (child.object), undoManager);
  13141. }
  13142. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13143. {
  13144. if (object != 0)
  13145. object->removeAllChildren (undoManager);
  13146. }
  13147. void ValueTree::moveChild (int currentIndex, int newIndex, UndoManager* undoManager)
  13148. {
  13149. if (object != 0)
  13150. object->moveChild (currentIndex, newIndex, undoManager);
  13151. }
  13152. void ValueTree::addListener (Listener* listener)
  13153. {
  13154. if (listener != 0)
  13155. {
  13156. if (listeners.size() == 0 && object != 0)
  13157. object->valueTreesWithListeners.add (this);
  13158. listeners.add (listener);
  13159. }
  13160. }
  13161. void ValueTree::removeListener (Listener* listener)
  13162. {
  13163. listeners.remove (listener);
  13164. if (listeners.size() == 0 && object != 0)
  13165. object->valueTreesWithListeners.removeValue (this);
  13166. }
  13167. XmlElement* ValueTree::SharedObject::createXml() const
  13168. {
  13169. XmlElement* xml = new XmlElement (type);
  13170. int i;
  13171. for (i = 0; i < properties.size(); ++i)
  13172. {
  13173. var::identifier name (properties.getName(i));
  13174. const var& v = properties [name];
  13175. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13176. xml->setAttribute (name.name, v.toString());
  13177. }
  13178. for (i = 0; i < children.size(); ++i)
  13179. xml->addChildElement (children.getUnchecked(i)->createXml());
  13180. return xml;
  13181. }
  13182. XmlElement* ValueTree::createXml() const
  13183. {
  13184. return object != 0 ? object->createXml() : 0;
  13185. }
  13186. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13187. {
  13188. ValueTree v (xml.getTagName());
  13189. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13190. for (int i = 0; i < numAtts; ++i)
  13191. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13192. forEachXmlChildElement (xml, e)
  13193. {
  13194. v.addChild (fromXml (*e), -1, 0);
  13195. }
  13196. return v;
  13197. }
  13198. void ValueTree::writeToStream (OutputStream& output)
  13199. {
  13200. output.writeString (getType());
  13201. const int numProps = getNumProperties();
  13202. output.writeCompressedInt (numProps);
  13203. int i;
  13204. for (i = 0; i < numProps; ++i)
  13205. {
  13206. const var::identifier name (getPropertyName(i));
  13207. output.writeString (name.name);
  13208. getProperty(name).writeToStream (output);
  13209. }
  13210. const int numChildren = getNumChildren();
  13211. output.writeCompressedInt (numChildren);
  13212. for (i = 0; i < numChildren; ++i)
  13213. getChild (i).writeToStream (output);
  13214. }
  13215. ValueTree ValueTree::readFromStream (InputStream& input)
  13216. {
  13217. String type (input.readString());
  13218. if (type.isEmpty())
  13219. return ValueTree::invalid;
  13220. ValueTree v (type);
  13221. const int numProps = input.readCompressedInt();
  13222. if (numProps < 0)
  13223. {
  13224. jassertfalse // trying to read corrupted data!
  13225. return v;
  13226. }
  13227. int i;
  13228. for (i = 0; i < numProps; ++i)
  13229. {
  13230. const String name (input.readString());
  13231. jassert (name.isNotEmpty());
  13232. const var value (var::readFromStream (input));
  13233. v.setProperty (name, value, 0);
  13234. }
  13235. const int numChildren = input.readCompressedInt();
  13236. for (i = 0; i < numChildren; ++i)
  13237. v.addChild (readFromStream (input), -1, 0);
  13238. return v;
  13239. }
  13240. END_JUCE_NAMESPACE
  13241. /*** End of inlined file: juce_ValueTree.cpp ***/
  13242. /*** Start of inlined file: juce_Value.cpp ***/
  13243. BEGIN_JUCE_NAMESPACE
  13244. Value::ValueSource::ValueSource()
  13245. {
  13246. }
  13247. Value::ValueSource::~ValueSource()
  13248. {
  13249. }
  13250. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13251. {
  13252. if (synchronous)
  13253. {
  13254. for (int i = valuesWithListeners.size(); --i >= 0;)
  13255. {
  13256. Value* const v = valuesWithListeners[i];
  13257. if (v != 0)
  13258. v->callListeners();
  13259. }
  13260. }
  13261. else
  13262. {
  13263. triggerAsyncUpdate();
  13264. }
  13265. }
  13266. void Value::ValueSource::handleAsyncUpdate()
  13267. {
  13268. sendChangeMessage (true);
  13269. }
  13270. class SimpleValueSource : public Value::ValueSource
  13271. {
  13272. public:
  13273. SimpleValueSource()
  13274. {
  13275. }
  13276. SimpleValueSource (const var& initialValue)
  13277. : value (initialValue)
  13278. {
  13279. }
  13280. ~SimpleValueSource()
  13281. {
  13282. }
  13283. const var getValue() const
  13284. {
  13285. return value;
  13286. }
  13287. void setValue (const var& newValue)
  13288. {
  13289. if (newValue != value)
  13290. {
  13291. value = newValue;
  13292. sendChangeMessage (false);
  13293. }
  13294. }
  13295. private:
  13296. var value;
  13297. SimpleValueSource (const SimpleValueSource&);
  13298. SimpleValueSource& operator= (const SimpleValueSource&);
  13299. };
  13300. Value::Value()
  13301. : value (new SimpleValueSource())
  13302. {
  13303. }
  13304. Value::Value (ValueSource* const value_)
  13305. : value (value_)
  13306. {
  13307. jassert (value_ != 0);
  13308. }
  13309. Value::Value (const var& initialValue)
  13310. : value (new SimpleValueSource (initialValue))
  13311. {
  13312. }
  13313. Value::Value (const Value& other)
  13314. : value (other.value)
  13315. {
  13316. }
  13317. Value& Value::operator= (const Value& other)
  13318. {
  13319. value = other.value;
  13320. return *this;
  13321. }
  13322. Value::~Value()
  13323. {
  13324. if (listeners.size() > 0)
  13325. value->valuesWithListeners.removeValue (this);
  13326. }
  13327. const var Value::getValue() const
  13328. {
  13329. return value->getValue();
  13330. }
  13331. Value::operator const var() const
  13332. {
  13333. return getValue();
  13334. }
  13335. void Value::setValue (const var& newValue)
  13336. {
  13337. value->setValue (newValue);
  13338. }
  13339. const String Value::toString() const
  13340. {
  13341. return value->getValue().toString();
  13342. }
  13343. Value& Value::operator= (const var& newValue)
  13344. {
  13345. value->setValue (newValue);
  13346. return *this;
  13347. }
  13348. void Value::referTo (const Value& valueToReferTo)
  13349. {
  13350. if (valueToReferTo.value != value)
  13351. {
  13352. if (listeners.size() > 0)
  13353. {
  13354. value->valuesWithListeners.removeValue (this);
  13355. valueToReferTo.value->valuesWithListeners.add (this);
  13356. }
  13357. value = valueToReferTo.value;
  13358. callListeners();
  13359. }
  13360. }
  13361. bool Value::refersToSameSourceAs (const Value& other) const
  13362. {
  13363. return value == other.value;
  13364. }
  13365. bool Value::operator== (const Value& other) const
  13366. {
  13367. return value == other.value || value->getValue() == other.getValue();
  13368. }
  13369. bool Value::operator!= (const Value& other) const
  13370. {
  13371. return value != other.value && value->getValue() != other.getValue();
  13372. }
  13373. void Value::addListener (Listener* const listener)
  13374. {
  13375. if (listener != 0)
  13376. {
  13377. if (listeners.size() == 0)
  13378. value->valuesWithListeners.add (this);
  13379. listeners.add (listener);
  13380. }
  13381. }
  13382. void Value::removeListener (Listener* const listener)
  13383. {
  13384. listeners.remove (listener);
  13385. if (listeners.size() == 0)
  13386. value->valuesWithListeners.removeValue (this);
  13387. }
  13388. void Value::callListeners()
  13389. {
  13390. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13391. listeners.call (&Listener::valueChanged, v);
  13392. }
  13393. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13394. {
  13395. return stream << value.toString();
  13396. }
  13397. END_JUCE_NAMESPACE
  13398. /*** End of inlined file: juce_Value.cpp ***/
  13399. /*** Start of inlined file: juce_Application.cpp ***/
  13400. #if JUCE_MSVC
  13401. #pragma warning (push)
  13402. #pragma warning (disable: 4245 4514 4100)
  13403. #include <crtdbg.h>
  13404. #pragma warning (pop)
  13405. #endif
  13406. BEGIN_JUCE_NAMESPACE
  13407. void juce_setCurrentThreadName (const String& name);
  13408. static JUCEApplication* appInstance = 0;
  13409. JUCEApplication::JUCEApplication()
  13410. : appReturnValue (0),
  13411. stillInitialising (true)
  13412. {
  13413. }
  13414. JUCEApplication::~JUCEApplication()
  13415. {
  13416. if (appLock != 0)
  13417. {
  13418. appLock->exit();
  13419. appLock = 0;
  13420. }
  13421. }
  13422. JUCEApplication* JUCEApplication::getInstance() throw()
  13423. {
  13424. return appInstance;
  13425. }
  13426. bool JUCEApplication::isInitialising() const throw()
  13427. {
  13428. return stillInitialising;
  13429. }
  13430. const String JUCEApplication::getApplicationVersion()
  13431. {
  13432. return String::empty;
  13433. }
  13434. bool JUCEApplication::moreThanOneInstanceAllowed()
  13435. {
  13436. return true;
  13437. }
  13438. void JUCEApplication::anotherInstanceStarted (const String&)
  13439. {
  13440. }
  13441. void JUCEApplication::systemRequestedQuit()
  13442. {
  13443. quit();
  13444. }
  13445. void JUCEApplication::quit()
  13446. {
  13447. MessageManager::getInstance()->stopDispatchLoop();
  13448. }
  13449. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13450. {
  13451. appReturnValue = newReturnValue;
  13452. }
  13453. void JUCEApplication::unhandledException (const std::exception*,
  13454. const String&,
  13455. const int)
  13456. {
  13457. jassertfalse
  13458. }
  13459. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13460. const char* const sourceFile,
  13461. const int lineNumber)
  13462. {
  13463. if (appInstance != 0)
  13464. appInstance->unhandledException (e, sourceFile, lineNumber);
  13465. }
  13466. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13467. {
  13468. return 0;
  13469. }
  13470. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13471. {
  13472. commands.add (StandardApplicationCommandIDs::quit);
  13473. }
  13474. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13475. {
  13476. if (commandID == StandardApplicationCommandIDs::quit)
  13477. {
  13478. result.setInfo (TRANS("Quit"),
  13479. TRANS("Quits the application"),
  13480. "Application",
  13481. 0);
  13482. result.defaultKeypresses.add (KeyPress ('q', ModifierKeys::commandModifier, 0));
  13483. }
  13484. }
  13485. bool JUCEApplication::perform (const InvocationInfo& info)
  13486. {
  13487. if (info.commandID == StandardApplicationCommandIDs::quit)
  13488. {
  13489. systemRequestedQuit();
  13490. return true;
  13491. }
  13492. return false;
  13493. }
  13494. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13495. {
  13496. if (! app->initialiseApp (commandLine))
  13497. return 0;
  13498. // now loop until a quit message is received..
  13499. JUCE_TRY
  13500. {
  13501. MessageManager::getInstance()->runDispatchLoop();
  13502. }
  13503. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13504. catch (const std::exception& e)
  13505. {
  13506. app->unhandledException (&e, __FILE__, __LINE__);
  13507. }
  13508. catch (...)
  13509. {
  13510. app->unhandledException (0, __FILE__, __LINE__);
  13511. }
  13512. #endif
  13513. return shutdownAppAndClearUp();
  13514. }
  13515. bool JUCEApplication::initialiseApp (String& commandLine)
  13516. {
  13517. jassert (appInstance == 0);
  13518. appInstance = this;
  13519. commandLineParameters = commandLine.trim();
  13520. commandLine = String::empty;
  13521. initialiseJuce_GUI();
  13522. #if ! JUCE_IPHONE
  13523. jassert (appLock == 0); // initialiseApp must only be called once!
  13524. if (! moreThanOneInstanceAllowed())
  13525. {
  13526. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13527. if (! appLock->enter(0))
  13528. {
  13529. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13530. delete appInstance;
  13531. appInstance = 0;
  13532. DBG ("Another instance is running - quitting...");
  13533. return false;
  13534. }
  13535. }
  13536. #endif
  13537. // let the app do its setting-up..
  13538. initialise (commandLineParameters);
  13539. // register for broadcast new app messages
  13540. MessageManager::getInstance()->registerBroadcastListener (this);
  13541. stillInitialising = false;
  13542. return true;
  13543. }
  13544. int JUCEApplication::shutdownAppAndClearUp()
  13545. {
  13546. jassert (appInstance != 0);
  13547. ScopedPointer<JUCEApplication> app (appInstance);
  13548. int returnValue = 0;
  13549. MessageManager::getInstance()->deregisterBroadcastListener (static_cast <JUCEApplication*> (app));
  13550. static bool reentrancyCheck = false;
  13551. if (! reentrancyCheck)
  13552. {
  13553. reentrancyCheck = true;
  13554. JUCE_TRY
  13555. {
  13556. // give the app a chance to clean up..
  13557. app->shutdown();
  13558. }
  13559. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13560. catch (const std::exception& e)
  13561. {
  13562. app->unhandledException (&e, __FILE__, __LINE__);
  13563. }
  13564. catch (...)
  13565. {
  13566. app->unhandledException (0, __FILE__, __LINE__);
  13567. }
  13568. #endif
  13569. JUCE_TRY
  13570. {
  13571. shutdownJuce_GUI();
  13572. returnValue = app->getApplicationReturnValue();
  13573. appInstance = 0;
  13574. app = 0;
  13575. }
  13576. JUCE_CATCH_ALL_ASSERT
  13577. reentrancyCheck = false;
  13578. }
  13579. return returnValue;
  13580. }
  13581. #if JUCE_IPHONE
  13582. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13583. #endif
  13584. #if ! JUCE_WINDOWS
  13585. extern const char* juce_Argv0;
  13586. #endif
  13587. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13588. {
  13589. #if ! JUCE_WINDOWS
  13590. juce_Argv0 = argv[0];
  13591. #endif
  13592. #if JUCE_IPHONE
  13593. const ScopedAutoReleasePool pool;
  13594. return juce_IPhoneMain (argc, argv, newApp);
  13595. #else
  13596. #if JUCE_MAC
  13597. const ScopedAutoReleasePool pool;
  13598. #endif
  13599. String cmd;
  13600. for (int i = 1; i < argc; ++i)
  13601. cmd << argv[i] << ' ';
  13602. return JUCEApplication::main (cmd, newApp);
  13603. #endif
  13604. }
  13605. void JUCEApplication::actionListenerCallback (const String& message)
  13606. {
  13607. if (message.startsWith (getApplicationName() + "/"))
  13608. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13609. }
  13610. static bool juceInitialisedGUI = false;
  13611. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13612. {
  13613. if (! juceInitialisedGUI)
  13614. {
  13615. #if JUCE_MAC || JUCE_IPHONE
  13616. const ScopedAutoReleasePool pool;
  13617. #endif
  13618. juceInitialisedGUI = true;
  13619. initialiseJuce_NonGUI();
  13620. MessageManager::getInstance();
  13621. LookAndFeel::setDefaultLookAndFeel (0);
  13622. juce_setCurrentThreadName ("Juce Message Thread");
  13623. #if JUCE_WINDOWS && JUCE_DEBUG
  13624. // This section is just for catching people who mess up their project settings and
  13625. // turn RTTI off..
  13626. try
  13627. {
  13628. TextButton tb (String::empty);
  13629. Component* c = &tb;
  13630. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13631. c = dynamic_cast <Button*> (c);
  13632. }
  13633. catch (...)
  13634. {
  13635. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13636. // got as far as this catch statement, then why haven't you got exception catching
  13637. // turned on in the debugger???
  13638. jassertfalse
  13639. }
  13640. #endif
  13641. }
  13642. }
  13643. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13644. {
  13645. if (juceInitialisedGUI)
  13646. {
  13647. #if JUCE_MAC
  13648. const ScopedAutoReleasePool pool;
  13649. #endif
  13650. {
  13651. DeletedAtShutdown::deleteAll();
  13652. LookAndFeel::clearDefaultLookAndFeel();
  13653. }
  13654. delete MessageManager::getInstance();
  13655. shutdownJuce_NonGUI();
  13656. juceInitialisedGUI = false;
  13657. }
  13658. }
  13659. END_JUCE_NAMESPACE
  13660. /*** End of inlined file: juce_Application.cpp ***/
  13661. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13662. BEGIN_JUCE_NAMESPACE
  13663. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13664. : commandID (commandID_),
  13665. flags (0)
  13666. {
  13667. }
  13668. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13669. const String& description_,
  13670. const String& categoryName_,
  13671. const int flags_) throw()
  13672. {
  13673. shortName = shortName_;
  13674. description = description_;
  13675. categoryName = categoryName_;
  13676. flags = flags_;
  13677. }
  13678. void ApplicationCommandInfo::setActive (const bool b) throw()
  13679. {
  13680. if (b)
  13681. flags &= ~isDisabled;
  13682. else
  13683. flags |= isDisabled;
  13684. }
  13685. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13686. {
  13687. if (b)
  13688. flags |= isTicked;
  13689. else
  13690. flags &= ~isTicked;
  13691. }
  13692. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13693. {
  13694. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13695. }
  13696. END_JUCE_NAMESPACE
  13697. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13698. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13699. BEGIN_JUCE_NAMESPACE
  13700. ApplicationCommandManager::ApplicationCommandManager()
  13701. : firstTarget (0)
  13702. {
  13703. keyMappings = new KeyPressMappingSet (this);
  13704. Desktop::getInstance().addFocusChangeListener (this);
  13705. }
  13706. ApplicationCommandManager::~ApplicationCommandManager()
  13707. {
  13708. Desktop::getInstance().removeFocusChangeListener (this);
  13709. keyMappings = 0;
  13710. }
  13711. void ApplicationCommandManager::clearCommands()
  13712. {
  13713. commands.clear();
  13714. keyMappings->clearAllKeyPresses();
  13715. triggerAsyncUpdate();
  13716. }
  13717. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13718. {
  13719. // zero isn't a valid command ID!
  13720. jassert (newCommand.commandID != 0);
  13721. // the name isn't optional!
  13722. jassert (newCommand.shortName.isNotEmpty());
  13723. if (getCommandForID (newCommand.commandID) == 0)
  13724. {
  13725. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13726. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13727. commands.add (newInfo);
  13728. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13729. triggerAsyncUpdate();
  13730. }
  13731. else
  13732. {
  13733. // trying to re-register the same command with different parameters?
  13734. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13735. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13736. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13737. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13738. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13739. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13740. }
  13741. }
  13742. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13743. {
  13744. if (target != 0)
  13745. {
  13746. Array <CommandID> commandIDs;
  13747. target->getAllCommands (commandIDs);
  13748. for (int i = 0; i < commandIDs.size(); ++i)
  13749. {
  13750. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13751. target->getCommandInfo (info.commandID, info);
  13752. registerCommand (info);
  13753. }
  13754. }
  13755. }
  13756. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13757. {
  13758. for (int i = commands.size(); --i >= 0;)
  13759. {
  13760. if (commands.getUnchecked (i)->commandID == commandID)
  13761. {
  13762. commands.remove (i);
  13763. triggerAsyncUpdate();
  13764. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13765. for (int j = keys.size(); --j >= 0;)
  13766. keyMappings->removeKeyPress (keys.getReference (j));
  13767. }
  13768. }
  13769. }
  13770. void ApplicationCommandManager::commandStatusChanged()
  13771. {
  13772. triggerAsyncUpdate();
  13773. }
  13774. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13775. {
  13776. for (int i = commands.size(); --i >= 0;)
  13777. if (commands.getUnchecked(i)->commandID == commandID)
  13778. return commands.getUnchecked(i);
  13779. return 0;
  13780. }
  13781. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13782. {
  13783. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13784. return (ci != 0) ? ci->shortName : String::empty;
  13785. }
  13786. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13787. {
  13788. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13789. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13790. : String::empty;
  13791. }
  13792. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13793. {
  13794. StringArray s;
  13795. for (int i = 0; i < commands.size(); ++i)
  13796. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13797. return s;
  13798. }
  13799. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13800. {
  13801. Array <CommandID> results;
  13802. for (int i = 0; i < commands.size(); ++i)
  13803. if (commands.getUnchecked(i)->categoryName == categoryName)
  13804. results.add (commands.getUnchecked(i)->commandID);
  13805. return results;
  13806. }
  13807. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13808. {
  13809. ApplicationCommandTarget::InvocationInfo info (commandID);
  13810. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13811. return invoke (info, asynchronously);
  13812. }
  13813. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13814. {
  13815. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13816. // manager first..
  13817. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13818. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13819. if (target == 0)
  13820. return false;
  13821. ApplicationCommandInfo commandInfo (0);
  13822. target->getCommandInfo (info_.commandID, commandInfo);
  13823. ApplicationCommandTarget::InvocationInfo info (info_);
  13824. info.commandFlags = commandInfo.flags;
  13825. sendListenerInvokeCallback (info);
  13826. const bool ok = target->invoke (info, asynchronously);
  13827. commandStatusChanged();
  13828. return ok;
  13829. }
  13830. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13831. {
  13832. return firstTarget != 0 ? firstTarget
  13833. : findDefaultComponentTarget();
  13834. }
  13835. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13836. {
  13837. firstTarget = newTarget;
  13838. }
  13839. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13840. ApplicationCommandInfo& upToDateInfo)
  13841. {
  13842. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13843. if (target == 0)
  13844. target = JUCEApplication::getInstance();
  13845. if (target != 0)
  13846. target = target->getTargetForCommand (commandID);
  13847. if (target != 0)
  13848. target->getCommandInfo (commandID, upToDateInfo);
  13849. return target;
  13850. }
  13851. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13852. {
  13853. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13854. if (target == 0 && c != 0)
  13855. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13856. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13857. return target;
  13858. }
  13859. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13860. {
  13861. Component* c = Component::getCurrentlyFocusedComponent();
  13862. if (c == 0)
  13863. {
  13864. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13865. if (activeWindow != 0)
  13866. {
  13867. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13868. if (c == 0)
  13869. c = activeWindow;
  13870. }
  13871. }
  13872. if (c == 0 && Process::isForegroundProcess())
  13873. {
  13874. // getting a bit desperate now - try all desktop comps..
  13875. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13876. {
  13877. ApplicationCommandTarget* const target
  13878. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13879. ->getPeer()->getLastFocusedSubcomponent());
  13880. if (target != 0)
  13881. return target;
  13882. }
  13883. }
  13884. if (c != 0)
  13885. {
  13886. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13887. // if we're focused on a ResizableWindow, chances are that it's the content
  13888. // component that really should get the event. And if not, the event will
  13889. // still be passed up to the top level window anyway, so let's send it to the
  13890. // content comp.
  13891. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13892. c = resizableWindow->getContentComponent();
  13893. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13894. if (target != 0)
  13895. return target;
  13896. }
  13897. return JUCEApplication::getInstance();
  13898. }
  13899. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13900. {
  13901. listeners.add (listener);
  13902. }
  13903. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13904. {
  13905. listeners.remove (listener);
  13906. }
  13907. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13908. {
  13909. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13910. }
  13911. void ApplicationCommandManager::handleAsyncUpdate()
  13912. {
  13913. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13914. }
  13915. void ApplicationCommandManager::globalFocusChanged (Component*)
  13916. {
  13917. commandStatusChanged();
  13918. }
  13919. END_JUCE_NAMESPACE
  13920. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13921. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13922. BEGIN_JUCE_NAMESPACE
  13923. ApplicationCommandTarget::ApplicationCommandTarget()
  13924. {
  13925. }
  13926. ApplicationCommandTarget::~ApplicationCommandTarget()
  13927. {
  13928. messageInvoker = 0;
  13929. }
  13930. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13931. {
  13932. if (isCommandActive (info.commandID))
  13933. {
  13934. if (async)
  13935. {
  13936. if (messageInvoker == 0)
  13937. messageInvoker = new CommandTargetMessageInvoker (this);
  13938. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13939. return true;
  13940. }
  13941. else
  13942. {
  13943. const bool success = perform (info);
  13944. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13945. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13946. // returns the command's info.
  13947. return success;
  13948. }
  13949. }
  13950. return false;
  13951. }
  13952. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13953. {
  13954. Component* c = dynamic_cast <Component*> (this);
  13955. if (c != 0)
  13956. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13957. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13958. return 0;
  13959. }
  13960. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13961. {
  13962. ApplicationCommandTarget* target = this;
  13963. int depth = 0;
  13964. while (target != 0)
  13965. {
  13966. Array <CommandID> commandIDs;
  13967. target->getAllCommands (commandIDs);
  13968. if (commandIDs.contains (commandID))
  13969. return target;
  13970. target = target->getNextCommandTarget();
  13971. ++depth;
  13972. jassert (depth < 100); // could be a recursive command chain??
  13973. jassert (target != this); // definitely a recursive command chain!
  13974. if (depth > 100 || target == this)
  13975. break;
  13976. }
  13977. if (target == 0)
  13978. {
  13979. target = JUCEApplication::getInstance();
  13980. if (target != 0)
  13981. {
  13982. Array <CommandID> commandIDs;
  13983. target->getAllCommands (commandIDs);
  13984. if (commandIDs.contains (commandID))
  13985. return target;
  13986. }
  13987. }
  13988. return 0;
  13989. }
  13990. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  13991. {
  13992. ApplicationCommandInfo info (commandID);
  13993. info.flags = ApplicationCommandInfo::isDisabled;
  13994. getCommandInfo (commandID, info);
  13995. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  13996. }
  13997. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  13998. {
  13999. ApplicationCommandTarget* target = this;
  14000. int depth = 0;
  14001. while (target != 0)
  14002. {
  14003. if (target->tryToInvoke (info, async))
  14004. return true;
  14005. target = target->getNextCommandTarget();
  14006. ++depth;
  14007. jassert (depth < 100); // could be a recursive command chain??
  14008. jassert (target != this); // definitely a recursive command chain!
  14009. if (depth > 100 || target == this)
  14010. break;
  14011. }
  14012. if (target == 0)
  14013. {
  14014. target = JUCEApplication::getInstance();
  14015. if (target != 0)
  14016. return target->tryToInvoke (info, async);
  14017. }
  14018. return false;
  14019. }
  14020. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14021. {
  14022. ApplicationCommandTarget::InvocationInfo info (commandID);
  14023. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14024. return invoke (info, asynchronously);
  14025. }
  14026. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14027. : commandID (commandID_),
  14028. commandFlags (0),
  14029. invocationMethod (direct),
  14030. originatingComponent (0),
  14031. isKeyDown (false),
  14032. millisecsSinceKeyPressed (0)
  14033. {
  14034. }
  14035. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14036. : owner (owner_)
  14037. {
  14038. }
  14039. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14040. {
  14041. }
  14042. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14043. {
  14044. const ScopedPointer <InvocationInfo> info (static_cast <InvocationInfo*> (message.pointerParameter));
  14045. owner->tryToInvoke (*info, false);
  14046. }
  14047. END_JUCE_NAMESPACE
  14048. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14049. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14050. BEGIN_JUCE_NAMESPACE
  14051. juce_ImplementSingleton (ApplicationProperties)
  14052. ApplicationProperties::ApplicationProperties() throw()
  14053. : msBeforeSaving (3000),
  14054. options (PropertiesFile::storeAsBinary),
  14055. commonSettingsAreReadOnly (0)
  14056. {
  14057. }
  14058. ApplicationProperties::~ApplicationProperties()
  14059. {
  14060. closeFiles();
  14061. clearSingletonInstance();
  14062. }
  14063. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14064. const String& fileNameSuffix,
  14065. const String& folderName_,
  14066. const int millisecondsBeforeSaving,
  14067. const int propertiesFileOptions) throw()
  14068. {
  14069. appName = applicationName;
  14070. fileSuffix = fileNameSuffix;
  14071. folderName = folderName_;
  14072. msBeforeSaving = millisecondsBeforeSaving;
  14073. options = propertiesFileOptions;
  14074. }
  14075. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14076. const bool testCommonSettings,
  14077. const bool showWarningDialogOnFailure)
  14078. {
  14079. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14080. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14081. if (! (userOk && commonOk))
  14082. {
  14083. if (showWarningDialogOnFailure)
  14084. {
  14085. String filenames;
  14086. if (userProps != 0 && ! userOk)
  14087. filenames << '\n' << userProps->getFile().getFullPathName();
  14088. if (commonProps != 0 && ! commonOk)
  14089. filenames << '\n' << commonProps->getFile().getFullPathName();
  14090. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14091. appName + TRANS(" - Unable to save settings"),
  14092. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14093. + appName + TRANS(" needs to be able to write to the following files:\n")
  14094. + filenames
  14095. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14096. }
  14097. return false;
  14098. }
  14099. return true;
  14100. }
  14101. void ApplicationProperties::openFiles() throw()
  14102. {
  14103. // You need to call setStorageParameters() before trying to get hold of the
  14104. // properties!
  14105. jassert (appName.isNotEmpty());
  14106. if (appName.isNotEmpty())
  14107. {
  14108. if (userProps == 0)
  14109. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14110. false, msBeforeSaving, options);
  14111. if (commonProps == 0)
  14112. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14113. true, msBeforeSaving, options);
  14114. userProps->setFallbackPropertySet (commonProps);
  14115. }
  14116. }
  14117. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14118. {
  14119. if (userProps == 0)
  14120. openFiles();
  14121. return userProps;
  14122. }
  14123. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14124. {
  14125. if (commonProps == 0)
  14126. openFiles();
  14127. if (returnUserPropsIfReadOnly)
  14128. {
  14129. if (commonSettingsAreReadOnly == 0)
  14130. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14131. if (commonSettingsAreReadOnly > 0)
  14132. return userProps;
  14133. }
  14134. return commonProps;
  14135. }
  14136. bool ApplicationProperties::saveIfNeeded()
  14137. {
  14138. return (userProps == 0 || userProps->saveIfNeeded())
  14139. && (commonProps == 0 || commonProps->saveIfNeeded());
  14140. }
  14141. void ApplicationProperties::closeFiles()
  14142. {
  14143. userProps = 0;
  14144. commonProps = 0;
  14145. }
  14146. END_JUCE_NAMESPACE
  14147. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14148. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14149. BEGIN_JUCE_NAMESPACE
  14150. static VoidArray objectsToDelete;
  14151. static CriticalSection lock;
  14152. DeletedAtShutdown::DeletedAtShutdown()
  14153. {
  14154. const ScopedLock sl (lock);
  14155. objectsToDelete.add (this);
  14156. }
  14157. DeletedAtShutdown::~DeletedAtShutdown()
  14158. {
  14159. const ScopedLock sl (lock);
  14160. objectsToDelete.removeValue (this);
  14161. }
  14162. void DeletedAtShutdown::deleteAll()
  14163. {
  14164. // make a local copy of the array, so it can't get into a loop if something
  14165. // creates another DeletedAtShutdown object during its destructor.
  14166. VoidArray localCopy;
  14167. {
  14168. const ScopedLock sl (lock);
  14169. localCopy = objectsToDelete;
  14170. }
  14171. for (int i = localCopy.size(); --i >= 0;)
  14172. {
  14173. JUCE_TRY
  14174. {
  14175. DeletedAtShutdown* deletee = static_cast <DeletedAtShutdown*> (localCopy.getUnchecked(i));
  14176. // double-check that it's not already been deleted during another object's destructor.
  14177. {
  14178. const ScopedLock sl (lock);
  14179. if (! objectsToDelete.contains (deletee))
  14180. deletee = 0;
  14181. }
  14182. delete deletee;
  14183. }
  14184. JUCE_CATCH_EXCEPTION
  14185. }
  14186. // if no objects got re-created during shutdown, this should have been emptied by their
  14187. // destructors
  14188. jassert (objectsToDelete.size() == 0);
  14189. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14190. }
  14191. END_JUCE_NAMESPACE
  14192. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14193. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14194. BEGIN_JUCE_NAMESPACE
  14195. namespace PropertyFileConstants
  14196. {
  14197. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14198. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14199. static const char* const fileTag = "PROPERTIES";
  14200. static const char* const valueTag = "VALUE";
  14201. static const char* const nameAttribute = "name";
  14202. static const char* const valueAttribute = "val";
  14203. }
  14204. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving,
  14205. const int options_, InterProcessLock* const processLock_)
  14206. : PropertySet (ignoreCaseOfKeyNames),
  14207. file (f),
  14208. timerInterval (millisecondsBeforeSaving),
  14209. options (options_),
  14210. loadedOk (false),
  14211. needsWriting (false),
  14212. processLock (processLock_)
  14213. {
  14214. // You need to correctly specify just one storage format for the file
  14215. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14216. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14217. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14218. ProcessScopedLock pl (createProcessLock());
  14219. if (pl != 0 && ! pl->isLocked())
  14220. return; // locking failure..
  14221. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14222. if (fileStream != 0)
  14223. {
  14224. int magicNumber = fileStream->readInt();
  14225. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14226. {
  14227. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14228. magicNumber = PropertyFileConstants::magicNumber;
  14229. }
  14230. if (magicNumber == PropertyFileConstants::magicNumber)
  14231. {
  14232. loadedOk = true;
  14233. BufferedInputStream in (fileStream.release(), 2048, true);
  14234. int numValues = in.readInt();
  14235. while (--numValues >= 0 && ! in.isExhausted())
  14236. {
  14237. const String key (in.readString());
  14238. const String value (in.readString());
  14239. jassert (key.isNotEmpty());
  14240. if (key.isNotEmpty())
  14241. getAllProperties().set (key, value);
  14242. }
  14243. }
  14244. else
  14245. {
  14246. // Not a binary props file - let's see if it's XML..
  14247. fileStream = 0;
  14248. XmlDocument parser (f);
  14249. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14250. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14251. {
  14252. doc = parser.getDocumentElement();
  14253. if (doc != 0)
  14254. {
  14255. loadedOk = true;
  14256. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14257. {
  14258. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14259. if (name.isNotEmpty())
  14260. {
  14261. getAllProperties().set (name,
  14262. e->getFirstChildElement() != 0
  14263. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14264. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14265. }
  14266. }
  14267. }
  14268. else
  14269. {
  14270. // must be a pretty broken XML file we're trying to parse here,
  14271. // or a sign that this object needs an InterProcessLock,
  14272. // or just a failure reading the file. This last reason is why
  14273. // we don't jassertfalse here.
  14274. }
  14275. }
  14276. }
  14277. }
  14278. else
  14279. {
  14280. loadedOk = ! f.exists();
  14281. }
  14282. }
  14283. PropertiesFile::~PropertiesFile()
  14284. {
  14285. if (! saveIfNeeded())
  14286. jassertfalse;
  14287. }
  14288. InterProcessLock::ScopedLockType* PropertiesFile::createProcessLock() const
  14289. {
  14290. return processLock != 0 ? new InterProcessLock::ScopedLockType (*processLock) : 0;
  14291. }
  14292. bool PropertiesFile::saveIfNeeded()
  14293. {
  14294. const ScopedLock sl (getLock());
  14295. return (! needsWriting) || save();
  14296. }
  14297. bool PropertiesFile::needsToBeSaved() const
  14298. {
  14299. const ScopedLock sl (getLock());
  14300. return needsWriting;
  14301. }
  14302. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14303. {
  14304. const ScopedLock sl (getLock());
  14305. needsWriting = needsToBeSaved;
  14306. }
  14307. bool PropertiesFile::save()
  14308. {
  14309. const ScopedLock sl (getLock());
  14310. stopTimer();
  14311. if (file == File::nonexistent
  14312. || file.isDirectory()
  14313. || ! file.getParentDirectory().createDirectory())
  14314. return false;
  14315. if ((options & storeAsXML) != 0)
  14316. {
  14317. XmlElement doc (PropertyFileConstants::fileTag);
  14318. for (int i = 0; i < getAllProperties().size(); ++i)
  14319. {
  14320. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14321. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14322. // if the value seems to contain xml, store it as such..
  14323. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14324. XmlElement* const childElement = xmlContent.getDocumentElement();
  14325. if (childElement != 0)
  14326. e->addChildElement (childElement);
  14327. else
  14328. e->setAttribute (PropertyFileConstants::valueAttribute,
  14329. getAllProperties().getAllValues() [i]);
  14330. }
  14331. ProcessScopedLock pl (createProcessLock());
  14332. if (pl != 0 && ! pl->isLocked())
  14333. return false; // locking failure..
  14334. if (doc.writeToFile (file, String::empty))
  14335. {
  14336. needsWriting = false;
  14337. return true;
  14338. }
  14339. }
  14340. else
  14341. {
  14342. ProcessScopedLock pl (createProcessLock());
  14343. if (pl != 0 && ! pl->isLocked())
  14344. return false; // locking failure..
  14345. TemporaryFile tempFile (file);
  14346. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14347. if (out != 0)
  14348. {
  14349. if ((options & storeAsCompressedBinary) != 0)
  14350. {
  14351. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14352. out->flush();
  14353. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14354. }
  14355. else
  14356. {
  14357. // have you set up the storage option flags correctly?
  14358. jassert ((options & storeAsBinary) != 0);
  14359. out->writeInt (PropertyFileConstants::magicNumber);
  14360. }
  14361. const int numProperties = getAllProperties().size();
  14362. out->writeInt (numProperties);
  14363. for (int i = 0; i < numProperties; ++i)
  14364. {
  14365. out->writeString (getAllProperties().getAllKeys() [i]);
  14366. out->writeString (getAllProperties().getAllValues() [i]);
  14367. }
  14368. out = 0;
  14369. if (tempFile.overwriteTargetFileWithTemporary())
  14370. {
  14371. needsWriting = false;
  14372. return true;
  14373. }
  14374. }
  14375. }
  14376. return false;
  14377. }
  14378. void PropertiesFile::timerCallback()
  14379. {
  14380. saveIfNeeded();
  14381. }
  14382. void PropertiesFile::propertyChanged()
  14383. {
  14384. sendChangeMessage (this);
  14385. needsWriting = true;
  14386. if (timerInterval > 0)
  14387. startTimer (timerInterval);
  14388. else if (timerInterval == 0)
  14389. saveIfNeeded();
  14390. }
  14391. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14392. const String& fileNameSuffix,
  14393. const String& folderName,
  14394. const bool commonToAllUsers)
  14395. {
  14396. // mustn't have illegal characters in this name..
  14397. jassert (applicationName == File::createLegalFileName (applicationName));
  14398. #if JUCE_MAC || JUCE_IPHONE
  14399. File dir (commonToAllUsers ? "/Library/Preferences"
  14400. : "~/Library/Preferences");
  14401. if (folderName.isNotEmpty())
  14402. dir = dir.getChildFile (folderName);
  14403. #endif
  14404. #ifdef JUCE_LINUX
  14405. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14406. + (folderName.isNotEmpty() ? folderName
  14407. : ("." + applicationName)));
  14408. #endif
  14409. #if JUCE_WIN32
  14410. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14411. : File::userApplicationDataDirectory));
  14412. if (dir == File::nonexistent)
  14413. return File::nonexistent;
  14414. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14415. : applicationName);
  14416. #endif
  14417. return dir.getChildFile (applicationName)
  14418. .withFileExtension (fileNameSuffix);
  14419. }
  14420. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14421. const String& fileNameSuffix,
  14422. const String& folderName,
  14423. const bool commonToAllUsers,
  14424. const int millisecondsBeforeSaving,
  14425. const int propertiesFileOptions,
  14426. InterProcessLock* processLock_)
  14427. {
  14428. const File file (getDefaultAppSettingsFile (applicationName,
  14429. fileNameSuffix,
  14430. folderName,
  14431. commonToAllUsers));
  14432. jassert (file != File::nonexistent);
  14433. if (file == File::nonexistent)
  14434. return 0;
  14435. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions,processLock_);
  14436. }
  14437. END_JUCE_NAMESPACE
  14438. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14439. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14440. BEGIN_JUCE_NAMESPACE
  14441. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14442. const String& fileWildcard_,
  14443. const String& openFileDialogTitle_,
  14444. const String& saveFileDialogTitle_)
  14445. : changedSinceSave (false),
  14446. fileExtension (fileExtension_),
  14447. fileWildcard (fileWildcard_),
  14448. openFileDialogTitle (openFileDialogTitle_),
  14449. saveFileDialogTitle (saveFileDialogTitle_)
  14450. {
  14451. }
  14452. FileBasedDocument::~FileBasedDocument()
  14453. {
  14454. }
  14455. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14456. {
  14457. if (changedSinceSave != hasChanged)
  14458. {
  14459. changedSinceSave = hasChanged;
  14460. sendChangeMessage (this);
  14461. }
  14462. }
  14463. void FileBasedDocument::changed()
  14464. {
  14465. changedSinceSave = true;
  14466. sendChangeMessage (this);
  14467. }
  14468. void FileBasedDocument::setFile (const File& newFile)
  14469. {
  14470. if (documentFile != newFile)
  14471. {
  14472. documentFile = newFile;
  14473. changed();
  14474. }
  14475. }
  14476. bool FileBasedDocument::loadFrom (const File& newFile,
  14477. const bool showMessageOnFailure)
  14478. {
  14479. MouseCursor::showWaitCursor();
  14480. const File oldFile (documentFile);
  14481. documentFile = newFile;
  14482. String error;
  14483. if (newFile.existsAsFile())
  14484. {
  14485. error = loadDocument (newFile);
  14486. if (error.isEmpty())
  14487. {
  14488. setChangedFlag (false);
  14489. MouseCursor::hideWaitCursor();
  14490. setLastDocumentOpened (newFile);
  14491. return true;
  14492. }
  14493. }
  14494. else
  14495. {
  14496. error = "The file doesn't exist";
  14497. }
  14498. documentFile = oldFile;
  14499. MouseCursor::hideWaitCursor();
  14500. if (showMessageOnFailure)
  14501. {
  14502. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14503. TRANS("Failed to open file..."),
  14504. TRANS("There was an error while trying to load the file:\n\n")
  14505. + newFile.getFullPathName()
  14506. + "\n\n"
  14507. + error);
  14508. }
  14509. return false;
  14510. }
  14511. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14512. {
  14513. FileChooser fc (openFileDialogTitle,
  14514. getLastDocumentOpened(),
  14515. fileWildcard);
  14516. if (fc.browseForFileToOpen())
  14517. return loadFrom (fc.getResult(), showMessageOnFailure);
  14518. return false;
  14519. }
  14520. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14521. const bool showMessageOnFailure)
  14522. {
  14523. return saveAs (documentFile,
  14524. false,
  14525. askUserForFileIfNotSpecified,
  14526. showMessageOnFailure);
  14527. }
  14528. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14529. const bool warnAboutOverwritingExistingFiles,
  14530. const bool askUserForFileIfNotSpecified,
  14531. const bool showMessageOnFailure)
  14532. {
  14533. if (newFile == File::nonexistent)
  14534. {
  14535. if (askUserForFileIfNotSpecified)
  14536. {
  14537. return saveAsInteractive (true);
  14538. }
  14539. else
  14540. {
  14541. // can't save to an unspecified file
  14542. jassertfalse
  14543. return failedToWriteToFile;
  14544. }
  14545. }
  14546. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14547. {
  14548. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14549. TRANS("File already exists"),
  14550. TRANS("There's already a file called:\n\n")
  14551. + newFile.getFullPathName()
  14552. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14553. TRANS("overwrite"),
  14554. TRANS("cancel")))
  14555. {
  14556. return userCancelledSave;
  14557. }
  14558. }
  14559. MouseCursor::showWaitCursor();
  14560. const File oldFile (documentFile);
  14561. documentFile = newFile;
  14562. String error (saveDocument (newFile));
  14563. if (error.isEmpty())
  14564. {
  14565. setChangedFlag (false);
  14566. MouseCursor::hideWaitCursor();
  14567. return savedOk;
  14568. }
  14569. documentFile = oldFile;
  14570. MouseCursor::hideWaitCursor();
  14571. if (showMessageOnFailure)
  14572. {
  14573. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14574. TRANS("Error writing to file..."),
  14575. TRANS("An error occurred while trying to save \"")
  14576. + getDocumentTitle()
  14577. + TRANS("\" to the file:\n\n")
  14578. + newFile.getFullPathName()
  14579. + "\n\n"
  14580. + error);
  14581. }
  14582. return failedToWriteToFile;
  14583. }
  14584. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14585. {
  14586. if (! hasChangedSinceSaved())
  14587. return savedOk;
  14588. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14589. TRANS("Closing document..."),
  14590. TRANS("Do you want to save the changes to \"")
  14591. + getDocumentTitle() + "\"?",
  14592. TRANS("save"),
  14593. TRANS("discard changes"),
  14594. TRANS("cancel"));
  14595. if (r == 1)
  14596. {
  14597. // save changes
  14598. return save (true, true);
  14599. }
  14600. else if (r == 2)
  14601. {
  14602. // discard changes
  14603. return savedOk;
  14604. }
  14605. return userCancelledSave;
  14606. }
  14607. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14608. {
  14609. File f;
  14610. if (documentFile.existsAsFile())
  14611. f = documentFile;
  14612. else
  14613. f = getLastDocumentOpened();
  14614. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14615. if (legalFilename.isEmpty())
  14616. legalFilename = "unnamed";
  14617. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14618. f = f.getSiblingFile (legalFilename);
  14619. else
  14620. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14621. f = f.withFileExtension (fileExtension)
  14622. .getNonexistentSibling (true);
  14623. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14624. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14625. {
  14626. setLastDocumentOpened (fc.getResult());
  14627. File chosen (fc.getResult());
  14628. if (chosen.getFileExtension().isEmpty())
  14629. {
  14630. chosen = chosen.withFileExtension (fileExtension);
  14631. if (chosen.exists())
  14632. {
  14633. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14634. TRANS("File already exists"),
  14635. TRANS("There's already a file called:")
  14636. + "\n\n" + chosen.getFullPathName()
  14637. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  14638. TRANS("overwrite"),
  14639. TRANS("cancel")))
  14640. {
  14641. return userCancelledSave;
  14642. }
  14643. }
  14644. }
  14645. return saveAs (chosen, false, false, true);
  14646. }
  14647. return userCancelledSave;
  14648. }
  14649. END_JUCE_NAMESPACE
  14650. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14651. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14652. BEGIN_JUCE_NAMESPACE
  14653. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14654. : maxNumberOfItems (10)
  14655. {
  14656. }
  14657. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14658. {
  14659. }
  14660. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14661. {
  14662. maxNumberOfItems = jmax (1, newMaxNumber);
  14663. while (getNumFiles() > maxNumberOfItems)
  14664. files.remove (getNumFiles() - 1);
  14665. }
  14666. int RecentlyOpenedFilesList::getNumFiles() const
  14667. {
  14668. return files.size();
  14669. }
  14670. const File RecentlyOpenedFilesList::getFile (const int index) const
  14671. {
  14672. return File (files [index]);
  14673. }
  14674. void RecentlyOpenedFilesList::clear()
  14675. {
  14676. files.clear();
  14677. }
  14678. void RecentlyOpenedFilesList::addFile (const File& file)
  14679. {
  14680. const String path (file.getFullPathName());
  14681. files.removeString (path, true);
  14682. files.insert (0, path);
  14683. setMaxNumberOfItems (maxNumberOfItems);
  14684. }
  14685. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14686. {
  14687. for (int i = getNumFiles(); --i >= 0;)
  14688. if (! getFile(i).exists())
  14689. files.remove (i);
  14690. }
  14691. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14692. const int baseItemId,
  14693. const bool showFullPaths,
  14694. const bool dontAddNonExistentFiles,
  14695. const File** filesToAvoid)
  14696. {
  14697. int num = 0;
  14698. for (int i = 0; i < getNumFiles(); ++i)
  14699. {
  14700. const File f (getFile(i));
  14701. if ((! dontAddNonExistentFiles) || f.exists())
  14702. {
  14703. bool needsAvoiding = false;
  14704. if (filesToAvoid != 0)
  14705. {
  14706. const File** avoid = filesToAvoid;
  14707. while (*avoid != 0)
  14708. {
  14709. if (f == **avoid)
  14710. {
  14711. needsAvoiding = true;
  14712. break;
  14713. }
  14714. ++avoid;
  14715. }
  14716. }
  14717. if (! needsAvoiding)
  14718. {
  14719. menuToAddTo.addItem (baseItemId + i,
  14720. showFullPaths ? f.getFullPathName()
  14721. : f.getFileName());
  14722. ++num;
  14723. }
  14724. }
  14725. }
  14726. return num;
  14727. }
  14728. const String RecentlyOpenedFilesList::toString() const
  14729. {
  14730. return files.joinIntoString ("\n");
  14731. }
  14732. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14733. {
  14734. clear();
  14735. files.addLines (stringifiedVersion);
  14736. setMaxNumberOfItems (maxNumberOfItems);
  14737. }
  14738. END_JUCE_NAMESPACE
  14739. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14740. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14741. BEGIN_JUCE_NAMESPACE
  14742. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14743. const int minimumTransactions)
  14744. : totalUnitsStored (0),
  14745. nextIndex (0),
  14746. newTransaction (true),
  14747. reentrancyCheck (false)
  14748. {
  14749. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14750. minimumTransactions);
  14751. }
  14752. UndoManager::~UndoManager()
  14753. {
  14754. clearUndoHistory();
  14755. }
  14756. void UndoManager::clearUndoHistory()
  14757. {
  14758. transactions.clear();
  14759. transactionNames.clear();
  14760. totalUnitsStored = 0;
  14761. nextIndex = 0;
  14762. sendChangeMessage (this);
  14763. }
  14764. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14765. {
  14766. return totalUnitsStored;
  14767. }
  14768. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14769. const int minimumTransactions)
  14770. {
  14771. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14772. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14773. }
  14774. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14775. {
  14776. if (command != 0)
  14777. {
  14778. if (actionName.isNotEmpty())
  14779. currentTransactionName = actionName;
  14780. if (reentrancyCheck)
  14781. {
  14782. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14783. // undo() methods, or else these actions won't actually get done.
  14784. return false;
  14785. }
  14786. else
  14787. {
  14788. bool success = false;
  14789. JUCE_TRY
  14790. {
  14791. success = command->perform();
  14792. }
  14793. JUCE_CATCH_EXCEPTION
  14794. jassert (success);
  14795. if (success)
  14796. {
  14797. if (nextIndex > 0 && ! newTransaction)
  14798. {
  14799. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14800. jassert (commandSet != 0);
  14801. if (commandSet == 0)
  14802. return false;
  14803. commandSet->add (command);
  14804. }
  14805. else
  14806. {
  14807. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14808. commandSet->add (command);
  14809. transactions.insert (nextIndex, commandSet);
  14810. transactionNames.insert (nextIndex, currentTransactionName);
  14811. ++nextIndex;
  14812. }
  14813. totalUnitsStored += command->getSizeInUnits();
  14814. newTransaction = false;
  14815. }
  14816. while (nextIndex < transactions.size())
  14817. {
  14818. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14819. for (int i = lastSet->size(); --i >= 0;)
  14820. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14821. transactions.removeLast();
  14822. transactionNames.remove (transactionNames.size() - 1);
  14823. }
  14824. while (nextIndex > 0
  14825. && totalUnitsStored > maxNumUnitsToKeep
  14826. && transactions.size() > minimumTransactionsToKeep)
  14827. {
  14828. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14829. for (int i = firstSet->size(); --i >= 0;)
  14830. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14831. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14832. transactions.remove (0);
  14833. transactionNames.remove (0);
  14834. --nextIndex;
  14835. }
  14836. sendChangeMessage (this);
  14837. return success;
  14838. }
  14839. }
  14840. return false;
  14841. }
  14842. void UndoManager::beginNewTransaction (const String& actionName)
  14843. {
  14844. newTransaction = true;
  14845. currentTransactionName = actionName;
  14846. }
  14847. void UndoManager::setCurrentTransactionName (const String& newName)
  14848. {
  14849. currentTransactionName = newName;
  14850. }
  14851. bool UndoManager::canUndo() const
  14852. {
  14853. return nextIndex > 0;
  14854. }
  14855. bool UndoManager::canRedo() const
  14856. {
  14857. return nextIndex < transactions.size();
  14858. }
  14859. const String UndoManager::getUndoDescription() const
  14860. {
  14861. return transactionNames [nextIndex - 1];
  14862. }
  14863. const String UndoManager::getRedoDescription() const
  14864. {
  14865. return transactionNames [nextIndex];
  14866. }
  14867. bool UndoManager::undo()
  14868. {
  14869. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14870. if (commandSet == 0)
  14871. return false;
  14872. reentrancyCheck = true;
  14873. bool failed = false;
  14874. for (int i = commandSet->size(); --i >= 0;)
  14875. {
  14876. if (! commandSet->getUnchecked(i)->undo())
  14877. {
  14878. jassertfalse
  14879. failed = true;
  14880. break;
  14881. }
  14882. }
  14883. reentrancyCheck = false;
  14884. if (failed)
  14885. {
  14886. clearUndoHistory();
  14887. }
  14888. else
  14889. {
  14890. --nextIndex;
  14891. }
  14892. beginNewTransaction();
  14893. sendChangeMessage (this);
  14894. return true;
  14895. }
  14896. bool UndoManager::redo()
  14897. {
  14898. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14899. if (commandSet == 0)
  14900. return false;
  14901. reentrancyCheck = true;
  14902. bool failed = false;
  14903. for (int i = 0; i < commandSet->size(); ++i)
  14904. {
  14905. if (! commandSet->getUnchecked(i)->perform())
  14906. {
  14907. jassertfalse
  14908. failed = true;
  14909. break;
  14910. }
  14911. }
  14912. reentrancyCheck = false;
  14913. if (failed)
  14914. {
  14915. clearUndoHistory();
  14916. }
  14917. else
  14918. {
  14919. ++nextIndex;
  14920. }
  14921. beginNewTransaction();
  14922. sendChangeMessage (this);
  14923. return true;
  14924. }
  14925. bool UndoManager::undoCurrentTransactionOnly()
  14926. {
  14927. return newTransaction ? false
  14928. : undo();
  14929. }
  14930. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14931. {
  14932. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14933. if (commandSet != 0 && ! newTransaction)
  14934. {
  14935. for (int i = 0; i < commandSet->size(); ++i)
  14936. actionsFound.add (commandSet->getUnchecked(i));
  14937. }
  14938. }
  14939. int UndoManager::getNumActionsInCurrentTransaction() const
  14940. {
  14941. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14942. if (commandSet != 0 && ! newTransaction)
  14943. return commandSet->size();
  14944. return 0;
  14945. }
  14946. END_JUCE_NAMESPACE
  14947. /*** End of inlined file: juce_UndoManager.cpp ***/
  14948. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14949. BEGIN_JUCE_NAMESPACE
  14950. static const char* const aiffFormatName = "AIFF file";
  14951. static const juce_wchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14952. class AiffAudioFormatReader : public AudioFormatReader
  14953. {
  14954. public:
  14955. int bytesPerFrame;
  14956. int64 dataChunkStart;
  14957. bool littleEndian;
  14958. AiffAudioFormatReader (InputStream* in)
  14959. : AudioFormatReader (in, TRANS (aiffFormatName))
  14960. {
  14961. if (input->readInt() == chunkName ("FORM"))
  14962. {
  14963. const int len = input->readIntBigEndian();
  14964. const int64 end = input->getPosition() + len;
  14965. const int nextType = input->readInt();
  14966. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14967. {
  14968. bool hasGotVer = false;
  14969. bool hasGotData = false;
  14970. bool hasGotType = false;
  14971. while (input->getPosition() < end)
  14972. {
  14973. const int type = input->readInt();
  14974. const uint32 length = (uint32) input->readIntBigEndian();
  14975. const int64 chunkEnd = input->getPosition() + length;
  14976. if (type == chunkName ("FVER"))
  14977. {
  14978. hasGotVer = true;
  14979. const int ver = input->readIntBigEndian();
  14980. if (ver != 0 && ver != (int)0xa2805140)
  14981. break;
  14982. }
  14983. else if (type == chunkName ("COMM"))
  14984. {
  14985. hasGotType = true;
  14986. numChannels = (unsigned int)input->readShortBigEndian();
  14987. lengthInSamples = input->readIntBigEndian();
  14988. bitsPerSample = input->readShortBigEndian();
  14989. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  14990. unsigned char sampleRateBytes[10];
  14991. input->read (sampleRateBytes, 10);
  14992. const int byte0 = sampleRateBytes[0];
  14993. if ((byte0 & 0x80) != 0
  14994. || byte0 <= 0x3F || byte0 > 0x40
  14995. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  14996. break;
  14997. unsigned int sampRate = ByteOrder::bigEndianInt (sampleRateBytes + 2);
  14998. sampRate >>= (16414 - ByteOrder::bigEndianShort (sampleRateBytes));
  14999. sampleRate = (int) sampRate;
  15000. if (length <= 18)
  15001. {
  15002. // some types don't have a chunk large enough to include a compression
  15003. // type, so assume it's just big-endian pcm
  15004. littleEndian = false;
  15005. }
  15006. else
  15007. {
  15008. const int compType = input->readInt();
  15009. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15010. {
  15011. littleEndian = false;
  15012. }
  15013. else if (compType == chunkName ("sowt"))
  15014. {
  15015. littleEndian = true;
  15016. }
  15017. else
  15018. {
  15019. sampleRate = 0;
  15020. break;
  15021. }
  15022. }
  15023. }
  15024. else if (type == chunkName ("SSND"))
  15025. {
  15026. hasGotData = true;
  15027. const int offset = input->readIntBigEndian();
  15028. dataChunkStart = input->getPosition() + 4 + offset;
  15029. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15030. }
  15031. else if ((hasGotVer && hasGotData && hasGotType)
  15032. || chunkEnd < input->getPosition()
  15033. || input->isExhausted())
  15034. {
  15035. break;
  15036. }
  15037. input->setPosition (chunkEnd);
  15038. }
  15039. }
  15040. }
  15041. }
  15042. ~AiffAudioFormatReader()
  15043. {
  15044. }
  15045. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15046. int64 startSampleInFile, int numSamples)
  15047. {
  15048. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15049. if (samplesAvailable < numSamples)
  15050. {
  15051. for (int i = numDestChannels; --i >= 0;)
  15052. if (destSamples[i] != 0)
  15053. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15054. numSamples = (int) samplesAvailable;
  15055. }
  15056. if (numSamples <= 0)
  15057. return true;
  15058. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15059. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15060. char tempBuffer [tempBufSize];
  15061. while (numSamples > 0)
  15062. {
  15063. int* left = destSamples[0];
  15064. if (left != 0)
  15065. left += startOffsetInDestBuffer;
  15066. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15067. if (right != 0)
  15068. right += startOffsetInDestBuffer;
  15069. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15070. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15071. if (bytesRead < numThisTime * bytesPerFrame)
  15072. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15073. if (bitsPerSample == 16)
  15074. {
  15075. if (littleEndian)
  15076. {
  15077. const short* src = reinterpret_cast <const short*> (tempBuffer);
  15078. if (numChannels > 1)
  15079. {
  15080. if (left == 0)
  15081. {
  15082. for (int i = numThisTime; --i >= 0;)
  15083. {
  15084. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15085. ++src;
  15086. }
  15087. }
  15088. else if (right == 0)
  15089. {
  15090. for (int i = numThisTime; --i >= 0;)
  15091. {
  15092. ++src;
  15093. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15094. }
  15095. }
  15096. else
  15097. {
  15098. for (int i = numThisTime; --i >= 0;)
  15099. {
  15100. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15101. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15102. }
  15103. }
  15104. }
  15105. else
  15106. {
  15107. for (int i = numThisTime; --i >= 0;)
  15108. {
  15109. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15110. }
  15111. }
  15112. }
  15113. else
  15114. {
  15115. const char* src = tempBuffer;
  15116. if (numChannels > 1)
  15117. {
  15118. if (left == 0)
  15119. {
  15120. for (int i = numThisTime; --i >= 0;)
  15121. {
  15122. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15123. src += 4;
  15124. }
  15125. }
  15126. else if (right == 0)
  15127. {
  15128. for (int i = numThisTime; --i >= 0;)
  15129. {
  15130. src += 2;
  15131. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15132. src += 2;
  15133. }
  15134. }
  15135. else
  15136. {
  15137. for (int i = numThisTime; --i >= 0;)
  15138. {
  15139. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15140. src += 2;
  15141. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15142. src += 2;
  15143. }
  15144. }
  15145. }
  15146. else
  15147. {
  15148. for (int i = numThisTime; --i >= 0;)
  15149. {
  15150. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15151. src += 2;
  15152. }
  15153. }
  15154. }
  15155. }
  15156. else if (bitsPerSample == 24)
  15157. {
  15158. const char* src = (const char*)tempBuffer;
  15159. if (littleEndian)
  15160. {
  15161. if (numChannels > 1)
  15162. {
  15163. if (left == 0)
  15164. {
  15165. for (int i = numThisTime; --i >= 0;)
  15166. {
  15167. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15168. src += 6;
  15169. }
  15170. }
  15171. else if (right == 0)
  15172. {
  15173. for (int i = numThisTime; --i >= 0;)
  15174. {
  15175. src += 3;
  15176. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15177. src += 3;
  15178. }
  15179. }
  15180. else
  15181. {
  15182. for (int i = numThisTime; --i >= 0;)
  15183. {
  15184. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15185. src += 3;
  15186. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15187. src += 3;
  15188. }
  15189. }
  15190. }
  15191. else
  15192. {
  15193. for (int i = numThisTime; --i >= 0;)
  15194. {
  15195. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15196. src += 3;
  15197. }
  15198. }
  15199. }
  15200. else
  15201. {
  15202. if (numChannels > 1)
  15203. {
  15204. if (left == 0)
  15205. {
  15206. for (int i = numThisTime; --i >= 0;)
  15207. {
  15208. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15209. src += 6;
  15210. }
  15211. }
  15212. else if (right == 0)
  15213. {
  15214. for (int i = numThisTime; --i >= 0;)
  15215. {
  15216. src += 3;
  15217. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15218. src += 3;
  15219. }
  15220. }
  15221. else
  15222. {
  15223. for (int i = numThisTime; --i >= 0;)
  15224. {
  15225. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15226. src += 3;
  15227. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15228. src += 3;
  15229. }
  15230. }
  15231. }
  15232. else
  15233. {
  15234. for (int i = numThisTime; --i >= 0;)
  15235. {
  15236. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15237. src += 3;
  15238. }
  15239. }
  15240. }
  15241. }
  15242. else if (bitsPerSample == 32)
  15243. {
  15244. const unsigned int* src = reinterpret_cast <const unsigned int*> (tempBuffer);
  15245. unsigned int* l = reinterpret_cast <unsigned int*> (left);
  15246. unsigned int* r = reinterpret_cast <unsigned int*> (right);
  15247. if (littleEndian)
  15248. {
  15249. if (numChannels > 1)
  15250. {
  15251. if (l == 0)
  15252. {
  15253. for (int i = numThisTime; --i >= 0;)
  15254. {
  15255. ++src;
  15256. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15257. }
  15258. }
  15259. else if (r == 0)
  15260. {
  15261. for (int i = numThisTime; --i >= 0;)
  15262. {
  15263. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15264. ++src;
  15265. }
  15266. }
  15267. else
  15268. {
  15269. for (int i = numThisTime; --i >= 0;)
  15270. {
  15271. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15272. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15273. }
  15274. }
  15275. }
  15276. else
  15277. {
  15278. for (int i = numThisTime; --i >= 0;)
  15279. {
  15280. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15281. }
  15282. }
  15283. }
  15284. else
  15285. {
  15286. if (numChannels > 1)
  15287. {
  15288. if (l == 0)
  15289. {
  15290. for (int i = numThisTime; --i >= 0;)
  15291. {
  15292. ++src;
  15293. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15294. }
  15295. }
  15296. else if (r == 0)
  15297. {
  15298. for (int i = numThisTime; --i >= 0;)
  15299. {
  15300. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15301. ++src;
  15302. }
  15303. }
  15304. else
  15305. {
  15306. for (int i = numThisTime; --i >= 0;)
  15307. {
  15308. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15309. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15310. }
  15311. }
  15312. }
  15313. else
  15314. {
  15315. for (int i = numThisTime; --i >= 0;)
  15316. {
  15317. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15318. }
  15319. }
  15320. }
  15321. left = reinterpret_cast <int*> (l);
  15322. right = reinterpret_cast <int*> (r);
  15323. }
  15324. else if (bitsPerSample == 8)
  15325. {
  15326. const char* src = tempBuffer;
  15327. if (numChannels > 1)
  15328. {
  15329. if (left == 0)
  15330. {
  15331. for (int i = numThisTime; --i >= 0;)
  15332. {
  15333. *right++ = ((int) *src++) << 24;
  15334. ++src;
  15335. }
  15336. }
  15337. else if (right == 0)
  15338. {
  15339. for (int i = numThisTime; --i >= 0;)
  15340. {
  15341. ++src;
  15342. *left++ = ((int) *src++) << 24;
  15343. }
  15344. }
  15345. else
  15346. {
  15347. for (int i = numThisTime; --i >= 0;)
  15348. {
  15349. *left++ = ((int) *src++) << 24;
  15350. *right++ = ((int) *src++) << 24;
  15351. }
  15352. }
  15353. }
  15354. else
  15355. {
  15356. for (int i = numThisTime; --i >= 0;)
  15357. {
  15358. *left++ = ((int) *src++) << 24;
  15359. }
  15360. }
  15361. }
  15362. startOffsetInDestBuffer += numThisTime;
  15363. numSamples -= numThisTime;
  15364. }
  15365. if (numSamples > 0)
  15366. {
  15367. for (int i = numDestChannels; --i >= 0;)
  15368. if (destSamples[i] != 0)
  15369. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15370. sizeof (int) * numSamples);
  15371. }
  15372. return true;
  15373. }
  15374. juce_UseDebuggingNewOperator
  15375. private:
  15376. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15377. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15378. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15379. };
  15380. class AiffAudioFormatWriter : public AudioFormatWriter
  15381. {
  15382. MemoryBlock tempBlock;
  15383. uint32 lengthInSamples, bytesWritten;
  15384. int64 headerPosition;
  15385. bool writeFailed;
  15386. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15387. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15388. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15389. void writeHeader()
  15390. {
  15391. const bool couldSeekOk = output->setPosition (headerPosition);
  15392. (void) couldSeekOk;
  15393. // if this fails, you've given it an output stream that can't seek! It needs
  15394. // to be able to seek back to write the header
  15395. jassert (couldSeekOk);
  15396. const int headerLen = 54;
  15397. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15398. audioBytes += (audioBytes & 1);
  15399. output->writeInt (chunkName ("FORM"));
  15400. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15401. output->writeInt (chunkName ("AIFF"));
  15402. output->writeInt (chunkName ("COMM"));
  15403. output->writeIntBigEndian (18);
  15404. output->writeShortBigEndian ((short) numChannels);
  15405. output->writeIntBigEndian (lengthInSamples);
  15406. output->writeShortBigEndian ((short) bitsPerSample);
  15407. uint8 sampleRateBytes[10];
  15408. zeromem (sampleRateBytes, 10);
  15409. if (sampleRate <= 1)
  15410. {
  15411. sampleRateBytes[0] = 0x3f;
  15412. sampleRateBytes[1] = 0xff;
  15413. sampleRateBytes[2] = 0x80;
  15414. }
  15415. else
  15416. {
  15417. int mask = 0x40000000;
  15418. sampleRateBytes[0] = 0x40;
  15419. if (sampleRate >= mask)
  15420. {
  15421. jassertfalse
  15422. sampleRateBytes[1] = 0x1d;
  15423. }
  15424. else
  15425. {
  15426. int n = (int) sampleRate;
  15427. int i;
  15428. for (i = 0; i <= 32 ; ++i)
  15429. {
  15430. if ((n & mask) != 0)
  15431. break;
  15432. mask >>= 1;
  15433. }
  15434. n = n << (i + 1);
  15435. sampleRateBytes[1] = (uint8) (29 - i);
  15436. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15437. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15438. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15439. sampleRateBytes[5] = (uint8) (n & 0xff);
  15440. }
  15441. }
  15442. output->write (sampleRateBytes, 10);
  15443. output->writeInt (chunkName ("SSND"));
  15444. output->writeIntBigEndian (audioBytes + 8);
  15445. output->writeInt (0);
  15446. output->writeInt (0);
  15447. jassert (output->getPosition() == headerLen);
  15448. }
  15449. public:
  15450. AiffAudioFormatWriter (OutputStream* out,
  15451. const double sampleRate_,
  15452. const unsigned int chans,
  15453. const int bits)
  15454. : AudioFormatWriter (out,
  15455. TRANS (aiffFormatName),
  15456. sampleRate_,
  15457. chans,
  15458. bits),
  15459. lengthInSamples (0),
  15460. bytesWritten (0),
  15461. writeFailed (false)
  15462. {
  15463. headerPosition = out->getPosition();
  15464. writeHeader();
  15465. }
  15466. ~AiffAudioFormatWriter()
  15467. {
  15468. if ((bytesWritten & 1) != 0)
  15469. output->writeByte (0);
  15470. writeHeader();
  15471. }
  15472. bool write (const int** data, int numSamples)
  15473. {
  15474. if (writeFailed)
  15475. return false;
  15476. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15477. tempBlock.ensureSize (bytes, false);
  15478. char* buffer = static_cast <char*> (tempBlock.getData());
  15479. const int* left = data[0];
  15480. const int* right = data[1];
  15481. if (right == 0)
  15482. right = left;
  15483. if (bitsPerSample == 16)
  15484. {
  15485. short* b = reinterpret_cast <short*> (buffer);
  15486. if (numChannels > 1)
  15487. {
  15488. for (int i = numSamples; --i >= 0;)
  15489. {
  15490. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15491. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15492. }
  15493. }
  15494. else
  15495. {
  15496. for (int i = numSamples; --i >= 0;)
  15497. {
  15498. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15499. }
  15500. }
  15501. }
  15502. else if (bitsPerSample == 24)
  15503. {
  15504. char* b = buffer;
  15505. if (numChannels > 1)
  15506. {
  15507. for (int i = numSamples; --i >= 0;)
  15508. {
  15509. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15510. b += 3;
  15511. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15512. b += 3;
  15513. }
  15514. }
  15515. else
  15516. {
  15517. for (int i = numSamples; --i >= 0;)
  15518. {
  15519. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15520. b += 3;
  15521. }
  15522. }
  15523. }
  15524. else if (bitsPerSample == 32)
  15525. {
  15526. uint32* b = reinterpret_cast <uint32*> (buffer);
  15527. if (numChannels > 1)
  15528. {
  15529. for (int i = numSamples; --i >= 0;)
  15530. {
  15531. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15532. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15533. }
  15534. }
  15535. else
  15536. {
  15537. for (int i = numSamples; --i >= 0;)
  15538. {
  15539. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15540. }
  15541. }
  15542. }
  15543. else if (bitsPerSample == 8)
  15544. {
  15545. char* b = buffer;
  15546. if (numChannels > 1)
  15547. {
  15548. for (int i = numSamples; --i >= 0;)
  15549. {
  15550. *b++ = (char) (*left++ >> 24);
  15551. *b++ = (char) (*right++ >> 24);
  15552. }
  15553. }
  15554. else
  15555. {
  15556. for (int i = numSamples; --i >= 0;)
  15557. {
  15558. *b++ = (char) (*left++ >> 24);
  15559. }
  15560. }
  15561. }
  15562. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15563. || ! output->write (buffer, bytes))
  15564. {
  15565. // failed to write to disk, so let's try writing the header.
  15566. // If it's just run out of disk space, then if it does manage
  15567. // to write the header, we'll still have a useable file..
  15568. writeHeader();
  15569. writeFailed = true;
  15570. return false;
  15571. }
  15572. else
  15573. {
  15574. bytesWritten += bytes;
  15575. lengthInSamples += numSamples;
  15576. return true;
  15577. }
  15578. }
  15579. juce_UseDebuggingNewOperator
  15580. };
  15581. AiffAudioFormat::AiffAudioFormat()
  15582. : AudioFormat (TRANS (aiffFormatName), (const juce_wchar**) aiffExtensions)
  15583. {
  15584. }
  15585. AiffAudioFormat::~AiffAudioFormat()
  15586. {
  15587. }
  15588. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15589. {
  15590. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15591. return Array <int> (rates);
  15592. }
  15593. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15594. {
  15595. const int depths[] = { 8, 16, 24, 0 };
  15596. return Array <int> (depths);
  15597. }
  15598. bool AiffAudioFormat::canDoStereo()
  15599. {
  15600. return true;
  15601. }
  15602. bool AiffAudioFormat::canDoMono()
  15603. {
  15604. return true;
  15605. }
  15606. #if JUCE_MAC
  15607. bool AiffAudioFormat::canHandleFile (const File& f)
  15608. {
  15609. if (AudioFormat::canHandleFile (f))
  15610. return true;
  15611. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15612. return type == 'AIFF' || type == 'AIFC'
  15613. || type == 'aiff' || type == 'aifc';
  15614. }
  15615. #endif
  15616. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15617. const bool deleteStreamIfOpeningFails)
  15618. {
  15619. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15620. if (w->sampleRate != 0)
  15621. return w.release();
  15622. if (! deleteStreamIfOpeningFails)
  15623. w->input = 0;
  15624. return 0;
  15625. }
  15626. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15627. double sampleRate,
  15628. unsigned int chans,
  15629. int bitsPerSample,
  15630. const StringPairArray& /*metadataValues*/,
  15631. int /*qualityOptionIndex*/)
  15632. {
  15633. if (getPossibleBitDepths().contains (bitsPerSample))
  15634. {
  15635. return new AiffAudioFormatWriter (out,
  15636. sampleRate,
  15637. chans,
  15638. bitsPerSample);
  15639. }
  15640. return 0;
  15641. }
  15642. END_JUCE_NAMESPACE
  15643. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15644. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15645. BEGIN_JUCE_NAMESPACE
  15646. #if JUCE_MAC && JUCE_USE_CDREADER
  15647. // Mac version doesn't need any native code because it's all done with files..
  15648. // Windows + Linux versions are in the platform-dependent code sections.
  15649. static void findCDs (Array<File>& cds)
  15650. {
  15651. File volumes ("/Volumes");
  15652. volumes.findChildFiles (cds, File::findDirectories, false);
  15653. for (int i = cds.size(); --i >= 0;)
  15654. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15655. cds.remove (i);
  15656. }
  15657. const StringArray AudioCDReader::getAvailableCDNames()
  15658. {
  15659. Array<File> cds;
  15660. findCDs (cds);
  15661. StringArray names;
  15662. for (int i = 0; i < cds.size(); ++i)
  15663. names.add (cds.getReference(i).getFileName());
  15664. return names;
  15665. }
  15666. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15667. {
  15668. Array<File> cds;
  15669. findCDs (cds);
  15670. if (cds[index] != File::nonexistent)
  15671. return new AudioCDReader (cds[index]);
  15672. else
  15673. return 0;
  15674. }
  15675. AudioCDReader::AudioCDReader (const File& volume)
  15676. : AudioFormatReader (0, "CD Audio"),
  15677. volumeDir (volume),
  15678. currentReaderTrack (-1),
  15679. reader (0)
  15680. {
  15681. sampleRate = 44100.0;
  15682. bitsPerSample = 16;
  15683. numChannels = 2;
  15684. usesFloatingPointData = false;
  15685. refreshTrackLengths();
  15686. }
  15687. AudioCDReader::~AudioCDReader()
  15688. {
  15689. }
  15690. static int getTrackNumber (const File& file)
  15691. {
  15692. return file.getFileName()
  15693. .initialSectionContainingOnly ("0123456789")
  15694. .getIntValue();
  15695. }
  15696. int AudioCDReader::compareElements (const File& first, const File& second)
  15697. {
  15698. const int firstTrack = getTrackNumber (first);
  15699. const int secondTrack = getTrackNumber (second);
  15700. jassert (firstTrack > 0 && secondTrack > 0);
  15701. return firstTrack - secondTrack;
  15702. }
  15703. void AudioCDReader::refreshTrackLengths()
  15704. {
  15705. tracks.clear();
  15706. trackStartSamples.clear();
  15707. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, "*.aiff");
  15708. tracks.sort (*this);
  15709. AiffAudioFormat format;
  15710. int sample = 0;
  15711. for (int i = 0; i < tracks.size(); ++i)
  15712. {
  15713. trackStartSamples.add (sample);
  15714. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15715. if (in != 0)
  15716. {
  15717. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15718. if (r != 0)
  15719. sample += (int) r->lengthInSamples;
  15720. }
  15721. }
  15722. trackStartSamples.add (sample);
  15723. lengthInSamples = sample;
  15724. }
  15725. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15726. int64 startSampleInFile, int numSamples)
  15727. {
  15728. while (numSamples > 0)
  15729. {
  15730. int track = -1;
  15731. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15732. {
  15733. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15734. {
  15735. track = i;
  15736. break;
  15737. }
  15738. }
  15739. if (track < 0)
  15740. return false;
  15741. if (track != currentReaderTrack)
  15742. {
  15743. reader = 0;
  15744. FileInputStream* const in = tracks [track].createInputStream();
  15745. if (in != 0)
  15746. {
  15747. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15748. AiffAudioFormat format;
  15749. reader = format.createReaderFor (bin, true);
  15750. if (reader == 0)
  15751. currentReaderTrack = -1;
  15752. else
  15753. currentReaderTrack = track;
  15754. }
  15755. }
  15756. if (reader == 0)
  15757. return false;
  15758. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15759. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15760. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15761. numSamples -= numAvailable;
  15762. startSampleInFile += numAvailable;
  15763. }
  15764. return true;
  15765. }
  15766. bool AudioCDReader::isCDStillPresent() const
  15767. {
  15768. return volumeDir.exists();
  15769. }
  15770. int AudioCDReader::getNumTracks() const
  15771. {
  15772. return tracks.size();
  15773. }
  15774. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15775. {
  15776. return trackStartSamples [trackNum];
  15777. }
  15778. bool AudioCDReader::isTrackAudio (int trackNum) const
  15779. {
  15780. return tracks [trackNum] != File::nonexistent;
  15781. }
  15782. void AudioCDReader::enableIndexScanning (bool b)
  15783. {
  15784. // any way to do this on a Mac??
  15785. }
  15786. int AudioCDReader::getLastIndex() const
  15787. {
  15788. return 0;
  15789. }
  15790. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15791. {
  15792. return Array <int>();
  15793. }
  15794. int AudioCDReader::getCDDBId()
  15795. {
  15796. return 0; //xxx
  15797. }
  15798. #endif
  15799. END_JUCE_NAMESPACE
  15800. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15801. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15802. BEGIN_JUCE_NAMESPACE
  15803. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15804. const String& formatName_)
  15805. : sampleRate (0),
  15806. bitsPerSample (0),
  15807. lengthInSamples (0),
  15808. numChannels (0),
  15809. usesFloatingPointData (false),
  15810. input (in),
  15811. formatName (formatName_)
  15812. {
  15813. }
  15814. AudioFormatReader::~AudioFormatReader()
  15815. {
  15816. delete input;
  15817. }
  15818. bool AudioFormatReader::read (int** destSamples,
  15819. int numDestChannels,
  15820. int64 startSampleInSource,
  15821. int numSamplesToRead,
  15822. const bool fillLeftoverChannelsWithCopies)
  15823. {
  15824. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15825. int startOffsetInDestBuffer = 0;
  15826. if (startSampleInSource < 0)
  15827. {
  15828. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15829. for (int i = numDestChannels; --i >= 0;)
  15830. if (destSamples[i] != 0)
  15831. zeromem (destSamples[i], sizeof (int) * silence);
  15832. startOffsetInDestBuffer += silence;
  15833. numSamplesToRead -= silence;
  15834. startSampleInSource = 0;
  15835. }
  15836. if (numSamplesToRead <= 0)
  15837. return true;
  15838. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15839. startSampleInSource, numSamplesToRead))
  15840. return false;
  15841. if (numDestChannels > (int) numChannels)
  15842. {
  15843. if (fillLeftoverChannelsWithCopies)
  15844. {
  15845. int* lastFullChannel = destSamples[0];
  15846. for (int i = numDestChannels; --i > 0;)
  15847. {
  15848. if (destSamples[i] != 0)
  15849. {
  15850. lastFullChannel = destSamples[i];
  15851. break;
  15852. }
  15853. }
  15854. if (lastFullChannel != 0)
  15855. for (int i = numChannels; i < numDestChannels; ++i)
  15856. if (destSamples[i] != 0)
  15857. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15858. }
  15859. else
  15860. {
  15861. for (int i = numChannels; i < numDestChannels; ++i)
  15862. if (destSamples[i] != 0)
  15863. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15864. }
  15865. }
  15866. return true;
  15867. }
  15868. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15869. {
  15870. float mn = buffer[0];
  15871. float mx = mn;
  15872. for (int i = 1; i < num; ++i)
  15873. {
  15874. const float s = buffer[i];
  15875. if (s > mx) mx = s;
  15876. if (s < mn) mn = s;
  15877. }
  15878. maxVal = mx;
  15879. minVal = mn;
  15880. }
  15881. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15882. int64 numSamples,
  15883. float& lowestLeft, float& highestLeft,
  15884. float& lowestRight, float& highestRight)
  15885. {
  15886. if (numSamples <= 0)
  15887. {
  15888. lowestLeft = 0;
  15889. lowestRight = 0;
  15890. highestLeft = 0;
  15891. highestRight = 0;
  15892. return;
  15893. }
  15894. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15895. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15896. int* tempBuffer[3];
  15897. tempBuffer[0] = (int*) tempSpace.getData();
  15898. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15899. tempBuffer[2] = 0;
  15900. if (usesFloatingPointData)
  15901. {
  15902. float lmin = 1.0e6f;
  15903. float lmax = -lmin;
  15904. float rmin = lmin;
  15905. float rmax = lmax;
  15906. while (numSamples > 0)
  15907. {
  15908. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15909. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15910. numSamples -= numToDo;
  15911. startSampleInFile += numToDo;
  15912. float bufmin, bufmax;
  15913. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15914. lmin = jmin (lmin, bufmin);
  15915. lmax = jmax (lmax, bufmax);
  15916. if (numChannels > 1)
  15917. {
  15918. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15919. rmin = jmin (rmin, bufmin);
  15920. rmax = jmax (rmax, bufmax);
  15921. }
  15922. }
  15923. if (numChannels <= 1)
  15924. {
  15925. rmax = lmax;
  15926. rmin = lmin;
  15927. }
  15928. lowestLeft = lmin;
  15929. highestLeft = lmax;
  15930. lowestRight = rmin;
  15931. highestRight = rmax;
  15932. }
  15933. else
  15934. {
  15935. int lmax = std::numeric_limits<int>::min();
  15936. int lmin = std::numeric_limits<int>::max();
  15937. int rmax = std::numeric_limits<int>::min();
  15938. int rmin = std::numeric_limits<int>::max();
  15939. while (numSamples > 0)
  15940. {
  15941. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15942. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15943. numSamples -= numToDo;
  15944. startSampleInFile += numToDo;
  15945. for (int j = numChannels; --j >= 0;)
  15946. {
  15947. int bufMax = std::numeric_limits<int>::min();
  15948. int bufMin = std::numeric_limits<int>::max();
  15949. const int* const b = tempBuffer[j];
  15950. for (int i = 0; i < numToDo; ++i)
  15951. {
  15952. const int samp = b[i];
  15953. if (samp < bufMin)
  15954. bufMin = samp;
  15955. if (samp > bufMax)
  15956. bufMax = samp;
  15957. }
  15958. if (j == 0)
  15959. {
  15960. lmax = jmax (lmax, bufMax);
  15961. lmin = jmin (lmin, bufMin);
  15962. }
  15963. else
  15964. {
  15965. rmax = jmax (rmax, bufMax);
  15966. rmin = jmin (rmin, bufMin);
  15967. }
  15968. }
  15969. }
  15970. if (numChannels <= 1)
  15971. {
  15972. rmax = lmax;
  15973. rmin = lmin;
  15974. }
  15975. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15976. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15977. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15978. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15979. }
  15980. }
  15981. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15982. int64 numSamplesToSearch,
  15983. const double magnitudeRangeMinimum,
  15984. const double magnitudeRangeMaximum,
  15985. const int minimumConsecutiveSamples)
  15986. {
  15987. if (numSamplesToSearch == 0)
  15988. return -1;
  15989. const int bufferSize = 4096;
  15990. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15991. int* tempBuffer[3];
  15992. tempBuffer[0] = (int*) tempSpace.getData();
  15993. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15994. tempBuffer[2] = 0;
  15995. int consecutive = 0;
  15996. int64 firstMatchPos = -1;
  15997. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  15998. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  15999. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16000. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16001. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16002. while (numSamplesToSearch != 0)
  16003. {
  16004. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16005. int64 bufferStart = startSample;
  16006. if (numSamplesToSearch < 0)
  16007. bufferStart -= numThisTime;
  16008. if (bufferStart >= (int) lengthInSamples)
  16009. break;
  16010. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16011. int num = numThisTime;
  16012. while (--num >= 0)
  16013. {
  16014. if (numSamplesToSearch < 0)
  16015. --startSample;
  16016. bool matches = false;
  16017. const int index = (int) (startSample - bufferStart);
  16018. if (usesFloatingPointData)
  16019. {
  16020. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16021. if (sample1 >= magnitudeRangeMinimum
  16022. && sample1 <= magnitudeRangeMaximum)
  16023. {
  16024. matches = true;
  16025. }
  16026. else if (numChannels > 1)
  16027. {
  16028. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16029. matches = (sample2 >= magnitudeRangeMinimum
  16030. && sample2 <= magnitudeRangeMaximum);
  16031. }
  16032. }
  16033. else
  16034. {
  16035. const int sample1 = abs (tempBuffer[0] [index]);
  16036. if (sample1 >= intMagnitudeRangeMinimum
  16037. && sample1 <= intMagnitudeRangeMaximum)
  16038. {
  16039. matches = true;
  16040. }
  16041. else if (numChannels > 1)
  16042. {
  16043. const int sample2 = abs (tempBuffer[1][index]);
  16044. matches = (sample2 >= intMagnitudeRangeMinimum
  16045. && sample2 <= intMagnitudeRangeMaximum);
  16046. }
  16047. }
  16048. if (matches)
  16049. {
  16050. if (firstMatchPos < 0)
  16051. firstMatchPos = startSample;
  16052. if (++consecutive >= minimumConsecutiveSamples)
  16053. {
  16054. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16055. return -1;
  16056. return firstMatchPos;
  16057. }
  16058. }
  16059. else
  16060. {
  16061. consecutive = 0;
  16062. firstMatchPos = -1;
  16063. }
  16064. if (numSamplesToSearch > 0)
  16065. ++startSample;
  16066. }
  16067. if (numSamplesToSearch > 0)
  16068. numSamplesToSearch -= numThisTime;
  16069. else
  16070. numSamplesToSearch += numThisTime;
  16071. }
  16072. return -1;
  16073. }
  16074. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16075. const String& formatName_,
  16076. const double rate,
  16077. const unsigned int numChannels_,
  16078. const unsigned int bitsPerSample_)
  16079. : sampleRate (rate),
  16080. numChannels (numChannels_),
  16081. bitsPerSample (bitsPerSample_),
  16082. usesFloatingPointData (false),
  16083. output (out),
  16084. formatName (formatName_)
  16085. {
  16086. }
  16087. AudioFormatWriter::~AudioFormatWriter()
  16088. {
  16089. delete output;
  16090. }
  16091. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16092. int64 startSample,
  16093. int64 numSamplesToRead)
  16094. {
  16095. const int bufferSize = 16384;
  16096. const int maxChans = 128;
  16097. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16098. int* buffers [maxChans];
  16099. for (int i = maxChans; --i >= 0;)
  16100. buffers[i] = 0;
  16101. if (numSamplesToRead < 0)
  16102. numSamplesToRead = reader.lengthInSamples;
  16103. while (numSamplesToRead > 0)
  16104. {
  16105. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16106. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16107. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16108. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16109. return false;
  16110. if (reader.usesFloatingPointData != isFloatingPoint())
  16111. {
  16112. int** bufferChan = buffers;
  16113. while (*bufferChan != 0)
  16114. {
  16115. int* b = *bufferChan++;
  16116. if (isFloatingPoint())
  16117. {
  16118. // int -> float
  16119. const double factor = 1.0 / std::numeric_limits<int>::max();
  16120. for (int i = 0; i < numToDo; ++i)
  16121. ((float*) b)[i] = (float) (factor * b[i]);
  16122. }
  16123. else
  16124. {
  16125. // float -> int
  16126. for (int i = 0; i < numToDo; ++i)
  16127. {
  16128. const double samp = *(const float*) b;
  16129. if (samp <= -1.0)
  16130. *b++ = std::numeric_limits<int>::min();
  16131. else if (samp >= 1.0)
  16132. *b++ = std::numeric_limits<int>::max();
  16133. else
  16134. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16135. }
  16136. }
  16137. }
  16138. }
  16139. if (! write ((const int**) buffers, numToDo))
  16140. return false;
  16141. numSamplesToRead -= numToDo;
  16142. startSample += numToDo;
  16143. }
  16144. return true;
  16145. }
  16146. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16147. int numSamplesToRead,
  16148. const int samplesPerBlock)
  16149. {
  16150. const int maxChans = 128;
  16151. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16152. int* buffers [maxChans];
  16153. while (numSamplesToRead > 0)
  16154. {
  16155. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16156. AudioSourceChannelInfo info;
  16157. info.buffer = &tempBuffer;
  16158. info.startSample = 0;
  16159. info.numSamples = numToDo;
  16160. info.clearActiveBufferRegion();
  16161. source.getNextAudioBlock (info);
  16162. int i;
  16163. for (i = maxChans; --i >= 0;)
  16164. buffers[i] = 0;
  16165. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16166. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16167. if (! isFloatingPoint())
  16168. {
  16169. int** bufferChan = buffers;
  16170. while (*bufferChan != 0)
  16171. {
  16172. int* b = *bufferChan++;
  16173. // float -> int
  16174. for (int j = numToDo; --j >= 0;)
  16175. {
  16176. const double samp = *(const float*) b;
  16177. if (samp <= -1.0)
  16178. *b++ = std::numeric_limits<int>::min();
  16179. else if (samp >= 1.0)
  16180. *b++ = std::numeric_limits<int>::max();
  16181. else
  16182. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16183. }
  16184. }
  16185. }
  16186. if (! write ((const int**) buffers, numToDo))
  16187. return false;
  16188. numSamplesToRead -= numToDo;
  16189. }
  16190. return true;
  16191. }
  16192. AudioFormat::AudioFormat (const String& name,
  16193. const juce_wchar** const extensions)
  16194. : formatName (name),
  16195. fileExtensions (extensions)
  16196. {
  16197. }
  16198. AudioFormat::~AudioFormat()
  16199. {
  16200. }
  16201. const String& AudioFormat::getFormatName() const
  16202. {
  16203. return formatName;
  16204. }
  16205. const StringArray& AudioFormat::getFileExtensions() const
  16206. {
  16207. return fileExtensions;
  16208. }
  16209. bool AudioFormat::canHandleFile (const File& f)
  16210. {
  16211. for (int i = 0; i < fileExtensions.size(); ++i)
  16212. if (f.hasFileExtension (fileExtensions[i]))
  16213. return true;
  16214. return false;
  16215. }
  16216. bool AudioFormat::isCompressed()
  16217. {
  16218. return false;
  16219. }
  16220. const StringArray AudioFormat::getQualityOptions()
  16221. {
  16222. return StringArray();
  16223. }
  16224. END_JUCE_NAMESPACE
  16225. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16226. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16227. BEGIN_JUCE_NAMESPACE
  16228. AudioFormatManager::AudioFormatManager()
  16229. : defaultFormatIndex (0)
  16230. {
  16231. }
  16232. AudioFormatManager::~AudioFormatManager()
  16233. {
  16234. clearFormats();
  16235. clearSingletonInstance();
  16236. }
  16237. juce_ImplementSingleton (AudioFormatManager);
  16238. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16239. const bool makeThisTheDefaultFormat)
  16240. {
  16241. jassert (newFormat != 0);
  16242. if (newFormat != 0)
  16243. {
  16244. #ifdef JUCE_DEBUG
  16245. for (int i = getNumKnownFormats(); --i >= 0;)
  16246. {
  16247. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16248. {
  16249. jassertfalse // trying to add the same format twice!
  16250. }
  16251. }
  16252. #endif
  16253. if (makeThisTheDefaultFormat)
  16254. defaultFormatIndex = knownFormats.size();
  16255. knownFormats.add (newFormat);
  16256. }
  16257. }
  16258. void AudioFormatManager::registerBasicFormats()
  16259. {
  16260. #if JUCE_MAC
  16261. registerFormat (new AiffAudioFormat(), true);
  16262. registerFormat (new WavAudioFormat(), false);
  16263. #else
  16264. registerFormat (new WavAudioFormat(), true);
  16265. registerFormat (new AiffAudioFormat(), false);
  16266. #endif
  16267. #if JUCE_USE_FLAC
  16268. registerFormat (new FlacAudioFormat(), false);
  16269. #endif
  16270. #if JUCE_USE_OGGVORBIS
  16271. registerFormat (new OggVorbisAudioFormat(), false);
  16272. #endif
  16273. }
  16274. void AudioFormatManager::clearFormats()
  16275. {
  16276. for (int i = getNumKnownFormats(); --i >= 0;)
  16277. delete getKnownFormat(i);
  16278. knownFormats.clear();
  16279. defaultFormatIndex = 0;
  16280. }
  16281. int AudioFormatManager::getNumKnownFormats() const
  16282. {
  16283. return knownFormats.size();
  16284. }
  16285. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16286. {
  16287. return (AudioFormat*) knownFormats [index];
  16288. }
  16289. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16290. {
  16291. return getKnownFormat (defaultFormatIndex);
  16292. }
  16293. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16294. {
  16295. String e (fileExtension);
  16296. if (! e.startsWithChar ('.'))
  16297. e = "." + e;
  16298. for (int i = 0; i < getNumKnownFormats(); ++i)
  16299. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16300. return getKnownFormat(i);
  16301. return 0;
  16302. }
  16303. const String AudioFormatManager::getWildcardForAllFormats() const
  16304. {
  16305. StringArray allExtensions;
  16306. int i;
  16307. for (i = 0; i < getNumKnownFormats(); ++i)
  16308. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16309. allExtensions.trim();
  16310. allExtensions.removeEmptyStrings();
  16311. String s;
  16312. for (i = 0; i < allExtensions.size(); ++i)
  16313. {
  16314. s << '*';
  16315. if (! allExtensions[i].startsWithChar ('.'))
  16316. s << '.';
  16317. s << allExtensions[i];
  16318. if (i < allExtensions.size() - 1)
  16319. s << ';';
  16320. }
  16321. return s;
  16322. }
  16323. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16324. {
  16325. // you need to actually register some formats before the manager can
  16326. // use them to open a file!
  16327. jassert (knownFormats.size() > 0);
  16328. for (int i = 0; i < getNumKnownFormats(); ++i)
  16329. {
  16330. AudioFormat* const af = getKnownFormat(i);
  16331. if (af->canHandleFile (file))
  16332. {
  16333. InputStream* const in = file.createInputStream();
  16334. if (in != 0)
  16335. {
  16336. AudioFormatReader* const r = af->createReaderFor (in, true);
  16337. if (r != 0)
  16338. return r;
  16339. }
  16340. }
  16341. }
  16342. return 0;
  16343. }
  16344. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16345. {
  16346. // you need to actually register some formats before the manager can
  16347. // use them to open a file!
  16348. jassert (knownFormats.size() > 0);
  16349. ScopedPointer <InputStream> in (audioFileStream);
  16350. if (in != 0)
  16351. {
  16352. const int64 originalStreamPos = in->getPosition();
  16353. for (int i = 0; i < getNumKnownFormats(); ++i)
  16354. {
  16355. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16356. if (r != 0)
  16357. {
  16358. in.release();
  16359. return r;
  16360. }
  16361. in->setPosition (originalStreamPos);
  16362. // the stream that is passed-in must be capable of being repositioned so
  16363. // that all the formats can have a go at opening it.
  16364. jassert (in->getPosition() == originalStreamPos);
  16365. }
  16366. }
  16367. return 0;
  16368. }
  16369. END_JUCE_NAMESPACE
  16370. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16371. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16372. BEGIN_JUCE_NAMESPACE
  16373. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16374. const int64 startSample_,
  16375. const int64 length_,
  16376. const bool deleteSourceWhenDeleted_)
  16377. : AudioFormatReader (0, source_->getFormatName()),
  16378. source (source_),
  16379. startSample (startSample_),
  16380. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16381. {
  16382. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16383. sampleRate = source->sampleRate;
  16384. bitsPerSample = source->bitsPerSample;
  16385. lengthInSamples = length;
  16386. numChannels = source->numChannels;
  16387. usesFloatingPointData = source->usesFloatingPointData;
  16388. }
  16389. AudioSubsectionReader::~AudioSubsectionReader()
  16390. {
  16391. if (deleteSourceWhenDeleted)
  16392. delete source;
  16393. }
  16394. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16395. int64 startSampleInFile, int numSamples)
  16396. {
  16397. if (startSampleInFile + numSamples > length)
  16398. {
  16399. for (int i = numDestChannels; --i >= 0;)
  16400. if (destSamples[i] != 0)
  16401. zeromem (destSamples[i], sizeof (int) * numSamples);
  16402. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16403. if (numSamples <= 0)
  16404. return true;
  16405. }
  16406. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16407. startSampleInFile + startSample, numSamples);
  16408. }
  16409. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16410. int64 numSamples,
  16411. float& lowestLeft,
  16412. float& highestLeft,
  16413. float& lowestRight,
  16414. float& highestRight)
  16415. {
  16416. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16417. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16418. source->readMaxLevels (startSampleInFile + startSample,
  16419. numSamples,
  16420. lowestLeft,
  16421. highestLeft,
  16422. lowestRight,
  16423. highestRight);
  16424. }
  16425. END_JUCE_NAMESPACE
  16426. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16427. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16428. BEGIN_JUCE_NAMESPACE
  16429. const int timeBeforeDeletingReader = 2000;
  16430. struct AudioThumbnailDataFormat
  16431. {
  16432. char thumbnailMagic[4];
  16433. int samplesPerThumbSample;
  16434. int64 totalSamples; // source samples
  16435. int64 numFinishedSamples; // source samples
  16436. int numThumbnailSamples;
  16437. int numChannels;
  16438. int sampleRate;
  16439. char future[16];
  16440. char data[1];
  16441. void swapEndiannessIfNeeded() throw()
  16442. {
  16443. #if JUCE_BIG_ENDIAN
  16444. flip (samplesPerThumbSample);
  16445. flip (totalSamples);
  16446. flip (numFinishedSamples);
  16447. flip (numThumbnailSamples);
  16448. flip (numChannels);
  16449. flip (sampleRate);
  16450. #endif
  16451. }
  16452. private:
  16453. #if JUCE_BIG_ENDIAN
  16454. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16455. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16456. #endif
  16457. };
  16458. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16459. AudioFormatManager& formatManagerToUse_,
  16460. AudioThumbnailCache& cacheToUse)
  16461. : formatManagerToUse (formatManagerToUse_),
  16462. cache (cacheToUse),
  16463. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16464. {
  16465. clear();
  16466. }
  16467. AudioThumbnail::~AudioThumbnail()
  16468. {
  16469. cache.removeThumbnail (this);
  16470. const ScopedLock sl (readerLock);
  16471. reader = 0;
  16472. }
  16473. void AudioThumbnail::setSource (InputSource* const newSource)
  16474. {
  16475. cache.removeThumbnail (this);
  16476. timerCallback(); // stops the timer and deletes the reader
  16477. source = newSource;
  16478. clear();
  16479. if (newSource != 0
  16480. && ! (cache.loadThumb (*this, newSource->hashCode())
  16481. && isFullyLoaded()))
  16482. {
  16483. {
  16484. const ScopedLock sl (readerLock);
  16485. reader = createReader();
  16486. }
  16487. if (reader != 0)
  16488. {
  16489. initialiseFromAudioFile (*reader);
  16490. cache.addThumbnail (this);
  16491. }
  16492. }
  16493. sendChangeMessage (this);
  16494. }
  16495. bool AudioThumbnail::useTimeSlice()
  16496. {
  16497. const ScopedLock sl (readerLock);
  16498. if (isFullyLoaded())
  16499. {
  16500. if (reader != 0)
  16501. startTimer (timeBeforeDeletingReader);
  16502. cache.removeThumbnail (this);
  16503. return false;
  16504. }
  16505. if (reader == 0)
  16506. reader = createReader();
  16507. if (reader != 0)
  16508. {
  16509. readNextBlockFromAudioFile (*reader);
  16510. stopTimer();
  16511. sendChangeMessage (this);
  16512. const bool justFinished = isFullyLoaded();
  16513. if (justFinished)
  16514. cache.storeThumb (*this, source->hashCode());
  16515. return ! justFinished;
  16516. }
  16517. return false;
  16518. }
  16519. AudioFormatReader* AudioThumbnail::createReader() const
  16520. {
  16521. if (source != 0)
  16522. {
  16523. InputStream* const audioFileStream = source->createInputStream();
  16524. if (audioFileStream != 0)
  16525. return formatManagerToUse.createReaderFor (audioFileStream);
  16526. }
  16527. return 0;
  16528. }
  16529. void AudioThumbnail::timerCallback()
  16530. {
  16531. stopTimer();
  16532. const ScopedLock sl (readerLock);
  16533. reader = 0;
  16534. }
  16535. void AudioThumbnail::clear()
  16536. {
  16537. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16538. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16539. d->thumbnailMagic[0] = 'j';
  16540. d->thumbnailMagic[1] = 'a';
  16541. d->thumbnailMagic[2] = 't';
  16542. d->thumbnailMagic[3] = 'm';
  16543. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16544. d->totalSamples = 0;
  16545. d->numFinishedSamples = 0;
  16546. d->numThumbnailSamples = 0;
  16547. d->numChannels = 0;
  16548. d->sampleRate = 0;
  16549. numSamplesCached = 0;
  16550. cacheNeedsRefilling = true;
  16551. }
  16552. void AudioThumbnail::loadFrom (InputStream& input)
  16553. {
  16554. const ScopedLock sl (readerLock);
  16555. data.setSize (0);
  16556. input.readIntoMemoryBlock (data);
  16557. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16558. d->swapEndiannessIfNeeded();
  16559. if (! (d->thumbnailMagic[0] == 'j'
  16560. && d->thumbnailMagic[1] == 'a'
  16561. && d->thumbnailMagic[2] == 't'
  16562. && d->thumbnailMagic[3] == 'm'))
  16563. {
  16564. clear();
  16565. }
  16566. numSamplesCached = 0;
  16567. cacheNeedsRefilling = true;
  16568. }
  16569. void AudioThumbnail::saveTo (OutputStream& output) const
  16570. {
  16571. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16572. d->swapEndiannessIfNeeded();
  16573. output.write (data.getData(), (int) data.getSize());
  16574. d->swapEndiannessIfNeeded();
  16575. }
  16576. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16577. {
  16578. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16579. d->totalSamples = fileReader.lengthInSamples;
  16580. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16581. d->numFinishedSamples = 0;
  16582. d->sampleRate = roundToInt (fileReader.sampleRate);
  16583. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16584. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16585. d = (AudioThumbnailDataFormat*) data.getData();
  16586. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16587. return d->totalSamples > 0;
  16588. }
  16589. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16590. {
  16591. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16592. if (d->numFinishedSamples < d->totalSamples)
  16593. {
  16594. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16595. generateSection (fileReader,
  16596. d->numFinishedSamples,
  16597. numToDo);
  16598. d->numFinishedSamples += numToDo;
  16599. }
  16600. cacheNeedsRefilling = true;
  16601. return (d->numFinishedSamples < d->totalSamples);
  16602. }
  16603. int AudioThumbnail::getNumChannels() const throw()
  16604. {
  16605. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16606. jassert (d != 0);
  16607. return d->numChannels;
  16608. }
  16609. double AudioThumbnail::getTotalLength() const throw()
  16610. {
  16611. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16612. jassert (d != 0);
  16613. if (d->sampleRate > 0)
  16614. return d->totalSamples / (double)d->sampleRate;
  16615. else
  16616. return 0.0;
  16617. }
  16618. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16619. int64 startSample,
  16620. int numSamples)
  16621. {
  16622. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16623. jassert (d != 0);
  16624. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16625. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16626. char* l = getChannelData (0);
  16627. char* r = getChannelData (1);
  16628. for (int i = firstDataPos; i < lastDataPos; ++i)
  16629. {
  16630. const int sourceStart = i * d->samplesPerThumbSample;
  16631. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16632. float lowestLeft, highestLeft, lowestRight, highestRight;
  16633. fileReader.readMaxLevels (sourceStart,
  16634. sourceEnd - sourceStart,
  16635. lowestLeft,
  16636. highestLeft,
  16637. lowestRight,
  16638. highestRight);
  16639. int n = i * 2;
  16640. if (r != 0)
  16641. {
  16642. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16643. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16644. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16645. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16646. }
  16647. else
  16648. {
  16649. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16650. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16651. }
  16652. }
  16653. }
  16654. char* AudioThumbnail::getChannelData (int channel) const
  16655. {
  16656. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16657. jassert (d != 0);
  16658. if (channel >= 0 && channel < d->numChannels)
  16659. return d->data + (channel * 2 * d->numThumbnailSamples);
  16660. return 0;
  16661. }
  16662. bool AudioThumbnail::isFullyLoaded() const throw()
  16663. {
  16664. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16665. jassert (d != 0);
  16666. return d->numFinishedSamples >= d->totalSamples;
  16667. }
  16668. void AudioThumbnail::refillCache (const int numSamples,
  16669. double startTime,
  16670. const double timePerPixel)
  16671. {
  16672. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16673. jassert (d != 0);
  16674. if (numSamples <= 0
  16675. || timePerPixel <= 0.0
  16676. || d->sampleRate <= 0)
  16677. {
  16678. numSamplesCached = 0;
  16679. cacheNeedsRefilling = true;
  16680. return;
  16681. }
  16682. if (numSamples == numSamplesCached
  16683. && numChannelsCached == d->numChannels
  16684. && startTime == cachedStart
  16685. && timePerPixel == cachedTimePerPixel
  16686. && ! cacheNeedsRefilling)
  16687. {
  16688. return;
  16689. }
  16690. numSamplesCached = numSamples;
  16691. numChannelsCached = d->numChannels;
  16692. cachedStart = startTime;
  16693. cachedTimePerPixel = timePerPixel;
  16694. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16695. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16696. const ScopedLock sl (readerLock);
  16697. cacheNeedsRefilling = false;
  16698. if (needExtraDetail && reader == 0)
  16699. reader = createReader();
  16700. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16701. {
  16702. startTimer (timeBeforeDeletingReader);
  16703. char* cacheData = static_cast <char*> (cachedLevels.getData());
  16704. int sample = roundToInt (startTime * d->sampleRate);
  16705. for (int i = numSamples; --i >= 0;)
  16706. {
  16707. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16708. if (sample >= 0)
  16709. {
  16710. if (sample >= reader->lengthInSamples)
  16711. break;
  16712. float lmin, lmax, rmin, rmax;
  16713. reader->readMaxLevels (sample,
  16714. jmax (1, nextSample - sample),
  16715. lmin, lmax, rmin, rmax);
  16716. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16717. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16718. if (numChannelsCached > 1)
  16719. {
  16720. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16721. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16722. }
  16723. cacheData += 2 * numChannelsCached;
  16724. }
  16725. startTime += timePerPixel;
  16726. sample = nextSample;
  16727. }
  16728. }
  16729. else
  16730. {
  16731. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16732. {
  16733. char* const channelData = getChannelData (channelNum);
  16734. char* cacheData = static_cast <char*> (cachedLevels.getData()) + channelNum * 2;
  16735. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16736. startTime = cachedStart;
  16737. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16738. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16739. for (int i = numSamples; --i >= 0;)
  16740. {
  16741. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16742. if (sample >= 0 && channelData != 0)
  16743. {
  16744. char mx = -128;
  16745. char mn = 127;
  16746. while (sample <= nextSample)
  16747. {
  16748. if (sample >= numFinished)
  16749. break;
  16750. const int n = sample << 1;
  16751. const char sampMin = channelData [n];
  16752. const char sampMax = channelData [n + 1];
  16753. if (sampMin < mn)
  16754. mn = sampMin;
  16755. if (sampMax > mx)
  16756. mx = sampMax;
  16757. ++sample;
  16758. }
  16759. if (mn <= mx)
  16760. {
  16761. cacheData[0] = mn;
  16762. cacheData[1] = mx;
  16763. }
  16764. else
  16765. {
  16766. cacheData[0] = 1;
  16767. cacheData[1] = 0;
  16768. }
  16769. }
  16770. else
  16771. {
  16772. cacheData[0] = 1;
  16773. cacheData[1] = 0;
  16774. }
  16775. cacheData += numChannelsCached * 2;
  16776. startTime += timePerPixel;
  16777. sample = nextSample;
  16778. }
  16779. }
  16780. }
  16781. }
  16782. void AudioThumbnail::drawChannel (Graphics& g,
  16783. int x, int y, int w, int h,
  16784. double startTime,
  16785. double endTime,
  16786. int channelNum,
  16787. const float verticalZoomFactor)
  16788. {
  16789. refillCache (w, startTime, (endTime - startTime) / w);
  16790. if (numSamplesCached >= w
  16791. && channelNum >= 0
  16792. && channelNum < numChannelsCached)
  16793. {
  16794. const float topY = (float) y;
  16795. const float bottomY = topY + h;
  16796. const float midY = topY + h * 0.5f;
  16797. const float vscale = verticalZoomFactor * h / 256.0f;
  16798. const Rectangle<int> clip (g.getClipBounds());
  16799. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16800. w -= skipLeft;
  16801. x += skipLeft;
  16802. const char* cacheData = static_cast <const char*> (cachedLevels.getData())
  16803. + (channelNum << 1)
  16804. + skipLeft * (numChannelsCached << 1);
  16805. while (--w >= 0)
  16806. {
  16807. const char mn = cacheData[0];
  16808. const char mx = cacheData[1];
  16809. cacheData += numChannelsCached << 1;
  16810. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16811. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16812. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16813. ++x;
  16814. if (x >= clip.getRight())
  16815. break;
  16816. }
  16817. }
  16818. }
  16819. END_JUCE_NAMESPACE
  16820. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16821. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16822. BEGIN_JUCE_NAMESPACE
  16823. struct ThumbnailCacheEntry
  16824. {
  16825. int64 hash;
  16826. uint32 lastUsed;
  16827. MemoryBlock data;
  16828. juce_UseDebuggingNewOperator
  16829. };
  16830. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16831. : TimeSliceThread ("thumb cache"),
  16832. maxNumThumbsToStore (maxNumThumbsToStore_)
  16833. {
  16834. startThread (2);
  16835. }
  16836. AudioThumbnailCache::~AudioThumbnailCache()
  16837. {
  16838. }
  16839. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16840. {
  16841. for (int i = thumbs.size(); --i >= 0;)
  16842. {
  16843. if (thumbs[i]->hash == hashCode)
  16844. {
  16845. MemoryInputStream in (thumbs[i]->data, false);
  16846. thumb.loadFrom (in);
  16847. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16848. return true;
  16849. }
  16850. }
  16851. return false;
  16852. }
  16853. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16854. const int64 hashCode)
  16855. {
  16856. MemoryOutputStream out;
  16857. thumb.saveTo (out);
  16858. ThumbnailCacheEntry* te = 0;
  16859. for (int i = thumbs.size(); --i >= 0;)
  16860. {
  16861. if (thumbs[i]->hash == hashCode)
  16862. {
  16863. te = thumbs[i];
  16864. break;
  16865. }
  16866. }
  16867. if (te == 0)
  16868. {
  16869. te = new ThumbnailCacheEntry();
  16870. te->hash = hashCode;
  16871. if (thumbs.size() < maxNumThumbsToStore)
  16872. {
  16873. thumbs.add (te);
  16874. }
  16875. else
  16876. {
  16877. int oldest = 0;
  16878. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16879. int i;
  16880. for (i = thumbs.size(); --i >= 0;)
  16881. if (thumbs[i]->lastUsed < oldestTime)
  16882. oldest = i;
  16883. thumbs.set (i, te);
  16884. }
  16885. }
  16886. te->lastUsed = Time::getMillisecondCounter();
  16887. te->data.setSize (0);
  16888. te->data.append (out.getData(), out.getDataSize());
  16889. }
  16890. void AudioThumbnailCache::clear()
  16891. {
  16892. thumbs.clear();
  16893. }
  16894. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16895. {
  16896. addTimeSliceClient (thumb);
  16897. }
  16898. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16899. {
  16900. removeTimeSliceClient (thumb);
  16901. }
  16902. END_JUCE_NAMESPACE
  16903. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16904. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16905. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16906. #if ! JUCE_WINDOWS
  16907. #include <QuickTime/Movies.h>
  16908. #include <QuickTime/QTML.h>
  16909. #include <QuickTime/QuickTimeComponents.h>
  16910. #include <QuickTime/MediaHandlers.h>
  16911. #include <QuickTime/ImageCodec.h>
  16912. #else
  16913. #if JUCE_MSVC
  16914. #pragma warning (push)
  16915. #pragma warning (disable : 4100)
  16916. #endif
  16917. #include <Movies.h>
  16918. #include <QTML.h>
  16919. #include <QuickTimeComponents.h>
  16920. #include <MediaHandlers.h>
  16921. #include <ImageCodec.h>
  16922. #if JUCE_MSVC
  16923. #pragma warning (pop)
  16924. #endif
  16925. #endif
  16926. BEGIN_JUCE_NAMESPACE
  16927. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16928. static const char* const quickTimeFormatName = "QuickTime file";
  16929. static const juce_wchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16930. class QTAudioReader : public AudioFormatReader
  16931. {
  16932. public:
  16933. QTAudioReader (InputStream* const input_, const int trackNum_)
  16934. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16935. ok (false),
  16936. movie (0),
  16937. trackNum (trackNum_),
  16938. lastSampleRead (0),
  16939. lastThreadId (0),
  16940. extractor (0),
  16941. dataHandle (0)
  16942. {
  16943. bufferList.calloc (256, 1);
  16944. #ifdef WIN32
  16945. if (InitializeQTML (0) != noErr)
  16946. return;
  16947. #endif
  16948. if (EnterMovies() != noErr)
  16949. return;
  16950. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16951. if (! opened)
  16952. return;
  16953. {
  16954. const int numTracks = GetMovieTrackCount (movie);
  16955. int trackCount = 0;
  16956. for (int i = 1; i <= numTracks; ++i)
  16957. {
  16958. track = GetMovieIndTrack (movie, i);
  16959. media = GetTrackMedia (track);
  16960. OSType mediaType;
  16961. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16962. if (mediaType == SoundMediaType
  16963. && trackCount++ == trackNum_)
  16964. {
  16965. ok = true;
  16966. break;
  16967. }
  16968. }
  16969. }
  16970. if (! ok)
  16971. return;
  16972. ok = false;
  16973. lengthInSamples = GetMediaDecodeDuration (media);
  16974. usesFloatingPointData = false;
  16975. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16976. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16977. / GetMediaTimeScale (media);
  16978. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16979. unsigned long output_layout_size;
  16980. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16981. kQTPropertyClass_MovieAudioExtraction_Audio,
  16982. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16983. 0, &output_layout_size, 0);
  16984. if (err != noErr)
  16985. return;
  16986. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  16987. qt_audio_channel_layout.calloc (output_layout_size, 1);
  16988. err = MovieAudioExtractionGetProperty (extractor,
  16989. kQTPropertyClass_MovieAudioExtraction_Audio,
  16990. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16991. output_layout_size, qt_audio_channel_layout, 0);
  16992. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  16993. err = MovieAudioExtractionSetProperty (extractor,
  16994. kQTPropertyClass_MovieAudioExtraction_Audio,
  16995. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16996. output_layout_size,
  16997. qt_audio_channel_layout);
  16998. err = MovieAudioExtractionGetProperty (extractor,
  16999. kQTPropertyClass_MovieAudioExtraction_Audio,
  17000. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17001. sizeof (inputStreamDesc),
  17002. &inputStreamDesc, 0);
  17003. if (err != noErr)
  17004. return;
  17005. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17006. | kAudioFormatFlagIsPacked
  17007. | kAudioFormatFlagsNativeEndian;
  17008. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17009. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17010. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17011. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17012. err = MovieAudioExtractionSetProperty (extractor,
  17013. kQTPropertyClass_MovieAudioExtraction_Audio,
  17014. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17015. sizeof (inputStreamDesc),
  17016. &inputStreamDesc);
  17017. if (err != noErr)
  17018. return;
  17019. Boolean allChannelsDiscrete = false;
  17020. err = MovieAudioExtractionSetProperty (extractor,
  17021. kQTPropertyClass_MovieAudioExtraction_Movie,
  17022. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17023. sizeof (allChannelsDiscrete),
  17024. &allChannelsDiscrete);
  17025. if (err != noErr)
  17026. return;
  17027. bufferList->mNumberBuffers = 1;
  17028. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17029. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17030. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17031. sampleRate = inputStreamDesc.mSampleRate;
  17032. bitsPerSample = 16;
  17033. numChannels = inputStreamDesc.mChannelsPerFrame;
  17034. detachThread();
  17035. ok = true;
  17036. }
  17037. ~QTAudioReader()
  17038. {
  17039. if (dataHandle != 0)
  17040. DisposeHandle (dataHandle);
  17041. if (extractor != 0)
  17042. {
  17043. MovieAudioExtractionEnd (extractor);
  17044. extractor = 0;
  17045. }
  17046. checkThreadIsAttached();
  17047. DisposeMovie (movie);
  17048. juce_free (bufferList->mBuffers[0].mData);
  17049. #if JUCE_MAC
  17050. ExitMoviesOnThread ();
  17051. #endif
  17052. }
  17053. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17054. int64 startSampleInFile, int numSamples)
  17055. {
  17056. checkThreadIsAttached();
  17057. while (numSamples > 0)
  17058. {
  17059. if (! loadFrame ((int) startSampleInFile))
  17060. return false;
  17061. const int numToDo = jmin (numSamples, samplesPerFrame);
  17062. for (int j = numDestChannels; --j >= 0;)
  17063. {
  17064. if (destSamples[j] != 0)
  17065. {
  17066. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17067. for (int i = 0; i < numToDo; ++i)
  17068. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17069. }
  17070. }
  17071. startOffsetInDestBuffer += numToDo;
  17072. startSampleInFile += numToDo;
  17073. numSamples -= numToDo;
  17074. }
  17075. detachThread();
  17076. return true;
  17077. }
  17078. bool loadFrame (const int sampleNum)
  17079. {
  17080. if (lastSampleRead != sampleNum)
  17081. {
  17082. TimeRecord time;
  17083. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17084. time.base = 0;
  17085. time.value.hi = 0;
  17086. time.value.lo = (UInt32) sampleNum;
  17087. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17088. kQTPropertyClass_MovieAudioExtraction_Movie,
  17089. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17090. sizeof (time), &time);
  17091. if (err != noErr)
  17092. return false;
  17093. }
  17094. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17095. UInt32 outFlags = 0;
  17096. UInt32 actualNumSamples = samplesPerFrame;
  17097. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17098. bufferList, &outFlags);
  17099. lastSampleRead = sampleNum + samplesPerFrame;
  17100. return err == noErr;
  17101. }
  17102. juce_UseDebuggingNewOperator
  17103. bool ok;
  17104. private:
  17105. Movie movie;
  17106. Media media;
  17107. Track track;
  17108. const int trackNum;
  17109. double trackUnitsPerFrame;
  17110. int samplesPerFrame;
  17111. int lastSampleRead;
  17112. Thread::ThreadID lastThreadId;
  17113. MovieAudioExtractionRef extractor;
  17114. AudioStreamBasicDescription inputStreamDesc;
  17115. HeapBlock <AudioBufferList> bufferList;
  17116. Handle dataHandle;
  17117. void checkThreadIsAttached()
  17118. {
  17119. #if JUCE_MAC
  17120. if (Thread::getCurrentThreadId() != lastThreadId)
  17121. EnterMoviesOnThread (0);
  17122. AttachMovieToCurrentThread (movie);
  17123. #endif
  17124. }
  17125. void detachThread()
  17126. {
  17127. #if JUCE_MAC
  17128. DetachMovieFromCurrentThread (movie);
  17129. #endif
  17130. }
  17131. QTAudioReader (const QTAudioReader&);
  17132. QTAudioReader& operator= (const QTAudioReader&);
  17133. };
  17134. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17135. : AudioFormat (TRANS (quickTimeFormatName), (const juce_wchar**) quickTimeExtensions)
  17136. {
  17137. }
  17138. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17139. {
  17140. }
  17141. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17142. {
  17143. return Array<int>();
  17144. }
  17145. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17146. {
  17147. return Array<int>();
  17148. }
  17149. bool QuickTimeAudioFormat::canDoStereo()
  17150. {
  17151. return true;
  17152. }
  17153. bool QuickTimeAudioFormat::canDoMono()
  17154. {
  17155. return true;
  17156. }
  17157. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17158. const bool deleteStreamIfOpeningFails)
  17159. {
  17160. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17161. if (r->ok)
  17162. return r.release();
  17163. if (! deleteStreamIfOpeningFails)
  17164. r->input = 0;
  17165. return 0;
  17166. }
  17167. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17168. double /*sampleRateToUse*/,
  17169. unsigned int /*numberOfChannels*/,
  17170. int /*bitsPerSample*/,
  17171. const StringPairArray& /*metadataValues*/,
  17172. int /*qualityOptionIndex*/)
  17173. {
  17174. jassertfalse // not yet implemented!
  17175. return 0;
  17176. }
  17177. END_JUCE_NAMESPACE
  17178. #endif
  17179. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17180. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17181. BEGIN_JUCE_NAMESPACE
  17182. static const char* const wavFormatName = "WAV file";
  17183. static const juce_wchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17184. const char* const WavAudioFormat::bwavDescription = "bwav description";
  17185. const char* const WavAudioFormat::bwavOriginator = "bwav originator";
  17186. const char* const WavAudioFormat::bwavOriginatorRef = "bwav originator ref";
  17187. const char* const WavAudioFormat::bwavOriginationDate = "bwav origination date";
  17188. const char* const WavAudioFormat::bwavOriginationTime = "bwav origination time";
  17189. const char* const WavAudioFormat::bwavTimeReference = "bwav time reference";
  17190. const char* const WavAudioFormat::bwavCodingHistory = "bwav coding history";
  17191. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17192. const String& originator,
  17193. const String& originatorRef,
  17194. const Time& date,
  17195. const int64 timeReferenceSamples,
  17196. const String& codingHistory)
  17197. {
  17198. StringPairArray m;
  17199. m.set (bwavDescription, description);
  17200. m.set (bwavOriginator, originator);
  17201. m.set (bwavOriginatorRef, originatorRef);
  17202. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17203. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17204. m.set (bwavTimeReference, String (timeReferenceSamples));
  17205. m.set (bwavCodingHistory, codingHistory);
  17206. return m;
  17207. }
  17208. #if JUCE_MSVC
  17209. #pragma pack (push, 1)
  17210. #define PACKED
  17211. #elif JUCE_GCC
  17212. #define PACKED __attribute__((packed))
  17213. #else
  17214. #define PACKED
  17215. #endif
  17216. struct BWAVChunk
  17217. {
  17218. char description [256];
  17219. char originator [32];
  17220. char originatorRef [32];
  17221. char originationDate [10];
  17222. char originationTime [8];
  17223. uint32 timeRefLow;
  17224. uint32 timeRefHigh;
  17225. uint16 version;
  17226. uint8 umid[64];
  17227. uint8 reserved[190];
  17228. char codingHistory[1];
  17229. void copyTo (StringPairArray& values) const
  17230. {
  17231. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17232. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17233. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17234. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17235. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17236. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17237. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17238. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17239. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17240. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17241. }
  17242. static MemoryBlock createFrom (const StringPairArray& values)
  17243. {
  17244. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17245. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17246. data.fillWith (0);
  17247. BWAVChunk* b = (BWAVChunk*) data.getData();
  17248. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17249. // as they get called in the right order..
  17250. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17251. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17252. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17253. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17254. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17255. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17256. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17257. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17258. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17259. if (b->description[0] != 0
  17260. || b->originator[0] != 0
  17261. || b->originationDate[0] != 0
  17262. || b->originationTime[0] != 0
  17263. || b->codingHistory[0] != 0
  17264. || time != 0)
  17265. {
  17266. return data;
  17267. }
  17268. return MemoryBlock();
  17269. }
  17270. } PACKED;
  17271. struct SMPLChunk
  17272. {
  17273. struct SampleLoop
  17274. {
  17275. uint32 identifier;
  17276. uint32 type;
  17277. uint32 start;
  17278. uint32 end;
  17279. uint32 fraction;
  17280. uint32 playCount;
  17281. } PACKED;
  17282. uint32 manufacturer;
  17283. uint32 product;
  17284. uint32 samplePeriod;
  17285. uint32 midiUnityNote;
  17286. uint32 midiPitchFraction;
  17287. uint32 smpteFormat;
  17288. uint32 smpteOffset;
  17289. uint32 numSampleLoops;
  17290. uint32 samplerData;
  17291. SampleLoop loops[1];
  17292. void copyTo (StringPairArray& values, const int totalSize) const
  17293. {
  17294. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17295. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17296. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17297. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17298. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17299. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17300. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17301. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17302. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17303. for (uint32 i = 0; i < numSampleLoops; ++i)
  17304. {
  17305. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17306. break;
  17307. const String prefix ("Loop" + String(i));
  17308. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17309. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17310. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17311. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17312. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17313. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17314. }
  17315. }
  17316. static MemoryBlock createFrom (const StringPairArray& values)
  17317. {
  17318. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17319. if (numLoops <= 0)
  17320. return MemoryBlock();
  17321. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17322. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17323. data.fillWith (0);
  17324. SMPLChunk* s = (SMPLChunk*) data.getData();
  17325. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17326. // as they get called in the right order..
  17327. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17328. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17329. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17330. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17331. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17332. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17333. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17334. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17335. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17336. for (int i = 0; i < numLoops; ++i)
  17337. {
  17338. const String prefix ("Loop" + String(i));
  17339. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17340. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17341. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17342. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17343. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17344. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17345. }
  17346. return data;
  17347. }
  17348. } PACKED;
  17349. struct ExtensibleWavSubFormat
  17350. {
  17351. uint32 data1;
  17352. uint16 data2;
  17353. uint16 data3;
  17354. uint8 data4[8];
  17355. } PACKED;
  17356. #if JUCE_MSVC
  17357. #pragma pack (pop)
  17358. #endif
  17359. #undef PACKED
  17360. class WavAudioFormatReader : public AudioFormatReader
  17361. {
  17362. int bytesPerFrame;
  17363. int64 dataChunkStart, dataLength;
  17364. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17365. WavAudioFormatReader (const WavAudioFormatReader&);
  17366. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17367. public:
  17368. int64 bwavChunkStart, bwavSize;
  17369. WavAudioFormatReader (InputStream* const in)
  17370. : AudioFormatReader (in, TRANS (wavFormatName)),
  17371. dataLength (0),
  17372. bwavChunkStart (0),
  17373. bwavSize (0)
  17374. {
  17375. if (input->readInt() == chunkName ("RIFF"))
  17376. {
  17377. const uint32 len = (uint32) input->readInt();
  17378. const int64 end = input->getPosition() + len;
  17379. bool hasGotType = false;
  17380. bool hasGotData = false;
  17381. if (input->readInt() == chunkName ("WAVE"))
  17382. {
  17383. while (input->getPosition() < end
  17384. && ! input->isExhausted())
  17385. {
  17386. const int chunkType = input->readInt();
  17387. uint32 length = (uint32) input->readInt();
  17388. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17389. if (chunkType == chunkName ("fmt "))
  17390. {
  17391. // read the format chunk
  17392. const unsigned short format = input->readShort();
  17393. const short numChans = input->readShort();
  17394. sampleRate = input->readInt();
  17395. const int bytesPerSec = input->readInt();
  17396. numChannels = numChans;
  17397. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17398. bitsPerSample = 8 * bytesPerFrame / numChans;
  17399. if (format == 3)
  17400. {
  17401. usesFloatingPointData = true;
  17402. }
  17403. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17404. {
  17405. if (length < 40) // too short
  17406. {
  17407. bytesPerFrame = 0;
  17408. }
  17409. else
  17410. {
  17411. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17412. ExtensibleWavSubFormat subFormat;
  17413. subFormat.data1 = input->readInt();
  17414. subFormat.data2 = input->readShort();
  17415. subFormat.data3 = input->readShort();
  17416. input->read (subFormat.data4, sizeof (subFormat.data4));
  17417. const ExtensibleWavSubFormat pcmFormat
  17418. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17419. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17420. {
  17421. const ExtensibleWavSubFormat ambisonicFormat
  17422. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17423. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17424. bytesPerFrame = 0;
  17425. }
  17426. }
  17427. }
  17428. else if (format != 1)
  17429. {
  17430. bytesPerFrame = 0;
  17431. }
  17432. hasGotType = true;
  17433. }
  17434. else if (chunkType == chunkName ("data"))
  17435. {
  17436. // get the data chunk's position
  17437. dataLength = length;
  17438. dataChunkStart = input->getPosition();
  17439. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17440. hasGotData = true;
  17441. }
  17442. else if (chunkType == chunkName ("bext"))
  17443. {
  17444. bwavChunkStart = input->getPosition();
  17445. bwavSize = length;
  17446. // Broadcast-wav extension chunk..
  17447. HeapBlock <BWAVChunk> bwav;
  17448. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17449. input->read (bwav, length);
  17450. bwav->copyTo (metadataValues);
  17451. }
  17452. else if (chunkType == chunkName ("smpl"))
  17453. {
  17454. HeapBlock <SMPLChunk> smpl;
  17455. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17456. input->read (smpl, length);
  17457. smpl->copyTo (metadataValues, length);
  17458. }
  17459. else if (chunkEnd <= input->getPosition())
  17460. {
  17461. break;
  17462. }
  17463. input->setPosition (chunkEnd);
  17464. }
  17465. }
  17466. }
  17467. }
  17468. ~WavAudioFormatReader()
  17469. {
  17470. }
  17471. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17472. int64 startSampleInFile, int numSamples)
  17473. {
  17474. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17475. if (samplesAvailable < numSamples)
  17476. {
  17477. for (int i = numDestChannels; --i >= 0;)
  17478. if (destSamples[i] != 0)
  17479. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17480. numSamples = (int) samplesAvailable;
  17481. }
  17482. if (numSamples <= 0)
  17483. return true;
  17484. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17485. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17486. char tempBuffer [tempBufSize];
  17487. while (numSamples > 0)
  17488. {
  17489. int* left = destSamples[0];
  17490. if (left != 0)
  17491. left += startOffsetInDestBuffer;
  17492. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17493. if (right != 0)
  17494. right += startOffsetInDestBuffer;
  17495. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17496. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17497. if (bytesRead < numThisTime * bytesPerFrame)
  17498. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17499. if (bitsPerSample == 16)
  17500. {
  17501. const short* src = reinterpret_cast <const short*> (tempBuffer);
  17502. if (numChannels > 1)
  17503. {
  17504. if (left == 0)
  17505. {
  17506. for (int i = numThisTime; --i >= 0;)
  17507. {
  17508. ++src;
  17509. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17510. }
  17511. }
  17512. else if (right == 0)
  17513. {
  17514. for (int i = numThisTime; --i >= 0;)
  17515. {
  17516. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17517. ++src;
  17518. }
  17519. }
  17520. else
  17521. {
  17522. for (int i = numThisTime; --i >= 0;)
  17523. {
  17524. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17525. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17526. }
  17527. }
  17528. }
  17529. else
  17530. {
  17531. for (int i = numThisTime; --i >= 0;)
  17532. {
  17533. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17534. }
  17535. }
  17536. }
  17537. else if (bitsPerSample == 24)
  17538. {
  17539. const char* src = tempBuffer;
  17540. if (numChannels > 1)
  17541. {
  17542. if (left == 0)
  17543. {
  17544. for (int i = numThisTime; --i >= 0;)
  17545. {
  17546. src += 3;
  17547. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17548. src += 3;
  17549. }
  17550. }
  17551. else if (right == 0)
  17552. {
  17553. for (int i = numThisTime; --i >= 0;)
  17554. {
  17555. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17556. src += 6;
  17557. }
  17558. }
  17559. else
  17560. {
  17561. for (int i = 0; i < numThisTime; ++i)
  17562. {
  17563. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17564. src += 3;
  17565. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17566. src += 3;
  17567. }
  17568. }
  17569. }
  17570. else
  17571. {
  17572. for (int i = 0; i < numThisTime; ++i)
  17573. {
  17574. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17575. src += 3;
  17576. }
  17577. }
  17578. }
  17579. else if (bitsPerSample == 32)
  17580. {
  17581. const unsigned int* src = (const unsigned int*) tempBuffer;
  17582. unsigned int* l = (unsigned int*) left;
  17583. unsigned int* r = (unsigned int*) right;
  17584. if (numChannels > 1)
  17585. {
  17586. if (l == 0)
  17587. {
  17588. for (int i = numThisTime; --i >= 0;)
  17589. {
  17590. ++src;
  17591. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17592. }
  17593. }
  17594. else if (r == 0)
  17595. {
  17596. for (int i = numThisTime; --i >= 0;)
  17597. {
  17598. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17599. ++src;
  17600. }
  17601. }
  17602. else
  17603. {
  17604. for (int i = numThisTime; --i >= 0;)
  17605. {
  17606. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17607. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17608. }
  17609. }
  17610. }
  17611. else
  17612. {
  17613. for (int i = numThisTime; --i >= 0;)
  17614. {
  17615. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17616. }
  17617. }
  17618. left = (int*)l;
  17619. right = (int*)r;
  17620. }
  17621. else if (bitsPerSample == 8)
  17622. {
  17623. const unsigned char* src = (const unsigned char*) tempBuffer;
  17624. if (numChannels > 1)
  17625. {
  17626. if (left == 0)
  17627. {
  17628. for (int i = numThisTime; --i >= 0;)
  17629. {
  17630. ++src;
  17631. *right++ = ((int) *src++ - 128) << 24;
  17632. }
  17633. }
  17634. else if (right == 0)
  17635. {
  17636. for (int i = numThisTime; --i >= 0;)
  17637. {
  17638. *left++ = ((int) *src++ - 128) << 24;
  17639. ++src;
  17640. }
  17641. }
  17642. else
  17643. {
  17644. for (int i = numThisTime; --i >= 0;)
  17645. {
  17646. *left++ = ((int) *src++ - 128) << 24;
  17647. *right++ = ((int) *src++ - 128) << 24;
  17648. }
  17649. }
  17650. }
  17651. else
  17652. {
  17653. for (int i = numThisTime; --i >= 0;)
  17654. {
  17655. *left++ = ((int)*src++ - 128) << 24;
  17656. }
  17657. }
  17658. }
  17659. startOffsetInDestBuffer += numThisTime;
  17660. numSamples -= numThisTime;
  17661. }
  17662. if (numSamples > 0)
  17663. {
  17664. for (int i = numDestChannels; --i >= 0;)
  17665. if (destSamples[i] != 0)
  17666. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17667. sizeof (int) * numSamples);
  17668. }
  17669. return true;
  17670. }
  17671. juce_UseDebuggingNewOperator
  17672. };
  17673. class WavAudioFormatWriter : public AudioFormatWriter
  17674. {
  17675. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17676. uint32 lengthInSamples, bytesWritten;
  17677. int64 headerPosition;
  17678. bool writeFailed;
  17679. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17680. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17681. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17682. void writeHeader()
  17683. {
  17684. const bool seekedOk = output->setPosition (headerPosition);
  17685. (void) seekedOk;
  17686. // if this fails, you've given it an output stream that can't seek! It needs
  17687. // to be able to seek back to write the header
  17688. jassert (seekedOk);
  17689. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17690. output->writeInt (chunkName ("RIFF"));
  17691. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17692. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17693. output->writeInt (chunkName ("WAVE"));
  17694. output->writeInt (chunkName ("fmt "));
  17695. output->writeInt (16);
  17696. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17697. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17698. output->writeShort ((short) numChannels);
  17699. output->writeInt ((int) sampleRate);
  17700. output->writeInt (bytesPerFrame * (int) sampleRate);
  17701. output->writeShort ((short) bytesPerFrame);
  17702. output->writeShort ((short) bitsPerSample);
  17703. if (bwavChunk.getSize() > 0)
  17704. {
  17705. output->writeInt (chunkName ("bext"));
  17706. output->writeInt ((int) bwavChunk.getSize());
  17707. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17708. }
  17709. if (smplChunk.getSize() > 0)
  17710. {
  17711. output->writeInt (chunkName ("smpl"));
  17712. output->writeInt ((int) smplChunk.getSize());
  17713. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17714. }
  17715. output->writeInt (chunkName ("data"));
  17716. output->writeInt (lengthInSamples * bytesPerFrame);
  17717. usesFloatingPointData = (bitsPerSample == 32);
  17718. }
  17719. public:
  17720. WavAudioFormatWriter (OutputStream* const out,
  17721. const double sampleRate_,
  17722. const unsigned int numChannels_,
  17723. const int bits,
  17724. const StringPairArray& metadataValues)
  17725. : AudioFormatWriter (out,
  17726. TRANS (wavFormatName),
  17727. sampleRate_,
  17728. numChannels_,
  17729. bits),
  17730. lengthInSamples (0),
  17731. bytesWritten (0),
  17732. writeFailed (false)
  17733. {
  17734. if (metadataValues.size() > 0)
  17735. {
  17736. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17737. smplChunk = SMPLChunk::createFrom (metadataValues);
  17738. }
  17739. headerPosition = out->getPosition();
  17740. writeHeader();
  17741. }
  17742. ~WavAudioFormatWriter()
  17743. {
  17744. writeHeader();
  17745. }
  17746. bool write (const int** data, int numSamples)
  17747. {
  17748. if (writeFailed)
  17749. return false;
  17750. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17751. tempBlock.ensureSize (bytes, false);
  17752. char* buffer = static_cast <char*> (tempBlock.getData());
  17753. const int* left = data[0];
  17754. const int* right = data[1];
  17755. if (right == 0)
  17756. right = left;
  17757. if (bitsPerSample == 16)
  17758. {
  17759. short* b = (short*) buffer;
  17760. if (numChannels > 1)
  17761. {
  17762. for (int i = numSamples; --i >= 0;)
  17763. {
  17764. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17765. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17766. }
  17767. }
  17768. else
  17769. {
  17770. for (int i = numSamples; --i >= 0;)
  17771. {
  17772. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17773. }
  17774. }
  17775. }
  17776. else if (bitsPerSample == 24)
  17777. {
  17778. char* b = buffer;
  17779. if (numChannels > 1)
  17780. {
  17781. for (int i = numSamples; --i >= 0;)
  17782. {
  17783. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17784. b += 3;
  17785. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17786. b += 3;
  17787. }
  17788. }
  17789. else
  17790. {
  17791. for (int i = numSamples; --i >= 0;)
  17792. {
  17793. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17794. b += 3;
  17795. }
  17796. }
  17797. }
  17798. else if (bitsPerSample == 32)
  17799. {
  17800. unsigned int* b = (unsigned int*) buffer;
  17801. if (numChannels > 1)
  17802. {
  17803. for (int i = numSamples; --i >= 0;)
  17804. {
  17805. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17806. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17807. }
  17808. }
  17809. else
  17810. {
  17811. for (int i = numSamples; --i >= 0;)
  17812. {
  17813. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17814. }
  17815. }
  17816. }
  17817. else if (bitsPerSample == 8)
  17818. {
  17819. unsigned char* b = (unsigned char*) buffer;
  17820. if (numChannels > 1)
  17821. {
  17822. for (int i = numSamples; --i >= 0;)
  17823. {
  17824. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17825. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17826. }
  17827. }
  17828. else
  17829. {
  17830. for (int i = numSamples; --i >= 0;)
  17831. {
  17832. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17833. }
  17834. }
  17835. }
  17836. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17837. || ! output->write (buffer, bytes))
  17838. {
  17839. // failed to write to disk, so let's try writing the header.
  17840. // If it's just run out of disk space, then if it does manage
  17841. // to write the header, we'll still have a useable file..
  17842. writeHeader();
  17843. writeFailed = true;
  17844. return false;
  17845. }
  17846. else
  17847. {
  17848. bytesWritten += bytes;
  17849. lengthInSamples += numSamples;
  17850. return true;
  17851. }
  17852. }
  17853. juce_UseDebuggingNewOperator
  17854. };
  17855. WavAudioFormat::WavAudioFormat()
  17856. : AudioFormat (TRANS (wavFormatName), (const juce_wchar**) wavExtensions)
  17857. {
  17858. }
  17859. WavAudioFormat::~WavAudioFormat()
  17860. {
  17861. }
  17862. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17863. {
  17864. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17865. return Array <int> (rates);
  17866. }
  17867. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17868. {
  17869. const int depths[] = { 8, 16, 24, 32, 0 };
  17870. return Array <int> (depths);
  17871. }
  17872. bool WavAudioFormat::canDoStereo()
  17873. {
  17874. return true;
  17875. }
  17876. bool WavAudioFormat::canDoMono()
  17877. {
  17878. return true;
  17879. }
  17880. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17881. const bool deleteStreamIfOpeningFails)
  17882. {
  17883. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17884. if (r->sampleRate != 0)
  17885. return r.release();
  17886. if (! deleteStreamIfOpeningFails)
  17887. r->input = 0;
  17888. return 0;
  17889. }
  17890. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17891. double sampleRate,
  17892. unsigned int numChannels,
  17893. int bitsPerSample,
  17894. const StringPairArray& metadataValues,
  17895. int /*qualityOptionIndex*/)
  17896. {
  17897. if (getPossibleBitDepths().contains (bitsPerSample))
  17898. {
  17899. return new WavAudioFormatWriter (out,
  17900. sampleRate,
  17901. numChannels,
  17902. bitsPerSample,
  17903. metadataValues);
  17904. }
  17905. return 0;
  17906. }
  17907. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17908. {
  17909. TemporaryFile tempFile (file);
  17910. WavAudioFormat wav;
  17911. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17912. if (reader != 0)
  17913. {
  17914. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17915. if (outStream != 0)
  17916. {
  17917. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17918. reader->numChannels, reader->bitsPerSample,
  17919. metadata, 0));
  17920. if (writer != 0)
  17921. {
  17922. outStream.release();
  17923. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17924. writer = 0;
  17925. reader = 0;
  17926. return ok && tempFile.overwriteTargetFileWithTemporary();
  17927. }
  17928. }
  17929. }
  17930. return false;
  17931. }
  17932. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17933. {
  17934. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17935. if (reader != 0)
  17936. {
  17937. const int64 bwavPos = reader->bwavChunkStart;
  17938. const int64 bwavSize = reader->bwavSize;
  17939. reader = 0;
  17940. if (bwavSize > 0)
  17941. {
  17942. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17943. if (chunk.getSize() <= (size_t) bwavSize)
  17944. {
  17945. // the new one will fit in the space available, so write it directly..
  17946. const int64 oldSize = wavFile.getSize();
  17947. {
  17948. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17949. out->setPosition (bwavPos);
  17950. out->write (chunk.getData(), (int) chunk.getSize());
  17951. out->setPosition (oldSize);
  17952. }
  17953. jassert (wavFile.getSize() == oldSize);
  17954. return true;
  17955. }
  17956. }
  17957. }
  17958. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17959. }
  17960. END_JUCE_NAMESPACE
  17961. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17962. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17963. BEGIN_JUCE_NAMESPACE
  17964. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17965. const bool deleteReaderWhenThisIsDeleted)
  17966. : reader (reader_),
  17967. deleteReader (deleteReaderWhenThisIsDeleted),
  17968. nextPlayPos (0),
  17969. looping (false)
  17970. {
  17971. jassert (reader != 0);
  17972. }
  17973. AudioFormatReaderSource::~AudioFormatReaderSource()
  17974. {
  17975. releaseResources();
  17976. if (deleteReader)
  17977. delete reader;
  17978. }
  17979. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17980. {
  17981. nextPlayPos = newPosition;
  17982. }
  17983. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17984. {
  17985. looping = shouldLoop;
  17986. }
  17987. int AudioFormatReaderSource::getNextReadPosition() const
  17988. {
  17989. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  17990. : nextPlayPos;
  17991. }
  17992. int AudioFormatReaderSource::getTotalLength() const
  17993. {
  17994. return (int) reader->lengthInSamples;
  17995. }
  17996. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  17997. double /*sampleRate*/)
  17998. {
  17999. }
  18000. void AudioFormatReaderSource::releaseResources()
  18001. {
  18002. }
  18003. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18004. {
  18005. if (info.numSamples > 0)
  18006. {
  18007. const int start = nextPlayPos;
  18008. if (looping)
  18009. {
  18010. const int newStart = start % (int) reader->lengthInSamples;
  18011. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18012. if (newEnd > newStart)
  18013. {
  18014. info.buffer->readFromAudioReader (reader,
  18015. info.startSample,
  18016. newEnd - newStart,
  18017. newStart,
  18018. true, true);
  18019. }
  18020. else
  18021. {
  18022. const int endSamps = (int) reader->lengthInSamples - newStart;
  18023. info.buffer->readFromAudioReader (reader,
  18024. info.startSample,
  18025. endSamps,
  18026. newStart,
  18027. true, true);
  18028. info.buffer->readFromAudioReader (reader,
  18029. info.startSample + endSamps,
  18030. newEnd,
  18031. 0,
  18032. true, true);
  18033. }
  18034. nextPlayPos = newEnd;
  18035. }
  18036. else
  18037. {
  18038. info.buffer->readFromAudioReader (reader,
  18039. info.startSample,
  18040. info.numSamples,
  18041. start,
  18042. true, true);
  18043. nextPlayPos += info.numSamples;
  18044. }
  18045. }
  18046. }
  18047. END_JUCE_NAMESPACE
  18048. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18049. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18050. BEGIN_JUCE_NAMESPACE
  18051. AudioSourcePlayer::AudioSourcePlayer()
  18052. : source (0),
  18053. sampleRate (0),
  18054. bufferSize (0),
  18055. tempBuffer (2, 8),
  18056. lastGain (1.0f),
  18057. gain (1.0f)
  18058. {
  18059. }
  18060. AudioSourcePlayer::~AudioSourcePlayer()
  18061. {
  18062. setSource (0);
  18063. }
  18064. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18065. {
  18066. if (source != newSource)
  18067. {
  18068. AudioSource* const oldSource = source;
  18069. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18070. newSource->prepareToPlay (bufferSize, sampleRate);
  18071. {
  18072. const ScopedLock sl (readLock);
  18073. source = newSource;
  18074. }
  18075. if (oldSource != 0)
  18076. oldSource->releaseResources();
  18077. }
  18078. }
  18079. void AudioSourcePlayer::setGain (const float newGain) throw()
  18080. {
  18081. gain = newGain;
  18082. }
  18083. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18084. int totalNumInputChannels,
  18085. float** outputChannelData,
  18086. int totalNumOutputChannels,
  18087. int numSamples)
  18088. {
  18089. // these should have been prepared by audioDeviceAboutToStart()...
  18090. jassert (sampleRate > 0 && bufferSize > 0);
  18091. const ScopedLock sl (readLock);
  18092. if (source != 0)
  18093. {
  18094. AudioSourceChannelInfo info;
  18095. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18096. // messy stuff needed to compact the channels down into an array
  18097. // of non-zero pointers..
  18098. for (i = 0; i < totalNumInputChannels; ++i)
  18099. {
  18100. if (inputChannelData[i] != 0)
  18101. {
  18102. inputChans [numInputs++] = inputChannelData[i];
  18103. if (numInputs >= numElementsInArray (inputChans))
  18104. break;
  18105. }
  18106. }
  18107. for (i = 0; i < totalNumOutputChannels; ++i)
  18108. {
  18109. if (outputChannelData[i] != 0)
  18110. {
  18111. outputChans [numOutputs++] = outputChannelData[i];
  18112. if (numOutputs >= numElementsInArray (outputChans))
  18113. break;
  18114. }
  18115. }
  18116. if (numInputs > numOutputs)
  18117. {
  18118. // if there aren't enough output channels for the number of
  18119. // inputs, we need to create some temporary extra ones (can't
  18120. // use the input data in case it gets written to)
  18121. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18122. false, false, true);
  18123. for (i = 0; i < numOutputs; ++i)
  18124. {
  18125. channels[numActiveChans] = outputChans[i];
  18126. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18127. ++numActiveChans;
  18128. }
  18129. for (i = numOutputs; i < numInputs; ++i)
  18130. {
  18131. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18132. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18133. ++numActiveChans;
  18134. }
  18135. }
  18136. else
  18137. {
  18138. for (i = 0; i < numInputs; ++i)
  18139. {
  18140. channels[numActiveChans] = outputChans[i];
  18141. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18142. ++numActiveChans;
  18143. }
  18144. for (i = numInputs; i < numOutputs; ++i)
  18145. {
  18146. channels[numActiveChans] = outputChans[i];
  18147. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18148. ++numActiveChans;
  18149. }
  18150. }
  18151. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18152. info.buffer = &buffer;
  18153. info.startSample = 0;
  18154. info.numSamples = numSamples;
  18155. source->getNextAudioBlock (info);
  18156. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18157. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18158. lastGain = gain;
  18159. }
  18160. else
  18161. {
  18162. for (int i = 0; i < totalNumOutputChannels; ++i)
  18163. if (outputChannelData[i] != 0)
  18164. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18165. }
  18166. }
  18167. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18168. {
  18169. sampleRate = device->getCurrentSampleRate();
  18170. bufferSize = device->getCurrentBufferSizeSamples();
  18171. zeromem (channels, sizeof (channels));
  18172. if (source != 0)
  18173. source->prepareToPlay (bufferSize, sampleRate);
  18174. }
  18175. void AudioSourcePlayer::audioDeviceStopped()
  18176. {
  18177. if (source != 0)
  18178. source->releaseResources();
  18179. sampleRate = 0.0;
  18180. bufferSize = 0;
  18181. tempBuffer.setSize (2, 8);
  18182. }
  18183. END_JUCE_NAMESPACE
  18184. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18185. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18186. BEGIN_JUCE_NAMESPACE
  18187. AudioTransportSource::AudioTransportSource()
  18188. : source (0),
  18189. resamplerSource (0),
  18190. bufferingSource (0),
  18191. positionableSource (0),
  18192. masterSource (0),
  18193. gain (1.0f),
  18194. lastGain (1.0f),
  18195. playing (false),
  18196. stopped (true),
  18197. sampleRate (44100.0),
  18198. sourceSampleRate (0.0),
  18199. blockSize (128),
  18200. readAheadBufferSize (0),
  18201. isPrepared (false),
  18202. inputStreamEOF (false)
  18203. {
  18204. }
  18205. AudioTransportSource::~AudioTransportSource()
  18206. {
  18207. setSource (0);
  18208. releaseResources();
  18209. }
  18210. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18211. int readAheadBufferSize_,
  18212. double sourceSampleRateToCorrectFor)
  18213. {
  18214. if (source == newSource)
  18215. {
  18216. if (source == 0)
  18217. return;
  18218. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18219. }
  18220. readAheadBufferSize = readAheadBufferSize_;
  18221. sourceSampleRate = sourceSampleRateToCorrectFor;
  18222. ResamplingAudioSource* newResamplerSource = 0;
  18223. BufferingAudioSource* newBufferingSource = 0;
  18224. PositionableAudioSource* newPositionableSource = 0;
  18225. AudioSource* newMasterSource = 0;
  18226. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18227. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18228. AudioSource* oldMasterSource = masterSource;
  18229. if (newSource != 0)
  18230. {
  18231. newPositionableSource = newSource;
  18232. if (readAheadBufferSize_ > 0)
  18233. newPositionableSource = newBufferingSource
  18234. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18235. newPositionableSource->setNextReadPosition (0);
  18236. if (sourceSampleRateToCorrectFor != 0)
  18237. newMasterSource = newResamplerSource
  18238. = new ResamplingAudioSource (newPositionableSource, false);
  18239. else
  18240. newMasterSource = newPositionableSource;
  18241. if (isPrepared)
  18242. {
  18243. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18244. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18245. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18246. }
  18247. }
  18248. {
  18249. const ScopedLock sl (callbackLock);
  18250. source = newSource;
  18251. resamplerSource = newResamplerSource;
  18252. bufferingSource = newBufferingSource;
  18253. masterSource = newMasterSource;
  18254. positionableSource = newPositionableSource;
  18255. playing = false;
  18256. }
  18257. if (oldMasterSource != 0)
  18258. oldMasterSource->releaseResources();
  18259. }
  18260. void AudioTransportSource::start()
  18261. {
  18262. if ((! playing) && masterSource != 0)
  18263. {
  18264. {
  18265. const ScopedLock sl (callbackLock);
  18266. playing = true;
  18267. stopped = false;
  18268. inputStreamEOF = false;
  18269. }
  18270. sendChangeMessage (this);
  18271. }
  18272. }
  18273. void AudioTransportSource::stop()
  18274. {
  18275. if (playing)
  18276. {
  18277. {
  18278. const ScopedLock sl (callbackLock);
  18279. playing = false;
  18280. }
  18281. int n = 500;
  18282. while (--n >= 0 && ! stopped)
  18283. Thread::sleep (2);
  18284. sendChangeMessage (this);
  18285. }
  18286. }
  18287. void AudioTransportSource::setPosition (double newPosition)
  18288. {
  18289. if (sampleRate > 0.0)
  18290. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18291. }
  18292. double AudioTransportSource::getCurrentPosition() const
  18293. {
  18294. if (sampleRate > 0.0)
  18295. return getNextReadPosition() / sampleRate;
  18296. else
  18297. return 0.0;
  18298. }
  18299. void AudioTransportSource::setNextReadPosition (int newPosition)
  18300. {
  18301. if (positionableSource != 0)
  18302. {
  18303. if (sampleRate > 0 && sourceSampleRate > 0)
  18304. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18305. positionableSource->setNextReadPosition (newPosition);
  18306. }
  18307. }
  18308. int AudioTransportSource::getNextReadPosition() const
  18309. {
  18310. if (positionableSource != 0)
  18311. {
  18312. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18313. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18314. }
  18315. return 0;
  18316. }
  18317. int AudioTransportSource::getTotalLength() const
  18318. {
  18319. const ScopedLock sl (callbackLock);
  18320. if (positionableSource != 0)
  18321. {
  18322. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18323. return roundToInt (positionableSource->getTotalLength() * ratio);
  18324. }
  18325. return 0;
  18326. }
  18327. bool AudioTransportSource::isLooping() const
  18328. {
  18329. const ScopedLock sl (callbackLock);
  18330. return positionableSource != 0
  18331. && positionableSource->isLooping();
  18332. }
  18333. void AudioTransportSource::setGain (const float newGain) throw()
  18334. {
  18335. gain = newGain;
  18336. }
  18337. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18338. double sampleRate_)
  18339. {
  18340. const ScopedLock sl (callbackLock);
  18341. sampleRate = sampleRate_;
  18342. blockSize = samplesPerBlockExpected;
  18343. if (masterSource != 0)
  18344. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18345. if (resamplerSource != 0 && sourceSampleRate != 0)
  18346. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18347. isPrepared = true;
  18348. }
  18349. void AudioTransportSource::releaseResources()
  18350. {
  18351. const ScopedLock sl (callbackLock);
  18352. if (masterSource != 0)
  18353. masterSource->releaseResources();
  18354. isPrepared = false;
  18355. }
  18356. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18357. {
  18358. const ScopedLock sl (callbackLock);
  18359. inputStreamEOF = false;
  18360. if (masterSource != 0 && ! stopped)
  18361. {
  18362. masterSource->getNextAudioBlock (info);
  18363. if (! playing)
  18364. {
  18365. // just stopped playing, so fade out the last block..
  18366. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18367. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18368. if (info.numSamples > 256)
  18369. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18370. }
  18371. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18372. && ! positionableSource->isLooping())
  18373. {
  18374. playing = false;
  18375. inputStreamEOF = true;
  18376. sendChangeMessage (this);
  18377. }
  18378. stopped = ! playing;
  18379. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18380. {
  18381. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18382. lastGain, gain);
  18383. }
  18384. }
  18385. else
  18386. {
  18387. info.clearActiveBufferRegion();
  18388. stopped = true;
  18389. }
  18390. lastGain = gain;
  18391. }
  18392. END_JUCE_NAMESPACE
  18393. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18394. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18395. BEGIN_JUCE_NAMESPACE
  18396. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18397. public Thread,
  18398. private Timer
  18399. {
  18400. public:
  18401. SharedBufferingAudioSourceThread()
  18402. : Thread ("Audio Buffer")
  18403. {
  18404. }
  18405. ~SharedBufferingAudioSourceThread()
  18406. {
  18407. stopThread (10000);
  18408. clearSingletonInstance();
  18409. }
  18410. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18411. void addSource (BufferingAudioSource* source)
  18412. {
  18413. const ScopedLock sl (lock);
  18414. if (! sources.contains (source))
  18415. {
  18416. sources.add (source);
  18417. startThread();
  18418. stopTimer();
  18419. }
  18420. notify();
  18421. }
  18422. void removeSource (BufferingAudioSource* source)
  18423. {
  18424. const ScopedLock sl (lock);
  18425. sources.removeValue (source);
  18426. if (sources.size() == 0)
  18427. startTimer (5000);
  18428. }
  18429. private:
  18430. Array <BufferingAudioSource*> sources;
  18431. CriticalSection lock;
  18432. void run()
  18433. {
  18434. while (! threadShouldExit())
  18435. {
  18436. bool busy = false;
  18437. for (int i = sources.size(); --i >= 0;)
  18438. {
  18439. if (threadShouldExit())
  18440. return;
  18441. const ScopedLock sl (lock);
  18442. BufferingAudioSource* const b = sources[i];
  18443. if (b != 0 && b->readNextBufferChunk())
  18444. busy = true;
  18445. }
  18446. if (! busy)
  18447. wait (500);
  18448. }
  18449. }
  18450. void timerCallback()
  18451. {
  18452. stopTimer();
  18453. if (sources.size() == 0)
  18454. deleteInstance();
  18455. }
  18456. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18457. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18458. };
  18459. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18460. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18461. const bool deleteSourceWhenDeleted_,
  18462. int numberOfSamplesToBuffer_)
  18463. : source (source_),
  18464. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18465. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18466. buffer (2, 0),
  18467. bufferValidStart (0),
  18468. bufferValidEnd (0),
  18469. nextPlayPos (0),
  18470. wasSourceLooping (false)
  18471. {
  18472. jassert (source_ != 0);
  18473. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18474. // not using a larger buffer..
  18475. }
  18476. BufferingAudioSource::~BufferingAudioSource()
  18477. {
  18478. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18479. if (thread != 0)
  18480. thread->removeSource (this);
  18481. if (deleteSourceWhenDeleted)
  18482. delete source;
  18483. }
  18484. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18485. {
  18486. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18487. sampleRate = sampleRate_;
  18488. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18489. buffer.clear();
  18490. bufferValidStart = 0;
  18491. bufferValidEnd = 0;
  18492. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18493. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18494. buffer.getNumSamples() / 2))
  18495. {
  18496. SharedBufferingAudioSourceThread::getInstance()->notify();
  18497. Thread::sleep (5);
  18498. }
  18499. }
  18500. void BufferingAudioSource::releaseResources()
  18501. {
  18502. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18503. if (thread != 0)
  18504. thread->removeSource (this);
  18505. buffer.setSize (2, 0);
  18506. source->releaseResources();
  18507. }
  18508. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18509. {
  18510. const ScopedLock sl (bufferStartPosLock);
  18511. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18512. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18513. if (validStart == validEnd)
  18514. {
  18515. // total cache miss
  18516. info.clearActiveBufferRegion();
  18517. }
  18518. else
  18519. {
  18520. if (validStart > 0)
  18521. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18522. if (validEnd < info.numSamples)
  18523. info.buffer->clear (info.startSample + validEnd,
  18524. info.numSamples - validEnd); // partial cache miss at end
  18525. if (validStart < validEnd)
  18526. {
  18527. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18528. {
  18529. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18530. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18531. if (startBufferIndex < endBufferIndex)
  18532. {
  18533. info.buffer->copyFrom (chan, info.startSample + validStart,
  18534. buffer,
  18535. chan, startBufferIndex,
  18536. validEnd - validStart);
  18537. }
  18538. else
  18539. {
  18540. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18541. info.buffer->copyFrom (chan, info.startSample + validStart,
  18542. buffer,
  18543. chan, startBufferIndex,
  18544. initialSize);
  18545. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18546. buffer,
  18547. chan, 0,
  18548. (validEnd - validStart) - initialSize);
  18549. }
  18550. }
  18551. }
  18552. nextPlayPos += info.numSamples;
  18553. if (source->isLooping() && nextPlayPos > 0)
  18554. nextPlayPos %= source->getTotalLength();
  18555. }
  18556. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18557. if (thread != 0)
  18558. thread->notify();
  18559. }
  18560. int BufferingAudioSource::getNextReadPosition() const
  18561. {
  18562. return (source->isLooping() && nextPlayPos > 0)
  18563. ? nextPlayPos % source->getTotalLength()
  18564. : nextPlayPos;
  18565. }
  18566. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18567. {
  18568. const ScopedLock sl (bufferStartPosLock);
  18569. nextPlayPos = newPosition;
  18570. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18571. if (thread != 0)
  18572. thread->notify();
  18573. }
  18574. bool BufferingAudioSource::readNextBufferChunk()
  18575. {
  18576. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18577. {
  18578. const ScopedLock sl (bufferStartPosLock);
  18579. if (wasSourceLooping != isLooping())
  18580. {
  18581. wasSourceLooping = isLooping();
  18582. bufferValidStart = 0;
  18583. bufferValidEnd = 0;
  18584. }
  18585. newBVS = jmax (0, nextPlayPos);
  18586. newBVE = newBVS + buffer.getNumSamples() - 4;
  18587. sectionToReadStart = 0;
  18588. sectionToReadEnd = 0;
  18589. const int maxChunkSize = 2048;
  18590. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18591. {
  18592. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18593. sectionToReadStart = newBVS;
  18594. sectionToReadEnd = newBVE;
  18595. bufferValidStart = 0;
  18596. bufferValidEnd = 0;
  18597. }
  18598. else if (abs (newBVS - bufferValidStart) > 512
  18599. || abs (newBVE - bufferValidEnd) > 512)
  18600. {
  18601. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18602. sectionToReadStart = bufferValidEnd;
  18603. sectionToReadEnd = newBVE;
  18604. bufferValidStart = newBVS;
  18605. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18606. }
  18607. }
  18608. if (sectionToReadStart != sectionToReadEnd)
  18609. {
  18610. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18611. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18612. if (bufferIndexStart < bufferIndexEnd)
  18613. {
  18614. readBufferSection (sectionToReadStart,
  18615. sectionToReadEnd - sectionToReadStart,
  18616. bufferIndexStart);
  18617. }
  18618. else
  18619. {
  18620. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18621. readBufferSection (sectionToReadStart,
  18622. initialSize,
  18623. bufferIndexStart);
  18624. readBufferSection (sectionToReadStart + initialSize,
  18625. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18626. 0);
  18627. }
  18628. const ScopedLock sl2 (bufferStartPosLock);
  18629. bufferValidStart = newBVS;
  18630. bufferValidEnd = newBVE;
  18631. return true;
  18632. }
  18633. else
  18634. {
  18635. return false;
  18636. }
  18637. }
  18638. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18639. {
  18640. if (source->getNextReadPosition() != start)
  18641. source->setNextReadPosition (start);
  18642. AudioSourceChannelInfo info;
  18643. info.buffer = &buffer;
  18644. info.startSample = bufferOffset;
  18645. info.numSamples = length;
  18646. source->getNextAudioBlock (info);
  18647. }
  18648. END_JUCE_NAMESPACE
  18649. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18650. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18651. BEGIN_JUCE_NAMESPACE
  18652. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18653. const bool deleteSourceWhenDeleted_)
  18654. : requiredNumberOfChannels (2),
  18655. source (source_),
  18656. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18657. buffer (2, 16)
  18658. {
  18659. remappedInfo.buffer = &buffer;
  18660. remappedInfo.startSample = 0;
  18661. }
  18662. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18663. {
  18664. if (deleteSourceWhenDeleted)
  18665. delete source;
  18666. }
  18667. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18668. {
  18669. const ScopedLock sl (lock);
  18670. requiredNumberOfChannels = requiredNumberOfChannels_;
  18671. }
  18672. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18673. {
  18674. const ScopedLock sl (lock);
  18675. remappedInputs.clear();
  18676. remappedOutputs.clear();
  18677. }
  18678. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18679. {
  18680. const ScopedLock sl (lock);
  18681. while (remappedInputs.size() < destIndex)
  18682. remappedInputs.add (-1);
  18683. remappedInputs.set (destIndex, sourceIndex);
  18684. }
  18685. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18686. {
  18687. const ScopedLock sl (lock);
  18688. while (remappedOutputs.size() < sourceIndex)
  18689. remappedOutputs.add (-1);
  18690. remappedOutputs.set (sourceIndex, destIndex);
  18691. }
  18692. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18693. {
  18694. const ScopedLock sl (lock);
  18695. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18696. return remappedInputs.getUnchecked (inputChannelIndex);
  18697. return -1;
  18698. }
  18699. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18700. {
  18701. const ScopedLock sl (lock);
  18702. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18703. return remappedOutputs .getUnchecked (outputChannelIndex);
  18704. return -1;
  18705. }
  18706. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18707. {
  18708. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18709. }
  18710. void ChannelRemappingAudioSource::releaseResources()
  18711. {
  18712. source->releaseResources();
  18713. }
  18714. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18715. {
  18716. const ScopedLock sl (lock);
  18717. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18718. const int numChans = bufferToFill.buffer->getNumChannels();
  18719. int i;
  18720. for (i = 0; i < buffer.getNumChannels(); ++i)
  18721. {
  18722. const int remappedChan = getRemappedInputChannel (i);
  18723. if (remappedChan >= 0 && remappedChan < numChans)
  18724. {
  18725. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18726. remappedChan,
  18727. bufferToFill.startSample,
  18728. bufferToFill.numSamples);
  18729. }
  18730. else
  18731. {
  18732. buffer.clear (i, 0, bufferToFill.numSamples);
  18733. }
  18734. }
  18735. remappedInfo.numSamples = bufferToFill.numSamples;
  18736. source->getNextAudioBlock (remappedInfo);
  18737. bufferToFill.clearActiveBufferRegion();
  18738. for (i = 0; i < requiredNumberOfChannels; ++i)
  18739. {
  18740. const int remappedChan = getRemappedOutputChannel (i);
  18741. if (remappedChan >= 0 && remappedChan < numChans)
  18742. {
  18743. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18744. buffer, i, 0, bufferToFill.numSamples);
  18745. }
  18746. }
  18747. }
  18748. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18749. {
  18750. XmlElement* e = new XmlElement ("MAPPINGS");
  18751. String ins, outs;
  18752. int i;
  18753. const ScopedLock sl (lock);
  18754. for (i = 0; i < remappedInputs.size(); ++i)
  18755. ins << remappedInputs.getUnchecked(i) << ' ';
  18756. for (i = 0; i < remappedOutputs.size(); ++i)
  18757. outs << remappedOutputs.getUnchecked(i) << ' ';
  18758. e->setAttribute ("inputs", ins.trimEnd());
  18759. e->setAttribute ("outputs", outs.trimEnd());
  18760. return e;
  18761. }
  18762. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18763. {
  18764. if (e.hasTagName ("MAPPINGS"))
  18765. {
  18766. const ScopedLock sl (lock);
  18767. clearAllMappings();
  18768. StringArray ins, outs;
  18769. ins.addTokens (e.getStringAttribute ("inputs"), false);
  18770. outs.addTokens (e.getStringAttribute ("outputs"), false);
  18771. int i;
  18772. for (i = 0; i < ins.size(); ++i)
  18773. remappedInputs.add (ins[i].getIntValue());
  18774. for (i = 0; i < outs.size(); ++i)
  18775. remappedOutputs.add (outs[i].getIntValue());
  18776. }
  18777. }
  18778. END_JUCE_NAMESPACE
  18779. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18780. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18781. BEGIN_JUCE_NAMESPACE
  18782. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18783. const bool deleteInputWhenDeleted_)
  18784. : input (inputSource),
  18785. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18786. {
  18787. jassert (inputSource != 0);
  18788. for (int i = 2; --i >= 0;)
  18789. iirFilters.add (new IIRFilter());
  18790. }
  18791. IIRFilterAudioSource::~IIRFilterAudioSource()
  18792. {
  18793. if (deleteInputWhenDeleted)
  18794. delete input;
  18795. }
  18796. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18797. {
  18798. for (int i = iirFilters.size(); --i >= 0;)
  18799. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18800. }
  18801. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18802. {
  18803. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18804. for (int i = iirFilters.size(); --i >= 0;)
  18805. iirFilters.getUnchecked(i)->reset();
  18806. }
  18807. void IIRFilterAudioSource::releaseResources()
  18808. {
  18809. input->releaseResources();
  18810. }
  18811. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18812. {
  18813. input->getNextAudioBlock (bufferToFill);
  18814. const int numChannels = bufferToFill.buffer->getNumChannels();
  18815. while (numChannels > iirFilters.size())
  18816. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18817. for (int i = 0; i < numChannels; ++i)
  18818. iirFilters.getUnchecked(i)
  18819. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18820. bufferToFill.numSamples);
  18821. }
  18822. END_JUCE_NAMESPACE
  18823. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18824. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18825. BEGIN_JUCE_NAMESPACE
  18826. MixerAudioSource::MixerAudioSource()
  18827. : tempBuffer (2, 0),
  18828. currentSampleRate (0.0),
  18829. bufferSizeExpected (0)
  18830. {
  18831. }
  18832. MixerAudioSource::~MixerAudioSource()
  18833. {
  18834. removeAllInputs();
  18835. }
  18836. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18837. {
  18838. if (input != 0 && ! inputs.contains (input))
  18839. {
  18840. double localRate;
  18841. int localBufferSize;
  18842. {
  18843. const ScopedLock sl (lock);
  18844. localRate = currentSampleRate;
  18845. localBufferSize = bufferSizeExpected;
  18846. }
  18847. if (localRate != 0.0)
  18848. input->prepareToPlay (localBufferSize, localRate);
  18849. const ScopedLock sl (lock);
  18850. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18851. inputs.add (input);
  18852. }
  18853. }
  18854. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18855. {
  18856. if (input != 0)
  18857. {
  18858. int index;
  18859. {
  18860. const ScopedLock sl (lock);
  18861. index = inputs.indexOf (input);
  18862. if (index >= 0)
  18863. {
  18864. inputsToDelete.shiftBits (index, 1);
  18865. inputs.remove (index);
  18866. }
  18867. }
  18868. if (index >= 0)
  18869. {
  18870. input->releaseResources();
  18871. if (deleteInput)
  18872. delete input;
  18873. }
  18874. }
  18875. }
  18876. void MixerAudioSource::removeAllInputs()
  18877. {
  18878. VoidArray inputsCopy;
  18879. BigInteger inputsToDeleteCopy;
  18880. {
  18881. const ScopedLock sl (lock);
  18882. inputsCopy = inputs;
  18883. inputsToDeleteCopy = inputsToDelete;
  18884. }
  18885. for (int i = inputsCopy.size(); --i >= 0;)
  18886. if (inputsToDeleteCopy[i])
  18887. delete (AudioSource*) inputsCopy[i];
  18888. }
  18889. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18890. {
  18891. tempBuffer.setSize (2, samplesPerBlockExpected);
  18892. const ScopedLock sl (lock);
  18893. currentSampleRate = sampleRate;
  18894. bufferSizeExpected = samplesPerBlockExpected;
  18895. for (int i = inputs.size(); --i >= 0;)
  18896. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18897. sampleRate);
  18898. }
  18899. void MixerAudioSource::releaseResources()
  18900. {
  18901. const ScopedLock sl (lock);
  18902. for (int i = inputs.size(); --i >= 0;)
  18903. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18904. tempBuffer.setSize (2, 0);
  18905. currentSampleRate = 0;
  18906. bufferSizeExpected = 0;
  18907. }
  18908. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18909. {
  18910. const ScopedLock sl (lock);
  18911. if (inputs.size() > 0)
  18912. {
  18913. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18914. if (inputs.size() > 1)
  18915. {
  18916. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18917. info.buffer->getNumSamples());
  18918. AudioSourceChannelInfo info2;
  18919. info2.buffer = &tempBuffer;
  18920. info2.numSamples = info.numSamples;
  18921. info2.startSample = 0;
  18922. for (int i = 1; i < inputs.size(); ++i)
  18923. {
  18924. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18925. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18926. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18927. }
  18928. }
  18929. }
  18930. else
  18931. {
  18932. info.clearActiveBufferRegion();
  18933. }
  18934. }
  18935. END_JUCE_NAMESPACE
  18936. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18937. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18938. BEGIN_JUCE_NAMESPACE
  18939. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18940. const bool deleteInputWhenDeleted_)
  18941. : input (inputSource),
  18942. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18943. ratio (1.0),
  18944. lastRatio (1.0),
  18945. buffer (2, 0),
  18946. sampsInBuffer (0)
  18947. {
  18948. jassert (input != 0);
  18949. }
  18950. ResamplingAudioSource::~ResamplingAudioSource()
  18951. {
  18952. if (deleteInputWhenDeleted)
  18953. delete input;
  18954. }
  18955. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18956. {
  18957. jassert (samplesInPerOutputSample > 0);
  18958. const ScopedLock sl (ratioLock);
  18959. ratio = jmax (0.0, samplesInPerOutputSample);
  18960. }
  18961. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18962. double sampleRate)
  18963. {
  18964. const ScopedLock sl (ratioLock);
  18965. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18966. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18967. buffer.clear();
  18968. sampsInBuffer = 0;
  18969. bufferPos = 0;
  18970. subSampleOffset = 0.0;
  18971. createLowPass (ratio);
  18972. resetFilters();
  18973. }
  18974. void ResamplingAudioSource::releaseResources()
  18975. {
  18976. input->releaseResources();
  18977. buffer.setSize (2, 0);
  18978. }
  18979. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18980. {
  18981. const ScopedLock sl (ratioLock);
  18982. if (lastRatio != ratio)
  18983. {
  18984. createLowPass (ratio);
  18985. lastRatio = ratio;
  18986. }
  18987. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  18988. int bufferSize = buffer.getNumSamples();
  18989. if (bufferSize < sampsNeeded + 8)
  18990. {
  18991. bufferPos %= bufferSize;
  18992. bufferSize = sampsNeeded + 32;
  18993. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  18994. }
  18995. bufferPos %= bufferSize;
  18996. int endOfBufferPos = bufferPos + sampsInBuffer;
  18997. while (sampsNeeded > sampsInBuffer)
  18998. {
  18999. endOfBufferPos %= bufferSize;
  19000. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19001. bufferSize - endOfBufferPos);
  19002. AudioSourceChannelInfo readInfo;
  19003. readInfo.buffer = &buffer;
  19004. readInfo.numSamples = numToDo;
  19005. readInfo.startSample = endOfBufferPos;
  19006. input->getNextAudioBlock (readInfo);
  19007. if (ratio > 1.0001)
  19008. {
  19009. // for down-sampling, pre-apply the filter..
  19010. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19011. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19012. }
  19013. sampsInBuffer += numToDo;
  19014. endOfBufferPos += numToDo;
  19015. }
  19016. float* dl = info.buffer->getSampleData (0, info.startSample);
  19017. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19018. const float* const bl = buffer.getSampleData (0, 0);
  19019. const float* const br = buffer.getSampleData (1, 0);
  19020. int nextPos = (bufferPos + 1) % bufferSize;
  19021. for (int m = info.numSamples; --m >= 0;)
  19022. {
  19023. const float alpha = (float) subSampleOffset;
  19024. const float invAlpha = 1.0f - alpha;
  19025. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19026. if (dr != 0)
  19027. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19028. subSampleOffset += ratio;
  19029. jassert (sampsInBuffer > 0);
  19030. while (subSampleOffset >= 1.0)
  19031. {
  19032. if (++bufferPos >= bufferSize)
  19033. bufferPos = 0;
  19034. --sampsInBuffer;
  19035. nextPos = (bufferPos + 1) % bufferSize;
  19036. subSampleOffset -= 1.0;
  19037. }
  19038. }
  19039. if (ratio < 0.9999)
  19040. {
  19041. // for up-sampling, apply the filter after transposing..
  19042. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19043. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19044. }
  19045. else if (ratio <= 1.0001)
  19046. {
  19047. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19048. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19049. {
  19050. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19051. FilterState& fs = filterStates[i];
  19052. if (info.numSamples > 1)
  19053. {
  19054. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19055. }
  19056. else
  19057. {
  19058. fs.y2 = fs.y1;
  19059. fs.x2 = fs.x1;
  19060. }
  19061. fs.y1 = fs.x1 = *endOfBuffer;
  19062. }
  19063. }
  19064. jassert (sampsInBuffer >= 0);
  19065. }
  19066. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19067. {
  19068. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19069. : 0.5 * frequencyRatio;
  19070. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19071. const double nSquared = n * n;
  19072. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19073. setFilterCoefficients (c1,
  19074. c1 * 2.0f,
  19075. c1,
  19076. 1.0,
  19077. c1 * 2.0 * (1.0 - nSquared),
  19078. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19079. }
  19080. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19081. {
  19082. const double a = 1.0 / c4;
  19083. c1 *= a;
  19084. c2 *= a;
  19085. c3 *= a;
  19086. c5 *= a;
  19087. c6 *= a;
  19088. coefficients[0] = c1;
  19089. coefficients[1] = c2;
  19090. coefficients[2] = c3;
  19091. coefficients[3] = c4;
  19092. coefficients[4] = c5;
  19093. coefficients[5] = c6;
  19094. }
  19095. void ResamplingAudioSource::resetFilters()
  19096. {
  19097. zeromem (filterStates, sizeof (filterStates));
  19098. }
  19099. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19100. {
  19101. while (--num >= 0)
  19102. {
  19103. const double in = *samples;
  19104. double out = coefficients[0] * in
  19105. + coefficients[1] * fs.x1
  19106. + coefficients[2] * fs.x2
  19107. - coefficients[4] * fs.y1
  19108. - coefficients[5] * fs.y2;
  19109. #if JUCE_INTEL
  19110. if (! (out < -1.0e-8 || out > 1.0e-8))
  19111. out = 0;
  19112. #endif
  19113. fs.x2 = fs.x1;
  19114. fs.x1 = in;
  19115. fs.y2 = fs.y1;
  19116. fs.y1 = out;
  19117. *samples++ = (float) out;
  19118. }
  19119. }
  19120. END_JUCE_NAMESPACE
  19121. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19122. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19123. BEGIN_JUCE_NAMESPACE
  19124. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19125. : frequency (1000.0),
  19126. sampleRate (44100.0),
  19127. currentPhase (0.0),
  19128. phasePerSample (0.0),
  19129. amplitude (0.5f)
  19130. {
  19131. }
  19132. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19133. {
  19134. }
  19135. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19136. {
  19137. amplitude = newAmplitude;
  19138. }
  19139. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19140. {
  19141. frequency = newFrequencyHz;
  19142. phasePerSample = 0.0;
  19143. }
  19144. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19145. double sampleRate_)
  19146. {
  19147. currentPhase = 0.0;
  19148. phasePerSample = 0.0;
  19149. sampleRate = sampleRate_;
  19150. }
  19151. void ToneGeneratorAudioSource::releaseResources()
  19152. {
  19153. }
  19154. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19155. {
  19156. if (phasePerSample == 0.0)
  19157. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19158. for (int i = 0; i < info.numSamples; ++i)
  19159. {
  19160. const float sample = amplitude * (float) sin (currentPhase);
  19161. currentPhase += phasePerSample;
  19162. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19163. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19164. }
  19165. }
  19166. END_JUCE_NAMESPACE
  19167. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19168. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19169. BEGIN_JUCE_NAMESPACE
  19170. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19171. : sampleRate (0),
  19172. bufferSize (0),
  19173. useDefaultInputChannels (true),
  19174. useDefaultOutputChannels (true)
  19175. {
  19176. }
  19177. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19178. {
  19179. return outputDeviceName == other.outputDeviceName
  19180. && inputDeviceName == other.inputDeviceName
  19181. && sampleRate == other.sampleRate
  19182. && bufferSize == other.bufferSize
  19183. && inputChannels == other.inputChannels
  19184. && useDefaultInputChannels == other.useDefaultInputChannels
  19185. && outputChannels == other.outputChannels
  19186. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19187. }
  19188. AudioDeviceManager::AudioDeviceManager()
  19189. : currentAudioDevice (0),
  19190. numInputChansNeeded (0),
  19191. numOutputChansNeeded (2),
  19192. listNeedsScanning (true),
  19193. useInputNames (false),
  19194. inputLevelMeasurementEnabledCount (0),
  19195. inputLevel (0),
  19196. tempBuffer (2, 2),
  19197. defaultMidiOutput (0),
  19198. cpuUsageMs (0),
  19199. timeToCpuScale (0)
  19200. {
  19201. callbackHandler.owner = this;
  19202. }
  19203. AudioDeviceManager::~AudioDeviceManager()
  19204. {
  19205. currentAudioDevice = 0;
  19206. defaultMidiOutput = 0;
  19207. }
  19208. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19209. {
  19210. if (availableDeviceTypes.size() == 0)
  19211. {
  19212. createAudioDeviceTypes (availableDeviceTypes);
  19213. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19214. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19215. if (availableDeviceTypes.size() > 0)
  19216. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19217. }
  19218. }
  19219. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19220. {
  19221. scanDevicesIfNeeded();
  19222. return availableDeviceTypes;
  19223. }
  19224. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19225. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19226. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19227. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19228. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19229. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19230. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19231. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19232. {
  19233. (void) list; // (to avoid 'unused param' warnings)
  19234. #if JUCE_WINDOWS
  19235. #if JUCE_WASAPI
  19236. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19237. list.add (juce_createAudioIODeviceType_WASAPI());
  19238. #endif
  19239. #if JUCE_DIRECTSOUND
  19240. list.add (juce_createAudioIODeviceType_DirectSound());
  19241. #endif
  19242. #if JUCE_ASIO
  19243. list.add (juce_createAudioIODeviceType_ASIO());
  19244. #endif
  19245. #endif
  19246. #if JUCE_MAC
  19247. list.add (juce_createAudioIODeviceType_CoreAudio());
  19248. #endif
  19249. #if JUCE_IPHONE
  19250. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19251. #endif
  19252. #if JUCE_LINUX && JUCE_ALSA
  19253. list.add (juce_createAudioIODeviceType_ALSA());
  19254. #endif
  19255. #if JUCE_LINUX && JUCE_JACK
  19256. list.add (juce_createAudioIODeviceType_JACK());
  19257. #endif
  19258. }
  19259. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19260. const int numOutputChannelsNeeded,
  19261. const XmlElement* const e,
  19262. const bool selectDefaultDeviceOnFailure,
  19263. const String& preferredDefaultDeviceName,
  19264. const AudioDeviceSetup* preferredSetupOptions)
  19265. {
  19266. scanDevicesIfNeeded();
  19267. numInputChansNeeded = numInputChannelsNeeded;
  19268. numOutputChansNeeded = numOutputChannelsNeeded;
  19269. if (e != 0 && e->hasTagName ("DEVICESETUP"))
  19270. {
  19271. lastExplicitSettings = new XmlElement (*e);
  19272. String error;
  19273. AudioDeviceSetup setup;
  19274. if (preferredSetupOptions != 0)
  19275. setup = *preferredSetupOptions;
  19276. if (e->getStringAttribute ("audioDeviceName").isNotEmpty())
  19277. {
  19278. setup.inputDeviceName = setup.outputDeviceName
  19279. = e->getStringAttribute ("audioDeviceName");
  19280. }
  19281. else
  19282. {
  19283. setup.inputDeviceName = e->getStringAttribute ("audioInputDeviceName");
  19284. setup.outputDeviceName = e->getStringAttribute ("audioOutputDeviceName");
  19285. }
  19286. currentDeviceType = e->getStringAttribute ("deviceType");
  19287. if (currentDeviceType.isEmpty())
  19288. {
  19289. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19290. if (type != 0)
  19291. currentDeviceType = type->getTypeName();
  19292. else if (availableDeviceTypes.size() > 0)
  19293. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19294. }
  19295. setup.bufferSize = e->getIntAttribute ("audioDeviceBufferSize");
  19296. setup.sampleRate = e->getDoubleAttribute ("audioDeviceRate");
  19297. setup.inputChannels.parseString (e->getStringAttribute ("audioDeviceInChans", "11"), 2);
  19298. setup.outputChannels.parseString (e->getStringAttribute ("audioDeviceOutChans", "11"), 2);
  19299. setup.useDefaultInputChannels = ! e->hasAttribute ("audioDeviceInChans");
  19300. setup.useDefaultOutputChannels = ! e->hasAttribute ("audioDeviceOutChans");
  19301. error = setAudioDeviceSetup (setup, true);
  19302. midiInsFromXml.clear();
  19303. forEachXmlChildElementWithTagName (*e, c, "MIDIINPUT")
  19304. midiInsFromXml.add (c->getStringAttribute ("name"));
  19305. const StringArray allMidiIns (MidiInput::getDevices());
  19306. for (int i = allMidiIns.size(); --i >= 0;)
  19307. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19308. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19309. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19310. false, preferredDefaultDeviceName);
  19311. setDefaultMidiOutput (e->getStringAttribute ("defaultMidiOutput"));
  19312. return error;
  19313. }
  19314. else
  19315. {
  19316. AudioDeviceSetup setup;
  19317. if (preferredSetupOptions != 0)
  19318. {
  19319. setup = *preferredSetupOptions;
  19320. }
  19321. else if (preferredDefaultDeviceName.isNotEmpty())
  19322. {
  19323. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19324. {
  19325. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19326. StringArray outs (type->getDeviceNames (false));
  19327. int i;
  19328. for (i = 0; i < outs.size(); ++i)
  19329. {
  19330. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19331. {
  19332. setup.outputDeviceName = outs[i];
  19333. break;
  19334. }
  19335. }
  19336. StringArray ins (type->getDeviceNames (true));
  19337. for (i = 0; i < ins.size(); ++i)
  19338. {
  19339. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19340. {
  19341. setup.inputDeviceName = ins[i];
  19342. break;
  19343. }
  19344. }
  19345. }
  19346. }
  19347. insertDefaultDeviceNames (setup);
  19348. return setAudioDeviceSetup (setup, false);
  19349. }
  19350. }
  19351. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19352. {
  19353. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19354. if (type != 0)
  19355. {
  19356. if (setup.outputDeviceName.isEmpty())
  19357. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19358. if (setup.inputDeviceName.isEmpty())
  19359. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19360. }
  19361. }
  19362. XmlElement* AudioDeviceManager::createStateXml() const
  19363. {
  19364. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19365. }
  19366. void AudioDeviceManager::scanDevicesIfNeeded()
  19367. {
  19368. if (listNeedsScanning)
  19369. {
  19370. listNeedsScanning = false;
  19371. createDeviceTypesIfNeeded();
  19372. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19373. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19374. }
  19375. }
  19376. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19377. {
  19378. scanDevicesIfNeeded();
  19379. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19380. {
  19381. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19382. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19383. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19384. {
  19385. return type;
  19386. }
  19387. }
  19388. return 0;
  19389. }
  19390. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19391. {
  19392. setup = currentSetup;
  19393. }
  19394. void AudioDeviceManager::deleteCurrentDevice()
  19395. {
  19396. currentAudioDevice = 0;
  19397. currentSetup.inputDeviceName = String::empty;
  19398. currentSetup.outputDeviceName = String::empty;
  19399. }
  19400. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19401. const bool treatAsChosenDevice)
  19402. {
  19403. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19404. {
  19405. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19406. && currentDeviceType != type)
  19407. {
  19408. currentDeviceType = type;
  19409. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19410. insertDefaultDeviceNames (s);
  19411. setAudioDeviceSetup (s, treatAsChosenDevice);
  19412. sendChangeMessage (this);
  19413. break;
  19414. }
  19415. }
  19416. }
  19417. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19418. {
  19419. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19420. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19421. return availableDeviceTypes[i];
  19422. return availableDeviceTypes[0];
  19423. }
  19424. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19425. const bool treatAsChosenDevice)
  19426. {
  19427. jassert (&newSetup != &currentSetup); // this will have no effect
  19428. if (newSetup == currentSetup && currentAudioDevice != 0)
  19429. return String::empty;
  19430. if (! (newSetup == currentSetup))
  19431. sendChangeMessage (this);
  19432. stopDevice();
  19433. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19434. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19435. String error;
  19436. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19437. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19438. {
  19439. deleteCurrentDevice();
  19440. if (treatAsChosenDevice)
  19441. updateXml();
  19442. return String::empty;
  19443. }
  19444. if (currentSetup.inputDeviceName != newInputDeviceName
  19445. || currentSetup.outputDeviceName != newOutputDeviceName
  19446. || currentAudioDevice == 0)
  19447. {
  19448. deleteCurrentDevice();
  19449. scanDevicesIfNeeded();
  19450. if (newOutputDeviceName.isNotEmpty()
  19451. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19452. {
  19453. return "No such device: " + newOutputDeviceName;
  19454. }
  19455. if (newInputDeviceName.isNotEmpty()
  19456. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19457. {
  19458. return "No such device: " + newInputDeviceName;
  19459. }
  19460. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19461. if (currentAudioDevice == 0)
  19462. 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!";
  19463. else
  19464. error = currentAudioDevice->getLastError();
  19465. if (error.isNotEmpty())
  19466. {
  19467. deleteCurrentDevice();
  19468. return error;
  19469. }
  19470. if (newSetup.useDefaultInputChannels)
  19471. {
  19472. inputChannels.clear();
  19473. inputChannels.setRange (0, numInputChansNeeded, true);
  19474. }
  19475. if (newSetup.useDefaultOutputChannels)
  19476. {
  19477. outputChannels.clear();
  19478. outputChannels.setRange (0, numOutputChansNeeded, true);
  19479. }
  19480. if (newInputDeviceName.isEmpty())
  19481. inputChannels.clear();
  19482. if (newOutputDeviceName.isEmpty())
  19483. outputChannels.clear();
  19484. }
  19485. if (! newSetup.useDefaultInputChannels)
  19486. inputChannels = newSetup.inputChannels;
  19487. if (! newSetup.useDefaultOutputChannels)
  19488. outputChannels = newSetup.outputChannels;
  19489. currentSetup = newSetup;
  19490. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19491. error = currentAudioDevice->open (inputChannels,
  19492. outputChannels,
  19493. currentSetup.sampleRate,
  19494. currentSetup.bufferSize);
  19495. if (error.isEmpty())
  19496. {
  19497. currentDeviceType = currentAudioDevice->getTypeName();
  19498. currentAudioDevice->start (&callbackHandler);
  19499. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19500. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19501. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19502. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19503. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19504. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19505. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19506. if (treatAsChosenDevice)
  19507. updateXml();
  19508. }
  19509. else
  19510. {
  19511. deleteCurrentDevice();
  19512. }
  19513. return error;
  19514. }
  19515. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19516. {
  19517. jassert (currentAudioDevice != 0);
  19518. if (rate > 0)
  19519. {
  19520. bool ok = false;
  19521. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19522. {
  19523. const double sr = currentAudioDevice->getSampleRate (i);
  19524. if (sr == rate)
  19525. ok = true;
  19526. }
  19527. if (! ok)
  19528. rate = 0;
  19529. }
  19530. if (rate == 0)
  19531. {
  19532. double lowestAbove44 = 0.0;
  19533. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19534. {
  19535. const double sr = currentAudioDevice->getSampleRate (i);
  19536. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19537. lowestAbove44 = sr;
  19538. }
  19539. if (lowestAbove44 == 0.0)
  19540. rate = currentAudioDevice->getSampleRate (0);
  19541. else
  19542. rate = lowestAbove44;
  19543. }
  19544. return rate;
  19545. }
  19546. void AudioDeviceManager::stopDevice()
  19547. {
  19548. if (currentAudioDevice != 0)
  19549. currentAudioDevice->stop();
  19550. testSound = 0;
  19551. }
  19552. void AudioDeviceManager::closeAudioDevice()
  19553. {
  19554. stopDevice();
  19555. currentAudioDevice = 0;
  19556. }
  19557. void AudioDeviceManager::restartLastAudioDevice()
  19558. {
  19559. if (currentAudioDevice == 0)
  19560. {
  19561. if (currentSetup.inputDeviceName.isEmpty()
  19562. && currentSetup.outputDeviceName.isEmpty())
  19563. {
  19564. // This method will only reload the last device that was running
  19565. // before closeAudioDevice() was called - you need to actually open
  19566. // one first, with setAudioDevice().
  19567. jassertfalse
  19568. return;
  19569. }
  19570. AudioDeviceSetup s (currentSetup);
  19571. setAudioDeviceSetup (s, false);
  19572. }
  19573. }
  19574. void AudioDeviceManager::updateXml()
  19575. {
  19576. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19577. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19578. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19579. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19580. if (currentAudioDevice != 0)
  19581. {
  19582. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19583. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19584. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19585. if (! currentSetup.useDefaultInputChannels)
  19586. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19587. if (! currentSetup.useDefaultOutputChannels)
  19588. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19589. }
  19590. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19591. {
  19592. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19593. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19594. }
  19595. if (midiInsFromXml.size() > 0)
  19596. {
  19597. // Add any midi devices that have been enabled before, but which aren't currently
  19598. // open because the device has been disconnected.
  19599. const StringArray availableMidiDevices (MidiInput::getDevices());
  19600. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19601. {
  19602. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19603. {
  19604. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19605. m->setAttribute ("name", midiInsFromXml[i]);
  19606. }
  19607. }
  19608. }
  19609. if (defaultMidiOutputName.isNotEmpty())
  19610. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19611. }
  19612. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19613. {
  19614. {
  19615. const ScopedLock sl (audioCallbackLock);
  19616. if (callbacks.contains (newCallback))
  19617. return;
  19618. }
  19619. if (currentAudioDevice != 0 && newCallback != 0)
  19620. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19621. const ScopedLock sl (audioCallbackLock);
  19622. callbacks.add (newCallback);
  19623. }
  19624. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19625. {
  19626. if (callback != 0)
  19627. {
  19628. bool needsDeinitialising = currentAudioDevice != 0;
  19629. {
  19630. const ScopedLock sl (audioCallbackLock);
  19631. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19632. callbacks.removeValue (callback);
  19633. }
  19634. if (needsDeinitialising)
  19635. callback->audioDeviceStopped();
  19636. }
  19637. }
  19638. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19639. int numInputChannels,
  19640. float** outputChannelData,
  19641. int numOutputChannels,
  19642. int numSamples)
  19643. {
  19644. const ScopedLock sl (audioCallbackLock);
  19645. if (inputLevelMeasurementEnabledCount > 0)
  19646. {
  19647. for (int j = 0; j < numSamples; ++j)
  19648. {
  19649. float s = 0;
  19650. for (int i = 0; i < numInputChannels; ++i)
  19651. s += fabsf (inputChannelData[i][j]);
  19652. s /= numInputChannels;
  19653. const double decayFactor = 0.99992;
  19654. if (s > inputLevel)
  19655. inputLevel = s;
  19656. else if (inputLevel > 0.001f)
  19657. inputLevel *= decayFactor;
  19658. else
  19659. inputLevel = 0;
  19660. }
  19661. }
  19662. if (callbacks.size() > 0)
  19663. {
  19664. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19665. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19666. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19667. outputChannelData, numOutputChannels, numSamples);
  19668. float** const tempChans = tempBuffer.getArrayOfChannels();
  19669. for (int i = callbacks.size(); --i > 0;)
  19670. {
  19671. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19672. tempChans, numOutputChannels, numSamples);
  19673. for (int chan = 0; chan < numOutputChannels; ++chan)
  19674. {
  19675. const float* const src = tempChans [chan];
  19676. float* const dst = outputChannelData [chan];
  19677. if (src != 0 && dst != 0)
  19678. for (int j = 0; j < numSamples; ++j)
  19679. dst[j] += src[j];
  19680. }
  19681. }
  19682. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19683. const double filterAmount = 0.2;
  19684. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19685. }
  19686. else
  19687. {
  19688. for (int i = 0; i < numOutputChannels; ++i)
  19689. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19690. }
  19691. if (testSound != 0)
  19692. {
  19693. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19694. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19695. for (int i = 0; i < numOutputChannels; ++i)
  19696. for (int j = 0; j < numSamps; ++j)
  19697. outputChannelData [i][j] += src[j];
  19698. testSoundPosition += numSamps;
  19699. if (testSoundPosition >= testSound->getNumSamples())
  19700. testSound = 0;
  19701. }
  19702. }
  19703. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19704. {
  19705. cpuUsageMs = 0;
  19706. const double sampleRate = device->getCurrentSampleRate();
  19707. const int blockSize = device->getCurrentBufferSizeSamples();
  19708. if (sampleRate > 0.0 && blockSize > 0)
  19709. {
  19710. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19711. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19712. }
  19713. {
  19714. const ScopedLock sl (audioCallbackLock);
  19715. for (int i = callbacks.size(); --i >= 0;)
  19716. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19717. }
  19718. sendChangeMessage (this);
  19719. }
  19720. void AudioDeviceManager::audioDeviceStoppedInt()
  19721. {
  19722. cpuUsageMs = 0;
  19723. timeToCpuScale = 0;
  19724. sendChangeMessage (this);
  19725. const ScopedLock sl (audioCallbackLock);
  19726. for (int i = callbacks.size(); --i >= 0;)
  19727. callbacks.getUnchecked(i)->audioDeviceStopped();
  19728. }
  19729. double AudioDeviceManager::getCpuUsage() const
  19730. {
  19731. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19732. }
  19733. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19734. const bool enabled)
  19735. {
  19736. if (enabled != isMidiInputEnabled (name))
  19737. {
  19738. if (enabled)
  19739. {
  19740. const int index = MidiInput::getDevices().indexOf (name);
  19741. if (index >= 0)
  19742. {
  19743. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19744. if (min != 0)
  19745. {
  19746. enabledMidiInputs.add (min);
  19747. min->start();
  19748. }
  19749. }
  19750. }
  19751. else
  19752. {
  19753. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19754. if (enabledMidiInputs[i]->getName() == name)
  19755. enabledMidiInputs.remove (i);
  19756. }
  19757. updateXml();
  19758. sendChangeMessage (this);
  19759. }
  19760. }
  19761. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19762. {
  19763. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19764. if (enabledMidiInputs[i]->getName() == name)
  19765. return true;
  19766. return false;
  19767. }
  19768. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19769. MidiInputCallback* callback)
  19770. {
  19771. removeMidiInputCallback (name, callback);
  19772. if (name.isEmpty())
  19773. {
  19774. midiCallbacks.add (callback);
  19775. midiCallbackDevices.add (0);
  19776. }
  19777. else
  19778. {
  19779. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19780. {
  19781. if (enabledMidiInputs[i]->getName() == name)
  19782. {
  19783. const ScopedLock sl (midiCallbackLock);
  19784. midiCallbacks.add (callback);
  19785. midiCallbackDevices.add (enabledMidiInputs[i]);
  19786. break;
  19787. }
  19788. }
  19789. }
  19790. }
  19791. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19792. MidiInputCallback* /*callback*/)
  19793. {
  19794. const ScopedLock sl (midiCallbackLock);
  19795. for (int i = midiCallbacks.size(); --i >= 0;)
  19796. {
  19797. String devName;
  19798. if (midiCallbackDevices.getUnchecked(i) != 0)
  19799. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19800. if (devName == name)
  19801. {
  19802. midiCallbacks.remove (i);
  19803. midiCallbackDevices.remove (i);
  19804. }
  19805. }
  19806. }
  19807. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19808. const MidiMessage& message)
  19809. {
  19810. if (! message.isActiveSense())
  19811. {
  19812. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19813. const ScopedLock sl (midiCallbackLock);
  19814. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19815. {
  19816. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19817. if (md == source || (md == 0 && isDefaultSource))
  19818. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19819. }
  19820. }
  19821. }
  19822. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19823. {
  19824. if (defaultMidiOutputName != deviceName)
  19825. {
  19826. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19827. {
  19828. const ScopedLock sl (audioCallbackLock);
  19829. oldCallbacks = callbacks;
  19830. callbacks.clear();
  19831. }
  19832. if (currentAudioDevice != 0)
  19833. for (int i = oldCallbacks.size(); --i >= 0;)
  19834. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19835. defaultMidiOutput = 0;
  19836. defaultMidiOutputName = deviceName;
  19837. if (deviceName.isNotEmpty())
  19838. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19839. if (currentAudioDevice != 0)
  19840. for (int i = oldCallbacks.size(); --i >= 0;)
  19841. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19842. {
  19843. const ScopedLock sl (audioCallbackLock);
  19844. callbacks = oldCallbacks;
  19845. }
  19846. updateXml();
  19847. sendChangeMessage (this);
  19848. }
  19849. }
  19850. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19851. int numInputChannels,
  19852. float** outputChannelData,
  19853. int numOutputChannels,
  19854. int numSamples)
  19855. {
  19856. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19857. }
  19858. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19859. {
  19860. owner->audioDeviceAboutToStartInt (device);
  19861. }
  19862. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19863. {
  19864. owner->audioDeviceStoppedInt();
  19865. }
  19866. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19867. {
  19868. owner->handleIncomingMidiMessageInt (source, message);
  19869. }
  19870. void AudioDeviceManager::playTestSound()
  19871. {
  19872. { // cunningly nested to swap, unlock and delete in that order.
  19873. ScopedPointer <AudioSampleBuffer> oldSound;
  19874. {
  19875. const ScopedLock sl (audioCallbackLock);
  19876. oldSound = testSound;
  19877. }
  19878. }
  19879. testSoundPosition = 0;
  19880. if (currentAudioDevice != 0)
  19881. {
  19882. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19883. const int soundLength = (int) sampleRate;
  19884. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19885. float* samples = newSound->getSampleData (0);
  19886. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19887. const float amplitude = 0.5f;
  19888. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19889. for (int i = 0; i < soundLength; ++i)
  19890. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19891. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19892. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19893. const ScopedLock sl (audioCallbackLock);
  19894. testSound = newSound;
  19895. }
  19896. }
  19897. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19898. {
  19899. const ScopedLock sl (audioCallbackLock);
  19900. if (enableMeasurement)
  19901. ++inputLevelMeasurementEnabledCount;
  19902. else
  19903. --inputLevelMeasurementEnabledCount;
  19904. inputLevel = 0;
  19905. }
  19906. double AudioDeviceManager::getCurrentInputLevel() const
  19907. {
  19908. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19909. return inputLevel;
  19910. }
  19911. END_JUCE_NAMESPACE
  19912. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19913. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19914. BEGIN_JUCE_NAMESPACE
  19915. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19916. : name (deviceName),
  19917. typeName (typeName_)
  19918. {
  19919. }
  19920. AudioIODevice::~AudioIODevice()
  19921. {
  19922. }
  19923. bool AudioIODevice::hasControlPanel() const
  19924. {
  19925. return false;
  19926. }
  19927. bool AudioIODevice::showControlPanel()
  19928. {
  19929. jassertfalse // this should only be called for devices which return true from
  19930. // their hasControlPanel() method.
  19931. return false;
  19932. }
  19933. END_JUCE_NAMESPACE
  19934. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19935. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19936. BEGIN_JUCE_NAMESPACE
  19937. AudioIODeviceType::AudioIODeviceType (const String& name)
  19938. : typeName (name)
  19939. {
  19940. }
  19941. AudioIODeviceType::~AudioIODeviceType()
  19942. {
  19943. }
  19944. END_JUCE_NAMESPACE
  19945. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19946. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19947. BEGIN_JUCE_NAMESPACE
  19948. MidiOutput::MidiOutput()
  19949. : Thread ("midi out"),
  19950. internal (0),
  19951. firstMessage (0)
  19952. {
  19953. }
  19954. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19955. const double sampleNumber)
  19956. : message (data, len, sampleNumber)
  19957. {
  19958. }
  19959. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19960. const double millisecondCounterToStartAt,
  19961. double samplesPerSecondForBuffer)
  19962. {
  19963. // You've got to call startBackgroundThread() for this to actually work..
  19964. jassert (isThreadRunning());
  19965. // this needs to be a value in the future - RTFM for this method!
  19966. jassert (millisecondCounterToStartAt > 0);
  19967. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19968. MidiBuffer::Iterator i (buffer);
  19969. const uint8* data;
  19970. int len, time;
  19971. while (i.getNextEvent (data, len, time))
  19972. {
  19973. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19974. PendingMessage* const m
  19975. = new PendingMessage (data, len, eventTime);
  19976. const ScopedLock sl (lock);
  19977. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19978. {
  19979. m->next = firstMessage;
  19980. firstMessage = m;
  19981. }
  19982. else
  19983. {
  19984. PendingMessage* mm = firstMessage;
  19985. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19986. mm = mm->next;
  19987. m->next = mm->next;
  19988. mm->next = m;
  19989. }
  19990. }
  19991. notify();
  19992. }
  19993. void MidiOutput::clearAllPendingMessages()
  19994. {
  19995. const ScopedLock sl (lock);
  19996. while (firstMessage != 0)
  19997. {
  19998. PendingMessage* const m = firstMessage;
  19999. firstMessage = firstMessage->next;
  20000. delete m;
  20001. }
  20002. }
  20003. void MidiOutput::startBackgroundThread()
  20004. {
  20005. startThread (9);
  20006. }
  20007. void MidiOutput::stopBackgroundThread()
  20008. {
  20009. stopThread (5000);
  20010. }
  20011. void MidiOutput::run()
  20012. {
  20013. while (! threadShouldExit())
  20014. {
  20015. uint32 now = Time::getMillisecondCounter();
  20016. uint32 eventTime = 0;
  20017. uint32 timeToWait = 500;
  20018. PendingMessage* message;
  20019. {
  20020. const ScopedLock sl (lock);
  20021. message = firstMessage;
  20022. if (message != 0)
  20023. {
  20024. eventTime = roundToInt (message->message.getTimeStamp());
  20025. if (eventTime > now + 20)
  20026. {
  20027. timeToWait = eventTime - (now + 20);
  20028. message = 0;
  20029. }
  20030. else
  20031. {
  20032. firstMessage = message->next;
  20033. }
  20034. }
  20035. }
  20036. if (message != 0)
  20037. {
  20038. if (eventTime > now)
  20039. {
  20040. Time::waitForMillisecondCounter (eventTime);
  20041. if (threadShouldExit())
  20042. break;
  20043. }
  20044. if (eventTime > now - 200)
  20045. sendMessageNow (message->message);
  20046. delete message;
  20047. }
  20048. else
  20049. {
  20050. jassert (timeToWait < 1000 * 30);
  20051. wait (timeToWait);
  20052. }
  20053. }
  20054. clearAllPendingMessages();
  20055. }
  20056. END_JUCE_NAMESPACE
  20057. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20058. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20059. BEGIN_JUCE_NAMESPACE
  20060. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20061. {
  20062. const double maxVal = (double) 0x7fff;
  20063. char* intData = static_cast <char*> (dest);
  20064. if (dest != (void*) source || destBytesPerSample <= 4)
  20065. {
  20066. for (int i = 0; i < numSamples; ++i)
  20067. {
  20068. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20069. intData += destBytesPerSample;
  20070. }
  20071. }
  20072. else
  20073. {
  20074. intData += destBytesPerSample * numSamples;
  20075. for (int i = numSamples; --i >= 0;)
  20076. {
  20077. intData -= destBytesPerSample;
  20078. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20079. }
  20080. }
  20081. }
  20082. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20083. {
  20084. const double maxVal = (double) 0x7fff;
  20085. char* intData = static_cast <char*> (dest);
  20086. if (dest != (void*) source || destBytesPerSample <= 4)
  20087. {
  20088. for (int i = 0; i < numSamples; ++i)
  20089. {
  20090. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20091. intData += destBytesPerSample;
  20092. }
  20093. }
  20094. else
  20095. {
  20096. intData += destBytesPerSample * numSamples;
  20097. for (int i = numSamples; --i >= 0;)
  20098. {
  20099. intData -= destBytesPerSample;
  20100. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20101. }
  20102. }
  20103. }
  20104. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20105. {
  20106. const double maxVal = (double) 0x7fffff;
  20107. char* intData = static_cast <char*> (dest);
  20108. if (dest != (void*) source || destBytesPerSample <= 4)
  20109. {
  20110. for (int i = 0; i < numSamples; ++i)
  20111. {
  20112. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20113. intData += destBytesPerSample;
  20114. }
  20115. }
  20116. else
  20117. {
  20118. intData += destBytesPerSample * numSamples;
  20119. for (int i = numSamples; --i >= 0;)
  20120. {
  20121. intData -= destBytesPerSample;
  20122. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20123. }
  20124. }
  20125. }
  20126. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20127. {
  20128. const double maxVal = (double) 0x7fffff;
  20129. char* intData = static_cast <char*> (dest);
  20130. if (dest != (void*) source || destBytesPerSample <= 4)
  20131. {
  20132. for (int i = 0; i < numSamples; ++i)
  20133. {
  20134. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20135. intData += destBytesPerSample;
  20136. }
  20137. }
  20138. else
  20139. {
  20140. intData += destBytesPerSample * numSamples;
  20141. for (int i = numSamples; --i >= 0;)
  20142. {
  20143. intData -= destBytesPerSample;
  20144. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20145. }
  20146. }
  20147. }
  20148. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20149. {
  20150. const double maxVal = (double) 0x7fffffff;
  20151. char* intData = static_cast <char*> (dest);
  20152. if (dest != (void*) source || destBytesPerSample <= 4)
  20153. {
  20154. for (int i = 0; i < numSamples; ++i)
  20155. {
  20156. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20157. intData += destBytesPerSample;
  20158. }
  20159. }
  20160. else
  20161. {
  20162. intData += destBytesPerSample * numSamples;
  20163. for (int i = numSamples; --i >= 0;)
  20164. {
  20165. intData -= destBytesPerSample;
  20166. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20167. }
  20168. }
  20169. }
  20170. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20171. {
  20172. const double maxVal = (double) 0x7fffffff;
  20173. char* intData = static_cast <char*> (dest);
  20174. if (dest != (void*) source || destBytesPerSample <= 4)
  20175. {
  20176. for (int i = 0; i < numSamples; ++i)
  20177. {
  20178. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20179. intData += destBytesPerSample;
  20180. }
  20181. }
  20182. else
  20183. {
  20184. intData += destBytesPerSample * numSamples;
  20185. for (int i = numSamples; --i >= 0;)
  20186. {
  20187. intData -= destBytesPerSample;
  20188. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20189. }
  20190. }
  20191. }
  20192. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20193. {
  20194. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20195. char* d = static_cast <char*> (dest);
  20196. for (int i = 0; i < numSamples; ++i)
  20197. {
  20198. *(float*) d = source[i];
  20199. #if JUCE_BIG_ENDIAN
  20200. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20201. #endif
  20202. d += destBytesPerSample;
  20203. }
  20204. }
  20205. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20206. {
  20207. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20208. char* d = static_cast <char*> (dest);
  20209. for (int i = 0; i < numSamples; ++i)
  20210. {
  20211. *(float*) d = source[i];
  20212. #if JUCE_LITTLE_ENDIAN
  20213. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20214. #endif
  20215. d += destBytesPerSample;
  20216. }
  20217. }
  20218. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20219. {
  20220. const float scale = 1.0f / 0x7fff;
  20221. const char* intData = static_cast <const char*> (source);
  20222. if (source != (void*) dest || srcBytesPerSample >= 4)
  20223. {
  20224. for (int i = 0; i < numSamples; ++i)
  20225. {
  20226. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20227. intData += srcBytesPerSample;
  20228. }
  20229. }
  20230. else
  20231. {
  20232. intData += srcBytesPerSample * numSamples;
  20233. for (int i = numSamples; --i >= 0;)
  20234. {
  20235. intData -= srcBytesPerSample;
  20236. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20237. }
  20238. }
  20239. }
  20240. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20241. {
  20242. const float scale = 1.0f / 0x7fff;
  20243. const char* intData = static_cast <const char*> (source);
  20244. if (source != (void*) dest || srcBytesPerSample >= 4)
  20245. {
  20246. for (int i = 0; i < numSamples; ++i)
  20247. {
  20248. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20249. intData += srcBytesPerSample;
  20250. }
  20251. }
  20252. else
  20253. {
  20254. intData += srcBytesPerSample * numSamples;
  20255. for (int i = numSamples; --i >= 0;)
  20256. {
  20257. intData -= srcBytesPerSample;
  20258. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20259. }
  20260. }
  20261. }
  20262. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20263. {
  20264. const float scale = 1.0f / 0x7fffff;
  20265. const char* intData = static_cast <const char*> (source);
  20266. if (source != (void*) dest || srcBytesPerSample >= 4)
  20267. {
  20268. for (int i = 0; i < numSamples; ++i)
  20269. {
  20270. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20271. intData += srcBytesPerSample;
  20272. }
  20273. }
  20274. else
  20275. {
  20276. intData += srcBytesPerSample * numSamples;
  20277. for (int i = numSamples; --i >= 0;)
  20278. {
  20279. intData -= srcBytesPerSample;
  20280. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20281. }
  20282. }
  20283. }
  20284. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20285. {
  20286. const float scale = 1.0f / 0x7fffff;
  20287. const char* intData = static_cast <const char*> (source);
  20288. if (source != (void*) dest || srcBytesPerSample >= 4)
  20289. {
  20290. for (int i = 0; i < numSamples; ++i)
  20291. {
  20292. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20293. intData += srcBytesPerSample;
  20294. }
  20295. }
  20296. else
  20297. {
  20298. intData += srcBytesPerSample * numSamples;
  20299. for (int i = numSamples; --i >= 0;)
  20300. {
  20301. intData -= srcBytesPerSample;
  20302. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20303. }
  20304. }
  20305. }
  20306. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20307. {
  20308. const float scale = 1.0f / 0x7fffffff;
  20309. const char* intData = static_cast <const char*> (source);
  20310. if (source != (void*) dest || srcBytesPerSample >= 4)
  20311. {
  20312. for (int i = 0; i < numSamples; ++i)
  20313. {
  20314. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20315. intData += srcBytesPerSample;
  20316. }
  20317. }
  20318. else
  20319. {
  20320. intData += srcBytesPerSample * numSamples;
  20321. for (int i = numSamples; --i >= 0;)
  20322. {
  20323. intData -= srcBytesPerSample;
  20324. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20325. }
  20326. }
  20327. }
  20328. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20329. {
  20330. const float scale = 1.0f / 0x7fffffff;
  20331. const char* intData = static_cast <const char*> (source);
  20332. if (source != (void*) dest || srcBytesPerSample >= 4)
  20333. {
  20334. for (int i = 0; i < numSamples; ++i)
  20335. {
  20336. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20337. intData += srcBytesPerSample;
  20338. }
  20339. }
  20340. else
  20341. {
  20342. intData += srcBytesPerSample * numSamples;
  20343. for (int i = numSamples; --i >= 0;)
  20344. {
  20345. intData -= srcBytesPerSample;
  20346. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20347. }
  20348. }
  20349. }
  20350. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20351. {
  20352. const char* s = static_cast <const char*> (source);
  20353. for (int i = 0; i < numSamples; ++i)
  20354. {
  20355. dest[i] = *(float*)s;
  20356. #if JUCE_BIG_ENDIAN
  20357. uint32* const d = (uint32*) (dest + i);
  20358. *d = ByteOrder::swap (*d);
  20359. #endif
  20360. s += srcBytesPerSample;
  20361. }
  20362. }
  20363. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20364. {
  20365. const char* s = static_cast <const char*> (source);
  20366. for (int i = 0; i < numSamples; ++i)
  20367. {
  20368. dest[i] = *(float*)s;
  20369. #if JUCE_LITTLE_ENDIAN
  20370. uint32* const d = (uint32*) (dest + i);
  20371. *d = ByteOrder::swap (*d);
  20372. #endif
  20373. s += srcBytesPerSample;
  20374. }
  20375. }
  20376. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20377. const float* const source,
  20378. void* const dest,
  20379. const int numSamples)
  20380. {
  20381. switch (destFormat)
  20382. {
  20383. case int16LE:
  20384. convertFloatToInt16LE (source, dest, numSamples);
  20385. break;
  20386. case int16BE:
  20387. convertFloatToInt16BE (source, dest, numSamples);
  20388. break;
  20389. case int24LE:
  20390. convertFloatToInt24LE (source, dest, numSamples);
  20391. break;
  20392. case int24BE:
  20393. convertFloatToInt24BE (source, dest, numSamples);
  20394. break;
  20395. case int32LE:
  20396. convertFloatToInt32LE (source, dest, numSamples);
  20397. break;
  20398. case int32BE:
  20399. convertFloatToInt32BE (source, dest, numSamples);
  20400. break;
  20401. case float32LE:
  20402. convertFloatToFloat32LE (source, dest, numSamples);
  20403. break;
  20404. case float32BE:
  20405. convertFloatToFloat32BE (source, dest, numSamples);
  20406. break;
  20407. default:
  20408. jassertfalse
  20409. break;
  20410. }
  20411. }
  20412. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20413. const void* const source,
  20414. float* const dest,
  20415. const int numSamples)
  20416. {
  20417. switch (sourceFormat)
  20418. {
  20419. case int16LE:
  20420. convertInt16LEToFloat (source, dest, numSamples);
  20421. break;
  20422. case int16BE:
  20423. convertInt16BEToFloat (source, dest, numSamples);
  20424. break;
  20425. case int24LE:
  20426. convertInt24LEToFloat (source, dest, numSamples);
  20427. break;
  20428. case int24BE:
  20429. convertInt24BEToFloat (source, dest, numSamples);
  20430. break;
  20431. case int32LE:
  20432. convertInt32LEToFloat (source, dest, numSamples);
  20433. break;
  20434. case int32BE:
  20435. convertInt32BEToFloat (source, dest, numSamples);
  20436. break;
  20437. case float32LE:
  20438. convertFloat32LEToFloat (source, dest, numSamples);
  20439. break;
  20440. case float32BE:
  20441. convertFloat32BEToFloat (source, dest, numSamples);
  20442. break;
  20443. default:
  20444. jassertfalse
  20445. break;
  20446. }
  20447. }
  20448. void AudioDataConverters::interleaveSamples (const float** const source,
  20449. float* const dest,
  20450. const int numSamples,
  20451. const int numChannels)
  20452. {
  20453. for (int chan = 0; chan < numChannels; ++chan)
  20454. {
  20455. int i = chan;
  20456. const float* src = source [chan];
  20457. for (int j = 0; j < numSamples; ++j)
  20458. {
  20459. dest [i] = src [j];
  20460. i += numChannels;
  20461. }
  20462. }
  20463. }
  20464. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20465. float** const dest,
  20466. const int numSamples,
  20467. const int numChannels)
  20468. {
  20469. for (int chan = 0; chan < numChannels; ++chan)
  20470. {
  20471. int i = chan;
  20472. float* dst = dest [chan];
  20473. for (int j = 0; j < numSamples; ++j)
  20474. {
  20475. dst [j] = source [i];
  20476. i += numChannels;
  20477. }
  20478. }
  20479. }
  20480. END_JUCE_NAMESPACE
  20481. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20482. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20483. BEGIN_JUCE_NAMESPACE
  20484. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20485. const int numSamples) throw()
  20486. : numChannels (numChannels_),
  20487. size (numSamples)
  20488. {
  20489. jassert (numSamples >= 0);
  20490. jassert (numChannels_ > 0);
  20491. allocateData();
  20492. }
  20493. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20494. : numChannels (other.numChannels),
  20495. size (other.size)
  20496. {
  20497. allocateData();
  20498. const size_t numBytes = size * sizeof (float);
  20499. for (int i = 0; i < numChannels; ++i)
  20500. memcpy (channels[i], other.channels[i], numBytes);
  20501. }
  20502. void AudioSampleBuffer::allocateData()
  20503. {
  20504. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20505. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20506. allocatedData.malloc (allocatedBytes);
  20507. channels = reinterpret_cast <float**> (allocatedData.getData());
  20508. float* chan = (float*) (allocatedData + channelListSize);
  20509. for (int i = 0; i < numChannels; ++i)
  20510. {
  20511. channels[i] = chan;
  20512. chan += size;
  20513. }
  20514. channels [numChannels] = 0;
  20515. }
  20516. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20517. const int numChannels_,
  20518. const int numSamples) throw()
  20519. : numChannels (numChannels_),
  20520. size (numSamples),
  20521. allocatedBytes (0)
  20522. {
  20523. jassert (numChannels_ > 0);
  20524. allocateChannels (dataToReferTo);
  20525. }
  20526. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20527. const int newNumChannels,
  20528. const int newNumSamples) throw()
  20529. {
  20530. jassert (newNumChannels > 0);
  20531. allocatedBytes = 0;
  20532. allocatedData.free();
  20533. numChannels = newNumChannels;
  20534. size = newNumSamples;
  20535. allocateChannels (dataToReferTo);
  20536. }
  20537. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20538. {
  20539. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20540. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20541. {
  20542. channels = static_cast <float**> (preallocatedChannelSpace);
  20543. }
  20544. else
  20545. {
  20546. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20547. channels = reinterpret_cast <float**> (allocatedData.getData());
  20548. }
  20549. for (int i = 0; i < numChannels; ++i)
  20550. {
  20551. // you have to pass in the same number of valid pointers as numChannels
  20552. jassert (dataToReferTo[i] != 0);
  20553. channels[i] = dataToReferTo[i];
  20554. }
  20555. channels [numChannels] = 0;
  20556. }
  20557. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20558. {
  20559. if (this != &other)
  20560. {
  20561. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20562. const size_t numBytes = size * sizeof (float);
  20563. for (int i = 0; i < numChannels; ++i)
  20564. memcpy (channels[i], other.channels[i], numBytes);
  20565. }
  20566. return *this;
  20567. }
  20568. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20569. {
  20570. }
  20571. void AudioSampleBuffer::setSize (const int newNumChannels,
  20572. const int newNumSamples,
  20573. const bool keepExistingContent,
  20574. const bool clearExtraSpace,
  20575. const bool avoidReallocating) throw()
  20576. {
  20577. jassert (newNumChannels > 0);
  20578. if (newNumSamples != size || newNumChannels != numChannels)
  20579. {
  20580. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20581. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20582. if (keepExistingContent)
  20583. {
  20584. HeapBlock <char> newData;
  20585. newData.allocate (newTotalBytes, clearExtraSpace);
  20586. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20587. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20588. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20589. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20590. for (int i = 0; i < numChansToCopy; ++i)
  20591. {
  20592. memcpy (newChan, channels[i], numBytesToCopy);
  20593. newChannels[i] = newChan;
  20594. newChan += newNumSamples;
  20595. }
  20596. allocatedData.swapWith (newData);
  20597. allocatedBytes = (int) newTotalBytes;
  20598. channels = newChannels;
  20599. }
  20600. else
  20601. {
  20602. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20603. {
  20604. if (clearExtraSpace)
  20605. zeromem (allocatedData, newTotalBytes);
  20606. }
  20607. else
  20608. {
  20609. allocatedBytes = newTotalBytes;
  20610. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20611. channels = reinterpret_cast <float**> (allocatedData.getData());
  20612. }
  20613. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20614. for (int i = 0; i < newNumChannels; ++i)
  20615. {
  20616. channels[i] = chan;
  20617. chan += newNumSamples;
  20618. }
  20619. }
  20620. channels [newNumChannels] = 0;
  20621. size = newNumSamples;
  20622. numChannels = newNumChannels;
  20623. }
  20624. }
  20625. void AudioSampleBuffer::clear() throw()
  20626. {
  20627. for (int i = 0; i < numChannels; ++i)
  20628. zeromem (channels[i], size * sizeof (float));
  20629. }
  20630. void AudioSampleBuffer::clear (const int startSample,
  20631. const int numSamples) throw()
  20632. {
  20633. jassert (startSample >= 0 && startSample + numSamples <= size);
  20634. for (int i = 0; i < numChannels; ++i)
  20635. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20636. }
  20637. void AudioSampleBuffer::clear (const int channel,
  20638. const int startSample,
  20639. const int numSamples) throw()
  20640. {
  20641. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20642. jassert (startSample >= 0 && startSample + numSamples <= size);
  20643. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20644. }
  20645. void AudioSampleBuffer::applyGain (const int channel,
  20646. const int startSample,
  20647. int numSamples,
  20648. const float gain) throw()
  20649. {
  20650. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20651. jassert (startSample >= 0 && startSample + numSamples <= size);
  20652. if (gain != 1.0f)
  20653. {
  20654. float* d = channels [channel] + startSample;
  20655. if (gain == 0.0f)
  20656. {
  20657. zeromem (d, sizeof (float) * numSamples);
  20658. }
  20659. else
  20660. {
  20661. while (--numSamples >= 0)
  20662. *d++ *= gain;
  20663. }
  20664. }
  20665. }
  20666. void AudioSampleBuffer::applyGainRamp (const int channel,
  20667. const int startSample,
  20668. int numSamples,
  20669. float startGain,
  20670. float endGain) throw()
  20671. {
  20672. if (startGain == endGain)
  20673. {
  20674. applyGain (channel, startSample, numSamples, startGain);
  20675. }
  20676. else
  20677. {
  20678. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20679. jassert (startSample >= 0 && startSample + numSamples <= size);
  20680. const float increment = (endGain - startGain) / numSamples;
  20681. float* d = channels [channel] + startSample;
  20682. while (--numSamples >= 0)
  20683. {
  20684. *d++ *= startGain;
  20685. startGain += increment;
  20686. }
  20687. }
  20688. }
  20689. void AudioSampleBuffer::applyGain (const int startSample,
  20690. const int numSamples,
  20691. const float gain) throw()
  20692. {
  20693. for (int i = 0; i < numChannels; ++i)
  20694. applyGain (i, startSample, numSamples, gain);
  20695. }
  20696. void AudioSampleBuffer::addFrom (const int destChannel,
  20697. const int destStartSample,
  20698. const AudioSampleBuffer& source,
  20699. const int sourceChannel,
  20700. const int sourceStartSample,
  20701. int numSamples,
  20702. const float gain) throw()
  20703. {
  20704. jassert (&source != this || sourceChannel != destChannel);
  20705. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20706. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20707. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20708. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20709. if (gain != 0.0f && numSamples > 0)
  20710. {
  20711. float* d = channels [destChannel] + destStartSample;
  20712. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20713. if (gain != 1.0f)
  20714. {
  20715. while (--numSamples >= 0)
  20716. *d++ += gain * *s++;
  20717. }
  20718. else
  20719. {
  20720. while (--numSamples >= 0)
  20721. *d++ += *s++;
  20722. }
  20723. }
  20724. }
  20725. void AudioSampleBuffer::addFrom (const int destChannel,
  20726. const int destStartSample,
  20727. const float* source,
  20728. int numSamples,
  20729. const float gain) throw()
  20730. {
  20731. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20732. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20733. jassert (source != 0);
  20734. if (gain != 0.0f && numSamples > 0)
  20735. {
  20736. float* d = channels [destChannel] + destStartSample;
  20737. if (gain != 1.0f)
  20738. {
  20739. while (--numSamples >= 0)
  20740. *d++ += gain * *source++;
  20741. }
  20742. else
  20743. {
  20744. while (--numSamples >= 0)
  20745. *d++ += *source++;
  20746. }
  20747. }
  20748. }
  20749. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20750. const int destStartSample,
  20751. const float* source,
  20752. int numSamples,
  20753. float startGain,
  20754. const float endGain) throw()
  20755. {
  20756. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20757. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20758. jassert (source != 0);
  20759. if (startGain == endGain)
  20760. {
  20761. addFrom (destChannel,
  20762. destStartSample,
  20763. source,
  20764. numSamples,
  20765. startGain);
  20766. }
  20767. else
  20768. {
  20769. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20770. {
  20771. const float increment = (endGain - startGain) / numSamples;
  20772. float* d = channels [destChannel] + destStartSample;
  20773. while (--numSamples >= 0)
  20774. {
  20775. *d++ += startGain * *source++;
  20776. startGain += increment;
  20777. }
  20778. }
  20779. }
  20780. }
  20781. void AudioSampleBuffer::copyFrom (const int destChannel,
  20782. const int destStartSample,
  20783. const AudioSampleBuffer& source,
  20784. const int sourceChannel,
  20785. const int sourceStartSample,
  20786. int numSamples) throw()
  20787. {
  20788. jassert (&source != this || sourceChannel != destChannel);
  20789. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20790. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20791. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20792. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20793. if (numSamples > 0)
  20794. {
  20795. memcpy (channels [destChannel] + destStartSample,
  20796. source.channels [sourceChannel] + sourceStartSample,
  20797. sizeof (float) * numSamples);
  20798. }
  20799. }
  20800. void AudioSampleBuffer::copyFrom (const int destChannel,
  20801. const int destStartSample,
  20802. const float* source,
  20803. int numSamples) throw()
  20804. {
  20805. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20806. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20807. jassert (source != 0);
  20808. if (numSamples > 0)
  20809. {
  20810. memcpy (channels [destChannel] + destStartSample,
  20811. source,
  20812. sizeof (float) * numSamples);
  20813. }
  20814. }
  20815. void AudioSampleBuffer::copyFrom (const int destChannel,
  20816. const int destStartSample,
  20817. const float* source,
  20818. int numSamples,
  20819. const float gain) throw()
  20820. {
  20821. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20822. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20823. jassert (source != 0);
  20824. if (numSamples > 0)
  20825. {
  20826. float* d = channels [destChannel] + destStartSample;
  20827. if (gain != 1.0f)
  20828. {
  20829. if (gain == 0)
  20830. {
  20831. zeromem (d, sizeof (float) * numSamples);
  20832. }
  20833. else
  20834. {
  20835. while (--numSamples >= 0)
  20836. *d++ = gain * *source++;
  20837. }
  20838. }
  20839. else
  20840. {
  20841. memcpy (d, source, sizeof (float) * numSamples);
  20842. }
  20843. }
  20844. }
  20845. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20846. const int destStartSample,
  20847. const float* source,
  20848. int numSamples,
  20849. float startGain,
  20850. float endGain) throw()
  20851. {
  20852. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20853. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20854. jassert (source != 0);
  20855. if (startGain == endGain)
  20856. {
  20857. copyFrom (destChannel,
  20858. destStartSample,
  20859. source,
  20860. numSamples,
  20861. startGain);
  20862. }
  20863. else
  20864. {
  20865. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20866. {
  20867. const float increment = (endGain - startGain) / numSamples;
  20868. float* d = channels [destChannel] + destStartSample;
  20869. while (--numSamples >= 0)
  20870. {
  20871. *d++ = startGain * *source++;
  20872. startGain += increment;
  20873. }
  20874. }
  20875. }
  20876. }
  20877. void AudioSampleBuffer::findMinMax (const int channel,
  20878. const int startSample,
  20879. int numSamples,
  20880. float& minVal,
  20881. float& maxVal) const throw()
  20882. {
  20883. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20884. jassert (startSample >= 0 && startSample + numSamples <= size);
  20885. if (numSamples <= 0)
  20886. {
  20887. minVal = 0.0f;
  20888. maxVal = 0.0f;
  20889. }
  20890. else
  20891. {
  20892. const float* d = channels [channel] + startSample;
  20893. float mn = *d++;
  20894. float mx = mn;
  20895. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20896. {
  20897. const float samp = *d++;
  20898. if (samp > mx)
  20899. mx = samp;
  20900. if (samp < mn)
  20901. mn = samp;
  20902. }
  20903. maxVal = mx;
  20904. minVal = mn;
  20905. }
  20906. }
  20907. float AudioSampleBuffer::getMagnitude (const int channel,
  20908. const int startSample,
  20909. const int numSamples) const throw()
  20910. {
  20911. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20912. jassert (startSample >= 0 && startSample + numSamples <= size);
  20913. float mn, mx;
  20914. findMinMax (channel, startSample, numSamples, mn, mx);
  20915. return jmax (mn, -mn, mx, -mx);
  20916. }
  20917. float AudioSampleBuffer::getMagnitude (const int startSample,
  20918. const int numSamples) const throw()
  20919. {
  20920. float mag = 0.0f;
  20921. for (int i = 0; i < numChannels; ++i)
  20922. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20923. return mag;
  20924. }
  20925. float AudioSampleBuffer::getRMSLevel (const int channel,
  20926. const int startSample,
  20927. const int numSamples) const throw()
  20928. {
  20929. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20930. jassert (startSample >= 0 && startSample + numSamples <= size);
  20931. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20932. return 0.0f;
  20933. const float* const data = channels [channel] + startSample;
  20934. double sum = 0.0;
  20935. for (int i = 0; i < numSamples; ++i)
  20936. {
  20937. const float sample = data [i];
  20938. sum += sample * sample;
  20939. }
  20940. return (float) sqrt (sum / numSamples);
  20941. }
  20942. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20943. const int startSample,
  20944. const int numSamples,
  20945. const int readerStartSample,
  20946. const bool useLeftChan,
  20947. const bool useRightChan) throw()
  20948. {
  20949. jassert (reader != 0);
  20950. jassert (startSample >= 0 && startSample + numSamples <= size);
  20951. if (numSamples > 0)
  20952. {
  20953. int* chans[3];
  20954. if (useLeftChan == useRightChan)
  20955. {
  20956. chans[0] = (int*) getSampleData (0, startSample);
  20957. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20958. }
  20959. else if (useLeftChan || (reader->numChannels == 1))
  20960. {
  20961. chans[0] = (int*) getSampleData (0, startSample);
  20962. chans[1] = 0;
  20963. }
  20964. else if (useRightChan)
  20965. {
  20966. chans[0] = 0;
  20967. chans[1] = (int*) getSampleData (0, startSample);
  20968. }
  20969. chans[2] = 0;
  20970. reader->read (chans, 2, readerStartSample, numSamples, true);
  20971. if (! reader->usesFloatingPointData)
  20972. {
  20973. for (int j = 0; j < 2; ++j)
  20974. {
  20975. float* const d = reinterpret_cast <float*> (chans[j]);
  20976. if (d != 0)
  20977. {
  20978. const float multiplier = 1.0f / 0x7fffffff;
  20979. for (int i = 0; i < numSamples; ++i)
  20980. d[i] = *(int*)(d + i) * multiplier;
  20981. }
  20982. }
  20983. }
  20984. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20985. {
  20986. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20987. memcpy (getSampleData (1, startSample),
  20988. getSampleData (0, startSample),
  20989. sizeof (float) * numSamples);
  20990. }
  20991. }
  20992. }
  20993. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  20994. const int startSample,
  20995. const int numSamples) const throw()
  20996. {
  20997. jassert (startSample >= 0 && startSample + numSamples <= size);
  20998. if (numSamples > 0)
  20999. {
  21000. int* chans [3];
  21001. if (writer->isFloatingPoint())
  21002. {
  21003. chans[0] = (int*) getSampleData (0, startSample);
  21004. if (numChannels > 1)
  21005. chans[1] = (int*) getSampleData (1, startSample);
  21006. else
  21007. chans[1] = 0;
  21008. chans[2] = 0;
  21009. writer->write ((const int**) chans, numSamples);
  21010. }
  21011. else
  21012. {
  21013. HeapBlock <int> tempBuffer (numSamples * 2);
  21014. chans[0] = tempBuffer;
  21015. if (numChannels > 1)
  21016. chans[1] = chans[0] + numSamples;
  21017. else
  21018. chans[1] = 0;
  21019. chans[2] = 0;
  21020. for (int j = 0; j < 2; ++j)
  21021. {
  21022. int* const dest = chans[j];
  21023. if (dest != 0)
  21024. {
  21025. const float* const src = channels [j] + startSample;
  21026. for (int i = 0; i < numSamples; ++i)
  21027. {
  21028. const double samp = src[i];
  21029. if (samp <= -1.0)
  21030. dest[i] = std::numeric_limits<int>::min();
  21031. else if (samp >= 1.0)
  21032. dest[i] = std::numeric_limits<int>::max();
  21033. else
  21034. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21035. }
  21036. }
  21037. }
  21038. writer->write ((const int**) chans, numSamples);
  21039. }
  21040. }
  21041. }
  21042. END_JUCE_NAMESPACE
  21043. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21044. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21045. BEGIN_JUCE_NAMESPACE
  21046. IIRFilter::IIRFilter()
  21047. : active (false)
  21048. {
  21049. reset();
  21050. }
  21051. IIRFilter::IIRFilter (const IIRFilter& other)
  21052. : active (other.active)
  21053. {
  21054. const ScopedLock sl (other.processLock);
  21055. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21056. reset();
  21057. }
  21058. IIRFilter::~IIRFilter()
  21059. {
  21060. }
  21061. void IIRFilter::reset() throw()
  21062. {
  21063. const ScopedLock sl (processLock);
  21064. x1 = 0;
  21065. x2 = 0;
  21066. y1 = 0;
  21067. y2 = 0;
  21068. }
  21069. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21070. {
  21071. float out = coefficients[0] * in
  21072. + coefficients[1] * x1
  21073. + coefficients[2] * x2
  21074. - coefficients[4] * y1
  21075. - coefficients[5] * y2;
  21076. #if JUCE_INTEL
  21077. if (! (out < -1.0e-8 || out > 1.0e-8))
  21078. out = 0;
  21079. #endif
  21080. x2 = x1;
  21081. x1 = in;
  21082. y2 = y1;
  21083. y1 = out;
  21084. return out;
  21085. }
  21086. void IIRFilter::processSamples (float* const samples,
  21087. const int numSamples) throw()
  21088. {
  21089. const ScopedLock sl (processLock);
  21090. if (active)
  21091. {
  21092. for (int i = 0; i < numSamples; ++i)
  21093. {
  21094. const float in = samples[i];
  21095. float out = coefficients[0] * in
  21096. + coefficients[1] * x1
  21097. + coefficients[2] * x2
  21098. - coefficients[4] * y1
  21099. - coefficients[5] * y2;
  21100. #if JUCE_INTEL
  21101. if (! (out < -1.0e-8 || out > 1.0e-8))
  21102. out = 0;
  21103. #endif
  21104. x2 = x1;
  21105. x1 = in;
  21106. y2 = y1;
  21107. y1 = out;
  21108. samples[i] = out;
  21109. }
  21110. }
  21111. }
  21112. void IIRFilter::makeLowPass (const double sampleRate,
  21113. const double frequency) throw()
  21114. {
  21115. jassert (sampleRate > 0);
  21116. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21117. const double nSquared = n * n;
  21118. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21119. setCoefficients (c1,
  21120. c1 * 2.0f,
  21121. c1,
  21122. 1.0,
  21123. c1 * 2.0 * (1.0 - nSquared),
  21124. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21125. }
  21126. void IIRFilter::makeHighPass (const double sampleRate,
  21127. const double frequency) throw()
  21128. {
  21129. const double n = tan (double_Pi * frequency / sampleRate);
  21130. const double nSquared = n * n;
  21131. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21132. setCoefficients (c1,
  21133. c1 * -2.0f,
  21134. c1,
  21135. 1.0,
  21136. c1 * 2.0 * (nSquared - 1.0),
  21137. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21138. }
  21139. void IIRFilter::makeLowShelf (const double sampleRate,
  21140. const double cutOffFrequency,
  21141. const double Q,
  21142. const float gainFactor) throw()
  21143. {
  21144. jassert (sampleRate > 0);
  21145. jassert (Q > 0);
  21146. const double A = jmax (0.0f, gainFactor);
  21147. const double aminus1 = A - 1.0;
  21148. const double aplus1 = A + 1.0;
  21149. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21150. const double coso = cos (omega);
  21151. const double beta = sin (omega) * sqrt (A) / Q;
  21152. const double aminus1TimesCoso = aminus1 * coso;
  21153. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21154. A * 2.0 * (aminus1 - aplus1 * coso),
  21155. A * (aplus1 - aminus1TimesCoso - beta),
  21156. aplus1 + aminus1TimesCoso + beta,
  21157. -2.0 * (aminus1 + aplus1 * coso),
  21158. aplus1 + aminus1TimesCoso - beta);
  21159. }
  21160. void IIRFilter::makeHighShelf (const double sampleRate,
  21161. const double cutOffFrequency,
  21162. const double Q,
  21163. const float gainFactor) throw()
  21164. {
  21165. jassert (sampleRate > 0);
  21166. jassert (Q > 0);
  21167. const double A = jmax (0.0f, gainFactor);
  21168. const double aminus1 = A - 1.0;
  21169. const double aplus1 = A + 1.0;
  21170. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21171. const double coso = cos (omega);
  21172. const double beta = sin (omega) * sqrt (A) / Q;
  21173. const double aminus1TimesCoso = aminus1 * coso;
  21174. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21175. A * -2.0 * (aminus1 + aplus1 * coso),
  21176. A * (aplus1 + aminus1TimesCoso - beta),
  21177. aplus1 - aminus1TimesCoso + beta,
  21178. 2.0 * (aminus1 - aplus1 * coso),
  21179. aplus1 - aminus1TimesCoso - beta);
  21180. }
  21181. void IIRFilter::makeBandPass (const double sampleRate,
  21182. const double centreFrequency,
  21183. const double Q,
  21184. const float gainFactor) throw()
  21185. {
  21186. jassert (sampleRate > 0);
  21187. jassert (Q > 0);
  21188. const double A = jmax (0.0f, gainFactor);
  21189. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21190. const double alpha = 0.5 * sin (omega) / Q;
  21191. const double c2 = -2.0 * cos (omega);
  21192. const double alphaTimesA = alpha * A;
  21193. const double alphaOverA = alpha / A;
  21194. setCoefficients (1.0 + alphaTimesA,
  21195. c2,
  21196. 1.0 - alphaTimesA,
  21197. 1.0 + alphaOverA,
  21198. c2,
  21199. 1.0 - alphaOverA);
  21200. }
  21201. void IIRFilter::makeInactive() throw()
  21202. {
  21203. const ScopedLock sl (processLock);
  21204. active = false;
  21205. }
  21206. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21207. {
  21208. const ScopedLock sl (processLock);
  21209. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21210. active = other.active;
  21211. }
  21212. void IIRFilter::setCoefficients (double c1,
  21213. double c2,
  21214. double c3,
  21215. double c4,
  21216. double c5,
  21217. double c6) throw()
  21218. {
  21219. const double a = 1.0 / c4;
  21220. c1 *= a;
  21221. c2 *= a;
  21222. c3 *= a;
  21223. c5 *= a;
  21224. c6 *= a;
  21225. const ScopedLock sl (processLock);
  21226. coefficients[0] = (float) c1;
  21227. coefficients[1] = (float) c2;
  21228. coefficients[2] = (float) c3;
  21229. coefficients[3] = (float) c4;
  21230. coefficients[4] = (float) c5;
  21231. coefficients[5] = (float) c6;
  21232. active = true;
  21233. }
  21234. END_JUCE_NAMESPACE
  21235. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21236. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21237. BEGIN_JUCE_NAMESPACE
  21238. MidiBuffer::MidiBuffer() throw()
  21239. : bytesUsed (0)
  21240. {
  21241. }
  21242. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21243. : bytesUsed (0)
  21244. {
  21245. addEvent (message, 0);
  21246. }
  21247. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21248. : data (other.data),
  21249. bytesUsed (other.bytesUsed)
  21250. {
  21251. }
  21252. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21253. {
  21254. bytesUsed = other.bytesUsed;
  21255. data = other.data;
  21256. return *this;
  21257. }
  21258. void MidiBuffer::swapWith (MidiBuffer& other)
  21259. {
  21260. data.swapWith (other.data);
  21261. swapVariables <int> (bytesUsed, other.bytesUsed);
  21262. }
  21263. MidiBuffer::~MidiBuffer() throw()
  21264. {
  21265. }
  21266. inline uint8* MidiBuffer::getData() const throw()
  21267. {
  21268. return static_cast <uint8*> (data.getData());
  21269. }
  21270. inline int MidiBuffer::getEventTime (const void* const d) throw()
  21271. {
  21272. return *static_cast <const int*> (d);
  21273. }
  21274. inline uint16 MidiBuffer::getEventDataSize (const void* const d) throw()
  21275. {
  21276. return *reinterpret_cast <const uint16*> (static_cast <const char*> (d) + sizeof (int));
  21277. }
  21278. inline uint16 MidiBuffer::getEventTotalSize (const void* const d) throw()
  21279. {
  21280. return getEventDataSize (d) + sizeof (int) + sizeof (uint16);
  21281. }
  21282. void MidiBuffer::clear() throw()
  21283. {
  21284. bytesUsed = 0;
  21285. }
  21286. void MidiBuffer::clear (const int startSample,
  21287. const int numSamples) throw()
  21288. {
  21289. uint8* const start = findEventAfter (getData(), startSample - 1);
  21290. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21291. if (end > start)
  21292. {
  21293. const int bytesToMove = bytesUsed - (int) (end - getData());
  21294. if (bytesToMove > 0)
  21295. memmove (start, end, bytesToMove);
  21296. bytesUsed -= (int) (end - start);
  21297. }
  21298. }
  21299. void MidiBuffer::addEvent (const MidiMessage& m,
  21300. const int sampleNumber) throw()
  21301. {
  21302. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21303. }
  21304. static int findActualEventLength (const uint8* const data,
  21305. const int maxBytes) throw()
  21306. {
  21307. unsigned int byte = (unsigned int) *data;
  21308. int size = 0;
  21309. if (byte == 0xf0 || byte == 0xf7)
  21310. {
  21311. const uint8* d = data + 1;
  21312. while (d < data + maxBytes)
  21313. if (*d++ == 0xf7)
  21314. break;
  21315. size = (int) (d - data);
  21316. }
  21317. else if (byte == 0xff)
  21318. {
  21319. int n;
  21320. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21321. size = jmin (maxBytes, n + 2 + bytesLeft);
  21322. }
  21323. else if (byte >= 0x80)
  21324. {
  21325. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21326. }
  21327. return size;
  21328. }
  21329. void MidiBuffer::addEvent (const uint8* const newData,
  21330. const int maxBytes,
  21331. const int sampleNumber) throw()
  21332. {
  21333. const int numBytes = findActualEventLength (newData, maxBytes);
  21334. if (numBytes > 0)
  21335. {
  21336. int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16);
  21337. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21338. uint8* d = findEventAfter (getData(), sampleNumber);
  21339. const int bytesToMove = bytesUsed - (int) (d - getData());
  21340. if (bytesToMove > 0)
  21341. memmove (d + numBytes + sizeof (int) + sizeof (uint16), d, bytesToMove);
  21342. *reinterpret_cast <int*> (d) = sampleNumber;
  21343. d += sizeof (int);
  21344. *reinterpret_cast <uint16*> (d) = (uint16) numBytes;
  21345. d += sizeof (uint16);
  21346. memcpy (d, newData, numBytes);
  21347. bytesUsed += numBytes + sizeof (int) + sizeof (uint16);
  21348. }
  21349. }
  21350. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21351. const int startSample,
  21352. const int numSamples,
  21353. const int sampleDeltaToAdd) throw()
  21354. {
  21355. Iterator i (otherBuffer);
  21356. i.setNextSamplePosition (startSample);
  21357. const uint8* eventData;
  21358. int eventSize, position;
  21359. while (i.getNextEvent (eventData, eventSize, position)
  21360. && (position < startSample + numSamples || numSamples < 0))
  21361. {
  21362. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21363. }
  21364. }
  21365. void MidiBuffer::ensureSize (size_t minimumNumBytes)
  21366. {
  21367. data.ensureSize (minimumNumBytes);
  21368. }
  21369. bool MidiBuffer::isEmpty() const throw()
  21370. {
  21371. return bytesUsed == 0;
  21372. }
  21373. int MidiBuffer::getNumEvents() const throw()
  21374. {
  21375. int n = 0;
  21376. const uint8* d = getData();
  21377. const uint8* const end = d + bytesUsed;
  21378. while (d < end)
  21379. {
  21380. d += getEventTotalSize (d);
  21381. ++n;
  21382. }
  21383. return n;
  21384. }
  21385. int MidiBuffer::getFirstEventTime() const throw()
  21386. {
  21387. return bytesUsed > 0 ? getEventTime (data.getData()) : 0;
  21388. }
  21389. int MidiBuffer::getLastEventTime() const throw()
  21390. {
  21391. if (bytesUsed == 0)
  21392. return 0;
  21393. const uint8* d = getData();
  21394. const uint8* const endData = d + bytesUsed;
  21395. for (;;)
  21396. {
  21397. const uint8* const nextOne = d + getEventTotalSize (d);
  21398. if (nextOne >= endData)
  21399. return getEventTime (d);
  21400. d = nextOne;
  21401. }
  21402. }
  21403. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21404. {
  21405. const uint8* const endData = getData() + bytesUsed;
  21406. while (d < endData && getEventTime (d) <= samplePosition)
  21407. d += getEventTotalSize (d);
  21408. return d;
  21409. }
  21410. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21411. : buffer (buffer_),
  21412. data (buffer_.getData())
  21413. {
  21414. }
  21415. MidiBuffer::Iterator::~Iterator() throw()
  21416. {
  21417. }
  21418. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21419. {
  21420. data = buffer.getData();
  21421. const uint8* dataEnd = data + buffer.bytesUsed;
  21422. while (data < dataEnd && getEventTime (data) < samplePosition)
  21423. data += getEventTotalSize (data);
  21424. }
  21425. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw()
  21426. {
  21427. if (data >= buffer.getData() + buffer.bytesUsed)
  21428. return false;
  21429. samplePosition = getEventTime (data);
  21430. numBytes = getEventDataSize (data);
  21431. data += sizeof (int) + sizeof (uint16);
  21432. midiData = data;
  21433. data += numBytes;
  21434. return true;
  21435. }
  21436. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePosition) throw()
  21437. {
  21438. if (data >= buffer.getData() + buffer.bytesUsed)
  21439. return false;
  21440. samplePosition = getEventTime (data);
  21441. const int numBytes = getEventDataSize (data);
  21442. data += sizeof (int) + sizeof (uint16);
  21443. result = MidiMessage (data, numBytes, samplePosition);
  21444. data += numBytes;
  21445. return true;
  21446. }
  21447. END_JUCE_NAMESPACE
  21448. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21449. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21450. BEGIN_JUCE_NAMESPACE
  21451. namespace MidiFileHelpers
  21452. {
  21453. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21454. {
  21455. unsigned int buffer = v & 0x7F;
  21456. while ((v >>= 7) != 0)
  21457. {
  21458. buffer <<= 8;
  21459. buffer |= ((v & 0x7F) | 0x80);
  21460. }
  21461. for (;;)
  21462. {
  21463. out.writeByte ((char) buffer);
  21464. if (buffer & 0x80)
  21465. buffer >>= 8;
  21466. else
  21467. break;
  21468. }
  21469. }
  21470. static bool parseMidiHeader (const uint8* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21471. {
  21472. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21473. data += 4;
  21474. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21475. {
  21476. bool ok = false;
  21477. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21478. {
  21479. for (int i = 0; i < 8; ++i)
  21480. {
  21481. ch = ByteOrder::bigEndianInt (data);
  21482. data += 4;
  21483. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21484. {
  21485. ok = true;
  21486. break;
  21487. }
  21488. }
  21489. }
  21490. if (! ok)
  21491. return false;
  21492. }
  21493. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21494. data += 4;
  21495. fileType = (short) ByteOrder::bigEndianShort (data);
  21496. data += 2;
  21497. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21498. data += 2;
  21499. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21500. data += 2;
  21501. bytesRemaining -= 6;
  21502. data += bytesRemaining;
  21503. return true;
  21504. }
  21505. static double convertTicksToSeconds (const double time,
  21506. const MidiMessageSequence& tempoEvents,
  21507. const int timeFormat)
  21508. {
  21509. if (timeFormat > 0)
  21510. {
  21511. int numer = 4, denom = 4;
  21512. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21513. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21514. double secsPerTick = 0.5 * tickLen;
  21515. const int numEvents = tempoEvents.getNumEvents();
  21516. for (int i = 0; i < numEvents; ++i)
  21517. {
  21518. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21519. if (time <= m.getTimeStamp())
  21520. break;
  21521. if (timeFormat > 0)
  21522. {
  21523. correctedTempoTime = correctedTempoTime
  21524. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21525. }
  21526. else
  21527. {
  21528. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21529. }
  21530. tempoTime = m.getTimeStamp();
  21531. if (m.isTempoMetaEvent())
  21532. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21533. else if (m.isTimeSignatureMetaEvent())
  21534. m.getTimeSignatureInfo (numer, denom);
  21535. while (i + 1 < numEvents)
  21536. {
  21537. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21538. if (m2.getTimeStamp() == tempoTime)
  21539. {
  21540. ++i;
  21541. if (m2.isTempoMetaEvent())
  21542. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21543. else if (m2.isTimeSignatureMetaEvent())
  21544. m2.getTimeSignatureInfo (numer, denom);
  21545. }
  21546. else
  21547. {
  21548. break;
  21549. }
  21550. }
  21551. }
  21552. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21553. }
  21554. else
  21555. {
  21556. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21557. }
  21558. }
  21559. }
  21560. MidiFile::MidiFile()
  21561. : timeFormat ((short) (unsigned short) 0xe728)
  21562. {
  21563. }
  21564. MidiFile::~MidiFile()
  21565. {
  21566. clear();
  21567. }
  21568. void MidiFile::clear()
  21569. {
  21570. tracks.clear();
  21571. }
  21572. int MidiFile::getNumTracks() const throw()
  21573. {
  21574. return tracks.size();
  21575. }
  21576. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21577. {
  21578. return tracks [index];
  21579. }
  21580. void MidiFile::addTrack (const MidiMessageSequence& trackSequence)
  21581. {
  21582. tracks.add (new MidiMessageSequence (trackSequence));
  21583. }
  21584. short MidiFile::getTimeFormat() const throw()
  21585. {
  21586. return timeFormat;
  21587. }
  21588. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21589. {
  21590. timeFormat = (short) ticks;
  21591. }
  21592. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21593. const int subframeResolution) throw()
  21594. {
  21595. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21596. }
  21597. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21598. {
  21599. for (int i = tracks.size(); --i >= 0;)
  21600. {
  21601. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21602. for (int j = 0; j < numEvents; ++j)
  21603. {
  21604. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21605. if (m.isTempoMetaEvent())
  21606. tempoChangeEvents.addEvent (m);
  21607. }
  21608. }
  21609. }
  21610. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21611. {
  21612. for (int i = tracks.size(); --i >= 0;)
  21613. {
  21614. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21615. for (int j = 0; j < numEvents; ++j)
  21616. {
  21617. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21618. if (m.isTimeSignatureMetaEvent())
  21619. timeSigEvents.addEvent (m);
  21620. }
  21621. }
  21622. }
  21623. double MidiFile::getLastTimestamp() const
  21624. {
  21625. double t = 0.0;
  21626. for (int i = tracks.size(); --i >= 0;)
  21627. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21628. return t;
  21629. }
  21630. bool MidiFile::readFrom (InputStream& sourceStream)
  21631. {
  21632. clear();
  21633. MemoryBlock data;
  21634. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21635. // (put a sanity-check on the file size, as midi files are generally small)
  21636. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21637. {
  21638. size_t size = data.getSize();
  21639. const uint8* d = static_cast <const uint8*> (data.getData());
  21640. short fileType, expectedTracks;
  21641. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21642. {
  21643. size -= (int) (d - static_cast <const uint8*> (data.getData()));
  21644. int track = 0;
  21645. while (size > 0 && track < expectedTracks)
  21646. {
  21647. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21648. d += 4;
  21649. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21650. d += 4;
  21651. if (chunkSize <= 0)
  21652. break;
  21653. if (size < 0)
  21654. return false;
  21655. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21656. {
  21657. readNextTrack (d, chunkSize);
  21658. }
  21659. size -= chunkSize + 8;
  21660. d += chunkSize;
  21661. ++track;
  21662. }
  21663. return true;
  21664. }
  21665. }
  21666. return false;
  21667. }
  21668. // a comparator that puts all the note-offs before note-ons that have the same time
  21669. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21670. const MidiMessageSequence::MidiEventHolder* const second)
  21671. {
  21672. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21673. if (diff == 0)
  21674. {
  21675. if (first->message.isNoteOff() && second->message.isNoteOn())
  21676. return -1;
  21677. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21678. return 1;
  21679. else
  21680. return 0;
  21681. }
  21682. else
  21683. {
  21684. return (diff > 0) ? 1 : -1;
  21685. }
  21686. }
  21687. void MidiFile::readNextTrack (const uint8* data, int size)
  21688. {
  21689. double time = 0;
  21690. char lastStatusByte = 0;
  21691. MidiMessageSequence result;
  21692. while (size > 0)
  21693. {
  21694. int bytesUsed;
  21695. const int delay = MidiMessage::readVariableLengthVal (data, bytesUsed);
  21696. data += bytesUsed;
  21697. size -= bytesUsed;
  21698. time += delay;
  21699. int messSize = 0;
  21700. const MidiMessage mm (data, size, messSize, lastStatusByte, time);
  21701. if (messSize <= 0)
  21702. break;
  21703. size -= messSize;
  21704. data += messSize;
  21705. result.addEvent (mm);
  21706. const char firstByte = *(mm.getRawData());
  21707. if ((firstByte & 0xf0) != 0xf0)
  21708. lastStatusByte = firstByte;
  21709. }
  21710. // use a sort that puts all the note-offs before note-ons that have the same time
  21711. result.list.sort (*this, true);
  21712. result.updateMatchedPairs();
  21713. addTrack (result);
  21714. }
  21715. void MidiFile::convertTimestampTicksToSeconds()
  21716. {
  21717. MidiMessageSequence tempoEvents;
  21718. findAllTempoEvents (tempoEvents);
  21719. findAllTimeSigEvents (tempoEvents);
  21720. for (int i = 0; i < tracks.size(); ++i)
  21721. {
  21722. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21723. for (int j = ms.getNumEvents(); --j >= 0;)
  21724. {
  21725. MidiMessage& m = ms.getEventPointer(j)->message;
  21726. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21727. tempoEvents,
  21728. timeFormat));
  21729. }
  21730. }
  21731. }
  21732. bool MidiFile::writeTo (OutputStream& out)
  21733. {
  21734. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21735. out.writeIntBigEndian (6);
  21736. out.writeShortBigEndian (1); // type
  21737. out.writeShortBigEndian ((short) tracks.size());
  21738. out.writeShortBigEndian (timeFormat);
  21739. for (int i = 0; i < tracks.size(); ++i)
  21740. writeTrack (out, i);
  21741. out.flush();
  21742. return true;
  21743. }
  21744. void MidiFile::writeTrack (OutputStream& mainOut,
  21745. const int trackNum)
  21746. {
  21747. MemoryOutputStream out;
  21748. const MidiMessageSequence& ms = *tracks[trackNum];
  21749. int lastTick = 0;
  21750. char lastStatusByte = 0;
  21751. for (int i = 0; i < ms.getNumEvents(); ++i)
  21752. {
  21753. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21754. const int tick = roundToInt (mm.getTimeStamp());
  21755. const int delta = jmax (0, tick - lastTick);
  21756. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21757. lastTick = tick;
  21758. const char statusByte = *(mm.getRawData());
  21759. if ((statusByte == lastStatusByte)
  21760. && ((statusByte & 0xf0) != 0xf0)
  21761. && i > 0
  21762. && mm.getRawDataSize() > 1)
  21763. {
  21764. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21765. }
  21766. else
  21767. {
  21768. out.write (mm.getRawData(), mm.getRawDataSize());
  21769. }
  21770. lastStatusByte = statusByte;
  21771. }
  21772. out.writeByte (0);
  21773. const MidiMessage m (MidiMessage::endOfTrack());
  21774. out.write (m.getRawData(),
  21775. m.getRawDataSize());
  21776. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21777. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21778. mainOut.write (out.getData(), (int) out.getDataSize());
  21779. }
  21780. END_JUCE_NAMESPACE
  21781. /*** End of inlined file: juce_MidiFile.cpp ***/
  21782. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21783. BEGIN_JUCE_NAMESPACE
  21784. MidiKeyboardState::MidiKeyboardState()
  21785. {
  21786. zerostruct (noteStates);
  21787. }
  21788. MidiKeyboardState::~MidiKeyboardState()
  21789. {
  21790. }
  21791. void MidiKeyboardState::reset()
  21792. {
  21793. const ScopedLock sl (lock);
  21794. zerostruct (noteStates);
  21795. eventsToAdd.clear();
  21796. }
  21797. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21798. {
  21799. jassert (midiChannel >= 0 && midiChannel <= 16);
  21800. return ((unsigned int) n) < 128
  21801. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21802. }
  21803. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21804. {
  21805. return ((unsigned int) n) < 128
  21806. && (noteStates[n] & midiChannelMask) != 0;
  21807. }
  21808. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21809. {
  21810. jassert (midiChannel >= 0 && midiChannel <= 16);
  21811. jassert (((unsigned int) midiNoteNumber) < 128);
  21812. const ScopedLock sl (lock);
  21813. if (((unsigned int) midiNoteNumber) < 128)
  21814. {
  21815. const int timeNow = (int) Time::getMillisecondCounter();
  21816. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21817. eventsToAdd.clear (0, timeNow - 500);
  21818. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21819. }
  21820. }
  21821. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21822. {
  21823. if (((unsigned int) midiNoteNumber) < 128)
  21824. {
  21825. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21826. for (int i = listeners.size(); --i >= 0;)
  21827. listeners.getUnchecked(i)->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21828. }
  21829. }
  21830. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21831. {
  21832. const ScopedLock sl (lock);
  21833. if (isNoteOn (midiChannel, midiNoteNumber))
  21834. {
  21835. const int timeNow = (int) Time::getMillisecondCounter();
  21836. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21837. eventsToAdd.clear (0, timeNow - 500);
  21838. noteOffInternal (midiChannel, midiNoteNumber);
  21839. }
  21840. }
  21841. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21842. {
  21843. if (isNoteOn (midiChannel, midiNoteNumber))
  21844. {
  21845. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21846. for (int i = listeners.size(); --i >= 0;)
  21847. listeners.getUnchecked(i)->handleNoteOff (this, midiChannel, midiNoteNumber);
  21848. }
  21849. }
  21850. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21851. {
  21852. const ScopedLock sl (lock);
  21853. if (midiChannel <= 0)
  21854. {
  21855. for (int i = 1; i <= 16; ++i)
  21856. allNotesOff (i);
  21857. }
  21858. else
  21859. {
  21860. for (int i = 0; i < 128; ++i)
  21861. noteOff (midiChannel, i);
  21862. }
  21863. }
  21864. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21865. {
  21866. if (message.isNoteOn())
  21867. {
  21868. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21869. }
  21870. else if (message.isNoteOff())
  21871. {
  21872. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21873. }
  21874. else if (message.isAllNotesOff())
  21875. {
  21876. for (int i = 0; i < 128; ++i)
  21877. noteOffInternal (message.getChannel(), i);
  21878. }
  21879. }
  21880. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21881. const int startSample,
  21882. const int numSamples,
  21883. const bool injectIndirectEvents)
  21884. {
  21885. MidiBuffer::Iterator i (buffer);
  21886. MidiMessage message (0xf4, 0.0);
  21887. int time;
  21888. const ScopedLock sl (lock);
  21889. while (i.getNextEvent (message, time))
  21890. processNextMidiEvent (message);
  21891. if (injectIndirectEvents)
  21892. {
  21893. MidiBuffer::Iterator i2 (eventsToAdd);
  21894. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21895. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21896. while (i2.getNextEvent (message, time))
  21897. {
  21898. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21899. buffer.addEvent (message, startSample + pos);
  21900. }
  21901. }
  21902. eventsToAdd.clear();
  21903. }
  21904. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21905. {
  21906. const ScopedLock sl (lock);
  21907. listeners.addIfNotAlreadyThere (listener);
  21908. }
  21909. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21910. {
  21911. const ScopedLock sl (lock);
  21912. listeners.removeValue (listener);
  21913. }
  21914. END_JUCE_NAMESPACE
  21915. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21916. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21917. BEGIN_JUCE_NAMESPACE
  21918. int MidiMessage::readVariableLengthVal (const uint8* data,
  21919. int& numBytesUsed) throw()
  21920. {
  21921. numBytesUsed = 0;
  21922. int v = 0;
  21923. int i;
  21924. do
  21925. {
  21926. i = (int) *data++;
  21927. if (++numBytesUsed > 6)
  21928. break;
  21929. v = (v << 7) + (i & 0x7f);
  21930. } while (i & 0x80);
  21931. return v;
  21932. }
  21933. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21934. {
  21935. // this method only works for valid starting bytes of a short midi message
  21936. jassert (firstByte >= 0x80
  21937. && firstByte != 0xf0
  21938. && firstByte != 0xf7);
  21939. static const char messageLengths[] =
  21940. {
  21941. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21942. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21943. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21944. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21945. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21946. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21947. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21948. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21949. };
  21950. return messageLengths [firstByte & 0x7f];
  21951. }
  21952. MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
  21953. : timeStamp (t),
  21954. size (dataSize)
  21955. {
  21956. jassert (dataSize > 0);
  21957. if (dataSize <= 4)
  21958. data = static_cast<uint8*> (preallocatedData.asBytes);
  21959. else
  21960. data = static_cast<uint8*> (juce_malloc (dataSize));
  21961. memcpy (data, d, dataSize);
  21962. // check that the length matches the data..
  21963. jassert (size > 3 || data[0] >= 0xf0 || getMessageLengthFromFirstByte (data[0]) == size);
  21964. }
  21965. MidiMessage::MidiMessage (const int byte1, const double t) throw()
  21966. : timeStamp (t),
  21967. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21968. size (1)
  21969. {
  21970. data[0] = (uint8) byte1;
  21971. // check that the length matches the data..
  21972. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21973. }
  21974. MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) throw()
  21975. : timeStamp (t),
  21976. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21977. size (2)
  21978. {
  21979. data[0] = (uint8) byte1;
  21980. data[1] = (uint8) byte2;
  21981. // check that the length matches the data..
  21982. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21983. }
  21984. MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) throw()
  21985. : timeStamp (t),
  21986. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21987. size (3)
  21988. {
  21989. data[0] = (uint8) byte1;
  21990. data[1] = (uint8) byte2;
  21991. data[2] = (uint8) byte3;
  21992. // check that the length matches the data..
  21993. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  21994. }
  21995. MidiMessage::MidiMessage (const MidiMessage& other)
  21996. : timeStamp (other.timeStamp),
  21997. size (other.size)
  21998. {
  21999. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  22000. {
  22001. data = static_cast<uint8*> (juce_malloc (size));
  22002. memcpy (data, other.data, size);
  22003. }
  22004. else
  22005. {
  22006. data = static_cast<uint8*> (preallocatedData.asBytes);
  22007. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  22008. }
  22009. }
  22010. MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
  22011. : timeStamp (newTimeStamp),
  22012. size (other.size)
  22013. {
  22014. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  22015. {
  22016. data = static_cast<uint8*> (juce_malloc (size));
  22017. memcpy (data, other.data, size);
  22018. }
  22019. else
  22020. {
  22021. data = static_cast<uint8*> (preallocatedData.asBytes);
  22022. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  22023. }
  22024. }
  22025. MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uint8 lastStatusByte, double t)
  22026. : timeStamp (t),
  22027. data (static_cast<uint8*> (preallocatedData.asBytes))
  22028. {
  22029. const uint8* src = static_cast <const uint8*> (src_);
  22030. unsigned int byte = (unsigned int) *src;
  22031. if (byte < 0x80)
  22032. {
  22033. byte = (unsigned int) (uint8) lastStatusByte;
  22034. numBytesUsed = -1;
  22035. }
  22036. else
  22037. {
  22038. numBytesUsed = 0;
  22039. --sz;
  22040. ++src;
  22041. }
  22042. if (byte >= 0x80)
  22043. {
  22044. if (byte == 0xf0)
  22045. {
  22046. const uint8* d = src;
  22047. while (d < src + sz)
  22048. {
  22049. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22050. {
  22051. if (*d == 0xf7) // include an 0xf7 if we hit one
  22052. ++d;
  22053. break;
  22054. }
  22055. ++d;
  22056. }
  22057. size = 1 + (int) (d - src);
  22058. data = static_cast<uint8*> (juce_malloc (size));
  22059. *data = (uint8) byte;
  22060. memcpy (data + 1, src, size - 1);
  22061. }
  22062. else if (byte == 0xff)
  22063. {
  22064. int n;
  22065. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22066. size = jmin (sz + 1, n + 2 + bytesLeft);
  22067. data = static_cast<uint8*> (juce_malloc (size));
  22068. *data = (uint8) byte;
  22069. memcpy (data + 1, src, size - 1);
  22070. }
  22071. else
  22072. {
  22073. preallocatedData.asInt32 = 0;
  22074. size = getMessageLengthFromFirstByte ((uint8) byte);
  22075. data[0] = (uint8) byte;
  22076. if (size > 1)
  22077. {
  22078. data[1] = src[0];
  22079. if (size > 2)
  22080. data[2] = src[1];
  22081. }
  22082. }
  22083. numBytesUsed += size;
  22084. }
  22085. else
  22086. {
  22087. preallocatedData.asInt32 = 0;
  22088. size = 0;
  22089. }
  22090. }
  22091. MidiMessage& MidiMessage::operator= (const MidiMessage& other)
  22092. {
  22093. if (this != &other)
  22094. {
  22095. timeStamp = other.timeStamp;
  22096. size = other.size;
  22097. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22098. juce_free (data);
  22099. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  22100. {
  22101. data = static_cast<uint8*> (juce_malloc (size));
  22102. memcpy (data, other.data, size);
  22103. }
  22104. else
  22105. {
  22106. data = static_cast<uint8*> (preallocatedData.asBytes);
  22107. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  22108. }
  22109. }
  22110. return *this;
  22111. }
  22112. MidiMessage::~MidiMessage()
  22113. {
  22114. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22115. juce_free (data);
  22116. }
  22117. int MidiMessage::getChannel() const throw()
  22118. {
  22119. if ((data[0] & 0xf0) != 0xf0)
  22120. return (data[0] & 0xf) + 1;
  22121. else
  22122. return 0;
  22123. }
  22124. bool MidiMessage::isForChannel (const int channel) const throw()
  22125. {
  22126. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22127. return ((data[0] & 0xf) == channel - 1)
  22128. && ((data[0] & 0xf0) != 0xf0);
  22129. }
  22130. void MidiMessage::setChannel (const int channel) throw()
  22131. {
  22132. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22133. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22134. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22135. | (uint8)(channel - 1));
  22136. }
  22137. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22138. {
  22139. return ((data[0] & 0xf0) == 0x90)
  22140. && (returnTrueForVelocity0 || data[2] != 0);
  22141. }
  22142. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22143. {
  22144. return ((data[0] & 0xf0) == 0x80)
  22145. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22146. }
  22147. bool MidiMessage::isNoteOnOrOff() const throw()
  22148. {
  22149. const int d = data[0] & 0xf0;
  22150. return (d == 0x90) || (d == 0x80);
  22151. }
  22152. int MidiMessage::getNoteNumber() const throw()
  22153. {
  22154. return data[1];
  22155. }
  22156. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22157. {
  22158. if (isNoteOnOrOff())
  22159. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22160. }
  22161. uint8 MidiMessage::getVelocity() const throw()
  22162. {
  22163. if (isNoteOnOrOff())
  22164. return data[2];
  22165. else
  22166. return 0;
  22167. }
  22168. float MidiMessage::getFloatVelocity() const throw()
  22169. {
  22170. return getVelocity() * (1.0f / 127.0f);
  22171. }
  22172. void MidiMessage::setVelocity (const float newVelocity) throw()
  22173. {
  22174. if (isNoteOnOrOff())
  22175. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22176. }
  22177. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22178. {
  22179. if (isNoteOnOrOff())
  22180. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22181. }
  22182. bool MidiMessage::isAftertouch() const throw()
  22183. {
  22184. return (data[0] & 0xf0) == 0xa0;
  22185. }
  22186. int MidiMessage::getAfterTouchValue() const throw()
  22187. {
  22188. return data[2];
  22189. }
  22190. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22191. const int noteNum,
  22192. const int aftertouchValue) throw()
  22193. {
  22194. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22195. jassert (((unsigned int) noteNum) <= 127);
  22196. jassert (((unsigned int) aftertouchValue) <= 127);
  22197. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22198. noteNum & 0x7f,
  22199. aftertouchValue & 0x7f);
  22200. }
  22201. bool MidiMessage::isChannelPressure() const throw()
  22202. {
  22203. return (data[0] & 0xf0) == 0xd0;
  22204. }
  22205. int MidiMessage::getChannelPressureValue() const throw()
  22206. {
  22207. jassert (isChannelPressure());
  22208. return data[1];
  22209. }
  22210. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22211. const int pressure) throw()
  22212. {
  22213. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22214. jassert (((unsigned int) pressure) <= 127);
  22215. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22216. pressure & 0x7f);
  22217. }
  22218. bool MidiMessage::isProgramChange() const throw()
  22219. {
  22220. return (data[0] & 0xf0) == 0xc0;
  22221. }
  22222. int MidiMessage::getProgramChangeNumber() const throw()
  22223. {
  22224. return data[1];
  22225. }
  22226. const MidiMessage MidiMessage::programChange (const int channel,
  22227. const int programNumber) throw()
  22228. {
  22229. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22230. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22231. programNumber & 0x7f);
  22232. }
  22233. bool MidiMessage::isPitchWheel() const throw()
  22234. {
  22235. return (data[0] & 0xf0) == 0xe0;
  22236. }
  22237. int MidiMessage::getPitchWheelValue() const throw()
  22238. {
  22239. return data[1] | (data[2] << 7);
  22240. }
  22241. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22242. const int position) throw()
  22243. {
  22244. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22245. jassert (((unsigned int) position) <= 0x3fff);
  22246. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22247. position & 127,
  22248. (position >> 7) & 127);
  22249. }
  22250. bool MidiMessage::isController() const throw()
  22251. {
  22252. return (data[0] & 0xf0) == 0xb0;
  22253. }
  22254. int MidiMessage::getControllerNumber() const throw()
  22255. {
  22256. jassert (isController());
  22257. return data[1];
  22258. }
  22259. int MidiMessage::getControllerValue() const throw()
  22260. {
  22261. jassert (isController());
  22262. return data[2];
  22263. }
  22264. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22265. const int controllerType,
  22266. const int value) throw()
  22267. {
  22268. // the channel must be between 1 and 16 inclusive
  22269. jassert (channel > 0 && channel <= 16);
  22270. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22271. controllerType & 127,
  22272. value & 127);
  22273. }
  22274. const MidiMessage MidiMessage::noteOn (const int channel,
  22275. const int noteNumber,
  22276. const float velocity) throw()
  22277. {
  22278. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22279. }
  22280. const MidiMessage MidiMessage::noteOn (const int channel,
  22281. const int noteNumber,
  22282. const uint8 velocity) throw()
  22283. {
  22284. jassert (channel > 0 && channel <= 16);
  22285. jassert (((unsigned int) noteNumber) <= 127);
  22286. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22287. noteNumber & 127,
  22288. jlimit (0, 127, roundToInt (velocity)));
  22289. }
  22290. const MidiMessage MidiMessage::noteOff (const int channel,
  22291. const int noteNumber) throw()
  22292. {
  22293. jassert (channel > 0 && channel <= 16);
  22294. jassert (((unsigned int) noteNumber) <= 127);
  22295. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22296. }
  22297. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22298. {
  22299. jassert (channel > 0 && channel <= 16);
  22300. return controllerEvent (channel, 123, 0);
  22301. }
  22302. bool MidiMessage::isAllNotesOff() const throw()
  22303. {
  22304. return (data[0] & 0xf0) == 0xb0
  22305. && data[1] == 123;
  22306. }
  22307. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22308. {
  22309. return controllerEvent (channel, 120, 0);
  22310. }
  22311. bool MidiMessage::isAllSoundOff() const throw()
  22312. {
  22313. return (data[0] & 0xf0) == 0xb0
  22314. && data[1] == 120;
  22315. }
  22316. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22317. {
  22318. return controllerEvent (channel, 121, 0);
  22319. }
  22320. const MidiMessage MidiMessage::masterVolume (const float volume)
  22321. {
  22322. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22323. uint8 buf[8];
  22324. buf[0] = 0xf0;
  22325. buf[1] = 0x7f;
  22326. buf[2] = 0x7f;
  22327. buf[3] = 0x04;
  22328. buf[4] = 0x01;
  22329. buf[5] = (uint8) (vol & 0x7f);
  22330. buf[6] = (uint8) (vol >> 7);
  22331. buf[7] = 0xf7;
  22332. return MidiMessage (buf, 8);
  22333. }
  22334. bool MidiMessage::isSysEx() const throw()
  22335. {
  22336. return *data == 0xf0;
  22337. }
  22338. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData, const int dataSize)
  22339. {
  22340. MemoryBlock mm (dataSize + 2);
  22341. uint8* const m = static_cast <uint8*> (mm.getData());
  22342. m[0] = 0xf0;
  22343. memcpy (m + 1, sysexData, dataSize);
  22344. m[dataSize + 1] = 0xf7;
  22345. return MidiMessage (m, dataSize + 2);
  22346. }
  22347. const uint8* MidiMessage::getSysExData() const throw()
  22348. {
  22349. return (isSysEx()) ? getRawData() + 1 : 0;
  22350. }
  22351. int MidiMessage::getSysExDataSize() const throw()
  22352. {
  22353. return (isSysEx()) ? size - 2 : 0;
  22354. }
  22355. bool MidiMessage::isMetaEvent() const throw()
  22356. {
  22357. return *data == 0xff;
  22358. }
  22359. bool MidiMessage::isActiveSense() const throw()
  22360. {
  22361. return *data == 0xfe;
  22362. }
  22363. int MidiMessage::getMetaEventType() const throw()
  22364. {
  22365. if (*data != 0xff)
  22366. return -1;
  22367. else
  22368. return data[1];
  22369. }
  22370. int MidiMessage::getMetaEventLength() const throw()
  22371. {
  22372. if (*data == 0xff)
  22373. {
  22374. int n;
  22375. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22376. }
  22377. return 0;
  22378. }
  22379. const uint8* MidiMessage::getMetaEventData() const throw()
  22380. {
  22381. int n;
  22382. const uint8* d = data + 2;
  22383. readVariableLengthVal (d, n);
  22384. return d + n;
  22385. }
  22386. bool MidiMessage::isTrackMetaEvent() const throw()
  22387. {
  22388. return getMetaEventType() == 0;
  22389. }
  22390. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22391. {
  22392. return getMetaEventType() == 47;
  22393. }
  22394. bool MidiMessage::isTextMetaEvent() const throw()
  22395. {
  22396. const int t = getMetaEventType();
  22397. return t > 0 && t < 16;
  22398. }
  22399. const String MidiMessage::getTextFromTextMetaEvent() const
  22400. {
  22401. return String (reinterpret_cast <const char*> (getMetaEventData()), getMetaEventLength());
  22402. }
  22403. bool MidiMessage::isTrackNameEvent() const throw()
  22404. {
  22405. return (data[1] == 3)
  22406. && (*data == 0xff);
  22407. }
  22408. bool MidiMessage::isTempoMetaEvent() const throw()
  22409. {
  22410. return (data[1] == 81)
  22411. && (*data == 0xff);
  22412. }
  22413. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22414. {
  22415. return (data[1] == 0x20)
  22416. && (*data == 0xff)
  22417. && (data[2] == 1);
  22418. }
  22419. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22420. {
  22421. return data[3] + 1;
  22422. }
  22423. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22424. {
  22425. if (! isTempoMetaEvent())
  22426. return 0.0;
  22427. const uint8* const d = getMetaEventData();
  22428. return (((unsigned int) d[0] << 16)
  22429. | ((unsigned int) d[1] << 8)
  22430. | d[2])
  22431. / 1000000.0;
  22432. }
  22433. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22434. {
  22435. if (timeFormat > 0)
  22436. {
  22437. if (! isTempoMetaEvent())
  22438. return 0.5 / timeFormat;
  22439. return getTempoSecondsPerQuarterNote() / timeFormat;
  22440. }
  22441. else
  22442. {
  22443. const int frameCode = (-timeFormat) >> 8;
  22444. double framesPerSecond;
  22445. switch (frameCode)
  22446. {
  22447. case 24: framesPerSecond = 24.0; break;
  22448. case 25: framesPerSecond = 25.0; break;
  22449. case 29: framesPerSecond = 29.97; break;
  22450. case 30: framesPerSecond = 30.0; break;
  22451. default: framesPerSecond = 30.0; break;
  22452. }
  22453. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22454. }
  22455. }
  22456. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22457. {
  22458. uint8 d[8];
  22459. d[0] = 0xff;
  22460. d[1] = 81;
  22461. d[2] = 3;
  22462. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22463. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22464. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22465. return MidiMessage (d, 6, 0.0);
  22466. }
  22467. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22468. {
  22469. return (data[1] == 0x58)
  22470. && (*data == (uint8) 0xff);
  22471. }
  22472. void MidiMessage::getTimeSignatureInfo (int& numerator, int& denominator) const throw()
  22473. {
  22474. if (isTimeSignatureMetaEvent())
  22475. {
  22476. const uint8* const d = getMetaEventData();
  22477. numerator = d[0];
  22478. denominator = 1 << d[1];
  22479. }
  22480. else
  22481. {
  22482. numerator = 4;
  22483. denominator = 4;
  22484. }
  22485. }
  22486. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator, const int denominator)
  22487. {
  22488. uint8 d[8];
  22489. d[0] = 0xff;
  22490. d[1] = 0x58;
  22491. d[2] = 0x04;
  22492. d[3] = (uint8) numerator;
  22493. int n = 1;
  22494. int powerOfTwo = 0;
  22495. while (n < denominator)
  22496. {
  22497. n <<= 1;
  22498. ++powerOfTwo;
  22499. }
  22500. d[4] = (uint8) powerOfTwo;
  22501. d[5] = 0x01;
  22502. d[6] = 96;
  22503. return MidiMessage (d, 7, 0.0);
  22504. }
  22505. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22506. {
  22507. uint8 d[8];
  22508. d[0] = 0xff;
  22509. d[1] = 0x20;
  22510. d[2] = 0x01;
  22511. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22512. return MidiMessage (d, 4, 0.0);
  22513. }
  22514. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22515. {
  22516. return getMetaEventType() == 89;
  22517. }
  22518. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22519. {
  22520. return (int) *getMetaEventData();
  22521. }
  22522. const MidiMessage MidiMessage::endOfTrack() throw()
  22523. {
  22524. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22525. }
  22526. bool MidiMessage::isSongPositionPointer() const throw()
  22527. {
  22528. return *data == 0xf2;
  22529. }
  22530. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22531. {
  22532. return data[1] | (data[2] << 7);
  22533. }
  22534. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22535. {
  22536. return MidiMessage (0xf2,
  22537. positionInMidiBeats & 127,
  22538. (positionInMidiBeats >> 7) & 127);
  22539. }
  22540. bool MidiMessage::isMidiStart() const throw()
  22541. {
  22542. return *data == 0xfa;
  22543. }
  22544. const MidiMessage MidiMessage::midiStart() throw()
  22545. {
  22546. return MidiMessage (0xfa);
  22547. }
  22548. bool MidiMessage::isMidiContinue() const throw()
  22549. {
  22550. return *data == 0xfb;
  22551. }
  22552. const MidiMessage MidiMessage::midiContinue() throw()
  22553. {
  22554. return MidiMessage (0xfb);
  22555. }
  22556. bool MidiMessage::isMidiStop() const throw()
  22557. {
  22558. return *data == 0xfc;
  22559. }
  22560. const MidiMessage MidiMessage::midiStop() throw()
  22561. {
  22562. return MidiMessage (0xfc);
  22563. }
  22564. bool MidiMessage::isMidiClock() const throw()
  22565. {
  22566. return *data == 0xf8;
  22567. }
  22568. const MidiMessage MidiMessage::midiClock() throw()
  22569. {
  22570. return MidiMessage (0xf8);
  22571. }
  22572. bool MidiMessage::isQuarterFrame() const throw()
  22573. {
  22574. return *data == 0xf1;
  22575. }
  22576. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22577. {
  22578. return ((int) data[1]) >> 4;
  22579. }
  22580. int MidiMessage::getQuarterFrameValue() const throw()
  22581. {
  22582. return ((int) data[1]) & 0x0f;
  22583. }
  22584. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22585. const int value) throw()
  22586. {
  22587. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22588. }
  22589. bool MidiMessage::isFullFrame() const throw()
  22590. {
  22591. return data[0] == 0xf0
  22592. && data[1] == 0x7f
  22593. && size >= 10
  22594. && data[3] == 0x01
  22595. && data[4] == 0x01;
  22596. }
  22597. void MidiMessage::getFullFrameParameters (int& hours,
  22598. int& minutes,
  22599. int& seconds,
  22600. int& frames,
  22601. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22602. {
  22603. jassert (isFullFrame());
  22604. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22605. hours = data[5] & 0x1f;
  22606. minutes = data[6];
  22607. seconds = data[7];
  22608. frames = data[8];
  22609. }
  22610. const MidiMessage MidiMessage::fullFrame (const int hours,
  22611. const int minutes,
  22612. const int seconds,
  22613. const int frames,
  22614. MidiMessage::SmpteTimecodeType timecodeType)
  22615. {
  22616. uint8 d[10];
  22617. d[0] = 0xf0;
  22618. d[1] = 0x7f;
  22619. d[2] = 0x7f;
  22620. d[3] = 0x01;
  22621. d[4] = 0x01;
  22622. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22623. d[6] = (uint8) minutes;
  22624. d[7] = (uint8) seconds;
  22625. d[8] = (uint8) frames;
  22626. d[9] = 0xf7;
  22627. return MidiMessage (d, 10, 0.0);
  22628. }
  22629. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22630. {
  22631. return data[0] == 0xf0
  22632. && data[1] == 0x7f
  22633. && data[3] == 0x06
  22634. && size > 5;
  22635. }
  22636. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22637. {
  22638. jassert (isMidiMachineControlMessage());
  22639. return (MidiMachineControlCommand) data[4];
  22640. }
  22641. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22642. {
  22643. uint8 d[6];
  22644. d[0] = 0xf0;
  22645. d[1] = 0x7f;
  22646. d[2] = 0x00;
  22647. d[3] = 0x06;
  22648. d[4] = (uint8) command;
  22649. d[5] = 0xf7;
  22650. return MidiMessage (d, 6, 0.0);
  22651. }
  22652. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22653. int& minutes,
  22654. int& seconds,
  22655. int& frames) const throw()
  22656. {
  22657. if (size >= 12
  22658. && data[0] == 0xf0
  22659. && data[1] == 0x7f
  22660. && data[3] == 0x06
  22661. && data[4] == 0x44
  22662. && data[5] == 0x06
  22663. && data[6] == 0x01)
  22664. {
  22665. hours = data[7] % 24; // (that some machines send out hours > 24)
  22666. minutes = data[8];
  22667. seconds = data[9];
  22668. frames = data[10];
  22669. return true;
  22670. }
  22671. return false;
  22672. }
  22673. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22674. int minutes,
  22675. int seconds,
  22676. int frames)
  22677. {
  22678. uint8 d[12];
  22679. d[0] = 0xf0;
  22680. d[1] = 0x7f;
  22681. d[2] = 0x00;
  22682. d[3] = 0x06;
  22683. d[4] = 0x44;
  22684. d[5] = 0x06;
  22685. d[6] = 0x01;
  22686. d[7] = (uint8) hours;
  22687. d[8] = (uint8) minutes;
  22688. d[9] = (uint8) seconds;
  22689. d[10] = (uint8) frames;
  22690. d[11] = 0xf7;
  22691. return MidiMessage (d, 12, 0.0);
  22692. }
  22693. const String MidiMessage::getMidiNoteName (int note,
  22694. bool useSharps,
  22695. bool includeOctaveNumber,
  22696. int octaveNumForMiddleC) throw()
  22697. {
  22698. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22699. "F", "F#", "G", "G#", "A",
  22700. "A#", "B" };
  22701. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22702. "F", "Gb", "G", "Ab", "A",
  22703. "Bb", "B" };
  22704. if (((unsigned int) note) < 128)
  22705. {
  22706. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22707. : flatNoteNames [note % 12]);
  22708. if (includeOctaveNumber)
  22709. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22710. else
  22711. return s;
  22712. }
  22713. return String::empty;
  22714. }
  22715. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22716. {
  22717. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22718. return 440.0 * pow (2.0, noteNumber / 12.0);
  22719. }
  22720. const String MidiMessage::getGMInstrumentName (int n) throw()
  22721. {
  22722. const char *names[] =
  22723. {
  22724. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22725. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22726. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22727. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22728. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22729. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22730. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22731. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22732. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22733. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22734. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22735. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22736. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22737. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22738. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22739. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22740. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22741. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22742. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22743. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22744. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22745. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22746. "Applause", "Gunshot"
  22747. };
  22748. return (((unsigned int) n) < 128) ? names[n]
  22749. : (const char*)0;
  22750. }
  22751. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22752. {
  22753. const char* names[] =
  22754. {
  22755. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22756. "Bass", "Strings", "Ensemble", "Brass",
  22757. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22758. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22759. };
  22760. return (((unsigned int) n) <= 15) ? names[n]
  22761. : (const char*)0;
  22762. }
  22763. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22764. {
  22765. const char* names[] =
  22766. {
  22767. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22768. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22769. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22770. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22771. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22772. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22773. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22774. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22775. "Mute Triangle", "Open Triangle"
  22776. };
  22777. return (n >= 35 && n <= 81) ? names [n - 35]
  22778. : (const char*)0;
  22779. }
  22780. const String MidiMessage::getControllerName (int n) throw()
  22781. {
  22782. const char* names[] =
  22783. {
  22784. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22785. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22786. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22787. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22788. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22789. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22790. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22791. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22792. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22793. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22794. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22795. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22796. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22797. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22798. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22799. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22800. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22801. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22802. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22804. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22805. "Poly Operation"
  22806. };
  22807. return (((unsigned int) n) < 128) ? names[n]
  22808. : (const char*)0;
  22809. }
  22810. END_JUCE_NAMESPACE
  22811. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22812. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22813. BEGIN_JUCE_NAMESPACE
  22814. MidiMessageCollector::MidiMessageCollector()
  22815. : lastCallbackTime (0),
  22816. sampleRate (44100.0001)
  22817. {
  22818. }
  22819. MidiMessageCollector::~MidiMessageCollector()
  22820. {
  22821. }
  22822. void MidiMessageCollector::reset (const double sampleRate_)
  22823. {
  22824. jassert (sampleRate_ > 0);
  22825. const ScopedLock sl (midiCallbackLock);
  22826. sampleRate = sampleRate_;
  22827. incomingMessages.clear();
  22828. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22829. }
  22830. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22831. {
  22832. // you need to call reset() to set the correct sample rate before using this object
  22833. jassert (sampleRate != 44100.0001);
  22834. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22835. // for details of what the number should be.
  22836. jassert (message.getTimeStamp() != 0);
  22837. const ScopedLock sl (midiCallbackLock);
  22838. const int sampleNumber
  22839. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22840. incomingMessages.addEvent (message, sampleNumber);
  22841. // if the messages don't get used for over a second, we'd better
  22842. // get rid of any old ones to avoid the queue getting too big
  22843. if (sampleNumber > sampleRate)
  22844. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22845. }
  22846. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22847. const int numSamples)
  22848. {
  22849. // you need to call reset() to set the correct sample rate before using this object
  22850. jassert (sampleRate != 44100.0001);
  22851. const double timeNow = Time::getMillisecondCounterHiRes();
  22852. const double msElapsed = timeNow - lastCallbackTime;
  22853. const ScopedLock sl (midiCallbackLock);
  22854. lastCallbackTime = timeNow;
  22855. if (! incomingMessages.isEmpty())
  22856. {
  22857. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22858. int startSample = 0;
  22859. int scale = 1 << 16;
  22860. const uint8* midiData;
  22861. int numBytes, samplePosition;
  22862. MidiBuffer::Iterator iter (incomingMessages);
  22863. if (numSourceSamples > numSamples)
  22864. {
  22865. // if our list of events is longer than the buffer we're being
  22866. // asked for, scale them down to squeeze them all in..
  22867. const int maxBlockLengthToUse = numSamples << 5;
  22868. if (numSourceSamples > maxBlockLengthToUse)
  22869. {
  22870. startSample = numSourceSamples - maxBlockLengthToUse;
  22871. numSourceSamples = maxBlockLengthToUse;
  22872. iter.setNextSamplePosition (startSample);
  22873. }
  22874. scale = (numSamples << 10) / numSourceSamples;
  22875. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22876. {
  22877. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22878. destBuffer.addEvent (midiData, numBytes,
  22879. jlimit (0, numSamples - 1, samplePosition));
  22880. }
  22881. }
  22882. else
  22883. {
  22884. // if our event list is shorter than the number we need, put them
  22885. // towards the end of the buffer
  22886. startSample = numSamples - numSourceSamples;
  22887. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22888. {
  22889. destBuffer.addEvent (midiData, numBytes,
  22890. jlimit (0, numSamples - 1, samplePosition + startSample));
  22891. }
  22892. }
  22893. incomingMessages.clear();
  22894. }
  22895. }
  22896. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22897. {
  22898. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22899. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22900. addMessageToQueue (m);
  22901. }
  22902. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22903. {
  22904. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22905. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22906. addMessageToQueue (m);
  22907. }
  22908. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22909. {
  22910. addMessageToQueue (message);
  22911. }
  22912. END_JUCE_NAMESPACE
  22913. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22914. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22915. BEGIN_JUCE_NAMESPACE
  22916. MidiMessageSequence::MidiMessageSequence()
  22917. {
  22918. }
  22919. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22920. {
  22921. list.ensureStorageAllocated (other.list.size());
  22922. for (int i = 0; i < other.list.size(); ++i)
  22923. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22924. }
  22925. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22926. {
  22927. MidiMessageSequence otherCopy (other);
  22928. swapWith (otherCopy);
  22929. return *this;
  22930. }
  22931. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22932. {
  22933. list.swapWithArray (other.list);
  22934. }
  22935. MidiMessageSequence::~MidiMessageSequence()
  22936. {
  22937. }
  22938. void MidiMessageSequence::clear()
  22939. {
  22940. list.clear();
  22941. }
  22942. int MidiMessageSequence::getNumEvents() const
  22943. {
  22944. return list.size();
  22945. }
  22946. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22947. {
  22948. return list [index];
  22949. }
  22950. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22951. {
  22952. const MidiEventHolder* const meh = list [index];
  22953. if (meh != 0 && meh->noteOffObject != 0)
  22954. return meh->noteOffObject->message.getTimeStamp();
  22955. else
  22956. return 0.0;
  22957. }
  22958. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22959. {
  22960. const MidiEventHolder* const meh = list [index];
  22961. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22962. }
  22963. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22964. {
  22965. return list.indexOf (event);
  22966. }
  22967. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22968. {
  22969. const int numEvents = list.size();
  22970. int i;
  22971. for (i = 0; i < numEvents; ++i)
  22972. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  22973. break;
  22974. return i;
  22975. }
  22976. double MidiMessageSequence::getStartTime() const
  22977. {
  22978. if (list.size() > 0)
  22979. return list.getUnchecked(0)->message.getTimeStamp();
  22980. else
  22981. return 0;
  22982. }
  22983. double MidiMessageSequence::getEndTime() const
  22984. {
  22985. if (list.size() > 0)
  22986. return list.getLast()->message.getTimeStamp();
  22987. else
  22988. return 0;
  22989. }
  22990. double MidiMessageSequence::getEventTime (const int index) const
  22991. {
  22992. if (((unsigned int) index) < (unsigned int) list.size())
  22993. return list.getUnchecked (index)->message.getTimeStamp();
  22994. return 0.0;
  22995. }
  22996. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  22997. double timeAdjustment)
  22998. {
  22999. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23000. timeAdjustment += newMessage.getTimeStamp();
  23001. newOne->message.setTimeStamp (timeAdjustment);
  23002. int i;
  23003. for (i = list.size(); --i >= 0;)
  23004. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23005. break;
  23006. list.insert (i + 1, newOne);
  23007. }
  23008. void MidiMessageSequence::deleteEvent (const int index,
  23009. const bool deleteMatchingNoteUp)
  23010. {
  23011. if (((unsigned int) index) < (unsigned int) list.size())
  23012. {
  23013. if (deleteMatchingNoteUp)
  23014. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23015. list.remove (index);
  23016. }
  23017. }
  23018. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23019. double timeAdjustment,
  23020. double firstAllowableTime,
  23021. double endOfAllowableDestTimes)
  23022. {
  23023. firstAllowableTime -= timeAdjustment;
  23024. endOfAllowableDestTimes -= timeAdjustment;
  23025. for (int i = 0; i < other.list.size(); ++i)
  23026. {
  23027. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23028. const double t = m.getTimeStamp();
  23029. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23030. {
  23031. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23032. newOne->message.setTimeStamp (timeAdjustment + t);
  23033. list.add (newOne);
  23034. }
  23035. }
  23036. sort();
  23037. }
  23038. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23039. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23040. {
  23041. const double diff = first->message.getTimeStamp()
  23042. - second->message.getTimeStamp();
  23043. return (diff > 0) - (diff < 0);
  23044. }
  23045. void MidiMessageSequence::sort()
  23046. {
  23047. list.sort (*this, true);
  23048. }
  23049. void MidiMessageSequence::updateMatchedPairs()
  23050. {
  23051. for (int i = 0; i < list.size(); ++i)
  23052. {
  23053. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23054. if (m1.isNoteOn())
  23055. {
  23056. list.getUnchecked(i)->noteOffObject = 0;
  23057. const int note = m1.getNoteNumber();
  23058. const int chan = m1.getChannel();
  23059. const int len = list.size();
  23060. for (int j = i + 1; j < len; ++j)
  23061. {
  23062. const MidiMessage& m = list.getUnchecked(j)->message;
  23063. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23064. {
  23065. if (m.isNoteOff())
  23066. {
  23067. list.getUnchecked(i)->noteOffObject = list[j];
  23068. break;
  23069. }
  23070. else if (m.isNoteOn())
  23071. {
  23072. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23073. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23074. list.getUnchecked(i)->noteOffObject = list[j];
  23075. break;
  23076. }
  23077. }
  23078. }
  23079. }
  23080. }
  23081. }
  23082. void MidiMessageSequence::addTimeToMessages (const double delta)
  23083. {
  23084. for (int i = list.size(); --i >= 0;)
  23085. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23086. + delta);
  23087. }
  23088. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23089. MidiMessageSequence& destSequence,
  23090. const bool alsoIncludeMetaEvents) const
  23091. {
  23092. for (int i = 0; i < list.size(); ++i)
  23093. {
  23094. const MidiMessage& mm = list.getUnchecked(i)->message;
  23095. if (mm.isForChannel (channelNumberToExtract)
  23096. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23097. {
  23098. destSequence.addEvent (mm);
  23099. }
  23100. }
  23101. }
  23102. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23103. {
  23104. for (int i = 0; i < list.size(); ++i)
  23105. {
  23106. const MidiMessage& mm = list.getUnchecked(i)->message;
  23107. if (mm.isSysEx())
  23108. destSequence.addEvent (mm);
  23109. }
  23110. }
  23111. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23112. {
  23113. for (int i = list.size(); --i >= 0;)
  23114. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23115. list.remove(i);
  23116. }
  23117. void MidiMessageSequence::deleteSysExMessages()
  23118. {
  23119. for (int i = list.size(); --i >= 0;)
  23120. if (list.getUnchecked(i)->message.isSysEx())
  23121. list.remove(i);
  23122. }
  23123. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23124. const double time,
  23125. OwnedArray<MidiMessage>& dest)
  23126. {
  23127. bool doneProg = false;
  23128. bool donePitchWheel = false;
  23129. Array <int> doneControllers;
  23130. doneControllers.ensureStorageAllocated (32);
  23131. for (int i = list.size(); --i >= 0;)
  23132. {
  23133. const MidiMessage& mm = list.getUnchecked(i)->message;
  23134. if (mm.isForChannel (channelNumber)
  23135. && mm.getTimeStamp() <= time)
  23136. {
  23137. if (mm.isProgramChange())
  23138. {
  23139. if (! doneProg)
  23140. {
  23141. dest.add (new MidiMessage (mm, 0.0));
  23142. doneProg = true;
  23143. }
  23144. }
  23145. else if (mm.isController())
  23146. {
  23147. if (! doneControllers.contains (mm.getControllerNumber()))
  23148. {
  23149. dest.add (new MidiMessage (mm, 0.0));
  23150. doneControllers.add (mm.getControllerNumber());
  23151. }
  23152. }
  23153. else if (mm.isPitchWheel())
  23154. {
  23155. if (! donePitchWheel)
  23156. {
  23157. dest.add (new MidiMessage (mm, 0.0));
  23158. donePitchWheel = true;
  23159. }
  23160. }
  23161. }
  23162. }
  23163. }
  23164. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23165. : message (message_),
  23166. noteOffObject (0)
  23167. {
  23168. }
  23169. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23170. {
  23171. }
  23172. END_JUCE_NAMESPACE
  23173. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23174. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23175. BEGIN_JUCE_NAMESPACE
  23176. AudioPluginFormat::AudioPluginFormat() throw()
  23177. {
  23178. }
  23179. AudioPluginFormat::~AudioPluginFormat()
  23180. {
  23181. }
  23182. END_JUCE_NAMESPACE
  23183. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23184. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23185. BEGIN_JUCE_NAMESPACE
  23186. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23187. {
  23188. }
  23189. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23190. {
  23191. clearSingletonInstance();
  23192. }
  23193. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23194. void AudioPluginFormatManager::addDefaultFormats()
  23195. {
  23196. #ifdef JUCE_DEBUG
  23197. // you should only call this method once!
  23198. for (int i = formats.size(); --i >= 0;)
  23199. {
  23200. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23201. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23202. #endif
  23203. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23204. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23205. #endif
  23206. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23207. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23208. #endif
  23209. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23210. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23211. #endif
  23212. }
  23213. #endif
  23214. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23215. formats.add (new AudioUnitPluginFormat());
  23216. #endif
  23217. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23218. formats.add (new VSTPluginFormat());
  23219. #endif
  23220. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23221. formats.add (new DirectXPluginFormat());
  23222. #endif
  23223. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23224. formats.add (new LADSPAPluginFormat());
  23225. #endif
  23226. }
  23227. int AudioPluginFormatManager::getNumFormats() throw()
  23228. {
  23229. return formats.size();
  23230. }
  23231. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23232. {
  23233. return formats [index];
  23234. }
  23235. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23236. {
  23237. formats.add (format);
  23238. }
  23239. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23240. String& errorMessage) const
  23241. {
  23242. AudioPluginInstance* result = 0;
  23243. for (int i = 0; i < formats.size(); ++i)
  23244. {
  23245. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23246. if (result != 0)
  23247. break;
  23248. }
  23249. if (result == 0)
  23250. {
  23251. if (! doesPluginStillExist (description))
  23252. errorMessage = TRANS ("This plug-in file no longer exists");
  23253. else
  23254. errorMessage = TRANS ("This plug-in failed to load correctly");
  23255. }
  23256. return result;
  23257. }
  23258. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23259. {
  23260. for (int i = 0; i < formats.size(); ++i)
  23261. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23262. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23263. return false;
  23264. }
  23265. END_JUCE_NAMESPACE
  23266. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23267. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23268. #define JUCE_PLUGIN_HOST 1
  23269. BEGIN_JUCE_NAMESPACE
  23270. AudioPluginInstance::AudioPluginInstance()
  23271. {
  23272. }
  23273. AudioPluginInstance::~AudioPluginInstance()
  23274. {
  23275. }
  23276. END_JUCE_NAMESPACE
  23277. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23278. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23279. BEGIN_JUCE_NAMESPACE
  23280. KnownPluginList::KnownPluginList()
  23281. {
  23282. }
  23283. KnownPluginList::~KnownPluginList()
  23284. {
  23285. }
  23286. void KnownPluginList::clear()
  23287. {
  23288. if (types.size() > 0)
  23289. {
  23290. types.clear();
  23291. sendChangeMessage (this);
  23292. }
  23293. }
  23294. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23295. {
  23296. for (int i = 0; i < types.size(); ++i)
  23297. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23298. return types.getUnchecked(i);
  23299. return 0;
  23300. }
  23301. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23302. {
  23303. for (int i = 0; i < types.size(); ++i)
  23304. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23305. return types.getUnchecked(i);
  23306. return 0;
  23307. }
  23308. bool KnownPluginList::addType (const PluginDescription& type)
  23309. {
  23310. for (int i = types.size(); --i >= 0;)
  23311. {
  23312. if (types.getUnchecked(i)->isDuplicateOf (type))
  23313. {
  23314. // strange - found a duplicate plugin with different info..
  23315. jassert (types.getUnchecked(i)->name == type.name);
  23316. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23317. *types.getUnchecked(i) = type;
  23318. return false;
  23319. }
  23320. }
  23321. types.add (new PluginDescription (type));
  23322. sendChangeMessage (this);
  23323. return true;
  23324. }
  23325. void KnownPluginList::removeType (const int index) throw()
  23326. {
  23327. types.remove (index);
  23328. sendChangeMessage (this);
  23329. }
  23330. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23331. {
  23332. if (fileOrIdentifier.startsWithChar ('/')
  23333. || fileOrIdentifier[1] == ':')
  23334. {
  23335. return File (fileOrIdentifier).getLastModificationTime();
  23336. }
  23337. return Time (0);
  23338. }
  23339. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23340. {
  23341. return t1 != t2 || t1 == Time (0);
  23342. }
  23343. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23344. {
  23345. if (getTypeForFile (fileOrIdentifier) == 0)
  23346. return false;
  23347. for (int i = types.size(); --i >= 0;)
  23348. {
  23349. const PluginDescription* const d = types.getUnchecked(i);
  23350. if (d->fileOrIdentifier == fileOrIdentifier
  23351. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23352. {
  23353. return false;
  23354. }
  23355. }
  23356. return true;
  23357. }
  23358. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23359. const bool dontRescanIfAlreadyInList,
  23360. OwnedArray <PluginDescription>& typesFound,
  23361. AudioPluginFormat& format)
  23362. {
  23363. bool addedOne = false;
  23364. if (dontRescanIfAlreadyInList
  23365. && getTypeForFile (fileOrIdentifier) != 0)
  23366. {
  23367. bool needsRescanning = false;
  23368. for (int i = types.size(); --i >= 0;)
  23369. {
  23370. const PluginDescription* const d = types.getUnchecked(i);
  23371. if (d->fileOrIdentifier == fileOrIdentifier)
  23372. {
  23373. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23374. needsRescanning = true;
  23375. else
  23376. typesFound.add (new PluginDescription (*d));
  23377. }
  23378. }
  23379. if (! needsRescanning)
  23380. return false;
  23381. }
  23382. OwnedArray <PluginDescription> found;
  23383. format.findAllTypesForFile (found, fileOrIdentifier);
  23384. for (int i = 0; i < found.size(); ++i)
  23385. {
  23386. PluginDescription* const desc = found.getUnchecked(i);
  23387. jassert (desc != 0);
  23388. if (addType (*desc))
  23389. addedOne = true;
  23390. typesFound.add (new PluginDescription (*desc));
  23391. }
  23392. return addedOne;
  23393. }
  23394. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23395. OwnedArray <PluginDescription>& typesFound)
  23396. {
  23397. for (int i = 0; i < files.size(); ++i)
  23398. {
  23399. bool loaded = false;
  23400. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23401. {
  23402. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23403. if (scanAndAddFile (files[i], true, typesFound, *format))
  23404. loaded = true;
  23405. }
  23406. if (! loaded)
  23407. {
  23408. const File f (files[i]);
  23409. if (f.isDirectory())
  23410. {
  23411. StringArray s;
  23412. {
  23413. Array<File> subFiles;
  23414. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23415. for (int j = 0; j < subFiles.size(); ++j)
  23416. s.add (subFiles.getReference(j).getFullPathName());
  23417. }
  23418. scanAndAddDragAndDroppedFiles (s, typesFound);
  23419. }
  23420. }
  23421. }
  23422. }
  23423. class PluginSorter
  23424. {
  23425. public:
  23426. KnownPluginList::SortMethod method;
  23427. PluginSorter() throw() {}
  23428. int compareElements (const PluginDescription* const first,
  23429. const PluginDescription* const second) const throw()
  23430. {
  23431. int diff = 0;
  23432. if (method == KnownPluginList::sortByCategory)
  23433. diff = first->category.compareLexicographically (second->category);
  23434. else if (method == KnownPluginList::sortByManufacturer)
  23435. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23436. else if (method == KnownPluginList::sortByFileSystemLocation)
  23437. diff = first->fileOrIdentifier.replaceCharacter ('\\', '/')
  23438. .upToLastOccurrenceOf ("/", false, false)
  23439. .compare (second->fileOrIdentifier.replaceCharacter ('\\', '/')
  23440. .upToLastOccurrenceOf ("/", false, false));
  23441. if (diff == 0)
  23442. diff = first->name.compareLexicographically (second->name);
  23443. return diff;
  23444. }
  23445. };
  23446. void KnownPluginList::sort (const SortMethod method)
  23447. {
  23448. if (method != defaultOrder)
  23449. {
  23450. PluginSorter sorter;
  23451. sorter.method = method;
  23452. types.sort (sorter, true);
  23453. sendChangeMessage (this);
  23454. }
  23455. }
  23456. XmlElement* KnownPluginList::createXml() const
  23457. {
  23458. XmlElement* const e = new XmlElement ("KNOWNPLUGINS");
  23459. for (int i = 0; i < types.size(); ++i)
  23460. e->addChildElement (types.getUnchecked(i)->createXml());
  23461. return e;
  23462. }
  23463. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23464. {
  23465. clear();
  23466. if (xml.hasTagName ("KNOWNPLUGINS"))
  23467. {
  23468. forEachXmlChildElement (xml, e)
  23469. {
  23470. PluginDescription info;
  23471. if (info.loadFromXml (*e))
  23472. addType (info);
  23473. }
  23474. }
  23475. }
  23476. const int menuIdBase = 0x324503f4;
  23477. // This is used to turn a bunch of paths into a nested menu structure.
  23478. struct PluginFilesystemTree
  23479. {
  23480. private:
  23481. String folder;
  23482. OwnedArray <PluginFilesystemTree> subFolders;
  23483. Array <PluginDescription*> plugins;
  23484. void addPlugin (PluginDescription* const pd, const String& path)
  23485. {
  23486. if (path.isEmpty())
  23487. {
  23488. plugins.add (pd);
  23489. }
  23490. else
  23491. {
  23492. const String firstSubFolder (path.upToFirstOccurrenceOf ("/", false, false));
  23493. const String remainingPath (path.fromFirstOccurrenceOf ("/", false, false));
  23494. for (int i = subFolders.size(); --i >= 0;)
  23495. {
  23496. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23497. {
  23498. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23499. return;
  23500. }
  23501. }
  23502. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23503. newFolder->folder = firstSubFolder;
  23504. subFolders.add (newFolder);
  23505. newFolder->addPlugin (pd, remainingPath);
  23506. }
  23507. }
  23508. // removes any deeply nested folders that don't contain any actual plugins
  23509. void optimise()
  23510. {
  23511. for (int i = subFolders.size(); --i >= 0;)
  23512. {
  23513. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23514. sub->optimise();
  23515. if (sub->plugins.size() == 0)
  23516. {
  23517. for (int j = 0; j < sub->subFolders.size(); ++j)
  23518. subFolders.add (sub->subFolders.getUnchecked(j));
  23519. sub->subFolders.clear (false);
  23520. subFolders.remove (i);
  23521. }
  23522. }
  23523. }
  23524. public:
  23525. void buildTree (const Array <PluginDescription*>& allPlugins)
  23526. {
  23527. for (int i = 0; i < allPlugins.size(); ++i)
  23528. {
  23529. String path (allPlugins.getUnchecked(i)
  23530. ->fileOrIdentifier.replaceCharacter ('\\', '/')
  23531. .upToLastOccurrenceOf ("/", false, false));
  23532. if (path.substring (1, 2) == ":")
  23533. path = path.substring (2);
  23534. addPlugin (allPlugins.getUnchecked(i), path);
  23535. }
  23536. optimise();
  23537. }
  23538. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23539. {
  23540. int i;
  23541. for (i = 0; i < subFolders.size(); ++i)
  23542. {
  23543. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23544. PopupMenu subMenu;
  23545. sub->addToMenu (subMenu, allPlugins);
  23546. #if JUCE_MAC
  23547. // avoid the special AU formatting nonsense on Mac..
  23548. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (":", false, false), subMenu);
  23549. #else
  23550. m.addSubMenu (sub->folder, subMenu);
  23551. #endif
  23552. }
  23553. for (i = 0; i < plugins.size(); ++i)
  23554. {
  23555. PluginDescription* const plugin = plugins.getUnchecked(i);
  23556. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23557. plugin->name, true, false);
  23558. }
  23559. }
  23560. };
  23561. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23562. {
  23563. Array <PluginDescription*> sorted;
  23564. {
  23565. PluginSorter sorter;
  23566. sorter.method = sortMethod;
  23567. for (int i = 0; i < types.size(); ++i)
  23568. sorted.addSorted (sorter, types.getUnchecked(i));
  23569. }
  23570. if (sortMethod == sortByCategory
  23571. || sortMethod == sortByManufacturer)
  23572. {
  23573. String lastSubMenuName;
  23574. PopupMenu sub;
  23575. for (int i = 0; i < sorted.size(); ++i)
  23576. {
  23577. const PluginDescription* const pd = sorted.getUnchecked(i);
  23578. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23579. : pd->manufacturerName);
  23580. if (! thisSubMenuName.containsNonWhitespaceChars())
  23581. thisSubMenuName = "Other";
  23582. if (thisSubMenuName != lastSubMenuName)
  23583. {
  23584. if (sub.getNumItems() > 0)
  23585. {
  23586. menu.addSubMenu (lastSubMenuName, sub);
  23587. sub.clear();
  23588. }
  23589. lastSubMenuName = thisSubMenuName;
  23590. }
  23591. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23592. }
  23593. if (sub.getNumItems() > 0)
  23594. menu.addSubMenu (lastSubMenuName, sub);
  23595. }
  23596. else if (sortMethod == sortByFileSystemLocation)
  23597. {
  23598. PluginFilesystemTree root;
  23599. root.buildTree (sorted);
  23600. root.addToMenu (menu, types);
  23601. }
  23602. else
  23603. {
  23604. for (int i = 0; i < sorted.size(); ++i)
  23605. {
  23606. const PluginDescription* const pd = sorted.getUnchecked(i);
  23607. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23608. }
  23609. }
  23610. }
  23611. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23612. {
  23613. const int i = menuResultCode - menuIdBase;
  23614. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23615. }
  23616. END_JUCE_NAMESPACE
  23617. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23618. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23619. BEGIN_JUCE_NAMESPACE
  23620. PluginDescription::PluginDescription() throw()
  23621. : uid (0),
  23622. isInstrument (false),
  23623. numInputChannels (0),
  23624. numOutputChannels (0)
  23625. {
  23626. }
  23627. PluginDescription::~PluginDescription() throw()
  23628. {
  23629. }
  23630. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23631. : name (other.name),
  23632. pluginFormatName (other.pluginFormatName),
  23633. category (other.category),
  23634. manufacturerName (other.manufacturerName),
  23635. version (other.version),
  23636. fileOrIdentifier (other.fileOrIdentifier),
  23637. lastFileModTime (other.lastFileModTime),
  23638. uid (other.uid),
  23639. isInstrument (other.isInstrument),
  23640. numInputChannels (other.numInputChannels),
  23641. numOutputChannels (other.numOutputChannels)
  23642. {
  23643. }
  23644. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23645. {
  23646. name = other.name;
  23647. pluginFormatName = other.pluginFormatName;
  23648. category = other.category;
  23649. manufacturerName = other.manufacturerName;
  23650. version = other.version;
  23651. fileOrIdentifier = other.fileOrIdentifier;
  23652. uid = other.uid;
  23653. isInstrument = other.isInstrument;
  23654. lastFileModTime = other.lastFileModTime;
  23655. numInputChannels = other.numInputChannels;
  23656. numOutputChannels = other.numOutputChannels;
  23657. return *this;
  23658. }
  23659. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23660. {
  23661. return fileOrIdentifier == other.fileOrIdentifier
  23662. && uid == other.uid;
  23663. }
  23664. const String PluginDescription::createIdentifierString() const throw()
  23665. {
  23666. return pluginFormatName
  23667. + "-" + name
  23668. + "-" + String::toHexString (fileOrIdentifier.hashCode())
  23669. + "-" + String::toHexString (uid);
  23670. }
  23671. XmlElement* PluginDescription::createXml() const
  23672. {
  23673. XmlElement* const e = new XmlElement ("PLUGIN");
  23674. e->setAttribute ("name", name);
  23675. e->setAttribute ("format", pluginFormatName);
  23676. e->setAttribute ("category", category);
  23677. e->setAttribute ("manufacturer", manufacturerName);
  23678. e->setAttribute ("version", version);
  23679. e->setAttribute ("file", fileOrIdentifier);
  23680. e->setAttribute ("uid", String::toHexString (uid));
  23681. e->setAttribute ("isInstrument", isInstrument);
  23682. e->setAttribute ("fileTime", String::toHexString (lastFileModTime.toMilliseconds()));
  23683. e->setAttribute ("numInputs", numInputChannels);
  23684. e->setAttribute ("numOutputs", numOutputChannels);
  23685. return e;
  23686. }
  23687. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23688. {
  23689. if (xml.hasTagName ("PLUGIN"))
  23690. {
  23691. name = xml.getStringAttribute ("name");
  23692. pluginFormatName = xml.getStringAttribute ("format");
  23693. category = xml.getStringAttribute ("category");
  23694. manufacturerName = xml.getStringAttribute ("manufacturer");
  23695. version = xml.getStringAttribute ("version");
  23696. fileOrIdentifier = xml.getStringAttribute ("file");
  23697. uid = xml.getStringAttribute ("uid").getHexValue32();
  23698. isInstrument = xml.getBoolAttribute ("isInstrument", false);
  23699. lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64());
  23700. numInputChannels = xml.getIntAttribute ("numInputs");
  23701. numOutputChannels = xml.getIntAttribute ("numOutputs");
  23702. return true;
  23703. }
  23704. return false;
  23705. }
  23706. END_JUCE_NAMESPACE
  23707. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23708. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23709. BEGIN_JUCE_NAMESPACE
  23710. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23711. AudioPluginFormat& formatToLookFor,
  23712. FileSearchPath directoriesToSearch,
  23713. const bool recursive,
  23714. const File& deadMansPedalFile_)
  23715. : list (listToAddTo),
  23716. format (formatToLookFor),
  23717. deadMansPedalFile (deadMansPedalFile_),
  23718. nextIndex (0),
  23719. progress (0)
  23720. {
  23721. directoriesToSearch.removeRedundantPaths();
  23722. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23723. // If any plugins have crashed recently when being loaded, move them to the
  23724. // end of the list to give the others a chance to load correctly..
  23725. const StringArray crashedPlugins (getDeadMansPedalFile());
  23726. for (int i = 0; i < crashedPlugins.size(); ++i)
  23727. {
  23728. const String f = crashedPlugins[i];
  23729. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23730. if (f == filesOrIdentifiersToScan[j])
  23731. filesOrIdentifiersToScan.move (j, -1);
  23732. }
  23733. }
  23734. PluginDirectoryScanner::~PluginDirectoryScanner()
  23735. {
  23736. }
  23737. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23738. {
  23739. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23740. }
  23741. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23742. {
  23743. String file (filesOrIdentifiersToScan [nextIndex]);
  23744. if (file.isNotEmpty())
  23745. {
  23746. if (! list.isListingUpToDate (file))
  23747. {
  23748. OwnedArray <PluginDescription> typesFound;
  23749. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23750. StringArray crashedPlugins (getDeadMansPedalFile());
  23751. crashedPlugins.removeString (file);
  23752. crashedPlugins.add (file);
  23753. setDeadMansPedalFile (crashedPlugins);
  23754. list.scanAndAddFile (file,
  23755. dontRescanIfAlreadyInList,
  23756. typesFound,
  23757. format);
  23758. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23759. crashedPlugins.removeString (file);
  23760. setDeadMansPedalFile (crashedPlugins);
  23761. if (typesFound.size() == 0)
  23762. failedFiles.add (file);
  23763. }
  23764. ++nextIndex;
  23765. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23766. }
  23767. return nextIndex < filesOrIdentifiersToScan.size();
  23768. }
  23769. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23770. {
  23771. StringArray lines;
  23772. if (deadMansPedalFile != File::nonexistent)
  23773. {
  23774. lines.addLines (deadMansPedalFile.loadFileAsString());
  23775. lines.removeEmptyStrings();
  23776. }
  23777. return lines;
  23778. }
  23779. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23780. {
  23781. if (deadMansPedalFile != File::nonexistent)
  23782. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23783. }
  23784. END_JUCE_NAMESPACE
  23785. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23786. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23787. BEGIN_JUCE_NAMESPACE
  23788. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23789. const File& deadMansPedalFile_,
  23790. PropertiesFile* const propertiesToUse_)
  23791. : list (listToEdit),
  23792. deadMansPedalFile (deadMansPedalFile_),
  23793. propertiesToUse (propertiesToUse_)
  23794. {
  23795. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23796. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23797. optionsButton->addButtonListener (this);
  23798. optionsButton->setTriggeredOnMouseDown (true);
  23799. setSize (400, 600);
  23800. list.addChangeListener (this);
  23801. }
  23802. PluginListComponent::~PluginListComponent()
  23803. {
  23804. list.removeChangeListener (this);
  23805. deleteAllChildren();
  23806. }
  23807. void PluginListComponent::resized()
  23808. {
  23809. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23810. optionsButton->changeWidthToFitText (24);
  23811. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23812. }
  23813. void PluginListComponent::changeListenerCallback (void*)
  23814. {
  23815. listBox->updateContent();
  23816. listBox->repaint();
  23817. }
  23818. int PluginListComponent::getNumRows()
  23819. {
  23820. return list.getNumTypes();
  23821. }
  23822. void PluginListComponent::paintListBoxItem (int row,
  23823. Graphics& g,
  23824. int width, int height,
  23825. bool rowIsSelected)
  23826. {
  23827. if (rowIsSelected)
  23828. g.fillAll (findColour (TextEditor::highlightColourId));
  23829. const PluginDescription* const pd = list.getType (row);
  23830. if (pd != 0)
  23831. {
  23832. GlyphArrangement ga;
  23833. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23834. g.setColour (Colours::black);
  23835. ga.draw (g);
  23836. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  23837. String desc;
  23838. desc << pd->pluginFormatName
  23839. << (pd->isInstrument ? " instrument" : " effect")
  23840. << " - "
  23841. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23842. << " / "
  23843. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23844. if (pd->manufacturerName.isNotEmpty())
  23845. desc << " - " << pd->manufacturerName;
  23846. if (pd->version.isNotEmpty())
  23847. desc << " - " << pd->version;
  23848. if (pd->category.isNotEmpty())
  23849. desc << " - category: '" << pd->category << '\'';
  23850. g.setColour (Colours::grey);
  23851. ga.clear();
  23852. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, bb.getRight() + 10.0f, height * 0.8f, width - bb.getRight() - 12.0f, true);
  23853. ga.draw (g);
  23854. }
  23855. }
  23856. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23857. {
  23858. list.removeType (lastRowSelected);
  23859. }
  23860. void PluginListComponent::buttonClicked (Button* b)
  23861. {
  23862. if (optionsButton == b)
  23863. {
  23864. PopupMenu menu;
  23865. menu.addItem (1, TRANS("Clear list"));
  23866. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23867. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23868. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23869. menu.addSeparator();
  23870. menu.addItem (2, TRANS("Sort alphabetically"));
  23871. menu.addItem (3, TRANS("Sort by category"));
  23872. menu.addItem (4, TRANS("Sort by manufacturer"));
  23873. menu.addSeparator();
  23874. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23875. {
  23876. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23877. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23878. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23879. }
  23880. const int r = menu.showAt (optionsButton);
  23881. if (r == 1)
  23882. {
  23883. list.clear();
  23884. }
  23885. else if (r == 2)
  23886. {
  23887. list.sort (KnownPluginList::sortAlphabetically);
  23888. }
  23889. else if (r == 3)
  23890. {
  23891. list.sort (KnownPluginList::sortByCategory);
  23892. }
  23893. else if (r == 4)
  23894. {
  23895. list.sort (KnownPluginList::sortByManufacturer);
  23896. }
  23897. else if (r == 5)
  23898. {
  23899. const SparseSet <int> selected (listBox->getSelectedRows());
  23900. for (int i = list.getNumTypes(); --i >= 0;)
  23901. if (selected.contains (i))
  23902. list.removeType (i);
  23903. }
  23904. else if (r == 6)
  23905. {
  23906. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23907. if (desc != 0)
  23908. {
  23909. if (File (desc->fileOrIdentifier).existsAsFile())
  23910. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23911. }
  23912. }
  23913. else if (r == 7)
  23914. {
  23915. for (int i = list.getNumTypes(); --i >= 0;)
  23916. {
  23917. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23918. {
  23919. list.removeType (i);
  23920. }
  23921. }
  23922. }
  23923. else if (r != 0)
  23924. {
  23925. typeToScan = r - 10;
  23926. startTimer (1);
  23927. }
  23928. }
  23929. }
  23930. void PluginListComponent::timerCallback()
  23931. {
  23932. stopTimer();
  23933. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23934. }
  23935. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23936. {
  23937. return true;
  23938. }
  23939. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23940. {
  23941. OwnedArray <PluginDescription> typesFound;
  23942. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23943. }
  23944. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23945. {
  23946. if (format == 0)
  23947. return;
  23948. FileSearchPath path (format->getDefaultLocationsToSearch());
  23949. if (propertiesToUse != 0)
  23950. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23951. {
  23952. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23953. FileSearchPathListComponent pathList;
  23954. pathList.setSize (500, 300);
  23955. pathList.setPath (path);
  23956. aw.addCustomComponent (&pathList);
  23957. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23958. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23959. if (aw.runModalLoop() == 0)
  23960. return;
  23961. path = pathList.getPath();
  23962. }
  23963. if (propertiesToUse != 0)
  23964. {
  23965. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23966. propertiesToUse->saveIfNeeded();
  23967. }
  23968. double progress = 0.0;
  23969. AlertWindow aw (TRANS("Scanning for plugins..."),
  23970. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23971. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23972. aw.addProgressBarComponent (progress);
  23973. aw.enterModalState();
  23974. MessageManager::getInstance()->runDispatchLoopUntil (300);
  23975. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  23976. for (;;)
  23977. {
  23978. aw.setMessage (TRANS("Testing:\n\n")
  23979. + scanner.getNextPluginFileThatWillBeScanned());
  23980. MessageManager::getInstance()->runDispatchLoopUntil (20);
  23981. if (! scanner.scanNextFile (true))
  23982. break;
  23983. if (! aw.isCurrentlyModal())
  23984. break;
  23985. progress = scanner.getProgress();
  23986. }
  23987. if (scanner.getFailedFiles().size() > 0)
  23988. {
  23989. StringArray shortNames;
  23990. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  23991. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  23992. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  23993. TRANS("Scan complete"),
  23994. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  23995. + shortNames.joinIntoString (", "));
  23996. }
  23997. }
  23998. END_JUCE_NAMESPACE
  23999. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24000. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24001. #if JUCE_PLUGINHOST_AU && ! (JUCE_LINUX || JUCE_WINDOWS)
  24002. #include <AudioUnit/AudioUnit.h>
  24003. #include <AudioUnit/AUCocoaUIView.h>
  24004. #include <CoreAudioKit/AUGenericView.h>
  24005. #if JUCE_SUPPORT_CARBON
  24006. #include <AudioToolbox/AudioUnitUtilities.h>
  24007. #include <AudioUnit/AudioUnitCarbonView.h>
  24008. #endif
  24009. BEGIN_JUCE_NAMESPACE
  24010. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24011. #endif
  24012. #if JUCE_MAC
  24013. // Change this to disable logging of various activities
  24014. #ifndef AU_LOGGING
  24015. #define AU_LOGGING 1
  24016. #endif
  24017. #if AU_LOGGING
  24018. #define log(a) Logger::writeToLog(a);
  24019. #else
  24020. #define log(a)
  24021. #endif
  24022. static int insideCallback = 0;
  24023. static const String osTypeToString (OSType type)
  24024. {
  24025. char s[4];
  24026. s[0] = (char) (((uint32) type) >> 24);
  24027. s[1] = (char) (((uint32) type) >> 16);
  24028. s[2] = (char) (((uint32) type) >> 8);
  24029. s[3] = (char) ((uint32) type);
  24030. return String (s, 4);
  24031. }
  24032. static OSType stringToOSType (const String& s1)
  24033. {
  24034. const String s (s1 + " ");
  24035. return (((OSType) (unsigned char) s[0]) << 24)
  24036. | (((OSType) (unsigned char) s[1]) << 16)
  24037. | (((OSType) (unsigned char) s[2]) << 8)
  24038. | ((OSType) (unsigned char) s[3]);
  24039. }
  24040. static const char* auIdentifierPrefix = "AudioUnit:";
  24041. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24042. {
  24043. jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong..
  24044. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24045. String s (auIdentifierPrefix);
  24046. if (desc.componentType == kAudioUnitType_MusicDevice)
  24047. s << "Synths/";
  24048. else if (desc.componentType == kAudioUnitType_MusicEffect
  24049. || desc.componentType == kAudioUnitType_Effect)
  24050. s << "Effects/";
  24051. else if (desc.componentType == kAudioUnitType_Generator)
  24052. s << "Generators/";
  24053. else if (desc.componentType == kAudioUnitType_Panner)
  24054. s << "Panners/";
  24055. s << osTypeToString (desc.componentType) << ","
  24056. << osTypeToString (desc.componentSubType) << ","
  24057. << osTypeToString (desc.componentManufacturer);
  24058. return s;
  24059. }
  24060. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24061. {
  24062. Handle componentNameHandle = NewHandle (sizeof (void*));
  24063. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24064. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24065. {
  24066. ComponentDescription desc;
  24067. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24068. {
  24069. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24070. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24071. if (nameString != 0 && nameString[0] != 0)
  24072. {
  24073. const String all ((const char*) nameString + 1, nameString[0]);
  24074. DBG ("name: "+ all);
  24075. manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim();
  24076. name = all.fromFirstOccurrenceOf (":", false, false).trim();
  24077. }
  24078. if (infoString != 0 && infoString[0] != 0)
  24079. {
  24080. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  24081. }
  24082. if (name.isEmpty())
  24083. name = "<Unknown>";
  24084. }
  24085. DisposeHandle (componentNameHandle);
  24086. DisposeHandle (componentInfoHandle);
  24087. }
  24088. }
  24089. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24090. String& name, String& version, String& manufacturer)
  24091. {
  24092. zerostruct (desc);
  24093. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24094. {
  24095. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'),
  24096. fileOrIdentifier.lastIndexOfChar ('/')) + 1));
  24097. StringArray tokens;
  24098. tokens.addTokens (s, ",", String::empty);
  24099. tokens.trim();
  24100. tokens.removeEmptyStrings();
  24101. if (tokens.size() == 3)
  24102. {
  24103. desc.componentType = stringToOSType (tokens[0]);
  24104. desc.componentSubType = stringToOSType (tokens[1]);
  24105. desc.componentManufacturer = stringToOSType (tokens[2]);
  24106. ComponentRecord* comp = FindNextComponent (0, &desc);
  24107. if (comp != 0)
  24108. {
  24109. getAUDetails (comp, name, manufacturer);
  24110. return true;
  24111. }
  24112. }
  24113. }
  24114. return false;
  24115. }
  24116. class AudioUnitPluginWindowCarbon;
  24117. class AudioUnitPluginWindowCocoa;
  24118. class AudioUnitPluginInstance : public AudioPluginInstance
  24119. {
  24120. public:
  24121. ~AudioUnitPluginInstance();
  24122. // AudioPluginInstance methods:
  24123. void fillInPluginDescription (PluginDescription& desc) const
  24124. {
  24125. desc.name = pluginName;
  24126. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24127. desc.uid = ((int) componentDesc.componentType)
  24128. ^ ((int) componentDesc.componentSubType)
  24129. ^ ((int) componentDesc.componentManufacturer);
  24130. desc.lastFileModTime = 0;
  24131. desc.pluginFormatName = "AudioUnit";
  24132. desc.category = getCategory();
  24133. desc.manufacturerName = manufacturer;
  24134. desc.version = version;
  24135. desc.numInputChannels = getNumInputChannels();
  24136. desc.numOutputChannels = getNumOutputChannels();
  24137. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24138. }
  24139. const String getName() const { return pluginName; }
  24140. bool acceptsMidi() const { return wantsMidiMessages; }
  24141. bool producesMidi() const { return false; }
  24142. // AudioProcessor methods:
  24143. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24144. void releaseResources();
  24145. void processBlock (AudioSampleBuffer& buffer,
  24146. MidiBuffer& midiMessages);
  24147. AudioProcessorEditor* createEditor();
  24148. const String getInputChannelName (const int index) const;
  24149. bool isInputChannelStereoPair (int index) const;
  24150. const String getOutputChannelName (const int index) const;
  24151. bool isOutputChannelStereoPair (int index) const;
  24152. int getNumParameters();
  24153. float getParameter (int index);
  24154. void setParameter (int index, float newValue);
  24155. const String getParameterName (int index);
  24156. const String getParameterText (int index);
  24157. bool isParameterAutomatable (int index) const;
  24158. int getNumPrograms();
  24159. int getCurrentProgram();
  24160. void setCurrentProgram (int index);
  24161. const String getProgramName (int index);
  24162. void changeProgramName (int index, const String& newName);
  24163. void getStateInformation (MemoryBlock& destData);
  24164. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24165. void setStateInformation (const void* data, int sizeInBytes);
  24166. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24167. juce_UseDebuggingNewOperator
  24168. private:
  24169. friend class AudioUnitPluginWindowCarbon;
  24170. friend class AudioUnitPluginWindowCocoa;
  24171. friend class AudioUnitPluginFormat;
  24172. ComponentDescription componentDesc;
  24173. String pluginName, manufacturer, version;
  24174. String fileOrIdentifier;
  24175. CriticalSection lock;
  24176. bool initialised, wantsMidiMessages, wasPlaying;
  24177. HeapBlock <AudioBufferList> outputBufferList;
  24178. AudioTimeStamp timeStamp;
  24179. AudioSampleBuffer* currentBuffer;
  24180. AudioUnit audioUnit;
  24181. Array <int> parameterIds;
  24182. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24183. void initialise();
  24184. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24185. const AudioTimeStamp* inTimeStamp,
  24186. UInt32 inBusNumber,
  24187. UInt32 inNumberFrames,
  24188. AudioBufferList* ioData) const;
  24189. static OSStatus renderGetInputCallback (void* inRefCon,
  24190. AudioUnitRenderActionFlags* ioActionFlags,
  24191. const AudioTimeStamp* inTimeStamp,
  24192. UInt32 inBusNumber,
  24193. UInt32 inNumberFrames,
  24194. AudioBufferList* ioData)
  24195. {
  24196. return ((AudioUnitPluginInstance*) inRefCon)
  24197. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24198. }
  24199. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24200. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24201. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24202. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24203. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24204. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24205. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24206. {
  24207. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24208. }
  24209. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24210. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24211. Float64* outCurrentMeasureDownBeat)
  24212. {
  24213. return ((AudioUnitPluginInstance*) inHostUserData)
  24214. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24215. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24216. }
  24217. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24218. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24219. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24220. {
  24221. return ((AudioUnitPluginInstance*) inHostUserData)
  24222. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24223. outCurrentSampleInTimeLine, outIsCycling,
  24224. outCycleStartBeat, outCycleEndBeat);
  24225. }
  24226. void getNumChannels (int& numIns, int& numOuts)
  24227. {
  24228. numIns = 0;
  24229. numOuts = 0;
  24230. AUChannelInfo supportedChannels [128];
  24231. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24232. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24233. 0, supportedChannels, &supportedChannelsSize) == noErr
  24234. && supportedChannelsSize > 0)
  24235. {
  24236. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24237. {
  24238. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24239. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24240. }
  24241. }
  24242. else
  24243. {
  24244. // (this really means the plugin will take any number of ins/outs as long
  24245. // as they are the same)
  24246. numIns = numOuts = 2;
  24247. }
  24248. }
  24249. const String getCategory() const;
  24250. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24251. };
  24252. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24253. : fileOrIdentifier (fileOrIdentifier),
  24254. initialised (false),
  24255. wantsMidiMessages (false),
  24256. audioUnit (0),
  24257. currentBuffer (0)
  24258. {
  24259. try
  24260. {
  24261. ++insideCallback;
  24262. log ("Opening AU: " + fileOrIdentifier);
  24263. if (getComponentDescFromFile (fileOrIdentifier))
  24264. {
  24265. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24266. if (comp != 0)
  24267. {
  24268. audioUnit = (AudioUnit) OpenComponent (comp);
  24269. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24270. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24271. }
  24272. }
  24273. --insideCallback;
  24274. }
  24275. catch (...)
  24276. {
  24277. --insideCallback;
  24278. }
  24279. }
  24280. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24281. {
  24282. const ScopedLock sl (lock);
  24283. jassert (insideCallback == 0);
  24284. if (audioUnit != 0)
  24285. {
  24286. AudioUnitUninitialize (audioUnit);
  24287. CloseComponent (audioUnit);
  24288. audioUnit = 0;
  24289. }
  24290. }
  24291. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24292. {
  24293. zerostruct (componentDesc);
  24294. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24295. return true;
  24296. const File file (fileOrIdentifier);
  24297. if (! file.hasFileExtension (".component"))
  24298. return false;
  24299. const char* const utf8 = fileOrIdentifier.toUTF8();
  24300. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24301. strlen (utf8), file.isDirectory());
  24302. if (url != 0)
  24303. {
  24304. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24305. CFRelease (url);
  24306. if (bundleRef != 0)
  24307. {
  24308. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24309. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24310. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24311. if (pluginName.isEmpty())
  24312. pluginName = file.getFileNameWithoutExtension();
  24313. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24314. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24315. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24316. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24317. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24318. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24319. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24320. UseResFile (resFileId);
  24321. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24322. {
  24323. Handle h = Get1IndResource ('thng', i);
  24324. if (h != 0)
  24325. {
  24326. HLock (h);
  24327. const uint32* const types = (const uint32*) *h;
  24328. if (types[0] == kAudioUnitType_MusicDevice
  24329. || types[0] == kAudioUnitType_MusicEffect
  24330. || types[0] == kAudioUnitType_Effect
  24331. || types[0] == kAudioUnitType_Generator
  24332. || types[0] == kAudioUnitType_Panner)
  24333. {
  24334. componentDesc.componentType = types[0];
  24335. componentDesc.componentSubType = types[1];
  24336. componentDesc.componentManufacturer = types[2];
  24337. break;
  24338. }
  24339. HUnlock (h);
  24340. ReleaseResource (h);
  24341. }
  24342. }
  24343. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24344. CFRelease (bundleRef);
  24345. }
  24346. }
  24347. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24348. }
  24349. void AudioUnitPluginInstance::initialise()
  24350. {
  24351. if (initialised || audioUnit == 0)
  24352. return;
  24353. log ("Initialising AU: " + pluginName);
  24354. parameterIds.clear();
  24355. {
  24356. UInt32 paramListSize = 0;
  24357. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24358. 0, 0, &paramListSize);
  24359. if (paramListSize > 0)
  24360. {
  24361. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24362. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24363. 0, &parameterIds.getReference(0), &paramListSize);
  24364. }
  24365. }
  24366. {
  24367. AURenderCallbackStruct info;
  24368. zerostruct (info);
  24369. info.inputProcRefCon = this;
  24370. info.inputProc = renderGetInputCallback;
  24371. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24372. 0, &info, sizeof (info));
  24373. }
  24374. {
  24375. HostCallbackInfo info;
  24376. zerostruct (info);
  24377. info.hostUserData = this;
  24378. info.beatAndTempoProc = getBeatAndTempoCallback;
  24379. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24380. info.transportStateProc = getTransportStateCallback;
  24381. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24382. 0, &info, sizeof (info));
  24383. }
  24384. int numIns, numOuts;
  24385. getNumChannels (numIns, numOuts);
  24386. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24387. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24388. setLatencySamples (0);
  24389. }
  24390. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24391. int samplesPerBlockExpected)
  24392. {
  24393. initialise();
  24394. if (initialised)
  24395. {
  24396. int numIns, numOuts;
  24397. getNumChannels (numIns, numOuts);
  24398. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24399. Float64 latencySecs = 0.0;
  24400. UInt32 latencySize = sizeof (latencySecs);
  24401. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24402. 0, &latencySecs, &latencySize);
  24403. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24404. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24405. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24406. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24407. AudioStreamBasicDescription stream;
  24408. zerostruct (stream);
  24409. stream.mSampleRate = sampleRate_;
  24410. stream.mFormatID = kAudioFormatLinearPCM;
  24411. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24412. stream.mFramesPerPacket = 1;
  24413. stream.mBytesPerPacket = 4;
  24414. stream.mBytesPerFrame = 4;
  24415. stream.mBitsPerChannel = 32;
  24416. stream.mChannelsPerFrame = numIns;
  24417. OSStatus err = AudioUnitSetProperty (audioUnit,
  24418. kAudioUnitProperty_StreamFormat,
  24419. kAudioUnitScope_Input,
  24420. 0, &stream, sizeof (stream));
  24421. stream.mChannelsPerFrame = numOuts;
  24422. err = AudioUnitSetProperty (audioUnit,
  24423. kAudioUnitProperty_StreamFormat,
  24424. kAudioUnitScope_Output,
  24425. 0, &stream, sizeof (stream));
  24426. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24427. outputBufferList->mNumberBuffers = numOuts;
  24428. for (int i = numOuts; --i >= 0;)
  24429. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24430. zerostruct (timeStamp);
  24431. timeStamp.mSampleTime = 0;
  24432. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24433. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24434. currentBuffer = 0;
  24435. wasPlaying = false;
  24436. }
  24437. }
  24438. void AudioUnitPluginInstance::releaseResources()
  24439. {
  24440. if (initialised)
  24441. {
  24442. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24443. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24444. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24445. outputBufferList.free();
  24446. currentBuffer = 0;
  24447. }
  24448. }
  24449. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24450. const AudioTimeStamp* inTimeStamp,
  24451. UInt32 inBusNumber,
  24452. UInt32 inNumberFrames,
  24453. AudioBufferList* ioData) const
  24454. {
  24455. if (inBusNumber == 0
  24456. && currentBuffer != 0)
  24457. {
  24458. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24459. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24460. {
  24461. if (i < currentBuffer->getNumChannels())
  24462. {
  24463. memcpy (ioData->mBuffers[i].mData,
  24464. currentBuffer->getSampleData (i, 0),
  24465. sizeof (float) * inNumberFrames);
  24466. }
  24467. else
  24468. {
  24469. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24470. }
  24471. }
  24472. }
  24473. return noErr;
  24474. }
  24475. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24476. MidiBuffer& midiMessages)
  24477. {
  24478. const int numSamples = buffer.getNumSamples();
  24479. if (initialised)
  24480. {
  24481. AudioUnitRenderActionFlags flags = 0;
  24482. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24483. for (int i = getNumOutputChannels(); --i >= 0;)
  24484. {
  24485. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24486. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24487. }
  24488. currentBuffer = &buffer;
  24489. if (wantsMidiMessages)
  24490. {
  24491. const uint8* midiEventData;
  24492. int midiEventSize, midiEventPosition;
  24493. MidiBuffer::Iterator i (midiMessages);
  24494. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24495. {
  24496. if (midiEventSize <= 3)
  24497. MusicDeviceMIDIEvent (audioUnit,
  24498. midiEventData[0], midiEventData[1], midiEventData[2],
  24499. midiEventPosition);
  24500. else
  24501. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24502. }
  24503. midiMessages.clear();
  24504. }
  24505. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24506. 0, numSamples, outputBufferList);
  24507. timeStamp.mSampleTime += numSamples;
  24508. }
  24509. else
  24510. {
  24511. // Not initialised, so just bypass..
  24512. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24513. buffer.clear (i, 0, buffer.getNumSamples());
  24514. }
  24515. }
  24516. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24517. {
  24518. AudioPlayHead* const ph = getPlayHead();
  24519. AudioPlayHead::CurrentPositionInfo result;
  24520. if (ph != 0 && ph->getCurrentPosition (result))
  24521. {
  24522. if (outCurrentBeat != 0)
  24523. *outCurrentBeat = result.ppqPosition;
  24524. if (outCurrentTempo != 0)
  24525. *outCurrentTempo = result.bpm;
  24526. }
  24527. else
  24528. {
  24529. if (outCurrentBeat != 0)
  24530. *outCurrentBeat = 0;
  24531. if (outCurrentTempo != 0)
  24532. *outCurrentTempo = 120.0;
  24533. }
  24534. return noErr;
  24535. }
  24536. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24537. Float32* outTimeSig_Numerator,
  24538. UInt32* outTimeSig_Denominator,
  24539. Float64* outCurrentMeasureDownBeat) const
  24540. {
  24541. AudioPlayHead* const ph = getPlayHead();
  24542. AudioPlayHead::CurrentPositionInfo result;
  24543. if (ph != 0 && ph->getCurrentPosition (result))
  24544. {
  24545. if (outTimeSig_Numerator != 0)
  24546. *outTimeSig_Numerator = result.timeSigNumerator;
  24547. if (outTimeSig_Denominator != 0)
  24548. *outTimeSig_Denominator = result.timeSigDenominator;
  24549. if (outDeltaSampleOffsetToNextBeat != 0)
  24550. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24551. if (outCurrentMeasureDownBeat != 0)
  24552. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24553. }
  24554. else
  24555. {
  24556. if (outDeltaSampleOffsetToNextBeat != 0)
  24557. *outDeltaSampleOffsetToNextBeat = 0;
  24558. if (outTimeSig_Numerator != 0)
  24559. *outTimeSig_Numerator = 4;
  24560. if (outTimeSig_Denominator != 0)
  24561. *outTimeSig_Denominator = 4;
  24562. if (outCurrentMeasureDownBeat != 0)
  24563. *outCurrentMeasureDownBeat = 0;
  24564. }
  24565. return noErr;
  24566. }
  24567. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24568. Boolean* outTransportStateChanged,
  24569. Float64* outCurrentSampleInTimeLine,
  24570. Boolean* outIsCycling,
  24571. Float64* outCycleStartBeat,
  24572. Float64* outCycleEndBeat)
  24573. {
  24574. AudioPlayHead* const ph = getPlayHead();
  24575. AudioPlayHead::CurrentPositionInfo result;
  24576. if (ph != 0 && ph->getCurrentPosition (result))
  24577. {
  24578. if (outIsPlaying != 0)
  24579. *outIsPlaying = result.isPlaying;
  24580. if (outTransportStateChanged != 0)
  24581. {
  24582. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24583. wasPlaying = result.isPlaying;
  24584. }
  24585. if (outCurrentSampleInTimeLine != 0)
  24586. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24587. if (outIsCycling != 0)
  24588. *outIsCycling = false;
  24589. if (outCycleStartBeat != 0)
  24590. *outCycleStartBeat = 0;
  24591. if (outCycleEndBeat != 0)
  24592. *outCycleEndBeat = 0;
  24593. }
  24594. else
  24595. {
  24596. if (outIsPlaying != 0)
  24597. *outIsPlaying = false;
  24598. if (outTransportStateChanged != 0)
  24599. *outTransportStateChanged = false;
  24600. if (outCurrentSampleInTimeLine != 0)
  24601. *outCurrentSampleInTimeLine = 0;
  24602. if (outIsCycling != 0)
  24603. *outIsCycling = false;
  24604. if (outCycleStartBeat != 0)
  24605. *outCycleStartBeat = 0;
  24606. if (outCycleEndBeat != 0)
  24607. *outCycleEndBeat = 0;
  24608. }
  24609. return noErr;
  24610. }
  24611. static VoidArray activeWindows;
  24612. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24613. {
  24614. public:
  24615. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24616. : AudioProcessorEditor (&plugin_),
  24617. plugin (plugin_),
  24618. wrapper (0)
  24619. {
  24620. addAndMakeVisible (wrapper = new NSViewComponent());
  24621. activeWindows.add (this);
  24622. setOpaque (true);
  24623. setVisible (true);
  24624. setSize (100, 100);
  24625. createView (createGenericViewIfNeeded);
  24626. }
  24627. ~AudioUnitPluginWindowCocoa()
  24628. {
  24629. const bool wasValid = isValid();
  24630. wrapper->setView (0);
  24631. activeWindows.removeValue (this);
  24632. if (wasValid)
  24633. plugin.editorBeingDeleted (this);
  24634. delete wrapper;
  24635. }
  24636. bool isValid() const { return wrapper->getView() != 0; }
  24637. void paint (Graphics& g)
  24638. {
  24639. g.fillAll (Colours::white);
  24640. }
  24641. void resized()
  24642. {
  24643. wrapper->setSize (getWidth(), getHeight());
  24644. }
  24645. private:
  24646. AudioUnitPluginInstance& plugin;
  24647. NSViewComponent* wrapper;
  24648. bool createView (const bool createGenericViewIfNeeded)
  24649. {
  24650. NSView* pluginView = 0;
  24651. UInt32 dataSize = 0;
  24652. Boolean isWritable = false;
  24653. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24654. 0, &dataSize, &isWritable) == noErr
  24655. && dataSize != 0
  24656. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24657. 0, &dataSize, &isWritable) == noErr)
  24658. {
  24659. HeapBlock <AudioUnitCocoaViewInfo> info;
  24660. info.calloc (dataSize, 1);
  24661. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24662. 0, info, &dataSize) == noErr)
  24663. {
  24664. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24665. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24666. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24667. Class viewClass = [viewBundle classNamed: viewClassName];
  24668. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24669. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24670. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24671. {
  24672. id factory = [[[viewClass alloc] init] autorelease];
  24673. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24674. withSize: NSMakeSize (getWidth(), getHeight())];
  24675. }
  24676. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24677. {
  24678. CFRelease (info->mCocoaAUViewClass[i]);
  24679. CFRelease (info->mCocoaAUViewBundleLocation);
  24680. }
  24681. }
  24682. }
  24683. if (createGenericViewIfNeeded && (pluginView == 0))
  24684. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24685. wrapper->setView (pluginView);
  24686. if (pluginView != 0)
  24687. setSize ([pluginView frame].size.width,
  24688. [pluginView frame].size.height);
  24689. return pluginView != 0;
  24690. }
  24691. };
  24692. #if JUCE_SUPPORT_CARBON
  24693. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24694. {
  24695. public:
  24696. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24697. : AudioProcessorEditor (&plugin_),
  24698. plugin (plugin_),
  24699. viewComponent (0)
  24700. {
  24701. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24702. activeWindows.add (this);
  24703. setOpaque (true);
  24704. setVisible (true);
  24705. setSize (400, 300);
  24706. ComponentDescription viewList [16];
  24707. UInt32 viewListSize = sizeof (viewList);
  24708. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24709. 0, &viewList, &viewListSize);
  24710. componentRecord = FindNextComponent (0, &viewList[0]);
  24711. }
  24712. ~AudioUnitPluginWindowCarbon()
  24713. {
  24714. innerWrapper = 0;
  24715. activeWindows.removeValue (this);
  24716. if (isValid())
  24717. plugin.editorBeingDeleted (this);
  24718. }
  24719. bool isValid() const throw() { return componentRecord != 0; }
  24720. void paint (Graphics& g)
  24721. {
  24722. g.fillAll (Colours::black);
  24723. }
  24724. void resized()
  24725. {
  24726. innerWrapper->setSize (getWidth(), getHeight());
  24727. }
  24728. bool keyStateChanged (bool)
  24729. {
  24730. return false;
  24731. }
  24732. bool keyPressed (const KeyPress&)
  24733. {
  24734. return false;
  24735. }
  24736. void broughtToFront()
  24737. {
  24738. activeWindows.removeValue (this);
  24739. activeWindows.add (this);
  24740. }
  24741. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24742. AudioUnitCarbonView getViewComponent()
  24743. {
  24744. if (viewComponent == 0 && componentRecord != 0)
  24745. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24746. return viewComponent;
  24747. }
  24748. void closeViewComponent()
  24749. {
  24750. if (viewComponent != 0)
  24751. {
  24752. CloseComponent (viewComponent);
  24753. viewComponent = 0;
  24754. }
  24755. }
  24756. juce_UseDebuggingNewOperator
  24757. private:
  24758. AudioUnitPluginInstance& plugin;
  24759. ComponentRecord* componentRecord;
  24760. AudioUnitCarbonView viewComponent;
  24761. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24762. {
  24763. public:
  24764. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24765. : owner (owner_)
  24766. {
  24767. }
  24768. ~InnerWrapperComponent()
  24769. {
  24770. deleteWindow();
  24771. }
  24772. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24773. {
  24774. log ("Opening AU GUI: " + owner->plugin.getName());
  24775. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24776. if (viewComponent == 0)
  24777. return 0;
  24778. Float32Point pos = { 0, 0 };
  24779. Float32Point size = { 250, 200 };
  24780. HIViewRef pluginView = 0;
  24781. AudioUnitCarbonViewCreate (viewComponent,
  24782. owner->getAudioUnit(),
  24783. windowRef,
  24784. rootView,
  24785. &pos,
  24786. &size,
  24787. (ControlRef*) &pluginView);
  24788. return pluginView;
  24789. }
  24790. void removeView (HIViewRef)
  24791. {
  24792. log ("Closing AU GUI: " + owner->plugin.getName());
  24793. owner->closeViewComponent();
  24794. }
  24795. private:
  24796. AudioUnitPluginWindowCarbon* const owner;
  24797. };
  24798. friend class InnerWrapperComponent;
  24799. ScopedPointer<InnerWrapperComponent> innerWrapper;
  24800. };
  24801. #endif
  24802. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24803. {
  24804. ScopedPointer<AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24805. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24806. w = 0;
  24807. #if JUCE_SUPPORT_CARBON
  24808. if (w == 0)
  24809. {
  24810. w = new AudioUnitPluginWindowCarbon (*this);
  24811. if (! static_cast <AudioUnitPluginWindowCarbon*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24812. w = 0;
  24813. }
  24814. #endif
  24815. if (w == 0)
  24816. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24817. return w.release();
  24818. }
  24819. const String AudioUnitPluginInstance::getCategory() const
  24820. {
  24821. const char* result = 0;
  24822. switch (componentDesc.componentType)
  24823. {
  24824. case kAudioUnitType_Effect:
  24825. case kAudioUnitType_MusicEffect:
  24826. result = "Effect";
  24827. break;
  24828. case kAudioUnitType_MusicDevice:
  24829. result = "Synth";
  24830. break;
  24831. case kAudioUnitType_Generator:
  24832. result = "Generator";
  24833. break;
  24834. case kAudioUnitType_Panner:
  24835. result = "Panner";
  24836. break;
  24837. default:
  24838. break;
  24839. }
  24840. return result;
  24841. }
  24842. int AudioUnitPluginInstance::getNumParameters()
  24843. {
  24844. return parameterIds.size();
  24845. }
  24846. float AudioUnitPluginInstance::getParameter (int index)
  24847. {
  24848. const ScopedLock sl (lock);
  24849. Float32 value = 0.0f;
  24850. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24851. {
  24852. AudioUnitGetParameter (audioUnit,
  24853. (UInt32) parameterIds.getUnchecked (index),
  24854. kAudioUnitScope_Global, 0,
  24855. &value);
  24856. }
  24857. return value;
  24858. }
  24859. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24860. {
  24861. const ScopedLock sl (lock);
  24862. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24863. {
  24864. AudioUnitSetParameter (audioUnit,
  24865. (UInt32) parameterIds.getUnchecked (index),
  24866. kAudioUnitScope_Global, 0,
  24867. newValue, 0);
  24868. }
  24869. }
  24870. const String AudioUnitPluginInstance::getParameterName (int index)
  24871. {
  24872. AudioUnitParameterInfo info;
  24873. zerostruct (info);
  24874. UInt32 sz = sizeof (info);
  24875. String name;
  24876. if (AudioUnitGetProperty (audioUnit,
  24877. kAudioUnitProperty_ParameterInfo,
  24878. kAudioUnitScope_Global,
  24879. parameterIds [index], &info, &sz) == noErr)
  24880. {
  24881. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24882. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24883. else
  24884. name = String (info.name, sizeof (info.name));
  24885. }
  24886. return name;
  24887. }
  24888. const String AudioUnitPluginInstance::getParameterText (int index)
  24889. {
  24890. return String (getParameter (index));
  24891. }
  24892. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24893. {
  24894. AudioUnitParameterInfo info;
  24895. UInt32 sz = sizeof (info);
  24896. if (AudioUnitGetProperty (audioUnit,
  24897. kAudioUnitProperty_ParameterInfo,
  24898. kAudioUnitScope_Global,
  24899. parameterIds [index], &info, &sz) == noErr)
  24900. {
  24901. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24902. }
  24903. return true;
  24904. }
  24905. int AudioUnitPluginInstance::getNumPrograms()
  24906. {
  24907. CFArrayRef presets;
  24908. UInt32 sz = sizeof (CFArrayRef);
  24909. int num = 0;
  24910. if (AudioUnitGetProperty (audioUnit,
  24911. kAudioUnitProperty_FactoryPresets,
  24912. kAudioUnitScope_Global,
  24913. 0, &presets, &sz) == noErr)
  24914. {
  24915. num = (int) CFArrayGetCount (presets);
  24916. CFRelease (presets);
  24917. }
  24918. return num;
  24919. }
  24920. int AudioUnitPluginInstance::getCurrentProgram()
  24921. {
  24922. AUPreset current;
  24923. current.presetNumber = 0;
  24924. UInt32 sz = sizeof (AUPreset);
  24925. AudioUnitGetProperty (audioUnit,
  24926. kAudioUnitProperty_FactoryPresets,
  24927. kAudioUnitScope_Global,
  24928. 0, &current, &sz);
  24929. return current.presetNumber;
  24930. }
  24931. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24932. {
  24933. AUPreset current;
  24934. current.presetNumber = newIndex;
  24935. current.presetName = 0;
  24936. AudioUnitSetProperty (audioUnit,
  24937. kAudioUnitProperty_FactoryPresets,
  24938. kAudioUnitScope_Global,
  24939. 0, &current, sizeof (AUPreset));
  24940. }
  24941. const String AudioUnitPluginInstance::getProgramName (int index)
  24942. {
  24943. String s;
  24944. CFArrayRef presets;
  24945. UInt32 sz = sizeof (CFArrayRef);
  24946. if (AudioUnitGetProperty (audioUnit,
  24947. kAudioUnitProperty_FactoryPresets,
  24948. kAudioUnitScope_Global,
  24949. 0, &presets, &sz) == noErr)
  24950. {
  24951. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24952. {
  24953. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24954. if (p != 0 && p->presetNumber == index)
  24955. {
  24956. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24957. break;
  24958. }
  24959. }
  24960. CFRelease (presets);
  24961. }
  24962. return s;
  24963. }
  24964. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24965. {
  24966. jassertfalse // xxx not implemented!
  24967. }
  24968. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24969. {
  24970. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24971. return "Input " + String (index + 1);
  24972. return String::empty;
  24973. }
  24974. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  24975. {
  24976. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  24977. return false;
  24978. return true;
  24979. }
  24980. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  24981. {
  24982. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  24983. return "Output " + String (index + 1);
  24984. return String::empty;
  24985. }
  24986. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  24987. {
  24988. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  24989. return false;
  24990. return true;
  24991. }
  24992. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  24993. {
  24994. getCurrentProgramStateInformation (destData);
  24995. }
  24996. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  24997. {
  24998. CFPropertyListRef propertyList = 0;
  24999. UInt32 sz = sizeof (CFPropertyListRef);
  25000. if (AudioUnitGetProperty (audioUnit,
  25001. kAudioUnitProperty_ClassInfo,
  25002. kAudioUnitScope_Global,
  25003. 0, &propertyList, &sz) == noErr)
  25004. {
  25005. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25006. CFWriteStreamOpen (stream);
  25007. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25008. CFWriteStreamClose (stream);
  25009. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25010. destData.setSize (bytesWritten);
  25011. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25012. CFRelease (data);
  25013. CFRelease (stream);
  25014. CFRelease (propertyList);
  25015. }
  25016. }
  25017. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25018. {
  25019. setCurrentProgramStateInformation (data, sizeInBytes);
  25020. }
  25021. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25022. {
  25023. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25024. (const UInt8*) data,
  25025. sizeInBytes,
  25026. kCFAllocatorNull);
  25027. CFReadStreamOpen (stream);
  25028. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25029. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25030. stream,
  25031. 0,
  25032. kCFPropertyListImmutable,
  25033. &format,
  25034. 0);
  25035. CFRelease (stream);
  25036. if (propertyList != 0)
  25037. AudioUnitSetProperty (audioUnit,
  25038. kAudioUnitProperty_ClassInfo,
  25039. kAudioUnitScope_Global,
  25040. 0, &propertyList, sizeof (propertyList));
  25041. }
  25042. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25043. {
  25044. }
  25045. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25046. {
  25047. }
  25048. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25049. const String& fileOrIdentifier)
  25050. {
  25051. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25052. return;
  25053. PluginDescription desc;
  25054. desc.fileOrIdentifier = fileOrIdentifier;
  25055. desc.uid = 0;
  25056. try
  25057. {
  25058. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25059. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25060. if (auInstance != 0)
  25061. {
  25062. auInstance->fillInPluginDescription (desc);
  25063. results.add (new PluginDescription (desc));
  25064. }
  25065. }
  25066. catch (...)
  25067. {
  25068. // crashed while loading...
  25069. }
  25070. }
  25071. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25072. {
  25073. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25074. {
  25075. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25076. if (result->audioUnit != 0)
  25077. {
  25078. result->initialise();
  25079. return result.release();
  25080. }
  25081. }
  25082. return 0;
  25083. }
  25084. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25085. const bool /*recursive*/)
  25086. {
  25087. StringArray result;
  25088. ComponentRecord* comp = 0;
  25089. ComponentDescription desc;
  25090. zerostruct (desc);
  25091. for (;;)
  25092. {
  25093. zerostruct (desc);
  25094. comp = FindNextComponent (comp, &desc);
  25095. if (comp == 0)
  25096. break;
  25097. GetComponentInfo (comp, &desc, 0, 0, 0);
  25098. if (desc.componentType == kAudioUnitType_MusicDevice
  25099. || desc.componentType == kAudioUnitType_MusicEffect
  25100. || desc.componentType == kAudioUnitType_Effect
  25101. || desc.componentType == kAudioUnitType_Generator
  25102. || desc.componentType == kAudioUnitType_Panner)
  25103. {
  25104. const String s (createAUPluginIdentifier (desc));
  25105. DBG (s);
  25106. result.add (s);
  25107. }
  25108. }
  25109. return result;
  25110. }
  25111. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25112. {
  25113. ComponentDescription desc;
  25114. String name, version, manufacturer;
  25115. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25116. return FindNextComponent (0, &desc) != 0;
  25117. const File f (fileOrIdentifier);
  25118. return f.hasFileExtension (".component")
  25119. && f.isDirectory();
  25120. }
  25121. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25122. {
  25123. ComponentDescription desc;
  25124. String name, version, manufacturer;
  25125. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25126. if (name.isEmpty())
  25127. name = fileOrIdentifier;
  25128. return name;
  25129. }
  25130. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25131. {
  25132. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25133. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25134. else
  25135. return File (desc.fileOrIdentifier).exists();
  25136. }
  25137. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25138. {
  25139. return FileSearchPath ("/(Default AudioUnit locations)");
  25140. }
  25141. #endif
  25142. END_JUCE_NAMESPACE
  25143. #undef log
  25144. #endif
  25145. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25146. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25147. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25148. #define JUCE_MAC_VST_INCLUDED 1
  25149. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25150. #if JUCE_PLUGINHOST_VST
  25151. #if JUCE_WINDOWS
  25152. #undef _WIN32_WINNT
  25153. #define _WIN32_WINNT 0x500
  25154. #undef STRICT
  25155. #define STRICT
  25156. #include <windows.h>
  25157. #include <float.h>
  25158. #pragma warning (disable : 4312 4355)
  25159. #elif JUCE_LINUX
  25160. #include <float.h>
  25161. #include <sys/time.h>
  25162. #include <X11/Xlib.h>
  25163. #include <X11/Xutil.h>
  25164. #include <X11/Xatom.h>
  25165. #undef Font
  25166. #undef KeyPress
  25167. #undef Drawable
  25168. #undef Time
  25169. #else
  25170. #ifndef JUCE_MAC_VST_INCLUDED
  25171. // On the mac, this file needs to be compiled indirectly, by using
  25172. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25173. #error
  25174. #endif
  25175. #include <Cocoa/Cocoa.h>
  25176. #include <Carbon/Carbon.h>
  25177. #endif
  25178. #if ! (JUCE_MAC && JUCE_64BIT)
  25179. BEGIN_JUCE_NAMESPACE
  25180. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25181. #endif
  25182. #undef PRAGMA_ALIGN_SUPPORTED
  25183. #define VST_FORCE_DEPRECATED 0
  25184. #ifdef _MSC_VER
  25185. #pragma warning (push)
  25186. #pragma warning (disable: 4996)
  25187. #endif
  25188. #include "pluginterfaces/vst2.x/aeffectx.h"
  25189. #ifdef _MSC_VER
  25190. #pragma warning (pop)
  25191. #endif
  25192. #if JUCE_LINUX
  25193. #define Font JUCE_NAMESPACE::Font
  25194. #define KeyPress JUCE_NAMESPACE::KeyPress
  25195. #define Drawable JUCE_NAMESPACE::Drawable
  25196. #define Time JUCE_NAMESPACE::Time
  25197. #endif
  25198. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25199. #ifdef __aeffect__
  25200. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25201. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25202. class VSTMidiEventList
  25203. {
  25204. public:
  25205. VSTMidiEventList()
  25206. : numEventsUsed (0), numEventsAllocated (0)
  25207. {
  25208. }
  25209. ~VSTMidiEventList()
  25210. {
  25211. freeEvents();
  25212. }
  25213. void clear()
  25214. {
  25215. numEventsUsed = 0;
  25216. if (events != 0)
  25217. events->numEvents = 0;
  25218. }
  25219. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25220. {
  25221. ensureSize (numEventsUsed + 1);
  25222. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25223. events->numEvents = ++numEventsUsed;
  25224. if (numBytes <= 4)
  25225. {
  25226. if (e->type == kVstSysExType)
  25227. {
  25228. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25229. e->type = kVstMidiType;
  25230. e->byteSize = sizeof (VstMidiEvent);
  25231. e->noteLength = 0;
  25232. e->noteOffset = 0;
  25233. e->detune = 0;
  25234. e->noteOffVelocity = 0;
  25235. }
  25236. e->deltaFrames = frameOffset;
  25237. memcpy (e->midiData, midiData, numBytes);
  25238. }
  25239. else
  25240. {
  25241. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25242. if (se->type == kVstSysExType)
  25243. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25244. else
  25245. se->sysexDump = (char*) juce_malloc (numBytes);
  25246. memcpy (se->sysexDump, midiData, numBytes);
  25247. se->type = kVstSysExType;
  25248. se->byteSize = sizeof (VstMidiSysexEvent);
  25249. se->deltaFrames = frameOffset;
  25250. se->flags = 0;
  25251. se->dumpBytes = numBytes;
  25252. se->resvd1 = 0;
  25253. se->resvd2 = 0;
  25254. }
  25255. }
  25256. // Handy method to pull the events out of an event buffer supplied by the host
  25257. // or plugin.
  25258. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25259. {
  25260. for (int i = 0; i < events->numEvents; ++i)
  25261. {
  25262. const VstEvent* const e = events->events[i];
  25263. if (e != 0)
  25264. {
  25265. if (e->type == kVstMidiType)
  25266. {
  25267. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25268. 4, e->deltaFrames);
  25269. }
  25270. else if (e->type == kVstSysExType)
  25271. {
  25272. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25273. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25274. e->deltaFrames);
  25275. }
  25276. }
  25277. }
  25278. }
  25279. void ensureSize (int numEventsNeeded)
  25280. {
  25281. if (numEventsNeeded > numEventsAllocated)
  25282. {
  25283. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25284. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25285. if (events == 0)
  25286. events.calloc (size, 1);
  25287. else
  25288. events.realloc (size, 1);
  25289. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25290. {
  25291. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25292. (int) sizeof (VstMidiSysexEvent)));
  25293. e->type = kVstMidiType;
  25294. e->byteSize = sizeof (VstMidiEvent);
  25295. events->events[i] = (VstEvent*) e;
  25296. }
  25297. numEventsAllocated = numEventsNeeded;
  25298. }
  25299. }
  25300. void freeEvents()
  25301. {
  25302. if (events != 0)
  25303. {
  25304. for (int i = numEventsAllocated; --i >= 0;)
  25305. {
  25306. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25307. if (e->type == kVstSysExType)
  25308. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25309. juce_free (e);
  25310. }
  25311. events.free();
  25312. numEventsUsed = 0;
  25313. numEventsAllocated = 0;
  25314. }
  25315. }
  25316. HeapBlock <VstEvents> events;
  25317. private:
  25318. int numEventsUsed, numEventsAllocated;
  25319. };
  25320. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25321. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25322. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25323. #if ! JUCE_WIN32
  25324. static void _fpreset() {}
  25325. static void _clearfp() {}
  25326. #endif
  25327. extern void juce_callAnyTimersSynchronously();
  25328. const int fxbVersionNum = 1;
  25329. struct fxProgram
  25330. {
  25331. long chunkMagic; // 'CcnK'
  25332. long byteSize; // of this chunk, excl. magic + byteSize
  25333. long fxMagic; // 'FxCk'
  25334. long version;
  25335. long fxID; // fx unique id
  25336. long fxVersion;
  25337. long numParams;
  25338. char prgName[28];
  25339. float params[1]; // variable no. of parameters
  25340. };
  25341. struct fxSet
  25342. {
  25343. long chunkMagic; // 'CcnK'
  25344. long byteSize; // of this chunk, excl. magic + byteSize
  25345. long fxMagic; // 'FxBk'
  25346. long version;
  25347. long fxID; // fx unique id
  25348. long fxVersion;
  25349. long numPrograms;
  25350. char future[128];
  25351. fxProgram programs[1]; // variable no. of programs
  25352. };
  25353. struct fxChunkSet
  25354. {
  25355. long chunkMagic; // 'CcnK'
  25356. long byteSize; // of this chunk, excl. magic + byteSize
  25357. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25358. long version;
  25359. long fxID; // fx unique id
  25360. long fxVersion;
  25361. long numPrograms;
  25362. char future[128];
  25363. long chunkSize;
  25364. char chunk[8]; // variable
  25365. };
  25366. struct fxProgramSet
  25367. {
  25368. long chunkMagic; // 'CcnK'
  25369. long byteSize; // of this chunk, excl. magic + byteSize
  25370. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25371. long version;
  25372. long fxID; // fx unique id
  25373. long fxVersion;
  25374. long numPrograms;
  25375. char name[28];
  25376. long chunkSize;
  25377. char chunk[8]; // variable
  25378. };
  25379. static long vst_swap (const long x) throw()
  25380. {
  25381. #ifdef JUCE_LITTLE_ENDIAN
  25382. return (long) ByteOrder::swap ((uint32) x);
  25383. #else
  25384. return x;
  25385. #endif
  25386. }
  25387. static float vst_swapFloat (const float x) throw()
  25388. {
  25389. #ifdef JUCE_LITTLE_ENDIAN
  25390. union { uint32 asInt; float asFloat; } n;
  25391. n.asFloat = x;
  25392. n.asInt = ByteOrder::swap (n.asInt);
  25393. return n.asFloat;
  25394. #else
  25395. return x;
  25396. #endif
  25397. }
  25398. typedef AEffect* (*MainCall) (audioMasterCallback);
  25399. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25400. static int shellUIDToCreate = 0;
  25401. static int insideVSTCallback = 0;
  25402. class VSTPluginWindow;
  25403. // Change this to disable logging of various VST activities
  25404. #ifndef VST_LOGGING
  25405. #define VST_LOGGING 1
  25406. #endif
  25407. #if VST_LOGGING
  25408. #define log(a) Logger::writeToLog(a);
  25409. #else
  25410. #define log(a)
  25411. #endif
  25412. #if JUCE_MAC && JUCE_PPC
  25413. static void* NewCFMFromMachO (void* const machofp) throw()
  25414. {
  25415. void* result = juce_malloc (8);
  25416. ((void**) result)[0] = machofp;
  25417. ((void**) result)[1] = result;
  25418. return result;
  25419. }
  25420. #endif
  25421. #if JUCE_LINUX
  25422. extern Display* display;
  25423. extern XContext improbableNumber;
  25424. typedef void (*EventProcPtr) (XEvent* ev);
  25425. static bool xErrorTriggered;
  25426. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25427. {
  25428. xErrorTriggered = true;
  25429. return 0;
  25430. }
  25431. static int getPropertyFromXWindow (Window handle, Atom atom)
  25432. {
  25433. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25434. xErrorTriggered = false;
  25435. int userSize;
  25436. unsigned long bytes, userCount;
  25437. unsigned char* data;
  25438. Atom userType;
  25439. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25440. &userType, &userSize, &userCount, &bytes, &data);
  25441. XSetErrorHandler (oldErrorHandler);
  25442. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25443. : 0;
  25444. }
  25445. static Window getChildWindow (Window windowToCheck)
  25446. {
  25447. Window rootWindow, parentWindow;
  25448. Window* childWindows;
  25449. unsigned int numChildren;
  25450. XQueryTree (display,
  25451. windowToCheck,
  25452. &rootWindow,
  25453. &parentWindow,
  25454. &childWindows,
  25455. &numChildren);
  25456. if (numChildren > 0)
  25457. return childWindows [0];
  25458. return 0;
  25459. }
  25460. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25461. {
  25462. if (e.mods.isLeftButtonDown())
  25463. {
  25464. ev.xbutton.button = Button1;
  25465. ev.xbutton.state |= Button1Mask;
  25466. }
  25467. else if (e.mods.isRightButtonDown())
  25468. {
  25469. ev.xbutton.button = Button3;
  25470. ev.xbutton.state |= Button3Mask;
  25471. }
  25472. else if (e.mods.isMiddleButtonDown())
  25473. {
  25474. ev.xbutton.button = Button2;
  25475. ev.xbutton.state |= Button2Mask;
  25476. }
  25477. }
  25478. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25479. {
  25480. if (e.mods.isLeftButtonDown())
  25481. ev.xmotion.state |= Button1Mask;
  25482. else if (e.mods.isRightButtonDown())
  25483. ev.xmotion.state |= Button3Mask;
  25484. else if (e.mods.isMiddleButtonDown())
  25485. ev.xmotion.state |= Button2Mask;
  25486. }
  25487. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25488. {
  25489. if (e.mods.isLeftButtonDown())
  25490. ev.xcrossing.state |= Button1Mask;
  25491. else if (e.mods.isRightButtonDown())
  25492. ev.xcrossing.state |= Button3Mask;
  25493. else if (e.mods.isMiddleButtonDown())
  25494. ev.xcrossing.state |= Button2Mask;
  25495. }
  25496. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25497. {
  25498. if (increment < 0)
  25499. {
  25500. ev.xbutton.button = Button5;
  25501. ev.xbutton.state |= Button5Mask;
  25502. }
  25503. else if (increment > 0)
  25504. {
  25505. ev.xbutton.button = Button4;
  25506. ev.xbutton.state |= Button4Mask;
  25507. }
  25508. }
  25509. #endif
  25510. static VoidArray activeModules;
  25511. class ModuleHandle : public ReferenceCountedObject
  25512. {
  25513. public:
  25514. File file;
  25515. MainCall moduleMain;
  25516. String pluginName;
  25517. static ModuleHandle* findOrCreateModule (const File& file)
  25518. {
  25519. for (int i = activeModules.size(); --i >= 0;)
  25520. {
  25521. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25522. if (module->file == file)
  25523. return module;
  25524. }
  25525. _fpreset(); // (doesn't do any harm)
  25526. ++insideVSTCallback;
  25527. shellUIDToCreate = 0;
  25528. log ("Attempting to load VST: " + file.getFullPathName());
  25529. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25530. if (! m->open())
  25531. m = 0;
  25532. --insideVSTCallback;
  25533. _fpreset(); // (doesn't do any harm)
  25534. return m.release();
  25535. }
  25536. ModuleHandle (const File& file_)
  25537. : file (file_),
  25538. moduleMain (0),
  25539. #if JUCE_WIN32 || JUCE_LINUX
  25540. hModule (0)
  25541. #elif JUCE_MAC
  25542. fragId (0),
  25543. resHandle (0),
  25544. bundleRef (0),
  25545. resFileId (0)
  25546. #endif
  25547. {
  25548. activeModules.add (this);
  25549. #if JUCE_WIN32 || JUCE_LINUX
  25550. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25551. #elif JUCE_MAC
  25552. FSRef ref;
  25553. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25554. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25555. #endif
  25556. }
  25557. ~ModuleHandle()
  25558. {
  25559. activeModules.removeValue (this);
  25560. close();
  25561. }
  25562. juce_UseDebuggingNewOperator
  25563. #if JUCE_WIN32 || JUCE_LINUX
  25564. void* hModule;
  25565. String fullParentDirectoryPathName;
  25566. bool open()
  25567. {
  25568. #if JUCE_WIN32
  25569. static bool timePeriodSet = false;
  25570. if (! timePeriodSet)
  25571. {
  25572. timePeriodSet = true;
  25573. timeBeginPeriod (2);
  25574. }
  25575. #endif
  25576. pluginName = file.getFileNameWithoutExtension();
  25577. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25578. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25579. if (moduleMain == 0)
  25580. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25581. return moduleMain != 0;
  25582. }
  25583. void close()
  25584. {
  25585. _fpreset(); // (doesn't do any harm)
  25586. PlatformUtilities::freeDynamicLibrary (hModule);
  25587. }
  25588. void closeEffect (AEffect* eff)
  25589. {
  25590. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25591. }
  25592. #else
  25593. CFragConnectionID fragId;
  25594. Handle resHandle;
  25595. CFBundleRef bundleRef;
  25596. FSSpec parentDirFSSpec;
  25597. short resFileId;
  25598. bool open()
  25599. {
  25600. bool ok = false;
  25601. const String filename (file.getFullPathName());
  25602. if (file.hasFileExtension (".vst"))
  25603. {
  25604. const char* const utf8 = filename.toUTF8();
  25605. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25606. strlen (utf8), file.isDirectory());
  25607. if (url != 0)
  25608. {
  25609. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25610. CFRelease (url);
  25611. if (bundleRef != 0)
  25612. {
  25613. if (CFBundleLoadExecutable (bundleRef))
  25614. {
  25615. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25616. if (moduleMain == 0)
  25617. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25618. if (moduleMain != 0)
  25619. {
  25620. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25621. if (name != 0)
  25622. {
  25623. if (CFGetTypeID (name) == CFStringGetTypeID())
  25624. {
  25625. char buffer[1024];
  25626. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25627. pluginName = buffer;
  25628. }
  25629. }
  25630. if (pluginName.isEmpty())
  25631. pluginName = file.getFileNameWithoutExtension();
  25632. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25633. ok = true;
  25634. }
  25635. }
  25636. if (! ok)
  25637. {
  25638. CFBundleUnloadExecutable (bundleRef);
  25639. CFRelease (bundleRef);
  25640. bundleRef = 0;
  25641. }
  25642. }
  25643. }
  25644. }
  25645. #if JUCE_PPC
  25646. else
  25647. {
  25648. FSRef fn;
  25649. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25650. {
  25651. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25652. if (resFileId != -1)
  25653. {
  25654. const int numEffs = Count1Resources ('aEff');
  25655. for (int i = 0; i < numEffs; ++i)
  25656. {
  25657. resHandle = Get1IndResource ('aEff', i + 1);
  25658. if (resHandle != 0)
  25659. {
  25660. OSType type;
  25661. Str255 name;
  25662. SInt16 id;
  25663. GetResInfo (resHandle, &id, &type, name);
  25664. pluginName = String ((const char*) name + 1, name[0]);
  25665. DetachResource (resHandle);
  25666. HLock (resHandle);
  25667. Ptr ptr;
  25668. Str255 errorText;
  25669. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25670. name, kPrivateCFragCopy,
  25671. &fragId, &ptr, errorText);
  25672. if (err == noErr)
  25673. {
  25674. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25675. ok = true;
  25676. }
  25677. else
  25678. {
  25679. HUnlock (resHandle);
  25680. }
  25681. break;
  25682. }
  25683. }
  25684. if (! ok)
  25685. CloseResFile (resFileId);
  25686. }
  25687. }
  25688. }
  25689. #endif
  25690. return ok;
  25691. }
  25692. void close()
  25693. {
  25694. #if JUCE_PPC
  25695. if (fragId != 0)
  25696. {
  25697. if (moduleMain != 0)
  25698. disposeMachOFromCFM ((void*) moduleMain);
  25699. CloseConnection (&fragId);
  25700. HUnlock (resHandle);
  25701. if (resFileId != 0)
  25702. CloseResFile (resFileId);
  25703. }
  25704. else
  25705. #endif
  25706. if (bundleRef != 0)
  25707. {
  25708. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25709. if (CFGetRetainCount (bundleRef) == 1)
  25710. CFBundleUnloadExecutable (bundleRef);
  25711. if (CFGetRetainCount (bundleRef) > 0)
  25712. CFRelease (bundleRef);
  25713. }
  25714. }
  25715. void closeEffect (AEffect* eff)
  25716. {
  25717. #if JUCE_PPC
  25718. if (fragId != 0)
  25719. {
  25720. VoidArray thingsToDelete;
  25721. thingsToDelete.add ((void*) eff->dispatcher);
  25722. thingsToDelete.add ((void*) eff->process);
  25723. thingsToDelete.add ((void*) eff->setParameter);
  25724. thingsToDelete.add ((void*) eff->getParameter);
  25725. thingsToDelete.add ((void*) eff->processReplacing);
  25726. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25727. for (int i = thingsToDelete.size(); --i >= 0;)
  25728. disposeMachOFromCFM (thingsToDelete[i]);
  25729. }
  25730. else
  25731. #endif
  25732. {
  25733. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25734. }
  25735. }
  25736. #if JUCE_PPC
  25737. static void* newMachOFromCFM (void* cfmfp)
  25738. {
  25739. if (cfmfp == 0)
  25740. return 0;
  25741. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25742. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25743. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25744. mfp[2] = 0x800c0000;
  25745. mfp[3] = 0x804c0004;
  25746. mfp[4] = 0x7c0903a6;
  25747. mfp[5] = 0x4e800420;
  25748. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25749. return mfp;
  25750. }
  25751. static void disposeMachOFromCFM (void* ptr)
  25752. {
  25753. juce_free (ptr);
  25754. }
  25755. void coerceAEffectFunctionCalls (AEffect* eff)
  25756. {
  25757. if (fragId != 0)
  25758. {
  25759. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25760. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25761. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25762. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25763. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25764. }
  25765. }
  25766. #endif
  25767. #endif
  25768. };
  25769. class VSTPluginInstance : public AudioPluginInstance,
  25770. private Timer,
  25771. private AsyncUpdater
  25772. {
  25773. public:
  25774. ~VSTPluginInstance();
  25775. // AudioPluginInstance methods:
  25776. void fillInPluginDescription (PluginDescription& desc) const
  25777. {
  25778. desc.name = name;
  25779. desc.fileOrIdentifier = module->file.getFullPathName();
  25780. desc.uid = getUID();
  25781. desc.lastFileModTime = module->file.getLastModificationTime();
  25782. desc.pluginFormatName = "VST";
  25783. desc.category = getCategory();
  25784. {
  25785. char buffer [kVstMaxVendorStrLen + 8];
  25786. zerostruct (buffer);
  25787. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25788. desc.manufacturerName = buffer;
  25789. }
  25790. desc.version = getVersion();
  25791. desc.numInputChannels = getNumInputChannels();
  25792. desc.numOutputChannels = getNumOutputChannels();
  25793. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25794. }
  25795. const String getName() const { return name; }
  25796. int getUID() const throw();
  25797. bool acceptsMidi() const { return wantsMidiMessages; }
  25798. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25799. // AudioProcessor methods:
  25800. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25801. void releaseResources();
  25802. void processBlock (AudioSampleBuffer& buffer,
  25803. MidiBuffer& midiMessages);
  25804. AudioProcessorEditor* createEditor();
  25805. const String getInputChannelName (const int index) const;
  25806. bool isInputChannelStereoPair (int index) const;
  25807. const String getOutputChannelName (const int index) const;
  25808. bool isOutputChannelStereoPair (int index) const;
  25809. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25810. float getParameter (int index);
  25811. void setParameter (int index, float newValue);
  25812. const String getParameterName (int index);
  25813. const String getParameterText (int index);
  25814. bool isParameterAutomatable (int index) const;
  25815. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25816. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25817. void setCurrentProgram (int index);
  25818. const String getProgramName (int index);
  25819. void changeProgramName (int index, const String& newName);
  25820. void getStateInformation (MemoryBlock& destData);
  25821. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25822. void setStateInformation (const void* data, int sizeInBytes);
  25823. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25824. void timerCallback();
  25825. void handleAsyncUpdate();
  25826. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25827. juce_UseDebuggingNewOperator
  25828. private:
  25829. friend class VSTPluginWindow;
  25830. friend class VSTPluginFormat;
  25831. AEffect* effect;
  25832. String name;
  25833. CriticalSection lock;
  25834. bool wantsMidiMessages, initialised, isPowerOn;
  25835. mutable StringArray programNames;
  25836. AudioSampleBuffer tempBuffer;
  25837. CriticalSection midiInLock;
  25838. MidiBuffer incomingMidi;
  25839. VSTMidiEventList midiEventsToSend;
  25840. VstTimeInfo vstHostTime;
  25841. HeapBlock <float*> channels;
  25842. ReferenceCountedObjectPtr <ModuleHandle> module;
  25843. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25844. bool restoreProgramSettings (const fxProgram* const prog);
  25845. const String getCurrentProgramName();
  25846. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25847. void updateStoredProgramNames();
  25848. void initialise();
  25849. void handleMidiFromPlugin (const VstEvents* const events);
  25850. void createTempParameterStore (MemoryBlock& dest);
  25851. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25852. const String getParameterLabel (int index) const;
  25853. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25854. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25855. void setChunkData (const char* data, int size, bool isPreset);
  25856. bool loadFromFXBFile (const void* data, int numBytes);
  25857. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25858. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25859. const String getVersion() const throw();
  25860. const String getCategory() const throw();
  25861. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25862. void setPower (const bool on);
  25863. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25864. };
  25865. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25866. : effect (0),
  25867. wantsMidiMessages (false),
  25868. initialised (false),
  25869. isPowerOn (false),
  25870. tempBuffer (1, 1),
  25871. module (module_)
  25872. {
  25873. try
  25874. {
  25875. _fpreset();
  25876. ++insideVSTCallback;
  25877. name = module->pluginName;
  25878. log ("Creating VST instance: " + name);
  25879. #if JUCE_MAC
  25880. if (module->resFileId != 0)
  25881. UseResFile (module->resFileId);
  25882. #if JUCE_PPC
  25883. if (module->fragId != 0)
  25884. {
  25885. static void* audioMasterCoerced = 0;
  25886. if (audioMasterCoerced == 0)
  25887. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25888. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25889. }
  25890. else
  25891. #endif
  25892. #endif
  25893. {
  25894. effect = module->moduleMain (&audioMaster);
  25895. }
  25896. --insideVSTCallback;
  25897. if (effect != 0 && effect->magic == kEffectMagic)
  25898. {
  25899. #if JUCE_PPC
  25900. module->coerceAEffectFunctionCalls (effect);
  25901. #endif
  25902. jassert (effect->resvd2 == 0);
  25903. jassert (effect->object != 0);
  25904. _fpreset(); // some dodgy plugs fuck around with this
  25905. }
  25906. else
  25907. {
  25908. effect = 0;
  25909. }
  25910. }
  25911. catch (...)
  25912. {
  25913. --insideVSTCallback;
  25914. }
  25915. }
  25916. VSTPluginInstance::~VSTPluginInstance()
  25917. {
  25918. {
  25919. const ScopedLock sl (lock);
  25920. jassert (insideVSTCallback == 0);
  25921. if (effect != 0 && effect->magic == kEffectMagic)
  25922. {
  25923. try
  25924. {
  25925. #if JUCE_MAC
  25926. if (module->resFileId != 0)
  25927. UseResFile (module->resFileId);
  25928. #endif
  25929. // Must delete any editors before deleting the plugin instance!
  25930. jassert (getActiveEditor() == 0);
  25931. _fpreset(); // some dodgy plugs fuck around with this
  25932. module->closeEffect (effect);
  25933. }
  25934. catch (...)
  25935. {}
  25936. }
  25937. module = 0;
  25938. effect = 0;
  25939. }
  25940. }
  25941. void VSTPluginInstance::initialise()
  25942. {
  25943. if (initialised || effect == 0)
  25944. return;
  25945. log ("Initialising VST: " + module->pluginName);
  25946. initialised = true;
  25947. dispatch (effIdentify, 0, 0, 0, 0);
  25948. // this code would ask the plugin for its name, but so few plugins
  25949. // actually bother implementing this correctly, that it's better to
  25950. // just ignore it and use the file name instead.
  25951. if (getSampleRate() > 0)
  25952. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25953. if (getBlockSize() > 0)
  25954. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25955. dispatch (effOpen, 0, 0, 0, 0);
  25956. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25957. getSampleRate(), getBlockSize());
  25958. if (getNumPrograms() > 1)
  25959. setCurrentProgram (0);
  25960. else
  25961. dispatch (effSetProgram, 0, 0, 0, 0);
  25962. int i;
  25963. for (i = effect->numInputs; --i >= 0;)
  25964. dispatch (effConnectInput, i, 1, 0, 0);
  25965. for (i = effect->numOutputs; --i >= 0;)
  25966. dispatch (effConnectOutput, i, 1, 0, 0);
  25967. updateStoredProgramNames();
  25968. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25969. setLatencySamples (effect->initialDelay);
  25970. }
  25971. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  25972. int samplesPerBlockExpected)
  25973. {
  25974. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25975. sampleRate_, samplesPerBlockExpected);
  25976. setLatencySamples (effect->initialDelay);
  25977. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  25978. vstHostTime.tempo = 120.0;
  25979. vstHostTime.timeSigNumerator = 4;
  25980. vstHostTime.timeSigDenominator = 4;
  25981. vstHostTime.sampleRate = sampleRate_;
  25982. vstHostTime.samplePos = 0;
  25983. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  25984. initialise();
  25985. if (initialised)
  25986. {
  25987. wantsMidiMessages = wantsMidiMessages
  25988. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  25989. if (wantsMidiMessages)
  25990. midiEventsToSend.ensureSize (256);
  25991. else
  25992. midiEventsToSend.freeEvents();
  25993. incomingMidi.clear();
  25994. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  25995. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  25996. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  25997. if (! isPowerOn)
  25998. setPower (true);
  25999. // dodgy hack to force some plugins to initialise the sample rate..
  26000. if ((! hasEditor()) && getNumParameters() > 0)
  26001. {
  26002. const float old = getParameter (0);
  26003. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26004. setParameter (0, old);
  26005. }
  26006. dispatch (effStartProcess, 0, 0, 0, 0);
  26007. }
  26008. }
  26009. void VSTPluginInstance::releaseResources()
  26010. {
  26011. if (initialised)
  26012. {
  26013. dispatch (effStopProcess, 0, 0, 0, 0);
  26014. setPower (false);
  26015. }
  26016. tempBuffer.setSize (1, 1);
  26017. incomingMidi.clear();
  26018. midiEventsToSend.freeEvents();
  26019. channels.free();
  26020. }
  26021. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26022. MidiBuffer& midiMessages)
  26023. {
  26024. const int numSamples = buffer.getNumSamples();
  26025. if (initialised)
  26026. {
  26027. AudioPlayHead* playHead = getPlayHead();
  26028. if (playHead != 0)
  26029. {
  26030. AudioPlayHead::CurrentPositionInfo position;
  26031. playHead->getCurrentPosition (position);
  26032. vstHostTime.tempo = position.bpm;
  26033. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26034. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26035. vstHostTime.ppqPos = position.ppqPosition;
  26036. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26037. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26038. if (position.isPlaying)
  26039. vstHostTime.flags |= kVstTransportPlaying;
  26040. else
  26041. vstHostTime.flags &= ~kVstTransportPlaying;
  26042. }
  26043. #if JUCE_WIN32
  26044. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26045. #elif JUCE_LINUX
  26046. timeval micro;
  26047. gettimeofday (&micro, 0);
  26048. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26049. #elif JUCE_MAC
  26050. UnsignedWide micro;
  26051. Microseconds (&micro);
  26052. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26053. #endif
  26054. if (wantsMidiMessages)
  26055. {
  26056. midiEventsToSend.clear();
  26057. midiEventsToSend.ensureSize (1);
  26058. MidiBuffer::Iterator iter (midiMessages);
  26059. const uint8* midiData;
  26060. int numBytesOfMidiData, samplePosition;
  26061. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26062. {
  26063. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26064. jlimit (0, numSamples - 1, samplePosition));
  26065. }
  26066. try
  26067. {
  26068. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26069. }
  26070. catch (...)
  26071. {}
  26072. }
  26073. int i;
  26074. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26075. for (i = 0; i < maxChans; ++i)
  26076. channels[i] = buffer.getSampleData (i);
  26077. channels [maxChans] = 0;
  26078. _clearfp();
  26079. if ((effect->flags & effFlagsCanReplacing) != 0)
  26080. {
  26081. try
  26082. {
  26083. effect->processReplacing (effect, channels, channels, numSamples);
  26084. }
  26085. catch (...)
  26086. {}
  26087. }
  26088. else
  26089. {
  26090. tempBuffer.setSize (effect->numOutputs, numSamples);
  26091. tempBuffer.clear();
  26092. float* outs [64];
  26093. for (i = effect->numOutputs; --i >= 0;)
  26094. outs[i] = tempBuffer.getSampleData (i);
  26095. outs [effect->numOutputs] = 0;
  26096. try
  26097. {
  26098. effect->process (effect, channels, outs, numSamples);
  26099. }
  26100. catch (...)
  26101. {}
  26102. for (i = effect->numOutputs; --i >= 0;)
  26103. buffer.copyFrom (i, 0, outs[i], numSamples);
  26104. }
  26105. }
  26106. else
  26107. {
  26108. // Not initialised, so just bypass..
  26109. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26110. buffer.clear (i, 0, buffer.getNumSamples());
  26111. }
  26112. {
  26113. // copy any incoming midi..
  26114. const ScopedLock sl (midiInLock);
  26115. midiMessages.swapWith (incomingMidi);
  26116. incomingMidi.clear();
  26117. }
  26118. }
  26119. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26120. {
  26121. if (events != 0)
  26122. {
  26123. const ScopedLock sl (midiInLock);
  26124. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26125. }
  26126. }
  26127. static Array <VSTPluginWindow*> activeVSTWindows;
  26128. class VSTPluginWindow : public AudioProcessorEditor,
  26129. #if ! JUCE_MAC
  26130. public ComponentMovementWatcher,
  26131. #endif
  26132. public Timer
  26133. {
  26134. public:
  26135. VSTPluginWindow (VSTPluginInstance& plugin_)
  26136. : AudioProcessorEditor (&plugin_),
  26137. #if ! JUCE_MAC
  26138. ComponentMovementWatcher (this),
  26139. #endif
  26140. plugin (plugin_),
  26141. isOpen (false),
  26142. wasShowing (false),
  26143. pluginRefusesToResize (false),
  26144. pluginWantsKeys (false),
  26145. alreadyInside (false),
  26146. recursiveResize (false)
  26147. {
  26148. #if JUCE_WIN32
  26149. sizeCheckCount = 0;
  26150. pluginHWND = 0;
  26151. #elif JUCE_LINUX
  26152. pluginWindow = None;
  26153. pluginProc = None;
  26154. #else
  26155. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26156. #endif
  26157. activeVSTWindows.add (this);
  26158. setSize (1, 1);
  26159. setOpaque (true);
  26160. setVisible (true);
  26161. }
  26162. ~VSTPluginWindow()
  26163. {
  26164. #if JUCE_MAC
  26165. innerWrapper = 0;
  26166. #else
  26167. closePluginWindow();
  26168. #endif
  26169. activeVSTWindows.removeValue (this);
  26170. plugin.editorBeingDeleted (this);
  26171. }
  26172. #if ! JUCE_MAC
  26173. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26174. {
  26175. if (recursiveResize)
  26176. return;
  26177. Component* const topComp = getTopLevelComponent();
  26178. if (topComp->getPeer() != 0)
  26179. {
  26180. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26181. recursiveResize = true;
  26182. #if JUCE_WIN32
  26183. if (pluginHWND != 0)
  26184. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26185. #elif JUCE_LINUX
  26186. if (pluginWindow != 0)
  26187. {
  26188. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26189. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26190. XMapRaised (display, pluginWindow);
  26191. }
  26192. #endif
  26193. recursiveResize = false;
  26194. }
  26195. }
  26196. void componentVisibilityChanged (Component&)
  26197. {
  26198. const bool isShowingNow = isShowing();
  26199. if (wasShowing != isShowingNow)
  26200. {
  26201. wasShowing = isShowingNow;
  26202. if (isShowingNow)
  26203. openPluginWindow();
  26204. else
  26205. closePluginWindow();
  26206. }
  26207. componentMovedOrResized (true, true);
  26208. }
  26209. void componentPeerChanged()
  26210. {
  26211. closePluginWindow();
  26212. openPluginWindow();
  26213. }
  26214. #endif
  26215. bool keyStateChanged (bool)
  26216. {
  26217. return pluginWantsKeys;
  26218. }
  26219. bool keyPressed (const KeyPress&)
  26220. {
  26221. return pluginWantsKeys;
  26222. }
  26223. #if JUCE_MAC
  26224. void paint (Graphics& g)
  26225. {
  26226. g.fillAll (Colours::black);
  26227. }
  26228. #else
  26229. void paint (Graphics& g)
  26230. {
  26231. if (isOpen)
  26232. {
  26233. ComponentPeer* const peer = getPeer();
  26234. if (peer != 0)
  26235. {
  26236. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26237. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26238. #if JUCE_LINUX
  26239. if (pluginWindow != 0)
  26240. {
  26241. const Rectangle<int> clip (g.getClipBounds());
  26242. XEvent ev;
  26243. zerostruct (ev);
  26244. ev.xexpose.type = Expose;
  26245. ev.xexpose.display = display;
  26246. ev.xexpose.window = pluginWindow;
  26247. ev.xexpose.x = clip.getX();
  26248. ev.xexpose.y = clip.getY();
  26249. ev.xexpose.width = clip.getWidth();
  26250. ev.xexpose.height = clip.getHeight();
  26251. sendEventToChild (&ev);
  26252. }
  26253. #endif
  26254. }
  26255. }
  26256. else
  26257. {
  26258. g.fillAll (Colours::black);
  26259. }
  26260. }
  26261. #endif
  26262. void timerCallback()
  26263. {
  26264. #if JUCE_WIN32
  26265. if (--sizeCheckCount <= 0)
  26266. {
  26267. sizeCheckCount = 10;
  26268. checkPluginWindowSize();
  26269. }
  26270. #endif
  26271. try
  26272. {
  26273. static bool reentrant = false;
  26274. if (! reentrant)
  26275. {
  26276. reentrant = true;
  26277. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26278. reentrant = false;
  26279. }
  26280. }
  26281. catch (...)
  26282. {}
  26283. }
  26284. void mouseDown (const MouseEvent& e)
  26285. {
  26286. #if JUCE_LINUX
  26287. if (pluginWindow == 0)
  26288. return;
  26289. toFront (true);
  26290. XEvent ev;
  26291. zerostruct (ev);
  26292. ev.xbutton.display = display;
  26293. ev.xbutton.type = ButtonPress;
  26294. ev.xbutton.window = pluginWindow;
  26295. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26296. ev.xbutton.time = CurrentTime;
  26297. ev.xbutton.x = e.x;
  26298. ev.xbutton.y = e.y;
  26299. ev.xbutton.x_root = e.getScreenX();
  26300. ev.xbutton.y_root = e.getScreenY();
  26301. translateJuceToXButtonModifiers (e, ev);
  26302. sendEventToChild (&ev);
  26303. #elif JUCE_WIN32
  26304. (void) e;
  26305. toFront (true);
  26306. #endif
  26307. }
  26308. void broughtToFront()
  26309. {
  26310. activeVSTWindows.removeValue (this);
  26311. activeVSTWindows.add (this);
  26312. #if JUCE_MAC
  26313. dispatch (effEditTop, 0, 0, 0, 0);
  26314. #endif
  26315. }
  26316. juce_UseDebuggingNewOperator
  26317. private:
  26318. VSTPluginInstance& plugin;
  26319. bool isOpen, wasShowing, recursiveResize;
  26320. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26321. #if JUCE_WIN32
  26322. HWND pluginHWND;
  26323. void* originalWndProc;
  26324. int sizeCheckCount;
  26325. #elif JUCE_LINUX
  26326. Window pluginWindow;
  26327. EventProcPtr pluginProc;
  26328. #endif
  26329. #if JUCE_MAC
  26330. void openPluginWindow (WindowRef parentWindow)
  26331. {
  26332. if (isOpen || parentWindow == 0)
  26333. return;
  26334. isOpen = true;
  26335. ERect* rect = 0;
  26336. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26337. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26338. // do this before and after like in the steinberg example
  26339. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26340. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26341. // Install keyboard hooks
  26342. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26343. // double-check it's not too tiny
  26344. int w = 250, h = 150;
  26345. if (rect != 0)
  26346. {
  26347. w = rect->right - rect->left;
  26348. h = rect->bottom - rect->top;
  26349. if (w == 0 || h == 0)
  26350. {
  26351. w = 250;
  26352. h = 150;
  26353. }
  26354. }
  26355. w = jmax (w, 32);
  26356. h = jmax (h, 32);
  26357. setSize (w, h);
  26358. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26359. repaint();
  26360. }
  26361. #else
  26362. void openPluginWindow()
  26363. {
  26364. if (isOpen || getWindowHandle() == 0)
  26365. return;
  26366. log ("Opening VST UI: " + plugin.name);
  26367. isOpen = true;
  26368. ERect* rect = 0;
  26369. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26370. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26371. // do this before and after like in the steinberg example
  26372. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26373. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26374. // Install keyboard hooks
  26375. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26376. #if JUCE_WIN32
  26377. originalWndProc = 0;
  26378. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26379. if (pluginHWND == 0)
  26380. {
  26381. isOpen = false;
  26382. setSize (300, 150);
  26383. return;
  26384. }
  26385. #pragma warning (push)
  26386. #pragma warning (disable: 4244)
  26387. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26388. if (! pluginWantsKeys)
  26389. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) vstHookWndProc);
  26390. #pragma warning (pop)
  26391. int w, h;
  26392. RECT r;
  26393. GetWindowRect (pluginHWND, &r);
  26394. w = r.right - r.left;
  26395. h = r.bottom - r.top;
  26396. if (rect != 0)
  26397. {
  26398. const int rw = rect->right - rect->left;
  26399. const int rh = rect->bottom - rect->top;
  26400. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26401. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26402. {
  26403. // very dodgy logic to decide which size is right.
  26404. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26405. {
  26406. SetWindowPos (pluginHWND, 0,
  26407. 0, 0, rw, rh,
  26408. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26409. GetWindowRect (pluginHWND, &r);
  26410. w = r.right - r.left;
  26411. h = r.bottom - r.top;
  26412. pluginRefusesToResize = (w != rw) || (h != rh);
  26413. w = rw;
  26414. h = rh;
  26415. }
  26416. }
  26417. }
  26418. #elif JUCE_LINUX
  26419. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26420. if (pluginWindow != 0)
  26421. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26422. XInternAtom (display, "_XEventProc", False));
  26423. int w = 250, h = 150;
  26424. if (rect != 0)
  26425. {
  26426. w = rect->right - rect->left;
  26427. h = rect->bottom - rect->top;
  26428. if (w == 0 || h == 0)
  26429. {
  26430. w = 250;
  26431. h = 150;
  26432. }
  26433. }
  26434. if (pluginWindow != 0)
  26435. XMapRaised (display, pluginWindow);
  26436. #endif
  26437. // double-check it's not too tiny
  26438. w = jmax (w, 32);
  26439. h = jmax (h, 32);
  26440. setSize (w, h);
  26441. #if JUCE_WIN32
  26442. checkPluginWindowSize();
  26443. #endif
  26444. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26445. repaint();
  26446. }
  26447. #endif
  26448. #if ! JUCE_MAC
  26449. void closePluginWindow()
  26450. {
  26451. if (isOpen)
  26452. {
  26453. log ("Closing VST UI: " + plugin.getName());
  26454. isOpen = false;
  26455. dispatch (effEditClose, 0, 0, 0, 0);
  26456. #if JUCE_WIN32
  26457. #pragma warning (push)
  26458. #pragma warning (disable: 4244)
  26459. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26460. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) originalWndProc);
  26461. #pragma warning (pop)
  26462. stopTimer();
  26463. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26464. DestroyWindow (pluginHWND);
  26465. pluginHWND = 0;
  26466. #elif JUCE_LINUX
  26467. stopTimer();
  26468. pluginWindow = 0;
  26469. pluginProc = 0;
  26470. #endif
  26471. }
  26472. }
  26473. #endif
  26474. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26475. {
  26476. return plugin.dispatch (opcode, index, value, ptr, opt);
  26477. }
  26478. #if JUCE_WIN32
  26479. void checkPluginWindowSize() throw()
  26480. {
  26481. RECT r;
  26482. GetWindowRect (pluginHWND, &r);
  26483. const int w = r.right - r.left;
  26484. const int h = r.bottom - r.top;
  26485. if (isShowing() && w > 0 && h > 0
  26486. && (w != getWidth() || h != getHeight())
  26487. && ! pluginRefusesToResize)
  26488. {
  26489. setSize (w, h);
  26490. sizeCheckCount = 0;
  26491. }
  26492. }
  26493. // hooks to get keyboard events from VST windows..
  26494. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26495. {
  26496. for (int i = activeVSTWindows.size(); --i >= 0;)
  26497. {
  26498. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26499. if (w->pluginHWND == hW)
  26500. {
  26501. if (message == WM_CHAR
  26502. || message == WM_KEYDOWN
  26503. || message == WM_SYSKEYDOWN
  26504. || message == WM_KEYUP
  26505. || message == WM_SYSKEYUP
  26506. || message == WM_APPCOMMAND)
  26507. {
  26508. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26509. message, wParam, lParam);
  26510. }
  26511. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26512. (HWND) w->pluginHWND,
  26513. message,
  26514. wParam,
  26515. lParam);
  26516. }
  26517. }
  26518. return DefWindowProc (hW, message, wParam, lParam);
  26519. }
  26520. #endif
  26521. #if JUCE_LINUX
  26522. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26523. void sendEventToChild (XEvent* event)
  26524. {
  26525. if (pluginProc != 0)
  26526. {
  26527. // if the plugin publishes an event procedure, pass the event directly..
  26528. pluginProc (event);
  26529. }
  26530. else if (pluginWindow != 0)
  26531. {
  26532. // if the plugin has a window, then send the event to the window so that
  26533. // its message thread will pick it up..
  26534. XSendEvent (display, pluginWindow, False, 0L, event);
  26535. XFlush (display);
  26536. }
  26537. }
  26538. void mouseEnter (const MouseEvent& e)
  26539. {
  26540. if (pluginWindow != 0)
  26541. {
  26542. XEvent ev;
  26543. zerostruct (ev);
  26544. ev.xcrossing.display = display;
  26545. ev.xcrossing.type = EnterNotify;
  26546. ev.xcrossing.window = pluginWindow;
  26547. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26548. ev.xcrossing.time = CurrentTime;
  26549. ev.xcrossing.x = e.x;
  26550. ev.xcrossing.y = e.y;
  26551. ev.xcrossing.x_root = e.getScreenX();
  26552. ev.xcrossing.y_root = e.getScreenY();
  26553. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26554. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26555. translateJuceToXCrossingModifiers (e, ev);
  26556. sendEventToChild (&ev);
  26557. }
  26558. }
  26559. void mouseExit (const MouseEvent& e)
  26560. {
  26561. if (pluginWindow != 0)
  26562. {
  26563. XEvent ev;
  26564. zerostruct (ev);
  26565. ev.xcrossing.display = display;
  26566. ev.xcrossing.type = LeaveNotify;
  26567. ev.xcrossing.window = pluginWindow;
  26568. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26569. ev.xcrossing.time = CurrentTime;
  26570. ev.xcrossing.x = e.x;
  26571. ev.xcrossing.y = e.y;
  26572. ev.xcrossing.x_root = e.getScreenX();
  26573. ev.xcrossing.y_root = e.getScreenY();
  26574. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26575. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26576. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26577. translateJuceToXCrossingModifiers (e, ev);
  26578. sendEventToChild (&ev);
  26579. }
  26580. }
  26581. void mouseMove (const MouseEvent& e)
  26582. {
  26583. if (pluginWindow != 0)
  26584. {
  26585. XEvent ev;
  26586. zerostruct (ev);
  26587. ev.xmotion.display = display;
  26588. ev.xmotion.type = MotionNotify;
  26589. ev.xmotion.window = pluginWindow;
  26590. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26591. ev.xmotion.time = CurrentTime;
  26592. ev.xmotion.is_hint = NotifyNormal;
  26593. ev.xmotion.x = e.x;
  26594. ev.xmotion.y = e.y;
  26595. ev.xmotion.x_root = e.getScreenX();
  26596. ev.xmotion.y_root = e.getScreenY();
  26597. sendEventToChild (&ev);
  26598. }
  26599. }
  26600. void mouseDrag (const MouseEvent& e)
  26601. {
  26602. if (pluginWindow != 0)
  26603. {
  26604. XEvent ev;
  26605. zerostruct (ev);
  26606. ev.xmotion.display = display;
  26607. ev.xmotion.type = MotionNotify;
  26608. ev.xmotion.window = pluginWindow;
  26609. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26610. ev.xmotion.time = CurrentTime;
  26611. ev.xmotion.x = e.x ;
  26612. ev.xmotion.y = e.y;
  26613. ev.xmotion.x_root = e.getScreenX();
  26614. ev.xmotion.y_root = e.getScreenY();
  26615. ev.xmotion.is_hint = NotifyNormal;
  26616. translateJuceToXMotionModifiers (e, ev);
  26617. sendEventToChild (&ev);
  26618. }
  26619. }
  26620. void mouseUp (const MouseEvent& e)
  26621. {
  26622. if (pluginWindow != 0)
  26623. {
  26624. XEvent ev;
  26625. zerostruct (ev);
  26626. ev.xbutton.display = display;
  26627. ev.xbutton.type = ButtonRelease;
  26628. ev.xbutton.window = pluginWindow;
  26629. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26630. ev.xbutton.time = CurrentTime;
  26631. ev.xbutton.x = e.x;
  26632. ev.xbutton.y = e.y;
  26633. ev.xbutton.x_root = e.getScreenX();
  26634. ev.xbutton.y_root = e.getScreenY();
  26635. translateJuceToXButtonModifiers (e, ev);
  26636. sendEventToChild (&ev);
  26637. }
  26638. }
  26639. void mouseWheelMove (const MouseEvent& e,
  26640. float incrementX,
  26641. float incrementY)
  26642. {
  26643. if (pluginWindow != 0)
  26644. {
  26645. XEvent ev;
  26646. zerostruct (ev);
  26647. ev.xbutton.display = display;
  26648. ev.xbutton.type = ButtonPress;
  26649. ev.xbutton.window = pluginWindow;
  26650. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26651. ev.xbutton.time = CurrentTime;
  26652. ev.xbutton.x = e.x;
  26653. ev.xbutton.y = e.y;
  26654. ev.xbutton.x_root = e.getScreenX();
  26655. ev.xbutton.y_root = e.getScreenY();
  26656. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26657. sendEventToChild (&ev);
  26658. // TODO - put a usleep here ?
  26659. ev.xbutton.type = ButtonRelease;
  26660. sendEventToChild (&ev);
  26661. }
  26662. }
  26663. #endif
  26664. #if JUCE_MAC
  26665. #if ! JUCE_SUPPORT_CARBON
  26666. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26667. #endif
  26668. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26669. {
  26670. public:
  26671. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26672. : owner (owner_),
  26673. alreadyInside (false)
  26674. {
  26675. }
  26676. ~InnerWrapperComponent()
  26677. {
  26678. deleteWindow();
  26679. }
  26680. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26681. {
  26682. owner->openPluginWindow (windowRef);
  26683. return 0;
  26684. }
  26685. void removeView (HIViewRef)
  26686. {
  26687. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26688. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26689. }
  26690. bool getEmbeddedViewSize (int& w, int& h)
  26691. {
  26692. ERect* rect = 0;
  26693. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26694. w = rect->right - rect->left;
  26695. h = rect->bottom - rect->top;
  26696. return true;
  26697. }
  26698. void mouseDown (int x, int y)
  26699. {
  26700. if (! alreadyInside)
  26701. {
  26702. alreadyInside = true;
  26703. getTopLevelComponent()->toFront (true);
  26704. owner->dispatch (effEditMouse, x, y, 0, 0);
  26705. alreadyInside = false;
  26706. }
  26707. else
  26708. {
  26709. PostEvent (::mouseDown, 0);
  26710. }
  26711. }
  26712. void paint()
  26713. {
  26714. ComponentPeer* const peer = getPeer();
  26715. if (peer != 0)
  26716. {
  26717. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26718. ERect r;
  26719. r.left = pos.getX();
  26720. r.right = r.left + getWidth();
  26721. r.top = pos.getY();
  26722. r.bottom = r.top + getHeight();
  26723. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26724. }
  26725. }
  26726. private:
  26727. VSTPluginWindow* const owner;
  26728. bool alreadyInside;
  26729. };
  26730. friend class InnerWrapperComponent;
  26731. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26732. void resized()
  26733. {
  26734. innerWrapper->setSize (getWidth(), getHeight());
  26735. }
  26736. #endif
  26737. };
  26738. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26739. {
  26740. if (hasEditor())
  26741. return new VSTPluginWindow (*this);
  26742. return 0;
  26743. }
  26744. void VSTPluginInstance::handleAsyncUpdate()
  26745. {
  26746. // indicates that something about the plugin has changed..
  26747. updateHostDisplay();
  26748. }
  26749. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26750. {
  26751. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26752. {
  26753. changeProgramName (getCurrentProgram(), prog->prgName);
  26754. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26755. setParameter (i, vst_swapFloat (prog->params[i]));
  26756. return true;
  26757. }
  26758. return false;
  26759. }
  26760. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26761. const int dataSize)
  26762. {
  26763. if (dataSize < 28)
  26764. return false;
  26765. const fxSet* const set = (const fxSet*) data;
  26766. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26767. || vst_swap (set->version) > fxbVersionNum)
  26768. return false;
  26769. if (vst_swap (set->fxMagic) == 'FxBk')
  26770. {
  26771. // bank of programs
  26772. if (vst_swap (set->numPrograms) >= 0)
  26773. {
  26774. const int oldProg = getCurrentProgram();
  26775. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26776. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26777. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26778. {
  26779. if (i != oldProg)
  26780. {
  26781. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26782. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26783. return false;
  26784. if (vst_swap (set->numPrograms) > 0)
  26785. setCurrentProgram (i);
  26786. if (! restoreProgramSettings (prog))
  26787. return false;
  26788. }
  26789. }
  26790. if (vst_swap (set->numPrograms) > 0)
  26791. setCurrentProgram (oldProg);
  26792. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26793. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26794. return false;
  26795. if (! restoreProgramSettings (prog))
  26796. return false;
  26797. }
  26798. }
  26799. else if (vst_swap (set->fxMagic) == 'FxCk')
  26800. {
  26801. // single program
  26802. const fxProgram* const prog = (const fxProgram*) data;
  26803. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26804. return false;
  26805. changeProgramName (getCurrentProgram(), prog->prgName);
  26806. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26807. setParameter (i, vst_swapFloat (prog->params[i]));
  26808. }
  26809. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26810. {
  26811. // non-preset chunk
  26812. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26813. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26814. return false;
  26815. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26816. }
  26817. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26818. {
  26819. // preset chunk
  26820. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26821. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26822. return false;
  26823. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26824. changeProgramName (getCurrentProgram(), cset->name);
  26825. }
  26826. else
  26827. {
  26828. return false;
  26829. }
  26830. return true;
  26831. }
  26832. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26833. {
  26834. const int numParams = getNumParameters();
  26835. prog->chunkMagic = vst_swap ('CcnK');
  26836. prog->byteSize = 0;
  26837. prog->fxMagic = vst_swap ('FxCk');
  26838. prog->version = vst_swap (fxbVersionNum);
  26839. prog->fxID = vst_swap (getUID());
  26840. prog->fxVersion = vst_swap (getVersionNumber());
  26841. prog->numParams = vst_swap (numParams);
  26842. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26843. for (int i = 0; i < numParams; ++i)
  26844. prog->params[i] = vst_swapFloat (getParameter (i));
  26845. }
  26846. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26847. {
  26848. const int numPrograms = getNumPrograms();
  26849. const int numParams = getNumParameters();
  26850. if (usesChunks())
  26851. {
  26852. if (isFXB)
  26853. {
  26854. MemoryBlock chunk;
  26855. getChunkData (chunk, false, maxSizeMB);
  26856. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26857. dest.setSize (totalLen, true);
  26858. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26859. set->chunkMagic = vst_swap ('CcnK');
  26860. set->byteSize = 0;
  26861. set->fxMagic = vst_swap ('FBCh');
  26862. set->version = vst_swap (fxbVersionNum);
  26863. set->fxID = vst_swap (getUID());
  26864. set->fxVersion = vst_swap (getVersionNumber());
  26865. set->numPrograms = vst_swap (numPrograms);
  26866. set->chunkSize = vst_swap ((long) chunk.getSize());
  26867. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26868. }
  26869. else
  26870. {
  26871. MemoryBlock chunk;
  26872. getChunkData (chunk, true, maxSizeMB);
  26873. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26874. dest.setSize (totalLen, true);
  26875. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26876. set->chunkMagic = vst_swap ('CcnK');
  26877. set->byteSize = 0;
  26878. set->fxMagic = vst_swap ('FPCh');
  26879. set->version = vst_swap (fxbVersionNum);
  26880. set->fxID = vst_swap (getUID());
  26881. set->fxVersion = vst_swap (getVersionNumber());
  26882. set->numPrograms = vst_swap (numPrograms);
  26883. set->chunkSize = vst_swap ((long) chunk.getSize());
  26884. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26885. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26886. }
  26887. }
  26888. else
  26889. {
  26890. if (isFXB)
  26891. {
  26892. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26893. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26894. dest.setSize (len, true);
  26895. fxSet* const set = (fxSet*) dest.getData();
  26896. set->chunkMagic = vst_swap ('CcnK');
  26897. set->byteSize = 0;
  26898. set->fxMagic = vst_swap ('FxBk');
  26899. set->version = vst_swap (fxbVersionNum);
  26900. set->fxID = vst_swap (getUID());
  26901. set->fxVersion = vst_swap (getVersionNumber());
  26902. set->numPrograms = vst_swap (numPrograms);
  26903. const int oldProgram = getCurrentProgram();
  26904. MemoryBlock oldSettings;
  26905. createTempParameterStore (oldSettings);
  26906. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26907. for (int i = 0; i < numPrograms; ++i)
  26908. {
  26909. if (i != oldProgram)
  26910. {
  26911. setCurrentProgram (i);
  26912. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26913. }
  26914. }
  26915. setCurrentProgram (oldProgram);
  26916. restoreFromTempParameterStore (oldSettings);
  26917. }
  26918. else
  26919. {
  26920. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26921. dest.setSize (totalLen, true);
  26922. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26923. }
  26924. }
  26925. return true;
  26926. }
  26927. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26928. {
  26929. if (usesChunks())
  26930. {
  26931. void* data = 0;
  26932. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26933. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26934. {
  26935. mb.setSize (bytes);
  26936. mb.copyFrom (data, 0, bytes);
  26937. }
  26938. }
  26939. }
  26940. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26941. {
  26942. if (size > 0 && usesChunks())
  26943. {
  26944. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26945. if (! isPreset)
  26946. updateStoredProgramNames();
  26947. }
  26948. }
  26949. void VSTPluginInstance::timerCallback()
  26950. {
  26951. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26952. stopTimer();
  26953. }
  26954. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26955. {
  26956. const ScopedLock sl (lock);
  26957. ++insideVSTCallback;
  26958. int result = 0;
  26959. try
  26960. {
  26961. if (effect != 0)
  26962. {
  26963. #if JUCE_MAC
  26964. if (module->resFileId != 0)
  26965. UseResFile (module->resFileId);
  26966. CGrafPtr oldPort;
  26967. if (getActiveEditor() != 0)
  26968. {
  26969. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26970. GetPort (&oldPort);
  26971. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  26972. SetOrigin (-pos.getX(), -pos.getY());
  26973. }
  26974. #endif
  26975. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  26976. #if JUCE_MAC
  26977. if (getActiveEditor() != 0)
  26978. SetPort (oldPort);
  26979. module->resFileId = CurResFile();
  26980. #endif
  26981. --insideVSTCallback;
  26982. return result;
  26983. }
  26984. }
  26985. catch (...)
  26986. {
  26987. }
  26988. --insideVSTCallback;
  26989. return result;
  26990. }
  26991. // handles non plugin-specific callbacks..
  26992. static const int defaultVSTSampleRateValue = 16384;
  26993. static const int defaultVSTBlockSizeValue = 512;
  26994. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26995. {
  26996. (void) index;
  26997. (void) value;
  26998. (void) opt;
  26999. switch (opcode)
  27000. {
  27001. case audioMasterCanDo:
  27002. {
  27003. static const char* canDos[] = { "supplyIdle",
  27004. "sendVstEvents",
  27005. "sendVstMidiEvent",
  27006. "sendVstTimeInfo",
  27007. "receiveVstEvents",
  27008. "receiveVstMidiEvent",
  27009. "supportShell",
  27010. "shellCategory" };
  27011. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27012. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27013. return 1;
  27014. return 0;
  27015. }
  27016. case audioMasterVersion:
  27017. return 0x2400;
  27018. case audioMasterCurrentId:
  27019. return shellUIDToCreate;
  27020. case audioMasterGetNumAutomatableParameters:
  27021. return 0;
  27022. case audioMasterGetAutomationState:
  27023. return 1;
  27024. case audioMasterGetVendorVersion:
  27025. return 0x0101;
  27026. case audioMasterGetVendorString:
  27027. case audioMasterGetProductString:
  27028. {
  27029. String hostName ("Juce VST Host");
  27030. if (JUCEApplication::getInstance() != 0)
  27031. hostName = JUCEApplication::getInstance()->getApplicationName();
  27032. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27033. }
  27034. break;
  27035. case audioMasterGetSampleRate:
  27036. return (VstIntPtr) defaultVSTSampleRateValue;
  27037. case audioMasterGetBlockSize:
  27038. return (VstIntPtr) defaultVSTBlockSizeValue;
  27039. case audioMasterSetOutputSampleRate:
  27040. return 0;
  27041. default:
  27042. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27043. break;
  27044. }
  27045. return 0;
  27046. }
  27047. // handles callbacks for a specific plugin
  27048. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27049. {
  27050. switch (opcode)
  27051. {
  27052. case audioMasterAutomate:
  27053. sendParamChangeMessageToListeners (index, opt);
  27054. break;
  27055. case audioMasterProcessEvents:
  27056. handleMidiFromPlugin ((const VstEvents*) ptr);
  27057. break;
  27058. case audioMasterGetTime:
  27059. #ifdef _MSC_VER
  27060. #pragma warning (push)
  27061. #pragma warning (disable: 4311)
  27062. #endif
  27063. return (VstIntPtr) &vstHostTime;
  27064. #ifdef _MSC_VER
  27065. #pragma warning (pop)
  27066. #endif
  27067. break;
  27068. case audioMasterIdle:
  27069. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27070. {
  27071. ++insideVSTCallback;
  27072. #if JUCE_MAC
  27073. if (getActiveEditor() != 0)
  27074. dispatch (effEditIdle, 0, 0, 0, 0);
  27075. #endif
  27076. juce_callAnyTimersSynchronously();
  27077. handleUpdateNowIfNeeded();
  27078. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27079. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27080. --insideVSTCallback;
  27081. }
  27082. break;
  27083. case audioMasterUpdateDisplay:
  27084. triggerAsyncUpdate();
  27085. break;
  27086. case audioMasterTempoAt:
  27087. // returns (10000 * bpm)
  27088. break;
  27089. case audioMasterNeedIdle:
  27090. startTimer (50);
  27091. break;
  27092. case audioMasterSizeWindow:
  27093. if (getActiveEditor() != 0)
  27094. getActiveEditor()->setSize (index, value);
  27095. return 1;
  27096. case audioMasterGetSampleRate:
  27097. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27098. case audioMasterGetBlockSize:
  27099. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27100. case audioMasterWantMidi:
  27101. wantsMidiMessages = true;
  27102. break;
  27103. case audioMasterGetDirectory:
  27104. #if JUCE_MAC
  27105. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27106. #else
  27107. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27108. #endif
  27109. case audioMasterGetAutomationState:
  27110. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27111. break;
  27112. // none of these are handled (yet)..
  27113. case audioMasterBeginEdit:
  27114. case audioMasterEndEdit:
  27115. case audioMasterSetTime:
  27116. case audioMasterPinConnected:
  27117. case audioMasterGetParameterQuantization:
  27118. case audioMasterIOChanged:
  27119. case audioMasterGetInputLatency:
  27120. case audioMasterGetOutputLatency:
  27121. case audioMasterGetPreviousPlug:
  27122. case audioMasterGetNextPlug:
  27123. case audioMasterWillReplaceOrAccumulate:
  27124. case audioMasterGetCurrentProcessLevel:
  27125. case audioMasterOfflineStart:
  27126. case audioMasterOfflineRead:
  27127. case audioMasterOfflineWrite:
  27128. case audioMasterOfflineGetCurrentPass:
  27129. case audioMasterOfflineGetCurrentMetaPass:
  27130. case audioMasterVendorSpecific:
  27131. case audioMasterSetIcon:
  27132. case audioMasterGetLanguage:
  27133. case audioMasterOpenWindow:
  27134. case audioMasterCloseWindow:
  27135. break;
  27136. default:
  27137. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27138. }
  27139. return 0;
  27140. }
  27141. // entry point for all callbacks from the plugin
  27142. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27143. {
  27144. try
  27145. {
  27146. if (effect != 0 && effect->resvd2 != 0)
  27147. {
  27148. return ((VSTPluginInstance*)(effect->resvd2))
  27149. ->handleCallback (opcode, index, value, ptr, opt);
  27150. }
  27151. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27152. }
  27153. catch (...)
  27154. {
  27155. return 0;
  27156. }
  27157. }
  27158. const String VSTPluginInstance::getVersion() const throw()
  27159. {
  27160. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27161. String s;
  27162. if (v == 0 || v == -1)
  27163. v = getVersionNumber();
  27164. if (v != 0)
  27165. {
  27166. int versionBits[4];
  27167. int n = 0;
  27168. while (v != 0)
  27169. {
  27170. versionBits [n++] = (v & 0xff);
  27171. v >>= 8;
  27172. }
  27173. s << 'V';
  27174. while (n > 0)
  27175. {
  27176. s << versionBits [--n];
  27177. if (n > 0)
  27178. s << '.';
  27179. }
  27180. }
  27181. return s;
  27182. }
  27183. int VSTPluginInstance::getUID() const throw()
  27184. {
  27185. int uid = effect != 0 ? effect->uniqueID : 0;
  27186. if (uid == 0)
  27187. uid = module->file.hashCode();
  27188. return uid;
  27189. }
  27190. const String VSTPluginInstance::getCategory() const throw()
  27191. {
  27192. const char* result = 0;
  27193. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27194. {
  27195. case kPlugCategEffect:
  27196. result = "Effect";
  27197. break;
  27198. case kPlugCategSynth:
  27199. result = "Synth";
  27200. break;
  27201. case kPlugCategAnalysis:
  27202. result = "Anaylsis";
  27203. break;
  27204. case kPlugCategMastering:
  27205. result = "Mastering";
  27206. break;
  27207. case kPlugCategSpacializer:
  27208. result = "Spacial";
  27209. break;
  27210. case kPlugCategRoomFx:
  27211. result = "Reverb";
  27212. break;
  27213. case kPlugSurroundFx:
  27214. result = "Surround";
  27215. break;
  27216. case kPlugCategRestoration:
  27217. result = "Restoration";
  27218. break;
  27219. case kPlugCategGenerator:
  27220. result = "Tone generation";
  27221. break;
  27222. default:
  27223. break;
  27224. }
  27225. return result;
  27226. }
  27227. float VSTPluginInstance::getParameter (int index)
  27228. {
  27229. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27230. {
  27231. try
  27232. {
  27233. const ScopedLock sl (lock);
  27234. return effect->getParameter (effect, index);
  27235. }
  27236. catch (...)
  27237. {
  27238. }
  27239. }
  27240. return 0.0f;
  27241. }
  27242. void VSTPluginInstance::setParameter (int index, float newValue)
  27243. {
  27244. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27245. {
  27246. try
  27247. {
  27248. const ScopedLock sl (lock);
  27249. if (effect->getParameter (effect, index) != newValue)
  27250. effect->setParameter (effect, index, newValue);
  27251. }
  27252. catch (...)
  27253. {
  27254. }
  27255. }
  27256. }
  27257. const String VSTPluginInstance::getParameterName (int index)
  27258. {
  27259. if (effect != 0)
  27260. {
  27261. jassert (index >= 0 && index < effect->numParams);
  27262. char nm [256];
  27263. zerostruct (nm);
  27264. dispatch (effGetParamName, index, 0, nm, 0);
  27265. return String (nm).trim();
  27266. }
  27267. return String::empty;
  27268. }
  27269. const String VSTPluginInstance::getParameterLabel (int index) const
  27270. {
  27271. if (effect != 0)
  27272. {
  27273. jassert (index >= 0 && index < effect->numParams);
  27274. char nm [256];
  27275. zerostruct (nm);
  27276. dispatch (effGetParamLabel, index, 0, nm, 0);
  27277. return String (nm).trim();
  27278. }
  27279. return String::empty;
  27280. }
  27281. const String VSTPluginInstance::getParameterText (int index)
  27282. {
  27283. if (effect != 0)
  27284. {
  27285. jassert (index >= 0 && index < effect->numParams);
  27286. char nm [256];
  27287. zerostruct (nm);
  27288. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27289. return String (nm).trim();
  27290. }
  27291. return String::empty;
  27292. }
  27293. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27294. {
  27295. if (effect != 0)
  27296. {
  27297. jassert (index >= 0 && index < effect->numParams);
  27298. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27299. }
  27300. return false;
  27301. }
  27302. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27303. {
  27304. dest.setSize (64 + 4 * getNumParameters());
  27305. dest.fillWith (0);
  27306. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27307. float* const p = (float*) (((char*) dest.getData()) + 64);
  27308. for (int i = 0; i < getNumParameters(); ++i)
  27309. p[i] = getParameter(i);
  27310. }
  27311. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27312. {
  27313. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27314. float* p = (float*) (((char*) m.getData()) + 64);
  27315. for (int i = 0; i < getNumParameters(); ++i)
  27316. setParameter (i, p[i]);
  27317. }
  27318. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27319. {
  27320. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27321. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27322. }
  27323. const String VSTPluginInstance::getProgramName (int index)
  27324. {
  27325. if (index == getCurrentProgram())
  27326. {
  27327. return getCurrentProgramName();
  27328. }
  27329. else if (effect != 0)
  27330. {
  27331. char nm [256];
  27332. zerostruct (nm);
  27333. if (dispatch (effGetProgramNameIndexed,
  27334. jlimit (0, getNumPrograms(), index),
  27335. -1, nm, 0) != 0)
  27336. {
  27337. return String (nm).trim();
  27338. }
  27339. }
  27340. return programNames [index];
  27341. }
  27342. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27343. {
  27344. if (index == getCurrentProgram())
  27345. {
  27346. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27347. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27348. }
  27349. else
  27350. {
  27351. jassertfalse // xxx not implemented!
  27352. }
  27353. }
  27354. void VSTPluginInstance::updateStoredProgramNames()
  27355. {
  27356. if (effect != 0 && getNumPrograms() > 0)
  27357. {
  27358. char nm [256];
  27359. zerostruct (nm);
  27360. // only do this if the plugin can't use indexed names..
  27361. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27362. {
  27363. const int oldProgram = getCurrentProgram();
  27364. MemoryBlock oldSettings;
  27365. createTempParameterStore (oldSettings);
  27366. for (int i = 0; i < getNumPrograms(); ++i)
  27367. {
  27368. setCurrentProgram (i);
  27369. getCurrentProgramName(); // (this updates the list)
  27370. }
  27371. setCurrentProgram (oldProgram);
  27372. restoreFromTempParameterStore (oldSettings);
  27373. }
  27374. }
  27375. }
  27376. const String VSTPluginInstance::getCurrentProgramName()
  27377. {
  27378. if (effect != 0)
  27379. {
  27380. char nm [256];
  27381. zerostruct (nm);
  27382. dispatch (effGetProgramName, 0, 0, nm, 0);
  27383. const int index = getCurrentProgram();
  27384. if (programNames[index].isEmpty())
  27385. {
  27386. while (programNames.size() < index)
  27387. programNames.add (String::empty);
  27388. programNames.set (index, String (nm).trim());
  27389. }
  27390. return String (nm).trim();
  27391. }
  27392. return String::empty;
  27393. }
  27394. const String VSTPluginInstance::getInputChannelName (const int index) const
  27395. {
  27396. if (index >= 0 && index < getNumInputChannels())
  27397. {
  27398. VstPinProperties pinProps;
  27399. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27400. return String (pinProps.label, sizeof (pinProps.label));
  27401. }
  27402. return String::empty;
  27403. }
  27404. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27405. {
  27406. if (index < 0 || index >= getNumInputChannels())
  27407. return false;
  27408. VstPinProperties pinProps;
  27409. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27410. return (pinProps.flags & kVstPinIsStereo) != 0;
  27411. return true;
  27412. }
  27413. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27414. {
  27415. if (index >= 0 && index < getNumOutputChannels())
  27416. {
  27417. VstPinProperties pinProps;
  27418. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27419. return String (pinProps.label, sizeof (pinProps.label));
  27420. }
  27421. return String::empty;
  27422. }
  27423. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27424. {
  27425. if (index < 0 || index >= getNumOutputChannels())
  27426. return false;
  27427. VstPinProperties pinProps;
  27428. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27429. return (pinProps.flags & kVstPinIsStereo) != 0;
  27430. return true;
  27431. }
  27432. void VSTPluginInstance::setPower (const bool on)
  27433. {
  27434. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27435. isPowerOn = on;
  27436. }
  27437. const int defaultMaxSizeMB = 64;
  27438. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27439. {
  27440. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27441. }
  27442. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27443. {
  27444. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27445. }
  27446. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27447. {
  27448. loadFromFXBFile (data, sizeInBytes);
  27449. }
  27450. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27451. {
  27452. loadFromFXBFile (data, sizeInBytes);
  27453. }
  27454. VSTPluginFormat::VSTPluginFormat()
  27455. {
  27456. }
  27457. VSTPluginFormat::~VSTPluginFormat()
  27458. {
  27459. }
  27460. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27461. const String& fileOrIdentifier)
  27462. {
  27463. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27464. return;
  27465. PluginDescription desc;
  27466. desc.fileOrIdentifier = fileOrIdentifier;
  27467. desc.uid = 0;
  27468. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27469. if (instance == 0)
  27470. return;
  27471. try
  27472. {
  27473. #if JUCE_MAC
  27474. if (instance->module->resFileId != 0)
  27475. UseResFile (instance->module->resFileId);
  27476. #endif
  27477. instance->fillInPluginDescription (desc);
  27478. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27479. if (category != kPlugCategShell)
  27480. {
  27481. // Normal plugin...
  27482. results.add (new PluginDescription (desc));
  27483. ++insideVSTCallback;
  27484. instance->dispatch (effOpen, 0, 0, 0, 0);
  27485. --insideVSTCallback;
  27486. }
  27487. else
  27488. {
  27489. // It's a shell plugin, so iterate all the subtypes...
  27490. char shellEffectName [64];
  27491. for (;;)
  27492. {
  27493. zerostruct (shellEffectName);
  27494. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27495. if (uid == 0)
  27496. {
  27497. break;
  27498. }
  27499. else
  27500. {
  27501. desc.uid = uid;
  27502. desc.name = shellEffectName;
  27503. bool alreadyThere = false;
  27504. for (int i = results.size(); --i >= 0;)
  27505. {
  27506. PluginDescription* const d = results.getUnchecked(i);
  27507. if (d->isDuplicateOf (desc))
  27508. {
  27509. alreadyThere = true;
  27510. break;
  27511. }
  27512. }
  27513. if (! alreadyThere)
  27514. results.add (new PluginDescription (desc));
  27515. }
  27516. }
  27517. }
  27518. }
  27519. catch (...)
  27520. {
  27521. // crashed while loading...
  27522. }
  27523. }
  27524. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27525. {
  27526. ScopedPointer <VSTPluginInstance> result;
  27527. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27528. {
  27529. File file (desc.fileOrIdentifier);
  27530. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27531. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27532. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27533. if (module != 0)
  27534. {
  27535. shellUIDToCreate = desc.uid;
  27536. result = new VSTPluginInstance (module);
  27537. if (result->effect != 0)
  27538. {
  27539. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27540. result->initialise();
  27541. }
  27542. else
  27543. {
  27544. result = 0;
  27545. }
  27546. }
  27547. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27548. }
  27549. return result.release();
  27550. }
  27551. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27552. {
  27553. const File f (fileOrIdentifier);
  27554. #if JUCE_MAC
  27555. if (f.isDirectory() && f.hasFileExtension (".vst"))
  27556. return true;
  27557. #if JUCE_PPC
  27558. FSRef fileRef;
  27559. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27560. {
  27561. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27562. if (resFileId != -1)
  27563. {
  27564. const int numEffects = Count1Resources ('aEff');
  27565. CloseResFile (resFileId);
  27566. if (numEffects > 0)
  27567. return true;
  27568. }
  27569. }
  27570. #endif
  27571. return false;
  27572. #elif JUCE_WIN32
  27573. return f.existsAsFile()
  27574. && f.hasFileExtension (".dll");
  27575. #elif JUCE_LINUX
  27576. return f.existsAsFile()
  27577. && f.hasFileExtension (".so");
  27578. #endif
  27579. }
  27580. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27581. {
  27582. return fileOrIdentifier;
  27583. }
  27584. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27585. {
  27586. return File (desc.fileOrIdentifier).exists();
  27587. }
  27588. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27589. {
  27590. StringArray results;
  27591. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27592. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27593. return results;
  27594. }
  27595. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27596. {
  27597. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27598. // .component or .vst directories.
  27599. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27600. while (iter.next())
  27601. {
  27602. const File f (iter.getFile());
  27603. bool isPlugin = false;
  27604. if (fileMightContainThisPluginType (f.getFullPathName()))
  27605. {
  27606. isPlugin = true;
  27607. results.add (f.getFullPathName());
  27608. }
  27609. if (recursive && (! isPlugin) && f.isDirectory())
  27610. recursiveFileSearch (results, f, true);
  27611. }
  27612. }
  27613. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27614. {
  27615. #if JUCE_MAC
  27616. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27617. #elif JUCE_WIN32
  27618. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27619. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27620. #elif JUCE_LINUX
  27621. return FileSearchPath ("/usr/lib/vst");
  27622. #endif
  27623. }
  27624. END_JUCE_NAMESPACE
  27625. #endif
  27626. #undef log
  27627. #endif
  27628. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27629. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27630. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27631. BEGIN_JUCE_NAMESPACE
  27632. AudioProcessor::AudioProcessor()
  27633. : playHead (0),
  27634. activeEditor (0),
  27635. sampleRate (0),
  27636. blockSize (0),
  27637. numInputChannels (0),
  27638. numOutputChannels (0),
  27639. latencySamples (0),
  27640. suspended (false),
  27641. nonRealtime (false)
  27642. {
  27643. }
  27644. AudioProcessor::~AudioProcessor()
  27645. {
  27646. // ooh, nasty - the editor should have been deleted before the filter
  27647. // that it refers to is deleted..
  27648. jassert (activeEditor == 0);
  27649. #ifdef JUCE_DEBUG
  27650. // This will fail if you've called beginParameterChangeGesture() for one
  27651. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27652. jassert (changingParams.countNumberOfSetBits() == 0);
  27653. #endif
  27654. }
  27655. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27656. {
  27657. playHead = newPlayHead;
  27658. }
  27659. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27660. {
  27661. const ScopedLock sl (listenerLock);
  27662. listeners.addIfNotAlreadyThere (newListener);
  27663. }
  27664. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27665. {
  27666. const ScopedLock sl (listenerLock);
  27667. listeners.removeValue (listenerToRemove);
  27668. }
  27669. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27670. const int numOuts,
  27671. const double sampleRate_,
  27672. const int blockSize_) throw()
  27673. {
  27674. numInputChannels = numIns;
  27675. numOutputChannels = numOuts;
  27676. sampleRate = sampleRate_;
  27677. blockSize = blockSize_;
  27678. }
  27679. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27680. {
  27681. nonRealtime = nonRealtime_;
  27682. }
  27683. void AudioProcessor::setLatencySamples (const int newLatency)
  27684. {
  27685. if (latencySamples != newLatency)
  27686. {
  27687. latencySamples = newLatency;
  27688. updateHostDisplay();
  27689. }
  27690. }
  27691. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27692. const float newValue)
  27693. {
  27694. setParameter (parameterIndex, newValue);
  27695. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27696. }
  27697. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27698. {
  27699. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27700. for (int i = listeners.size(); --i >= 0;)
  27701. {
  27702. AudioProcessorListener* l;
  27703. {
  27704. const ScopedLock sl (listenerLock);
  27705. l = (AudioProcessorListener*) listeners [i];
  27706. }
  27707. if (l != 0)
  27708. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27709. }
  27710. }
  27711. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27712. {
  27713. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27714. #ifdef JUCE_DEBUG
  27715. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27716. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27717. jassert (! changingParams [parameterIndex]);
  27718. changingParams.setBit (parameterIndex);
  27719. #endif
  27720. for (int i = listeners.size(); --i >= 0;)
  27721. {
  27722. AudioProcessorListener* l;
  27723. {
  27724. const ScopedLock sl (listenerLock);
  27725. l = (AudioProcessorListener*) listeners [i];
  27726. }
  27727. if (l != 0)
  27728. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27729. }
  27730. }
  27731. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27732. {
  27733. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27734. #ifdef JUCE_DEBUG
  27735. // This means you've called endParameterChangeGesture without having previously called
  27736. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27737. // calls matched correctly.
  27738. jassert (changingParams [parameterIndex]);
  27739. changingParams.clearBit (parameterIndex);
  27740. #endif
  27741. for (int i = listeners.size(); --i >= 0;)
  27742. {
  27743. AudioProcessorListener* l;
  27744. {
  27745. const ScopedLock sl (listenerLock);
  27746. l = (AudioProcessorListener*) listeners [i];
  27747. }
  27748. if (l != 0)
  27749. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27750. }
  27751. }
  27752. void AudioProcessor::updateHostDisplay()
  27753. {
  27754. for (int i = listeners.size(); --i >= 0;)
  27755. {
  27756. AudioProcessorListener* l;
  27757. {
  27758. const ScopedLock sl (listenerLock);
  27759. l = (AudioProcessorListener*) listeners [i];
  27760. }
  27761. if (l != 0)
  27762. l->audioProcessorChanged (this);
  27763. }
  27764. }
  27765. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27766. {
  27767. return true;
  27768. }
  27769. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27770. {
  27771. return false;
  27772. }
  27773. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27774. {
  27775. const ScopedLock sl (callbackLock);
  27776. suspended = shouldBeSuspended;
  27777. }
  27778. void AudioProcessor::reset()
  27779. {
  27780. }
  27781. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27782. {
  27783. const ScopedLock sl (callbackLock);
  27784. jassert (activeEditor == editor);
  27785. if (activeEditor == editor)
  27786. activeEditor = 0;
  27787. }
  27788. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27789. {
  27790. if (activeEditor != 0)
  27791. return activeEditor;
  27792. AudioProcessorEditor* const ed = createEditor();
  27793. if (ed != 0)
  27794. {
  27795. // you must give your editor comp a size before returning it..
  27796. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27797. const ScopedLock sl (callbackLock);
  27798. activeEditor = ed;
  27799. }
  27800. return ed;
  27801. }
  27802. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27803. {
  27804. getStateInformation (destData);
  27805. }
  27806. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27807. {
  27808. setStateInformation (data, sizeInBytes);
  27809. }
  27810. // magic number to identify memory blocks that we've stored as XML
  27811. const uint32 magicXmlNumber = 0x21324356;
  27812. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27813. JUCE_NAMESPACE::MemoryBlock& destData)
  27814. {
  27815. const String xmlString (xml.createDocument (String::empty, true, false));
  27816. const int stringLength = xmlString.getNumBytesAsUTF8();
  27817. destData.setSize (stringLength + 10);
  27818. char* const d = (char*) destData.getData();
  27819. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27820. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27821. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27822. }
  27823. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27824. const int sizeInBytes)
  27825. {
  27826. if (sizeInBytes > 8
  27827. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27828. {
  27829. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27830. if (stringLength > 0)
  27831. {
  27832. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27833. jmin ((sizeInBytes - 8), stringLength)));
  27834. return doc.getDocumentElement();
  27835. }
  27836. }
  27837. return 0;
  27838. }
  27839. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27840. {
  27841. }
  27842. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27843. {
  27844. }
  27845. bool AudioPlayHead::CurrentPositionInfo::operator== (const CurrentPositionInfo& other) const throw()
  27846. {
  27847. return timeInSeconds == other.timeInSeconds
  27848. && ppqPosition == other.ppqPosition
  27849. && editOriginTime == other.editOriginTime
  27850. && ppqPositionOfLastBarStart == other.ppqPositionOfLastBarStart
  27851. && frameRate == other.frameRate
  27852. && isPlaying == other.isPlaying
  27853. && isRecording == other.isRecording
  27854. && bpm == other.bpm
  27855. && timeSigNumerator == other.timeSigNumerator
  27856. && timeSigDenominator == other.timeSigDenominator;
  27857. }
  27858. bool AudioPlayHead::CurrentPositionInfo::operator!= (const CurrentPositionInfo& other) const throw()
  27859. {
  27860. return ! operator== (other);
  27861. }
  27862. void AudioPlayHead::CurrentPositionInfo::resetToDefault()
  27863. {
  27864. zerostruct (*this);
  27865. timeSigNumerator = 4;
  27866. timeSigDenominator = 4;
  27867. bpm = 120;
  27868. }
  27869. END_JUCE_NAMESPACE
  27870. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27871. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27872. BEGIN_JUCE_NAMESPACE
  27873. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27874. : owner (owner_)
  27875. {
  27876. // the filter must be valid..
  27877. jassert (owner != 0);
  27878. }
  27879. AudioProcessorEditor::~AudioProcessorEditor()
  27880. {
  27881. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27882. // filter for some reason..
  27883. jassert (owner->getActiveEditor() != this);
  27884. }
  27885. END_JUCE_NAMESPACE
  27886. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27887. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27888. BEGIN_JUCE_NAMESPACE
  27889. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27890. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27891. : id (id_),
  27892. processor (processor_),
  27893. isPrepared (false)
  27894. {
  27895. jassert (processor_ != 0);
  27896. }
  27897. AudioProcessorGraph::Node::~Node()
  27898. {
  27899. delete processor;
  27900. }
  27901. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27902. AudioProcessorGraph* const graph)
  27903. {
  27904. if (! isPrepared)
  27905. {
  27906. isPrepared = true;
  27907. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27908. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27909. if (ioProc != 0)
  27910. ioProc->setParentGraph (graph);
  27911. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27912. processor->getNumOutputChannels(),
  27913. sampleRate, blockSize);
  27914. processor->prepareToPlay (sampleRate, blockSize);
  27915. }
  27916. }
  27917. void AudioProcessorGraph::Node::unprepare()
  27918. {
  27919. if (isPrepared)
  27920. {
  27921. isPrepared = false;
  27922. processor->releaseResources();
  27923. }
  27924. }
  27925. AudioProcessorGraph::AudioProcessorGraph()
  27926. : lastNodeId (0),
  27927. renderingBuffers (1, 1),
  27928. currentAudioOutputBuffer (1, 1)
  27929. {
  27930. }
  27931. AudioProcessorGraph::~AudioProcessorGraph()
  27932. {
  27933. clearRenderingSequence();
  27934. clear();
  27935. }
  27936. const String AudioProcessorGraph::getName() const
  27937. {
  27938. return "Audio Graph";
  27939. }
  27940. void AudioProcessorGraph::clear()
  27941. {
  27942. nodes.clear();
  27943. connections.clear();
  27944. triggerAsyncUpdate();
  27945. }
  27946. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27947. {
  27948. for (int i = nodes.size(); --i >= 0;)
  27949. if (nodes.getUnchecked(i)->id == nodeId)
  27950. return nodes.getUnchecked(i);
  27951. return 0;
  27952. }
  27953. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27954. uint32 nodeId)
  27955. {
  27956. if (newProcessor == 0)
  27957. {
  27958. jassertfalse
  27959. return 0;
  27960. }
  27961. if (nodeId == 0)
  27962. {
  27963. nodeId = ++lastNodeId;
  27964. }
  27965. else
  27966. {
  27967. // you can't add a node with an id that already exists in the graph..
  27968. jassert (getNodeForId (nodeId) == 0);
  27969. removeNode (nodeId);
  27970. }
  27971. lastNodeId = nodeId;
  27972. Node* const n = new Node (nodeId, newProcessor);
  27973. nodes.add (n);
  27974. triggerAsyncUpdate();
  27975. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27976. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27977. if (ioProc != 0)
  27978. ioProc->setParentGraph (this);
  27979. return n;
  27980. }
  27981. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27982. {
  27983. disconnectNode (nodeId);
  27984. for (int i = nodes.size(); --i >= 0;)
  27985. {
  27986. if (nodes.getUnchecked(i)->id == nodeId)
  27987. {
  27988. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27989. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27990. if (ioProc != 0)
  27991. ioProc->setParentGraph (0);
  27992. nodes.remove (i);
  27993. triggerAsyncUpdate();
  27994. return true;
  27995. }
  27996. }
  27997. return false;
  27998. }
  27999. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28000. const int sourceChannelIndex,
  28001. const uint32 destNodeId,
  28002. const int destChannelIndex) const
  28003. {
  28004. for (int i = connections.size(); --i >= 0;)
  28005. {
  28006. const Connection* const c = connections.getUnchecked(i);
  28007. if (c->sourceNodeId == sourceNodeId
  28008. && c->destNodeId == destNodeId
  28009. && c->sourceChannelIndex == sourceChannelIndex
  28010. && c->destChannelIndex == destChannelIndex)
  28011. {
  28012. return c;
  28013. }
  28014. }
  28015. return 0;
  28016. }
  28017. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28018. const uint32 possibleDestNodeId) const
  28019. {
  28020. for (int i = connections.size(); --i >= 0;)
  28021. {
  28022. const Connection* const c = connections.getUnchecked(i);
  28023. if (c->sourceNodeId == possibleSourceNodeId
  28024. && c->destNodeId == possibleDestNodeId)
  28025. {
  28026. return true;
  28027. }
  28028. }
  28029. return false;
  28030. }
  28031. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28032. const int sourceChannelIndex,
  28033. const uint32 destNodeId,
  28034. const int destChannelIndex) const
  28035. {
  28036. if (sourceChannelIndex < 0
  28037. || destChannelIndex < 0
  28038. || sourceNodeId == destNodeId
  28039. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28040. return false;
  28041. const Node* const source = getNodeForId (sourceNodeId);
  28042. if (source == 0
  28043. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28044. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28045. return false;
  28046. const Node* const dest = getNodeForId (destNodeId);
  28047. if (dest == 0
  28048. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28049. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28050. return false;
  28051. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28052. destNodeId, destChannelIndex) == 0;
  28053. }
  28054. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28055. const int sourceChannelIndex,
  28056. const uint32 destNodeId,
  28057. const int destChannelIndex)
  28058. {
  28059. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28060. return false;
  28061. Connection* const c = new Connection();
  28062. c->sourceNodeId = sourceNodeId;
  28063. c->sourceChannelIndex = sourceChannelIndex;
  28064. c->destNodeId = destNodeId;
  28065. c->destChannelIndex = destChannelIndex;
  28066. connections.add (c);
  28067. triggerAsyncUpdate();
  28068. return true;
  28069. }
  28070. void AudioProcessorGraph::removeConnection (const int index)
  28071. {
  28072. connections.remove (index);
  28073. triggerAsyncUpdate();
  28074. }
  28075. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28076. const uint32 destNodeId, const int destChannelIndex)
  28077. {
  28078. bool doneAnything = false;
  28079. for (int i = connections.size(); --i >= 0;)
  28080. {
  28081. const Connection* const c = connections.getUnchecked(i);
  28082. if (c->sourceNodeId == sourceNodeId
  28083. && c->destNodeId == destNodeId
  28084. && c->sourceChannelIndex == sourceChannelIndex
  28085. && c->destChannelIndex == destChannelIndex)
  28086. {
  28087. removeConnection (i);
  28088. doneAnything = true;
  28089. triggerAsyncUpdate();
  28090. }
  28091. }
  28092. return doneAnything;
  28093. }
  28094. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28095. {
  28096. bool doneAnything = false;
  28097. for (int i = connections.size(); --i >= 0;)
  28098. {
  28099. const Connection* const c = connections.getUnchecked(i);
  28100. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28101. {
  28102. removeConnection (i);
  28103. doneAnything = true;
  28104. triggerAsyncUpdate();
  28105. }
  28106. }
  28107. return doneAnything;
  28108. }
  28109. bool AudioProcessorGraph::removeIllegalConnections()
  28110. {
  28111. bool doneAnything = false;
  28112. for (int i = connections.size(); --i >= 0;)
  28113. {
  28114. const Connection* const c = connections.getUnchecked(i);
  28115. const Node* const source = getNodeForId (c->sourceNodeId);
  28116. const Node* const dest = getNodeForId (c->destNodeId);
  28117. if (source == 0 || dest == 0
  28118. || (c->sourceChannelIndex != midiChannelIndex
  28119. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28120. || (c->sourceChannelIndex == midiChannelIndex
  28121. && ! source->processor->producesMidi())
  28122. || (c->destChannelIndex != midiChannelIndex
  28123. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28124. || (c->destChannelIndex == midiChannelIndex
  28125. && ! dest->processor->acceptsMidi()))
  28126. {
  28127. removeConnection (i);
  28128. doneAnything = true;
  28129. triggerAsyncUpdate();
  28130. }
  28131. }
  28132. return doneAnything;
  28133. }
  28134. namespace GraphRenderingOps
  28135. {
  28136. class AudioGraphRenderingOp
  28137. {
  28138. public:
  28139. AudioGraphRenderingOp() {}
  28140. virtual ~AudioGraphRenderingOp() {}
  28141. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28142. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28143. const int numSamples) = 0;
  28144. juce_UseDebuggingNewOperator
  28145. };
  28146. class ClearChannelOp : public AudioGraphRenderingOp
  28147. {
  28148. public:
  28149. ClearChannelOp (const int channelNum_)
  28150. : channelNum (channelNum_)
  28151. {}
  28152. ~ClearChannelOp() {}
  28153. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28154. {
  28155. sharedBufferChans.clear (channelNum, 0, numSamples);
  28156. }
  28157. private:
  28158. const int channelNum;
  28159. ClearChannelOp (const ClearChannelOp&);
  28160. ClearChannelOp& operator= (const ClearChannelOp&);
  28161. };
  28162. class CopyChannelOp : public AudioGraphRenderingOp
  28163. {
  28164. public:
  28165. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28166. : srcChannelNum (srcChannelNum_),
  28167. dstChannelNum (dstChannelNum_)
  28168. {}
  28169. ~CopyChannelOp() {}
  28170. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28171. {
  28172. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28173. }
  28174. private:
  28175. const int srcChannelNum, dstChannelNum;
  28176. CopyChannelOp (const CopyChannelOp&);
  28177. CopyChannelOp& operator= (const CopyChannelOp&);
  28178. };
  28179. class AddChannelOp : public AudioGraphRenderingOp
  28180. {
  28181. public:
  28182. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28183. : srcChannelNum (srcChannelNum_),
  28184. dstChannelNum (dstChannelNum_)
  28185. {}
  28186. ~AddChannelOp() {}
  28187. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28188. {
  28189. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28190. }
  28191. private:
  28192. const int srcChannelNum, dstChannelNum;
  28193. AddChannelOp (const AddChannelOp&);
  28194. AddChannelOp& operator= (const AddChannelOp&);
  28195. };
  28196. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28197. {
  28198. public:
  28199. ClearMidiBufferOp (const int bufferNum_)
  28200. : bufferNum (bufferNum_)
  28201. {}
  28202. ~ClearMidiBufferOp() {}
  28203. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28204. {
  28205. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28206. }
  28207. private:
  28208. const int bufferNum;
  28209. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28210. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28211. };
  28212. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28213. {
  28214. public:
  28215. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28216. : srcBufferNum (srcBufferNum_),
  28217. dstBufferNum (dstBufferNum_)
  28218. {}
  28219. ~CopyMidiBufferOp() {}
  28220. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28221. {
  28222. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28223. }
  28224. private:
  28225. const int srcBufferNum, dstBufferNum;
  28226. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28227. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28228. };
  28229. class AddMidiBufferOp : public AudioGraphRenderingOp
  28230. {
  28231. public:
  28232. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28233. : srcBufferNum (srcBufferNum_),
  28234. dstBufferNum (dstBufferNum_)
  28235. {}
  28236. ~AddMidiBufferOp() {}
  28237. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28238. {
  28239. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28240. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28241. }
  28242. private:
  28243. const int srcBufferNum, dstBufferNum;
  28244. AddMidiBufferOp (const AddMidiBufferOp&);
  28245. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28246. };
  28247. class ProcessBufferOp : public AudioGraphRenderingOp
  28248. {
  28249. public:
  28250. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28251. const Array <int>& audioChannelsToUse_,
  28252. const int totalChans_,
  28253. const int midiBufferToUse_)
  28254. : node (node_),
  28255. processor (node_->processor),
  28256. audioChannelsToUse (audioChannelsToUse_),
  28257. totalChans (jmax (1, totalChans_)),
  28258. midiBufferToUse (midiBufferToUse_)
  28259. {
  28260. channels.calloc (totalChans);
  28261. while (audioChannelsToUse.size() < totalChans)
  28262. audioChannelsToUse.add (0);
  28263. }
  28264. ~ProcessBufferOp()
  28265. {
  28266. }
  28267. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28268. {
  28269. for (int i = totalChans; --i >= 0;)
  28270. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28271. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28272. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28273. }
  28274. const AudioProcessorGraph::Node::Ptr node;
  28275. AudioProcessor* const processor;
  28276. private:
  28277. Array <int> audioChannelsToUse;
  28278. HeapBlock <float*> channels;
  28279. int totalChans;
  28280. int midiBufferToUse;
  28281. ProcessBufferOp (const ProcessBufferOp&);
  28282. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28283. };
  28284. class RenderingOpSequenceCalculator
  28285. {
  28286. public:
  28287. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28288. const VoidArray& orderedNodes_,
  28289. VoidArray& renderingOps)
  28290. : graph (graph_),
  28291. orderedNodes (orderedNodes_)
  28292. {
  28293. nodeIds.add (-2); // first buffer is read-only zeros
  28294. channels.add (0);
  28295. midiNodeIds.add (-2);
  28296. for (int i = 0; i < orderedNodes.size(); ++i)
  28297. {
  28298. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28299. renderingOps, i);
  28300. markAnyUnusedBuffersAsFree (i);
  28301. }
  28302. }
  28303. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28304. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28305. juce_UseDebuggingNewOperator
  28306. private:
  28307. AudioProcessorGraph& graph;
  28308. const VoidArray& orderedNodes;
  28309. Array <int> nodeIds, channels, midiNodeIds;
  28310. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28311. VoidArray& renderingOps,
  28312. const int ourRenderingIndex)
  28313. {
  28314. const int numIns = node->processor->getNumInputChannels();
  28315. const int numOuts = node->processor->getNumOutputChannels();
  28316. const int totalChans = jmax (numIns, numOuts);
  28317. Array <int> audioChannelsToUse;
  28318. int midiBufferToUse = -1;
  28319. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28320. {
  28321. // get a list of all the inputs to this node
  28322. Array <int> sourceNodes, sourceOutputChans;
  28323. for (int i = graph.getNumConnections(); --i >= 0;)
  28324. {
  28325. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28326. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28327. {
  28328. sourceNodes.add (c->sourceNodeId);
  28329. sourceOutputChans.add (c->sourceChannelIndex);
  28330. }
  28331. }
  28332. int bufIndex = -1;
  28333. if (sourceNodes.size() == 0)
  28334. {
  28335. // unconnected input channel
  28336. if (inputChan >= numOuts)
  28337. {
  28338. bufIndex = getReadOnlyEmptyBuffer();
  28339. jassert (bufIndex >= 0);
  28340. }
  28341. else
  28342. {
  28343. bufIndex = getFreeBuffer (false);
  28344. renderingOps.add (new ClearChannelOp (bufIndex));
  28345. }
  28346. }
  28347. else if (sourceNodes.size() == 1)
  28348. {
  28349. // channel with a straightforward single input..
  28350. const int srcNode = sourceNodes.getUnchecked(0);
  28351. const int srcChan = sourceOutputChans.getUnchecked(0);
  28352. bufIndex = getBufferContaining (srcNode, srcChan);
  28353. if (bufIndex < 0)
  28354. {
  28355. // if not found, this is probably a feedback loop
  28356. bufIndex = getReadOnlyEmptyBuffer();
  28357. jassert (bufIndex >= 0);
  28358. }
  28359. if (inputChan < numOuts
  28360. && isBufferNeededLater (ourRenderingIndex,
  28361. inputChan,
  28362. srcNode, srcChan))
  28363. {
  28364. // can't mess up this channel because it's needed later by another node, so we
  28365. // need to use a copy of it..
  28366. const int newFreeBuffer = getFreeBuffer (false);
  28367. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28368. bufIndex = newFreeBuffer;
  28369. }
  28370. }
  28371. else
  28372. {
  28373. // channel with a mix of several inputs..
  28374. // try to find a re-usable channel from our inputs..
  28375. int reusableInputIndex = -1;
  28376. for (int i = 0; i < sourceNodes.size(); ++i)
  28377. {
  28378. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28379. sourceOutputChans.getUnchecked(i));
  28380. if (sourceBufIndex >= 0
  28381. && ! isBufferNeededLater (ourRenderingIndex,
  28382. inputChan,
  28383. sourceNodes.getUnchecked(i),
  28384. sourceOutputChans.getUnchecked(i)))
  28385. {
  28386. // we've found one of our input chans that can be re-used..
  28387. reusableInputIndex = i;
  28388. bufIndex = sourceBufIndex;
  28389. break;
  28390. }
  28391. }
  28392. if (reusableInputIndex < 0)
  28393. {
  28394. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28395. bufIndex = getFreeBuffer (false);
  28396. jassert (bufIndex != 0);
  28397. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28398. sourceOutputChans.getUnchecked (0));
  28399. if (srcIndex < 0)
  28400. {
  28401. // if not found, this is probably a feedback loop
  28402. renderingOps.add (new ClearChannelOp (bufIndex));
  28403. }
  28404. else
  28405. {
  28406. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28407. }
  28408. reusableInputIndex = 0;
  28409. }
  28410. for (int j = 0; j < sourceNodes.size(); ++j)
  28411. {
  28412. if (j != reusableInputIndex)
  28413. {
  28414. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28415. sourceOutputChans.getUnchecked(j));
  28416. if (srcIndex >= 0)
  28417. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28418. }
  28419. }
  28420. }
  28421. jassert (bufIndex >= 0);
  28422. audioChannelsToUse.add (bufIndex);
  28423. if (inputChan < numOuts)
  28424. markBufferAsContaining (bufIndex, node->id, inputChan);
  28425. }
  28426. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28427. {
  28428. const int bufIndex = getFreeBuffer (false);
  28429. jassert (bufIndex != 0);
  28430. audioChannelsToUse.add (bufIndex);
  28431. markBufferAsContaining (bufIndex, node->id, outputChan);
  28432. }
  28433. // Now the same thing for midi..
  28434. Array <int> midiSourceNodes;
  28435. for (int i = graph.getNumConnections(); --i >= 0;)
  28436. {
  28437. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28438. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28439. midiSourceNodes.add (c->sourceNodeId);
  28440. }
  28441. if (midiSourceNodes.size() == 0)
  28442. {
  28443. // No midi inputs..
  28444. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28445. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28446. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28447. }
  28448. else if (midiSourceNodes.size() == 1)
  28449. {
  28450. // One midi input..
  28451. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28452. AudioProcessorGraph::midiChannelIndex);
  28453. if (midiBufferToUse >= 0)
  28454. {
  28455. if (isBufferNeededLater (ourRenderingIndex,
  28456. AudioProcessorGraph::midiChannelIndex,
  28457. midiSourceNodes.getUnchecked(0),
  28458. AudioProcessorGraph::midiChannelIndex))
  28459. {
  28460. // can't mess up this channel because it's needed later by another node, so we
  28461. // need to use a copy of it..
  28462. const int newFreeBuffer = getFreeBuffer (true);
  28463. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28464. midiBufferToUse = newFreeBuffer;
  28465. }
  28466. }
  28467. else
  28468. {
  28469. // probably a feedback loop, so just use an empty one..
  28470. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28471. }
  28472. }
  28473. else
  28474. {
  28475. // More than one midi input being mixed..
  28476. int reusableInputIndex = -1;
  28477. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28478. {
  28479. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28480. AudioProcessorGraph::midiChannelIndex);
  28481. if (sourceBufIndex >= 0
  28482. && ! isBufferNeededLater (ourRenderingIndex,
  28483. AudioProcessorGraph::midiChannelIndex,
  28484. midiSourceNodes.getUnchecked(i),
  28485. AudioProcessorGraph::midiChannelIndex))
  28486. {
  28487. // we've found one of our input buffers that can be re-used..
  28488. reusableInputIndex = i;
  28489. midiBufferToUse = sourceBufIndex;
  28490. break;
  28491. }
  28492. }
  28493. if (reusableInputIndex < 0)
  28494. {
  28495. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28496. midiBufferToUse = getFreeBuffer (true);
  28497. jassert (midiBufferToUse >= 0);
  28498. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28499. AudioProcessorGraph::midiChannelIndex);
  28500. if (srcIndex >= 0)
  28501. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28502. else
  28503. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28504. reusableInputIndex = 0;
  28505. }
  28506. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28507. {
  28508. if (j != reusableInputIndex)
  28509. {
  28510. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28511. AudioProcessorGraph::midiChannelIndex);
  28512. if (srcIndex >= 0)
  28513. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28514. }
  28515. }
  28516. }
  28517. if (node->processor->producesMidi())
  28518. markBufferAsContaining (midiBufferToUse, node->id,
  28519. AudioProcessorGraph::midiChannelIndex);
  28520. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28521. totalChans, midiBufferToUse));
  28522. }
  28523. int getFreeBuffer (const bool forMidi)
  28524. {
  28525. if (forMidi)
  28526. {
  28527. for (int i = 1; i < midiNodeIds.size(); ++i)
  28528. if (midiNodeIds.getUnchecked(i) < 0)
  28529. return i;
  28530. midiNodeIds.add (-1);
  28531. return midiNodeIds.size() - 1;
  28532. }
  28533. else
  28534. {
  28535. for (int i = 1; i < nodeIds.size(); ++i)
  28536. if (nodeIds.getUnchecked(i) < 0)
  28537. return i;
  28538. nodeIds.add (-1);
  28539. channels.add (0);
  28540. return nodeIds.size() - 1;
  28541. }
  28542. }
  28543. int getReadOnlyEmptyBuffer() const
  28544. {
  28545. return 0;
  28546. }
  28547. int getBufferContaining (const int nodeId, const int outputChannel) const
  28548. {
  28549. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28550. {
  28551. for (int i = midiNodeIds.size(); --i >= 0;)
  28552. if (midiNodeIds.getUnchecked(i) == nodeId)
  28553. return i;
  28554. }
  28555. else
  28556. {
  28557. for (int i = nodeIds.size(); --i >= 0;)
  28558. if (nodeIds.getUnchecked(i) == nodeId
  28559. && channels.getUnchecked(i) == outputChannel)
  28560. return i;
  28561. }
  28562. return -1;
  28563. }
  28564. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28565. {
  28566. int i;
  28567. for (i = 0; i < nodeIds.size(); ++i)
  28568. {
  28569. if (nodeIds.getUnchecked(i) >= 0
  28570. && ! isBufferNeededLater (stepIndex, -1,
  28571. nodeIds.getUnchecked(i),
  28572. channels.getUnchecked(i)))
  28573. {
  28574. nodeIds.set (i, -1);
  28575. }
  28576. }
  28577. for (i = 0; i < midiNodeIds.size(); ++i)
  28578. {
  28579. if (midiNodeIds.getUnchecked(i) >= 0
  28580. && ! isBufferNeededLater (stepIndex, -1,
  28581. midiNodeIds.getUnchecked(i),
  28582. AudioProcessorGraph::midiChannelIndex))
  28583. {
  28584. midiNodeIds.set (i, -1);
  28585. }
  28586. }
  28587. }
  28588. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28589. int inputChannelOfIndexToIgnore,
  28590. const int nodeId,
  28591. const int outputChanIndex) const
  28592. {
  28593. while (stepIndexToSearchFrom < orderedNodes.size())
  28594. {
  28595. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28596. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28597. {
  28598. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28599. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28600. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28601. return true;
  28602. }
  28603. else
  28604. {
  28605. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28606. if (i != inputChannelOfIndexToIgnore
  28607. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28608. node->id, i) != 0)
  28609. return true;
  28610. }
  28611. inputChannelOfIndexToIgnore = -1;
  28612. ++stepIndexToSearchFrom;
  28613. }
  28614. return false;
  28615. }
  28616. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28617. {
  28618. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28619. {
  28620. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28621. midiNodeIds.set (bufferNum, nodeId);
  28622. }
  28623. else
  28624. {
  28625. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28626. nodeIds.set (bufferNum, nodeId);
  28627. channels.set (bufferNum, outputIndex);
  28628. }
  28629. }
  28630. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28631. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28632. };
  28633. }
  28634. void AudioProcessorGraph::clearRenderingSequence()
  28635. {
  28636. const ScopedLock sl (renderLock);
  28637. for (int i = renderingOps.size(); --i >= 0;)
  28638. {
  28639. GraphRenderingOps::AudioGraphRenderingOp* const r
  28640. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28641. renderingOps.remove (i);
  28642. delete r;
  28643. }
  28644. }
  28645. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28646. const uint32 possibleDestinationId,
  28647. const int recursionCheck) const
  28648. {
  28649. if (recursionCheck > 0)
  28650. {
  28651. for (int i = connections.size(); --i >= 0;)
  28652. {
  28653. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28654. if (c->destNodeId == possibleDestinationId
  28655. && (c->sourceNodeId == possibleInputId
  28656. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28657. return true;
  28658. }
  28659. }
  28660. return false;
  28661. }
  28662. void AudioProcessorGraph::buildRenderingSequence()
  28663. {
  28664. VoidArray newRenderingOps;
  28665. int numRenderingBuffersNeeded = 2;
  28666. int numMidiBuffersNeeded = 1;
  28667. {
  28668. MessageManagerLock mml;
  28669. VoidArray orderedNodes;
  28670. int i;
  28671. for (i = 0; i < nodes.size(); ++i)
  28672. {
  28673. Node* const node = nodes.getUnchecked(i);
  28674. node->prepare (getSampleRate(), getBlockSize(), this);
  28675. int j = 0;
  28676. for (; j < orderedNodes.size(); ++j)
  28677. if (isAnInputTo (node->id,
  28678. ((Node*) orderedNodes.getUnchecked (j))->id,
  28679. nodes.size() + 1))
  28680. break;
  28681. orderedNodes.insert (j, node);
  28682. }
  28683. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28684. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28685. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28686. }
  28687. VoidArray oldRenderingOps (renderingOps);
  28688. {
  28689. // swap over to the new rendering sequence..
  28690. const ScopedLock sl (renderLock);
  28691. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28692. renderingBuffers.clear();
  28693. for (int i = midiBuffers.size(); --i >= 0;)
  28694. midiBuffers.getUnchecked(i)->clear();
  28695. while (midiBuffers.size() < numMidiBuffersNeeded)
  28696. midiBuffers.add (new MidiBuffer());
  28697. renderingOps = newRenderingOps;
  28698. }
  28699. for (int i = oldRenderingOps.size(); --i >= 0;)
  28700. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28701. }
  28702. void AudioProcessorGraph::handleAsyncUpdate()
  28703. {
  28704. buildRenderingSequence();
  28705. }
  28706. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28707. {
  28708. currentAudioInputBuffer = 0;
  28709. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28710. currentMidiInputBuffer = 0;
  28711. currentMidiOutputBuffer.clear();
  28712. clearRenderingSequence();
  28713. buildRenderingSequence();
  28714. }
  28715. void AudioProcessorGraph::releaseResources()
  28716. {
  28717. for (int i = 0; i < nodes.size(); ++i)
  28718. nodes.getUnchecked(i)->unprepare();
  28719. renderingBuffers.setSize (1, 1);
  28720. midiBuffers.clear();
  28721. currentAudioInputBuffer = 0;
  28722. currentAudioOutputBuffer.setSize (1, 1);
  28723. currentMidiInputBuffer = 0;
  28724. currentMidiOutputBuffer.clear();
  28725. }
  28726. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28727. {
  28728. const int numSamples = buffer.getNumSamples();
  28729. const ScopedLock sl (renderLock);
  28730. currentAudioInputBuffer = &buffer;
  28731. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28732. currentAudioOutputBuffer.clear();
  28733. currentMidiInputBuffer = &midiMessages;
  28734. currentMidiOutputBuffer.clear();
  28735. int i;
  28736. for (i = 0; i < renderingOps.size(); ++i)
  28737. {
  28738. GraphRenderingOps::AudioGraphRenderingOp* const op
  28739. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28740. op->perform (renderingBuffers, midiBuffers, numSamples);
  28741. }
  28742. for (i = 0; i < buffer.getNumChannels(); ++i)
  28743. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28744. midiMessages.clear();
  28745. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28746. }
  28747. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28748. {
  28749. return "Input " + String (channelIndex + 1);
  28750. }
  28751. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28752. {
  28753. return "Output " + String (channelIndex + 1);
  28754. }
  28755. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28756. {
  28757. return true;
  28758. }
  28759. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28760. {
  28761. return true;
  28762. }
  28763. bool AudioProcessorGraph::acceptsMidi() const
  28764. {
  28765. return true;
  28766. }
  28767. bool AudioProcessorGraph::producesMidi() const
  28768. {
  28769. return true;
  28770. }
  28771. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28772. {
  28773. }
  28774. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28775. {
  28776. }
  28777. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28778. : type (type_),
  28779. graph (0)
  28780. {
  28781. }
  28782. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28783. {
  28784. }
  28785. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28786. {
  28787. switch (type)
  28788. {
  28789. case audioOutputNode:
  28790. return "Audio Output";
  28791. case audioInputNode:
  28792. return "Audio Input";
  28793. case midiOutputNode:
  28794. return "Midi Output";
  28795. case midiInputNode:
  28796. return "Midi Input";
  28797. default:
  28798. break;
  28799. }
  28800. return String::empty;
  28801. }
  28802. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28803. {
  28804. d.name = getName();
  28805. d.uid = d.name.hashCode();
  28806. d.category = "I/O devices";
  28807. d.pluginFormatName = "Internal";
  28808. d.manufacturerName = "Raw Material Software";
  28809. d.version = "1.0";
  28810. d.isInstrument = false;
  28811. d.numInputChannels = getNumInputChannels();
  28812. if (type == audioOutputNode && graph != 0)
  28813. d.numInputChannels = graph->getNumInputChannels();
  28814. d.numOutputChannels = getNumOutputChannels();
  28815. if (type == audioInputNode && graph != 0)
  28816. d.numOutputChannels = graph->getNumOutputChannels();
  28817. }
  28818. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28819. {
  28820. jassert (graph != 0);
  28821. }
  28822. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28823. {
  28824. }
  28825. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28826. MidiBuffer& midiMessages)
  28827. {
  28828. jassert (graph != 0);
  28829. switch (type)
  28830. {
  28831. case audioOutputNode:
  28832. {
  28833. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28834. buffer.getNumChannels()); --i >= 0;)
  28835. {
  28836. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28837. }
  28838. break;
  28839. }
  28840. case audioInputNode:
  28841. {
  28842. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28843. buffer.getNumChannels()); --i >= 0;)
  28844. {
  28845. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28846. }
  28847. break;
  28848. }
  28849. case midiOutputNode:
  28850. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28851. break;
  28852. case midiInputNode:
  28853. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28854. break;
  28855. default:
  28856. break;
  28857. }
  28858. }
  28859. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28860. {
  28861. return type == midiOutputNode;
  28862. }
  28863. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28864. {
  28865. return type == midiInputNode;
  28866. }
  28867. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28868. {
  28869. switch (type)
  28870. {
  28871. case audioOutputNode:
  28872. return "Output " + String (channelIndex + 1);
  28873. case midiOutputNode:
  28874. return "Midi Output";
  28875. default:
  28876. break;
  28877. }
  28878. return String::empty;
  28879. }
  28880. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28881. {
  28882. switch (type)
  28883. {
  28884. case audioInputNode:
  28885. return "Input " + String (channelIndex + 1);
  28886. case midiInputNode:
  28887. return "Midi Input";
  28888. default:
  28889. break;
  28890. }
  28891. return String::empty;
  28892. }
  28893. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28894. {
  28895. return type == audioInputNode || type == audioOutputNode;
  28896. }
  28897. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28898. {
  28899. return isInputChannelStereoPair (index);
  28900. }
  28901. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28902. {
  28903. return type == audioInputNode || type == midiInputNode;
  28904. }
  28905. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28906. {
  28907. return type == audioOutputNode || type == midiOutputNode;
  28908. }
  28909. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28910. {
  28911. return 0;
  28912. }
  28913. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28914. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28915. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28916. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28917. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28918. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28919. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28920. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28921. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28922. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28923. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28924. {
  28925. }
  28926. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28927. {
  28928. }
  28929. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28930. {
  28931. graph = newGraph;
  28932. if (graph != 0)
  28933. {
  28934. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28935. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28936. getSampleRate(),
  28937. getBlockSize());
  28938. updateHostDisplay();
  28939. }
  28940. }
  28941. END_JUCE_NAMESPACE
  28942. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28943. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28944. BEGIN_JUCE_NAMESPACE
  28945. AudioProcessorPlayer::AudioProcessorPlayer()
  28946. : processor (0),
  28947. sampleRate (0),
  28948. blockSize (0),
  28949. isPrepared (false),
  28950. numInputChans (0),
  28951. numOutputChans (0),
  28952. tempBuffer (1, 1)
  28953. {
  28954. }
  28955. AudioProcessorPlayer::~AudioProcessorPlayer()
  28956. {
  28957. setProcessor (0);
  28958. }
  28959. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28960. {
  28961. if (processor != processorToPlay)
  28962. {
  28963. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28964. {
  28965. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28966. sampleRate, blockSize);
  28967. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28968. }
  28969. AudioProcessor* oldOne;
  28970. {
  28971. const ScopedLock sl (lock);
  28972. oldOne = isPrepared ? processor : 0;
  28973. processor = processorToPlay;
  28974. isPrepared = true;
  28975. }
  28976. if (oldOne != 0)
  28977. oldOne->releaseResources();
  28978. }
  28979. }
  28980. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28981. int numInputChannels,
  28982. float** outputChannelData,
  28983. int numOutputChannels,
  28984. int numSamples)
  28985. {
  28986. // these should have been prepared by audioDeviceAboutToStart()...
  28987. jassert (sampleRate > 0 && blockSize > 0);
  28988. incomingMidi.clear();
  28989. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28990. int i, totalNumChans = 0;
  28991. if (numInputChannels > numOutputChannels)
  28992. {
  28993. // if there aren't enough output channels for the number of
  28994. // inputs, we need to create some temporary extra ones (can't
  28995. // use the input data in case it gets written to)
  28996. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  28997. false, false, true);
  28998. for (i = 0; i < numOutputChannels; ++i)
  28999. {
  29000. channels[totalNumChans] = outputChannelData[i];
  29001. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29002. ++totalNumChans;
  29003. }
  29004. for (i = numOutputChannels; i < numInputChannels; ++i)
  29005. {
  29006. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29007. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29008. ++totalNumChans;
  29009. }
  29010. }
  29011. else
  29012. {
  29013. for (i = 0; i < numInputChannels; ++i)
  29014. {
  29015. channels[totalNumChans] = outputChannelData[i];
  29016. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29017. ++totalNumChans;
  29018. }
  29019. for (i = numInputChannels; i < numOutputChannels; ++i)
  29020. {
  29021. channels[totalNumChans] = outputChannelData[i];
  29022. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29023. ++totalNumChans;
  29024. }
  29025. }
  29026. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29027. const ScopedLock sl (lock);
  29028. if (processor != 0)
  29029. processor->processBlock (buffer, incomingMidi);
  29030. }
  29031. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29032. {
  29033. const ScopedLock sl (lock);
  29034. sampleRate = device->getCurrentSampleRate();
  29035. blockSize = device->getCurrentBufferSizeSamples();
  29036. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29037. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29038. messageCollector.reset (sampleRate);
  29039. zeromem (channels, sizeof (channels));
  29040. if (processor != 0)
  29041. {
  29042. if (isPrepared)
  29043. processor->releaseResources();
  29044. AudioProcessor* const oldProcessor = processor;
  29045. setProcessor (0);
  29046. setProcessor (oldProcessor);
  29047. }
  29048. }
  29049. void AudioProcessorPlayer::audioDeviceStopped()
  29050. {
  29051. const ScopedLock sl (lock);
  29052. if (processor != 0 && isPrepared)
  29053. processor->releaseResources();
  29054. sampleRate = 0.0;
  29055. blockSize = 0;
  29056. isPrepared = false;
  29057. tempBuffer.setSize (1, 1);
  29058. }
  29059. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29060. {
  29061. messageCollector.addMessageToQueue (message);
  29062. }
  29063. END_JUCE_NAMESPACE
  29064. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29065. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29066. BEGIN_JUCE_NAMESPACE
  29067. class ProcessorParameterPropertyComp : public PropertyComponent,
  29068. public AudioProcessorListener,
  29069. public AsyncUpdater
  29070. {
  29071. public:
  29072. ProcessorParameterPropertyComp (const String& name,
  29073. AudioProcessor* const owner_,
  29074. const int index_)
  29075. : PropertyComponent (name),
  29076. owner (owner_),
  29077. index (index_)
  29078. {
  29079. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29080. owner_->addListener (this);
  29081. }
  29082. ~ProcessorParameterPropertyComp()
  29083. {
  29084. owner->removeListener (this);
  29085. deleteAllChildren();
  29086. }
  29087. void refresh()
  29088. {
  29089. slider->setValue (owner->getParameter (index), false);
  29090. }
  29091. void audioProcessorChanged (AudioProcessor*) {}
  29092. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29093. {
  29094. if (parameterIndex == index)
  29095. triggerAsyncUpdate();
  29096. }
  29097. void handleAsyncUpdate()
  29098. {
  29099. refresh();
  29100. }
  29101. juce_UseDebuggingNewOperator
  29102. private:
  29103. AudioProcessor* const owner;
  29104. const int index;
  29105. Slider* slider;
  29106. class ParamSlider : public Slider
  29107. {
  29108. public:
  29109. ParamSlider (AudioProcessor* const owner_, const int index_)
  29110. : Slider (String::empty),
  29111. owner (owner_),
  29112. index (index_)
  29113. {
  29114. setRange (0.0, 1.0, 0.0);
  29115. setSliderStyle (Slider::LinearBar);
  29116. setTextBoxIsEditable (false);
  29117. setScrollWheelEnabled (false);
  29118. }
  29119. ~ParamSlider()
  29120. {
  29121. }
  29122. void valueChanged()
  29123. {
  29124. const float newVal = (float) getValue();
  29125. if (owner->getParameter (index) != newVal)
  29126. owner->setParameter (index, newVal);
  29127. }
  29128. const String getTextFromValue (double /*value*/)
  29129. {
  29130. return owner->getParameterText (index);
  29131. }
  29132. juce_UseDebuggingNewOperator
  29133. private:
  29134. AudioProcessor* const owner;
  29135. const int index;
  29136. ParamSlider (const ParamSlider&);
  29137. ParamSlider& operator= (const ParamSlider&);
  29138. };
  29139. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29140. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29141. };
  29142. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29143. : AudioProcessorEditor (owner_)
  29144. {
  29145. setOpaque (true);
  29146. addAndMakeVisible (panel = new PropertyPanel());
  29147. Array <PropertyComponent*> params;
  29148. const int numParams = owner_->getNumParameters();
  29149. int totalHeight = 0;
  29150. for (int i = 0; i < numParams; ++i)
  29151. {
  29152. String name (owner_->getParameterName (i));
  29153. if (name.trim().isEmpty())
  29154. name = "Unnamed";
  29155. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29156. params.add (pc);
  29157. totalHeight += pc->getPreferredHeight();
  29158. }
  29159. panel->addProperties (params);
  29160. setSize (400, jlimit (25, 400, totalHeight));
  29161. }
  29162. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29163. {
  29164. deleteAllChildren();
  29165. }
  29166. void GenericAudioProcessorEditor::paint (Graphics& g)
  29167. {
  29168. g.fillAll (Colours::white);
  29169. }
  29170. void GenericAudioProcessorEditor::resized()
  29171. {
  29172. panel->setSize (getWidth(), getHeight());
  29173. }
  29174. END_JUCE_NAMESPACE
  29175. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29176. /*** Start of inlined file: juce_Sampler.cpp ***/
  29177. BEGIN_JUCE_NAMESPACE
  29178. SamplerSound::SamplerSound (const String& name_,
  29179. AudioFormatReader& source,
  29180. const BigInteger& midiNotes_,
  29181. const int midiNoteForNormalPitch,
  29182. const double attackTimeSecs,
  29183. const double releaseTimeSecs,
  29184. const double maxSampleLengthSeconds)
  29185. : name (name_),
  29186. midiNotes (midiNotes_),
  29187. midiRootNote (midiNoteForNormalPitch)
  29188. {
  29189. sourceSampleRate = source.sampleRate;
  29190. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29191. {
  29192. length = 0;
  29193. attackSamples = 0;
  29194. releaseSamples = 0;
  29195. }
  29196. else
  29197. {
  29198. length = jmin ((int) source.lengthInSamples,
  29199. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29200. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29201. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29202. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29203. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29204. }
  29205. }
  29206. SamplerSound::~SamplerSound()
  29207. {
  29208. }
  29209. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29210. {
  29211. return midiNotes [midiNoteNumber];
  29212. }
  29213. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29214. {
  29215. return true;
  29216. }
  29217. SamplerVoice::SamplerVoice()
  29218. : pitchRatio (0.0),
  29219. sourceSamplePosition (0.0),
  29220. lgain (0.0f),
  29221. rgain (0.0f),
  29222. isInAttack (false),
  29223. isInRelease (false)
  29224. {
  29225. }
  29226. SamplerVoice::~SamplerVoice()
  29227. {
  29228. }
  29229. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29230. {
  29231. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29232. }
  29233. void SamplerVoice::startNote (const int midiNoteNumber,
  29234. const float velocity,
  29235. SynthesiserSound* s,
  29236. const int /*currentPitchWheelPosition*/)
  29237. {
  29238. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29239. jassert (sound != 0); // this object can only play SamplerSounds!
  29240. if (sound != 0)
  29241. {
  29242. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29243. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29244. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29245. sourceSamplePosition = 0.0;
  29246. lgain = velocity;
  29247. rgain = velocity;
  29248. isInAttack = (sound->attackSamples > 0);
  29249. isInRelease = false;
  29250. if (isInAttack)
  29251. {
  29252. attackReleaseLevel = 0.0f;
  29253. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29254. }
  29255. else
  29256. {
  29257. attackReleaseLevel = 1.0f;
  29258. attackDelta = 0.0f;
  29259. }
  29260. if (sound->releaseSamples > 0)
  29261. {
  29262. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29263. }
  29264. else
  29265. {
  29266. releaseDelta = 0.0f;
  29267. }
  29268. }
  29269. }
  29270. void SamplerVoice::stopNote (const bool allowTailOff)
  29271. {
  29272. if (allowTailOff)
  29273. {
  29274. isInAttack = false;
  29275. isInRelease = true;
  29276. }
  29277. else
  29278. {
  29279. clearCurrentNote();
  29280. }
  29281. }
  29282. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29283. {
  29284. }
  29285. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29286. const int /*newValue*/)
  29287. {
  29288. }
  29289. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29290. {
  29291. const SamplerSound* const playingSound = static_cast <SamplerSound*> (getCurrentlyPlayingSound().getObject());
  29292. if (playingSound != 0)
  29293. {
  29294. const float* const inL = playingSound->data->getSampleData (0, 0);
  29295. const float* const inR = playingSound->data->getNumChannels() > 1
  29296. ? playingSound->data->getSampleData (1, 0) : 0;
  29297. float* outL = outputBuffer.getSampleData (0, startSample);
  29298. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29299. while (--numSamples >= 0)
  29300. {
  29301. const int pos = (int) sourceSamplePosition;
  29302. const float alpha = (float) (sourceSamplePosition - pos);
  29303. const float invAlpha = 1.0f - alpha;
  29304. // just using a very simple linear interpolation here..
  29305. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29306. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29307. : l;
  29308. l *= lgain;
  29309. r *= rgain;
  29310. if (isInAttack)
  29311. {
  29312. l *= attackReleaseLevel;
  29313. r *= attackReleaseLevel;
  29314. attackReleaseLevel += attackDelta;
  29315. if (attackReleaseLevel >= 1.0f)
  29316. {
  29317. attackReleaseLevel = 1.0f;
  29318. isInAttack = false;
  29319. }
  29320. }
  29321. else if (isInRelease)
  29322. {
  29323. l *= attackReleaseLevel;
  29324. r *= attackReleaseLevel;
  29325. attackReleaseLevel += releaseDelta;
  29326. if (attackReleaseLevel <= 0.0f)
  29327. {
  29328. stopNote (false);
  29329. break;
  29330. }
  29331. }
  29332. if (outR != 0)
  29333. {
  29334. *outL++ += l;
  29335. *outR++ += r;
  29336. }
  29337. else
  29338. {
  29339. *outL++ += (l + r) * 0.5f;
  29340. }
  29341. sourceSamplePosition += pitchRatio;
  29342. if (sourceSamplePosition > playingSound->length)
  29343. {
  29344. stopNote (false);
  29345. break;
  29346. }
  29347. }
  29348. }
  29349. }
  29350. END_JUCE_NAMESPACE
  29351. /*** End of inlined file: juce_Sampler.cpp ***/
  29352. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29353. BEGIN_JUCE_NAMESPACE
  29354. SynthesiserSound::SynthesiserSound()
  29355. {
  29356. }
  29357. SynthesiserSound::~SynthesiserSound()
  29358. {
  29359. }
  29360. SynthesiserVoice::SynthesiserVoice()
  29361. : currentSampleRate (44100.0),
  29362. currentlyPlayingNote (-1),
  29363. noteOnTime (0),
  29364. currentlyPlayingSound (0)
  29365. {
  29366. }
  29367. SynthesiserVoice::~SynthesiserVoice()
  29368. {
  29369. }
  29370. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29371. {
  29372. return currentlyPlayingSound != 0
  29373. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29374. }
  29375. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29376. {
  29377. currentSampleRate = newRate;
  29378. }
  29379. void SynthesiserVoice::clearCurrentNote()
  29380. {
  29381. currentlyPlayingNote = -1;
  29382. currentlyPlayingSound = 0;
  29383. }
  29384. Synthesiser::Synthesiser()
  29385. : sampleRate (0),
  29386. lastNoteOnCounter (0),
  29387. shouldStealNotes (true)
  29388. {
  29389. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29390. lastPitchWheelValues[i] = 0x2000;
  29391. }
  29392. Synthesiser::~Synthesiser()
  29393. {
  29394. }
  29395. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29396. {
  29397. const ScopedLock sl (lock);
  29398. return voices [index];
  29399. }
  29400. void Synthesiser::clearVoices()
  29401. {
  29402. const ScopedLock sl (lock);
  29403. voices.clear();
  29404. }
  29405. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29406. {
  29407. const ScopedLock sl (lock);
  29408. voices.add (newVoice);
  29409. }
  29410. void Synthesiser::removeVoice (const int index)
  29411. {
  29412. const ScopedLock sl (lock);
  29413. voices.remove (index);
  29414. }
  29415. void Synthesiser::clearSounds()
  29416. {
  29417. const ScopedLock sl (lock);
  29418. sounds.clear();
  29419. }
  29420. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29421. {
  29422. const ScopedLock sl (lock);
  29423. sounds.add (newSound);
  29424. }
  29425. void Synthesiser::removeSound (const int index)
  29426. {
  29427. const ScopedLock sl (lock);
  29428. sounds.remove (index);
  29429. }
  29430. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29431. {
  29432. shouldStealNotes = shouldStealNotes_;
  29433. }
  29434. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29435. {
  29436. if (sampleRate != newRate)
  29437. {
  29438. const ScopedLock sl (lock);
  29439. allNotesOff (0, false);
  29440. sampleRate = newRate;
  29441. for (int i = voices.size(); --i >= 0;)
  29442. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29443. }
  29444. }
  29445. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29446. const MidiBuffer& midiData,
  29447. int startSample,
  29448. int numSamples)
  29449. {
  29450. // must set the sample rate before using this!
  29451. jassert (sampleRate != 0);
  29452. const ScopedLock sl (lock);
  29453. MidiBuffer::Iterator midiIterator (midiData);
  29454. midiIterator.setNextSamplePosition (startSample);
  29455. MidiMessage m (0xf4, 0.0);
  29456. while (numSamples > 0)
  29457. {
  29458. int midiEventPos;
  29459. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29460. && midiEventPos < startSample + numSamples;
  29461. const int numThisTime = useEvent ? midiEventPos - startSample
  29462. : numSamples;
  29463. if (numThisTime > 0)
  29464. {
  29465. for (int i = voices.size(); --i >= 0;)
  29466. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29467. }
  29468. if (useEvent)
  29469. {
  29470. if (m.isNoteOn())
  29471. {
  29472. const int channel = m.getChannel();
  29473. noteOn (channel,
  29474. m.getNoteNumber(),
  29475. m.getFloatVelocity());
  29476. }
  29477. else if (m.isNoteOff())
  29478. {
  29479. noteOff (m.getChannel(),
  29480. m.getNoteNumber(),
  29481. true);
  29482. }
  29483. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29484. {
  29485. allNotesOff (m.getChannel(), true);
  29486. }
  29487. else if (m.isPitchWheel())
  29488. {
  29489. const int channel = m.getChannel();
  29490. const int wheelPos = m.getPitchWheelValue();
  29491. lastPitchWheelValues [channel - 1] = wheelPos;
  29492. handlePitchWheel (channel, wheelPos);
  29493. }
  29494. else if (m.isController())
  29495. {
  29496. handleController (m.getChannel(),
  29497. m.getControllerNumber(),
  29498. m.getControllerValue());
  29499. }
  29500. }
  29501. startSample += numThisTime;
  29502. numSamples -= numThisTime;
  29503. }
  29504. }
  29505. void Synthesiser::noteOn (const int midiChannel,
  29506. const int midiNoteNumber,
  29507. const float velocity)
  29508. {
  29509. const ScopedLock sl (lock);
  29510. for (int i = sounds.size(); --i >= 0;)
  29511. {
  29512. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29513. if (sound->appliesToNote (midiNoteNumber)
  29514. && sound->appliesToChannel (midiChannel))
  29515. {
  29516. startVoice (findFreeVoice (sound, shouldStealNotes),
  29517. sound, midiChannel, midiNoteNumber, velocity);
  29518. }
  29519. }
  29520. }
  29521. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29522. SynthesiserSound* const sound,
  29523. const int midiChannel,
  29524. const int midiNoteNumber,
  29525. const float velocity)
  29526. {
  29527. if (voice != 0 && sound != 0)
  29528. {
  29529. if (voice->currentlyPlayingSound != 0)
  29530. voice->stopNote (false);
  29531. voice->startNote (midiNoteNumber,
  29532. velocity,
  29533. sound,
  29534. lastPitchWheelValues [midiChannel - 1]);
  29535. voice->currentlyPlayingNote = midiNoteNumber;
  29536. voice->noteOnTime = ++lastNoteOnCounter;
  29537. voice->currentlyPlayingSound = sound;
  29538. }
  29539. }
  29540. void Synthesiser::noteOff (const int midiChannel,
  29541. const int midiNoteNumber,
  29542. const bool allowTailOff)
  29543. {
  29544. const ScopedLock sl (lock);
  29545. for (int i = voices.size(); --i >= 0;)
  29546. {
  29547. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29548. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29549. {
  29550. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29551. if (sound != 0
  29552. && sound->appliesToNote (midiNoteNumber)
  29553. && sound->appliesToChannel (midiChannel))
  29554. {
  29555. voice->stopNote (allowTailOff);
  29556. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29557. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29558. }
  29559. }
  29560. }
  29561. }
  29562. void Synthesiser::allNotesOff (const int midiChannel,
  29563. const bool allowTailOff)
  29564. {
  29565. const ScopedLock sl (lock);
  29566. for (int i = voices.size(); --i >= 0;)
  29567. {
  29568. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29569. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29570. voice->stopNote (allowTailOff);
  29571. }
  29572. }
  29573. void Synthesiser::handlePitchWheel (const int midiChannel,
  29574. const int wheelValue)
  29575. {
  29576. const ScopedLock sl (lock);
  29577. for (int i = voices.size(); --i >= 0;)
  29578. {
  29579. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29580. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29581. {
  29582. voice->pitchWheelMoved (wheelValue);
  29583. }
  29584. }
  29585. }
  29586. void Synthesiser::handleController (const int midiChannel,
  29587. const int controllerNumber,
  29588. const int controllerValue)
  29589. {
  29590. const ScopedLock sl (lock);
  29591. for (int i = voices.size(); --i >= 0;)
  29592. {
  29593. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29594. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29595. voice->controllerMoved (controllerNumber, controllerValue);
  29596. }
  29597. }
  29598. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29599. const bool stealIfNoneAvailable) const
  29600. {
  29601. const ScopedLock sl (lock);
  29602. for (int i = voices.size(); --i >= 0;)
  29603. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29604. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29605. return voices.getUnchecked (i);
  29606. if (stealIfNoneAvailable)
  29607. {
  29608. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29609. SynthesiserVoice* oldest = 0;
  29610. for (int i = voices.size(); --i >= 0;)
  29611. {
  29612. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29613. if (voice->canPlaySound (soundToPlay)
  29614. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29615. oldest = voice;
  29616. }
  29617. jassert (oldest != 0);
  29618. return oldest;
  29619. }
  29620. return 0;
  29621. }
  29622. END_JUCE_NAMESPACE
  29623. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29624. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29625. BEGIN_JUCE_NAMESPACE
  29626. ActionBroadcaster::ActionBroadcaster() throw()
  29627. {
  29628. // are you trying to create this object before or after juce has been intialised??
  29629. jassert (MessageManager::instance != 0);
  29630. }
  29631. ActionBroadcaster::~ActionBroadcaster()
  29632. {
  29633. // all event-based objects must be deleted BEFORE juce is shut down!
  29634. jassert (MessageManager::instance != 0);
  29635. }
  29636. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29637. {
  29638. actionListenerList.addActionListener (listener);
  29639. }
  29640. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29641. {
  29642. jassert (actionListenerList.isValidMessageListener());
  29643. if (actionListenerList.isValidMessageListener())
  29644. actionListenerList.removeActionListener (listener);
  29645. }
  29646. void ActionBroadcaster::removeAllActionListeners()
  29647. {
  29648. actionListenerList.removeAllActionListeners();
  29649. }
  29650. void ActionBroadcaster::sendActionMessage (const String& message) const
  29651. {
  29652. actionListenerList.sendActionMessage (message);
  29653. }
  29654. END_JUCE_NAMESPACE
  29655. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29656. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29657. BEGIN_JUCE_NAMESPACE
  29658. // special message of our own with a string in it
  29659. class ActionMessage : public Message
  29660. {
  29661. public:
  29662. const String message;
  29663. ActionMessage (const String& messageText,
  29664. void* const listener_) throw()
  29665. : message (messageText)
  29666. {
  29667. pointerParameter = listener_;
  29668. }
  29669. ~ActionMessage() throw()
  29670. {
  29671. }
  29672. private:
  29673. ActionMessage (const ActionMessage&);
  29674. ActionMessage& operator= (const ActionMessage&);
  29675. };
  29676. ActionListenerList::ActionListenerList() throw()
  29677. {
  29678. }
  29679. ActionListenerList::~ActionListenerList() throw()
  29680. {
  29681. }
  29682. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29683. {
  29684. const ScopedLock sl (actionListenerLock_);
  29685. jassert (listener != 0);
  29686. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29687. if (listener != 0)
  29688. actionListeners_.add (listener);
  29689. }
  29690. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29691. {
  29692. const ScopedLock sl (actionListenerLock_);
  29693. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29694. actionListeners_.removeValue (listener);
  29695. }
  29696. void ActionListenerList::removeAllActionListeners() throw()
  29697. {
  29698. const ScopedLock sl (actionListenerLock_);
  29699. actionListeners_.clear();
  29700. }
  29701. void ActionListenerList::sendActionMessage (const String& message) const
  29702. {
  29703. const ScopedLock sl (actionListenerLock_);
  29704. for (int i = actionListeners_.size(); --i >= 0;)
  29705. postMessage (new ActionMessage (message, static_cast <ActionListener*> (actionListeners_.getUnchecked(i))));
  29706. }
  29707. void ActionListenerList::handleMessage (const Message& message)
  29708. {
  29709. const ActionMessage& am = (const ActionMessage&) message;
  29710. if (actionListeners_.contains (am.pointerParameter))
  29711. static_cast <ActionListener*> (am.pointerParameter)->actionListenerCallback (am.message);
  29712. }
  29713. END_JUCE_NAMESPACE
  29714. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29715. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29716. BEGIN_JUCE_NAMESPACE
  29717. AsyncUpdater::AsyncUpdater() throw()
  29718. : asyncMessagePending (false)
  29719. {
  29720. internalAsyncHandler.owner = this;
  29721. }
  29722. AsyncUpdater::~AsyncUpdater()
  29723. {
  29724. }
  29725. void AsyncUpdater::triggerAsyncUpdate() throw()
  29726. {
  29727. if (! asyncMessagePending)
  29728. {
  29729. asyncMessagePending = true;
  29730. internalAsyncHandler.postMessage (new Message());
  29731. }
  29732. }
  29733. void AsyncUpdater::cancelPendingUpdate() throw()
  29734. {
  29735. asyncMessagePending = false;
  29736. }
  29737. void AsyncUpdater::handleUpdateNowIfNeeded()
  29738. {
  29739. if (asyncMessagePending)
  29740. {
  29741. asyncMessagePending = false;
  29742. handleAsyncUpdate();
  29743. }
  29744. }
  29745. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29746. {
  29747. owner->handleUpdateNowIfNeeded();
  29748. }
  29749. END_JUCE_NAMESPACE
  29750. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29751. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29752. BEGIN_JUCE_NAMESPACE
  29753. ChangeBroadcaster::ChangeBroadcaster() throw()
  29754. {
  29755. // are you trying to create this object before or after juce has been intialised??
  29756. jassert (MessageManager::instance != 0);
  29757. }
  29758. ChangeBroadcaster::~ChangeBroadcaster()
  29759. {
  29760. // all event-based objects must be deleted BEFORE juce is shut down!
  29761. jassert (MessageManager::instance != 0);
  29762. }
  29763. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29764. {
  29765. changeListenerList.addChangeListener (listener);
  29766. }
  29767. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29768. {
  29769. jassert (changeListenerList.isValidMessageListener());
  29770. if (changeListenerList.isValidMessageListener())
  29771. changeListenerList.removeChangeListener (listener);
  29772. }
  29773. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29774. {
  29775. changeListenerList.removeAllChangeListeners();
  29776. }
  29777. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29778. {
  29779. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29780. }
  29781. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29782. {
  29783. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29784. }
  29785. void ChangeBroadcaster::dispatchPendingMessages()
  29786. {
  29787. changeListenerList.dispatchPendingMessages();
  29788. }
  29789. END_JUCE_NAMESPACE
  29790. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29791. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29792. BEGIN_JUCE_NAMESPACE
  29793. ChangeListenerList::ChangeListenerList() throw()
  29794. : lastChangedObject (0),
  29795. messagePending (false)
  29796. {
  29797. }
  29798. ChangeListenerList::~ChangeListenerList() throw()
  29799. {
  29800. }
  29801. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29802. {
  29803. const ScopedLock sl (lock);
  29804. jassert (listener != 0);
  29805. if (listener != 0)
  29806. listeners.add (listener);
  29807. }
  29808. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29809. {
  29810. const ScopedLock sl (lock);
  29811. listeners.removeValue (listener);
  29812. }
  29813. void ChangeListenerList::removeAllChangeListeners() throw()
  29814. {
  29815. const ScopedLock sl (lock);
  29816. listeners.clear();
  29817. }
  29818. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29819. {
  29820. const ScopedLock sl (lock);
  29821. if ((! messagePending) && (listeners.size() > 0))
  29822. {
  29823. lastChangedObject = objectThatHasChanged;
  29824. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29825. messagePending = true;
  29826. }
  29827. }
  29828. void ChangeListenerList::handleMessage (const Message& message)
  29829. {
  29830. sendSynchronousChangeMessage (message.pointerParameter);
  29831. }
  29832. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29833. {
  29834. const ScopedLock sl (lock);
  29835. messagePending = false;
  29836. for (int i = listeners.size(); --i >= 0;)
  29837. {
  29838. ChangeListener* const l = static_cast <ChangeListener*> (listeners.getUnchecked (i));
  29839. {
  29840. const ScopedUnlock tempUnlocker (lock);
  29841. l->changeListenerCallback (objectThatHasChanged);
  29842. }
  29843. i = jmin (i, listeners.size());
  29844. }
  29845. }
  29846. void ChangeListenerList::dispatchPendingMessages()
  29847. {
  29848. if (messagePending)
  29849. sendSynchronousChangeMessage (lastChangedObject);
  29850. }
  29851. END_JUCE_NAMESPACE
  29852. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29853. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29854. BEGIN_JUCE_NAMESPACE
  29855. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29856. const uint32 magicMessageHeaderNumber)
  29857. : Thread ("Juce IPC connection"),
  29858. callbackConnectionState (false),
  29859. useMessageThread (callbacksOnMessageThread),
  29860. magicMessageHeader (magicMessageHeaderNumber),
  29861. pipeReceiveMessageTimeout (-1)
  29862. {
  29863. }
  29864. InterprocessConnection::~InterprocessConnection()
  29865. {
  29866. callbackConnectionState = false;
  29867. disconnect();
  29868. }
  29869. bool InterprocessConnection::connectToSocket (const String& hostName,
  29870. const int portNumber,
  29871. const int timeOutMillisecs)
  29872. {
  29873. disconnect();
  29874. const ScopedLock sl (pipeAndSocketLock);
  29875. socket = new StreamingSocket();
  29876. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29877. {
  29878. connectionMadeInt();
  29879. startThread();
  29880. return true;
  29881. }
  29882. else
  29883. {
  29884. socket = 0;
  29885. return false;
  29886. }
  29887. }
  29888. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29889. const int pipeReceiveMessageTimeoutMs)
  29890. {
  29891. disconnect();
  29892. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29893. if (newPipe->openExisting (pipeName))
  29894. {
  29895. const ScopedLock sl (pipeAndSocketLock);
  29896. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29897. initialiseWithPipe (newPipe.release());
  29898. return true;
  29899. }
  29900. return false;
  29901. }
  29902. bool InterprocessConnection::createPipe (const String& pipeName,
  29903. const int pipeReceiveMessageTimeoutMs)
  29904. {
  29905. disconnect();
  29906. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29907. if (newPipe->createNewPipe (pipeName))
  29908. {
  29909. const ScopedLock sl (pipeAndSocketLock);
  29910. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29911. initialiseWithPipe (newPipe.release());
  29912. return true;
  29913. }
  29914. return false;
  29915. }
  29916. void InterprocessConnection::disconnect()
  29917. {
  29918. if (socket != 0)
  29919. socket->close();
  29920. if (pipe != 0)
  29921. {
  29922. pipe->cancelPendingReads();
  29923. pipe->close();
  29924. }
  29925. stopThread (4000);
  29926. {
  29927. const ScopedLock sl (pipeAndSocketLock);
  29928. socket = 0;
  29929. pipe = 0;
  29930. }
  29931. connectionLostInt();
  29932. }
  29933. bool InterprocessConnection::isConnected() const
  29934. {
  29935. const ScopedLock sl (pipeAndSocketLock);
  29936. return ((socket != 0 && socket->isConnected())
  29937. || (pipe != 0 && pipe->isOpen()))
  29938. && isThreadRunning();
  29939. }
  29940. const String InterprocessConnection::getConnectedHostName() const
  29941. {
  29942. if (pipe != 0)
  29943. {
  29944. return "localhost";
  29945. }
  29946. else if (socket != 0)
  29947. {
  29948. if (! socket->isLocal())
  29949. return socket->getHostName();
  29950. return "localhost";
  29951. }
  29952. return String::empty;
  29953. }
  29954. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29955. {
  29956. uint32 messageHeader[2];
  29957. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29958. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29959. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29960. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29961. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29962. size_t bytesWritten = 0;
  29963. const ScopedLock sl (pipeAndSocketLock);
  29964. if (socket != 0)
  29965. {
  29966. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29967. }
  29968. else if (pipe != 0)
  29969. {
  29970. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29971. }
  29972. if (bytesWritten < 0)
  29973. {
  29974. // error..
  29975. return false;
  29976. }
  29977. return (bytesWritten == messageData.getSize());
  29978. }
  29979. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29980. {
  29981. jassert (socket == 0);
  29982. socket = socket_;
  29983. connectionMadeInt();
  29984. startThread();
  29985. }
  29986. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29987. {
  29988. jassert (pipe == 0);
  29989. pipe = pipe_;
  29990. connectionMadeInt();
  29991. startThread();
  29992. }
  29993. const int messageMagicNumber = 0xb734128b;
  29994. void InterprocessConnection::handleMessage (const Message& message)
  29995. {
  29996. if (message.intParameter1 == messageMagicNumber)
  29997. {
  29998. switch (message.intParameter2)
  29999. {
  30000. case 0:
  30001. {
  30002. ScopedPointer <MemoryBlock> data (static_cast <MemoryBlock*> (message.pointerParameter));
  30003. messageReceived (*data);
  30004. break;
  30005. }
  30006. case 1:
  30007. connectionMade();
  30008. break;
  30009. case 2:
  30010. connectionLost();
  30011. break;
  30012. }
  30013. }
  30014. }
  30015. void InterprocessConnection::connectionMadeInt()
  30016. {
  30017. if (! callbackConnectionState)
  30018. {
  30019. callbackConnectionState = true;
  30020. if (useMessageThread)
  30021. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30022. else
  30023. connectionMade();
  30024. }
  30025. }
  30026. void InterprocessConnection::connectionLostInt()
  30027. {
  30028. if (callbackConnectionState)
  30029. {
  30030. callbackConnectionState = false;
  30031. if (useMessageThread)
  30032. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30033. else
  30034. connectionLost();
  30035. }
  30036. }
  30037. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30038. {
  30039. jassert (callbackConnectionState);
  30040. if (useMessageThread)
  30041. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30042. else
  30043. messageReceived (data);
  30044. }
  30045. bool InterprocessConnection::readNextMessageInt()
  30046. {
  30047. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30048. uint32 messageHeader[2];
  30049. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30050. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30051. if (bytes == sizeof (messageHeader)
  30052. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30053. {
  30054. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30055. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30056. {
  30057. MemoryBlock messageData (bytesInMessage, true);
  30058. int bytesRead = 0;
  30059. while (bytesInMessage > 0)
  30060. {
  30061. if (threadShouldExit())
  30062. return false;
  30063. const int numThisTime = jmin (bytesInMessage, 65536);
  30064. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  30065. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  30066. if (bytesIn <= 0)
  30067. break;
  30068. bytesRead += bytesIn;
  30069. bytesInMessage -= bytesIn;
  30070. }
  30071. if (bytesRead >= 0)
  30072. deliverDataInt (messageData);
  30073. }
  30074. }
  30075. else if (bytes < 0)
  30076. {
  30077. {
  30078. const ScopedLock sl (pipeAndSocketLock);
  30079. socket = 0;
  30080. }
  30081. connectionLostInt();
  30082. return false;
  30083. }
  30084. return true;
  30085. }
  30086. void InterprocessConnection::run()
  30087. {
  30088. while (! threadShouldExit())
  30089. {
  30090. if (socket != 0)
  30091. {
  30092. const int ready = socket->waitUntilReady (true, 0);
  30093. if (ready < 0)
  30094. {
  30095. {
  30096. const ScopedLock sl (pipeAndSocketLock);
  30097. socket = 0;
  30098. }
  30099. connectionLostInt();
  30100. break;
  30101. }
  30102. else if (ready > 0)
  30103. {
  30104. if (! readNextMessageInt())
  30105. break;
  30106. }
  30107. else
  30108. {
  30109. Thread::sleep (2);
  30110. }
  30111. }
  30112. else if (pipe != 0)
  30113. {
  30114. if (! pipe->isOpen())
  30115. {
  30116. {
  30117. const ScopedLock sl (pipeAndSocketLock);
  30118. pipe = 0;
  30119. }
  30120. connectionLostInt();
  30121. break;
  30122. }
  30123. else
  30124. {
  30125. if (! readNextMessageInt())
  30126. break;
  30127. }
  30128. }
  30129. else
  30130. {
  30131. break;
  30132. }
  30133. }
  30134. }
  30135. END_JUCE_NAMESPACE
  30136. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30137. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30138. BEGIN_JUCE_NAMESPACE
  30139. InterprocessConnectionServer::InterprocessConnectionServer()
  30140. : Thread ("Juce IPC server")
  30141. {
  30142. }
  30143. InterprocessConnectionServer::~InterprocessConnectionServer()
  30144. {
  30145. stop();
  30146. }
  30147. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30148. {
  30149. stop();
  30150. socket = new StreamingSocket();
  30151. if (socket->createListener (portNumber))
  30152. {
  30153. startThread();
  30154. return true;
  30155. }
  30156. socket = 0;
  30157. return false;
  30158. }
  30159. void InterprocessConnectionServer::stop()
  30160. {
  30161. signalThreadShouldExit();
  30162. if (socket != 0)
  30163. socket->close();
  30164. stopThread (4000);
  30165. socket = 0;
  30166. }
  30167. void InterprocessConnectionServer::run()
  30168. {
  30169. while ((! threadShouldExit()) && socket != 0)
  30170. {
  30171. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30172. if (clientSocket != 0)
  30173. {
  30174. InterprocessConnection* newConnection = createConnectionObject();
  30175. if (newConnection != 0)
  30176. newConnection->initialiseWithSocket (clientSocket.release());
  30177. }
  30178. }
  30179. }
  30180. END_JUCE_NAMESPACE
  30181. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30182. /*** Start of inlined file: juce_Message.cpp ***/
  30183. BEGIN_JUCE_NAMESPACE
  30184. Message::Message() throw()
  30185. : intParameter1 (0),
  30186. intParameter2 (0),
  30187. intParameter3 (0),
  30188. pointerParameter (0)
  30189. {
  30190. }
  30191. Message::Message (const int intParameter1_,
  30192. const int intParameter2_,
  30193. const int intParameter3_,
  30194. void* const pointerParameter_) throw()
  30195. : intParameter1 (intParameter1_),
  30196. intParameter2 (intParameter2_),
  30197. intParameter3 (intParameter3_),
  30198. pointerParameter (pointerParameter_)
  30199. {
  30200. }
  30201. Message::~Message() throw()
  30202. {
  30203. }
  30204. END_JUCE_NAMESPACE
  30205. /*** End of inlined file: juce_Message.cpp ***/
  30206. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30207. BEGIN_JUCE_NAMESPACE
  30208. MessageListener::MessageListener() throw()
  30209. {
  30210. // are you trying to create a messagelistener before or after juce has been intialised??
  30211. jassert (MessageManager::instance != 0);
  30212. if (MessageManager::instance != 0)
  30213. MessageManager::instance->messageListeners.add (this);
  30214. }
  30215. MessageListener::~MessageListener()
  30216. {
  30217. if (MessageManager::instance != 0)
  30218. MessageManager::instance->messageListeners.removeValue (this);
  30219. }
  30220. void MessageListener::postMessage (Message* const message) const throw()
  30221. {
  30222. message->messageRecipient = const_cast <MessageListener*> (this);
  30223. if (MessageManager::instance == 0)
  30224. MessageManager::getInstance();
  30225. MessageManager::instance->postMessageToQueue (message);
  30226. }
  30227. bool MessageListener::isValidMessageListener() const throw()
  30228. {
  30229. return (MessageManager::instance != 0)
  30230. && MessageManager::instance->messageListeners.contains (this);
  30231. }
  30232. END_JUCE_NAMESPACE
  30233. /*** End of inlined file: juce_MessageListener.cpp ***/
  30234. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30235. BEGIN_JUCE_NAMESPACE
  30236. // platform-specific functions..
  30237. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30238. bool juce_postMessageToSystemQueue (void* message);
  30239. MessageManager* MessageManager::instance = 0;
  30240. static const int quitMessageId = 0xfffff321;
  30241. MessageManager::MessageManager() throw()
  30242. : quitMessagePosted (false),
  30243. quitMessageReceived (false),
  30244. threadWithLock (0)
  30245. {
  30246. messageThreadId = Thread::getCurrentThreadId();
  30247. }
  30248. MessageManager::~MessageManager() throw()
  30249. {
  30250. broadcastListeners = 0;
  30251. doPlatformSpecificShutdown();
  30252. jassert (instance == this);
  30253. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30254. }
  30255. MessageManager* MessageManager::getInstance() throw()
  30256. {
  30257. if (instance == 0)
  30258. {
  30259. instance = new MessageManager();
  30260. doPlatformSpecificInitialisation();
  30261. }
  30262. return instance;
  30263. }
  30264. void MessageManager::postMessageToQueue (Message* const message)
  30265. {
  30266. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30267. delete message;
  30268. }
  30269. CallbackMessage::CallbackMessage() throw() {}
  30270. CallbackMessage::~CallbackMessage() throw() {}
  30271. void CallbackMessage::post()
  30272. {
  30273. if (MessageManager::instance != 0)
  30274. MessageManager::instance->postCallbackMessage (this);
  30275. }
  30276. void MessageManager::postCallbackMessage (Message* const message)
  30277. {
  30278. message->messageRecipient = 0;
  30279. postMessageToQueue (message);
  30280. }
  30281. // not for public use..
  30282. void MessageManager::deliverMessage (void* const message)
  30283. {
  30284. const ScopedPointer <Message> m (static_cast <Message*> (message));
  30285. MessageListener* const recipient = m->messageRecipient;
  30286. JUCE_TRY
  30287. {
  30288. if (messageListeners.contains (recipient))
  30289. {
  30290. recipient->handleMessage (*m);
  30291. }
  30292. else if (recipient == 0)
  30293. {
  30294. if (m->intParameter1 == quitMessageId)
  30295. {
  30296. quitMessageReceived = true;
  30297. }
  30298. else
  30299. {
  30300. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> (static_cast <Message*> (m));
  30301. if (cm != 0)
  30302. cm->messageCallback();
  30303. }
  30304. }
  30305. }
  30306. JUCE_CATCH_EXCEPTION
  30307. }
  30308. #if ! (JUCE_MAC || JUCE_IPHONE)
  30309. void MessageManager::runDispatchLoop()
  30310. {
  30311. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30312. runDispatchLoopUntil (-1);
  30313. }
  30314. void MessageManager::stopDispatchLoop()
  30315. {
  30316. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30317. m->messageRecipient = 0;
  30318. postMessageToQueue (m);
  30319. quitMessagePosted = true;
  30320. }
  30321. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30322. {
  30323. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30324. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30325. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30326. && ! quitMessageReceived)
  30327. {
  30328. JUCE_TRY
  30329. {
  30330. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30331. {
  30332. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30333. if (msToWait > 0)
  30334. Thread::sleep (jmin (5, msToWait));
  30335. }
  30336. }
  30337. JUCE_CATCH_EXCEPTION
  30338. }
  30339. return ! quitMessageReceived;
  30340. }
  30341. #endif
  30342. void MessageManager::deliverBroadcastMessage (const String& value)
  30343. {
  30344. if (broadcastListeners != 0)
  30345. broadcastListeners->sendActionMessage (value);
  30346. }
  30347. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30348. {
  30349. if (broadcastListeners == 0)
  30350. broadcastListeners = new ActionListenerList();
  30351. broadcastListeners->addActionListener (listener);
  30352. }
  30353. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30354. {
  30355. if (broadcastListeners != 0)
  30356. broadcastListeners->removeActionListener (listener);
  30357. }
  30358. bool MessageManager::isThisTheMessageThread() const throw()
  30359. {
  30360. return Thread::getCurrentThreadId() == messageThreadId;
  30361. }
  30362. void MessageManager::setCurrentThreadAsMessageThread()
  30363. {
  30364. if (messageThreadId != Thread::getCurrentThreadId())
  30365. {
  30366. messageThreadId = Thread::getCurrentThreadId();
  30367. // This is needed on windows to make sure the message window is created by this thread
  30368. doPlatformSpecificShutdown();
  30369. doPlatformSpecificInitialisation();
  30370. }
  30371. }
  30372. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30373. {
  30374. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30375. return thisThread == messageThreadId || thisThread == threadWithLock;
  30376. }
  30377. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30378. {
  30379. public:
  30380. SharedEvents() {}
  30381. ~SharedEvents() {}
  30382. WaitableEvent lockedEvent, releaseEvent;
  30383. private:
  30384. SharedEvents (const SharedEvents&);
  30385. SharedEvents& operator= (const SharedEvents&);
  30386. };
  30387. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30388. {
  30389. public:
  30390. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30391. ~BlockingMessage() throw() {}
  30392. void messageCallback()
  30393. {
  30394. events->lockedEvent.signal();
  30395. events->releaseEvent.wait();
  30396. }
  30397. juce_UseDebuggingNewOperator
  30398. private:
  30399. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30400. BlockingMessage (const BlockingMessage&);
  30401. BlockingMessage& operator= (const BlockingMessage&);
  30402. };
  30403. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30404. : sharedEvents (0),
  30405. locked (false)
  30406. {
  30407. init (threadToCheck, 0);
  30408. }
  30409. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30410. : sharedEvents (0),
  30411. locked (false)
  30412. {
  30413. init (0, jobToCheckForExitSignal);
  30414. }
  30415. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30416. {
  30417. if (MessageManager::instance != 0)
  30418. {
  30419. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30420. {
  30421. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30422. }
  30423. else
  30424. {
  30425. if (threadToCheck == 0 && job == 0)
  30426. {
  30427. MessageManager::instance->lockingLock.enter();
  30428. }
  30429. else
  30430. {
  30431. while (! MessageManager::instance->lockingLock.tryEnter())
  30432. {
  30433. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30434. || (job != 0 && job->shouldExit()))
  30435. return;
  30436. Thread::sleep (1);
  30437. }
  30438. }
  30439. sharedEvents = new SharedEvents();
  30440. sharedEvents->incReferenceCount();
  30441. (new BlockingMessage (sharedEvents))->post();
  30442. while (! sharedEvents->lockedEvent.wait (50))
  30443. {
  30444. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30445. || (job != 0 && job->shouldExit()))
  30446. {
  30447. sharedEvents->releaseEvent.signal();
  30448. sharedEvents->decReferenceCount();
  30449. sharedEvents = 0;
  30450. MessageManager::instance->lockingLock.exit();
  30451. return;
  30452. }
  30453. }
  30454. jassert (MessageManager::instance->threadWithLock == 0);
  30455. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30456. locked = true;
  30457. }
  30458. }
  30459. }
  30460. MessageManagerLock::~MessageManagerLock() throw()
  30461. {
  30462. if (sharedEvents != 0)
  30463. {
  30464. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30465. sharedEvents->releaseEvent.signal();
  30466. sharedEvents->decReferenceCount();
  30467. if (MessageManager::instance != 0)
  30468. {
  30469. MessageManager::instance->threadWithLock = 0;
  30470. MessageManager::instance->lockingLock.exit();
  30471. }
  30472. }
  30473. }
  30474. END_JUCE_NAMESPACE
  30475. /*** End of inlined file: juce_MessageManager.cpp ***/
  30476. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30477. BEGIN_JUCE_NAMESPACE
  30478. class MultiTimer::MultiTimerCallback : public Timer
  30479. {
  30480. public:
  30481. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30482. : timerId (timerId_),
  30483. owner (owner_)
  30484. {
  30485. }
  30486. ~MultiTimerCallback()
  30487. {
  30488. }
  30489. void timerCallback()
  30490. {
  30491. owner.timerCallback (timerId);
  30492. }
  30493. const int timerId;
  30494. private:
  30495. MultiTimer& owner;
  30496. };
  30497. MultiTimer::MultiTimer() throw()
  30498. {
  30499. }
  30500. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30501. {
  30502. }
  30503. MultiTimer::~MultiTimer()
  30504. {
  30505. const ScopedLock sl (timerListLock);
  30506. timers.clear();
  30507. }
  30508. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30509. {
  30510. const ScopedLock sl (timerListLock);
  30511. for (int i = timers.size(); --i >= 0;)
  30512. {
  30513. MultiTimerCallback* const t = timers.getUnchecked(i);
  30514. if (t->timerId == timerId)
  30515. {
  30516. t->startTimer (intervalInMilliseconds);
  30517. return;
  30518. }
  30519. }
  30520. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30521. timers.add (newTimer);
  30522. newTimer->startTimer (intervalInMilliseconds);
  30523. }
  30524. void MultiTimer::stopTimer (const int timerId) throw()
  30525. {
  30526. const ScopedLock sl (timerListLock);
  30527. for (int i = timers.size(); --i >= 0;)
  30528. {
  30529. MultiTimerCallback* const t = timers.getUnchecked(i);
  30530. if (t->timerId == timerId)
  30531. t->stopTimer();
  30532. }
  30533. }
  30534. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30535. {
  30536. const ScopedLock sl (timerListLock);
  30537. for (int i = timers.size(); --i >= 0;)
  30538. {
  30539. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30540. if (t->timerId == timerId)
  30541. return t->isTimerRunning();
  30542. }
  30543. return false;
  30544. }
  30545. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30546. {
  30547. const ScopedLock sl (timerListLock);
  30548. for (int i = timers.size(); --i >= 0;)
  30549. {
  30550. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30551. if (t->timerId == timerId)
  30552. return t->getTimerInterval();
  30553. }
  30554. return 0;
  30555. }
  30556. END_JUCE_NAMESPACE
  30557. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30558. /*** Start of inlined file: juce_Timer.cpp ***/
  30559. BEGIN_JUCE_NAMESPACE
  30560. class InternalTimerThread : private Thread,
  30561. private MessageListener,
  30562. private DeletedAtShutdown,
  30563. private AsyncUpdater
  30564. {
  30565. public:
  30566. InternalTimerThread()
  30567. : Thread ("Juce Timer"),
  30568. firstTimer (0),
  30569. callbackNeeded (false)
  30570. {
  30571. triggerAsyncUpdate();
  30572. }
  30573. ~InternalTimerThread() throw()
  30574. {
  30575. stopThread (4000);
  30576. jassert (instance == this || instance == 0);
  30577. if (instance == this)
  30578. instance = 0;
  30579. }
  30580. void run()
  30581. {
  30582. uint32 lastTime = Time::getMillisecondCounter();
  30583. while (! threadShouldExit())
  30584. {
  30585. const uint32 now = Time::getMillisecondCounter();
  30586. if (now <= lastTime)
  30587. {
  30588. wait (2);
  30589. continue;
  30590. }
  30591. const int elapsed = now - lastTime;
  30592. lastTime = now;
  30593. int timeUntilFirstTimer = 1000;
  30594. {
  30595. const ScopedLock sl (lock);
  30596. decrementAllCounters (elapsed);
  30597. if (firstTimer != 0)
  30598. timeUntilFirstTimer = firstTimer->countdownMs;
  30599. }
  30600. if (timeUntilFirstTimer <= 0)
  30601. {
  30602. if (callbackNeeded.set (true))
  30603. {
  30604. postMessage (new Message());
  30605. const uint32 messageDeliveryTimeout = now + 2000;
  30606. while (callbackNeeded.get())
  30607. {
  30608. wait (4);
  30609. if (threadShouldExit())
  30610. return;
  30611. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30612. break;
  30613. }
  30614. }
  30615. }
  30616. else
  30617. {
  30618. // don't wait for too long because running this loop also helps keep the
  30619. // Time::getApproximateMillisecondTimer value stay up-to-date
  30620. wait (jlimit (1, 50, timeUntilFirstTimer));
  30621. }
  30622. }
  30623. }
  30624. void callTimers()
  30625. {
  30626. const ScopedLock sl (lock);
  30627. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30628. {
  30629. Timer* const t = firstTimer;
  30630. t->countdownMs = t->periodMs;
  30631. removeTimer (t);
  30632. addTimer (t);
  30633. const ScopedUnlock ul (lock);
  30634. JUCE_TRY
  30635. {
  30636. t->timerCallback();
  30637. }
  30638. JUCE_CATCH_EXCEPTION
  30639. }
  30640. callbackNeeded.set (false);
  30641. }
  30642. void handleMessage (const Message&)
  30643. {
  30644. callTimers();
  30645. }
  30646. void callTimersSynchronously()
  30647. {
  30648. if (! isThreadRunning())
  30649. {
  30650. // (This is relied on by some plugins in cases where the MM has
  30651. // had to restart and the async callback never started)
  30652. cancelPendingUpdate();
  30653. triggerAsyncUpdate();
  30654. }
  30655. callTimers();
  30656. }
  30657. static void callAnyTimersSynchronously()
  30658. {
  30659. if (InternalTimerThread::instance != 0)
  30660. InternalTimerThread::instance->callTimersSynchronously();
  30661. }
  30662. static inline void add (Timer* const tim) throw()
  30663. {
  30664. if (instance == 0)
  30665. instance = new InternalTimerThread();
  30666. const ScopedLock sl (instance->lock);
  30667. instance->addTimer (tim);
  30668. }
  30669. static inline void remove (Timer* const tim) throw()
  30670. {
  30671. if (instance != 0)
  30672. {
  30673. const ScopedLock sl (instance->lock);
  30674. instance->removeTimer (tim);
  30675. }
  30676. }
  30677. static inline void resetCounter (Timer* const tim,
  30678. const int newCounter) throw()
  30679. {
  30680. if (instance != 0)
  30681. {
  30682. tim->countdownMs = newCounter;
  30683. tim->periodMs = newCounter;
  30684. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30685. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30686. {
  30687. const ScopedLock sl (instance->lock);
  30688. instance->removeTimer (tim);
  30689. instance->addTimer (tim);
  30690. }
  30691. }
  30692. }
  30693. private:
  30694. friend class Timer;
  30695. static InternalTimerThread* instance;
  30696. static CriticalSection lock;
  30697. Timer* volatile firstTimer;
  30698. class AtomicBool
  30699. {
  30700. public:
  30701. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30702. ~AtomicBool() throw() {}
  30703. bool get() const throw() { return value != 0; }
  30704. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30705. private:
  30706. int32 value;
  30707. AtomicBool (const AtomicBool&);
  30708. AtomicBool& operator= (const AtomicBool&);
  30709. };
  30710. AtomicBool callbackNeeded;
  30711. void addTimer (Timer* const t) throw()
  30712. {
  30713. #ifdef JUCE_DEBUG
  30714. Timer* tt = firstTimer;
  30715. while (tt != 0)
  30716. {
  30717. // trying to add a timer that's already here - shouldn't get to this point,
  30718. // so if you get this assertion, let me know!
  30719. jassert (tt != t);
  30720. tt = tt->next;
  30721. }
  30722. jassert (t->previous == 0 && t->next == 0);
  30723. #endif
  30724. Timer* i = firstTimer;
  30725. if (i == 0 || i->countdownMs > t->countdownMs)
  30726. {
  30727. t->next = firstTimer;
  30728. firstTimer = t;
  30729. }
  30730. else
  30731. {
  30732. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30733. i = i->next;
  30734. jassert (i != 0);
  30735. t->next = i->next;
  30736. t->previous = i;
  30737. i->next = t;
  30738. }
  30739. if (t->next != 0)
  30740. t->next->previous = t;
  30741. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30742. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30743. notify();
  30744. }
  30745. void removeTimer (Timer* const t) throw()
  30746. {
  30747. #ifdef JUCE_DEBUG
  30748. Timer* tt = firstTimer;
  30749. bool found = false;
  30750. while (tt != 0)
  30751. {
  30752. if (tt == t)
  30753. {
  30754. found = true;
  30755. break;
  30756. }
  30757. tt = tt->next;
  30758. }
  30759. // trying to remove a timer that's not here - shouldn't get to this point,
  30760. // so if you get this assertion, let me know!
  30761. jassert (found);
  30762. #endif
  30763. if (t->previous != 0)
  30764. {
  30765. jassert (firstTimer != t);
  30766. t->previous->next = t->next;
  30767. }
  30768. else
  30769. {
  30770. jassert (firstTimer == t);
  30771. firstTimer = t->next;
  30772. }
  30773. if (t->next != 0)
  30774. t->next->previous = t->previous;
  30775. t->next = 0;
  30776. t->previous = 0;
  30777. }
  30778. void decrementAllCounters (const int numMillisecs) const
  30779. {
  30780. Timer* t = firstTimer;
  30781. while (t != 0)
  30782. {
  30783. t->countdownMs -= numMillisecs;
  30784. t = t->next;
  30785. }
  30786. }
  30787. void handleAsyncUpdate()
  30788. {
  30789. startThread (7);
  30790. }
  30791. InternalTimerThread (const InternalTimerThread&);
  30792. InternalTimerThread& operator= (const InternalTimerThread&);
  30793. };
  30794. InternalTimerThread* InternalTimerThread::instance = 0;
  30795. CriticalSection InternalTimerThread::lock;
  30796. void juce_callAnyTimersSynchronously()
  30797. {
  30798. InternalTimerThread::callAnyTimersSynchronously();
  30799. }
  30800. #ifdef JUCE_DEBUG
  30801. static SortedSet <Timer*> activeTimers;
  30802. #endif
  30803. Timer::Timer() throw()
  30804. : countdownMs (0),
  30805. periodMs (0),
  30806. previous (0),
  30807. next (0)
  30808. {
  30809. #ifdef JUCE_DEBUG
  30810. activeTimers.add (this);
  30811. #endif
  30812. }
  30813. Timer::Timer (const Timer&) throw()
  30814. : countdownMs (0),
  30815. periodMs (0),
  30816. previous (0),
  30817. next (0)
  30818. {
  30819. #ifdef JUCE_DEBUG
  30820. activeTimers.add (this);
  30821. #endif
  30822. }
  30823. Timer::~Timer()
  30824. {
  30825. stopTimer();
  30826. #ifdef JUCE_DEBUG
  30827. activeTimers.removeValue (this);
  30828. #endif
  30829. }
  30830. void Timer::startTimer (const int interval) throw()
  30831. {
  30832. const ScopedLock sl (InternalTimerThread::lock);
  30833. #ifdef JUCE_DEBUG
  30834. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30835. jassert (activeTimers.contains (this));
  30836. #endif
  30837. if (periodMs == 0)
  30838. {
  30839. countdownMs = interval;
  30840. periodMs = jmax (1, interval);
  30841. InternalTimerThread::add (this);
  30842. }
  30843. else
  30844. {
  30845. InternalTimerThread::resetCounter (this, interval);
  30846. }
  30847. }
  30848. void Timer::stopTimer() throw()
  30849. {
  30850. const ScopedLock sl (InternalTimerThread::lock);
  30851. #ifdef JUCE_DEBUG
  30852. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30853. jassert (activeTimers.contains (this));
  30854. #endif
  30855. if (periodMs > 0)
  30856. {
  30857. InternalTimerThread::remove (this);
  30858. periodMs = 0;
  30859. }
  30860. }
  30861. END_JUCE_NAMESPACE
  30862. /*** End of inlined file: juce_Timer.cpp ***/
  30863. #endif
  30864. #if JUCE_BUILD_GUI
  30865. /*** Start of inlined file: juce_Component.cpp ***/
  30866. BEGIN_JUCE_NAMESPACE
  30867. Component* Component::currentlyFocusedComponent = 0;
  30868. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30869. static Array <int> modalReturnValues;
  30870. enum ComponentMessageNumbers
  30871. {
  30872. customCommandMessage = 0x7fff0001,
  30873. exitModalStateMessage = 0x7fff0002
  30874. };
  30875. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30876. static uint32 nextComponentUID = 0;
  30877. Component::Component()
  30878. : parentComponent_ (0),
  30879. componentUID (++nextComponentUID),
  30880. numDeepMouseListeners (0),
  30881. lookAndFeel_ (0),
  30882. effect_ (0),
  30883. bufferedImage_ (0),
  30884. mouseListeners_ (0),
  30885. keyListeners_ (0),
  30886. componentFlags_ (0)
  30887. {
  30888. }
  30889. Component::Component (const String& name)
  30890. : componentName_ (name),
  30891. parentComponent_ (0),
  30892. componentUID (++nextComponentUID),
  30893. numDeepMouseListeners (0),
  30894. lookAndFeel_ (0),
  30895. effect_ (0),
  30896. bufferedImage_ (0),
  30897. mouseListeners_ (0),
  30898. keyListeners_ (0),
  30899. componentFlags_ (0)
  30900. {
  30901. }
  30902. Component::~Component()
  30903. {
  30904. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30905. if (parentComponent_ != 0)
  30906. {
  30907. parentComponent_->removeChildComponent (this);
  30908. }
  30909. else if ((currentlyFocusedComponent == this)
  30910. || isParentOf (currentlyFocusedComponent))
  30911. {
  30912. giveAwayFocus();
  30913. }
  30914. if (flags.hasHeavyweightPeerFlag)
  30915. removeFromDesktop();
  30916. modalComponentStack.removeValue (this);
  30917. for (int i = childComponentList_.size(); --i >= 0;)
  30918. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30919. delete bufferedImage_;
  30920. delete mouseListeners_;
  30921. delete keyListeners_;
  30922. }
  30923. void Component::setName (const String& name)
  30924. {
  30925. // if component methods are being called from threads other than the message
  30926. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30927. checkMessageManagerIsLocked
  30928. if (componentName_ != name)
  30929. {
  30930. componentName_ = name;
  30931. if (flags.hasHeavyweightPeerFlag)
  30932. {
  30933. ComponentPeer* const peer = getPeer();
  30934. jassert (peer != 0);
  30935. if (peer != 0)
  30936. peer->setTitle (name);
  30937. }
  30938. BailOutChecker checker (this);
  30939. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30940. }
  30941. }
  30942. void Component::setVisible (bool shouldBeVisible)
  30943. {
  30944. if (flags.visibleFlag != shouldBeVisible)
  30945. {
  30946. // if component methods are being called from threads other than the message
  30947. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30948. checkMessageManagerIsLocked
  30949. SafePointer<Component> safePointer (this);
  30950. flags.visibleFlag = shouldBeVisible;
  30951. internalRepaint (0, 0, getWidth(), getHeight());
  30952. sendFakeMouseMove();
  30953. if (! shouldBeVisible)
  30954. {
  30955. if (currentlyFocusedComponent == this
  30956. || isParentOf (currentlyFocusedComponent))
  30957. {
  30958. if (parentComponent_ != 0)
  30959. parentComponent_->grabKeyboardFocus();
  30960. else
  30961. giveAwayFocus();
  30962. }
  30963. }
  30964. if (safePointer != 0)
  30965. {
  30966. sendVisibilityChangeMessage();
  30967. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30968. {
  30969. ComponentPeer* const peer = getPeer();
  30970. jassert (peer != 0);
  30971. if (peer != 0)
  30972. {
  30973. peer->setVisible (shouldBeVisible);
  30974. internalHierarchyChanged();
  30975. }
  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 (comp->getLocalBounds());
  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. Array<Component*>& childList = parentComponent_->childComponentList_;
  31247. if (childList.getLast() != this)
  31248. {
  31249. const int index = childList.indexOf (this);
  31250. if (index >= 0)
  31251. {
  31252. int insertIndex = -1;
  31253. if (! flags.alwaysOnTopFlag)
  31254. {
  31255. insertIndex = childList.size() - 1;
  31256. while (insertIndex > 0 && childList.getUnchecked (insertIndex)->isAlwaysOnTop())
  31257. --insertIndex;
  31258. }
  31259. if (index != insertIndex)
  31260. {
  31261. childList.move (index, insertIndex);
  31262. sendFakeMouseMove();
  31263. repaintParent();
  31264. }
  31265. }
  31266. }
  31267. if (setAsForeground)
  31268. {
  31269. internalBroughtToFront();
  31270. grabKeyboardFocus();
  31271. }
  31272. }
  31273. }
  31274. void Component::toBehind (Component* const other)
  31275. {
  31276. if (other != 0 && other != this)
  31277. {
  31278. // the two components must belong to the same parent..
  31279. jassert (parentComponent_ == other->parentComponent_);
  31280. if (parentComponent_ != 0)
  31281. {
  31282. Array<Component*>& childList = parentComponent_->childComponentList_;
  31283. const int index = childList.indexOf (this);
  31284. if (index >= 0 && childList [index + 1] != other)
  31285. {
  31286. int otherIndex = childList.indexOf (other);
  31287. if (otherIndex >= 0)
  31288. {
  31289. if (index < otherIndex)
  31290. --otherIndex;
  31291. childList.move (index, otherIndex);
  31292. sendFakeMouseMove();
  31293. repaintParent();
  31294. }
  31295. }
  31296. }
  31297. else if (isOnDesktop())
  31298. {
  31299. jassert (other->isOnDesktop());
  31300. if (other->isOnDesktop())
  31301. {
  31302. ComponentPeer* const us = getPeer();
  31303. ComponentPeer* const them = other->getPeer();
  31304. jassert (us != 0 && them != 0);
  31305. if (us != 0 && them != 0)
  31306. us->toBehind (them);
  31307. }
  31308. }
  31309. }
  31310. }
  31311. void Component::toBack()
  31312. {
  31313. Array<Component*>& childList = parentComponent_->childComponentList_;
  31314. if (isOnDesktop())
  31315. {
  31316. jassertfalse //xxx need to add this to native window
  31317. }
  31318. else if (parentComponent_ != 0 && childList.getFirst() != this)
  31319. {
  31320. const int index = childList.indexOf (this);
  31321. if (index > 0)
  31322. {
  31323. int insertIndex = 0;
  31324. if (flags.alwaysOnTopFlag)
  31325. {
  31326. while (insertIndex < childList.size()
  31327. && ! childList.getUnchecked (insertIndex)->isAlwaysOnTop())
  31328. {
  31329. ++insertIndex;
  31330. }
  31331. }
  31332. if (index != insertIndex)
  31333. {
  31334. childList.move (index, insertIndex);
  31335. sendFakeMouseMove();
  31336. repaintParent();
  31337. }
  31338. }
  31339. }
  31340. }
  31341. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31342. {
  31343. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31344. {
  31345. flags.alwaysOnTopFlag = shouldStayOnTop;
  31346. if (isOnDesktop())
  31347. {
  31348. ComponentPeer* const peer = getPeer();
  31349. jassert (peer != 0);
  31350. if (peer != 0)
  31351. {
  31352. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31353. {
  31354. // some kinds of peer can't change their always-on-top status, so
  31355. // for these, we'll need to create a new window
  31356. const int oldFlags = peer->getStyleFlags();
  31357. removeFromDesktop();
  31358. addToDesktop (oldFlags);
  31359. }
  31360. }
  31361. }
  31362. if (shouldStayOnTop)
  31363. toFront (false);
  31364. internalHierarchyChanged();
  31365. }
  31366. }
  31367. bool Component::isAlwaysOnTop() const throw()
  31368. {
  31369. return flags.alwaysOnTopFlag;
  31370. }
  31371. int Component::proportionOfWidth (const float proportion) const throw()
  31372. {
  31373. return roundToInt (proportion * bounds_.getWidth());
  31374. }
  31375. int Component::proportionOfHeight (const float proportion) const throw()
  31376. {
  31377. return roundToInt (proportion * bounds_.getHeight());
  31378. }
  31379. int Component::getParentWidth() const throw()
  31380. {
  31381. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31382. : getParentMonitorArea().getWidth();
  31383. }
  31384. int Component::getParentHeight() const throw()
  31385. {
  31386. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31387. : getParentMonitorArea().getHeight();
  31388. }
  31389. int Component::getScreenX() const
  31390. {
  31391. return getScreenPosition().getX();
  31392. }
  31393. int Component::getScreenY() const
  31394. {
  31395. return getScreenPosition().getY();
  31396. }
  31397. const Point<int> Component::getScreenPosition() const
  31398. {
  31399. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31400. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31401. : getPosition());
  31402. }
  31403. const Rectangle<int> Component::getScreenBounds() const
  31404. {
  31405. return bounds_.withPosition (getScreenPosition());
  31406. }
  31407. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31408. {
  31409. const Component* c = this;
  31410. Point<int> p (relativePosition);
  31411. do
  31412. {
  31413. if (c->flags.hasHeavyweightPeerFlag)
  31414. return c->getPeer()->relativePositionToGlobal (p);
  31415. p += c->getPosition();
  31416. c = c->parentComponent_;
  31417. }
  31418. while (c != 0);
  31419. return p;
  31420. }
  31421. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31422. {
  31423. if (flags.hasHeavyweightPeerFlag)
  31424. {
  31425. return getPeer()->globalPositionToRelative (screenPosition);
  31426. }
  31427. else
  31428. {
  31429. if (parentComponent_ != 0)
  31430. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31431. return screenPosition - getPosition();
  31432. }
  31433. }
  31434. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31435. {
  31436. Point<int> p (positionRelativeToThis);
  31437. if (targetComponent != 0)
  31438. {
  31439. const Component* c = this;
  31440. do
  31441. {
  31442. if (c == targetComponent)
  31443. return p;
  31444. if (c->flags.hasHeavyweightPeerFlag)
  31445. {
  31446. p = c->getPeer()->relativePositionToGlobal (p);
  31447. break;
  31448. }
  31449. p += c->getPosition();
  31450. c = c->parentComponent_;
  31451. }
  31452. while (c != 0);
  31453. p = targetComponent->globalPositionToRelative (p);
  31454. }
  31455. return p;
  31456. }
  31457. void Component::setBounds (int x, int y, int w, int h)
  31458. {
  31459. // if component methods are being called from threads other than the message
  31460. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31461. checkMessageManagerIsLocked
  31462. if (w < 0) w = 0;
  31463. if (h < 0) h = 0;
  31464. const bool wasResized = (getWidth() != w || getHeight() != h);
  31465. const bool wasMoved = (getX() != x || getY() != y);
  31466. #ifdef JUCE_DEBUG
  31467. // It's a very bad idea to try to resize a window during its paint() method!
  31468. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31469. #endif
  31470. if (wasMoved || wasResized)
  31471. {
  31472. if (flags.visibleFlag)
  31473. {
  31474. // send a fake mouse move to trigger enter/exit messages if needed..
  31475. sendFakeMouseMove();
  31476. if (! flags.hasHeavyweightPeerFlag)
  31477. repaintParent();
  31478. }
  31479. bounds_.setBounds (x, y, w, h);
  31480. if (wasResized)
  31481. repaint();
  31482. else if (! flags.hasHeavyweightPeerFlag)
  31483. repaintParent();
  31484. if (flags.hasHeavyweightPeerFlag)
  31485. {
  31486. ComponentPeer* const peer = getPeer();
  31487. if (peer != 0)
  31488. {
  31489. if (wasMoved && wasResized)
  31490. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31491. else if (wasMoved)
  31492. peer->setPosition (getX(), getY());
  31493. else if (wasResized)
  31494. peer->setSize (getWidth(), getHeight());
  31495. }
  31496. }
  31497. sendMovedResizedMessages (wasMoved, wasResized);
  31498. }
  31499. }
  31500. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31501. {
  31502. JUCE_TRY
  31503. {
  31504. if (wasMoved)
  31505. moved();
  31506. if (wasResized)
  31507. {
  31508. resized();
  31509. for (int i = childComponentList_.size(); --i >= 0;)
  31510. {
  31511. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31512. i = jmin (i, childComponentList_.size());
  31513. }
  31514. }
  31515. BailOutChecker checker (this);
  31516. if (parentComponent_ != 0)
  31517. parentComponent_->childBoundsChanged (this);
  31518. if (! checker.shouldBailOut())
  31519. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31520. *this, wasMoved, wasResized);
  31521. }
  31522. JUCE_CATCH_EXCEPTION
  31523. }
  31524. void Component::setSize (const int w, const int h)
  31525. {
  31526. setBounds (getX(), getY(), w, h);
  31527. }
  31528. void Component::setTopLeftPosition (const int x, const int y)
  31529. {
  31530. setBounds (x, y, getWidth(), getHeight());
  31531. }
  31532. void Component::setTopRightPosition (const int x, const int y)
  31533. {
  31534. setTopLeftPosition (x - getWidth(), y);
  31535. }
  31536. void Component::setBounds (const Rectangle<int>& r)
  31537. {
  31538. setBounds (r.getX(),
  31539. r.getY(),
  31540. r.getWidth(),
  31541. r.getHeight());
  31542. }
  31543. void Component::setBoundsRelative (const float x, const float y,
  31544. const float w, const float h)
  31545. {
  31546. const int pw = getParentWidth();
  31547. const int ph = getParentHeight();
  31548. setBounds (roundToInt (x * pw),
  31549. roundToInt (y * ph),
  31550. roundToInt (w * pw),
  31551. roundToInt (h * ph));
  31552. }
  31553. void Component::setCentrePosition (const int x, const int y)
  31554. {
  31555. setTopLeftPosition (x - getWidth() / 2,
  31556. y - getHeight() / 2);
  31557. }
  31558. void Component::setCentreRelative (const float x, const float y)
  31559. {
  31560. setCentrePosition (roundToInt (getParentWidth() * x),
  31561. roundToInt (getParentHeight() * y));
  31562. }
  31563. void Component::centreWithSize (const int width, const int height)
  31564. {
  31565. setBounds ((getParentWidth() - width) / 2,
  31566. (getParentHeight() - height) / 2,
  31567. width,
  31568. height);
  31569. }
  31570. void Component::setBoundsInset (const BorderSize& borders)
  31571. {
  31572. setBounds (borders.getLeft(),
  31573. borders.getTop(),
  31574. getParentWidth() - (borders.getLeftAndRight()),
  31575. getParentHeight() - (borders.getTopAndBottom()));
  31576. }
  31577. void Component::setBoundsToFit (int x, int y, int width, int height,
  31578. const Justification& justification,
  31579. const bool onlyReduceInSize)
  31580. {
  31581. // it's no good calling this method unless both the component and
  31582. // target rectangle have a finite size.
  31583. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31584. if (getWidth() > 0 && getHeight() > 0
  31585. && width > 0 && height > 0)
  31586. {
  31587. int newW, newH;
  31588. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31589. {
  31590. newW = getWidth();
  31591. newH = getHeight();
  31592. }
  31593. else
  31594. {
  31595. const double imageRatio = getHeight() / (double) getWidth();
  31596. const double targetRatio = height / (double) width;
  31597. if (imageRatio <= targetRatio)
  31598. {
  31599. newW = width;
  31600. newH = jmin (height, roundToInt (newW * imageRatio));
  31601. }
  31602. else
  31603. {
  31604. newH = height;
  31605. newW = jmin (width, roundToInt (newH / imageRatio));
  31606. }
  31607. }
  31608. if (newW > 0 && newH > 0)
  31609. {
  31610. int newX, newY;
  31611. justification.applyToRectangle (newX, newY, newW, newH,
  31612. x, y, width, height);
  31613. setBounds (newX, newY, newW, newH);
  31614. }
  31615. }
  31616. }
  31617. bool Component::hitTest (int x, int y)
  31618. {
  31619. if (! flags.ignoresMouseClicksFlag)
  31620. return true;
  31621. if (flags.allowChildMouseClicksFlag)
  31622. {
  31623. for (int i = getNumChildComponents(); --i >= 0;)
  31624. {
  31625. Component* const c = getChildComponent (i);
  31626. if (c->isVisible()
  31627. && c->bounds_.contains (x, y)
  31628. && c->hitTest (x - c->getX(),
  31629. y - c->getY()))
  31630. {
  31631. return true;
  31632. }
  31633. }
  31634. }
  31635. return false;
  31636. }
  31637. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31638. const bool allowClicksOnChildComponents) throw()
  31639. {
  31640. flags.ignoresMouseClicksFlag = ! allowClicks;
  31641. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31642. }
  31643. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31644. bool& allowsClicksOnChildComponents) const throw()
  31645. {
  31646. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31647. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31648. }
  31649. bool Component::contains (const int x, const int y)
  31650. {
  31651. if (((unsigned int) x) < (unsigned int) getWidth()
  31652. && ((unsigned int) y) < (unsigned int) getHeight()
  31653. && hitTest (x, y))
  31654. {
  31655. if (parentComponent_ != 0)
  31656. {
  31657. return parentComponent_->contains (x + getX(),
  31658. y + getY());
  31659. }
  31660. else if (flags.hasHeavyweightPeerFlag)
  31661. {
  31662. const ComponentPeer* const peer = getPeer();
  31663. if (peer != 0)
  31664. return peer->contains (Point<int> (x, y), true);
  31665. }
  31666. }
  31667. return false;
  31668. }
  31669. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31670. {
  31671. if (! contains (x, y))
  31672. return false;
  31673. Component* p = this;
  31674. while (p->parentComponent_ != 0)
  31675. {
  31676. x += p->getX();
  31677. y += p->getY();
  31678. p = p->parentComponent_;
  31679. }
  31680. const Component* const c = p->getComponentAt (x, y);
  31681. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31682. }
  31683. Component* Component::getComponentAt (const Point<int>& position)
  31684. {
  31685. return getComponentAt (position.getX(), position.getY());
  31686. }
  31687. Component* Component::getComponentAt (const int x, const int y)
  31688. {
  31689. if (flags.visibleFlag
  31690. && ((unsigned int) x) < (unsigned int) getWidth()
  31691. && ((unsigned int) y) < (unsigned int) getHeight()
  31692. && hitTest (x, y))
  31693. {
  31694. for (int i = childComponentList_.size(); --i >= 0;)
  31695. {
  31696. Component* const child = childComponentList_.getUnchecked(i);
  31697. Component* const c = child->getComponentAt (x - child->getX(),
  31698. y - child->getY());
  31699. if (c != 0)
  31700. return c;
  31701. }
  31702. return this;
  31703. }
  31704. return 0;
  31705. }
  31706. void Component::addChildComponent (Component* const child, int zOrder)
  31707. {
  31708. // if component methods are being called from threads other than the message
  31709. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31710. checkMessageManagerIsLocked
  31711. if (child != 0 && child->parentComponent_ != this)
  31712. {
  31713. if (child->parentComponent_ != 0)
  31714. child->parentComponent_->removeChildComponent (child);
  31715. else
  31716. child->removeFromDesktop();
  31717. child->parentComponent_ = this;
  31718. if (child->isVisible())
  31719. child->repaintParent();
  31720. if (! child->isAlwaysOnTop())
  31721. {
  31722. if (zOrder < 0 || zOrder > childComponentList_.size())
  31723. zOrder = childComponentList_.size();
  31724. while (zOrder > 0)
  31725. {
  31726. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31727. break;
  31728. --zOrder;
  31729. }
  31730. }
  31731. childComponentList_.insert (zOrder, child);
  31732. child->internalHierarchyChanged();
  31733. internalChildrenChanged();
  31734. }
  31735. }
  31736. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31737. {
  31738. if (child != 0)
  31739. {
  31740. child->setVisible (true);
  31741. addChildComponent (child, zOrder);
  31742. }
  31743. }
  31744. void Component::removeChildComponent (Component* const child)
  31745. {
  31746. removeChildComponent (childComponentList_.indexOf (child));
  31747. }
  31748. Component* Component::removeChildComponent (const int index)
  31749. {
  31750. // if component methods are being called from threads other than the message
  31751. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31752. checkMessageManagerIsLocked
  31753. Component* const child = childComponentList_ [index];
  31754. if (child != 0)
  31755. {
  31756. sendFakeMouseMove();
  31757. child->repaintParent();
  31758. childComponentList_.remove (index);
  31759. child->parentComponent_ = 0;
  31760. JUCE_TRY
  31761. {
  31762. if ((currentlyFocusedComponent == child)
  31763. || child->isParentOf (currentlyFocusedComponent))
  31764. {
  31765. // get rid first to force the grabKeyboardFocus to change to us.
  31766. giveAwayFocus();
  31767. grabKeyboardFocus();
  31768. }
  31769. }
  31770. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31771. catch (const std::exception& e)
  31772. {
  31773. currentlyFocusedComponent = 0;
  31774. Desktop::getInstance().triggerFocusCallback();
  31775. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31776. }
  31777. catch (...)
  31778. {
  31779. currentlyFocusedComponent = 0;
  31780. Desktop::getInstance().triggerFocusCallback();
  31781. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31782. }
  31783. #endif
  31784. child->internalHierarchyChanged();
  31785. internalChildrenChanged();
  31786. }
  31787. return child;
  31788. }
  31789. void Component::removeAllChildren()
  31790. {
  31791. while (childComponentList_.size() > 0)
  31792. removeChildComponent (childComponentList_.size() - 1);
  31793. }
  31794. void Component::deleteAllChildren()
  31795. {
  31796. while (childComponentList_.size() > 0)
  31797. delete (removeChildComponent (childComponentList_.size() - 1));
  31798. }
  31799. int Component::getNumChildComponents() const throw()
  31800. {
  31801. return childComponentList_.size();
  31802. }
  31803. Component* Component::getChildComponent (const int index) const throw()
  31804. {
  31805. return childComponentList_ [index];
  31806. }
  31807. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31808. {
  31809. return childComponentList_.indexOf (const_cast <Component*> (child));
  31810. }
  31811. Component* Component::getTopLevelComponent() const throw()
  31812. {
  31813. const Component* comp = this;
  31814. while (comp->parentComponent_ != 0)
  31815. comp = comp->parentComponent_;
  31816. return const_cast <Component*> (comp);
  31817. }
  31818. bool Component::isParentOf (const Component* possibleChild) const throw()
  31819. {
  31820. if (! possibleChild->isValidComponent())
  31821. {
  31822. jassert (possibleChild == 0);
  31823. return false;
  31824. }
  31825. while (possibleChild != 0)
  31826. {
  31827. possibleChild = possibleChild->parentComponent_;
  31828. if (possibleChild == this)
  31829. return true;
  31830. }
  31831. return false;
  31832. }
  31833. void Component::parentHierarchyChanged()
  31834. {
  31835. }
  31836. void Component::childrenChanged()
  31837. {
  31838. }
  31839. void Component::internalChildrenChanged()
  31840. {
  31841. if (componentListeners.isEmpty())
  31842. {
  31843. childrenChanged();
  31844. }
  31845. else
  31846. {
  31847. BailOutChecker checker (this);
  31848. childrenChanged();
  31849. if (! checker.shouldBailOut())
  31850. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31851. }
  31852. }
  31853. void Component::internalHierarchyChanged()
  31854. {
  31855. BailOutChecker checker (this);
  31856. parentHierarchyChanged();
  31857. if (checker.shouldBailOut())
  31858. return;
  31859. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31860. if (checker.shouldBailOut())
  31861. return;
  31862. for (int i = childComponentList_.size(); --i >= 0;)
  31863. {
  31864. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31865. if (checker.shouldBailOut())
  31866. {
  31867. // you really shouldn't delete the parent component during a callback telling you
  31868. // that it's changed..
  31869. jassertfalse;
  31870. return;
  31871. }
  31872. i = jmin (i, childComponentList_.size());
  31873. }
  31874. }
  31875. void* Component::runModalLoopCallback (void* userData)
  31876. {
  31877. return (void*) (pointer_sized_int) static_cast <Component*> (userData)->runModalLoop();
  31878. }
  31879. int Component::runModalLoop()
  31880. {
  31881. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31882. {
  31883. // use a callback so this can be called from non-gui threads
  31884. return (int) (pointer_sized_int)
  31885. MessageManager::getInstance()
  31886. ->callFunctionOnMessageThread (&runModalLoopCallback, this);
  31887. }
  31888. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31889. if (! isCurrentlyModal())
  31890. enterModalState();
  31891. JUCE_TRY
  31892. {
  31893. while (flags.currentlyModalFlag && flags.visibleFlag)
  31894. {
  31895. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31896. break;
  31897. // check whether this component was deleted during the last message
  31898. if (! isValidMessageListener())
  31899. break;
  31900. }
  31901. }
  31902. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31903. catch (const std::exception& e)
  31904. {
  31905. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31906. return 0;
  31907. }
  31908. catch (...)
  31909. {
  31910. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31911. return 0;
  31912. }
  31913. #endif
  31914. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31915. int returnValue = 0;
  31916. if (modalIndex >= 0)
  31917. {
  31918. modalComponentReturnValueKeys.remove (modalIndex);
  31919. returnValue = modalReturnValues.remove (modalIndex);
  31920. }
  31921. modalComponentStack.removeValue (this);
  31922. if (prevFocused != 0)
  31923. prevFocused->grabKeyboardFocus();
  31924. return returnValue;
  31925. }
  31926. void Component::enterModalState (const bool takeKeyboardFocus_)
  31927. {
  31928. // if component methods are being called from threads other than the message
  31929. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31930. checkMessageManagerIsLocked
  31931. // Check for an attempt to make a component modal when it already is!
  31932. // This can cause nasty problems..
  31933. jassert (! flags.currentlyModalFlag);
  31934. if (! isCurrentlyModal())
  31935. {
  31936. modalComponentStack.add (this);
  31937. modalComponentReturnValueKeys.add (this);
  31938. modalReturnValues.add (0);
  31939. flags.currentlyModalFlag = true;
  31940. setVisible (true);
  31941. if (takeKeyboardFocus_)
  31942. grabKeyboardFocus();
  31943. }
  31944. }
  31945. void Component::exitModalState (const int returnValue)
  31946. {
  31947. if (isCurrentlyModal())
  31948. {
  31949. if (MessageManager::getInstance()->isThisTheMessageThread())
  31950. {
  31951. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31952. if (modalIndex >= 0)
  31953. {
  31954. modalReturnValues.set (modalIndex, returnValue);
  31955. }
  31956. else
  31957. {
  31958. modalComponentReturnValueKeys.add (this);
  31959. modalReturnValues.add (returnValue);
  31960. }
  31961. modalComponentStack.removeValue (this);
  31962. flags.currentlyModalFlag = false;
  31963. bringModalComponentToFront();
  31964. }
  31965. else
  31966. {
  31967. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31968. }
  31969. }
  31970. }
  31971. bool Component::isCurrentlyModal() const throw()
  31972. {
  31973. return flags.currentlyModalFlag
  31974. && getCurrentlyModalComponent() == this;
  31975. }
  31976. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31977. {
  31978. Component* const mc = getCurrentlyModalComponent();
  31979. return mc != 0
  31980. && mc != this
  31981. && (! mc->isParentOf (this))
  31982. && ! mc->canModalEventBeSentToComponent (this);
  31983. }
  31984. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31985. {
  31986. return modalComponentStack.size();
  31987. }
  31988. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31989. {
  31990. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31991. return c->isValidComponent() ? c : 0;
  31992. }
  31993. void Component::bringModalComponentToFront()
  31994. {
  31995. ComponentPeer* lastOne = 0;
  31996. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31997. {
  31998. Component* const c = getCurrentlyModalComponent (i);
  31999. if (c == 0)
  32000. break;
  32001. ComponentPeer* peer = c->getPeer();
  32002. if (peer != 0 && peer != lastOne)
  32003. {
  32004. if (lastOne == 0)
  32005. {
  32006. peer->toFront (true);
  32007. peer->grabFocus();
  32008. }
  32009. else
  32010. peer->toBehind (lastOne);
  32011. lastOne = peer;
  32012. }
  32013. }
  32014. }
  32015. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32016. {
  32017. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32018. }
  32019. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32020. {
  32021. return flags.bringToFrontOnClickFlag;
  32022. }
  32023. void Component::setMouseCursor (const MouseCursor& cursor)
  32024. {
  32025. if (cursor_ != cursor)
  32026. {
  32027. cursor_ = cursor;
  32028. if (flags.visibleFlag)
  32029. updateMouseCursor();
  32030. }
  32031. }
  32032. const MouseCursor Component::getMouseCursor()
  32033. {
  32034. return cursor_;
  32035. }
  32036. void Component::updateMouseCursor() const
  32037. {
  32038. sendFakeMouseMove();
  32039. }
  32040. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32041. {
  32042. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32043. }
  32044. void Component::repaintParent()
  32045. {
  32046. if (flags.visibleFlag)
  32047. internalRepaint (0, 0, getWidth(), getHeight());
  32048. }
  32049. void Component::repaint()
  32050. {
  32051. repaint (0, 0, getWidth(), getHeight());
  32052. }
  32053. void Component::repaint (const int x, const int y,
  32054. const int w, const int h)
  32055. {
  32056. deleteAndZero (bufferedImage_);
  32057. if (flags.visibleFlag)
  32058. internalRepaint (x, y, w, h);
  32059. }
  32060. void Component::internalRepaint (int x, int y, int w, int h)
  32061. {
  32062. // if component methods are being called from threads other than the message
  32063. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32064. checkMessageManagerIsLocked
  32065. if (x < 0)
  32066. {
  32067. w += x;
  32068. x = 0;
  32069. }
  32070. if (x + w > getWidth())
  32071. w = getWidth() - x;
  32072. if (w > 0)
  32073. {
  32074. if (y < 0)
  32075. {
  32076. h += y;
  32077. y = 0;
  32078. }
  32079. if (y + h > getHeight())
  32080. h = getHeight() - y;
  32081. if (h > 0)
  32082. {
  32083. if (parentComponent_ != 0)
  32084. {
  32085. x += getX();
  32086. y += getY();
  32087. if (parentComponent_->flags.visibleFlag)
  32088. parentComponent_->internalRepaint (x, y, w, h);
  32089. }
  32090. else if (flags.hasHeavyweightPeerFlag)
  32091. {
  32092. ComponentPeer* const peer = getPeer();
  32093. if (peer != 0)
  32094. peer->repaint (x, y, w, h);
  32095. }
  32096. }
  32097. }
  32098. }
  32099. void Component::renderComponent (Graphics& g)
  32100. {
  32101. const Rectangle<int> clipBounds (g.getClipBounds());
  32102. g.saveState();
  32103. clipObscuredRegions (g, clipBounds, 0, 0);
  32104. if (! g.isClipEmpty())
  32105. {
  32106. if (flags.bufferToImageFlag)
  32107. {
  32108. if (bufferedImage_ == 0)
  32109. {
  32110. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32111. getWidth(), getHeight(), ! flags.opaqueFlag);
  32112. Graphics imG (*bufferedImage_);
  32113. paint (imG);
  32114. }
  32115. g.setColour (Colours::black);
  32116. g.drawImageAt (bufferedImage_, 0, 0);
  32117. }
  32118. else
  32119. {
  32120. paint (g);
  32121. }
  32122. }
  32123. g.restoreState();
  32124. for (int i = 0; i < childComponentList_.size(); ++i)
  32125. {
  32126. Component* const child = childComponentList_.getUnchecked (i);
  32127. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32128. {
  32129. g.saveState();
  32130. if (g.reduceClipRegion (child->getX(), child->getY(),
  32131. child->getWidth(), child->getHeight()))
  32132. {
  32133. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32134. {
  32135. const Component* const sibling = childComponentList_.getUnchecked (j);
  32136. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32137. g.excludeClipRegion (sibling->getBounds());
  32138. }
  32139. if (! g.isClipEmpty())
  32140. {
  32141. g.setOrigin (child->getX(), child->getY());
  32142. child->paintEntireComponent (g);
  32143. }
  32144. }
  32145. g.restoreState();
  32146. }
  32147. }
  32148. g.saveState();
  32149. paintOverChildren (g);
  32150. g.restoreState();
  32151. }
  32152. void Component::paintEntireComponent (Graphics& g)
  32153. {
  32154. jassert (! g.isClipEmpty());
  32155. #ifdef JUCE_DEBUG
  32156. flags.isInsidePaintCall = true;
  32157. #endif
  32158. if (effect_ != 0)
  32159. {
  32160. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32161. getWidth(), getHeight(),
  32162. ! flags.opaqueFlag));
  32163. {
  32164. Graphics g2 (*effectImage);
  32165. renderComponent (g2);
  32166. }
  32167. effect_->applyEffect (*effectImage, g);
  32168. }
  32169. else
  32170. {
  32171. renderComponent (g);
  32172. }
  32173. #ifdef JUCE_DEBUG
  32174. flags.isInsidePaintCall = false;
  32175. #endif
  32176. }
  32177. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32178. const bool clipImageToComponentBounds)
  32179. {
  32180. Rectangle<int> r (areaToGrab);
  32181. if (clipImageToComponentBounds)
  32182. r = r.getIntersection (getLocalBounds());
  32183. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32184. jmax (1, r.getWidth()),
  32185. jmax (1, r.getHeight()),
  32186. true));
  32187. Graphics imageContext (*componentImage);
  32188. imageContext.setOrigin (-r.getX(), -r.getY());
  32189. paintEntireComponent (imageContext);
  32190. return componentImage.release();
  32191. }
  32192. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32193. {
  32194. if (effect_ != effect)
  32195. {
  32196. effect_ = effect;
  32197. repaint();
  32198. }
  32199. }
  32200. LookAndFeel& Component::getLookAndFeel() const throw()
  32201. {
  32202. const Component* c = this;
  32203. do
  32204. {
  32205. if (c->lookAndFeel_ != 0)
  32206. return *(c->lookAndFeel_);
  32207. c = c->parentComponent_;
  32208. }
  32209. while (c != 0);
  32210. return LookAndFeel::getDefaultLookAndFeel();
  32211. }
  32212. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32213. {
  32214. if (lookAndFeel_ != newLookAndFeel)
  32215. {
  32216. lookAndFeel_ = newLookAndFeel;
  32217. sendLookAndFeelChange();
  32218. }
  32219. }
  32220. void Component::lookAndFeelChanged()
  32221. {
  32222. }
  32223. void Component::sendLookAndFeelChange()
  32224. {
  32225. repaint();
  32226. lookAndFeelChanged();
  32227. // (it's not a great idea to do anything that would delete this component
  32228. // during the lookAndFeelChanged() callback)
  32229. jassert (isValidComponent());
  32230. SafePointer<Component> safePointer (this);
  32231. for (int i = childComponentList_.size(); --i >= 0;)
  32232. {
  32233. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32234. if (safePointer == 0)
  32235. return;
  32236. i = jmin (i, childComponentList_.size());
  32237. }
  32238. }
  32239. static const var::identifier getColourPropertyId (const int colourId)
  32240. {
  32241. String s;
  32242. s.preallocateStorage (18);
  32243. s << "jcclr_" << String::toHexString (colourId);
  32244. return s;
  32245. }
  32246. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32247. {
  32248. var* v = properties.getItem (getColourPropertyId (colourId));
  32249. if (v != 0)
  32250. return Colour ((int) *v);
  32251. if (inheritFromParent && parentComponent_ != 0)
  32252. return parentComponent_->findColour (colourId, true);
  32253. return getLookAndFeel().findColour (colourId);
  32254. }
  32255. bool Component::isColourSpecified (const int colourId) const
  32256. {
  32257. return properties.contains (getColourPropertyId (colourId));
  32258. }
  32259. void Component::removeColour (const int colourId)
  32260. {
  32261. if (properties.remove (getColourPropertyId (colourId)))
  32262. colourChanged();
  32263. }
  32264. void Component::setColour (const int colourId, const Colour& colour)
  32265. {
  32266. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32267. colourChanged();
  32268. }
  32269. void Component::copyAllExplicitColoursTo (Component& target) const
  32270. {
  32271. bool changed = false;
  32272. for (int i = properties.size(); --i >= 0;)
  32273. {
  32274. const var::identifier name (properties.getName(i));
  32275. if (name.name.startsWith ("jcclr_"))
  32276. if (target.properties.set (name, properties [name]))
  32277. changed = true;
  32278. }
  32279. if (changed)
  32280. target.colourChanged();
  32281. }
  32282. void Component::colourChanged()
  32283. {
  32284. }
  32285. const Rectangle<int> Component::getLocalBounds() const throw()
  32286. {
  32287. return Rectangle<int> (0, 0, getWidth(), getHeight());
  32288. }
  32289. const Rectangle<int> Component::getUnclippedArea() const
  32290. {
  32291. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32292. Component* p = parentComponent_;
  32293. int px = getX();
  32294. int py = getY();
  32295. while (p != 0)
  32296. {
  32297. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32298. return Rectangle<int>();
  32299. px += p->getX();
  32300. py += p->getY();
  32301. p = p->parentComponent_;
  32302. }
  32303. return Rectangle<int> (x, y, w, h);
  32304. }
  32305. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32306. const int deltaX, const int deltaY) const
  32307. {
  32308. for (int i = childComponentList_.size(); --i >= 0;)
  32309. {
  32310. const Component* const c = childComponentList_.getUnchecked(i);
  32311. if (c->isVisible())
  32312. {
  32313. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32314. if (! newClip.isEmpty())
  32315. {
  32316. if (c->isOpaque())
  32317. {
  32318. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32319. }
  32320. else
  32321. {
  32322. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32323. c->getX() + deltaX,
  32324. c->getY() + deltaY);
  32325. }
  32326. }
  32327. }
  32328. }
  32329. }
  32330. void Component::getVisibleArea (RectangleList& result, const bool includeSiblings) const
  32331. {
  32332. result.clear();
  32333. const Rectangle<int> unclipped (getUnclippedArea());
  32334. if (! unclipped.isEmpty())
  32335. {
  32336. result.add (unclipped);
  32337. if (includeSiblings)
  32338. {
  32339. const Component* const c = getTopLevelComponent();
  32340. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32341. c->getLocalBounds(), this);
  32342. }
  32343. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32344. result.consolidate();
  32345. }
  32346. }
  32347. void Component::subtractObscuredRegions (RectangleList& result,
  32348. const Point<int>& delta,
  32349. const Rectangle<int>& clipRect,
  32350. const Component* const compToAvoid) const
  32351. {
  32352. for (int i = childComponentList_.size(); --i >= 0;)
  32353. {
  32354. const Component* const c = childComponentList_.getUnchecked(i);
  32355. if (c != compToAvoid && c->isVisible())
  32356. {
  32357. if (c->isOpaque())
  32358. {
  32359. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32360. childBounds.translate (delta.getX(), delta.getY());
  32361. result.subtract (childBounds);
  32362. }
  32363. else
  32364. {
  32365. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32366. newClip.translate (-c->getX(), -c->getY());
  32367. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32368. newClip, compToAvoid);
  32369. }
  32370. }
  32371. }
  32372. }
  32373. void Component::mouseEnter (const MouseEvent&)
  32374. {
  32375. // base class does nothing
  32376. }
  32377. void Component::mouseExit (const MouseEvent&)
  32378. {
  32379. // base class does nothing
  32380. }
  32381. void Component::mouseDown (const MouseEvent&)
  32382. {
  32383. // base class does nothing
  32384. }
  32385. void Component::mouseUp (const MouseEvent&)
  32386. {
  32387. // base class does nothing
  32388. }
  32389. void Component::mouseDrag (const MouseEvent&)
  32390. {
  32391. // base class does nothing
  32392. }
  32393. void Component::mouseMove (const MouseEvent&)
  32394. {
  32395. // base class does nothing
  32396. }
  32397. void Component::mouseDoubleClick (const MouseEvent&)
  32398. {
  32399. // base class does nothing
  32400. }
  32401. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32402. {
  32403. // the base class just passes this event up to its parent..
  32404. if (parentComponent_ != 0)
  32405. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32406. wheelIncrementX, wheelIncrementY);
  32407. }
  32408. void Component::resized()
  32409. {
  32410. // base class does nothing
  32411. }
  32412. void Component::moved()
  32413. {
  32414. // base class does nothing
  32415. }
  32416. void Component::childBoundsChanged (Component*)
  32417. {
  32418. // base class does nothing
  32419. }
  32420. void Component::parentSizeChanged()
  32421. {
  32422. // base class does nothing
  32423. }
  32424. void Component::addComponentListener (ComponentListener* const newListener)
  32425. {
  32426. jassert (isValidComponent());
  32427. componentListeners.add (newListener);
  32428. }
  32429. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32430. {
  32431. jassert (isValidComponent());
  32432. componentListeners.remove (listenerToRemove);
  32433. }
  32434. void Component::inputAttemptWhenModal()
  32435. {
  32436. bringModalComponentToFront();
  32437. getLookAndFeel().playAlertSound();
  32438. }
  32439. bool Component::canModalEventBeSentToComponent (const Component*)
  32440. {
  32441. return false;
  32442. }
  32443. void Component::internalModalInputAttempt()
  32444. {
  32445. Component* const current = getCurrentlyModalComponent();
  32446. if (current != 0)
  32447. current->inputAttemptWhenModal();
  32448. }
  32449. void Component::paint (Graphics&)
  32450. {
  32451. // all painting is done in the subclasses
  32452. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32453. }
  32454. void Component::paintOverChildren (Graphics&)
  32455. {
  32456. // all painting is done in the subclasses
  32457. }
  32458. void Component::handleMessage (const Message& message)
  32459. {
  32460. if (message.intParameter1 == exitModalStateMessage)
  32461. {
  32462. exitModalState (message.intParameter2);
  32463. }
  32464. else if (message.intParameter1 == customCommandMessage)
  32465. {
  32466. handleCommandMessage (message.intParameter2);
  32467. }
  32468. }
  32469. void Component::postCommandMessage (const int commandId)
  32470. {
  32471. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32472. }
  32473. void Component::handleCommandMessage (int)
  32474. {
  32475. // used by subclasses
  32476. }
  32477. void Component::addMouseListener (MouseListener* const newListener,
  32478. const bool wantsEventsForAllNestedChildComponents)
  32479. {
  32480. // if component methods are being called from threads other than the message
  32481. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32482. checkMessageManagerIsLocked
  32483. if (mouseListeners_ == 0)
  32484. mouseListeners_ = new Array<MouseListener*>();
  32485. if (! mouseListeners_->contains (newListener))
  32486. {
  32487. if (wantsEventsForAllNestedChildComponents)
  32488. {
  32489. mouseListeners_->insert (0, newListener);
  32490. ++numDeepMouseListeners;
  32491. }
  32492. else
  32493. {
  32494. mouseListeners_->add (newListener);
  32495. }
  32496. }
  32497. }
  32498. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32499. {
  32500. // if component methods are being called from threads other than the message
  32501. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32502. checkMessageManagerIsLocked
  32503. if (mouseListeners_ != 0)
  32504. {
  32505. const int index = mouseListeners_->indexOf (listenerToRemove);
  32506. if (index >= 0)
  32507. {
  32508. if (index < numDeepMouseListeners)
  32509. --numDeepMouseListeners;
  32510. mouseListeners_->remove (index);
  32511. }
  32512. }
  32513. }
  32514. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32515. {
  32516. if (isCurrentlyBlockedByAnotherModalComponent())
  32517. {
  32518. // if something else is modal, always just show a normal mouse cursor
  32519. source.showMouseCursor (MouseCursor::NormalCursor);
  32520. return;
  32521. }
  32522. if (! flags.mouseInsideFlag)
  32523. {
  32524. flags.mouseInsideFlag = true;
  32525. flags.mouseOverFlag = true;
  32526. flags.draggingFlag = false;
  32527. BailOutChecker checker (this);
  32528. if (flags.repaintOnMouseActivityFlag)
  32529. repaint();
  32530. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32531. this, time, relativePos,
  32532. time, 0, false);
  32533. mouseEnter (me);
  32534. if (checker.shouldBailOut())
  32535. return;
  32536. Desktop::getInstance().resetTimer();
  32537. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32538. if (checker.shouldBailOut())
  32539. return;
  32540. if (mouseListeners_ != 0)
  32541. {
  32542. for (int i = mouseListeners_->size(); --i >= 0;)
  32543. {
  32544. mouseListeners_->getUnchecked(i)->mouseEnter (me);
  32545. if (checker.shouldBailOut())
  32546. return;
  32547. i = jmin (i, mouseListeners_->size());
  32548. }
  32549. }
  32550. Component* p = parentComponent_;
  32551. while (p != 0)
  32552. {
  32553. if (p->numDeepMouseListeners > 0)
  32554. {
  32555. BailOutChecker checker (this, p);
  32556. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32557. {
  32558. p->mouseListeners_->getUnchecked(i)->mouseEnter (me);
  32559. if (checker.shouldBailOut())
  32560. return;
  32561. i = jmin (i, p->numDeepMouseListeners);
  32562. }
  32563. }
  32564. p = p->parentComponent_;
  32565. }
  32566. }
  32567. }
  32568. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32569. {
  32570. BailOutChecker checker (this);
  32571. if (flags.draggingFlag)
  32572. {
  32573. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32574. if (checker.shouldBailOut())
  32575. return;
  32576. }
  32577. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32578. {
  32579. flags.mouseInsideFlag = false;
  32580. flags.mouseOverFlag = false;
  32581. flags.draggingFlag = false;
  32582. if (flags.repaintOnMouseActivityFlag)
  32583. repaint();
  32584. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32585. this, time, relativePos,
  32586. time, 0, false);
  32587. mouseExit (me);
  32588. if (checker.shouldBailOut())
  32589. return;
  32590. Desktop::getInstance().resetTimer();
  32591. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32592. if (checker.shouldBailOut())
  32593. return;
  32594. if (mouseListeners_ != 0)
  32595. {
  32596. for (int i = mouseListeners_->size(); --i >= 0;)
  32597. {
  32598. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32599. if (checker.shouldBailOut())
  32600. return;
  32601. i = jmin (i, mouseListeners_->size());
  32602. }
  32603. }
  32604. Component* p = parentComponent_;
  32605. while (p != 0)
  32606. {
  32607. if (p->numDeepMouseListeners > 0)
  32608. {
  32609. BailOutChecker checker (this, p);
  32610. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32611. {
  32612. p->mouseListeners_->getUnchecked (i)->mouseExit (me);
  32613. if (checker.shouldBailOut())
  32614. return;
  32615. i = jmin (i, p->numDeepMouseListeners);
  32616. }
  32617. }
  32618. p = p->parentComponent_;
  32619. }
  32620. }
  32621. }
  32622. class InternalDragRepeater : public Timer
  32623. {
  32624. public:
  32625. InternalDragRepeater()
  32626. {}
  32627. ~InternalDragRepeater()
  32628. {
  32629. clearSingletonInstance();
  32630. }
  32631. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32632. void timerCallback()
  32633. {
  32634. Desktop& desktop = Desktop::getInstance();
  32635. int numMiceDown = 0;
  32636. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32637. {
  32638. MouseInputSource* const source = desktop.getMouseSource(i);
  32639. if (source->isDragging())
  32640. {
  32641. source->triggerFakeMove();
  32642. ++numMiceDown;
  32643. }
  32644. }
  32645. if (numMiceDown == 0)
  32646. deleteInstance();
  32647. }
  32648. juce_UseDebuggingNewOperator
  32649. private:
  32650. InternalDragRepeater (const InternalDragRepeater&);
  32651. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32652. };
  32653. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32654. void Component::beginDragAutoRepeat (const int interval)
  32655. {
  32656. if (interval > 0)
  32657. {
  32658. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32659. InternalDragRepeater::getInstance()->startTimer (interval);
  32660. }
  32661. else
  32662. {
  32663. InternalDragRepeater::deleteInstance();
  32664. }
  32665. }
  32666. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32667. {
  32668. Desktop& desktop = Desktop::getInstance();
  32669. BailOutChecker checker (this);
  32670. if (isCurrentlyBlockedByAnotherModalComponent())
  32671. {
  32672. internalModalInputAttempt();
  32673. if (checker.shouldBailOut())
  32674. return;
  32675. // If processing the input attempt has exited the modal loop, we'll allow the event
  32676. // to be delivered..
  32677. if (isCurrentlyBlockedByAnotherModalComponent())
  32678. {
  32679. // allow blocked mouse-events to go to global listeners..
  32680. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32681. this, time, relativePos, time,
  32682. source.getNumberOfMultipleClicks(), false);
  32683. desktop.resetTimer();
  32684. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32685. return;
  32686. }
  32687. }
  32688. {
  32689. Component* c = this;
  32690. while (c != 0)
  32691. {
  32692. if (c->isBroughtToFrontOnMouseClick())
  32693. {
  32694. c->toFront (true);
  32695. if (checker.shouldBailOut())
  32696. return;
  32697. }
  32698. c = c->parentComponent_;
  32699. }
  32700. }
  32701. if (! flags.dontFocusOnMouseClickFlag)
  32702. {
  32703. grabFocusInternal (focusChangedByMouseClick);
  32704. if (checker.shouldBailOut())
  32705. return;
  32706. }
  32707. flags.draggingFlag = true;
  32708. flags.mouseOverFlag = true;
  32709. if (flags.repaintOnMouseActivityFlag)
  32710. repaint();
  32711. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32712. this, time, relativePos, time,
  32713. source.getNumberOfMultipleClicks(), false);
  32714. mouseDown (me);
  32715. if (checker.shouldBailOut())
  32716. return;
  32717. desktop.resetTimer();
  32718. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32719. if (checker.shouldBailOut())
  32720. return;
  32721. if (mouseListeners_ != 0)
  32722. {
  32723. for (int i = mouseListeners_->size(); --i >= 0;)
  32724. {
  32725. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32726. if (checker.shouldBailOut())
  32727. return;
  32728. i = jmin (i, mouseListeners_->size());
  32729. }
  32730. }
  32731. Component* p = parentComponent_;
  32732. while (p != 0)
  32733. {
  32734. if (p->numDeepMouseListeners > 0)
  32735. {
  32736. BailOutChecker checker (this, p);
  32737. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32738. {
  32739. p->mouseListeners_->getUnchecked (i)->mouseDown (me);
  32740. if (checker.shouldBailOut())
  32741. return;
  32742. i = jmin (i, p->numDeepMouseListeners);
  32743. }
  32744. }
  32745. p = p->parentComponent_;
  32746. }
  32747. }
  32748. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32749. {
  32750. if (flags.draggingFlag)
  32751. {
  32752. Desktop& desktop = Desktop::getInstance();
  32753. flags.draggingFlag = false;
  32754. BailOutChecker checker (this);
  32755. if (flags.repaintOnMouseActivityFlag)
  32756. repaint();
  32757. const MouseEvent me (source, relativePos,
  32758. oldModifiers, this, time,
  32759. globalPositionToRelative (source.getLastMouseDownPosition()),
  32760. source.getLastMouseDownTime(),
  32761. source.getNumberOfMultipleClicks(),
  32762. source.hasMouseMovedSignificantlySincePressed());
  32763. mouseUp (me);
  32764. if (checker.shouldBailOut())
  32765. return;
  32766. desktop.resetTimer();
  32767. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32768. if (checker.shouldBailOut())
  32769. return;
  32770. if (mouseListeners_ != 0)
  32771. {
  32772. for (int i = mouseListeners_->size(); --i >= 0;)
  32773. {
  32774. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32775. if (checker.shouldBailOut())
  32776. return;
  32777. i = jmin (i, mouseListeners_->size());
  32778. }
  32779. }
  32780. {
  32781. Component* p = parentComponent_;
  32782. while (p != 0)
  32783. {
  32784. if (p->numDeepMouseListeners > 0)
  32785. {
  32786. BailOutChecker checker (this, p);
  32787. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32788. {
  32789. p->mouseListeners_->getUnchecked (i)->mouseUp (me);
  32790. if (checker.shouldBailOut())
  32791. return;
  32792. i = jmin (i, p->numDeepMouseListeners);
  32793. }
  32794. }
  32795. p = p->parentComponent_;
  32796. }
  32797. }
  32798. // check for double-click
  32799. if (me.getNumberOfClicks() >= 2)
  32800. {
  32801. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32802. mouseDoubleClick (me);
  32803. if (checker.shouldBailOut())
  32804. return;
  32805. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32806. if (checker.shouldBailOut())
  32807. return;
  32808. for (int i = numListeners; --i >= 0;)
  32809. {
  32810. if (checker.shouldBailOut())
  32811. return;
  32812. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32813. if (ml != 0)
  32814. ml->mouseDoubleClick (me);
  32815. }
  32816. if (checker.shouldBailOut())
  32817. return;
  32818. Component* p = parentComponent_;
  32819. while (p != 0)
  32820. {
  32821. if (p->numDeepMouseListeners > 0)
  32822. {
  32823. BailOutChecker checker (this, p);
  32824. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32825. {
  32826. p->mouseListeners_->getUnchecked (i)->mouseDoubleClick (me);
  32827. if (checker.shouldBailOut())
  32828. return;
  32829. i = jmin (i, p->numDeepMouseListeners);
  32830. }
  32831. }
  32832. p = p->parentComponent_;
  32833. }
  32834. }
  32835. }
  32836. }
  32837. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32838. {
  32839. if (flags.draggingFlag)
  32840. {
  32841. Desktop& desktop = Desktop::getInstance();
  32842. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32843. BailOutChecker checker (this);
  32844. const MouseEvent me (source, relativePos,
  32845. source.getCurrentModifiers(), this, time,
  32846. globalPositionToRelative (source.getLastMouseDownPosition()),
  32847. source.getLastMouseDownTime(),
  32848. source.getNumberOfMultipleClicks(),
  32849. source.hasMouseMovedSignificantlySincePressed());
  32850. mouseDrag (me);
  32851. if (checker.shouldBailOut())
  32852. return;
  32853. desktop.resetTimer();
  32854. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32855. if (checker.shouldBailOut())
  32856. return;
  32857. if (mouseListeners_ != 0)
  32858. {
  32859. for (int i = mouseListeners_->size(); --i >= 0;)
  32860. {
  32861. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32862. if (checker.shouldBailOut())
  32863. return;
  32864. i = jmin (i, mouseListeners_->size());
  32865. }
  32866. }
  32867. Component* p = parentComponent_;
  32868. while (p != 0)
  32869. {
  32870. if (p->numDeepMouseListeners > 0)
  32871. {
  32872. BailOutChecker checker (this, p);
  32873. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32874. {
  32875. p->mouseListeners_->getUnchecked (i)->mouseDrag (me);
  32876. if (checker.shouldBailOut())
  32877. return;
  32878. i = jmin (i, p->numDeepMouseListeners);
  32879. }
  32880. }
  32881. p = p->parentComponent_;
  32882. }
  32883. }
  32884. }
  32885. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32886. {
  32887. Desktop& desktop = Desktop::getInstance();
  32888. BailOutChecker checker (this);
  32889. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32890. this, time, relativePos,
  32891. time, 0, false);
  32892. if (isCurrentlyBlockedByAnotherModalComponent())
  32893. {
  32894. // allow blocked mouse-events to go to global listeners..
  32895. desktop.sendMouseMove();
  32896. }
  32897. else
  32898. {
  32899. flags.mouseOverFlag = true;
  32900. mouseMove (me);
  32901. if (checker.shouldBailOut())
  32902. return;
  32903. desktop.resetTimer();
  32904. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32905. if (checker.shouldBailOut())
  32906. return;
  32907. if (mouseListeners_ != 0)
  32908. {
  32909. for (int i = mouseListeners_->size(); --i >= 0;)
  32910. {
  32911. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32912. if (checker.shouldBailOut())
  32913. return;
  32914. i = jmin (i, mouseListeners_->size());
  32915. }
  32916. }
  32917. Component* p = parentComponent_;
  32918. while (p != 0)
  32919. {
  32920. if (p->numDeepMouseListeners > 0)
  32921. {
  32922. BailOutChecker checker (this, p);
  32923. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32924. {
  32925. p->mouseListeners_->getUnchecked (i)->mouseMove (me);
  32926. if (checker.shouldBailOut())
  32927. return;
  32928. i = jmin (i, p->numDeepMouseListeners);
  32929. }
  32930. }
  32931. p = p->parentComponent_;
  32932. }
  32933. }
  32934. }
  32935. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32936. const Time& time, const float amountX, const float amountY)
  32937. {
  32938. Desktop& desktop = Desktop::getInstance();
  32939. BailOutChecker checker (this);
  32940. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32941. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32942. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32943. this, time, relativePos, time, 0, false);
  32944. if (isCurrentlyBlockedByAnotherModalComponent())
  32945. {
  32946. // allow blocked mouse-events to go to global listeners..
  32947. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32948. }
  32949. else
  32950. {
  32951. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32952. if (checker.shouldBailOut())
  32953. return;
  32954. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32955. if (checker.shouldBailOut())
  32956. return;
  32957. if (mouseListeners_ != 0)
  32958. {
  32959. for (int i = mouseListeners_->size(); --i >= 0;)
  32960. {
  32961. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32962. if (checker.shouldBailOut())
  32963. return;
  32964. i = jmin (i, mouseListeners_->size());
  32965. }
  32966. }
  32967. Component* p = parentComponent_;
  32968. while (p != 0)
  32969. {
  32970. if (p->numDeepMouseListeners > 0)
  32971. {
  32972. BailOutChecker checker (this, p);
  32973. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32974. {
  32975. p->mouseListeners_->getUnchecked (i)->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32976. if (checker.shouldBailOut())
  32977. return;
  32978. i = jmin (i, p->numDeepMouseListeners);
  32979. }
  32980. }
  32981. p = p->parentComponent_;
  32982. }
  32983. }
  32984. }
  32985. void Component::sendFakeMouseMove() const
  32986. {
  32987. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32988. }
  32989. void Component::broughtToFront()
  32990. {
  32991. }
  32992. void Component::internalBroughtToFront()
  32993. {
  32994. if (! isValidComponent())
  32995. return;
  32996. if (flags.hasHeavyweightPeerFlag)
  32997. Desktop::getInstance().componentBroughtToFront (this);
  32998. BailOutChecker checker (this);
  32999. broughtToFront();
  33000. if (checker.shouldBailOut())
  33001. return;
  33002. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  33003. if (checker.shouldBailOut())
  33004. return;
  33005. // When brought to the front and there's a modal component blocking this one,
  33006. // we need to bring the modal one to the front instead..
  33007. Component* const cm = getCurrentlyModalComponent();
  33008. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33009. bringModalComponentToFront();
  33010. }
  33011. void Component::focusGained (FocusChangeType)
  33012. {
  33013. // base class does nothing
  33014. }
  33015. void Component::internalFocusGain (const FocusChangeType cause)
  33016. {
  33017. SafePointer<Component> safePointer (this);
  33018. focusGained (cause);
  33019. if (safePointer != 0)
  33020. internalChildFocusChange (cause);
  33021. }
  33022. void Component::focusLost (FocusChangeType)
  33023. {
  33024. // base class does nothing
  33025. }
  33026. void Component::internalFocusLoss (const FocusChangeType cause)
  33027. {
  33028. SafePointer<Component> safePointer (this);
  33029. focusLost (focusChangedDirectly);
  33030. if (safePointer != 0)
  33031. internalChildFocusChange (cause);
  33032. }
  33033. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33034. {
  33035. // base class does nothing
  33036. }
  33037. void Component::internalChildFocusChange (FocusChangeType cause)
  33038. {
  33039. const bool childIsNowFocused = hasKeyboardFocus (true);
  33040. if (flags.childCompFocusedFlag != childIsNowFocused)
  33041. {
  33042. flags.childCompFocusedFlag = childIsNowFocused;
  33043. SafePointer<Component> safePointer (this);
  33044. focusOfChildComponentChanged (cause);
  33045. if (safePointer == 0)
  33046. return;
  33047. }
  33048. if (parentComponent_ != 0)
  33049. parentComponent_->internalChildFocusChange (cause);
  33050. }
  33051. bool Component::isEnabled() const throw()
  33052. {
  33053. return (! flags.isDisabledFlag)
  33054. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33055. }
  33056. void Component::setEnabled (const bool shouldBeEnabled)
  33057. {
  33058. if (flags.isDisabledFlag == shouldBeEnabled)
  33059. {
  33060. flags.isDisabledFlag = ! shouldBeEnabled;
  33061. // if any parent components are disabled, setting our flag won't make a difference,
  33062. // so no need to send a change message
  33063. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33064. sendEnablementChangeMessage();
  33065. }
  33066. }
  33067. void Component::sendEnablementChangeMessage()
  33068. {
  33069. SafePointer<Component> safePointer (this);
  33070. enablementChanged();
  33071. if (safePointer == 0)
  33072. return;
  33073. for (int i = getNumChildComponents(); --i >= 0;)
  33074. {
  33075. Component* const c = getChildComponent (i);
  33076. if (c != 0)
  33077. {
  33078. c->sendEnablementChangeMessage();
  33079. if (safePointer == 0)
  33080. return;
  33081. }
  33082. }
  33083. }
  33084. void Component::enablementChanged()
  33085. {
  33086. }
  33087. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33088. {
  33089. flags.wantsFocusFlag = wantsFocus;
  33090. }
  33091. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33092. {
  33093. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33094. }
  33095. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33096. {
  33097. return ! flags.dontFocusOnMouseClickFlag;
  33098. }
  33099. bool Component::getWantsKeyboardFocus() const throw()
  33100. {
  33101. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33102. }
  33103. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33104. {
  33105. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33106. }
  33107. bool Component::isFocusContainer() const throw()
  33108. {
  33109. return flags.isFocusContainerFlag;
  33110. }
  33111. int Component::getExplicitFocusOrder() const
  33112. {
  33113. return properties ["_jexfo"];
  33114. }
  33115. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33116. {
  33117. properties.set ("_jexfo", newFocusOrderIndex);
  33118. }
  33119. KeyboardFocusTraverser* Component::createFocusTraverser()
  33120. {
  33121. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33122. return new KeyboardFocusTraverser();
  33123. return parentComponent_->createFocusTraverser();
  33124. }
  33125. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33126. {
  33127. // give the focus to this component
  33128. if (currentlyFocusedComponent != this)
  33129. {
  33130. JUCE_TRY
  33131. {
  33132. // get the focus onto our desktop window
  33133. ComponentPeer* const peer = getPeer();
  33134. if (peer != 0)
  33135. {
  33136. SafePointer<Component> safePointer (this);
  33137. peer->grabFocus();
  33138. if (peer->isFocused() && currentlyFocusedComponent != this)
  33139. {
  33140. Component* const componentLosingFocus = currentlyFocusedComponent;
  33141. currentlyFocusedComponent = this;
  33142. Desktop::getInstance().triggerFocusCallback();
  33143. // call this after setting currentlyFocusedComponent so that the one that's
  33144. // losing it has a chance to see where focus is going
  33145. if (componentLosingFocus->isValidComponent())
  33146. componentLosingFocus->internalFocusLoss (cause);
  33147. if (currentlyFocusedComponent == this)
  33148. {
  33149. focusGained (cause);
  33150. if (safePointer != 0)
  33151. internalChildFocusChange (cause);
  33152. }
  33153. }
  33154. }
  33155. }
  33156. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33157. catch (const std::exception& e)
  33158. {
  33159. currentlyFocusedComponent = 0;
  33160. Desktop::getInstance().triggerFocusCallback();
  33161. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33162. }
  33163. catch (...)
  33164. {
  33165. currentlyFocusedComponent = 0;
  33166. Desktop::getInstance().triggerFocusCallback();
  33167. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33168. }
  33169. #endif
  33170. }
  33171. }
  33172. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33173. {
  33174. if (isShowing())
  33175. {
  33176. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33177. {
  33178. takeKeyboardFocus (cause);
  33179. }
  33180. else
  33181. {
  33182. if (isParentOf (currentlyFocusedComponent)
  33183. && currentlyFocusedComponent->isShowing())
  33184. {
  33185. // do nothing if the focused component is actually a child of ours..
  33186. }
  33187. else
  33188. {
  33189. // find the default child component..
  33190. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33191. if (traverser != 0)
  33192. {
  33193. Component* const defaultComp = traverser->getDefaultComponent (this);
  33194. traverser = 0;
  33195. if (defaultComp != 0)
  33196. {
  33197. defaultComp->grabFocusInternal (cause, false);
  33198. return;
  33199. }
  33200. }
  33201. if (canTryParent && parentComponent_ != 0)
  33202. {
  33203. // if no children want it and we're allowed to try our parent comp,
  33204. // then pass up to parent, which will try our siblings.
  33205. parentComponent_->grabFocusInternal (cause, true);
  33206. }
  33207. }
  33208. }
  33209. }
  33210. }
  33211. void Component::grabKeyboardFocus()
  33212. {
  33213. // if component methods are being called from threads other than the message
  33214. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33215. checkMessageManagerIsLocked
  33216. grabFocusInternal (focusChangedDirectly);
  33217. }
  33218. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33219. {
  33220. // if component methods are being called from threads other than the message
  33221. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33222. checkMessageManagerIsLocked
  33223. if (parentComponent_ != 0)
  33224. {
  33225. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33226. if (traverser != 0)
  33227. {
  33228. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33229. : traverser->getPreviousComponent (this);
  33230. traverser = 0;
  33231. if (nextComp != 0)
  33232. {
  33233. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33234. {
  33235. SafePointer<Component> nextCompPointer (nextComp);
  33236. internalModalInputAttempt();
  33237. if (nextCompPointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33238. return;
  33239. }
  33240. nextComp->grabFocusInternal (focusChangedByTabKey);
  33241. return;
  33242. }
  33243. }
  33244. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33245. }
  33246. }
  33247. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33248. {
  33249. return (currentlyFocusedComponent == this)
  33250. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33251. }
  33252. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33253. {
  33254. return currentlyFocusedComponent;
  33255. }
  33256. void Component::giveAwayFocus()
  33257. {
  33258. // use a copy so we can clear the value before the call
  33259. Component* const componentLosingFocus = currentlyFocusedComponent;
  33260. currentlyFocusedComponent = 0;
  33261. Desktop::getInstance().triggerFocusCallback();
  33262. if (componentLosingFocus->isValidComponent())
  33263. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33264. }
  33265. bool Component::isMouseOver() const throw()
  33266. {
  33267. return flags.mouseOverFlag;
  33268. }
  33269. bool Component::isMouseButtonDown() const throw()
  33270. {
  33271. return flags.draggingFlag;
  33272. }
  33273. bool Component::isMouseOverOrDragging() const throw()
  33274. {
  33275. return flags.mouseOverFlag || flags.draggingFlag;
  33276. }
  33277. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33278. {
  33279. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33280. }
  33281. const Point<int> Component::getMouseXYRelative() const
  33282. {
  33283. return globalPositionToRelative (Desktop::getMousePosition());
  33284. }
  33285. const Rectangle<int> Component::getParentMonitorArea() const
  33286. {
  33287. return Desktop::getInstance()
  33288. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33289. getHeight() / 2)));
  33290. }
  33291. void Component::addKeyListener (KeyListener* const newListener)
  33292. {
  33293. if (keyListeners_ == 0)
  33294. keyListeners_ = new VoidArray();
  33295. keyListeners_->addIfNotAlreadyThere (newListener);
  33296. }
  33297. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33298. {
  33299. if (keyListeners_ != 0)
  33300. keyListeners_->removeValue (listenerToRemove);
  33301. }
  33302. bool Component::keyPressed (const KeyPress&)
  33303. {
  33304. return false;
  33305. }
  33306. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33307. {
  33308. return false;
  33309. }
  33310. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33311. {
  33312. if (parentComponent_ != 0)
  33313. parentComponent_->modifierKeysChanged (modifiers);
  33314. }
  33315. void Component::internalModifierKeysChanged()
  33316. {
  33317. sendFakeMouseMove();
  33318. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33319. }
  33320. ComponentPeer* Component::getPeer() const
  33321. {
  33322. if (flags.hasHeavyweightPeerFlag)
  33323. return ComponentPeer::getPeerFor (this);
  33324. else if (parentComponent_ != 0)
  33325. return parentComponent_->getPeer();
  33326. else
  33327. return 0;
  33328. }
  33329. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33330. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33331. {
  33332. jassert (component1 != 0);
  33333. }
  33334. bool Component::BailOutChecker::shouldBailOut() const throw()
  33335. {
  33336. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33337. }
  33338. END_JUCE_NAMESPACE
  33339. /*** End of inlined file: juce_Component.cpp ***/
  33340. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33341. BEGIN_JUCE_NAMESPACE
  33342. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33343. void ComponentListener::componentBroughtToFront (Component&) {}
  33344. void ComponentListener::componentVisibilityChanged (Component&) {}
  33345. void ComponentListener::componentChildrenChanged (Component&) {}
  33346. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33347. void ComponentListener::componentNameChanged (Component&) {}
  33348. void ComponentListener::componentBeingDeleted (Component&) {}
  33349. END_JUCE_NAMESPACE
  33350. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33351. /*** Start of inlined file: juce_Desktop.cpp ***/
  33352. BEGIN_JUCE_NAMESPACE
  33353. Desktop::Desktop()
  33354. : mouseClickCounter (0),
  33355. kioskModeComponent (0)
  33356. {
  33357. createMouseInputSources();
  33358. refreshMonitorSizes();
  33359. }
  33360. Desktop::~Desktop()
  33361. {
  33362. jassert (instance == this);
  33363. instance = 0;
  33364. // doh! If you don't delete all your windows before exiting, you're going to
  33365. // be leaking memory!
  33366. jassert (desktopComponents.size() == 0);
  33367. }
  33368. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33369. {
  33370. if (instance == 0)
  33371. instance = new Desktop();
  33372. return *instance;
  33373. }
  33374. Desktop* Desktop::instance = 0;
  33375. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33376. const bool clipToWorkArea);
  33377. void Desktop::refreshMonitorSizes()
  33378. {
  33379. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33380. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33381. monitorCoordsClipped.clear();
  33382. monitorCoordsUnclipped.clear();
  33383. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33384. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33385. jassert (monitorCoordsClipped.size() > 0
  33386. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33387. if (oldClipped != monitorCoordsClipped
  33388. || oldUnclipped != monitorCoordsUnclipped)
  33389. {
  33390. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33391. {
  33392. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33393. if (p != 0)
  33394. p->handleScreenSizeChange();
  33395. }
  33396. }
  33397. }
  33398. int Desktop::getNumDisplayMonitors() const throw()
  33399. {
  33400. return monitorCoordsClipped.size();
  33401. }
  33402. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33403. {
  33404. return clippedToWorkArea ? monitorCoordsClipped [index]
  33405. : monitorCoordsUnclipped [index];
  33406. }
  33407. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33408. {
  33409. RectangleList rl;
  33410. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33411. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33412. return rl;
  33413. }
  33414. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33415. {
  33416. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33417. }
  33418. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33419. {
  33420. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33421. double bestDistance = 1.0e10;
  33422. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33423. {
  33424. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33425. if (rect.contains (position))
  33426. return rect;
  33427. const double distance = rect.getCentre().getDistanceFrom (position);
  33428. if (distance < bestDistance)
  33429. {
  33430. bestDistance = distance;
  33431. best = rect;
  33432. }
  33433. }
  33434. return best;
  33435. }
  33436. int Desktop::getNumComponents() const throw()
  33437. {
  33438. return desktopComponents.size();
  33439. }
  33440. Component* Desktop::getComponent (const int index) const throw()
  33441. {
  33442. return desktopComponents [index];
  33443. }
  33444. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33445. {
  33446. for (int i = desktopComponents.size(); --i >= 0;)
  33447. {
  33448. Component* const c = desktopComponents.getUnchecked(i);
  33449. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33450. if (c->contains (relative.getX(), relative.getY()))
  33451. return c->getComponentAt (relative.getX(), relative.getY());
  33452. }
  33453. return 0;
  33454. }
  33455. void Desktop::addDesktopComponent (Component* const c)
  33456. {
  33457. jassert (c != 0);
  33458. jassert (! desktopComponents.contains (c));
  33459. desktopComponents.addIfNotAlreadyThere (c);
  33460. }
  33461. void Desktop::removeDesktopComponent (Component* const c)
  33462. {
  33463. desktopComponents.removeValue (c);
  33464. }
  33465. void Desktop::componentBroughtToFront (Component* const c)
  33466. {
  33467. const int index = desktopComponents.indexOf (c);
  33468. jassert (index >= 0);
  33469. if (index >= 0)
  33470. {
  33471. int newIndex = -1;
  33472. if (! c->isAlwaysOnTop())
  33473. {
  33474. newIndex = desktopComponents.size();
  33475. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33476. --newIndex;
  33477. --newIndex;
  33478. }
  33479. desktopComponents.move (index, newIndex);
  33480. }
  33481. }
  33482. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33483. {
  33484. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33485. }
  33486. int Desktop::getMouseButtonClickCounter() throw()
  33487. {
  33488. return getInstance().mouseClickCounter;
  33489. }
  33490. void Desktop::incrementMouseClickCounter() throw()
  33491. {
  33492. ++mouseClickCounter;
  33493. }
  33494. int Desktop::getNumDraggingMouseSources() const throw()
  33495. {
  33496. int num = 0;
  33497. for (int i = mouseSources.size(); --i >= 0;)
  33498. if (mouseSources.getUnchecked(i)->isDragging())
  33499. ++num;
  33500. return num;
  33501. }
  33502. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33503. {
  33504. int num = 0;
  33505. for (int i = mouseSources.size(); --i >= 0;)
  33506. {
  33507. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33508. if (mi->isDragging())
  33509. {
  33510. if (index == num)
  33511. return mi;
  33512. ++num;
  33513. }
  33514. }
  33515. return 0;
  33516. }
  33517. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33518. {
  33519. focusListeners.add (listener);
  33520. }
  33521. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33522. {
  33523. focusListeners.remove (listener);
  33524. }
  33525. void Desktop::triggerFocusCallback()
  33526. {
  33527. triggerAsyncUpdate();
  33528. }
  33529. void Desktop::handleAsyncUpdate()
  33530. {
  33531. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33532. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33533. }
  33534. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33535. {
  33536. mouseListeners.add (listener);
  33537. resetTimer();
  33538. }
  33539. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33540. {
  33541. mouseListeners.remove (listener);
  33542. resetTimer();
  33543. }
  33544. void Desktop::timerCallback()
  33545. {
  33546. if (lastFakeMouseMove != getMousePosition())
  33547. sendMouseMove();
  33548. }
  33549. void Desktop::sendMouseMove()
  33550. {
  33551. if (! mouseListeners.isEmpty())
  33552. {
  33553. startTimer (20);
  33554. lastFakeMouseMove = getMousePosition();
  33555. Component* const target = findComponentAt (lastFakeMouseMove);
  33556. if (target != 0)
  33557. {
  33558. Component::BailOutChecker checker (target);
  33559. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33560. const Time now (Time::getCurrentTime());
  33561. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33562. target, now, pos, now, 0, false);
  33563. if (me.mods.isAnyMouseButtonDown())
  33564. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33565. else
  33566. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33567. }
  33568. }
  33569. }
  33570. void Desktop::resetTimer()
  33571. {
  33572. if (mouseListeners.size() == 0)
  33573. stopTimer();
  33574. else
  33575. startTimer (100);
  33576. lastFakeMouseMove = getMousePosition();
  33577. }
  33578. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33579. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33580. {
  33581. if (kioskModeComponent != componentToUse)
  33582. {
  33583. // agh! Don't delete a component without first stopping it being the kiosk comp
  33584. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33585. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33586. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33587. if (kioskModeComponent->isValidComponent())
  33588. {
  33589. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33590. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33591. }
  33592. kioskModeComponent = componentToUse;
  33593. if (kioskModeComponent != 0)
  33594. {
  33595. jassert (kioskModeComponent->isValidComponent());
  33596. // Only components that are already on the desktop can be put into kiosk mode!
  33597. jassert (kioskModeComponent->isOnDesktop());
  33598. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33599. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33600. }
  33601. }
  33602. }
  33603. END_JUCE_NAMESPACE
  33604. /*** End of inlined file: juce_Desktop.cpp ***/
  33605. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33606. BEGIN_JUCE_NAMESPACE
  33607. ArrowButton::ArrowButton (const String& name,
  33608. float arrowDirectionInRadians,
  33609. const Colour& arrowColour)
  33610. : Button (name),
  33611. colour (arrowColour)
  33612. {
  33613. path.lineTo (0.0f, 1.0f);
  33614. path.lineTo (1.0f, 0.5f);
  33615. path.closeSubPath();
  33616. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33617. 0.5f, 0.5f));
  33618. setComponentEffect (&shadow);
  33619. buttonStateChanged();
  33620. }
  33621. ArrowButton::~ArrowButton()
  33622. {
  33623. }
  33624. void ArrowButton::paintButton (Graphics& g,
  33625. bool /*isMouseOverButton*/,
  33626. bool /*isButtonDown*/)
  33627. {
  33628. g.setColour (colour);
  33629. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33630. (float) offset,
  33631. (float) (getWidth() - 3),
  33632. (float) (getHeight() - 3),
  33633. false));
  33634. }
  33635. void ArrowButton::buttonStateChanged()
  33636. {
  33637. offset = (isDown()) ? 1 : 0;
  33638. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33639. 0.3f, -1, 0);
  33640. }
  33641. END_JUCE_NAMESPACE
  33642. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33643. /*** Start of inlined file: juce_Button.cpp ***/
  33644. BEGIN_JUCE_NAMESPACE
  33645. class Button::RepeatTimer : public Timer
  33646. {
  33647. public:
  33648. RepeatTimer (Button& owner_) : owner (owner_) {}
  33649. void timerCallback() { owner.repeatTimerCallback(); }
  33650. juce_UseDebuggingNewOperator
  33651. private:
  33652. Button& owner;
  33653. RepeatTimer (const RepeatTimer&);
  33654. RepeatTimer& operator= (const RepeatTimer&);
  33655. };
  33656. Button::Button (const String& name)
  33657. : Component (name),
  33658. text (name),
  33659. buttonPressTime (0),
  33660. lastTimeCallbackTime (0),
  33661. commandManagerToUse (0),
  33662. autoRepeatDelay (-1),
  33663. autoRepeatSpeed (0),
  33664. autoRepeatMinimumDelay (-1),
  33665. radioGroupId (0),
  33666. commandID (0),
  33667. connectedEdgeFlags (0),
  33668. buttonState (buttonNormal),
  33669. lastToggleState (false),
  33670. clickTogglesState (false),
  33671. needsToRelease (false),
  33672. needsRepainting (false),
  33673. isKeyDown (false),
  33674. triggerOnMouseDown (false),
  33675. generateTooltip (false)
  33676. {
  33677. setWantsKeyboardFocus (true);
  33678. isOn.addListener (this);
  33679. }
  33680. Button::~Button()
  33681. {
  33682. isOn.removeListener (this);
  33683. if (commandManagerToUse != 0)
  33684. commandManagerToUse->removeListener (this);
  33685. repeatTimer = 0;
  33686. clearShortcuts();
  33687. }
  33688. void Button::setButtonText (const String& newText)
  33689. {
  33690. if (text != newText)
  33691. {
  33692. text = newText;
  33693. repaint();
  33694. }
  33695. }
  33696. void Button::setTooltip (const String& newTooltip)
  33697. {
  33698. SettableTooltipClient::setTooltip (newTooltip);
  33699. generateTooltip = false;
  33700. }
  33701. const String Button::getTooltip()
  33702. {
  33703. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33704. {
  33705. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33706. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33707. for (int i = 0; i < keyPresses.size(); ++i)
  33708. {
  33709. const String key (keyPresses.getReference(i).getTextDescription());
  33710. tt << " [";
  33711. if (key.length() == 1)
  33712. tt << TRANS("shortcut") << ": '" << key << "']";
  33713. else
  33714. tt << key << ']';
  33715. }
  33716. return tt;
  33717. }
  33718. return SettableTooltipClient::getTooltip();
  33719. }
  33720. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33721. {
  33722. if (connectedEdgeFlags != connectedEdgeFlags_)
  33723. {
  33724. connectedEdgeFlags = connectedEdgeFlags_;
  33725. repaint();
  33726. }
  33727. }
  33728. void Button::setToggleState (const bool shouldBeOn,
  33729. const bool sendChangeNotification)
  33730. {
  33731. if (shouldBeOn != lastToggleState)
  33732. {
  33733. isOn = shouldBeOn;
  33734. lastToggleState = shouldBeOn;
  33735. repaint();
  33736. if (sendChangeNotification)
  33737. {
  33738. Component::SafePointer<Component> deletionWatcher (this);
  33739. sendClickMessage (ModifierKeys());
  33740. if (deletionWatcher == 0)
  33741. return;
  33742. }
  33743. if (lastToggleState)
  33744. turnOffOtherButtonsInGroup (sendChangeNotification);
  33745. }
  33746. }
  33747. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33748. {
  33749. clickTogglesState = shouldToggle;
  33750. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33751. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33752. // it is that this button represents, and the button will update its state to reflect this
  33753. // in the applicationCommandListChanged() method.
  33754. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33755. }
  33756. bool Button::getClickingTogglesState() const throw()
  33757. {
  33758. return clickTogglesState;
  33759. }
  33760. void Button::valueChanged (Value& value)
  33761. {
  33762. if (value.refersToSameSourceAs (isOn))
  33763. setToggleState (isOn.getValue(), true);
  33764. }
  33765. void Button::setRadioGroupId (const int newGroupId)
  33766. {
  33767. if (radioGroupId != newGroupId)
  33768. {
  33769. radioGroupId = newGroupId;
  33770. if (lastToggleState)
  33771. turnOffOtherButtonsInGroup (true);
  33772. }
  33773. }
  33774. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33775. {
  33776. Component* const p = getParentComponent();
  33777. if (p != 0 && radioGroupId != 0)
  33778. {
  33779. Component::SafePointer<Component> deletionWatcher (this);
  33780. for (int i = p->getNumChildComponents(); --i >= 0;)
  33781. {
  33782. Component* const c = p->getChildComponent (i);
  33783. if (c != this)
  33784. {
  33785. Button* const b = dynamic_cast <Button*> (c);
  33786. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33787. {
  33788. b->setToggleState (false, sendChangeNotification);
  33789. if (deletionWatcher == 0)
  33790. return;
  33791. }
  33792. }
  33793. }
  33794. }
  33795. }
  33796. void Button::enablementChanged()
  33797. {
  33798. updateState (0);
  33799. repaint();
  33800. }
  33801. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33802. {
  33803. ButtonState state = buttonNormal;
  33804. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33805. {
  33806. Point<int> mousePos;
  33807. if (e == 0)
  33808. mousePos = getMouseXYRelative();
  33809. else
  33810. mousePos = e->getEventRelativeTo (this).getPosition();
  33811. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33812. const bool down = isMouseButtonDown();
  33813. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33814. state = buttonDown;
  33815. else if (over)
  33816. state = buttonOver;
  33817. }
  33818. setState (state);
  33819. return state;
  33820. }
  33821. void Button::setState (const ButtonState newState)
  33822. {
  33823. if (buttonState != newState)
  33824. {
  33825. buttonState = newState;
  33826. repaint();
  33827. if (buttonState == buttonDown)
  33828. {
  33829. buttonPressTime = Time::getApproximateMillisecondCounter();
  33830. lastTimeCallbackTime = buttonPressTime;
  33831. }
  33832. sendStateMessage();
  33833. }
  33834. }
  33835. bool Button::isDown() const throw()
  33836. {
  33837. return buttonState == buttonDown;
  33838. }
  33839. bool Button::isOver() const throw()
  33840. {
  33841. return buttonState != buttonNormal;
  33842. }
  33843. void Button::buttonStateChanged()
  33844. {
  33845. }
  33846. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33847. {
  33848. const uint32 now = Time::getApproximateMillisecondCounter();
  33849. return now > buttonPressTime ? now - buttonPressTime : 0;
  33850. }
  33851. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33852. {
  33853. triggerOnMouseDown = isTriggeredOnMouseDown;
  33854. }
  33855. void Button::clicked()
  33856. {
  33857. }
  33858. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33859. {
  33860. clicked();
  33861. }
  33862. static const int clickMessageId = 0x2f3f4f99;
  33863. void Button::triggerClick()
  33864. {
  33865. postCommandMessage (clickMessageId);
  33866. }
  33867. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33868. {
  33869. if (clickTogglesState)
  33870. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33871. sendClickMessage (modifiers);
  33872. }
  33873. void Button::flashButtonState()
  33874. {
  33875. if (isEnabled())
  33876. {
  33877. needsToRelease = true;
  33878. setState (buttonDown);
  33879. getRepeatTimer().startTimer (100);
  33880. }
  33881. }
  33882. void Button::handleCommandMessage (int commandId)
  33883. {
  33884. if (commandId == clickMessageId)
  33885. {
  33886. if (isEnabled())
  33887. {
  33888. flashButtonState();
  33889. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33890. }
  33891. }
  33892. else
  33893. {
  33894. Component::handleCommandMessage (commandId);
  33895. }
  33896. }
  33897. void Button::addButtonListener (ButtonListener* const newListener)
  33898. {
  33899. buttonListeners.add (newListener);
  33900. }
  33901. void Button::removeButtonListener (ButtonListener* const listener)
  33902. {
  33903. buttonListeners.remove (listener);
  33904. }
  33905. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33906. {
  33907. Component::BailOutChecker checker (this);
  33908. if (commandManagerToUse != 0 && commandID != 0)
  33909. {
  33910. ApplicationCommandTarget::InvocationInfo info (commandID);
  33911. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33912. info.originatingComponent = this;
  33913. commandManagerToUse->invoke (info, true);
  33914. }
  33915. clicked (modifiers);
  33916. if (! checker.shouldBailOut())
  33917. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33918. }
  33919. void Button::sendStateMessage()
  33920. {
  33921. Component::BailOutChecker checker (this);
  33922. buttonStateChanged();
  33923. if (! checker.shouldBailOut())
  33924. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33925. }
  33926. void Button::paint (Graphics& g)
  33927. {
  33928. if (needsToRelease && isEnabled())
  33929. {
  33930. needsToRelease = false;
  33931. needsRepainting = true;
  33932. }
  33933. paintButton (g, isOver(), isDown());
  33934. }
  33935. void Button::mouseEnter (const MouseEvent& e)
  33936. {
  33937. updateState (&e);
  33938. }
  33939. void Button::mouseExit (const MouseEvent& e)
  33940. {
  33941. updateState (&e);
  33942. }
  33943. void Button::mouseDown (const MouseEvent& e)
  33944. {
  33945. updateState (&e);
  33946. if (isDown())
  33947. {
  33948. if (autoRepeatDelay >= 0)
  33949. getRepeatTimer().startTimer (autoRepeatDelay);
  33950. if (triggerOnMouseDown)
  33951. internalClickCallback (e.mods);
  33952. }
  33953. }
  33954. void Button::mouseUp (const MouseEvent& e)
  33955. {
  33956. const bool wasDown = isDown();
  33957. updateState (&e);
  33958. if (wasDown && isOver() && ! triggerOnMouseDown)
  33959. internalClickCallback (e.mods);
  33960. }
  33961. void Button::mouseDrag (const MouseEvent& e)
  33962. {
  33963. const ButtonState oldState = buttonState;
  33964. updateState (&e);
  33965. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33966. getRepeatTimer().startTimer (autoRepeatSpeed);
  33967. }
  33968. void Button::focusGained (FocusChangeType)
  33969. {
  33970. updateState (0);
  33971. repaint();
  33972. }
  33973. void Button::focusLost (FocusChangeType)
  33974. {
  33975. updateState (0);
  33976. repaint();
  33977. }
  33978. void Button::setVisible (bool shouldBeVisible)
  33979. {
  33980. if (shouldBeVisible != isVisible())
  33981. {
  33982. Component::setVisible (shouldBeVisible);
  33983. if (! shouldBeVisible)
  33984. needsToRelease = false;
  33985. updateState (0);
  33986. }
  33987. else
  33988. {
  33989. Component::setVisible (shouldBeVisible);
  33990. }
  33991. }
  33992. void Button::parentHierarchyChanged()
  33993. {
  33994. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33995. if (newKeySource != keySource.getComponent())
  33996. {
  33997. if (keySource != 0)
  33998. keySource->removeKeyListener (this);
  33999. keySource = newKeySource;
  34000. if (keySource != 0)
  34001. keySource->addKeyListener (this);
  34002. }
  34003. }
  34004. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34005. const int commandID_,
  34006. const bool generateTooltip_)
  34007. {
  34008. commandID = commandID_;
  34009. generateTooltip = generateTooltip_;
  34010. if (commandManagerToUse != commandManagerToUse_)
  34011. {
  34012. if (commandManagerToUse != 0)
  34013. commandManagerToUse->removeListener (this);
  34014. commandManagerToUse = commandManagerToUse_;
  34015. if (commandManagerToUse != 0)
  34016. commandManagerToUse->addListener (this);
  34017. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34018. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34019. // it is that this button represents, and the button will update its state to reflect this
  34020. // in the applicationCommandListChanged() method.
  34021. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34022. }
  34023. if (commandManagerToUse != 0)
  34024. applicationCommandListChanged();
  34025. else
  34026. setEnabled (true);
  34027. }
  34028. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34029. {
  34030. if (info.commandID == commandID
  34031. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34032. {
  34033. flashButtonState();
  34034. }
  34035. }
  34036. void Button::applicationCommandListChanged()
  34037. {
  34038. if (commandManagerToUse != 0)
  34039. {
  34040. ApplicationCommandInfo info (0);
  34041. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34042. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34043. if (target != 0)
  34044. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34045. }
  34046. }
  34047. void Button::addShortcut (const KeyPress& key)
  34048. {
  34049. if (key.isValid())
  34050. {
  34051. jassert (! isRegisteredForShortcut (key)); // already registered!
  34052. shortcuts.add (key);
  34053. parentHierarchyChanged();
  34054. }
  34055. }
  34056. void Button::clearShortcuts()
  34057. {
  34058. shortcuts.clear();
  34059. parentHierarchyChanged();
  34060. }
  34061. bool Button::isShortcutPressed() const
  34062. {
  34063. if (! isCurrentlyBlockedByAnotherModalComponent())
  34064. {
  34065. for (int i = shortcuts.size(); --i >= 0;)
  34066. if (shortcuts.getReference(i).isCurrentlyDown())
  34067. return true;
  34068. }
  34069. return false;
  34070. }
  34071. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34072. {
  34073. for (int i = shortcuts.size(); --i >= 0;)
  34074. if (key == shortcuts.getReference(i))
  34075. return true;
  34076. return false;
  34077. }
  34078. bool Button::keyStateChanged (const bool, Component*)
  34079. {
  34080. if (! isEnabled())
  34081. return false;
  34082. const bool wasDown = isKeyDown;
  34083. isKeyDown = isShortcutPressed();
  34084. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34085. getRepeatTimer().startTimer (autoRepeatDelay);
  34086. updateState (0);
  34087. if (isEnabled() && wasDown && ! isKeyDown)
  34088. {
  34089. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34090. // (return immediately - this button may now have been deleted)
  34091. return true;
  34092. }
  34093. return wasDown || isKeyDown;
  34094. }
  34095. bool Button::keyPressed (const KeyPress&, Component*)
  34096. {
  34097. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34098. return isShortcutPressed();
  34099. }
  34100. bool Button::keyPressed (const KeyPress& key)
  34101. {
  34102. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34103. {
  34104. triggerClick();
  34105. return true;
  34106. }
  34107. return false;
  34108. }
  34109. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34110. const int repeatMillisecs,
  34111. const int minimumDelayInMillisecs) throw()
  34112. {
  34113. autoRepeatDelay = initialDelayMillisecs;
  34114. autoRepeatSpeed = repeatMillisecs;
  34115. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34116. }
  34117. void Button::repeatTimerCallback()
  34118. {
  34119. if (needsRepainting)
  34120. {
  34121. getRepeatTimer().stopTimer();
  34122. updateState (0);
  34123. needsRepainting = false;
  34124. }
  34125. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34126. {
  34127. int repeatSpeed = autoRepeatSpeed;
  34128. if (autoRepeatMinimumDelay >= 0)
  34129. {
  34130. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34131. timeHeldDown *= timeHeldDown;
  34132. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34133. }
  34134. repeatSpeed = jmax (1, repeatSpeed);
  34135. getRepeatTimer().startTimer (repeatSpeed);
  34136. const uint32 now = Time::getApproximateMillisecondCounter();
  34137. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34138. lastTimeCallbackTime = now;
  34139. Component::SafePointer<Component> deletionWatcher (this);
  34140. for (int i = numTimesToCallback; --i >= 0;)
  34141. {
  34142. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34143. if (deletionWatcher == 0 || ! isDown())
  34144. return;
  34145. }
  34146. }
  34147. else if (! needsToRelease)
  34148. {
  34149. getRepeatTimer().stopTimer();
  34150. }
  34151. }
  34152. Button::RepeatTimer& Button::getRepeatTimer()
  34153. {
  34154. if (repeatTimer == 0)
  34155. repeatTimer = new RepeatTimer (*this);
  34156. return *repeatTimer;
  34157. }
  34158. END_JUCE_NAMESPACE
  34159. /*** End of inlined file: juce_Button.cpp ***/
  34160. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34161. BEGIN_JUCE_NAMESPACE
  34162. DrawableButton::DrawableButton (const String& name,
  34163. const DrawableButton::ButtonStyle buttonStyle)
  34164. : Button (name),
  34165. style (buttonStyle),
  34166. edgeIndent (3)
  34167. {
  34168. if (buttonStyle == ImageOnButtonBackground)
  34169. {
  34170. backgroundOff = Colour (0xffbbbbff);
  34171. backgroundOn = Colour (0xff3333ff);
  34172. }
  34173. else
  34174. {
  34175. backgroundOff = Colours::transparentBlack;
  34176. backgroundOn = Colour (0xaabbbbff);
  34177. }
  34178. }
  34179. DrawableButton::~DrawableButton()
  34180. {
  34181. deleteImages();
  34182. }
  34183. void DrawableButton::deleteImages()
  34184. {
  34185. }
  34186. void DrawableButton::setImages (const Drawable* normal,
  34187. const Drawable* over,
  34188. const Drawable* down,
  34189. const Drawable* disabled,
  34190. const Drawable* normalOn,
  34191. const Drawable* overOn,
  34192. const Drawable* downOn,
  34193. const Drawable* disabledOn)
  34194. {
  34195. deleteImages();
  34196. jassert (normal != 0); // you really need to give it at least a normal image..
  34197. if (normal != 0)
  34198. normalImage = normal->createCopy();
  34199. if (over != 0)
  34200. overImage = over->createCopy();
  34201. if (down != 0)
  34202. downImage = down->createCopy();
  34203. if (disabled != 0)
  34204. disabledImage = disabled->createCopy();
  34205. if (normalOn != 0)
  34206. normalImageOn = normalOn->createCopy();
  34207. if (overOn != 0)
  34208. overImageOn = overOn->createCopy();
  34209. if (downOn != 0)
  34210. downImageOn = downOn->createCopy();
  34211. if (disabledOn != 0)
  34212. disabledImageOn = disabledOn->createCopy();
  34213. repaint();
  34214. }
  34215. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34216. {
  34217. if (style != newStyle)
  34218. {
  34219. style = newStyle;
  34220. repaint();
  34221. }
  34222. }
  34223. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34224. const Colour& toggledOnColour)
  34225. {
  34226. if (backgroundOff != toggledOffColour
  34227. || backgroundOn != toggledOnColour)
  34228. {
  34229. backgroundOff = toggledOffColour;
  34230. backgroundOn = toggledOnColour;
  34231. repaint();
  34232. }
  34233. }
  34234. const Colour& DrawableButton::getBackgroundColour() const throw()
  34235. {
  34236. return getToggleState() ? backgroundOn
  34237. : backgroundOff;
  34238. }
  34239. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34240. {
  34241. edgeIndent = numPixelsIndent;
  34242. repaint();
  34243. }
  34244. void DrawableButton::paintButton (Graphics& g,
  34245. bool isMouseOverButton,
  34246. bool isButtonDown)
  34247. {
  34248. Rectangle<int> imageSpace;
  34249. if (style == ImageOnButtonBackground)
  34250. {
  34251. const int insetX = getWidth() / 4;
  34252. const int insetY = getHeight() / 4;
  34253. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34254. getLookAndFeel().drawButtonBackground (g, *this,
  34255. getBackgroundColour(),
  34256. isMouseOverButton,
  34257. isButtonDown);
  34258. }
  34259. else
  34260. {
  34261. g.fillAll (getBackgroundColour());
  34262. const int textH = (style == ImageAboveTextLabel)
  34263. ? jmin (16, proportionOfHeight (0.25f))
  34264. : 0;
  34265. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34266. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34267. imageSpace.setBounds (indentX, indentY,
  34268. getWidth() - indentX * 2,
  34269. getHeight() - indentY * 2 - textH);
  34270. if (textH > 0)
  34271. {
  34272. g.setFont ((float) textH);
  34273. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34274. g.drawFittedText (getButtonText(),
  34275. 2, getHeight() - textH - 1,
  34276. getWidth() - 4, textH,
  34277. Justification::centred, 1);
  34278. }
  34279. }
  34280. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34281. g.setOpacity (1.0f);
  34282. const Drawable* imageToDraw = 0;
  34283. if (isEnabled())
  34284. {
  34285. imageToDraw = getCurrentImage();
  34286. }
  34287. else
  34288. {
  34289. imageToDraw = getToggleState() ? disabledImageOn
  34290. : disabledImage;
  34291. if (imageToDraw == 0)
  34292. {
  34293. g.setOpacity (0.4f);
  34294. imageToDraw = getNormalImage();
  34295. }
  34296. }
  34297. if (imageToDraw != 0)
  34298. {
  34299. if (style == ImageRaw)
  34300. {
  34301. imageToDraw->draw (g, 1.0f);
  34302. }
  34303. else
  34304. {
  34305. imageToDraw->drawWithin (g,
  34306. imageSpace.getX(),
  34307. imageSpace.getY(),
  34308. imageSpace.getWidth(),
  34309. imageSpace.getHeight(),
  34310. RectanglePlacement::centred,
  34311. 1.0f);
  34312. }
  34313. }
  34314. }
  34315. const Drawable* DrawableButton::getCurrentImage() const throw()
  34316. {
  34317. if (isDown())
  34318. return getDownImage();
  34319. if (isOver())
  34320. return getOverImage();
  34321. return getNormalImage();
  34322. }
  34323. const Drawable* DrawableButton::getNormalImage() const throw()
  34324. {
  34325. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34326. : normalImage;
  34327. }
  34328. const Drawable* DrawableButton::getOverImage() const throw()
  34329. {
  34330. const Drawable* d = normalImage;
  34331. if (getToggleState())
  34332. {
  34333. if (overImageOn != 0)
  34334. d = overImageOn;
  34335. else if (normalImageOn != 0)
  34336. d = normalImageOn;
  34337. else if (overImage != 0)
  34338. d = overImage;
  34339. }
  34340. else
  34341. {
  34342. if (overImage != 0)
  34343. d = overImage;
  34344. }
  34345. return d;
  34346. }
  34347. const Drawable* DrawableButton::getDownImage() const throw()
  34348. {
  34349. const Drawable* d = normalImage;
  34350. if (getToggleState())
  34351. {
  34352. if (downImageOn != 0)
  34353. d = downImageOn;
  34354. else if (overImageOn != 0)
  34355. d = overImageOn;
  34356. else if (normalImageOn != 0)
  34357. d = normalImageOn;
  34358. else if (downImage != 0)
  34359. d = downImage;
  34360. else
  34361. d = getOverImage();
  34362. }
  34363. else
  34364. {
  34365. if (downImage != 0)
  34366. d = downImage;
  34367. else
  34368. d = getOverImage();
  34369. }
  34370. return d;
  34371. }
  34372. END_JUCE_NAMESPACE
  34373. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34374. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34375. BEGIN_JUCE_NAMESPACE
  34376. HyperlinkButton::HyperlinkButton (const String& linkText,
  34377. const URL& linkURL)
  34378. : Button (linkText),
  34379. url (linkURL),
  34380. font (14.0f, Font::underlined),
  34381. resizeFont (true),
  34382. justification (Justification::centred)
  34383. {
  34384. setMouseCursor (MouseCursor::PointingHandCursor);
  34385. setTooltip (linkURL.toString (false));
  34386. }
  34387. HyperlinkButton::~HyperlinkButton()
  34388. {
  34389. }
  34390. void HyperlinkButton::setFont (const Font& newFont,
  34391. const bool resizeToMatchComponentHeight,
  34392. const Justification& justificationType)
  34393. {
  34394. font = newFont;
  34395. resizeFont = resizeToMatchComponentHeight;
  34396. justification = justificationType;
  34397. repaint();
  34398. }
  34399. void HyperlinkButton::setURL (const URL& newURL) throw()
  34400. {
  34401. url = newURL;
  34402. setTooltip (newURL.toString (false));
  34403. }
  34404. const Font HyperlinkButton::getFontToUse() const
  34405. {
  34406. Font f (font);
  34407. if (resizeFont)
  34408. f.setHeight (getHeight() * 0.7f);
  34409. return f;
  34410. }
  34411. void HyperlinkButton::changeWidthToFitText()
  34412. {
  34413. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34414. }
  34415. void HyperlinkButton::colourChanged()
  34416. {
  34417. repaint();
  34418. }
  34419. void HyperlinkButton::clicked()
  34420. {
  34421. if (url.isWellFormed())
  34422. url.launchInDefaultBrowser();
  34423. }
  34424. void HyperlinkButton::paintButton (Graphics& g,
  34425. bool isMouseOverButton,
  34426. bool isButtonDown)
  34427. {
  34428. const Colour textColour (findColour (textColourId));
  34429. if (isEnabled())
  34430. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34431. : textColour);
  34432. else
  34433. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34434. g.setFont (getFontToUse());
  34435. g.drawText (getButtonText(),
  34436. 2, 0, getWidth() - 2, getHeight(),
  34437. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34438. true);
  34439. }
  34440. END_JUCE_NAMESPACE
  34441. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34442. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34443. BEGIN_JUCE_NAMESPACE
  34444. ImageButton::ImageButton (const String& text_)
  34445. : Button (text_),
  34446. scaleImageToFit (true),
  34447. preserveProportions (true),
  34448. alphaThreshold (0),
  34449. imageX (0),
  34450. imageY (0),
  34451. imageW (0),
  34452. imageH (0),
  34453. normalImage (0),
  34454. overImage (0),
  34455. downImage (0)
  34456. {
  34457. }
  34458. ImageButton::~ImageButton()
  34459. {
  34460. deleteImages();
  34461. }
  34462. void ImageButton::deleteImages()
  34463. {
  34464. ImageCache::releaseOrDelete (normalImage);
  34465. ImageCache::releaseOrDelete (overImage);
  34466. ImageCache::releaseOrDelete (downImage);
  34467. }
  34468. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34469. const bool rescaleImagesWhenButtonSizeChanges,
  34470. const bool preserveImageProportions,
  34471. Image* const normalImage_,
  34472. const float imageOpacityWhenNormal,
  34473. const Colour& overlayColourWhenNormal,
  34474. Image* const overImage_,
  34475. const float imageOpacityWhenOver,
  34476. const Colour& overlayColourWhenOver,
  34477. Image* const downImage_,
  34478. const float imageOpacityWhenDown,
  34479. const Colour& overlayColourWhenDown,
  34480. const float hitTestAlphaThreshold)
  34481. {
  34482. deleteImages();
  34483. normalImage = normalImage_;
  34484. overImage = overImage_;
  34485. downImage = downImage_;
  34486. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34487. {
  34488. imageW = normalImage->getWidth();
  34489. imageH = normalImage->getHeight();
  34490. setSize (imageW, imageH);
  34491. }
  34492. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34493. preserveProportions = preserveImageProportions;
  34494. normalOpacity = imageOpacityWhenNormal;
  34495. normalOverlay = overlayColourWhenNormal;
  34496. overOpacity = imageOpacityWhenOver;
  34497. overOverlay = overlayColourWhenOver;
  34498. downOpacity = imageOpacityWhenDown;
  34499. downOverlay = overlayColourWhenDown;
  34500. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34501. repaint();
  34502. }
  34503. Image* ImageButton::getCurrentImage() const
  34504. {
  34505. if (isDown() || getToggleState())
  34506. return getDownImage();
  34507. if (isOver())
  34508. return getOverImage();
  34509. return getNormalImage();
  34510. }
  34511. Image* ImageButton::getNormalImage() const throw()
  34512. {
  34513. return normalImage;
  34514. }
  34515. Image* ImageButton::getOverImage() const throw()
  34516. {
  34517. return (overImage != 0) ? overImage
  34518. : normalImage;
  34519. }
  34520. Image* ImageButton::getDownImage() const throw()
  34521. {
  34522. return (downImage != 0) ? downImage
  34523. : getOverImage();
  34524. }
  34525. void ImageButton::paintButton (Graphics& g,
  34526. bool isMouseOverButton,
  34527. bool isButtonDown)
  34528. {
  34529. if (! isEnabled())
  34530. {
  34531. isMouseOverButton = false;
  34532. isButtonDown = false;
  34533. }
  34534. Image* const im = getCurrentImage();
  34535. if (im != 0)
  34536. {
  34537. const int iw = im->getWidth();
  34538. const int ih = im->getHeight();
  34539. imageW = getWidth();
  34540. imageH = getHeight();
  34541. imageX = (imageW - iw) >> 1;
  34542. imageY = (imageH - ih) >> 1;
  34543. if (scaleImageToFit)
  34544. {
  34545. if (preserveProportions)
  34546. {
  34547. int newW, newH;
  34548. const float imRatio = ih / (float)iw;
  34549. const float destRatio = imageH / (float)imageW;
  34550. if (imRatio > destRatio)
  34551. {
  34552. newW = roundToInt (imageH / imRatio);
  34553. newH = imageH;
  34554. }
  34555. else
  34556. {
  34557. newW = imageW;
  34558. newH = roundToInt (imageW * imRatio);
  34559. }
  34560. imageX = (imageW - newW) / 2;
  34561. imageY = (imageH - newH) / 2;
  34562. imageW = newW;
  34563. imageH = newH;
  34564. }
  34565. else
  34566. {
  34567. imageX = 0;
  34568. imageY = 0;
  34569. }
  34570. }
  34571. if (! scaleImageToFit)
  34572. {
  34573. imageW = iw;
  34574. imageH = ih;
  34575. }
  34576. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34577. isButtonDown ? downOverlay
  34578. : (isMouseOverButton ? overOverlay
  34579. : normalOverlay),
  34580. isButtonDown ? downOpacity
  34581. : (isMouseOverButton ? overOpacity
  34582. : normalOpacity),
  34583. *this);
  34584. }
  34585. }
  34586. bool ImageButton::hitTest (int x, int y)
  34587. {
  34588. if (alphaThreshold == 0)
  34589. return true;
  34590. Image* const im = getCurrentImage();
  34591. return im == 0
  34592. || (imageW > 0 && imageH > 0
  34593. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34594. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34595. }
  34596. END_JUCE_NAMESPACE
  34597. /*** End of inlined file: juce_ImageButton.cpp ***/
  34598. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34599. BEGIN_JUCE_NAMESPACE
  34600. ShapeButton::ShapeButton (const String& text_,
  34601. const Colour& normalColour_,
  34602. const Colour& overColour_,
  34603. const Colour& downColour_)
  34604. : Button (text_),
  34605. normalColour (normalColour_),
  34606. overColour (overColour_),
  34607. downColour (downColour_),
  34608. maintainShapeProportions (false),
  34609. outlineWidth (0.0f)
  34610. {
  34611. }
  34612. ShapeButton::~ShapeButton()
  34613. {
  34614. }
  34615. void ShapeButton::setColours (const Colour& newNormalColour,
  34616. const Colour& newOverColour,
  34617. const Colour& newDownColour)
  34618. {
  34619. normalColour = newNormalColour;
  34620. overColour = newOverColour;
  34621. downColour = newDownColour;
  34622. }
  34623. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34624. const float newOutlineWidth)
  34625. {
  34626. outlineColour = newOutlineColour;
  34627. outlineWidth = newOutlineWidth;
  34628. }
  34629. void ShapeButton::setShape (const Path& newShape,
  34630. const bool resizeNowToFitThisShape,
  34631. const bool maintainShapeProportions_,
  34632. const bool hasShadow)
  34633. {
  34634. shape = newShape;
  34635. maintainShapeProportions = maintainShapeProportions_;
  34636. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34637. setComponentEffect ((hasShadow) ? &shadow : 0);
  34638. if (resizeNowToFitThisShape)
  34639. {
  34640. Rectangle<float> bounds (shape.getBounds());
  34641. if (hasShadow)
  34642. bounds.expand (4.0f, 4.0f);
  34643. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34644. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34645. 1 + (int) (bounds.getHeight() + outlineWidth));
  34646. }
  34647. }
  34648. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34649. {
  34650. if (! isEnabled())
  34651. {
  34652. isMouseOverButton = false;
  34653. isButtonDown = false;
  34654. }
  34655. g.setColour ((isButtonDown) ? downColour
  34656. : (isMouseOverButton) ? overColour
  34657. : normalColour);
  34658. int w = getWidth();
  34659. int h = getHeight();
  34660. if (getComponentEffect() != 0)
  34661. {
  34662. w -= 4;
  34663. h -= 4;
  34664. }
  34665. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34666. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34667. w - offset - outlineWidth,
  34668. h - offset - outlineWidth,
  34669. maintainShapeProportions));
  34670. g.fillPath (shape, trans);
  34671. if (outlineWidth > 0.0f)
  34672. {
  34673. g.setColour (outlineColour);
  34674. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34675. }
  34676. }
  34677. END_JUCE_NAMESPACE
  34678. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34679. /*** Start of inlined file: juce_TextButton.cpp ***/
  34680. BEGIN_JUCE_NAMESPACE
  34681. TextButton::TextButton (const String& name,
  34682. const String& toolTip)
  34683. : Button (name)
  34684. {
  34685. setTooltip (toolTip);
  34686. }
  34687. TextButton::~TextButton()
  34688. {
  34689. }
  34690. void TextButton::paintButton (Graphics& g,
  34691. bool isMouseOverButton,
  34692. bool isButtonDown)
  34693. {
  34694. getLookAndFeel().drawButtonBackground (g, *this,
  34695. findColour (getToggleState() ? buttonOnColourId
  34696. : buttonColourId),
  34697. isMouseOverButton,
  34698. isButtonDown);
  34699. getLookAndFeel().drawButtonText (g, *this,
  34700. isMouseOverButton,
  34701. isButtonDown);
  34702. }
  34703. void TextButton::colourChanged()
  34704. {
  34705. repaint();
  34706. }
  34707. const Font TextButton::getFont()
  34708. {
  34709. return Font (jmin (15.0f, getHeight() * 0.6f));
  34710. }
  34711. void TextButton::changeWidthToFitText (const int newHeight)
  34712. {
  34713. if (newHeight >= 0)
  34714. setSize (jmax (1, getWidth()), newHeight);
  34715. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34716. getHeight());
  34717. }
  34718. END_JUCE_NAMESPACE
  34719. /*** End of inlined file: juce_TextButton.cpp ***/
  34720. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34721. BEGIN_JUCE_NAMESPACE
  34722. ToggleButton::ToggleButton (const String& buttonText)
  34723. : Button (buttonText)
  34724. {
  34725. setClickingTogglesState (true);
  34726. }
  34727. ToggleButton::~ToggleButton()
  34728. {
  34729. }
  34730. void ToggleButton::paintButton (Graphics& g,
  34731. bool isMouseOverButton,
  34732. bool isButtonDown)
  34733. {
  34734. getLookAndFeel().drawToggleButton (g, *this,
  34735. isMouseOverButton,
  34736. isButtonDown);
  34737. }
  34738. void ToggleButton::changeWidthToFitText()
  34739. {
  34740. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34741. }
  34742. void ToggleButton::colourChanged()
  34743. {
  34744. repaint();
  34745. }
  34746. END_JUCE_NAMESPACE
  34747. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34748. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34749. BEGIN_JUCE_NAMESPACE
  34750. ToolbarButton::ToolbarButton (const int itemId_,
  34751. const String& buttonText,
  34752. Drawable* const normalImage_,
  34753. Drawable* const toggledOnImage_)
  34754. : ToolbarItemComponent (itemId_, buttonText, true),
  34755. normalImage (normalImage_),
  34756. toggledOnImage (toggledOnImage_)
  34757. {
  34758. }
  34759. ToolbarButton::~ToolbarButton()
  34760. {
  34761. }
  34762. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34763. bool /*isToolbarVertical*/,
  34764. int& preferredSize,
  34765. int& minSize, int& maxSize)
  34766. {
  34767. preferredSize = minSize = maxSize = toolbarDepth;
  34768. return true;
  34769. }
  34770. void ToolbarButton::paintButtonArea (Graphics& g,
  34771. int width, int height,
  34772. bool /*isMouseOver*/,
  34773. bool /*isMouseDown*/)
  34774. {
  34775. Drawable* d = normalImage;
  34776. if (getToggleState() && toggledOnImage != 0)
  34777. d = toggledOnImage;
  34778. if (! isEnabled())
  34779. {
  34780. Image im (Image::ARGB, width, height, true);
  34781. Graphics g2 (im);
  34782. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34783. im.desaturate();
  34784. g.drawImageAt (&im, 0, 0);
  34785. }
  34786. else
  34787. {
  34788. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34789. }
  34790. }
  34791. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34792. {
  34793. }
  34794. END_JUCE_NAMESPACE
  34795. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34796. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34797. BEGIN_JUCE_NAMESPACE
  34798. class CodeDocumentLine
  34799. {
  34800. public:
  34801. CodeDocumentLine (const juce_wchar* const line_,
  34802. const int lineLength_,
  34803. const int numNewLineChars,
  34804. const int lineStartInFile_)
  34805. : line (line_, lineLength_),
  34806. lineStartInFile (lineStartInFile_),
  34807. lineLength (lineLength_),
  34808. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34809. {
  34810. }
  34811. ~CodeDocumentLine()
  34812. {
  34813. }
  34814. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34815. {
  34816. const juce_wchar* const t = text;
  34817. int pos = 0;
  34818. while (t [pos] != 0)
  34819. {
  34820. const int startOfLine = pos;
  34821. int numNewLineChars = 0;
  34822. while (t[pos] != 0)
  34823. {
  34824. if (t[pos] == '\r')
  34825. {
  34826. ++numNewLineChars;
  34827. ++pos;
  34828. if (t[pos] == '\n')
  34829. {
  34830. ++numNewLineChars;
  34831. ++pos;
  34832. }
  34833. break;
  34834. }
  34835. if (t[pos] == '\n')
  34836. {
  34837. ++numNewLineChars;
  34838. ++pos;
  34839. break;
  34840. }
  34841. ++pos;
  34842. }
  34843. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34844. numNewLineChars, startOfLine));
  34845. }
  34846. jassert (pos == text.length());
  34847. }
  34848. bool endsWithLineBreak() const throw()
  34849. {
  34850. return lineLengthWithoutNewLines != lineLength;
  34851. }
  34852. void updateLength() throw()
  34853. {
  34854. lineLengthWithoutNewLines = lineLength = line.length();
  34855. while (lineLengthWithoutNewLines > 0
  34856. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34857. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34858. {
  34859. --lineLengthWithoutNewLines;
  34860. }
  34861. }
  34862. String line;
  34863. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34864. };
  34865. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34866. : document (document_),
  34867. currentLine (document_->lines[0]),
  34868. line (0),
  34869. position (0)
  34870. {
  34871. }
  34872. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34873. : document (other.document),
  34874. currentLine (other.currentLine),
  34875. line (other.line),
  34876. position (other.position)
  34877. {
  34878. }
  34879. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34880. {
  34881. document = other.document;
  34882. currentLine = other.currentLine;
  34883. line = other.line;
  34884. position = other.position;
  34885. return *this;
  34886. }
  34887. CodeDocument::Iterator::~Iterator() throw()
  34888. {
  34889. }
  34890. juce_wchar CodeDocument::Iterator::nextChar()
  34891. {
  34892. if (currentLine == 0)
  34893. return 0;
  34894. jassert (currentLine == document->lines.getUnchecked (line));
  34895. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34896. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34897. {
  34898. ++line;
  34899. currentLine = document->lines [line];
  34900. }
  34901. return result;
  34902. }
  34903. void CodeDocument::Iterator::skip()
  34904. {
  34905. if (currentLine != 0)
  34906. {
  34907. jassert (currentLine == document->lines.getUnchecked (line));
  34908. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34909. {
  34910. ++line;
  34911. currentLine = document->lines [line];
  34912. }
  34913. }
  34914. }
  34915. void CodeDocument::Iterator::skipToEndOfLine()
  34916. {
  34917. if (currentLine != 0)
  34918. {
  34919. jassert (currentLine == document->lines.getUnchecked (line));
  34920. ++line;
  34921. currentLine = document->lines [line];
  34922. if (currentLine != 0)
  34923. position = currentLine->lineStartInFile;
  34924. else
  34925. position = document->getNumCharacters();
  34926. }
  34927. }
  34928. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34929. {
  34930. if (currentLine == 0)
  34931. return 0;
  34932. jassert (currentLine == document->lines.getUnchecked (line));
  34933. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34934. }
  34935. void CodeDocument::Iterator::skipWhitespace()
  34936. {
  34937. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34938. skip();
  34939. }
  34940. bool CodeDocument::Iterator::isEOF() const throw()
  34941. {
  34942. return currentLine == 0;
  34943. }
  34944. CodeDocument::Position::Position() throw()
  34945. : owner (0), characterPos (0), line (0),
  34946. indexInLine (0), positionMaintained (false)
  34947. {
  34948. }
  34949. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34950. const int line_, const int indexInLine_) throw()
  34951. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34952. characterPos (0), line (line_),
  34953. indexInLine (indexInLine_), positionMaintained (false)
  34954. {
  34955. setLineAndIndex (line_, indexInLine_);
  34956. }
  34957. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34958. const int characterPos_) throw()
  34959. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34960. positionMaintained (false)
  34961. {
  34962. setPosition (characterPos_);
  34963. }
  34964. CodeDocument::Position::Position (const Position& other) throw()
  34965. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34966. indexInLine (other.indexInLine), positionMaintained (false)
  34967. {
  34968. jassert (*this == other);
  34969. }
  34970. CodeDocument::Position::~Position() throw()
  34971. {
  34972. setPositionMaintained (false);
  34973. }
  34974. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34975. {
  34976. if (this != &other)
  34977. {
  34978. const bool wasPositionMaintained = positionMaintained;
  34979. if (owner != other.owner)
  34980. setPositionMaintained (false);
  34981. owner = other.owner;
  34982. line = other.line;
  34983. indexInLine = other.indexInLine;
  34984. characterPos = other.characterPos;
  34985. setPositionMaintained (wasPositionMaintained);
  34986. jassert (*this == other);
  34987. }
  34988. return *this;
  34989. }
  34990. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34991. {
  34992. jassert ((characterPos == other.characterPos)
  34993. == (line == other.line && indexInLine == other.indexInLine));
  34994. return characterPos == other.characterPos
  34995. && line == other.line
  34996. && indexInLine == other.indexInLine
  34997. && owner == other.owner;
  34998. }
  34999. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35000. {
  35001. return ! operator== (other);
  35002. }
  35003. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35004. {
  35005. jassert (owner != 0);
  35006. if (owner->lines.size() == 0)
  35007. {
  35008. line = 0;
  35009. indexInLine = 0;
  35010. characterPos = 0;
  35011. }
  35012. else
  35013. {
  35014. if (newLine >= owner->lines.size())
  35015. {
  35016. line = owner->lines.size() - 1;
  35017. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35018. jassert (l != 0);
  35019. indexInLine = l->lineLengthWithoutNewLines;
  35020. characterPos = l->lineStartInFile + indexInLine;
  35021. }
  35022. else
  35023. {
  35024. line = jmax (0, newLine);
  35025. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35026. jassert (l != 0);
  35027. if (l->lineLengthWithoutNewLines > 0)
  35028. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35029. else
  35030. indexInLine = 0;
  35031. characterPos = l->lineStartInFile + indexInLine;
  35032. }
  35033. }
  35034. }
  35035. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35036. {
  35037. jassert (owner != 0);
  35038. line = 0;
  35039. indexInLine = 0;
  35040. characterPos = 0;
  35041. if (newPosition > 0)
  35042. {
  35043. int lineStart = 0;
  35044. int lineEnd = owner->lines.size();
  35045. for (;;)
  35046. {
  35047. if (lineEnd - lineStart < 4)
  35048. {
  35049. for (int i = lineStart; i < lineEnd; ++i)
  35050. {
  35051. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35052. int index = newPosition - l->lineStartInFile;
  35053. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35054. {
  35055. line = i;
  35056. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35057. characterPos = l->lineStartInFile + indexInLine;
  35058. }
  35059. }
  35060. break;
  35061. }
  35062. else
  35063. {
  35064. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35065. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35066. if (newPosition >= mid->lineStartInFile)
  35067. lineStart = midIndex;
  35068. else
  35069. lineEnd = midIndex;
  35070. }
  35071. }
  35072. }
  35073. }
  35074. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35075. {
  35076. jassert (owner != 0);
  35077. if (characterDelta == 1)
  35078. {
  35079. setPosition (getPosition());
  35080. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35081. if (line < owner->lines.size())
  35082. {
  35083. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35084. if (indexInLine + characterDelta < l->lineLength
  35085. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35086. ++characterDelta;
  35087. }
  35088. }
  35089. setPosition (characterPos + characterDelta);
  35090. }
  35091. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35092. {
  35093. CodeDocument::Position p (*this);
  35094. p.moveBy (characterDelta);
  35095. return p;
  35096. }
  35097. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35098. {
  35099. CodeDocument::Position p (*this);
  35100. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35101. return p;
  35102. }
  35103. const juce_wchar CodeDocument::Position::getCharacter() const throw()
  35104. {
  35105. const CodeDocumentLine* const l = owner->lines [line];
  35106. return l == 0 ? 0 : l->line [getIndexInLine()];
  35107. }
  35108. const String CodeDocument::Position::getLineText() const throw()
  35109. {
  35110. const CodeDocumentLine* const l = owner->lines [line];
  35111. return l == 0 ? String::empty : l->line;
  35112. }
  35113. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35114. {
  35115. if (isMaintained != positionMaintained)
  35116. {
  35117. positionMaintained = isMaintained;
  35118. if (owner != 0)
  35119. {
  35120. if (isMaintained)
  35121. {
  35122. jassert (! owner->positionsToMaintain.contains (this));
  35123. owner->positionsToMaintain.add (this);
  35124. }
  35125. else
  35126. {
  35127. jassert (owner->positionsToMaintain.contains (this));
  35128. owner->positionsToMaintain.removeValue (this);
  35129. }
  35130. }
  35131. }
  35132. }
  35133. CodeDocument::CodeDocument()
  35134. : undoManager (std::numeric_limits<int>::max(), 10000),
  35135. currentActionIndex (0),
  35136. indexOfSavedState (-1),
  35137. maximumLineLength (-1),
  35138. newLineChars ("\r\n")
  35139. {
  35140. }
  35141. CodeDocument::~CodeDocument()
  35142. {
  35143. }
  35144. const String CodeDocument::getAllContent() const throw()
  35145. {
  35146. return getTextBetween (Position (this, 0),
  35147. Position (this, lines.size(), 0));
  35148. }
  35149. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35150. {
  35151. if (end.getPosition() <= start.getPosition())
  35152. return String::empty;
  35153. const int startLine = start.getLineNumber();
  35154. const int endLine = end.getLineNumber();
  35155. if (startLine == endLine)
  35156. {
  35157. CodeDocumentLine* const line = lines [startLine];
  35158. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35159. }
  35160. String result;
  35161. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35162. String::Concatenator concatenator (result);
  35163. const int maxLine = jmin (lines.size() - 1, endLine);
  35164. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35165. {
  35166. const CodeDocumentLine* line = lines.getUnchecked(i);
  35167. int len = line->lineLength;
  35168. if (i == startLine)
  35169. {
  35170. const int index = start.getIndexInLine();
  35171. concatenator.append (line->line.substring (index, len));
  35172. }
  35173. else if (i == endLine)
  35174. {
  35175. len = end.getIndexInLine();
  35176. concatenator.append (line->line.substring (0, len));
  35177. }
  35178. else
  35179. {
  35180. concatenator.append (line->line);
  35181. }
  35182. }
  35183. return result;
  35184. }
  35185. int CodeDocument::getNumCharacters() const throw()
  35186. {
  35187. const CodeDocumentLine* const lastLine = lines.getLast();
  35188. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35189. }
  35190. const String CodeDocument::getLine (const int lineIndex) const throw()
  35191. {
  35192. const CodeDocumentLine* const line = lines [lineIndex];
  35193. return (line == 0) ? String::empty : line->line;
  35194. }
  35195. int CodeDocument::getMaximumLineLength() throw()
  35196. {
  35197. if (maximumLineLength < 0)
  35198. {
  35199. maximumLineLength = 0;
  35200. for (int i = lines.size(); --i >= 0;)
  35201. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35202. }
  35203. return maximumLineLength;
  35204. }
  35205. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35206. {
  35207. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35208. }
  35209. void CodeDocument::insertText (const Position& position, const String& text)
  35210. {
  35211. insert (text, position.getPosition(), true);
  35212. }
  35213. void CodeDocument::replaceAllContent (const String& newContent)
  35214. {
  35215. remove (0, getNumCharacters(), true);
  35216. insert (newContent, 0, true);
  35217. }
  35218. bool CodeDocument::loadFromStream (InputStream& stream)
  35219. {
  35220. replaceAllContent (stream.readEntireStreamAsString());
  35221. setSavePoint();
  35222. clearUndoHistory();
  35223. return true;
  35224. }
  35225. bool CodeDocument::writeToStream (OutputStream& stream)
  35226. {
  35227. for (int i = 0; i < lines.size(); ++i)
  35228. {
  35229. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35230. const char* utf8 = temp.toUTF8();
  35231. if (! stream.write (utf8, (int) strlen (utf8)))
  35232. return false;
  35233. }
  35234. return true;
  35235. }
  35236. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35237. {
  35238. jassert (newLine == "\r\n" || newLine == "\n" || newLine == "\r");
  35239. newLineChars = newLine;
  35240. }
  35241. void CodeDocument::newTransaction()
  35242. {
  35243. undoManager.beginNewTransaction (String::empty);
  35244. }
  35245. void CodeDocument::undo()
  35246. {
  35247. newTransaction();
  35248. undoManager.undo();
  35249. }
  35250. void CodeDocument::redo()
  35251. {
  35252. undoManager.redo();
  35253. }
  35254. void CodeDocument::clearUndoHistory()
  35255. {
  35256. undoManager.clearUndoHistory();
  35257. }
  35258. void CodeDocument::setSavePoint() throw()
  35259. {
  35260. indexOfSavedState = currentActionIndex;
  35261. }
  35262. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35263. {
  35264. return currentActionIndex != indexOfSavedState;
  35265. }
  35266. static int getCodeCharacterCategory (const juce_wchar character) throw()
  35267. {
  35268. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35269. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35270. }
  35271. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35272. {
  35273. Position p (position);
  35274. const int maxDistance = 256;
  35275. int i = 0;
  35276. while (i < maxDistance
  35277. && CharacterFunctions::isWhitespace (p.getCharacter())
  35278. && (i == 0 || (p.getCharacter() != '\n'
  35279. && p.getCharacter() != '\r')))
  35280. {
  35281. ++i;
  35282. p.moveBy (1);
  35283. }
  35284. if (i == 0)
  35285. {
  35286. const int type = getCodeCharacterCategory (p.getCharacter());
  35287. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35288. {
  35289. ++i;
  35290. p.moveBy (1);
  35291. }
  35292. while (i < maxDistance
  35293. && CharacterFunctions::isWhitespace (p.getCharacter())
  35294. && (i == 0 || (p.getCharacter() != '\n'
  35295. && p.getCharacter() != '\r')))
  35296. {
  35297. ++i;
  35298. p.moveBy (1);
  35299. }
  35300. }
  35301. return p;
  35302. }
  35303. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35304. {
  35305. Position p (position);
  35306. const int maxDistance = 256;
  35307. int i = 0;
  35308. bool stoppedAtLineStart = false;
  35309. while (i < maxDistance)
  35310. {
  35311. const juce_wchar c = p.movedBy (-1).getCharacter();
  35312. if (c == '\r' || c == '\n')
  35313. {
  35314. stoppedAtLineStart = true;
  35315. if (i > 0)
  35316. break;
  35317. }
  35318. if (! CharacterFunctions::isWhitespace (c))
  35319. break;
  35320. p.moveBy (-1);
  35321. ++i;
  35322. }
  35323. if (i < maxDistance && ! stoppedAtLineStart)
  35324. {
  35325. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35326. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35327. {
  35328. p.moveBy (-1);
  35329. ++i;
  35330. }
  35331. }
  35332. return p;
  35333. }
  35334. void CodeDocument::checkLastLineStatus()
  35335. {
  35336. while (lines.size() > 0
  35337. && lines.getLast()->lineLength == 0
  35338. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35339. {
  35340. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35341. lines.removeLast();
  35342. }
  35343. const CodeDocumentLine* const lastLine = lines.getLast();
  35344. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35345. {
  35346. // check that there's an empty line at the end if the preceding one ends in a newline..
  35347. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35348. }
  35349. }
  35350. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35351. {
  35352. listeners.add (listener);
  35353. }
  35354. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35355. {
  35356. listeners.remove (listener);
  35357. }
  35358. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35359. {
  35360. Position startPos (this, startLine, 0);
  35361. Position endPos (this, endLine, 0);
  35362. listeners.call (&Listener::codeDocumentChanged, startPos, endPos);
  35363. }
  35364. class CodeDocumentInsertAction : public UndoableAction
  35365. {
  35366. CodeDocument& owner;
  35367. const String text;
  35368. int insertPos;
  35369. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35370. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35371. public:
  35372. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35373. : owner (owner_),
  35374. text (text_),
  35375. insertPos (insertPos_)
  35376. {
  35377. }
  35378. ~CodeDocumentInsertAction() {}
  35379. bool perform()
  35380. {
  35381. owner.currentActionIndex++;
  35382. owner.insert (text, insertPos, false);
  35383. return true;
  35384. }
  35385. bool undo()
  35386. {
  35387. owner.currentActionIndex--;
  35388. owner.remove (insertPos, insertPos + text.length(), false);
  35389. return true;
  35390. }
  35391. int getSizeInUnits() { return text.length() + 32; }
  35392. };
  35393. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35394. {
  35395. if (text.isEmpty())
  35396. return;
  35397. if (undoable)
  35398. {
  35399. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35400. }
  35401. else
  35402. {
  35403. Position pos (this, insertPos);
  35404. const int firstAffectedLine = pos.getLineNumber();
  35405. int lastAffectedLine = firstAffectedLine + 1;
  35406. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35407. String textInsideOriginalLine (text);
  35408. if (firstLine != 0)
  35409. {
  35410. const int index = pos.getIndexInLine();
  35411. textInsideOriginalLine = firstLine->line.substring (0, index)
  35412. + textInsideOriginalLine
  35413. + firstLine->line.substring (index);
  35414. }
  35415. maximumLineLength = -1;
  35416. Array <CodeDocumentLine*> newLines;
  35417. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35418. jassert (newLines.size() > 0);
  35419. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35420. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35421. lines.set (firstAffectedLine, newFirstLine);
  35422. if (newLines.size() > 1)
  35423. {
  35424. for (int i = 1; i < newLines.size(); ++i)
  35425. {
  35426. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35427. lines.insert (firstAffectedLine + i, l);
  35428. }
  35429. lastAffectedLine = lines.size();
  35430. }
  35431. int i, lineStart = newFirstLine->lineStartInFile;
  35432. for (i = firstAffectedLine; i < lines.size(); ++i)
  35433. {
  35434. CodeDocumentLine* const l = lines.getUnchecked (i);
  35435. l->lineStartInFile = lineStart;
  35436. lineStart += l->lineLength;
  35437. }
  35438. checkLastLineStatus();
  35439. const int newTextLength = text.length();
  35440. for (i = 0; i < positionsToMaintain.size(); ++i)
  35441. {
  35442. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35443. if (p->getPosition() >= insertPos)
  35444. p->setPosition (p->getPosition() + newTextLength);
  35445. }
  35446. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35447. }
  35448. }
  35449. class CodeDocumentDeleteAction : public UndoableAction
  35450. {
  35451. CodeDocument& owner;
  35452. int startPos, endPos;
  35453. String removedText;
  35454. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35455. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35456. public:
  35457. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35458. : owner (owner_),
  35459. startPos (startPos_),
  35460. endPos (endPos_)
  35461. {
  35462. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35463. CodeDocument::Position (&owner, endPos));
  35464. }
  35465. ~CodeDocumentDeleteAction() {}
  35466. bool perform()
  35467. {
  35468. owner.currentActionIndex++;
  35469. owner.remove (startPos, endPos, false);
  35470. return true;
  35471. }
  35472. bool undo()
  35473. {
  35474. owner.currentActionIndex--;
  35475. owner.insert (removedText, startPos, false);
  35476. return true;
  35477. }
  35478. int getSizeInUnits() { return removedText.length() + 32; }
  35479. };
  35480. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35481. {
  35482. if (endPos <= startPos)
  35483. return;
  35484. if (undoable)
  35485. {
  35486. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35487. }
  35488. else
  35489. {
  35490. Position startPosition (this, startPos);
  35491. Position endPosition (this, endPos);
  35492. maximumLineLength = -1;
  35493. const int firstAffectedLine = startPosition.getLineNumber();
  35494. const int endLine = endPosition.getLineNumber();
  35495. int lastAffectedLine = firstAffectedLine + 1;
  35496. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35497. if (firstAffectedLine == endLine)
  35498. {
  35499. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35500. + firstLine->line.substring (endPosition.getIndexInLine());
  35501. firstLine->updateLength();
  35502. }
  35503. else
  35504. {
  35505. lastAffectedLine = lines.size();
  35506. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35507. jassert (lastLine != 0);
  35508. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35509. + lastLine->line.substring (endPosition.getIndexInLine());
  35510. firstLine->updateLength();
  35511. int numLinesToRemove = endLine - firstAffectedLine;
  35512. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35513. }
  35514. int i;
  35515. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35516. {
  35517. CodeDocumentLine* const l = lines.getUnchecked (i);
  35518. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35519. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35520. }
  35521. checkLastLineStatus();
  35522. const int totalChars = getNumCharacters();
  35523. for (i = 0; i < positionsToMaintain.size(); ++i)
  35524. {
  35525. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35526. if (p->getPosition() > startPosition.getPosition())
  35527. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35528. if (p->getPosition() > totalChars)
  35529. p->setPosition (totalChars);
  35530. }
  35531. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35532. }
  35533. }
  35534. END_JUCE_NAMESPACE
  35535. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35536. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35537. BEGIN_JUCE_NAMESPACE
  35538. class CodeEditorComponent::CaretComponent : public Component,
  35539. public Timer
  35540. {
  35541. public:
  35542. CaretComponent()
  35543. {
  35544. setAlwaysOnTop (true);
  35545. setInterceptsMouseClicks (false, false);
  35546. }
  35547. ~CaretComponent()
  35548. {
  35549. }
  35550. void paint (Graphics& g)
  35551. {
  35552. if (getParentComponent()->hasKeyboardFocus (true))
  35553. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35554. }
  35555. void timerCallback()
  35556. {
  35557. setVisible (! isVisible());
  35558. }
  35559. void updatePosition (CodeEditorComponent& owner)
  35560. {
  35561. startTimer (400);
  35562. setVisible (true);
  35563. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35564. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35565. }
  35566. private:
  35567. CaretComponent (const CaretComponent&);
  35568. CaretComponent& operator= (const CaretComponent&);
  35569. };
  35570. class CodeEditorComponent::CodeEditorLine
  35571. {
  35572. public:
  35573. CodeEditorLine() throw()
  35574. : highlightColumnStart (0), highlightColumnEnd (0)
  35575. {
  35576. }
  35577. ~CodeEditorLine() throw()
  35578. {
  35579. }
  35580. bool update (CodeDocument& document, int lineNum,
  35581. CodeDocument::Iterator& source,
  35582. CodeTokeniser* analyser, const int spacesPerTab,
  35583. const CodeDocument::Position& selectionStart,
  35584. const CodeDocument::Position& selectionEnd)
  35585. {
  35586. Array <SyntaxToken> newTokens;
  35587. newTokens.ensureStorageAllocated (8);
  35588. if (analyser == 0)
  35589. {
  35590. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35591. }
  35592. else if (lineNum < document.getNumLines())
  35593. {
  35594. const CodeDocument::Position pos (&document, lineNum, 0);
  35595. createTokens (pos.getPosition(), pos.getLineText(),
  35596. source, analyser, newTokens);
  35597. }
  35598. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35599. int newHighlightStart = 0;
  35600. int newHighlightEnd = 0;
  35601. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35602. {
  35603. const String line (document.getLine (lineNum));
  35604. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35605. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35606. line, spacesPerTab);
  35607. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35608. line, spacesPerTab);
  35609. }
  35610. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35611. {
  35612. highlightColumnStart = newHighlightStart;
  35613. highlightColumnEnd = newHighlightEnd;
  35614. }
  35615. else
  35616. {
  35617. if (tokens.size() == newTokens.size())
  35618. {
  35619. bool allTheSame = true;
  35620. for (int i = newTokens.size(); --i >= 0;)
  35621. {
  35622. if (tokens.getReference(i) != newTokens.getReference(i))
  35623. {
  35624. allTheSame = false;
  35625. break;
  35626. }
  35627. }
  35628. if (allTheSame)
  35629. return false;
  35630. }
  35631. }
  35632. tokens.swapWithArray (newTokens);
  35633. return true;
  35634. }
  35635. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35636. float x, const int y, const int baselineOffset, const int lineHeight,
  35637. const Colour& highlightColour) const throw()
  35638. {
  35639. if (highlightColumnStart < highlightColumnEnd)
  35640. {
  35641. g.setColour (highlightColour);
  35642. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35643. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35644. }
  35645. int lastType = std::numeric_limits<int>::min();
  35646. for (int i = 0; i < tokens.size(); ++i)
  35647. {
  35648. SyntaxToken& token = tokens.getReference(i);
  35649. if (lastType != token.tokenType)
  35650. {
  35651. lastType = token.tokenType;
  35652. g.setColour (owner.getColourForTokenType (lastType));
  35653. }
  35654. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35655. if (i < tokens.size() - 1)
  35656. {
  35657. if (token.width < 0)
  35658. token.width = font.getStringWidthFloat (token.text);
  35659. x += token.width;
  35660. }
  35661. }
  35662. }
  35663. private:
  35664. struct SyntaxToken
  35665. {
  35666. String text;
  35667. int tokenType;
  35668. float width;
  35669. SyntaxToken (const String& text_, const int type) throw()
  35670. : text (text_), tokenType (type), width (-1.0f)
  35671. {
  35672. }
  35673. bool operator!= (const SyntaxToken& other) const throw()
  35674. {
  35675. return text != other.text || tokenType != other.tokenType;
  35676. }
  35677. };
  35678. Array <SyntaxToken> tokens;
  35679. int highlightColumnStart, highlightColumnEnd;
  35680. static void createTokens (int startPosition, const String& lineText,
  35681. CodeDocument::Iterator& source,
  35682. CodeTokeniser* analyser,
  35683. Array <SyntaxToken>& newTokens)
  35684. {
  35685. CodeDocument::Iterator lastIterator (source);
  35686. const int lineLength = lineText.length();
  35687. for (;;)
  35688. {
  35689. int tokenType = analyser->readNextToken (source);
  35690. int tokenStart = lastIterator.getPosition();
  35691. int tokenEnd = source.getPosition();
  35692. if (tokenEnd <= tokenStart)
  35693. break;
  35694. tokenEnd -= startPosition;
  35695. if (tokenEnd > 0)
  35696. {
  35697. tokenStart -= startPosition;
  35698. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35699. tokenType));
  35700. if (tokenEnd >= lineLength)
  35701. break;
  35702. }
  35703. lastIterator = source;
  35704. }
  35705. source = lastIterator;
  35706. }
  35707. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35708. {
  35709. int x = 0;
  35710. for (int i = 0; i < tokens.size(); ++i)
  35711. {
  35712. SyntaxToken& t = tokens.getReference(i);
  35713. for (;;)
  35714. {
  35715. int tabPos = t.text.indexOfChar ('\t');
  35716. if (tabPos < 0)
  35717. break;
  35718. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35719. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (" ", spacesNeeded));
  35720. }
  35721. x += t.text.length();
  35722. }
  35723. }
  35724. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35725. {
  35726. jassert (index <= line.length());
  35727. int col = 0;
  35728. for (int i = 0; i < index; ++i)
  35729. {
  35730. if (line[i] != '\t')
  35731. ++col;
  35732. else
  35733. col += spacesPerTab - (col % spacesPerTab);
  35734. }
  35735. return col;
  35736. }
  35737. };
  35738. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35739. CodeTokeniser* const codeTokeniser_)
  35740. : document (document_),
  35741. firstLineOnScreen (0),
  35742. gutter (5),
  35743. spacesPerTab (4),
  35744. lineHeight (0),
  35745. linesOnScreen (0),
  35746. columnsOnScreen (0),
  35747. scrollbarThickness (16),
  35748. columnToTryToMaintain (-1),
  35749. useSpacesForTabs (false),
  35750. xOffset (0),
  35751. codeTokeniser (codeTokeniser_)
  35752. {
  35753. caretPos = CodeDocument::Position (&document_, 0, 0);
  35754. caretPos.setPositionMaintained (true);
  35755. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35756. selectionStart.setPositionMaintained (true);
  35757. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35758. selectionEnd.setPositionMaintained (true);
  35759. setOpaque (true);
  35760. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35761. setWantsKeyboardFocus (true);
  35762. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35763. verticalScrollBar->setSingleStepSize (1.0);
  35764. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35765. horizontalScrollBar->setSingleStepSize (1.0);
  35766. addAndMakeVisible (caret = new CaretComponent());
  35767. Font f (12.0f);
  35768. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35769. setFont (f);
  35770. resetToDefaultColours();
  35771. verticalScrollBar->addListener (this);
  35772. horizontalScrollBar->addListener (this);
  35773. document.addListener (this);
  35774. }
  35775. CodeEditorComponent::~CodeEditorComponent()
  35776. {
  35777. document.removeListener (this);
  35778. deleteAllChildren();
  35779. }
  35780. void CodeEditorComponent::loadContent (const String& newContent)
  35781. {
  35782. clearCachedIterators (0);
  35783. document.replaceAllContent (newContent);
  35784. document.clearUndoHistory();
  35785. document.setSavePoint();
  35786. caretPos.setPosition (0);
  35787. selectionStart.setPosition (0);
  35788. selectionEnd.setPosition (0);
  35789. scrollToLine (0);
  35790. }
  35791. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35792. const CodeDocument::Position& affectedTextEnd)
  35793. {
  35794. clearCachedIterators (affectedTextStart.getLineNumber());
  35795. triggerAsyncUpdate();
  35796. caret->updatePosition (*this);
  35797. columnToTryToMaintain = -1;
  35798. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35799. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35800. deselectAll();
  35801. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35802. || caretPos.getPosition() < affectedTextStart.getPosition())
  35803. moveCaretTo (affectedTextStart, false);
  35804. updateScrollBars();
  35805. }
  35806. void CodeEditorComponent::resized()
  35807. {
  35808. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35809. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35810. lines.clear();
  35811. rebuildLineTokens();
  35812. caret->updatePosition (*this);
  35813. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35814. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35815. updateScrollBars();
  35816. }
  35817. void CodeEditorComponent::paint (Graphics& g)
  35818. {
  35819. handleUpdateNowIfNeeded();
  35820. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35821. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35822. g.setFont (font);
  35823. const int baselineOffset = (int) font.getAscent();
  35824. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35825. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35826. const Rectangle<int> clip (g.getClipBounds());
  35827. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35828. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35829. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35830. {
  35831. lines.getUnchecked(j)->draw (*this, g, font,
  35832. (float) (gutter - xOffset * charWidth),
  35833. lineHeight * j, baselineOffset, lineHeight,
  35834. highlightColour);
  35835. }
  35836. }
  35837. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35838. {
  35839. if (scrollbarThickness != thickness)
  35840. {
  35841. scrollbarThickness = thickness;
  35842. resized();
  35843. }
  35844. }
  35845. void CodeEditorComponent::handleAsyncUpdate()
  35846. {
  35847. rebuildLineTokens();
  35848. }
  35849. void CodeEditorComponent::rebuildLineTokens()
  35850. {
  35851. cancelPendingUpdate();
  35852. const int numNeeded = linesOnScreen + 1;
  35853. int minLineToRepaint = numNeeded;
  35854. int maxLineToRepaint = 0;
  35855. if (numNeeded != lines.size())
  35856. {
  35857. lines.clear();
  35858. for (int i = numNeeded; --i >= 0;)
  35859. lines.add (new CodeEditorLine());
  35860. minLineToRepaint = 0;
  35861. maxLineToRepaint = numNeeded;
  35862. }
  35863. jassert (numNeeded == lines.size());
  35864. CodeDocument::Iterator source (&document);
  35865. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35866. for (int i = 0; i < numNeeded; ++i)
  35867. {
  35868. CodeEditorLine* const line = lines.getUnchecked(i);
  35869. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35870. selectionStart, selectionEnd))
  35871. {
  35872. minLineToRepaint = jmin (minLineToRepaint, i);
  35873. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35874. }
  35875. }
  35876. if (minLineToRepaint <= maxLineToRepaint)
  35877. {
  35878. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35879. verticalScrollBar->getX() - gutter,
  35880. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35881. }
  35882. }
  35883. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35884. {
  35885. caretPos = newPos;
  35886. columnToTryToMaintain = -1;
  35887. if (highlighting)
  35888. {
  35889. if (dragType == notDragging)
  35890. {
  35891. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35892. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35893. dragType = draggingSelectionStart;
  35894. else
  35895. dragType = draggingSelectionEnd;
  35896. }
  35897. if (dragType == draggingSelectionStart)
  35898. {
  35899. selectionStart = caretPos;
  35900. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35901. {
  35902. const CodeDocument::Position temp (selectionStart);
  35903. selectionStart = selectionEnd;
  35904. selectionEnd = temp;
  35905. dragType = draggingSelectionEnd;
  35906. }
  35907. }
  35908. else
  35909. {
  35910. selectionEnd = caretPos;
  35911. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35912. {
  35913. const CodeDocument::Position temp (selectionStart);
  35914. selectionStart = selectionEnd;
  35915. selectionEnd = temp;
  35916. dragType = draggingSelectionStart;
  35917. }
  35918. }
  35919. triggerAsyncUpdate();
  35920. }
  35921. else
  35922. {
  35923. deselectAll();
  35924. }
  35925. caret->updatePosition (*this);
  35926. scrollToKeepCaretOnScreen();
  35927. updateScrollBars();
  35928. }
  35929. void CodeEditorComponent::deselectAll()
  35930. {
  35931. if (selectionStart != selectionEnd)
  35932. triggerAsyncUpdate();
  35933. selectionStart = caretPos;
  35934. selectionEnd = caretPos;
  35935. }
  35936. void CodeEditorComponent::updateScrollBars()
  35937. {
  35938. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35939. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35940. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35941. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35942. }
  35943. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35944. {
  35945. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35946. newFirstLineOnScreen);
  35947. if (newFirstLineOnScreen != firstLineOnScreen)
  35948. {
  35949. firstLineOnScreen = newFirstLineOnScreen;
  35950. caret->updatePosition (*this);
  35951. updateCachedIterators (firstLineOnScreen);
  35952. triggerAsyncUpdate();
  35953. }
  35954. }
  35955. void CodeEditorComponent::scrollToColumnInternal (double column)
  35956. {
  35957. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35958. if (xOffset != newOffset)
  35959. {
  35960. xOffset = newOffset;
  35961. caret->updatePosition (*this);
  35962. repaint();
  35963. }
  35964. }
  35965. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35966. {
  35967. scrollToLineInternal (newFirstLineOnScreen);
  35968. updateScrollBars();
  35969. }
  35970. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35971. {
  35972. scrollToColumnInternal (newFirstColumnOnScreen);
  35973. updateScrollBars();
  35974. }
  35975. void CodeEditorComponent::scrollBy (int deltaLines)
  35976. {
  35977. scrollToLine (firstLineOnScreen + deltaLines);
  35978. }
  35979. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35980. {
  35981. if (caretPos.getLineNumber() < firstLineOnScreen)
  35982. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35983. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35984. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35985. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35986. if (column >= xOffset + columnsOnScreen - 1)
  35987. scrollToColumn (column + 1 - columnsOnScreen);
  35988. else if (column < xOffset)
  35989. scrollToColumn (column);
  35990. }
  35991. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35992. {
  35993. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35994. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35995. roundToInt (charWidth),
  35996. lineHeight);
  35997. }
  35998. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35999. {
  36000. const int line = y / lineHeight + firstLineOnScreen;
  36001. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36002. const int index = columnToIndex (line, column);
  36003. return CodeDocument::Position (&document, line, index);
  36004. }
  36005. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36006. {
  36007. document.deleteSection (selectionStart, selectionEnd);
  36008. if (newText.isNotEmpty())
  36009. document.insertText (caretPos, newText);
  36010. scrollToKeepCaretOnScreen();
  36011. }
  36012. void CodeEditorComponent::insertTabAtCaret()
  36013. {
  36014. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36015. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36016. {
  36017. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36018. }
  36019. if (useSpacesForTabs)
  36020. {
  36021. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36022. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36023. insertTextAtCaret (String::repeatedString (" ", spacesNeeded));
  36024. }
  36025. else
  36026. {
  36027. insertTextAtCaret ("\t");
  36028. }
  36029. }
  36030. void CodeEditorComponent::cut()
  36031. {
  36032. insertTextAtCaret (String::empty);
  36033. }
  36034. void CodeEditorComponent::copy()
  36035. {
  36036. newTransaction();
  36037. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36038. if (selection.isNotEmpty())
  36039. SystemClipboard::copyTextToClipboard (selection);
  36040. }
  36041. void CodeEditorComponent::copyThenCut()
  36042. {
  36043. copy();
  36044. cut();
  36045. newTransaction();
  36046. }
  36047. void CodeEditorComponent::paste()
  36048. {
  36049. newTransaction();
  36050. const String clip (SystemClipboard::getTextFromClipboard());
  36051. if (clip.isNotEmpty())
  36052. insertTextAtCaret (clip);
  36053. newTransaction();
  36054. }
  36055. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36056. {
  36057. newTransaction();
  36058. if (moveInWholeWordSteps)
  36059. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36060. else
  36061. moveCaretTo (caretPos.movedBy (-1), selecting);
  36062. }
  36063. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36064. {
  36065. newTransaction();
  36066. if (moveInWholeWordSteps)
  36067. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36068. else
  36069. moveCaretTo (caretPos.movedBy (1), selecting);
  36070. }
  36071. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36072. {
  36073. CodeDocument::Position pos (caretPos);
  36074. const int newLineNum = pos.getLineNumber() + delta;
  36075. if (columnToTryToMaintain < 0)
  36076. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36077. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36078. const int colToMaintain = columnToTryToMaintain;
  36079. moveCaretTo (pos, selecting);
  36080. columnToTryToMaintain = colToMaintain;
  36081. }
  36082. void CodeEditorComponent::cursorDown (const bool selecting)
  36083. {
  36084. newTransaction();
  36085. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36086. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36087. else
  36088. moveLineDelta (1, selecting);
  36089. }
  36090. void CodeEditorComponent::cursorUp (const bool selecting)
  36091. {
  36092. newTransaction();
  36093. if (caretPos.getLineNumber() == 0)
  36094. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36095. else
  36096. moveLineDelta (-1, selecting);
  36097. }
  36098. void CodeEditorComponent::pageDown (const bool selecting)
  36099. {
  36100. newTransaction();
  36101. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36102. moveLineDelta (linesOnScreen, selecting);
  36103. }
  36104. void CodeEditorComponent::pageUp (const bool selecting)
  36105. {
  36106. newTransaction();
  36107. scrollBy (-linesOnScreen);
  36108. moveLineDelta (-linesOnScreen, selecting);
  36109. }
  36110. void CodeEditorComponent::scrollUp()
  36111. {
  36112. newTransaction();
  36113. scrollBy (1);
  36114. if (caretPos.getLineNumber() < firstLineOnScreen)
  36115. moveLineDelta (1, false);
  36116. }
  36117. void CodeEditorComponent::scrollDown()
  36118. {
  36119. newTransaction();
  36120. scrollBy (-1);
  36121. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36122. moveLineDelta (-1, false);
  36123. }
  36124. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36125. {
  36126. newTransaction();
  36127. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36128. }
  36129. static int findFirstNonWhitespaceChar (const String& line) throw()
  36130. {
  36131. const int len = line.length();
  36132. for (int i = 0; i < len; ++i)
  36133. if (! CharacterFunctions::isWhitespace (line [i]))
  36134. return i;
  36135. return 0;
  36136. }
  36137. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36138. {
  36139. newTransaction();
  36140. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36141. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36142. index = 0;
  36143. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36144. }
  36145. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36146. {
  36147. newTransaction();
  36148. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36149. }
  36150. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36151. {
  36152. newTransaction();
  36153. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36154. }
  36155. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36156. {
  36157. if (moveInWholeWordSteps)
  36158. {
  36159. cut(); // in case something is already highlighted
  36160. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36161. }
  36162. else
  36163. {
  36164. if (selectionStart == selectionEnd)
  36165. selectionStart.moveBy (-1);
  36166. }
  36167. cut();
  36168. }
  36169. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36170. {
  36171. if (moveInWholeWordSteps)
  36172. {
  36173. cut(); // in case something is already highlighted
  36174. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36175. }
  36176. else
  36177. {
  36178. if (selectionStart == selectionEnd)
  36179. selectionEnd.moveBy (1);
  36180. else
  36181. newTransaction();
  36182. }
  36183. cut();
  36184. }
  36185. void CodeEditorComponent::selectAll()
  36186. {
  36187. newTransaction();
  36188. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36189. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36190. }
  36191. void CodeEditorComponent::undo()
  36192. {
  36193. document.undo();
  36194. scrollToKeepCaretOnScreen();
  36195. }
  36196. void CodeEditorComponent::redo()
  36197. {
  36198. document.redo();
  36199. scrollToKeepCaretOnScreen();
  36200. }
  36201. void CodeEditorComponent::newTransaction()
  36202. {
  36203. document.newTransaction();
  36204. startTimer (600);
  36205. }
  36206. void CodeEditorComponent::timerCallback()
  36207. {
  36208. newTransaction();
  36209. }
  36210. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36211. {
  36212. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36213. }
  36214. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36215. {
  36216. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36217. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36218. }
  36219. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36220. {
  36221. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36222. CodeDocument::Position (&document, range.getEnd()));
  36223. }
  36224. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36225. {
  36226. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36227. const bool shiftDown = key.getModifiers().isShiftDown();
  36228. if (key.isKeyCode (KeyPress::leftKey))
  36229. {
  36230. cursorLeft (moveInWholeWordSteps, shiftDown);
  36231. }
  36232. else if (key.isKeyCode (KeyPress::rightKey))
  36233. {
  36234. cursorRight (moveInWholeWordSteps, shiftDown);
  36235. }
  36236. else if (key.isKeyCode (KeyPress::upKey))
  36237. {
  36238. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36239. scrollDown();
  36240. #if JUCE_MAC
  36241. else if (key.getModifiers().isCommandDown())
  36242. goToStartOfDocument (shiftDown);
  36243. #endif
  36244. else
  36245. cursorUp (shiftDown);
  36246. }
  36247. else if (key.isKeyCode (KeyPress::downKey))
  36248. {
  36249. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36250. scrollUp();
  36251. #if JUCE_MAC
  36252. else if (key.getModifiers().isCommandDown())
  36253. goToEndOfDocument (shiftDown);
  36254. #endif
  36255. else
  36256. cursorDown (shiftDown);
  36257. }
  36258. else if (key.isKeyCode (KeyPress::pageDownKey))
  36259. {
  36260. pageDown (shiftDown);
  36261. }
  36262. else if (key.isKeyCode (KeyPress::pageUpKey))
  36263. {
  36264. pageUp (shiftDown);
  36265. }
  36266. else if (key.isKeyCode (KeyPress::homeKey))
  36267. {
  36268. if (moveInWholeWordSteps)
  36269. goToStartOfDocument (shiftDown);
  36270. else
  36271. goToStartOfLine (shiftDown);
  36272. }
  36273. else if (key.isKeyCode (KeyPress::endKey))
  36274. {
  36275. if (moveInWholeWordSteps)
  36276. goToEndOfDocument (shiftDown);
  36277. else
  36278. goToEndOfLine (shiftDown);
  36279. }
  36280. else if (key.isKeyCode (KeyPress::backspaceKey))
  36281. {
  36282. backspace (moveInWholeWordSteps);
  36283. }
  36284. else if (key.isKeyCode (KeyPress::deleteKey))
  36285. {
  36286. deleteForward (moveInWholeWordSteps);
  36287. }
  36288. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0))
  36289. {
  36290. copy();
  36291. }
  36292. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  36293. {
  36294. copyThenCut();
  36295. }
  36296. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0))
  36297. {
  36298. paste();
  36299. }
  36300. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  36301. {
  36302. undo();
  36303. }
  36304. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0)
  36305. || key == KeyPress ('z', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36306. {
  36307. redo();
  36308. }
  36309. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  36310. {
  36311. selectAll();
  36312. }
  36313. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36314. {
  36315. insertTabAtCaret();
  36316. }
  36317. else if (key == KeyPress::returnKey)
  36318. {
  36319. newTransaction();
  36320. insertTextAtCaret (document.getNewLineCharacters());
  36321. }
  36322. else if (key.isKeyCode (KeyPress::escapeKey))
  36323. {
  36324. newTransaction();
  36325. }
  36326. else if (key.getTextCharacter() >= ' ')
  36327. {
  36328. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36329. }
  36330. else
  36331. {
  36332. return false;
  36333. }
  36334. return true;
  36335. }
  36336. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36337. {
  36338. newTransaction();
  36339. dragType = notDragging;
  36340. if (! e.mods.isPopupMenu())
  36341. {
  36342. beginDragAutoRepeat (100);
  36343. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36344. }
  36345. else
  36346. {
  36347. }
  36348. }
  36349. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36350. {
  36351. if (! e.mods.isPopupMenu())
  36352. moveCaretTo (getPositionAt (e.x, e.y), true);
  36353. }
  36354. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36355. {
  36356. newTransaction();
  36357. beginDragAutoRepeat (0);
  36358. dragType = notDragging;
  36359. }
  36360. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36361. {
  36362. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36363. CodeDocument::Position tokenEnd (tokenStart);
  36364. if (e.getNumberOfClicks() > 2)
  36365. {
  36366. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36367. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36368. }
  36369. else
  36370. {
  36371. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36372. tokenEnd.moveBy (1);
  36373. tokenStart = tokenEnd;
  36374. while (tokenStart.getIndexInLine() > 0
  36375. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36376. tokenStart.moveBy (-1);
  36377. }
  36378. moveCaretTo (tokenEnd, false);
  36379. moveCaretTo (tokenStart, true);
  36380. }
  36381. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36382. {
  36383. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36384. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36385. }
  36386. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36387. {
  36388. if (scrollBarThatHasMoved == verticalScrollBar)
  36389. scrollToLineInternal ((int) newRangeStart);
  36390. else
  36391. scrollToColumnInternal (newRangeStart);
  36392. }
  36393. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36394. {
  36395. useSpacesForTabs = insertSpaces;
  36396. if (spacesPerTab != numSpaces)
  36397. {
  36398. spacesPerTab = numSpaces;
  36399. triggerAsyncUpdate();
  36400. }
  36401. }
  36402. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36403. {
  36404. const String line (document.getLine (lineNum));
  36405. jassert (index <= line.length());
  36406. int col = 0;
  36407. for (int i = 0; i < index; ++i)
  36408. {
  36409. if (line[i] != '\t')
  36410. ++col;
  36411. else
  36412. col += getTabSize() - (col % getTabSize());
  36413. }
  36414. return col;
  36415. }
  36416. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36417. {
  36418. const String line (document.getLine (lineNum));
  36419. const int lineLength = line.length();
  36420. int i, col = 0;
  36421. for (i = 0; i < lineLength; ++i)
  36422. {
  36423. if (line[i] != '\t')
  36424. ++col;
  36425. else
  36426. col += getTabSize() - (col % getTabSize());
  36427. if (col > column)
  36428. break;
  36429. }
  36430. return i;
  36431. }
  36432. void CodeEditorComponent::setFont (const Font& newFont)
  36433. {
  36434. font = newFont;
  36435. charWidth = font.getStringWidthFloat ("0");
  36436. lineHeight = roundToInt (font.getHeight());
  36437. resized();
  36438. }
  36439. void CodeEditorComponent::resetToDefaultColours()
  36440. {
  36441. coloursForTokenCategories.clear();
  36442. if (codeTokeniser != 0)
  36443. {
  36444. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36445. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36446. }
  36447. }
  36448. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36449. {
  36450. jassert (tokenType < 256);
  36451. while (coloursForTokenCategories.size() < tokenType)
  36452. coloursForTokenCategories.add (Colours::black);
  36453. coloursForTokenCategories.set (tokenType, colour);
  36454. repaint();
  36455. }
  36456. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36457. {
  36458. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36459. return findColour (CodeEditorComponent::defaultTextColourId);
  36460. return coloursForTokenCategories.getReference (tokenType);
  36461. }
  36462. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36463. {
  36464. int i;
  36465. for (i = cachedIterators.size(); --i >= 0;)
  36466. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36467. break;
  36468. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36469. }
  36470. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36471. {
  36472. const int maxNumCachedPositions = 5000;
  36473. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36474. if (cachedIterators.size() == 0)
  36475. cachedIterators.add (new CodeDocument::Iterator (&document));
  36476. if (codeTokeniser == 0)
  36477. return;
  36478. for (;;)
  36479. {
  36480. CodeDocument::Iterator* last = cachedIterators.getLast();
  36481. if (last->getLine() >= maxLineNum)
  36482. break;
  36483. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36484. cachedIterators.add (t);
  36485. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36486. for (;;)
  36487. {
  36488. codeTokeniser->readNextToken (*t);
  36489. if (t->getLine() >= targetLine)
  36490. break;
  36491. if (t->isEOF())
  36492. return;
  36493. }
  36494. }
  36495. }
  36496. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36497. {
  36498. if (codeTokeniser == 0)
  36499. return;
  36500. for (int i = cachedIterators.size(); --i >= 0;)
  36501. {
  36502. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36503. if (t->getPosition() <= position)
  36504. {
  36505. source = *t;
  36506. break;
  36507. }
  36508. }
  36509. while (source.getPosition() < position)
  36510. {
  36511. const CodeDocument::Iterator original (source);
  36512. codeTokeniser->readNextToken (source);
  36513. if (source.getPosition() > position || source.isEOF())
  36514. {
  36515. source = original;
  36516. break;
  36517. }
  36518. }
  36519. }
  36520. END_JUCE_NAMESPACE
  36521. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36522. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36523. BEGIN_JUCE_NAMESPACE
  36524. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36525. {
  36526. }
  36527. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36528. {
  36529. }
  36530. namespace CppTokeniser
  36531. {
  36532. static bool isIdentifierStart (const juce_wchar c) throw()
  36533. {
  36534. return CharacterFunctions::isLetter (c)
  36535. || c == '_' || c == '@';
  36536. }
  36537. static bool isIdentifierBody (const juce_wchar c) throw()
  36538. {
  36539. return CharacterFunctions::isLetter (c)
  36540. || CharacterFunctions::isDigit (c)
  36541. || c == '_' || c == '@';
  36542. }
  36543. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36544. {
  36545. static const juce_wchar* keywords2Char[] =
  36546. { T("if"), T("do"), T("or"), 0 };
  36547. static const juce_wchar* keywords3Char[] =
  36548. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36549. static const juce_wchar* keywords4Char[] =
  36550. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36551. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36552. static const juce_wchar* keywords5Char[] =
  36553. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36554. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36555. static const juce_wchar* keywords6Char[] =
  36556. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36557. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36558. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36559. static const juce_wchar* keywordsOther[] =
  36560. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36561. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36562. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36563. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36564. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36565. int tokenLength = 0;
  36566. juce_wchar possibleIdentifier [19];
  36567. while (isIdentifierBody (source.peekNextChar()))
  36568. {
  36569. const juce_wchar c = source.nextChar();
  36570. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36571. possibleIdentifier [tokenLength] = c;
  36572. ++tokenLength;
  36573. }
  36574. if (tokenLength > 1 && tokenLength <= 16)
  36575. {
  36576. possibleIdentifier [tokenLength] = 0;
  36577. const juce_wchar** k;
  36578. switch (tokenLength)
  36579. {
  36580. case 2: k = keywords2Char; break;
  36581. case 3: k = keywords3Char; break;
  36582. case 4: k = keywords4Char; break;
  36583. case 5: k = keywords5Char; break;
  36584. case 6: k = keywords6Char; break;
  36585. default: k = keywordsOther; break;
  36586. }
  36587. int i = 0;
  36588. while (k[i] != 0)
  36589. {
  36590. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36591. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36592. ++i;
  36593. }
  36594. }
  36595. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36596. }
  36597. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36598. {
  36599. const juce_wchar c = source.peekNextChar();
  36600. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36601. source.skip();
  36602. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36603. return false;
  36604. return true;
  36605. }
  36606. static bool isHexDigit (const juce_wchar c) throw()
  36607. {
  36608. return (c >= '0' && c <= '9')
  36609. || (c >= 'a' && c <= 'f')
  36610. || (c >= 'A' && c <= 'F');
  36611. }
  36612. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36613. {
  36614. if (source.nextChar() != '0')
  36615. return false;
  36616. juce_wchar c = source.nextChar();
  36617. if (c != 'x' && c != 'X')
  36618. return false;
  36619. int numDigits = 0;
  36620. while (isHexDigit (source.peekNextChar()))
  36621. {
  36622. ++numDigits;
  36623. source.skip();
  36624. }
  36625. if (numDigits == 0)
  36626. return false;
  36627. return skipNumberSuffix (source);
  36628. }
  36629. static bool isOctalDigit (const juce_wchar c) throw()
  36630. {
  36631. return c >= '0' && c <= '7';
  36632. }
  36633. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36634. {
  36635. if (source.nextChar() != '0')
  36636. return false;
  36637. if (! isOctalDigit (source.nextChar()))
  36638. return false;
  36639. while (isOctalDigit (source.peekNextChar()))
  36640. source.skip();
  36641. return skipNumberSuffix (source);
  36642. }
  36643. static bool isDecimalDigit (const juce_wchar c) throw()
  36644. {
  36645. return c >= '0' && c <= '9';
  36646. }
  36647. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36648. {
  36649. int numChars = 0;
  36650. while (isDecimalDigit (source.peekNextChar()))
  36651. {
  36652. ++numChars;
  36653. source.skip();
  36654. }
  36655. if (numChars == 0)
  36656. return false;
  36657. return skipNumberSuffix (source);
  36658. }
  36659. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36660. {
  36661. int numDigits = 0;
  36662. while (isDecimalDigit (source.peekNextChar()))
  36663. {
  36664. source.skip();
  36665. ++numDigits;
  36666. }
  36667. const bool hasPoint = (source.peekNextChar() == '.');
  36668. if (hasPoint)
  36669. {
  36670. source.skip();
  36671. while (isDecimalDigit (source.peekNextChar()))
  36672. {
  36673. source.skip();
  36674. ++numDigits;
  36675. }
  36676. }
  36677. if (numDigits == 0)
  36678. return false;
  36679. juce_wchar c = source.peekNextChar();
  36680. const bool hasExponent = (c == 'e' || c == 'E');
  36681. if (hasExponent)
  36682. {
  36683. source.skip();
  36684. c = source.peekNextChar();
  36685. if (c == '+' || c == '-')
  36686. source.skip();
  36687. int numExpDigits = 0;
  36688. while (isDecimalDigit (source.peekNextChar()))
  36689. {
  36690. source.skip();
  36691. ++numExpDigits;
  36692. }
  36693. if (numExpDigits == 0)
  36694. return false;
  36695. }
  36696. c = source.peekNextChar();
  36697. if (c == 'f' || c == 'F')
  36698. source.skip();
  36699. else if (! (hasExponent || hasPoint))
  36700. return false;
  36701. return true;
  36702. }
  36703. static int parseNumber (CodeDocument::Iterator& source)
  36704. {
  36705. const CodeDocument::Iterator original (source);
  36706. if (parseFloatLiteral (source))
  36707. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36708. source = original;
  36709. if (parseHexLiteral (source))
  36710. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36711. source = original;
  36712. if (parseOctalLiteral (source))
  36713. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36714. source = original;
  36715. if (parseDecimalLiteral (source))
  36716. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36717. source = original;
  36718. source.skip();
  36719. return CPlusPlusCodeTokeniser::tokenType_error;
  36720. }
  36721. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36722. {
  36723. const juce_wchar quote = source.nextChar();
  36724. for (;;)
  36725. {
  36726. const juce_wchar c = source.nextChar();
  36727. if (c == quote || c == 0)
  36728. break;
  36729. if (c == '\\')
  36730. source.skip();
  36731. }
  36732. }
  36733. static void skipComment (CodeDocument::Iterator& source) throw()
  36734. {
  36735. bool lastWasStar = false;
  36736. for (;;)
  36737. {
  36738. const juce_wchar c = source.nextChar();
  36739. if (c == 0 || (c == '/' && lastWasStar))
  36740. break;
  36741. lastWasStar = (c == '*');
  36742. }
  36743. }
  36744. }
  36745. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36746. {
  36747. int result = tokenType_error;
  36748. source.skipWhitespace();
  36749. juce_wchar firstChar = source.peekNextChar();
  36750. switch (firstChar)
  36751. {
  36752. case 0:
  36753. source.skip();
  36754. break;
  36755. case '0':
  36756. case '1':
  36757. case '2':
  36758. case '3':
  36759. case '4':
  36760. case '5':
  36761. case '6':
  36762. case '7':
  36763. case '8':
  36764. case '9':
  36765. result = CppTokeniser::parseNumber (source);
  36766. break;
  36767. case '.':
  36768. result = CppTokeniser::parseNumber (source);
  36769. if (result == tokenType_error)
  36770. result = tokenType_punctuation;
  36771. break;
  36772. case ',':
  36773. case ';':
  36774. case ':':
  36775. source.skip();
  36776. result = tokenType_punctuation;
  36777. break;
  36778. case '(':
  36779. case ')':
  36780. case '{':
  36781. case '}':
  36782. case '[':
  36783. case ']':
  36784. source.skip();
  36785. result = tokenType_bracket;
  36786. break;
  36787. case '"':
  36788. case '\'':
  36789. CppTokeniser::skipQuotedString (source);
  36790. result = tokenType_stringLiteral;
  36791. break;
  36792. case '+':
  36793. result = tokenType_operator;
  36794. source.skip();
  36795. if (source.peekNextChar() == '+')
  36796. source.skip();
  36797. else if (source.peekNextChar() == '=')
  36798. source.skip();
  36799. break;
  36800. case '-':
  36801. source.skip();
  36802. result = CppTokeniser::parseNumber (source);
  36803. if (result == tokenType_error)
  36804. {
  36805. result = tokenType_operator;
  36806. if (source.peekNextChar() == '-')
  36807. source.skip();
  36808. else if (source.peekNextChar() == '=')
  36809. source.skip();
  36810. }
  36811. break;
  36812. case '*':
  36813. case '%':
  36814. case '=':
  36815. case '!':
  36816. result = tokenType_operator;
  36817. source.skip();
  36818. if (source.peekNextChar() == '=')
  36819. source.skip();
  36820. break;
  36821. case '/':
  36822. result = tokenType_operator;
  36823. source.skip();
  36824. if (source.peekNextChar() == '=')
  36825. {
  36826. source.skip();
  36827. }
  36828. else if (source.peekNextChar() == '/')
  36829. {
  36830. result = tokenType_comment;
  36831. source.skipToEndOfLine();
  36832. }
  36833. else if (source.peekNextChar() == '*')
  36834. {
  36835. source.skip();
  36836. result = tokenType_comment;
  36837. CppTokeniser::skipComment (source);
  36838. }
  36839. break;
  36840. case '?':
  36841. case '~':
  36842. source.skip();
  36843. result = tokenType_operator;
  36844. break;
  36845. case '<':
  36846. source.skip();
  36847. result = tokenType_operator;
  36848. if (source.peekNextChar() == '=')
  36849. {
  36850. source.skip();
  36851. }
  36852. else if (source.peekNextChar() == '<')
  36853. {
  36854. source.skip();
  36855. if (source.peekNextChar() == '=')
  36856. source.skip();
  36857. }
  36858. break;
  36859. case '>':
  36860. source.skip();
  36861. result = tokenType_operator;
  36862. if (source.peekNextChar() == '=')
  36863. {
  36864. source.skip();
  36865. }
  36866. else if (source.peekNextChar() == '<')
  36867. {
  36868. source.skip();
  36869. if (source.peekNextChar() == '=')
  36870. source.skip();
  36871. }
  36872. break;
  36873. case '|':
  36874. source.skip();
  36875. result = tokenType_operator;
  36876. if (source.peekNextChar() == '=')
  36877. {
  36878. source.skip();
  36879. }
  36880. else if (source.peekNextChar() == '|')
  36881. {
  36882. source.skip();
  36883. if (source.peekNextChar() == '=')
  36884. source.skip();
  36885. }
  36886. break;
  36887. case '&':
  36888. source.skip();
  36889. result = tokenType_operator;
  36890. if (source.peekNextChar() == '=')
  36891. {
  36892. source.skip();
  36893. }
  36894. else if (source.peekNextChar() == '&')
  36895. {
  36896. source.skip();
  36897. if (source.peekNextChar() == '=')
  36898. source.skip();
  36899. }
  36900. break;
  36901. case '^':
  36902. source.skip();
  36903. result = tokenType_operator;
  36904. if (source.peekNextChar() == '=')
  36905. {
  36906. source.skip();
  36907. }
  36908. else if (source.peekNextChar() == '^')
  36909. {
  36910. source.skip();
  36911. if (source.peekNextChar() == '=')
  36912. source.skip();
  36913. }
  36914. break;
  36915. case '#':
  36916. result = tokenType_preprocessor;
  36917. source.skipToEndOfLine();
  36918. break;
  36919. default:
  36920. if (CppTokeniser::isIdentifierStart (firstChar))
  36921. result = CppTokeniser::parseIdentifier (source);
  36922. else
  36923. source.skip();
  36924. break;
  36925. }
  36926. //jassert (result != tokenType_unknown);
  36927. return result;
  36928. }
  36929. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36930. {
  36931. StringArray s;
  36932. s.add ("Error");
  36933. s.add ("Comment");
  36934. s.add ("C++ keyword");
  36935. s.add ("Identifier");
  36936. s.add ("Integer literal");
  36937. s.add ("Float literal");
  36938. s.add ("String literal");
  36939. s.add ("Operator");
  36940. s.add ("Bracket");
  36941. s.add ("Punctuation");
  36942. s.add ("Preprocessor line");
  36943. return s;
  36944. }
  36945. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36946. {
  36947. const uint32 colours[] =
  36948. {
  36949. 0xffcc0000, // error
  36950. 0xff00aa00, // comment
  36951. 0xff0000cc, // keyword
  36952. 0xff000000, // identifier
  36953. 0xff880000, // int literal
  36954. 0xff885500, // float literal
  36955. 0xff990099, // string literal
  36956. 0xff225500, // operator
  36957. 0xff000055, // bracket
  36958. 0xff004400, // punctuation
  36959. 0xff660000 // preprocessor
  36960. };
  36961. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36962. return Colour (colours [tokenType]);
  36963. return Colours::black;
  36964. }
  36965. END_JUCE_NAMESPACE
  36966. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36967. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36968. BEGIN_JUCE_NAMESPACE
  36969. ComboBox::ComboBox (const String& name)
  36970. : Component (name),
  36971. lastCurrentId (0),
  36972. isButtonDown (false),
  36973. separatorPending (false),
  36974. menuActive (false),
  36975. label (0)
  36976. {
  36977. noChoicesMessage = TRANS("(no choices)");
  36978. setRepaintsOnMouseActivity (true);
  36979. lookAndFeelChanged();
  36980. currentId.addListener (this);
  36981. }
  36982. ComboBox::~ComboBox()
  36983. {
  36984. currentId.removeListener (this);
  36985. if (menuActive)
  36986. PopupMenu::dismissAllActiveMenus();
  36987. label = 0;
  36988. deleteAllChildren();
  36989. }
  36990. void ComboBox::setEditableText (const bool isEditable)
  36991. {
  36992. label->setEditable (isEditable, isEditable, false);
  36993. setWantsKeyboardFocus (! isEditable);
  36994. resized();
  36995. }
  36996. bool ComboBox::isTextEditable() const throw()
  36997. {
  36998. return label->isEditable();
  36999. }
  37000. void ComboBox::setJustificationType (const Justification& justification) throw()
  37001. {
  37002. label->setJustificationType (justification);
  37003. }
  37004. const Justification ComboBox::getJustificationType() const throw()
  37005. {
  37006. return label->getJustificationType();
  37007. }
  37008. void ComboBox::setTooltip (const String& newTooltip)
  37009. {
  37010. SettableTooltipClient::setTooltip (newTooltip);
  37011. label->setTooltip (newTooltip);
  37012. }
  37013. void ComboBox::addItem (const String& newItemText,
  37014. const int newItemId) throw()
  37015. {
  37016. // you can't add empty strings to the list..
  37017. jassert (newItemText.isNotEmpty());
  37018. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37019. jassert (newItemId != 0);
  37020. // you shouldn't use duplicate item IDs!
  37021. jassert (getItemForId (newItemId) == 0);
  37022. if (newItemText.isNotEmpty() && newItemId != 0)
  37023. {
  37024. if (separatorPending)
  37025. {
  37026. separatorPending = false;
  37027. ItemInfo* const item = new ItemInfo();
  37028. item->itemId = 0;
  37029. item->isEnabled = false;
  37030. item->isHeading = false;
  37031. items.add (item);
  37032. }
  37033. ItemInfo* const item = new ItemInfo();
  37034. item->name = newItemText;
  37035. item->itemId = newItemId;
  37036. item->isEnabled = true;
  37037. item->isHeading = false;
  37038. items.add (item);
  37039. }
  37040. }
  37041. void ComboBox::addSeparator() throw()
  37042. {
  37043. separatorPending = (items.size() > 0);
  37044. }
  37045. void ComboBox::addSectionHeading (const String& headingName) throw()
  37046. {
  37047. // you can't add empty strings to the list..
  37048. jassert (headingName.isNotEmpty());
  37049. if (headingName.isNotEmpty())
  37050. {
  37051. if (separatorPending)
  37052. {
  37053. separatorPending = false;
  37054. ItemInfo* const item = new ItemInfo();
  37055. item->itemId = 0;
  37056. item->isEnabled = false;
  37057. item->isHeading = false;
  37058. items.add (item);
  37059. }
  37060. ItemInfo* const item = new ItemInfo();
  37061. item->name = headingName;
  37062. item->itemId = 0;
  37063. item->isEnabled = true;
  37064. item->isHeading = true;
  37065. items.add (item);
  37066. }
  37067. }
  37068. void ComboBox::setItemEnabled (const int itemId,
  37069. const bool shouldBeEnabled) throw()
  37070. {
  37071. ItemInfo* const item = getItemForId (itemId);
  37072. if (item != 0)
  37073. item->isEnabled = shouldBeEnabled;
  37074. }
  37075. void ComboBox::changeItemText (const int itemId,
  37076. const String& newText) throw()
  37077. {
  37078. ItemInfo* const item = getItemForId (itemId);
  37079. jassert (item != 0);
  37080. if (item != 0)
  37081. item->name = newText;
  37082. }
  37083. void ComboBox::clear (const bool dontSendChangeMessage)
  37084. {
  37085. items.clear();
  37086. separatorPending = false;
  37087. if (! label->isEditable())
  37088. setSelectedItemIndex (-1, dontSendChangeMessage);
  37089. }
  37090. bool ComboBox::ItemInfo::isSeparator() const throw()
  37091. {
  37092. return name.isEmpty();
  37093. }
  37094. bool ComboBox::ItemInfo::isRealItem() const throw()
  37095. {
  37096. return ! (isHeading || name.isEmpty());
  37097. }
  37098. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37099. {
  37100. if (itemId != 0)
  37101. {
  37102. for (int i = items.size(); --i >= 0;)
  37103. if (items.getUnchecked(i)->itemId == itemId)
  37104. return items.getUnchecked(i);
  37105. }
  37106. return 0;
  37107. }
  37108. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37109. {
  37110. int n = 0;
  37111. for (int i = 0; i < items.size(); ++i)
  37112. {
  37113. ItemInfo* const item = items.getUnchecked(i);
  37114. if (item->isRealItem())
  37115. if (n++ == index)
  37116. return item;
  37117. }
  37118. return 0;
  37119. }
  37120. int ComboBox::getNumItems() const throw()
  37121. {
  37122. int n = 0;
  37123. for (int i = items.size(); --i >= 0;)
  37124. if (items.getUnchecked(i)->isRealItem())
  37125. ++n;
  37126. return n;
  37127. }
  37128. const String ComboBox::getItemText (const int index) const throw()
  37129. {
  37130. const ItemInfo* const item = getItemForIndex (index);
  37131. if (item != 0)
  37132. return item->name;
  37133. return String::empty;
  37134. }
  37135. int ComboBox::getItemId (const int index) const throw()
  37136. {
  37137. const ItemInfo* const item = getItemForIndex (index);
  37138. return (item != 0) ? item->itemId : 0;
  37139. }
  37140. int ComboBox::indexOfItemId (const int itemId) const throw()
  37141. {
  37142. int n = 0;
  37143. for (int i = 0; i < items.size(); ++i)
  37144. {
  37145. const ItemInfo* const item = items.getUnchecked(i);
  37146. if (item->isRealItem())
  37147. {
  37148. if (item->itemId == itemId)
  37149. return n;
  37150. ++n;
  37151. }
  37152. }
  37153. return -1;
  37154. }
  37155. int ComboBox::getSelectedItemIndex() const throw()
  37156. {
  37157. int index = indexOfItemId (currentId.getValue());
  37158. if (getText() != getItemText (index))
  37159. index = -1;
  37160. return index;
  37161. }
  37162. void ComboBox::setSelectedItemIndex (const int index,
  37163. const bool dontSendChangeMessage) throw()
  37164. {
  37165. setSelectedId (getItemId (index), dontSendChangeMessage);
  37166. }
  37167. int ComboBox::getSelectedId() const throw()
  37168. {
  37169. const ItemInfo* const item = getItemForId (currentId.getValue());
  37170. return (item != 0 && getText() == item->name)
  37171. ? item->itemId
  37172. : 0;
  37173. }
  37174. void ComboBox::setSelectedId (const int newItemId,
  37175. const bool dontSendChangeMessage) throw()
  37176. {
  37177. const ItemInfo* const item = getItemForId (newItemId);
  37178. const String newItemText (item != 0 ? item->name : String::empty);
  37179. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37180. {
  37181. if (! dontSendChangeMessage)
  37182. triggerAsyncUpdate();
  37183. label->setText (newItemText, false);
  37184. lastCurrentId = newItemId;
  37185. currentId = newItemId;
  37186. repaint(); // for the benefit of the 'none selected' text
  37187. }
  37188. }
  37189. void ComboBox::valueChanged (Value&)
  37190. {
  37191. if (lastCurrentId != (int) currentId.getValue())
  37192. setSelectedId (currentId.getValue(), false);
  37193. }
  37194. const String ComboBox::getText() const throw()
  37195. {
  37196. return label->getText();
  37197. }
  37198. void ComboBox::setText (const String& newText,
  37199. const bool dontSendChangeMessage) throw()
  37200. {
  37201. for (int i = items.size(); --i >= 0;)
  37202. {
  37203. const ItemInfo* const item = items.getUnchecked(i);
  37204. if (item->isRealItem()
  37205. && item->name == newText)
  37206. {
  37207. setSelectedId (item->itemId, dontSendChangeMessage);
  37208. return;
  37209. }
  37210. }
  37211. lastCurrentId = 0;
  37212. currentId = 0;
  37213. if (label->getText() != newText)
  37214. {
  37215. label->setText (newText, false);
  37216. if (! dontSendChangeMessage)
  37217. triggerAsyncUpdate();
  37218. }
  37219. repaint();
  37220. }
  37221. void ComboBox::showEditor()
  37222. {
  37223. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37224. label->showEditor();
  37225. }
  37226. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37227. {
  37228. textWhenNothingSelected = newMessage;
  37229. repaint();
  37230. }
  37231. const String ComboBox::getTextWhenNothingSelected() const throw()
  37232. {
  37233. return textWhenNothingSelected;
  37234. }
  37235. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37236. {
  37237. noChoicesMessage = newMessage;
  37238. }
  37239. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37240. {
  37241. return noChoicesMessage;
  37242. }
  37243. void ComboBox::paint (Graphics& g)
  37244. {
  37245. getLookAndFeel().drawComboBox (g,
  37246. getWidth(),
  37247. getHeight(),
  37248. isButtonDown,
  37249. label->getRight(),
  37250. 0,
  37251. getWidth() - label->getRight(),
  37252. getHeight(),
  37253. *this);
  37254. if (textWhenNothingSelected.isNotEmpty()
  37255. && label->getText().isEmpty()
  37256. && ! label->isBeingEdited())
  37257. {
  37258. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37259. g.setFont (label->getFont());
  37260. g.drawFittedText (textWhenNothingSelected,
  37261. label->getX() + 2, label->getY() + 1,
  37262. label->getWidth() - 4, label->getHeight() - 2,
  37263. label->getJustificationType(),
  37264. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37265. }
  37266. }
  37267. void ComboBox::resized()
  37268. {
  37269. if (getHeight() > 0 && getWidth() > 0)
  37270. getLookAndFeel().positionComboBoxText (*this, *label);
  37271. }
  37272. void ComboBox::enablementChanged()
  37273. {
  37274. repaint();
  37275. }
  37276. void ComboBox::lookAndFeelChanged()
  37277. {
  37278. repaint();
  37279. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37280. if (label != 0)
  37281. {
  37282. newLabel->setEditable (label->isEditable());
  37283. newLabel->setJustificationType (label->getJustificationType());
  37284. newLabel->setTooltip (label->getTooltip());
  37285. newLabel->setText (label->getText(), false);
  37286. }
  37287. label = newLabel;
  37288. addAndMakeVisible (newLabel);
  37289. newLabel->addListener (this);
  37290. newLabel->addMouseListener (this, false);
  37291. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37292. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37293. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37294. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37295. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37296. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37297. resized();
  37298. }
  37299. void ComboBox::colourChanged()
  37300. {
  37301. lookAndFeelChanged();
  37302. }
  37303. bool ComboBox::keyPressed (const KeyPress& key)
  37304. {
  37305. bool used = false;
  37306. if (key.isKeyCode (KeyPress::upKey)
  37307. || key.isKeyCode (KeyPress::leftKey))
  37308. {
  37309. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37310. used = true;
  37311. }
  37312. else if (key.isKeyCode (KeyPress::downKey)
  37313. || key.isKeyCode (KeyPress::rightKey))
  37314. {
  37315. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37316. used = true;
  37317. }
  37318. else if (key.isKeyCode (KeyPress::returnKey))
  37319. {
  37320. showPopup();
  37321. used = true;
  37322. }
  37323. return used;
  37324. }
  37325. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37326. {
  37327. // only forward key events that aren't used by this component
  37328. return isKeyDown
  37329. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37330. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37331. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37332. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37333. }
  37334. void ComboBox::focusGained (FocusChangeType)
  37335. {
  37336. repaint();
  37337. }
  37338. void ComboBox::focusLost (FocusChangeType)
  37339. {
  37340. repaint();
  37341. }
  37342. void ComboBox::labelTextChanged (Label*)
  37343. {
  37344. triggerAsyncUpdate();
  37345. }
  37346. void ComboBox::showPopup()
  37347. {
  37348. if (! menuActive)
  37349. {
  37350. const int selectedId = getSelectedId();
  37351. Component::SafePointer<Component> deletionWatcher (this);
  37352. PopupMenu menu;
  37353. menu.setLookAndFeel (&getLookAndFeel());
  37354. for (int i = 0; i < items.size(); ++i)
  37355. {
  37356. const ItemInfo* const item = items.getUnchecked(i);
  37357. if (item->isSeparator())
  37358. menu.addSeparator();
  37359. else if (item->isHeading)
  37360. menu.addSectionHeader (item->name);
  37361. else
  37362. menu.addItem (item->itemId, item->name,
  37363. item->isEnabled, item->itemId == selectedId);
  37364. }
  37365. if (items.size() == 0)
  37366. menu.addItem (1, noChoicesMessage, false);
  37367. const int itemHeight = jlimit (12, 24, getHeight());
  37368. menuActive = true;
  37369. const int resultId = menu.showAt (this, selectedId,
  37370. getWidth(), 1, itemHeight);
  37371. if (deletionWatcher == 0)
  37372. return;
  37373. menuActive = false;
  37374. if (resultId != 0)
  37375. setSelectedId (resultId);
  37376. }
  37377. }
  37378. void ComboBox::mouseDown (const MouseEvent& e)
  37379. {
  37380. beginDragAutoRepeat (300);
  37381. isButtonDown = isEnabled();
  37382. if (isButtonDown
  37383. && (e.eventComponent == this || ! label->isEditable()))
  37384. {
  37385. showPopup();
  37386. }
  37387. }
  37388. void ComboBox::mouseDrag (const MouseEvent& e)
  37389. {
  37390. beginDragAutoRepeat (50);
  37391. if (isButtonDown && ! e.mouseWasClicked())
  37392. showPopup();
  37393. }
  37394. void ComboBox::mouseUp (const MouseEvent& e2)
  37395. {
  37396. if (isButtonDown)
  37397. {
  37398. isButtonDown = false;
  37399. repaint();
  37400. const MouseEvent e (e2.getEventRelativeTo (this));
  37401. if (reallyContains (e.x, e.y, true)
  37402. && (e2.eventComponent == this || ! label->isEditable()))
  37403. {
  37404. showPopup();
  37405. }
  37406. }
  37407. }
  37408. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37409. {
  37410. listeners.add (listener);
  37411. }
  37412. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37413. {
  37414. listeners.remove (listener);
  37415. }
  37416. void ComboBox::handleAsyncUpdate()
  37417. {
  37418. Component::BailOutChecker checker (this);
  37419. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37420. }
  37421. END_JUCE_NAMESPACE
  37422. /*** End of inlined file: juce_ComboBox.cpp ***/
  37423. /*** Start of inlined file: juce_Label.cpp ***/
  37424. BEGIN_JUCE_NAMESPACE
  37425. Label::Label (const String& componentName,
  37426. const String& labelText)
  37427. : Component (componentName),
  37428. textValue (labelText),
  37429. lastTextValue (labelText),
  37430. font (15.0f),
  37431. justification (Justification::centredLeft),
  37432. ownerComponent (0),
  37433. horizontalBorderSize (5),
  37434. verticalBorderSize (1),
  37435. minimumHorizontalScale (0.7f),
  37436. editSingleClick (false),
  37437. editDoubleClick (false),
  37438. lossOfFocusDiscardsChanges (false)
  37439. {
  37440. setColour (TextEditor::textColourId, Colours::black);
  37441. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37442. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37443. textValue.addListener (this);
  37444. }
  37445. Label::~Label()
  37446. {
  37447. textValue.removeListener (this);
  37448. if (ownerComponent != 0)
  37449. ownerComponent->removeComponentListener (this);
  37450. editor = 0;
  37451. }
  37452. void Label::setText (const String& newText,
  37453. const bool broadcastChangeMessage)
  37454. {
  37455. hideEditor (true);
  37456. if (lastTextValue != newText)
  37457. {
  37458. lastTextValue = newText;
  37459. textValue = newText;
  37460. repaint();
  37461. textWasChanged();
  37462. if (ownerComponent != 0)
  37463. componentMovedOrResized (*ownerComponent, true, true);
  37464. if (broadcastChangeMessage)
  37465. callChangeListeners();
  37466. }
  37467. }
  37468. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37469. {
  37470. return (returnActiveEditorContents && isBeingEdited())
  37471. ? editor->getText()
  37472. : textValue.toString();
  37473. }
  37474. void Label::valueChanged (Value&)
  37475. {
  37476. if (lastTextValue != textValue.toString())
  37477. setText (textValue.toString(), true);
  37478. }
  37479. void Label::setFont (const Font& newFont) throw()
  37480. {
  37481. font = newFont;
  37482. repaint();
  37483. }
  37484. const Font& Label::getFont() const throw()
  37485. {
  37486. return font;
  37487. }
  37488. void Label::setEditable (const bool editOnSingleClick,
  37489. const bool editOnDoubleClick,
  37490. const bool lossOfFocusDiscardsChanges_) throw()
  37491. {
  37492. editSingleClick = editOnSingleClick;
  37493. editDoubleClick = editOnDoubleClick;
  37494. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37495. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37496. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37497. }
  37498. void Label::setJustificationType (const Justification& justification_) throw()
  37499. {
  37500. justification = justification_;
  37501. repaint();
  37502. }
  37503. void Label::setBorderSize (int h, int v)
  37504. {
  37505. horizontalBorderSize = h;
  37506. verticalBorderSize = v;
  37507. repaint();
  37508. }
  37509. Component* Label::getAttachedComponent() const
  37510. {
  37511. return static_cast<Component*> (ownerComponent);
  37512. }
  37513. void Label::attachToComponent (Component* owner,
  37514. const bool onLeft)
  37515. {
  37516. if (ownerComponent != 0)
  37517. ownerComponent->removeComponentListener (this);
  37518. ownerComponent = owner;
  37519. leftOfOwnerComp = onLeft;
  37520. if (ownerComponent != 0)
  37521. {
  37522. setVisible (owner->isVisible());
  37523. ownerComponent->addComponentListener (this);
  37524. componentParentHierarchyChanged (*ownerComponent);
  37525. componentMovedOrResized (*ownerComponent, true, true);
  37526. }
  37527. }
  37528. void Label::componentMovedOrResized (Component& component,
  37529. bool /*wasMoved*/,
  37530. bool /*wasResized*/)
  37531. {
  37532. if (leftOfOwnerComp)
  37533. {
  37534. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37535. component.getHeight());
  37536. setTopRightPosition (component.getX(), component.getY());
  37537. }
  37538. else
  37539. {
  37540. setSize (component.getWidth(),
  37541. 8 + roundToInt (getFont().getHeight()));
  37542. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37543. }
  37544. }
  37545. void Label::componentParentHierarchyChanged (Component& component)
  37546. {
  37547. if (component.getParentComponent() != 0)
  37548. component.getParentComponent()->addChildComponent (this);
  37549. }
  37550. void Label::componentVisibilityChanged (Component& component)
  37551. {
  37552. setVisible (component.isVisible());
  37553. }
  37554. void Label::textWasEdited()
  37555. {
  37556. }
  37557. void Label::textWasChanged()
  37558. {
  37559. }
  37560. void Label::showEditor()
  37561. {
  37562. if (editor == 0)
  37563. {
  37564. addAndMakeVisible (editor = createEditorComponent());
  37565. editor->setText (getText(), false);
  37566. editor->addListener (this);
  37567. editor->grabKeyboardFocus();
  37568. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37569. editor->addListener (this);
  37570. resized();
  37571. repaint();
  37572. editorShown (editor);
  37573. enterModalState (false);
  37574. editor->grabKeyboardFocus();
  37575. }
  37576. }
  37577. void Label::editorShown (TextEditor* /*editorComponent*/)
  37578. {
  37579. }
  37580. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37581. {
  37582. }
  37583. bool Label::updateFromTextEditorContents()
  37584. {
  37585. jassert (editor != 0);
  37586. const String newText (editor->getText());
  37587. if (textValue.toString() != newText)
  37588. {
  37589. lastTextValue = newText;
  37590. textValue = newText;
  37591. repaint();
  37592. textWasChanged();
  37593. if (ownerComponent != 0)
  37594. componentMovedOrResized (*ownerComponent, true, true);
  37595. return true;
  37596. }
  37597. return false;
  37598. }
  37599. void Label::hideEditor (const bool discardCurrentEditorContents)
  37600. {
  37601. if (editor != 0)
  37602. {
  37603. Component::SafePointer<Component> deletionChecker (this);
  37604. editorAboutToBeHidden (editor);
  37605. const bool changed = (! discardCurrentEditorContents)
  37606. && updateFromTextEditorContents();
  37607. editor = 0;
  37608. repaint();
  37609. if (changed)
  37610. textWasEdited();
  37611. if (deletionChecker != 0)
  37612. exitModalState (0);
  37613. if (changed && deletionChecker != 0)
  37614. callChangeListeners();
  37615. }
  37616. }
  37617. void Label::inputAttemptWhenModal()
  37618. {
  37619. if (editor != 0)
  37620. {
  37621. if (lossOfFocusDiscardsChanges)
  37622. textEditorEscapeKeyPressed (*editor);
  37623. else
  37624. textEditorReturnKeyPressed (*editor);
  37625. }
  37626. }
  37627. bool Label::isBeingEdited() const throw()
  37628. {
  37629. return editor != 0;
  37630. }
  37631. TextEditor* Label::createEditorComponent()
  37632. {
  37633. TextEditor* const ed = new TextEditor (getName());
  37634. ed->setFont (font);
  37635. // copy these colours from our own settings..
  37636. const int cols[] = { TextEditor::backgroundColourId,
  37637. TextEditor::textColourId,
  37638. TextEditor::highlightColourId,
  37639. TextEditor::highlightedTextColourId,
  37640. TextEditor::caretColourId,
  37641. TextEditor::outlineColourId,
  37642. TextEditor::focusedOutlineColourId,
  37643. TextEditor::shadowColourId };
  37644. for (int i = 0; i < numElementsInArray (cols); ++i)
  37645. ed->setColour (cols[i], findColour (cols[i]));
  37646. return ed;
  37647. }
  37648. void Label::paint (Graphics& g)
  37649. {
  37650. getLookAndFeel().drawLabel (g, *this);
  37651. }
  37652. void Label::mouseUp (const MouseEvent& e)
  37653. {
  37654. if (editSingleClick
  37655. && e.mouseWasClicked()
  37656. && contains (e.x, e.y)
  37657. && ! e.mods.isPopupMenu())
  37658. {
  37659. showEditor();
  37660. }
  37661. }
  37662. void Label::mouseDoubleClick (const MouseEvent& e)
  37663. {
  37664. if (editDoubleClick && ! e.mods.isPopupMenu())
  37665. showEditor();
  37666. }
  37667. void Label::resized()
  37668. {
  37669. if (editor != 0)
  37670. editor->setBoundsInset (BorderSize (0));
  37671. }
  37672. void Label::focusGained (FocusChangeType cause)
  37673. {
  37674. if (editSingleClick && cause == focusChangedByTabKey)
  37675. showEditor();
  37676. }
  37677. void Label::enablementChanged()
  37678. {
  37679. repaint();
  37680. }
  37681. void Label::colourChanged()
  37682. {
  37683. repaint();
  37684. }
  37685. void Label::setMinimumHorizontalScale (const float newScale)
  37686. {
  37687. if (minimumHorizontalScale != newScale)
  37688. {
  37689. minimumHorizontalScale = newScale;
  37690. repaint();
  37691. }
  37692. }
  37693. // We'll use a custom focus traverser here to make sure focus goes from the
  37694. // text editor to another component rather than back to the label itself.
  37695. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37696. {
  37697. public:
  37698. LabelKeyboardFocusTraverser() {}
  37699. Component* getNextComponent (Component* current)
  37700. {
  37701. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37702. ? current->getParentComponent() : current);
  37703. }
  37704. Component* getPreviousComponent (Component* current)
  37705. {
  37706. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37707. ? current->getParentComponent() : current);
  37708. }
  37709. };
  37710. KeyboardFocusTraverser* Label::createFocusTraverser()
  37711. {
  37712. return new LabelKeyboardFocusTraverser();
  37713. }
  37714. void Label::addListener (LabelListener* const listener) throw()
  37715. {
  37716. listeners.add (listener);
  37717. }
  37718. void Label::removeListener (LabelListener* const listener) throw()
  37719. {
  37720. listeners.remove (listener);
  37721. }
  37722. void Label::callChangeListeners()
  37723. {
  37724. Component::BailOutChecker checker (this);
  37725. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37726. }
  37727. void Label::textEditorTextChanged (TextEditor& ed)
  37728. {
  37729. if (editor != 0)
  37730. {
  37731. jassert (&ed == editor);
  37732. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37733. {
  37734. if (lossOfFocusDiscardsChanges)
  37735. textEditorEscapeKeyPressed (ed);
  37736. else
  37737. textEditorReturnKeyPressed (ed);
  37738. }
  37739. }
  37740. }
  37741. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37742. {
  37743. if (editor != 0)
  37744. {
  37745. jassert (&ed == editor);
  37746. (void) ed;
  37747. const bool changed = updateFromTextEditorContents();
  37748. hideEditor (true);
  37749. if (changed)
  37750. {
  37751. Component::SafePointer<Component> deletionChecker (this);
  37752. textWasEdited();
  37753. if (deletionChecker != 0)
  37754. callChangeListeners();
  37755. }
  37756. }
  37757. }
  37758. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37759. {
  37760. if (editor != 0)
  37761. {
  37762. jassert (&ed == editor);
  37763. (void) ed;
  37764. editor->setText (textValue.toString(), false);
  37765. hideEditor (true);
  37766. }
  37767. }
  37768. void Label::textEditorFocusLost (TextEditor& ed)
  37769. {
  37770. textEditorTextChanged (ed);
  37771. }
  37772. END_JUCE_NAMESPACE
  37773. /*** End of inlined file: juce_Label.cpp ***/
  37774. /*** Start of inlined file: juce_ListBox.cpp ***/
  37775. BEGIN_JUCE_NAMESPACE
  37776. class ListBoxRowComponent : public Component,
  37777. public TooltipClient
  37778. {
  37779. public:
  37780. ListBoxRowComponent (ListBox& owner_)
  37781. : owner (owner_),
  37782. row (-1),
  37783. selected (false),
  37784. isDragging (false)
  37785. {
  37786. }
  37787. ~ListBoxRowComponent()
  37788. {
  37789. deleteAllChildren();
  37790. }
  37791. void paint (Graphics& g)
  37792. {
  37793. if (owner.getModel() != 0)
  37794. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37795. }
  37796. void update (const int row_, const bool selected_)
  37797. {
  37798. if (row != row_ || selected != selected_)
  37799. {
  37800. repaint();
  37801. row = row_;
  37802. selected = selected_;
  37803. }
  37804. if (owner.getModel() != 0)
  37805. {
  37806. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37807. if (customComp != 0)
  37808. {
  37809. addAndMakeVisible (customComp);
  37810. customComp->setBounds (0, 0, getWidth(), getHeight());
  37811. for (int i = getNumChildComponents(); --i >= 0;)
  37812. if (getChildComponent (i) != customComp)
  37813. delete getChildComponent (i);
  37814. }
  37815. else
  37816. {
  37817. deleteAllChildren();
  37818. }
  37819. }
  37820. }
  37821. void mouseDown (const MouseEvent& e)
  37822. {
  37823. isDragging = false;
  37824. selectRowOnMouseUp = false;
  37825. if (isEnabled())
  37826. {
  37827. if (! selected)
  37828. {
  37829. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37830. if (owner.getModel() != 0)
  37831. owner.getModel()->listBoxItemClicked (row, e);
  37832. }
  37833. else
  37834. {
  37835. selectRowOnMouseUp = true;
  37836. }
  37837. }
  37838. }
  37839. void mouseUp (const MouseEvent& e)
  37840. {
  37841. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37842. {
  37843. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37844. if (owner.getModel() != 0)
  37845. owner.getModel()->listBoxItemClicked (row, e);
  37846. }
  37847. }
  37848. void mouseDoubleClick (const MouseEvent& e)
  37849. {
  37850. if (owner.getModel() != 0 && isEnabled())
  37851. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37852. }
  37853. void mouseDrag (const MouseEvent& e)
  37854. {
  37855. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37856. {
  37857. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37858. if (selectedRows.size() > 0)
  37859. {
  37860. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37861. if (dragDescription.isNotEmpty())
  37862. {
  37863. isDragging = true;
  37864. owner.startDragAndDrop (e, dragDescription);
  37865. }
  37866. }
  37867. }
  37868. }
  37869. void resized()
  37870. {
  37871. if (getNumChildComponents() > 0)
  37872. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37873. }
  37874. const String getTooltip()
  37875. {
  37876. if (owner.getModel() != 0)
  37877. return owner.getModel()->getTooltipForRow (row);
  37878. return String::empty;
  37879. }
  37880. juce_UseDebuggingNewOperator
  37881. bool neededFlag;
  37882. private:
  37883. ListBox& owner;
  37884. int row;
  37885. bool selected, isDragging, selectRowOnMouseUp;
  37886. ListBoxRowComponent (const ListBoxRowComponent&);
  37887. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37888. };
  37889. class ListViewport : public Viewport
  37890. {
  37891. public:
  37892. int firstIndex, firstWholeIndex, lastWholeIndex;
  37893. bool hasUpdated;
  37894. ListViewport (ListBox& owner_)
  37895. : owner (owner_)
  37896. {
  37897. setWantsKeyboardFocus (false);
  37898. setViewedComponent (new Component());
  37899. getViewedComponent()->addMouseListener (this, false);
  37900. getViewedComponent()->setWantsKeyboardFocus (false);
  37901. }
  37902. ~ListViewport()
  37903. {
  37904. getViewedComponent()->removeMouseListener (this);
  37905. getViewedComponent()->deleteAllChildren();
  37906. }
  37907. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37908. {
  37909. return static_cast <ListBoxRowComponent*>
  37910. (getViewedComponent()->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents())));
  37911. }
  37912. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37913. {
  37914. const int index = getIndexOfChildComponent (rowComponent);
  37915. const int num = getViewedComponent()->getNumChildComponents();
  37916. for (int i = num; --i >= 0;)
  37917. if (((firstIndex + i) % jmax (1, num)) == index)
  37918. return firstIndex + i;
  37919. return -1;
  37920. }
  37921. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37922. {
  37923. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37924. ? getComponentForRow (row) : 0;
  37925. }
  37926. void visibleAreaChanged (int, int, int, int)
  37927. {
  37928. updateVisibleArea (true);
  37929. if (owner.getModel() != 0)
  37930. owner.getModel()->listWasScrolled();
  37931. }
  37932. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37933. {
  37934. hasUpdated = false;
  37935. const int newX = getViewedComponent()->getX();
  37936. int newY = getViewedComponent()->getY();
  37937. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37938. const int newH = owner.totalItems * owner.getRowHeight();
  37939. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37940. newY = getMaximumVisibleHeight() - newH;
  37941. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37942. if (makeSureItUpdatesContent && ! hasUpdated)
  37943. updateContents();
  37944. }
  37945. void updateContents()
  37946. {
  37947. hasUpdated = true;
  37948. const int rowHeight = owner.getRowHeight();
  37949. if (rowHeight > 0)
  37950. {
  37951. const int y = getViewPositionY();
  37952. const int w = getViewedComponent()->getWidth();
  37953. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37954. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37955. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37956. jassert (numNeeded >= 0);
  37957. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37958. {
  37959. Component* const rowToRemove
  37960. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37961. delete rowToRemove;
  37962. }
  37963. firstIndex = y / rowHeight;
  37964. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37965. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37966. for (int i = 0; i < numNeeded; ++i)
  37967. {
  37968. const int row = i + firstIndex;
  37969. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37970. if (rowComp != 0)
  37971. {
  37972. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37973. rowComp->update (row, owner.isRowSelected (row));
  37974. }
  37975. }
  37976. }
  37977. if (owner.headerComponent != 0)
  37978. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37979. owner.outlineThickness,
  37980. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37981. getViewedComponent()->getWidth()),
  37982. owner.headerComponent->getHeight());
  37983. }
  37984. void paint (Graphics& g)
  37985. {
  37986. if (isOpaque())
  37987. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37988. }
  37989. bool keyPressed (const KeyPress& key)
  37990. {
  37991. if (key.isKeyCode (KeyPress::upKey)
  37992. || key.isKeyCode (KeyPress::downKey)
  37993. || key.isKeyCode (KeyPress::pageUpKey)
  37994. || key.isKeyCode (KeyPress::pageDownKey)
  37995. || key.isKeyCode (KeyPress::homeKey)
  37996. || key.isKeyCode (KeyPress::endKey))
  37997. {
  37998. // we want to avoid these keypresses going to the viewport, and instead allow
  37999. // them to pass up to our listbox..
  38000. return false;
  38001. }
  38002. return Viewport::keyPressed (key);
  38003. }
  38004. juce_UseDebuggingNewOperator
  38005. private:
  38006. ListBox& owner;
  38007. ListViewport (const ListViewport&);
  38008. ListViewport& operator= (const ListViewport&);
  38009. };
  38010. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38011. : Component (name),
  38012. model (model_),
  38013. headerComponent (0),
  38014. totalItems (0),
  38015. rowHeight (22),
  38016. minimumRowWidth (0),
  38017. outlineThickness (0),
  38018. lastRowSelected (-1),
  38019. mouseMoveSelects (false),
  38020. multipleSelection (false),
  38021. hasDoneInitialUpdate (false)
  38022. {
  38023. addAndMakeVisible (viewport = new ListViewport (*this));
  38024. setWantsKeyboardFocus (true);
  38025. colourChanged();
  38026. }
  38027. ListBox::~ListBox()
  38028. {
  38029. deleteAllChildren();
  38030. }
  38031. void ListBox::setModel (ListBoxModel* const newModel)
  38032. {
  38033. if (model != newModel)
  38034. {
  38035. model = newModel;
  38036. updateContent();
  38037. }
  38038. }
  38039. void ListBox::setMultipleSelectionEnabled (bool b)
  38040. {
  38041. multipleSelection = b;
  38042. }
  38043. void ListBox::setMouseMoveSelectsRows (bool b)
  38044. {
  38045. mouseMoveSelects = b;
  38046. if (b)
  38047. addMouseListener (this, true);
  38048. }
  38049. void ListBox::paint (Graphics& g)
  38050. {
  38051. if (! hasDoneInitialUpdate)
  38052. updateContent();
  38053. g.fillAll (findColour (backgroundColourId));
  38054. }
  38055. void ListBox::paintOverChildren (Graphics& g)
  38056. {
  38057. if (outlineThickness > 0)
  38058. {
  38059. g.setColour (findColour (outlineColourId));
  38060. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38061. }
  38062. }
  38063. void ListBox::resized()
  38064. {
  38065. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38066. outlineThickness,
  38067. outlineThickness,
  38068. outlineThickness));
  38069. viewport->setSingleStepSizes (20, getRowHeight());
  38070. viewport->updateVisibleArea (false);
  38071. }
  38072. void ListBox::visibilityChanged()
  38073. {
  38074. viewport->updateVisibleArea (true);
  38075. }
  38076. Viewport* ListBox::getViewport() const throw()
  38077. {
  38078. return viewport;
  38079. }
  38080. void ListBox::updateContent()
  38081. {
  38082. hasDoneInitialUpdate = true;
  38083. totalItems = (model != 0) ? model->getNumRows() : 0;
  38084. bool selectionChanged = false;
  38085. if (selected [selected.size() - 1] >= totalItems)
  38086. {
  38087. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38088. lastRowSelected = getSelectedRow (0);
  38089. selectionChanged = true;
  38090. }
  38091. viewport->updateVisibleArea (isVisible());
  38092. viewport->resized();
  38093. if (selectionChanged && model != 0)
  38094. model->selectedRowsChanged (lastRowSelected);
  38095. }
  38096. void ListBox::selectRow (const int row,
  38097. bool dontScroll,
  38098. bool deselectOthersFirst)
  38099. {
  38100. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38101. }
  38102. void ListBox::selectRowInternal (const int row,
  38103. bool dontScroll,
  38104. bool deselectOthersFirst,
  38105. bool isMouseClick)
  38106. {
  38107. if (! multipleSelection)
  38108. deselectOthersFirst = true;
  38109. if ((! isRowSelected (row))
  38110. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38111. {
  38112. if (((unsigned int) row) < (unsigned int) totalItems)
  38113. {
  38114. if (deselectOthersFirst)
  38115. selected.clear();
  38116. selected.addRange (row, 1);
  38117. if (getHeight() == 0 || getWidth() == 0)
  38118. dontScroll = true;
  38119. viewport->hasUpdated = false;
  38120. if (row < viewport->firstWholeIndex && ! dontScroll)
  38121. {
  38122. viewport->setViewPosition (viewport->getViewPositionX(),
  38123. row * getRowHeight());
  38124. }
  38125. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38126. {
  38127. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38128. if (row >= lastRowSelected + rowsOnScreen
  38129. && rowsOnScreen < totalItems - 1
  38130. && ! isMouseClick)
  38131. {
  38132. viewport->setViewPosition (viewport->getViewPositionX(),
  38133. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38134. * getRowHeight());
  38135. }
  38136. else
  38137. {
  38138. viewport->setViewPosition (viewport->getViewPositionX(),
  38139. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38140. }
  38141. }
  38142. if (! viewport->hasUpdated)
  38143. viewport->updateContents();
  38144. lastRowSelected = row;
  38145. model->selectedRowsChanged (row);
  38146. }
  38147. else
  38148. {
  38149. if (deselectOthersFirst)
  38150. deselectAllRows();
  38151. }
  38152. }
  38153. }
  38154. void ListBox::deselectRow (const int row)
  38155. {
  38156. if (selected.contains (row))
  38157. {
  38158. selected.removeRange (row, 1);
  38159. if (row == lastRowSelected)
  38160. lastRowSelected = getSelectedRow (0);
  38161. viewport->updateContents();
  38162. model->selectedRowsChanged (lastRowSelected);
  38163. }
  38164. }
  38165. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38166. const bool sendNotificationEventToModel)
  38167. {
  38168. selected = setOfRowsToBeSelected;
  38169. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38170. if (! isRowSelected (lastRowSelected))
  38171. lastRowSelected = getSelectedRow (0);
  38172. viewport->updateContents();
  38173. if ((model != 0) && sendNotificationEventToModel)
  38174. model->selectedRowsChanged (lastRowSelected);
  38175. }
  38176. const SparseSet<int> ListBox::getSelectedRows() const
  38177. {
  38178. return selected;
  38179. }
  38180. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38181. {
  38182. if (multipleSelection && (firstRow != lastRow))
  38183. {
  38184. const int numRows = totalItems - 1;
  38185. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38186. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38187. selected.addRange (jmin (firstRow, lastRow),
  38188. abs (firstRow - lastRow) + 1);
  38189. selected.removeRange (lastRow, 1);
  38190. }
  38191. selectRowInternal (lastRow, false, false, true);
  38192. }
  38193. void ListBox::flipRowSelection (const int row)
  38194. {
  38195. if (isRowSelected (row))
  38196. deselectRow (row);
  38197. else
  38198. selectRowInternal (row, false, false, true);
  38199. }
  38200. void ListBox::deselectAllRows()
  38201. {
  38202. if (! selected.isEmpty())
  38203. {
  38204. selected.clear();
  38205. lastRowSelected = -1;
  38206. viewport->updateContents();
  38207. if (model != 0)
  38208. model->selectedRowsChanged (lastRowSelected);
  38209. }
  38210. }
  38211. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38212. const ModifierKeys& mods)
  38213. {
  38214. if (multipleSelection && mods.isCommandDown())
  38215. {
  38216. flipRowSelection (row);
  38217. }
  38218. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38219. {
  38220. selectRangeOfRows (lastRowSelected, row);
  38221. }
  38222. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38223. {
  38224. selectRowInternal (row, false, true, true);
  38225. }
  38226. }
  38227. int ListBox::getNumSelectedRows() const
  38228. {
  38229. return selected.size();
  38230. }
  38231. int ListBox::getSelectedRow (const int index) const
  38232. {
  38233. return (((unsigned int) index) < (unsigned int) selected.size())
  38234. ? selected [index] : -1;
  38235. }
  38236. bool ListBox::isRowSelected (const int row) const
  38237. {
  38238. return selected.contains (row);
  38239. }
  38240. int ListBox::getLastRowSelected() const
  38241. {
  38242. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38243. }
  38244. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38245. {
  38246. if (((unsigned int) x) < (unsigned int) getWidth())
  38247. {
  38248. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38249. if (((unsigned int) row) < (unsigned int) totalItems)
  38250. return row;
  38251. }
  38252. return -1;
  38253. }
  38254. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38255. {
  38256. if (((unsigned int) x) < (unsigned int) getWidth())
  38257. {
  38258. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38259. return jlimit (0, totalItems, row);
  38260. }
  38261. return -1;
  38262. }
  38263. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38264. {
  38265. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38266. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38267. }
  38268. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38269. {
  38270. return viewport->getRowNumberOfComponent (rowComponent);
  38271. }
  38272. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38273. const bool relativeToComponentTopLeft) const throw()
  38274. {
  38275. const int rowHeight = getRowHeight();
  38276. int y = viewport->getY() + rowHeight * rowNumber;
  38277. if (relativeToComponentTopLeft)
  38278. y -= viewport->getViewPositionY();
  38279. return Rectangle<int> (viewport->getX(), y,
  38280. viewport->getViewedComponent()->getWidth(), rowHeight);
  38281. }
  38282. void ListBox::setVerticalPosition (const double proportion)
  38283. {
  38284. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38285. viewport->setViewPosition (viewport->getViewPositionX(),
  38286. jmax (0, roundToInt (proportion * offscreen)));
  38287. }
  38288. double ListBox::getVerticalPosition() const
  38289. {
  38290. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38291. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38292. : 0;
  38293. }
  38294. int ListBox::getVisibleRowWidth() const throw()
  38295. {
  38296. return viewport->getViewWidth();
  38297. }
  38298. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38299. {
  38300. if (row < viewport->firstWholeIndex)
  38301. {
  38302. viewport->setViewPosition (viewport->getViewPositionX(),
  38303. row * getRowHeight());
  38304. }
  38305. else if (row >= viewport->lastWholeIndex)
  38306. {
  38307. viewport->setViewPosition (viewport->getViewPositionX(),
  38308. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38309. }
  38310. }
  38311. bool ListBox::keyPressed (const KeyPress& key)
  38312. {
  38313. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38314. const bool multiple = multipleSelection
  38315. && (lastRowSelected >= 0)
  38316. && (key.getModifiers().isShiftDown()
  38317. || key.getModifiers().isCtrlDown()
  38318. || key.getModifiers().isCommandDown());
  38319. if (key.isKeyCode (KeyPress::upKey))
  38320. {
  38321. if (multiple)
  38322. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38323. else
  38324. selectRow (jmax (0, lastRowSelected - 1));
  38325. }
  38326. else if (key.isKeyCode (KeyPress::returnKey)
  38327. && isRowSelected (lastRowSelected))
  38328. {
  38329. if (model != 0)
  38330. model->returnKeyPressed (lastRowSelected);
  38331. }
  38332. else if (key.isKeyCode (KeyPress::pageUpKey))
  38333. {
  38334. if (multiple)
  38335. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38336. else
  38337. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38338. }
  38339. else if (key.isKeyCode (KeyPress::pageDownKey))
  38340. {
  38341. if (multiple)
  38342. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38343. else
  38344. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38345. }
  38346. else if (key.isKeyCode (KeyPress::homeKey))
  38347. {
  38348. if (multiple && key.getModifiers().isShiftDown())
  38349. selectRangeOfRows (lastRowSelected, 0);
  38350. else
  38351. selectRow (0);
  38352. }
  38353. else if (key.isKeyCode (KeyPress::endKey))
  38354. {
  38355. if (multiple && key.getModifiers().isShiftDown())
  38356. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38357. else
  38358. selectRow (totalItems - 1);
  38359. }
  38360. else if (key.isKeyCode (KeyPress::downKey))
  38361. {
  38362. if (multiple)
  38363. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38364. else
  38365. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38366. }
  38367. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38368. && isRowSelected (lastRowSelected))
  38369. {
  38370. if (model != 0)
  38371. model->deleteKeyPressed (lastRowSelected);
  38372. }
  38373. else if (multiple && key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  38374. {
  38375. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38376. }
  38377. else
  38378. {
  38379. return false;
  38380. }
  38381. return true;
  38382. }
  38383. bool ListBox::keyStateChanged (const bool isKeyDown)
  38384. {
  38385. return isKeyDown
  38386. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38387. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38388. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38389. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38390. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38391. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38392. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38393. }
  38394. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38395. {
  38396. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38397. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38398. }
  38399. void ListBox::mouseMove (const MouseEvent& e)
  38400. {
  38401. if (mouseMoveSelects)
  38402. {
  38403. const MouseEvent e2 (e.getEventRelativeTo (this));
  38404. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38405. }
  38406. }
  38407. void ListBox::mouseExit (const MouseEvent& e)
  38408. {
  38409. mouseMove (e);
  38410. }
  38411. void ListBox::mouseUp (const MouseEvent& e)
  38412. {
  38413. if (e.mouseWasClicked() && model != 0)
  38414. model->backgroundClicked();
  38415. }
  38416. void ListBox::setRowHeight (const int newHeight)
  38417. {
  38418. rowHeight = jmax (1, newHeight);
  38419. viewport->setSingleStepSizes (20, rowHeight);
  38420. updateContent();
  38421. }
  38422. int ListBox::getNumRowsOnScreen() const throw()
  38423. {
  38424. return viewport->getMaximumVisibleHeight() / rowHeight;
  38425. }
  38426. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38427. {
  38428. minimumRowWidth = newMinimumWidth;
  38429. updateContent();
  38430. }
  38431. int ListBox::getVisibleContentWidth() const throw()
  38432. {
  38433. return viewport->getMaximumVisibleWidth();
  38434. }
  38435. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38436. {
  38437. return viewport->getVerticalScrollBar();
  38438. }
  38439. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38440. {
  38441. return viewport->getHorizontalScrollBar();
  38442. }
  38443. void ListBox::colourChanged()
  38444. {
  38445. setOpaque (findColour (backgroundColourId).isOpaque());
  38446. viewport->setOpaque (isOpaque());
  38447. repaint();
  38448. }
  38449. void ListBox::setOutlineThickness (const int outlineThickness_)
  38450. {
  38451. outlineThickness = outlineThickness_;
  38452. resized();
  38453. }
  38454. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38455. {
  38456. if (headerComponent != newHeaderComponent)
  38457. {
  38458. delete headerComponent;
  38459. headerComponent = newHeaderComponent;
  38460. addAndMakeVisible (newHeaderComponent);
  38461. ListBox::resized();
  38462. }
  38463. }
  38464. void ListBox::repaintRow (const int rowNumber) throw()
  38465. {
  38466. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38467. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38468. }
  38469. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38470. {
  38471. Rectangle<int> imageArea;
  38472. const int firstRow = getRowContainingPosition (0, 0);
  38473. int i;
  38474. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38475. {
  38476. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38477. if (rowComp != 0 && isRowSelected (firstRow + i))
  38478. {
  38479. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38480. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38481. if (imageArea.isEmpty())
  38482. imageArea = rowRect;
  38483. else
  38484. imageArea = imageArea.getUnion (rowRect);
  38485. }
  38486. }
  38487. imageArea = imageArea.getIntersection (getLocalBounds());
  38488. imageX = imageArea.getX();
  38489. imageY = imageArea.getY();
  38490. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38491. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38492. {
  38493. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38494. if (rowComp != 0 && isRowSelected (firstRow + i))
  38495. {
  38496. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38497. Graphics g (*snapshot);
  38498. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38499. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38500. rowComp->paintEntireComponent (g);
  38501. }
  38502. }
  38503. return snapshot;
  38504. }
  38505. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38506. {
  38507. DragAndDropContainer* const dragContainer
  38508. = DragAndDropContainer::findParentDragContainerFor (this);
  38509. if (dragContainer != 0)
  38510. {
  38511. int x, y;
  38512. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38513. dragImage->multiplyAllAlphas (0.6f);
  38514. MouseEvent e2 (e.getEventRelativeTo (this));
  38515. const Point<int> p (x - e2.x, y - e2.y);
  38516. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38517. }
  38518. else
  38519. {
  38520. // to be able to do a drag-and-drop operation, the listbox needs to
  38521. // be inside a component which is also a DragAndDropContainer.
  38522. jassertfalse
  38523. }
  38524. }
  38525. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38526. {
  38527. (void) existingComponentToUpdate;
  38528. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38529. return 0;
  38530. }
  38531. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38532. {
  38533. }
  38534. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38535. {
  38536. }
  38537. void ListBoxModel::backgroundClicked()
  38538. {
  38539. }
  38540. void ListBoxModel::selectedRowsChanged (int)
  38541. {
  38542. }
  38543. void ListBoxModel::deleteKeyPressed (int)
  38544. {
  38545. }
  38546. void ListBoxModel::returnKeyPressed (int)
  38547. {
  38548. }
  38549. void ListBoxModel::listWasScrolled()
  38550. {
  38551. }
  38552. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38553. {
  38554. return String::empty;
  38555. }
  38556. const String ListBoxModel::getTooltipForRow (int)
  38557. {
  38558. return String::empty;
  38559. }
  38560. END_JUCE_NAMESPACE
  38561. /*** End of inlined file: juce_ListBox.cpp ***/
  38562. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38563. BEGIN_JUCE_NAMESPACE
  38564. ProgressBar::ProgressBar (double& progress_)
  38565. : progress (progress_),
  38566. displayPercentage (true),
  38567. lastCallbackTime (0)
  38568. {
  38569. currentValue = jlimit (0.0, 1.0, progress);
  38570. }
  38571. ProgressBar::~ProgressBar()
  38572. {
  38573. }
  38574. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38575. {
  38576. displayPercentage = shouldDisplayPercentage;
  38577. repaint();
  38578. }
  38579. void ProgressBar::setTextToDisplay (const String& text)
  38580. {
  38581. displayPercentage = false;
  38582. displayedMessage = text;
  38583. }
  38584. void ProgressBar::lookAndFeelChanged()
  38585. {
  38586. setOpaque (findColour (backgroundColourId).isOpaque());
  38587. }
  38588. void ProgressBar::colourChanged()
  38589. {
  38590. lookAndFeelChanged();
  38591. }
  38592. void ProgressBar::paint (Graphics& g)
  38593. {
  38594. String text;
  38595. if (displayPercentage)
  38596. {
  38597. if (currentValue >= 0 && currentValue <= 1.0)
  38598. text << roundToInt (currentValue * 100.0) << '%';
  38599. }
  38600. else
  38601. {
  38602. text = displayedMessage;
  38603. }
  38604. getLookAndFeel().drawProgressBar (g, *this,
  38605. getWidth(), getHeight(),
  38606. currentValue, text);
  38607. }
  38608. void ProgressBar::visibilityChanged()
  38609. {
  38610. if (isVisible())
  38611. startTimer (30);
  38612. else
  38613. stopTimer();
  38614. }
  38615. void ProgressBar::timerCallback()
  38616. {
  38617. double newProgress = progress;
  38618. const uint32 now = Time::getMillisecondCounter();
  38619. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38620. lastCallbackTime = now;
  38621. if (currentValue != newProgress
  38622. || newProgress < 0 || newProgress >= 1.0
  38623. || currentMessage != displayedMessage)
  38624. {
  38625. if (currentValue < newProgress
  38626. && newProgress >= 0 && newProgress < 1.0
  38627. && currentValue >= 0 && currentValue < 1.0)
  38628. {
  38629. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38630. newProgress);
  38631. }
  38632. currentValue = newProgress;
  38633. currentMessage = displayedMessage;
  38634. repaint();
  38635. }
  38636. }
  38637. END_JUCE_NAMESPACE
  38638. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38639. /*** Start of inlined file: juce_Slider.cpp ***/
  38640. BEGIN_JUCE_NAMESPACE
  38641. class SliderPopupDisplayComponent : public BubbleComponent
  38642. {
  38643. public:
  38644. SliderPopupDisplayComponent (Slider* const owner_)
  38645. : owner (owner_),
  38646. font (15.0f, Font::bold)
  38647. {
  38648. setAlwaysOnTop (true);
  38649. }
  38650. ~SliderPopupDisplayComponent()
  38651. {
  38652. }
  38653. void paintContent (Graphics& g, int w, int h)
  38654. {
  38655. g.setFont (font);
  38656. g.setColour (Colours::black);
  38657. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38658. }
  38659. void getContentSize (int& w, int& h)
  38660. {
  38661. w = font.getStringWidth (text) + 18;
  38662. h = (int) (font.getHeight() * 1.6f);
  38663. }
  38664. void updatePosition (const String& newText)
  38665. {
  38666. if (text != newText)
  38667. {
  38668. text = newText;
  38669. repaint();
  38670. }
  38671. BubbleComponent::setPosition (owner);
  38672. }
  38673. juce_UseDebuggingNewOperator
  38674. private:
  38675. Slider* owner;
  38676. Font font;
  38677. String text;
  38678. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38679. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38680. };
  38681. Slider::Slider (const String& name)
  38682. : Component (name),
  38683. lastCurrentValue (0),
  38684. lastValueMin (0),
  38685. lastValueMax (0),
  38686. minimum (0),
  38687. maximum (10),
  38688. interval (0),
  38689. skewFactor (1.0),
  38690. velocityModeSensitivity (1.0),
  38691. velocityModeOffset (0.0),
  38692. velocityModeThreshold (1),
  38693. rotaryStart (float_Pi * 1.2f),
  38694. rotaryEnd (float_Pi * 2.8f),
  38695. numDecimalPlaces (7),
  38696. sliderRegionStart (0),
  38697. sliderRegionSize (1),
  38698. sliderBeingDragged (-1),
  38699. pixelsForFullDragExtent (250),
  38700. style (LinearHorizontal),
  38701. textBoxPos (TextBoxLeft),
  38702. textBoxWidth (80),
  38703. textBoxHeight (20),
  38704. incDecButtonMode (incDecButtonsNotDraggable),
  38705. editableText (true),
  38706. doubleClickToValue (false),
  38707. isVelocityBased (false),
  38708. userKeyOverridesVelocity (true),
  38709. rotaryStop (true),
  38710. incDecButtonsSideBySide (false),
  38711. sendChangeOnlyOnRelease (false),
  38712. popupDisplayEnabled (false),
  38713. menuEnabled (false),
  38714. menuShown (false),
  38715. scrollWheelEnabled (true),
  38716. snapsToMousePos (true),
  38717. valueBox (0),
  38718. incButton (0),
  38719. decButton (0),
  38720. popupDisplay (0),
  38721. parentForPopupDisplay (0)
  38722. {
  38723. setWantsKeyboardFocus (false);
  38724. setRepaintsOnMouseActivity (true);
  38725. lookAndFeelChanged();
  38726. updateText();
  38727. currentValue.addListener (this);
  38728. valueMin.addListener (this);
  38729. valueMax.addListener (this);
  38730. }
  38731. Slider::~Slider()
  38732. {
  38733. currentValue.removeListener (this);
  38734. valueMin.removeListener (this);
  38735. valueMax.removeListener (this);
  38736. popupDisplay = 0;
  38737. deleteAllChildren();
  38738. }
  38739. void Slider::handleAsyncUpdate()
  38740. {
  38741. cancelPendingUpdate();
  38742. Component::BailOutChecker checker (this);
  38743. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38744. }
  38745. void Slider::sendDragStart()
  38746. {
  38747. startedDragging();
  38748. Component::BailOutChecker checker (this);
  38749. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38750. }
  38751. void Slider::sendDragEnd()
  38752. {
  38753. stoppedDragging();
  38754. sliderBeingDragged = -1;
  38755. Component::BailOutChecker checker (this);
  38756. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38757. }
  38758. void Slider::addListener (SliderListener* const listener)
  38759. {
  38760. listeners.add (listener);
  38761. }
  38762. void Slider::removeListener (SliderListener* const listener)
  38763. {
  38764. listeners.remove (listener);
  38765. }
  38766. void Slider::setSliderStyle (const SliderStyle newStyle)
  38767. {
  38768. if (style != newStyle)
  38769. {
  38770. style = newStyle;
  38771. repaint();
  38772. lookAndFeelChanged();
  38773. }
  38774. }
  38775. void Slider::setRotaryParameters (const float startAngleRadians,
  38776. const float endAngleRadians,
  38777. const bool stopAtEnd)
  38778. {
  38779. // make sure the values are sensible..
  38780. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38781. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38782. jassert (rotaryStart < rotaryEnd);
  38783. rotaryStart = startAngleRadians;
  38784. rotaryEnd = endAngleRadians;
  38785. rotaryStop = stopAtEnd;
  38786. }
  38787. void Slider::setVelocityBasedMode (const bool velBased)
  38788. {
  38789. isVelocityBased = velBased;
  38790. }
  38791. void Slider::setVelocityModeParameters (const double sensitivity,
  38792. const int threshold,
  38793. const double offset,
  38794. const bool userCanPressKeyToSwapMode)
  38795. {
  38796. jassert (threshold >= 0);
  38797. jassert (sensitivity > 0);
  38798. jassert (offset >= 0);
  38799. velocityModeSensitivity = sensitivity;
  38800. velocityModeOffset = offset;
  38801. velocityModeThreshold = threshold;
  38802. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38803. }
  38804. void Slider::setSkewFactor (const double factor)
  38805. {
  38806. skewFactor = factor;
  38807. }
  38808. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38809. {
  38810. if (maximum > minimum)
  38811. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38812. / (maximum - minimum));
  38813. }
  38814. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38815. {
  38816. jassert (distanceForFullScaleDrag > 0);
  38817. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38818. }
  38819. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38820. {
  38821. if (incDecButtonMode != mode)
  38822. {
  38823. incDecButtonMode = mode;
  38824. lookAndFeelChanged();
  38825. }
  38826. }
  38827. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38828. const bool isReadOnly,
  38829. const int textEntryBoxWidth,
  38830. const int textEntryBoxHeight)
  38831. {
  38832. textBoxPos = newPosition;
  38833. editableText = ! isReadOnly;
  38834. textBoxWidth = textEntryBoxWidth;
  38835. textBoxHeight = textEntryBoxHeight;
  38836. repaint();
  38837. lookAndFeelChanged();
  38838. }
  38839. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38840. {
  38841. editableText = shouldBeEditable;
  38842. if (valueBox != 0)
  38843. valueBox->setEditable (shouldBeEditable && isEnabled());
  38844. }
  38845. void Slider::showTextBox()
  38846. {
  38847. jassert (editableText); // this should probably be avoided in read-only sliders.
  38848. if (valueBox != 0)
  38849. valueBox->showEditor();
  38850. }
  38851. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38852. {
  38853. if (valueBox != 0)
  38854. {
  38855. valueBox->hideEditor (discardCurrentEditorContents);
  38856. if (discardCurrentEditorContents)
  38857. updateText();
  38858. }
  38859. }
  38860. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38861. {
  38862. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38863. }
  38864. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38865. {
  38866. snapsToMousePos = shouldSnapToMouse;
  38867. }
  38868. void Slider::setPopupDisplayEnabled (const bool enabled,
  38869. Component* const parentComponentToUse)
  38870. {
  38871. popupDisplayEnabled = enabled;
  38872. parentForPopupDisplay = parentComponentToUse;
  38873. }
  38874. void Slider::colourChanged()
  38875. {
  38876. lookAndFeelChanged();
  38877. }
  38878. void Slider::lookAndFeelChanged()
  38879. {
  38880. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38881. : getTextFromValue (currentValue.getValue()));
  38882. deleteAllChildren();
  38883. valueBox = 0;
  38884. LookAndFeel& lf = getLookAndFeel();
  38885. if (textBoxPos != NoTextBox)
  38886. {
  38887. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38888. valueBox->setWantsKeyboardFocus (false);
  38889. valueBox->setText (previousTextBoxContent, false);
  38890. valueBox->setEditable (editableText && isEnabled());
  38891. valueBox->addListener (this);
  38892. if (style == LinearBar)
  38893. valueBox->addMouseListener (this, false);
  38894. valueBox->setTooltip (getTooltip());
  38895. }
  38896. if (style == IncDecButtons)
  38897. {
  38898. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38899. incButton->addButtonListener (this);
  38900. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38901. decButton->addButtonListener (this);
  38902. if (incDecButtonMode != incDecButtonsNotDraggable)
  38903. {
  38904. incButton->addMouseListener (this, false);
  38905. decButton->addMouseListener (this, false);
  38906. }
  38907. else
  38908. {
  38909. incButton->setRepeatSpeed (300, 100, 20);
  38910. incButton->addMouseListener (decButton, false);
  38911. decButton->setRepeatSpeed (300, 100, 20);
  38912. decButton->addMouseListener (incButton, false);
  38913. }
  38914. incButton->setTooltip (getTooltip());
  38915. decButton->setTooltip (getTooltip());
  38916. }
  38917. setComponentEffect (lf.getSliderEffect());
  38918. resized();
  38919. repaint();
  38920. }
  38921. void Slider::setRange (const double newMin,
  38922. const double newMax,
  38923. const double newInt)
  38924. {
  38925. if (minimum != newMin
  38926. || maximum != newMax
  38927. || interval != newInt)
  38928. {
  38929. minimum = newMin;
  38930. maximum = newMax;
  38931. interval = newInt;
  38932. // figure out the number of DPs needed to display all values at this
  38933. // interval setting.
  38934. numDecimalPlaces = 7;
  38935. if (newInt != 0)
  38936. {
  38937. int v = abs ((int) (newInt * 10000000));
  38938. while ((v % 10) == 0)
  38939. {
  38940. --numDecimalPlaces;
  38941. v /= 10;
  38942. }
  38943. }
  38944. // keep the current values inside the new range..
  38945. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38946. {
  38947. setValue (getValue(), false, false);
  38948. }
  38949. else
  38950. {
  38951. setMinValue (getMinValue(), false, false);
  38952. setMaxValue (getMaxValue(), false, false);
  38953. }
  38954. updateText();
  38955. }
  38956. }
  38957. void Slider::triggerChangeMessage (const bool synchronous)
  38958. {
  38959. if (synchronous)
  38960. handleAsyncUpdate();
  38961. else
  38962. triggerAsyncUpdate();
  38963. valueChanged();
  38964. }
  38965. void Slider::valueChanged (Value& value)
  38966. {
  38967. if (value.refersToSameSourceAs (currentValue))
  38968. {
  38969. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38970. setValue (currentValue.getValue(), false, false);
  38971. }
  38972. else if (value.refersToSameSourceAs (valueMin))
  38973. setMinValue (valueMin.getValue(), false, false, true);
  38974. else if (value.refersToSameSourceAs (valueMax))
  38975. setMaxValue (valueMax.getValue(), false, false, true);
  38976. }
  38977. double Slider::getValue() const
  38978. {
  38979. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38980. // methods to get the two values.
  38981. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38982. return currentValue.getValue();
  38983. }
  38984. void Slider::setValue (double newValue,
  38985. const bool sendUpdateMessage,
  38986. const bool sendMessageSynchronously)
  38987. {
  38988. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38989. // methods to set the two values.
  38990. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38991. newValue = constrainedValue (newValue);
  38992. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38993. {
  38994. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38995. newValue = jlimit ((double) valueMin.getValue(),
  38996. (double) valueMax.getValue(),
  38997. newValue);
  38998. }
  38999. if (newValue != lastCurrentValue)
  39000. {
  39001. if (valueBox != 0)
  39002. valueBox->hideEditor (true);
  39003. lastCurrentValue = newValue;
  39004. currentValue = newValue;
  39005. updateText();
  39006. repaint();
  39007. if (popupDisplay != 0)
  39008. {
  39009. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39010. ->updatePosition (getTextFromValue (newValue));
  39011. popupDisplay->repaint();
  39012. }
  39013. if (sendUpdateMessage)
  39014. triggerChangeMessage (sendMessageSynchronously);
  39015. }
  39016. }
  39017. double Slider::getMinValue() const
  39018. {
  39019. // The minimum value only applies to sliders that are in two- or three-value mode.
  39020. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39021. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39022. return valueMin.getValue();
  39023. }
  39024. double Slider::getMaxValue() const
  39025. {
  39026. // The maximum value only applies to sliders that are in two- or three-value mode.
  39027. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39028. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39029. return valueMax.getValue();
  39030. }
  39031. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39032. {
  39033. // The minimum value only applies to sliders that are in two- or three-value mode.
  39034. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39035. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39036. newValue = constrainedValue (newValue);
  39037. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39038. {
  39039. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39040. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39041. newValue = jmin ((double) valueMax.getValue(), newValue);
  39042. }
  39043. else
  39044. {
  39045. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39046. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39047. newValue = jmin (lastCurrentValue, newValue);
  39048. }
  39049. if (lastValueMin != newValue)
  39050. {
  39051. lastValueMin = newValue;
  39052. valueMin = newValue;
  39053. repaint();
  39054. if (popupDisplay != 0)
  39055. {
  39056. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39057. ->updatePosition (getTextFromValue (newValue));
  39058. popupDisplay->repaint();
  39059. }
  39060. if (sendUpdateMessage)
  39061. triggerChangeMessage (sendMessageSynchronously);
  39062. }
  39063. }
  39064. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39065. {
  39066. // The maximum value only applies to sliders that are in two- or three-value mode.
  39067. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39068. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39069. newValue = constrainedValue (newValue);
  39070. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39071. {
  39072. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39073. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39074. newValue = jmax ((double) valueMin.getValue(), newValue);
  39075. }
  39076. else
  39077. {
  39078. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39079. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39080. newValue = jmax (lastCurrentValue, newValue);
  39081. }
  39082. if (lastValueMax != newValue)
  39083. {
  39084. lastValueMax = newValue;
  39085. valueMax = newValue;
  39086. repaint();
  39087. if (popupDisplay != 0)
  39088. {
  39089. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39090. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39091. popupDisplay->repaint();
  39092. }
  39093. if (sendUpdateMessage)
  39094. triggerChangeMessage (sendMessageSynchronously);
  39095. }
  39096. }
  39097. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39098. const double valueToSetOnDoubleClick)
  39099. {
  39100. doubleClickToValue = isDoubleClickEnabled;
  39101. doubleClickReturnValue = valueToSetOnDoubleClick;
  39102. }
  39103. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39104. {
  39105. isEnabled_ = doubleClickToValue;
  39106. return doubleClickReturnValue;
  39107. }
  39108. void Slider::updateText()
  39109. {
  39110. if (valueBox != 0)
  39111. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39112. }
  39113. void Slider::setTextValueSuffix (const String& suffix)
  39114. {
  39115. if (textSuffix != suffix)
  39116. {
  39117. textSuffix = suffix;
  39118. updateText();
  39119. }
  39120. }
  39121. const String Slider::getTextValueSuffix() const
  39122. {
  39123. return textSuffix;
  39124. }
  39125. const String Slider::getTextFromValue (double v)
  39126. {
  39127. if (getNumDecimalPlacesToDisplay() > 0)
  39128. return String (v, getNumDecimalPlacesToDisplay()) + getTextValueSuffix();
  39129. else
  39130. return String (roundToInt (v)) + getTextValueSuffix();
  39131. }
  39132. double Slider::getValueFromText (const String& text)
  39133. {
  39134. String t (text.trimStart());
  39135. if (t.endsWith (textSuffix))
  39136. t = t.substring (0, t.length() - textSuffix.length());
  39137. while (t.startsWithChar ('+'))
  39138. t = t.substring (1).trimStart();
  39139. return t.initialSectionContainingOnly ("0123456789.,-")
  39140. .getDoubleValue();
  39141. }
  39142. double Slider::proportionOfLengthToValue (double proportion)
  39143. {
  39144. if (skewFactor != 1.0 && proportion > 0.0)
  39145. proportion = exp (log (proportion) / skewFactor);
  39146. return minimum + (maximum - minimum) * proportion;
  39147. }
  39148. double Slider::valueToProportionOfLength (double value)
  39149. {
  39150. const double n = (value - minimum) / (maximum - minimum);
  39151. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39152. }
  39153. double Slider::snapValue (double attemptedValue, const bool)
  39154. {
  39155. return attemptedValue;
  39156. }
  39157. void Slider::startedDragging()
  39158. {
  39159. }
  39160. void Slider::stoppedDragging()
  39161. {
  39162. }
  39163. void Slider::valueChanged()
  39164. {
  39165. }
  39166. void Slider::enablementChanged()
  39167. {
  39168. repaint();
  39169. }
  39170. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39171. {
  39172. menuEnabled = menuEnabled_;
  39173. }
  39174. void Slider::setScrollWheelEnabled (const bool enabled)
  39175. {
  39176. scrollWheelEnabled = enabled;
  39177. }
  39178. void Slider::labelTextChanged (Label* label)
  39179. {
  39180. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39181. if (newValue != (double) currentValue.getValue())
  39182. {
  39183. sendDragStart();
  39184. setValue (newValue, true, true);
  39185. sendDragEnd();
  39186. }
  39187. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39188. }
  39189. void Slider::buttonClicked (Button* button)
  39190. {
  39191. if (style == IncDecButtons)
  39192. {
  39193. sendDragStart();
  39194. if (button == incButton)
  39195. setValue (snapValue (getValue() + interval, false), true, true);
  39196. else if (button == decButton)
  39197. setValue (snapValue (getValue() - interval, false), true, true);
  39198. sendDragEnd();
  39199. }
  39200. }
  39201. double Slider::constrainedValue (double value) const
  39202. {
  39203. if (interval > 0)
  39204. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39205. if (value <= minimum || maximum <= minimum)
  39206. value = minimum;
  39207. else if (value >= maximum)
  39208. value = maximum;
  39209. return value;
  39210. }
  39211. float Slider::getLinearSliderPos (const double value)
  39212. {
  39213. double sliderPosProportional;
  39214. if (maximum > minimum)
  39215. {
  39216. if (value < minimum)
  39217. {
  39218. sliderPosProportional = 0.0;
  39219. }
  39220. else if (value > maximum)
  39221. {
  39222. sliderPosProportional = 1.0;
  39223. }
  39224. else
  39225. {
  39226. sliderPosProportional = valueToProportionOfLength (value);
  39227. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39228. }
  39229. }
  39230. else
  39231. {
  39232. sliderPosProportional = 0.5;
  39233. }
  39234. if (isVertical() || style == IncDecButtons)
  39235. sliderPosProportional = 1.0 - sliderPosProportional;
  39236. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39237. }
  39238. bool Slider::isHorizontal() const
  39239. {
  39240. return style == LinearHorizontal
  39241. || style == LinearBar
  39242. || style == TwoValueHorizontal
  39243. || style == ThreeValueHorizontal;
  39244. }
  39245. bool Slider::isVertical() const
  39246. {
  39247. return style == LinearVertical
  39248. || style == TwoValueVertical
  39249. || style == ThreeValueVertical;
  39250. }
  39251. bool Slider::incDecDragDirectionIsHorizontal() const
  39252. {
  39253. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39254. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39255. }
  39256. float Slider::getPositionOfValue (const double value)
  39257. {
  39258. if (isHorizontal() || isVertical())
  39259. {
  39260. return getLinearSliderPos (value);
  39261. }
  39262. else
  39263. {
  39264. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39265. return 0.0f;
  39266. }
  39267. }
  39268. void Slider::paint (Graphics& g)
  39269. {
  39270. if (style != IncDecButtons)
  39271. {
  39272. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39273. {
  39274. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39275. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39276. getLookAndFeel().drawRotarySlider (g,
  39277. sliderRect.getX(),
  39278. sliderRect.getY(),
  39279. sliderRect.getWidth(),
  39280. sliderRect.getHeight(),
  39281. sliderPos,
  39282. rotaryStart, rotaryEnd,
  39283. *this);
  39284. }
  39285. else
  39286. {
  39287. getLookAndFeel().drawLinearSlider (g,
  39288. sliderRect.getX(),
  39289. sliderRect.getY(),
  39290. sliderRect.getWidth(),
  39291. sliderRect.getHeight(),
  39292. getLinearSliderPos (lastCurrentValue),
  39293. getLinearSliderPos (lastValueMin),
  39294. getLinearSliderPos (lastValueMax),
  39295. style,
  39296. *this);
  39297. }
  39298. if (style == LinearBar && valueBox == 0)
  39299. {
  39300. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39301. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39302. }
  39303. }
  39304. }
  39305. void Slider::resized()
  39306. {
  39307. int minXSpace = 0;
  39308. int minYSpace = 0;
  39309. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39310. minXSpace = 30;
  39311. else
  39312. minYSpace = 15;
  39313. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39314. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39315. if (style == LinearBar)
  39316. {
  39317. if (valueBox != 0)
  39318. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39319. }
  39320. else
  39321. {
  39322. if (textBoxPos == NoTextBox)
  39323. {
  39324. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39325. }
  39326. else if (textBoxPos == TextBoxLeft)
  39327. {
  39328. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39329. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39330. }
  39331. else if (textBoxPos == TextBoxRight)
  39332. {
  39333. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39334. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39335. }
  39336. else if (textBoxPos == TextBoxAbove)
  39337. {
  39338. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39339. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39340. }
  39341. else if (textBoxPos == TextBoxBelow)
  39342. {
  39343. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39344. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39345. }
  39346. }
  39347. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39348. if (style == LinearBar)
  39349. {
  39350. const int barIndent = 1;
  39351. sliderRegionStart = barIndent;
  39352. sliderRegionSize = getWidth() - barIndent * 2;
  39353. sliderRect.setBounds (sliderRegionStart, barIndent,
  39354. sliderRegionSize, getHeight() - barIndent * 2);
  39355. }
  39356. else if (isHorizontal())
  39357. {
  39358. sliderRegionStart = sliderRect.getX() + indent;
  39359. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39360. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39361. sliderRegionSize, sliderRect.getHeight());
  39362. }
  39363. else if (isVertical())
  39364. {
  39365. sliderRegionStart = sliderRect.getY() + indent;
  39366. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39367. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39368. sliderRect.getWidth(), sliderRegionSize);
  39369. }
  39370. else
  39371. {
  39372. sliderRegionStart = 0;
  39373. sliderRegionSize = 100;
  39374. }
  39375. if (style == IncDecButtons)
  39376. {
  39377. Rectangle<int> buttonRect (sliderRect);
  39378. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39379. buttonRect.expand (-2, 0);
  39380. else
  39381. buttonRect.expand (0, -2);
  39382. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39383. if (incDecButtonsSideBySide)
  39384. {
  39385. decButton->setBounds (buttonRect.getX(),
  39386. buttonRect.getY(),
  39387. buttonRect.getWidth() / 2,
  39388. buttonRect.getHeight());
  39389. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39390. incButton->setBounds (buttonRect.getCentreX(),
  39391. buttonRect.getY(),
  39392. buttonRect.getWidth() / 2,
  39393. buttonRect.getHeight());
  39394. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39395. }
  39396. else
  39397. {
  39398. incButton->setBounds (buttonRect.getX(),
  39399. buttonRect.getY(),
  39400. buttonRect.getWidth(),
  39401. buttonRect.getHeight() / 2);
  39402. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39403. decButton->setBounds (buttonRect.getX(),
  39404. buttonRect.getCentreY(),
  39405. buttonRect.getWidth(),
  39406. buttonRect.getHeight() / 2);
  39407. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39408. }
  39409. }
  39410. }
  39411. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39412. {
  39413. repaint();
  39414. }
  39415. void Slider::mouseDown (const MouseEvent& e)
  39416. {
  39417. mouseWasHidden = false;
  39418. incDecDragged = false;
  39419. mouseXWhenLastDragged = e.x;
  39420. mouseYWhenLastDragged = e.y;
  39421. mouseDragStartX = e.getMouseDownX();
  39422. mouseDragStartY = e.getMouseDownY();
  39423. if (isEnabled())
  39424. {
  39425. if (e.mods.isPopupMenu() && menuEnabled)
  39426. {
  39427. menuShown = true;
  39428. PopupMenu m;
  39429. m.setLookAndFeel (&getLookAndFeel());
  39430. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39431. m.addSeparator();
  39432. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39433. {
  39434. PopupMenu rotaryMenu;
  39435. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39436. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39437. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39438. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39439. }
  39440. const int r = m.show();
  39441. if (r == 1)
  39442. {
  39443. setVelocityBasedMode (! isVelocityBased);
  39444. }
  39445. else if (r == 2)
  39446. {
  39447. setSliderStyle (Rotary);
  39448. }
  39449. else if (r == 3)
  39450. {
  39451. setSliderStyle (RotaryHorizontalDrag);
  39452. }
  39453. else if (r == 4)
  39454. {
  39455. setSliderStyle (RotaryVerticalDrag);
  39456. }
  39457. }
  39458. else if (maximum > minimum)
  39459. {
  39460. menuShown = false;
  39461. if (valueBox != 0)
  39462. valueBox->hideEditor (true);
  39463. sliderBeingDragged = 0;
  39464. if (style == TwoValueHorizontal
  39465. || style == TwoValueVertical
  39466. || style == ThreeValueHorizontal
  39467. || style == ThreeValueVertical)
  39468. {
  39469. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39470. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39471. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39472. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39473. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39474. {
  39475. if (maxPosDistance <= minPosDistance)
  39476. sliderBeingDragged = 2;
  39477. else
  39478. sliderBeingDragged = 1;
  39479. }
  39480. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39481. {
  39482. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39483. sliderBeingDragged = 1;
  39484. else if (normalPosDistance >= maxPosDistance)
  39485. sliderBeingDragged = 2;
  39486. }
  39487. }
  39488. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39489. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39490. * valueToProportionOfLength (currentValue.getValue());
  39491. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39492. : ((sliderBeingDragged == 1) ? valueMin
  39493. : currentValue)).getValue();
  39494. valueOnMouseDown = valueWhenLastDragged;
  39495. if (popupDisplayEnabled)
  39496. {
  39497. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39498. popupDisplay = popup;
  39499. if (parentForPopupDisplay != 0)
  39500. {
  39501. parentForPopupDisplay->addChildComponent (popup);
  39502. }
  39503. else
  39504. {
  39505. popup->addToDesktop (0);
  39506. }
  39507. popup->setVisible (true);
  39508. }
  39509. sendDragStart();
  39510. mouseDrag (e);
  39511. }
  39512. }
  39513. }
  39514. void Slider::mouseUp (const MouseEvent&)
  39515. {
  39516. if (isEnabled()
  39517. && (! menuShown)
  39518. && (maximum > minimum)
  39519. && (style != IncDecButtons || incDecDragged))
  39520. {
  39521. restoreMouseIfHidden();
  39522. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39523. triggerChangeMessage (false);
  39524. sendDragEnd();
  39525. popupDisplay = 0;
  39526. if (style == IncDecButtons)
  39527. {
  39528. incButton->setState (Button::buttonNormal);
  39529. decButton->setState (Button::buttonNormal);
  39530. }
  39531. }
  39532. }
  39533. void Slider::restoreMouseIfHidden()
  39534. {
  39535. if (mouseWasHidden)
  39536. {
  39537. mouseWasHidden = false;
  39538. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39539. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39540. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39541. : ((sliderBeingDragged == 1) ? getMinValue()
  39542. : (double) currentValue.getValue());
  39543. Point<int> mousePos;
  39544. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39545. {
  39546. mousePos = Desktop::getLastMouseDownPosition();
  39547. if (style == RotaryHorizontalDrag)
  39548. {
  39549. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39550. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39551. }
  39552. else
  39553. {
  39554. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39555. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39556. }
  39557. }
  39558. else
  39559. {
  39560. const int pixelPos = (int) getLinearSliderPos (pos);
  39561. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39562. isVertical() ? pixelPos : (getHeight() / 2)));
  39563. }
  39564. Desktop::setMousePosition (mousePos);
  39565. }
  39566. }
  39567. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39568. {
  39569. if (isEnabled()
  39570. && style != IncDecButtons
  39571. && style != Rotary
  39572. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39573. {
  39574. restoreMouseIfHidden();
  39575. }
  39576. }
  39577. static double smallestAngleBetween (double a1, double a2)
  39578. {
  39579. return jmin (fabs (a1 - a2),
  39580. fabs (a1 + double_Pi * 2.0 - a2),
  39581. fabs (a2 + double_Pi * 2.0 - a1));
  39582. }
  39583. void Slider::mouseDrag (const MouseEvent& e)
  39584. {
  39585. if (isEnabled()
  39586. && (! menuShown)
  39587. && (maximum > minimum))
  39588. {
  39589. if (style == Rotary)
  39590. {
  39591. int dx = e.x - sliderRect.getCentreX();
  39592. int dy = e.y - sliderRect.getCentreY();
  39593. if (dx * dx + dy * dy > 25)
  39594. {
  39595. double angle = atan2 ((double) dx, (double) -dy);
  39596. while (angle < 0.0)
  39597. angle += double_Pi * 2.0;
  39598. if (rotaryStop && ! e.mouseWasClicked())
  39599. {
  39600. if (fabs (angle - lastAngle) > double_Pi)
  39601. {
  39602. if (angle >= lastAngle)
  39603. angle -= double_Pi * 2.0;
  39604. else
  39605. angle += double_Pi * 2.0;
  39606. }
  39607. if (angle >= lastAngle)
  39608. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39609. else
  39610. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39611. }
  39612. else
  39613. {
  39614. while (angle < rotaryStart)
  39615. angle += double_Pi * 2.0;
  39616. if (angle > rotaryEnd)
  39617. {
  39618. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39619. angle = rotaryStart;
  39620. else
  39621. angle = rotaryEnd;
  39622. }
  39623. }
  39624. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39625. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39626. lastAngle = angle;
  39627. }
  39628. }
  39629. else
  39630. {
  39631. if (style == LinearBar && e.mouseWasClicked()
  39632. && valueBox != 0 && valueBox->isEditable())
  39633. return;
  39634. if (style == IncDecButtons && ! incDecDragged)
  39635. {
  39636. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39637. return;
  39638. incDecDragged = true;
  39639. mouseDragStartX = e.x;
  39640. mouseDragStartY = e.y;
  39641. }
  39642. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39643. : false))
  39644. || ((maximum - minimum) / sliderRegionSize < interval))
  39645. {
  39646. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39647. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39648. if (style == RotaryHorizontalDrag
  39649. || style == RotaryVerticalDrag
  39650. || style == IncDecButtons
  39651. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39652. && ! snapsToMousePos))
  39653. {
  39654. const int mouseDiff = (style == RotaryHorizontalDrag
  39655. || style == LinearHorizontal
  39656. || style == LinearBar
  39657. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39658. ? e.x - mouseDragStartX
  39659. : mouseDragStartY - e.y;
  39660. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39661. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39662. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39663. if (style == IncDecButtons)
  39664. {
  39665. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39666. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39667. }
  39668. }
  39669. else
  39670. {
  39671. if (isVertical())
  39672. scaledMousePos = 1.0 - scaledMousePos;
  39673. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39674. }
  39675. }
  39676. else
  39677. {
  39678. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39679. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39680. ? e.x - mouseXWhenLastDragged
  39681. : e.y - mouseYWhenLastDragged;
  39682. const double maxSpeed = jmax (200, sliderRegionSize);
  39683. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39684. if (speed != 0)
  39685. {
  39686. speed = 0.2 * velocityModeSensitivity
  39687. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39688. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39689. / maxSpeed))));
  39690. if (mouseDiff < 0)
  39691. speed = -speed;
  39692. if (isVertical() || style == RotaryVerticalDrag
  39693. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39694. speed = -speed;
  39695. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39696. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39697. e.source.enableUnboundedMouseMovement (true, false);
  39698. mouseWasHidden = true;
  39699. }
  39700. }
  39701. }
  39702. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39703. if (sliderBeingDragged == 0)
  39704. {
  39705. setValue (snapValue (valueWhenLastDragged, true),
  39706. ! sendChangeOnlyOnRelease, true);
  39707. }
  39708. else if (sliderBeingDragged == 1)
  39709. {
  39710. setMinValue (snapValue (valueWhenLastDragged, true),
  39711. ! sendChangeOnlyOnRelease, false, true);
  39712. if (e.mods.isShiftDown())
  39713. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39714. else
  39715. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39716. }
  39717. else
  39718. {
  39719. jassert (sliderBeingDragged == 2);
  39720. setMaxValue (snapValue (valueWhenLastDragged, true),
  39721. ! sendChangeOnlyOnRelease, false, true);
  39722. if (e.mods.isShiftDown())
  39723. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39724. else
  39725. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39726. }
  39727. mouseXWhenLastDragged = e.x;
  39728. mouseYWhenLastDragged = e.y;
  39729. }
  39730. }
  39731. void Slider::mouseDoubleClick (const MouseEvent&)
  39732. {
  39733. if (doubleClickToValue
  39734. && isEnabled()
  39735. && style != IncDecButtons
  39736. && minimum <= doubleClickReturnValue
  39737. && maximum >= doubleClickReturnValue)
  39738. {
  39739. sendDragStart();
  39740. setValue (doubleClickReturnValue, true, true);
  39741. sendDragEnd();
  39742. }
  39743. }
  39744. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39745. {
  39746. if (scrollWheelEnabled && isEnabled()
  39747. && style != TwoValueHorizontal
  39748. && style != TwoValueVertical)
  39749. {
  39750. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39751. {
  39752. if (valueBox != 0)
  39753. valueBox->hideEditor (false);
  39754. const double value = (double) currentValue.getValue();
  39755. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39756. const double currentPos = valueToProportionOfLength (value);
  39757. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39758. double delta = (newValue != value)
  39759. ? jmax (fabs (newValue - value), interval) : 0;
  39760. if (value > newValue)
  39761. delta = -delta;
  39762. sendDragStart();
  39763. setValue (snapValue (value + delta, false), true, true);
  39764. sendDragEnd();
  39765. }
  39766. }
  39767. else
  39768. {
  39769. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39770. }
  39771. }
  39772. void SliderListener::sliderDragStarted (Slider*)
  39773. {
  39774. }
  39775. void SliderListener::sliderDragEnded (Slider*)
  39776. {
  39777. }
  39778. END_JUCE_NAMESPACE
  39779. /*** End of inlined file: juce_Slider.cpp ***/
  39780. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39781. BEGIN_JUCE_NAMESPACE
  39782. class DragOverlayComp : public Component
  39783. {
  39784. public:
  39785. DragOverlayComp (Image* const image_)
  39786. : image (image_)
  39787. {
  39788. image->multiplyAllAlphas (0.8f);
  39789. setAlwaysOnTop (true);
  39790. }
  39791. ~DragOverlayComp()
  39792. {
  39793. }
  39794. void paint (Graphics& g)
  39795. {
  39796. g.drawImageAt (image, 0, 0);
  39797. }
  39798. private:
  39799. ScopedPointer <Image> image;
  39800. DragOverlayComp (const DragOverlayComp&);
  39801. DragOverlayComp& operator= (const DragOverlayComp&);
  39802. };
  39803. TableHeaderComponent::TableHeaderComponent()
  39804. : columnsChanged (false),
  39805. columnsResized (false),
  39806. sortChanged (false),
  39807. menuActive (true),
  39808. stretchToFit (false),
  39809. columnIdBeingResized (0),
  39810. columnIdBeingDragged (0),
  39811. columnIdUnderMouse (0),
  39812. lastDeliberateWidth (0)
  39813. {
  39814. }
  39815. TableHeaderComponent::~TableHeaderComponent()
  39816. {
  39817. dragOverlayComp = 0;
  39818. }
  39819. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39820. {
  39821. menuActive = hasMenu;
  39822. }
  39823. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39824. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39825. {
  39826. if (onlyCountVisibleColumns)
  39827. {
  39828. int num = 0;
  39829. for (int i = columns.size(); --i >= 0;)
  39830. if (columns.getUnchecked(i)->isVisible())
  39831. ++num;
  39832. return num;
  39833. }
  39834. else
  39835. {
  39836. return columns.size();
  39837. }
  39838. }
  39839. const String TableHeaderComponent::getColumnName (const int columnId) const
  39840. {
  39841. const ColumnInfo* const ci = getInfoForId (columnId);
  39842. return ci != 0 ? ci->name : String::empty;
  39843. }
  39844. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39845. {
  39846. ColumnInfo* const ci = getInfoForId (columnId);
  39847. if (ci != 0 && ci->name != newName)
  39848. {
  39849. ci->name = newName;
  39850. sendColumnsChanged();
  39851. }
  39852. }
  39853. void TableHeaderComponent::addColumn (const String& columnName,
  39854. const int columnId,
  39855. const int width,
  39856. const int minimumWidth,
  39857. const int maximumWidth,
  39858. const int propertyFlags,
  39859. const int insertIndex)
  39860. {
  39861. // can't have a duplicate or null ID!
  39862. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39863. jassert (width > 0);
  39864. ColumnInfo* const ci = new ColumnInfo();
  39865. ci->name = columnName;
  39866. ci->id = columnId;
  39867. ci->width = width;
  39868. ci->lastDeliberateWidth = width;
  39869. ci->minimumWidth = minimumWidth;
  39870. ci->maximumWidth = maximumWidth;
  39871. if (ci->maximumWidth < 0)
  39872. ci->maximumWidth = std::numeric_limits<int>::max();
  39873. jassert (ci->maximumWidth >= ci->minimumWidth);
  39874. ci->propertyFlags = propertyFlags;
  39875. columns.insert (insertIndex, ci);
  39876. sendColumnsChanged();
  39877. }
  39878. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39879. {
  39880. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39881. if (index >= 0)
  39882. {
  39883. columns.remove (index);
  39884. sortChanged = true;
  39885. sendColumnsChanged();
  39886. }
  39887. }
  39888. void TableHeaderComponent::removeAllColumns()
  39889. {
  39890. if (columns.size() > 0)
  39891. {
  39892. columns.clear();
  39893. sendColumnsChanged();
  39894. }
  39895. }
  39896. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39897. {
  39898. const int currentIndex = getIndexOfColumnId (columnId, false);
  39899. newIndex = visibleIndexToTotalIndex (newIndex);
  39900. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39901. {
  39902. columns.move (currentIndex, newIndex);
  39903. sendColumnsChanged();
  39904. }
  39905. }
  39906. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39907. {
  39908. const ColumnInfo* const ci = getInfoForId (columnId);
  39909. return ci != 0 ? ci->width : 0;
  39910. }
  39911. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39912. {
  39913. ColumnInfo* const ci = getInfoForId (columnId);
  39914. if (ci != 0 && ci->width != newWidth)
  39915. {
  39916. const int numColumns = getNumColumns (true);
  39917. ci->lastDeliberateWidth = ci->width
  39918. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39919. if (stretchToFit)
  39920. {
  39921. const int index = getIndexOfColumnId (columnId, true) + 1;
  39922. if (((unsigned int) index) < (unsigned int) numColumns)
  39923. {
  39924. const int x = getColumnPosition (index).getX();
  39925. if (lastDeliberateWidth == 0)
  39926. lastDeliberateWidth = getTotalWidth();
  39927. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39928. }
  39929. }
  39930. repaint();
  39931. columnsResized = true;
  39932. triggerAsyncUpdate();
  39933. }
  39934. }
  39935. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39936. {
  39937. int n = 0;
  39938. for (int i = 0; i < columns.size(); ++i)
  39939. {
  39940. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39941. {
  39942. if (columns.getUnchecked(i)->id == columnId)
  39943. return n;
  39944. ++n;
  39945. }
  39946. }
  39947. return -1;
  39948. }
  39949. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39950. {
  39951. if (onlyCountVisibleColumns)
  39952. index = visibleIndexToTotalIndex (index);
  39953. const ColumnInfo* const ci = columns [index];
  39954. return (ci != 0) ? ci->id : 0;
  39955. }
  39956. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39957. {
  39958. int x = 0, width = 0, n = 0;
  39959. for (int i = 0; i < columns.size(); ++i)
  39960. {
  39961. x += width;
  39962. if (columns.getUnchecked(i)->isVisible())
  39963. {
  39964. width = columns.getUnchecked(i)->width;
  39965. if (n++ == index)
  39966. break;
  39967. }
  39968. else
  39969. {
  39970. width = 0;
  39971. }
  39972. }
  39973. return Rectangle<int> (x, 0, width, getHeight());
  39974. }
  39975. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39976. {
  39977. if (xToFind >= 0)
  39978. {
  39979. int x = 0;
  39980. for (int i = 0; i < columns.size(); ++i)
  39981. {
  39982. const ColumnInfo* const ci = columns.getUnchecked(i);
  39983. if (ci->isVisible())
  39984. {
  39985. x += ci->width;
  39986. if (xToFind < x)
  39987. return ci->id;
  39988. }
  39989. }
  39990. }
  39991. return 0;
  39992. }
  39993. int TableHeaderComponent::getTotalWidth() const
  39994. {
  39995. int w = 0;
  39996. for (int i = columns.size(); --i >= 0;)
  39997. if (columns.getUnchecked(i)->isVisible())
  39998. w += columns.getUnchecked(i)->width;
  39999. return w;
  40000. }
  40001. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40002. {
  40003. stretchToFit = shouldStretchToFit;
  40004. lastDeliberateWidth = getTotalWidth();
  40005. resized();
  40006. }
  40007. bool TableHeaderComponent::isStretchToFitActive() const
  40008. {
  40009. return stretchToFit;
  40010. }
  40011. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40012. {
  40013. if (stretchToFit && getWidth() > 0
  40014. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40015. {
  40016. lastDeliberateWidth = targetTotalWidth;
  40017. resizeColumnsToFit (0, targetTotalWidth);
  40018. }
  40019. }
  40020. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40021. {
  40022. targetTotalWidth = jmax (targetTotalWidth, 0);
  40023. StretchableObjectResizer sor;
  40024. int i;
  40025. for (i = firstColumnIndex; i < columns.size(); ++i)
  40026. {
  40027. ColumnInfo* const ci = columns.getUnchecked(i);
  40028. if (ci->isVisible())
  40029. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40030. }
  40031. sor.resizeToFit (targetTotalWidth);
  40032. int visIndex = 0;
  40033. for (i = firstColumnIndex; i < columns.size(); ++i)
  40034. {
  40035. ColumnInfo* const ci = columns.getUnchecked(i);
  40036. if (ci->isVisible())
  40037. {
  40038. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40039. (int) floor (sor.getItemSize (visIndex++)));
  40040. if (newWidth != ci->width)
  40041. {
  40042. ci->width = newWidth;
  40043. repaint();
  40044. columnsResized = true;
  40045. triggerAsyncUpdate();
  40046. }
  40047. }
  40048. }
  40049. }
  40050. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40051. {
  40052. ColumnInfo* const ci = getInfoForId (columnId);
  40053. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40054. {
  40055. if (shouldBeVisible)
  40056. ci->propertyFlags |= visible;
  40057. else
  40058. ci->propertyFlags &= ~visible;
  40059. sendColumnsChanged();
  40060. resized();
  40061. }
  40062. }
  40063. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40064. {
  40065. const ColumnInfo* const ci = getInfoForId (columnId);
  40066. return ci != 0 && ci->isVisible();
  40067. }
  40068. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40069. {
  40070. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40071. {
  40072. for (int i = columns.size(); --i >= 0;)
  40073. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40074. ColumnInfo* const ci = getInfoForId (columnId);
  40075. if (ci != 0)
  40076. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40077. reSortTable();
  40078. }
  40079. }
  40080. int TableHeaderComponent::getSortColumnId() const
  40081. {
  40082. for (int i = columns.size(); --i >= 0;)
  40083. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40084. return columns.getUnchecked(i)->id;
  40085. return 0;
  40086. }
  40087. bool TableHeaderComponent::isSortedForwards() const
  40088. {
  40089. for (int i = columns.size(); --i >= 0;)
  40090. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40091. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40092. return true;
  40093. }
  40094. void TableHeaderComponent::reSortTable()
  40095. {
  40096. sortChanged = true;
  40097. repaint();
  40098. triggerAsyncUpdate();
  40099. }
  40100. const String TableHeaderComponent::toString() const
  40101. {
  40102. String s;
  40103. XmlElement doc ("TABLELAYOUT");
  40104. doc.setAttribute ("sortedCol", getSortColumnId());
  40105. doc.setAttribute ("sortForwards", isSortedForwards());
  40106. for (int i = 0; i < columns.size(); ++i)
  40107. {
  40108. const ColumnInfo* const ci = columns.getUnchecked (i);
  40109. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40110. e->setAttribute ("id", ci->id);
  40111. e->setAttribute ("visible", ci->isVisible());
  40112. e->setAttribute ("width", ci->width);
  40113. }
  40114. return doc.createDocument (String::empty, true, false);
  40115. }
  40116. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40117. {
  40118. XmlDocument doc (storedVersion);
  40119. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40120. int index = 0;
  40121. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40122. {
  40123. forEachXmlChildElement (*storedXml, col)
  40124. {
  40125. const int tabId = col->getIntAttribute ("id");
  40126. ColumnInfo* const ci = getInfoForId (tabId);
  40127. if (ci != 0)
  40128. {
  40129. columns.move (columns.indexOf (ci), index);
  40130. ci->width = col->getIntAttribute ("width");
  40131. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40132. }
  40133. ++index;
  40134. }
  40135. columnsResized = true;
  40136. sendColumnsChanged();
  40137. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40138. storedXml->getBoolAttribute ("sortForwards", true));
  40139. }
  40140. }
  40141. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40142. {
  40143. listeners.addIfNotAlreadyThere (newListener);
  40144. }
  40145. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40146. {
  40147. listeners.removeValue (listenerToRemove);
  40148. }
  40149. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40150. {
  40151. const ColumnInfo* const ci = getInfoForId (columnId);
  40152. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40153. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40154. }
  40155. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40156. {
  40157. for (int i = 0; i < columns.size(); ++i)
  40158. {
  40159. const ColumnInfo* const ci = columns.getUnchecked(i);
  40160. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40161. menu.addItem (ci->id, ci->name,
  40162. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40163. isColumnVisible (ci->id));
  40164. }
  40165. }
  40166. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40167. {
  40168. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40169. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40170. }
  40171. void TableHeaderComponent::paint (Graphics& g)
  40172. {
  40173. LookAndFeel& lf = getLookAndFeel();
  40174. lf.drawTableHeaderBackground (g, *this);
  40175. const Rectangle<int> clip (g.getClipBounds());
  40176. int x = 0;
  40177. for (int i = 0; i < columns.size(); ++i)
  40178. {
  40179. const ColumnInfo* const ci = columns.getUnchecked(i);
  40180. if (ci->isVisible())
  40181. {
  40182. if (x + ci->width > clip.getX()
  40183. && (ci->id != columnIdBeingDragged
  40184. || dragOverlayComp == 0
  40185. || ! dragOverlayComp->isVisible()))
  40186. {
  40187. g.saveState();
  40188. g.setOrigin (x, 0);
  40189. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40190. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40191. ci->id == columnIdUnderMouse,
  40192. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40193. ci->propertyFlags);
  40194. g.restoreState();
  40195. }
  40196. x += ci->width;
  40197. if (x >= clip.getRight())
  40198. break;
  40199. }
  40200. }
  40201. }
  40202. void TableHeaderComponent::resized()
  40203. {
  40204. }
  40205. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40206. {
  40207. updateColumnUnderMouse (e.x, e.y);
  40208. }
  40209. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40210. {
  40211. updateColumnUnderMouse (e.x, e.y);
  40212. }
  40213. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40214. {
  40215. updateColumnUnderMouse (e.x, e.y);
  40216. }
  40217. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40218. {
  40219. repaint();
  40220. columnIdBeingResized = 0;
  40221. columnIdBeingDragged = 0;
  40222. if (columnIdUnderMouse != 0)
  40223. {
  40224. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40225. if (e.mods.isPopupMenu())
  40226. columnClicked (columnIdUnderMouse, e.mods);
  40227. }
  40228. if (menuActive && e.mods.isPopupMenu())
  40229. showColumnChooserMenu (columnIdUnderMouse);
  40230. }
  40231. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40232. {
  40233. if (columnIdBeingResized == 0
  40234. && columnIdBeingDragged == 0
  40235. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40236. {
  40237. dragOverlayComp = 0;
  40238. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40239. if (columnIdBeingResized != 0)
  40240. {
  40241. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40242. initialColumnWidth = ci->width;
  40243. }
  40244. else
  40245. {
  40246. beginDrag (e);
  40247. }
  40248. }
  40249. if (columnIdBeingResized != 0)
  40250. {
  40251. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40252. if (ci != 0)
  40253. {
  40254. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40255. initialColumnWidth + e.getDistanceFromDragStartX());
  40256. if (stretchToFit)
  40257. {
  40258. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40259. int minWidthOnRight = 0;
  40260. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40261. if (columns.getUnchecked (i)->isVisible())
  40262. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40263. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40264. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40265. }
  40266. setColumnWidth (columnIdBeingResized, w);
  40267. }
  40268. }
  40269. else if (columnIdBeingDragged != 0)
  40270. {
  40271. if (e.y >= -50 && e.y < getHeight() + 50)
  40272. {
  40273. if (dragOverlayComp != 0)
  40274. {
  40275. dragOverlayComp->setVisible (true);
  40276. dragOverlayComp->setBounds (jlimit (0,
  40277. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40278. e.x - draggingColumnOffset),
  40279. 0,
  40280. dragOverlayComp->getWidth(),
  40281. getHeight());
  40282. for (int i = columns.size(); --i >= 0;)
  40283. {
  40284. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40285. int newIndex = currentIndex;
  40286. if (newIndex > 0)
  40287. {
  40288. // if the previous column isn't draggable, we can't move our column
  40289. // past it, because that'd change the undraggable column's position..
  40290. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40291. if ((previous->propertyFlags & draggable) != 0)
  40292. {
  40293. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40294. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40295. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40296. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40297. {
  40298. --newIndex;
  40299. }
  40300. }
  40301. }
  40302. if (newIndex < columns.size() - 1)
  40303. {
  40304. // if the next column isn't draggable, we can't move our column
  40305. // past it, because that'd change the undraggable column's position..
  40306. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40307. if ((nextCol->propertyFlags & draggable) != 0)
  40308. {
  40309. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40310. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40311. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40312. > abs (dragOverlayComp->getRight() - rightOfNext))
  40313. {
  40314. ++newIndex;
  40315. }
  40316. }
  40317. }
  40318. if (newIndex != currentIndex)
  40319. moveColumn (columnIdBeingDragged, newIndex);
  40320. else
  40321. break;
  40322. }
  40323. }
  40324. }
  40325. else
  40326. {
  40327. endDrag (draggingColumnOriginalIndex);
  40328. }
  40329. }
  40330. }
  40331. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40332. {
  40333. if (columnIdBeingDragged == 0)
  40334. {
  40335. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40336. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40337. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40338. {
  40339. columnIdBeingDragged = 0;
  40340. }
  40341. else
  40342. {
  40343. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40344. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40345. const int temp = columnIdBeingDragged;
  40346. columnIdBeingDragged = 0;
  40347. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40348. columnIdBeingDragged = temp;
  40349. dragOverlayComp->setBounds (columnRect);
  40350. for (int i = listeners.size(); --i >= 0;)
  40351. {
  40352. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40353. i = jmin (i, listeners.size() - 1);
  40354. }
  40355. }
  40356. }
  40357. }
  40358. void TableHeaderComponent::endDrag (const int finalIndex)
  40359. {
  40360. if (columnIdBeingDragged != 0)
  40361. {
  40362. moveColumn (columnIdBeingDragged, finalIndex);
  40363. columnIdBeingDragged = 0;
  40364. repaint();
  40365. for (int i = listeners.size(); --i >= 0;)
  40366. {
  40367. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40368. i = jmin (i, listeners.size() - 1);
  40369. }
  40370. }
  40371. }
  40372. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40373. {
  40374. mouseDrag (e);
  40375. for (int i = columns.size(); --i >= 0;)
  40376. if (columns.getUnchecked (i)->isVisible())
  40377. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40378. columnIdBeingResized = 0;
  40379. repaint();
  40380. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40381. updateColumnUnderMouse (e.x, e.y);
  40382. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40383. columnClicked (columnIdUnderMouse, e.mods);
  40384. dragOverlayComp = 0;
  40385. }
  40386. const MouseCursor TableHeaderComponent::getMouseCursor()
  40387. {
  40388. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40389. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40390. return Component::getMouseCursor();
  40391. }
  40392. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40393. {
  40394. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40395. }
  40396. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40397. {
  40398. for (int i = columns.size(); --i >= 0;)
  40399. if (columns.getUnchecked(i)->id == id)
  40400. return columns.getUnchecked(i);
  40401. return 0;
  40402. }
  40403. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40404. {
  40405. int n = 0;
  40406. for (int i = 0; i < columns.size(); ++i)
  40407. {
  40408. if (columns.getUnchecked(i)->isVisible())
  40409. {
  40410. if (n == visibleIndex)
  40411. return i;
  40412. ++n;
  40413. }
  40414. }
  40415. return -1;
  40416. }
  40417. void TableHeaderComponent::sendColumnsChanged()
  40418. {
  40419. if (stretchToFit && lastDeliberateWidth > 0)
  40420. resizeAllColumnsToFit (lastDeliberateWidth);
  40421. repaint();
  40422. columnsChanged = true;
  40423. triggerAsyncUpdate();
  40424. }
  40425. void TableHeaderComponent::handleAsyncUpdate()
  40426. {
  40427. const bool changed = columnsChanged || sortChanged;
  40428. const bool sized = columnsResized || changed;
  40429. const bool sorted = sortChanged;
  40430. columnsChanged = false;
  40431. columnsResized = false;
  40432. sortChanged = false;
  40433. if (sorted)
  40434. {
  40435. for (int i = listeners.size(); --i >= 0;)
  40436. {
  40437. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40438. i = jmin (i, listeners.size() - 1);
  40439. }
  40440. }
  40441. if (changed)
  40442. {
  40443. for (int i = listeners.size(); --i >= 0;)
  40444. {
  40445. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40446. i = jmin (i, listeners.size() - 1);
  40447. }
  40448. }
  40449. if (sized)
  40450. {
  40451. for (int i = listeners.size(); --i >= 0;)
  40452. {
  40453. listeners.getUnchecked(i)->tableColumnsResized (this);
  40454. i = jmin (i, listeners.size() - 1);
  40455. }
  40456. }
  40457. }
  40458. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40459. {
  40460. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40461. {
  40462. const int draggableDistance = 3;
  40463. int x = 0;
  40464. for (int i = 0; i < columns.size(); ++i)
  40465. {
  40466. const ColumnInfo* const ci = columns.getUnchecked(i);
  40467. if (ci->isVisible())
  40468. {
  40469. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40470. && (ci->propertyFlags & resizable) != 0)
  40471. return ci->id;
  40472. x += ci->width;
  40473. }
  40474. }
  40475. }
  40476. return 0;
  40477. }
  40478. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40479. {
  40480. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40481. ? getColumnIdAtX (x) : 0;
  40482. if (newCol != columnIdUnderMouse)
  40483. {
  40484. columnIdUnderMouse = newCol;
  40485. repaint();
  40486. }
  40487. }
  40488. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40489. {
  40490. PopupMenu m;
  40491. addMenuItems (m, columnIdClicked);
  40492. if (m.getNumItems() > 0)
  40493. {
  40494. m.setLookAndFeel (&getLookAndFeel());
  40495. const int result = m.show();
  40496. if (result != 0)
  40497. reactToMenuItem (result, columnIdClicked);
  40498. }
  40499. }
  40500. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40501. {
  40502. }
  40503. END_JUCE_NAMESPACE
  40504. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40505. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40506. BEGIN_JUCE_NAMESPACE
  40507. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40508. class TableListRowComp : public Component,
  40509. public TooltipClient
  40510. {
  40511. public:
  40512. TableListRowComp (TableListBox& owner_)
  40513. : owner (owner_),
  40514. row (-1),
  40515. isSelected (false)
  40516. {
  40517. }
  40518. ~TableListRowComp()
  40519. {
  40520. deleteAllChildren();
  40521. }
  40522. void paint (Graphics& g)
  40523. {
  40524. TableListBoxModel* const model = owner.getModel();
  40525. if (model != 0)
  40526. {
  40527. const TableHeaderComponent* const header = owner.getHeader();
  40528. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40529. const int numColumns = header->getNumColumns (true);
  40530. for (int i = 0; i < numColumns; ++i)
  40531. {
  40532. if (! columnsWithComponents [i])
  40533. {
  40534. const int columnId = header->getColumnIdOfIndex (i, true);
  40535. Rectangle<int> columnRect (header->getColumnPosition (i));
  40536. columnRect.setSize (columnRect.getWidth(), getHeight());
  40537. g.saveState();
  40538. g.reduceClipRegion (columnRect);
  40539. g.setOrigin (columnRect.getX(), 0);
  40540. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40541. g.restoreState();
  40542. }
  40543. }
  40544. }
  40545. }
  40546. void update (const int newRow, const bool isNowSelected)
  40547. {
  40548. if (newRow != row || isNowSelected != isSelected)
  40549. {
  40550. row = newRow;
  40551. isSelected = isNowSelected;
  40552. repaint();
  40553. }
  40554. if (row < owner.getNumRows())
  40555. {
  40556. jassert (row >= 0);
  40557. const var::identifier tagPropertyName ("_tableLastUseNum");
  40558. const int newTag = Random::getSystemRandom().nextInt();
  40559. const TableHeaderComponent* const header = owner.getHeader();
  40560. const int numColumns = header->getNumColumns (true);
  40561. int i;
  40562. columnsWithComponents.clear();
  40563. if (owner.getModel() != 0)
  40564. {
  40565. for (i = 0; i < numColumns; ++i)
  40566. {
  40567. const int columnId = header->getColumnIdOfIndex (i, true);
  40568. Component* const newComp
  40569. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40570. findChildComponentForColumn (columnId));
  40571. if (newComp != 0)
  40572. {
  40573. addAndMakeVisible (newComp);
  40574. newComp->getProperties().set (tagPropertyName, newTag);
  40575. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40576. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40577. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40578. columnsWithComponents.setBit (i);
  40579. }
  40580. }
  40581. }
  40582. for (i = getNumChildComponents(); --i >= 0;)
  40583. {
  40584. Component* const c = getChildComponent (i);
  40585. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40586. delete c;
  40587. }
  40588. }
  40589. else
  40590. {
  40591. columnsWithComponents.clear();
  40592. deleteAllChildren();
  40593. }
  40594. }
  40595. void resized()
  40596. {
  40597. for (int i = getNumChildComponents(); --i >= 0;)
  40598. {
  40599. Component* const c = getChildComponent (i);
  40600. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40601. if (columnId != 0)
  40602. {
  40603. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40604. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40605. }
  40606. }
  40607. }
  40608. void mouseDown (const MouseEvent& e)
  40609. {
  40610. isDragging = false;
  40611. selectRowOnMouseUp = false;
  40612. if (isEnabled())
  40613. {
  40614. if (! isSelected)
  40615. {
  40616. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40617. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40618. if (columnId != 0 && owner.getModel() != 0)
  40619. owner.getModel()->cellClicked (row, columnId, e);
  40620. }
  40621. else
  40622. {
  40623. selectRowOnMouseUp = true;
  40624. }
  40625. }
  40626. }
  40627. void mouseDrag (const MouseEvent& e)
  40628. {
  40629. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40630. {
  40631. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40632. if (selectedRows.size() > 0)
  40633. {
  40634. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40635. if (dragDescription.isNotEmpty())
  40636. {
  40637. isDragging = true;
  40638. owner.startDragAndDrop (e, dragDescription);
  40639. }
  40640. }
  40641. }
  40642. }
  40643. void mouseUp (const MouseEvent& e)
  40644. {
  40645. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40646. {
  40647. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40648. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40649. if (columnId != 0 && owner.getModel() != 0)
  40650. owner.getModel()->cellClicked (row, columnId, e);
  40651. }
  40652. }
  40653. void mouseDoubleClick (const MouseEvent& e)
  40654. {
  40655. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40656. if (columnId != 0 && owner.getModel() != 0)
  40657. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40658. }
  40659. const String getTooltip()
  40660. {
  40661. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40662. if (columnId != 0 && owner.getModel() != 0)
  40663. return owner.getModel()->getCellTooltip (row, columnId);
  40664. return String::empty;
  40665. }
  40666. juce_UseDebuggingNewOperator
  40667. private:
  40668. TableListBox& owner;
  40669. int row;
  40670. bool isSelected, isDragging, selectRowOnMouseUp;
  40671. BigInteger columnsWithComponents;
  40672. Component* findChildComponentForColumn (const int columnId) const
  40673. {
  40674. for (int i = getNumChildComponents(); --i >= 0;)
  40675. {
  40676. Component* const c = getChildComponent (i);
  40677. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40678. return c;
  40679. }
  40680. return 0;
  40681. }
  40682. TableListRowComp (const TableListRowComp&);
  40683. TableListRowComp& operator= (const TableListRowComp&);
  40684. };
  40685. class TableListBoxHeader : public TableHeaderComponent
  40686. {
  40687. public:
  40688. TableListBoxHeader (TableListBox& owner_)
  40689. : owner (owner_)
  40690. {
  40691. }
  40692. ~TableListBoxHeader()
  40693. {
  40694. }
  40695. void addMenuItems (PopupMenu& menu, int columnIdClicked)
  40696. {
  40697. if (owner.isAutoSizeMenuOptionShown())
  40698. {
  40699. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40700. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40701. menu.addSeparator();
  40702. }
  40703. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40704. }
  40705. void reactToMenuItem (int menuReturnId, int columnIdClicked)
  40706. {
  40707. if (menuReturnId == 0xf836743)
  40708. {
  40709. owner.autoSizeColumn (columnIdClicked);
  40710. }
  40711. else if (menuReturnId == 0xf836744)
  40712. {
  40713. owner.autoSizeAllColumns();
  40714. }
  40715. else
  40716. {
  40717. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40718. }
  40719. }
  40720. juce_UseDebuggingNewOperator
  40721. private:
  40722. TableListBox& owner;
  40723. TableListBoxHeader (const TableListBoxHeader&);
  40724. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40725. };
  40726. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40727. : ListBox (name, 0),
  40728. model (model_),
  40729. autoSizeOptionsShown (true)
  40730. {
  40731. ListBox::model = this;
  40732. header = new TableListBoxHeader (*this);
  40733. header->setSize (100, 28);
  40734. header->addListener (this);
  40735. setHeaderComponent (header);
  40736. }
  40737. TableListBox::~TableListBox()
  40738. {
  40739. deleteAllChildren();
  40740. }
  40741. void TableListBox::setModel (TableListBoxModel* const newModel)
  40742. {
  40743. if (model != newModel)
  40744. {
  40745. model = newModel;
  40746. updateContent();
  40747. }
  40748. }
  40749. int TableListBox::getHeaderHeight() const
  40750. {
  40751. return header->getHeight();
  40752. }
  40753. void TableListBox::setHeaderHeight (const int newHeight)
  40754. {
  40755. header->setSize (header->getWidth(), newHeight);
  40756. resized();
  40757. }
  40758. void TableListBox::autoSizeColumn (const int columnId)
  40759. {
  40760. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40761. if (width > 0)
  40762. header->setColumnWidth (columnId, width);
  40763. }
  40764. void TableListBox::autoSizeAllColumns()
  40765. {
  40766. for (int i = 0; i < header->getNumColumns (true); ++i)
  40767. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40768. }
  40769. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40770. {
  40771. autoSizeOptionsShown = shouldBeShown;
  40772. }
  40773. bool TableListBox::isAutoSizeMenuOptionShown() const
  40774. {
  40775. return autoSizeOptionsShown;
  40776. }
  40777. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40778. const int rowNumber,
  40779. const bool relativeToComponentTopLeft) const
  40780. {
  40781. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40782. if (relativeToComponentTopLeft)
  40783. headerCell.translate (header->getX(), 0);
  40784. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40785. return Rectangle<int> (headerCell.getX(), row.getY(),
  40786. headerCell.getWidth(), row.getHeight());
  40787. }
  40788. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40789. {
  40790. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40791. if (scrollbar != 0)
  40792. {
  40793. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40794. double x = scrollbar->getCurrentRangeStart();
  40795. const double w = scrollbar->getCurrentRangeSize();
  40796. if (pos.getX() < x)
  40797. x = pos.getX();
  40798. else if (pos.getRight() > x + w)
  40799. x += jmax (0.0, pos.getRight() - (x + w));
  40800. scrollbar->setCurrentRangeStart (x);
  40801. }
  40802. }
  40803. int TableListBox::getNumRows()
  40804. {
  40805. return model != 0 ? model->getNumRows() : 0;
  40806. }
  40807. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40808. {
  40809. }
  40810. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40811. {
  40812. if (existingComponentToUpdate == 0)
  40813. existingComponentToUpdate = new TableListRowComp (*this);
  40814. static_cast <TableListRowComp*> (existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40815. return existingComponentToUpdate;
  40816. }
  40817. void TableListBox::selectedRowsChanged (int row)
  40818. {
  40819. if (model != 0)
  40820. model->selectedRowsChanged (row);
  40821. }
  40822. void TableListBox::deleteKeyPressed (int row)
  40823. {
  40824. if (model != 0)
  40825. model->deleteKeyPressed (row);
  40826. }
  40827. void TableListBox::returnKeyPressed (int row)
  40828. {
  40829. if (model != 0)
  40830. model->returnKeyPressed (row);
  40831. }
  40832. void TableListBox::backgroundClicked()
  40833. {
  40834. if (model != 0)
  40835. model->backgroundClicked();
  40836. }
  40837. void TableListBox::listWasScrolled()
  40838. {
  40839. if (model != 0)
  40840. model->listWasScrolled();
  40841. }
  40842. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40843. {
  40844. setMinimumContentWidth (header->getTotalWidth());
  40845. repaint();
  40846. updateColumnComponents();
  40847. }
  40848. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40849. {
  40850. setMinimumContentWidth (header->getTotalWidth());
  40851. repaint();
  40852. updateColumnComponents();
  40853. }
  40854. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40855. {
  40856. if (model != 0)
  40857. model->sortOrderChanged (header->getSortColumnId(),
  40858. header->isSortedForwards());
  40859. }
  40860. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40861. {
  40862. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40863. repaint();
  40864. }
  40865. void TableListBox::resized()
  40866. {
  40867. ListBox::resized();
  40868. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40869. setMinimumContentWidth (header->getTotalWidth());
  40870. }
  40871. void TableListBox::updateColumnComponents() const
  40872. {
  40873. const int firstRow = getRowContainingPosition (0, 0);
  40874. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40875. {
  40876. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40877. if (rowComp != 0)
  40878. rowComp->resized();
  40879. }
  40880. }
  40881. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40882. {
  40883. }
  40884. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40885. {
  40886. }
  40887. void TableListBoxModel::backgroundClicked()
  40888. {
  40889. }
  40890. void TableListBoxModel::sortOrderChanged (int, const bool)
  40891. {
  40892. }
  40893. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40894. {
  40895. return 0;
  40896. }
  40897. void TableListBoxModel::selectedRowsChanged (int)
  40898. {
  40899. }
  40900. void TableListBoxModel::deleteKeyPressed (int)
  40901. {
  40902. }
  40903. void TableListBoxModel::returnKeyPressed (int)
  40904. {
  40905. }
  40906. void TableListBoxModel::listWasScrolled()
  40907. {
  40908. }
  40909. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40910. {
  40911. return String::empty;
  40912. }
  40913. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40914. {
  40915. return String::empty;
  40916. }
  40917. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40918. {
  40919. (void) existingComponentToUpdate;
  40920. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40921. return 0;
  40922. }
  40923. END_JUCE_NAMESPACE
  40924. /*** End of inlined file: juce_TableListBox.cpp ***/
  40925. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40926. BEGIN_JUCE_NAMESPACE
  40927. // a word or space that can't be broken down any further
  40928. struct TextAtom
  40929. {
  40930. String atomText;
  40931. float width;
  40932. uint16 numChars;
  40933. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40934. bool isNewLine() const { return atomText[0] == '\r' || atomText[0] == '\n'; }
  40935. const String getText (const juce_wchar passwordCharacter) const
  40936. {
  40937. if (passwordCharacter == 0)
  40938. return atomText;
  40939. else
  40940. return String::repeatedString (String::charToString (passwordCharacter),
  40941. atomText.length());
  40942. }
  40943. const String getTrimmedText (const juce_wchar passwordCharacter) const
  40944. {
  40945. if (passwordCharacter == 0)
  40946. return atomText.substring (0, numChars);
  40947. else if (isNewLine())
  40948. return String::empty;
  40949. else
  40950. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40951. }
  40952. };
  40953. // a run of text with a single font and colour
  40954. class TextEditor::UniformTextSection
  40955. {
  40956. public:
  40957. UniformTextSection (const String& text,
  40958. const Font& font_,
  40959. const Colour& colour_,
  40960. const juce_wchar passwordCharacter)
  40961. : font (font_),
  40962. colour (colour_)
  40963. {
  40964. initialiseAtoms (text, passwordCharacter);
  40965. }
  40966. UniformTextSection (const UniformTextSection& other)
  40967. : font (other.font),
  40968. colour (other.colour)
  40969. {
  40970. atoms.ensureStorageAllocated (other.atoms.size());
  40971. for (int i = 0; i < other.atoms.size(); ++i)
  40972. atoms.add (new TextAtom (*other.atoms.getUnchecked(i)));
  40973. }
  40974. ~UniformTextSection()
  40975. {
  40976. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40977. }
  40978. void clear()
  40979. {
  40980. for (int i = atoms.size(); --i >= 0;)
  40981. delete getAtom(i);
  40982. atoms.clear();
  40983. }
  40984. int getNumAtoms() const
  40985. {
  40986. return atoms.size();
  40987. }
  40988. TextAtom* getAtom (const int index) const throw()
  40989. {
  40990. return atoms.getUnchecked (index);
  40991. }
  40992. void append (const UniformTextSection& other, const juce_wchar passwordCharacter)
  40993. {
  40994. if (other.atoms.size() > 0)
  40995. {
  40996. TextAtom* const lastAtom = atoms.getLast();
  40997. int i = 0;
  40998. if (lastAtom != 0)
  40999. {
  41000. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41001. {
  41002. TextAtom* const first = other.getAtom(0);
  41003. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41004. {
  41005. lastAtom->atomText += first->atomText;
  41006. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41007. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41008. delete first;
  41009. ++i;
  41010. }
  41011. }
  41012. }
  41013. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41014. while (i < other.atoms.size())
  41015. {
  41016. atoms.add (other.getAtom(i));
  41017. ++i;
  41018. }
  41019. }
  41020. }
  41021. UniformTextSection* split (const int indexToBreakAt,
  41022. const juce_wchar passwordCharacter)
  41023. {
  41024. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41025. font, colour,
  41026. passwordCharacter);
  41027. int index = 0;
  41028. for (int i = 0; i < atoms.size(); ++i)
  41029. {
  41030. TextAtom* const atom = getAtom(i);
  41031. const int nextIndex = index + atom->numChars;
  41032. if (index == indexToBreakAt)
  41033. {
  41034. int j;
  41035. for (j = i; j < atoms.size(); ++j)
  41036. section2->atoms.add (getAtom (j));
  41037. for (j = atoms.size(); --j >= i;)
  41038. atoms.remove (j);
  41039. break;
  41040. }
  41041. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41042. {
  41043. TextAtom* const secondAtom = new TextAtom();
  41044. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41045. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41046. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41047. section2->atoms.add (secondAtom);
  41048. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41049. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41050. atom->numChars = (uint16) (indexToBreakAt - index);
  41051. int j;
  41052. for (j = i + 1; j < atoms.size(); ++j)
  41053. section2->atoms.add (getAtom (j));
  41054. for (j = atoms.size(); --j > i;)
  41055. atoms.remove (j);
  41056. break;
  41057. }
  41058. index = nextIndex;
  41059. }
  41060. return section2;
  41061. }
  41062. void appendAllText (String::Concatenator& concatenator) const
  41063. {
  41064. for (int i = 0; i < atoms.size(); ++i)
  41065. concatenator.append (getAtom(i)->atomText);
  41066. }
  41067. void appendSubstring (String::Concatenator& concatenator,
  41068. const Range<int>& range) const
  41069. {
  41070. int index = 0;
  41071. for (int i = 0; i < atoms.size(); ++i)
  41072. {
  41073. const TextAtom* const atom = getAtom (i);
  41074. const int nextIndex = index + atom->numChars;
  41075. if (range.getStart() < nextIndex)
  41076. {
  41077. if (range.getEnd() <= index)
  41078. break;
  41079. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41080. if (! r.isEmpty())
  41081. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41082. }
  41083. index = nextIndex;
  41084. }
  41085. }
  41086. int getTotalLength() const
  41087. {
  41088. int total = 0;
  41089. for (int i = atoms.size(); --i >= 0;)
  41090. total += getAtom(i)->numChars;
  41091. return total;
  41092. }
  41093. void setFont (const Font& newFont,
  41094. const juce_wchar passwordCharacter)
  41095. {
  41096. if (font != newFont)
  41097. {
  41098. font = newFont;
  41099. for (int i = atoms.size(); --i >= 0;)
  41100. {
  41101. TextAtom* const atom = atoms.getUnchecked(i);
  41102. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41103. }
  41104. }
  41105. }
  41106. juce_UseDebuggingNewOperator
  41107. Font font;
  41108. Colour colour;
  41109. private:
  41110. Array <TextAtom*> atoms;
  41111. void initialiseAtoms (const String& textToParse,
  41112. const juce_wchar passwordCharacter)
  41113. {
  41114. int i = 0;
  41115. const int len = textToParse.length();
  41116. const juce_wchar* const text = textToParse;
  41117. while (i < len)
  41118. {
  41119. int start = i;
  41120. // create a whitespace atom unless it starts with non-ws
  41121. if (CharacterFunctions::isWhitespace (text[i])
  41122. && text[i] != '\r'
  41123. && text[i] != '\n')
  41124. {
  41125. while (i < len
  41126. && CharacterFunctions::isWhitespace (text[i])
  41127. && text[i] != '\r'
  41128. && text[i] != '\n')
  41129. {
  41130. ++i;
  41131. }
  41132. }
  41133. else
  41134. {
  41135. if (text[i] == '\r')
  41136. {
  41137. ++i;
  41138. if ((i < len) && (text[i] == '\n'))
  41139. {
  41140. ++start;
  41141. ++i;
  41142. }
  41143. }
  41144. else if (text[i] == '\n')
  41145. {
  41146. ++i;
  41147. }
  41148. else
  41149. {
  41150. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41151. ++i;
  41152. }
  41153. }
  41154. TextAtom* const atom = new TextAtom();
  41155. atom->atomText = String (text + start, i - start);
  41156. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41157. atom->numChars = (uint16) (i - start);
  41158. atoms.add (atom);
  41159. }
  41160. }
  41161. UniformTextSection& operator= (const UniformTextSection& other);
  41162. };
  41163. class TextEditor::Iterator
  41164. {
  41165. public:
  41166. Iterator (const Array <UniformTextSection*>& sections_,
  41167. const float wordWrapWidth_,
  41168. const juce_wchar passwordCharacter_)
  41169. : indexInText (0),
  41170. lineY (0),
  41171. lineHeight (0),
  41172. maxDescent (0),
  41173. atomX (0),
  41174. atomRight (0),
  41175. atom (0),
  41176. currentSection (0),
  41177. sections (sections_),
  41178. sectionIndex (0),
  41179. atomIndex (0),
  41180. wordWrapWidth (wordWrapWidth_),
  41181. passwordCharacter (passwordCharacter_)
  41182. {
  41183. jassert (wordWrapWidth_ > 0);
  41184. if (sections.size() > 0)
  41185. {
  41186. currentSection = sections.getUnchecked (sectionIndex);
  41187. if (currentSection != 0)
  41188. beginNewLine();
  41189. }
  41190. }
  41191. Iterator (const Iterator& other)
  41192. : indexInText (other.indexInText),
  41193. lineY (other.lineY),
  41194. lineHeight (other.lineHeight),
  41195. maxDescent (other.maxDescent),
  41196. atomX (other.atomX),
  41197. atomRight (other.atomRight),
  41198. atom (other.atom),
  41199. currentSection (other.currentSection),
  41200. sections (other.sections),
  41201. sectionIndex (other.sectionIndex),
  41202. atomIndex (other.atomIndex),
  41203. wordWrapWidth (other.wordWrapWidth),
  41204. passwordCharacter (other.passwordCharacter),
  41205. tempAtom (other.tempAtom)
  41206. {
  41207. }
  41208. ~Iterator()
  41209. {
  41210. }
  41211. bool next()
  41212. {
  41213. if (atom == &tempAtom)
  41214. {
  41215. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41216. if (numRemaining > 0)
  41217. {
  41218. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41219. atomX = 0;
  41220. if (tempAtom.numChars > 0)
  41221. lineY += lineHeight;
  41222. indexInText += tempAtom.numChars;
  41223. GlyphArrangement g;
  41224. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41225. int split;
  41226. for (split = 0; split < g.getNumGlyphs(); ++split)
  41227. if (shouldWrap (g.getGlyph (split).getRight()))
  41228. break;
  41229. if (split > 0 && split <= numRemaining)
  41230. {
  41231. tempAtom.numChars = (uint16) split;
  41232. tempAtom.width = g.getGlyph (split - 1).getRight();
  41233. atomRight = atomX + tempAtom.width;
  41234. return true;
  41235. }
  41236. }
  41237. }
  41238. bool forceNewLine = false;
  41239. if (sectionIndex >= sections.size())
  41240. {
  41241. moveToEndOfLastAtom();
  41242. return false;
  41243. }
  41244. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41245. {
  41246. if (atomIndex >= currentSection->getNumAtoms())
  41247. {
  41248. if (++sectionIndex >= sections.size())
  41249. {
  41250. moveToEndOfLastAtom();
  41251. return false;
  41252. }
  41253. atomIndex = 0;
  41254. currentSection = sections.getUnchecked (sectionIndex);
  41255. }
  41256. else
  41257. {
  41258. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41259. if (! lastAtom->isWhitespace())
  41260. {
  41261. // handle the case where the last atom in a section is actually part of the same
  41262. // word as the first atom of the next section...
  41263. float right = atomRight + lastAtom->width;
  41264. float lineHeight2 = lineHeight;
  41265. float maxDescent2 = maxDescent;
  41266. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41267. {
  41268. const UniformTextSection* const s = sections.getUnchecked (section);
  41269. if (s->getNumAtoms() == 0)
  41270. break;
  41271. const TextAtom* const nextAtom = s->getAtom (0);
  41272. if (nextAtom->isWhitespace())
  41273. break;
  41274. right += nextAtom->width;
  41275. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41276. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41277. if (shouldWrap (right))
  41278. {
  41279. lineHeight = lineHeight2;
  41280. maxDescent = maxDescent2;
  41281. forceNewLine = true;
  41282. break;
  41283. }
  41284. if (s->getNumAtoms() > 1)
  41285. break;
  41286. }
  41287. }
  41288. }
  41289. }
  41290. if (atom != 0)
  41291. {
  41292. atomX = atomRight;
  41293. indexInText += atom->numChars;
  41294. if (atom->isNewLine())
  41295. beginNewLine();
  41296. }
  41297. atom = currentSection->getAtom (atomIndex);
  41298. atomRight = atomX + atom->width;
  41299. ++atomIndex;
  41300. if (shouldWrap (atomRight) || forceNewLine)
  41301. {
  41302. if (atom->isWhitespace())
  41303. {
  41304. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41305. atomRight = jmin (atomRight, wordWrapWidth);
  41306. }
  41307. else
  41308. {
  41309. atomRight = atom->width;
  41310. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41311. {
  41312. tempAtom = *atom;
  41313. tempAtom.width = 0;
  41314. tempAtom.numChars = 0;
  41315. atom = &tempAtom;
  41316. if (atomX > 0)
  41317. beginNewLine();
  41318. return next();
  41319. }
  41320. beginNewLine();
  41321. return true;
  41322. }
  41323. }
  41324. return true;
  41325. }
  41326. void beginNewLine()
  41327. {
  41328. atomX = 0;
  41329. lineY += lineHeight;
  41330. int tempSectionIndex = sectionIndex;
  41331. int tempAtomIndex = atomIndex;
  41332. const UniformTextSection* section = sections.getUnchecked (tempSectionIndex);
  41333. lineHeight = section->font.getHeight();
  41334. maxDescent = section->font.getDescent();
  41335. float x = (atom != 0) ? atom->width : 0;
  41336. while (! shouldWrap (x))
  41337. {
  41338. if (tempSectionIndex >= sections.size())
  41339. break;
  41340. bool checkSize = false;
  41341. if (tempAtomIndex >= section->getNumAtoms())
  41342. {
  41343. if (++tempSectionIndex >= sections.size())
  41344. break;
  41345. tempAtomIndex = 0;
  41346. section = sections.getUnchecked (tempSectionIndex);
  41347. checkSize = true;
  41348. }
  41349. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41350. if (nextAtom == 0)
  41351. break;
  41352. x += nextAtom->width;
  41353. if (shouldWrap (x) || nextAtom->isNewLine())
  41354. break;
  41355. if (checkSize)
  41356. {
  41357. lineHeight = jmax (lineHeight, section->font.getHeight());
  41358. maxDescent = jmax (maxDescent, section->font.getDescent());
  41359. }
  41360. ++tempAtomIndex;
  41361. }
  41362. }
  41363. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41364. {
  41365. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41366. {
  41367. if (lastSection != currentSection)
  41368. {
  41369. lastSection = currentSection;
  41370. g.setColour (currentSection->colour);
  41371. g.setFont (currentSection->font);
  41372. }
  41373. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41374. GlyphArrangement ga;
  41375. ga.addLineOfText (currentSection->font,
  41376. atom->getTrimmedText (passwordCharacter),
  41377. atomX,
  41378. (float) roundToInt (lineY + lineHeight - maxDescent));
  41379. ga.draw (g);
  41380. }
  41381. }
  41382. void drawSelection (Graphics& g,
  41383. const Range<int>& selection) const
  41384. {
  41385. const int startX = roundToInt (indexToX (selection.getStart()));
  41386. const int endX = roundToInt (indexToX (selection.getEnd()));
  41387. const int y = roundToInt (lineY);
  41388. const int nextY = roundToInt (lineY + lineHeight);
  41389. g.fillRect (startX, y, endX - startX, nextY - y);
  41390. }
  41391. void drawSelectedText (Graphics& g,
  41392. const Range<int>& selection,
  41393. const Colour& selectedTextColour) const
  41394. {
  41395. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41396. {
  41397. GlyphArrangement ga;
  41398. ga.addLineOfText (currentSection->font,
  41399. atom->getTrimmedText (passwordCharacter),
  41400. atomX,
  41401. (float) roundToInt (lineY + lineHeight - maxDescent));
  41402. if (selection.getEnd() < indexInText + atom->numChars)
  41403. {
  41404. GlyphArrangement ga2 (ga);
  41405. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41406. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41407. g.setColour (currentSection->colour);
  41408. ga2.draw (g);
  41409. }
  41410. if (selection.getStart() > indexInText)
  41411. {
  41412. GlyphArrangement ga2 (ga);
  41413. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41414. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41415. g.setColour (currentSection->colour);
  41416. ga2.draw (g);
  41417. }
  41418. g.setColour (selectedTextColour);
  41419. ga.draw (g);
  41420. }
  41421. }
  41422. float indexToX (const int indexToFind) const
  41423. {
  41424. if (indexToFind <= indexInText)
  41425. return atomX;
  41426. if (indexToFind >= indexInText + atom->numChars)
  41427. return atomRight;
  41428. GlyphArrangement g;
  41429. g.addLineOfText (currentSection->font,
  41430. atom->getText (passwordCharacter),
  41431. atomX, 0.0f);
  41432. if (indexToFind - indexInText >= g.getNumGlyphs())
  41433. return atomRight;
  41434. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41435. }
  41436. int xToIndex (const float xToFind) const
  41437. {
  41438. if (xToFind <= atomX || atom->isNewLine())
  41439. return indexInText;
  41440. if (xToFind >= atomRight)
  41441. return indexInText + atom->numChars;
  41442. GlyphArrangement g;
  41443. g.addLineOfText (currentSection->font,
  41444. atom->getText (passwordCharacter),
  41445. atomX, 0.0f);
  41446. int j;
  41447. for (j = 0; j < g.getNumGlyphs(); ++j)
  41448. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41449. break;
  41450. return indexInText + j;
  41451. }
  41452. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41453. {
  41454. while (next())
  41455. {
  41456. if (indexInText + atom->numChars > index)
  41457. {
  41458. cx = indexToX (index);
  41459. cy = lineY;
  41460. lineHeight_ = lineHeight;
  41461. return true;
  41462. }
  41463. }
  41464. cx = atomX;
  41465. cy = lineY;
  41466. lineHeight_ = lineHeight;
  41467. return false;
  41468. }
  41469. juce_UseDebuggingNewOperator
  41470. int indexInText;
  41471. float lineY, lineHeight, maxDescent;
  41472. float atomX, atomRight;
  41473. const TextAtom* atom;
  41474. const UniformTextSection* currentSection;
  41475. private:
  41476. const Array <UniformTextSection*>& sections;
  41477. int sectionIndex, atomIndex;
  41478. const float wordWrapWidth;
  41479. const juce_wchar passwordCharacter;
  41480. TextAtom tempAtom;
  41481. Iterator& operator= (const Iterator&);
  41482. void moveToEndOfLastAtom()
  41483. {
  41484. if (atom != 0)
  41485. {
  41486. atomX = atomRight;
  41487. if (atom->isNewLine())
  41488. {
  41489. atomX = 0.0f;
  41490. lineY += lineHeight;
  41491. }
  41492. }
  41493. }
  41494. bool shouldWrap (const float x) const
  41495. {
  41496. return (x - 0.0001f) >= wordWrapWidth;
  41497. }
  41498. };
  41499. class TextEditor::InsertAction : public UndoableAction
  41500. {
  41501. TextEditor& owner;
  41502. const String text;
  41503. const int insertIndex, oldCaretPos, newCaretPos;
  41504. const Font font;
  41505. const Colour colour;
  41506. InsertAction (const InsertAction&);
  41507. InsertAction& operator= (const InsertAction&);
  41508. public:
  41509. InsertAction (TextEditor& owner_,
  41510. const String& text_,
  41511. const int insertIndex_,
  41512. const Font& font_,
  41513. const Colour& colour_,
  41514. const int oldCaretPos_,
  41515. const int newCaretPos_)
  41516. : owner (owner_),
  41517. text (text_),
  41518. insertIndex (insertIndex_),
  41519. oldCaretPos (oldCaretPos_),
  41520. newCaretPos (newCaretPos_),
  41521. font (font_),
  41522. colour (colour_)
  41523. {
  41524. }
  41525. ~InsertAction()
  41526. {
  41527. }
  41528. bool perform()
  41529. {
  41530. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41531. return true;
  41532. }
  41533. bool undo()
  41534. {
  41535. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41536. return true;
  41537. }
  41538. int getSizeInUnits()
  41539. {
  41540. return text.length() + 16;
  41541. }
  41542. };
  41543. class TextEditor::RemoveAction : public UndoableAction
  41544. {
  41545. TextEditor& owner;
  41546. const Range<int> range;
  41547. const int oldCaretPos, newCaretPos;
  41548. Array <UniformTextSection*> removedSections;
  41549. RemoveAction (const RemoveAction&);
  41550. RemoveAction& operator= (const RemoveAction&);
  41551. public:
  41552. RemoveAction (TextEditor& owner_,
  41553. const Range<int> range_,
  41554. const int oldCaretPos_,
  41555. const int newCaretPos_,
  41556. const Array <UniformTextSection*>& removedSections_)
  41557. : owner (owner_),
  41558. range (range_),
  41559. oldCaretPos (oldCaretPos_),
  41560. newCaretPos (newCaretPos_),
  41561. removedSections (removedSections_)
  41562. {
  41563. }
  41564. ~RemoveAction()
  41565. {
  41566. for (int i = removedSections.size(); --i >= 0;)
  41567. {
  41568. UniformTextSection* const section = removedSections.getUnchecked (i);
  41569. section->clear();
  41570. delete section;
  41571. }
  41572. }
  41573. bool perform()
  41574. {
  41575. owner.remove (range, 0, newCaretPos);
  41576. return true;
  41577. }
  41578. bool undo()
  41579. {
  41580. owner.reinsert (range.getStart(), removedSections);
  41581. owner.moveCursorTo (oldCaretPos, false);
  41582. return true;
  41583. }
  41584. int getSizeInUnits()
  41585. {
  41586. int n = 0;
  41587. for (int i = removedSections.size(); --i >= 0;)
  41588. n += removedSections.getUnchecked (i)->getTotalLength();
  41589. return n + 16;
  41590. }
  41591. };
  41592. class TextEditor::TextHolderComponent : public Component,
  41593. public Timer,
  41594. public Value::Listener
  41595. {
  41596. public:
  41597. TextHolderComponent (TextEditor& owner_)
  41598. : owner (owner_)
  41599. {
  41600. setWantsKeyboardFocus (false);
  41601. setInterceptsMouseClicks (false, true);
  41602. owner.getTextValue().addListener (this);
  41603. }
  41604. ~TextHolderComponent()
  41605. {
  41606. owner.getTextValue().removeListener (this);
  41607. }
  41608. void paint (Graphics& g)
  41609. {
  41610. owner.drawContent (g);
  41611. }
  41612. void timerCallback()
  41613. {
  41614. owner.timerCallbackInt();
  41615. }
  41616. const MouseCursor getMouseCursor()
  41617. {
  41618. return owner.getMouseCursor();
  41619. }
  41620. void valueChanged (Value&)
  41621. {
  41622. owner.textWasChangedByValue();
  41623. }
  41624. private:
  41625. TextEditor& owner;
  41626. TextHolderComponent (const TextHolderComponent&);
  41627. TextHolderComponent& operator= (const TextHolderComponent&);
  41628. };
  41629. class TextEditorViewport : public Viewport
  41630. {
  41631. public:
  41632. TextEditorViewport (TextEditor* const owner_)
  41633. : owner (owner_),
  41634. lastWordWrapWidth (0)
  41635. {
  41636. }
  41637. ~TextEditorViewport()
  41638. {
  41639. }
  41640. void visibleAreaChanged (int, int, int, int)
  41641. {
  41642. const float wordWrapWidth = owner->getWordWrapWidth();
  41643. if (wordWrapWidth != lastWordWrapWidth)
  41644. {
  41645. lastWordWrapWidth = wordWrapWidth;
  41646. owner->updateTextHolderSize();
  41647. }
  41648. }
  41649. private:
  41650. TextEditor* const owner;
  41651. float lastWordWrapWidth;
  41652. TextEditorViewport (const TextEditorViewport&);
  41653. TextEditorViewport& operator= (const TextEditorViewport&);
  41654. };
  41655. namespace TextEditorDefs
  41656. {
  41657. const int flashSpeedIntervalMs = 380;
  41658. const int textChangeMessageId = 0x10003001;
  41659. const int returnKeyMessageId = 0x10003002;
  41660. const int escapeKeyMessageId = 0x10003003;
  41661. const int focusLossMessageId = 0x10003004;
  41662. const int maxActionsPerTransaction = 100;
  41663. }
  41664. TextEditor::TextEditor (const String& name,
  41665. const juce_wchar passwordCharacter_)
  41666. : Component (name),
  41667. borderSize (1, 1, 1, 3),
  41668. readOnly (false),
  41669. multiline (false),
  41670. wordWrap (false),
  41671. returnKeyStartsNewLine (false),
  41672. caretVisible (true),
  41673. popupMenuEnabled (true),
  41674. selectAllTextWhenFocused (false),
  41675. scrollbarVisible (true),
  41676. wasFocused (false),
  41677. caretFlashState (true),
  41678. keepCursorOnScreen (true),
  41679. tabKeyUsed (false),
  41680. menuActive (false),
  41681. valueTextNeedsUpdating (false),
  41682. cursorX (0),
  41683. cursorY (0),
  41684. cursorHeight (0),
  41685. maxTextLength (0),
  41686. leftIndent (4),
  41687. topIndent (4),
  41688. lastTransactionTime (0),
  41689. currentFont (14.0f),
  41690. totalNumChars (0),
  41691. caretPosition (0),
  41692. passwordCharacter (passwordCharacter_),
  41693. dragType (notDragging)
  41694. {
  41695. setOpaque (true);
  41696. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41697. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41698. viewport->setWantsKeyboardFocus (false);
  41699. viewport->setScrollBarsShown (false, false);
  41700. setMouseCursor (MouseCursor::IBeamCursor);
  41701. setWantsKeyboardFocus (true);
  41702. }
  41703. TextEditor::~TextEditor()
  41704. {
  41705. textValue.referTo (Value());
  41706. clearInternal (0);
  41707. viewport = 0;
  41708. textHolder = 0;
  41709. }
  41710. void TextEditor::newTransaction()
  41711. {
  41712. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41713. undoManager.beginNewTransaction();
  41714. }
  41715. void TextEditor::doUndoRedo (const bool isRedo)
  41716. {
  41717. if (! isReadOnly())
  41718. {
  41719. if (isRedo ? undoManager.redo()
  41720. : undoManager.undo())
  41721. {
  41722. scrollToMakeSureCursorIsVisible();
  41723. repaint();
  41724. textChanged();
  41725. }
  41726. }
  41727. }
  41728. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41729. const bool shouldWordWrap)
  41730. {
  41731. multiline = shouldBeMultiLine;
  41732. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41733. setScrollbarsShown (scrollbarVisible);
  41734. viewport->setViewPosition (0, 0);
  41735. resized();
  41736. scrollToMakeSureCursorIsVisible();
  41737. }
  41738. bool TextEditor::isMultiLine() const
  41739. {
  41740. return multiline;
  41741. }
  41742. void TextEditor::setScrollbarsShown (bool enabled)
  41743. {
  41744. scrollbarVisible = enabled;
  41745. enabled = enabled && isMultiLine();
  41746. viewport->setScrollBarsShown (enabled, enabled);
  41747. }
  41748. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41749. {
  41750. readOnly = shouldBeReadOnly;
  41751. enablementChanged();
  41752. }
  41753. bool TextEditor::isReadOnly() const
  41754. {
  41755. return readOnly || ! isEnabled();
  41756. }
  41757. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41758. {
  41759. returnKeyStartsNewLine = shouldStartNewLine;
  41760. }
  41761. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41762. {
  41763. tabKeyUsed = shouldTabKeyBeUsed;
  41764. }
  41765. void TextEditor::setPopupMenuEnabled (const bool b)
  41766. {
  41767. popupMenuEnabled = b;
  41768. }
  41769. void TextEditor::setSelectAllWhenFocused (const bool b)
  41770. {
  41771. selectAllTextWhenFocused = b;
  41772. }
  41773. const Font TextEditor::getFont() const
  41774. {
  41775. return currentFont;
  41776. }
  41777. void TextEditor::setFont (const Font& newFont)
  41778. {
  41779. currentFont = newFont;
  41780. scrollToMakeSureCursorIsVisible();
  41781. }
  41782. void TextEditor::applyFontToAllText (const Font& newFont)
  41783. {
  41784. currentFont = newFont;
  41785. const Colour overallColour (findColour (textColourId));
  41786. for (int i = sections.size(); --i >= 0;)
  41787. {
  41788. UniformTextSection* const uts = sections.getUnchecked (i);
  41789. uts->setFont (newFont, passwordCharacter);
  41790. uts->colour = overallColour;
  41791. }
  41792. coalesceSimilarSections();
  41793. updateTextHolderSize();
  41794. scrollToMakeSureCursorIsVisible();
  41795. repaint();
  41796. }
  41797. void TextEditor::colourChanged()
  41798. {
  41799. setOpaque (findColour (backgroundColourId).isOpaque());
  41800. repaint();
  41801. }
  41802. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41803. {
  41804. caretVisible = shouldCaretBeVisible;
  41805. if (shouldCaretBeVisible)
  41806. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41807. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41808. : MouseCursor::NormalCursor);
  41809. }
  41810. void TextEditor::setInputRestrictions (const int maxLen,
  41811. const String& chars)
  41812. {
  41813. maxTextLength = jmax (0, maxLen);
  41814. allowedCharacters = chars;
  41815. }
  41816. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41817. {
  41818. textToShowWhenEmpty = text;
  41819. colourForTextWhenEmpty = colourToUse;
  41820. }
  41821. void TextEditor::setPasswordCharacter (const juce_wchar newPasswordCharacter)
  41822. {
  41823. if (passwordCharacter != newPasswordCharacter)
  41824. {
  41825. passwordCharacter = newPasswordCharacter;
  41826. resized();
  41827. repaint();
  41828. }
  41829. }
  41830. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41831. {
  41832. viewport->setScrollBarThickness (newThicknessPixels);
  41833. }
  41834. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41835. {
  41836. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41837. }
  41838. void TextEditor::clear()
  41839. {
  41840. clearInternal (0);
  41841. updateTextHolderSize();
  41842. undoManager.clearUndoHistory();
  41843. }
  41844. void TextEditor::setText (const String& newText,
  41845. const bool sendTextChangeMessage)
  41846. {
  41847. const int newLength = newText.length();
  41848. if (newLength != getTotalNumChars() || getText() != newText)
  41849. {
  41850. const int oldCursorPos = caretPosition;
  41851. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41852. clearInternal (0);
  41853. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41854. // if you're adding text with line-feeds to a single-line text editor, it
  41855. // ain't gonna look right!
  41856. jassert (multiline || ! newText.containsAnyOf ("\r\n"));
  41857. if (cursorWasAtEnd && ! isMultiLine())
  41858. moveCursorTo (getTotalNumChars(), false);
  41859. else
  41860. moveCursorTo (oldCursorPos, false);
  41861. if (sendTextChangeMessage)
  41862. textChanged();
  41863. repaint();
  41864. }
  41865. updateTextHolderSize();
  41866. scrollToMakeSureCursorIsVisible();
  41867. undoManager.clearUndoHistory();
  41868. }
  41869. Value& TextEditor::getTextValue()
  41870. {
  41871. if (valueTextNeedsUpdating)
  41872. {
  41873. valueTextNeedsUpdating = false;
  41874. textValue = getText();
  41875. }
  41876. return textValue;
  41877. }
  41878. void TextEditor::textWasChangedByValue()
  41879. {
  41880. if (textValue.getValueSource().getReferenceCount() > 1)
  41881. setText (textValue.getValue());
  41882. }
  41883. void TextEditor::textChanged()
  41884. {
  41885. updateTextHolderSize();
  41886. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41887. if (textValue.getValueSource().getReferenceCount() > 1)
  41888. {
  41889. valueTextNeedsUpdating = false;
  41890. textValue = getText();
  41891. }
  41892. }
  41893. void TextEditor::returnPressed()
  41894. {
  41895. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41896. }
  41897. void TextEditor::escapePressed()
  41898. {
  41899. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41900. }
  41901. void TextEditor::addListener (TextEditorListener* const newListener)
  41902. {
  41903. listeners.add (newListener);
  41904. }
  41905. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41906. {
  41907. listeners.remove (listenerToRemove);
  41908. }
  41909. void TextEditor::timerCallbackInt()
  41910. {
  41911. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41912. if (caretFlashState != newState)
  41913. {
  41914. caretFlashState = newState;
  41915. if (caretFlashState)
  41916. wasFocused = true;
  41917. if (caretVisible
  41918. && hasKeyboardFocus (false)
  41919. && ! isReadOnly())
  41920. {
  41921. repaintCaret();
  41922. }
  41923. }
  41924. const unsigned int now = Time::getApproximateMillisecondCounter();
  41925. if (now > lastTransactionTime + 200)
  41926. newTransaction();
  41927. }
  41928. void TextEditor::repaintCaret()
  41929. {
  41930. if (! findColour (caretColourId).isTransparent())
  41931. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41932. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41933. 4,
  41934. roundToInt (cursorHeight) + 2);
  41935. }
  41936. void TextEditor::repaintText (const Range<int>& range)
  41937. {
  41938. if (! range.isEmpty())
  41939. {
  41940. float x = 0, y = 0, lh = currentFont.getHeight();
  41941. const float wordWrapWidth = getWordWrapWidth();
  41942. if (wordWrapWidth > 0)
  41943. {
  41944. Iterator i (sections, wordWrapWidth, passwordCharacter);
  41945. i.getCharPosition (range.getStart(), x, y, lh);
  41946. const int y1 = (int) y;
  41947. int y2;
  41948. if (range.getEnd() >= getTotalNumChars())
  41949. {
  41950. y2 = textHolder->getHeight();
  41951. }
  41952. else
  41953. {
  41954. i.getCharPosition (range.getEnd(), x, y, lh);
  41955. y2 = (int) (y + lh * 2.0f);
  41956. }
  41957. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41958. }
  41959. }
  41960. }
  41961. void TextEditor::moveCaret (int newCaretPos)
  41962. {
  41963. if (newCaretPos < 0)
  41964. newCaretPos = 0;
  41965. else if (newCaretPos > getTotalNumChars())
  41966. newCaretPos = getTotalNumChars();
  41967. if (newCaretPos != getCaretPosition())
  41968. {
  41969. repaintCaret();
  41970. caretFlashState = true;
  41971. caretPosition = newCaretPos;
  41972. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41973. scrollToMakeSureCursorIsVisible();
  41974. repaintCaret();
  41975. }
  41976. }
  41977. void TextEditor::setCaretPosition (const int newIndex)
  41978. {
  41979. moveCursorTo (newIndex, false);
  41980. }
  41981. int TextEditor::getCaretPosition() const
  41982. {
  41983. return caretPosition;
  41984. }
  41985. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41986. const int desiredCaretY)
  41987. {
  41988. updateCaretPosition();
  41989. int vx = roundToInt (cursorX) - desiredCaretX;
  41990. int vy = roundToInt (cursorY) - desiredCaretY;
  41991. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41992. {
  41993. vx += desiredCaretX - proportionOfWidth (0.2f);
  41994. }
  41995. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41996. {
  41997. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41998. }
  41999. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42000. if (! isMultiLine())
  42001. {
  42002. vy = viewport->getViewPositionY();
  42003. }
  42004. else
  42005. {
  42006. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42007. const int curH = roundToInt (cursorHeight);
  42008. if (desiredCaretY < 0)
  42009. {
  42010. vy = jmax (0, desiredCaretY + vy);
  42011. }
  42012. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42013. {
  42014. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42015. }
  42016. }
  42017. viewport->setViewPosition (vx, vy);
  42018. }
  42019. const Rectangle<int> TextEditor::getCaretRectangle()
  42020. {
  42021. updateCaretPosition();
  42022. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42023. roundToInt (cursorY) - viewport->getY(),
  42024. 1, roundToInt (cursorHeight));
  42025. }
  42026. float TextEditor::getWordWrapWidth() const
  42027. {
  42028. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42029. : 1.0e10f;
  42030. }
  42031. void TextEditor::updateTextHolderSize()
  42032. {
  42033. const float wordWrapWidth = getWordWrapWidth();
  42034. if (wordWrapWidth > 0)
  42035. {
  42036. float maxWidth = 0.0f;
  42037. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42038. while (i.next())
  42039. maxWidth = jmax (maxWidth, i.atomRight);
  42040. const int w = leftIndent + roundToInt (maxWidth);
  42041. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42042. currentFont.getHeight()));
  42043. textHolder->setSize (w + 1, h + 1);
  42044. }
  42045. }
  42046. int TextEditor::getTextWidth() const
  42047. {
  42048. return textHolder->getWidth();
  42049. }
  42050. int TextEditor::getTextHeight() const
  42051. {
  42052. return textHolder->getHeight();
  42053. }
  42054. void TextEditor::setIndents (const int newLeftIndent,
  42055. const int newTopIndent)
  42056. {
  42057. leftIndent = newLeftIndent;
  42058. topIndent = newTopIndent;
  42059. }
  42060. void TextEditor::setBorder (const BorderSize& border)
  42061. {
  42062. borderSize = border;
  42063. resized();
  42064. }
  42065. const BorderSize TextEditor::getBorder() const
  42066. {
  42067. return borderSize;
  42068. }
  42069. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42070. {
  42071. keepCursorOnScreen = shouldScrollToShowCursor;
  42072. }
  42073. void TextEditor::updateCaretPosition()
  42074. {
  42075. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42076. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42077. }
  42078. void TextEditor::scrollToMakeSureCursorIsVisible()
  42079. {
  42080. updateCaretPosition();
  42081. if (keepCursorOnScreen)
  42082. {
  42083. int x = viewport->getViewPositionX();
  42084. int y = viewport->getViewPositionY();
  42085. const int relativeCursorX = roundToInt (cursorX) - x;
  42086. const int relativeCursorY = roundToInt (cursorY) - y;
  42087. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42088. {
  42089. x += relativeCursorX - proportionOfWidth (0.2f);
  42090. }
  42091. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42092. {
  42093. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42094. }
  42095. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42096. if (! isMultiLine())
  42097. {
  42098. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42099. }
  42100. else
  42101. {
  42102. const int curH = roundToInt (cursorHeight);
  42103. if (relativeCursorY < 0)
  42104. {
  42105. y = jmax (0, relativeCursorY + y);
  42106. }
  42107. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42108. {
  42109. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42110. }
  42111. }
  42112. viewport->setViewPosition (x, y);
  42113. }
  42114. }
  42115. void TextEditor::moveCursorTo (const int newPosition,
  42116. const bool isSelecting)
  42117. {
  42118. if (isSelecting)
  42119. {
  42120. moveCaret (newPosition);
  42121. const Range<int> oldSelection (selection);
  42122. if (dragType == notDragging)
  42123. {
  42124. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42125. dragType = draggingSelectionStart;
  42126. else
  42127. dragType = draggingSelectionEnd;
  42128. }
  42129. if (dragType == draggingSelectionStart)
  42130. {
  42131. if (getCaretPosition() >= selection.getEnd())
  42132. dragType = draggingSelectionEnd;
  42133. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42134. }
  42135. else
  42136. {
  42137. if (getCaretPosition() < selection.getStart())
  42138. dragType = draggingSelectionStart;
  42139. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42140. }
  42141. repaintText (selection.getUnionWith (oldSelection));
  42142. }
  42143. else
  42144. {
  42145. dragType = notDragging;
  42146. repaintText (selection);
  42147. moveCaret (newPosition);
  42148. selection = Range<int>::emptyRange (getCaretPosition());
  42149. }
  42150. }
  42151. int TextEditor::getTextIndexAt (const int x,
  42152. const int y)
  42153. {
  42154. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42155. (float) (y + viewport->getViewPositionY() - topIndent));
  42156. }
  42157. void TextEditor::insertTextAtCaret (const String& newText_)
  42158. {
  42159. String newText (newText_);
  42160. if (allowedCharacters.isNotEmpty())
  42161. newText = newText.retainCharacters (allowedCharacters);
  42162. if ((! returnKeyStartsNewLine) && newText == "\n")
  42163. {
  42164. returnPressed();
  42165. return;
  42166. }
  42167. if (! isMultiLine())
  42168. newText = newText.replaceCharacters ("\r\n", " ");
  42169. else
  42170. newText = newText.replace ("\r\n", "\n");
  42171. const int newCaretPos = selection.getStart() + newText.length();
  42172. const int insertIndex = selection.getStart();
  42173. remove (selection, getUndoManager(),
  42174. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42175. if (maxTextLength > 0)
  42176. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42177. if (newText.isNotEmpty())
  42178. insert (newText,
  42179. insertIndex,
  42180. currentFont,
  42181. findColour (textColourId),
  42182. getUndoManager(),
  42183. newCaretPos);
  42184. textChanged();
  42185. }
  42186. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42187. {
  42188. moveCursorTo (newSelection.getStart(), false);
  42189. moveCursorTo (newSelection.getEnd(), true);
  42190. }
  42191. void TextEditor::copy()
  42192. {
  42193. if (passwordCharacter == 0)
  42194. {
  42195. const String selection (getHighlightedText());
  42196. if (selection.isNotEmpty())
  42197. SystemClipboard::copyTextToClipboard (selection);
  42198. }
  42199. }
  42200. void TextEditor::paste()
  42201. {
  42202. if (! isReadOnly())
  42203. {
  42204. const String clip (SystemClipboard::getTextFromClipboard());
  42205. if (clip.isNotEmpty())
  42206. insertTextAtCaret (clip);
  42207. }
  42208. }
  42209. void TextEditor::cut()
  42210. {
  42211. if (! isReadOnly())
  42212. {
  42213. moveCaret (selection.getEnd());
  42214. insertTextAtCaret (String::empty);
  42215. }
  42216. }
  42217. void TextEditor::drawContent (Graphics& g)
  42218. {
  42219. const float wordWrapWidth = getWordWrapWidth();
  42220. if (wordWrapWidth > 0)
  42221. {
  42222. g.setOrigin (leftIndent, topIndent);
  42223. const Rectangle<int> clip (g.getClipBounds());
  42224. Colour selectedTextColour;
  42225. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42226. while (i.lineY + 200.0 < clip.getY() && i.next())
  42227. {}
  42228. if (! selection.isEmpty())
  42229. {
  42230. g.setColour (findColour (highlightColourId)
  42231. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42232. selectedTextColour = findColour (highlightedTextColourId);
  42233. Iterator i2 (i);
  42234. while (i2.next() && i2.lineY < clip.getBottom())
  42235. {
  42236. if (i2.lineY + i2.lineHeight >= clip.getY()
  42237. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42238. {
  42239. i2.drawSelection (g, selection);
  42240. }
  42241. }
  42242. }
  42243. const UniformTextSection* lastSection = 0;
  42244. while (i.next() && i.lineY < clip.getBottom())
  42245. {
  42246. if (i.lineY + i.lineHeight >= clip.getY())
  42247. {
  42248. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42249. {
  42250. i.drawSelectedText (g, selection, selectedTextColour);
  42251. lastSection = 0;
  42252. }
  42253. else
  42254. {
  42255. i.draw (g, lastSection);
  42256. }
  42257. }
  42258. }
  42259. }
  42260. }
  42261. void TextEditor::paint (Graphics& g)
  42262. {
  42263. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42264. }
  42265. void TextEditor::paintOverChildren (Graphics& g)
  42266. {
  42267. if (caretFlashState
  42268. && hasKeyboardFocus (false)
  42269. && caretVisible
  42270. && ! isReadOnly())
  42271. {
  42272. g.setColour (findColour (caretColourId));
  42273. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42274. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42275. 2.0f, cursorHeight);
  42276. }
  42277. if (textToShowWhenEmpty.isNotEmpty()
  42278. && (! hasKeyboardFocus (false))
  42279. && getTotalNumChars() == 0)
  42280. {
  42281. g.setColour (colourForTextWhenEmpty);
  42282. g.setFont (getFont());
  42283. if (isMultiLine())
  42284. {
  42285. g.drawText (textToShowWhenEmpty,
  42286. 0, 0, getWidth(), getHeight(),
  42287. Justification::centred, true);
  42288. }
  42289. else
  42290. {
  42291. g.drawText (textToShowWhenEmpty,
  42292. leftIndent, topIndent,
  42293. viewport->getWidth() - leftIndent,
  42294. viewport->getHeight() - topIndent,
  42295. Justification::centredLeft, true);
  42296. }
  42297. }
  42298. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42299. }
  42300. void TextEditor::mouseDown (const MouseEvent& e)
  42301. {
  42302. beginDragAutoRepeat (100);
  42303. newTransaction();
  42304. if (wasFocused || ! selectAllTextWhenFocused)
  42305. {
  42306. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42307. {
  42308. moveCursorTo (getTextIndexAt (e.x, e.y),
  42309. e.mods.isShiftDown());
  42310. }
  42311. else
  42312. {
  42313. PopupMenu m;
  42314. m.setLookAndFeel (&getLookAndFeel());
  42315. addPopupMenuItems (m, &e);
  42316. menuActive = true;
  42317. const int result = m.show();
  42318. menuActive = false;
  42319. if (result != 0)
  42320. performPopupMenuAction (result);
  42321. }
  42322. }
  42323. }
  42324. void TextEditor::mouseDrag (const MouseEvent& e)
  42325. {
  42326. if (wasFocused || ! selectAllTextWhenFocused)
  42327. {
  42328. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42329. {
  42330. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42331. }
  42332. }
  42333. }
  42334. void TextEditor::mouseUp (const MouseEvent& e)
  42335. {
  42336. newTransaction();
  42337. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42338. if (wasFocused || ! selectAllTextWhenFocused)
  42339. {
  42340. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42341. {
  42342. moveCaret (getTextIndexAt (e.x, e.y));
  42343. }
  42344. }
  42345. wasFocused = true;
  42346. }
  42347. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42348. {
  42349. int tokenEnd = getTextIndexAt (e.x, e.y);
  42350. int tokenStart = tokenEnd;
  42351. if (e.getNumberOfClicks() > 3)
  42352. {
  42353. tokenStart = 0;
  42354. tokenEnd = getTotalNumChars();
  42355. }
  42356. else
  42357. {
  42358. const String t (getText());
  42359. const int totalLength = getTotalNumChars();
  42360. while (tokenEnd < totalLength)
  42361. {
  42362. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42363. ++tokenEnd;
  42364. else
  42365. break;
  42366. }
  42367. tokenStart = tokenEnd;
  42368. while (tokenStart > 0)
  42369. {
  42370. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42371. --tokenStart;
  42372. else
  42373. break;
  42374. }
  42375. if (e.getNumberOfClicks() > 2)
  42376. {
  42377. while (tokenEnd < totalLength)
  42378. {
  42379. if (t [tokenEnd] != '\r' && t [tokenEnd] != '\n')
  42380. ++tokenEnd;
  42381. else
  42382. break;
  42383. }
  42384. while (tokenStart > 0)
  42385. {
  42386. if (t [tokenStart - 1] != '\r' && t [tokenStart - 1] != '\n')
  42387. --tokenStart;
  42388. else
  42389. break;
  42390. }
  42391. }
  42392. }
  42393. moveCursorTo (tokenEnd, false);
  42394. moveCursorTo (tokenStart, true);
  42395. }
  42396. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42397. {
  42398. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42399. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42400. }
  42401. bool TextEditor::keyPressed (const KeyPress& key)
  42402. {
  42403. if (isReadOnly() && key != KeyPress ('c', ModifierKeys::commandModifier, 0))
  42404. return false;
  42405. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42406. if (key.isKeyCode (KeyPress::leftKey)
  42407. || key.isKeyCode (KeyPress::upKey))
  42408. {
  42409. newTransaction();
  42410. int newPos;
  42411. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42412. newPos = indexAtPosition (cursorX, cursorY - 1);
  42413. else if (moveInWholeWordSteps)
  42414. newPos = findWordBreakBefore (getCaretPosition());
  42415. else
  42416. newPos = getCaretPosition() - 1;
  42417. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42418. }
  42419. else if (key.isKeyCode (KeyPress::rightKey)
  42420. || key.isKeyCode (KeyPress::downKey))
  42421. {
  42422. newTransaction();
  42423. int newPos;
  42424. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42425. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42426. else if (moveInWholeWordSteps)
  42427. newPos = findWordBreakAfter (getCaretPosition());
  42428. else
  42429. newPos = getCaretPosition() + 1;
  42430. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42431. }
  42432. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42433. {
  42434. newTransaction();
  42435. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42436. key.getModifiers().isShiftDown());
  42437. }
  42438. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42439. {
  42440. newTransaction();
  42441. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42442. key.getModifiers().isShiftDown());
  42443. }
  42444. else if (key.isKeyCode (KeyPress::homeKey))
  42445. {
  42446. newTransaction();
  42447. if (isMultiLine() && ! moveInWholeWordSteps)
  42448. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42449. key.getModifiers().isShiftDown());
  42450. else
  42451. moveCursorTo (0, key.getModifiers().isShiftDown());
  42452. }
  42453. else if (key.isKeyCode (KeyPress::endKey))
  42454. {
  42455. newTransaction();
  42456. if (isMultiLine() && ! moveInWholeWordSteps)
  42457. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42458. key.getModifiers().isShiftDown());
  42459. else
  42460. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42461. }
  42462. else if (key.isKeyCode (KeyPress::backspaceKey))
  42463. {
  42464. if (moveInWholeWordSteps)
  42465. {
  42466. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42467. }
  42468. else
  42469. {
  42470. if (selection.isEmpty() && selection.getStart() > 0)
  42471. selection.setStart (selection.getEnd() - 1);
  42472. }
  42473. cut();
  42474. }
  42475. else if (key.isKeyCode (KeyPress::deleteKey))
  42476. {
  42477. if (key.getModifiers().isShiftDown())
  42478. copy();
  42479. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42480. selection.setEnd (selection.getStart() + 1);
  42481. cut();
  42482. }
  42483. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0)
  42484. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42485. {
  42486. newTransaction();
  42487. copy();
  42488. }
  42489. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  42490. {
  42491. newTransaction();
  42492. copy();
  42493. cut();
  42494. }
  42495. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0)
  42496. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42497. {
  42498. newTransaction();
  42499. paste();
  42500. }
  42501. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  42502. {
  42503. newTransaction();
  42504. doUndoRedo (false);
  42505. }
  42506. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0))
  42507. {
  42508. newTransaction();
  42509. doUndoRedo (true);
  42510. }
  42511. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  42512. {
  42513. newTransaction();
  42514. moveCursorTo (getTotalNumChars(), false);
  42515. moveCursorTo (0, true);
  42516. }
  42517. else if (key == KeyPress::returnKey)
  42518. {
  42519. newTransaction();
  42520. insertTextAtCaret ("\n");
  42521. }
  42522. else if (key.isKeyCode (KeyPress::escapeKey))
  42523. {
  42524. newTransaction();
  42525. moveCursorTo (getCaretPosition(), false);
  42526. escapePressed();
  42527. }
  42528. else if (key.getTextCharacter() >= ' '
  42529. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42530. {
  42531. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42532. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42533. }
  42534. else
  42535. {
  42536. return false;
  42537. }
  42538. return true;
  42539. }
  42540. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42541. {
  42542. if (! isKeyDown)
  42543. return false;
  42544. #if JUCE_WIN32
  42545. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42546. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42547. #endif
  42548. // (overridden to avoid forwarding key events to the parent)
  42549. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42550. }
  42551. const int baseMenuItemID = 0x7fff0000;
  42552. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42553. {
  42554. const bool writable = ! isReadOnly();
  42555. if (passwordCharacter == 0)
  42556. {
  42557. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42558. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42559. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42560. }
  42561. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42562. m.addSeparator();
  42563. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42564. m.addSeparator();
  42565. if (getUndoManager() != 0)
  42566. {
  42567. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42568. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42569. }
  42570. }
  42571. void TextEditor::performPopupMenuAction (const int menuItemID)
  42572. {
  42573. switch (menuItemID)
  42574. {
  42575. case baseMenuItemID + 1:
  42576. copy();
  42577. cut();
  42578. break;
  42579. case baseMenuItemID + 2:
  42580. copy();
  42581. break;
  42582. case baseMenuItemID + 3:
  42583. paste();
  42584. break;
  42585. case baseMenuItemID + 4:
  42586. cut();
  42587. break;
  42588. case baseMenuItemID + 5:
  42589. moveCursorTo (getTotalNumChars(), false);
  42590. moveCursorTo (0, true);
  42591. break;
  42592. case baseMenuItemID + 6:
  42593. doUndoRedo (false);
  42594. break;
  42595. case baseMenuItemID + 7:
  42596. doUndoRedo (true);
  42597. break;
  42598. default:
  42599. break;
  42600. }
  42601. }
  42602. void TextEditor::focusGained (FocusChangeType)
  42603. {
  42604. newTransaction();
  42605. caretFlashState = true;
  42606. if (selectAllTextWhenFocused)
  42607. {
  42608. moveCursorTo (0, false);
  42609. moveCursorTo (getTotalNumChars(), true);
  42610. }
  42611. repaint();
  42612. if (caretVisible)
  42613. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42614. ComponentPeer* const peer = getPeer();
  42615. if (peer != 0 && ! isReadOnly())
  42616. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42617. }
  42618. void TextEditor::focusLost (FocusChangeType)
  42619. {
  42620. newTransaction();
  42621. wasFocused = false;
  42622. textHolder->stopTimer();
  42623. caretFlashState = false;
  42624. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42625. repaint();
  42626. }
  42627. void TextEditor::resized()
  42628. {
  42629. viewport->setBoundsInset (borderSize);
  42630. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42631. updateTextHolderSize();
  42632. if (! isMultiLine())
  42633. {
  42634. scrollToMakeSureCursorIsVisible();
  42635. }
  42636. else
  42637. {
  42638. updateCaretPosition();
  42639. }
  42640. }
  42641. void TextEditor::handleCommandMessage (const int commandId)
  42642. {
  42643. Component::BailOutChecker checker (this);
  42644. switch (commandId)
  42645. {
  42646. case TextEditorDefs::textChangeMessageId:
  42647. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42648. break;
  42649. case TextEditorDefs::returnKeyMessageId:
  42650. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42651. break;
  42652. case TextEditorDefs::escapeKeyMessageId:
  42653. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42654. break;
  42655. case TextEditorDefs::focusLossMessageId:
  42656. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42657. break;
  42658. default:
  42659. jassertfalse
  42660. break;
  42661. }
  42662. }
  42663. void TextEditor::enablementChanged()
  42664. {
  42665. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42666. : MouseCursor::IBeamCursor);
  42667. repaint();
  42668. }
  42669. UndoManager* TextEditor::getUndoManager() throw()
  42670. {
  42671. return isReadOnly() ? &undoManager : 0;
  42672. }
  42673. void TextEditor::clearInternal (UndoManager* const um)
  42674. {
  42675. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42676. }
  42677. void TextEditor::insert (const String& text,
  42678. const int insertIndex,
  42679. const Font& font,
  42680. const Colour& colour,
  42681. UndoManager* const um,
  42682. const int caretPositionToMoveTo)
  42683. {
  42684. if (text.isNotEmpty())
  42685. {
  42686. if (um != 0)
  42687. {
  42688. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42689. newTransaction();
  42690. um->perform (new InsertAction (*this, text, insertIndex, font, colour,
  42691. caretPosition, caretPositionToMoveTo));
  42692. }
  42693. else
  42694. {
  42695. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42696. // a line gets moved due to word wrap
  42697. int index = 0;
  42698. int nextIndex = 0;
  42699. for (int i = 0; i < sections.size(); ++i)
  42700. {
  42701. nextIndex = index + sections.getUnchecked (i)->getTotalLength();
  42702. if (insertIndex == index)
  42703. {
  42704. sections.insert (i, new UniformTextSection (text,
  42705. font, colour,
  42706. passwordCharacter));
  42707. break;
  42708. }
  42709. else if (insertIndex > index && insertIndex < nextIndex)
  42710. {
  42711. splitSection (i, insertIndex - index);
  42712. sections.insert (i + 1, new UniformTextSection (text,
  42713. font, colour,
  42714. passwordCharacter));
  42715. break;
  42716. }
  42717. index = nextIndex;
  42718. }
  42719. if (nextIndex == insertIndex)
  42720. sections.add (new UniformTextSection (text,
  42721. font, colour,
  42722. passwordCharacter));
  42723. coalesceSimilarSections();
  42724. totalNumChars = -1;
  42725. valueTextNeedsUpdating = true;
  42726. moveCursorTo (caretPositionToMoveTo, false);
  42727. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42728. }
  42729. }
  42730. }
  42731. void TextEditor::reinsert (const int insertIndex,
  42732. const Array <UniformTextSection*>& sectionsToInsert)
  42733. {
  42734. int index = 0;
  42735. int nextIndex = 0;
  42736. for (int i = 0; i < sections.size(); ++i)
  42737. {
  42738. nextIndex = index + sections.getUnchecked (i)->getTotalLength();
  42739. if (insertIndex == index)
  42740. {
  42741. for (int j = sectionsToInsert.size(); --j >= 0;)
  42742. sections.insert (i, new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42743. break;
  42744. }
  42745. else if (insertIndex > index && insertIndex < nextIndex)
  42746. {
  42747. splitSection (i, insertIndex - index);
  42748. for (int j = sectionsToInsert.size(); --j >= 0;)
  42749. sections.insert (i + 1, new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42750. break;
  42751. }
  42752. index = nextIndex;
  42753. }
  42754. if (nextIndex == insertIndex)
  42755. {
  42756. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42757. sections.add (new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42758. }
  42759. coalesceSimilarSections();
  42760. totalNumChars = -1;
  42761. valueTextNeedsUpdating = true;
  42762. }
  42763. void TextEditor::remove (const Range<int>& range,
  42764. UndoManager* const um,
  42765. const int caretPositionToMoveTo)
  42766. {
  42767. if (! range.isEmpty())
  42768. {
  42769. int index = 0;
  42770. for (int i = 0; i < sections.size(); ++i)
  42771. {
  42772. const int nextIndex = index + sections.getUnchecked(i)->getTotalLength();
  42773. if (range.getStart() > index && range.getStart() < nextIndex)
  42774. {
  42775. splitSection (i, range.getStart() - index);
  42776. --i;
  42777. }
  42778. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42779. {
  42780. splitSection (i, range.getEnd() - index);
  42781. --i;
  42782. }
  42783. else
  42784. {
  42785. index = nextIndex;
  42786. if (index > range.getEnd())
  42787. break;
  42788. }
  42789. }
  42790. index = 0;
  42791. if (um != 0)
  42792. {
  42793. Array <UniformTextSection*> removedSections;
  42794. for (int i = 0; i < sections.size(); ++i)
  42795. {
  42796. if (range.getEnd() <= range.getStart())
  42797. break;
  42798. UniformTextSection* const section = sections.getUnchecked (i);
  42799. const int nextIndex = index + section->getTotalLength();
  42800. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42801. removedSections.add (new UniformTextSection (*section));
  42802. index = nextIndex;
  42803. }
  42804. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42805. newTransaction();
  42806. um->perform (new RemoveAction (*this, range, caretPosition,
  42807. caretPositionToMoveTo, removedSections));
  42808. }
  42809. else
  42810. {
  42811. Range<int> remainingRange (range);
  42812. for (int i = 0; i < sections.size(); ++i)
  42813. {
  42814. UniformTextSection* const section = sections.getUnchecked (i);
  42815. const int nextIndex = index + section->getTotalLength();
  42816. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42817. {
  42818. sections.remove(i);
  42819. section->clear();
  42820. delete section;
  42821. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42822. if (remainingRange.isEmpty())
  42823. break;
  42824. --i;
  42825. }
  42826. else
  42827. {
  42828. index = nextIndex;
  42829. }
  42830. }
  42831. coalesceSimilarSections();
  42832. totalNumChars = -1;
  42833. valueTextNeedsUpdating = true;
  42834. moveCursorTo (caretPositionToMoveTo, false);
  42835. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42836. }
  42837. }
  42838. }
  42839. const String TextEditor::getText() const
  42840. {
  42841. String t;
  42842. t.preallocateStorage (getTotalNumChars());
  42843. String::Concatenator concatenator (t);
  42844. for (int i = 0; i < sections.size(); ++i)
  42845. sections.getUnchecked (i)->appendAllText (concatenator);
  42846. return t;
  42847. }
  42848. const String TextEditor::getTextInRange (const Range<int>& range) const
  42849. {
  42850. String t;
  42851. if (! range.isEmpty())
  42852. {
  42853. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42854. String::Concatenator concatenator (t);
  42855. int index = 0;
  42856. for (int i = 0; i < sections.size(); ++i)
  42857. {
  42858. const UniformTextSection* const s = sections.getUnchecked (i);
  42859. const int nextIndex = index + s->getTotalLength();
  42860. if (range.getStart() < nextIndex)
  42861. {
  42862. if (range.getEnd() <= index)
  42863. break;
  42864. s->appendSubstring (concatenator, range - index);
  42865. }
  42866. index = nextIndex;
  42867. }
  42868. }
  42869. return t;
  42870. }
  42871. const String TextEditor::getHighlightedText() const
  42872. {
  42873. return getTextInRange (selection);
  42874. }
  42875. int TextEditor::getTotalNumChars() const
  42876. {
  42877. if (totalNumChars < 0)
  42878. {
  42879. totalNumChars = 0;
  42880. for (int i = sections.size(); --i >= 0;)
  42881. totalNumChars += sections.getUnchecked (i)->getTotalLength();
  42882. }
  42883. return totalNumChars;
  42884. }
  42885. bool TextEditor::isEmpty() const
  42886. {
  42887. return getTotalNumChars() == 0;
  42888. }
  42889. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42890. {
  42891. const float wordWrapWidth = getWordWrapWidth();
  42892. if (wordWrapWidth > 0 && sections.size() > 0)
  42893. {
  42894. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42895. i.getCharPosition (index, cx, cy, lineHeight);
  42896. }
  42897. else
  42898. {
  42899. cx = cy = 0;
  42900. lineHeight = currentFont.getHeight();
  42901. }
  42902. }
  42903. int TextEditor::indexAtPosition (const float x, const float y)
  42904. {
  42905. const float wordWrapWidth = getWordWrapWidth();
  42906. if (wordWrapWidth > 0)
  42907. {
  42908. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42909. while (i.next())
  42910. {
  42911. if (i.lineY + i.lineHeight > y)
  42912. {
  42913. if (i.lineY > y)
  42914. return jmax (0, i.indexInText - 1);
  42915. if (i.atomX >= x)
  42916. return i.indexInText;
  42917. if (x < i.atomRight)
  42918. return i.xToIndex (x);
  42919. }
  42920. }
  42921. }
  42922. return getTotalNumChars();
  42923. }
  42924. static int getCharacterCategory (const juce_wchar character)
  42925. {
  42926. return CharacterFunctions::isLetterOrDigit (character)
  42927. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42928. }
  42929. int TextEditor::findWordBreakAfter (const int position) const
  42930. {
  42931. const String t (getTextInRange (Range<int> (position, position + 512)));
  42932. const int totalLength = t.length();
  42933. int i = 0;
  42934. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42935. ++i;
  42936. const int type = getCharacterCategory (t[i]);
  42937. while (i < totalLength && type == getCharacterCategory (t[i]))
  42938. ++i;
  42939. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42940. ++i;
  42941. return position + i;
  42942. }
  42943. int TextEditor::findWordBreakBefore (const int position) const
  42944. {
  42945. if (position <= 0)
  42946. return 0;
  42947. const int startOfBuffer = jmax (0, position - 512);
  42948. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42949. int i = position - startOfBuffer;
  42950. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42951. --i;
  42952. if (i > 0)
  42953. {
  42954. const int type = getCharacterCategory (t [i - 1]);
  42955. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42956. --i;
  42957. }
  42958. jassert (startOfBuffer + i >= 0);
  42959. return startOfBuffer + i;
  42960. }
  42961. void TextEditor::splitSection (const int sectionIndex,
  42962. const int charToSplitAt)
  42963. {
  42964. jassert (sections[sectionIndex] != 0);
  42965. sections.insert (sectionIndex + 1,
  42966. sections.getUnchecked (sectionIndex)->split (charToSplitAt, passwordCharacter));
  42967. }
  42968. void TextEditor::coalesceSimilarSections()
  42969. {
  42970. for (int i = 0; i < sections.size() - 1; ++i)
  42971. {
  42972. UniformTextSection* const s1 = sections.getUnchecked (i);
  42973. UniformTextSection* const s2 = sections.getUnchecked (i + 1);
  42974. if (s1->font == s2->font
  42975. && s1->colour == s2->colour)
  42976. {
  42977. s1->append (*s2, passwordCharacter);
  42978. sections.remove (i + 1);
  42979. delete s2;
  42980. --i;
  42981. }
  42982. }
  42983. }
  42984. END_JUCE_NAMESPACE
  42985. /*** End of inlined file: juce_TextEditor.cpp ***/
  42986. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42987. BEGIN_JUCE_NAMESPACE
  42988. const char* const Toolbar::toolbarDragDescriptor = "_toolbarItem_";
  42989. class ToolbarSpacerComp : public ToolbarItemComponent
  42990. {
  42991. public:
  42992. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42993. : ToolbarItemComponent (itemId_, String::empty, false),
  42994. fixedSize (fixedSize_),
  42995. drawBar (drawBar_)
  42996. {
  42997. }
  42998. ~ToolbarSpacerComp()
  42999. {
  43000. }
  43001. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43002. int& preferredSize, int& minSize, int& maxSize)
  43003. {
  43004. if (fixedSize <= 0)
  43005. {
  43006. preferredSize = toolbarThickness * 2;
  43007. minSize = 4;
  43008. maxSize = 32768;
  43009. }
  43010. else
  43011. {
  43012. maxSize = roundToInt (toolbarThickness * fixedSize);
  43013. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43014. preferredSize = maxSize;
  43015. if (getEditingMode() == editableOnPalette)
  43016. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43017. }
  43018. return true;
  43019. }
  43020. void paintButtonArea (Graphics&, int, int, bool, bool)
  43021. {
  43022. }
  43023. void contentAreaChanged (const Rectangle<int>&)
  43024. {
  43025. }
  43026. int getResizeOrder() const throw()
  43027. {
  43028. return fixedSize <= 0 ? 0 : 1;
  43029. }
  43030. void paint (Graphics& g)
  43031. {
  43032. const int w = getWidth();
  43033. const int h = getHeight();
  43034. if (drawBar)
  43035. {
  43036. g.setColour (findColour (Toolbar::separatorColourId, true));
  43037. const float thickness = 0.2f;
  43038. if (isToolbarVertical())
  43039. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43040. else
  43041. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43042. }
  43043. if (getEditingMode() != normalMode && ! drawBar)
  43044. {
  43045. g.setColour (findColour (Toolbar::separatorColourId, true));
  43046. const int indentX = jmin (2, (w - 3) / 2);
  43047. const int indentY = jmin (2, (h - 3) / 2);
  43048. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43049. if (fixedSize <= 0)
  43050. {
  43051. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43052. if (isToolbarVertical())
  43053. {
  43054. x1 = w * 0.5f;
  43055. y1 = h * 0.4f;
  43056. x2 = x1;
  43057. y2 = indentX * 2.0f;
  43058. x3 = x1;
  43059. y3 = h * 0.6f;
  43060. x4 = x1;
  43061. y4 = h - y2;
  43062. hw = w * 0.15f;
  43063. hl = w * 0.2f;
  43064. }
  43065. else
  43066. {
  43067. x1 = w * 0.4f;
  43068. y1 = h * 0.5f;
  43069. x2 = indentX * 2.0f;
  43070. y2 = y1;
  43071. x3 = w * 0.6f;
  43072. y3 = y1;
  43073. x4 = w - x2;
  43074. y4 = y1;
  43075. hw = h * 0.15f;
  43076. hl = h * 0.2f;
  43077. }
  43078. Path p;
  43079. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43080. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43081. g.fillPath (p);
  43082. }
  43083. }
  43084. }
  43085. juce_UseDebuggingNewOperator
  43086. private:
  43087. const float fixedSize;
  43088. const bool drawBar;
  43089. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43090. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43091. };
  43092. class MissingItemsComponent : public PopupMenuCustomComponent
  43093. {
  43094. public:
  43095. MissingItemsComponent (Toolbar& owner_, const int height_)
  43096. : PopupMenuCustomComponent (true),
  43097. owner (owner_),
  43098. height (height_)
  43099. {
  43100. for (int i = owner_.items.size(); --i >= 0;)
  43101. {
  43102. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43103. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43104. {
  43105. oldIndexes.insert (0, i);
  43106. addAndMakeVisible (tc, 0);
  43107. }
  43108. }
  43109. layout (400);
  43110. }
  43111. ~MissingItemsComponent()
  43112. {
  43113. // deleting the toolbar while its menu it open??
  43114. jassert (owner.isValidComponent());
  43115. for (int i = 0; i < getNumChildComponents(); ++i)
  43116. {
  43117. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43118. if (tc != 0)
  43119. {
  43120. tc->setVisible (false);
  43121. const int index = oldIndexes.remove (i);
  43122. owner.addChildComponent (tc, index);
  43123. --i;
  43124. }
  43125. }
  43126. owner.resized();
  43127. }
  43128. void layout (const int preferredWidth)
  43129. {
  43130. const int indent = 8;
  43131. int x = indent;
  43132. int y = indent;
  43133. int maxX = 0;
  43134. for (int i = 0; i < getNumChildComponents(); ++i)
  43135. {
  43136. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43137. if (tc != 0)
  43138. {
  43139. int preferredSize = 1, minSize = 1, maxSize = 1;
  43140. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43141. {
  43142. if (x + preferredSize > preferredWidth && x > indent)
  43143. {
  43144. x = indent;
  43145. y += height;
  43146. }
  43147. tc->setBounds (x, y, preferredSize, height);
  43148. x += preferredSize;
  43149. maxX = jmax (maxX, x);
  43150. }
  43151. }
  43152. }
  43153. setSize (maxX + 8, y + height + 8);
  43154. }
  43155. void getIdealSize (int& idealWidth, int& idealHeight)
  43156. {
  43157. idealWidth = getWidth();
  43158. idealHeight = getHeight();
  43159. }
  43160. juce_UseDebuggingNewOperator
  43161. private:
  43162. Toolbar& owner;
  43163. const int height;
  43164. Array <int> oldIndexes;
  43165. MissingItemsComponent (const MissingItemsComponent&);
  43166. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43167. };
  43168. Toolbar::Toolbar()
  43169. : vertical (false),
  43170. isEditingActive (false),
  43171. toolbarStyle (Toolbar::iconsOnly)
  43172. {
  43173. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43174. missingItemsButton->setAlwaysOnTop (true);
  43175. missingItemsButton->addButtonListener (this);
  43176. }
  43177. Toolbar::~Toolbar()
  43178. {
  43179. animator.cancelAllAnimations (true);
  43180. deleteAllChildren();
  43181. }
  43182. void Toolbar::setVertical (const bool shouldBeVertical)
  43183. {
  43184. if (vertical != shouldBeVertical)
  43185. {
  43186. vertical = shouldBeVertical;
  43187. resized();
  43188. }
  43189. }
  43190. void Toolbar::clear()
  43191. {
  43192. for (int i = items.size(); --i >= 0;)
  43193. {
  43194. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43195. items.remove (i);
  43196. delete tc;
  43197. }
  43198. resized();
  43199. }
  43200. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43201. {
  43202. if (itemId == ToolbarItemFactory::separatorBarId)
  43203. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43204. else if (itemId == ToolbarItemFactory::spacerId)
  43205. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43206. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43207. return new ToolbarSpacerComp (itemId, 0, false);
  43208. return factory.createItem (itemId);
  43209. }
  43210. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43211. const int itemId,
  43212. const int insertIndex)
  43213. {
  43214. // An ID can't be zero - this might indicate a mistake somewhere?
  43215. jassert (itemId != 0);
  43216. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43217. if (tc != 0)
  43218. {
  43219. #ifdef JUCE_DEBUG
  43220. Array <int> allowedIds;
  43221. factory.getAllToolbarItemIds (allowedIds);
  43222. // If your factory can create an item for a given ID, it must also return
  43223. // that ID from its getAllToolbarItemIds() method!
  43224. jassert (allowedIds.contains (itemId));
  43225. #endif
  43226. items.insert (insertIndex, tc);
  43227. addAndMakeVisible (tc, insertIndex);
  43228. }
  43229. }
  43230. void Toolbar::addItem (ToolbarItemFactory& factory,
  43231. const int itemId,
  43232. const int insertIndex)
  43233. {
  43234. addItemInternal (factory, itemId, insertIndex);
  43235. resized();
  43236. }
  43237. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43238. {
  43239. Array <int> ids;
  43240. factoryToUse.getDefaultItemSet (ids);
  43241. clear();
  43242. for (int i = 0; i < ids.size(); ++i)
  43243. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43244. resized();
  43245. }
  43246. void Toolbar::removeToolbarItem (const int itemIndex)
  43247. {
  43248. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43249. if (tc != 0)
  43250. {
  43251. items.removeValue (tc);
  43252. delete tc;
  43253. resized();
  43254. }
  43255. }
  43256. int Toolbar::getNumItems() const throw()
  43257. {
  43258. return items.size();
  43259. }
  43260. int Toolbar::getItemId (const int itemIndex) const throw()
  43261. {
  43262. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43263. return tc != 0 ? tc->getItemId() : 0;
  43264. }
  43265. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43266. {
  43267. return items [itemIndex];
  43268. }
  43269. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43270. {
  43271. for (;;)
  43272. {
  43273. index += delta;
  43274. ToolbarItemComponent* const tc = getItemComponent (index);
  43275. if (tc == 0)
  43276. break;
  43277. if (tc->isActive)
  43278. return tc;
  43279. }
  43280. return 0;
  43281. }
  43282. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43283. {
  43284. if (toolbarStyle != newStyle)
  43285. {
  43286. toolbarStyle = newStyle;
  43287. updateAllItemPositions (false);
  43288. }
  43289. }
  43290. const String Toolbar::toString() const
  43291. {
  43292. String s ("TB:");
  43293. for (int i = 0; i < getNumItems(); ++i)
  43294. s << getItemId(i) << ' ';
  43295. return s.trimEnd();
  43296. }
  43297. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43298. const String& savedVersion)
  43299. {
  43300. if (! savedVersion.startsWith ("TB:"))
  43301. return false;
  43302. StringArray tokens;
  43303. tokens.addTokens (savedVersion.substring (3), false);
  43304. clear();
  43305. for (int i = 0; i < tokens.size(); ++i)
  43306. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43307. resized();
  43308. return true;
  43309. }
  43310. void Toolbar::paint (Graphics& g)
  43311. {
  43312. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43313. }
  43314. int Toolbar::getThickness() const throw()
  43315. {
  43316. return vertical ? getWidth() : getHeight();
  43317. }
  43318. int Toolbar::getLength() const throw()
  43319. {
  43320. return vertical ? getHeight() : getWidth();
  43321. }
  43322. void Toolbar::setEditingActive (const bool active)
  43323. {
  43324. if (isEditingActive != active)
  43325. {
  43326. isEditingActive = active;
  43327. updateAllItemPositions (false);
  43328. }
  43329. }
  43330. void Toolbar::resized()
  43331. {
  43332. updateAllItemPositions (false);
  43333. }
  43334. void Toolbar::updateAllItemPositions (const bool animate)
  43335. {
  43336. if (getWidth() > 0 && getHeight() > 0)
  43337. {
  43338. StretchableObjectResizer resizer;
  43339. int i;
  43340. for (i = 0; i < items.size(); ++i)
  43341. {
  43342. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43343. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43344. : ToolbarItemComponent::normalMode);
  43345. tc->setStyle (toolbarStyle);
  43346. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43347. int preferredSize = 1, minSize = 1, maxSize = 1;
  43348. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43349. preferredSize, minSize, maxSize))
  43350. {
  43351. tc->isActive = true;
  43352. resizer.addItem (preferredSize, minSize, maxSize,
  43353. spacer != 0 ? spacer->getResizeOrder() : 2);
  43354. }
  43355. else
  43356. {
  43357. tc->isActive = false;
  43358. tc->setVisible (false);
  43359. }
  43360. }
  43361. resizer.resizeToFit (getLength());
  43362. int totalLength = 0;
  43363. for (i = 0; i < resizer.getNumItems(); ++i)
  43364. totalLength += (int) resizer.getItemSize (i);
  43365. const bool itemsOffTheEnd = totalLength > getLength();
  43366. const int extrasButtonSize = getThickness() / 2;
  43367. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43368. missingItemsButton->setVisible (itemsOffTheEnd);
  43369. missingItemsButton->setEnabled (! isEditingActive);
  43370. if (vertical)
  43371. missingItemsButton->setCentrePosition (getWidth() / 2,
  43372. getHeight() - 4 - extrasButtonSize / 2);
  43373. else
  43374. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43375. getHeight() / 2);
  43376. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43377. : missingItemsButton->getX()) - 4
  43378. : getLength();
  43379. int pos = 0, activeIndex = 0;
  43380. for (i = 0; i < items.size(); ++i)
  43381. {
  43382. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43383. if (tc->isActive)
  43384. {
  43385. const int size = (int) resizer.getItemSize (activeIndex++);
  43386. Rectangle<int> newBounds;
  43387. if (vertical)
  43388. newBounds.setBounds (0, pos, getWidth(), size);
  43389. else
  43390. newBounds.setBounds (pos, 0, size, getHeight());
  43391. if (animate)
  43392. {
  43393. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43394. }
  43395. else
  43396. {
  43397. animator.cancelAnimation (tc, false);
  43398. tc->setBounds (newBounds);
  43399. }
  43400. pos += size;
  43401. tc->setVisible (pos <= maxLength
  43402. && ((! tc->isBeingDragged)
  43403. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43404. }
  43405. }
  43406. }
  43407. }
  43408. void Toolbar::buttonClicked (Button*)
  43409. {
  43410. jassert (missingItemsButton->isShowing());
  43411. if (missingItemsButton->isShowing())
  43412. {
  43413. PopupMenu m;
  43414. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43415. m.showAt (missingItemsButton);
  43416. }
  43417. }
  43418. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43419. Component* /*sourceComponent*/)
  43420. {
  43421. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43422. }
  43423. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43424. {
  43425. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43426. if (tc != 0)
  43427. {
  43428. if (getNumItems() == 0)
  43429. {
  43430. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43431. {
  43432. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43433. if (palette != 0)
  43434. palette->replaceComponent (tc);
  43435. }
  43436. else
  43437. {
  43438. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43439. }
  43440. items.add (tc);
  43441. addChildComponent (tc);
  43442. updateAllItemPositions (false);
  43443. }
  43444. else
  43445. {
  43446. for (int i = getNumItems(); --i >= 0;)
  43447. {
  43448. int currentIndex = getIndexOfChildComponent (tc);
  43449. if (currentIndex < 0)
  43450. {
  43451. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43452. {
  43453. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43454. if (palette != 0)
  43455. palette->replaceComponent (tc);
  43456. }
  43457. else
  43458. {
  43459. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43460. }
  43461. items.add (tc);
  43462. addChildComponent (tc);
  43463. currentIndex = getIndexOfChildComponent (tc);
  43464. updateAllItemPositions (true);
  43465. }
  43466. int newIndex = currentIndex;
  43467. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43468. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43469. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43470. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43471. if (prev != 0)
  43472. {
  43473. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43474. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43475. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43476. {
  43477. newIndex = getIndexOfChildComponent (prev);
  43478. }
  43479. }
  43480. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43481. if (next != 0)
  43482. {
  43483. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43484. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43485. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43486. {
  43487. newIndex = getIndexOfChildComponent (next) + 1;
  43488. }
  43489. }
  43490. if (newIndex != currentIndex)
  43491. {
  43492. items.removeValue (tc);
  43493. removeChildComponent (tc);
  43494. addChildComponent (tc, newIndex);
  43495. items.insert (newIndex, tc);
  43496. updateAllItemPositions (true);
  43497. }
  43498. else
  43499. {
  43500. break;
  43501. }
  43502. }
  43503. }
  43504. }
  43505. }
  43506. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43507. {
  43508. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43509. if (tc != 0)
  43510. {
  43511. if (isParentOf (tc))
  43512. {
  43513. items.removeValue (tc);
  43514. removeChildComponent (tc);
  43515. updateAllItemPositions (true);
  43516. }
  43517. }
  43518. }
  43519. void Toolbar::itemDropped (const String&, Component*, int, int)
  43520. {
  43521. }
  43522. void Toolbar::mouseDown (const MouseEvent& e)
  43523. {
  43524. if (e.mods.isPopupMenu())
  43525. {
  43526. }
  43527. }
  43528. class ToolbarCustomisationDialog : public DialogWindow
  43529. {
  43530. public:
  43531. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43532. Toolbar* const toolbar_,
  43533. const int optionFlags)
  43534. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43535. toolbar (toolbar_)
  43536. {
  43537. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43538. setResizable (true, true);
  43539. setResizeLimits (400, 300, 1500, 1000);
  43540. positionNearBar();
  43541. }
  43542. ~ToolbarCustomisationDialog()
  43543. {
  43544. setContentComponent (0, true);
  43545. }
  43546. void closeButtonPressed()
  43547. {
  43548. setVisible (false);
  43549. }
  43550. bool canModalEventBeSentToComponent (const Component* comp)
  43551. {
  43552. return toolbar->isParentOf (comp);
  43553. }
  43554. void positionNearBar()
  43555. {
  43556. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43557. const int tbx = toolbar->getScreenX();
  43558. const int tby = toolbar->getScreenY();
  43559. const int gap = 8;
  43560. int x, y;
  43561. if (toolbar->isVertical())
  43562. {
  43563. y = tby;
  43564. if (tbx > screenSize.getCentreX())
  43565. x = tbx - getWidth() - gap;
  43566. else
  43567. x = tbx + toolbar->getWidth() + gap;
  43568. }
  43569. else
  43570. {
  43571. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43572. if (tby > screenSize.getCentreY())
  43573. y = tby - getHeight() - gap;
  43574. else
  43575. y = tby + toolbar->getHeight() + gap;
  43576. }
  43577. setTopLeftPosition (x, y);
  43578. }
  43579. private:
  43580. Toolbar* const toolbar;
  43581. class CustomiserPanel : public Component,
  43582. private ComboBoxListener,
  43583. private ButtonListener
  43584. {
  43585. public:
  43586. CustomiserPanel (ToolbarItemFactory& factory_,
  43587. Toolbar* const toolbar_,
  43588. const int optionFlags)
  43589. : factory (factory_),
  43590. toolbar (toolbar_),
  43591. styleBox (0),
  43592. defaultButton (0)
  43593. {
  43594. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43595. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43596. | Toolbar::allowIconsWithTextChoice
  43597. | Toolbar::allowTextOnlyChoice)) != 0)
  43598. {
  43599. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43600. styleBox->setEditableText (false);
  43601. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43602. styleBox->addItem (TRANS("Show icons only"), 1);
  43603. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43604. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43605. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43606. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43607. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43608. styleBox->setSelectedId (1);
  43609. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43610. styleBox->setSelectedId (2);
  43611. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43612. styleBox->setSelectedId (3);
  43613. styleBox->addListener (this);
  43614. }
  43615. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43616. {
  43617. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43618. defaultButton->addButtonListener (this);
  43619. }
  43620. addAndMakeVisible (instructions = new Label (String::empty,
  43621. 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.")));
  43622. instructions->setFont (Font (13.0f));
  43623. setSize (500, 300);
  43624. }
  43625. ~CustomiserPanel()
  43626. {
  43627. deleteAllChildren();
  43628. }
  43629. void comboBoxChanged (ComboBox*)
  43630. {
  43631. if (styleBox->getSelectedId() == 1)
  43632. toolbar->setStyle (Toolbar::iconsOnly);
  43633. else if (styleBox->getSelectedId() == 2)
  43634. toolbar->setStyle (Toolbar::iconsWithText);
  43635. else if (styleBox->getSelectedId() == 3)
  43636. toolbar->setStyle (Toolbar::textOnly);
  43637. palette->resized(); // to make it update the styles
  43638. }
  43639. void buttonClicked (Button*)
  43640. {
  43641. toolbar->addDefaultItems (factory);
  43642. }
  43643. void paint (Graphics& g)
  43644. {
  43645. Colour background;
  43646. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43647. if (dw != 0)
  43648. background = dw->getBackgroundColour();
  43649. g.setColour (background.contrasting().withAlpha (0.3f));
  43650. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43651. }
  43652. void resized()
  43653. {
  43654. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43655. if (styleBox != 0)
  43656. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43657. if (defaultButton != 0)
  43658. {
  43659. defaultButton->changeWidthToFitText (22);
  43660. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43661. }
  43662. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43663. }
  43664. private:
  43665. ToolbarItemFactory& factory;
  43666. Toolbar* const toolbar;
  43667. Label* instructions;
  43668. ToolbarItemPalette* palette;
  43669. ComboBox* styleBox;
  43670. TextButton* defaultButton;
  43671. };
  43672. };
  43673. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43674. {
  43675. setEditingActive (true);
  43676. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43677. dw.runModalLoop();
  43678. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43679. setEditingActive (false);
  43680. }
  43681. END_JUCE_NAMESPACE
  43682. /*** End of inlined file: juce_Toolbar.cpp ***/
  43683. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43684. BEGIN_JUCE_NAMESPACE
  43685. ToolbarItemFactory::ToolbarItemFactory()
  43686. {
  43687. }
  43688. ToolbarItemFactory::~ToolbarItemFactory()
  43689. {
  43690. }
  43691. class ItemDragAndDropOverlayComponent : public Component
  43692. {
  43693. public:
  43694. ItemDragAndDropOverlayComponent()
  43695. : isDragging (false)
  43696. {
  43697. setAlwaysOnTop (true);
  43698. setRepaintsOnMouseActivity (true);
  43699. setMouseCursor (MouseCursor::DraggingHandCursor);
  43700. }
  43701. ~ItemDragAndDropOverlayComponent()
  43702. {
  43703. }
  43704. void paint (Graphics& g)
  43705. {
  43706. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43707. if (isMouseOverOrDragging()
  43708. && tc != 0
  43709. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43710. {
  43711. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43712. g.drawRect (0, 0, getWidth(), getHeight(),
  43713. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43714. }
  43715. }
  43716. void mouseDown (const MouseEvent& e)
  43717. {
  43718. isDragging = false;
  43719. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43720. if (tc != 0)
  43721. {
  43722. tc->dragOffsetX = e.x;
  43723. tc->dragOffsetY = e.y;
  43724. }
  43725. }
  43726. void mouseDrag (const MouseEvent& e)
  43727. {
  43728. if (! (isDragging || e.mouseWasClicked()))
  43729. {
  43730. isDragging = true;
  43731. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43732. if (dnd != 0)
  43733. {
  43734. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43735. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43736. if (tc != 0)
  43737. {
  43738. tc->isBeingDragged = true;
  43739. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43740. tc->setVisible (false);
  43741. }
  43742. }
  43743. }
  43744. }
  43745. void mouseUp (const MouseEvent&)
  43746. {
  43747. isDragging = false;
  43748. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43749. if (tc != 0)
  43750. {
  43751. tc->isBeingDragged = false;
  43752. Toolbar* const tb = tc->getToolbar();
  43753. if (tb != 0)
  43754. tb->updateAllItemPositions (true);
  43755. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43756. delete tc;
  43757. }
  43758. }
  43759. void parentSizeChanged()
  43760. {
  43761. setBounds (0, 0, getParentWidth(), getParentHeight());
  43762. }
  43763. juce_UseDebuggingNewOperator
  43764. private:
  43765. bool isDragging;
  43766. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43767. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43768. };
  43769. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43770. const String& labelText,
  43771. const bool isBeingUsedAsAButton_)
  43772. : Button (labelText),
  43773. itemId (itemId_),
  43774. mode (normalMode),
  43775. toolbarStyle (Toolbar::iconsOnly),
  43776. dragOffsetX (0),
  43777. dragOffsetY (0),
  43778. isActive (true),
  43779. isBeingDragged (false),
  43780. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43781. {
  43782. // Your item ID can't be 0!
  43783. jassert (itemId_ != 0);
  43784. }
  43785. ToolbarItemComponent::~ToolbarItemComponent()
  43786. {
  43787. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43788. overlayComp = 0;
  43789. }
  43790. Toolbar* ToolbarItemComponent::getToolbar() const
  43791. {
  43792. return dynamic_cast <Toolbar*> (getParentComponent());
  43793. }
  43794. bool ToolbarItemComponent::isToolbarVertical() const
  43795. {
  43796. const Toolbar* const t = getToolbar();
  43797. return t != 0 && t->isVertical();
  43798. }
  43799. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43800. {
  43801. if (toolbarStyle != newStyle)
  43802. {
  43803. toolbarStyle = newStyle;
  43804. repaint();
  43805. resized();
  43806. }
  43807. }
  43808. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43809. {
  43810. if (isBeingUsedAsAButton)
  43811. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43812. isMouseOver, isMouseDown, *this);
  43813. if (toolbarStyle != Toolbar::iconsOnly)
  43814. {
  43815. const int indent = contentArea.getX();
  43816. int y = indent;
  43817. int h = getHeight() - indent * 2;
  43818. if (toolbarStyle == Toolbar::iconsWithText)
  43819. {
  43820. y = contentArea.getBottom() + indent / 2;
  43821. h -= contentArea.getHeight();
  43822. }
  43823. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43824. getButtonText(), *this);
  43825. }
  43826. if (! contentArea.isEmpty())
  43827. {
  43828. g.saveState();
  43829. g.setOrigin (contentArea.getX(), contentArea.getY());
  43830. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43831. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43832. g.restoreState();
  43833. }
  43834. }
  43835. void ToolbarItemComponent::resized()
  43836. {
  43837. if (toolbarStyle != Toolbar::textOnly)
  43838. {
  43839. const int indent = jmin (proportionOfWidth (0.08f),
  43840. proportionOfHeight (0.08f));
  43841. contentArea = Rectangle<int> (indent, indent,
  43842. getWidth() - indent * 2,
  43843. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43844. : (getHeight() - indent * 2));
  43845. }
  43846. else
  43847. {
  43848. contentArea = Rectangle<int>();
  43849. }
  43850. contentAreaChanged (contentArea);
  43851. }
  43852. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43853. {
  43854. if (mode != newMode)
  43855. {
  43856. mode = newMode;
  43857. repaint();
  43858. if (mode == normalMode)
  43859. {
  43860. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43861. overlayComp = 0;
  43862. }
  43863. else if (overlayComp == 0)
  43864. {
  43865. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43866. overlayComp->parentSizeChanged();
  43867. }
  43868. resized();
  43869. }
  43870. }
  43871. END_JUCE_NAMESPACE
  43872. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43873. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43874. BEGIN_JUCE_NAMESPACE
  43875. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43876. Toolbar* const toolbar_)
  43877. : factory (factory_),
  43878. toolbar (toolbar_)
  43879. {
  43880. Component* const itemHolder = new Component();
  43881. Array <int> allIds;
  43882. factory_.getAllToolbarItemIds (allIds);
  43883. for (int i = 0; i < allIds.size(); ++i)
  43884. {
  43885. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43886. jassert (tc != 0);
  43887. if (tc != 0)
  43888. {
  43889. itemHolder->addAndMakeVisible (tc);
  43890. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43891. }
  43892. }
  43893. viewport = new Viewport();
  43894. viewport->setViewedComponent (itemHolder);
  43895. addAndMakeVisible (viewport);
  43896. }
  43897. ToolbarItemPalette::~ToolbarItemPalette()
  43898. {
  43899. viewport->getViewedComponent()->deleteAllChildren();
  43900. deleteAllChildren();
  43901. }
  43902. void ToolbarItemPalette::resized()
  43903. {
  43904. viewport->setBoundsInset (BorderSize (1));
  43905. Component* const itemHolder = viewport->getViewedComponent();
  43906. const int indent = 8;
  43907. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43908. const int height = toolbar->getThickness();
  43909. int x = indent;
  43910. int y = indent;
  43911. int maxX = 0;
  43912. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43913. {
  43914. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43915. if (tc != 0)
  43916. {
  43917. tc->setStyle (toolbar->getStyle());
  43918. int preferredSize = 1, minSize = 1, maxSize = 1;
  43919. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43920. {
  43921. if (x + preferredSize > preferredWidth && x > indent)
  43922. {
  43923. x = indent;
  43924. y += height;
  43925. }
  43926. tc->setBounds (x, y, preferredSize, height);
  43927. x += preferredSize + 8;
  43928. maxX = jmax (maxX, x);
  43929. }
  43930. }
  43931. }
  43932. itemHolder->setSize (maxX, y + height + 8);
  43933. }
  43934. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43935. {
  43936. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43937. jassert (tc != 0);
  43938. if (tc != 0)
  43939. {
  43940. tc->setBounds (comp->getBounds());
  43941. tc->setStyle (toolbar->getStyle());
  43942. tc->setEditingMode (comp->getEditingMode());
  43943. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43944. }
  43945. }
  43946. END_JUCE_NAMESPACE
  43947. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43948. /*** Start of inlined file: juce_TreeView.cpp ***/
  43949. BEGIN_JUCE_NAMESPACE
  43950. class TreeViewContentComponent : public Component,
  43951. public TooltipClient
  43952. {
  43953. public:
  43954. TreeViewContentComponent (TreeView* const owner_)
  43955. : owner (owner_),
  43956. buttonUnderMouse (0),
  43957. isDragging (false)
  43958. {
  43959. }
  43960. ~TreeViewContentComponent()
  43961. {
  43962. deleteAllChildren();
  43963. }
  43964. void mouseDown (const MouseEvent& e)
  43965. {
  43966. updateButtonUnderMouse (e);
  43967. isDragging = false;
  43968. needSelectionOnMouseUp = false;
  43969. Rectangle<int> pos;
  43970. TreeViewItem* const item = findItemAt (e.y, pos);
  43971. if (item == 0)
  43972. return;
  43973. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43974. // as selection clicks)
  43975. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43976. {
  43977. if (e.x >= pos.getX() - owner->getIndentSize())
  43978. item->setOpen (! item->isOpen());
  43979. // (clicks to the left of an open/close button are ignored)
  43980. }
  43981. else
  43982. {
  43983. // mouse-down inside the body of the item..
  43984. if (! owner->isMultiSelectEnabled())
  43985. item->setSelected (true, true);
  43986. else if (item->isSelected())
  43987. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43988. else
  43989. selectBasedOnModifiers (item, e.mods);
  43990. if (e.x >= pos.getX())
  43991. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43992. }
  43993. }
  43994. void mouseUp (const MouseEvent& e)
  43995. {
  43996. updateButtonUnderMouse (e);
  43997. if (needSelectionOnMouseUp && e.mouseWasClicked())
  43998. {
  43999. Rectangle<int> pos;
  44000. TreeViewItem* const item = findItemAt (e.y, pos);
  44001. if (item != 0)
  44002. selectBasedOnModifiers (item, e.mods);
  44003. }
  44004. }
  44005. void mouseDoubleClick (const MouseEvent& e)
  44006. {
  44007. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44008. {
  44009. Rectangle<int> pos;
  44010. TreeViewItem* const item = findItemAt (e.y, pos);
  44011. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44012. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44013. }
  44014. }
  44015. void mouseDrag (const MouseEvent& e)
  44016. {
  44017. if (isEnabled()
  44018. && ! (isDragging || e.mouseWasClicked()
  44019. || e.getDistanceFromDragStart() < 5
  44020. || e.mods.isPopupMenu()))
  44021. {
  44022. isDragging = true;
  44023. Rectangle<int> pos;
  44024. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44025. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44026. {
  44027. const String dragDescription (item->getDragSourceDescription());
  44028. if (dragDescription.isNotEmpty())
  44029. {
  44030. DragAndDropContainer* const dragContainer
  44031. = DragAndDropContainer::findParentDragContainerFor (this);
  44032. if (dragContainer != 0)
  44033. {
  44034. pos.setSize (pos.getWidth(), item->itemHeight);
  44035. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44036. dragImage->multiplyAllAlphas (0.6f);
  44037. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44038. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44039. }
  44040. else
  44041. {
  44042. // to be able to do a drag-and-drop operation, the treeview needs to
  44043. // be inside a component which is also a DragAndDropContainer.
  44044. jassertfalse
  44045. }
  44046. }
  44047. }
  44048. }
  44049. }
  44050. void mouseMove (const MouseEvent& e)
  44051. {
  44052. updateButtonUnderMouse (e);
  44053. }
  44054. void mouseExit (const MouseEvent& e)
  44055. {
  44056. updateButtonUnderMouse (e);
  44057. }
  44058. void paint (Graphics& g);
  44059. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44060. static bool isMouseDraggingInChildCompOf (Component* const comp)
  44061. {
  44062. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  44063. {
  44064. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  44065. if (source->isDragging())
  44066. {
  44067. Component* const underMouse = source->getComponentUnderMouse();
  44068. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44069. return true;
  44070. }
  44071. }
  44072. return false;
  44073. }
  44074. void updateComponents()
  44075. {
  44076. const int visibleTop = -getY();
  44077. const int visibleBottom = visibleTop + getParentHeight();
  44078. BigInteger itemsToKeep;
  44079. TreeViewItem* item = owner->rootItem;
  44080. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44081. while (item != 0 && y < visibleBottom)
  44082. {
  44083. y += item->itemHeight;
  44084. if (y >= visibleTop)
  44085. {
  44086. const int index = rowComponentIds.indexOf (item->uid);
  44087. if (index < 0)
  44088. {
  44089. Component* const comp = item->createItemComponent();
  44090. if (comp != 0)
  44091. {
  44092. addAndMakeVisible (comp);
  44093. itemsToKeep.setBit (rowComponentItems.size());
  44094. rowComponentItems.add (item);
  44095. rowComponentIds.add (item->uid);
  44096. rowComponents.add (comp);
  44097. }
  44098. }
  44099. else
  44100. {
  44101. itemsToKeep.setBit (index);
  44102. }
  44103. }
  44104. item = item->getNextVisibleItem (true);
  44105. }
  44106. for (int i = rowComponentItems.size(); --i >= 0;)
  44107. {
  44108. Component* const comp = rowComponents.getUnchecked(i);
  44109. bool keep = false;
  44110. if (isParentOf (comp))
  44111. {
  44112. if (itemsToKeep[i])
  44113. {
  44114. const TreeViewItem* const item = rowComponentItems.getUnchecked(i);
  44115. Rectangle<int> pos (item->getItemPosition (false));
  44116. pos.setSize (pos.getWidth(), item->itemHeight);
  44117. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44118. {
  44119. keep = true;
  44120. comp->setBounds (pos);
  44121. }
  44122. }
  44123. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44124. {
  44125. keep = true;
  44126. comp->setSize (0, 0);
  44127. }
  44128. }
  44129. if (! keep)
  44130. {
  44131. delete comp;
  44132. rowComponents.remove (i);
  44133. rowComponentIds.remove (i);
  44134. rowComponentItems.remove (i);
  44135. }
  44136. }
  44137. }
  44138. void updateButtonUnderMouse (const MouseEvent& e)
  44139. {
  44140. TreeViewItem* newItem = 0;
  44141. if (owner->openCloseButtonsVisible)
  44142. {
  44143. Rectangle<int> pos;
  44144. TreeViewItem* item = findItemAt (e.y, pos);
  44145. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44146. {
  44147. newItem = item;
  44148. if (! newItem->mightContainSubItems())
  44149. newItem = 0;
  44150. }
  44151. }
  44152. if (buttonUnderMouse != newItem)
  44153. {
  44154. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44155. {
  44156. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44157. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44158. }
  44159. buttonUnderMouse = newItem;
  44160. if (buttonUnderMouse != 0)
  44161. {
  44162. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44163. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44164. }
  44165. }
  44166. }
  44167. bool isMouseOverButton (TreeViewItem* item) const throw()
  44168. {
  44169. return item == buttonUnderMouse;
  44170. }
  44171. void resized()
  44172. {
  44173. owner->itemsChanged();
  44174. }
  44175. const String getTooltip()
  44176. {
  44177. Rectangle<int> pos;
  44178. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44179. if (item != 0)
  44180. return item->getTooltip();
  44181. return owner->getTooltip();
  44182. }
  44183. juce_UseDebuggingNewOperator
  44184. private:
  44185. TreeView* const owner;
  44186. Array <TreeViewItem*> rowComponentItems;
  44187. Array <int> rowComponentIds;
  44188. Array <Component*> rowComponents;
  44189. TreeViewItem* buttonUnderMouse;
  44190. bool isDragging, needSelectionOnMouseUp;
  44191. TreeViewContentComponent (const TreeViewContentComponent&);
  44192. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44193. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44194. {
  44195. TreeViewItem* firstSelected = 0;
  44196. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44197. {
  44198. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44199. jassert (lastSelected != 0);
  44200. int rowStart = firstSelected->getRowNumberInTree();
  44201. int rowEnd = lastSelected->getRowNumberInTree();
  44202. if (rowStart > rowEnd)
  44203. swapVariables (rowStart, rowEnd);
  44204. int ourRow = item->getRowNumberInTree();
  44205. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44206. if (ourRow > otherEnd)
  44207. swapVariables (ourRow, otherEnd);
  44208. for (int i = ourRow; i <= otherEnd; ++i)
  44209. owner->getItemOnRow (i)->setSelected (true, false);
  44210. }
  44211. else
  44212. {
  44213. const bool cmd = modifiers.isCommandDown();
  44214. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44215. }
  44216. }
  44217. bool containsItem (TreeViewItem* const item) const
  44218. {
  44219. for (int i = rowComponentItems.size(); --i >= 0;)
  44220. if (rowComponentItems.getUnchecked(i) == item)
  44221. return true;
  44222. return false;
  44223. }
  44224. };
  44225. class TreeView::TreeViewport : public Viewport
  44226. {
  44227. public:
  44228. TreeViewport() throw() {}
  44229. ~TreeViewport() throw() {}
  44230. void updateComponents()
  44231. {
  44232. TreeViewContentComponent* const tvc = static_cast <TreeViewContentComponent*> (getViewedComponent());
  44233. if (tvc != 0)
  44234. tvc->updateComponents();
  44235. repaint();
  44236. }
  44237. void visibleAreaChanged (int, int, int, int)
  44238. {
  44239. updateComponents();
  44240. }
  44241. juce_UseDebuggingNewOperator
  44242. private:
  44243. TreeViewport (const TreeViewport&);
  44244. TreeViewport& operator= (const TreeViewport&);
  44245. };
  44246. TreeView::TreeView (const String& componentName)
  44247. : Component (componentName),
  44248. rootItem (0),
  44249. dragInsertPointHighlight (0),
  44250. dragTargetGroupHighlight (0),
  44251. indentSize (24),
  44252. defaultOpenness (false),
  44253. needsRecalculating (true),
  44254. rootItemVisible (true),
  44255. multiSelectEnabled (false),
  44256. openCloseButtonsVisible (true)
  44257. {
  44258. addAndMakeVisible (viewport = new TreeViewport());
  44259. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44260. viewport->setWantsKeyboardFocus (false);
  44261. setWantsKeyboardFocus (true);
  44262. }
  44263. TreeView::~TreeView()
  44264. {
  44265. if (rootItem != 0)
  44266. rootItem->setOwnerView (0);
  44267. deleteAllChildren();
  44268. }
  44269. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44270. {
  44271. if (rootItem != newRootItem)
  44272. {
  44273. if (newRootItem != 0)
  44274. {
  44275. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44276. if (newRootItem->ownerView != 0)
  44277. newRootItem->ownerView->setRootItem (0);
  44278. }
  44279. if (rootItem != 0)
  44280. rootItem->setOwnerView (0);
  44281. rootItem = newRootItem;
  44282. if (newRootItem != 0)
  44283. newRootItem->setOwnerView (this);
  44284. needsRecalculating = true;
  44285. handleAsyncUpdate();
  44286. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44287. {
  44288. rootItem->setOpen (false); // force a re-open
  44289. rootItem->setOpen (true);
  44290. }
  44291. }
  44292. }
  44293. void TreeView::deleteRootItem()
  44294. {
  44295. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44296. setRootItem (0);
  44297. }
  44298. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44299. {
  44300. rootItemVisible = shouldBeVisible;
  44301. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44302. {
  44303. rootItem->setOpen (false); // force a re-open
  44304. rootItem->setOpen (true);
  44305. }
  44306. itemsChanged();
  44307. }
  44308. void TreeView::colourChanged()
  44309. {
  44310. setOpaque (findColour (backgroundColourId).isOpaque());
  44311. repaint();
  44312. }
  44313. void TreeView::setIndentSize (const int newIndentSize)
  44314. {
  44315. if (indentSize != newIndentSize)
  44316. {
  44317. indentSize = newIndentSize;
  44318. resized();
  44319. }
  44320. }
  44321. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44322. {
  44323. if (defaultOpenness != isOpenByDefault)
  44324. {
  44325. defaultOpenness = isOpenByDefault;
  44326. itemsChanged();
  44327. }
  44328. }
  44329. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44330. {
  44331. multiSelectEnabled = canMultiSelect;
  44332. }
  44333. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44334. {
  44335. if (openCloseButtonsVisible != shouldBeVisible)
  44336. {
  44337. openCloseButtonsVisible = shouldBeVisible;
  44338. itemsChanged();
  44339. }
  44340. }
  44341. Viewport* TreeView::getViewport() const throw()
  44342. {
  44343. return viewport;
  44344. }
  44345. void TreeView::clearSelectedItems()
  44346. {
  44347. if (rootItem != 0)
  44348. rootItem->deselectAllRecursively();
  44349. }
  44350. int TreeView::getNumSelectedItems() const throw()
  44351. {
  44352. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44353. }
  44354. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44355. {
  44356. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44357. }
  44358. int TreeView::getNumRowsInTree() const
  44359. {
  44360. if (rootItem != 0)
  44361. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44362. return 0;
  44363. }
  44364. TreeViewItem* TreeView::getItemOnRow (int index) const
  44365. {
  44366. if (! rootItemVisible)
  44367. ++index;
  44368. if (rootItem != 0 && index >= 0)
  44369. return rootItem->getItemOnRow (index);
  44370. return 0;
  44371. }
  44372. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44373. {
  44374. TreeViewContentComponent* const tc = static_cast <TreeViewContentComponent*> (viewport->getViewedComponent());
  44375. Rectangle<int> pos;
  44376. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44377. }
  44378. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44379. {
  44380. if (rootItem == 0)
  44381. return 0;
  44382. return rootItem->findItemFromIdentifierString (identifierString);
  44383. }
  44384. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44385. {
  44386. XmlElement* e = 0;
  44387. if (rootItem != 0)
  44388. {
  44389. e = rootItem->getOpennessState();
  44390. if (e != 0 && alsoIncludeScrollPosition)
  44391. e->setAttribute ("scrollPos", viewport->getViewPositionY());
  44392. }
  44393. return e;
  44394. }
  44395. void TreeView::restoreOpennessState (const XmlElement& newState)
  44396. {
  44397. if (rootItem != 0)
  44398. {
  44399. rootItem->restoreOpennessState (newState);
  44400. if (newState.hasAttribute ("scrollPos"))
  44401. viewport->setViewPosition (viewport->getViewPositionX(),
  44402. newState.getIntAttribute ("scrollPos"));
  44403. }
  44404. }
  44405. void TreeView::paint (Graphics& g)
  44406. {
  44407. g.fillAll (findColour (backgroundColourId));
  44408. }
  44409. void TreeView::resized()
  44410. {
  44411. viewport->setBounds (0, 0, getWidth(), getHeight());
  44412. itemsChanged();
  44413. handleAsyncUpdate();
  44414. }
  44415. void TreeView::enablementChanged()
  44416. {
  44417. repaint();
  44418. }
  44419. void TreeView::moveSelectedRow (int delta)
  44420. {
  44421. if (delta == 0)
  44422. return;
  44423. int rowSelected = 0;
  44424. TreeViewItem* const firstSelected = getSelectedItem (0);
  44425. if (firstSelected != 0)
  44426. rowSelected = firstSelected->getRowNumberInTree();
  44427. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44428. for (;;)
  44429. {
  44430. TreeViewItem* item = getItemOnRow (rowSelected);
  44431. if (item != 0)
  44432. {
  44433. if (! item->canBeSelected())
  44434. {
  44435. // if the row we want to highlight doesn't allow it, try skipping
  44436. // to the next item..
  44437. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44438. rowSelected + (delta < 0 ? -1 : 1));
  44439. if (rowSelected != nextRowToTry)
  44440. {
  44441. rowSelected = nextRowToTry;
  44442. continue;
  44443. }
  44444. else
  44445. {
  44446. break;
  44447. }
  44448. }
  44449. item->setSelected (true, true);
  44450. scrollToKeepItemVisible (item);
  44451. }
  44452. break;
  44453. }
  44454. }
  44455. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44456. {
  44457. if (item != 0 && item->ownerView == this)
  44458. {
  44459. handleAsyncUpdate();
  44460. item = item->getDeepestOpenParentItem();
  44461. int y = item->y;
  44462. int viewTop = viewport->getViewPositionY();
  44463. if (y < viewTop)
  44464. {
  44465. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44466. }
  44467. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44468. {
  44469. viewport->setViewPosition (viewport->getViewPositionX(),
  44470. (y + item->itemHeight) - viewport->getViewHeight());
  44471. }
  44472. }
  44473. }
  44474. bool TreeView::keyPressed (const KeyPress& key)
  44475. {
  44476. if (key.isKeyCode (KeyPress::upKey))
  44477. {
  44478. moveSelectedRow (-1);
  44479. }
  44480. else if (key.isKeyCode (KeyPress::downKey))
  44481. {
  44482. moveSelectedRow (1);
  44483. }
  44484. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44485. {
  44486. if (rootItem != 0)
  44487. {
  44488. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44489. if (key.isKeyCode (KeyPress::pageUpKey))
  44490. rowsOnScreen = -rowsOnScreen;
  44491. moveSelectedRow (rowsOnScreen);
  44492. }
  44493. }
  44494. else if (key.isKeyCode (KeyPress::homeKey))
  44495. {
  44496. moveSelectedRow (-0x3fffffff);
  44497. }
  44498. else if (key.isKeyCode (KeyPress::endKey))
  44499. {
  44500. moveSelectedRow (0x3fffffff);
  44501. }
  44502. else if (key.isKeyCode (KeyPress::returnKey))
  44503. {
  44504. TreeViewItem* const firstSelected = getSelectedItem (0);
  44505. if (firstSelected != 0)
  44506. firstSelected->setOpen (! firstSelected->isOpen());
  44507. }
  44508. else if (key.isKeyCode (KeyPress::leftKey))
  44509. {
  44510. TreeViewItem* const firstSelected = getSelectedItem (0);
  44511. if (firstSelected != 0)
  44512. {
  44513. if (firstSelected->isOpen())
  44514. {
  44515. firstSelected->setOpen (false);
  44516. }
  44517. else
  44518. {
  44519. TreeViewItem* parent = firstSelected->parentItem;
  44520. if ((! rootItemVisible) && parent == rootItem)
  44521. parent = 0;
  44522. if (parent != 0)
  44523. {
  44524. parent->setSelected (true, true);
  44525. scrollToKeepItemVisible (parent);
  44526. }
  44527. }
  44528. }
  44529. }
  44530. else if (key.isKeyCode (KeyPress::rightKey))
  44531. {
  44532. TreeViewItem* const firstSelected = getSelectedItem (0);
  44533. if (firstSelected != 0)
  44534. {
  44535. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44536. moveSelectedRow (1);
  44537. else
  44538. firstSelected->setOpen (true);
  44539. }
  44540. }
  44541. else
  44542. {
  44543. return false;
  44544. }
  44545. return true;
  44546. }
  44547. void TreeView::itemsChanged() throw()
  44548. {
  44549. needsRecalculating = true;
  44550. repaint();
  44551. triggerAsyncUpdate();
  44552. }
  44553. void TreeView::handleAsyncUpdate()
  44554. {
  44555. if (needsRecalculating)
  44556. {
  44557. needsRecalculating = false;
  44558. const ScopedLock sl (nodeAlterationLock);
  44559. if (rootItem != 0)
  44560. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44561. viewport->updateComponents();
  44562. if (rootItem != 0)
  44563. {
  44564. viewport->getViewedComponent()
  44565. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44566. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44567. }
  44568. else
  44569. {
  44570. viewport->getViewedComponent()->setSize (0, 0);
  44571. }
  44572. }
  44573. }
  44574. class TreeView::InsertPointHighlight : public Component
  44575. {
  44576. public:
  44577. InsertPointHighlight()
  44578. : lastItem (0)
  44579. {
  44580. setSize (100, 12);
  44581. setAlwaysOnTop (true);
  44582. setInterceptsMouseClicks (false, false);
  44583. }
  44584. ~InsertPointHighlight() {}
  44585. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44586. {
  44587. lastItem = item;
  44588. lastIndex = insertIndex;
  44589. const int offset = getHeight() / 2;
  44590. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44591. }
  44592. void paint (Graphics& g)
  44593. {
  44594. Path p;
  44595. const float h = (float) getHeight();
  44596. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44597. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44598. p.lineTo ((float) getWidth(), h / 2.0f);
  44599. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44600. g.strokePath (p, PathStrokeType (2.0f));
  44601. }
  44602. TreeViewItem* lastItem;
  44603. int lastIndex;
  44604. private:
  44605. InsertPointHighlight (const InsertPointHighlight&);
  44606. InsertPointHighlight& operator= (const InsertPointHighlight&);
  44607. };
  44608. class TreeView::TargetGroupHighlight : public Component
  44609. {
  44610. public:
  44611. TargetGroupHighlight()
  44612. {
  44613. setAlwaysOnTop (true);
  44614. setInterceptsMouseClicks (false, false);
  44615. }
  44616. ~TargetGroupHighlight() {}
  44617. void setTargetPosition (TreeViewItem* const item) throw()
  44618. {
  44619. Rectangle<int> r (item->getItemPosition (true));
  44620. r.setHeight (item->getItemHeight());
  44621. setBounds (r);
  44622. }
  44623. void paint (Graphics& g)
  44624. {
  44625. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44626. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44627. }
  44628. private:
  44629. TargetGroupHighlight (const TargetGroupHighlight&);
  44630. TargetGroupHighlight& operator= (const TargetGroupHighlight&);
  44631. };
  44632. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44633. {
  44634. beginDragAutoRepeat (1000 / 30);
  44635. if (dragInsertPointHighlight == 0)
  44636. {
  44637. addAndMakeVisible (dragInsertPointHighlight = new InsertPointHighlight());
  44638. addAndMakeVisible (dragTargetGroupHighlight = new TargetGroupHighlight());
  44639. }
  44640. dragInsertPointHighlight->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44641. dragTargetGroupHighlight->setTargetPosition (item);
  44642. }
  44643. void TreeView::hideDragHighlight() throw()
  44644. {
  44645. deleteAndZero (dragInsertPointHighlight);
  44646. deleteAndZero (dragTargetGroupHighlight);
  44647. }
  44648. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44649. const StringArray& files, const String& sourceDescription,
  44650. Component* sourceComponent) const throw()
  44651. {
  44652. insertIndex = 0;
  44653. TreeViewItem* item = getItemAt (y);
  44654. if (item == 0)
  44655. return 0;
  44656. Rectangle<int> itemPos (item->getItemPosition (true));
  44657. insertIndex = item->getIndexInParent();
  44658. const int oldY = y;
  44659. y = itemPos.getY();
  44660. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44661. {
  44662. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44663. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44664. {
  44665. // Check if we're trying to drag into an empty group item..
  44666. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44667. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44668. {
  44669. insertIndex = 0;
  44670. x = itemPos.getX() + getIndentSize();
  44671. y = itemPos.getBottom();
  44672. return item;
  44673. }
  44674. }
  44675. }
  44676. if (oldY > itemPos.getCentreY())
  44677. {
  44678. y += item->getItemHeight();
  44679. while (item->isLastOfSiblings() && item->parentItem != 0
  44680. && item->parentItem->parentItem != 0)
  44681. {
  44682. if (x > itemPos.getX())
  44683. break;
  44684. item = item->parentItem;
  44685. itemPos = item->getItemPosition (true);
  44686. insertIndex = item->getIndexInParent();
  44687. }
  44688. ++insertIndex;
  44689. }
  44690. x = itemPos.getX();
  44691. return item->parentItem;
  44692. }
  44693. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44694. {
  44695. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44696. int insertIndex;
  44697. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44698. if (item != 0)
  44699. {
  44700. if (scrolled || dragInsertPointHighlight == 0
  44701. || dragInsertPointHighlight->lastItem != item
  44702. || dragInsertPointHighlight->lastIndex != insertIndex)
  44703. {
  44704. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44705. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44706. showDragHighlight (item, insertIndex, x, y);
  44707. else
  44708. hideDragHighlight();
  44709. }
  44710. }
  44711. else
  44712. {
  44713. hideDragHighlight();
  44714. }
  44715. }
  44716. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44717. {
  44718. hideDragHighlight();
  44719. int insertIndex;
  44720. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44721. if (item != 0)
  44722. {
  44723. if (files.size() > 0)
  44724. {
  44725. if (item->isInterestedInFileDrag (files))
  44726. item->filesDropped (files, insertIndex);
  44727. }
  44728. else
  44729. {
  44730. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44731. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44732. }
  44733. }
  44734. }
  44735. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44736. {
  44737. return true;
  44738. }
  44739. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44740. {
  44741. fileDragMove (files, x, y);
  44742. }
  44743. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44744. {
  44745. handleDrag (files, String::empty, 0, x, y);
  44746. }
  44747. void TreeView::fileDragExit (const StringArray&)
  44748. {
  44749. hideDragHighlight();
  44750. }
  44751. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44752. {
  44753. handleDrop (files, String::empty, 0, x, y);
  44754. }
  44755. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44756. {
  44757. return true;
  44758. }
  44759. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44760. {
  44761. itemDragMove (sourceDescription, sourceComponent, x, y);
  44762. }
  44763. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44764. {
  44765. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44766. }
  44767. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44768. {
  44769. hideDragHighlight();
  44770. }
  44771. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44772. {
  44773. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44774. }
  44775. void TreeViewContentComponent::paint (Graphics& g)
  44776. {
  44777. if (owner->rootItem != 0)
  44778. {
  44779. owner->handleAsyncUpdate();
  44780. if (! owner->rootItemVisible)
  44781. g.setOrigin (0, -owner->rootItem->itemHeight);
  44782. owner->rootItem->paintRecursively (g, getWidth());
  44783. }
  44784. }
  44785. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44786. {
  44787. if (owner->rootItem != 0)
  44788. {
  44789. owner->handleAsyncUpdate();
  44790. if (! owner->rootItemVisible)
  44791. y += owner->rootItem->itemHeight;
  44792. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44793. if (ti != 0)
  44794. itemPosition = ti->getItemPosition (false);
  44795. return ti;
  44796. }
  44797. return 0;
  44798. }
  44799. enum TreeViewOpenness
  44800. {
  44801. opennessDefault = 0,
  44802. opennessClosed = 1,
  44803. opennessOpen = 2
  44804. };
  44805. TreeViewItem::TreeViewItem()
  44806. : ownerView (0),
  44807. parentItem (0),
  44808. y (0),
  44809. itemHeight (0),
  44810. totalHeight (0),
  44811. selected (false),
  44812. redrawNeeded (true),
  44813. drawLinesInside (true),
  44814. drawsInLeftMargin (false),
  44815. openness (opennessDefault)
  44816. {
  44817. static int nextUID = 0;
  44818. uid = nextUID++;
  44819. }
  44820. TreeViewItem::~TreeViewItem()
  44821. {
  44822. }
  44823. const String TreeViewItem::getUniqueName() const
  44824. {
  44825. return String::empty;
  44826. }
  44827. void TreeViewItem::itemOpennessChanged (bool)
  44828. {
  44829. }
  44830. int TreeViewItem::getNumSubItems() const throw()
  44831. {
  44832. return subItems.size();
  44833. }
  44834. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44835. {
  44836. return subItems [index];
  44837. }
  44838. void TreeViewItem::clearSubItems()
  44839. {
  44840. if (subItems.size() > 0)
  44841. {
  44842. if (ownerView != 0)
  44843. {
  44844. const ScopedLock sl (ownerView->nodeAlterationLock);
  44845. subItems.clear();
  44846. treeHasChanged();
  44847. }
  44848. else
  44849. {
  44850. subItems.clear();
  44851. }
  44852. }
  44853. }
  44854. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44855. {
  44856. if (newItem != 0)
  44857. {
  44858. newItem->parentItem = this;
  44859. newItem->setOwnerView (ownerView);
  44860. newItem->y = 0;
  44861. newItem->itemHeight = newItem->getItemHeight();
  44862. newItem->totalHeight = 0;
  44863. newItem->itemWidth = newItem->getItemWidth();
  44864. newItem->totalWidth = 0;
  44865. if (ownerView != 0)
  44866. {
  44867. const ScopedLock sl (ownerView->nodeAlterationLock);
  44868. subItems.insert (insertPosition, newItem);
  44869. treeHasChanged();
  44870. if (newItem->isOpen())
  44871. newItem->itemOpennessChanged (true);
  44872. }
  44873. else
  44874. {
  44875. subItems.insert (insertPosition, newItem);
  44876. if (newItem->isOpen())
  44877. newItem->itemOpennessChanged (true);
  44878. }
  44879. }
  44880. }
  44881. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44882. {
  44883. if (ownerView != 0)
  44884. {
  44885. const ScopedLock sl (ownerView->nodeAlterationLock);
  44886. if (((unsigned int) index) < (unsigned int) subItems.size())
  44887. {
  44888. subItems.remove (index, deleteItem);
  44889. treeHasChanged();
  44890. }
  44891. }
  44892. else
  44893. {
  44894. subItems.remove (index, deleteItem);
  44895. }
  44896. }
  44897. bool TreeViewItem::isOpen() const throw()
  44898. {
  44899. if (openness == opennessDefault)
  44900. return ownerView != 0 && ownerView->defaultOpenness;
  44901. else
  44902. return openness == opennessOpen;
  44903. }
  44904. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44905. {
  44906. if (isOpen() != shouldBeOpen)
  44907. {
  44908. openness = shouldBeOpen ? opennessOpen
  44909. : opennessClosed;
  44910. treeHasChanged();
  44911. itemOpennessChanged (isOpen());
  44912. }
  44913. }
  44914. bool TreeViewItem::isSelected() const throw()
  44915. {
  44916. return selected;
  44917. }
  44918. void TreeViewItem::deselectAllRecursively()
  44919. {
  44920. setSelected (false, false);
  44921. for (int i = 0; i < subItems.size(); ++i)
  44922. subItems.getUnchecked(i)->deselectAllRecursively();
  44923. }
  44924. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44925. const bool deselectOtherItemsFirst)
  44926. {
  44927. if (shouldBeSelected && ! canBeSelected())
  44928. return;
  44929. if (deselectOtherItemsFirst)
  44930. getTopLevelItem()->deselectAllRecursively();
  44931. if (shouldBeSelected != selected)
  44932. {
  44933. selected = shouldBeSelected;
  44934. if (ownerView != 0)
  44935. ownerView->repaint();
  44936. itemSelectionChanged (shouldBeSelected);
  44937. }
  44938. }
  44939. void TreeViewItem::paintItem (Graphics&, int, int)
  44940. {
  44941. }
  44942. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44943. {
  44944. ownerView->getLookAndFeel()
  44945. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44946. }
  44947. void TreeViewItem::itemClicked (const MouseEvent&)
  44948. {
  44949. }
  44950. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44951. {
  44952. if (mightContainSubItems())
  44953. setOpen (! isOpen());
  44954. }
  44955. void TreeViewItem::itemSelectionChanged (bool)
  44956. {
  44957. }
  44958. const String TreeViewItem::getTooltip()
  44959. {
  44960. return String::empty;
  44961. }
  44962. const String TreeViewItem::getDragSourceDescription()
  44963. {
  44964. return String::empty;
  44965. }
  44966. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44967. {
  44968. return false;
  44969. }
  44970. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44971. {
  44972. }
  44973. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44974. {
  44975. return false;
  44976. }
  44977. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44978. {
  44979. }
  44980. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44981. {
  44982. const int indentX = getIndentX();
  44983. int width = itemWidth;
  44984. if (ownerView != 0 && width < 0)
  44985. width = ownerView->viewport->getViewWidth() - indentX;
  44986. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44987. if (relativeToTreeViewTopLeft)
  44988. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44989. r.getY() - ownerView->viewport->getViewPositionY());
  44990. return r;
  44991. }
  44992. void TreeViewItem::treeHasChanged() const throw()
  44993. {
  44994. if (ownerView != 0)
  44995. ownerView->itemsChanged();
  44996. }
  44997. void TreeViewItem::repaintItem() const
  44998. {
  44999. if (ownerView != 0 && areAllParentsOpen())
  45000. {
  45001. const Rectangle<int> r (getItemPosition (true));
  45002. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45003. }
  45004. }
  45005. bool TreeViewItem::areAllParentsOpen() const throw()
  45006. {
  45007. return parentItem == 0
  45008. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45009. }
  45010. void TreeViewItem::updatePositions (int newY)
  45011. {
  45012. y = newY;
  45013. itemHeight = getItemHeight();
  45014. totalHeight = itemHeight;
  45015. itemWidth = getItemWidth();
  45016. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45017. if (isOpen())
  45018. {
  45019. newY += totalHeight;
  45020. for (int i = 0; i < subItems.size(); ++i)
  45021. {
  45022. TreeViewItem* const ti = subItems.getUnchecked(i);
  45023. ti->updatePositions (newY);
  45024. newY += ti->totalHeight;
  45025. totalHeight += ti->totalHeight;
  45026. totalWidth = jmax (totalWidth, ti->totalWidth);
  45027. }
  45028. }
  45029. }
  45030. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45031. {
  45032. TreeViewItem* result = this;
  45033. TreeViewItem* item = this;
  45034. while (item->parentItem != 0)
  45035. {
  45036. item = item->parentItem;
  45037. if (! item->isOpen())
  45038. result = item;
  45039. }
  45040. return result;
  45041. }
  45042. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45043. {
  45044. ownerView = newOwner;
  45045. for (int i = subItems.size(); --i >= 0;)
  45046. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45047. }
  45048. int TreeViewItem::getIndentX() const throw()
  45049. {
  45050. const int indentWidth = ownerView->getIndentSize();
  45051. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45052. if (! ownerView->openCloseButtonsVisible)
  45053. x -= indentWidth;
  45054. TreeViewItem* p = parentItem;
  45055. while (p != 0)
  45056. {
  45057. x += indentWidth;
  45058. p = p->parentItem;
  45059. }
  45060. return x;
  45061. }
  45062. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45063. {
  45064. drawsInLeftMargin = canDrawInLeftMargin;
  45065. }
  45066. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45067. {
  45068. jassert (ownerView != 0);
  45069. if (ownerView == 0)
  45070. return;
  45071. const int indent = getIndentX();
  45072. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45073. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45074. const float halfH = itemHeight * 0.5f;
  45075. int depth = 0;
  45076. TreeViewItem* p = parentItem;
  45077. while (p != 0)
  45078. {
  45079. ++depth;
  45080. p = p->parentItem;
  45081. }
  45082. if (! ownerView->rootItemVisible)
  45083. --depth;
  45084. const int indentWidth = ownerView->getIndentSize();
  45085. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45086. {
  45087. float x = (depth + 0.5f) * indentWidth;
  45088. if (depth >= 0)
  45089. {
  45090. if (parentItem != 0 && parentItem->drawLinesInside)
  45091. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45092. if ((parentItem != 0 && parentItem->drawLinesInside)
  45093. || (parentItem == 0 && drawLinesInside))
  45094. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45095. }
  45096. p = parentItem;
  45097. int d = depth;
  45098. while (p != 0 && --d >= 0)
  45099. {
  45100. x -= (float) indentWidth;
  45101. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45102. && ! p->isLastOfSiblings())
  45103. {
  45104. g.drawLine (x, 0, x, (float) itemHeight);
  45105. }
  45106. p = p->parentItem;
  45107. }
  45108. if (mightContainSubItems())
  45109. {
  45110. g.saveState();
  45111. g.setOrigin (depth * indentWidth, 0);
  45112. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45113. paintOpenCloseButton (g, indentWidth, itemHeight,
  45114. static_cast <TreeViewContentComponent*> (ownerView->viewport->getViewedComponent())
  45115. ->isMouseOverButton (this));
  45116. g.restoreState();
  45117. }
  45118. }
  45119. {
  45120. g.saveState();
  45121. g.setOrigin (indent, 0);
  45122. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45123. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45124. paintItem (g, itemW, itemHeight);
  45125. g.restoreState();
  45126. }
  45127. if (isOpen())
  45128. {
  45129. const Rectangle<int> clip (g.getClipBounds());
  45130. for (int i = 0; i < subItems.size(); ++i)
  45131. {
  45132. TreeViewItem* const ti = subItems.getUnchecked(i);
  45133. const int relY = ti->y - y;
  45134. if (relY >= clip.getBottom())
  45135. break;
  45136. if (relY + ti->totalHeight >= clip.getY())
  45137. {
  45138. g.saveState();
  45139. g.setOrigin (0, relY);
  45140. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45141. ti->paintRecursively (g, width);
  45142. g.restoreState();
  45143. }
  45144. }
  45145. }
  45146. }
  45147. bool TreeViewItem::isLastOfSiblings() const throw()
  45148. {
  45149. return parentItem == 0
  45150. || parentItem->subItems.getLast() == this;
  45151. }
  45152. int TreeViewItem::getIndexInParent() const throw()
  45153. {
  45154. if (parentItem == 0)
  45155. return 0;
  45156. return parentItem->subItems.indexOf (this);
  45157. }
  45158. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45159. {
  45160. return (parentItem == 0) ? this
  45161. : parentItem->getTopLevelItem();
  45162. }
  45163. int TreeViewItem::getNumRows() const throw()
  45164. {
  45165. int num = 1;
  45166. if (isOpen())
  45167. {
  45168. for (int i = subItems.size(); --i >= 0;)
  45169. num += subItems.getUnchecked(i)->getNumRows();
  45170. }
  45171. return num;
  45172. }
  45173. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45174. {
  45175. if (index == 0)
  45176. return this;
  45177. if (index > 0 && isOpen())
  45178. {
  45179. --index;
  45180. for (int i = 0; i < subItems.size(); ++i)
  45181. {
  45182. TreeViewItem* const item = subItems.getUnchecked(i);
  45183. if (index == 0)
  45184. return item;
  45185. const int numRows = item->getNumRows();
  45186. if (numRows > index)
  45187. return item->getItemOnRow (index);
  45188. index -= numRows;
  45189. }
  45190. }
  45191. return 0;
  45192. }
  45193. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45194. {
  45195. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45196. {
  45197. const int h = itemHeight;
  45198. if (targetY < h)
  45199. return this;
  45200. if (isOpen())
  45201. {
  45202. targetY -= h;
  45203. for (int i = 0; i < subItems.size(); ++i)
  45204. {
  45205. TreeViewItem* const ti = subItems.getUnchecked(i);
  45206. if (targetY < ti->totalHeight)
  45207. return ti->findItemRecursively (targetY);
  45208. targetY -= ti->totalHeight;
  45209. }
  45210. }
  45211. }
  45212. return 0;
  45213. }
  45214. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45215. {
  45216. int total = 0;
  45217. if (isSelected())
  45218. ++total;
  45219. for (int i = subItems.size(); --i >= 0;)
  45220. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45221. return total;
  45222. }
  45223. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45224. {
  45225. if (isSelected())
  45226. {
  45227. if (index == 0)
  45228. return this;
  45229. --index;
  45230. }
  45231. if (index >= 0)
  45232. {
  45233. for (int i = 0; i < subItems.size(); ++i)
  45234. {
  45235. TreeViewItem* const item = subItems.getUnchecked(i);
  45236. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45237. if (found != 0)
  45238. return found;
  45239. index -= item->countSelectedItemsRecursively();
  45240. }
  45241. }
  45242. return 0;
  45243. }
  45244. int TreeViewItem::getRowNumberInTree() const throw()
  45245. {
  45246. if (parentItem != 0 && ownerView != 0)
  45247. {
  45248. int n = 1 + parentItem->getRowNumberInTree();
  45249. int ourIndex = parentItem->subItems.indexOf (this);
  45250. jassert (ourIndex >= 0);
  45251. while (--ourIndex >= 0)
  45252. n += parentItem->subItems [ourIndex]->getNumRows();
  45253. if (parentItem->parentItem == 0
  45254. && ! ownerView->rootItemVisible)
  45255. --n;
  45256. return n;
  45257. }
  45258. else
  45259. {
  45260. return 0;
  45261. }
  45262. }
  45263. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45264. {
  45265. drawLinesInside = drawLines;
  45266. }
  45267. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45268. {
  45269. if (recurse && isOpen() && subItems.size() > 0)
  45270. return subItems [0];
  45271. if (parentItem != 0)
  45272. {
  45273. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45274. if (nextIndex >= parentItem->subItems.size())
  45275. return parentItem->getNextVisibleItem (false);
  45276. return parentItem->subItems [nextIndex];
  45277. }
  45278. return 0;
  45279. }
  45280. const String TreeViewItem::getItemIdentifierString() const
  45281. {
  45282. String s;
  45283. if (parentItem != 0)
  45284. s = parentItem->getItemIdentifierString();
  45285. return s + "/" + getUniqueName().replaceCharacter ('/', '\\');
  45286. }
  45287. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45288. {
  45289. const String uid (getUniqueName());
  45290. if (uid == identifierString)
  45291. return this;
  45292. if (identifierString.startsWith (uid + "/"))
  45293. {
  45294. const String remainingPath (identifierString.substring (uid.length() + 1));
  45295. bool wasOpen = isOpen();
  45296. setOpen (true);
  45297. for (int i = subItems.size(); --i >= 0;)
  45298. {
  45299. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45300. if (item != 0)
  45301. return item;
  45302. }
  45303. setOpen (wasOpen);
  45304. }
  45305. return 0;
  45306. }
  45307. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45308. {
  45309. if (e.hasTagName ("CLOSED"))
  45310. {
  45311. setOpen (false);
  45312. }
  45313. else if (e.hasTagName ("OPEN"))
  45314. {
  45315. setOpen (true);
  45316. forEachXmlChildElement (e, n)
  45317. {
  45318. const String id (n->getStringAttribute ("id"));
  45319. for (int i = 0; i < subItems.size(); ++i)
  45320. {
  45321. TreeViewItem* const ti = subItems.getUnchecked(i);
  45322. if (ti->getUniqueName() == id)
  45323. {
  45324. ti->restoreOpennessState (*n);
  45325. break;
  45326. }
  45327. }
  45328. }
  45329. }
  45330. }
  45331. XmlElement* TreeViewItem::getOpennessState() const throw()
  45332. {
  45333. const String name (getUniqueName());
  45334. if (name.isNotEmpty())
  45335. {
  45336. XmlElement* e;
  45337. if (isOpen())
  45338. {
  45339. e = new XmlElement ("OPEN");
  45340. for (int i = 0; i < subItems.size(); ++i)
  45341. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45342. }
  45343. else
  45344. {
  45345. e = new XmlElement ("CLOSED");
  45346. }
  45347. e->setAttribute ("id", name);
  45348. return e;
  45349. }
  45350. else
  45351. {
  45352. // trying to save the openness for an element that has no name - this won't
  45353. // work because it needs the names to identify what to open.
  45354. jassertfalse
  45355. }
  45356. return 0;
  45357. }
  45358. END_JUCE_NAMESPACE
  45359. /*** End of inlined file: juce_TreeView.cpp ***/
  45360. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45361. BEGIN_JUCE_NAMESPACE
  45362. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45363. : fileList (listToShow)
  45364. {
  45365. }
  45366. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45367. {
  45368. }
  45369. FileBrowserListener::~FileBrowserListener()
  45370. {
  45371. }
  45372. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener)
  45373. {
  45374. listeners.add (listener);
  45375. }
  45376. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener)
  45377. {
  45378. listeners.remove (listener);
  45379. }
  45380. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45381. {
  45382. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45383. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45384. }
  45385. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45386. {
  45387. if (fileList.getDirectory().exists())
  45388. {
  45389. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45390. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45391. }
  45392. }
  45393. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45394. {
  45395. if (fileList.getDirectory().exists())
  45396. {
  45397. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45398. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45399. }
  45400. }
  45401. END_JUCE_NAMESPACE
  45402. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45403. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45404. BEGIN_JUCE_NAMESPACE
  45405. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45406. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45407. Time* creationTime, bool* isReadOnly);
  45408. bool juce_findFileNext (void* handle, String& resultFile,
  45409. bool* isDirectory, bool* isHidden, int64* fileSize,
  45410. Time* modTime, Time* creationTime, bool* isReadOnly);
  45411. void juce_findFileClose (void* handle);
  45412. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45413. TimeSliceThread& thread_)
  45414. : fileFilter (fileFilter_),
  45415. thread (thread_),
  45416. includeDirectories (false),
  45417. includeFiles (false),
  45418. ignoreHiddenFiles (true),
  45419. fileFindHandle (0),
  45420. shouldStop (true)
  45421. {
  45422. }
  45423. DirectoryContentsList::~DirectoryContentsList()
  45424. {
  45425. clear();
  45426. }
  45427. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45428. {
  45429. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45430. }
  45431. const File& DirectoryContentsList::getDirectory() const
  45432. {
  45433. return root;
  45434. }
  45435. void DirectoryContentsList::setDirectory (const File& directory,
  45436. const bool includeDirectories_,
  45437. const bool includeFiles_)
  45438. {
  45439. if (directory != root
  45440. || includeDirectories != includeDirectories_
  45441. || includeFiles != includeFiles_)
  45442. {
  45443. clear();
  45444. root = directory;
  45445. includeDirectories = includeDirectories_;
  45446. includeFiles = includeFiles_;
  45447. refresh();
  45448. }
  45449. }
  45450. void DirectoryContentsList::clear()
  45451. {
  45452. shouldStop = true;
  45453. thread.removeTimeSliceClient (this);
  45454. if (fileFindHandle != 0)
  45455. {
  45456. juce_findFileClose (fileFindHandle);
  45457. fileFindHandle = 0;
  45458. }
  45459. if (files.size() > 0)
  45460. {
  45461. files.clear();
  45462. changed();
  45463. }
  45464. }
  45465. void DirectoryContentsList::refresh()
  45466. {
  45467. clear();
  45468. if (root.isDirectory())
  45469. {
  45470. String fileFound;
  45471. bool fileFoundIsDir, isHidden, isReadOnly;
  45472. int64 fileSize;
  45473. Time modTime, creationTime;
  45474. String path (root.getFullPathName());
  45475. if (! path.endsWithChar (File::separator))
  45476. path += File::separator;
  45477. jassert (fileFindHandle == 0);
  45478. fileFindHandle = juce_findFileStart (path, "*", fileFound,
  45479. &fileFoundIsDir,
  45480. &isHidden,
  45481. &fileSize,
  45482. &modTime,
  45483. &creationTime,
  45484. &isReadOnly);
  45485. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45486. {
  45487. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45488. fileSize, modTime, creationTime, isReadOnly))
  45489. {
  45490. changed();
  45491. }
  45492. }
  45493. shouldStop = false;
  45494. thread.addTimeSliceClient (this);
  45495. }
  45496. }
  45497. int DirectoryContentsList::getNumFiles() const
  45498. {
  45499. return files.size();
  45500. }
  45501. bool DirectoryContentsList::getFileInfo (const int index,
  45502. FileInfo& result) const
  45503. {
  45504. const ScopedLock sl (fileListLock);
  45505. const FileInfo* const info = files [index];
  45506. if (info != 0)
  45507. {
  45508. result = *info;
  45509. return true;
  45510. }
  45511. return false;
  45512. }
  45513. const File DirectoryContentsList::getFile (const int index) const
  45514. {
  45515. const ScopedLock sl (fileListLock);
  45516. const FileInfo* const info = files [index];
  45517. if (info != 0)
  45518. return root.getChildFile (info->filename);
  45519. return File::nonexistent;
  45520. }
  45521. bool DirectoryContentsList::isStillLoading() const
  45522. {
  45523. return fileFindHandle != 0;
  45524. }
  45525. void DirectoryContentsList::changed()
  45526. {
  45527. sendChangeMessage (this);
  45528. }
  45529. bool DirectoryContentsList::useTimeSlice()
  45530. {
  45531. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45532. bool hasChanged = false;
  45533. for (int i = 100; --i >= 0;)
  45534. {
  45535. if (! checkNextFile (hasChanged))
  45536. {
  45537. if (hasChanged)
  45538. changed();
  45539. return false;
  45540. }
  45541. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45542. break;
  45543. }
  45544. if (hasChanged)
  45545. changed();
  45546. return true;
  45547. }
  45548. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45549. {
  45550. if (fileFindHandle != 0)
  45551. {
  45552. String fileFound;
  45553. bool fileFoundIsDir, isHidden, isReadOnly;
  45554. int64 fileSize;
  45555. Time modTime, creationTime;
  45556. if (juce_findFileNext (fileFindHandle, fileFound,
  45557. &fileFoundIsDir, &isHidden,
  45558. &fileSize,
  45559. &modTime,
  45560. &creationTime,
  45561. &isReadOnly))
  45562. {
  45563. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45564. modTime, creationTime, isReadOnly))
  45565. {
  45566. hasChanged = true;
  45567. }
  45568. return true;
  45569. }
  45570. else
  45571. {
  45572. juce_findFileClose (fileFindHandle);
  45573. fileFindHandle = 0;
  45574. }
  45575. }
  45576. return false;
  45577. }
  45578. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45579. const DirectoryContentsList::FileInfo* const second)
  45580. {
  45581. #if JUCE_WINDOWS
  45582. if (first->isDirectory != second->isDirectory)
  45583. return first->isDirectory ? -1 : 1;
  45584. #endif
  45585. return first->filename.compareIgnoreCase (second->filename);
  45586. }
  45587. bool DirectoryContentsList::addFile (const String& filename,
  45588. const bool isDir,
  45589. const bool isHidden,
  45590. const int64 fileSize,
  45591. const Time& modTime,
  45592. const Time& creationTime,
  45593. const bool isReadOnly)
  45594. {
  45595. if (filename == ".."
  45596. || filename == "."
  45597. || (ignoreHiddenFiles && isHidden))
  45598. return false;
  45599. const File file (root.getChildFile (filename));
  45600. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45601. && (fileFilter == 0
  45602. || ((! isDir) && fileFilter->isFileSuitable (file))
  45603. || (isDir && fileFilter->isDirectorySuitable (file))))
  45604. {
  45605. ScopedPointer <FileInfo> info (new FileInfo());
  45606. info->filename = filename;
  45607. info->fileSize = fileSize;
  45608. info->modificationTime = modTime;
  45609. info->creationTime = creationTime;
  45610. info->isDirectory = isDir;
  45611. info->isReadOnly = isReadOnly;
  45612. const ScopedLock sl (fileListLock);
  45613. for (int i = files.size(); --i >= 0;)
  45614. if (files.getUnchecked(i)->filename == info->filename)
  45615. return false;
  45616. files.addSorted (*this, info.release());
  45617. return true;
  45618. }
  45619. return false;
  45620. }
  45621. END_JUCE_NAMESPACE
  45622. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45623. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45624. BEGIN_JUCE_NAMESPACE
  45625. FileBrowserComponent::FileBrowserComponent (int flags_,
  45626. const File& initialFileOrDirectory,
  45627. const FileFilter* fileFilter_,
  45628. FilePreviewComponent* previewComp_)
  45629. : FileFilter (String::empty),
  45630. fileFilter (fileFilter_),
  45631. flags (flags_),
  45632. previewComp (previewComp_),
  45633. thread ("Juce FileBrowser")
  45634. {
  45635. // You need to specify one or other of the open/save flags..
  45636. jassert ((flags & (saveMode | openMode)) != 0);
  45637. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45638. // You need to specify at least one of these flags..
  45639. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45640. String filename;
  45641. if (initialFileOrDirectory == File::nonexistent)
  45642. {
  45643. currentRoot = File::getCurrentWorkingDirectory();
  45644. }
  45645. else if (initialFileOrDirectory.isDirectory())
  45646. {
  45647. currentRoot = initialFileOrDirectory;
  45648. }
  45649. else
  45650. {
  45651. chosenFiles.add (initialFileOrDirectory);
  45652. currentRoot = initialFileOrDirectory.getParentDirectory();
  45653. filename = initialFileOrDirectory.getFileName();
  45654. }
  45655. fileList = new DirectoryContentsList (this, thread);
  45656. if ((flags & useTreeView) != 0)
  45657. {
  45658. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45659. if ((flags & canSelectMultipleItems) != 0)
  45660. tree->setMultiSelectEnabled (true);
  45661. addAndMakeVisible (tree);
  45662. fileListComponent = tree;
  45663. }
  45664. else
  45665. {
  45666. FileListComponent* const list = new FileListComponent (*fileList);
  45667. list->setOutlineThickness (1);
  45668. if ((flags & canSelectMultipleItems) != 0)
  45669. list->setMultipleSelectionEnabled (true);
  45670. addAndMakeVisible (list);
  45671. fileListComponent = list;
  45672. }
  45673. fileListComponent->addListener (this);
  45674. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45675. currentPathBox->setEditableText (true);
  45676. StringArray rootNames, rootPaths;
  45677. const BigInteger separators (getRoots (rootNames, rootPaths));
  45678. for (int i = 0; i < rootNames.size(); ++i)
  45679. {
  45680. if (separators [i])
  45681. currentPathBox->addSeparator();
  45682. currentPathBox->addItem (rootNames[i], i + 1);
  45683. }
  45684. currentPathBox->addSeparator();
  45685. currentPathBox->addListener (this);
  45686. addAndMakeVisible (filenameBox = new TextEditor());
  45687. filenameBox->setMultiLine (false);
  45688. filenameBox->setSelectAllWhenFocused (true);
  45689. filenameBox->setText (filename, false);
  45690. filenameBox->addListener (this);
  45691. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45692. Label* label = new Label ("f", TRANS("file:"));
  45693. addAndMakeVisible (label);
  45694. label->attachToComponent (filenameBox, true);
  45695. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45696. goUpButton->addButtonListener (this);
  45697. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45698. if (previewComp != 0)
  45699. addAndMakeVisible (previewComp);
  45700. setRoot (currentRoot);
  45701. thread.startThread (4);
  45702. }
  45703. FileBrowserComponent::~FileBrowserComponent()
  45704. {
  45705. if (previewComp != 0)
  45706. removeChildComponent (previewComp);
  45707. deleteAllChildren();
  45708. fileList = 0;
  45709. thread.stopThread (10000);
  45710. }
  45711. void FileBrowserComponent::addListener (FileBrowserListener* const newListener)
  45712. {
  45713. listeners.add (newListener);
  45714. }
  45715. void FileBrowserComponent::removeListener (FileBrowserListener* const listener)
  45716. {
  45717. listeners.remove (listener);
  45718. }
  45719. bool FileBrowserComponent::isSaveMode() const throw()
  45720. {
  45721. return (flags & saveMode) != 0;
  45722. }
  45723. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45724. {
  45725. if (chosenFiles.size() == 0 && currentFileIsValid())
  45726. return 1;
  45727. return chosenFiles.size();
  45728. }
  45729. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45730. {
  45731. if (! filenameBox->isReadOnly())
  45732. return currentRoot.getChildFile (filenameBox->getText());
  45733. else
  45734. return chosenFiles[index];
  45735. }
  45736. bool FileBrowserComponent::currentFileIsValid() const
  45737. {
  45738. if (isSaveMode())
  45739. return ! getSelectedFile (0).isDirectory();
  45740. else
  45741. return getSelectedFile (0).exists();
  45742. }
  45743. const File FileBrowserComponent::getHighlightedFile() const throw()
  45744. {
  45745. return fileListComponent->getSelectedFile (0);
  45746. }
  45747. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45748. {
  45749. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45750. : false;
  45751. }
  45752. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45753. {
  45754. return true;
  45755. }
  45756. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45757. {
  45758. if (f.isDirectory())
  45759. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45760. return (flags & canSelectFiles) != 0 && f.exists()
  45761. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45762. }
  45763. const File FileBrowserComponent::getRoot() const
  45764. {
  45765. return currentRoot;
  45766. }
  45767. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45768. {
  45769. if (currentRoot != newRootDirectory)
  45770. {
  45771. fileListComponent->scrollToTop();
  45772. String path (newRootDirectory.getFullPathName());
  45773. if (path.isEmpty())
  45774. path += File::separator;
  45775. StringArray rootNames, rootPaths;
  45776. getRoots (rootNames, rootPaths);
  45777. if (! rootPaths.contains (path, true))
  45778. {
  45779. bool alreadyListed = false;
  45780. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45781. {
  45782. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45783. {
  45784. alreadyListed = true;
  45785. break;
  45786. }
  45787. }
  45788. if (! alreadyListed)
  45789. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45790. }
  45791. }
  45792. currentRoot = newRootDirectory;
  45793. fileList->setDirectory (currentRoot, true, true);
  45794. String currentRootName (currentRoot.getFullPathName());
  45795. if (currentRootName.isEmpty())
  45796. currentRootName += File::separator;
  45797. currentPathBox->setText (currentRootName, true);
  45798. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45799. && currentRoot.getParentDirectory() != currentRoot);
  45800. }
  45801. void FileBrowserComponent::goUp()
  45802. {
  45803. setRoot (getRoot().getParentDirectory());
  45804. }
  45805. void FileBrowserComponent::refresh()
  45806. {
  45807. fileList->refresh();
  45808. }
  45809. const String FileBrowserComponent::getActionVerb() const
  45810. {
  45811. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45812. }
  45813. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45814. {
  45815. return previewComp;
  45816. }
  45817. void FileBrowserComponent::resized()
  45818. {
  45819. getLookAndFeel()
  45820. .layoutFileBrowserComponent (*this, fileListComponent,
  45821. previewComp, currentPathBox,
  45822. filenameBox, goUpButton);
  45823. }
  45824. void FileBrowserComponent::sendListenerChangeMessage()
  45825. {
  45826. Component::BailOutChecker checker (this);
  45827. if (previewComp != 0)
  45828. previewComp->selectedFileChanged (getSelectedFile (0));
  45829. // You shouldn't delete the browser when the file gets changed!
  45830. jassert (! checker.shouldBailOut());
  45831. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45832. }
  45833. void FileBrowserComponent::selectionChanged()
  45834. {
  45835. StringArray newFilenames;
  45836. bool resetChosenFiles = true;
  45837. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45838. {
  45839. const File f (fileListComponent->getSelectedFile (i));
  45840. if (isFileOrDirSuitable (f))
  45841. {
  45842. if (resetChosenFiles)
  45843. {
  45844. chosenFiles.clear();
  45845. resetChosenFiles = false;
  45846. }
  45847. chosenFiles.add (f);
  45848. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45849. }
  45850. }
  45851. if (newFilenames.size() > 0)
  45852. filenameBox->setText (newFilenames.joinIntoString (", "), false);
  45853. sendListenerChangeMessage();
  45854. }
  45855. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45856. {
  45857. Component::BailOutChecker checker (this);
  45858. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45859. }
  45860. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45861. {
  45862. if (f.isDirectory())
  45863. {
  45864. setRoot (f);
  45865. }
  45866. else
  45867. {
  45868. Component::BailOutChecker checker (this);
  45869. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45870. }
  45871. }
  45872. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45873. {
  45874. #if JUCE_LINUX || JUCE_WINDOWS
  45875. if (key.getModifiers().isCommandDown()
  45876. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45877. {
  45878. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45879. fileList->refresh();
  45880. return true;
  45881. }
  45882. #endif
  45883. return false;
  45884. }
  45885. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45886. {
  45887. sendListenerChangeMessage();
  45888. }
  45889. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45890. {
  45891. if (filenameBox->getText().containsChar (File::separator))
  45892. {
  45893. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45894. if (f.isDirectory())
  45895. {
  45896. setRoot (f);
  45897. chosenFiles.clear();
  45898. filenameBox->setText (String::empty);
  45899. }
  45900. else
  45901. {
  45902. setRoot (f.getParentDirectory());
  45903. chosenFiles.clear();
  45904. chosenFiles.add (f);
  45905. filenameBox->setText (f.getFileName());
  45906. }
  45907. }
  45908. else
  45909. {
  45910. fileDoubleClicked (getSelectedFile (0));
  45911. }
  45912. }
  45913. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45914. {
  45915. }
  45916. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45917. {
  45918. if (! isSaveMode())
  45919. selectionChanged();
  45920. }
  45921. void FileBrowserComponent::buttonClicked (Button*)
  45922. {
  45923. goUp();
  45924. }
  45925. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45926. {
  45927. const String newText (currentPathBox->getText().trim().unquoted());
  45928. if (newText.isNotEmpty())
  45929. {
  45930. const int index = currentPathBox->getSelectedId() - 1;
  45931. StringArray rootNames, rootPaths;
  45932. getRoots (rootNames, rootPaths);
  45933. if (rootPaths [index].isNotEmpty())
  45934. {
  45935. setRoot (File (rootPaths [index]));
  45936. }
  45937. else
  45938. {
  45939. File f (newText);
  45940. for (;;)
  45941. {
  45942. if (f.isDirectory())
  45943. {
  45944. setRoot (f);
  45945. break;
  45946. }
  45947. if (f.getParentDirectory() == f)
  45948. break;
  45949. f = f.getParentDirectory();
  45950. }
  45951. }
  45952. }
  45953. }
  45954. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45955. {
  45956. BigInteger separators;
  45957. #if JUCE_WINDOWS
  45958. Array<File> roots;
  45959. File::findFileSystemRoots (roots);
  45960. rootPaths.clear();
  45961. for (int i = 0; i < roots.size(); ++i)
  45962. {
  45963. const File& drive = roots.getReference(i);
  45964. String name (drive.getFullPathName());
  45965. rootPaths.add (name);
  45966. if (drive.isOnHardDisk())
  45967. {
  45968. String volume (drive.getVolumeLabel());
  45969. if (volume.isEmpty())
  45970. volume = TRANS("Hard Drive");
  45971. name << " [" << drive.getVolumeLabel() << ']';
  45972. }
  45973. else if (drive.isOnCDRomDrive())
  45974. {
  45975. name << TRANS(" [CD/DVD drive]");
  45976. }
  45977. rootNames.add (name);
  45978. }
  45979. separators.setBit (rootPaths.size());
  45980. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45981. rootNames.add ("Documents");
  45982. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45983. rootNames.add ("Desktop");
  45984. #endif
  45985. #if JUCE_MAC
  45986. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45987. rootNames.add ("Home folder");
  45988. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45989. rootNames.add ("Documents");
  45990. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45991. rootNames.add ("Desktop");
  45992. separators.setBit (rootPaths.size());
  45993. Array <File> volumes;
  45994. File vol ("/Volumes");
  45995. vol.findChildFiles (volumes, File::findDirectories, false);
  45996. for (int i = 0; i < volumes.size(); ++i)
  45997. {
  45998. const File& volume = volumes.getReference(i);
  45999. if (volume.isDirectory() && ! volume.getFileName().startsWithChar ('.'))
  46000. {
  46001. rootPaths.add (volume.getFullPathName());
  46002. rootNames.add (volume.getFileName());
  46003. }
  46004. }
  46005. #endif
  46006. #if JUCE_LINUX
  46007. rootPaths.add ("/");
  46008. rootNames.add ("/");
  46009. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46010. rootNames.add ("Home folder");
  46011. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46012. rootNames.add ("Desktop");
  46013. #endif
  46014. return separators;
  46015. }
  46016. END_JUCE_NAMESPACE
  46017. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46018. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46019. BEGIN_JUCE_NAMESPACE
  46020. FileChooser::FileChooser (const String& chooserBoxTitle,
  46021. const File& currentFileOrDirectory,
  46022. const String& fileFilters,
  46023. const bool useNativeDialogBox_)
  46024. : title (chooserBoxTitle),
  46025. filters (fileFilters),
  46026. startingFile (currentFileOrDirectory),
  46027. useNativeDialogBox (useNativeDialogBox_)
  46028. {
  46029. #if JUCE_LINUX
  46030. useNativeDialogBox = false;
  46031. #endif
  46032. if (! fileFilters.containsNonWhitespaceChars())
  46033. filters = "*";
  46034. }
  46035. FileChooser::~FileChooser()
  46036. {
  46037. }
  46038. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46039. {
  46040. return showDialog (false, true, false, false, false, previewComponent);
  46041. }
  46042. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46043. {
  46044. return showDialog (false, true, false, false, true, previewComponent);
  46045. }
  46046. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46047. {
  46048. return showDialog (true, true, false, false, true, previewComponent);
  46049. }
  46050. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46051. {
  46052. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46053. }
  46054. bool FileChooser::browseForDirectory()
  46055. {
  46056. return showDialog (true, false, false, false, false, 0);
  46057. }
  46058. const File FileChooser::getResult() const
  46059. {
  46060. // if you've used a multiple-file select, you should use the getResults() method
  46061. // to retrieve all the files that were chosen.
  46062. jassert (results.size() <= 1);
  46063. return results.getFirst();
  46064. }
  46065. const Array<File>& FileChooser::getResults() const
  46066. {
  46067. return results;
  46068. }
  46069. bool FileChooser::showDialog (const bool selectsDirectories,
  46070. const bool selectsFiles,
  46071. const bool isSave,
  46072. const bool warnAboutOverwritingExistingFiles,
  46073. const bool selectMultipleFiles,
  46074. FilePreviewComponent* const previewComponent)
  46075. {
  46076. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46077. results.clear();
  46078. // the preview component needs to be the right size before you pass it in here..
  46079. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46080. && previewComponent->getHeight() > 10));
  46081. #if JUCE_WINDOWS
  46082. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46083. #elif JUCE_MAC
  46084. if (useNativeDialogBox && (previewComponent == 0))
  46085. #else
  46086. if (false)
  46087. #endif
  46088. {
  46089. showPlatformDialog (results, title, startingFile, filters,
  46090. selectsDirectories, selectsFiles, isSave,
  46091. warnAboutOverwritingExistingFiles,
  46092. selectMultipleFiles,
  46093. previewComponent);
  46094. }
  46095. else
  46096. {
  46097. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46098. selectsDirectories ? "*" : String::empty,
  46099. String::empty);
  46100. int flags = isSave ? FileBrowserComponent::saveMode
  46101. : FileBrowserComponent::openMode;
  46102. if (selectsFiles)
  46103. flags |= FileBrowserComponent::canSelectFiles;
  46104. if (selectsDirectories)
  46105. flags |= FileBrowserComponent::canSelectDirectories;
  46106. if (selectMultipleFiles)
  46107. flags |= FileBrowserComponent::canSelectMultipleItems;
  46108. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46109. FileChooserDialogBox box (title, String::empty,
  46110. browserComponent,
  46111. warnAboutOverwritingExistingFiles,
  46112. browserComponent.findColour (AlertWindow::backgroundColourId));
  46113. if (box.show())
  46114. {
  46115. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46116. results.add (browserComponent.getSelectedFile (i));
  46117. }
  46118. }
  46119. if (previouslyFocused != 0)
  46120. previouslyFocused->grabKeyboardFocus();
  46121. return results.size() > 0;
  46122. }
  46123. FilePreviewComponent::FilePreviewComponent()
  46124. {
  46125. }
  46126. FilePreviewComponent::~FilePreviewComponent()
  46127. {
  46128. }
  46129. END_JUCE_NAMESPACE
  46130. /*** End of inlined file: juce_FileChooser.cpp ***/
  46131. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46132. BEGIN_JUCE_NAMESPACE
  46133. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46134. const String& instructions,
  46135. FileBrowserComponent& chooserComponent,
  46136. const bool warnAboutOverwritingExistingFiles_,
  46137. const Colour& backgroundColour)
  46138. : ResizableWindow (name, backgroundColour, true),
  46139. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46140. {
  46141. content = new ContentComponent();
  46142. content->setName (name);
  46143. content->instructions = instructions;
  46144. content->chooserComponent = &chooserComponent;
  46145. content->addAndMakeVisible (&chooserComponent);
  46146. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46147. content->addAndMakeVisible (content->okButton);
  46148. content->okButton->addButtonListener (this);
  46149. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46150. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46151. content->cancelButton = new TextButton (TRANS("Cancel"));
  46152. content->addAndMakeVisible (content->cancelButton);
  46153. content->cancelButton->addButtonListener (this);
  46154. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46155. setContentComponent (content);
  46156. setResizable (true, true);
  46157. setResizeLimits (300, 300, 1200, 1000);
  46158. content->chooserComponent->addListener (this);
  46159. }
  46160. FileChooserDialogBox::~FileChooserDialogBox()
  46161. {
  46162. content->chooserComponent->removeListener (this);
  46163. }
  46164. bool FileChooserDialogBox::show (int w, int h)
  46165. {
  46166. if (w <= 0)
  46167. {
  46168. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46169. if (previewComp != 0)
  46170. w = 400 + previewComp->getWidth();
  46171. else
  46172. w = 600;
  46173. }
  46174. if (h <= 0)
  46175. h = 500;
  46176. centreWithSize (w, h);
  46177. const bool ok = (runModalLoop() != 0);
  46178. setVisible (false);
  46179. return ok;
  46180. }
  46181. void FileChooserDialogBox::buttonClicked (Button* button)
  46182. {
  46183. if (button == content->okButton)
  46184. {
  46185. if (warnAboutOverwritingExistingFiles
  46186. && content->chooserComponent->isSaveMode()
  46187. && content->chooserComponent->getSelectedFile(0).exists())
  46188. {
  46189. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46190. TRANS("File already exists"),
  46191. TRANS("There's already a file called:")
  46192. + "\n\n" + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46193. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  46194. TRANS("overwrite"),
  46195. TRANS("cancel")))
  46196. {
  46197. return;
  46198. }
  46199. }
  46200. exitModalState (1);
  46201. }
  46202. else if (button == content->cancelButton)
  46203. closeButtonPressed();
  46204. }
  46205. void FileChooserDialogBox::closeButtonPressed()
  46206. {
  46207. setVisible (false);
  46208. }
  46209. void FileChooserDialogBox::selectionChanged()
  46210. {
  46211. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46212. }
  46213. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46214. {
  46215. }
  46216. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46217. {
  46218. selectionChanged();
  46219. content->okButton->triggerClick();
  46220. }
  46221. FileChooserDialogBox::ContentComponent::ContentComponent()
  46222. {
  46223. setInterceptsMouseClicks (false, true);
  46224. }
  46225. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46226. {
  46227. delete okButton;
  46228. delete cancelButton;
  46229. }
  46230. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46231. {
  46232. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46233. text.draw (g);
  46234. }
  46235. void FileChooserDialogBox::ContentComponent::resized()
  46236. {
  46237. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46238. const Rectangle<float> bb (text.getBoundingBox (0, text.getNumGlyphs(), false));
  46239. const int y = roundToInt (bb.getBottom()) + 10;
  46240. const int buttonHeight = 26;
  46241. const int buttonY = getHeight() - buttonHeight - 8;
  46242. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46243. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46244. proportionOfWidth (0.2f), buttonHeight);
  46245. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46246. proportionOfWidth (0.2f), buttonHeight);
  46247. }
  46248. END_JUCE_NAMESPACE
  46249. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46250. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46251. BEGIN_JUCE_NAMESPACE
  46252. FileFilter::FileFilter (const String& filterDescription)
  46253. : description (filterDescription)
  46254. {
  46255. }
  46256. FileFilter::~FileFilter()
  46257. {
  46258. }
  46259. const String& FileFilter::getDescription() const throw()
  46260. {
  46261. return description;
  46262. }
  46263. END_JUCE_NAMESPACE
  46264. /*** End of inlined file: juce_FileFilter.cpp ***/
  46265. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46266. BEGIN_JUCE_NAMESPACE
  46267. Image* juce_createIconForFile (const File& file);
  46268. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46269. : ListBox (String::empty, 0),
  46270. DirectoryContentsDisplayComponent (listToShow)
  46271. {
  46272. setModel (this);
  46273. fileList.addChangeListener (this);
  46274. }
  46275. FileListComponent::~FileListComponent()
  46276. {
  46277. fileList.removeChangeListener (this);
  46278. deleteAllChildren();
  46279. }
  46280. int FileListComponent::getNumSelectedFiles() const
  46281. {
  46282. return getNumSelectedRows();
  46283. }
  46284. const File FileListComponent::getSelectedFile (int index) const
  46285. {
  46286. return fileList.getFile (getSelectedRow (index));
  46287. }
  46288. void FileListComponent::scrollToTop()
  46289. {
  46290. getVerticalScrollBar()->setCurrentRangeStart (0);
  46291. }
  46292. void FileListComponent::changeListenerCallback (void*)
  46293. {
  46294. updateContent();
  46295. if (lastDirectory != fileList.getDirectory())
  46296. {
  46297. lastDirectory = fileList.getDirectory();
  46298. deselectAllRows();
  46299. }
  46300. }
  46301. class FileListItemComponent : public Component,
  46302. public TimeSliceClient,
  46303. public AsyncUpdater
  46304. {
  46305. public:
  46306. FileListItemComponent (FileListComponent& owner_, TimeSliceThread& thread_)
  46307. : owner (owner_), thread (thread_),
  46308. highlighted (false), index (0), icon (0)
  46309. {
  46310. }
  46311. ~FileListItemComponent()
  46312. {
  46313. thread.removeTimeSliceClient (this);
  46314. clearIcon();
  46315. }
  46316. void paint (Graphics& g)
  46317. {
  46318. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46319. file.getFileName(),
  46320. icon,
  46321. fileSize, modTime,
  46322. isDirectory, highlighted,
  46323. index);
  46324. }
  46325. void mouseDown (const MouseEvent& e)
  46326. {
  46327. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46328. owner.sendMouseClickMessage (file, e);
  46329. }
  46330. void mouseDoubleClick (const MouseEvent&)
  46331. {
  46332. owner.sendDoubleClickMessage (file);
  46333. }
  46334. void update (const File& root,
  46335. const DirectoryContentsList::FileInfo* const fileInfo,
  46336. const int index_,
  46337. const bool highlighted_)
  46338. {
  46339. thread.removeTimeSliceClient (this);
  46340. if (highlighted_ != highlighted
  46341. || index_ != index)
  46342. {
  46343. index = index_;
  46344. highlighted = highlighted_;
  46345. repaint();
  46346. }
  46347. File newFile;
  46348. String newFileSize;
  46349. String newModTime;
  46350. if (fileInfo != 0)
  46351. {
  46352. newFile = root.getChildFile (fileInfo->filename);
  46353. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46354. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46355. }
  46356. if (newFile != file
  46357. || fileSize != newFileSize
  46358. || modTime != newModTime)
  46359. {
  46360. file = newFile;
  46361. fileSize = newFileSize;
  46362. modTime = newModTime;
  46363. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46364. repaint();
  46365. clearIcon();
  46366. }
  46367. if (file != File::nonexistent
  46368. && icon == 0 && ! isDirectory)
  46369. {
  46370. updateIcon (true);
  46371. if (icon == 0)
  46372. thread.addTimeSliceClient (this);
  46373. }
  46374. }
  46375. bool useTimeSlice()
  46376. {
  46377. updateIcon (false);
  46378. return false;
  46379. }
  46380. void handleAsyncUpdate()
  46381. {
  46382. repaint();
  46383. }
  46384. juce_UseDebuggingNewOperator
  46385. private:
  46386. FileListComponent& owner;
  46387. TimeSliceThread& thread;
  46388. bool highlighted;
  46389. int index;
  46390. File file;
  46391. String fileSize;
  46392. String modTime;
  46393. Image* icon;
  46394. bool isDirectory;
  46395. void clearIcon()
  46396. {
  46397. ImageCache::release (icon);
  46398. icon = 0;
  46399. }
  46400. void updateIcon (const bool onlyUpdateIfCached)
  46401. {
  46402. if (icon == 0)
  46403. {
  46404. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46405. Image* im = ImageCache::getFromHashCode (hashCode);
  46406. if (im == 0 && ! onlyUpdateIfCached)
  46407. {
  46408. im = juce_createIconForFile (file);
  46409. if (im != 0)
  46410. ImageCache::addImageToCache (im, hashCode);
  46411. }
  46412. if (im != 0)
  46413. {
  46414. icon = im;
  46415. triggerAsyncUpdate();
  46416. }
  46417. }
  46418. }
  46419. };
  46420. int FileListComponent::getNumRows()
  46421. {
  46422. return fileList.getNumFiles();
  46423. }
  46424. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46425. {
  46426. }
  46427. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46428. {
  46429. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46430. if (comp == 0)
  46431. {
  46432. delete existingComponentToUpdate;
  46433. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46434. }
  46435. DirectoryContentsList::FileInfo fileInfo;
  46436. if (fileList.getFileInfo (row, fileInfo))
  46437. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46438. else
  46439. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46440. return comp;
  46441. }
  46442. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46443. {
  46444. sendSelectionChangeMessage();
  46445. }
  46446. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46447. {
  46448. }
  46449. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46450. {
  46451. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46452. }
  46453. END_JUCE_NAMESPACE
  46454. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46455. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46456. BEGIN_JUCE_NAMESPACE
  46457. FilenameComponent::FilenameComponent (const String& name,
  46458. const File& currentFile,
  46459. const bool canEditFilename,
  46460. const bool isDirectory,
  46461. const bool isForSaving,
  46462. const String& fileBrowserWildcard,
  46463. const String& enforcedSuffix_,
  46464. const String& textWhenNothingSelected)
  46465. : Component (name),
  46466. maxRecentFiles (30),
  46467. isDir (isDirectory),
  46468. isSaving (isForSaving),
  46469. isFileDragOver (false),
  46470. wildcard (fileBrowserWildcard),
  46471. enforcedSuffix (enforcedSuffix_)
  46472. {
  46473. addAndMakeVisible (filenameBox = new ComboBox ("fn"));
  46474. filenameBox->setEditableText (canEditFilename);
  46475. filenameBox->addListener (this);
  46476. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46477. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46478. browseButton = 0;
  46479. setBrowseButtonText ("...");
  46480. setCurrentFile (currentFile, true);
  46481. }
  46482. FilenameComponent::~FilenameComponent()
  46483. {
  46484. deleteAllChildren();
  46485. }
  46486. void FilenameComponent::paintOverChildren (Graphics& g)
  46487. {
  46488. if (isFileDragOver)
  46489. {
  46490. g.setColour (Colours::red.withAlpha (0.2f));
  46491. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46492. }
  46493. }
  46494. void FilenameComponent::resized()
  46495. {
  46496. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46497. }
  46498. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46499. {
  46500. browseButtonText = newBrowseButtonText;
  46501. lookAndFeelChanged();
  46502. }
  46503. void FilenameComponent::lookAndFeelChanged()
  46504. {
  46505. deleteAndZero (browseButton);
  46506. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46507. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46508. resized();
  46509. browseButton->addButtonListener (this);
  46510. }
  46511. void FilenameComponent::setTooltip (const String& newTooltip)
  46512. {
  46513. SettableTooltipClient::setTooltip (newTooltip);
  46514. filenameBox->setTooltip (newTooltip);
  46515. }
  46516. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46517. {
  46518. defaultBrowseFile = newDefaultDirectory;
  46519. }
  46520. void FilenameComponent::buttonClicked (Button*)
  46521. {
  46522. FileChooser fc (TRANS("Choose a new file"),
  46523. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46524. : getCurrentFile(),
  46525. wildcard);
  46526. if (isDir ? fc.browseForDirectory()
  46527. : (isSaving ? fc.browseForFileToSave (false)
  46528. : fc.browseForFileToOpen()))
  46529. {
  46530. setCurrentFile (fc.getResult(), true);
  46531. }
  46532. }
  46533. void FilenameComponent::comboBoxChanged (ComboBox*)
  46534. {
  46535. setCurrentFile (getCurrentFile(), true);
  46536. }
  46537. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46538. {
  46539. return true;
  46540. }
  46541. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46542. {
  46543. isFileDragOver = false;
  46544. repaint();
  46545. const File f (filenames[0]);
  46546. if (f.exists() && (f.isDirectory() == isDir))
  46547. setCurrentFile (f, true);
  46548. }
  46549. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46550. {
  46551. isFileDragOver = true;
  46552. repaint();
  46553. }
  46554. void FilenameComponent::fileDragExit (const StringArray&)
  46555. {
  46556. isFileDragOver = false;
  46557. repaint();
  46558. }
  46559. const File FilenameComponent::getCurrentFile() const
  46560. {
  46561. File f (filenameBox->getText());
  46562. if (enforcedSuffix.isNotEmpty())
  46563. f = f.withFileExtension (enforcedSuffix);
  46564. return f;
  46565. }
  46566. void FilenameComponent::setCurrentFile (File newFile,
  46567. const bool addToRecentlyUsedList,
  46568. const bool sendChangeNotification)
  46569. {
  46570. if (enforcedSuffix.isNotEmpty())
  46571. newFile = newFile.withFileExtension (enforcedSuffix);
  46572. if (newFile.getFullPathName() != lastFilename)
  46573. {
  46574. lastFilename = newFile.getFullPathName();
  46575. if (addToRecentlyUsedList)
  46576. addRecentlyUsedFile (newFile);
  46577. filenameBox->setText (lastFilename, true);
  46578. if (sendChangeNotification)
  46579. triggerAsyncUpdate();
  46580. }
  46581. }
  46582. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46583. {
  46584. filenameBox->setEditableText (shouldBeEditable);
  46585. }
  46586. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46587. {
  46588. StringArray names;
  46589. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46590. names.add (filenameBox->getItemText (i));
  46591. return names;
  46592. }
  46593. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46594. {
  46595. if (filenames != getRecentlyUsedFilenames())
  46596. {
  46597. filenameBox->clear();
  46598. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46599. filenameBox->addItem (filenames[i], i + 1);
  46600. }
  46601. }
  46602. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46603. {
  46604. maxRecentFiles = jmax (1, newMaximum);
  46605. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46606. }
  46607. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46608. {
  46609. StringArray files (getRecentlyUsedFilenames());
  46610. if (file.getFullPathName().isNotEmpty())
  46611. {
  46612. files.removeString (file.getFullPathName(), true);
  46613. files.insert (0, file.getFullPathName());
  46614. setRecentlyUsedFilenames (files);
  46615. }
  46616. }
  46617. void FilenameComponent::addListener (FilenameComponentListener* const listener)
  46618. {
  46619. listeners.add (listener);
  46620. }
  46621. void FilenameComponent::removeListener (FilenameComponentListener* const listener)
  46622. {
  46623. listeners.remove (listener);
  46624. }
  46625. void FilenameComponent::handleAsyncUpdate()
  46626. {
  46627. Component::BailOutChecker checker (this);
  46628. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46629. }
  46630. END_JUCE_NAMESPACE
  46631. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46632. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46633. BEGIN_JUCE_NAMESPACE
  46634. FileSearchPathListComponent::FileSearchPathListComponent()
  46635. {
  46636. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46637. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46638. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46639. listBox->setOutlineThickness (1);
  46640. addAndMakeVisible (addButton = new TextButton ("+"));
  46641. addButton->addButtonListener (this);
  46642. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46643. addAndMakeVisible (removeButton = new TextButton ("-"));
  46644. removeButton->addButtonListener (this);
  46645. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46646. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46647. changeButton->addButtonListener (this);
  46648. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46649. upButton->addButtonListener (this);
  46650. {
  46651. Path arrowPath;
  46652. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46653. DrawablePath arrowImage;
  46654. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46655. arrowImage.setPath (arrowPath);
  46656. upButton->setImages (&arrowImage);
  46657. }
  46658. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46659. downButton->addButtonListener (this);
  46660. {
  46661. Path arrowPath;
  46662. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46663. DrawablePath arrowImage;
  46664. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46665. arrowImage.setPath (arrowPath);
  46666. downButton->setImages (&arrowImage);
  46667. }
  46668. updateButtons();
  46669. }
  46670. FileSearchPathListComponent::~FileSearchPathListComponent()
  46671. {
  46672. deleteAllChildren();
  46673. }
  46674. void FileSearchPathListComponent::updateButtons()
  46675. {
  46676. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46677. removeButton->setEnabled (anythingSelected);
  46678. changeButton->setEnabled (anythingSelected);
  46679. upButton->setEnabled (anythingSelected);
  46680. downButton->setEnabled (anythingSelected);
  46681. }
  46682. void FileSearchPathListComponent::changed()
  46683. {
  46684. listBox->updateContent();
  46685. listBox->repaint();
  46686. updateButtons();
  46687. }
  46688. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46689. {
  46690. if (newPath.toString() != path.toString())
  46691. {
  46692. path = newPath;
  46693. changed();
  46694. }
  46695. }
  46696. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46697. {
  46698. defaultBrowseTarget = newDefaultDirectory;
  46699. }
  46700. int FileSearchPathListComponent::getNumRows()
  46701. {
  46702. return path.getNumPaths();
  46703. }
  46704. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46705. {
  46706. if (rowIsSelected)
  46707. g.fillAll (findColour (TextEditor::highlightColourId));
  46708. g.setColour (findColour (ListBox::textColourId));
  46709. Font f (height * 0.7f);
  46710. f.setHorizontalScale (0.9f);
  46711. g.setFont (f);
  46712. g.drawText (path [rowNumber].getFullPathName(),
  46713. 4, 0, width - 6, height,
  46714. Justification::centredLeft, true);
  46715. }
  46716. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46717. {
  46718. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46719. {
  46720. path.remove (row);
  46721. changed();
  46722. }
  46723. }
  46724. void FileSearchPathListComponent::returnKeyPressed (int row)
  46725. {
  46726. FileChooser chooser (TRANS("Change folder..."), path [row], "*");
  46727. if (chooser.browseForDirectory())
  46728. {
  46729. path.remove (row);
  46730. path.add (chooser.getResult(), row);
  46731. changed();
  46732. }
  46733. }
  46734. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46735. {
  46736. returnKeyPressed (row);
  46737. }
  46738. void FileSearchPathListComponent::selectedRowsChanged (int)
  46739. {
  46740. updateButtons();
  46741. }
  46742. void FileSearchPathListComponent::paint (Graphics& g)
  46743. {
  46744. g.fillAll (findColour (backgroundColourId));
  46745. }
  46746. void FileSearchPathListComponent::resized()
  46747. {
  46748. const int buttonH = 22;
  46749. const int buttonY = getHeight() - buttonH - 4;
  46750. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46751. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46752. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46753. changeButton->changeWidthToFitText (buttonH);
  46754. downButton->setSize (buttonH * 2, buttonH);
  46755. upButton->setSize (buttonH * 2, buttonH);
  46756. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46757. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46758. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46759. }
  46760. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46761. {
  46762. return true;
  46763. }
  46764. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46765. {
  46766. for (int i = filenames.size(); --i >= 0;)
  46767. {
  46768. const File f (filenames[i]);
  46769. if (f.isDirectory())
  46770. {
  46771. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46772. path.add (f, row);
  46773. changed();
  46774. }
  46775. }
  46776. }
  46777. void FileSearchPathListComponent::buttonClicked (Button* button)
  46778. {
  46779. const int currentRow = listBox->getSelectedRow();
  46780. if (button == removeButton)
  46781. {
  46782. deleteKeyPressed (currentRow);
  46783. }
  46784. else if (button == addButton)
  46785. {
  46786. File start (defaultBrowseTarget);
  46787. if (start == File::nonexistent)
  46788. start = path [0];
  46789. if (start == File::nonexistent)
  46790. start = File::getCurrentWorkingDirectory();
  46791. FileChooser chooser (TRANS("Add a folder..."), start, "*");
  46792. if (chooser.browseForDirectory())
  46793. {
  46794. path.add (chooser.getResult(), currentRow);
  46795. }
  46796. }
  46797. else if (button == changeButton)
  46798. {
  46799. returnKeyPressed (currentRow);
  46800. }
  46801. else if (button == upButton)
  46802. {
  46803. if (currentRow > 0 && currentRow < path.getNumPaths())
  46804. {
  46805. const File f (path[currentRow]);
  46806. path.remove (currentRow);
  46807. path.add (f, currentRow - 1);
  46808. listBox->selectRow (currentRow - 1);
  46809. }
  46810. }
  46811. else if (button == downButton)
  46812. {
  46813. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46814. {
  46815. const File f (path[currentRow]);
  46816. path.remove (currentRow);
  46817. path.add (f, currentRow + 1);
  46818. listBox->selectRow (currentRow + 1);
  46819. }
  46820. }
  46821. changed();
  46822. }
  46823. END_JUCE_NAMESPACE
  46824. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46825. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46826. BEGIN_JUCE_NAMESPACE
  46827. Image* juce_createIconForFile (const File& file);
  46828. class FileListTreeItem : public TreeViewItem,
  46829. public TimeSliceClient,
  46830. public AsyncUpdater,
  46831. public ChangeListener
  46832. {
  46833. public:
  46834. FileListTreeItem (FileTreeComponent& owner_,
  46835. DirectoryContentsList* const parentContentsList_,
  46836. const int indexInContentsList_,
  46837. const File& file_,
  46838. TimeSliceThread& thread_)
  46839. : file (file_),
  46840. owner (owner_),
  46841. parentContentsList (parentContentsList_),
  46842. indexInContentsList (indexInContentsList_),
  46843. subContentsList (0),
  46844. canDeleteSubContentsList (false),
  46845. thread (thread_),
  46846. icon (0)
  46847. {
  46848. DirectoryContentsList::FileInfo fileInfo;
  46849. if (parentContentsList_ != 0
  46850. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46851. {
  46852. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46853. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46854. isDirectory = fileInfo.isDirectory;
  46855. }
  46856. else
  46857. {
  46858. isDirectory = true;
  46859. }
  46860. }
  46861. ~FileListTreeItem()
  46862. {
  46863. thread.removeTimeSliceClient (this);
  46864. clearSubItems();
  46865. ImageCache::release (icon);
  46866. if (canDeleteSubContentsList)
  46867. delete subContentsList;
  46868. }
  46869. bool mightContainSubItems() { return isDirectory; }
  46870. const String getUniqueName() const { return file.getFullPathName(); }
  46871. int getItemHeight() const { return 22; }
  46872. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46873. void itemOpennessChanged (bool isNowOpen)
  46874. {
  46875. if (isNowOpen)
  46876. {
  46877. clearSubItems();
  46878. isDirectory = file.isDirectory();
  46879. if (isDirectory)
  46880. {
  46881. if (subContentsList == 0)
  46882. {
  46883. jassert (parentContentsList != 0);
  46884. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46885. l->setDirectory (file, true, true);
  46886. setSubContentsList (l);
  46887. canDeleteSubContentsList = true;
  46888. }
  46889. changeListenerCallback (0);
  46890. }
  46891. }
  46892. }
  46893. void setSubContentsList (DirectoryContentsList* newList)
  46894. {
  46895. jassert (subContentsList == 0);
  46896. subContentsList = newList;
  46897. newList->addChangeListener (this);
  46898. }
  46899. void changeListenerCallback (void*)
  46900. {
  46901. clearSubItems();
  46902. if (isOpen() && subContentsList != 0)
  46903. {
  46904. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46905. {
  46906. FileListTreeItem* const item
  46907. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46908. addSubItem (item);
  46909. }
  46910. }
  46911. }
  46912. void paintItem (Graphics& g, int width, int height)
  46913. {
  46914. if (file != File::nonexistent)
  46915. {
  46916. updateIcon (true);
  46917. if (icon == 0)
  46918. thread.addTimeSliceClient (this);
  46919. }
  46920. owner.getLookAndFeel()
  46921. .drawFileBrowserRow (g, width, height,
  46922. file.getFileName(),
  46923. icon,
  46924. fileSize, modTime,
  46925. isDirectory, isSelected(),
  46926. indexInContentsList);
  46927. }
  46928. void itemClicked (const MouseEvent& e)
  46929. {
  46930. owner.sendMouseClickMessage (file, e);
  46931. }
  46932. void itemDoubleClicked (const MouseEvent& e)
  46933. {
  46934. TreeViewItem::itemDoubleClicked (e);
  46935. owner.sendDoubleClickMessage (file);
  46936. }
  46937. void itemSelectionChanged (bool)
  46938. {
  46939. owner.sendSelectionChangeMessage();
  46940. }
  46941. bool useTimeSlice()
  46942. {
  46943. updateIcon (false);
  46944. thread.removeTimeSliceClient (this);
  46945. return false;
  46946. }
  46947. void handleAsyncUpdate()
  46948. {
  46949. owner.repaint();
  46950. }
  46951. const File file;
  46952. juce_UseDebuggingNewOperator
  46953. private:
  46954. FileTreeComponent& owner;
  46955. DirectoryContentsList* parentContentsList;
  46956. int indexInContentsList;
  46957. DirectoryContentsList* subContentsList;
  46958. bool isDirectory, canDeleteSubContentsList;
  46959. TimeSliceThread& thread;
  46960. Image* icon;
  46961. String fileSize;
  46962. String modTime;
  46963. void updateIcon (const bool onlyUpdateIfCached)
  46964. {
  46965. if (icon == 0)
  46966. {
  46967. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46968. Image* im = ImageCache::getFromHashCode (hashCode);
  46969. if (im == 0 && ! onlyUpdateIfCached)
  46970. {
  46971. im = juce_createIconForFile (file);
  46972. if (im != 0)
  46973. ImageCache::addImageToCache (im, hashCode);
  46974. }
  46975. if (im != 0)
  46976. {
  46977. icon = im;
  46978. triggerAsyncUpdate();
  46979. }
  46980. }
  46981. }
  46982. };
  46983. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46984. : DirectoryContentsDisplayComponent (listToShow)
  46985. {
  46986. FileListTreeItem* const root
  46987. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46988. listToShow.getTimeSliceThread());
  46989. root->setSubContentsList (&listToShow);
  46990. setRootItemVisible (false);
  46991. setRootItem (root);
  46992. }
  46993. FileTreeComponent::~FileTreeComponent()
  46994. {
  46995. deleteRootItem();
  46996. }
  46997. const File FileTreeComponent::getSelectedFile (const int index) const
  46998. {
  46999. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47000. if (item != 0)
  47001. return item->file;
  47002. return File::nonexistent;
  47003. }
  47004. void FileTreeComponent::scrollToTop()
  47005. {
  47006. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47007. }
  47008. void FileTreeComponent::setDragAndDropDescription (const String& description)
  47009. {
  47010. dragAndDropDescription = description;
  47011. }
  47012. END_JUCE_NAMESPACE
  47013. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47014. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47015. BEGIN_JUCE_NAMESPACE
  47016. ImagePreviewComponent::ImagePreviewComponent()
  47017. {
  47018. }
  47019. ImagePreviewComponent::~ImagePreviewComponent()
  47020. {
  47021. }
  47022. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47023. {
  47024. const int availableW = proportionOfWidth (0.97f);
  47025. const int availableH = getHeight() - 13 * 4;
  47026. const double scale = jmin (1.0,
  47027. availableW / (double) w,
  47028. availableH / (double) h);
  47029. w = roundToInt (scale * w);
  47030. h = roundToInt (scale * h);
  47031. }
  47032. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47033. {
  47034. if (fileToLoad != file)
  47035. {
  47036. fileToLoad = file;
  47037. startTimer (100);
  47038. }
  47039. }
  47040. void ImagePreviewComponent::timerCallback()
  47041. {
  47042. stopTimer();
  47043. currentThumbnail = 0;
  47044. currentDetails = String::empty;
  47045. repaint();
  47046. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47047. if (in != 0)
  47048. {
  47049. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47050. if (format != 0)
  47051. {
  47052. currentThumbnail = format->decodeImage (*in);
  47053. if (currentThumbnail != 0)
  47054. {
  47055. int w = currentThumbnail->getWidth();
  47056. int h = currentThumbnail->getHeight();
  47057. currentDetails
  47058. << fileToLoad.getFileName() << "\n"
  47059. << format->getFormatName() << "\n"
  47060. << w << " x " << h << " pixels\n"
  47061. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47062. getThumbSize (w, h);
  47063. currentThumbnail = currentThumbnail->createCopy (w, h);
  47064. }
  47065. }
  47066. }
  47067. }
  47068. void ImagePreviewComponent::paint (Graphics& g)
  47069. {
  47070. if (currentThumbnail != 0)
  47071. {
  47072. g.setFont (13.0f);
  47073. int w = currentThumbnail->getWidth();
  47074. int h = currentThumbnail->getHeight();
  47075. getThumbSize (w, h);
  47076. const int numLines = 4;
  47077. const int totalH = 13 * numLines + h + 4;
  47078. const int y = (getHeight() - totalH) / 2;
  47079. g.drawImageWithin (currentThumbnail,
  47080. (getWidth() - w) / 2, y, w, h,
  47081. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47082. false);
  47083. g.drawFittedText (currentDetails,
  47084. 0, y + h + 4, getWidth(), 100,
  47085. Justification::centredTop, numLines);
  47086. }
  47087. }
  47088. END_JUCE_NAMESPACE
  47089. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47090. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47091. BEGIN_JUCE_NAMESPACE
  47092. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47093. const String& directoryWildcardPatterns,
  47094. const String& description_)
  47095. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47096. : (description_ + " (" + fileWildcardPatterns + ")"))
  47097. {
  47098. parse (fileWildcardPatterns, fileWildcards);
  47099. parse (directoryWildcardPatterns, directoryWildcards);
  47100. }
  47101. WildcardFileFilter::~WildcardFileFilter()
  47102. {
  47103. }
  47104. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47105. {
  47106. return match (file, fileWildcards);
  47107. }
  47108. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47109. {
  47110. return match (file, directoryWildcards);
  47111. }
  47112. void WildcardFileFilter::parse (const String& pattern, StringArray& result)
  47113. {
  47114. result.addTokens (pattern.toLowerCase(), ";,", "\"'");
  47115. result.trim();
  47116. result.removeEmptyStrings();
  47117. // special case for *.*, because people use it to mean "any file", but it
  47118. // would actually ignore files with no extension.
  47119. for (int i = result.size(); --i >= 0;)
  47120. if (result[i] == "*.*")
  47121. result.set (i, "*");
  47122. }
  47123. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards)
  47124. {
  47125. const String filename (file.getFileName());
  47126. for (int i = wildcards.size(); --i >= 0;)
  47127. if (filename.matchesWildcard (wildcards[i], true))
  47128. return true;
  47129. return false;
  47130. }
  47131. END_JUCE_NAMESPACE
  47132. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47133. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47134. BEGIN_JUCE_NAMESPACE
  47135. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47136. {
  47137. }
  47138. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47139. {
  47140. }
  47141. namespace KeyboardFocusHelpers
  47142. {
  47143. // This will sort a set of components, so that they are ordered in terms of
  47144. // left-to-right and then top-to-bottom.
  47145. class ScreenPositionComparator
  47146. {
  47147. public:
  47148. ScreenPositionComparator() {}
  47149. static int compareElements (const Component* const first, const Component* const second)
  47150. {
  47151. int explicitOrder1 = first->getExplicitFocusOrder();
  47152. if (explicitOrder1 <= 0)
  47153. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47154. int explicitOrder2 = second->getExplicitFocusOrder();
  47155. if (explicitOrder2 <= 0)
  47156. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47157. if (explicitOrder1 != explicitOrder2)
  47158. return explicitOrder1 - explicitOrder2;
  47159. const int diff = first->getY() - second->getY();
  47160. return (diff == 0) ? first->getX() - second->getX()
  47161. : diff;
  47162. }
  47163. };
  47164. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47165. {
  47166. if (parent->getNumChildComponents() > 0)
  47167. {
  47168. Array <Component*> localComps;
  47169. ScreenPositionComparator comparator;
  47170. int i;
  47171. for (i = parent->getNumChildComponents(); --i >= 0;)
  47172. {
  47173. Component* const c = parent->getChildComponent (i);
  47174. if (c->isVisible() && c->isEnabled())
  47175. localComps.addSorted (comparator, c);
  47176. }
  47177. for (i = 0; i < localComps.size(); ++i)
  47178. {
  47179. Component* const c = localComps.getUnchecked (i);
  47180. if (c->getWantsKeyboardFocus())
  47181. comps.add (c);
  47182. if (! c->isFocusContainer())
  47183. findAllFocusableComponents (c, comps);
  47184. }
  47185. }
  47186. }
  47187. }
  47188. static Component* getIncrementedComponent (Component* const current, const int delta)
  47189. {
  47190. Component* focusContainer = current->getParentComponent();
  47191. if (focusContainer != 0)
  47192. {
  47193. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47194. focusContainer = focusContainer->getParentComponent();
  47195. if (focusContainer != 0)
  47196. {
  47197. Array <Component*> comps;
  47198. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47199. if (comps.size() > 0)
  47200. {
  47201. const int index = comps.indexOf (current);
  47202. return comps [(index + comps.size() + delta) % comps.size()];
  47203. }
  47204. }
  47205. }
  47206. return 0;
  47207. }
  47208. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47209. {
  47210. return getIncrementedComponent (current, 1);
  47211. }
  47212. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47213. {
  47214. return getIncrementedComponent (current, -1);
  47215. }
  47216. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47217. {
  47218. Array <Component*> comps;
  47219. if (parentComponent != 0)
  47220. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47221. return comps.getFirst();
  47222. }
  47223. END_JUCE_NAMESPACE
  47224. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47225. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47226. BEGIN_JUCE_NAMESPACE
  47227. bool KeyListener::keyStateChanged (const bool, Component*)
  47228. {
  47229. return false;
  47230. }
  47231. END_JUCE_NAMESPACE
  47232. /*** End of inlined file: juce_KeyListener.cpp ***/
  47233. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47234. BEGIN_JUCE_NAMESPACE
  47235. // N.B. these two includes are put here deliberately to avoid problems with
  47236. // old GCCs failing on long include paths
  47237. const int maxKeys = 3;
  47238. class KeyMappingChangeButton : public Button
  47239. {
  47240. public:
  47241. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47242. const CommandID commandID_,
  47243. const String& keyName,
  47244. const int keyNum_)
  47245. : Button (keyName),
  47246. owner (owner_),
  47247. commandID (commandID_),
  47248. keyNum (keyNum_)
  47249. {
  47250. setWantsKeyboardFocus (false);
  47251. setTriggeredOnMouseDown (keyNum >= 0);
  47252. if (keyNum_ < 0)
  47253. setTooltip (TRANS("adds a new key-mapping"));
  47254. else
  47255. setTooltip (TRANS("click to change this key-mapping"));
  47256. }
  47257. ~KeyMappingChangeButton()
  47258. {
  47259. }
  47260. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47261. {
  47262. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47263. keyNum >= 0 ? getName() : String::empty);
  47264. }
  47265. void clicked()
  47266. {
  47267. if (keyNum >= 0)
  47268. {
  47269. // existing key clicked..
  47270. PopupMenu m;
  47271. m.addItem (1, TRANS("change this key-mapping"));
  47272. m.addSeparator();
  47273. m.addItem (2, TRANS("remove this key-mapping"));
  47274. const int res = m.show();
  47275. if (res == 1)
  47276. {
  47277. owner->assignNewKey (commandID, keyNum);
  47278. }
  47279. else if (res == 2)
  47280. {
  47281. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47282. }
  47283. }
  47284. else
  47285. {
  47286. // + button pressed..
  47287. owner->assignNewKey (commandID, -1);
  47288. }
  47289. }
  47290. void fitToContent (const int h) throw()
  47291. {
  47292. if (keyNum < 0)
  47293. {
  47294. setSize (h, h);
  47295. }
  47296. else
  47297. {
  47298. Font f (h * 0.6f);
  47299. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47300. }
  47301. }
  47302. juce_UseDebuggingNewOperator
  47303. private:
  47304. KeyMappingEditorComponent* const owner;
  47305. const CommandID commandID;
  47306. const int keyNum;
  47307. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47308. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47309. };
  47310. class KeyMappingItemComponent : public Component
  47311. {
  47312. public:
  47313. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47314. const CommandID commandID_)
  47315. : owner (owner_),
  47316. commandID (commandID_)
  47317. {
  47318. setInterceptsMouseClicks (false, true);
  47319. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47320. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47321. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47322. {
  47323. KeyMappingChangeButton* const kb
  47324. = new KeyMappingChangeButton (owner_, commandID,
  47325. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47326. kb->setEnabled (! isReadOnly);
  47327. addAndMakeVisible (kb);
  47328. }
  47329. KeyMappingChangeButton* const kb
  47330. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47331. addChildComponent (kb);
  47332. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47333. }
  47334. ~KeyMappingItemComponent()
  47335. {
  47336. deleteAllChildren();
  47337. }
  47338. void paint (Graphics& g)
  47339. {
  47340. g.setFont (getHeight() * 0.7f);
  47341. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47342. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47343. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47344. Justification::centredLeft, true);
  47345. }
  47346. void resized()
  47347. {
  47348. int x = getWidth() - 4;
  47349. for (int i = getNumChildComponents(); --i >= 0;)
  47350. {
  47351. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47352. kb->fitToContent (getHeight() - 2);
  47353. kb->setTopRightPosition (x, 1);
  47354. x -= kb->getWidth() + 5;
  47355. }
  47356. }
  47357. juce_UseDebuggingNewOperator
  47358. private:
  47359. KeyMappingEditorComponent* const owner;
  47360. const CommandID commandID;
  47361. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47362. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47363. };
  47364. class KeyMappingTreeViewItem : public TreeViewItem
  47365. {
  47366. public:
  47367. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47368. const CommandID commandID_)
  47369. : owner (owner_),
  47370. commandID (commandID_)
  47371. {
  47372. }
  47373. ~KeyMappingTreeViewItem()
  47374. {
  47375. }
  47376. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47377. bool mightContainSubItems() { return false; }
  47378. int getItemHeight() const { return 20; }
  47379. Component* createItemComponent()
  47380. {
  47381. return new KeyMappingItemComponent (owner, commandID);
  47382. }
  47383. juce_UseDebuggingNewOperator
  47384. private:
  47385. KeyMappingEditorComponent* const owner;
  47386. const CommandID commandID;
  47387. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47388. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47389. };
  47390. class KeyCategoryTreeViewItem : public TreeViewItem
  47391. {
  47392. public:
  47393. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47394. const String& name)
  47395. : owner (owner_),
  47396. categoryName (name)
  47397. {
  47398. }
  47399. ~KeyCategoryTreeViewItem()
  47400. {
  47401. }
  47402. const String getUniqueName() const { return categoryName + "_cat"; }
  47403. bool mightContainSubItems() { return true; }
  47404. int getItemHeight() const { return 28; }
  47405. void paintItem (Graphics& g, int width, int height)
  47406. {
  47407. g.setFont (height * 0.6f, Font::bold);
  47408. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47409. g.drawText (categoryName,
  47410. 2, 0, width - 2, height,
  47411. Justification::centredLeft, true);
  47412. }
  47413. void itemOpennessChanged (bool isNowOpen)
  47414. {
  47415. if (isNowOpen)
  47416. {
  47417. if (getNumSubItems() == 0)
  47418. {
  47419. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47420. for (int i = 0; i < commands.size(); ++i)
  47421. {
  47422. if (owner->shouldCommandBeIncluded (commands[i]))
  47423. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47424. }
  47425. }
  47426. }
  47427. else
  47428. {
  47429. clearSubItems();
  47430. }
  47431. }
  47432. juce_UseDebuggingNewOperator
  47433. private:
  47434. KeyMappingEditorComponent* owner;
  47435. String categoryName;
  47436. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47437. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47438. };
  47439. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47440. const bool showResetToDefaultButton)
  47441. : mappings (mappingManager)
  47442. {
  47443. jassert (mappingManager != 0); // can't be null!
  47444. mappingManager->addChangeListener (this);
  47445. setLinesDrawnForSubItems (false);
  47446. resetButton = 0;
  47447. if (showResetToDefaultButton)
  47448. {
  47449. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47450. resetButton->addButtonListener (this);
  47451. }
  47452. addAndMakeVisible (tree = new TreeView());
  47453. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47454. tree->setRootItemVisible (false);
  47455. tree->setDefaultOpenness (true);
  47456. tree->setRootItem (this);
  47457. }
  47458. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47459. {
  47460. mappings->removeChangeListener (this);
  47461. deleteAllChildren();
  47462. }
  47463. bool KeyMappingEditorComponent::mightContainSubItems()
  47464. {
  47465. return true;
  47466. }
  47467. const String KeyMappingEditorComponent::getUniqueName() const
  47468. {
  47469. return "keys";
  47470. }
  47471. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47472. const Colour& textColour)
  47473. {
  47474. setColour (backgroundColourId, mainBackground);
  47475. setColour (textColourId, textColour);
  47476. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47477. }
  47478. void KeyMappingEditorComponent::parentHierarchyChanged()
  47479. {
  47480. changeListenerCallback (0);
  47481. }
  47482. void KeyMappingEditorComponent::resized()
  47483. {
  47484. int h = getHeight();
  47485. if (resetButton != 0)
  47486. {
  47487. const int buttonHeight = 20;
  47488. h -= buttonHeight + 8;
  47489. int x = getWidth() - 8;
  47490. const int y = h + 6;
  47491. resetButton->changeWidthToFitText (buttonHeight);
  47492. resetButton->setTopRightPosition (x, y);
  47493. }
  47494. tree->setBounds (0, 0, getWidth(), h);
  47495. }
  47496. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47497. {
  47498. if (button == resetButton)
  47499. {
  47500. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47501. TRANS("Reset to defaults"),
  47502. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47503. TRANS("Reset")))
  47504. {
  47505. mappings->resetToDefaultMappings();
  47506. }
  47507. }
  47508. }
  47509. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47510. {
  47511. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47512. clearSubItems();
  47513. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47514. for (int i = 0; i < categories.size(); ++i)
  47515. {
  47516. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47517. int count = 0;
  47518. for (int j = 0; j < commands.size(); ++j)
  47519. if (shouldCommandBeIncluded (commands[j]))
  47520. ++count;
  47521. if (count > 0)
  47522. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47523. }
  47524. if (openness != 0)
  47525. tree->restoreOpennessState (*openness);
  47526. }
  47527. class KeyEntryWindow : public AlertWindow
  47528. {
  47529. public:
  47530. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47531. : AlertWindow (TRANS("New key-mapping"),
  47532. TRANS("Please press a key combination now..."),
  47533. AlertWindow::NoIcon),
  47534. owner (owner_)
  47535. {
  47536. addButton (TRANS("ok"), 1);
  47537. addButton (TRANS("cancel"), 0);
  47538. // (avoid return + escape keys getting processed by the buttons..)
  47539. for (int i = getNumChildComponents(); --i >= 0;)
  47540. getChildComponent (i)->setWantsKeyboardFocus (false);
  47541. setWantsKeyboardFocus (true);
  47542. grabKeyboardFocus();
  47543. }
  47544. ~KeyEntryWindow()
  47545. {
  47546. }
  47547. bool keyPressed (const KeyPress& key)
  47548. {
  47549. lastPress = key;
  47550. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47551. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47552. if (previousCommand != 0)
  47553. {
  47554. message << "\n\n"
  47555. << TRANS("(Currently assigned to \"")
  47556. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47557. << "\")";
  47558. }
  47559. setMessage (message);
  47560. return true;
  47561. }
  47562. bool keyStateChanged (bool)
  47563. {
  47564. return true;
  47565. }
  47566. KeyPress lastPress;
  47567. juce_UseDebuggingNewOperator
  47568. private:
  47569. KeyMappingEditorComponent* owner;
  47570. KeyEntryWindow (const KeyEntryWindow&);
  47571. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47572. };
  47573. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47574. {
  47575. KeyEntryWindow entryWindow (this);
  47576. if (entryWindow.runModalLoop() != 0)
  47577. {
  47578. entryWindow.setVisible (false);
  47579. if (entryWindow.lastPress.isValid())
  47580. {
  47581. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47582. if (previousCommand != 0)
  47583. {
  47584. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47585. TRANS("Change key-mapping"),
  47586. TRANS("This key is already assigned to the command \"")
  47587. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47588. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47589. TRANS("re-assign"),
  47590. TRANS("cancel")))
  47591. {
  47592. return;
  47593. }
  47594. }
  47595. mappings->removeKeyPress (entryWindow.lastPress);
  47596. if (index >= 0)
  47597. mappings->removeKeyPress (commandID, index);
  47598. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47599. }
  47600. }
  47601. }
  47602. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47603. {
  47604. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47605. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47606. }
  47607. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47608. {
  47609. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47610. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47611. }
  47612. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47613. {
  47614. return key.getTextDescription();
  47615. }
  47616. END_JUCE_NAMESPACE
  47617. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47618. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47619. BEGIN_JUCE_NAMESPACE
  47620. KeyPress::KeyPress() throw()
  47621. : keyCode (0),
  47622. mods (0),
  47623. textCharacter (0)
  47624. {
  47625. }
  47626. KeyPress::KeyPress (const int keyCode_,
  47627. const ModifierKeys& mods_,
  47628. const juce_wchar textCharacter_) throw()
  47629. : keyCode (keyCode_),
  47630. mods (mods_),
  47631. textCharacter (textCharacter_)
  47632. {
  47633. }
  47634. KeyPress::KeyPress (const int keyCode_) throw()
  47635. : keyCode (keyCode_),
  47636. textCharacter (0)
  47637. {
  47638. }
  47639. KeyPress::KeyPress (const KeyPress& other) throw()
  47640. : keyCode (other.keyCode),
  47641. mods (other.mods),
  47642. textCharacter (other.textCharacter)
  47643. {
  47644. }
  47645. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47646. {
  47647. keyCode = other.keyCode;
  47648. mods = other.mods;
  47649. textCharacter = other.textCharacter;
  47650. return *this;
  47651. }
  47652. bool KeyPress::operator== (const KeyPress& other) const throw()
  47653. {
  47654. return mods.getRawFlags() == other.mods.getRawFlags()
  47655. && (textCharacter == other.textCharacter
  47656. || textCharacter == 0
  47657. || other.textCharacter == 0)
  47658. && (keyCode == other.keyCode
  47659. || (keyCode < 256
  47660. && other.keyCode < 256
  47661. && CharacterFunctions::toLowerCase ((juce_wchar) keyCode)
  47662. == CharacterFunctions::toLowerCase ((juce_wchar) other.keyCode)));
  47663. }
  47664. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47665. {
  47666. return ! operator== (other);
  47667. }
  47668. bool KeyPress::isCurrentlyDown() const
  47669. {
  47670. return isKeyCurrentlyDown (keyCode)
  47671. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47672. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47673. }
  47674. namespace KeyPressHelpers
  47675. {
  47676. struct KeyNameAndCode
  47677. {
  47678. const char* name;
  47679. int code;
  47680. };
  47681. static const KeyNameAndCode translations[] =
  47682. {
  47683. { "spacebar", KeyPress::spaceKey },
  47684. { "return", KeyPress::returnKey },
  47685. { "escape", KeyPress::escapeKey },
  47686. { "backspace", KeyPress::backspaceKey },
  47687. { "cursor left", KeyPress::leftKey },
  47688. { "cursor right", KeyPress::rightKey },
  47689. { "cursor up", KeyPress::upKey },
  47690. { "cursor down", KeyPress::downKey },
  47691. { "page up", KeyPress::pageUpKey },
  47692. { "page down", KeyPress::pageDownKey },
  47693. { "home", KeyPress::homeKey },
  47694. { "end", KeyPress::endKey },
  47695. { "delete", KeyPress::deleteKey },
  47696. { "insert", KeyPress::insertKey },
  47697. { "tab", KeyPress::tabKey },
  47698. { "play", KeyPress::playKey },
  47699. { "stop", KeyPress::stopKey },
  47700. { "fast forward", KeyPress::fastForwardKey },
  47701. { "rewind", KeyPress::rewindKey }
  47702. };
  47703. static const String numberPadPrefix() { return "numpad "; }
  47704. }
  47705. const KeyPress KeyPress::createFromDescription (const String& desc)
  47706. {
  47707. int modifiers = 0;
  47708. if (desc.containsWholeWordIgnoreCase ("ctrl")
  47709. || desc.containsWholeWordIgnoreCase ("control")
  47710. || desc.containsWholeWordIgnoreCase ("ctl"))
  47711. modifiers |= ModifierKeys::ctrlModifier;
  47712. if (desc.containsWholeWordIgnoreCase ("shift")
  47713. || desc.containsWholeWordIgnoreCase ("shft"))
  47714. modifiers |= ModifierKeys::shiftModifier;
  47715. if (desc.containsWholeWordIgnoreCase ("alt")
  47716. || desc.containsWholeWordIgnoreCase ("option"))
  47717. modifiers |= ModifierKeys::altModifier;
  47718. if (desc.containsWholeWordIgnoreCase ("command")
  47719. || desc.containsWholeWordIgnoreCase ("cmd"))
  47720. modifiers |= ModifierKeys::commandModifier;
  47721. int key = 0;
  47722. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47723. {
  47724. if (desc.containsWholeWordIgnoreCase (String (KeyPressHelpers::translations[i].name)))
  47725. {
  47726. key = KeyPressHelpers::translations[i].code;
  47727. break;
  47728. }
  47729. }
  47730. if (key == 0)
  47731. {
  47732. // see if it's a numpad key..
  47733. if (desc.containsIgnoreCase (KeyPressHelpers::numberPadPrefix()))
  47734. {
  47735. const juce_wchar lastChar = desc.trimEnd().getLastCharacter();
  47736. if (lastChar >= '0' && lastChar <= '9')
  47737. key = numberPad0 + lastChar - '0';
  47738. else if (lastChar == '+')
  47739. key = numberPadAdd;
  47740. else if (lastChar == '-')
  47741. key = numberPadSubtract;
  47742. else if (lastChar == '*')
  47743. key = numberPadMultiply;
  47744. else if (lastChar == '/')
  47745. key = numberPadDivide;
  47746. else if (lastChar == '.')
  47747. key = numberPadDecimalPoint;
  47748. else if (lastChar == '=')
  47749. key = numberPadEquals;
  47750. else if (desc.endsWith ("separator"))
  47751. key = numberPadSeparator;
  47752. else if (desc.endsWith ("delete"))
  47753. key = numberPadDelete;
  47754. }
  47755. if (key == 0)
  47756. {
  47757. // see if it's a function key..
  47758. for (int i = 1; i <= 12; ++i)
  47759. if (desc.containsWholeWordIgnoreCase ("f" + String (i)))
  47760. key = F1Key + i - 1;
  47761. if (key == 0)
  47762. {
  47763. // give up and use the hex code..
  47764. const int hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
  47765. .toLowerCase()
  47766. .retainCharacters ("0123456789abcdef")
  47767. .getHexValue32();
  47768. if (hexCode > 0)
  47769. key = hexCode;
  47770. else
  47771. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47772. }
  47773. }
  47774. }
  47775. return KeyPress (key, ModifierKeys (modifiers), 0);
  47776. }
  47777. const String KeyPress::getTextDescription() const
  47778. {
  47779. String desc;
  47780. if (keyCode > 0)
  47781. {
  47782. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47783. // want to store it as being a slash, not shift+whatever.
  47784. if (textCharacter == '/')
  47785. return "/";
  47786. if (mods.isCtrlDown())
  47787. desc << "ctrl + ";
  47788. if (mods.isShiftDown())
  47789. desc << "shift + ";
  47790. #if JUCE_MAC
  47791. // only do this on the mac, because on Windows ctrl and command are the same,
  47792. // and this would get confusing
  47793. if (mods.isCommandDown())
  47794. desc << "command + ";
  47795. if (mods.isAltDown())
  47796. desc << "option + ";
  47797. #else
  47798. if (mods.isAltDown())
  47799. desc << "alt + ";
  47800. #endif
  47801. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47802. if (keyCode == KeyPressHelpers::translations[i].code)
  47803. return desc + KeyPressHelpers::translations[i].name;
  47804. if (keyCode >= F1Key && keyCode <= F16Key)
  47805. desc << 'F' << (1 + keyCode - F1Key);
  47806. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47807. desc << KeyPressHelpers::numberPadPrefix() << (keyCode - numberPad0);
  47808. else if (keyCode >= 33 && keyCode < 176)
  47809. desc += CharacterFunctions::toUpperCase ((juce_wchar) keyCode);
  47810. else if (keyCode == numberPadAdd)
  47811. desc << KeyPressHelpers::numberPadPrefix() << '+';
  47812. else if (keyCode == numberPadSubtract)
  47813. desc << KeyPressHelpers::numberPadPrefix() << '-';
  47814. else if (keyCode == numberPadMultiply)
  47815. desc << KeyPressHelpers::numberPadPrefix() << '*';
  47816. else if (keyCode == numberPadDivide)
  47817. desc << KeyPressHelpers::numberPadPrefix() << '/';
  47818. else if (keyCode == numberPadSeparator)
  47819. desc << KeyPressHelpers::numberPadPrefix() << "separator";
  47820. else if (keyCode == numberPadDecimalPoint)
  47821. desc << KeyPressHelpers::numberPadPrefix() << '.';
  47822. else if (keyCode == numberPadDelete)
  47823. desc << KeyPressHelpers::numberPadPrefix() << "delete";
  47824. else
  47825. desc << '#' << String::toHexString (keyCode);
  47826. }
  47827. return desc;
  47828. }
  47829. END_JUCE_NAMESPACE
  47830. /*** End of inlined file: juce_KeyPress.cpp ***/
  47831. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47832. BEGIN_JUCE_NAMESPACE
  47833. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_)
  47834. : commandManager (commandManager_)
  47835. {
  47836. // A manager is needed to get the descriptions of commands, and will be called when
  47837. // a command is invoked. So you can't leave this null..
  47838. jassert (commandManager_ != 0);
  47839. Desktop::getInstance().addFocusChangeListener (this);
  47840. }
  47841. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other)
  47842. : commandManager (other.commandManager)
  47843. {
  47844. Desktop::getInstance().addFocusChangeListener (this);
  47845. }
  47846. KeyPressMappingSet::~KeyPressMappingSet()
  47847. {
  47848. Desktop::getInstance().removeFocusChangeListener (this);
  47849. }
  47850. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const
  47851. {
  47852. for (int i = 0; i < mappings.size(); ++i)
  47853. if (mappings.getUnchecked(i)->commandID == commandID)
  47854. return mappings.getUnchecked (i)->keypresses;
  47855. return Array <KeyPress> ();
  47856. }
  47857. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47858. const KeyPress& newKeyPress,
  47859. int insertIndex)
  47860. {
  47861. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47862. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47863. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47864. && ! newKeyPress.getModifiers().isShiftDown()));
  47865. if (findCommandForKeyPress (newKeyPress) != commandID)
  47866. {
  47867. removeKeyPress (newKeyPress);
  47868. if (newKeyPress.isValid())
  47869. {
  47870. for (int i = mappings.size(); --i >= 0;)
  47871. {
  47872. if (mappings.getUnchecked(i)->commandID == commandID)
  47873. {
  47874. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47875. sendChangeMessage (this);
  47876. return;
  47877. }
  47878. }
  47879. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47880. if (ci != 0)
  47881. {
  47882. CommandMapping* const cm = new CommandMapping();
  47883. cm->commandID = commandID;
  47884. cm->keypresses.add (newKeyPress);
  47885. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47886. mappings.add (cm);
  47887. sendChangeMessage (this);
  47888. }
  47889. }
  47890. }
  47891. }
  47892. void KeyPressMappingSet::resetToDefaultMappings()
  47893. {
  47894. mappings.clear();
  47895. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47896. {
  47897. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47898. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47899. {
  47900. addKeyPress (ci->commandID,
  47901. ci->defaultKeypresses.getReference (j));
  47902. }
  47903. }
  47904. sendChangeMessage (this);
  47905. }
  47906. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID)
  47907. {
  47908. clearAllKeyPresses (commandID);
  47909. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47910. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47911. {
  47912. addKeyPress (ci->commandID,
  47913. ci->defaultKeypresses.getReference (j));
  47914. }
  47915. }
  47916. void KeyPressMappingSet::clearAllKeyPresses()
  47917. {
  47918. if (mappings.size() > 0)
  47919. {
  47920. sendChangeMessage (this);
  47921. mappings.clear();
  47922. }
  47923. }
  47924. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID)
  47925. {
  47926. for (int i = mappings.size(); --i >= 0;)
  47927. {
  47928. if (mappings.getUnchecked(i)->commandID == commandID)
  47929. {
  47930. mappings.remove (i);
  47931. sendChangeMessage (this);
  47932. }
  47933. }
  47934. }
  47935. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress)
  47936. {
  47937. if (keypress.isValid())
  47938. {
  47939. for (int i = mappings.size(); --i >= 0;)
  47940. {
  47941. CommandMapping* const cm = mappings.getUnchecked(i);
  47942. for (int j = cm->keypresses.size(); --j >= 0;)
  47943. {
  47944. if (keypress == cm->keypresses [j])
  47945. {
  47946. cm->keypresses.remove (j);
  47947. sendChangeMessage (this);
  47948. }
  47949. }
  47950. }
  47951. }
  47952. }
  47953. void KeyPressMappingSet::removeKeyPress (const CommandID commandID, const int keyPressIndex)
  47954. {
  47955. for (int i = mappings.size(); --i >= 0;)
  47956. {
  47957. if (mappings.getUnchecked(i)->commandID == commandID)
  47958. {
  47959. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47960. sendChangeMessage (this);
  47961. break;
  47962. }
  47963. }
  47964. }
  47965. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47966. {
  47967. for (int i = 0; i < mappings.size(); ++i)
  47968. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47969. return mappings.getUnchecked(i)->commandID;
  47970. return 0;
  47971. }
  47972. bool KeyPressMappingSet::containsMapping (const CommandID commandID, const KeyPress& keyPress) const throw()
  47973. {
  47974. for (int i = mappings.size(); --i >= 0;)
  47975. if (mappings.getUnchecked(i)->commandID == commandID)
  47976. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47977. return false;
  47978. }
  47979. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47980. const KeyPress& key,
  47981. const bool isKeyDown,
  47982. const int millisecsSinceKeyPressed,
  47983. Component* const originatingComponent) const
  47984. {
  47985. ApplicationCommandTarget::InvocationInfo info (commandID);
  47986. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47987. info.isKeyDown = isKeyDown;
  47988. info.keyPress = key;
  47989. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47990. info.originatingComponent = originatingComponent;
  47991. commandManager->invoke (info, false);
  47992. }
  47993. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47994. {
  47995. if (xmlVersion.hasTagName ("KEYMAPPINGS"))
  47996. {
  47997. if (xmlVersion.getBoolAttribute ("basedOnDefaults", true))
  47998. {
  47999. // if the XML was created as a set of differences from the default mappings,
  48000. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48001. resetToDefaultMappings();
  48002. }
  48003. else
  48004. {
  48005. // if the XML was created calling createXml (false), then we need to clear all
  48006. // the keys and treat the xml as describing the entire set of mappings.
  48007. clearAllKeyPresses();
  48008. }
  48009. forEachXmlChildElement (xmlVersion, map)
  48010. {
  48011. const CommandID commandId = map->getStringAttribute ("commandId").getHexValue32();
  48012. if (commandId != 0)
  48013. {
  48014. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute ("key")));
  48015. if (map->hasTagName ("MAPPING"))
  48016. {
  48017. addKeyPress (commandId, key);
  48018. }
  48019. else if (map->hasTagName ("UNMAPPING"))
  48020. {
  48021. if (containsMapping (commandId, key))
  48022. removeKeyPress (key);
  48023. }
  48024. }
  48025. }
  48026. return true;
  48027. }
  48028. return false;
  48029. }
  48030. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48031. {
  48032. ScopedPointer <KeyPressMappingSet> defaultSet;
  48033. if (saveDifferencesFromDefaultSet)
  48034. {
  48035. defaultSet = new KeyPressMappingSet (commandManager);
  48036. defaultSet->resetToDefaultMappings();
  48037. }
  48038. XmlElement* const doc = new XmlElement ("KEYMAPPINGS");
  48039. doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
  48040. int i;
  48041. for (i = 0; i < mappings.size(); ++i)
  48042. {
  48043. const CommandMapping* const cm = mappings.getUnchecked(i);
  48044. for (int j = 0; j < cm->keypresses.size(); ++j)
  48045. {
  48046. if (defaultSet == 0
  48047. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48048. {
  48049. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48050. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  48051. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  48052. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  48053. }
  48054. }
  48055. }
  48056. if (defaultSet != 0)
  48057. {
  48058. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48059. {
  48060. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48061. for (int j = 0; j < cm->keypresses.size(); ++j)
  48062. {
  48063. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48064. {
  48065. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48066. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  48067. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  48068. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  48069. }
  48070. }
  48071. }
  48072. }
  48073. return doc;
  48074. }
  48075. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48076. Component* originatingComponent)
  48077. {
  48078. bool used = false;
  48079. const CommandID commandID = findCommandForKeyPress (key);
  48080. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48081. if (ci != 0
  48082. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48083. {
  48084. ApplicationCommandInfo info (0);
  48085. if (commandManager->getTargetForCommand (commandID, info) != 0
  48086. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48087. {
  48088. invokeCommand (commandID, key, true, 0, originatingComponent);
  48089. used = true;
  48090. }
  48091. else
  48092. {
  48093. if (originatingComponent != 0)
  48094. originatingComponent->getLookAndFeel().playAlertSound();
  48095. }
  48096. }
  48097. return used;
  48098. }
  48099. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48100. {
  48101. bool used = false;
  48102. const uint32 now = Time::getMillisecondCounter();
  48103. for (int i = mappings.size(); --i >= 0;)
  48104. {
  48105. CommandMapping* const cm = mappings.getUnchecked(i);
  48106. if (cm->wantsKeyUpDownCallbacks)
  48107. {
  48108. for (int j = cm->keypresses.size(); --j >= 0;)
  48109. {
  48110. const KeyPress key (cm->keypresses.getReference (j));
  48111. const bool isDown = key.isCurrentlyDown();
  48112. int keyPressEntryIndex = 0;
  48113. bool wasDown = false;
  48114. for (int k = keysDown.size(); --k >= 0;)
  48115. {
  48116. if (key == keysDown.getUnchecked(k)->key)
  48117. {
  48118. keyPressEntryIndex = k;
  48119. wasDown = true;
  48120. used = true;
  48121. break;
  48122. }
  48123. }
  48124. if (isDown != wasDown)
  48125. {
  48126. int millisecs = 0;
  48127. if (isDown)
  48128. {
  48129. KeyPressTime* const k = new KeyPressTime();
  48130. k->key = key;
  48131. k->timeWhenPressed = now;
  48132. keysDown.add (k);
  48133. }
  48134. else
  48135. {
  48136. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48137. if (now > pressTime)
  48138. millisecs = now - pressTime;
  48139. keysDown.remove (keyPressEntryIndex);
  48140. }
  48141. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48142. used = true;
  48143. }
  48144. }
  48145. }
  48146. }
  48147. return used;
  48148. }
  48149. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48150. {
  48151. if (focusedComponent != 0)
  48152. focusedComponent->keyStateChanged (false);
  48153. }
  48154. END_JUCE_NAMESPACE
  48155. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48156. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48157. BEGIN_JUCE_NAMESPACE
  48158. ModifierKeys::ModifierKeys (const int flags_) throw()
  48159. : flags (flags_)
  48160. {
  48161. }
  48162. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48163. : flags (other.flags)
  48164. {
  48165. }
  48166. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48167. {
  48168. flags = other.flags;
  48169. return *this;
  48170. }
  48171. ModifierKeys ModifierKeys::currentModifiers;
  48172. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48173. {
  48174. return currentModifiers;
  48175. }
  48176. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48177. {
  48178. int num = 0;
  48179. if (isLeftButtonDown()) ++num;
  48180. if (isRightButtonDown()) ++num;
  48181. if (isMiddleButtonDown()) ++num;
  48182. return num;
  48183. }
  48184. END_JUCE_NAMESPACE
  48185. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48186. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48187. BEGIN_JUCE_NAMESPACE
  48188. class ComponentAnimator::AnimationTask
  48189. {
  48190. public:
  48191. AnimationTask (Component* const comp)
  48192. : component (comp)
  48193. {
  48194. }
  48195. Component::SafePointer<Component> component;
  48196. Rectangle<int> destination;
  48197. int msElapsed, msTotal;
  48198. double startSpeed, midSpeed, endSpeed, lastProgress;
  48199. double left, top, right, bottom;
  48200. bool useTimeslice (const int elapsed)
  48201. {
  48202. if (component == 0)
  48203. return false;
  48204. msElapsed += elapsed;
  48205. double newProgress = msElapsed / (double) msTotal;
  48206. if (newProgress >= 0 && newProgress < 1.0)
  48207. {
  48208. newProgress = timeToDistance (newProgress);
  48209. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48210. jassert (newProgress >= lastProgress);
  48211. lastProgress = newProgress;
  48212. left += (destination.getX() - left) * delta;
  48213. top += (destination.getY() - top) * delta;
  48214. right += (destination.getRight() - right) * delta;
  48215. bottom += (destination.getBottom() - bottom) * delta;
  48216. if (delta < 1.0)
  48217. {
  48218. const Rectangle<int> newBounds (roundToInt (left),
  48219. roundToInt (top),
  48220. roundToInt (right - left),
  48221. roundToInt (bottom - top));
  48222. if (newBounds != destination)
  48223. {
  48224. component->setBounds (newBounds);
  48225. return true;
  48226. }
  48227. }
  48228. }
  48229. component->setBounds (destination);
  48230. return false;
  48231. }
  48232. void moveToFinalDestination()
  48233. {
  48234. if (component != 0)
  48235. component->setBounds (destination);
  48236. }
  48237. private:
  48238. inline double timeToDistance (const double time) const
  48239. {
  48240. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48241. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48242. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48243. }
  48244. };
  48245. ComponentAnimator::ComponentAnimator()
  48246. : lastTime (0)
  48247. {
  48248. }
  48249. ComponentAnimator::~ComponentAnimator()
  48250. {
  48251. cancelAllAnimations (false);
  48252. jassert (tasks.size() == 0);
  48253. }
  48254. ComponentAnimator::AnimationTask* ComponentAnimator::findTaskFor (Component* const component) const
  48255. {
  48256. for (int i = tasks.size(); --i >= 0;)
  48257. if (component == tasks.getUnchecked(i)->component.getComponent())
  48258. return tasks.getUnchecked(i);
  48259. return 0;
  48260. }
  48261. void ComponentAnimator::animateComponent (Component* const component,
  48262. const Rectangle<int>& finalPosition,
  48263. const int millisecondsToSpendMoving,
  48264. const double startSpeed,
  48265. const double endSpeed)
  48266. {
  48267. if (component != 0)
  48268. {
  48269. AnimationTask* at = findTaskFor (component);
  48270. if (at == 0)
  48271. {
  48272. at = new AnimationTask (component);
  48273. tasks.add (at);
  48274. sendChangeMessage (this);
  48275. }
  48276. at->msElapsed = 0;
  48277. at->lastProgress = 0;
  48278. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48279. at->destination = finalPosition;
  48280. // the speeds must be 0 or greater!
  48281. jassert (startSpeed >= 0 && endSpeed >= 0)
  48282. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48283. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48284. at->midSpeed = invTotalDistance;
  48285. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48286. at->left = component->getX();
  48287. at->top = component->getY();
  48288. at->right = component->getRight();
  48289. at->bottom = component->getBottom();
  48290. if (! isTimerRunning())
  48291. {
  48292. lastTime = Time::getMillisecondCounter();
  48293. startTimer (1000 / 50);
  48294. }
  48295. }
  48296. }
  48297. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48298. {
  48299. for (int i = tasks.size(); --i >= 0;)
  48300. {
  48301. AnimationTask* const at = tasks.getUnchecked(i);
  48302. if (moveComponentsToTheirFinalPositions)
  48303. at->moveToFinalDestination();
  48304. delete at;
  48305. tasks.remove (i);
  48306. sendChangeMessage (this);
  48307. }
  48308. }
  48309. void ComponentAnimator::cancelAnimation (Component* const component,
  48310. const bool moveComponentToItsFinalPosition)
  48311. {
  48312. AnimationTask* const at = findTaskFor (component);
  48313. if (at != 0)
  48314. {
  48315. if (moveComponentToItsFinalPosition)
  48316. at->moveToFinalDestination();
  48317. tasks.removeValue (at);
  48318. delete at;
  48319. sendChangeMessage (this);
  48320. }
  48321. }
  48322. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48323. {
  48324. AnimationTask* const at = findTaskFor (component);
  48325. if (at != 0)
  48326. return at->destination;
  48327. else if (component != 0)
  48328. return component->getBounds();
  48329. return Rectangle<int>();
  48330. }
  48331. bool ComponentAnimator::isAnimating (Component* component) const
  48332. {
  48333. return findTaskFor (component) != 0;
  48334. }
  48335. void ComponentAnimator::timerCallback()
  48336. {
  48337. const uint32 timeNow = Time::getMillisecondCounter();
  48338. if (lastTime == 0 || lastTime == timeNow)
  48339. lastTime = timeNow;
  48340. const int elapsed = timeNow - lastTime;
  48341. for (int i = tasks.size(); --i >= 0;)
  48342. {
  48343. AnimationTask* const at = tasks.getUnchecked(i);
  48344. if (! at->useTimeslice (elapsed))
  48345. {
  48346. tasks.remove (i);
  48347. delete at;
  48348. sendChangeMessage (this);
  48349. }
  48350. }
  48351. lastTime = timeNow;
  48352. if (tasks.size() == 0)
  48353. stopTimer();
  48354. }
  48355. END_JUCE_NAMESPACE
  48356. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48357. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48358. BEGIN_JUCE_NAMESPACE
  48359. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48360. : minW (0),
  48361. maxW (0x3fffffff),
  48362. minH (0),
  48363. maxH (0x3fffffff),
  48364. minOffTop (0),
  48365. minOffLeft (0),
  48366. minOffBottom (0),
  48367. minOffRight (0),
  48368. aspectRatio (0.0)
  48369. {
  48370. }
  48371. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48372. {
  48373. }
  48374. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48375. {
  48376. minW = minimumWidth;
  48377. }
  48378. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48379. {
  48380. maxW = maximumWidth;
  48381. }
  48382. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48383. {
  48384. minH = minimumHeight;
  48385. }
  48386. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48387. {
  48388. maxH = maximumHeight;
  48389. }
  48390. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48391. {
  48392. jassert (maxW >= minimumWidth);
  48393. jassert (maxH >= minimumHeight);
  48394. jassert (minimumWidth > 0 && minimumHeight > 0);
  48395. minW = minimumWidth;
  48396. minH = minimumHeight;
  48397. if (minW > maxW)
  48398. maxW = minW;
  48399. if (minH > maxH)
  48400. maxH = minH;
  48401. }
  48402. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48403. {
  48404. jassert (maximumWidth >= minW);
  48405. jassert (maximumHeight >= minH);
  48406. jassert (maximumWidth > 0 && maximumHeight > 0);
  48407. maxW = jmax (minW, maximumWidth);
  48408. maxH = jmax (minH, maximumHeight);
  48409. }
  48410. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48411. const int minimumHeight,
  48412. const int maximumWidth,
  48413. const int maximumHeight) throw()
  48414. {
  48415. jassert (maximumWidth >= minimumWidth);
  48416. jassert (maximumHeight >= minimumHeight);
  48417. jassert (maximumWidth > 0 && maximumHeight > 0);
  48418. jassert (minimumWidth > 0 && minimumHeight > 0);
  48419. minW = jmax (0, minimumWidth);
  48420. minH = jmax (0, minimumHeight);
  48421. maxW = jmax (minW, maximumWidth);
  48422. maxH = jmax (minH, maximumHeight);
  48423. }
  48424. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48425. const int minimumWhenOffTheLeft,
  48426. const int minimumWhenOffTheBottom,
  48427. const int minimumWhenOffTheRight) throw()
  48428. {
  48429. minOffTop = minimumWhenOffTheTop;
  48430. minOffLeft = minimumWhenOffTheLeft;
  48431. minOffBottom = minimumWhenOffTheBottom;
  48432. minOffRight = minimumWhenOffTheRight;
  48433. }
  48434. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48435. {
  48436. aspectRatio = jmax (0.0, widthOverHeight);
  48437. }
  48438. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48439. {
  48440. return aspectRatio;
  48441. }
  48442. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48443. const Rectangle<int>& targetBounds,
  48444. const bool isStretchingTop,
  48445. const bool isStretchingLeft,
  48446. const bool isStretchingBottom,
  48447. const bool isStretchingRight)
  48448. {
  48449. jassert (component != 0);
  48450. Rectangle<int> limits, bounds (targetBounds);
  48451. BorderSize border;
  48452. Component* const parent = component->getParentComponent();
  48453. if (parent == 0)
  48454. {
  48455. ComponentPeer* peer = component->getPeer();
  48456. if (peer != 0)
  48457. border = peer->getFrameSize();
  48458. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48459. }
  48460. else
  48461. {
  48462. limits.setSize (parent->getWidth(), parent->getHeight());
  48463. }
  48464. border.addTo (bounds);
  48465. checkBounds (bounds,
  48466. border.addedTo (component->getBounds()), limits,
  48467. isStretchingTop, isStretchingLeft,
  48468. isStretchingBottom, isStretchingRight);
  48469. border.subtractFrom (bounds);
  48470. applyBoundsToComponent (component, bounds);
  48471. }
  48472. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48473. {
  48474. setBoundsForComponent (component, component->getBounds(),
  48475. false, false, false, false);
  48476. }
  48477. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48478. const Rectangle<int>& bounds)
  48479. {
  48480. component->setBounds (bounds);
  48481. }
  48482. void ComponentBoundsConstrainer::resizeStart()
  48483. {
  48484. }
  48485. void ComponentBoundsConstrainer::resizeEnd()
  48486. {
  48487. }
  48488. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48489. const Rectangle<int>& old,
  48490. const Rectangle<int>& limits,
  48491. const bool isStretchingTop,
  48492. const bool isStretchingLeft,
  48493. const bool isStretchingBottom,
  48494. const bool isStretchingRight)
  48495. {
  48496. int x = bounds.getX();
  48497. int y = bounds.getY();
  48498. int w = bounds.getWidth();
  48499. int h = bounds.getHeight();
  48500. // constrain the size if it's being stretched..
  48501. if (isStretchingLeft)
  48502. {
  48503. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48504. w = old.getRight() - x;
  48505. }
  48506. if (isStretchingRight)
  48507. {
  48508. w = jlimit (minW, maxW, w);
  48509. }
  48510. if (isStretchingTop)
  48511. {
  48512. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48513. h = old.getBottom() - y;
  48514. }
  48515. if (isStretchingBottom)
  48516. {
  48517. h = jlimit (minH, maxH, h);
  48518. }
  48519. // constrain the aspect ratio if one has been specified..
  48520. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48521. {
  48522. bool adjustWidth;
  48523. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48524. {
  48525. adjustWidth = true;
  48526. }
  48527. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48528. {
  48529. adjustWidth = false;
  48530. }
  48531. else
  48532. {
  48533. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48534. const double newRatio = fabs (w / (double) h);
  48535. adjustWidth = (oldRatio > newRatio);
  48536. }
  48537. if (adjustWidth)
  48538. {
  48539. w = roundToInt (h * aspectRatio);
  48540. if (w > maxW || w < minW)
  48541. {
  48542. w = jlimit (minW, maxW, w);
  48543. h = roundToInt (w / aspectRatio);
  48544. }
  48545. }
  48546. else
  48547. {
  48548. h = roundToInt (w / aspectRatio);
  48549. if (h > maxH || h < minH)
  48550. {
  48551. h = jlimit (minH, maxH, h);
  48552. w = roundToInt (h * aspectRatio);
  48553. }
  48554. }
  48555. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48556. {
  48557. x = old.getX() + (old.getWidth() - w) / 2;
  48558. }
  48559. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48560. {
  48561. y = old.getY() + (old.getHeight() - h) / 2;
  48562. }
  48563. else
  48564. {
  48565. if (isStretchingLeft)
  48566. x = old.getRight() - w;
  48567. if (isStretchingTop)
  48568. y = old.getBottom() - h;
  48569. }
  48570. }
  48571. // ...and constrain the position if limits have been set for that.
  48572. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48573. {
  48574. if (minOffTop > 0)
  48575. {
  48576. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48577. if (y < limit)
  48578. {
  48579. if (isStretchingTop)
  48580. h -= (limit - y);
  48581. y = limit;
  48582. }
  48583. }
  48584. if (minOffLeft > 0)
  48585. {
  48586. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48587. if (x < limit)
  48588. {
  48589. if (isStretchingLeft)
  48590. w -= (limit - x);
  48591. x = limit;
  48592. }
  48593. }
  48594. if (minOffBottom > 0)
  48595. {
  48596. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48597. if (y > limit)
  48598. {
  48599. if (isStretchingBottom)
  48600. h += (limit - y);
  48601. else
  48602. y = limit;
  48603. }
  48604. }
  48605. if (minOffRight > 0)
  48606. {
  48607. const int limit = limits.getRight() - jmin (minOffRight, w);
  48608. if (x > limit)
  48609. {
  48610. if (isStretchingRight)
  48611. w += (limit - x);
  48612. else
  48613. x = limit;
  48614. }
  48615. }
  48616. }
  48617. jassert (w >= 0 && h >= 0);
  48618. bounds = Rectangle<int> (x, y, w, h);
  48619. }
  48620. END_JUCE_NAMESPACE
  48621. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48622. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48623. BEGIN_JUCE_NAMESPACE
  48624. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48625. : component (component_),
  48626. lastPeer (0),
  48627. reentrant (false)
  48628. {
  48629. jassert (component != 0); // can't use this with a null pointer..
  48630. component->addComponentListener (this);
  48631. registerWithParentComps();
  48632. }
  48633. ComponentMovementWatcher::~ComponentMovementWatcher()
  48634. {
  48635. component->removeComponentListener (this);
  48636. unregister();
  48637. }
  48638. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48639. {
  48640. // agh! don't delete the target component without deleting this object first!
  48641. jassert (component != 0);
  48642. if (! reentrant)
  48643. {
  48644. reentrant = true;
  48645. ComponentPeer* const peer = component->getPeer();
  48646. if (peer != lastPeer)
  48647. {
  48648. componentPeerChanged();
  48649. if (component == 0)
  48650. return;
  48651. lastPeer = peer;
  48652. }
  48653. unregister();
  48654. registerWithParentComps();
  48655. reentrant = false;
  48656. componentMovedOrResized (*component, true, true);
  48657. }
  48658. }
  48659. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48660. {
  48661. // agh! don't delete the target component without deleting this object first!
  48662. jassert (component != 0);
  48663. if (wasMoved)
  48664. {
  48665. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48666. wasMoved = lastBounds.getPosition() != pos;
  48667. lastBounds.setPosition (pos);
  48668. }
  48669. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48670. lastBounds.setSize (component->getWidth(), component->getHeight());
  48671. if (wasMoved || wasResized)
  48672. componentMovedOrResized (wasMoved, wasResized);
  48673. }
  48674. void ComponentMovementWatcher::registerWithParentComps() throw()
  48675. {
  48676. Component* p = component->getParentComponent();
  48677. while (p != 0)
  48678. {
  48679. p->addComponentListener (this);
  48680. registeredParentComps.add (p);
  48681. p = p->getParentComponent();
  48682. }
  48683. }
  48684. void ComponentMovementWatcher::unregister() throw()
  48685. {
  48686. for (int i = registeredParentComps.size(); --i >= 0;)
  48687. static_cast <Component*> (registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48688. registeredParentComps.clear();
  48689. }
  48690. END_JUCE_NAMESPACE
  48691. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48692. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48693. BEGIN_JUCE_NAMESPACE
  48694. GroupComponent::GroupComponent (const String& componentName,
  48695. const String& labelText)
  48696. : Component (componentName),
  48697. text (labelText),
  48698. justification (Justification::left)
  48699. {
  48700. setInterceptsMouseClicks (false, true);
  48701. }
  48702. GroupComponent::~GroupComponent()
  48703. {
  48704. }
  48705. void GroupComponent::setText (const String& newText)
  48706. {
  48707. if (text != newText)
  48708. {
  48709. text = newText;
  48710. repaint();
  48711. }
  48712. }
  48713. const String GroupComponent::getText() const
  48714. {
  48715. return text;
  48716. }
  48717. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48718. {
  48719. if (justification.getFlags() != newJustification.getFlags())
  48720. {
  48721. justification = newJustification;
  48722. repaint();
  48723. }
  48724. }
  48725. void GroupComponent::paint (Graphics& g)
  48726. {
  48727. getLookAndFeel()
  48728. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48729. text, justification,
  48730. *this);
  48731. }
  48732. void GroupComponent::enablementChanged()
  48733. {
  48734. repaint();
  48735. }
  48736. void GroupComponent::colourChanged()
  48737. {
  48738. repaint();
  48739. }
  48740. END_JUCE_NAMESPACE
  48741. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48742. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48743. BEGIN_JUCE_NAMESPACE
  48744. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48745. : DocumentWindow (String::empty, backgroundColour,
  48746. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48747. {
  48748. }
  48749. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48750. {
  48751. }
  48752. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48753. {
  48754. MultiDocumentPanel* const owner = getOwner();
  48755. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48756. if (owner != 0)
  48757. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48758. }
  48759. void MultiDocumentPanelWindow::closeButtonPressed()
  48760. {
  48761. MultiDocumentPanel* const owner = getOwner();
  48762. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48763. if (owner != 0)
  48764. owner->closeDocument (getContentComponent(), true);
  48765. }
  48766. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48767. {
  48768. DocumentWindow::activeWindowStatusChanged();
  48769. updateOrder();
  48770. }
  48771. void MultiDocumentPanelWindow::broughtToFront()
  48772. {
  48773. DocumentWindow::broughtToFront();
  48774. updateOrder();
  48775. }
  48776. void MultiDocumentPanelWindow::updateOrder()
  48777. {
  48778. MultiDocumentPanel* const owner = getOwner();
  48779. if (owner != 0)
  48780. owner->updateOrder();
  48781. }
  48782. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48783. {
  48784. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48785. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48786. }
  48787. class MDITabbedComponentInternal : public TabbedComponent
  48788. {
  48789. public:
  48790. MDITabbedComponentInternal()
  48791. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48792. {
  48793. }
  48794. ~MDITabbedComponentInternal()
  48795. {
  48796. }
  48797. void currentTabChanged (int, const String&)
  48798. {
  48799. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48800. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48801. if (owner != 0)
  48802. owner->updateOrder();
  48803. }
  48804. };
  48805. MultiDocumentPanel::MultiDocumentPanel()
  48806. : mode (MaximisedWindowsWithTabs),
  48807. tabComponent (0),
  48808. backgroundColour (Colours::lightblue),
  48809. maximumNumDocuments (0),
  48810. numDocsBeforeTabsUsed (0)
  48811. {
  48812. setOpaque (true);
  48813. }
  48814. MultiDocumentPanel::~MultiDocumentPanel()
  48815. {
  48816. closeAllDocuments (false);
  48817. }
  48818. static bool shouldDeleteComp (Component* const c)
  48819. {
  48820. return c->getProperties() ["mdiDocumentDelete_"];
  48821. }
  48822. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48823. {
  48824. while (components.size() > 0)
  48825. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48826. return false;
  48827. return true;
  48828. }
  48829. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48830. {
  48831. return new MultiDocumentPanelWindow (backgroundColour);
  48832. }
  48833. void MultiDocumentPanel::addWindow (Component* component)
  48834. {
  48835. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48836. dw->setResizable (true, false);
  48837. dw->setContentComponent (component, false, true);
  48838. dw->setName (component->getName());
  48839. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48840. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48841. int x = 4;
  48842. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48843. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48844. x += 16;
  48845. dw->setTopLeftPosition (x, x);
  48846. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48847. if (pos.toString().isNotEmpty())
  48848. dw->restoreWindowStateFromString (pos.toString());
  48849. addAndMakeVisible (dw);
  48850. dw->toFront (true);
  48851. }
  48852. bool MultiDocumentPanel::addDocument (Component* const component,
  48853. const Colour& docColour,
  48854. const bool deleteWhenRemoved)
  48855. {
  48856. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48857. // with a frame-within-a-frame! Just pass in the bare content component.
  48858. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48859. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48860. return false;
  48861. components.add (component);
  48862. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48863. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48864. component->addComponentListener (this);
  48865. if (mode == FloatingWindows)
  48866. {
  48867. if (isFullscreenWhenOneDocument())
  48868. {
  48869. if (components.size() == 1)
  48870. {
  48871. addAndMakeVisible (component);
  48872. }
  48873. else
  48874. {
  48875. if (components.size() == 2)
  48876. addWindow (components.getFirst());
  48877. addWindow (component);
  48878. }
  48879. }
  48880. else
  48881. {
  48882. addWindow (component);
  48883. }
  48884. }
  48885. else
  48886. {
  48887. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48888. {
  48889. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48890. Array <Component*> temp (components);
  48891. for (int i = 0; i < temp.size(); ++i)
  48892. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48893. resized();
  48894. }
  48895. else
  48896. {
  48897. if (tabComponent != 0)
  48898. tabComponent->addTab (component->getName(), docColour, component, false);
  48899. else
  48900. addAndMakeVisible (component);
  48901. }
  48902. setActiveDocument (component);
  48903. }
  48904. resized();
  48905. activeDocumentChanged();
  48906. return true;
  48907. }
  48908. bool MultiDocumentPanel::closeDocument (Component* component,
  48909. const bool checkItsOkToCloseFirst)
  48910. {
  48911. if (components.contains (component))
  48912. {
  48913. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48914. return false;
  48915. component->removeComponentListener (this);
  48916. const bool shouldDelete = shouldDeleteComp (component);
  48917. component->getProperties().remove ("mdiDocumentDelete_");
  48918. component->getProperties().remove ("mdiDocumentBkg_");
  48919. if (mode == FloatingWindows)
  48920. {
  48921. for (int i = getNumChildComponents(); --i >= 0;)
  48922. {
  48923. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48924. if (dw != 0 && dw->getContentComponent() == component)
  48925. {
  48926. dw->setContentComponent (0, false);
  48927. delete dw;
  48928. break;
  48929. }
  48930. }
  48931. if (shouldDelete)
  48932. delete component;
  48933. components.removeValue (component);
  48934. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48935. {
  48936. for (int i = getNumChildComponents(); --i >= 0;)
  48937. {
  48938. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48939. if (dw != 0)
  48940. {
  48941. dw->setContentComponent (0, false);
  48942. delete dw;
  48943. }
  48944. }
  48945. addAndMakeVisible (components.getFirst());
  48946. }
  48947. }
  48948. else
  48949. {
  48950. jassert (components.indexOf (component) >= 0);
  48951. if (tabComponent != 0)
  48952. {
  48953. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48954. if (tabComponent->getTabContentComponent (i) == component)
  48955. tabComponent->removeTab (i);
  48956. }
  48957. else
  48958. {
  48959. removeChildComponent (component);
  48960. }
  48961. if (shouldDelete)
  48962. delete component;
  48963. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48964. deleteAndZero (tabComponent);
  48965. components.removeValue (component);
  48966. if (components.size() > 0 && tabComponent == 0)
  48967. addAndMakeVisible (components.getFirst());
  48968. }
  48969. resized();
  48970. activeDocumentChanged();
  48971. }
  48972. else
  48973. {
  48974. jassertfalse
  48975. }
  48976. return true;
  48977. }
  48978. int MultiDocumentPanel::getNumDocuments() const throw()
  48979. {
  48980. return components.size();
  48981. }
  48982. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48983. {
  48984. return components [index];
  48985. }
  48986. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48987. {
  48988. if (mode == FloatingWindows)
  48989. {
  48990. for (int i = getNumChildComponents(); --i >= 0;)
  48991. {
  48992. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48993. if (dw != 0 && dw->isActiveWindow())
  48994. return dw->getContentComponent();
  48995. }
  48996. }
  48997. return components.getLast();
  48998. }
  48999. void MultiDocumentPanel::setActiveDocument (Component* component)
  49000. {
  49001. if (mode == FloatingWindows)
  49002. {
  49003. component = getContainerComp (component);
  49004. if (component != 0)
  49005. component->toFront (true);
  49006. }
  49007. else if (tabComponent != 0)
  49008. {
  49009. jassert (components.indexOf (component) >= 0);
  49010. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49011. {
  49012. if (tabComponent->getTabContentComponent (i) == component)
  49013. {
  49014. tabComponent->setCurrentTabIndex (i);
  49015. break;
  49016. }
  49017. }
  49018. }
  49019. else
  49020. {
  49021. component->grabKeyboardFocus();
  49022. }
  49023. }
  49024. void MultiDocumentPanel::activeDocumentChanged()
  49025. {
  49026. }
  49027. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49028. {
  49029. maximumNumDocuments = newNumber;
  49030. }
  49031. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49032. {
  49033. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49034. }
  49035. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49036. {
  49037. return numDocsBeforeTabsUsed != 0;
  49038. }
  49039. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49040. {
  49041. if (mode != newLayoutMode)
  49042. {
  49043. mode = newLayoutMode;
  49044. if (mode == FloatingWindows)
  49045. {
  49046. deleteAndZero (tabComponent);
  49047. }
  49048. else
  49049. {
  49050. for (int i = getNumChildComponents(); --i >= 0;)
  49051. {
  49052. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49053. if (dw != 0)
  49054. {
  49055. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49056. dw->setContentComponent (0, false);
  49057. delete dw;
  49058. }
  49059. }
  49060. }
  49061. resized();
  49062. const Array <Component*> tempComps (components);
  49063. components.clear();
  49064. for (int i = 0; i < tempComps.size(); ++i)
  49065. {
  49066. Component* const c = tempComps.getUnchecked(i);
  49067. addDocument (c,
  49068. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49069. shouldDeleteComp (c));
  49070. }
  49071. }
  49072. }
  49073. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49074. {
  49075. if (backgroundColour != newBackgroundColour)
  49076. {
  49077. backgroundColour = newBackgroundColour;
  49078. setOpaque (newBackgroundColour.isOpaque());
  49079. repaint();
  49080. }
  49081. }
  49082. void MultiDocumentPanel::paint (Graphics& g)
  49083. {
  49084. g.fillAll (backgroundColour);
  49085. }
  49086. void MultiDocumentPanel::resized()
  49087. {
  49088. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49089. {
  49090. for (int i = getNumChildComponents(); --i >= 0;)
  49091. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49092. }
  49093. setWantsKeyboardFocus (components.size() == 0);
  49094. }
  49095. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49096. {
  49097. if (mode == FloatingWindows)
  49098. {
  49099. for (int i = 0; i < getNumChildComponents(); ++i)
  49100. {
  49101. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49102. if (dw != 0 && dw->getContentComponent() == c)
  49103. {
  49104. c = dw;
  49105. break;
  49106. }
  49107. }
  49108. }
  49109. return c;
  49110. }
  49111. void MultiDocumentPanel::componentNameChanged (Component&)
  49112. {
  49113. if (mode == FloatingWindows)
  49114. {
  49115. for (int i = 0; i < getNumChildComponents(); ++i)
  49116. {
  49117. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49118. if (dw != 0)
  49119. dw->setName (dw->getContentComponent()->getName());
  49120. }
  49121. }
  49122. else if (tabComponent != 0)
  49123. {
  49124. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49125. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49126. }
  49127. }
  49128. void MultiDocumentPanel::updateOrder()
  49129. {
  49130. const Array <Component*> oldList (components);
  49131. if (mode == FloatingWindows)
  49132. {
  49133. components.clear();
  49134. for (int i = 0; i < getNumChildComponents(); ++i)
  49135. {
  49136. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49137. if (dw != 0)
  49138. components.add (dw->getContentComponent());
  49139. }
  49140. }
  49141. else
  49142. {
  49143. if (tabComponent != 0)
  49144. {
  49145. Component* const current = tabComponent->getCurrentContentComponent();
  49146. if (current != 0)
  49147. {
  49148. components.removeValue (current);
  49149. components.add (current);
  49150. }
  49151. }
  49152. }
  49153. if (components != oldList)
  49154. activeDocumentChanged();
  49155. }
  49156. END_JUCE_NAMESPACE
  49157. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49158. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49159. BEGIN_JUCE_NAMESPACE
  49160. ResizableBorderComponent::Zone::Zone (int zoneFlags) throw()
  49161. : zone (zoneFlags)
  49162. {
  49163. }
  49164. ResizableBorderComponent::Zone::Zone (const ResizableBorderComponent::Zone& other) throw() : zone (other.zone) {}
  49165. ResizableBorderComponent::Zone& ResizableBorderComponent::Zone::operator= (const ResizableBorderComponent::Zone& other) throw() { zone = other.zone; return *this; }
  49166. bool ResizableBorderComponent::Zone::operator== (const ResizableBorderComponent::Zone& other) const throw() { return zone == other.zone; }
  49167. bool ResizableBorderComponent::Zone::operator!= (const ResizableBorderComponent::Zone& other) const throw() { return zone != other.zone; }
  49168. const ResizableBorderComponent::Zone ResizableBorderComponent::Zone::fromPositionOnBorder (const Rectangle<int>& totalSize,
  49169. const BorderSize& border,
  49170. const Point<int>& position)
  49171. {
  49172. int z = 0;
  49173. if (totalSize.contains (position)
  49174. && ! border.subtractedFrom (totalSize).contains (position))
  49175. {
  49176. const int minW = jmax (totalSize.getWidth() / 10, jmin (10, totalSize.getWidth() / 3));
  49177. if (position.getX() < jmax (border.getLeft(), minW))
  49178. z |= left;
  49179. else if (position.getX() >= totalSize.getWidth() - jmax (border.getRight(), minW))
  49180. z |= right;
  49181. const int minH = jmax (totalSize.getHeight() / 10, jmin (10, totalSize.getHeight() / 3));
  49182. if (position.getY() < jmax (border.getTop(), minH))
  49183. z |= top;
  49184. else if (position.getY() >= totalSize.getHeight() - jmax (border.getBottom(), minH))
  49185. z |= bottom;
  49186. }
  49187. return Zone (z);
  49188. }
  49189. const MouseCursor ResizableBorderComponent::Zone::getMouseCursor() const throw()
  49190. {
  49191. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49192. switch (zone)
  49193. {
  49194. case (left | top): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49195. case top: mc = MouseCursor::TopEdgeResizeCursor; break;
  49196. case (right | top): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49197. case left: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49198. case right: mc = MouseCursor::RightEdgeResizeCursor; break;
  49199. case (left | bottom): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49200. case bottom: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49201. case (right | bottom): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49202. default: break;
  49203. }
  49204. return mc;
  49205. }
  49206. const Rectangle<int> ResizableBorderComponent::Zone::resizeRectangleBy (Rectangle<int> b, const Point<int>& offset) const throw()
  49207. {
  49208. if (isDraggingWholeObject())
  49209. return b + offset;
  49210. if (isDraggingLeftEdge())
  49211. b.setLeft (b.getX() + offset.getX());
  49212. if (isDraggingRightEdge())
  49213. b.setWidth (jmax (0, b.getWidth() + offset.getX()));
  49214. if (isDraggingTopEdge())
  49215. b.setTop (b.getY() + offset.getY());
  49216. if (isDraggingBottomEdge())
  49217. b.setHeight (jmax (0, b.getHeight() + offset.getY()));
  49218. return b;
  49219. }
  49220. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49221. ComponentBoundsConstrainer* const constrainer_)
  49222. : component (componentToResize),
  49223. constrainer (constrainer_),
  49224. borderSize (5),
  49225. mouseZone (0)
  49226. {
  49227. }
  49228. ResizableBorderComponent::~ResizableBorderComponent()
  49229. {
  49230. }
  49231. void ResizableBorderComponent::paint (Graphics& g)
  49232. {
  49233. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49234. }
  49235. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49236. {
  49237. updateMouseZone (e);
  49238. }
  49239. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49240. {
  49241. updateMouseZone (e);
  49242. }
  49243. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49244. {
  49245. if (component == 0)
  49246. {
  49247. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49248. return;
  49249. }
  49250. updateMouseZone (e);
  49251. originalBounds = component->getBounds();
  49252. if (constrainer != 0)
  49253. constrainer->resizeStart();
  49254. }
  49255. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49256. {
  49257. if (component == 0)
  49258. {
  49259. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49260. return;
  49261. }
  49262. const Rectangle<int> bounds (mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart()));
  49263. if (constrainer != 0)
  49264. constrainer->setBoundsForComponent (component, bounds,
  49265. mouseZone.isDraggingTopEdge(),
  49266. mouseZone.isDraggingLeftEdge(),
  49267. mouseZone.isDraggingBottomEdge(),
  49268. mouseZone.isDraggingRightEdge());
  49269. else
  49270. component->setBounds (bounds);
  49271. }
  49272. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49273. {
  49274. if (constrainer != 0)
  49275. constrainer->resizeEnd();
  49276. }
  49277. bool ResizableBorderComponent::hitTest (int x, int y)
  49278. {
  49279. return x < borderSize.getLeft()
  49280. || x >= getWidth() - borderSize.getRight()
  49281. || y < borderSize.getTop()
  49282. || y >= getHeight() - borderSize.getBottom();
  49283. }
  49284. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49285. {
  49286. if (borderSize != newBorderSize)
  49287. {
  49288. borderSize = newBorderSize;
  49289. repaint();
  49290. }
  49291. }
  49292. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49293. {
  49294. return borderSize;
  49295. }
  49296. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49297. {
  49298. Zone newZone (Zone::fromPositionOnBorder (getLocalBounds(), borderSize, e.getPosition()));
  49299. if (mouseZone != newZone)
  49300. {
  49301. mouseZone = newZone;
  49302. setMouseCursor (newZone.getMouseCursor());
  49303. }
  49304. }
  49305. END_JUCE_NAMESPACE
  49306. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49307. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49308. BEGIN_JUCE_NAMESPACE
  49309. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49310. ComponentBoundsConstrainer* const constrainer_)
  49311. : component (componentToResize),
  49312. constrainer (constrainer_)
  49313. {
  49314. setRepaintsOnMouseActivity (true);
  49315. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49316. }
  49317. ResizableCornerComponent::~ResizableCornerComponent()
  49318. {
  49319. }
  49320. void ResizableCornerComponent::paint (Graphics& g)
  49321. {
  49322. getLookAndFeel()
  49323. .drawCornerResizer (g, getWidth(), getHeight(),
  49324. isMouseOverOrDragging(),
  49325. isMouseButtonDown());
  49326. }
  49327. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49328. {
  49329. if (component == 0)
  49330. {
  49331. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49332. return;
  49333. }
  49334. originalBounds = component->getBounds();
  49335. if (constrainer != 0)
  49336. constrainer->resizeStart();
  49337. }
  49338. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49339. {
  49340. if (component == 0)
  49341. {
  49342. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49343. return;
  49344. }
  49345. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49346. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49347. if (constrainer != 0)
  49348. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49349. else
  49350. component->setBounds (r);
  49351. }
  49352. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49353. {
  49354. if (constrainer != 0)
  49355. constrainer->resizeStart();
  49356. }
  49357. bool ResizableCornerComponent::hitTest (int x, int y)
  49358. {
  49359. if (getWidth() <= 0)
  49360. return false;
  49361. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49362. return y >= yAtX - getHeight() / 4;
  49363. }
  49364. END_JUCE_NAMESPACE
  49365. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49366. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49367. BEGIN_JUCE_NAMESPACE
  49368. class ScrollBar::ScrollbarButton : public Button
  49369. {
  49370. public:
  49371. int direction;
  49372. ScrollbarButton (const int direction_, ScrollBar& owner_)
  49373. : Button (String::empty),
  49374. direction (direction_),
  49375. owner (owner_)
  49376. {
  49377. setWantsKeyboardFocus (false);
  49378. }
  49379. ~ScrollbarButton()
  49380. {
  49381. }
  49382. void paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  49383. {
  49384. getLookAndFeel()
  49385. .drawScrollbarButton (g, owner,
  49386. getWidth(), getHeight(),
  49387. direction,
  49388. owner.isVertical(),
  49389. isMouseOver, isMouseDown);
  49390. }
  49391. void clicked()
  49392. {
  49393. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49394. }
  49395. juce_UseDebuggingNewOperator
  49396. private:
  49397. ScrollBar& owner;
  49398. ScrollbarButton (const ScrollbarButton&);
  49399. ScrollbarButton& operator= (const ScrollbarButton&);
  49400. };
  49401. ScrollBar::ScrollBar (const bool vertical_,
  49402. const bool buttonsAreVisible)
  49403. : totalRange (0.0, 1.0),
  49404. visibleRange (0.0, 0.1),
  49405. singleStepSize (0.1),
  49406. thumbAreaStart (0),
  49407. thumbAreaSize (0),
  49408. thumbStart (0),
  49409. thumbSize (0),
  49410. initialDelayInMillisecs (100),
  49411. repeatDelayInMillisecs (50),
  49412. minimumDelayInMillisecs (10),
  49413. vertical (vertical_),
  49414. isDraggingThumb (false),
  49415. alwaysVisible (false),
  49416. upButton (0),
  49417. downButton (0)
  49418. {
  49419. setButtonVisibility (buttonsAreVisible);
  49420. setRepaintsOnMouseActivity (true);
  49421. setFocusContainer (true);
  49422. }
  49423. ScrollBar::~ScrollBar()
  49424. {
  49425. deleteAllChildren();
  49426. }
  49427. void ScrollBar::setRangeLimits (const Range<double>& newRangeLimit)
  49428. {
  49429. if (totalRange != newRangeLimit)
  49430. {
  49431. totalRange = newRangeLimit;
  49432. setCurrentRange (visibleRange);
  49433. updateThumbPosition();
  49434. }
  49435. }
  49436. void ScrollBar::setRangeLimits (const double newMinimum, const double newMaximum)
  49437. {
  49438. jassert (newMaximum >= newMinimum); // these can't be the wrong way round!
  49439. setRangeLimits (Range<double> (newMinimum, newMaximum));
  49440. }
  49441. void ScrollBar::setCurrentRange (const Range<double>& newRange)
  49442. {
  49443. const Range<double> constrainedRange (totalRange.constrainRange (newRange));
  49444. if (visibleRange != constrainedRange)
  49445. {
  49446. visibleRange = constrainedRange;
  49447. updateThumbPosition();
  49448. triggerAsyncUpdate();
  49449. }
  49450. }
  49451. void ScrollBar::setCurrentRange (const double newStart, const double newSize)
  49452. {
  49453. setCurrentRange (Range<double> (newStart, newStart + newSize));
  49454. }
  49455. void ScrollBar::setCurrentRangeStart (const double newStart)
  49456. {
  49457. setCurrentRange (visibleRange.movedToStartAt (newStart));
  49458. }
  49459. void ScrollBar::setSingleStepSize (const double newSingleStepSize)
  49460. {
  49461. singleStepSize = newSingleStepSize;
  49462. }
  49463. void ScrollBar::moveScrollbarInSteps (const int howManySteps)
  49464. {
  49465. setCurrentRange (visibleRange + howManySteps * singleStepSize);
  49466. }
  49467. void ScrollBar::moveScrollbarInPages (const int howManyPages)
  49468. {
  49469. setCurrentRange (visibleRange + howManyPages * visibleRange.getLength());
  49470. }
  49471. void ScrollBar::scrollToTop()
  49472. {
  49473. setCurrentRange (visibleRange.movedToStartAt (getMinimumRangeLimit()));
  49474. }
  49475. void ScrollBar::scrollToBottom()
  49476. {
  49477. setCurrentRange (visibleRange.movedToEndAt (getMaximumRangeLimit()));
  49478. }
  49479. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49480. const int repeatDelayInMillisecs_,
  49481. const int minimumDelayInMillisecs_)
  49482. {
  49483. initialDelayInMillisecs = initialDelayInMillisecs_;
  49484. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49485. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49486. if (upButton != 0)
  49487. {
  49488. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49489. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49490. }
  49491. }
  49492. void ScrollBar::addListener (ScrollBarListener* const listener)
  49493. {
  49494. listeners.add (listener);
  49495. }
  49496. void ScrollBar::removeListener (ScrollBarListener* const listener)
  49497. {
  49498. listeners.remove (listener);
  49499. }
  49500. void ScrollBar::handleAsyncUpdate()
  49501. {
  49502. double start = visibleRange.getStart(); // (need to use a temp variable for VC7 compatibility)
  49503. listeners.call (&ScrollBarListener::scrollBarMoved, this, start);
  49504. }
  49505. void ScrollBar::updateThumbPosition()
  49506. {
  49507. int newThumbSize = roundToInt (totalRange.getLength() > 0 ? (visibleRange.getLength() * thumbAreaSize) / totalRange.getLength()
  49508. : thumbAreaSize);
  49509. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49510. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49511. if (newThumbSize > thumbAreaSize)
  49512. newThumbSize = thumbAreaSize;
  49513. int newThumbStart = thumbAreaStart;
  49514. if (totalRange.getLength() > visibleRange.getLength())
  49515. newThumbStart += roundToInt (((visibleRange.getStart() - totalRange.getStart()) * (thumbAreaSize - newThumbSize))
  49516. / (totalRange.getLength() - visibleRange.getLength()));
  49517. setVisible (alwaysVisible || (totalRange.getLength() > visibleRange.getLength() && visibleRange.getLength() > 0.0));
  49518. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49519. {
  49520. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49521. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49522. if (vertical)
  49523. repaint (0, repaintStart, getWidth(), repaintSize);
  49524. else
  49525. repaint (repaintStart, 0, repaintSize, getHeight());
  49526. thumbStart = newThumbStart;
  49527. thumbSize = newThumbSize;
  49528. }
  49529. }
  49530. void ScrollBar::setOrientation (const bool shouldBeVertical)
  49531. {
  49532. if (vertical != shouldBeVertical)
  49533. {
  49534. vertical = shouldBeVertical;
  49535. if (upButton != 0)
  49536. {
  49537. upButton->direction = vertical ? 0 : 3;
  49538. downButton->direction = vertical ? 2 : 1;
  49539. }
  49540. updateThumbPosition();
  49541. }
  49542. }
  49543. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49544. {
  49545. delete upButton;
  49546. upButton = 0;
  49547. delete downButton;
  49548. downButton = 0;
  49549. if (buttonsAreVisible)
  49550. {
  49551. addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this));
  49552. addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this));
  49553. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49554. }
  49555. updateThumbPosition();
  49556. }
  49557. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49558. {
  49559. alwaysVisible = ! shouldHideWhenFullRange;
  49560. updateThumbPosition();
  49561. }
  49562. void ScrollBar::paint (Graphics& g)
  49563. {
  49564. if (thumbAreaSize > 0)
  49565. {
  49566. LookAndFeel& lf = getLookAndFeel();
  49567. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49568. ? thumbSize : 0;
  49569. if (vertical)
  49570. {
  49571. lf.drawScrollbar (g, *this,
  49572. 0, thumbAreaStart,
  49573. getWidth(), thumbAreaSize,
  49574. vertical,
  49575. thumbStart, thumb,
  49576. isMouseOver(), isMouseButtonDown());
  49577. }
  49578. else
  49579. {
  49580. lf.drawScrollbar (g, *this,
  49581. thumbAreaStart, 0,
  49582. thumbAreaSize, getHeight(),
  49583. vertical,
  49584. thumbStart, thumb,
  49585. isMouseOver(), isMouseButtonDown());
  49586. }
  49587. }
  49588. }
  49589. void ScrollBar::lookAndFeelChanged()
  49590. {
  49591. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49592. }
  49593. void ScrollBar::resized()
  49594. {
  49595. const int length = ((vertical) ? getHeight() : getWidth());
  49596. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49597. : 0;
  49598. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49599. {
  49600. thumbAreaStart = length >> 1;
  49601. thumbAreaSize = 0;
  49602. }
  49603. else
  49604. {
  49605. thumbAreaStart = buttonSize;
  49606. thumbAreaSize = length - (buttonSize << 1);
  49607. }
  49608. if (upButton != 0)
  49609. {
  49610. if (vertical)
  49611. {
  49612. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49613. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49614. }
  49615. else
  49616. {
  49617. upButton->setBounds (0, 0, buttonSize, getHeight());
  49618. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49619. }
  49620. }
  49621. updateThumbPosition();
  49622. }
  49623. void ScrollBar::mouseDown (const MouseEvent& e)
  49624. {
  49625. isDraggingThumb = false;
  49626. lastMousePos = vertical ? e.y : e.x;
  49627. dragStartMousePos = lastMousePos;
  49628. dragStartRange = visibleRange.getStart();
  49629. if (dragStartMousePos < thumbStart)
  49630. {
  49631. moveScrollbarInPages (-1);
  49632. startTimer (400);
  49633. }
  49634. else if (dragStartMousePos >= thumbStart + thumbSize)
  49635. {
  49636. moveScrollbarInPages (1);
  49637. startTimer (400);
  49638. }
  49639. else
  49640. {
  49641. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49642. && (thumbAreaSize > thumbSize);
  49643. }
  49644. }
  49645. void ScrollBar::mouseDrag (const MouseEvent& e)
  49646. {
  49647. if (isDraggingThumb)
  49648. {
  49649. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49650. setCurrentRangeStart (dragStartRange
  49651. + deltaPixels * (totalRange.getLength() - visibleRange.getLength())
  49652. / (thumbAreaSize - thumbSize));
  49653. }
  49654. else
  49655. {
  49656. lastMousePos = (vertical) ? e.y : e.x;
  49657. }
  49658. }
  49659. void ScrollBar::mouseUp (const MouseEvent&)
  49660. {
  49661. isDraggingThumb = false;
  49662. stopTimer();
  49663. repaint();
  49664. }
  49665. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49666. float wheelIncrementX,
  49667. float wheelIncrementY)
  49668. {
  49669. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49670. if (increment < 0)
  49671. increment = jmin (increment * 10.0f, -1.0f);
  49672. else if (increment > 0)
  49673. increment = jmax (increment * 10.0f, 1.0f);
  49674. setCurrentRange (visibleRange - singleStepSize * increment);
  49675. }
  49676. void ScrollBar::timerCallback()
  49677. {
  49678. if (isMouseButtonDown())
  49679. {
  49680. startTimer (40);
  49681. if (lastMousePos < thumbStart)
  49682. setCurrentRange (visibleRange - visibleRange.getLength());
  49683. else if (lastMousePos > thumbStart + thumbSize)
  49684. setCurrentRangeStart (visibleRange.getEnd());
  49685. }
  49686. else
  49687. {
  49688. stopTimer();
  49689. }
  49690. }
  49691. bool ScrollBar::keyPressed (const KeyPress& key)
  49692. {
  49693. if (! isVisible())
  49694. return false;
  49695. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49696. moveScrollbarInSteps (-1);
  49697. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49698. moveScrollbarInSteps (1);
  49699. else if (key.isKeyCode (KeyPress::pageUpKey))
  49700. moveScrollbarInPages (-1);
  49701. else if (key.isKeyCode (KeyPress::pageDownKey))
  49702. moveScrollbarInPages (1);
  49703. else if (key.isKeyCode (KeyPress::homeKey))
  49704. scrollToTop();
  49705. else if (key.isKeyCode (KeyPress::endKey))
  49706. scrollToBottom();
  49707. else
  49708. return false;
  49709. return true;
  49710. }
  49711. END_JUCE_NAMESPACE
  49712. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49713. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49714. BEGIN_JUCE_NAMESPACE
  49715. StretchableLayoutManager::StretchableLayoutManager()
  49716. : totalSize (0)
  49717. {
  49718. }
  49719. StretchableLayoutManager::~StretchableLayoutManager()
  49720. {
  49721. }
  49722. void StretchableLayoutManager::clearAllItems()
  49723. {
  49724. items.clear();
  49725. totalSize = 0;
  49726. }
  49727. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49728. const double minimumSize,
  49729. const double maximumSize,
  49730. const double preferredSize)
  49731. {
  49732. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49733. if (layout == 0)
  49734. {
  49735. layout = new ItemLayoutProperties();
  49736. layout->itemIndex = itemIndex;
  49737. int i;
  49738. for (i = 0; i < items.size(); ++i)
  49739. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49740. break;
  49741. items.insert (i, layout);
  49742. }
  49743. layout->minSize = minimumSize;
  49744. layout->maxSize = maximumSize;
  49745. layout->preferredSize = preferredSize;
  49746. layout->currentSize = 0;
  49747. }
  49748. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49749. double& minimumSize,
  49750. double& maximumSize,
  49751. double& preferredSize) const
  49752. {
  49753. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49754. if (layout != 0)
  49755. {
  49756. minimumSize = layout->minSize;
  49757. maximumSize = layout->maxSize;
  49758. preferredSize = layout->preferredSize;
  49759. return true;
  49760. }
  49761. return false;
  49762. }
  49763. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49764. {
  49765. totalSize = newTotalSize;
  49766. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49767. }
  49768. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49769. {
  49770. int pos = 0;
  49771. for (int i = 0; i < itemIndex; ++i)
  49772. {
  49773. const ItemLayoutProperties* const layout = getInfoFor (i);
  49774. if (layout != 0)
  49775. pos += layout->currentSize;
  49776. }
  49777. return pos;
  49778. }
  49779. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49780. {
  49781. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49782. if (layout != 0)
  49783. return layout->currentSize;
  49784. return 0;
  49785. }
  49786. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49787. {
  49788. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49789. if (layout != 0)
  49790. return -layout->currentSize / (double) totalSize;
  49791. return 0;
  49792. }
  49793. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49794. int newPosition)
  49795. {
  49796. for (int i = items.size(); --i >= 0;)
  49797. {
  49798. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49799. if (layout->itemIndex == itemIndex)
  49800. {
  49801. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49802. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49803. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49804. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49805. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49806. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49807. endPos += layout->currentSize;
  49808. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49809. updatePrefSizesToMatchCurrentPositions();
  49810. break;
  49811. }
  49812. }
  49813. }
  49814. void StretchableLayoutManager::layOutComponents (Component** const components,
  49815. int numComponents,
  49816. int x, int y, int w, int h,
  49817. const bool vertically,
  49818. const bool resizeOtherDimension)
  49819. {
  49820. setTotalSize (vertically ? h : w);
  49821. int pos = vertically ? y : x;
  49822. for (int i = 0; i < numComponents; ++i)
  49823. {
  49824. const ItemLayoutProperties* const layout = getInfoFor (i);
  49825. if (layout != 0)
  49826. {
  49827. Component* const c = components[i];
  49828. if (c != 0)
  49829. {
  49830. if (i == numComponents - 1)
  49831. {
  49832. // if it's the last item, crop it to exactly fit the available space..
  49833. if (resizeOtherDimension)
  49834. {
  49835. if (vertically)
  49836. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49837. else
  49838. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49839. }
  49840. else
  49841. {
  49842. if (vertically)
  49843. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49844. else
  49845. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49846. }
  49847. }
  49848. else
  49849. {
  49850. if (resizeOtherDimension)
  49851. {
  49852. if (vertically)
  49853. c->setBounds (x, pos, w, layout->currentSize);
  49854. else
  49855. c->setBounds (pos, y, layout->currentSize, h);
  49856. }
  49857. else
  49858. {
  49859. if (vertically)
  49860. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49861. else
  49862. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49863. }
  49864. }
  49865. }
  49866. pos += layout->currentSize;
  49867. }
  49868. }
  49869. }
  49870. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49871. {
  49872. for (int i = items.size(); --i >= 0;)
  49873. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49874. return items.getUnchecked(i);
  49875. return 0;
  49876. }
  49877. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49878. const int endIndex,
  49879. const int availableSpace,
  49880. int startPos)
  49881. {
  49882. // calculate the total sizes
  49883. int i;
  49884. double totalIdealSize = 0.0;
  49885. int totalMinimums = 0;
  49886. for (i = startIndex; i < endIndex; ++i)
  49887. {
  49888. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49889. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49890. totalMinimums += layout->currentSize;
  49891. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49892. }
  49893. if (totalIdealSize <= 0)
  49894. totalIdealSize = 1.0;
  49895. // now calc the best sizes..
  49896. int extraSpace = availableSpace - totalMinimums;
  49897. while (extraSpace > 0)
  49898. {
  49899. int numWantingMoreSpace = 0;
  49900. int numHavingTakenExtraSpace = 0;
  49901. // first figure out how many comps want a slice of the extra space..
  49902. for (i = startIndex; i < endIndex; ++i)
  49903. {
  49904. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49905. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49906. const int bestSize = jlimit (layout->currentSize,
  49907. jmax (layout->currentSize,
  49908. sizeToRealSize (layout->maxSize, totalSize)),
  49909. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49910. if (bestSize > layout->currentSize)
  49911. ++numWantingMoreSpace;
  49912. }
  49913. // ..share out the extra space..
  49914. for (i = startIndex; i < endIndex; ++i)
  49915. {
  49916. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49917. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49918. int bestSize = jlimit (layout->currentSize,
  49919. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49920. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49921. const int extraWanted = bestSize - layout->currentSize;
  49922. if (extraWanted > 0)
  49923. {
  49924. const int extraAllowed = jmin (extraWanted,
  49925. extraSpace / jmax (1, numWantingMoreSpace));
  49926. if (extraAllowed > 0)
  49927. {
  49928. ++numHavingTakenExtraSpace;
  49929. --numWantingMoreSpace;
  49930. layout->currentSize += extraAllowed;
  49931. extraSpace -= extraAllowed;
  49932. }
  49933. }
  49934. }
  49935. if (numHavingTakenExtraSpace <= 0)
  49936. break;
  49937. }
  49938. // ..and calculate the end position
  49939. for (i = startIndex; i < endIndex; ++i)
  49940. {
  49941. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49942. startPos += layout->currentSize;
  49943. }
  49944. return startPos;
  49945. }
  49946. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49947. const int endIndex) const
  49948. {
  49949. int totalMinimums = 0;
  49950. for (int i = startIndex; i < endIndex; ++i)
  49951. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49952. return totalMinimums;
  49953. }
  49954. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49955. {
  49956. int totalMaximums = 0;
  49957. for (int i = startIndex; i < endIndex; ++i)
  49958. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49959. return totalMaximums;
  49960. }
  49961. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49962. {
  49963. for (int i = 0; i < items.size(); ++i)
  49964. {
  49965. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49966. layout->preferredSize
  49967. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49968. : getItemCurrentAbsoluteSize (i);
  49969. }
  49970. }
  49971. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49972. {
  49973. if (size < 0)
  49974. size *= -totalSpace;
  49975. return roundToInt (size);
  49976. }
  49977. END_JUCE_NAMESPACE
  49978. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49979. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49980. BEGIN_JUCE_NAMESPACE
  49981. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49982. const int itemIndex_,
  49983. const bool isVertical_)
  49984. : layout (layout_),
  49985. itemIndex (itemIndex_),
  49986. isVertical (isVertical_)
  49987. {
  49988. setRepaintsOnMouseActivity (true);
  49989. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49990. : MouseCursor::UpDownResizeCursor));
  49991. }
  49992. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49993. {
  49994. }
  49995. void StretchableLayoutResizerBar::paint (Graphics& g)
  49996. {
  49997. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49998. getWidth(), getHeight(),
  49999. isVertical,
  50000. isMouseOver(),
  50001. isMouseButtonDown());
  50002. }
  50003. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50004. {
  50005. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50006. }
  50007. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50008. {
  50009. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50010. : e.getDistanceFromDragStartY());
  50011. layout->setItemPosition (itemIndex, desiredPos);
  50012. hasBeenMoved();
  50013. }
  50014. void StretchableLayoutResizerBar::hasBeenMoved()
  50015. {
  50016. if (getParentComponent() != 0)
  50017. getParentComponent()->resized();
  50018. }
  50019. END_JUCE_NAMESPACE
  50020. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50021. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50022. BEGIN_JUCE_NAMESPACE
  50023. StretchableObjectResizer::StretchableObjectResizer()
  50024. {
  50025. }
  50026. StretchableObjectResizer::~StretchableObjectResizer()
  50027. {
  50028. }
  50029. void StretchableObjectResizer::addItem (const double size,
  50030. const double minSize, const double maxSize,
  50031. const int order)
  50032. {
  50033. // the order must be >= 0 but less than the maximum integer value.
  50034. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50035. Item* const item = new Item();
  50036. item->size = size;
  50037. item->minSize = minSize;
  50038. item->maxSize = maxSize;
  50039. item->order = order;
  50040. items.add (item);
  50041. }
  50042. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50043. {
  50044. const Item* const it = items [index];
  50045. return it != 0 ? it->size : 0;
  50046. }
  50047. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50048. {
  50049. int order = 0;
  50050. for (;;)
  50051. {
  50052. double currentSize = 0;
  50053. double minSize = 0;
  50054. double maxSize = 0;
  50055. int nextHighestOrder = std::numeric_limits<int>::max();
  50056. for (int i = 0; i < items.size(); ++i)
  50057. {
  50058. const Item* const it = items.getUnchecked(i);
  50059. currentSize += it->size;
  50060. if (it->order <= order)
  50061. {
  50062. minSize += it->minSize;
  50063. maxSize += it->maxSize;
  50064. }
  50065. else
  50066. {
  50067. minSize += it->size;
  50068. maxSize += it->size;
  50069. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50070. }
  50071. }
  50072. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50073. if (thisIterationTarget >= currentSize)
  50074. {
  50075. const double availableExtraSpace = maxSize - currentSize;
  50076. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50077. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50078. for (int i = 0; i < items.size(); ++i)
  50079. {
  50080. Item* const it = items.getUnchecked(i);
  50081. if (it->order <= order)
  50082. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50083. }
  50084. }
  50085. else
  50086. {
  50087. const double amountOfSlack = currentSize - minSize;
  50088. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50089. const double scale = targetAmountOfSlack / amountOfSlack;
  50090. for (int i = 0; i < items.size(); ++i)
  50091. {
  50092. Item* const it = items.getUnchecked(i);
  50093. if (it->order <= order)
  50094. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50095. }
  50096. }
  50097. if (nextHighestOrder < std::numeric_limits<int>::max())
  50098. order = nextHighestOrder;
  50099. else
  50100. break;
  50101. }
  50102. }
  50103. END_JUCE_NAMESPACE
  50104. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50105. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50106. BEGIN_JUCE_NAMESPACE
  50107. TabBarButton::TabBarButton (const String& name,
  50108. TabbedButtonBar* const owner_,
  50109. const int index)
  50110. : Button (name),
  50111. owner (owner_),
  50112. tabIndex (index),
  50113. overlapPixels (0)
  50114. {
  50115. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50116. setComponentEffect (&shadow);
  50117. setWantsKeyboardFocus (false);
  50118. }
  50119. TabBarButton::~TabBarButton()
  50120. {
  50121. }
  50122. void TabBarButton::paintButton (Graphics& g,
  50123. bool isMouseOverButton,
  50124. bool isButtonDown)
  50125. {
  50126. int x, y, w, h;
  50127. getActiveArea (x, y, w, h);
  50128. g.setOrigin (x, y);
  50129. getLookAndFeel()
  50130. .drawTabButton (g, w, h,
  50131. owner->getTabBackgroundColour (tabIndex),
  50132. tabIndex, getButtonText(), *this,
  50133. owner->getOrientation(),
  50134. isMouseOverButton, isButtonDown,
  50135. getToggleState());
  50136. }
  50137. void TabBarButton::clicked (const ModifierKeys& mods)
  50138. {
  50139. if (mods.isPopupMenu())
  50140. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50141. else
  50142. owner->setCurrentTabIndex (tabIndex);
  50143. }
  50144. bool TabBarButton::hitTest (int mx, int my)
  50145. {
  50146. int x, y, w, h;
  50147. getActiveArea (x, y, w, h);
  50148. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50149. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50150. {
  50151. if (((unsigned int) mx) < (unsigned int) getWidth()
  50152. && my >= y + overlapPixels
  50153. && my < y + h - overlapPixels)
  50154. return true;
  50155. }
  50156. else
  50157. {
  50158. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50159. && ((unsigned int) my) < (unsigned int) getHeight())
  50160. return true;
  50161. }
  50162. Path p;
  50163. getLookAndFeel()
  50164. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50165. owner->getOrientation(),
  50166. false, false, getToggleState());
  50167. return p.contains ((float) (mx - x),
  50168. (float) (my - y));
  50169. }
  50170. int TabBarButton::getBestTabLength (const int depth)
  50171. {
  50172. return jlimit (depth * 2,
  50173. depth * 7,
  50174. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50175. }
  50176. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50177. {
  50178. x = 0;
  50179. y = 0;
  50180. int r = getWidth();
  50181. int b = getHeight();
  50182. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50183. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50184. r -= spaceAroundImage;
  50185. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50186. x += spaceAroundImage;
  50187. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50188. y += spaceAroundImage;
  50189. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50190. b -= spaceAroundImage;
  50191. w = r - x;
  50192. h = b - y;
  50193. }
  50194. class TabAreaBehindFrontButtonComponent : public Component
  50195. {
  50196. public:
  50197. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50198. : owner (owner_)
  50199. {
  50200. setInterceptsMouseClicks (false, false);
  50201. }
  50202. ~TabAreaBehindFrontButtonComponent()
  50203. {
  50204. }
  50205. void paint (Graphics& g)
  50206. {
  50207. getLookAndFeel()
  50208. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50209. *owner, owner->getOrientation());
  50210. }
  50211. void enablementChanged()
  50212. {
  50213. repaint();
  50214. }
  50215. private:
  50216. TabbedButtonBar* const owner;
  50217. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50218. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50219. };
  50220. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50221. : orientation (orientation_),
  50222. currentTabIndex (-1),
  50223. extraTabsButton (0)
  50224. {
  50225. setInterceptsMouseClicks (false, true);
  50226. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50227. setFocusContainer (true);
  50228. }
  50229. TabbedButtonBar::~TabbedButtonBar()
  50230. {
  50231. deleteAllChildren();
  50232. }
  50233. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50234. {
  50235. orientation = newOrientation;
  50236. for (int i = getNumChildComponents(); --i >= 0;)
  50237. getChildComponent (i)->resized();
  50238. resized();
  50239. }
  50240. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50241. {
  50242. return new TabBarButton (name, this, index);
  50243. }
  50244. void TabbedButtonBar::clearTabs()
  50245. {
  50246. tabs.clear();
  50247. tabColours.clear();
  50248. currentTabIndex = -1;
  50249. deleteAndZero (extraTabsButton);
  50250. removeChildComponent (behindFrontTab);
  50251. deleteAllChildren();
  50252. addChildComponent (behindFrontTab);
  50253. setCurrentTabIndex (-1);
  50254. }
  50255. void TabbedButtonBar::addTab (const String& tabName,
  50256. const Colour& tabBackgroundColour,
  50257. int insertIndex)
  50258. {
  50259. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50260. if (tabName.isNotEmpty())
  50261. {
  50262. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50263. insertIndex = tabs.size();
  50264. for (int i = tabs.size(); --i >= insertIndex;)
  50265. {
  50266. TabBarButton* const tb = getTabButton (i);
  50267. if (tb != 0)
  50268. tb->tabIndex++;
  50269. }
  50270. tabs.insert (insertIndex, tabName);
  50271. tabColours.insert (insertIndex, tabBackgroundColour);
  50272. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50273. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50274. addAndMakeVisible (tb, insertIndex);
  50275. resized();
  50276. if (currentTabIndex < 0)
  50277. setCurrentTabIndex (0);
  50278. }
  50279. }
  50280. void TabbedButtonBar::setTabName (const int tabIndex,
  50281. const String& newName)
  50282. {
  50283. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50284. && tabs[tabIndex] != newName)
  50285. {
  50286. tabs.set (tabIndex, newName);
  50287. TabBarButton* const tb = getTabButton (tabIndex);
  50288. if (tb != 0)
  50289. tb->setButtonText (newName);
  50290. resized();
  50291. }
  50292. }
  50293. void TabbedButtonBar::removeTab (const int tabIndex)
  50294. {
  50295. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50296. {
  50297. const int oldTabIndex = currentTabIndex;
  50298. if (currentTabIndex == tabIndex)
  50299. currentTabIndex = -1;
  50300. tabs.remove (tabIndex);
  50301. tabColours.remove (tabIndex);
  50302. delete getTabButton (tabIndex);
  50303. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50304. {
  50305. TabBarButton* const tb = getTabButton (i);
  50306. if (tb != 0)
  50307. tb->tabIndex--;
  50308. }
  50309. resized();
  50310. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50311. }
  50312. }
  50313. void TabbedButtonBar::moveTab (const int currentIndex,
  50314. const int newIndex)
  50315. {
  50316. tabs.move (currentIndex, newIndex);
  50317. tabColours.move (currentIndex, newIndex);
  50318. resized();
  50319. }
  50320. int TabbedButtonBar::getNumTabs() const
  50321. {
  50322. return tabs.size();
  50323. }
  50324. const StringArray TabbedButtonBar::getTabNames() const
  50325. {
  50326. return tabs;
  50327. }
  50328. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50329. {
  50330. if (currentTabIndex != newIndex)
  50331. {
  50332. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50333. newIndex = -1;
  50334. currentTabIndex = newIndex;
  50335. for (int i = 0; i < getNumChildComponents(); ++i)
  50336. {
  50337. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50338. if (tb != 0)
  50339. tb->setToggleState (tb->tabIndex == newIndex, false);
  50340. }
  50341. resized();
  50342. if (sendChangeMessage_)
  50343. sendChangeMessage (this);
  50344. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50345. }
  50346. }
  50347. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50348. {
  50349. for (int i = getNumChildComponents(); --i >= 0;)
  50350. {
  50351. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50352. if (tb != 0 && tb->tabIndex == index)
  50353. return tb;
  50354. }
  50355. return 0;
  50356. }
  50357. void TabbedButtonBar::lookAndFeelChanged()
  50358. {
  50359. deleteAndZero (extraTabsButton);
  50360. resized();
  50361. }
  50362. void TabbedButtonBar::resized()
  50363. {
  50364. const double minimumScale = 0.7;
  50365. int depth = getWidth();
  50366. int length = getHeight();
  50367. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50368. swapVariables (depth, length);
  50369. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50370. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50371. int i, totalLength = overlap;
  50372. int numVisibleButtons = tabs.size();
  50373. for (i = 0; i < getNumChildComponents(); ++i)
  50374. {
  50375. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50376. if (tb != 0)
  50377. {
  50378. totalLength += tb->getBestTabLength (depth) - overlap;
  50379. tb->overlapPixels = overlap / 2;
  50380. }
  50381. }
  50382. double scale = 1.0;
  50383. if (totalLength > length)
  50384. scale = jmax (minimumScale, length / (double) totalLength);
  50385. const bool isTooBig = totalLength * scale > length;
  50386. int tabsButtonPos = 0;
  50387. if (isTooBig)
  50388. {
  50389. if (extraTabsButton == 0)
  50390. {
  50391. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50392. extraTabsButton->addButtonListener (this);
  50393. extraTabsButton->setAlwaysOnTop (true);
  50394. extraTabsButton->setTriggeredOnMouseDown (true);
  50395. }
  50396. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50397. extraTabsButton->setSize (buttonSize, buttonSize);
  50398. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50399. {
  50400. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50401. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50402. }
  50403. else
  50404. {
  50405. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50406. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50407. }
  50408. totalLength = 0;
  50409. for (i = 0; i < tabs.size(); ++i)
  50410. {
  50411. TabBarButton* const tb = getTabButton (i);
  50412. if (tb != 0)
  50413. {
  50414. const int newLength = totalLength + tb->getBestTabLength (depth);
  50415. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50416. {
  50417. totalLength += overlap;
  50418. break;
  50419. }
  50420. numVisibleButtons = i + 1;
  50421. totalLength = newLength - overlap;
  50422. }
  50423. }
  50424. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50425. }
  50426. else
  50427. {
  50428. deleteAndZero (extraTabsButton);
  50429. }
  50430. int pos = 0;
  50431. TabBarButton* frontTab = 0;
  50432. for (i = 0; i < tabs.size(); ++i)
  50433. {
  50434. TabBarButton* const tb = getTabButton (i);
  50435. if (tb != 0)
  50436. {
  50437. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50438. if (i < numVisibleButtons)
  50439. {
  50440. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50441. tb->setBounds (pos, 0, bestLength, getHeight());
  50442. else
  50443. tb->setBounds (0, pos, getWidth(), bestLength);
  50444. tb->toBack();
  50445. if (tb->tabIndex == currentTabIndex)
  50446. frontTab = tb;
  50447. tb->setVisible (true);
  50448. }
  50449. else
  50450. {
  50451. tb->setVisible (false);
  50452. }
  50453. pos += bestLength - overlap;
  50454. }
  50455. }
  50456. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50457. if (frontTab != 0)
  50458. {
  50459. frontTab->toFront (false);
  50460. behindFrontTab->toBehind (frontTab);
  50461. }
  50462. }
  50463. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50464. {
  50465. return tabColours [tabIndex];
  50466. }
  50467. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50468. {
  50469. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50470. && tabColours [tabIndex] != newColour)
  50471. {
  50472. tabColours.set (tabIndex, newColour);
  50473. repaint();
  50474. }
  50475. }
  50476. void TabbedButtonBar::buttonClicked (Button* button)
  50477. {
  50478. if (extraTabsButton == button)
  50479. {
  50480. PopupMenu m;
  50481. for (int i = 0; i < tabs.size(); ++i)
  50482. {
  50483. TabBarButton* const tb = getTabButton (i);
  50484. if (tb != 0 && ! tb->isVisible())
  50485. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50486. }
  50487. const int res = m.showAt (extraTabsButton);
  50488. if (res != 0)
  50489. setCurrentTabIndex (res - 1);
  50490. }
  50491. }
  50492. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50493. {
  50494. }
  50495. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50496. {
  50497. }
  50498. END_JUCE_NAMESPACE
  50499. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50500. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50501. BEGIN_JUCE_NAMESPACE
  50502. class TabCompButtonBar : public TabbedButtonBar
  50503. {
  50504. public:
  50505. TabCompButtonBar (TabbedComponent* const owner_,
  50506. const TabbedButtonBar::Orientation orientation)
  50507. : TabbedButtonBar (orientation),
  50508. owner (owner_)
  50509. {
  50510. }
  50511. ~TabCompButtonBar()
  50512. {
  50513. }
  50514. void currentTabChanged (int newCurrentTabIndex,
  50515. const String& newTabName)
  50516. {
  50517. owner->changeCallback (newCurrentTabIndex, newTabName);
  50518. }
  50519. void popupMenuClickOnTab (int tabIndex,
  50520. const String& tabName)
  50521. {
  50522. owner->popupMenuClickOnTab (tabIndex, tabName);
  50523. }
  50524. const Colour getTabBackgroundColour (const int tabIndex)
  50525. {
  50526. return owner->tabs->getTabBackgroundColour (tabIndex);
  50527. }
  50528. TabBarButton* createTabButton (const String& tabName, int tabIndex)
  50529. {
  50530. return owner->createTabButton (tabName, tabIndex);
  50531. }
  50532. juce_UseDebuggingNewOperator
  50533. private:
  50534. TabbedComponent* const owner;
  50535. TabCompButtonBar (const TabCompButtonBar&);
  50536. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50537. };
  50538. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50539. : panelComponent (0),
  50540. tabDepth (30),
  50541. outlineThickness (1),
  50542. edgeIndent (0)
  50543. {
  50544. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50545. }
  50546. TabbedComponent::~TabbedComponent()
  50547. {
  50548. clearTabs();
  50549. delete tabs;
  50550. }
  50551. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50552. {
  50553. tabs->setOrientation (orientation);
  50554. resized();
  50555. }
  50556. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50557. {
  50558. return tabs->getOrientation();
  50559. }
  50560. void TabbedComponent::setTabBarDepth (const int newDepth)
  50561. {
  50562. if (tabDepth != newDepth)
  50563. {
  50564. tabDepth = newDepth;
  50565. resized();
  50566. }
  50567. }
  50568. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50569. {
  50570. return new TabBarButton (tabName, tabs, tabIndex);
  50571. }
  50572. void TabbedComponent::clearTabs()
  50573. {
  50574. if (panelComponent != 0)
  50575. {
  50576. panelComponent->setVisible (false);
  50577. removeChildComponent (panelComponent);
  50578. panelComponent = 0;
  50579. }
  50580. tabs->clearTabs();
  50581. for (int i = contentComponents.size(); --i >= 0;)
  50582. {
  50583. Component* const c = contentComponents.getUnchecked(i);
  50584. // be careful not to delete these components until they've been removed from the tab component
  50585. jassert (c == 0 || c->isValidComponent());
  50586. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50587. delete c;
  50588. }
  50589. contentComponents.clear();
  50590. }
  50591. void TabbedComponent::addTab (const String& tabName,
  50592. const Colour& tabBackgroundColour,
  50593. Component* const contentComponent,
  50594. const bool deleteComponentWhenNotNeeded,
  50595. const int insertIndex)
  50596. {
  50597. contentComponents.insert (insertIndex, contentComponent);
  50598. if (contentComponent != 0)
  50599. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50600. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50601. }
  50602. void TabbedComponent::setTabName (const int tabIndex,
  50603. const String& newName)
  50604. {
  50605. tabs->setTabName (tabIndex, newName);
  50606. }
  50607. void TabbedComponent::removeTab (const int tabIndex)
  50608. {
  50609. Component* const c = contentComponents [tabIndex];
  50610. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50611. {
  50612. if (c == panelComponent)
  50613. panelComponent = 0;
  50614. delete c;
  50615. }
  50616. contentComponents.remove (tabIndex);
  50617. tabs->removeTab (tabIndex);
  50618. }
  50619. int TabbedComponent::getNumTabs() const
  50620. {
  50621. return tabs->getNumTabs();
  50622. }
  50623. const StringArray TabbedComponent::getTabNames() const
  50624. {
  50625. return tabs->getTabNames();
  50626. }
  50627. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50628. {
  50629. return contentComponents [tabIndex];
  50630. }
  50631. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50632. {
  50633. return tabs->getTabBackgroundColour (tabIndex);
  50634. }
  50635. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50636. {
  50637. tabs->setTabBackgroundColour (tabIndex, newColour);
  50638. if (getCurrentTabIndex() == tabIndex)
  50639. repaint();
  50640. }
  50641. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50642. {
  50643. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50644. }
  50645. int TabbedComponent::getCurrentTabIndex() const
  50646. {
  50647. return tabs->getCurrentTabIndex();
  50648. }
  50649. const String& TabbedComponent::getCurrentTabName() const
  50650. {
  50651. return tabs->getCurrentTabName();
  50652. }
  50653. void TabbedComponent::setOutline (int thickness)
  50654. {
  50655. outlineThickness = thickness;
  50656. repaint();
  50657. }
  50658. void TabbedComponent::setIndent (const int indentThickness)
  50659. {
  50660. edgeIndent = indentThickness;
  50661. }
  50662. void TabbedComponent::paint (Graphics& g)
  50663. {
  50664. g.fillAll (findColour (backgroundColourId));
  50665. const TabbedButtonBar::Orientation o = getOrientation();
  50666. int x = 0;
  50667. int y = 0;
  50668. int r = getWidth();
  50669. int b = getHeight();
  50670. if (o == TabbedButtonBar::TabsAtTop)
  50671. y += tabDepth;
  50672. else if (o == TabbedButtonBar::TabsAtBottom)
  50673. b -= tabDepth;
  50674. else if (o == TabbedButtonBar::TabsAtLeft)
  50675. x += tabDepth;
  50676. else if (o == TabbedButtonBar::TabsAtRight)
  50677. r -= tabDepth;
  50678. g.reduceClipRegion (x, y, r - x, b - y);
  50679. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50680. if (outlineThickness > 0)
  50681. {
  50682. if (o == TabbedButtonBar::TabsAtTop)
  50683. --y;
  50684. else if (o == TabbedButtonBar::TabsAtBottom)
  50685. ++b;
  50686. else if (o == TabbedButtonBar::TabsAtLeft)
  50687. --x;
  50688. else if (o == TabbedButtonBar::TabsAtRight)
  50689. ++r;
  50690. g.setColour (findColour (outlineColourId));
  50691. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50692. }
  50693. }
  50694. void TabbedComponent::resized()
  50695. {
  50696. const TabbedButtonBar::Orientation o = getOrientation();
  50697. const int indent = edgeIndent + outlineThickness;
  50698. BorderSize indents (indent);
  50699. if (o == TabbedButtonBar::TabsAtTop)
  50700. {
  50701. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50702. indents.setTop (tabDepth + edgeIndent);
  50703. }
  50704. else if (o == TabbedButtonBar::TabsAtBottom)
  50705. {
  50706. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50707. indents.setBottom (tabDepth + edgeIndent);
  50708. }
  50709. else if (o == TabbedButtonBar::TabsAtLeft)
  50710. {
  50711. tabs->setBounds (0, 0, tabDepth, getHeight());
  50712. indents.setLeft (tabDepth + edgeIndent);
  50713. }
  50714. else if (o == TabbedButtonBar::TabsAtRight)
  50715. {
  50716. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50717. indents.setRight (tabDepth + edgeIndent);
  50718. }
  50719. const Rectangle<int> bounds (indents.subtractedFrom (getLocalBounds()));
  50720. for (int i = contentComponents.size(); --i >= 0;)
  50721. if (contentComponents.getUnchecked (i) != 0)
  50722. contentComponents.getUnchecked (i)->setBounds (bounds);
  50723. }
  50724. void TabbedComponent::lookAndFeelChanged()
  50725. {
  50726. for (int i = contentComponents.size(); --i >= 0;)
  50727. if (contentComponents.getUnchecked (i) != 0)
  50728. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50729. }
  50730. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50731. const String& newTabName)
  50732. {
  50733. if (panelComponent != 0)
  50734. {
  50735. panelComponent->setVisible (false);
  50736. removeChildComponent (panelComponent);
  50737. panelComponent = 0;
  50738. }
  50739. if (getCurrentTabIndex() >= 0)
  50740. {
  50741. panelComponent = contentComponents [getCurrentTabIndex()];
  50742. if (panelComponent != 0)
  50743. {
  50744. // do these ops as two stages instead of addAndMakeVisible() so that the
  50745. // component has always got a parent when it gets the visibilityChanged() callback
  50746. addChildComponent (panelComponent);
  50747. panelComponent->setVisible (true);
  50748. panelComponent->toFront (true);
  50749. }
  50750. repaint();
  50751. }
  50752. resized();
  50753. currentTabChanged (newCurrentTabIndex, newTabName);
  50754. }
  50755. void TabbedComponent::currentTabChanged (const int, const String&)
  50756. {
  50757. }
  50758. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50759. {
  50760. }
  50761. END_JUCE_NAMESPACE
  50762. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50763. /*** Start of inlined file: juce_Viewport.cpp ***/
  50764. BEGIN_JUCE_NAMESPACE
  50765. Viewport::Viewport (const String& componentName)
  50766. : Component (componentName),
  50767. contentComp (0),
  50768. lastVX (0),
  50769. lastVY (0),
  50770. lastVW (0),
  50771. lastVH (0),
  50772. scrollBarThickness (0),
  50773. singleStepX (16),
  50774. singleStepY (16),
  50775. showHScrollbar (true),
  50776. showVScrollbar (true)
  50777. {
  50778. // content holder is used to clip the contents so they don't overlap the scrollbars
  50779. addAndMakeVisible (contentHolder = new Component());
  50780. contentHolder->setInterceptsMouseClicks (false, true);
  50781. verticalScrollBar = new ScrollBar (true);
  50782. horizontalScrollBar = new ScrollBar (false);
  50783. addChildComponent (verticalScrollBar);
  50784. addChildComponent (horizontalScrollBar);
  50785. verticalScrollBar->addListener (this);
  50786. horizontalScrollBar->addListener (this);
  50787. setInterceptsMouseClicks (false, true);
  50788. setWantsKeyboardFocus (true);
  50789. }
  50790. Viewport::~Viewport()
  50791. {
  50792. contentHolder->deleteAllChildren();
  50793. deleteAllChildren();
  50794. }
  50795. void Viewport::visibleAreaChanged (int, int, int, int)
  50796. {
  50797. }
  50798. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50799. {
  50800. if (contentComp.getComponent() != newViewedComponent)
  50801. {
  50802. {
  50803. ScopedPointer<Component> oldCompDeleter (contentComp);
  50804. contentComp = 0;
  50805. }
  50806. contentComp = newViewedComponent;
  50807. if (contentComp != 0)
  50808. {
  50809. contentComp->setTopLeftPosition (0, 0);
  50810. contentHolder->addAndMakeVisible (contentComp);
  50811. contentComp->addComponentListener (this);
  50812. }
  50813. updateVisibleRegion();
  50814. }
  50815. }
  50816. int Viewport::getMaximumVisibleWidth() const throw()
  50817. {
  50818. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50819. }
  50820. int Viewport::getMaximumVisibleHeight() const throw()
  50821. {
  50822. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50823. }
  50824. void Viewport::setViewPosition (const int xPixelsOffset,
  50825. const int yPixelsOffset)
  50826. {
  50827. if (contentComp != 0)
  50828. contentComp->setTopLeftPosition (-xPixelsOffset,
  50829. -yPixelsOffset);
  50830. }
  50831. void Viewport::setViewPositionProportionately (const double x,
  50832. const double y)
  50833. {
  50834. if (contentComp != 0)
  50835. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50836. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50837. }
  50838. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50839. {
  50840. if (contentComp != 0)
  50841. {
  50842. int dx = 0, dy = 0;
  50843. if (mouseX < activeBorderThickness)
  50844. dx = activeBorderThickness - mouseX;
  50845. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50846. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50847. if (dx < 0)
  50848. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50849. else
  50850. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50851. if (mouseY < activeBorderThickness)
  50852. dy = activeBorderThickness - mouseY;
  50853. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50854. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50855. if (dy < 0)
  50856. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50857. else
  50858. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50859. if (dx != 0 || dy != 0)
  50860. {
  50861. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50862. contentComp->getY() + dy);
  50863. return true;
  50864. }
  50865. }
  50866. return false;
  50867. }
  50868. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50869. {
  50870. updateVisibleRegion();
  50871. }
  50872. void Viewport::resized()
  50873. {
  50874. updateVisibleRegion();
  50875. }
  50876. void Viewport::updateVisibleRegion()
  50877. {
  50878. if (contentComp != 0)
  50879. {
  50880. const int newVX = -contentComp->getX();
  50881. const int newVY = -contentComp->getY();
  50882. if (newVX == 0 && newVY == 0
  50883. && contentComp->getWidth() <= getWidth()
  50884. && contentComp->getHeight() <= getHeight())
  50885. {
  50886. horizontalScrollBar->setVisible (false);
  50887. verticalScrollBar->setVisible (false);
  50888. }
  50889. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50890. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50891. horizontalScrollBar->setSingleStepSize (singleStepX);
  50892. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50893. horizontalScrollBar->setVisible (false);
  50894. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50895. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50896. verticalScrollBar->setSingleStepSize (singleStepY);
  50897. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50898. verticalScrollBar->setVisible (false);
  50899. if (verticalScrollBar->isVisible())
  50900. {
  50901. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50902. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50903. verticalScrollBar
  50904. ->setBounds (getMaximumVisibleWidth(), 0,
  50905. getScrollBarThickness(), getMaximumVisibleHeight());
  50906. }
  50907. if (horizontalScrollBar->isVisible())
  50908. {
  50909. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50910. horizontalScrollBar
  50911. ->setBounds (0, getMaximumVisibleHeight(),
  50912. getMaximumVisibleWidth(), getScrollBarThickness());
  50913. }
  50914. contentHolder->setSize (getMaximumVisibleWidth(),
  50915. getMaximumVisibleHeight());
  50916. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50917. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50918. if (newVX != lastVX
  50919. || newVY != lastVY
  50920. || newVW != lastVW
  50921. || newVH != lastVH)
  50922. {
  50923. lastVX = newVX;
  50924. lastVY = newVY;
  50925. lastVW = newVW;
  50926. lastVH = newVH;
  50927. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50928. }
  50929. horizontalScrollBar->handleUpdateNowIfNeeded();
  50930. verticalScrollBar->handleUpdateNowIfNeeded();
  50931. }
  50932. else
  50933. {
  50934. horizontalScrollBar->setVisible (false);
  50935. verticalScrollBar->setVisible (false);
  50936. }
  50937. }
  50938. void Viewport::setSingleStepSizes (const int stepX,
  50939. const int stepY)
  50940. {
  50941. singleStepX = stepX;
  50942. singleStepY = stepY;
  50943. updateVisibleRegion();
  50944. }
  50945. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50946. const bool showHorizontalScrollbarIfNeeded)
  50947. {
  50948. showVScrollbar = showVerticalScrollbarIfNeeded;
  50949. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50950. updateVisibleRegion();
  50951. }
  50952. void Viewport::setScrollBarThickness (const int thickness)
  50953. {
  50954. scrollBarThickness = thickness;
  50955. updateVisibleRegion();
  50956. }
  50957. int Viewport::getScrollBarThickness() const throw()
  50958. {
  50959. return (scrollBarThickness > 0) ? scrollBarThickness
  50960. : getLookAndFeel().getDefaultScrollbarWidth();
  50961. }
  50962. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50963. {
  50964. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50965. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50966. }
  50967. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50968. {
  50969. if (scrollBarThatHasMoved == horizontalScrollBar)
  50970. {
  50971. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50972. }
  50973. else if (scrollBarThatHasMoved == verticalScrollBar)
  50974. {
  50975. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50976. }
  50977. }
  50978. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50979. {
  50980. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50981. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50982. }
  50983. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50984. {
  50985. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50986. {
  50987. const bool hasVertBar = verticalScrollBar->isVisible();
  50988. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50989. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50990. {
  50991. if (wheelIncrementX == 0 && ! hasVertBar)
  50992. wheelIncrementX = wheelIncrementY;
  50993. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50994. wheelIncrementX, wheelIncrementY);
  50995. return true;
  50996. }
  50997. else if (hasVertBar && wheelIncrementY != 0)
  50998. {
  50999. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51000. wheelIncrementX, wheelIncrementY);
  51001. return true;
  51002. }
  51003. }
  51004. return false;
  51005. }
  51006. bool Viewport::keyPressed (const KeyPress& key)
  51007. {
  51008. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51009. || key.isKeyCode (KeyPress::downKey)
  51010. || key.isKeyCode (KeyPress::pageUpKey)
  51011. || key.isKeyCode (KeyPress::pageDownKey)
  51012. || key.isKeyCode (KeyPress::homeKey)
  51013. || key.isKeyCode (KeyPress::endKey);
  51014. if (verticalScrollBar->isVisible() && isUpDownKey)
  51015. return verticalScrollBar->keyPressed (key);
  51016. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51017. || key.isKeyCode (KeyPress::rightKey);
  51018. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51019. return horizontalScrollBar->keyPressed (key);
  51020. return false;
  51021. }
  51022. END_JUCE_NAMESPACE
  51023. /*** End of inlined file: juce_Viewport.cpp ***/
  51024. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51025. BEGIN_JUCE_NAMESPACE
  51026. static const Colour createBaseColour (const Colour& buttonColour,
  51027. const bool hasKeyboardFocus,
  51028. const bool isMouseOverButton,
  51029. const bool isButtonDown) throw()
  51030. {
  51031. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51032. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51033. if (isButtonDown)
  51034. return baseColour.contrasting (0.2f);
  51035. else if (isMouseOverButton)
  51036. return baseColour.contrasting (0.1f);
  51037. return baseColour;
  51038. }
  51039. LookAndFeel::LookAndFeel()
  51040. {
  51041. /* if this fails it means you're trying to create a LookAndFeel object before
  51042. the static Colours have been initialised. That ain't gonna work. It probably
  51043. means that you're using a static LookAndFeel object and that your compiler has
  51044. decided to intialise it before the Colours class.
  51045. */
  51046. jassert (Colours::white == Colour (0xffffffff));
  51047. // set up the standard set of colours..
  51048. const int textButtonColour = 0xffbbbbff;
  51049. const int textHighlightColour = 0x401111ee;
  51050. const int standardOutlineColour = 0xb2808080;
  51051. static const int standardColours[] =
  51052. {
  51053. TextButton::buttonColourId, textButtonColour,
  51054. TextButton::buttonOnColourId, 0xff4444ff,
  51055. TextButton::textColourOnId, 0xff000000,
  51056. TextButton::textColourOffId, 0xff000000,
  51057. ComboBox::buttonColourId, 0xffbbbbff,
  51058. ComboBox::outlineColourId, standardOutlineColour,
  51059. ToggleButton::textColourId, 0xff000000,
  51060. TextEditor::backgroundColourId, 0xffffffff,
  51061. TextEditor::textColourId, 0xff000000,
  51062. TextEditor::highlightColourId, textHighlightColour,
  51063. TextEditor::highlightedTextColourId, 0xff000000,
  51064. TextEditor::caretColourId, 0xff000000,
  51065. TextEditor::outlineColourId, 0x00000000,
  51066. TextEditor::focusedOutlineColourId, textButtonColour,
  51067. TextEditor::shadowColourId, 0x38000000,
  51068. Label::backgroundColourId, 0x00000000,
  51069. Label::textColourId, 0xff000000,
  51070. Label::outlineColourId, 0x00000000,
  51071. ScrollBar::backgroundColourId, 0x00000000,
  51072. ScrollBar::thumbColourId, 0xffffffff,
  51073. ScrollBar::trackColourId, 0xffffffff,
  51074. TreeView::linesColourId, 0x4c000000,
  51075. TreeView::backgroundColourId, 0x00000000,
  51076. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51077. PopupMenu::backgroundColourId, 0xffffffff,
  51078. PopupMenu::textColourId, 0xff000000,
  51079. PopupMenu::headerTextColourId, 0xff000000,
  51080. PopupMenu::highlightedTextColourId, 0xffffffff,
  51081. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51082. ComboBox::textColourId, 0xff000000,
  51083. ComboBox::backgroundColourId, 0xffffffff,
  51084. ComboBox::arrowColourId, 0x99000000,
  51085. ListBox::backgroundColourId, 0xffffffff,
  51086. ListBox::outlineColourId, standardOutlineColour,
  51087. ListBox::textColourId, 0xff000000,
  51088. Slider::backgroundColourId, 0x00000000,
  51089. Slider::thumbColourId, textButtonColour,
  51090. Slider::trackColourId, 0x7fffffff,
  51091. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51092. Slider::rotarySliderOutlineColourId, 0x66000000,
  51093. Slider::textBoxTextColourId, 0xff000000,
  51094. Slider::textBoxBackgroundColourId, 0xffffffff,
  51095. Slider::textBoxHighlightColourId, textHighlightColour,
  51096. Slider::textBoxOutlineColourId, standardOutlineColour,
  51097. ResizableWindow::backgroundColourId, 0xff777777,
  51098. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51099. AlertWindow::backgroundColourId, 0xffededed,
  51100. AlertWindow::textColourId, 0xff000000,
  51101. AlertWindow::outlineColourId, 0xff666666,
  51102. ProgressBar::backgroundColourId, 0xffeeeeee,
  51103. ProgressBar::foregroundColourId, 0xffaaaaee,
  51104. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51105. TooltipWindow::textColourId, 0xff000000,
  51106. TooltipWindow::outlineColourId, 0x4c000000,
  51107. TabbedComponent::backgroundColourId, 0x00000000,
  51108. TabbedComponent::outlineColourId, 0xff777777,
  51109. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51110. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51111. Toolbar::backgroundColourId, 0xfff6f8f9,
  51112. Toolbar::separatorColourId, 0x4c000000,
  51113. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51114. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51115. Toolbar::labelTextColourId, 0xff000000,
  51116. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51117. HyperlinkButton::textColourId, 0xcc1111ee,
  51118. GroupComponent::outlineColourId, 0x66000000,
  51119. GroupComponent::textColourId, 0xff000000,
  51120. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51121. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51122. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51123. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51124. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51125. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51126. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51127. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51128. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51129. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51130. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51131. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51132. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51133. CodeEditorComponent::caretColourId, 0xff000000,
  51134. CodeEditorComponent::highlightColourId, textHighlightColour,
  51135. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51136. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51137. ColourSelector::labelTextColourId, 0xff000000,
  51138. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51139. KeyMappingEditorComponent::textColourId, 0xff000000,
  51140. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51141. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51142. };
  51143. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51144. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51145. static String defaultSansName, defaultSerifName, defaultFixedName;
  51146. if (defaultSansName.isEmpty())
  51147. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51148. defaultSans = defaultSansName;
  51149. defaultSerif = defaultSerifName;
  51150. defaultFixed = defaultFixedName;
  51151. }
  51152. LookAndFeel::~LookAndFeel()
  51153. {
  51154. }
  51155. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51156. {
  51157. const int index = colourIds.indexOf (colourId);
  51158. if (index >= 0)
  51159. return colours [index];
  51160. jassertfalse
  51161. return Colours::black;
  51162. }
  51163. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51164. {
  51165. const int index = colourIds.indexOf (colourId);
  51166. if (index >= 0)
  51167. colours.set (index, colour);
  51168. colourIds.add (colourId);
  51169. colours.add (colour);
  51170. }
  51171. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51172. {
  51173. return colourIds.contains (colourId);
  51174. }
  51175. static LookAndFeel* defaultLF = 0;
  51176. static LookAndFeel* currentDefaultLF = 0;
  51177. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51178. {
  51179. // if this happens, your app hasn't initialised itself properly.. if you're
  51180. // trying to hack your own main() function, have a look at
  51181. // JUCEApplication::initialiseForGUI()
  51182. jassert (currentDefaultLF != 0);
  51183. return *currentDefaultLF;
  51184. }
  51185. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51186. {
  51187. if (newDefaultLookAndFeel == 0)
  51188. {
  51189. if (defaultLF == 0)
  51190. defaultLF = new LookAndFeel();
  51191. newDefaultLookAndFeel = defaultLF;
  51192. }
  51193. currentDefaultLF = newDefaultLookAndFeel;
  51194. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51195. {
  51196. Component* const c = Desktop::getInstance().getComponent (i);
  51197. if (c != 0)
  51198. c->sendLookAndFeelChange();
  51199. }
  51200. }
  51201. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51202. {
  51203. if (currentDefaultLF == defaultLF)
  51204. currentDefaultLF = 0;
  51205. deleteAndZero (defaultLF);
  51206. }
  51207. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51208. {
  51209. String faceName (font.getTypefaceName());
  51210. if (faceName == Font::getDefaultSansSerifFontName())
  51211. faceName = defaultSans;
  51212. else if (faceName == Font::getDefaultSerifFontName())
  51213. faceName = defaultSerif;
  51214. else if (faceName == Font::getDefaultMonospacedFontName())
  51215. faceName = defaultFixed;
  51216. Font f (font);
  51217. f.setTypefaceName (faceName);
  51218. return Typeface::createSystemTypefaceFor (f);
  51219. }
  51220. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51221. {
  51222. defaultSans = newName;
  51223. }
  51224. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51225. {
  51226. return component.getMouseCursor();
  51227. }
  51228. void LookAndFeel::drawButtonBackground (Graphics& g,
  51229. Button& button,
  51230. const Colour& backgroundColour,
  51231. bool isMouseOverButton,
  51232. bool isButtonDown)
  51233. {
  51234. const int width = button.getWidth();
  51235. const int height = button.getHeight();
  51236. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51237. const float halfThickness = outlineThickness * 0.5f;
  51238. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51239. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51240. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51241. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51242. const Colour baseColour (createBaseColour (backgroundColour,
  51243. button.hasKeyboardFocus (true),
  51244. isMouseOverButton, isButtonDown)
  51245. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51246. drawGlassLozenge (g,
  51247. indentL,
  51248. indentT,
  51249. width - indentL - indentR,
  51250. height - indentT - indentB,
  51251. baseColour, outlineThickness, -1.0f,
  51252. button.isConnectedOnLeft(),
  51253. button.isConnectedOnRight(),
  51254. button.isConnectedOnTop(),
  51255. button.isConnectedOnBottom());
  51256. }
  51257. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51258. {
  51259. return button.getFont();
  51260. }
  51261. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51262. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51263. {
  51264. Font font (getFontForTextButton (button));
  51265. g.setFont (font);
  51266. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51267. : TextButton::textColourOffId)
  51268. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51269. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51270. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51271. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51272. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51273. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51274. g.drawFittedText (button.getButtonText(),
  51275. leftIndent,
  51276. yIndent,
  51277. button.getWidth() - leftIndent - rightIndent,
  51278. button.getHeight() - yIndent * 2,
  51279. Justification::centred, 2);
  51280. }
  51281. void LookAndFeel::drawTickBox (Graphics& g,
  51282. Component& component,
  51283. float x, float y, float w, float h,
  51284. const bool ticked,
  51285. const bool isEnabled,
  51286. const bool isMouseOverButton,
  51287. const bool isButtonDown)
  51288. {
  51289. const float boxSize = w * 0.7f;
  51290. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51291. createBaseColour (component.findColour (TextButton::buttonColourId)
  51292. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51293. true,
  51294. isMouseOverButton,
  51295. isButtonDown),
  51296. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51297. if (ticked)
  51298. {
  51299. Path tick;
  51300. tick.startNewSubPath (1.5f, 3.0f);
  51301. tick.lineTo (3.0f, 6.0f);
  51302. tick.lineTo (6.0f, 0.0f);
  51303. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51304. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51305. .translated (x, y));
  51306. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51307. }
  51308. }
  51309. void LookAndFeel::drawToggleButton (Graphics& g,
  51310. ToggleButton& button,
  51311. bool isMouseOverButton,
  51312. bool isButtonDown)
  51313. {
  51314. if (button.hasKeyboardFocus (true))
  51315. {
  51316. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51317. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51318. }
  51319. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51320. const float tickWidth = fontSize * 1.1f;
  51321. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51322. tickWidth, tickWidth,
  51323. button.getToggleState(),
  51324. button.isEnabled(),
  51325. isMouseOverButton,
  51326. isButtonDown);
  51327. g.setColour (button.findColour (ToggleButton::textColourId));
  51328. g.setFont (fontSize);
  51329. if (! button.isEnabled())
  51330. g.setOpacity (0.5f);
  51331. const int textX = (int) tickWidth + 5;
  51332. g.drawFittedText (button.getButtonText(),
  51333. textX, 0,
  51334. button.getWidth() - textX - 2, button.getHeight(),
  51335. Justification::centredLeft, 10);
  51336. }
  51337. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51338. {
  51339. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51340. const int tickWidth = jmin (24, button.getHeight());
  51341. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51342. button.getHeight());
  51343. }
  51344. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51345. const String& message,
  51346. const String& button1,
  51347. const String& button2,
  51348. const String& button3,
  51349. AlertWindow::AlertIconType iconType,
  51350. int numButtons,
  51351. Component* associatedComponent)
  51352. {
  51353. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51354. if (numButtons == 1)
  51355. {
  51356. aw->addButton (button1, 0,
  51357. KeyPress (KeyPress::escapeKey, 0, 0),
  51358. KeyPress (KeyPress::returnKey, 0, 0));
  51359. }
  51360. else
  51361. {
  51362. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51363. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51364. if (button1ShortCut == button2ShortCut)
  51365. button2ShortCut = KeyPress();
  51366. if (numButtons == 2)
  51367. {
  51368. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51369. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51370. }
  51371. else if (numButtons == 3)
  51372. {
  51373. aw->addButton (button1, 1, button1ShortCut);
  51374. aw->addButton (button2, 2, button2ShortCut);
  51375. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51376. }
  51377. }
  51378. return aw;
  51379. }
  51380. void LookAndFeel::drawAlertBox (Graphics& g,
  51381. AlertWindow& alert,
  51382. const Rectangle<int>& textArea,
  51383. TextLayout& textLayout)
  51384. {
  51385. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51386. int iconSpaceUsed = 0;
  51387. Justification alignment (Justification::horizontallyCentred);
  51388. const int iconWidth = 80;
  51389. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51390. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51391. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51392. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51393. iconSize, iconSize);
  51394. if (alert.getAlertType() != AlertWindow::NoIcon)
  51395. {
  51396. Path icon;
  51397. uint32 colour;
  51398. char character;
  51399. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51400. {
  51401. colour = 0x55ff5555;
  51402. character = '!';
  51403. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51404. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51405. (float) iconRect.getX(), (float) iconRect.getBottom());
  51406. icon = icon.createPathWithRoundedCorners (5.0f);
  51407. }
  51408. else
  51409. {
  51410. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51411. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51412. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51413. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51414. }
  51415. GlyphArrangement ga;
  51416. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51417. String::charToString (character),
  51418. (float) iconRect.getX(), (float) iconRect.getY(),
  51419. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51420. Justification::centred, false);
  51421. ga.createPath (icon);
  51422. icon.setUsingNonZeroWinding (false);
  51423. g.setColour (Colour (colour));
  51424. g.fillPath (icon);
  51425. iconSpaceUsed = iconWidth;
  51426. alignment = Justification::left;
  51427. }
  51428. g.setColour (alert.findColour (AlertWindow::textColourId));
  51429. textLayout.drawWithin (g,
  51430. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51431. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51432. alignment.getFlags() | Justification::top);
  51433. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51434. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51435. }
  51436. int LookAndFeel::getAlertBoxWindowFlags()
  51437. {
  51438. return ComponentPeer::windowAppearsOnTaskbar
  51439. | ComponentPeer::windowHasDropShadow;
  51440. }
  51441. int LookAndFeel::getAlertWindowButtonHeight()
  51442. {
  51443. return 28;
  51444. }
  51445. const Font LookAndFeel::getAlertWindowFont()
  51446. {
  51447. return Font (12.0f);
  51448. }
  51449. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51450. int width, int height,
  51451. double progress, const String& textToShow)
  51452. {
  51453. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51454. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51455. g.fillAll (background);
  51456. if (progress >= 0.0f && progress < 1.0f)
  51457. {
  51458. drawGlassLozenge (g, 1.0f, 1.0f,
  51459. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51460. (float) (height - 2),
  51461. foreground,
  51462. 0.5f, 0.0f,
  51463. true, true, true, true);
  51464. }
  51465. else
  51466. {
  51467. // spinning bar..
  51468. g.setColour (foreground);
  51469. const int stripeWidth = height * 2;
  51470. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51471. Path p;
  51472. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51473. p.addQuadrilateral (x, 0.0f,
  51474. x + stripeWidth * 0.5f, 0.0f,
  51475. x, (float) height,
  51476. x - stripeWidth * 0.5f, (float) height);
  51477. Image im (Image::ARGB, width, height, true);
  51478. {
  51479. Graphics g2 (im);
  51480. drawGlassLozenge (g2, 1.0f, 1.0f,
  51481. (float) (width - 2),
  51482. (float) (height - 2),
  51483. foreground,
  51484. 0.5f, 0.0f,
  51485. true, true, true, true);
  51486. }
  51487. g.setTiledImageFill (im, 0, 0, 0.85f);
  51488. g.fillPath (p);
  51489. }
  51490. if (textToShow.isNotEmpty())
  51491. {
  51492. g.setColour (Colour::contrasting (background, foreground));
  51493. g.setFont (height * 0.6f);
  51494. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51495. }
  51496. }
  51497. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51498. {
  51499. const float radius = jmin (w, h) * 0.4f;
  51500. const float thickness = radius * 0.15f;
  51501. Path p;
  51502. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51503. radius * 0.6f, thickness,
  51504. thickness * 0.5f);
  51505. const float cx = x + w * 0.5f;
  51506. const float cy = y + h * 0.5f;
  51507. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51508. for (int i = 0; i < 12; ++i)
  51509. {
  51510. const int n = (i + 12 - animationIndex) % 12;
  51511. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51512. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51513. .translated (cx, cy));
  51514. }
  51515. }
  51516. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51517. ScrollBar& scrollbar,
  51518. int width, int height,
  51519. int buttonDirection,
  51520. bool /*isScrollbarVertical*/,
  51521. bool /*isMouseOverButton*/,
  51522. bool isButtonDown)
  51523. {
  51524. Path p;
  51525. if (buttonDirection == 0)
  51526. p.addTriangle (width * 0.5f, height * 0.2f,
  51527. width * 0.1f, height * 0.7f,
  51528. width * 0.9f, height * 0.7f);
  51529. else if (buttonDirection == 1)
  51530. p.addTriangle (width * 0.8f, height * 0.5f,
  51531. width * 0.3f, height * 0.1f,
  51532. width * 0.3f, height * 0.9f);
  51533. else if (buttonDirection == 2)
  51534. p.addTriangle (width * 0.5f, height * 0.8f,
  51535. width * 0.1f, height * 0.3f,
  51536. width * 0.9f, height * 0.3f);
  51537. else if (buttonDirection == 3)
  51538. p.addTriangle (width * 0.2f, height * 0.5f,
  51539. width * 0.7f, height * 0.1f,
  51540. width * 0.7f, height * 0.9f);
  51541. if (isButtonDown)
  51542. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51543. else
  51544. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51545. g.fillPath (p);
  51546. g.setColour (Colour (0x80000000));
  51547. g.strokePath (p, PathStrokeType (0.5f));
  51548. }
  51549. void LookAndFeel::drawScrollbar (Graphics& g,
  51550. ScrollBar& scrollbar,
  51551. int x, int y,
  51552. int width, int height,
  51553. bool isScrollbarVertical,
  51554. int thumbStartPosition,
  51555. int thumbSize,
  51556. bool /*isMouseOver*/,
  51557. bool /*isMouseDown*/)
  51558. {
  51559. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51560. Path slotPath, thumbPath;
  51561. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51562. const float slotIndentx2 = slotIndent * 2.0f;
  51563. const float thumbIndent = slotIndent + 1.0f;
  51564. const float thumbIndentx2 = thumbIndent * 2.0f;
  51565. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51566. if (isScrollbarVertical)
  51567. {
  51568. slotPath.addRoundedRectangle (x + slotIndent,
  51569. y + slotIndent,
  51570. width - slotIndentx2,
  51571. height - slotIndentx2,
  51572. (width - slotIndentx2) * 0.5f);
  51573. if (thumbSize > 0)
  51574. thumbPath.addRoundedRectangle (x + thumbIndent,
  51575. thumbStartPosition + thumbIndent,
  51576. width - thumbIndentx2,
  51577. thumbSize - thumbIndentx2,
  51578. (width - thumbIndentx2) * 0.5f);
  51579. gx1 = (float) x;
  51580. gx2 = x + width * 0.7f;
  51581. }
  51582. else
  51583. {
  51584. slotPath.addRoundedRectangle (x + slotIndent,
  51585. y + slotIndent,
  51586. width - slotIndentx2,
  51587. height - slotIndentx2,
  51588. (height - slotIndentx2) * 0.5f);
  51589. if (thumbSize > 0)
  51590. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51591. y + thumbIndent,
  51592. thumbSize - thumbIndentx2,
  51593. height - thumbIndentx2,
  51594. (height - thumbIndentx2) * 0.5f);
  51595. gy1 = (float) y;
  51596. gy2 = y + height * 0.7f;
  51597. }
  51598. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51599. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51600. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51601. g.fillPath (slotPath);
  51602. if (isScrollbarVertical)
  51603. {
  51604. gx1 = x + width * 0.6f;
  51605. gx2 = (float) x + width;
  51606. }
  51607. else
  51608. {
  51609. gy1 = y + height * 0.6f;
  51610. gy2 = (float) y + height;
  51611. }
  51612. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51613. Colour (0x19000000), gx2, gy2, false));
  51614. g.fillPath (slotPath);
  51615. g.setColour (thumbColour);
  51616. g.fillPath (thumbPath);
  51617. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51618. Colours::transparentBlack, gx2, gy2, false));
  51619. g.saveState();
  51620. if (isScrollbarVertical)
  51621. g.reduceClipRegion (x + width / 2, y, width, height);
  51622. else
  51623. g.reduceClipRegion (x, y + height / 2, width, height);
  51624. g.fillPath (thumbPath);
  51625. g.restoreState();
  51626. g.setColour (Colour (0x4c000000));
  51627. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51628. }
  51629. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51630. {
  51631. return 0;
  51632. }
  51633. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51634. {
  51635. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51636. }
  51637. int LookAndFeel::getDefaultScrollbarWidth()
  51638. {
  51639. return 18;
  51640. }
  51641. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51642. {
  51643. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51644. : scrollbar.getHeight());
  51645. }
  51646. const Path LookAndFeel::getTickShape (const float height)
  51647. {
  51648. static const unsigned char tickShapeData[] =
  51649. {
  51650. 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,
  51651. 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,
  51652. 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,
  51653. 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,
  51654. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51655. };
  51656. Path p;
  51657. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51658. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51659. return p;
  51660. }
  51661. const Path LookAndFeel::getCrossShape (const float height)
  51662. {
  51663. static const unsigned char crossShapeData[] =
  51664. {
  51665. 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,
  51666. 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,
  51667. 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,
  51668. 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,
  51669. 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,
  51670. 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,
  51671. 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
  51672. };
  51673. Path p;
  51674. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51675. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51676. return p;
  51677. }
  51678. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51679. {
  51680. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51681. x += (w - boxSize) >> 1;
  51682. y += (h - boxSize) >> 1;
  51683. w = boxSize;
  51684. h = boxSize;
  51685. g.setColour (Colour (0xe5ffffff));
  51686. g.fillRect (x, y, w, h);
  51687. g.setColour (Colour (0x80000000));
  51688. g.drawRect (x, y, w, h);
  51689. const float size = boxSize / 2 + 1.0f;
  51690. const float centre = (float) (boxSize / 2);
  51691. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51692. if (isPlus)
  51693. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51694. }
  51695. void LookAndFeel::drawBubble (Graphics& g,
  51696. float tipX, float tipY,
  51697. float boxX, float boxY,
  51698. float boxW, float boxH)
  51699. {
  51700. int side = 0;
  51701. if (tipX < boxX)
  51702. side = 1;
  51703. else if (tipX > boxX + boxW)
  51704. side = 3;
  51705. else if (tipY > boxY + boxH)
  51706. side = 2;
  51707. const float indent = 2.0f;
  51708. Path p;
  51709. p.addBubble (boxX + indent,
  51710. boxY + indent,
  51711. boxW - indent * 2.0f,
  51712. boxH - indent * 2.0f,
  51713. 5.0f,
  51714. tipX, tipY,
  51715. side,
  51716. 0.5f,
  51717. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51718. //xxx need to take comp as param for colour
  51719. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51720. g.fillPath (p);
  51721. //xxx as above
  51722. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51723. g.strokePath (p, PathStrokeType (1.33f));
  51724. }
  51725. const Font LookAndFeel::getPopupMenuFont()
  51726. {
  51727. return Font (17.0f);
  51728. }
  51729. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51730. const bool isSeparator,
  51731. int standardMenuItemHeight,
  51732. int& idealWidth,
  51733. int& idealHeight)
  51734. {
  51735. if (isSeparator)
  51736. {
  51737. idealWidth = 50;
  51738. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51739. }
  51740. else
  51741. {
  51742. Font font (getPopupMenuFont());
  51743. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51744. font.setHeight (standardMenuItemHeight / 1.3f);
  51745. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51746. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51747. }
  51748. }
  51749. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51750. {
  51751. const Colour background (findColour (PopupMenu::backgroundColourId));
  51752. g.fillAll (background);
  51753. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51754. for (int i = 0; i < height; i += 3)
  51755. g.fillRect (0, i, width, 1);
  51756. #if ! JUCE_MAC
  51757. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51758. g.drawRect (0, 0, width, height);
  51759. #endif
  51760. }
  51761. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51762. int width, int height,
  51763. bool isScrollUpArrow)
  51764. {
  51765. const Colour background (findColour (PopupMenu::backgroundColourId));
  51766. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51767. background.withAlpha (0.0f),
  51768. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51769. false));
  51770. g.fillRect (1, 1, width - 2, height - 2);
  51771. const float hw = width * 0.5f;
  51772. const float arrowW = height * 0.3f;
  51773. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51774. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51775. Path p;
  51776. p.addTriangle (hw - arrowW, y1,
  51777. hw + arrowW, y1,
  51778. hw, y2);
  51779. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51780. g.fillPath (p);
  51781. }
  51782. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51783. int width, int height,
  51784. const bool isSeparator,
  51785. const bool isActive,
  51786. const bool isHighlighted,
  51787. const bool isTicked,
  51788. const bool hasSubMenu,
  51789. const String& text,
  51790. const String& shortcutKeyText,
  51791. Image* image,
  51792. const Colour* const textColourToUse)
  51793. {
  51794. const float halfH = height * 0.5f;
  51795. if (isSeparator)
  51796. {
  51797. const float separatorIndent = 5.5f;
  51798. g.setColour (Colour (0x33000000));
  51799. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51800. g.setColour (Colour (0x66ffffff));
  51801. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51802. }
  51803. else
  51804. {
  51805. Colour textColour (findColour (PopupMenu::textColourId));
  51806. if (textColourToUse != 0)
  51807. textColour = *textColourToUse;
  51808. if (isHighlighted)
  51809. {
  51810. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51811. g.fillRect (1, 1, width - 2, height - 2);
  51812. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51813. }
  51814. else
  51815. {
  51816. g.setColour (textColour);
  51817. }
  51818. if (! isActive)
  51819. g.setOpacity (0.3f);
  51820. Font font (getPopupMenuFont());
  51821. if (font.getHeight() > height / 1.3f)
  51822. font.setHeight (height / 1.3f);
  51823. g.setFont (font);
  51824. const int leftBorder = (height * 5) / 4;
  51825. const int rightBorder = 4;
  51826. if (image != 0)
  51827. {
  51828. g.drawImageWithin (image,
  51829. 2, 1, leftBorder - 4, height - 2,
  51830. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51831. }
  51832. else if (isTicked)
  51833. {
  51834. const Path tick (getTickShape (1.0f));
  51835. const float th = font.getAscent();
  51836. const float ty = halfH - th * 0.5f;
  51837. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51838. th, true));
  51839. }
  51840. g.drawFittedText (text,
  51841. leftBorder, 0,
  51842. width - (leftBorder + rightBorder), height,
  51843. Justification::centredLeft, 1);
  51844. if (shortcutKeyText.isNotEmpty())
  51845. {
  51846. Font f2 (font);
  51847. f2.setHeight (f2.getHeight() * 0.75f);
  51848. f2.setHorizontalScale (0.95f);
  51849. g.setFont (f2);
  51850. g.drawText (shortcutKeyText,
  51851. leftBorder,
  51852. 0,
  51853. width - (leftBorder + rightBorder + 4),
  51854. height,
  51855. Justification::centredRight,
  51856. true);
  51857. }
  51858. if (hasSubMenu)
  51859. {
  51860. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51861. const float x = width - height * 0.6f;
  51862. Path p;
  51863. p.addTriangle (x, halfH - arrowH * 0.5f,
  51864. x, halfH + arrowH * 0.5f,
  51865. x + arrowH * 0.6f, halfH);
  51866. g.fillPath (p);
  51867. }
  51868. }
  51869. }
  51870. int LookAndFeel::getMenuWindowFlags()
  51871. {
  51872. return ComponentPeer::windowHasDropShadow;
  51873. }
  51874. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51875. bool, MenuBarComponent& menuBar)
  51876. {
  51877. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51878. if (menuBar.isEnabled())
  51879. {
  51880. drawShinyButtonShape (g,
  51881. -4.0f, 0.0f,
  51882. width + 8.0f, (float) height,
  51883. 0.0f,
  51884. baseColour,
  51885. 0.4f,
  51886. true, true, true, true);
  51887. }
  51888. else
  51889. {
  51890. g.fillAll (baseColour);
  51891. }
  51892. }
  51893. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51894. {
  51895. return Font (menuBar.getHeight() * 0.7f);
  51896. }
  51897. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51898. {
  51899. return getMenuBarFont (menuBar, itemIndex, itemText)
  51900. .getStringWidth (itemText) + menuBar.getHeight();
  51901. }
  51902. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51903. int width, int height,
  51904. int itemIndex,
  51905. const String& itemText,
  51906. bool isMouseOverItem,
  51907. bool isMenuOpen,
  51908. bool /*isMouseOverBar*/,
  51909. MenuBarComponent& menuBar)
  51910. {
  51911. if (! menuBar.isEnabled())
  51912. {
  51913. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51914. .withMultipliedAlpha (0.5f));
  51915. }
  51916. else if (isMenuOpen || isMouseOverItem)
  51917. {
  51918. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51919. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51920. }
  51921. else
  51922. {
  51923. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51924. }
  51925. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51926. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51927. }
  51928. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51929. TextEditor& textEditor)
  51930. {
  51931. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51932. }
  51933. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51934. {
  51935. if (textEditor.isEnabled())
  51936. {
  51937. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51938. {
  51939. const int border = 2;
  51940. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51941. g.drawRect (0, 0, width, height, border);
  51942. g.setOpacity (1.0f);
  51943. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51944. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51945. }
  51946. else
  51947. {
  51948. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51949. g.drawRect (0, 0, width, height);
  51950. g.setOpacity (1.0f);
  51951. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51952. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51953. }
  51954. }
  51955. }
  51956. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51957. const bool isButtonDown,
  51958. int buttonX, int buttonY,
  51959. int buttonW, int buttonH,
  51960. ComboBox& box)
  51961. {
  51962. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51963. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51964. {
  51965. g.setColour (box.findColour (TextButton::buttonColourId));
  51966. g.drawRect (0, 0, width, height, 2);
  51967. }
  51968. else
  51969. {
  51970. g.setColour (box.findColour (ComboBox::outlineColourId));
  51971. g.drawRect (0, 0, width, height);
  51972. }
  51973. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51974. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51975. box.hasKeyboardFocus (true),
  51976. false, isButtonDown)
  51977. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51978. drawGlassLozenge (g,
  51979. buttonX + outlineThickness, buttonY + outlineThickness,
  51980. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51981. baseColour, outlineThickness, -1.0f,
  51982. true, true, true, true);
  51983. if (box.isEnabled())
  51984. {
  51985. const float arrowX = 0.3f;
  51986. const float arrowH = 0.2f;
  51987. Path p;
  51988. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51989. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51990. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51991. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51992. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51993. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51994. g.setColour (box.findColour (ComboBox::arrowColourId));
  51995. g.fillPath (p);
  51996. }
  51997. }
  51998. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51999. {
  52000. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52001. }
  52002. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52003. {
  52004. return new Label (String::empty, String::empty);
  52005. }
  52006. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52007. {
  52008. label.setBounds (1, 1,
  52009. box.getWidth() + 3 - box.getHeight(),
  52010. box.getHeight() - 2);
  52011. label.setFont (getComboBoxFont (box));
  52012. }
  52013. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52014. {
  52015. g.fillAll (label.findColour (Label::backgroundColourId));
  52016. if (! label.isBeingEdited())
  52017. {
  52018. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52019. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52020. g.setFont (label.getFont());
  52021. g.drawFittedText (label.getText(),
  52022. label.getHorizontalBorderSize(),
  52023. label.getVerticalBorderSize(),
  52024. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52025. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52026. label.getJustificationType(),
  52027. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52028. label.getMinimumHorizontalScale());
  52029. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52030. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52031. }
  52032. else if (label.isEnabled())
  52033. {
  52034. g.setColour (label.findColour (Label::outlineColourId));
  52035. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52036. }
  52037. }
  52038. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52039. int x, int y,
  52040. int width, int height,
  52041. float /*sliderPos*/,
  52042. float /*minSliderPos*/,
  52043. float /*maxSliderPos*/,
  52044. const Slider::SliderStyle /*style*/,
  52045. Slider& slider)
  52046. {
  52047. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52048. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52049. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52050. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52051. Path indent;
  52052. if (slider.isHorizontal())
  52053. {
  52054. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52055. const float ih = sliderRadius;
  52056. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52057. gradCol2, 0.0f, iy + ih, false));
  52058. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52059. width + sliderRadius, ih,
  52060. 5.0f);
  52061. g.fillPath (indent);
  52062. }
  52063. else
  52064. {
  52065. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52066. const float iw = sliderRadius;
  52067. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52068. gradCol2, ix + iw, 0.0f, false));
  52069. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52070. iw, height + sliderRadius,
  52071. 5.0f);
  52072. g.fillPath (indent);
  52073. }
  52074. g.setColour (Colour (0x4c000000));
  52075. g.strokePath (indent, PathStrokeType (0.5f));
  52076. }
  52077. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52078. int x, int y,
  52079. int width, int height,
  52080. float sliderPos,
  52081. float minSliderPos,
  52082. float maxSliderPos,
  52083. const Slider::SliderStyle style,
  52084. Slider& slider)
  52085. {
  52086. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52087. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52088. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52089. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52090. slider.isMouseButtonDown() && slider.isEnabled()));
  52091. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52092. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52093. {
  52094. float kx, ky;
  52095. if (style == Slider::LinearVertical)
  52096. {
  52097. kx = x + width * 0.5f;
  52098. ky = sliderPos;
  52099. }
  52100. else
  52101. {
  52102. kx = sliderPos;
  52103. ky = y + height * 0.5f;
  52104. }
  52105. drawGlassSphere (g,
  52106. kx - sliderRadius,
  52107. ky - sliderRadius,
  52108. sliderRadius * 2.0f,
  52109. knobColour, outlineThickness);
  52110. }
  52111. else
  52112. {
  52113. if (style == Slider::ThreeValueVertical)
  52114. {
  52115. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52116. sliderPos - sliderRadius,
  52117. sliderRadius * 2.0f,
  52118. knobColour, outlineThickness);
  52119. }
  52120. else if (style == Slider::ThreeValueHorizontal)
  52121. {
  52122. drawGlassSphere (g,sliderPos - sliderRadius,
  52123. y + height * 0.5f - sliderRadius,
  52124. sliderRadius * 2.0f,
  52125. knobColour, outlineThickness);
  52126. }
  52127. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52128. {
  52129. const float sr = jmin (sliderRadius, width * 0.4f);
  52130. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52131. minSliderPos - sliderRadius,
  52132. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52133. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52134. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52135. }
  52136. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52137. {
  52138. const float sr = jmin (sliderRadius, height * 0.4f);
  52139. drawGlassPointer (g, minSliderPos - sr,
  52140. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52141. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52142. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52143. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52144. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52145. }
  52146. }
  52147. }
  52148. void LookAndFeel::drawLinearSlider (Graphics& g,
  52149. int x, int y,
  52150. int width, int height,
  52151. float sliderPos,
  52152. float minSliderPos,
  52153. float maxSliderPos,
  52154. const Slider::SliderStyle style,
  52155. Slider& slider)
  52156. {
  52157. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52158. if (style == Slider::LinearBar)
  52159. {
  52160. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52161. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52162. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52163. false,
  52164. isMouseOver,
  52165. isMouseOver || slider.isMouseButtonDown()));
  52166. drawShinyButtonShape (g,
  52167. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52168. baseColour,
  52169. slider.isEnabled() ? 0.9f : 0.3f,
  52170. true, true, true, true);
  52171. }
  52172. else
  52173. {
  52174. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52175. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52176. }
  52177. }
  52178. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52179. {
  52180. return jmin (7,
  52181. slider.getHeight() / 2,
  52182. slider.getWidth() / 2) + 2;
  52183. }
  52184. void LookAndFeel::drawRotarySlider (Graphics& g,
  52185. int x, int y,
  52186. int width, int height,
  52187. float sliderPos,
  52188. const float rotaryStartAngle,
  52189. const float rotaryEndAngle,
  52190. Slider& slider)
  52191. {
  52192. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52193. const float centreX = x + width * 0.5f;
  52194. const float centreY = y + height * 0.5f;
  52195. const float rx = centreX - radius;
  52196. const float ry = centreY - radius;
  52197. const float rw = radius * 2.0f;
  52198. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52199. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52200. if (radius > 12.0f)
  52201. {
  52202. if (slider.isEnabled())
  52203. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52204. else
  52205. g.setColour (Colour (0x80808080));
  52206. const float thickness = 0.7f;
  52207. {
  52208. Path filledArc;
  52209. filledArc.addPieSegment (rx, ry, rw, rw,
  52210. rotaryStartAngle,
  52211. angle,
  52212. thickness);
  52213. g.fillPath (filledArc);
  52214. }
  52215. if (thickness > 0)
  52216. {
  52217. const float innerRadius = radius * 0.2f;
  52218. Path p;
  52219. p.addTriangle (-innerRadius, 0.0f,
  52220. 0.0f, -radius * thickness * 1.1f,
  52221. innerRadius, 0.0f);
  52222. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52223. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52224. }
  52225. if (slider.isEnabled())
  52226. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52227. else
  52228. g.setColour (Colour (0x80808080));
  52229. Path outlineArc;
  52230. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52231. outlineArc.closeSubPath();
  52232. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52233. }
  52234. else
  52235. {
  52236. if (slider.isEnabled())
  52237. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52238. else
  52239. g.setColour (Colour (0x80808080));
  52240. Path p;
  52241. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52242. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52243. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52244. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52245. }
  52246. }
  52247. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52248. {
  52249. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52250. }
  52251. class SliderLabelComp : public Label
  52252. {
  52253. public:
  52254. SliderLabelComp() : Label (String::empty, String::empty) {}
  52255. ~SliderLabelComp() {}
  52256. void mouseWheelMove (const MouseEvent&, float, float) {}
  52257. };
  52258. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52259. {
  52260. Label* const l = new SliderLabelComp();
  52261. l->setJustificationType (Justification::centred);
  52262. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52263. l->setColour (Label::backgroundColourId,
  52264. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52265. : slider.findColour (Slider::textBoxBackgroundColourId));
  52266. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52267. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52268. l->setColour (TextEditor::backgroundColourId,
  52269. slider.findColour (Slider::textBoxBackgroundColourId)
  52270. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52271. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52272. return l;
  52273. }
  52274. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52275. {
  52276. return 0;
  52277. }
  52278. static const TextLayout layoutTooltipText (const String& text) throw()
  52279. {
  52280. const float tooltipFontSize = 12.0f;
  52281. const int maxToolTipWidth = 400;
  52282. const Font f (tooltipFontSize, Font::bold);
  52283. TextLayout tl (text, f);
  52284. tl.layout (maxToolTipWidth, Justification::left, true);
  52285. return tl;
  52286. }
  52287. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52288. {
  52289. const TextLayout tl (layoutTooltipText (tipText));
  52290. width = tl.getWidth() + 14;
  52291. height = tl.getHeight() + 6;
  52292. }
  52293. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52294. {
  52295. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52296. const Colour textCol (findColour (TooltipWindow::textColourId));
  52297. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52298. g.setColour (findColour (TooltipWindow::outlineColourId));
  52299. g.drawRect (0, 0, width, height, 1);
  52300. #endif
  52301. const TextLayout tl (layoutTooltipText (text));
  52302. g.setColour (findColour (TooltipWindow::textColourId));
  52303. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52304. }
  52305. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52306. {
  52307. return new TextButton (text, TRANS("click to browse for a different file"));
  52308. }
  52309. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52310. ComboBox* filenameBox,
  52311. Button* browseButton)
  52312. {
  52313. browseButton->setSize (80, filenameComp.getHeight());
  52314. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52315. if (tb != 0)
  52316. tb->changeWidthToFitText();
  52317. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52318. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52319. }
  52320. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52321. int imageX, int imageY, int imageW, int imageH,
  52322. const Colour& overlayColour,
  52323. float imageOpacity,
  52324. ImageButton& button)
  52325. {
  52326. if (! button.isEnabled())
  52327. imageOpacity *= 0.3f;
  52328. if (! overlayColour.isOpaque())
  52329. {
  52330. g.setOpacity (imageOpacity);
  52331. g.drawImage (image, imageX, imageY, imageW, imageH,
  52332. 0, 0, image->getWidth(), image->getHeight(), false);
  52333. }
  52334. if (! overlayColour.isTransparent())
  52335. {
  52336. g.setColour (overlayColour);
  52337. g.drawImage (image, imageX, imageY, imageW, imageH,
  52338. 0, 0, image->getWidth(), image->getHeight(), true);
  52339. }
  52340. }
  52341. void LookAndFeel::drawCornerResizer (Graphics& g,
  52342. int w, int h,
  52343. bool /*isMouseOver*/,
  52344. bool /*isMouseDragging*/)
  52345. {
  52346. const float lineThickness = jmin (w, h) * 0.075f;
  52347. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52348. {
  52349. g.setColour (Colours::lightgrey);
  52350. g.drawLine (w * i,
  52351. h + 1.0f,
  52352. w + 1.0f,
  52353. h * i,
  52354. lineThickness);
  52355. g.setColour (Colours::darkgrey);
  52356. g.drawLine (w * i + lineThickness,
  52357. h + 1.0f,
  52358. w + 1.0f,
  52359. h * i + lineThickness,
  52360. lineThickness);
  52361. }
  52362. }
  52363. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52364. const BorderSize& /*borders*/)
  52365. {
  52366. }
  52367. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52368. const BorderSize& /*border*/, ResizableWindow& window)
  52369. {
  52370. g.fillAll (window.getBackgroundColour());
  52371. }
  52372. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52373. const BorderSize& border, ResizableWindow&)
  52374. {
  52375. g.setColour (Colour (0x80000000));
  52376. g.drawRect (0, 0, w, h);
  52377. g.setColour (Colour (0x19000000));
  52378. g.drawRect (border.getLeft() - 1,
  52379. border.getTop() - 1,
  52380. w + 2 - border.getLeftAndRight(),
  52381. h + 2 - border.getTopAndBottom());
  52382. }
  52383. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52384. Graphics& g, int w, int h,
  52385. int titleSpaceX, int titleSpaceW,
  52386. const Image* icon,
  52387. bool drawTitleTextOnLeft)
  52388. {
  52389. const bool isActive = window.isActiveWindow();
  52390. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52391. 0.0f, 0.0f,
  52392. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52393. 0.0f, (float) h, false));
  52394. g.fillAll();
  52395. Font font (h * 0.65f, Font::bold);
  52396. g.setFont (font);
  52397. int textW = font.getStringWidth (window.getName());
  52398. int iconW = 0;
  52399. int iconH = 0;
  52400. if (icon != 0)
  52401. {
  52402. iconH = (int) font.getHeight();
  52403. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52404. }
  52405. textW = jmin (titleSpaceW, textW + iconW);
  52406. int textX = drawTitleTextOnLeft ? titleSpaceX
  52407. : jmax (titleSpaceX, (w - textW) / 2);
  52408. if (textX + textW > titleSpaceX + titleSpaceW)
  52409. textX = titleSpaceX + titleSpaceW - textW;
  52410. if (icon != 0)
  52411. {
  52412. g.setOpacity (isActive ? 1.0f : 0.6f);
  52413. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52414. RectanglePlacement::centred, false);
  52415. textX += iconW;
  52416. textW -= iconW;
  52417. }
  52418. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52419. g.setColour (findColour (DocumentWindow::textColourId));
  52420. else
  52421. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52422. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52423. }
  52424. class GlassWindowButton : public Button
  52425. {
  52426. public:
  52427. GlassWindowButton (const String& name, const Colour& col,
  52428. const Path& normalShape_,
  52429. const Path& toggledShape_) throw()
  52430. : Button (name),
  52431. colour (col),
  52432. normalShape (normalShape_),
  52433. toggledShape (toggledShape_)
  52434. {
  52435. }
  52436. ~GlassWindowButton()
  52437. {
  52438. }
  52439. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52440. {
  52441. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52442. if (! isEnabled())
  52443. alpha *= 0.5f;
  52444. float x = 0, y = 0, diam;
  52445. if (getWidth() < getHeight())
  52446. {
  52447. diam = (float) getWidth();
  52448. y = (getHeight() - getWidth()) * 0.5f;
  52449. }
  52450. else
  52451. {
  52452. diam = (float) getHeight();
  52453. y = (getWidth() - getHeight()) * 0.5f;
  52454. }
  52455. x += diam * 0.05f;
  52456. y += diam * 0.05f;
  52457. diam *= 0.9f;
  52458. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52459. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52460. g.fillEllipse (x, y, diam, diam);
  52461. x += 2.0f;
  52462. y += 2.0f;
  52463. diam -= 4.0f;
  52464. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52465. Path& p = getToggleState() ? toggledShape : normalShape;
  52466. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52467. diam * 0.4f, diam * 0.4f, true));
  52468. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52469. g.fillPath (p, t);
  52470. }
  52471. juce_UseDebuggingNewOperator
  52472. private:
  52473. Colour colour;
  52474. Path normalShape, toggledShape;
  52475. GlassWindowButton (const GlassWindowButton&);
  52476. GlassWindowButton& operator= (const GlassWindowButton&);
  52477. };
  52478. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52479. {
  52480. Path shape;
  52481. const float crossThickness = 0.25f;
  52482. if (buttonType == DocumentWindow::closeButton)
  52483. {
  52484. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52485. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52486. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52487. }
  52488. else if (buttonType == DocumentWindow::minimiseButton)
  52489. {
  52490. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52491. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52492. }
  52493. else if (buttonType == DocumentWindow::maximiseButton)
  52494. {
  52495. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52496. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52497. Path fullscreenShape;
  52498. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52499. fullscreenShape.lineTo (0.0f, 100.0f);
  52500. fullscreenShape.lineTo (0.0f, 0.0f);
  52501. fullscreenShape.lineTo (100.0f, 0.0f);
  52502. fullscreenShape.lineTo (100.0f, 45.0f);
  52503. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52504. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52505. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52506. }
  52507. jassertfalse
  52508. return 0;
  52509. }
  52510. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52511. int titleBarX,
  52512. int titleBarY,
  52513. int titleBarW,
  52514. int titleBarH,
  52515. Button* minimiseButton,
  52516. Button* maximiseButton,
  52517. Button* closeButton,
  52518. bool positionTitleBarButtonsOnLeft)
  52519. {
  52520. const int buttonW = titleBarH - titleBarH / 8;
  52521. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52522. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52523. if (closeButton != 0)
  52524. {
  52525. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52526. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52527. }
  52528. if (positionTitleBarButtonsOnLeft)
  52529. swapVariables (minimiseButton, maximiseButton);
  52530. if (maximiseButton != 0)
  52531. {
  52532. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52533. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52534. }
  52535. if (minimiseButton != 0)
  52536. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52537. }
  52538. int LookAndFeel::getDefaultMenuBarHeight()
  52539. {
  52540. return 24;
  52541. }
  52542. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52543. {
  52544. return new DropShadower (0.4f, 1, 5, 10);
  52545. }
  52546. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52547. int w, int h,
  52548. bool /*isVerticalBar*/,
  52549. bool isMouseOver,
  52550. bool isMouseDragging)
  52551. {
  52552. float alpha = 0.5f;
  52553. if (isMouseOver || isMouseDragging)
  52554. {
  52555. g.fillAll (Colour (0x190000ff));
  52556. alpha = 1.0f;
  52557. }
  52558. const float cx = w * 0.5f;
  52559. const float cy = h * 0.5f;
  52560. const float cr = jmin (w, h) * 0.4f;
  52561. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52562. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52563. true));
  52564. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52565. }
  52566. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52567. const String& text,
  52568. const Justification& position,
  52569. GroupComponent& group)
  52570. {
  52571. const float textH = 15.0f;
  52572. const float indent = 3.0f;
  52573. const float textEdgeGap = 4.0f;
  52574. float cs = 5.0f;
  52575. Font f (textH);
  52576. Path p;
  52577. float x = indent;
  52578. float y = f.getAscent() - 3.0f;
  52579. float w = jmax (0.0f, width - x * 2.0f);
  52580. float h = jmax (0.0f, height - y - indent);
  52581. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52582. const float cs2 = 2.0f * cs;
  52583. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52584. float textX = cs + textEdgeGap;
  52585. if (position.testFlags (Justification::horizontallyCentred))
  52586. textX = cs + (w - cs2 - textW) * 0.5f;
  52587. else if (position.testFlags (Justification::right))
  52588. textX = w - cs - textW - textEdgeGap;
  52589. p.startNewSubPath (x + textX + textW, y);
  52590. p.lineTo (x + w - cs, y);
  52591. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52592. p.lineTo (x + w, y + h - cs);
  52593. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52594. p.lineTo (x + cs, y + h);
  52595. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52596. p.lineTo (x, y + cs);
  52597. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52598. p.lineTo (x + textX, y);
  52599. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52600. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52601. .withMultipliedAlpha (alpha));
  52602. g.strokePath (p, PathStrokeType (2.0f));
  52603. g.setColour (group.findColour (GroupComponent::textColourId)
  52604. .withMultipliedAlpha (alpha));
  52605. g.setFont (f);
  52606. g.drawText (text,
  52607. roundToInt (x + textX), 0,
  52608. roundToInt (textW),
  52609. roundToInt (textH),
  52610. Justification::centred, true);
  52611. }
  52612. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52613. {
  52614. return 1 + tabDepth / 3;
  52615. }
  52616. int LookAndFeel::getTabButtonSpaceAroundImage()
  52617. {
  52618. return 4;
  52619. }
  52620. void LookAndFeel::createTabButtonShape (Path& p,
  52621. int width, int height,
  52622. int /*tabIndex*/,
  52623. const String& /*text*/,
  52624. Button& /*button*/,
  52625. TabbedButtonBar::Orientation orientation,
  52626. const bool /*isMouseOver*/,
  52627. const bool /*isMouseDown*/,
  52628. const bool /*isFrontTab*/)
  52629. {
  52630. const float w = (float) width;
  52631. const float h = (float) height;
  52632. float length = w;
  52633. float depth = h;
  52634. if (orientation == TabbedButtonBar::TabsAtLeft
  52635. || orientation == TabbedButtonBar::TabsAtRight)
  52636. {
  52637. swapVariables (length, depth);
  52638. }
  52639. const float indent = (float) getTabButtonOverlap ((int) depth);
  52640. const float overhang = 4.0f;
  52641. if (orientation == TabbedButtonBar::TabsAtLeft)
  52642. {
  52643. p.startNewSubPath (w, 0.0f);
  52644. p.lineTo (0.0f, indent);
  52645. p.lineTo (0.0f, h - indent);
  52646. p.lineTo (w, h);
  52647. p.lineTo (w + overhang, h + overhang);
  52648. p.lineTo (w + overhang, -overhang);
  52649. }
  52650. else if (orientation == TabbedButtonBar::TabsAtRight)
  52651. {
  52652. p.startNewSubPath (0.0f, 0.0f);
  52653. p.lineTo (w, indent);
  52654. p.lineTo (w, h - indent);
  52655. p.lineTo (0.0f, h);
  52656. p.lineTo (-overhang, h + overhang);
  52657. p.lineTo (-overhang, -overhang);
  52658. }
  52659. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52660. {
  52661. p.startNewSubPath (0.0f, 0.0f);
  52662. p.lineTo (indent, h);
  52663. p.lineTo (w - indent, h);
  52664. p.lineTo (w, 0.0f);
  52665. p.lineTo (w + overhang, -overhang);
  52666. p.lineTo (-overhang, -overhang);
  52667. }
  52668. else
  52669. {
  52670. p.startNewSubPath (0.0f, h);
  52671. p.lineTo (indent, 0.0f);
  52672. p.lineTo (w - indent, 0.0f);
  52673. p.lineTo (w, h);
  52674. p.lineTo (w + overhang, h + overhang);
  52675. p.lineTo (-overhang, h + overhang);
  52676. }
  52677. p.closeSubPath();
  52678. p = p.createPathWithRoundedCorners (3.0f);
  52679. }
  52680. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52681. const Path& path,
  52682. const Colour& preferredColour,
  52683. int /*tabIndex*/,
  52684. const String& /*text*/,
  52685. Button& button,
  52686. TabbedButtonBar::Orientation /*orientation*/,
  52687. const bool /*isMouseOver*/,
  52688. const bool /*isMouseDown*/,
  52689. const bool isFrontTab)
  52690. {
  52691. g.setColour (isFrontTab ? preferredColour
  52692. : preferredColour.withMultipliedAlpha (0.9f));
  52693. g.fillPath (path);
  52694. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52695. : TabbedButtonBar::tabOutlineColourId, false)
  52696. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52697. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52698. }
  52699. void LookAndFeel::drawTabButtonText (Graphics& g,
  52700. int x, int y, int w, int h,
  52701. const Colour& preferredBackgroundColour,
  52702. int /*tabIndex*/,
  52703. const String& text,
  52704. Button& button,
  52705. TabbedButtonBar::Orientation orientation,
  52706. const bool isMouseOver,
  52707. const bool isMouseDown,
  52708. const bool isFrontTab)
  52709. {
  52710. int length = w;
  52711. int depth = h;
  52712. if (orientation == TabbedButtonBar::TabsAtLeft
  52713. || orientation == TabbedButtonBar::TabsAtRight)
  52714. {
  52715. swapVariables (length, depth);
  52716. }
  52717. Font font (depth * 0.6f);
  52718. font.setUnderline (button.hasKeyboardFocus (false));
  52719. GlyphArrangement textLayout;
  52720. textLayout.addFittedText (font, text.trim(),
  52721. 0.0f, 0.0f, (float) length, (float) depth,
  52722. Justification::centred,
  52723. jmax (1, depth / 12));
  52724. AffineTransform transform;
  52725. if (orientation == TabbedButtonBar::TabsAtLeft)
  52726. {
  52727. transform = transform.rotated (float_Pi * -0.5f)
  52728. .translated ((float) x, (float) (y + h));
  52729. }
  52730. else if (orientation == TabbedButtonBar::TabsAtRight)
  52731. {
  52732. transform = transform.rotated (float_Pi * 0.5f)
  52733. .translated ((float) (x + w), (float) y);
  52734. }
  52735. else
  52736. {
  52737. transform = transform.translated ((float) x, (float) y);
  52738. }
  52739. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52740. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52741. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52742. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52743. else
  52744. g.setColour (preferredBackgroundColour.contrasting());
  52745. if (! (isMouseOver || isMouseDown))
  52746. g.setOpacity (0.8f);
  52747. if (! button.isEnabled())
  52748. g.setOpacity (0.3f);
  52749. textLayout.draw (g, transform);
  52750. }
  52751. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52752. const String& text,
  52753. int tabDepth,
  52754. Button&)
  52755. {
  52756. Font f (tabDepth * 0.6f);
  52757. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52758. }
  52759. void LookAndFeel::drawTabButton (Graphics& g,
  52760. int w, int h,
  52761. const Colour& preferredColour,
  52762. int tabIndex,
  52763. const String& text,
  52764. Button& button,
  52765. TabbedButtonBar::Orientation orientation,
  52766. const bool isMouseOver,
  52767. const bool isMouseDown,
  52768. const bool isFrontTab)
  52769. {
  52770. int length = w;
  52771. int depth = h;
  52772. if (orientation == TabbedButtonBar::TabsAtLeft
  52773. || orientation == TabbedButtonBar::TabsAtRight)
  52774. {
  52775. swapVariables (length, depth);
  52776. }
  52777. Path tabShape;
  52778. createTabButtonShape (tabShape, w, h,
  52779. tabIndex, text, button, orientation,
  52780. isMouseOver, isMouseDown, isFrontTab);
  52781. fillTabButtonShape (g, tabShape, preferredColour,
  52782. tabIndex, text, button, orientation,
  52783. isMouseOver, isMouseDown, isFrontTab);
  52784. const int indent = getTabButtonOverlap (depth);
  52785. int x = 0, y = 0;
  52786. if (orientation == TabbedButtonBar::TabsAtLeft
  52787. || orientation == TabbedButtonBar::TabsAtRight)
  52788. {
  52789. y += indent;
  52790. h -= indent * 2;
  52791. }
  52792. else
  52793. {
  52794. x += indent;
  52795. w -= indent * 2;
  52796. }
  52797. drawTabButtonText (g, x, y, w, h, preferredColour,
  52798. tabIndex, text, button, orientation,
  52799. isMouseOver, isMouseDown, isFrontTab);
  52800. }
  52801. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52802. int w, int h,
  52803. TabbedButtonBar& tabBar,
  52804. TabbedButtonBar::Orientation orientation)
  52805. {
  52806. const float shadowSize = 0.2f;
  52807. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52808. Rectangle<int> shadowRect;
  52809. if (orientation == TabbedButtonBar::TabsAtLeft)
  52810. {
  52811. x1 = (float) w;
  52812. x2 = w * (1.0f - shadowSize);
  52813. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52814. }
  52815. else if (orientation == TabbedButtonBar::TabsAtRight)
  52816. {
  52817. x2 = w * shadowSize;
  52818. shadowRect.setBounds (0, 0, (int) x2, h);
  52819. }
  52820. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52821. {
  52822. y2 = h * shadowSize;
  52823. shadowRect.setBounds (0, 0, w, (int) y2);
  52824. }
  52825. else
  52826. {
  52827. y1 = (float) h;
  52828. y2 = h * (1.0f - shadowSize);
  52829. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52830. }
  52831. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52832. Colours::transparentBlack, x2, y2, false));
  52833. shadowRect.expand (2, 2);
  52834. g.fillRect (shadowRect);
  52835. g.setColour (Colour (0x80000000));
  52836. if (orientation == TabbedButtonBar::TabsAtLeft)
  52837. {
  52838. g.fillRect (w - 1, 0, 1, h);
  52839. }
  52840. else if (orientation == TabbedButtonBar::TabsAtRight)
  52841. {
  52842. g.fillRect (0, 0, 1, h);
  52843. }
  52844. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52845. {
  52846. g.fillRect (0, 0, w, 1);
  52847. }
  52848. else
  52849. {
  52850. g.fillRect (0, h - 1, w, 1);
  52851. }
  52852. }
  52853. Button* LookAndFeel::createTabBarExtrasButton()
  52854. {
  52855. const float thickness = 7.0f;
  52856. const float indent = 22.0f;
  52857. Path p;
  52858. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52859. DrawablePath ellipse;
  52860. ellipse.setPath (p);
  52861. ellipse.setFill (Colour (0x99ffffff));
  52862. p.clear();
  52863. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52864. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52865. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52866. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52867. p.setUsingNonZeroWinding (false);
  52868. DrawablePath dp;
  52869. dp.setPath (p);
  52870. dp.setFill (Colour (0x59000000));
  52871. DrawableComposite normalImage;
  52872. normalImage.insertDrawable (ellipse);
  52873. normalImage.insertDrawable (dp);
  52874. dp.setFill (Colour (0xcc000000));
  52875. DrawableComposite overImage;
  52876. overImage.insertDrawable (ellipse);
  52877. overImage.insertDrawable (dp);
  52878. DrawableButton* db = new DrawableButton ("tabs", DrawableButton::ImageFitted);
  52879. db->setImages (&normalImage, &overImage, 0);
  52880. return db;
  52881. }
  52882. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52883. {
  52884. g.fillAll (Colours::white);
  52885. const int w = header.getWidth();
  52886. const int h = header.getHeight();
  52887. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52888. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52889. false));
  52890. g.fillRect (0, h / 2, w, h);
  52891. g.setColour (Colour (0x33000000));
  52892. g.fillRect (0, h - 1, w, 1);
  52893. for (int i = header.getNumColumns (true); --i >= 0;)
  52894. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52895. }
  52896. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52897. int width, int height,
  52898. bool isMouseOver, bool isMouseDown,
  52899. int columnFlags)
  52900. {
  52901. if (isMouseDown)
  52902. g.fillAll (Colour (0x8899aadd));
  52903. else if (isMouseOver)
  52904. g.fillAll (Colour (0x5599aadd));
  52905. int rightOfText = width - 4;
  52906. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52907. {
  52908. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52909. const float bottom = height - top;
  52910. const float w = height * 0.5f;
  52911. const float x = rightOfText - (w * 1.25f);
  52912. rightOfText = (int) x;
  52913. Path sortArrow;
  52914. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52915. g.setColour (Colour (0x99000000));
  52916. g.fillPath (sortArrow);
  52917. }
  52918. g.setColour (Colours::black);
  52919. g.setFont (height * 0.5f, Font::bold);
  52920. const int textX = 4;
  52921. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52922. }
  52923. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52924. {
  52925. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52926. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52927. background.darker (0.1f),
  52928. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52929. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52930. false));
  52931. g.fillAll();
  52932. }
  52933. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52934. {
  52935. return createTabBarExtrasButton();
  52936. }
  52937. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52938. bool isMouseOver, bool isMouseDown,
  52939. ToolbarItemComponent& component)
  52940. {
  52941. if (isMouseDown)
  52942. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52943. else if (isMouseOver)
  52944. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52945. }
  52946. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52947. const String& text, ToolbarItemComponent& component)
  52948. {
  52949. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52950. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52951. const float fontHeight = jmin (14.0f, height * 0.85f);
  52952. g.setFont (fontHeight);
  52953. g.drawFittedText (text,
  52954. x, y, width, height,
  52955. Justification::centred,
  52956. jmax (1, height / (int) fontHeight));
  52957. }
  52958. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52959. bool isOpen, int width, int height)
  52960. {
  52961. const int buttonSize = (height * 3) / 4;
  52962. const int buttonIndent = (height - buttonSize) / 2;
  52963. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52964. const int textX = buttonIndent * 2 + buttonSize + 2;
  52965. g.setColour (Colours::black);
  52966. g.setFont (height * 0.7f, Font::bold);
  52967. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52968. }
  52969. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52970. PropertyComponent&)
  52971. {
  52972. g.setColour (Colour (0x66ffffff));
  52973. g.fillRect (0, 0, width, height - 1);
  52974. }
  52975. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52976. PropertyComponent& component)
  52977. {
  52978. g.setColour (Colours::black);
  52979. if (! component.isEnabled())
  52980. g.setOpacity (0.6f);
  52981. g.setFont (jmin (height, 24) * 0.65f);
  52982. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52983. g.drawFittedText (component.getName(),
  52984. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52985. Justification::centredLeft, 2);
  52986. }
  52987. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52988. {
  52989. return Rectangle<int> (component.getWidth() / 3, 1,
  52990. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52991. }
  52992. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52993. const String& instructions,
  52994. GlyphArrangement& text,
  52995. int width)
  52996. {
  52997. text.clear();
  52998. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52999. 8.0f, 22.0f, width - 16.0f,
  53000. Justification::centred);
  53001. text.addJustifiedText (Font (14.0f), instructions,
  53002. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53003. Justification::centred);
  53004. }
  53005. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53006. const String& filename, Image* icon,
  53007. const String& fileSizeDescription,
  53008. const String& fileTimeDescription,
  53009. const bool isDirectory,
  53010. const bool isItemSelected,
  53011. const int /*itemIndex*/)
  53012. {
  53013. if (isItemSelected)
  53014. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53015. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53016. g.setFont (height * 0.7f);
  53017. Image* im = icon;
  53018. Image* toRelease = 0;
  53019. if (im == 0)
  53020. {
  53021. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53022. : getDefaultDocumentFileImage());
  53023. }
  53024. const int x = 32;
  53025. if (im != 0)
  53026. {
  53027. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53028. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53029. false);
  53030. ImageCache::release (toRelease);
  53031. }
  53032. if (width > 450 && ! isDirectory)
  53033. {
  53034. const int sizeX = roundToInt (width * 0.7f);
  53035. const int dateX = roundToInt (width * 0.8f);
  53036. g.drawFittedText (filename,
  53037. x, 0, sizeX - x, height,
  53038. Justification::centredLeft, 1);
  53039. g.setFont (height * 0.5f);
  53040. g.setColour (Colours::darkgrey);
  53041. if (! isDirectory)
  53042. {
  53043. g.drawFittedText (fileSizeDescription,
  53044. sizeX, 0, dateX - sizeX - 8, height,
  53045. Justification::centredRight, 1);
  53046. g.drawFittedText (fileTimeDescription,
  53047. dateX, 0, width - 8 - dateX, height,
  53048. Justification::centredRight, 1);
  53049. }
  53050. }
  53051. else
  53052. {
  53053. g.drawFittedText (filename,
  53054. x, 0, width - x, height,
  53055. Justification::centredLeft, 1);
  53056. }
  53057. }
  53058. Button* LookAndFeel::createFileBrowserGoUpButton()
  53059. {
  53060. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53061. Path arrowPath;
  53062. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53063. DrawablePath arrowImage;
  53064. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53065. arrowImage.setPath (arrowPath);
  53066. goUpButton->setImages (&arrowImage);
  53067. return goUpButton;
  53068. }
  53069. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53070. DirectoryContentsDisplayComponent* fileListComponent,
  53071. FilePreviewComponent* previewComp,
  53072. ComboBox* currentPathBox,
  53073. TextEditor* filenameBox,
  53074. Button* goUpButton)
  53075. {
  53076. const int x = 8;
  53077. int w = browserComp.getWidth() - x - x;
  53078. if (previewComp != 0)
  53079. {
  53080. const int previewWidth = w / 3;
  53081. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53082. w -= previewWidth + 4;
  53083. }
  53084. int y = 4;
  53085. const int controlsHeight = 22;
  53086. const int bottomSectionHeight = controlsHeight + 8;
  53087. const int upButtonWidth = 50;
  53088. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53089. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53090. y += controlsHeight + 4;
  53091. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53092. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53093. y = listAsComp->getBottom() + 4;
  53094. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53095. }
  53096. Image* LookAndFeel::getDefaultFolderImage()
  53097. {
  53098. 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,
  53099. 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,
  53100. 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,
  53101. 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,
  53102. 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,
  53103. 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,
  53104. 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,
  53105. 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,
  53106. 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,
  53107. 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,
  53108. 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,
  53109. 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,
  53110. 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,
  53111. 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,
  53112. 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,
  53113. 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,
  53114. 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,
  53115. 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,
  53116. 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,
  53117. 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,
  53118. 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,
  53119. 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,
  53120. 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,
  53121. 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,
  53122. 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,
  53123. 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,
  53124. 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,
  53125. 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,
  53126. 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,
  53127. 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,
  53128. 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,
  53129. 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,
  53130. 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,
  53131. 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,
  53132. 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,
  53133. 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,
  53134. 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,
  53135. 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,
  53136. 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,
  53137. 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,
  53138. 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,
  53139. 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,
  53140. 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,
  53141. 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};
  53142. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53143. }
  53144. Image* LookAndFeel::getDefaultDocumentFileImage()
  53145. {
  53146. 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,
  53147. 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,
  53148. 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,
  53149. 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,
  53150. 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,
  53151. 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,
  53152. 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,
  53153. 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,
  53154. 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,
  53155. 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,
  53156. 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,
  53157. 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,
  53158. 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,
  53159. 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,
  53160. 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,
  53161. 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,
  53162. 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,
  53163. 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,
  53164. 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,
  53165. 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,
  53166. 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,
  53167. 174,66,96,130,0,0};
  53168. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53169. }
  53170. void LookAndFeel::playAlertSound()
  53171. {
  53172. PlatformUtilities::beep();
  53173. }
  53174. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53175. {
  53176. g.setColour (Colours::white.withAlpha (0.7f));
  53177. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53178. g.setColour (Colours::black.withAlpha (0.2f));
  53179. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53180. const int totalBlocks = 7;
  53181. const int numBlocks = roundToInt (totalBlocks * level);
  53182. const float w = (width - 6.0f) / (float) totalBlocks;
  53183. for (int i = 0; i < totalBlocks; ++i)
  53184. {
  53185. if (i >= numBlocks)
  53186. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53187. else
  53188. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53189. : Colours::red);
  53190. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53191. }
  53192. }
  53193. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53194. {
  53195. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53196. if (keyDescription.isNotEmpty())
  53197. {
  53198. if (button.isEnabled())
  53199. {
  53200. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53201. g.fillAll (textColour.withAlpha (alpha));
  53202. g.setOpacity (0.3f);
  53203. g.drawBevel (0, 0, width, height, 2);
  53204. }
  53205. g.setColour (textColour);
  53206. g.setFont (height * 0.6f);
  53207. g.drawFittedText (keyDescription,
  53208. 3, 0, width - 6, height,
  53209. Justification::centred, 1);
  53210. }
  53211. else
  53212. {
  53213. const float thickness = 7.0f;
  53214. const float indent = 22.0f;
  53215. Path p;
  53216. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53217. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53218. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53219. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53220. p.setUsingNonZeroWinding (false);
  53221. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53222. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53223. }
  53224. if (button.hasKeyboardFocus (false))
  53225. {
  53226. g.setColour (textColour.withAlpha (0.4f));
  53227. g.drawRect (0, 0, width, height);
  53228. }
  53229. }
  53230. static void createRoundedPath (Path& p,
  53231. const float x, const float y,
  53232. const float w, const float h,
  53233. const float cs,
  53234. const bool curveTopLeft, const bool curveTopRight,
  53235. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53236. {
  53237. const float cs2 = 2.0f * cs;
  53238. if (curveTopLeft)
  53239. {
  53240. p.startNewSubPath (x, y + cs);
  53241. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53242. }
  53243. else
  53244. {
  53245. p.startNewSubPath (x, y);
  53246. }
  53247. if (curveTopRight)
  53248. {
  53249. p.lineTo (x + w - cs, y);
  53250. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53251. }
  53252. else
  53253. {
  53254. p.lineTo (x + w, y);
  53255. }
  53256. if (curveBottomRight)
  53257. {
  53258. p.lineTo (x + w, y + h - cs);
  53259. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53260. }
  53261. else
  53262. {
  53263. p.lineTo (x + w, y + h);
  53264. }
  53265. if (curveBottomLeft)
  53266. {
  53267. p.lineTo (x + cs, y + h);
  53268. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53269. }
  53270. else
  53271. {
  53272. p.lineTo (x, y + h);
  53273. }
  53274. p.closeSubPath();
  53275. }
  53276. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53277. float x, float y, float w, float h,
  53278. float maxCornerSize,
  53279. const Colour& baseColour,
  53280. const float strokeWidth,
  53281. const bool flatOnLeft,
  53282. const bool flatOnRight,
  53283. const bool flatOnTop,
  53284. const bool flatOnBottom) throw()
  53285. {
  53286. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53287. return;
  53288. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53289. Path outline;
  53290. createRoundedPath (outline, x, y, w, h, cs,
  53291. ! (flatOnLeft || flatOnTop),
  53292. ! (flatOnRight || flatOnTop),
  53293. ! (flatOnLeft || flatOnBottom),
  53294. ! (flatOnRight || flatOnBottom));
  53295. ColourGradient cg (baseColour, 0.0f, y,
  53296. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53297. false);
  53298. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53299. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53300. g.setGradientFill (cg);
  53301. g.fillPath (outline);
  53302. g.setColour (Colour (0x80000000));
  53303. g.strokePath (outline, PathStrokeType (strokeWidth));
  53304. }
  53305. void LookAndFeel::drawGlassSphere (Graphics& g,
  53306. const float x, const float y,
  53307. const float diameter,
  53308. const Colour& colour,
  53309. const float outlineThickness) throw()
  53310. {
  53311. if (diameter <= outlineThickness)
  53312. return;
  53313. Path p;
  53314. p.addEllipse (x, y, diameter, diameter);
  53315. {
  53316. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53317. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53318. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53319. g.setGradientFill (cg);
  53320. g.fillPath (p);
  53321. }
  53322. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53323. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53324. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53325. ColourGradient cg (Colours::transparentBlack,
  53326. x + diameter * 0.5f, y + diameter * 0.5f,
  53327. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53328. x, y + diameter * 0.5f, true);
  53329. cg.addColour (0.7, Colours::transparentBlack);
  53330. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53331. g.setGradientFill (cg);
  53332. g.fillPath (p);
  53333. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53334. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53335. }
  53336. void LookAndFeel::drawGlassPointer (Graphics& g,
  53337. const float x, const float y,
  53338. const float diameter,
  53339. const Colour& colour, const float outlineThickness,
  53340. const int direction) throw()
  53341. {
  53342. if (diameter <= outlineThickness)
  53343. return;
  53344. Path p;
  53345. p.startNewSubPath (x + diameter * 0.5f, y);
  53346. p.lineTo (x + diameter, y + diameter * 0.6f);
  53347. p.lineTo (x + diameter, y + diameter);
  53348. p.lineTo (x, y + diameter);
  53349. p.lineTo (x, y + diameter * 0.6f);
  53350. p.closeSubPath();
  53351. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53352. {
  53353. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53354. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53355. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53356. g.setGradientFill (cg);
  53357. g.fillPath (p);
  53358. }
  53359. ColourGradient cg (Colours::transparentBlack,
  53360. x + diameter * 0.5f, y + diameter * 0.5f,
  53361. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53362. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53363. cg.addColour (0.5, Colours::transparentBlack);
  53364. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53365. g.setGradientFill (cg);
  53366. g.fillPath (p);
  53367. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53368. g.strokePath (p, PathStrokeType (outlineThickness));
  53369. }
  53370. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53371. const float x, const float y,
  53372. const float width, const float height,
  53373. const Colour& colour,
  53374. const float outlineThickness,
  53375. const float cornerSize,
  53376. const bool flatOnLeft,
  53377. const bool flatOnRight,
  53378. const bool flatOnTop,
  53379. const bool flatOnBottom) throw()
  53380. {
  53381. if (width <= outlineThickness || height <= outlineThickness)
  53382. return;
  53383. const int intX = (int) x;
  53384. const int intY = (int) y;
  53385. const int intW = (int) width;
  53386. const int intH = (int) height;
  53387. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53388. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53389. const int intEdge = (int) edgeBlurRadius;
  53390. Path outline;
  53391. createRoundedPath (outline, x, y, width, height, cs,
  53392. ! (flatOnLeft || flatOnTop),
  53393. ! (flatOnRight || flatOnTop),
  53394. ! (flatOnLeft || flatOnBottom),
  53395. ! (flatOnRight || flatOnBottom));
  53396. {
  53397. ColourGradient cg (colour.darker (0.2f), 0, y,
  53398. colour.darker (0.2f), 0, y + height, false);
  53399. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53400. cg.addColour (0.4, colour);
  53401. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53402. g.setGradientFill (cg);
  53403. g.fillPath (outline);
  53404. }
  53405. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53406. colour.darker (0.2f), x, y + height * 0.5f, true);
  53407. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53408. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53409. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53410. {
  53411. g.saveState();
  53412. g.setGradientFill (cg);
  53413. g.reduceClipRegion (intX, intY, intEdge, intH);
  53414. g.fillPath (outline);
  53415. g.restoreState();
  53416. }
  53417. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53418. {
  53419. cg.x1 = x + width - edgeBlurRadius;
  53420. cg.x2 = x + width;
  53421. g.saveState();
  53422. g.setGradientFill (cg);
  53423. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53424. g.fillPath (outline);
  53425. g.restoreState();
  53426. }
  53427. {
  53428. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53429. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53430. Path highlight;
  53431. createRoundedPath (highlight,
  53432. x + leftIndent,
  53433. y + cs * 0.1f,
  53434. width - (leftIndent + rightIndent),
  53435. height * 0.4f, cs * 0.4f,
  53436. ! (flatOnLeft || flatOnTop),
  53437. ! (flatOnRight || flatOnTop),
  53438. ! (flatOnLeft || flatOnBottom),
  53439. ! (flatOnRight || flatOnBottom));
  53440. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53441. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53442. g.fillPath (highlight);
  53443. }
  53444. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53445. g.strokePath (outline, PathStrokeType (outlineThickness));
  53446. }
  53447. END_JUCE_NAMESPACE
  53448. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53449. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53450. BEGIN_JUCE_NAMESPACE
  53451. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53452. {
  53453. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53454. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53455. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53456. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53457. setColour (Slider::thumbColourId, Colours::white);
  53458. setColour (Slider::trackColourId, Colour (0x7f000000));
  53459. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53460. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53461. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53462. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53463. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53464. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53465. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53466. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53467. }
  53468. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53469. {
  53470. }
  53471. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53472. Button& button,
  53473. const Colour& backgroundColour,
  53474. bool isMouseOverButton,
  53475. bool isButtonDown)
  53476. {
  53477. const int width = button.getWidth();
  53478. const int height = button.getHeight();
  53479. const float indent = 2.0f;
  53480. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53481. roundToInt (height * 0.4f));
  53482. Path p;
  53483. p.addRoundedRectangle (indent, indent,
  53484. width - indent * 2.0f,
  53485. height - indent * 2.0f,
  53486. (float) cornerSize);
  53487. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53488. if (isMouseOverButton)
  53489. {
  53490. if (isButtonDown)
  53491. bc = bc.brighter();
  53492. else if (bc.getBrightness() > 0.5f)
  53493. bc = bc.darker (0.1f);
  53494. else
  53495. bc = bc.brighter (0.1f);
  53496. }
  53497. g.setColour (bc);
  53498. g.fillPath (p);
  53499. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53500. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53501. }
  53502. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53503. Component& /*component*/,
  53504. float x, float y, float w, float h,
  53505. const bool ticked,
  53506. const bool isEnabled,
  53507. const bool /*isMouseOverButton*/,
  53508. const bool isButtonDown)
  53509. {
  53510. Path box;
  53511. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53512. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53513. : Colours::lightgrey.withAlpha (0.1f));
  53514. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53515. g.fillPath (box, trans);
  53516. g.setColour (Colours::black.withAlpha (0.6f));
  53517. g.strokePath (box, PathStrokeType (0.9f), trans);
  53518. if (ticked)
  53519. {
  53520. Path tick;
  53521. tick.startNewSubPath (1.5f, 3.0f);
  53522. tick.lineTo (3.0f, 6.0f);
  53523. tick.lineTo (6.0f, 0.0f);
  53524. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53525. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53526. }
  53527. }
  53528. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53529. ToggleButton& button,
  53530. bool isMouseOverButton,
  53531. bool isButtonDown)
  53532. {
  53533. if (button.hasKeyboardFocus (true))
  53534. {
  53535. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53536. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53537. }
  53538. const int tickWidth = jmin (20, button.getHeight() - 4);
  53539. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53540. (float) tickWidth, (float) tickWidth,
  53541. button.getToggleState(),
  53542. button.isEnabled(),
  53543. isMouseOverButton,
  53544. isButtonDown);
  53545. g.setColour (button.findColour (ToggleButton::textColourId));
  53546. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53547. if (! button.isEnabled())
  53548. g.setOpacity (0.5f);
  53549. const int textX = tickWidth + 5;
  53550. g.drawFittedText (button.getButtonText(),
  53551. textX, 4,
  53552. button.getWidth() - textX - 2, button.getHeight() - 8,
  53553. Justification::centredLeft, 10);
  53554. }
  53555. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53556. int width, int height,
  53557. double progress, const String& textToShow)
  53558. {
  53559. if (progress < 0 || progress >= 1.0)
  53560. {
  53561. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53562. }
  53563. else
  53564. {
  53565. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53566. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53567. g.fillAll (background);
  53568. g.setColour (foreground);
  53569. g.fillRect (1, 1,
  53570. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53571. height - 2);
  53572. if (textToShow.isNotEmpty())
  53573. {
  53574. g.setColour (Colour::contrasting (background, foreground));
  53575. g.setFont (height * 0.6f);
  53576. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53577. }
  53578. }
  53579. }
  53580. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53581. ScrollBar& bar,
  53582. int width, int height,
  53583. int buttonDirection,
  53584. bool isScrollbarVertical,
  53585. bool isMouseOverButton,
  53586. bool isButtonDown)
  53587. {
  53588. if (isScrollbarVertical)
  53589. width -= 2;
  53590. else
  53591. height -= 2;
  53592. Path p;
  53593. if (buttonDirection == 0)
  53594. p.addTriangle (width * 0.5f, height * 0.2f,
  53595. width * 0.1f, height * 0.7f,
  53596. width * 0.9f, height * 0.7f);
  53597. else if (buttonDirection == 1)
  53598. p.addTriangle (width * 0.8f, height * 0.5f,
  53599. width * 0.3f, height * 0.1f,
  53600. width * 0.3f, height * 0.9f);
  53601. else if (buttonDirection == 2)
  53602. p.addTriangle (width * 0.5f, height * 0.8f,
  53603. width * 0.1f, height * 0.3f,
  53604. width * 0.9f, height * 0.3f);
  53605. else if (buttonDirection == 3)
  53606. p.addTriangle (width * 0.2f, height * 0.5f,
  53607. width * 0.7f, height * 0.1f,
  53608. width * 0.7f, height * 0.9f);
  53609. if (isButtonDown)
  53610. g.setColour (Colours::white);
  53611. else if (isMouseOverButton)
  53612. g.setColour (Colours::white.withAlpha (0.7f));
  53613. else
  53614. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53615. g.fillPath (p);
  53616. g.setColour (Colours::black.withAlpha (0.5f));
  53617. g.strokePath (p, PathStrokeType (0.5f));
  53618. }
  53619. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53620. ScrollBar& bar,
  53621. int x, int y,
  53622. int width, int height,
  53623. bool isScrollbarVertical,
  53624. int thumbStartPosition,
  53625. int thumbSize,
  53626. bool isMouseOver,
  53627. bool isMouseDown)
  53628. {
  53629. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53630. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53631. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53632. if (thumbSize > 0.0f)
  53633. {
  53634. Rectangle<int> thumb;
  53635. if (isScrollbarVertical)
  53636. {
  53637. width -= 2;
  53638. g.fillRect (x + roundToInt (width * 0.35f), y,
  53639. roundToInt (width * 0.3f), height);
  53640. thumb.setBounds (x + 1, thumbStartPosition,
  53641. width - 2, thumbSize);
  53642. }
  53643. else
  53644. {
  53645. height -= 2;
  53646. g.fillRect (x, y + roundToInt (height * 0.35f),
  53647. width, roundToInt (height * 0.3f));
  53648. thumb.setBounds (thumbStartPosition, y + 1,
  53649. thumbSize, height - 2);
  53650. }
  53651. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53652. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53653. g.fillRect (thumb);
  53654. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53655. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53656. if (thumbSize > 16)
  53657. {
  53658. for (int i = 3; --i >= 0;)
  53659. {
  53660. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53661. g.setColour (Colours::black.withAlpha (0.15f));
  53662. if (isScrollbarVertical)
  53663. {
  53664. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53665. g.setColour (Colours::white.withAlpha (0.15f));
  53666. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53667. }
  53668. else
  53669. {
  53670. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53671. g.setColour (Colours::white.withAlpha (0.15f));
  53672. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53673. }
  53674. }
  53675. }
  53676. }
  53677. }
  53678. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53679. {
  53680. return &scrollbarShadow;
  53681. }
  53682. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53683. {
  53684. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53685. g.setColour (Colours::black.withAlpha (0.6f));
  53686. g.drawRect (0, 0, width, height);
  53687. }
  53688. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53689. bool, MenuBarComponent& menuBar)
  53690. {
  53691. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53692. }
  53693. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53694. {
  53695. if (textEditor.isEnabled())
  53696. {
  53697. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53698. g.drawRect (0, 0, width, height);
  53699. }
  53700. }
  53701. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53702. const bool isButtonDown,
  53703. int buttonX, int buttonY,
  53704. int buttonW, int buttonH,
  53705. ComboBox& box)
  53706. {
  53707. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53708. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53709. : ComboBox::backgroundColourId));
  53710. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53711. g.setColour (box.findColour (ComboBox::outlineColourId));
  53712. g.drawRect (0, 0, width, height);
  53713. const float arrowX = 0.2f;
  53714. const float arrowH = 0.3f;
  53715. if (box.isEnabled())
  53716. {
  53717. Path p;
  53718. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53719. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53720. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53721. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53722. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53723. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53724. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53725. : ComboBox::buttonColourId));
  53726. g.fillPath (p);
  53727. }
  53728. }
  53729. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53730. {
  53731. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53732. f.setHorizontalScale (0.9f);
  53733. return f;
  53734. }
  53735. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53736. {
  53737. Path p;
  53738. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53739. g.setColour (fill);
  53740. g.fillPath (p);
  53741. g.setColour (outline);
  53742. g.strokePath (p, PathStrokeType (0.3f));
  53743. }
  53744. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53745. int x, int y,
  53746. int w, int h,
  53747. float sliderPos,
  53748. float minSliderPos,
  53749. float maxSliderPos,
  53750. const Slider::SliderStyle style,
  53751. Slider& slider)
  53752. {
  53753. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53754. if (style == Slider::LinearBar)
  53755. {
  53756. g.setColour (slider.findColour (Slider::thumbColourId));
  53757. g.fillRect (x, y, (int) sliderPos - x, h);
  53758. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53759. g.drawRect (x, y, (int) sliderPos - x, h);
  53760. }
  53761. else
  53762. {
  53763. g.setColour (slider.findColour (Slider::trackColourId)
  53764. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53765. if (slider.isHorizontal())
  53766. {
  53767. g.fillRect (x, y + roundToInt (h * 0.6f),
  53768. w, roundToInt (h * 0.2f));
  53769. }
  53770. else
  53771. {
  53772. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53773. jmin (4, roundToInt (w * 0.2f)), h);
  53774. }
  53775. float alpha = 0.35f;
  53776. if (slider.isEnabled())
  53777. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53778. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53779. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53780. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53781. {
  53782. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53783. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53784. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53785. fill, outline);
  53786. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53787. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53788. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53789. fill, outline);
  53790. }
  53791. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53792. {
  53793. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53794. minSliderPos - 7.0f, y + h * 0.9f ,
  53795. minSliderPos, y + h * 0.9f,
  53796. fill, outline);
  53797. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53798. maxSliderPos, y + h * 0.9f,
  53799. maxSliderPos + 7.0f, y + h * 0.9f,
  53800. fill, outline);
  53801. }
  53802. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53803. {
  53804. drawTriangle (g, sliderPos, y + h * 0.9f,
  53805. sliderPos - 7.0f, y + h * 0.2f,
  53806. sliderPos + 7.0f, y + h * 0.2f,
  53807. fill, outline);
  53808. }
  53809. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53810. {
  53811. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53812. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53813. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53814. fill, outline);
  53815. }
  53816. }
  53817. }
  53818. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53819. {
  53820. if (isIncrement)
  53821. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53822. else
  53823. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53824. }
  53825. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53826. {
  53827. return &scrollbarShadow;
  53828. }
  53829. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53830. {
  53831. return 8;
  53832. }
  53833. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53834. int w, int h,
  53835. bool isMouseOver,
  53836. bool isMouseDragging)
  53837. {
  53838. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53839. : Colours::darkgrey);
  53840. const float lineThickness = jmin (w, h) * 0.1f;
  53841. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53842. {
  53843. g.drawLine (w * i,
  53844. h + 1.0f,
  53845. w + 1.0f,
  53846. h * i,
  53847. lineThickness);
  53848. }
  53849. }
  53850. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53851. {
  53852. Path shape;
  53853. if (buttonType == DocumentWindow::closeButton)
  53854. {
  53855. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53856. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53857. ShapeButton* const b = new ShapeButton ("close",
  53858. Colour (0x7fff3333),
  53859. Colour (0xd7ff3333),
  53860. Colour (0xf7ff3333));
  53861. b->setShape (shape, true, true, true);
  53862. return b;
  53863. }
  53864. else if (buttonType == DocumentWindow::minimiseButton)
  53865. {
  53866. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53867. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53868. DrawablePath dp;
  53869. dp.setPath (shape);
  53870. dp.setFill (Colours::black.withAlpha (0.3f));
  53871. b->setImages (&dp);
  53872. return b;
  53873. }
  53874. else if (buttonType == DocumentWindow::maximiseButton)
  53875. {
  53876. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53877. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53878. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53879. DrawablePath dp;
  53880. dp.setPath (shape);
  53881. dp.setFill (Colours::black.withAlpha (0.3f));
  53882. b->setImages (&dp);
  53883. return b;
  53884. }
  53885. jassertfalse
  53886. return 0;
  53887. }
  53888. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53889. int titleBarX,
  53890. int titleBarY,
  53891. int titleBarW,
  53892. int titleBarH,
  53893. Button* minimiseButton,
  53894. Button* maximiseButton,
  53895. Button* closeButton,
  53896. bool positionTitleBarButtonsOnLeft)
  53897. {
  53898. titleBarY += titleBarH / 8;
  53899. titleBarH -= titleBarH / 4;
  53900. const int buttonW = titleBarH;
  53901. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53902. : titleBarX + titleBarW - buttonW - 4;
  53903. if (closeButton != 0)
  53904. {
  53905. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53906. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53907. : -(buttonW + buttonW / 5);
  53908. }
  53909. if (positionTitleBarButtonsOnLeft)
  53910. swapVariables (minimiseButton, maximiseButton);
  53911. if (maximiseButton != 0)
  53912. {
  53913. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53914. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53915. }
  53916. if (minimiseButton != 0)
  53917. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53918. }
  53919. END_JUCE_NAMESPACE
  53920. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53921. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53922. BEGIN_JUCE_NAMESPACE
  53923. class DummyMenuComponent : public Component
  53924. {
  53925. DummyMenuComponent (const DummyMenuComponent&);
  53926. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53927. public:
  53928. DummyMenuComponent() {}
  53929. ~DummyMenuComponent() {}
  53930. void inputAttemptWhenModal()
  53931. {
  53932. exitModalState (0);
  53933. }
  53934. };
  53935. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53936. : model (0),
  53937. itemUnderMouse (-1),
  53938. currentPopupIndex (-1),
  53939. indexToShowAgain (-1),
  53940. lastMouseX (0),
  53941. lastMouseY (0),
  53942. inModalState (false)
  53943. {
  53944. setRepaintsOnMouseActivity (true);
  53945. setWantsKeyboardFocus (false);
  53946. setMouseClickGrabsKeyboardFocus (false);
  53947. setModel (model_);
  53948. }
  53949. MenuBarComponent::~MenuBarComponent()
  53950. {
  53951. setModel (0);
  53952. Desktop::getInstance().removeGlobalMouseListener (this);
  53953. currentPopup = 0;
  53954. }
  53955. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53956. {
  53957. if (model != newModel)
  53958. {
  53959. if (model != 0)
  53960. model->removeListener (this);
  53961. model = newModel;
  53962. if (model != 0)
  53963. model->addListener (this);
  53964. repaint();
  53965. menuBarItemsChanged (0);
  53966. }
  53967. }
  53968. void MenuBarComponent::paint (Graphics& g)
  53969. {
  53970. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53971. getLookAndFeel().drawMenuBarBackground (g,
  53972. getWidth(),
  53973. getHeight(),
  53974. isMouseOverBar,
  53975. *this);
  53976. if (model != 0)
  53977. {
  53978. for (int i = 0; i < menuNames.size(); ++i)
  53979. {
  53980. g.saveState();
  53981. g.setOrigin (xPositions [i], 0);
  53982. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53983. getLookAndFeel().drawMenuBarItem (g,
  53984. xPositions[i + 1] - xPositions[i],
  53985. getHeight(),
  53986. i,
  53987. menuNames[i],
  53988. i == itemUnderMouse,
  53989. i == currentPopupIndex,
  53990. isMouseOverBar,
  53991. *this);
  53992. g.restoreState();
  53993. }
  53994. }
  53995. }
  53996. void MenuBarComponent::resized()
  53997. {
  53998. xPositions.clear();
  53999. int x = 2;
  54000. xPositions.add (x);
  54001. for (int i = 0; i < menuNames.size(); ++i)
  54002. {
  54003. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54004. xPositions.add (x);
  54005. }
  54006. }
  54007. int MenuBarComponent::getItemAt (const int x, const int y)
  54008. {
  54009. for (int i = 0; i < xPositions.size(); ++i)
  54010. if (x >= xPositions[i] && x < xPositions[i + 1])
  54011. return reallyContains (x, y, true) ? i : -1;
  54012. return -1;
  54013. }
  54014. void MenuBarComponent::repaintMenuItem (int index)
  54015. {
  54016. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54017. {
  54018. const int x1 = xPositions [index];
  54019. const int x2 = xPositions [index + 1];
  54020. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54021. }
  54022. }
  54023. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54024. {
  54025. const int newItem = getItemAt (x, y);
  54026. if (itemUnderMouse != newItem)
  54027. {
  54028. repaintMenuItem (itemUnderMouse);
  54029. itemUnderMouse = newItem;
  54030. repaintMenuItem (itemUnderMouse);
  54031. }
  54032. }
  54033. void MenuBarComponent::hideCurrentMenu()
  54034. {
  54035. currentPopup = 0;
  54036. repaint();
  54037. }
  54038. void MenuBarComponent::showMenu (int index)
  54039. {
  54040. if (index != currentPopupIndex)
  54041. {
  54042. if (inModalState)
  54043. {
  54044. hideCurrentMenu();
  54045. indexToShowAgain = index;
  54046. return;
  54047. }
  54048. indexToShowAgain = -1;
  54049. currentPopupIndex = -1;
  54050. itemUnderMouse = index;
  54051. currentPopup = 0;
  54052. menuBarItemsChanged (0);
  54053. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  54054. Component::SafePointer<Component> deletionChecker (this);
  54055. enterModalState (false);
  54056. inModalState = true;
  54057. int result = 0;
  54058. ApplicationCommandManager* managerOfChosenCommand = 0;
  54059. Desktop::getInstance().addGlobalMouseListener (this);
  54060. for (;;)
  54061. {
  54062. const int x = getScreenX() + xPositions [itemUnderMouse];
  54063. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54064. currentPopupIndex = itemUnderMouse;
  54065. indexToShowAgain = -1;
  54066. repaint();
  54067. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54068. {
  54069. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54070. menuNames [itemUnderMouse]));
  54071. if (m.lookAndFeel == 0)
  54072. m.setLookAndFeel (&getLookAndFeel());
  54073. currentPopup = m.createMenuComponent (x, getScreenY(),
  54074. w, getHeight(),
  54075. 0, w, 0, 0,
  54076. true, this,
  54077. &managerOfChosenCommand,
  54078. this);
  54079. }
  54080. if (currentPopup == 0)
  54081. {
  54082. currentPopup = new DummyMenuComponent();
  54083. addAndMakeVisible (currentPopup);
  54084. }
  54085. currentPopup->enterModalState (false);
  54086. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54087. // be stuck behind other comps that are already modal..
  54088. result = currentPopup->runModalLoop();
  54089. if (deletionChecker == 0)
  54090. return;
  54091. const int lastPopupIndex = currentPopupIndex;
  54092. currentPopup = 0;
  54093. currentPopupIndex = -1;
  54094. if (result != 0)
  54095. {
  54096. topLevelIndexClicked = lastPopupIndex;
  54097. break;
  54098. }
  54099. else if (indexToShowAgain >= 0)
  54100. {
  54101. menuBarItemsChanged (0);
  54102. repaint();
  54103. itemUnderMouse = indexToShowAgain;
  54104. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54105. break;
  54106. }
  54107. else
  54108. {
  54109. break;
  54110. }
  54111. }
  54112. Desktop::getInstance().removeGlobalMouseListener (this);
  54113. inModalState = false;
  54114. exitModalState (0);
  54115. if (prevFocused != 0)
  54116. prevFocused->grabKeyboardFocus();
  54117. const Point<int> mousePos (getMouseXYRelative());
  54118. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54119. repaint();
  54120. if (result != 0)
  54121. {
  54122. if (managerOfChosenCommand != 0)
  54123. {
  54124. ApplicationCommandTarget::InvocationInfo info (result);
  54125. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54126. managerOfChosenCommand->invoke (info, true);
  54127. }
  54128. postCommandMessage (result);
  54129. }
  54130. }
  54131. }
  54132. void MenuBarComponent::handleCommandMessage (int commandId)
  54133. {
  54134. if (model != 0)
  54135. model->menuItemSelected (commandId, topLevelIndexClicked);
  54136. }
  54137. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54138. {
  54139. if (e.eventComponent == this)
  54140. updateItemUnderMouse (e.x, e.y);
  54141. }
  54142. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54143. {
  54144. if (e.eventComponent == this)
  54145. updateItemUnderMouse (e.x, e.y);
  54146. }
  54147. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54148. {
  54149. if (currentPopupIndex < 0)
  54150. {
  54151. const MouseEvent e2 (e.getEventRelativeTo (this));
  54152. updateItemUnderMouse (e2.x, e2.y);
  54153. currentPopupIndex = -2;
  54154. showMenu (itemUnderMouse);
  54155. }
  54156. }
  54157. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54158. {
  54159. const MouseEvent e2 (e.getEventRelativeTo (this));
  54160. const int item = getItemAt (e2.x, e2.y);
  54161. if (item >= 0)
  54162. showMenu (item);
  54163. }
  54164. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54165. {
  54166. const MouseEvent e2 (e.getEventRelativeTo (this));
  54167. updateItemUnderMouse (e2.x, e2.y);
  54168. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> (static_cast <Component*> (currentPopup)) != 0)
  54169. hideCurrentMenu();
  54170. }
  54171. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54172. {
  54173. const MouseEvent e2 (e.getEventRelativeTo (this));
  54174. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54175. {
  54176. if (currentPopupIndex >= 0)
  54177. {
  54178. const int item = getItemAt (e2.x, e2.y);
  54179. if (item >= 0)
  54180. showMenu (item);
  54181. }
  54182. else
  54183. {
  54184. updateItemUnderMouse (e2.x, e2.y);
  54185. }
  54186. lastMouseX = e2.x;
  54187. lastMouseY = e2.y;
  54188. }
  54189. }
  54190. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54191. {
  54192. bool used = false;
  54193. const int numMenus = menuNames.size();
  54194. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54195. if (key.isKeyCode (KeyPress::leftKey))
  54196. {
  54197. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54198. used = true;
  54199. }
  54200. else if (key.isKeyCode (KeyPress::rightKey))
  54201. {
  54202. showMenu ((currentIndex + 1) % numMenus);
  54203. used = true;
  54204. }
  54205. return used;
  54206. }
  54207. void MenuBarComponent::inputAttemptWhenModal()
  54208. {
  54209. hideCurrentMenu();
  54210. }
  54211. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54212. {
  54213. StringArray newNames;
  54214. if (model != 0)
  54215. newNames = model->getMenuBarNames();
  54216. if (newNames != menuNames)
  54217. {
  54218. menuNames = newNames;
  54219. repaint();
  54220. resized();
  54221. }
  54222. }
  54223. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54224. const ApplicationCommandTarget::InvocationInfo& info)
  54225. {
  54226. if (model == 0
  54227. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54228. return;
  54229. for (int i = 0; i < menuNames.size(); ++i)
  54230. {
  54231. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54232. if (menu.containsCommandItem (info.commandID))
  54233. {
  54234. itemUnderMouse = i;
  54235. repaintMenuItem (i);
  54236. startTimer (200);
  54237. break;
  54238. }
  54239. }
  54240. }
  54241. void MenuBarComponent::timerCallback()
  54242. {
  54243. stopTimer();
  54244. const Point<int> mousePos (getMouseXYRelative());
  54245. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54246. }
  54247. END_JUCE_NAMESPACE
  54248. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54249. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54250. BEGIN_JUCE_NAMESPACE
  54251. MenuBarModel::MenuBarModel() throw()
  54252. : manager (0)
  54253. {
  54254. }
  54255. MenuBarModel::~MenuBarModel()
  54256. {
  54257. setApplicationCommandManagerToWatch (0);
  54258. }
  54259. void MenuBarModel::menuItemsChanged()
  54260. {
  54261. triggerAsyncUpdate();
  54262. }
  54263. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54264. {
  54265. if (manager != newManager)
  54266. {
  54267. if (manager != 0)
  54268. manager->removeListener (this);
  54269. manager = newManager;
  54270. if (manager != 0)
  54271. manager->addListener (this);
  54272. }
  54273. }
  54274. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54275. {
  54276. listeners.add (newListener);
  54277. }
  54278. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54279. {
  54280. // Trying to remove a listener that isn't on the list!
  54281. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54282. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54283. jassert (listeners.contains (listenerToRemove));
  54284. listeners.remove (listenerToRemove);
  54285. }
  54286. void MenuBarModel::handleAsyncUpdate()
  54287. {
  54288. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54289. }
  54290. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54291. {
  54292. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54293. }
  54294. void MenuBarModel::applicationCommandListChanged()
  54295. {
  54296. menuItemsChanged();
  54297. }
  54298. END_JUCE_NAMESPACE
  54299. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54300. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54301. BEGIN_JUCE_NAMESPACE
  54302. class PopupMenu::Item
  54303. {
  54304. public:
  54305. Item()
  54306. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54307. usesColour (false), customComp (0), commandManager (0)
  54308. {
  54309. }
  54310. Item (const int itemId_,
  54311. const String& text_,
  54312. const bool active_,
  54313. const bool isTicked_,
  54314. const Image* im,
  54315. const Colour& textColour_,
  54316. const bool usesColour_,
  54317. PopupMenuCustomComponent* const customComp_,
  54318. const PopupMenu* const subMenu_,
  54319. ApplicationCommandManager* const commandManager_)
  54320. : itemId (itemId_), text (text_), textColour (textColour_),
  54321. active (active_), isSeparator (false), isTicked (isTicked_),
  54322. usesColour (usesColour_), customComp (customComp_),
  54323. commandManager (commandManager_)
  54324. {
  54325. if (subMenu_ != 0)
  54326. subMenu = new PopupMenu (*subMenu_);
  54327. if (im != 0)
  54328. image = im->createCopy();
  54329. if (commandManager_ != 0 && itemId_ != 0)
  54330. {
  54331. String shortcutKey;
  54332. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54333. ->getKeyPressesAssignedToCommand (itemId_));
  54334. for (int i = 0; i < keyPresses.size(); ++i)
  54335. {
  54336. const String key (keyPresses.getReference(i).getTextDescription());
  54337. if (shortcutKey.isNotEmpty())
  54338. shortcutKey << ", ";
  54339. if (key.length() == 1)
  54340. shortcutKey << "shortcut: '" << key << '\'';
  54341. else
  54342. shortcutKey << key;
  54343. }
  54344. shortcutKey = shortcutKey.trim();
  54345. if (shortcutKey.isNotEmpty())
  54346. text << "<end>" << shortcutKey;
  54347. }
  54348. }
  54349. Item (const Item& other)
  54350. : itemId (other.itemId),
  54351. text (other.text),
  54352. textColour (other.textColour),
  54353. active (other.active),
  54354. isSeparator (other.isSeparator),
  54355. isTicked (other.isTicked),
  54356. usesColour (other.usesColour),
  54357. customComp (other.customComp),
  54358. commandManager (other.commandManager)
  54359. {
  54360. if (other.subMenu != 0)
  54361. subMenu = new PopupMenu (*(other.subMenu));
  54362. if (other.image != 0)
  54363. image = other.image->createCopy();
  54364. }
  54365. ~Item()
  54366. {
  54367. customComp = 0;
  54368. }
  54369. bool canBeTriggered() const throw()
  54370. {
  54371. return active && ! (isSeparator || (subMenu != 0));
  54372. }
  54373. bool hasActiveSubMenu() const throw()
  54374. {
  54375. return active && (subMenu != 0);
  54376. }
  54377. const int itemId;
  54378. String text;
  54379. const Colour textColour;
  54380. const bool active, isSeparator, isTicked, usesColour;
  54381. ScopedPointer <Image> image;
  54382. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54383. ScopedPointer <PopupMenu> subMenu;
  54384. ApplicationCommandManager* const commandManager;
  54385. juce_UseDebuggingNewOperator
  54386. private:
  54387. Item& operator= (const Item&);
  54388. };
  54389. class PopupMenu::ItemComponent : public Component
  54390. {
  54391. public:
  54392. ItemComponent (const PopupMenu::Item& itemInfo_)
  54393. : itemInfo (itemInfo_),
  54394. isHighlighted (false)
  54395. {
  54396. if (itemInfo.customComp != 0)
  54397. addAndMakeVisible (itemInfo.customComp);
  54398. }
  54399. ~ItemComponent()
  54400. {
  54401. if (itemInfo.customComp != 0)
  54402. removeChildComponent (itemInfo.customComp);
  54403. }
  54404. void getIdealSize (int& idealWidth,
  54405. int& idealHeight,
  54406. const int standardItemHeight)
  54407. {
  54408. if (itemInfo.customComp != 0)
  54409. {
  54410. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54411. }
  54412. else
  54413. {
  54414. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54415. itemInfo.isSeparator,
  54416. standardItemHeight,
  54417. idealWidth,
  54418. idealHeight);
  54419. }
  54420. }
  54421. void paint (Graphics& g)
  54422. {
  54423. if (itemInfo.customComp == 0)
  54424. {
  54425. String mainText (itemInfo.text);
  54426. String endText;
  54427. const int endIndex = mainText.indexOf ("<end>");
  54428. if (endIndex >= 0)
  54429. {
  54430. endText = mainText.substring (endIndex + 5).trim();
  54431. mainText = mainText.substring (0, endIndex);
  54432. }
  54433. getLookAndFeel()
  54434. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54435. itemInfo.isSeparator,
  54436. itemInfo.active,
  54437. isHighlighted,
  54438. itemInfo.isTicked,
  54439. itemInfo.subMenu != 0,
  54440. mainText, endText,
  54441. itemInfo.image,
  54442. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54443. }
  54444. }
  54445. void resized()
  54446. {
  54447. if (getNumChildComponents() > 0)
  54448. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54449. }
  54450. void setHighlighted (bool shouldBeHighlighted)
  54451. {
  54452. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54453. if (isHighlighted != shouldBeHighlighted)
  54454. {
  54455. isHighlighted = shouldBeHighlighted;
  54456. if (itemInfo.customComp != 0)
  54457. {
  54458. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54459. itemInfo.customComp->repaint();
  54460. }
  54461. repaint();
  54462. }
  54463. }
  54464. PopupMenu::Item itemInfo;
  54465. juce_UseDebuggingNewOperator
  54466. private:
  54467. bool isHighlighted;
  54468. ItemComponent (const ItemComponent&);
  54469. ItemComponent& operator= (const ItemComponent&);
  54470. };
  54471. namespace PopupMenuSettings
  54472. {
  54473. static const int scrollZone = 24;
  54474. static const int borderSize = 2;
  54475. static const int timerInterval = 50;
  54476. static const int dismissCommandId = 0x6287345f;
  54477. }
  54478. class PopupMenu::Window : public Component,
  54479. private Timer
  54480. {
  54481. public:
  54482. Window()
  54483. : Component ("menu"),
  54484. owner (0),
  54485. currentChild (0),
  54486. activeSubMenu (0),
  54487. menuBarComponent (0),
  54488. managerOfChosenCommand (0),
  54489. minimumWidth (0),
  54490. maximumNumColumns (7),
  54491. standardItemHeight (0),
  54492. isOver (false),
  54493. hasBeenOver (false),
  54494. isDown (false),
  54495. needsToScroll (false),
  54496. hideOnExit (false),
  54497. disableMouseMoves (false),
  54498. hasAnyJuceCompHadFocus (false),
  54499. numColumns (0),
  54500. contentHeight (0),
  54501. childYOffset (0),
  54502. timeEnteredCurrentChildComp (0),
  54503. scrollAcceleration (1.0)
  54504. {
  54505. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54506. setWantsKeyboardFocus (true);
  54507. setMouseClickGrabsKeyboardFocus (false);
  54508. setOpaque (true);
  54509. setAlwaysOnTop (true);
  54510. Desktop::getInstance().addGlobalMouseListener (this);
  54511. getActiveWindows().add (this);
  54512. }
  54513. ~Window()
  54514. {
  54515. getActiveWindows().removeValue (this);
  54516. Desktop::getInstance().removeGlobalMouseListener (this);
  54517. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54518. activeSubMenu = 0;
  54519. deleteAllChildren();
  54520. }
  54521. static Window* create (const PopupMenu& menu,
  54522. const bool dismissOnMouseUp,
  54523. Window* const owner_,
  54524. const int minX, const int maxX,
  54525. const int minY, const int maxY,
  54526. const int minimumWidth,
  54527. const int maximumNumColumns,
  54528. const int standardItemHeight,
  54529. const bool alignToRectangle,
  54530. const int itemIdThatMustBeVisible,
  54531. Component* const menuBarComponent,
  54532. ApplicationCommandManager** managerOfChosenCommand,
  54533. Component* const componentAttachedTo)
  54534. {
  54535. if (menu.items.size() > 0)
  54536. {
  54537. int totalItems = 0;
  54538. ScopedPointer <Window> mw (new Window());
  54539. mw->setLookAndFeel (menu.lookAndFeel);
  54540. mw->setWantsKeyboardFocus (false);
  54541. mw->minimumWidth = minimumWidth;
  54542. mw->maximumNumColumns = maximumNumColumns;
  54543. mw->standardItemHeight = standardItemHeight;
  54544. mw->dismissOnMouseUp = dismissOnMouseUp;
  54545. for (int i = 0; i < menu.items.size(); ++i)
  54546. {
  54547. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54548. mw->addItem (*item);
  54549. ++totalItems;
  54550. }
  54551. if (totalItems > 0)
  54552. {
  54553. mw->owner = owner_;
  54554. mw->menuBarComponent = menuBarComponent;
  54555. mw->managerOfChosenCommand = managerOfChosenCommand;
  54556. mw->componentAttachedTo = componentAttachedTo;
  54557. mw->componentAttachedToOriginal = componentAttachedTo;
  54558. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54559. mw->setTopLeftPosition (mw->windowPos.getX(),
  54560. mw->windowPos.getY());
  54561. mw->updateYPositions();
  54562. if (itemIdThatMustBeVisible != 0)
  54563. {
  54564. const int y = minY - mw->windowPos.getY();
  54565. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54566. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54567. }
  54568. mw->resizeToBestWindowPos();
  54569. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54570. | mw->getLookAndFeel().getMenuWindowFlags());
  54571. return mw.release();
  54572. }
  54573. }
  54574. return 0;
  54575. }
  54576. void paint (Graphics& g)
  54577. {
  54578. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54579. }
  54580. void paintOverChildren (Graphics& g)
  54581. {
  54582. if (isScrolling())
  54583. {
  54584. LookAndFeel& lf = getLookAndFeel();
  54585. if (isScrollZoneActive (false))
  54586. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54587. if (isScrollZoneActive (true))
  54588. {
  54589. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54590. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54591. }
  54592. }
  54593. }
  54594. bool isScrollZoneActive (bool bottomOne) const
  54595. {
  54596. return isScrolling()
  54597. && (bottomOne
  54598. ? childYOffset < contentHeight - windowPos.getHeight()
  54599. : childYOffset > 0);
  54600. }
  54601. void addItem (const PopupMenu::Item& item)
  54602. {
  54603. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54604. addAndMakeVisible (mic);
  54605. int itemW = 80;
  54606. int itemH = 16;
  54607. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54608. mic->setSize (itemW, jlimit (2, 600, itemH));
  54609. mic->addMouseListener (this, false);
  54610. }
  54611. // hide this and all sub-comps
  54612. void hide (const PopupMenu::Item* const item)
  54613. {
  54614. if (isVisible())
  54615. {
  54616. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54617. activeSubMenu = 0;
  54618. currentChild = 0;
  54619. exitModalState (item != 0 ? item->itemId : 0);
  54620. setVisible (false);
  54621. if (item != 0
  54622. && item->commandManager != 0
  54623. && item->itemId != 0)
  54624. {
  54625. *managerOfChosenCommand = item->commandManager;
  54626. }
  54627. }
  54628. }
  54629. void dismissMenu (const PopupMenu::Item* const item)
  54630. {
  54631. if (owner != 0)
  54632. {
  54633. owner->dismissMenu (item);
  54634. }
  54635. else
  54636. {
  54637. if (item != 0)
  54638. {
  54639. // need a copy of this on the stack as the one passed in will get deleted during this call
  54640. const PopupMenu::Item mi (*item);
  54641. hide (&mi);
  54642. }
  54643. else
  54644. {
  54645. hide (0);
  54646. }
  54647. }
  54648. }
  54649. void mouseMove (const MouseEvent&)
  54650. {
  54651. timerCallback();
  54652. }
  54653. void mouseDown (const MouseEvent&)
  54654. {
  54655. timerCallback();
  54656. }
  54657. void mouseDrag (const MouseEvent&)
  54658. {
  54659. timerCallback();
  54660. }
  54661. void mouseUp (const MouseEvent&)
  54662. {
  54663. timerCallback();
  54664. }
  54665. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54666. {
  54667. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54668. lastMouse = Point<int> (-1, -1);
  54669. }
  54670. bool keyPressed (const KeyPress& key)
  54671. {
  54672. if (key.isKeyCode (KeyPress::downKey))
  54673. {
  54674. selectNextItem (1);
  54675. }
  54676. else if (key.isKeyCode (KeyPress::upKey))
  54677. {
  54678. selectNextItem (-1);
  54679. }
  54680. else if (key.isKeyCode (KeyPress::leftKey))
  54681. {
  54682. if (owner != 0)
  54683. {
  54684. Component::SafePointer<Window> parentWindow (owner);
  54685. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54686. hide (0);
  54687. if (parentWindow != 0)
  54688. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54689. disableTimerUntilMouseMoves();
  54690. }
  54691. else if (menuBarComponent != 0)
  54692. {
  54693. menuBarComponent->keyPressed (key);
  54694. }
  54695. }
  54696. else if (key.isKeyCode (KeyPress::rightKey))
  54697. {
  54698. disableTimerUntilMouseMoves();
  54699. if (showSubMenuFor (currentChild))
  54700. {
  54701. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54702. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54703. activeSubMenu->selectNextItem (1);
  54704. }
  54705. else if (menuBarComponent != 0)
  54706. {
  54707. menuBarComponent->keyPressed (key);
  54708. }
  54709. }
  54710. else if (key.isKeyCode (KeyPress::returnKey))
  54711. {
  54712. triggerCurrentlyHighlightedItem();
  54713. }
  54714. else if (key.isKeyCode (KeyPress::escapeKey))
  54715. {
  54716. dismissMenu (0);
  54717. }
  54718. else
  54719. {
  54720. return false;
  54721. }
  54722. return true;
  54723. }
  54724. void inputAttemptWhenModal()
  54725. {
  54726. timerCallback();
  54727. if (! isOverAnyMenu())
  54728. {
  54729. if (componentAttachedTo != 0)
  54730. {
  54731. // we want to dismiss the menu, but if we do it synchronously, then
  54732. // the mouse-click will be allowed to pass through. That's good, except
  54733. // when the user clicks on the button that orginally popped the menu up,
  54734. // as they'll expect the menu to go away, and in fact it'll just
  54735. // come back. So only dismiss synchronously if they're not on the original
  54736. // comp that we're attached to.
  54737. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54738. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54739. {
  54740. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54741. return;
  54742. }
  54743. }
  54744. dismissMenu (0);
  54745. }
  54746. }
  54747. void handleCommandMessage (int commandId)
  54748. {
  54749. Component::handleCommandMessage (commandId);
  54750. if (commandId == PopupMenuSettings::dismissCommandId)
  54751. dismissMenu (0);
  54752. }
  54753. void timerCallback()
  54754. {
  54755. if (! isVisible())
  54756. return;
  54757. if (componentAttachedTo != componentAttachedToOriginal)
  54758. {
  54759. dismissMenu (0);
  54760. return;
  54761. }
  54762. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54763. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54764. return;
  54765. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54766. // move rather than a real timer callback
  54767. const Point<int> globalMousePos (Desktop::getMousePosition());
  54768. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54769. const uint32 now = Time::getMillisecondCounter();
  54770. if (now > timeEnteredCurrentChildComp + 100
  54771. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54772. && currentChild->isValidComponent()
  54773. && (! disableMouseMoves)
  54774. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54775. {
  54776. showSubMenuFor (currentChild);
  54777. }
  54778. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54779. {
  54780. highlightItemUnderMouse (globalMousePos, localMousePos);
  54781. }
  54782. bool overScrollArea = false;
  54783. if (isScrolling()
  54784. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54785. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54786. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54787. {
  54788. if (now > lastScroll + 20)
  54789. {
  54790. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54791. int amount = 0;
  54792. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54793. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54794. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54795. lastScroll = now;
  54796. }
  54797. overScrollArea = true;
  54798. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54799. }
  54800. else
  54801. {
  54802. scrollAcceleration = 1.0;
  54803. }
  54804. const bool wasDown = isDown;
  54805. bool isOverAny = isOverAnyMenu();
  54806. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54807. {
  54808. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54809. isOverAny = isOverAnyMenu();
  54810. }
  54811. if (hideOnExit && hasBeenOver && ! isOverAny)
  54812. {
  54813. hide (0);
  54814. }
  54815. else
  54816. {
  54817. isDown = hasBeenOver
  54818. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54819. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54820. bool anyFocused = Process::isForegroundProcess();
  54821. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54822. {
  54823. // because no component at all may have focus, our test here will
  54824. // only be triggered when something has focus and then loses it.
  54825. anyFocused = ! hasAnyJuceCompHadFocus;
  54826. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54827. {
  54828. if (ComponentPeer::getPeer (i)->isFocused())
  54829. {
  54830. anyFocused = true;
  54831. hasAnyJuceCompHadFocus = true;
  54832. break;
  54833. }
  54834. }
  54835. }
  54836. if (! anyFocused)
  54837. {
  54838. if (now > lastFocused + 10)
  54839. {
  54840. wasHiddenBecauseOfAppChange() = true;
  54841. dismissMenu (0);
  54842. return; // may have been deleted by the previous call..
  54843. }
  54844. }
  54845. else if (wasDown && now > menuCreationTime + 250
  54846. && ! (isDown || overScrollArea))
  54847. {
  54848. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54849. if (isOver)
  54850. {
  54851. triggerCurrentlyHighlightedItem();
  54852. }
  54853. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54854. {
  54855. dismissMenu (0);
  54856. }
  54857. return; // may have been deleted by the previous calls..
  54858. }
  54859. else
  54860. {
  54861. lastFocused = now;
  54862. }
  54863. }
  54864. }
  54865. static Array<Window*>& getActiveWindows()
  54866. {
  54867. static Array<Window*> activeMenuWindows;
  54868. return activeMenuWindows;
  54869. }
  54870. static bool& wasHiddenBecauseOfAppChange() throw()
  54871. {
  54872. static bool b = false;
  54873. return b;
  54874. }
  54875. juce_UseDebuggingNewOperator
  54876. private:
  54877. Window* owner;
  54878. PopupMenu::ItemComponent* currentChild;
  54879. ScopedPointer <Window> activeSubMenu;
  54880. Component* menuBarComponent;
  54881. ApplicationCommandManager** managerOfChosenCommand;
  54882. Component::SafePointer<Component> componentAttachedTo;
  54883. Component* componentAttachedToOriginal;
  54884. Rectangle<int> windowPos;
  54885. Point<int> lastMouse;
  54886. int minimumWidth, maximumNumColumns, standardItemHeight;
  54887. bool isOver, hasBeenOver, isDown, needsToScroll;
  54888. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54889. int numColumns, contentHeight, childYOffset;
  54890. Array <int> columnWidths;
  54891. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54892. double scrollAcceleration;
  54893. bool overlaps (const Rectangle<int>& r) const
  54894. {
  54895. return r.intersects (getBounds())
  54896. || (owner != 0 && owner->overlaps (r));
  54897. }
  54898. bool isOverAnyMenu() const
  54899. {
  54900. return (owner != 0) ? owner->isOverAnyMenu()
  54901. : isOverChildren();
  54902. }
  54903. bool isOverChildren() const
  54904. {
  54905. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54906. return isVisible()
  54907. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54908. }
  54909. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54910. {
  54911. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54912. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54913. if (activeSubMenu != 0)
  54914. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54915. }
  54916. bool treeContains (const Window* const window) const throw()
  54917. {
  54918. const Window* mw = this;
  54919. while (mw->owner != 0)
  54920. mw = mw->owner;
  54921. while (mw != 0)
  54922. {
  54923. if (mw == window)
  54924. return true;
  54925. mw = mw->activeSubMenu;
  54926. }
  54927. return false;
  54928. }
  54929. void calculateWindowPos (const int minX, const int maxX,
  54930. const int minY, const int maxY,
  54931. const bool alignToRectangle)
  54932. {
  54933. const Rectangle<int> mon (Desktop::getInstance()
  54934. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54935. (minY + maxY) / 2),
  54936. #if JUCE_MAC
  54937. true));
  54938. #else
  54939. false)); // on windows, don't stop the menu overlapping the taskbar
  54940. #endif
  54941. int x, y, widthToUse, heightToUse;
  54942. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54943. if (alignToRectangle)
  54944. {
  54945. x = minX;
  54946. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54947. const int spaceOver = minY - mon.getY();
  54948. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54949. y = maxY;
  54950. else
  54951. y = minY - heightToUse;
  54952. }
  54953. else
  54954. {
  54955. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54956. if (owner != 0)
  54957. {
  54958. if (owner->owner != 0)
  54959. {
  54960. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54961. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54962. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54963. tendTowardsRight = true;
  54964. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54965. tendTowardsRight = false;
  54966. }
  54967. else if (maxX + widthToUse < mon.getRight() - 32)
  54968. {
  54969. tendTowardsRight = true;
  54970. }
  54971. }
  54972. const int biggestSpace = jmax (mon.getRight() - maxX,
  54973. minX - mon.getX()) - 32;
  54974. if (biggestSpace < widthToUse)
  54975. {
  54976. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54977. if (numColumns > 1)
  54978. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54979. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54980. }
  54981. if (tendTowardsRight)
  54982. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54983. else
  54984. x = jmax (mon.getX() + 4, minX - widthToUse);
  54985. y = minY;
  54986. if ((minY + maxY) / 2 > mon.getCentreY())
  54987. y = jmax (mon.getY(), maxY - heightToUse);
  54988. }
  54989. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54990. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54991. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54992. // sets this flag if it's big enough to obscure any of its parent menus
  54993. hideOnExit = (owner != 0)
  54994. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54995. }
  54996. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54997. {
  54998. numColumns = 0;
  54999. contentHeight = 0;
  55000. const int maxMenuH = getParentHeight() - 24;
  55001. int totalW;
  55002. do
  55003. {
  55004. ++numColumns;
  55005. totalW = workOutBestSize (maxMenuW);
  55006. if (totalW > maxMenuW)
  55007. {
  55008. numColumns = jmax (1, numColumns - 1);
  55009. totalW = workOutBestSize (maxMenuW); // to update col widths
  55010. break;
  55011. }
  55012. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55013. {
  55014. break;
  55015. }
  55016. } while (numColumns < maximumNumColumns);
  55017. const int actualH = jmin (contentHeight, maxMenuH);
  55018. needsToScroll = contentHeight > actualH;
  55019. width = updateYPositions();
  55020. height = actualH + PopupMenuSettings::borderSize * 2;
  55021. }
  55022. int workOutBestSize (const int maxMenuW)
  55023. {
  55024. int totalW = 0;
  55025. contentHeight = 0;
  55026. int childNum = 0;
  55027. for (int col = 0; col < numColumns; ++col)
  55028. {
  55029. int i, colW = 50, colH = 0;
  55030. const int numChildren = jmin (getNumChildComponents() - childNum,
  55031. (getNumChildComponents() + numColumns - 1) / numColumns);
  55032. for (i = numChildren; --i >= 0;)
  55033. {
  55034. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55035. colH += getChildComponent (childNum + i)->getHeight();
  55036. }
  55037. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55038. columnWidths.set (col, colW);
  55039. totalW += colW;
  55040. contentHeight = jmax (contentHeight, colH);
  55041. childNum += numChildren;
  55042. }
  55043. if (totalW < minimumWidth)
  55044. {
  55045. totalW = minimumWidth;
  55046. for (int col = 0; col < numColumns; ++col)
  55047. columnWidths.set (0, totalW / numColumns);
  55048. }
  55049. return totalW;
  55050. }
  55051. void ensureItemIsVisible (const int itemId, int wantedY)
  55052. {
  55053. jassert (itemId != 0)
  55054. for (int i = getNumChildComponents(); --i >= 0;)
  55055. {
  55056. PopupMenu::ItemComponent* const m = static_cast <PopupMenu::ItemComponent*> (getChildComponent (i));
  55057. if (m != 0
  55058. && m->itemInfo.itemId == itemId
  55059. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55060. {
  55061. const int currentY = m->getY();
  55062. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55063. {
  55064. if (wantedY < 0)
  55065. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55066. jmax (PopupMenuSettings::scrollZone,
  55067. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55068. currentY);
  55069. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55070. int deltaY = wantedY - currentY;
  55071. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55072. jmin (windowPos.getHeight(), mon.getHeight()));
  55073. const int newY = jlimit (mon.getY(),
  55074. mon.getBottom() - windowPos.getHeight(),
  55075. windowPos.getY() + deltaY);
  55076. deltaY -= newY - windowPos.getY();
  55077. childYOffset -= deltaY;
  55078. windowPos.setPosition (windowPos.getX(), newY);
  55079. updateYPositions();
  55080. }
  55081. break;
  55082. }
  55083. }
  55084. }
  55085. void resizeToBestWindowPos()
  55086. {
  55087. Rectangle<int> r (windowPos);
  55088. if (childYOffset < 0)
  55089. {
  55090. r.setBounds (r.getX(), r.getY() - childYOffset,
  55091. r.getWidth(), r.getHeight() + childYOffset);
  55092. }
  55093. else if (childYOffset > 0)
  55094. {
  55095. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55096. if (spaceAtBottom > 0)
  55097. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55098. }
  55099. setBounds (r);
  55100. updateYPositions();
  55101. }
  55102. void alterChildYPos (const int delta)
  55103. {
  55104. if (isScrolling())
  55105. {
  55106. childYOffset += delta;
  55107. if (delta < 0)
  55108. {
  55109. childYOffset = jmax (childYOffset, 0);
  55110. }
  55111. else if (delta > 0)
  55112. {
  55113. childYOffset = jmin (childYOffset,
  55114. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55115. }
  55116. updateYPositions();
  55117. }
  55118. else
  55119. {
  55120. childYOffset = 0;
  55121. }
  55122. resizeToBestWindowPos();
  55123. repaint();
  55124. }
  55125. int updateYPositions()
  55126. {
  55127. int x = 0;
  55128. int childNum = 0;
  55129. for (int col = 0; col < numColumns; ++col)
  55130. {
  55131. const int numChildren = jmin (getNumChildComponents() - childNum,
  55132. (getNumChildComponents() + numColumns - 1) / numColumns);
  55133. const int colW = columnWidths [col];
  55134. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55135. for (int i = 0; i < numChildren; ++i)
  55136. {
  55137. Component* const c = getChildComponent (childNum + i);
  55138. c->setBounds (x, y, colW, c->getHeight());
  55139. y += c->getHeight();
  55140. }
  55141. x += colW;
  55142. childNum += numChildren;
  55143. }
  55144. return x;
  55145. }
  55146. bool isScrolling() const throw()
  55147. {
  55148. return childYOffset != 0 || needsToScroll;
  55149. }
  55150. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55151. {
  55152. if (currentChild->isValidComponent())
  55153. currentChild->setHighlighted (false);
  55154. currentChild = child;
  55155. if (currentChild != 0)
  55156. {
  55157. currentChild->setHighlighted (true);
  55158. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55159. }
  55160. }
  55161. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55162. {
  55163. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55164. activeSubMenu = 0;
  55165. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55166. {
  55167. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55168. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55169. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55170. dismissOnMouseUp,
  55171. this,
  55172. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55173. 0, maximumNumColumns,
  55174. standardItemHeight,
  55175. false, 0, menuBarComponent,
  55176. managerOfChosenCommand,
  55177. componentAttachedTo);
  55178. if (activeSubMenu != 0)
  55179. {
  55180. activeSubMenu->setVisible (true);
  55181. activeSubMenu->enterModalState (false);
  55182. activeSubMenu->toFront (false);
  55183. return true;
  55184. }
  55185. }
  55186. return false;
  55187. }
  55188. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55189. {
  55190. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55191. if (isOver)
  55192. hasBeenOver = true;
  55193. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55194. {
  55195. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55196. if (disableMouseMoves && isOver)
  55197. disableMouseMoves = false;
  55198. }
  55199. if (disableMouseMoves || (activeSubMenu != 0 && activeSubMenu->isOverChildren()))
  55200. return;
  55201. bool isMovingTowardsMenu = false;
  55202. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55203. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55204. {
  55205. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55206. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55207. // extends from the last mouse pos to the submenu's rectangle..
  55208. float subX = (float) activeSubMenu->getScreenX();
  55209. if (activeSubMenu->getX() > getX())
  55210. {
  55211. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55212. }
  55213. else
  55214. {
  55215. lastMouse += Point<int> (2, 0);
  55216. subX += activeSubMenu->getWidth();
  55217. }
  55218. Path areaTowardsSubMenu;
  55219. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55220. (float) lastMouse.getY(),
  55221. subX,
  55222. (float) activeSubMenu->getScreenY(),
  55223. subX,
  55224. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55225. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55226. }
  55227. lastMouse = globalMousePos;
  55228. if (! isMovingTowardsMenu)
  55229. {
  55230. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55231. if (c == this)
  55232. c = 0;
  55233. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55234. if (mic == 0 && c != 0)
  55235. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55236. if (mic != currentChild
  55237. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55238. {
  55239. if (isOver && (c != 0) && (activeSubMenu != 0))
  55240. {
  55241. activeSubMenu->hide (0);
  55242. }
  55243. if (! isOver)
  55244. mic = 0;
  55245. setCurrentlyHighlightedChild (mic);
  55246. }
  55247. }
  55248. }
  55249. void triggerCurrentlyHighlightedItem()
  55250. {
  55251. if (currentChild->isValidComponent()
  55252. && currentChild->itemInfo.canBeTriggered()
  55253. && (currentChild->itemInfo.customComp == 0
  55254. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55255. {
  55256. dismissMenu (&currentChild->itemInfo);
  55257. }
  55258. }
  55259. void selectNextItem (const int delta)
  55260. {
  55261. disableTimerUntilMouseMoves();
  55262. PopupMenu::ItemComponent* mic = 0;
  55263. bool wasLastOne = (currentChild == 0);
  55264. const int numItems = getNumChildComponents();
  55265. for (int i = 0; i < numItems + 1; ++i)
  55266. {
  55267. int index = (delta > 0) ? i : (numItems - 1 - i);
  55268. index = (index + numItems) % numItems;
  55269. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55270. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55271. && wasLastOne)
  55272. break;
  55273. if (mic == currentChild)
  55274. wasLastOne = true;
  55275. }
  55276. setCurrentlyHighlightedChild (mic);
  55277. }
  55278. void disableTimerUntilMouseMoves()
  55279. {
  55280. disableMouseMoves = true;
  55281. if (owner != 0)
  55282. owner->disableTimerUntilMouseMoves();
  55283. }
  55284. Window (const Window&);
  55285. Window& operator= (const Window&);
  55286. };
  55287. PopupMenu::PopupMenu()
  55288. : lookAndFeel (0),
  55289. separatorPending (false)
  55290. {
  55291. }
  55292. PopupMenu::PopupMenu (const PopupMenu& other)
  55293. : lookAndFeel (other.lookAndFeel),
  55294. separatorPending (false)
  55295. {
  55296. items.ensureStorageAllocated (other.items.size());
  55297. for (int i = 0; i < other.items.size(); ++i)
  55298. items.add (new Item (*other.items.getUnchecked(i)));
  55299. }
  55300. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55301. {
  55302. if (this != &other)
  55303. {
  55304. lookAndFeel = other.lookAndFeel;
  55305. clear();
  55306. items.ensureStorageAllocated (other.items.size());
  55307. for (int i = 0; i < other.items.size(); ++i)
  55308. items.add (new Item (*other.items.getUnchecked(i)));
  55309. }
  55310. return *this;
  55311. }
  55312. PopupMenu::~PopupMenu()
  55313. {
  55314. clear();
  55315. }
  55316. void PopupMenu::clear()
  55317. {
  55318. items.clear();
  55319. separatorPending = false;
  55320. }
  55321. void PopupMenu::addSeparatorIfPending()
  55322. {
  55323. if (separatorPending)
  55324. {
  55325. separatorPending = false;
  55326. if (items.size() > 0)
  55327. items.add (new Item());
  55328. }
  55329. }
  55330. void PopupMenu::addItem (const int itemResultId,
  55331. const String& itemText,
  55332. const bool isActive,
  55333. const bool isTicked,
  55334. const Image* const iconToUse)
  55335. {
  55336. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55337. // didn't pick anything, so you shouldn't use it as the id
  55338. // for an item..
  55339. addSeparatorIfPending();
  55340. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55341. iconToUse, Colours::black, false, 0, 0, 0));
  55342. }
  55343. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55344. const int commandID,
  55345. const String& displayName)
  55346. {
  55347. jassert (commandManager != 0 && commandID != 0);
  55348. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55349. if (registeredInfo != 0)
  55350. {
  55351. ApplicationCommandInfo info (*registeredInfo);
  55352. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55353. addSeparatorIfPending();
  55354. items.add (new Item (commandID,
  55355. displayName.isNotEmpty() ? displayName
  55356. : info.shortName,
  55357. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55358. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55359. 0,
  55360. Colours::black,
  55361. false,
  55362. 0, 0,
  55363. commandManager));
  55364. }
  55365. }
  55366. void PopupMenu::addColouredItem (const int itemResultId,
  55367. const String& itemText,
  55368. const Colour& itemTextColour,
  55369. const bool isActive,
  55370. const bool isTicked,
  55371. const Image* const iconToUse)
  55372. {
  55373. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55374. // didn't pick anything, so you shouldn't use it as the id
  55375. // for an item..
  55376. addSeparatorIfPending();
  55377. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55378. iconToUse, itemTextColour, true, 0, 0, 0));
  55379. }
  55380. void PopupMenu::addCustomItem (const int itemResultId,
  55381. PopupMenuCustomComponent* const customComponent)
  55382. {
  55383. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55384. // didn't pick anything, so you shouldn't use it as the id
  55385. // for an item..
  55386. addSeparatorIfPending();
  55387. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55388. Colours::black, false, customComponent, 0, 0));
  55389. }
  55390. class NormalComponentWrapper : public PopupMenuCustomComponent
  55391. {
  55392. public:
  55393. NormalComponentWrapper (Component* const comp,
  55394. const int w, const int h,
  55395. const bool triggerMenuItemAutomaticallyWhenClicked)
  55396. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55397. width (w),
  55398. height (h)
  55399. {
  55400. addAndMakeVisible (comp);
  55401. }
  55402. ~NormalComponentWrapper() {}
  55403. void getIdealSize (int& idealWidth, int& idealHeight)
  55404. {
  55405. idealWidth = width;
  55406. idealHeight = height;
  55407. }
  55408. void resized()
  55409. {
  55410. if (getChildComponent(0) != 0)
  55411. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55412. }
  55413. juce_UseDebuggingNewOperator
  55414. private:
  55415. const int width, height;
  55416. NormalComponentWrapper (const NormalComponentWrapper&);
  55417. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55418. };
  55419. void PopupMenu::addCustomItem (const int itemResultId,
  55420. Component* customComponent,
  55421. int idealWidth, int idealHeight,
  55422. const bool triggerMenuItemAutomaticallyWhenClicked)
  55423. {
  55424. addCustomItem (itemResultId,
  55425. new NormalComponentWrapper (customComponent,
  55426. idealWidth, idealHeight,
  55427. triggerMenuItemAutomaticallyWhenClicked));
  55428. }
  55429. void PopupMenu::addSubMenu (const String& subMenuName,
  55430. const PopupMenu& subMenu,
  55431. const bool isActive,
  55432. Image* const iconToUse,
  55433. const bool isTicked)
  55434. {
  55435. addSeparatorIfPending();
  55436. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55437. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55438. }
  55439. void PopupMenu::addSeparator()
  55440. {
  55441. separatorPending = true;
  55442. }
  55443. class HeaderItemComponent : public PopupMenuCustomComponent
  55444. {
  55445. public:
  55446. HeaderItemComponent (const String& name)
  55447. : PopupMenuCustomComponent (false)
  55448. {
  55449. setName (name);
  55450. }
  55451. ~HeaderItemComponent()
  55452. {
  55453. }
  55454. void paint (Graphics& g)
  55455. {
  55456. Font f (getLookAndFeel().getPopupMenuFont());
  55457. f.setBold (true);
  55458. g.setFont (f);
  55459. g.setColour (findColour (PopupMenu::headerTextColourId));
  55460. g.drawFittedText (getName(),
  55461. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55462. Justification::bottomLeft, 1);
  55463. }
  55464. void getIdealSize (int& idealWidth,
  55465. int& idealHeight)
  55466. {
  55467. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55468. idealHeight += idealHeight / 2;
  55469. idealWidth += idealWidth / 4;
  55470. }
  55471. juce_UseDebuggingNewOperator
  55472. };
  55473. void PopupMenu::addSectionHeader (const String& title)
  55474. {
  55475. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55476. }
  55477. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55478. const int itemIdThatMustBeVisible,
  55479. const int minimumWidth,
  55480. const int maximumNumColumns,
  55481. const int standardItemHeight,
  55482. const bool alignToRectangle,
  55483. Component* menuBarComponent,
  55484. ApplicationCommandManager** managerOfChosenCommand,
  55485. Component* const componentAttachedTo)
  55486. {
  55487. Window* const pw
  55488. = Window::create (*this,
  55489. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55490. 0,
  55491. x, x + w,
  55492. y, y + h,
  55493. minimumWidth,
  55494. maximumNumColumns,
  55495. standardItemHeight,
  55496. alignToRectangle,
  55497. itemIdThatMustBeVisible,
  55498. menuBarComponent,
  55499. managerOfChosenCommand,
  55500. componentAttachedTo);
  55501. if (pw != 0)
  55502. pw->setVisible (true);
  55503. return pw;
  55504. }
  55505. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55506. const int itemIdThatMustBeVisible,
  55507. const int minimumWidth,
  55508. const int maximumNumColumns,
  55509. const int standardItemHeight,
  55510. const bool alignToRectangle,
  55511. Component* const componentAttachedTo)
  55512. {
  55513. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55514. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55515. Window::wasHiddenBecauseOfAppChange() = false;
  55516. int result = 0;
  55517. ApplicationCommandManager* managerOfChosenCommand = 0;
  55518. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55519. itemIdThatMustBeVisible,
  55520. minimumWidth,
  55521. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55522. standardItemHeight,
  55523. alignToRectangle, 0,
  55524. &managerOfChosenCommand,
  55525. componentAttachedTo));
  55526. if (popupComp != 0)
  55527. {
  55528. popupComp->enterModalState (false);
  55529. popupComp->toFront (false); // need to do this after making it modal, or it could
  55530. // be stuck behind other comps that are already modal..
  55531. result = popupComp->runModalLoop();
  55532. popupComp = 0;
  55533. if (! Window::wasHiddenBecauseOfAppChange())
  55534. {
  55535. if (prevTopLevel != 0)
  55536. prevTopLevel->toFront (true);
  55537. if (prevFocused != 0)
  55538. prevFocused->grabKeyboardFocus();
  55539. }
  55540. }
  55541. if (managerOfChosenCommand != 0 && result != 0)
  55542. {
  55543. ApplicationCommandTarget::InvocationInfo info (result);
  55544. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55545. managerOfChosenCommand->invoke (info, true);
  55546. }
  55547. return result;
  55548. }
  55549. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55550. const int minimumWidth,
  55551. const int maximumNumColumns,
  55552. const int standardItemHeight)
  55553. {
  55554. const Point<int> mousePos (Desktop::getMousePosition());
  55555. return showAt (mousePos.getX(), mousePos.getY(),
  55556. itemIdThatMustBeVisible,
  55557. minimumWidth,
  55558. maximumNumColumns,
  55559. standardItemHeight);
  55560. }
  55561. int PopupMenu::showAt (const int screenX,
  55562. const int screenY,
  55563. const int itemIdThatMustBeVisible,
  55564. const int minimumWidth,
  55565. const int maximumNumColumns,
  55566. const int standardItemHeight)
  55567. {
  55568. return showMenu (screenX, screenY, 1, 1,
  55569. itemIdThatMustBeVisible,
  55570. minimumWidth, maximumNumColumns,
  55571. standardItemHeight,
  55572. false, 0);
  55573. }
  55574. int PopupMenu::showAt (Component* componentToAttachTo,
  55575. const int itemIdThatMustBeVisible,
  55576. const int minimumWidth,
  55577. const int maximumNumColumns,
  55578. const int standardItemHeight)
  55579. {
  55580. if (componentToAttachTo != 0)
  55581. {
  55582. return showMenu (componentToAttachTo->getScreenX(),
  55583. componentToAttachTo->getScreenY(),
  55584. componentToAttachTo->getWidth(),
  55585. componentToAttachTo->getHeight(),
  55586. itemIdThatMustBeVisible,
  55587. minimumWidth,
  55588. maximumNumColumns,
  55589. standardItemHeight,
  55590. true, componentToAttachTo);
  55591. }
  55592. else
  55593. {
  55594. return show (itemIdThatMustBeVisible,
  55595. minimumWidth,
  55596. maximumNumColumns,
  55597. standardItemHeight);
  55598. }
  55599. }
  55600. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55601. {
  55602. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55603. {
  55604. Window* const pmw = Window::getActiveWindows()[i];
  55605. if (pmw != 0)
  55606. pmw->dismissMenu (0);
  55607. }
  55608. }
  55609. int PopupMenu::getNumItems() const throw()
  55610. {
  55611. int num = 0;
  55612. for (int i = items.size(); --i >= 0;)
  55613. if (! (items.getUnchecked(i))->isSeparator)
  55614. ++num;
  55615. return num;
  55616. }
  55617. bool PopupMenu::containsCommandItem (const int commandID) const
  55618. {
  55619. for (int i = items.size(); --i >= 0;)
  55620. {
  55621. const Item* mi = items.getUnchecked (i);
  55622. if ((mi->itemId == commandID && mi->commandManager != 0)
  55623. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55624. {
  55625. return true;
  55626. }
  55627. }
  55628. return false;
  55629. }
  55630. bool PopupMenu::containsAnyActiveItems() const throw()
  55631. {
  55632. for (int i = items.size(); --i >= 0;)
  55633. {
  55634. const Item* const mi = items.getUnchecked (i);
  55635. if (mi->subMenu != 0)
  55636. {
  55637. if (mi->subMenu->containsAnyActiveItems())
  55638. return true;
  55639. }
  55640. else if (mi->active)
  55641. {
  55642. return true;
  55643. }
  55644. }
  55645. return false;
  55646. }
  55647. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55648. {
  55649. lookAndFeel = newLookAndFeel;
  55650. }
  55651. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55652. : isHighlighted (false),
  55653. isTriggeredAutomatically (isTriggeredAutomatically_)
  55654. {
  55655. }
  55656. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55657. {
  55658. }
  55659. void PopupMenuCustomComponent::triggerMenuItem()
  55660. {
  55661. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55662. if (mic != 0)
  55663. {
  55664. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55665. if (pmw != 0)
  55666. {
  55667. pmw->dismissMenu (&mic->itemInfo);
  55668. }
  55669. else
  55670. {
  55671. // something must have gone wrong with the component hierarchy if this happens..
  55672. jassertfalse
  55673. }
  55674. }
  55675. else
  55676. {
  55677. // why isn't this component inside a menu? Not much point triggering the item if
  55678. // there's no menu.
  55679. jassertfalse
  55680. }
  55681. }
  55682. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55683. : subMenu (0),
  55684. itemId (0),
  55685. isSeparator (false),
  55686. isTicked (false),
  55687. isEnabled (false),
  55688. isCustomComponent (false),
  55689. isSectionHeader (false),
  55690. customColour (0),
  55691. customImage (0),
  55692. menu (menu_),
  55693. index (0)
  55694. {
  55695. }
  55696. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55697. {
  55698. }
  55699. bool PopupMenu::MenuItemIterator::next()
  55700. {
  55701. if (index >= menu.items.size())
  55702. return false;
  55703. const Item* const item = menu.items.getUnchecked (index);
  55704. ++index;
  55705. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55706. subMenu = item->subMenu;
  55707. itemId = item->itemId;
  55708. isSeparator = item->isSeparator;
  55709. isTicked = item->isTicked;
  55710. isEnabled = item->active;
  55711. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55712. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55713. customColour = item->usesColour ? &(item->textColour) : 0;
  55714. customImage = item->image;
  55715. commandManager = item->commandManager;
  55716. return true;
  55717. }
  55718. END_JUCE_NAMESPACE
  55719. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55720. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55721. BEGIN_JUCE_NAMESPACE
  55722. ComponentDragger::ComponentDragger()
  55723. : constrainer (0)
  55724. {
  55725. }
  55726. ComponentDragger::~ComponentDragger()
  55727. {
  55728. }
  55729. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55730. ComponentBoundsConstrainer* const constrainer_)
  55731. {
  55732. jassert (componentToDrag->isValidComponent());
  55733. if (componentToDrag != 0)
  55734. {
  55735. constrainer = constrainer_;
  55736. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55737. }
  55738. }
  55739. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55740. {
  55741. jassert (componentToDrag->isValidComponent());
  55742. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55743. if (componentToDrag != 0)
  55744. {
  55745. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55746. const Component* const parentComp = componentToDrag->getParentComponent();
  55747. if (parentComp != 0)
  55748. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55749. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55750. if (constrainer != 0)
  55751. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55752. else
  55753. componentToDrag->setBounds (bounds);
  55754. }
  55755. }
  55756. END_JUCE_NAMESPACE
  55757. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55758. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55759. BEGIN_JUCE_NAMESPACE
  55760. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55761. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55762. class DragImageComponent : public Component,
  55763. public Timer
  55764. {
  55765. public:
  55766. DragImageComponent (Image* const im,
  55767. const String& desc,
  55768. Component* const sourceComponent,
  55769. Component* const mouseDragSource_,
  55770. DragAndDropContainer* const o,
  55771. const Point<int>& imageOffset_)
  55772. : image (im),
  55773. source (sourceComponent),
  55774. mouseDragSource (mouseDragSource_),
  55775. owner (o),
  55776. dragDesc (desc),
  55777. imageOffset (imageOffset_),
  55778. hasCheckedForExternalDrag (false),
  55779. drawImage (true)
  55780. {
  55781. setSize (im->getWidth(), im->getHeight());
  55782. if (mouseDragSource == 0)
  55783. mouseDragSource = source;
  55784. mouseDragSource->addMouseListener (this, false);
  55785. startTimer (200);
  55786. setInterceptsMouseClicks (false, false);
  55787. setAlwaysOnTop (true);
  55788. }
  55789. ~DragImageComponent()
  55790. {
  55791. if (owner->dragImageComponent == this)
  55792. owner->dragImageComponent.release();
  55793. if (mouseDragSource != 0)
  55794. {
  55795. mouseDragSource->removeMouseListener (this);
  55796. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55797. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55798. }
  55799. }
  55800. void paint (Graphics& g)
  55801. {
  55802. if (isOpaque())
  55803. g.fillAll (Colours::white);
  55804. if (drawImage)
  55805. {
  55806. g.setOpacity (1.0f);
  55807. g.drawImageAt (image, 0, 0);
  55808. }
  55809. }
  55810. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55811. {
  55812. Component* hit = getParentComponent();
  55813. if (hit == 0)
  55814. {
  55815. hit = Desktop::getInstance().findComponentAt (screenPos);
  55816. }
  55817. else
  55818. {
  55819. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55820. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55821. }
  55822. // (note: use a local copy of the dragDesc member in case the callback runs
  55823. // a modal loop and deletes this object before the method completes)
  55824. const String dragDescLocal (dragDesc);
  55825. while (hit != 0)
  55826. {
  55827. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55828. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55829. {
  55830. relativePos = hit->globalPositionToRelative (screenPos);
  55831. return ddt;
  55832. }
  55833. hit = hit->getParentComponent();
  55834. }
  55835. return 0;
  55836. }
  55837. void mouseUp (const MouseEvent& e)
  55838. {
  55839. if (e.originalComponent != this)
  55840. {
  55841. if (mouseDragSource != 0)
  55842. mouseDragSource->removeMouseListener (this);
  55843. bool dropAccepted = false;
  55844. DragAndDropTarget* ddt = 0;
  55845. Point<int> relPos;
  55846. if (isVisible())
  55847. {
  55848. setVisible (false);
  55849. ddt = findTarget (e.getScreenPosition(), relPos);
  55850. // fade this component and remove it - it'll be deleted later by the timer callback
  55851. dropAccepted = ddt != 0;
  55852. setVisible (true);
  55853. if (dropAccepted || source == 0)
  55854. {
  55855. fadeOutComponent (120);
  55856. }
  55857. else
  55858. {
  55859. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55860. source->getHeight() / 2)));
  55861. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55862. getHeight() / 2)));
  55863. fadeOutComponent (120,
  55864. target.getX() - ourCentre.getX(),
  55865. target.getY() - ourCentre.getY());
  55866. }
  55867. }
  55868. if (getParentComponent() != 0)
  55869. getParentComponent()->removeChildComponent (this);
  55870. if (dropAccepted && ddt != 0)
  55871. {
  55872. // (note: use a local copy of the dragDesc member in case the callback runs
  55873. // a modal loop and deletes this object before the method completes)
  55874. const String dragDescLocal (dragDesc);
  55875. currentlyOverComp = 0;
  55876. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55877. }
  55878. // careful - this object could now be deleted..
  55879. }
  55880. }
  55881. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55882. {
  55883. // (note: use a local copy of the dragDesc member in case the callback runs
  55884. // a modal loop and deletes this object before it returns)
  55885. const String dragDescLocal (dragDesc);
  55886. Point<int> newPos (screenPos + imageOffset);
  55887. if (getParentComponent() != 0)
  55888. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55889. //if (newX != getX() || newY != getY())
  55890. {
  55891. setTopLeftPosition (newPos.getX(), newPos.getY());
  55892. Point<int> relPos;
  55893. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55894. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55895. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55896. if (ddtComp != currentlyOverComp)
  55897. {
  55898. if (currentlyOverComp != 0 && source != 0
  55899. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55900. {
  55901. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55902. }
  55903. currentlyOverComp = ddtComp;
  55904. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55905. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55906. }
  55907. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55908. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55909. if (getCurrentlyOver() == 0
  55910. && canDoExternalDrag
  55911. && ! hasCheckedForExternalDrag)
  55912. {
  55913. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55914. {
  55915. hasCheckedForExternalDrag = true;
  55916. StringArray files;
  55917. bool canMoveFiles = false;
  55918. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55919. && files.size() > 0)
  55920. {
  55921. Component::SafePointer<Component> cdw (this);
  55922. setVisible (false);
  55923. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55924. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55925. if (cdw != 0)
  55926. delete this;
  55927. return;
  55928. }
  55929. }
  55930. }
  55931. }
  55932. }
  55933. void mouseDrag (const MouseEvent& e)
  55934. {
  55935. if (e.originalComponent != this)
  55936. updateLocation (true, e.getScreenPosition());
  55937. }
  55938. void timerCallback()
  55939. {
  55940. if (source == 0)
  55941. {
  55942. delete this;
  55943. }
  55944. else if (! isMouseButtonDownAnywhere())
  55945. {
  55946. if (mouseDragSource != 0)
  55947. mouseDragSource->removeMouseListener (this);
  55948. delete this;
  55949. }
  55950. }
  55951. private:
  55952. ScopedPointer<Image> image;
  55953. Component::SafePointer<Component> source;
  55954. Component::SafePointer<Component> mouseDragSource;
  55955. DragAndDropContainer* const owner;
  55956. Component::SafePointer<Component> currentlyOverComp;
  55957. DragAndDropTarget* getCurrentlyOver()
  55958. {
  55959. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55960. }
  55961. String dragDesc;
  55962. const Point<int> imageOffset;
  55963. bool hasCheckedForExternalDrag, drawImage;
  55964. DragImageComponent (const DragImageComponent&);
  55965. DragImageComponent& operator= (const DragImageComponent&);
  55966. };
  55967. DragAndDropContainer::DragAndDropContainer()
  55968. {
  55969. }
  55970. DragAndDropContainer::~DragAndDropContainer()
  55971. {
  55972. dragImageComponent = 0;
  55973. }
  55974. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55975. Component* sourceComponent,
  55976. Image* dragImage_,
  55977. const bool allowDraggingToExternalWindows,
  55978. const Point<int>* imageOffsetFromMouse)
  55979. {
  55980. ScopedPointer <Image> dragImage (dragImage_);
  55981. if (dragImageComponent == 0)
  55982. {
  55983. Component* const thisComp = dynamic_cast <Component*> (this);
  55984. if (thisComp == 0)
  55985. {
  55986. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55987. return;
  55988. }
  55989. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55990. if (draggingSource == 0 || ! draggingSource->isDragging())
  55991. {
  55992. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55993. return;
  55994. }
  55995. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55996. Point<int> imageOffset;
  55997. if (dragImage == 0)
  55998. {
  55999. dragImage = sourceComponent->createComponentSnapshot (sourceComponent->getLocalBounds());
  56000. if (dragImage->getFormat() != Image::ARGB)
  56001. {
  56002. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56003. Graphics g2 (*newIm);
  56004. g2.drawImageAt (dragImage, 0, 0);
  56005. dragImage = newIm;
  56006. }
  56007. dragImage->multiplyAllAlphas (0.6f);
  56008. const int lo = 150;
  56009. const int hi = 400;
  56010. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  56011. Point<int> clipped (dragImage->getBounds().getConstrainedPoint (relPos));
  56012. for (int y = dragImage->getHeight(); --y >= 0;)
  56013. {
  56014. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  56015. for (int x = dragImage->getWidth(); --x >= 0;)
  56016. {
  56017. const int dx = x - clipped.getX();
  56018. const int distance = roundToInt (sqrt (dx * dx + dy));
  56019. if (distance > lo)
  56020. {
  56021. const float alpha = (distance > hi) ? 0
  56022. : (hi - distance) / (float) (hi - lo)
  56023. + Random::getSystemRandom().nextFloat() * 0.008f;
  56024. dragImage->multiplyAlphaAt (x, y, alpha);
  56025. }
  56026. }
  56027. }
  56028. imageOffset = -clipped;
  56029. }
  56030. else
  56031. {
  56032. if (imageOffsetFromMouse == 0)
  56033. imageOffset = Point<int> (dragImage->getWidth() / -2,
  56034. dragImage->getHeight() / -2);
  56035. else
  56036. imageOffset = *imageOffsetFromMouse;
  56037. }
  56038. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56039. draggingSource->getComponentUnderMouse(), this, imageOffset);
  56040. currentDragDesc = sourceDescription;
  56041. if (allowDraggingToExternalWindows)
  56042. {
  56043. if (! Desktop::canUseSemiTransparentWindows())
  56044. dragImageComponent->setOpaque (true);
  56045. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56046. | ComponentPeer::windowIsTemporary
  56047. | ComponentPeer::windowIgnoresKeyPresses);
  56048. }
  56049. else
  56050. thisComp->addChildComponent (dragImageComponent);
  56051. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  56052. dragImageComponent->setVisible (true);
  56053. }
  56054. }
  56055. bool DragAndDropContainer::isDragAndDropActive() const
  56056. {
  56057. return dragImageComponent != 0;
  56058. }
  56059. const String DragAndDropContainer::getCurrentDragDescription() const
  56060. {
  56061. return (dragImageComponent != 0) ? currentDragDesc
  56062. : String::empty;
  56063. }
  56064. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56065. {
  56066. if (c == 0)
  56067. return 0;
  56068. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56069. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56070. }
  56071. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56072. {
  56073. return false;
  56074. }
  56075. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56076. {
  56077. }
  56078. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56079. {
  56080. }
  56081. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56082. {
  56083. }
  56084. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56085. {
  56086. return true;
  56087. }
  56088. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56089. {
  56090. }
  56091. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56092. {
  56093. }
  56094. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56095. {
  56096. }
  56097. END_JUCE_NAMESPACE
  56098. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56099. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56100. BEGIN_JUCE_NAMESPACE
  56101. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY);
  56102. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type);
  56103. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard);
  56104. class MouseCursor::SharedCursorHandle
  56105. {
  56106. public:
  56107. explicit SharedCursorHandle (const MouseCursor::StandardCursorType type)
  56108. : handle (juce_createStandardMouseCursor (type)),
  56109. refCount (1),
  56110. standardType (type),
  56111. isStandard (true)
  56112. {
  56113. }
  56114. SharedCursorHandle (const Image& image, const int hotSpotX, const int hotSpotY)
  56115. : handle (juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY)),
  56116. refCount (1),
  56117. standardType (MouseCursor::NormalCursor),
  56118. isStandard (false)
  56119. {
  56120. }
  56121. static SharedCursorHandle* createStandard (const MouseCursor::StandardCursorType type)
  56122. {
  56123. const ScopedLock sl (getLock());
  56124. for (int i = getCursors().size(); --i >= 0;)
  56125. {
  56126. SharedCursorHandle* const sc = getCursors().getUnchecked(i);
  56127. if (sc->standardType == type)
  56128. return sc->retain();
  56129. }
  56130. SharedCursorHandle* const sc = new SharedCursorHandle (type);
  56131. getCursors().add (sc);
  56132. return sc;
  56133. }
  56134. SharedCursorHandle* retain() throw()
  56135. {
  56136. Atomic::increment (refCount);
  56137. return this;
  56138. }
  56139. void release()
  56140. {
  56141. if (Atomic::decrementAndReturn (refCount) == 0)
  56142. {
  56143. if (isStandard)
  56144. {
  56145. const ScopedLock sl (getLock());
  56146. getCursors().removeValue (this);
  56147. }
  56148. delete this;
  56149. }
  56150. }
  56151. void* getHandle() const throw() { return handle; }
  56152. juce_UseDebuggingNewOperator
  56153. private:
  56154. void* const handle;
  56155. int32 refCount;
  56156. const MouseCursor::StandardCursorType standardType;
  56157. const bool isStandard;
  56158. static CriticalSection& getLock()
  56159. {
  56160. static CriticalSection lock;
  56161. return lock;
  56162. }
  56163. static Array <SharedCursorHandle*>& getCursors()
  56164. {
  56165. static Array <SharedCursorHandle*> cursors;
  56166. return cursors;
  56167. }
  56168. ~SharedCursorHandle()
  56169. {
  56170. juce_deleteMouseCursor (handle, isStandard);
  56171. }
  56172. SharedCursorHandle& operator= (const SharedCursorHandle&);
  56173. };
  56174. MouseCursor::MouseCursor()
  56175. : cursorHandle (SharedCursorHandle::createStandard (NormalCursor))
  56176. {
  56177. jassert (cursorHandle != 0);
  56178. }
  56179. MouseCursor::MouseCursor (const StandardCursorType type)
  56180. : cursorHandle (SharedCursorHandle::createStandard (type))
  56181. {
  56182. jassert (cursorHandle != 0);
  56183. }
  56184. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY)
  56185. : cursorHandle (new SharedCursorHandle (image, hotSpotX, hotSpotY))
  56186. {
  56187. }
  56188. MouseCursor::MouseCursor (const MouseCursor& other)
  56189. : cursorHandle (other.cursorHandle->retain())
  56190. {
  56191. }
  56192. MouseCursor::~MouseCursor()
  56193. {
  56194. cursorHandle->release();
  56195. }
  56196. MouseCursor& MouseCursor::operator= (const MouseCursor& other)
  56197. {
  56198. other.cursorHandle->retain();
  56199. cursorHandle->release();
  56200. cursorHandle = other.cursorHandle;
  56201. return *this;
  56202. }
  56203. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56204. {
  56205. return getHandle() == other.getHandle();
  56206. }
  56207. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56208. {
  56209. return getHandle() != other.getHandle();
  56210. }
  56211. void* MouseCursor::getHandle() const throw()
  56212. {
  56213. return cursorHandle->getHandle();
  56214. }
  56215. void MouseCursor::showWaitCursor() throw()
  56216. {
  56217. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56218. }
  56219. void MouseCursor::hideWaitCursor() throw()
  56220. {
  56221. Desktop::getInstance().getMainMouseSource().revealCursor();
  56222. }
  56223. END_JUCE_NAMESPACE
  56224. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56225. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56226. BEGIN_JUCE_NAMESPACE
  56227. MouseEvent::MouseEvent (MouseInputSource& source_,
  56228. const Point<int>& position,
  56229. const ModifierKeys& mods_,
  56230. Component* const originator,
  56231. const Time& eventTime_,
  56232. const Point<int> mouseDownPos_,
  56233. const Time& mouseDownTime_,
  56234. const int numberOfClicks_,
  56235. const bool mouseWasDragged) throw()
  56236. : x (position.getX()),
  56237. y (position.getY()),
  56238. mods (mods_),
  56239. eventComponent (originator),
  56240. originalComponent (originator),
  56241. eventTime (eventTime_),
  56242. source (source_),
  56243. mouseDownPos (mouseDownPos_),
  56244. mouseDownTime (mouseDownTime_),
  56245. numberOfClicks (numberOfClicks_),
  56246. wasMovedSinceMouseDown (mouseWasDragged)
  56247. {
  56248. }
  56249. MouseEvent::~MouseEvent() throw()
  56250. {
  56251. }
  56252. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56253. {
  56254. if (otherComponent == 0)
  56255. {
  56256. jassertfalse
  56257. return *this;
  56258. }
  56259. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56260. mods, originalComponent, eventTime,
  56261. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56262. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56263. }
  56264. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56265. {
  56266. return MouseEvent (source, newPosition, mods, originalComponent,
  56267. eventTime, mouseDownPos, mouseDownTime,
  56268. numberOfClicks, wasMovedSinceMouseDown);
  56269. }
  56270. bool MouseEvent::mouseWasClicked() const throw()
  56271. {
  56272. return ! wasMovedSinceMouseDown;
  56273. }
  56274. int MouseEvent::getMouseDownX() const throw()
  56275. {
  56276. return mouseDownPos.getX();
  56277. }
  56278. int MouseEvent::getMouseDownY() const throw()
  56279. {
  56280. return mouseDownPos.getY();
  56281. }
  56282. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56283. {
  56284. return mouseDownPos;
  56285. }
  56286. int MouseEvent::getDistanceFromDragStartX() const throw()
  56287. {
  56288. return x - mouseDownPos.getX();
  56289. }
  56290. int MouseEvent::getDistanceFromDragStartY() const throw()
  56291. {
  56292. return y - mouseDownPos.getY();
  56293. }
  56294. int MouseEvent::getDistanceFromDragStart() const throw()
  56295. {
  56296. return mouseDownPos.getDistanceFrom (getPosition());
  56297. }
  56298. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56299. {
  56300. return getPosition() - mouseDownPos;
  56301. }
  56302. int MouseEvent::getLengthOfMousePress() const throw()
  56303. {
  56304. if (mouseDownTime.toMilliseconds() > 0)
  56305. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56306. return 0;
  56307. }
  56308. const Point<int> MouseEvent::getPosition() const throw()
  56309. {
  56310. return Point<int> (x, y);
  56311. }
  56312. int MouseEvent::getScreenX() const
  56313. {
  56314. return getScreenPosition().getX();
  56315. }
  56316. int MouseEvent::getScreenY() const
  56317. {
  56318. return getScreenPosition().getY();
  56319. }
  56320. const Point<int> MouseEvent::getScreenPosition() const
  56321. {
  56322. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56323. }
  56324. int MouseEvent::getMouseDownScreenX() const
  56325. {
  56326. return getMouseDownScreenPosition().getX();
  56327. }
  56328. int MouseEvent::getMouseDownScreenY() const
  56329. {
  56330. return getMouseDownScreenPosition().getY();
  56331. }
  56332. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56333. {
  56334. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56335. }
  56336. static int doubleClickTimeOutMs = 400;
  56337. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56338. {
  56339. doubleClickTimeOutMs = newTime;
  56340. }
  56341. int MouseEvent::getDoubleClickTimeout() throw()
  56342. {
  56343. return doubleClickTimeOutMs;
  56344. }
  56345. END_JUCE_NAMESPACE
  56346. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56347. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56348. BEGIN_JUCE_NAMESPACE
  56349. class MouseInputSourceInternal : public AsyncUpdater
  56350. {
  56351. public:
  56352. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56353. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56354. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56355. {
  56356. zerostruct (mouseDowns);
  56357. }
  56358. ~MouseInputSourceInternal()
  56359. {
  56360. }
  56361. bool isDragging() const throw()
  56362. {
  56363. return buttonState.isAnyMouseButtonDown();
  56364. }
  56365. Component* getComponentUnderMouse() const
  56366. {
  56367. return static_cast <Component*> (componentUnderMouse);
  56368. }
  56369. const ModifierKeys getCurrentModifiers() const
  56370. {
  56371. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56372. }
  56373. ComponentPeer* getPeer()
  56374. {
  56375. if (! ComponentPeer::isValidPeer (lastPeer))
  56376. lastPeer = 0;
  56377. return lastPeer;
  56378. }
  56379. Component* findComponentAt (const Point<int>& screenPos)
  56380. {
  56381. ComponentPeer* const peer = getPeer();
  56382. if (peer != 0)
  56383. {
  56384. Component* const comp = peer->getComponent();
  56385. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56386. // (the contains() call is needed to test for overlapping desktop windows)
  56387. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56388. return comp->getComponentAt (relativePos);
  56389. }
  56390. return 0;
  56391. }
  56392. const Point<int> getScreenPosition() const throw()
  56393. {
  56394. return lastScreenPos + unboundedMouseOffset;
  56395. }
  56396. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56397. {
  56398. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56399. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56400. }
  56401. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56402. {
  56403. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56404. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56405. }
  56406. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56407. {
  56408. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56409. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56410. }
  56411. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56412. {
  56413. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56414. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56415. }
  56416. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56417. {
  56418. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56419. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56420. }
  56421. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56422. {
  56423. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56424. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56425. }
  56426. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56427. {
  56428. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56429. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56430. }
  56431. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56432. {
  56433. if (buttonState != newButtonState)
  56434. {
  56435. // (ignore secondary clicks when there's already a button down)
  56436. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56437. {
  56438. buttonState = newButtonState;
  56439. return;
  56440. }
  56441. if (buttonState.isAnyMouseButtonDown())
  56442. {
  56443. Component* const current = getComponentUnderMouse();
  56444. if (current != 0)
  56445. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56446. enableUnboundedMouseMovement (false, false);
  56447. }
  56448. buttonState = newButtonState;
  56449. if (buttonState.isAnyMouseButtonDown())
  56450. {
  56451. Desktop::getInstance().incrementMouseClickCounter();
  56452. Component* const current = getComponentUnderMouse();
  56453. if (current != 0)
  56454. {
  56455. registerMouseDown (screenPos, time, current);
  56456. sendMouseDown (current, screenPos, time);
  56457. }
  56458. }
  56459. }
  56460. }
  56461. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56462. {
  56463. Component* current = getComponentUnderMouse();
  56464. if (newComponent != current)
  56465. {
  56466. Component::SafePointer<Component> safeNewComp (newComponent);
  56467. const ModifierKeys originalButtonState (buttonState);
  56468. if (current != 0)
  56469. {
  56470. setButtons (screenPos, time, ModifierKeys());
  56471. sendMouseExit (current, screenPos, time);
  56472. buttonState = originalButtonState;
  56473. }
  56474. componentUnderMouse = safeNewComp;
  56475. current = getComponentUnderMouse();
  56476. if (current != 0)
  56477. sendMouseEnter (current, screenPos, time);
  56478. revealCursor (false);
  56479. setButtons (screenPos, time, originalButtonState);
  56480. }
  56481. }
  56482. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56483. {
  56484. ModifierKeys::updateCurrentModifiers();
  56485. if (newPeer != lastPeer)
  56486. {
  56487. setComponentUnderMouse (0, screenPos, time);
  56488. lastPeer = newPeer;
  56489. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56490. }
  56491. }
  56492. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56493. {
  56494. if (! isDragging())
  56495. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56496. if (newScreenPos != lastScreenPos || forceUpdate)
  56497. {
  56498. cancelPendingUpdate();
  56499. lastScreenPos = newScreenPos;
  56500. Component* const current = getComponentUnderMouse();
  56501. if (current != 0)
  56502. {
  56503. if (isDragging())
  56504. {
  56505. registerMouseDrag (newScreenPos);
  56506. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56507. if (isUnboundedMouseModeOn)
  56508. handleUnboundedDrag (current);
  56509. }
  56510. else
  56511. {
  56512. sendMouseMove (current, newScreenPos, time);
  56513. }
  56514. }
  56515. revealCursor (false);
  56516. }
  56517. }
  56518. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56519. {
  56520. jassert (newPeer != 0);
  56521. lastTime = time;
  56522. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56523. if (isDragging() && newMods.isAnyMouseButtonDown())
  56524. {
  56525. setScreenPos (screenPos, time, false);
  56526. }
  56527. else
  56528. {
  56529. setPeer (newPeer, screenPos, time);
  56530. ComponentPeer* peer = getPeer();
  56531. if (peer != 0)
  56532. {
  56533. setButtons (screenPos, time, newMods);
  56534. peer = getPeer();
  56535. if (peer != 0)
  56536. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56537. }
  56538. }
  56539. }
  56540. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56541. {
  56542. jassert (peer != 0);
  56543. lastTime = time;
  56544. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56545. setPeer (peer, screenPos, time);
  56546. setScreenPos (screenPos, time, false);
  56547. triggerFakeMove();
  56548. if (! isDragging())
  56549. {
  56550. Component* current = getComponentUnderMouse();
  56551. if (current != 0)
  56552. sendMouseWheel (current, screenPos, time, x, y);
  56553. }
  56554. }
  56555. const Time getLastMouseDownTime() const throw()
  56556. {
  56557. return Time (mouseDowns[0].time);
  56558. }
  56559. const Point<int> getLastMouseDownPosition() const throw()
  56560. {
  56561. return mouseDowns[0].position;
  56562. }
  56563. int getNumberOfMultipleClicks() const throw()
  56564. {
  56565. int numClicks = 0;
  56566. if (mouseDowns[0].time != 0)
  56567. {
  56568. if (! mouseMovedSignificantlySincePressed)
  56569. ++numClicks;
  56570. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56571. {
  56572. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56573. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56574. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56575. && mouseDowns[0].component == mouseDowns[i].component)
  56576. {
  56577. ++numClicks;
  56578. }
  56579. else
  56580. {
  56581. break;
  56582. }
  56583. }
  56584. }
  56585. return numClicks;
  56586. }
  56587. bool hasMouseMovedSignificantlySincePressed() const throw()
  56588. {
  56589. return mouseMovedSignificantlySincePressed
  56590. || lastTime > mouseDowns[0].time + 300;
  56591. }
  56592. void triggerFakeMove()
  56593. {
  56594. triggerAsyncUpdate();
  56595. }
  56596. void handleAsyncUpdate()
  56597. {
  56598. if (! isDragging())
  56599. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56600. }
  56601. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56602. {
  56603. enable = enable && isDragging();
  56604. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56605. if (enable != isUnboundedMouseModeOn)
  56606. {
  56607. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56608. {
  56609. // when released, return the mouse to within the component's bounds
  56610. Component* current = getComponentUnderMouse();
  56611. if (current != 0)
  56612. Desktop::setMousePosition (current->getScreenBounds()
  56613. .getConstrainedPoint (current->getMouseXYRelative()));
  56614. }
  56615. isUnboundedMouseModeOn = enable;
  56616. unboundedMouseOffset = Point<int>();
  56617. revealCursor (true);
  56618. }
  56619. }
  56620. void handleUnboundedDrag (Component* current)
  56621. {
  56622. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56623. if (! screenArea.contains (lastScreenPos))
  56624. {
  56625. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56626. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56627. Desktop::setMousePosition (componentCentre);
  56628. }
  56629. else if (isCursorVisibleUntilOffscreen
  56630. && (! unboundedMouseOffset.isOrigin())
  56631. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56632. {
  56633. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56634. unboundedMouseOffset = Point<int>();
  56635. }
  56636. }
  56637. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56638. {
  56639. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56640. {
  56641. cursor = MouseCursor::NoCursor;
  56642. forcedUpdate = true;
  56643. }
  56644. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56645. {
  56646. currentCursorHandle = cursor.getHandle();
  56647. cursor.showInWindow (getPeer());
  56648. }
  56649. }
  56650. void hideCursor()
  56651. {
  56652. showMouseCursor (MouseCursor::NoCursor, true);
  56653. }
  56654. void revealCursor (bool forcedUpdate)
  56655. {
  56656. MouseCursor mc (MouseCursor::NormalCursor);
  56657. Component* current = getComponentUnderMouse();
  56658. if (current != 0)
  56659. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56660. showMouseCursor (mc, forcedUpdate);
  56661. }
  56662. int index;
  56663. bool isMouseDevice;
  56664. Point<int> lastScreenPos;
  56665. ModifierKeys buttonState;
  56666. private:
  56667. MouseInputSource& source;
  56668. Component::SafePointer<Component> componentUnderMouse;
  56669. ComponentPeer* lastPeer;
  56670. Point<int> unboundedMouseOffset;
  56671. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56672. void* currentCursorHandle;
  56673. struct RecentMouseDown
  56674. {
  56675. Point<int> position;
  56676. int64 time;
  56677. Component* component;
  56678. };
  56679. RecentMouseDown mouseDowns[4];
  56680. bool mouseMovedSignificantlySincePressed;
  56681. int64 lastTime;
  56682. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56683. {
  56684. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56685. mouseDowns[i] = mouseDowns[i - 1];
  56686. mouseDowns[0].position = screenPos;
  56687. mouseDowns[0].time = time;
  56688. mouseDowns[0].component = component;
  56689. mouseMovedSignificantlySincePressed = false;
  56690. }
  56691. void registerMouseDrag (const Point<int>& screenPos) throw()
  56692. {
  56693. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56694. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56695. }
  56696. MouseInputSourceInternal (const MouseInputSourceInternal&);
  56697. MouseInputSourceInternal& operator= (const MouseInputSourceInternal&);
  56698. };
  56699. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56700. {
  56701. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56702. }
  56703. MouseInputSource::~MouseInputSource()
  56704. {
  56705. }
  56706. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56707. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56708. bool MouseInputSource::canHover() const { return isMouse(); }
  56709. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56710. int MouseInputSource::getIndex() const { return pimpl->index; }
  56711. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56712. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56713. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56714. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56715. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56716. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56717. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56718. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56719. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56720. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56721. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56722. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56723. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56724. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56725. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56726. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56727. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56728. {
  56729. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56730. }
  56731. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56732. {
  56733. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56734. }
  56735. END_JUCE_NAMESPACE
  56736. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56737. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56738. BEGIN_JUCE_NAMESPACE
  56739. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56740. : source (0),
  56741. hoverTimeMillisecs (hoverTimeMillisecs_),
  56742. hasJustHovered (false)
  56743. {
  56744. internalTimer.owner = this;
  56745. }
  56746. MouseHoverDetector::~MouseHoverDetector()
  56747. {
  56748. setHoverComponent (0);
  56749. }
  56750. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56751. {
  56752. hoverTimeMillisecs = newTimeInMillisecs;
  56753. }
  56754. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56755. {
  56756. if (source != newSourceComponent)
  56757. {
  56758. internalTimer.stopTimer();
  56759. hasJustHovered = false;
  56760. if (source != 0)
  56761. {
  56762. // ! you need to delete the hover detector before deleting its component
  56763. jassert (source->isValidComponent());
  56764. source->removeMouseListener (&internalTimer);
  56765. }
  56766. source = newSourceComponent;
  56767. if (newSourceComponent != 0)
  56768. newSourceComponent->addMouseListener (&internalTimer, false);
  56769. }
  56770. }
  56771. void MouseHoverDetector::hoverTimerCallback()
  56772. {
  56773. internalTimer.stopTimer();
  56774. if (source != 0)
  56775. {
  56776. const Point<int> pos (source->getMouseXYRelative());
  56777. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56778. {
  56779. hasJustHovered = true;
  56780. mouseHovered (pos.getX(), pos.getY());
  56781. }
  56782. }
  56783. }
  56784. void MouseHoverDetector::checkJustHoveredCallback()
  56785. {
  56786. if (hasJustHovered)
  56787. {
  56788. hasJustHovered = false;
  56789. mouseMovedAfterHover();
  56790. }
  56791. }
  56792. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56793. {
  56794. owner->hoverTimerCallback();
  56795. }
  56796. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56797. {
  56798. stopTimer();
  56799. owner->checkJustHoveredCallback();
  56800. }
  56801. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56802. {
  56803. stopTimer();
  56804. owner->checkJustHoveredCallback();
  56805. }
  56806. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56807. {
  56808. stopTimer();
  56809. owner->checkJustHoveredCallback();
  56810. }
  56811. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56812. {
  56813. stopTimer();
  56814. owner->checkJustHoveredCallback();
  56815. }
  56816. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56817. {
  56818. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56819. {
  56820. lastX = e.x;
  56821. lastY = e.y;
  56822. if (owner->source != 0)
  56823. startTimer (owner->hoverTimeMillisecs);
  56824. owner->checkJustHoveredCallback();
  56825. }
  56826. }
  56827. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56828. {
  56829. stopTimer();
  56830. owner->checkJustHoveredCallback();
  56831. }
  56832. END_JUCE_NAMESPACE
  56833. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56834. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56835. BEGIN_JUCE_NAMESPACE
  56836. void MouseListener::mouseEnter (const MouseEvent&)
  56837. {
  56838. }
  56839. void MouseListener::mouseExit (const MouseEvent&)
  56840. {
  56841. }
  56842. void MouseListener::mouseDown (const MouseEvent&)
  56843. {
  56844. }
  56845. void MouseListener::mouseUp (const MouseEvent&)
  56846. {
  56847. }
  56848. void MouseListener::mouseDrag (const MouseEvent&)
  56849. {
  56850. }
  56851. void MouseListener::mouseMove (const MouseEvent&)
  56852. {
  56853. }
  56854. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56855. {
  56856. }
  56857. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56858. {
  56859. }
  56860. END_JUCE_NAMESPACE
  56861. /*** End of inlined file: juce_MouseListener.cpp ***/
  56862. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56863. BEGIN_JUCE_NAMESPACE
  56864. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56865. const String& buttonTextWhenTrue,
  56866. const String& buttonTextWhenFalse)
  56867. : PropertyComponent (name),
  56868. onText (buttonTextWhenTrue),
  56869. offText (buttonTextWhenFalse)
  56870. {
  56871. createButton();
  56872. button->addButtonListener (this);
  56873. }
  56874. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56875. const String& name,
  56876. const String& buttonText)
  56877. : PropertyComponent (name),
  56878. onText (buttonText),
  56879. offText (buttonText)
  56880. {
  56881. createButton();
  56882. button->setButtonText (buttonText);
  56883. button->getToggleStateValue().referTo (valueToControl);
  56884. button->setClickingTogglesState (true);
  56885. }
  56886. BooleanPropertyComponent::~BooleanPropertyComponent()
  56887. {
  56888. deleteAllChildren();
  56889. }
  56890. void BooleanPropertyComponent::createButton()
  56891. {
  56892. addAndMakeVisible (button = new ToggleButton (String::empty));
  56893. button->setClickingTogglesState (false);
  56894. }
  56895. void BooleanPropertyComponent::setState (const bool newState)
  56896. {
  56897. button->setToggleState (newState, true);
  56898. }
  56899. bool BooleanPropertyComponent::getState() const
  56900. {
  56901. return button->getToggleState();
  56902. }
  56903. void BooleanPropertyComponent::paint (Graphics& g)
  56904. {
  56905. PropertyComponent::paint (g);
  56906. const Rectangle<int> r (button->getBounds());
  56907. g.setColour (Colours::white);
  56908. g.fillRect (r);
  56909. g.setColour (findColour (ComboBox::outlineColourId));
  56910. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56911. }
  56912. void BooleanPropertyComponent::refresh()
  56913. {
  56914. button->setToggleState (getState(), false);
  56915. button->setButtonText (button->getToggleState() ? onText : offText);
  56916. }
  56917. void BooleanPropertyComponent::buttonClicked (Button*)
  56918. {
  56919. setState (! getState());
  56920. }
  56921. END_JUCE_NAMESPACE
  56922. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56923. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56924. BEGIN_JUCE_NAMESPACE
  56925. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56926. const bool triggerOnMouseDown)
  56927. : PropertyComponent (name)
  56928. {
  56929. addAndMakeVisible (button = new TextButton (String::empty));
  56930. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56931. button->addButtonListener (this);
  56932. }
  56933. ButtonPropertyComponent::~ButtonPropertyComponent()
  56934. {
  56935. deleteAllChildren();
  56936. }
  56937. void ButtonPropertyComponent::refresh()
  56938. {
  56939. button->setButtonText (getButtonText());
  56940. }
  56941. void ButtonPropertyComponent::buttonClicked (Button*)
  56942. {
  56943. buttonClicked();
  56944. }
  56945. END_JUCE_NAMESPACE
  56946. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56947. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56948. BEGIN_JUCE_NAMESPACE
  56949. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56950. : PropertyComponent (name),
  56951. comboBox (0)
  56952. {
  56953. }
  56954. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56955. const String& name,
  56956. const StringArray& choices_,
  56957. const Array <int>* choiceIDs)
  56958. : PropertyComponent (name),
  56959. choices (choices_),
  56960. comboBox (0)
  56961. {
  56962. createComboBox (choiceIDs);
  56963. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56964. }
  56965. ChoicePropertyComponent::~ChoicePropertyComponent()
  56966. {
  56967. deleteAllChildren();
  56968. }
  56969. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56970. {
  56971. // The array of IDs must contain the same number of values as the choices list!
  56972. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56973. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56974. for (int i = 0; i < choices.size(); ++i)
  56975. {
  56976. if (choices[i].isNotEmpty())
  56977. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56978. : ((*choiceIDs)[i]));
  56979. else
  56980. comboBox->addSeparator();
  56981. }
  56982. comboBox->setEditableText (false);
  56983. }
  56984. void ChoicePropertyComponent::setIndex (const int newIndex)
  56985. {
  56986. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56987. }
  56988. int ChoicePropertyComponent::getIndex() const
  56989. {
  56990. return comboBox->getSelectedItemIndex();
  56991. }
  56992. const StringArray& ChoicePropertyComponent::getChoices() const
  56993. {
  56994. return choices;
  56995. }
  56996. void ChoicePropertyComponent::refresh()
  56997. {
  56998. if (comboBox == 0)
  56999. {
  57000. createComboBox (0);
  57001. comboBox->addListener (this);
  57002. }
  57003. comboBox->setSelectedId (getIndex() + 1, true);
  57004. }
  57005. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57006. {
  57007. const int newIndex = comboBox->getSelectedId() - 1;
  57008. if (newIndex != getIndex())
  57009. setIndex (newIndex);
  57010. }
  57011. END_JUCE_NAMESPACE
  57012. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57013. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57014. BEGIN_JUCE_NAMESPACE
  57015. PropertyComponent::PropertyComponent (const String& name,
  57016. const int preferredHeight_)
  57017. : Component (name),
  57018. preferredHeight (preferredHeight_)
  57019. {
  57020. jassert (name.isNotEmpty());
  57021. }
  57022. PropertyComponent::~PropertyComponent()
  57023. {
  57024. }
  57025. void PropertyComponent::paint (Graphics& g)
  57026. {
  57027. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57028. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57029. }
  57030. void PropertyComponent::resized()
  57031. {
  57032. if (getNumChildComponents() > 0)
  57033. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57034. }
  57035. void PropertyComponent::enablementChanged()
  57036. {
  57037. repaint();
  57038. }
  57039. END_JUCE_NAMESPACE
  57040. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57041. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57042. BEGIN_JUCE_NAMESPACE
  57043. class PropertyPanel::PropertyHolderComponent : public Component
  57044. {
  57045. public:
  57046. PropertyHolderComponent()
  57047. {
  57048. }
  57049. ~PropertyHolderComponent()
  57050. {
  57051. deleteAllChildren();
  57052. }
  57053. void paint (Graphics&)
  57054. {
  57055. }
  57056. void updateLayout (int width);
  57057. void refreshAll() const;
  57058. private:
  57059. PropertyHolderComponent (const PropertyHolderComponent&);
  57060. PropertyHolderComponent& operator= (const PropertyHolderComponent&);
  57061. };
  57062. class PropertySectionComponent : public Component
  57063. {
  57064. public:
  57065. PropertySectionComponent (const String& sectionTitle,
  57066. const Array <PropertyComponent*>& newProperties,
  57067. const bool open)
  57068. : Component (sectionTitle),
  57069. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57070. isOpen_ (open)
  57071. {
  57072. for (int i = newProperties.size(); --i >= 0;)
  57073. {
  57074. addAndMakeVisible (newProperties.getUnchecked(i));
  57075. newProperties.getUnchecked(i)->refresh();
  57076. }
  57077. }
  57078. ~PropertySectionComponent()
  57079. {
  57080. deleteAllChildren();
  57081. }
  57082. void paint (Graphics& g)
  57083. {
  57084. if (titleHeight > 0)
  57085. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57086. }
  57087. void resized()
  57088. {
  57089. int y = titleHeight;
  57090. for (int i = getNumChildComponents(); --i >= 0;)
  57091. {
  57092. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57093. if (pec != 0)
  57094. {
  57095. const int prefH = pec->getPreferredHeight();
  57096. pec->setBounds (1, y, getWidth() - 2, prefH);
  57097. y += prefH;
  57098. }
  57099. }
  57100. }
  57101. int getPreferredHeight() const
  57102. {
  57103. int y = titleHeight;
  57104. if (isOpen())
  57105. {
  57106. for (int i = 0; i < getNumChildComponents(); ++i)
  57107. {
  57108. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57109. if (pec != 0)
  57110. y += pec->getPreferredHeight();
  57111. }
  57112. }
  57113. return y;
  57114. }
  57115. void setOpen (const bool open)
  57116. {
  57117. if (isOpen_ != open)
  57118. {
  57119. isOpen_ = open;
  57120. for (int i = 0; i < getNumChildComponents(); ++i)
  57121. {
  57122. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57123. if (pec != 0)
  57124. pec->setVisible (open);
  57125. }
  57126. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57127. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57128. if (pp != 0)
  57129. pp->resized();
  57130. }
  57131. }
  57132. bool isOpen() const
  57133. {
  57134. return isOpen_;
  57135. }
  57136. void refreshAll() const
  57137. {
  57138. for (int i = 0; i < getNumChildComponents(); ++i)
  57139. {
  57140. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57141. if (pec != 0)
  57142. pec->refresh();
  57143. }
  57144. }
  57145. void mouseDown (const MouseEvent&)
  57146. {
  57147. }
  57148. void mouseUp (const MouseEvent& e)
  57149. {
  57150. if (e.getMouseDownX() < titleHeight
  57151. && e.x < titleHeight
  57152. && e.y < titleHeight
  57153. && e.getNumberOfClicks() != 2)
  57154. {
  57155. setOpen (! isOpen());
  57156. }
  57157. }
  57158. void mouseDoubleClick (const MouseEvent& e)
  57159. {
  57160. if (e.y < titleHeight)
  57161. setOpen (! isOpen());
  57162. }
  57163. private:
  57164. int titleHeight;
  57165. bool isOpen_;
  57166. PropertySectionComponent (const PropertySectionComponent&);
  57167. PropertySectionComponent& operator= (const PropertySectionComponent&);
  57168. };
  57169. void PropertyPanel::PropertyHolderComponent::updateLayout (const int width)
  57170. {
  57171. int y = 0;
  57172. for (int i = getNumChildComponents(); --i >= 0;)
  57173. {
  57174. PropertySectionComponent* const section
  57175. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57176. if (section != 0)
  57177. {
  57178. const int prefH = section->getPreferredHeight();
  57179. section->setBounds (0, y, width, prefH);
  57180. y += prefH;
  57181. }
  57182. }
  57183. setSize (width, y);
  57184. repaint();
  57185. }
  57186. void PropertyPanel::PropertyHolderComponent::refreshAll() const
  57187. {
  57188. for (int i = getNumChildComponents(); --i >= 0;)
  57189. {
  57190. PropertySectionComponent* const section
  57191. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57192. if (section != 0)
  57193. section->refreshAll();
  57194. }
  57195. }
  57196. PropertyPanel::PropertyPanel()
  57197. {
  57198. messageWhenEmpty = TRANS("(nothing selected)");
  57199. addAndMakeVisible (viewport = new Viewport());
  57200. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57201. viewport->setFocusContainer (true);
  57202. }
  57203. PropertyPanel::~PropertyPanel()
  57204. {
  57205. clear();
  57206. deleteAllChildren();
  57207. }
  57208. void PropertyPanel::paint (Graphics& g)
  57209. {
  57210. if (propertyHolderComponent->getNumChildComponents() == 0)
  57211. {
  57212. g.setColour (Colours::black.withAlpha (0.5f));
  57213. g.setFont (14.0f);
  57214. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57215. Justification::centred, true);
  57216. }
  57217. }
  57218. void PropertyPanel::resized()
  57219. {
  57220. viewport->setBounds (0, 0, getWidth(), getHeight());
  57221. updatePropHolderLayout();
  57222. }
  57223. void PropertyPanel::clear()
  57224. {
  57225. if (propertyHolderComponent->getNumChildComponents() > 0)
  57226. {
  57227. propertyHolderComponent->deleteAllChildren();
  57228. repaint();
  57229. }
  57230. }
  57231. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57232. {
  57233. if (propertyHolderComponent->getNumChildComponents() == 0)
  57234. repaint();
  57235. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57236. newProperties,
  57237. true), 0);
  57238. updatePropHolderLayout();
  57239. }
  57240. void PropertyPanel::addSection (const String& sectionTitle,
  57241. const Array <PropertyComponent*>& newProperties,
  57242. const bool shouldBeOpen)
  57243. {
  57244. jassert (sectionTitle.isNotEmpty());
  57245. if (propertyHolderComponent->getNumChildComponents() == 0)
  57246. repaint();
  57247. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57248. newProperties,
  57249. shouldBeOpen), 0);
  57250. updatePropHolderLayout();
  57251. }
  57252. void PropertyPanel::updatePropHolderLayout() const
  57253. {
  57254. const int maxWidth = viewport->getMaximumVisibleWidth();
  57255. propertyHolderComponent->updateLayout (maxWidth);
  57256. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57257. if (maxWidth != newMaxWidth)
  57258. {
  57259. // need to do this twice because of scrollbars changing the size, etc.
  57260. propertyHolderComponent->updateLayout (newMaxWidth);
  57261. }
  57262. }
  57263. void PropertyPanel::refreshAll() const
  57264. {
  57265. propertyHolderComponent->refreshAll();
  57266. }
  57267. const StringArray PropertyPanel::getSectionNames() const
  57268. {
  57269. StringArray s;
  57270. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57271. {
  57272. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57273. if (section != 0 && section->getName().isNotEmpty())
  57274. s.add (section->getName());
  57275. }
  57276. return s;
  57277. }
  57278. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57279. {
  57280. int index = 0;
  57281. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57282. {
  57283. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57284. if (section != 0 && section->getName().isNotEmpty())
  57285. {
  57286. if (index == sectionIndex)
  57287. return section->isOpen();
  57288. ++index;
  57289. }
  57290. }
  57291. return false;
  57292. }
  57293. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57294. {
  57295. int index = 0;
  57296. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57297. {
  57298. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57299. if (section != 0 && section->getName().isNotEmpty())
  57300. {
  57301. if (index == sectionIndex)
  57302. {
  57303. section->setOpen (shouldBeOpen);
  57304. break;
  57305. }
  57306. ++index;
  57307. }
  57308. }
  57309. }
  57310. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57311. {
  57312. int index = 0;
  57313. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57314. {
  57315. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57316. if (section != 0 && section->getName().isNotEmpty())
  57317. {
  57318. if (index == sectionIndex)
  57319. {
  57320. section->setEnabled (shouldBeEnabled);
  57321. break;
  57322. }
  57323. ++index;
  57324. }
  57325. }
  57326. }
  57327. XmlElement* PropertyPanel::getOpennessState() const
  57328. {
  57329. XmlElement* const xml = new XmlElement ("PROPERTYPANELSTATE");
  57330. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57331. const StringArray sections (getSectionNames());
  57332. for (int i = 0; i < sections.size(); ++i)
  57333. {
  57334. if (sections[i].isNotEmpty())
  57335. {
  57336. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57337. e->setAttribute ("name", sections[i]);
  57338. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57339. }
  57340. }
  57341. return xml;
  57342. }
  57343. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57344. {
  57345. if (xml.hasTagName ("PROPERTYPANELSTATE"))
  57346. {
  57347. const StringArray sections (getSectionNames());
  57348. forEachXmlChildElementWithTagName (xml, e, "SECTION")
  57349. {
  57350. setSectionOpen (sections.indexOf (e->getStringAttribute ("name")),
  57351. e->getBoolAttribute ("open"));
  57352. }
  57353. viewport->setViewPosition (viewport->getViewPositionX(),
  57354. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57355. }
  57356. }
  57357. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57358. {
  57359. if (messageWhenEmpty != newMessage)
  57360. {
  57361. messageWhenEmpty = newMessage;
  57362. repaint();
  57363. }
  57364. }
  57365. const String& PropertyPanel::getMessageWhenEmpty() const
  57366. {
  57367. return messageWhenEmpty;
  57368. }
  57369. END_JUCE_NAMESPACE
  57370. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57371. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57372. BEGIN_JUCE_NAMESPACE
  57373. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57374. const double rangeMin,
  57375. const double rangeMax,
  57376. const double interval,
  57377. const double skewFactor)
  57378. : PropertyComponent (name)
  57379. {
  57380. addAndMakeVisible (slider = new Slider (name));
  57381. slider->setRange (rangeMin, rangeMax, interval);
  57382. slider->setSkewFactor (skewFactor);
  57383. slider->setSliderStyle (Slider::LinearBar);
  57384. slider->addListener (this);
  57385. }
  57386. SliderPropertyComponent::SliderPropertyComponent (const Value& valueToControl,
  57387. const String& name,
  57388. const double rangeMin,
  57389. const double rangeMax,
  57390. const double interval,
  57391. const double skewFactor)
  57392. : PropertyComponent (name)
  57393. {
  57394. addAndMakeVisible (slider = new Slider (name));
  57395. slider->setRange (rangeMin, rangeMax, interval);
  57396. slider->setSkewFactor (skewFactor);
  57397. slider->setSliderStyle (Slider::LinearBar);
  57398. slider->getValueObject().referTo (valueToControl);
  57399. }
  57400. SliderPropertyComponent::~SliderPropertyComponent()
  57401. {
  57402. deleteAllChildren();
  57403. }
  57404. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57405. {
  57406. }
  57407. double SliderPropertyComponent::getValue() const
  57408. {
  57409. return slider->getValue();
  57410. }
  57411. void SliderPropertyComponent::refresh()
  57412. {
  57413. slider->setValue (getValue(), false);
  57414. }
  57415. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57416. {
  57417. if (getValue() != slider->getValue())
  57418. setValue (slider->getValue());
  57419. }
  57420. END_JUCE_NAMESPACE
  57421. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57422. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57423. BEGIN_JUCE_NAMESPACE
  57424. class TextPropLabel : public Label
  57425. {
  57426. TextPropertyComponent& owner;
  57427. int maxChars;
  57428. bool isMultiline;
  57429. public:
  57430. TextPropLabel (TextPropertyComponent& owner_,
  57431. const int maxChars_, const bool isMultiline_)
  57432. : Label (String::empty, String::empty),
  57433. owner (owner_),
  57434. maxChars (maxChars_),
  57435. isMultiline (isMultiline_)
  57436. {
  57437. setEditable (true, true, false);
  57438. setColour (backgroundColourId, Colours::white);
  57439. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57440. }
  57441. ~TextPropLabel()
  57442. {
  57443. }
  57444. TextEditor* createEditorComponent()
  57445. {
  57446. TextEditor* const textEditor = Label::createEditorComponent();
  57447. textEditor->setInputRestrictions (maxChars);
  57448. if (isMultiline)
  57449. {
  57450. textEditor->setMultiLine (true, true);
  57451. textEditor->setReturnKeyStartsNewLine (true);
  57452. }
  57453. return textEditor;
  57454. }
  57455. void textWasEdited()
  57456. {
  57457. owner.textWasEdited();
  57458. }
  57459. };
  57460. TextPropertyComponent::TextPropertyComponent (const String& name,
  57461. const int maxNumChars,
  57462. const bool isMultiLine)
  57463. : PropertyComponent (name)
  57464. {
  57465. createEditor (maxNumChars, isMultiLine);
  57466. }
  57467. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57468. const String& name,
  57469. const int maxNumChars,
  57470. const bool isMultiLine)
  57471. : PropertyComponent (name)
  57472. {
  57473. createEditor (maxNumChars, isMultiLine);
  57474. textEditor->getTextValue().referTo (valueToControl);
  57475. }
  57476. TextPropertyComponent::~TextPropertyComponent()
  57477. {
  57478. deleteAllChildren();
  57479. }
  57480. void TextPropertyComponent::setText (const String& newText)
  57481. {
  57482. textEditor->setText (newText, true);
  57483. }
  57484. const String TextPropertyComponent::getText() const
  57485. {
  57486. return textEditor->getText();
  57487. }
  57488. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57489. {
  57490. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57491. if (isMultiLine)
  57492. {
  57493. textEditor->setJustificationType (Justification::topLeft);
  57494. preferredHeight = 120;
  57495. }
  57496. }
  57497. void TextPropertyComponent::refresh()
  57498. {
  57499. textEditor->setText (getText(), false);
  57500. }
  57501. void TextPropertyComponent::textWasEdited()
  57502. {
  57503. const String newText (textEditor->getText());
  57504. if (getText() != newText)
  57505. setText (newText);
  57506. }
  57507. END_JUCE_NAMESPACE
  57508. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57509. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57510. BEGIN_JUCE_NAMESPACE
  57511. class SimpleDeviceManagerInputLevelMeter : public Component,
  57512. public Timer
  57513. {
  57514. public:
  57515. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57516. : manager (manager_),
  57517. level (0)
  57518. {
  57519. startTimer (50);
  57520. manager->enableInputLevelMeasurement (true);
  57521. }
  57522. ~SimpleDeviceManagerInputLevelMeter()
  57523. {
  57524. manager->enableInputLevelMeasurement (false);
  57525. }
  57526. void timerCallback()
  57527. {
  57528. const float newLevel = (float) manager->getCurrentInputLevel();
  57529. if (fabsf (level - newLevel) > 0.005f)
  57530. {
  57531. level = newLevel;
  57532. repaint();
  57533. }
  57534. }
  57535. void paint (Graphics& g)
  57536. {
  57537. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57538. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57539. }
  57540. private:
  57541. AudioDeviceManager* const manager;
  57542. float level;
  57543. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57544. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57545. };
  57546. class AudioDeviceSelectorComponent::MidiInputSelectorComponentListBox : public ListBox,
  57547. public ListBoxModel
  57548. {
  57549. public:
  57550. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57551. const String& noItemsMessage_,
  57552. const int minNumber_,
  57553. const int maxNumber_)
  57554. : ListBox (String::empty, 0),
  57555. deviceManager (deviceManager_),
  57556. noItemsMessage (noItemsMessage_),
  57557. minNumber (minNumber_),
  57558. maxNumber (maxNumber_)
  57559. {
  57560. items = MidiInput::getDevices();
  57561. setModel (this);
  57562. setOutlineThickness (1);
  57563. }
  57564. ~MidiInputSelectorComponentListBox()
  57565. {
  57566. }
  57567. int getNumRows()
  57568. {
  57569. return items.size();
  57570. }
  57571. void paintListBoxItem (int row,
  57572. Graphics& g,
  57573. int width, int height,
  57574. bool rowIsSelected)
  57575. {
  57576. if (((unsigned int) row) < (unsigned int) items.size())
  57577. {
  57578. if (rowIsSelected)
  57579. g.fillAll (findColour (TextEditor::highlightColourId)
  57580. .withMultipliedAlpha (0.3f));
  57581. const String item (items [row]);
  57582. bool enabled = deviceManager.isMidiInputEnabled (item);
  57583. const int x = getTickX();
  57584. const float tickW = height * 0.75f;
  57585. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57586. enabled, true, true, false);
  57587. g.setFont (height * 0.6f);
  57588. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57589. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57590. }
  57591. }
  57592. void listBoxItemClicked (int row, const MouseEvent& e)
  57593. {
  57594. selectRow (row);
  57595. if (e.x < getTickX())
  57596. flipEnablement (row);
  57597. }
  57598. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57599. {
  57600. flipEnablement (row);
  57601. }
  57602. void returnKeyPressed (int row)
  57603. {
  57604. flipEnablement (row);
  57605. }
  57606. void paint (Graphics& g)
  57607. {
  57608. ListBox::paint (g);
  57609. if (items.size() == 0)
  57610. {
  57611. g.setColour (Colours::grey);
  57612. g.setFont (13.0f);
  57613. g.drawText (noItemsMessage,
  57614. 0, 0, getWidth(), getHeight() / 2,
  57615. Justification::centred, true);
  57616. }
  57617. }
  57618. int getBestHeight (const int preferredHeight)
  57619. {
  57620. const int extra = getOutlineThickness() * 2;
  57621. return jmax (getRowHeight() * 2 + extra,
  57622. jmin (getRowHeight() * getNumRows() + extra,
  57623. preferredHeight));
  57624. }
  57625. juce_UseDebuggingNewOperator
  57626. private:
  57627. AudioDeviceManager& deviceManager;
  57628. const String noItemsMessage;
  57629. StringArray items;
  57630. int minNumber, maxNumber;
  57631. void flipEnablement (const int row)
  57632. {
  57633. if (((unsigned int) row) < (unsigned int) items.size())
  57634. {
  57635. const String item (items [row]);
  57636. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57637. }
  57638. }
  57639. int getTickX() const
  57640. {
  57641. return getRowHeight() + 5;
  57642. }
  57643. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57644. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57645. };
  57646. class AudioDeviceSettingsPanel : public Component,
  57647. public ComboBoxListener,
  57648. public ChangeListener,
  57649. public ButtonListener
  57650. {
  57651. public:
  57652. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57653. AudioIODeviceType::DeviceSetupDetails& setup_,
  57654. const bool hideAdvancedOptionsWithButton)
  57655. : type (type_),
  57656. setup (setup_)
  57657. {
  57658. sampleRateDropDown = 0;
  57659. sampleRateLabel = 0;
  57660. bufferSizeDropDown = 0;
  57661. bufferSizeLabel = 0;
  57662. outputDeviceDropDown = 0;
  57663. outputDeviceLabel = 0;
  57664. inputDeviceDropDown = 0;
  57665. inputDeviceLabel = 0;
  57666. testButton = 0;
  57667. inputLevelMeter = 0;
  57668. showUIButton = 0;
  57669. inputChanList = 0;
  57670. outputChanList = 0;
  57671. inputChanLabel = 0;
  57672. outputChanLabel = 0;
  57673. showAdvancedSettingsButton = 0;
  57674. if (hideAdvancedOptionsWithButton)
  57675. {
  57676. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57677. showAdvancedSettingsButton->addButtonListener (this);
  57678. }
  57679. type->scanForDevices();
  57680. setup.manager->addChangeListener (this);
  57681. changeListenerCallback (0);
  57682. }
  57683. ~AudioDeviceSettingsPanel()
  57684. {
  57685. setup.manager->removeChangeListener (this);
  57686. deleteAndZero (outputDeviceLabel);
  57687. deleteAndZero (inputDeviceLabel);
  57688. deleteAndZero (sampleRateLabel);
  57689. deleteAndZero (bufferSizeLabel);
  57690. deleteAndZero (showUIButton);
  57691. deleteAndZero (inputChanLabel);
  57692. deleteAndZero (outputChanLabel);
  57693. deleteAndZero (showAdvancedSettingsButton);
  57694. deleteAllChildren();
  57695. }
  57696. void resized()
  57697. {
  57698. const int lx = proportionOfWidth (0.35f);
  57699. const int w = proportionOfWidth (0.4f);
  57700. const int h = 24;
  57701. const int space = 6;
  57702. const int dh = h + space;
  57703. int y = 0;
  57704. if (outputDeviceDropDown != 0)
  57705. {
  57706. outputDeviceDropDown->setBounds (lx, y, w, h);
  57707. if (testButton != 0)
  57708. testButton->setBounds (proportionOfWidth (0.77f),
  57709. outputDeviceDropDown->getY(),
  57710. proportionOfWidth (0.18f),
  57711. h);
  57712. y += dh;
  57713. }
  57714. if (inputDeviceDropDown != 0)
  57715. {
  57716. inputDeviceDropDown->setBounds (lx, y, w, h);
  57717. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57718. inputDeviceDropDown->getY(),
  57719. proportionOfWidth (0.18f),
  57720. h);
  57721. y += dh;
  57722. }
  57723. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57724. if (outputChanList != 0)
  57725. {
  57726. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57727. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57728. y += bh + space;
  57729. }
  57730. if (inputChanList != 0)
  57731. {
  57732. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57733. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57734. y += bh + space;
  57735. }
  57736. y += space * 2;
  57737. if (showAdvancedSettingsButton != 0)
  57738. {
  57739. showAdvancedSettingsButton->changeWidthToFitText (h);
  57740. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57741. }
  57742. if (sampleRateDropDown != 0)
  57743. {
  57744. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57745. || ! showAdvancedSettingsButton->isVisible());
  57746. sampleRateDropDown->setBounds (lx, y, w, h);
  57747. y += dh;
  57748. }
  57749. if (bufferSizeDropDown != 0)
  57750. {
  57751. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57752. || ! showAdvancedSettingsButton->isVisible());
  57753. bufferSizeDropDown->setBounds (lx, y, w, h);
  57754. y += dh;
  57755. }
  57756. if (showUIButton != 0)
  57757. {
  57758. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57759. || ! showAdvancedSettingsButton->isVisible());
  57760. showUIButton->changeWidthToFitText (h);
  57761. showUIButton->setTopLeftPosition (lx, y);
  57762. }
  57763. }
  57764. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57765. {
  57766. if (comboBoxThatHasChanged == 0)
  57767. return;
  57768. AudioDeviceManager::AudioDeviceSetup config;
  57769. setup.manager->getAudioDeviceSetup (config);
  57770. String error;
  57771. if (comboBoxThatHasChanged == outputDeviceDropDown
  57772. || comboBoxThatHasChanged == inputDeviceDropDown)
  57773. {
  57774. if (outputDeviceDropDown != 0)
  57775. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57776. : outputDeviceDropDown->getText();
  57777. if (inputDeviceDropDown != 0)
  57778. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57779. : inputDeviceDropDown->getText();
  57780. if (! type->hasSeparateInputsAndOutputs())
  57781. config.inputDeviceName = config.outputDeviceName;
  57782. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57783. config.useDefaultInputChannels = true;
  57784. else
  57785. config.useDefaultOutputChannels = true;
  57786. error = setup.manager->setAudioDeviceSetup (config, true);
  57787. showCorrectDeviceName (inputDeviceDropDown, true);
  57788. showCorrectDeviceName (outputDeviceDropDown, false);
  57789. updateControlPanelButton();
  57790. resized();
  57791. }
  57792. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57793. {
  57794. if (sampleRateDropDown->getSelectedId() > 0)
  57795. {
  57796. config.sampleRate = sampleRateDropDown->getSelectedId();
  57797. error = setup.manager->setAudioDeviceSetup (config, true);
  57798. }
  57799. }
  57800. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57801. {
  57802. if (bufferSizeDropDown->getSelectedId() > 0)
  57803. {
  57804. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57805. error = setup.manager->setAudioDeviceSetup (config, true);
  57806. }
  57807. }
  57808. if (error.isNotEmpty())
  57809. {
  57810. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57811. "Error when trying to open audio device!",
  57812. error);
  57813. }
  57814. }
  57815. void buttonClicked (Button* button)
  57816. {
  57817. if (button == showAdvancedSettingsButton)
  57818. {
  57819. showAdvancedSettingsButton->setVisible (false);
  57820. resized();
  57821. }
  57822. else if (button == showUIButton)
  57823. {
  57824. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57825. if (device != 0 && device->showControlPanel())
  57826. {
  57827. setup.manager->closeAudioDevice();
  57828. setup.manager->restartLastAudioDevice();
  57829. getTopLevelComponent()->toFront (true);
  57830. }
  57831. }
  57832. else if (button == testButton && testButton != 0)
  57833. {
  57834. setup.manager->playTestSound();
  57835. }
  57836. }
  57837. void updateControlPanelButton()
  57838. {
  57839. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57840. deleteAndZero (showUIButton);
  57841. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57842. {
  57843. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57844. TRANS ("opens the device's own control panel")));
  57845. showUIButton->addButtonListener (this);
  57846. }
  57847. resized();
  57848. }
  57849. void changeListenerCallback (void*)
  57850. {
  57851. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57852. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57853. {
  57854. if (outputDeviceDropDown == 0)
  57855. {
  57856. outputDeviceDropDown = new ComboBox (String::empty);
  57857. outputDeviceDropDown->addListener (this);
  57858. addAndMakeVisible (outputDeviceDropDown);
  57859. outputDeviceLabel = new Label (String::empty,
  57860. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57861. : TRANS ("device:"));
  57862. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57863. if (setup.maxNumOutputChannels > 0)
  57864. {
  57865. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57866. testButton->addButtonListener (this);
  57867. }
  57868. }
  57869. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57870. }
  57871. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57872. {
  57873. if (inputDeviceDropDown == 0)
  57874. {
  57875. inputDeviceDropDown = new ComboBox (String::empty);
  57876. inputDeviceDropDown->addListener (this);
  57877. addAndMakeVisible (inputDeviceDropDown);
  57878. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57879. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57880. addAndMakeVisible (inputLevelMeter
  57881. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57882. }
  57883. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57884. }
  57885. updateControlPanelButton();
  57886. showCorrectDeviceName (inputDeviceDropDown, true);
  57887. showCorrectDeviceName (outputDeviceDropDown, false);
  57888. if (currentDevice != 0)
  57889. {
  57890. if (setup.maxNumOutputChannels > 0
  57891. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57892. {
  57893. if (outputChanList == 0)
  57894. {
  57895. addAndMakeVisible (outputChanList
  57896. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57897. TRANS ("(no audio output channels found)")));
  57898. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57899. outputChanLabel->attachToComponent (outputChanList, true);
  57900. }
  57901. outputChanList->refresh();
  57902. }
  57903. else
  57904. {
  57905. deleteAndZero (outputChanLabel);
  57906. deleteAndZero (outputChanList);
  57907. }
  57908. if (setup.maxNumInputChannels > 0
  57909. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57910. {
  57911. if (inputChanList == 0)
  57912. {
  57913. addAndMakeVisible (inputChanList
  57914. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57915. TRANS ("(no audio input channels found)")));
  57916. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57917. inputChanLabel->attachToComponent (inputChanList, true);
  57918. }
  57919. inputChanList->refresh();
  57920. }
  57921. else
  57922. {
  57923. deleteAndZero (inputChanLabel);
  57924. deleteAndZero (inputChanList);
  57925. }
  57926. // sample rate..
  57927. {
  57928. if (sampleRateDropDown == 0)
  57929. {
  57930. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57931. sampleRateDropDown->addListener (this);
  57932. delete sampleRateLabel;
  57933. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57934. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57935. }
  57936. else
  57937. {
  57938. sampleRateDropDown->clear();
  57939. sampleRateDropDown->removeListener (this);
  57940. }
  57941. const int numRates = currentDevice->getNumSampleRates();
  57942. for (int i = 0; i < numRates; ++i)
  57943. {
  57944. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57945. sampleRateDropDown->addItem (String (rate) + " Hz", rate);
  57946. }
  57947. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57948. sampleRateDropDown->addListener (this);
  57949. }
  57950. // buffer size
  57951. {
  57952. if (bufferSizeDropDown == 0)
  57953. {
  57954. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57955. bufferSizeDropDown->addListener (this);
  57956. delete bufferSizeLabel;
  57957. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57958. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57959. }
  57960. else
  57961. {
  57962. bufferSizeDropDown->clear();
  57963. }
  57964. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57965. double currentRate = currentDevice->getCurrentSampleRate();
  57966. if (currentRate == 0)
  57967. currentRate = 48000.0;
  57968. for (int i = 0; i < numBufferSizes; ++i)
  57969. {
  57970. const int bs = currentDevice->getBufferSizeSamples (i);
  57971. bufferSizeDropDown->addItem (String (bs)
  57972. + " samples ("
  57973. + String (bs * 1000.0 / currentRate, 1)
  57974. + " ms)",
  57975. bs);
  57976. }
  57977. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57978. }
  57979. }
  57980. else
  57981. {
  57982. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57983. deleteAndZero (sampleRateLabel);
  57984. deleteAndZero (bufferSizeLabel);
  57985. deleteAndZero (sampleRateDropDown);
  57986. deleteAndZero (bufferSizeDropDown);
  57987. if (outputDeviceDropDown != 0)
  57988. outputDeviceDropDown->setSelectedId (-1, true);
  57989. if (inputDeviceDropDown != 0)
  57990. inputDeviceDropDown->setSelectedId (-1, true);
  57991. }
  57992. resized();
  57993. setSize (getWidth(), getLowestY() + 4);
  57994. }
  57995. private:
  57996. AudioIODeviceType* const type;
  57997. const AudioIODeviceType::DeviceSetupDetails setup;
  57998. ComboBox* outputDeviceDropDown;
  57999. ComboBox* inputDeviceDropDown;
  58000. ComboBox* sampleRateDropDown;
  58001. ComboBox* bufferSizeDropDown;
  58002. Label* outputDeviceLabel;
  58003. Label* inputDeviceLabel;
  58004. Label* sampleRateLabel;
  58005. Label* bufferSizeLabel;
  58006. Label* inputChanLabel;
  58007. Label* outputChanLabel;
  58008. TextButton* testButton;
  58009. Component* inputLevelMeter;
  58010. TextButton* showUIButton;
  58011. TextButton* showAdvancedSettingsButton;
  58012. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58013. {
  58014. if (box != 0)
  58015. {
  58016. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58017. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58018. box->setSelectedId (index + 1, true);
  58019. if (testButton != 0 && ! isInput)
  58020. testButton->setEnabled (index >= 0);
  58021. }
  58022. }
  58023. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58024. {
  58025. const StringArray devs (type->getDeviceNames (isInputs));
  58026. combo.clear (true);
  58027. for (int i = 0; i < devs.size(); ++i)
  58028. combo.addItem (devs[i], i + 1);
  58029. combo.addItem (TRANS("<< none >>"), -1);
  58030. combo.setSelectedId (-1, true);
  58031. }
  58032. int getLowestY() const
  58033. {
  58034. int y = 0;
  58035. for (int i = getNumChildComponents(); --i >= 0;)
  58036. y = jmax (y, getChildComponent (i)->getBottom());
  58037. return y;
  58038. }
  58039. public:
  58040. class ChannelSelectorListBox : public ListBox,
  58041. public ListBoxModel
  58042. {
  58043. public:
  58044. enum BoxType
  58045. {
  58046. audioInputType,
  58047. audioOutputType
  58048. };
  58049. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58050. const BoxType type_,
  58051. const String& noItemsMessage_)
  58052. : ListBox (String::empty, 0),
  58053. setup (setup_),
  58054. type (type_),
  58055. noItemsMessage (noItemsMessage_)
  58056. {
  58057. refresh();
  58058. setModel (this);
  58059. setOutlineThickness (1);
  58060. }
  58061. ~ChannelSelectorListBox()
  58062. {
  58063. }
  58064. void refresh()
  58065. {
  58066. items.clear();
  58067. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58068. if (currentDevice != 0)
  58069. {
  58070. if (type == audioInputType)
  58071. items = currentDevice->getInputChannelNames();
  58072. else if (type == audioOutputType)
  58073. items = currentDevice->getOutputChannelNames();
  58074. if (setup.useStereoPairs)
  58075. {
  58076. StringArray pairs;
  58077. for (int i = 0; i < items.size(); i += 2)
  58078. {
  58079. const String name (items[i]);
  58080. const String name2 (items[i + 1]);
  58081. String commonBit;
  58082. for (int j = 0; j < name.length(); ++j)
  58083. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58084. commonBit = name.substring (0, j);
  58085. // Make sure we only split the name at a space, because otherwise, things
  58086. // like "input 11" + "input 12" would become "input 11 + 2"
  58087. while (commonBit.isNotEmpty() && ! CharacterFunctions::isWhitespace (commonBit.getLastCharacter()))
  58088. commonBit = commonBit.dropLastCharacters (1);
  58089. pairs.add (name.trim() + " + " + name2.substring (commonBit.length()).trim());
  58090. }
  58091. items = pairs;
  58092. }
  58093. }
  58094. updateContent();
  58095. repaint();
  58096. }
  58097. int getNumRows()
  58098. {
  58099. return items.size();
  58100. }
  58101. void paintListBoxItem (int row,
  58102. Graphics& g,
  58103. int width, int height,
  58104. bool rowIsSelected)
  58105. {
  58106. if (((unsigned int) row) < (unsigned int) items.size())
  58107. {
  58108. if (rowIsSelected)
  58109. g.fillAll (findColour (TextEditor::highlightColourId)
  58110. .withMultipliedAlpha (0.3f));
  58111. const String item (items [row]);
  58112. bool enabled = false;
  58113. AudioDeviceManager::AudioDeviceSetup config;
  58114. setup.manager->getAudioDeviceSetup (config);
  58115. if (setup.useStereoPairs)
  58116. {
  58117. if (type == audioInputType)
  58118. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58119. else if (type == audioOutputType)
  58120. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58121. }
  58122. else
  58123. {
  58124. if (type == audioInputType)
  58125. enabled = config.inputChannels [row];
  58126. else if (type == audioOutputType)
  58127. enabled = config.outputChannels [row];
  58128. }
  58129. const int x = getTickX();
  58130. const float tickW = height * 0.75f;
  58131. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58132. enabled, true, true, false);
  58133. g.setFont (height * 0.6f);
  58134. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58135. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58136. }
  58137. }
  58138. void listBoxItemClicked (int row, const MouseEvent& e)
  58139. {
  58140. selectRow (row);
  58141. if (e.x < getTickX())
  58142. flipEnablement (row);
  58143. }
  58144. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58145. {
  58146. flipEnablement (row);
  58147. }
  58148. void returnKeyPressed (int row)
  58149. {
  58150. flipEnablement (row);
  58151. }
  58152. void paint (Graphics& g)
  58153. {
  58154. ListBox::paint (g);
  58155. if (items.size() == 0)
  58156. {
  58157. g.setColour (Colours::grey);
  58158. g.setFont (13.0f);
  58159. g.drawText (noItemsMessage,
  58160. 0, 0, getWidth(), getHeight() / 2,
  58161. Justification::centred, true);
  58162. }
  58163. }
  58164. int getBestHeight (int maxHeight)
  58165. {
  58166. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58167. getNumRows())
  58168. + getOutlineThickness() * 2;
  58169. }
  58170. juce_UseDebuggingNewOperator
  58171. private:
  58172. const AudioIODeviceType::DeviceSetupDetails setup;
  58173. const BoxType type;
  58174. const String noItemsMessage;
  58175. StringArray items;
  58176. void flipEnablement (const int row)
  58177. {
  58178. jassert (type == audioInputType || type == audioOutputType);
  58179. if (((unsigned int) row) < (unsigned int) items.size())
  58180. {
  58181. AudioDeviceManager::AudioDeviceSetup config;
  58182. setup.manager->getAudioDeviceSetup (config);
  58183. if (setup.useStereoPairs)
  58184. {
  58185. BigInteger bits;
  58186. BigInteger& original = (type == audioInputType ? config.inputChannels
  58187. : config.outputChannels);
  58188. int i;
  58189. for (i = 0; i < 256; i += 2)
  58190. bits.setBit (i / 2, original [i] || original [i + 1]);
  58191. if (type == audioInputType)
  58192. {
  58193. config.useDefaultInputChannels = false;
  58194. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58195. }
  58196. else
  58197. {
  58198. config.useDefaultOutputChannels = false;
  58199. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58200. }
  58201. for (i = 0; i < 256; ++i)
  58202. original.setBit (i, bits [i / 2]);
  58203. }
  58204. else
  58205. {
  58206. if (type == audioInputType)
  58207. {
  58208. config.useDefaultInputChannels = false;
  58209. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58210. }
  58211. else
  58212. {
  58213. config.useDefaultOutputChannels = false;
  58214. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58215. }
  58216. }
  58217. String error (setup.manager->setAudioDeviceSetup (config, true));
  58218. if (! error.isEmpty())
  58219. {
  58220. //xxx
  58221. }
  58222. }
  58223. }
  58224. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58225. {
  58226. const int numActive = chans.countNumberOfSetBits();
  58227. if (chans [index])
  58228. {
  58229. if (numActive > minNumber)
  58230. chans.setBit (index, false);
  58231. }
  58232. else
  58233. {
  58234. if (numActive >= maxNumber)
  58235. {
  58236. const int firstActiveChan = chans.findNextSetBit();
  58237. chans.setBit (index > firstActiveChan
  58238. ? firstActiveChan : chans.getHighestBit(),
  58239. false);
  58240. }
  58241. chans.setBit (index, true);
  58242. }
  58243. }
  58244. int getTickX() const
  58245. {
  58246. return getRowHeight() + 5;
  58247. }
  58248. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58249. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58250. };
  58251. private:
  58252. ChannelSelectorListBox* inputChanList;
  58253. ChannelSelectorListBox* outputChanList;
  58254. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58255. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58256. };
  58257. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58258. const int minInputChannels_,
  58259. const int maxInputChannels_,
  58260. const int minOutputChannels_,
  58261. const int maxOutputChannels_,
  58262. const bool showMidiInputOptions,
  58263. const bool showMidiOutputSelector,
  58264. const bool showChannelsAsStereoPairs_,
  58265. const bool hideAdvancedOptionsWithButton_)
  58266. : deviceManager (deviceManager_),
  58267. deviceTypeDropDown (0),
  58268. deviceTypeDropDownLabel (0),
  58269. audioDeviceSettingsComp (0),
  58270. minOutputChannels (minOutputChannels_),
  58271. maxOutputChannels (maxOutputChannels_),
  58272. minInputChannels (minInputChannels_),
  58273. maxInputChannels (maxInputChannels_),
  58274. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58275. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58276. {
  58277. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58278. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58279. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58280. {
  58281. deviceTypeDropDown = new ComboBox (String::empty);
  58282. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58283. {
  58284. deviceTypeDropDown
  58285. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58286. i + 1);
  58287. }
  58288. addAndMakeVisible (deviceTypeDropDown);
  58289. deviceTypeDropDown->addListener (this);
  58290. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58291. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58292. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58293. }
  58294. if (showMidiInputOptions)
  58295. {
  58296. addAndMakeVisible (midiInputsList
  58297. = new MidiInputSelectorComponentListBox (deviceManager,
  58298. TRANS("(no midi inputs available)"),
  58299. 0, 0));
  58300. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58301. midiInputsLabel->setJustificationType (Justification::topRight);
  58302. midiInputsLabel->attachToComponent (midiInputsList, true);
  58303. }
  58304. else
  58305. {
  58306. midiInputsList = 0;
  58307. midiInputsLabel = 0;
  58308. }
  58309. if (showMidiOutputSelector)
  58310. {
  58311. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58312. midiOutputSelector->addListener (this);
  58313. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58314. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58315. }
  58316. else
  58317. {
  58318. midiOutputSelector = 0;
  58319. midiOutputLabel = 0;
  58320. }
  58321. deviceManager_.addChangeListener (this);
  58322. changeListenerCallback (0);
  58323. }
  58324. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58325. {
  58326. deviceManager.removeChangeListener (this);
  58327. deleteAllChildren();
  58328. }
  58329. void AudioDeviceSelectorComponent::resized()
  58330. {
  58331. const int lx = proportionOfWidth (0.35f);
  58332. const int w = proportionOfWidth (0.4f);
  58333. const int h = 24;
  58334. const int space = 6;
  58335. const int dh = h + space;
  58336. int y = 15;
  58337. if (deviceTypeDropDown != 0)
  58338. {
  58339. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58340. y += dh + space * 2;
  58341. }
  58342. if (audioDeviceSettingsComp != 0)
  58343. {
  58344. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58345. y += audioDeviceSettingsComp->getHeight() + space;
  58346. }
  58347. if (midiInputsList != 0)
  58348. {
  58349. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58350. midiInputsList->setBounds (lx, y, w, bh);
  58351. y += bh + space;
  58352. }
  58353. if (midiOutputSelector != 0)
  58354. midiOutputSelector->setBounds (lx, y, w, h);
  58355. }
  58356. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58357. {
  58358. if (child == audioDeviceSettingsComp)
  58359. resized();
  58360. }
  58361. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58362. {
  58363. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58364. if (device != 0 && device->hasControlPanel())
  58365. {
  58366. if (device->showControlPanel())
  58367. deviceManager.restartLastAudioDevice();
  58368. getTopLevelComponent()->toFront (true);
  58369. }
  58370. }
  58371. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58372. {
  58373. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58374. {
  58375. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58376. if (type != 0)
  58377. {
  58378. deleteAndZero (audioDeviceSettingsComp);
  58379. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58380. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58381. }
  58382. }
  58383. else if (comboBoxThatHasChanged == midiOutputSelector)
  58384. {
  58385. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58386. }
  58387. }
  58388. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58389. {
  58390. if (deviceTypeDropDown != 0)
  58391. {
  58392. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58393. }
  58394. if (audioDeviceSettingsComp == 0
  58395. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58396. {
  58397. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58398. deleteAndZero (audioDeviceSettingsComp);
  58399. AudioIODeviceType* const type
  58400. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58401. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58402. if (type != 0)
  58403. {
  58404. AudioIODeviceType::DeviceSetupDetails details;
  58405. details.manager = &deviceManager;
  58406. details.minNumInputChannels = minInputChannels;
  58407. details.maxNumInputChannels = maxInputChannels;
  58408. details.minNumOutputChannels = minOutputChannels;
  58409. details.maxNumOutputChannels = maxOutputChannels;
  58410. details.useStereoPairs = showChannelsAsStereoPairs;
  58411. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58412. if (audioDeviceSettingsComp != 0)
  58413. {
  58414. addAndMakeVisible (audioDeviceSettingsComp);
  58415. audioDeviceSettingsComp->resized();
  58416. }
  58417. }
  58418. }
  58419. if (midiInputsList != 0)
  58420. {
  58421. midiInputsList->updateContent();
  58422. midiInputsList->repaint();
  58423. }
  58424. if (midiOutputSelector != 0)
  58425. {
  58426. midiOutputSelector->clear();
  58427. const StringArray midiOuts (MidiOutput::getDevices());
  58428. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58429. midiOutputSelector->addSeparator();
  58430. for (int i = 0; i < midiOuts.size(); ++i)
  58431. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58432. int current = -1;
  58433. if (deviceManager.getDefaultMidiOutput() != 0)
  58434. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58435. midiOutputSelector->setSelectedId (current, true);
  58436. }
  58437. resized();
  58438. }
  58439. END_JUCE_NAMESPACE
  58440. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58441. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58442. BEGIN_JUCE_NAMESPACE
  58443. BubbleComponent::BubbleComponent()
  58444. : side (0),
  58445. allowablePlacements (above | below | left | right),
  58446. arrowTipX (0.0f),
  58447. arrowTipY (0.0f)
  58448. {
  58449. setInterceptsMouseClicks (false, false);
  58450. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58451. setComponentEffect (&shadow);
  58452. }
  58453. BubbleComponent::~BubbleComponent()
  58454. {
  58455. }
  58456. void BubbleComponent::paint (Graphics& g)
  58457. {
  58458. int x = content.getX();
  58459. int y = content.getY();
  58460. int w = content.getWidth();
  58461. int h = content.getHeight();
  58462. int cw, ch;
  58463. getContentSize (cw, ch);
  58464. if (side == 3)
  58465. x += w - cw;
  58466. else if (side != 1)
  58467. x += (w - cw) / 2;
  58468. w = cw;
  58469. if (side == 2)
  58470. y += h - ch;
  58471. else if (side != 0)
  58472. y += (h - ch) / 2;
  58473. h = ch;
  58474. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58475. (float) x, (float) y,
  58476. (float) w, (float) h);
  58477. const int cx = x + (w - cw) / 2;
  58478. const int cy = y + (h - ch) / 2;
  58479. const int indent = 3;
  58480. g.setOrigin (cx + indent, cy + indent);
  58481. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58482. paintContent (g, cw - indent * 2, ch - indent * 2);
  58483. }
  58484. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58485. {
  58486. allowablePlacements = newPlacement;
  58487. }
  58488. void BubbleComponent::setPosition (Component* componentToPointTo)
  58489. {
  58490. jassert (componentToPointTo->isValidComponent());
  58491. Point<int> pos;
  58492. if (getParentComponent() != 0)
  58493. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58494. else
  58495. pos = componentToPointTo->relativePositionToGlobal (pos);
  58496. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58497. }
  58498. void BubbleComponent::setPosition (const int arrowTipX_,
  58499. const int arrowTipY_)
  58500. {
  58501. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58502. }
  58503. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58504. {
  58505. Rectangle<int> availableSpace;
  58506. if (getParentComponent() != 0)
  58507. {
  58508. availableSpace.setSize (getParentComponent()->getWidth(),
  58509. getParentComponent()->getHeight());
  58510. }
  58511. else
  58512. {
  58513. availableSpace = getParentMonitorArea();
  58514. }
  58515. int x = 0;
  58516. int y = 0;
  58517. int w = 150;
  58518. int h = 30;
  58519. getContentSize (w, h);
  58520. w += 30;
  58521. h += 30;
  58522. const float edgeIndent = 2.0f;
  58523. const int arrowLength = jmin (10, h / 3, w / 3);
  58524. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58525. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58526. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58527. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58528. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58529. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58530. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58531. {
  58532. spaceLeft = spaceRight = 0;
  58533. }
  58534. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58535. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58536. {
  58537. spaceAbove = spaceBelow = 0;
  58538. }
  58539. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58540. {
  58541. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58542. arrowTipX = w * 0.5f;
  58543. content.setSize (w, h - arrowLength);
  58544. if (spaceAbove >= spaceBelow)
  58545. {
  58546. // above
  58547. y = rectangleToPointTo.getY() - h;
  58548. content.setPosition (0, 0);
  58549. arrowTipY = h - edgeIndent;
  58550. side = 2;
  58551. }
  58552. else
  58553. {
  58554. // below
  58555. y = rectangleToPointTo.getBottom();
  58556. content.setPosition (0, arrowLength);
  58557. arrowTipY = edgeIndent;
  58558. side = 0;
  58559. }
  58560. }
  58561. else
  58562. {
  58563. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58564. arrowTipY = h * 0.5f;
  58565. content.setSize (w - arrowLength, h);
  58566. if (spaceLeft > spaceRight)
  58567. {
  58568. // on the left
  58569. x = rectangleToPointTo.getX() - w;
  58570. content.setPosition (0, 0);
  58571. arrowTipX = w - edgeIndent;
  58572. side = 3;
  58573. }
  58574. else
  58575. {
  58576. // on the right
  58577. x = rectangleToPointTo.getRight();
  58578. content.setPosition (arrowLength, 0);
  58579. arrowTipX = edgeIndent;
  58580. side = 1;
  58581. }
  58582. }
  58583. setBounds (x, y, w, h);
  58584. }
  58585. END_JUCE_NAMESPACE
  58586. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58587. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58588. BEGIN_JUCE_NAMESPACE
  58589. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58590. : fadeOutLength (fadeOutLengthMs),
  58591. deleteAfterUse (false)
  58592. {
  58593. }
  58594. BubbleMessageComponent::~BubbleMessageComponent()
  58595. {
  58596. fadeOutComponent (fadeOutLength);
  58597. }
  58598. void BubbleMessageComponent::showAt (int x, int y,
  58599. const String& text,
  58600. const int numMillisecondsBeforeRemoving,
  58601. const bool removeWhenMouseClicked,
  58602. const bool deleteSelfAfterUse)
  58603. {
  58604. textLayout.clear();
  58605. textLayout.setText (text, Font (14.0f));
  58606. textLayout.layout (256, Justification::centredLeft, true);
  58607. setPosition (x, y);
  58608. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58609. }
  58610. void BubbleMessageComponent::showAt (Component* const component,
  58611. const String& text,
  58612. const int numMillisecondsBeforeRemoving,
  58613. const bool removeWhenMouseClicked,
  58614. const bool deleteSelfAfterUse)
  58615. {
  58616. textLayout.clear();
  58617. textLayout.setText (text, Font (14.0f));
  58618. textLayout.layout (256, Justification::centredLeft, true);
  58619. setPosition (component);
  58620. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58621. }
  58622. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58623. const bool removeWhenMouseClicked,
  58624. const bool deleteSelfAfterUse)
  58625. {
  58626. setVisible (true);
  58627. deleteAfterUse = deleteSelfAfterUse;
  58628. if (numMillisecondsBeforeRemoving > 0)
  58629. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58630. else
  58631. expiryTime = 0;
  58632. startTimer (77);
  58633. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58634. if (! (removeWhenMouseClicked && isShowing()))
  58635. mouseClickCounter += 0xfffff;
  58636. repaint();
  58637. }
  58638. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58639. {
  58640. w = textLayout.getWidth() + 16;
  58641. h = textLayout.getHeight() + 16;
  58642. }
  58643. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58644. {
  58645. g.setColour (findColour (TooltipWindow::textColourId));
  58646. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58647. }
  58648. void BubbleMessageComponent::timerCallback()
  58649. {
  58650. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58651. {
  58652. stopTimer();
  58653. setVisible (false);
  58654. if (deleteAfterUse)
  58655. delete this;
  58656. }
  58657. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58658. {
  58659. stopTimer();
  58660. fadeOutComponent (fadeOutLength);
  58661. if (deleteAfterUse)
  58662. delete this;
  58663. }
  58664. }
  58665. END_JUCE_NAMESPACE
  58666. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58667. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58668. BEGIN_JUCE_NAMESPACE
  58669. static const int swatchesPerRow = 8;
  58670. static const int swatchHeight = 22;
  58671. class ColourComponentSlider : public Slider
  58672. {
  58673. public:
  58674. ColourComponentSlider (const String& name)
  58675. : Slider (name)
  58676. {
  58677. setRange (0.0, 255.0, 1.0);
  58678. }
  58679. ~ColourComponentSlider()
  58680. {
  58681. }
  58682. const String getTextFromValue (double value)
  58683. {
  58684. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58685. }
  58686. double getValueFromText (const String& text)
  58687. {
  58688. return (double) text.getHexValue32();
  58689. }
  58690. private:
  58691. ColourComponentSlider (const ColourComponentSlider&);
  58692. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58693. };
  58694. class ColourSpaceMarker : public Component
  58695. {
  58696. public:
  58697. ColourSpaceMarker()
  58698. {
  58699. setInterceptsMouseClicks (false, false);
  58700. }
  58701. ~ColourSpaceMarker()
  58702. {
  58703. }
  58704. void paint (Graphics& g)
  58705. {
  58706. g.setColour (Colour::greyLevel (0.1f));
  58707. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58708. g.setColour (Colour::greyLevel (0.9f));
  58709. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58710. }
  58711. private:
  58712. ColourSpaceMarker (const ColourSpaceMarker&);
  58713. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58714. };
  58715. class ColourSelector::ColourSpaceView : public Component
  58716. {
  58717. public:
  58718. ColourSpaceView (ColourSelector* owner_,
  58719. float& h_, float& s_, float& v_,
  58720. const int edgeSize)
  58721. : owner (owner_),
  58722. h (h_), s (s_), v (v_),
  58723. lastHue (0.0f),
  58724. edge (edgeSize)
  58725. {
  58726. addAndMakeVisible (marker = new ColourSpaceMarker());
  58727. setMouseCursor (MouseCursor::CrosshairCursor);
  58728. }
  58729. ~ColourSpaceView()
  58730. {
  58731. deleteAllChildren();
  58732. }
  58733. void paint (Graphics& g)
  58734. {
  58735. if (colours == 0)
  58736. {
  58737. const int width = getWidth() / 2;
  58738. const int height = getHeight() / 2;
  58739. colours = new Image (Image::RGB, width, height, false);
  58740. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58741. for (int y = 0; y < height; ++y)
  58742. {
  58743. const float v = 1.0f - y / (float) height;
  58744. for (int x = 0; x < width; ++x)
  58745. {
  58746. const float s = x / (float) width;
  58747. const Colour col (h, s, v, 1.0f);
  58748. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58749. pix->set (col.getPixelARGB());
  58750. }
  58751. }
  58752. }
  58753. g.setOpacity (1.0f);
  58754. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58755. 0, 0, colours->getWidth(), colours->getHeight());
  58756. }
  58757. void mouseDown (const MouseEvent& e)
  58758. {
  58759. mouseDrag (e);
  58760. }
  58761. void mouseDrag (const MouseEvent& e)
  58762. {
  58763. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58764. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58765. owner->setSV (s, v);
  58766. }
  58767. void updateIfNeeded()
  58768. {
  58769. if (lastHue != h)
  58770. {
  58771. lastHue = h;
  58772. colours = 0;
  58773. repaint();
  58774. }
  58775. updateMarker();
  58776. }
  58777. void resized()
  58778. {
  58779. colours = 0;
  58780. updateMarker();
  58781. }
  58782. private:
  58783. ColourSelector* const owner;
  58784. float& h;
  58785. float& s;
  58786. float& v;
  58787. float lastHue;
  58788. ColourSpaceMarker* marker;
  58789. const int edge;
  58790. ScopedPointer <Image> colours;
  58791. void updateMarker() const throw()
  58792. {
  58793. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58794. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58795. edge * 2, edge * 2);
  58796. }
  58797. ColourSpaceView (const ColourSpaceView&);
  58798. ColourSpaceView& operator= (const ColourSpaceView&);
  58799. };
  58800. class HueSelectorMarker : public Component
  58801. {
  58802. public:
  58803. HueSelectorMarker()
  58804. {
  58805. setInterceptsMouseClicks (false, false);
  58806. }
  58807. ~HueSelectorMarker()
  58808. {
  58809. }
  58810. void paint (Graphics& g)
  58811. {
  58812. Path p;
  58813. p.addTriangle (1.0f, 1.0f,
  58814. getWidth() * 0.3f, getHeight() * 0.5f,
  58815. 1.0f, getHeight() - 1.0f);
  58816. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58817. getWidth() * 0.7f, getHeight() * 0.5f,
  58818. getWidth() - 1.0f, getHeight() - 1.0f);
  58819. g.setColour (Colours::white.withAlpha (0.75f));
  58820. g.fillPath (p);
  58821. g.setColour (Colours::black.withAlpha (0.75f));
  58822. g.strokePath (p, PathStrokeType (1.2f));
  58823. }
  58824. private:
  58825. HueSelectorMarker (const HueSelectorMarker&);
  58826. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58827. };
  58828. class ColourSelector::HueSelectorComp : public Component
  58829. {
  58830. public:
  58831. HueSelectorComp (ColourSelector* owner_,
  58832. float& h_, float& s_, float& v_,
  58833. const int edgeSize)
  58834. : owner (owner_),
  58835. h (h_), s (s_), v (v_),
  58836. lastHue (0.0f),
  58837. edge (edgeSize)
  58838. {
  58839. addAndMakeVisible (marker = new HueSelectorMarker());
  58840. }
  58841. ~HueSelectorComp()
  58842. {
  58843. deleteAllChildren();
  58844. }
  58845. void paint (Graphics& g)
  58846. {
  58847. const float yScale = 1.0f / (getHeight() - edge * 2);
  58848. const Rectangle<int> clip (g.getClipBounds());
  58849. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58850. {
  58851. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58852. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58853. }
  58854. }
  58855. void resized()
  58856. {
  58857. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58858. getWidth(), edge * 2);
  58859. }
  58860. void mouseDown (const MouseEvent& e)
  58861. {
  58862. mouseDrag (e);
  58863. }
  58864. void mouseDrag (const MouseEvent& e)
  58865. {
  58866. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58867. owner->setHue (hue);
  58868. }
  58869. void updateIfNeeded()
  58870. {
  58871. resized();
  58872. }
  58873. private:
  58874. ColourSelector* const owner;
  58875. float& h;
  58876. float& s;
  58877. float& v;
  58878. float lastHue;
  58879. HueSelectorMarker* marker;
  58880. const int edge;
  58881. HueSelectorComp (const HueSelectorComp&);
  58882. HueSelectorComp& operator= (const HueSelectorComp&);
  58883. };
  58884. class ColourSelector::SwatchComponent : public Component
  58885. {
  58886. public:
  58887. SwatchComponent (ColourSelector* owner_, int index_)
  58888. : owner (owner_),
  58889. index (index_)
  58890. {
  58891. }
  58892. ~SwatchComponent()
  58893. {
  58894. }
  58895. void paint (Graphics& g)
  58896. {
  58897. const Colour colour (owner->getSwatchColour (index));
  58898. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58899. 6, 6,
  58900. Colour (0xffdddddd).overlaidWith (colour),
  58901. Colour (0xffffffff).overlaidWith (colour));
  58902. }
  58903. void mouseDown (const MouseEvent&)
  58904. {
  58905. PopupMenu m;
  58906. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58907. m.addSeparator();
  58908. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58909. const int r = m.showAt (this);
  58910. if (r == 1)
  58911. {
  58912. owner->setCurrentColour (owner->getSwatchColour (index));
  58913. }
  58914. else if (r == 2)
  58915. {
  58916. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58917. {
  58918. owner->setSwatchColour (index, owner->getCurrentColour());
  58919. repaint();
  58920. }
  58921. }
  58922. }
  58923. private:
  58924. ColourSelector* const owner;
  58925. const int index;
  58926. SwatchComponent (const SwatchComponent&);
  58927. SwatchComponent& operator= (const SwatchComponent&);
  58928. };
  58929. ColourSelector::ColourSelector (const int flags_,
  58930. const int edgeGap_,
  58931. const int gapAroundColourSpaceComponent)
  58932. : colour (Colours::white),
  58933. flags (flags_),
  58934. topSpace (0),
  58935. edgeGap (edgeGap_)
  58936. {
  58937. // not much point having a selector with no components in it!
  58938. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58939. updateHSV();
  58940. if ((flags & showSliders) != 0)
  58941. {
  58942. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58943. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58944. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58945. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58946. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58947. for (int i = 4; --i >= 0;)
  58948. sliders[i]->addListener (this);
  58949. }
  58950. else
  58951. {
  58952. zeromem (sliders, sizeof (sliders));
  58953. }
  58954. if ((flags & showColourspace) != 0)
  58955. {
  58956. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58957. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58958. }
  58959. else
  58960. {
  58961. colourSpace = 0;
  58962. hueSelector = 0;
  58963. }
  58964. update();
  58965. }
  58966. ColourSelector::~ColourSelector()
  58967. {
  58968. dispatchPendingMessages();
  58969. swatchComponents.clear();
  58970. deleteAllChildren();
  58971. }
  58972. const Colour ColourSelector::getCurrentColour() const
  58973. {
  58974. return ((flags & showAlphaChannel) != 0) ? colour
  58975. : colour.withAlpha ((uint8) 0xff);
  58976. }
  58977. void ColourSelector::setCurrentColour (const Colour& c)
  58978. {
  58979. if (c != colour)
  58980. {
  58981. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58982. updateHSV();
  58983. update();
  58984. }
  58985. }
  58986. void ColourSelector::setHue (float newH)
  58987. {
  58988. newH = jlimit (0.0f, 1.0f, newH);
  58989. if (h != newH)
  58990. {
  58991. h = newH;
  58992. colour = Colour (h, s, v, colour.getFloatAlpha());
  58993. update();
  58994. }
  58995. }
  58996. void ColourSelector::setSV (float newS, float newV)
  58997. {
  58998. newS = jlimit (0.0f, 1.0f, newS);
  58999. newV = jlimit (0.0f, 1.0f, newV);
  59000. if (s != newS || v != newV)
  59001. {
  59002. s = newS;
  59003. v = newV;
  59004. colour = Colour (h, s, v, colour.getFloatAlpha());
  59005. update();
  59006. }
  59007. }
  59008. void ColourSelector::updateHSV()
  59009. {
  59010. colour.getHSB (h, s, v);
  59011. }
  59012. void ColourSelector::update()
  59013. {
  59014. if (sliders[0] != 0)
  59015. {
  59016. sliders[0]->setValue ((int) colour.getRed());
  59017. sliders[1]->setValue ((int) colour.getGreen());
  59018. sliders[2]->setValue ((int) colour.getBlue());
  59019. sliders[3]->setValue ((int) colour.getAlpha());
  59020. }
  59021. if (colourSpace != 0)
  59022. {
  59023. colourSpace->updateIfNeeded();
  59024. hueSelector->updateIfNeeded();
  59025. }
  59026. if ((flags & showColourAtTop) != 0)
  59027. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59028. sendChangeMessage (this);
  59029. }
  59030. void ColourSelector::paint (Graphics& g)
  59031. {
  59032. g.fillAll (findColour (backgroundColourId));
  59033. if ((flags & showColourAtTop) != 0)
  59034. {
  59035. const Colour colour (getCurrentColour());
  59036. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59037. 10, 10,
  59038. Colour (0xffdddddd).overlaidWith (colour),
  59039. Colour (0xffffffff).overlaidWith (colour));
  59040. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59041. g.setFont (14.0f, true);
  59042. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  59043. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59044. Justification::centred, false);
  59045. }
  59046. if ((flags & showSliders) != 0)
  59047. {
  59048. g.setColour (findColour (labelTextColourId));
  59049. g.setFont (11.0f);
  59050. for (int i = 4; --i >= 0;)
  59051. {
  59052. if (sliders[i]->isVisible())
  59053. g.drawText (sliders[i]->getName() + ":",
  59054. 0, sliders[i]->getY(),
  59055. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59056. Justification::centredRight, false);
  59057. }
  59058. }
  59059. }
  59060. void ColourSelector::resized()
  59061. {
  59062. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59063. const int numSwatches = getNumSwatches();
  59064. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59065. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59066. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59067. int y = topSpace;
  59068. if ((flags & showColourspace) != 0)
  59069. {
  59070. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59071. colourSpace->setBounds (edgeGap, y,
  59072. getWidth() - hueWidth - edgeGap - 4,
  59073. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59074. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59075. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59076. colourSpace->getHeight());
  59077. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59078. }
  59079. if ((flags & showSliders) != 0)
  59080. {
  59081. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59082. for (int i = 0; i < numSliders; ++i)
  59083. {
  59084. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59085. proportionOfWidth (0.72f), sliderHeight - 2);
  59086. y += sliderHeight;
  59087. }
  59088. }
  59089. if (numSwatches > 0)
  59090. {
  59091. const int startX = 8;
  59092. const int xGap = 4;
  59093. const int yGap = 4;
  59094. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59095. y += edgeGap;
  59096. if (swatchComponents.size() != numSwatches)
  59097. {
  59098. swatchComponents.clear();
  59099. for (int i = 0; i < numSwatches; ++i)
  59100. {
  59101. SwatchComponent* const sc = new SwatchComponent (this, i);
  59102. swatchComponents.add (sc);
  59103. addAndMakeVisible (sc);
  59104. }
  59105. }
  59106. int x = startX;
  59107. for (int i = 0; i < swatchComponents.size(); ++i)
  59108. {
  59109. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59110. sc->setBounds (x + xGap / 2,
  59111. y + yGap / 2,
  59112. swatchWidth - xGap,
  59113. swatchHeight - yGap);
  59114. if (((i + 1) % swatchesPerRow) == 0)
  59115. {
  59116. x = startX;
  59117. y += swatchHeight;
  59118. }
  59119. else
  59120. {
  59121. x += swatchWidth;
  59122. }
  59123. }
  59124. }
  59125. }
  59126. void ColourSelector::sliderValueChanged (Slider*)
  59127. {
  59128. if (sliders[0] != 0)
  59129. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59130. (uint8) sliders[1]->getValue(),
  59131. (uint8) sliders[2]->getValue(),
  59132. (uint8) sliders[3]->getValue()));
  59133. }
  59134. int ColourSelector::getNumSwatches() const
  59135. {
  59136. return 0;
  59137. }
  59138. const Colour ColourSelector::getSwatchColour (const int) const
  59139. {
  59140. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59141. return Colours::black;
  59142. }
  59143. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59144. {
  59145. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59146. }
  59147. END_JUCE_NAMESPACE
  59148. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59149. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59150. BEGIN_JUCE_NAMESPACE
  59151. class ShadowWindow : public Component
  59152. {
  59153. Component* owner;
  59154. Image** shadowImageSections;
  59155. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59156. public:
  59157. ShadowWindow (Component* const owner_,
  59158. const int type_,
  59159. Image** const shadowImageSections_)
  59160. : owner (owner_),
  59161. shadowImageSections (shadowImageSections_),
  59162. type (type_)
  59163. {
  59164. setInterceptsMouseClicks (false, false);
  59165. if (owner_->isOnDesktop())
  59166. {
  59167. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59168. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59169. | ComponentPeer::windowIsTemporary
  59170. | ComponentPeer::windowIgnoresKeyPresses);
  59171. }
  59172. else if (owner_->getParentComponent() != 0)
  59173. {
  59174. owner_->getParentComponent()->addChildComponent (this);
  59175. }
  59176. }
  59177. ~ShadowWindow()
  59178. {
  59179. }
  59180. void paint (Graphics& g)
  59181. {
  59182. Image* const topLeft = shadowImageSections [type * 3];
  59183. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59184. Image* const filler = shadowImageSections [type * 3 + 2];
  59185. g.setOpacity (1.0f);
  59186. if (type < 2)
  59187. {
  59188. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59189. g.drawImage (topLeft,
  59190. 0, 0, topLeft->getWidth(), imH,
  59191. 0, 0, topLeft->getWidth(), imH);
  59192. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59193. g.drawImage (bottomRight,
  59194. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59195. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59196. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59197. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59198. }
  59199. else
  59200. {
  59201. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59202. g.drawImage (topLeft,
  59203. 0, 0, imW, topLeft->getHeight(),
  59204. 0, 0, imW, topLeft->getHeight());
  59205. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59206. g.drawImage (bottomRight,
  59207. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59208. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59209. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59210. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59211. }
  59212. }
  59213. void resized()
  59214. {
  59215. repaint(); // (needed for correct repainting)
  59216. }
  59217. private:
  59218. ShadowWindow (const ShadowWindow&);
  59219. ShadowWindow& operator= (const ShadowWindow&);
  59220. };
  59221. DropShadower::DropShadower (const float alpha_,
  59222. const int xOffset_,
  59223. const int yOffset_,
  59224. const float blurRadius_)
  59225. : owner (0),
  59226. numShadows (0),
  59227. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59228. xOffset (xOffset_),
  59229. yOffset (yOffset_),
  59230. alpha (alpha_),
  59231. blurRadius (blurRadius_),
  59232. inDestructor (false),
  59233. reentrant (false)
  59234. {
  59235. }
  59236. DropShadower::~DropShadower()
  59237. {
  59238. if (owner != 0)
  59239. owner->removeComponentListener (this);
  59240. inDestructor = true;
  59241. deleteShadowWindows();
  59242. }
  59243. void DropShadower::deleteShadowWindows()
  59244. {
  59245. if (numShadows > 0)
  59246. {
  59247. int i;
  59248. for (i = numShadows; --i >= 0;)
  59249. delete shadowWindows[i];
  59250. for (i = 12; --i >= 0;)
  59251. delete shadowImageSections[i];
  59252. numShadows = 0;
  59253. }
  59254. }
  59255. void DropShadower::setOwner (Component* componentToFollow)
  59256. {
  59257. if (componentToFollow != owner)
  59258. {
  59259. if (owner != 0)
  59260. owner->removeComponentListener (this);
  59261. // (the component can't be null)
  59262. jassert (componentToFollow != 0);
  59263. owner = componentToFollow;
  59264. jassert (owner != 0);
  59265. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59266. owner->addComponentListener (this);
  59267. updateShadows();
  59268. }
  59269. }
  59270. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59271. {
  59272. updateShadows();
  59273. }
  59274. void DropShadower::componentBroughtToFront (Component&)
  59275. {
  59276. bringShadowWindowsToFront();
  59277. }
  59278. void DropShadower::componentChildrenChanged (Component&)
  59279. {
  59280. }
  59281. void DropShadower::componentParentHierarchyChanged (Component&)
  59282. {
  59283. deleteShadowWindows();
  59284. updateShadows();
  59285. }
  59286. void DropShadower::componentVisibilityChanged (Component&)
  59287. {
  59288. updateShadows();
  59289. }
  59290. void DropShadower::updateShadows()
  59291. {
  59292. if (reentrant || inDestructor || (owner == 0))
  59293. return;
  59294. reentrant = true;
  59295. ComponentPeer* const nw = owner->getPeer();
  59296. const bool isOwnerVisible = owner->isVisible()
  59297. && (nw == 0 || ! nw->isMinimised());
  59298. const bool createShadowWindows = numShadows == 0
  59299. && owner->getWidth() > 0
  59300. && owner->getHeight() > 0
  59301. && isOwnerVisible
  59302. && (Desktop::canUseSemiTransparentWindows()
  59303. || owner->getParentComponent() != 0);
  59304. if (createShadowWindows)
  59305. {
  59306. // keep a cached version of the image to save doing the gaussian too often
  59307. String imageId;
  59308. imageId << shadowEdge << ',' << xOffset << ',' << yOffset << ',' << alpha;
  59309. const int hash = imageId.hashCode();
  59310. Image* bigIm = ImageCache::getFromHashCode (hash);
  59311. if (bigIm == 0)
  59312. {
  59313. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59314. Graphics bigG (*bigIm);
  59315. bigG.setColour (Colours::black.withAlpha (alpha));
  59316. bigG.fillRect (shadowEdge + xOffset,
  59317. shadowEdge + yOffset,
  59318. bigIm->getWidth() - (shadowEdge * 2),
  59319. bigIm->getHeight() - (shadowEdge * 2));
  59320. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59321. blurKernel.createGaussianBlur (blurRadius);
  59322. blurKernel.applyToImage (*bigIm, 0,
  59323. Rectangle<int> (xOffset, yOffset,
  59324. bigIm->getWidth(), bigIm->getHeight()));
  59325. ImageCache::addImageToCache (bigIm, hash);
  59326. }
  59327. const int iw = bigIm->getWidth();
  59328. const int ih = bigIm->getHeight();
  59329. const int shadowEdge2 = shadowEdge * 2;
  59330. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59331. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59332. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59333. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59334. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59335. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59336. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59337. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59338. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59339. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59340. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59341. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59342. ImageCache::release (bigIm);
  59343. for (int i = 0; i < 4; ++i)
  59344. {
  59345. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59346. ++numShadows;
  59347. }
  59348. }
  59349. if (numShadows > 0)
  59350. {
  59351. for (int i = numShadows; --i >= 0;)
  59352. {
  59353. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59354. shadowWindows[i]->setVisible (isOwnerVisible);
  59355. }
  59356. const int x = owner->getX();
  59357. const int y = owner->getY() - shadowEdge;
  59358. const int w = owner->getWidth();
  59359. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59360. shadowWindows[0]->setBounds (x - shadowEdge,
  59361. y,
  59362. shadowEdge,
  59363. h);
  59364. shadowWindows[1]->setBounds (x + w,
  59365. y,
  59366. shadowEdge,
  59367. h);
  59368. shadowWindows[2]->setBounds (x,
  59369. y,
  59370. w,
  59371. shadowEdge);
  59372. shadowWindows[3]->setBounds (x,
  59373. owner->getBottom(),
  59374. w,
  59375. shadowEdge);
  59376. }
  59377. reentrant = false;
  59378. if (createShadowWindows)
  59379. bringShadowWindowsToFront();
  59380. }
  59381. void DropShadower::setShadowImage (Image* const src, const int num, const int w, const int h,
  59382. const int sx, const int sy)
  59383. {
  59384. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59385. Graphics g (*shadowImageSections[num]);
  59386. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59387. }
  59388. void DropShadower::bringShadowWindowsToFront()
  59389. {
  59390. if (! (inDestructor || reentrant))
  59391. {
  59392. updateShadows();
  59393. reentrant = true;
  59394. for (int i = numShadows; --i >= 0;)
  59395. shadowWindows[i]->toBehind (owner);
  59396. reentrant = false;
  59397. }
  59398. }
  59399. END_JUCE_NAMESPACE
  59400. /*** End of inlined file: juce_DropShadower.cpp ***/
  59401. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59402. BEGIN_JUCE_NAMESPACE
  59403. class MagnifyingPeer : public ComponentPeer
  59404. {
  59405. public:
  59406. MagnifyingPeer (Component* const component_,
  59407. MagnifierComponent* const magnifierComp_)
  59408. : ComponentPeer (component_, 0),
  59409. magnifierComp (magnifierComp_)
  59410. {
  59411. }
  59412. ~MagnifyingPeer()
  59413. {
  59414. }
  59415. void* getNativeHandle() const { return 0; }
  59416. void setVisible (bool) {}
  59417. void setTitle (const String&) {}
  59418. void setPosition (int, int) {}
  59419. void setSize (int, int) {}
  59420. void setBounds (int, int, int, int, bool) {}
  59421. void setMinimised (bool) {}
  59422. bool isMinimised() const { return false; }
  59423. void setFullScreen (bool) {}
  59424. bool isFullScreen() const { return false; }
  59425. const BorderSize getFrameSize() const { return BorderSize (0); }
  59426. bool setAlwaysOnTop (bool) { return true; }
  59427. void toFront (bool) {}
  59428. void toBehind (ComponentPeer*) {}
  59429. void setIcon (const Image&) {}
  59430. bool isFocused() const
  59431. {
  59432. return magnifierComp->hasKeyboardFocus (true);
  59433. }
  59434. void grabFocus()
  59435. {
  59436. ComponentPeer* peer = magnifierComp->getPeer();
  59437. if (peer != 0)
  59438. peer->grabFocus();
  59439. }
  59440. void textInputRequired (const Point<int>& position)
  59441. {
  59442. ComponentPeer* peer = magnifierComp->getPeer();
  59443. if (peer != 0)
  59444. peer->textInputRequired (position);
  59445. }
  59446. const Rectangle<int> getBounds() const
  59447. {
  59448. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59449. component->getWidth(), component->getHeight());
  59450. }
  59451. const Point<int> getScreenPosition() const
  59452. {
  59453. return magnifierComp->getScreenPosition();
  59454. }
  59455. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59456. {
  59457. const double zoom = magnifierComp->getScaleFactor();
  59458. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59459. roundToInt (relativePosition.getY() * zoom)));
  59460. }
  59461. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59462. {
  59463. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59464. const double zoom = magnifierComp->getScaleFactor();
  59465. return Point<int> (roundToInt (p.getX() / zoom),
  59466. roundToInt (p.getY() / zoom));
  59467. }
  59468. bool contains (const Point<int>& position, bool) const
  59469. {
  59470. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59471. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59472. }
  59473. void repaint (int x, int y, int w, int h)
  59474. {
  59475. const double zoom = magnifierComp->getScaleFactor();
  59476. magnifierComp->repaint ((int) (x * zoom),
  59477. (int) (y * zoom),
  59478. roundToInt (w * zoom) + 1,
  59479. roundToInt (h * zoom) + 1);
  59480. }
  59481. void performAnyPendingRepaintsNow()
  59482. {
  59483. }
  59484. juce_UseDebuggingNewOperator
  59485. private:
  59486. MagnifierComponent* const magnifierComp;
  59487. MagnifyingPeer (const MagnifyingPeer&);
  59488. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59489. };
  59490. class PeerHolderComp : public Component
  59491. {
  59492. public:
  59493. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59494. : magnifierComp (magnifierComp_)
  59495. {
  59496. setVisible (true);
  59497. }
  59498. ~PeerHolderComp()
  59499. {
  59500. }
  59501. ComponentPeer* createNewPeer (int, void*)
  59502. {
  59503. return new MagnifyingPeer (this, magnifierComp);
  59504. }
  59505. void childBoundsChanged (Component* c)
  59506. {
  59507. if (c != 0)
  59508. {
  59509. setSize (c->getWidth(), c->getHeight());
  59510. magnifierComp->childBoundsChanged (this);
  59511. }
  59512. }
  59513. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59514. {
  59515. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59516. Component* const p = magnifierComp->getParentComponent();
  59517. if (p != 0)
  59518. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59519. }
  59520. private:
  59521. MagnifierComponent* const magnifierComp;
  59522. PeerHolderComp (const PeerHolderComp&);
  59523. PeerHolderComp& operator= (const PeerHolderComp&);
  59524. };
  59525. MagnifierComponent::MagnifierComponent (Component* const content_,
  59526. const bool deleteContentCompWhenNoLongerNeeded)
  59527. : content (content_),
  59528. scaleFactor (0.0),
  59529. peer (0),
  59530. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59531. quality (Graphics::lowResamplingQuality),
  59532. mouseSource (0, true)
  59533. {
  59534. holderComp = new PeerHolderComp (this);
  59535. setScaleFactor (1.0);
  59536. }
  59537. MagnifierComponent::~MagnifierComponent()
  59538. {
  59539. delete holderComp;
  59540. if (deleteContent)
  59541. delete content;
  59542. }
  59543. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59544. {
  59545. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59546. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59547. if (scaleFactor != newScaleFactor)
  59548. {
  59549. scaleFactor = newScaleFactor;
  59550. if (scaleFactor == 1.0)
  59551. {
  59552. holderComp->removeFromDesktop();
  59553. peer = 0;
  59554. addChildComponent (content);
  59555. childBoundsChanged (content);
  59556. }
  59557. else
  59558. {
  59559. holderComp->addAndMakeVisible (content);
  59560. holderComp->childBoundsChanged (content);
  59561. childBoundsChanged (holderComp);
  59562. holderComp->addToDesktop (0);
  59563. peer = holderComp->getPeer();
  59564. }
  59565. repaint();
  59566. }
  59567. }
  59568. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59569. {
  59570. quality = newQuality;
  59571. }
  59572. void MagnifierComponent::paint (Graphics& g)
  59573. {
  59574. const int w = holderComp->getWidth();
  59575. const int h = holderComp->getHeight();
  59576. if (w == 0 || h == 0)
  59577. return;
  59578. const Rectangle<int> r (g.getClipBounds());
  59579. const int srcX = (int) (r.getX() / scaleFactor);
  59580. const int srcY = (int) (r.getY() / scaleFactor);
  59581. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59582. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59583. if (scaleFactor >= 1.0)
  59584. {
  59585. ++srcW;
  59586. ++srcH;
  59587. }
  59588. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59589. temp.clear (srcX, srcY, srcW, srcH);
  59590. {
  59591. Graphics g2 (temp);
  59592. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59593. holderComp->paintEntireComponent (g2);
  59594. }
  59595. g.setImageResamplingQuality (quality);
  59596. g.drawImageTransformed (&temp, temp.getBounds(),
  59597. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59598. false);
  59599. }
  59600. void MagnifierComponent::childBoundsChanged (Component* c)
  59601. {
  59602. if (c != 0)
  59603. setSize (roundToInt (c->getWidth() * scaleFactor),
  59604. roundToInt (c->getHeight() * scaleFactor));
  59605. }
  59606. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59607. {
  59608. if (peer != 0)
  59609. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59610. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59611. }
  59612. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59613. {
  59614. passOnMouseEventToPeer (e);
  59615. }
  59616. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59617. {
  59618. passOnMouseEventToPeer (e);
  59619. }
  59620. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59621. {
  59622. passOnMouseEventToPeer (e);
  59623. }
  59624. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59625. {
  59626. passOnMouseEventToPeer (e);
  59627. }
  59628. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59629. {
  59630. passOnMouseEventToPeer (e);
  59631. }
  59632. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59633. {
  59634. passOnMouseEventToPeer (e);
  59635. }
  59636. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59637. {
  59638. if (peer != 0)
  59639. peer->handleMouseWheel (e.source.getIndex(),
  59640. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59641. ix * 256.0f, iy * 256.0f);
  59642. else
  59643. Component::mouseWheelMove (e, ix, iy);
  59644. }
  59645. int MagnifierComponent::scaleInt (const int n) const
  59646. {
  59647. return roundToInt (n / scaleFactor);
  59648. }
  59649. END_JUCE_NAMESPACE
  59650. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59651. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59652. BEGIN_JUCE_NAMESPACE
  59653. class MidiKeyboardUpDownButton : public Button
  59654. {
  59655. public:
  59656. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59657. const int delta_)
  59658. : Button (String::empty),
  59659. owner (owner_),
  59660. delta (delta_)
  59661. {
  59662. setOpaque (true);
  59663. }
  59664. ~MidiKeyboardUpDownButton()
  59665. {
  59666. }
  59667. void clicked()
  59668. {
  59669. int note = owner->getLowestVisibleKey();
  59670. if (delta < 0)
  59671. note = (note - 1) / 12;
  59672. else
  59673. note = note / 12 + 1;
  59674. owner->setLowestVisibleKey (note * 12);
  59675. }
  59676. void paintButton (Graphics& g,
  59677. bool isMouseOverButton,
  59678. bool isButtonDown)
  59679. {
  59680. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59681. isMouseOverButton, isButtonDown,
  59682. delta > 0);
  59683. }
  59684. private:
  59685. MidiKeyboardComponent* const owner;
  59686. const int delta;
  59687. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59688. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59689. };
  59690. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59691. const Orientation orientation_)
  59692. : state (state_),
  59693. xOffset (0),
  59694. blackNoteLength (1),
  59695. keyWidth (16.0f),
  59696. orientation (orientation_),
  59697. midiChannel (1),
  59698. midiInChannelMask (0xffff),
  59699. velocity (1.0f),
  59700. noteUnderMouse (-1),
  59701. mouseDownNote (-1),
  59702. rangeStart (0),
  59703. rangeEnd (127),
  59704. firstKey (12 * 4),
  59705. canScroll (true),
  59706. mouseDragging (false),
  59707. useMousePositionForVelocity (true),
  59708. keyMappingOctave (6),
  59709. octaveNumForMiddleC (3)
  59710. {
  59711. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59712. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59713. // initialise with a default set of querty key-mappings..
  59714. const char* const keymap = "awsedftgyhujkolp;";
  59715. for (int i = String (keymap).length(); --i >= 0;)
  59716. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59717. setOpaque (true);
  59718. setWantsKeyboardFocus (true);
  59719. state.addListener (this);
  59720. }
  59721. MidiKeyboardComponent::~MidiKeyboardComponent()
  59722. {
  59723. state.removeListener (this);
  59724. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59725. deleteAllChildren();
  59726. }
  59727. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59728. {
  59729. keyWidth = widthInPixels;
  59730. resized();
  59731. }
  59732. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59733. {
  59734. if (orientation != newOrientation)
  59735. {
  59736. orientation = newOrientation;
  59737. resized();
  59738. }
  59739. }
  59740. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59741. const int highestNote)
  59742. {
  59743. jassert (lowestNote >= 0 && lowestNote <= 127);
  59744. jassert (highestNote >= 0 && highestNote <= 127);
  59745. jassert (lowestNote <= highestNote);
  59746. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59747. {
  59748. rangeStart = jlimit (0, 127, lowestNote);
  59749. rangeEnd = jlimit (0, 127, highestNote);
  59750. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59751. resized();
  59752. }
  59753. }
  59754. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59755. {
  59756. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59757. if (noteNumber != firstKey)
  59758. {
  59759. firstKey = noteNumber;
  59760. sendChangeMessage (this);
  59761. resized();
  59762. }
  59763. }
  59764. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59765. {
  59766. if (canScroll != canScroll_)
  59767. {
  59768. canScroll = canScroll_;
  59769. resized();
  59770. }
  59771. }
  59772. void MidiKeyboardComponent::colourChanged()
  59773. {
  59774. repaint();
  59775. }
  59776. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59777. {
  59778. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59779. if (midiChannel != midiChannelNumber)
  59780. {
  59781. resetAnyKeysInUse();
  59782. midiChannel = jlimit (1, 16, midiChannelNumber);
  59783. }
  59784. }
  59785. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59786. {
  59787. midiInChannelMask = midiChannelMask;
  59788. triggerAsyncUpdate();
  59789. }
  59790. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59791. {
  59792. velocity = jlimit (0.0f, 1.0f, velocity_);
  59793. useMousePositionForVelocity = useMousePositionForVelocity_;
  59794. }
  59795. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59796. {
  59797. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59798. static const float blackNoteWidth = 0.7f;
  59799. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59800. 1.0f, 2 - blackNoteWidth * 0.4f,
  59801. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59802. 4.0f, 5 - blackNoteWidth * 0.5f,
  59803. 5.0f, 6 - blackNoteWidth * 0.3f,
  59804. 6.0f };
  59805. static const float widths[] = { 1.0f, blackNoteWidth,
  59806. 1.0f, blackNoteWidth,
  59807. 1.0f, 1.0f, blackNoteWidth,
  59808. 1.0f, blackNoteWidth,
  59809. 1.0f, blackNoteWidth,
  59810. 1.0f };
  59811. const int octave = midiNoteNumber / 12;
  59812. const int note = midiNoteNumber % 12;
  59813. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59814. w = roundToInt (widths [note] * keyWidth);
  59815. }
  59816. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59817. {
  59818. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59819. int rx, rw;
  59820. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59821. x -= xOffset + rx;
  59822. }
  59823. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59824. {
  59825. int x, y;
  59826. getKeyPos (midiNoteNumber, x, y);
  59827. return x;
  59828. }
  59829. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59830. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59831. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59832. {
  59833. if (! reallyContains (pos.getX(), pos.getY(), false))
  59834. return -1;
  59835. Point<int> p (pos);
  59836. if (orientation != horizontalKeyboard)
  59837. {
  59838. p = Point<int> (p.getY(), p.getX());
  59839. if (orientation == verticalKeyboardFacingLeft)
  59840. p = Point<int> (p.getX(), getWidth() - p.getY());
  59841. else
  59842. p = Point<int> (getHeight() - p.getX(), p.getY());
  59843. }
  59844. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59845. }
  59846. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59847. {
  59848. if (pos.getY() < blackNoteLength)
  59849. {
  59850. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59851. {
  59852. for (int i = 0; i < 5; ++i)
  59853. {
  59854. const int note = octaveStart + blackNotes [i];
  59855. if (note >= rangeStart && note <= rangeEnd)
  59856. {
  59857. int kx, kw;
  59858. getKeyPos (note, kx, kw);
  59859. kx += xOffset;
  59860. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59861. {
  59862. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59863. return note;
  59864. }
  59865. }
  59866. }
  59867. }
  59868. }
  59869. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59870. {
  59871. for (int i = 0; i < 7; ++i)
  59872. {
  59873. const int note = octaveStart + whiteNotes [i];
  59874. if (note >= rangeStart && note <= rangeEnd)
  59875. {
  59876. int kx, kw;
  59877. getKeyPos (note, kx, kw);
  59878. kx += xOffset;
  59879. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59880. {
  59881. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59882. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59883. return note;
  59884. }
  59885. }
  59886. }
  59887. }
  59888. mousePositionVelocity = 0;
  59889. return -1;
  59890. }
  59891. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59892. {
  59893. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59894. {
  59895. int x, w;
  59896. getKeyPos (noteNum, x, w);
  59897. if (orientation == horizontalKeyboard)
  59898. repaint (x, 0, w, getHeight());
  59899. else if (orientation == verticalKeyboardFacingLeft)
  59900. repaint (0, x, getWidth(), w);
  59901. else if (orientation == verticalKeyboardFacingRight)
  59902. repaint (0, getHeight() - x - w, getWidth(), w);
  59903. }
  59904. }
  59905. void MidiKeyboardComponent::paint (Graphics& g)
  59906. {
  59907. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59908. const Colour lineColour (findColour (keySeparatorLineColourId));
  59909. const Colour textColour (findColour (textLabelColourId));
  59910. int x, w, octave;
  59911. for (octave = 0; octave < 128; octave += 12)
  59912. {
  59913. for (int white = 0; white < 7; ++white)
  59914. {
  59915. const int noteNum = octave + whiteNotes [white];
  59916. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59917. {
  59918. getKeyPos (noteNum, x, w);
  59919. if (orientation == horizontalKeyboard)
  59920. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59921. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59922. noteUnderMouse == noteNum,
  59923. lineColour, textColour);
  59924. else if (orientation == verticalKeyboardFacingLeft)
  59925. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59926. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59927. noteUnderMouse == noteNum,
  59928. lineColour, textColour);
  59929. else if (orientation == verticalKeyboardFacingRight)
  59930. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59931. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59932. noteUnderMouse == noteNum,
  59933. lineColour, textColour);
  59934. }
  59935. }
  59936. }
  59937. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59938. if (orientation == verticalKeyboardFacingLeft)
  59939. {
  59940. x1 = getWidth() - 1.0f;
  59941. x2 = getWidth() - 5.0f;
  59942. }
  59943. else if (orientation == verticalKeyboardFacingRight)
  59944. x2 = 5.0f;
  59945. else
  59946. y2 = 5.0f;
  59947. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59948. Colours::transparentBlack, x2, y2, false));
  59949. getKeyPos (rangeEnd, x, w);
  59950. x += w;
  59951. if (orientation == verticalKeyboardFacingLeft)
  59952. g.fillRect (getWidth() - 5, 0, 5, x);
  59953. else if (orientation == verticalKeyboardFacingRight)
  59954. g.fillRect (0, 0, 5, x);
  59955. else
  59956. g.fillRect (0, 0, x, 5);
  59957. g.setColour (lineColour);
  59958. if (orientation == verticalKeyboardFacingLeft)
  59959. g.fillRect (0, 0, 1, x);
  59960. else if (orientation == verticalKeyboardFacingRight)
  59961. g.fillRect (getWidth() - 1, 0, 1, x);
  59962. else
  59963. g.fillRect (0, getHeight() - 1, x, 1);
  59964. const Colour blackNoteColour (findColour (blackNoteColourId));
  59965. for (octave = 0; octave < 128; octave += 12)
  59966. {
  59967. for (int black = 0; black < 5; ++black)
  59968. {
  59969. const int noteNum = octave + blackNotes [black];
  59970. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59971. {
  59972. getKeyPos (noteNum, x, w);
  59973. if (orientation == horizontalKeyboard)
  59974. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59975. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59976. noteUnderMouse == noteNum,
  59977. blackNoteColour);
  59978. else if (orientation == verticalKeyboardFacingLeft)
  59979. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59980. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59981. noteUnderMouse == noteNum,
  59982. blackNoteColour);
  59983. else if (orientation == verticalKeyboardFacingRight)
  59984. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59985. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59986. noteUnderMouse == noteNum,
  59987. blackNoteColour);
  59988. }
  59989. }
  59990. }
  59991. }
  59992. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59993. Graphics& g, int x, int y, int w, int h,
  59994. bool isDown, bool isOver,
  59995. const Colour& lineColour,
  59996. const Colour& textColour)
  59997. {
  59998. Colour c (Colours::transparentWhite);
  59999. if (isDown)
  60000. c = findColour (keyDownOverlayColourId);
  60001. if (isOver)
  60002. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60003. g.setColour (c);
  60004. g.fillRect (x, y, w, h);
  60005. const String text (getWhiteNoteText (midiNoteNumber));
  60006. if (! text.isEmpty())
  60007. {
  60008. g.setColour (textColour);
  60009. Font f (jmin (12.0f, keyWidth * 0.9f));
  60010. f.setHorizontalScale (0.8f);
  60011. g.setFont (f);
  60012. Justification justification (Justification::centredBottom);
  60013. if (orientation == verticalKeyboardFacingLeft)
  60014. justification = Justification::centredLeft;
  60015. else if (orientation == verticalKeyboardFacingRight)
  60016. justification = Justification::centredRight;
  60017. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60018. }
  60019. g.setColour (lineColour);
  60020. if (orientation == horizontalKeyboard)
  60021. g.fillRect (x, y, 1, h);
  60022. else if (orientation == verticalKeyboardFacingLeft)
  60023. g.fillRect (x, y, w, 1);
  60024. else if (orientation == verticalKeyboardFacingRight)
  60025. g.fillRect (x, y + h - 1, w, 1);
  60026. if (midiNoteNumber == rangeEnd)
  60027. {
  60028. if (orientation == horizontalKeyboard)
  60029. g.fillRect (x + w, y, 1, h);
  60030. else if (orientation == verticalKeyboardFacingLeft)
  60031. g.fillRect (x, y + h, w, 1);
  60032. else if (orientation == verticalKeyboardFacingRight)
  60033. g.fillRect (x, y - 1, w, 1);
  60034. }
  60035. }
  60036. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60037. Graphics& g, int x, int y, int w, int h,
  60038. bool isDown, bool isOver,
  60039. const Colour& noteFillColour)
  60040. {
  60041. Colour c (noteFillColour);
  60042. if (isDown)
  60043. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60044. if (isOver)
  60045. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60046. g.setColour (c);
  60047. g.fillRect (x, y, w, h);
  60048. if (isDown)
  60049. {
  60050. g.setColour (noteFillColour);
  60051. g.drawRect (x, y, w, h);
  60052. }
  60053. else
  60054. {
  60055. const int xIndent = jmax (1, jmin (w, h) / 8);
  60056. g.setColour (c.brighter());
  60057. if (orientation == horizontalKeyboard)
  60058. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60059. else if (orientation == verticalKeyboardFacingLeft)
  60060. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60061. else if (orientation == verticalKeyboardFacingRight)
  60062. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60063. }
  60064. }
  60065. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60066. {
  60067. octaveNumForMiddleC = octaveNumForMiddleC_;
  60068. repaint();
  60069. }
  60070. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60071. {
  60072. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60073. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60074. return String::empty;
  60075. }
  60076. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60077. const bool isMouseOver,
  60078. const bool isButtonDown,
  60079. const bool movesOctavesUp)
  60080. {
  60081. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60082. float angle;
  60083. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60084. angle = movesOctavesUp ? 0.0f : 0.5f;
  60085. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60086. angle = movesOctavesUp ? 0.25f : 0.75f;
  60087. else
  60088. angle = movesOctavesUp ? 0.75f : 0.25f;
  60089. Path path;
  60090. path.lineTo (0.0f, 1.0f);
  60091. path.lineTo (1.0f, 0.5f);
  60092. path.closeSubPath();
  60093. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60094. g.setColour (findColour (upDownButtonArrowColourId)
  60095. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60096. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60097. w - 2.0f,
  60098. h - 2.0f,
  60099. true));
  60100. }
  60101. void MidiKeyboardComponent::resized()
  60102. {
  60103. int w = getWidth();
  60104. int h = getHeight();
  60105. if (w > 0 && h > 0)
  60106. {
  60107. if (orientation != horizontalKeyboard)
  60108. swapVariables (w, h);
  60109. blackNoteLength = roundToInt (h * 0.7f);
  60110. int kx2, kw2;
  60111. getKeyPos (rangeEnd, kx2, kw2);
  60112. kx2 += kw2;
  60113. if (firstKey != rangeStart)
  60114. {
  60115. int kx1, kw1;
  60116. getKeyPos (rangeStart, kx1, kw1);
  60117. if (kx2 - kx1 <= w)
  60118. {
  60119. firstKey = rangeStart;
  60120. sendChangeMessage (this);
  60121. repaint();
  60122. }
  60123. }
  60124. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60125. scrollDown->setVisible (showScrollButtons);
  60126. scrollUp->setVisible (showScrollButtons);
  60127. xOffset = 0;
  60128. if (showScrollButtons)
  60129. {
  60130. const int scrollButtonW = jmin (12, w / 2);
  60131. if (orientation == horizontalKeyboard)
  60132. {
  60133. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60134. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60135. }
  60136. else if (orientation == verticalKeyboardFacingLeft)
  60137. {
  60138. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60139. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60140. }
  60141. else if (orientation == verticalKeyboardFacingRight)
  60142. {
  60143. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60144. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60145. }
  60146. int endOfLastKey, kw;
  60147. getKeyPos (rangeEnd, endOfLastKey, kw);
  60148. endOfLastKey += kw;
  60149. float mousePositionVelocity;
  60150. const int spaceAvailable = w - scrollButtonW * 2;
  60151. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60152. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60153. {
  60154. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60155. sendChangeMessage (this);
  60156. }
  60157. int newOffset = 0;
  60158. getKeyPos (firstKey, newOffset, kw);
  60159. xOffset = newOffset - scrollButtonW;
  60160. }
  60161. else
  60162. {
  60163. firstKey = rangeStart;
  60164. }
  60165. timerCallback();
  60166. repaint();
  60167. }
  60168. }
  60169. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60170. {
  60171. triggerAsyncUpdate();
  60172. }
  60173. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60174. {
  60175. triggerAsyncUpdate();
  60176. }
  60177. void MidiKeyboardComponent::handleAsyncUpdate()
  60178. {
  60179. for (int i = rangeStart; i <= rangeEnd; ++i)
  60180. {
  60181. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60182. {
  60183. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60184. repaintNote (i);
  60185. }
  60186. }
  60187. }
  60188. void MidiKeyboardComponent::resetAnyKeysInUse()
  60189. {
  60190. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60191. {
  60192. state.allNotesOff (midiChannel);
  60193. keysPressed.clear();
  60194. mouseDownNote = -1;
  60195. }
  60196. }
  60197. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60198. {
  60199. float mousePositionVelocity = 0.0f;
  60200. const int newNote = (mouseDragging || isMouseOver())
  60201. ? xyToNote (pos, mousePositionVelocity) : -1;
  60202. if (noteUnderMouse != newNote)
  60203. {
  60204. if (mouseDownNote >= 0)
  60205. {
  60206. state.noteOff (midiChannel, mouseDownNote);
  60207. mouseDownNote = -1;
  60208. }
  60209. if (mouseDragging && newNote >= 0)
  60210. {
  60211. if (! useMousePositionForVelocity)
  60212. mousePositionVelocity = 1.0f;
  60213. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60214. mouseDownNote = newNote;
  60215. }
  60216. repaintNote (noteUnderMouse);
  60217. noteUnderMouse = newNote;
  60218. repaintNote (noteUnderMouse);
  60219. }
  60220. else if (mouseDownNote >= 0 && ! mouseDragging)
  60221. {
  60222. state.noteOff (midiChannel, mouseDownNote);
  60223. mouseDownNote = -1;
  60224. }
  60225. }
  60226. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60227. {
  60228. updateNoteUnderMouse (e.getPosition());
  60229. stopTimer();
  60230. }
  60231. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60232. {
  60233. float mousePositionVelocity;
  60234. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60235. if (newNote >= 0)
  60236. mouseDraggedToKey (newNote, e);
  60237. updateNoteUnderMouse (e.getPosition());
  60238. }
  60239. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60240. {
  60241. return true;
  60242. }
  60243. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60244. {
  60245. }
  60246. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60247. {
  60248. float mousePositionVelocity;
  60249. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60250. mouseDragging = false;
  60251. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60252. {
  60253. repaintNote (noteUnderMouse);
  60254. noteUnderMouse = -1;
  60255. mouseDragging = true;
  60256. updateNoteUnderMouse (e.getPosition());
  60257. startTimer (500);
  60258. }
  60259. }
  60260. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60261. {
  60262. mouseDragging = false;
  60263. updateNoteUnderMouse (e.getPosition());
  60264. stopTimer();
  60265. }
  60266. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60267. {
  60268. updateNoteUnderMouse (e.getPosition());
  60269. }
  60270. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60271. {
  60272. updateNoteUnderMouse (e.getPosition());
  60273. }
  60274. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60275. {
  60276. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60277. }
  60278. void MidiKeyboardComponent::timerCallback()
  60279. {
  60280. updateNoteUnderMouse (getMouseXYRelative());
  60281. }
  60282. void MidiKeyboardComponent::clearKeyMappings()
  60283. {
  60284. resetAnyKeysInUse();
  60285. keyPressNotes.clear();
  60286. keyPresses.clear();
  60287. }
  60288. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60289. const int midiNoteOffsetFromC)
  60290. {
  60291. removeKeyPressForNote (midiNoteOffsetFromC);
  60292. keyPressNotes.add (midiNoteOffsetFromC);
  60293. keyPresses.add (key);
  60294. }
  60295. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60296. {
  60297. for (int i = keyPressNotes.size(); --i >= 0;)
  60298. {
  60299. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60300. {
  60301. keyPressNotes.remove (i);
  60302. keyPresses.remove (i);
  60303. }
  60304. }
  60305. }
  60306. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60307. {
  60308. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60309. keyMappingOctave = newOctaveNumber;
  60310. }
  60311. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60312. {
  60313. bool keyPressUsed = false;
  60314. for (int i = keyPresses.size(); --i >= 0;)
  60315. {
  60316. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60317. if (keyPresses.getReference(i).isCurrentlyDown())
  60318. {
  60319. if (! keysPressed [note])
  60320. {
  60321. keysPressed.setBit (note);
  60322. state.noteOn (midiChannel, note, velocity);
  60323. keyPressUsed = true;
  60324. }
  60325. }
  60326. else
  60327. {
  60328. if (keysPressed [note])
  60329. {
  60330. keysPressed.clearBit (note);
  60331. state.noteOff (midiChannel, note);
  60332. keyPressUsed = true;
  60333. }
  60334. }
  60335. }
  60336. return keyPressUsed;
  60337. }
  60338. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60339. {
  60340. resetAnyKeysInUse();
  60341. }
  60342. END_JUCE_NAMESPACE
  60343. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60344. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60345. #if JUCE_OPENGL
  60346. BEGIN_JUCE_NAMESPACE
  60347. extern void juce_glViewport (const int w, const int h);
  60348. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60349. const int alphaBits_,
  60350. const int depthBufferBits_,
  60351. const int stencilBufferBits_)
  60352. : redBits (bitsPerRGBComponent),
  60353. greenBits (bitsPerRGBComponent),
  60354. blueBits (bitsPerRGBComponent),
  60355. alphaBits (alphaBits_),
  60356. depthBufferBits (depthBufferBits_),
  60357. stencilBufferBits (stencilBufferBits_),
  60358. accumulationBufferRedBits (0),
  60359. accumulationBufferGreenBits (0),
  60360. accumulationBufferBlueBits (0),
  60361. accumulationBufferAlphaBits (0),
  60362. fullSceneAntiAliasingNumSamples (0)
  60363. {
  60364. }
  60365. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60366. : redBits (other.redBits),
  60367. greenBits (other.greenBits),
  60368. blueBits (other.blueBits),
  60369. alphaBits (other.alphaBits),
  60370. depthBufferBits (other.depthBufferBits),
  60371. stencilBufferBits (other.stencilBufferBits),
  60372. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60373. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60374. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60375. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60376. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60377. {
  60378. }
  60379. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60380. {
  60381. redBits = other.redBits;
  60382. greenBits = other.greenBits;
  60383. blueBits = other.blueBits;
  60384. alphaBits = other.alphaBits;
  60385. depthBufferBits = other.depthBufferBits;
  60386. stencilBufferBits = other.stencilBufferBits;
  60387. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60388. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60389. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60390. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60391. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60392. return *this;
  60393. }
  60394. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60395. {
  60396. return redBits == other.redBits
  60397. && greenBits == other.greenBits
  60398. && blueBits == other.blueBits
  60399. && alphaBits == other.alphaBits
  60400. && depthBufferBits == other.depthBufferBits
  60401. && stencilBufferBits == other.stencilBufferBits
  60402. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60403. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60404. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60405. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60406. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60407. }
  60408. static VoidArray knownContexts;
  60409. OpenGLContext::OpenGLContext() throw()
  60410. {
  60411. knownContexts.add (this);
  60412. }
  60413. OpenGLContext::~OpenGLContext()
  60414. {
  60415. knownContexts.removeValue (this);
  60416. }
  60417. OpenGLContext* OpenGLContext::getCurrentContext()
  60418. {
  60419. for (int i = knownContexts.size(); --i >= 0;)
  60420. {
  60421. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60422. if (oglc->isActive())
  60423. return oglc;
  60424. }
  60425. return 0;
  60426. }
  60427. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60428. {
  60429. public:
  60430. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60431. : ComponentMovementWatcher (owner_),
  60432. owner (owner_),
  60433. wasShowing (false)
  60434. {
  60435. }
  60436. ~OpenGLComponentWatcher() {}
  60437. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60438. {
  60439. owner->updateContextPosition();
  60440. }
  60441. void componentPeerChanged()
  60442. {
  60443. const ScopedLock sl (owner->getContextLock());
  60444. owner->deleteContext();
  60445. }
  60446. void componentVisibilityChanged (Component&)
  60447. {
  60448. const bool isShowingNow = owner->isShowing();
  60449. if (wasShowing != isShowingNow)
  60450. {
  60451. wasShowing = isShowingNow;
  60452. owner->updateContextPosition();
  60453. }
  60454. }
  60455. juce_UseDebuggingNewOperator
  60456. private:
  60457. OpenGLComponent* const owner;
  60458. bool wasShowing;
  60459. };
  60460. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60461. : type (type_),
  60462. contextToShareListsWith (0),
  60463. needToUpdateViewport (true)
  60464. {
  60465. setOpaque (true);
  60466. componentWatcher = new OpenGLComponentWatcher (this);
  60467. }
  60468. OpenGLComponent::~OpenGLComponent()
  60469. {
  60470. deleteContext();
  60471. componentWatcher = 0;
  60472. }
  60473. void OpenGLComponent::deleteContext()
  60474. {
  60475. const ScopedLock sl (contextLock);
  60476. context = 0;
  60477. }
  60478. void OpenGLComponent::updateContextPosition()
  60479. {
  60480. needToUpdateViewport = true;
  60481. if (getWidth() > 0 && getHeight() > 0)
  60482. {
  60483. Component* const topComp = getTopLevelComponent();
  60484. if (topComp->getPeer() != 0)
  60485. {
  60486. const ScopedLock sl (contextLock);
  60487. if (context != 0)
  60488. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60489. getScreenY() - topComp->getScreenY(),
  60490. getWidth(),
  60491. getHeight(),
  60492. topComp->getHeight());
  60493. }
  60494. }
  60495. }
  60496. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60497. {
  60498. OpenGLPixelFormat pf;
  60499. const ScopedLock sl (contextLock);
  60500. if (context != 0)
  60501. pf = context->getPixelFormat();
  60502. return pf;
  60503. }
  60504. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60505. {
  60506. if (! (preferredPixelFormat == formatToUse))
  60507. {
  60508. const ScopedLock sl (contextLock);
  60509. deleteContext();
  60510. preferredPixelFormat = formatToUse;
  60511. }
  60512. }
  60513. void OpenGLComponent::shareWith (OpenGLContext* c)
  60514. {
  60515. if (contextToShareListsWith != c)
  60516. {
  60517. const ScopedLock sl (contextLock);
  60518. deleteContext();
  60519. contextToShareListsWith = c;
  60520. }
  60521. }
  60522. bool OpenGLComponent::makeCurrentContextActive()
  60523. {
  60524. if (context == 0)
  60525. {
  60526. const ScopedLock sl (contextLock);
  60527. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60528. {
  60529. context = createContext();
  60530. if (context != 0)
  60531. {
  60532. updateContextPosition();
  60533. if (context->makeActive())
  60534. newOpenGLContextCreated();
  60535. }
  60536. }
  60537. }
  60538. return context != 0 && context->makeActive();
  60539. }
  60540. void OpenGLComponent::makeCurrentContextInactive()
  60541. {
  60542. if (context != 0)
  60543. context->makeInactive();
  60544. }
  60545. bool OpenGLComponent::isActiveContext() const throw()
  60546. {
  60547. return context != 0 && context->isActive();
  60548. }
  60549. void OpenGLComponent::swapBuffers()
  60550. {
  60551. if (context != 0)
  60552. context->swapBuffers();
  60553. }
  60554. void OpenGLComponent::paint (Graphics&)
  60555. {
  60556. if (renderAndSwapBuffers())
  60557. {
  60558. ComponentPeer* const peer = getPeer();
  60559. if (peer != 0)
  60560. {
  60561. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60562. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60563. }
  60564. }
  60565. }
  60566. bool OpenGLComponent::renderAndSwapBuffers()
  60567. {
  60568. const ScopedLock sl (contextLock);
  60569. if (! makeCurrentContextActive())
  60570. return false;
  60571. if (needToUpdateViewport)
  60572. {
  60573. needToUpdateViewport = false;
  60574. juce_glViewport (getWidth(), getHeight());
  60575. }
  60576. renderOpenGL();
  60577. swapBuffers();
  60578. return true;
  60579. }
  60580. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60581. {
  60582. Component::internalRepaint (x, y, w, h);
  60583. if (context != 0)
  60584. context->repaint();
  60585. }
  60586. END_JUCE_NAMESPACE
  60587. #endif
  60588. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60589. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60590. BEGIN_JUCE_NAMESPACE
  60591. PreferencesPanel::PreferencesPanel()
  60592. : buttonSize (70)
  60593. {
  60594. }
  60595. PreferencesPanel::~PreferencesPanel()
  60596. {
  60597. currentPage = 0;
  60598. deleteAllChildren();
  60599. }
  60600. void PreferencesPanel::addSettingsPage (const String& title,
  60601. const Drawable* icon,
  60602. const Drawable* overIcon,
  60603. const Drawable* downIcon)
  60604. {
  60605. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60606. button->setImages (icon, overIcon, downIcon);
  60607. button->setRadioGroupId (1);
  60608. button->addButtonListener (this);
  60609. button->setClickingTogglesState (true);
  60610. button->setWantsKeyboardFocus (false);
  60611. addAndMakeVisible (button);
  60612. resized();
  60613. if (currentPage == 0)
  60614. setCurrentPage (title);
  60615. }
  60616. void PreferencesPanel::addSettingsPage (const String& title,
  60617. const char* imageData,
  60618. const int imageDataSize)
  60619. {
  60620. DrawableImage icon, iconOver, iconDown;
  60621. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60622. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60623. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60624. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60625. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60626. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60627. }
  60628. class PrefsDialogWindow : public DialogWindow
  60629. {
  60630. public:
  60631. PrefsDialogWindow (const String& dialogtitle,
  60632. const Colour& backgroundColour)
  60633. : DialogWindow (dialogtitle, backgroundColour, true)
  60634. {
  60635. }
  60636. ~PrefsDialogWindow()
  60637. {
  60638. }
  60639. void closeButtonPressed()
  60640. {
  60641. exitModalState (0);
  60642. }
  60643. private:
  60644. PrefsDialogWindow (const PrefsDialogWindow&);
  60645. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60646. };
  60647. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60648. int dialogWidth,
  60649. int dialogHeight,
  60650. const Colour& backgroundColour)
  60651. {
  60652. setSize (dialogWidth, dialogHeight);
  60653. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60654. dw.setContentComponent (this, true, true);
  60655. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60656. dw.runModalLoop();
  60657. dw.setContentComponent (0, false, false);
  60658. }
  60659. void PreferencesPanel::resized()
  60660. {
  60661. int x = 0;
  60662. for (int i = 0; i < getNumChildComponents(); ++i)
  60663. {
  60664. Component* c = getChildComponent (i);
  60665. if (dynamic_cast <DrawableButton*> (c) == 0)
  60666. {
  60667. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60668. }
  60669. else
  60670. {
  60671. c->setBounds (x, 0, buttonSize, buttonSize);
  60672. x += buttonSize;
  60673. }
  60674. }
  60675. }
  60676. void PreferencesPanel::paint (Graphics& g)
  60677. {
  60678. g.setColour (Colours::grey);
  60679. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60680. }
  60681. void PreferencesPanel::setCurrentPage (const String& pageName)
  60682. {
  60683. if (currentPageName != pageName)
  60684. {
  60685. currentPageName = pageName;
  60686. currentPage = 0;
  60687. currentPage = createComponentForPage (pageName);
  60688. if (currentPage != 0)
  60689. {
  60690. addAndMakeVisible (currentPage);
  60691. currentPage->toBack();
  60692. resized();
  60693. }
  60694. for (int i = 0; i < getNumChildComponents(); ++i)
  60695. {
  60696. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60697. if (db != 0 && db->getName() == pageName)
  60698. {
  60699. db->setToggleState (true, false);
  60700. break;
  60701. }
  60702. }
  60703. }
  60704. }
  60705. void PreferencesPanel::buttonClicked (Button*)
  60706. {
  60707. for (int i = 0; i < getNumChildComponents(); ++i)
  60708. {
  60709. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60710. if (db != 0 && db->getToggleState())
  60711. {
  60712. setCurrentPage (db->getName());
  60713. break;
  60714. }
  60715. }
  60716. }
  60717. END_JUCE_NAMESPACE
  60718. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60719. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60720. #if JUCE_WINDOWS || JUCE_LINUX
  60721. BEGIN_JUCE_NAMESPACE
  60722. SystemTrayIconComponent::SystemTrayIconComponent()
  60723. {
  60724. addToDesktop (0);
  60725. }
  60726. SystemTrayIconComponent::~SystemTrayIconComponent()
  60727. {
  60728. }
  60729. END_JUCE_NAMESPACE
  60730. #endif
  60731. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60732. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60733. BEGIN_JUCE_NAMESPACE
  60734. class AlertWindowTextEditor : public TextEditor
  60735. {
  60736. public:
  60737. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60738. : TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0)
  60739. {
  60740. setSelectAllWhenFocused (true);
  60741. }
  60742. ~AlertWindowTextEditor()
  60743. {
  60744. }
  60745. void returnPressed()
  60746. {
  60747. // pass these up the component hierarchy to be trigger the buttons
  60748. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, '\n'));
  60749. }
  60750. void escapePressed()
  60751. {
  60752. // pass these up the component hierarchy to be trigger the buttons
  60753. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60754. }
  60755. private:
  60756. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60757. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60758. static juce_wchar getDefaultPasswordChar() throw()
  60759. {
  60760. #if JUCE_LINUX
  60761. return 0x2022;
  60762. #else
  60763. return 0x25cf;
  60764. #endif
  60765. }
  60766. };
  60767. AlertWindow::AlertWindow (const String& title,
  60768. const String& message,
  60769. AlertIconType iconType,
  60770. Component* associatedComponent_)
  60771. : TopLevelWindow (title, true),
  60772. alertIconType (iconType),
  60773. associatedComponent (associatedComponent_)
  60774. {
  60775. if (message.isEmpty())
  60776. text = " "; // to force an update if the message is empty
  60777. setMessage (message);
  60778. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60779. {
  60780. Component* const c = Desktop::getInstance().getComponent (i);
  60781. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60782. {
  60783. setAlwaysOnTop (true);
  60784. break;
  60785. }
  60786. }
  60787. if (JUCEApplication::getInstance() == 0)
  60788. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60789. lookAndFeelChanged();
  60790. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60791. }
  60792. AlertWindow::~AlertWindow()
  60793. {
  60794. for (int i = customComps.size(); --i >= 0;)
  60795. removeChildComponent ((Component*) customComps[i]);
  60796. deleteAllChildren();
  60797. }
  60798. void AlertWindow::userTriedToCloseWindow()
  60799. {
  60800. exitModalState (0);
  60801. }
  60802. void AlertWindow::setMessage (const String& message)
  60803. {
  60804. const String newMessage (message.substring (0, 2048));
  60805. if (text != newMessage)
  60806. {
  60807. text = newMessage;
  60808. font.setHeight (15.0f);
  60809. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60810. textLayout.setText (getName() + "\n\n", titleFont);
  60811. textLayout.appendText (text, font);
  60812. updateLayout (true);
  60813. repaint();
  60814. }
  60815. }
  60816. void AlertWindow::buttonClicked (Button* button)
  60817. {
  60818. for (int i = 0; i < buttons.size(); i++)
  60819. {
  60820. TextButton* const c = (TextButton*) buttons[i];
  60821. if (button->getName() == c->getName())
  60822. {
  60823. if (c->getParentComponent() != 0)
  60824. c->getParentComponent()->exitModalState (c->getCommandID());
  60825. break;
  60826. }
  60827. }
  60828. }
  60829. void AlertWindow::addButton (const String& name,
  60830. const int returnValue,
  60831. const KeyPress& shortcutKey1,
  60832. const KeyPress& shortcutKey2)
  60833. {
  60834. TextButton* const b = new TextButton (name, String::empty);
  60835. b->setWantsKeyboardFocus (true);
  60836. b->setMouseClickGrabsKeyboardFocus (false);
  60837. b->setCommandToTrigger (0, returnValue, false);
  60838. b->addShortcut (shortcutKey1);
  60839. b->addShortcut (shortcutKey2);
  60840. b->addButtonListener (this);
  60841. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60842. addAndMakeVisible (b, 0);
  60843. buttons.add (b);
  60844. updateLayout (false);
  60845. }
  60846. int AlertWindow::getNumButtons() const
  60847. {
  60848. return buttons.size();
  60849. }
  60850. void AlertWindow::addTextEditor (const String& name,
  60851. const String& initialContents,
  60852. const String& onScreenLabel,
  60853. const bool isPasswordBox)
  60854. {
  60855. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60856. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60857. tc->setFont (font);
  60858. tc->setText (initialContents);
  60859. tc->setCaretPosition (initialContents.length());
  60860. addAndMakeVisible (tc);
  60861. textBoxes.add (tc);
  60862. allComps.add (tc);
  60863. textboxNames.add (onScreenLabel);
  60864. updateLayout (false);
  60865. }
  60866. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60867. {
  60868. for (int i = textBoxes.size(); --i >= 0;)
  60869. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60870. return ((TextEditor*)textBoxes[i])->getText();
  60871. return String::empty;
  60872. }
  60873. void AlertWindow::addComboBox (const String& name,
  60874. const StringArray& items,
  60875. const String& onScreenLabel)
  60876. {
  60877. ComboBox* const cb = new ComboBox (name);
  60878. for (int i = 0; i < items.size(); ++i)
  60879. cb->addItem (items[i], i + 1);
  60880. addAndMakeVisible (cb);
  60881. cb->setSelectedItemIndex (0);
  60882. comboBoxes.add (cb);
  60883. allComps.add (cb);
  60884. comboBoxNames.add (onScreenLabel);
  60885. updateLayout (false);
  60886. }
  60887. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60888. {
  60889. for (int i = comboBoxes.size(); --i >= 0;)
  60890. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60891. return (ComboBox*) comboBoxes[i];
  60892. return 0;
  60893. }
  60894. class AlertTextComp : public TextEditor
  60895. {
  60896. public:
  60897. AlertTextComp (const String& message,
  60898. const Font& font)
  60899. {
  60900. setReadOnly (true);
  60901. setMultiLine (true, true);
  60902. setCaretVisible (false);
  60903. setScrollbarsShown (true);
  60904. lookAndFeelChanged();
  60905. setWantsKeyboardFocus (false);
  60906. setFont (font);
  60907. setText (message, false);
  60908. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60909. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60910. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60911. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60912. }
  60913. ~AlertTextComp()
  60914. {
  60915. }
  60916. int getPreferredWidth() const throw() { return bestWidth; }
  60917. void updateLayout (const int width)
  60918. {
  60919. TextLayout text;
  60920. text.appendText (getText(), getFont());
  60921. text.layout (width - 8, Justification::topLeft, true);
  60922. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60923. }
  60924. private:
  60925. int bestWidth;
  60926. AlertTextComp (const AlertTextComp&);
  60927. AlertTextComp& operator= (const AlertTextComp&);
  60928. };
  60929. void AlertWindow::addTextBlock (const String& text)
  60930. {
  60931. AlertTextComp* const c = new AlertTextComp (text, font);
  60932. textBlocks.add (c);
  60933. allComps.add (c);
  60934. addAndMakeVisible (c);
  60935. updateLayout (false);
  60936. }
  60937. void AlertWindow::addProgressBarComponent (double& progressValue)
  60938. {
  60939. ProgressBar* const pb = new ProgressBar (progressValue);
  60940. progressBars.add (pb);
  60941. allComps.add (pb);
  60942. addAndMakeVisible (pb);
  60943. updateLayout (false);
  60944. }
  60945. void AlertWindow::addCustomComponent (Component* const component)
  60946. {
  60947. customComps.add (component);
  60948. allComps.add (component);
  60949. addAndMakeVisible (component);
  60950. updateLayout (false);
  60951. }
  60952. int AlertWindow::getNumCustomComponents() const
  60953. {
  60954. return customComps.size();
  60955. }
  60956. Component* AlertWindow::getCustomComponent (const int index) const
  60957. {
  60958. return (Component*) customComps [index];
  60959. }
  60960. Component* AlertWindow::removeCustomComponent (const int index)
  60961. {
  60962. Component* const c = getCustomComponent (index);
  60963. if (c != 0)
  60964. {
  60965. customComps.removeValue (c);
  60966. allComps.removeValue (c);
  60967. removeChildComponent (c);
  60968. updateLayout (false);
  60969. }
  60970. return c;
  60971. }
  60972. void AlertWindow::paint (Graphics& g)
  60973. {
  60974. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60975. g.setColour (findColour (textColourId));
  60976. g.setFont (getLookAndFeel().getAlertWindowFont());
  60977. int i;
  60978. for (i = textBoxes.size(); --i >= 0;)
  60979. {
  60980. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60981. g.drawFittedText (textboxNames[i],
  60982. te->getX(), te->getY() - 14,
  60983. te->getWidth(), 14,
  60984. Justification::centredLeft, 1);
  60985. }
  60986. for (i = comboBoxNames.size(); --i >= 0;)
  60987. {
  60988. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60989. g.drawFittedText (comboBoxNames[i],
  60990. cb->getX(), cb->getY() - 14,
  60991. cb->getWidth(), 14,
  60992. Justification::centredLeft, 1);
  60993. }
  60994. for (i = customComps.size(); --i >= 0;)
  60995. {
  60996. const Component* const c = (Component*) customComps[i];
  60997. g.drawFittedText (c->getName(),
  60998. c->getX(), c->getY() - 14,
  60999. c->getWidth(), 14,
  61000. Justification::centredLeft, 1);
  61001. }
  61002. }
  61003. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61004. {
  61005. const int titleH = 24;
  61006. const int iconWidth = 80;
  61007. const int wid = jmax (font.getStringWidth (text),
  61008. font.getStringWidth (getName()));
  61009. const int sw = (int) sqrt (font.getHeight() * wid);
  61010. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61011. const int edgeGap = 10;
  61012. const int labelHeight = 18;
  61013. int iconSpace;
  61014. if (alertIconType == NoIcon)
  61015. {
  61016. textLayout.layout (w, Justification::horizontallyCentred, true);
  61017. iconSpace = 0;
  61018. }
  61019. else
  61020. {
  61021. textLayout.layout (w, Justification::left, true);
  61022. iconSpace = iconWidth;
  61023. }
  61024. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61025. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61026. const int textLayoutH = textLayout.getHeight();
  61027. const int textBottom = 16 + titleH + textLayoutH;
  61028. int h = textBottom;
  61029. int buttonW = 40;
  61030. int i;
  61031. for (i = 0; i < buttons.size(); ++i)
  61032. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61033. w = jmax (buttonW, w);
  61034. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61035. if (buttons.size() > 0)
  61036. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61037. for (i = customComps.size(); --i >= 0;)
  61038. {
  61039. Component* c = (Component*) customComps[i];
  61040. w = jmax (w, (c->getWidth() * 100) / 80);
  61041. h += 10 + c->getHeight();
  61042. if (c->getName().isNotEmpty())
  61043. h += labelHeight;
  61044. }
  61045. for (i = textBlocks.size(); --i >= 0;)
  61046. {
  61047. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61048. w = jmax (w, ac->getPreferredWidth());
  61049. }
  61050. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61051. for (i = textBlocks.size(); --i >= 0;)
  61052. {
  61053. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61054. ac->updateLayout ((int) (w * 0.8f));
  61055. h += ac->getHeight() + 10;
  61056. }
  61057. h = jmin (getParentHeight() - 50, h);
  61058. if (onlyIncreaseSize)
  61059. {
  61060. w = jmax (w, getWidth());
  61061. h = jmax (h, getHeight());
  61062. }
  61063. if (! isVisible())
  61064. {
  61065. centreAroundComponent (associatedComponent, w, h);
  61066. }
  61067. else
  61068. {
  61069. const int cx = getX() + getWidth() / 2;
  61070. const int cy = getY() + getHeight() / 2;
  61071. setBounds (cx - w / 2,
  61072. cy - h / 2,
  61073. w, h);
  61074. }
  61075. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61076. const int spacer = 16;
  61077. int totalWidth = -spacer;
  61078. for (i = buttons.size(); --i >= 0;)
  61079. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61080. int x = (w - totalWidth) / 2;
  61081. int y = (int) (getHeight() * 0.95f);
  61082. for (i = 0; i < buttons.size(); ++i)
  61083. {
  61084. TextButton* const c = (TextButton*) buttons[i];
  61085. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61086. c->setTopLeftPosition (x, ny);
  61087. if (ny < y)
  61088. y = ny;
  61089. x += c->getWidth() + spacer;
  61090. c->toFront (false);
  61091. }
  61092. y = textBottom;
  61093. for (i = 0; i < allComps.size(); ++i)
  61094. {
  61095. Component* const c = (Component*) allComps[i];
  61096. int h = 22;
  61097. const int comboIndex = comboBoxes.indexOf (c);
  61098. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61099. y += labelHeight;
  61100. const int tbIndex = textBoxes.indexOf (c);
  61101. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61102. y += labelHeight;
  61103. if (customComps.contains (c))
  61104. {
  61105. if (c->getName().isNotEmpty())
  61106. y += labelHeight;
  61107. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61108. h = c->getHeight();
  61109. }
  61110. else if (textBlocks.contains (c))
  61111. {
  61112. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61113. h = c->getHeight();
  61114. }
  61115. else
  61116. {
  61117. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61118. }
  61119. y += h + 10;
  61120. }
  61121. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61122. }
  61123. bool AlertWindow::containsAnyExtraComponents() const
  61124. {
  61125. return textBoxes.size()
  61126. + comboBoxes.size()
  61127. + progressBars.size()
  61128. + customComps.size() > 0;
  61129. }
  61130. void AlertWindow::mouseDown (const MouseEvent&)
  61131. {
  61132. dragger.startDraggingComponent (this, &constrainer);
  61133. }
  61134. void AlertWindow::mouseDrag (const MouseEvent& e)
  61135. {
  61136. dragger.dragComponent (this, e);
  61137. }
  61138. bool AlertWindow::keyPressed (const KeyPress& key)
  61139. {
  61140. for (int i = buttons.size(); --i >= 0;)
  61141. {
  61142. TextButton* const b = (TextButton*) buttons[i];
  61143. if (b->isRegisteredForShortcut (key))
  61144. {
  61145. b->triggerClick();
  61146. return true;
  61147. }
  61148. }
  61149. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61150. {
  61151. exitModalState (0);
  61152. return true;
  61153. }
  61154. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61155. {
  61156. ((TextButton*) buttons.getFirst())->triggerClick();
  61157. return true;
  61158. }
  61159. return false;
  61160. }
  61161. void AlertWindow::lookAndFeelChanged()
  61162. {
  61163. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61164. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61165. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61166. }
  61167. int AlertWindow::getDesktopWindowStyleFlags() const
  61168. {
  61169. return getLookAndFeel().getAlertBoxWindowFlags();
  61170. }
  61171. struct AlertWindowInfo
  61172. {
  61173. String title, message, button1, button2, button3;
  61174. AlertWindow::AlertIconType iconType;
  61175. int numButtons;
  61176. Component::SafePointer<Component> associatedComponent;
  61177. int run() const
  61178. {
  61179. return (int) (pointer_sized_int)
  61180. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61181. }
  61182. private:
  61183. int show() const
  61184. {
  61185. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61186. : LookAndFeel::getDefaultLookAndFeel();
  61187. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61188. iconType, numButtons, associatedComponent));
  61189. jassert (alertBox != 0); // you have to return one of these!
  61190. return alertBox->runModalLoop();
  61191. }
  61192. static void* showCallback (void* userData)
  61193. {
  61194. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61195. }
  61196. };
  61197. void AlertWindow::showMessageBox (AlertIconType iconType,
  61198. const String& title,
  61199. const String& message,
  61200. const String& buttonText,
  61201. Component* associatedComponent)
  61202. {
  61203. AlertWindowInfo info;
  61204. info.title = title;
  61205. info.message = message;
  61206. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61207. info.iconType = iconType;
  61208. info.numButtons = 1;
  61209. info.associatedComponent = associatedComponent;
  61210. info.run();
  61211. }
  61212. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61213. const String& title,
  61214. const String& message,
  61215. const String& button1Text,
  61216. const String& button2Text,
  61217. Component* associatedComponent)
  61218. {
  61219. AlertWindowInfo info;
  61220. info.title = title;
  61221. info.message = message;
  61222. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61223. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61224. info.iconType = iconType;
  61225. info.numButtons = 2;
  61226. info.associatedComponent = associatedComponent;
  61227. return info.run() != 0;
  61228. }
  61229. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61230. const String& title,
  61231. const String& message,
  61232. const String& button1Text,
  61233. const String& button2Text,
  61234. const String& button3Text,
  61235. Component* associatedComponent)
  61236. {
  61237. AlertWindowInfo info;
  61238. info.title = title;
  61239. info.message = message;
  61240. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61241. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61242. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61243. info.iconType = iconType;
  61244. info.numButtons = 3;
  61245. info.associatedComponent = associatedComponent;
  61246. return info.run();
  61247. }
  61248. END_JUCE_NAMESPACE
  61249. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61250. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61251. BEGIN_JUCE_NAMESPACE
  61252. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61253. static VoidArray heavyweightPeers;
  61254. ComponentPeer::ComponentPeer (Component* const component_,
  61255. const int styleFlags_) throw()
  61256. : component (component_),
  61257. styleFlags (styleFlags_),
  61258. lastPaintTime (0),
  61259. constrainer (0),
  61260. lastDragAndDropCompUnderMouse (0),
  61261. fakeMouseMessageSent (false),
  61262. isWindowMinimised (false)
  61263. {
  61264. heavyweightPeers.add (this);
  61265. }
  61266. ComponentPeer::~ComponentPeer()
  61267. {
  61268. heavyweightPeers.removeValue (this);
  61269. Desktop::getInstance().triggerFocusCallback();
  61270. }
  61271. int ComponentPeer::getNumPeers() throw()
  61272. {
  61273. return heavyweightPeers.size();
  61274. }
  61275. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61276. {
  61277. return (ComponentPeer*) heavyweightPeers [index];
  61278. }
  61279. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61280. {
  61281. for (int i = heavyweightPeers.size(); --i >= 0;)
  61282. {
  61283. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61284. if (peer->getComponent() == component)
  61285. return peer;
  61286. }
  61287. return 0;
  61288. }
  61289. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61290. {
  61291. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61292. }
  61293. void ComponentPeer::updateCurrentModifiers() throw()
  61294. {
  61295. ModifierKeys::updateCurrentModifiers();
  61296. }
  61297. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61298. {
  61299. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61300. jassert (mouse != 0); // not enough sources!
  61301. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61302. }
  61303. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61304. {
  61305. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61306. jassert (mouse != 0); // not enough sources!
  61307. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61308. }
  61309. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61310. {
  61311. Graphics g (&contextToPaintTo);
  61312. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61313. g.saveState();
  61314. #endif
  61315. JUCE_TRY
  61316. {
  61317. component->paintEntireComponent (g);
  61318. }
  61319. JUCE_CATCH_EXCEPTION
  61320. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61321. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61322. // clearly when things are being repainted.
  61323. {
  61324. g.restoreState();
  61325. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61326. (uint8) Random::getSystemRandom().nextInt (255),
  61327. (uint8) Random::getSystemRandom().nextInt (255),
  61328. (uint8) 0x50));
  61329. }
  61330. #endif
  61331. }
  61332. bool ComponentPeer::handleKeyPress (const int keyCode,
  61333. const juce_wchar textCharacter)
  61334. {
  61335. updateCurrentModifiers();
  61336. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61337. ? Component::getCurrentlyFocusedComponent()
  61338. : component;
  61339. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61340. {
  61341. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61342. if (currentModalComp != 0)
  61343. target = currentModalComp;
  61344. }
  61345. const KeyPress keyInfo (keyCode,
  61346. ModifierKeys::getCurrentModifiers().getRawFlags()
  61347. & ModifierKeys::allKeyboardModifiers,
  61348. textCharacter);
  61349. bool keyWasUsed = false;
  61350. while (target != 0)
  61351. {
  61352. const Component::SafePointer<Component> deletionChecker (target);
  61353. if (target->keyListeners_ != 0)
  61354. {
  61355. for (int i = target->keyListeners_->size(); --i >= 0;)
  61356. {
  61357. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61358. if (keyWasUsed || deletionChecker == 0)
  61359. return keyWasUsed;
  61360. i = jmin (i, target->keyListeners_->size());
  61361. }
  61362. }
  61363. keyWasUsed = target->keyPressed (keyInfo);
  61364. if (keyWasUsed || deletionChecker == 0)
  61365. break;
  61366. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61367. {
  61368. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61369. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61370. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61371. break;
  61372. }
  61373. target = target->parentComponent_;
  61374. }
  61375. return keyWasUsed;
  61376. }
  61377. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61378. {
  61379. updateCurrentModifiers();
  61380. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61381. ? Component::getCurrentlyFocusedComponent()
  61382. : component;
  61383. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61384. {
  61385. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61386. if (currentModalComp != 0)
  61387. target = currentModalComp;
  61388. }
  61389. bool keyWasUsed = false;
  61390. while (target != 0)
  61391. {
  61392. const Component::SafePointer<Component> deletionChecker (target);
  61393. keyWasUsed = target->keyStateChanged (isKeyDown);
  61394. if (keyWasUsed || deletionChecker == 0)
  61395. break;
  61396. if (target->keyListeners_ != 0)
  61397. {
  61398. for (int i = target->keyListeners_->size(); --i >= 0;)
  61399. {
  61400. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61401. if (keyWasUsed || deletionChecker == 0)
  61402. return keyWasUsed;
  61403. i = jmin (i, target->keyListeners_->size());
  61404. }
  61405. }
  61406. target = target->parentComponent_;
  61407. }
  61408. return keyWasUsed;
  61409. }
  61410. void ComponentPeer::handleModifierKeysChange()
  61411. {
  61412. updateCurrentModifiers();
  61413. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61414. if (target == 0)
  61415. target = Component::getCurrentlyFocusedComponent();
  61416. if (target == 0)
  61417. target = component;
  61418. if (target != 0)
  61419. target->internalModifierKeysChanged();
  61420. }
  61421. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61422. {
  61423. Component* const c = Component::getCurrentlyFocusedComponent();
  61424. if (component->isParentOf (c))
  61425. return dynamic_cast <TextInputTarget*> (c);
  61426. return 0;
  61427. }
  61428. void ComponentPeer::handleBroughtToFront()
  61429. {
  61430. updateCurrentModifiers();
  61431. if (component != 0)
  61432. component->internalBroughtToFront();
  61433. }
  61434. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61435. {
  61436. constrainer = newConstrainer;
  61437. }
  61438. void ComponentPeer::handleMovedOrResized()
  61439. {
  61440. jassert (component->isValidComponent());
  61441. updateCurrentModifiers();
  61442. const bool nowMinimised = isMinimised();
  61443. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61444. {
  61445. const Component::SafePointer<Component> deletionChecker (component);
  61446. const Rectangle<int> newBounds (getBounds());
  61447. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61448. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61449. if (wasMoved || wasResized)
  61450. {
  61451. component->bounds_ = newBounds;
  61452. if (wasResized)
  61453. component->repaint();
  61454. component->sendMovedResizedMessages (wasMoved, wasResized);
  61455. if (deletionChecker == 0)
  61456. return;
  61457. }
  61458. }
  61459. if (isWindowMinimised != nowMinimised)
  61460. {
  61461. isWindowMinimised = nowMinimised;
  61462. component->minimisationStateChanged (nowMinimised);
  61463. component->sendVisibilityChangeMessage();
  61464. }
  61465. if (! isFullScreen())
  61466. lastNonFullscreenBounds = component->getBounds();
  61467. }
  61468. void ComponentPeer::handleFocusGain()
  61469. {
  61470. updateCurrentModifiers();
  61471. if (component->isParentOf (lastFocusedComponent))
  61472. {
  61473. Component::currentlyFocusedComponent = lastFocusedComponent;
  61474. Desktop::getInstance().triggerFocusCallback();
  61475. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61476. }
  61477. else
  61478. {
  61479. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61480. component->grabKeyboardFocus();
  61481. else
  61482. Component::bringModalComponentToFront();
  61483. }
  61484. }
  61485. void ComponentPeer::handleFocusLoss()
  61486. {
  61487. updateCurrentModifiers();
  61488. if (component->hasKeyboardFocus (true))
  61489. {
  61490. lastFocusedComponent = Component::currentlyFocusedComponent;
  61491. if (lastFocusedComponent != 0)
  61492. {
  61493. Component::currentlyFocusedComponent = 0;
  61494. Desktop::getInstance().triggerFocusCallback();
  61495. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61496. }
  61497. }
  61498. }
  61499. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61500. {
  61501. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61502. ? static_cast <Component*> (lastFocusedComponent)
  61503. : component;
  61504. }
  61505. void ComponentPeer::handleScreenSizeChange()
  61506. {
  61507. updateCurrentModifiers();
  61508. component->parentSizeChanged();
  61509. handleMovedOrResized();
  61510. }
  61511. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61512. {
  61513. lastNonFullscreenBounds = newBounds;
  61514. }
  61515. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61516. {
  61517. return lastNonFullscreenBounds;
  61518. }
  61519. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61520. const StringArray& files,
  61521. FileDragAndDropTarget* const lastOne)
  61522. {
  61523. while (c != 0)
  61524. {
  61525. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61526. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61527. return t;
  61528. c = c->getParentComponent();
  61529. }
  61530. return 0;
  61531. }
  61532. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61533. {
  61534. updateCurrentModifiers();
  61535. FileDragAndDropTarget* lastTarget
  61536. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61537. FileDragAndDropTarget* newTarget = 0;
  61538. Component* const compUnderMouse = component->getComponentAt (position);
  61539. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61540. {
  61541. lastDragAndDropCompUnderMouse = compUnderMouse;
  61542. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61543. if (newTarget != lastTarget)
  61544. {
  61545. if (lastTarget != 0)
  61546. lastTarget->fileDragExit (files);
  61547. dragAndDropTargetComponent = 0;
  61548. if (newTarget != 0)
  61549. {
  61550. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61551. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61552. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61553. }
  61554. }
  61555. }
  61556. else
  61557. {
  61558. newTarget = lastTarget;
  61559. }
  61560. if (newTarget != 0)
  61561. {
  61562. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61563. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61564. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61565. }
  61566. }
  61567. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61568. {
  61569. handleFileDragMove (files, Point<int> (-1, -1));
  61570. jassert (dragAndDropTargetComponent == 0);
  61571. lastDragAndDropCompUnderMouse = 0;
  61572. }
  61573. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61574. {
  61575. handleFileDragMove (files, position);
  61576. if (dragAndDropTargetComponent != 0)
  61577. {
  61578. FileDragAndDropTarget* const target
  61579. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61580. dragAndDropTargetComponent = 0;
  61581. lastDragAndDropCompUnderMouse = 0;
  61582. if (target != 0)
  61583. {
  61584. Component* const targetComp = dynamic_cast <Component*> (target);
  61585. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61586. {
  61587. targetComp->internalModalInputAttempt();
  61588. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61589. return;
  61590. }
  61591. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61592. target->filesDropped (files, pos.getX(), pos.getY());
  61593. }
  61594. }
  61595. }
  61596. void ComponentPeer::handleUserClosingWindow()
  61597. {
  61598. updateCurrentModifiers();
  61599. component->userTriedToCloseWindow();
  61600. }
  61601. void ComponentPeer::bringModalComponentToFront()
  61602. {
  61603. Component::bringModalComponentToFront();
  61604. }
  61605. void ComponentPeer::clearMaskedRegion() throw()
  61606. {
  61607. maskedRegion.clear();
  61608. }
  61609. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61610. {
  61611. maskedRegion.add (x, y, w, h);
  61612. }
  61613. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61614. {
  61615. StringArray s;
  61616. s.add ("Software Renderer");
  61617. return s;
  61618. }
  61619. int ComponentPeer::getCurrentRenderingEngine() throw()
  61620. {
  61621. return 0;
  61622. }
  61623. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61624. {
  61625. }
  61626. END_JUCE_NAMESPACE
  61627. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61628. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61629. BEGIN_JUCE_NAMESPACE
  61630. DialogWindow::DialogWindow (const String& name,
  61631. const Colour& backgroundColour_,
  61632. const bool escapeKeyTriggersCloseButton_,
  61633. const bool addToDesktop_)
  61634. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61635. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61636. {
  61637. }
  61638. DialogWindow::~DialogWindow()
  61639. {
  61640. }
  61641. void DialogWindow::resized()
  61642. {
  61643. DocumentWindow::resized();
  61644. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61645. if (escapeKeyTriggersCloseButton
  61646. && getCloseButton() != 0
  61647. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61648. {
  61649. getCloseButton()->addShortcut (esc);
  61650. }
  61651. }
  61652. class TempDialogWindow : public DialogWindow
  61653. {
  61654. public:
  61655. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61656. : DialogWindow (title, colour, escapeCloses, true)
  61657. {
  61658. }
  61659. ~TempDialogWindow()
  61660. {
  61661. }
  61662. void closeButtonPressed()
  61663. {
  61664. setVisible (false);
  61665. }
  61666. private:
  61667. TempDialogWindow (const TempDialogWindow&);
  61668. TempDialogWindow& operator= (const TempDialogWindow&);
  61669. };
  61670. int DialogWindow::showModalDialog (const String& dialogTitle,
  61671. Component* contentComponent,
  61672. Component* componentToCentreAround,
  61673. const Colour& colour,
  61674. const bool escapeKeyTriggersCloseButton,
  61675. const bool shouldBeResizable,
  61676. const bool useBottomRightCornerResizer)
  61677. {
  61678. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61679. dw.setContentComponent (contentComponent, true, true);
  61680. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61681. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61682. const int result = dw.runModalLoop();
  61683. dw.setContentComponent (0, false);
  61684. return result;
  61685. }
  61686. END_JUCE_NAMESPACE
  61687. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61688. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61689. BEGIN_JUCE_NAMESPACE
  61690. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61691. {
  61692. public:
  61693. ButtonListenerProxy (DocumentWindow& owner_)
  61694. : owner (owner_)
  61695. {
  61696. }
  61697. void buttonClicked (Button* button)
  61698. {
  61699. if (button == owner.getMinimiseButton())
  61700. owner.minimiseButtonPressed();
  61701. else if (button == owner.getMaximiseButton())
  61702. owner.maximiseButtonPressed();
  61703. else if (button == owner.getCloseButton())
  61704. owner.closeButtonPressed();
  61705. }
  61706. juce_UseDebuggingNewOperator
  61707. private:
  61708. DocumentWindow& owner;
  61709. ButtonListenerProxy (const ButtonListenerProxy&);
  61710. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61711. };
  61712. DocumentWindow::DocumentWindow (const String& title,
  61713. const Colour& backgroundColour,
  61714. const int requiredButtons_,
  61715. const bool addToDesktop_)
  61716. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61717. titleBarHeight (26),
  61718. menuBarHeight (24),
  61719. requiredButtons (requiredButtons_),
  61720. #if JUCE_MAC
  61721. positionTitleBarButtonsOnLeft (true),
  61722. #else
  61723. positionTitleBarButtonsOnLeft (false),
  61724. #endif
  61725. drawTitleTextCentred (true),
  61726. menuBarModel (0)
  61727. {
  61728. setResizeLimits (128, 128, 32768, 32768);
  61729. lookAndFeelChanged();
  61730. }
  61731. DocumentWindow::~DocumentWindow()
  61732. {
  61733. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61734. titleBarButtons[i] = 0;
  61735. menuBar = 0;
  61736. }
  61737. void DocumentWindow::repaintTitleBar()
  61738. {
  61739. const Rectangle<int> titleBarArea (getTitleBarArea());
  61740. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61741. titleBarArea.getWidth(), titleBarArea.getHeight());
  61742. }
  61743. void DocumentWindow::setName (const String& newName)
  61744. {
  61745. if (newName != getName())
  61746. {
  61747. Component::setName (newName);
  61748. repaintTitleBar();
  61749. }
  61750. }
  61751. void DocumentWindow::setIcon (const Image* imageToUse)
  61752. {
  61753. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61754. repaintTitleBar();
  61755. }
  61756. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61757. {
  61758. titleBarHeight = newHeight;
  61759. resized();
  61760. repaintTitleBar();
  61761. }
  61762. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61763. const bool positionTitleBarButtonsOnLeft_)
  61764. {
  61765. requiredButtons = requiredButtons_;
  61766. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61767. lookAndFeelChanged();
  61768. }
  61769. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61770. {
  61771. drawTitleTextCentred = textShouldBeCentred;
  61772. repaintTitleBar();
  61773. }
  61774. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61775. const int menuBarHeight_)
  61776. {
  61777. if (menuBarModel != menuBarModel_)
  61778. {
  61779. menuBar = 0;
  61780. menuBarModel = menuBarModel_;
  61781. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61782. : getLookAndFeel().getDefaultMenuBarHeight();
  61783. if (menuBarModel != 0)
  61784. {
  61785. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61786. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61787. menuBar->setEnabled (isActiveWindow());
  61788. }
  61789. resized();
  61790. }
  61791. }
  61792. void DocumentWindow::closeButtonPressed()
  61793. {
  61794. /* If you've got a close button, you have to override this method to get
  61795. rid of your window!
  61796. If the window is just a pop-up, you should override this method and make
  61797. it delete the window in whatever way is appropriate for your app. E.g. you
  61798. might just want to call "delete this".
  61799. If your app is centred around this window such that the whole app should quit when
  61800. the window is closed, then you will probably want to use this method as an opportunity
  61801. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61802. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61803. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61804. or closing it via the taskbar icon on Windows).
  61805. */
  61806. jassertfalse
  61807. }
  61808. void DocumentWindow::minimiseButtonPressed()
  61809. {
  61810. setMinimised (true);
  61811. }
  61812. void DocumentWindow::maximiseButtonPressed()
  61813. {
  61814. setFullScreen (! isFullScreen());
  61815. }
  61816. void DocumentWindow::paint (Graphics& g)
  61817. {
  61818. ResizableWindow::paint (g);
  61819. if (resizableBorder == 0)
  61820. {
  61821. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61822. const BorderSize border (getBorderThickness());
  61823. g.fillRect (0, 0, getWidth(), border.getTop());
  61824. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61825. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61826. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61827. }
  61828. const Rectangle<int> titleBarArea (getTitleBarArea());
  61829. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61830. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61831. int titleSpaceX1 = 6;
  61832. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61833. for (int i = 0; i < 3; ++i)
  61834. {
  61835. if (titleBarButtons[i] != 0)
  61836. {
  61837. if (positionTitleBarButtonsOnLeft)
  61838. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61839. else
  61840. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61841. }
  61842. }
  61843. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61844. titleBarArea.getWidth(),
  61845. titleBarArea.getHeight(),
  61846. titleSpaceX1,
  61847. jmax (1, titleSpaceX2 - titleSpaceX1),
  61848. titleBarIcon,
  61849. ! drawTitleTextCentred);
  61850. }
  61851. void DocumentWindow::resized()
  61852. {
  61853. ResizableWindow::resized();
  61854. if (titleBarButtons[1] != 0)
  61855. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61856. const Rectangle<int> titleBarArea (getTitleBarArea());
  61857. getLookAndFeel()
  61858. .positionDocumentWindowButtons (*this,
  61859. titleBarArea.getX(), titleBarArea.getY(),
  61860. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61861. titleBarButtons[0],
  61862. titleBarButtons[1],
  61863. titleBarButtons[2],
  61864. positionTitleBarButtonsOnLeft);
  61865. if (menuBar != 0)
  61866. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61867. titleBarArea.getWidth(), menuBarHeight);
  61868. }
  61869. const BorderSize DocumentWindow::getBorderThickness()
  61870. {
  61871. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61872. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61873. }
  61874. const BorderSize DocumentWindow::getContentComponentBorder()
  61875. {
  61876. BorderSize border (getBorderThickness());
  61877. border.setTop (border.getTop()
  61878. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61879. + (menuBar != 0 ? menuBarHeight : 0));
  61880. return border;
  61881. }
  61882. int DocumentWindow::getTitleBarHeight() const
  61883. {
  61884. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61885. }
  61886. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61887. {
  61888. const BorderSize border (getBorderThickness());
  61889. return Rectangle<int> (border.getLeft(), border.getTop(),
  61890. getWidth() - border.getLeftAndRight(),
  61891. getTitleBarHeight());
  61892. }
  61893. Button* DocumentWindow::getCloseButton() const throw()
  61894. {
  61895. return titleBarButtons[2];
  61896. }
  61897. Button* DocumentWindow::getMinimiseButton() const throw()
  61898. {
  61899. return titleBarButtons[0];
  61900. }
  61901. Button* DocumentWindow::getMaximiseButton() const throw()
  61902. {
  61903. return titleBarButtons[1];
  61904. }
  61905. int DocumentWindow::getDesktopWindowStyleFlags() const
  61906. {
  61907. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61908. if ((requiredButtons & minimiseButton) != 0)
  61909. flags |= ComponentPeer::windowHasMinimiseButton;
  61910. if ((requiredButtons & maximiseButton) != 0)
  61911. flags |= ComponentPeer::windowHasMaximiseButton;
  61912. if ((requiredButtons & closeButton) != 0)
  61913. flags |= ComponentPeer::windowHasCloseButton;
  61914. return flags;
  61915. }
  61916. void DocumentWindow::lookAndFeelChanged()
  61917. {
  61918. int i;
  61919. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61920. titleBarButtons[i] = 0;
  61921. if (! isUsingNativeTitleBar())
  61922. {
  61923. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61924. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61925. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61926. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61927. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61928. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61929. for (i = 0; i < 3; ++i)
  61930. {
  61931. if (titleBarButtons[i] != 0)
  61932. {
  61933. if (buttonListener == 0)
  61934. buttonListener = new ButtonListenerProxy (*this);
  61935. titleBarButtons[i]->addButtonListener (buttonListener);
  61936. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61937. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61938. Component::addAndMakeVisible (titleBarButtons[i]);
  61939. }
  61940. }
  61941. if (getCloseButton() != 0)
  61942. {
  61943. #if JUCE_MAC
  61944. getCloseButton()->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
  61945. #else
  61946. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61947. #endif
  61948. }
  61949. }
  61950. activeWindowStatusChanged();
  61951. ResizableWindow::lookAndFeelChanged();
  61952. }
  61953. void DocumentWindow::parentHierarchyChanged()
  61954. {
  61955. lookAndFeelChanged();
  61956. }
  61957. void DocumentWindow::activeWindowStatusChanged()
  61958. {
  61959. ResizableWindow::activeWindowStatusChanged();
  61960. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61961. if (titleBarButtons[i] != 0)
  61962. titleBarButtons[i]->setEnabled (isActiveWindow());
  61963. if (menuBar != 0)
  61964. menuBar->setEnabled (isActiveWindow());
  61965. }
  61966. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61967. {
  61968. if (getTitleBarArea().contains (e.x, e.y)
  61969. && getMaximiseButton() != 0)
  61970. {
  61971. getMaximiseButton()->triggerClick();
  61972. }
  61973. }
  61974. void DocumentWindow::userTriedToCloseWindow()
  61975. {
  61976. closeButtonPressed();
  61977. }
  61978. END_JUCE_NAMESPACE
  61979. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61980. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61981. BEGIN_JUCE_NAMESPACE
  61982. ResizableWindow::ResizableWindow (const String& name,
  61983. const bool addToDesktop_)
  61984. : TopLevelWindow (name, addToDesktop_),
  61985. resizeToFitContent (false),
  61986. fullscreen (false),
  61987. lastNonFullScreenPos (50, 50, 256, 256),
  61988. constrainer (0)
  61989. #ifdef JUCE_DEBUG
  61990. , hasBeenResized (false)
  61991. #endif
  61992. {
  61993. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61994. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61995. if (addToDesktop_)
  61996. Component::addToDesktop (getDesktopWindowStyleFlags());
  61997. }
  61998. ResizableWindow::ResizableWindow (const String& name,
  61999. const Colour& backgroundColour_,
  62000. const bool addToDesktop_)
  62001. : TopLevelWindow (name, addToDesktop_),
  62002. resizeToFitContent (false),
  62003. fullscreen (false),
  62004. lastNonFullScreenPos (50, 50, 256, 256),
  62005. constrainer (0)
  62006. #ifdef JUCE_DEBUG
  62007. , hasBeenResized (false)
  62008. #endif
  62009. {
  62010. setBackgroundColour (backgroundColour_);
  62011. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62012. if (addToDesktop_)
  62013. Component::addToDesktop (getDesktopWindowStyleFlags());
  62014. }
  62015. ResizableWindow::~ResizableWindow()
  62016. {
  62017. resizableCorner = 0;
  62018. resizableBorder = 0;
  62019. contentComponent = 0;
  62020. // have you been adding your own components directly to this window..? tut tut tut.
  62021. // Read the instructions for using a ResizableWindow!
  62022. jassert (getNumChildComponents() == 0);
  62023. }
  62024. int ResizableWindow::getDesktopWindowStyleFlags() const
  62025. {
  62026. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62027. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62028. flags |= ComponentPeer::windowIsResizable;
  62029. return flags;
  62030. }
  62031. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62032. const bool deleteOldOne,
  62033. const bool resizeToFit)
  62034. {
  62035. resizeToFitContent = resizeToFit;
  62036. if (newContentComponent != static_cast <Component*> (contentComponent))
  62037. {
  62038. if (! deleteOldOne)
  62039. removeChildComponent (contentComponent.release());
  62040. contentComponent = newContentComponent;
  62041. Component::addAndMakeVisible (contentComponent);
  62042. }
  62043. if (resizeToFit)
  62044. childBoundsChanged (contentComponent);
  62045. resized(); // must always be called to position the new content comp
  62046. }
  62047. void ResizableWindow::setContentComponentSize (int width, int height)
  62048. {
  62049. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62050. const BorderSize border (getContentComponentBorder());
  62051. setSize (width + border.getLeftAndRight(),
  62052. height + border.getTopAndBottom());
  62053. }
  62054. const BorderSize ResizableWindow::getBorderThickness()
  62055. {
  62056. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62057. }
  62058. const BorderSize ResizableWindow::getContentComponentBorder()
  62059. {
  62060. return getBorderThickness();
  62061. }
  62062. void ResizableWindow::moved()
  62063. {
  62064. updateLastPos();
  62065. }
  62066. void ResizableWindow::visibilityChanged()
  62067. {
  62068. TopLevelWindow::visibilityChanged();
  62069. updateLastPos();
  62070. }
  62071. void ResizableWindow::resized()
  62072. {
  62073. if (resizableBorder != 0)
  62074. {
  62075. resizableBorder->setVisible (! isFullScreen());
  62076. resizableBorder->setBorderThickness (getBorderThickness());
  62077. resizableBorder->setSize (getWidth(), getHeight());
  62078. resizableBorder->toBack();
  62079. }
  62080. if (resizableCorner != 0)
  62081. {
  62082. resizableCorner->setVisible (! isFullScreen());
  62083. const int resizerSize = 18;
  62084. resizableCorner->setBounds (getWidth() - resizerSize,
  62085. getHeight() - resizerSize,
  62086. resizerSize, resizerSize);
  62087. }
  62088. if (contentComponent != 0)
  62089. contentComponent->setBoundsInset (getContentComponentBorder());
  62090. updateLastPos();
  62091. #ifdef JUCE_DEBUG
  62092. hasBeenResized = true;
  62093. #endif
  62094. }
  62095. void ResizableWindow::childBoundsChanged (Component* child)
  62096. {
  62097. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62098. {
  62099. // not going to look very good if this component has a zero size..
  62100. jassert (child->getWidth() > 0);
  62101. jassert (child->getHeight() > 0);
  62102. const BorderSize borders (getContentComponentBorder());
  62103. setSize (child->getWidth() + borders.getLeftAndRight(),
  62104. child->getHeight() + borders.getTopAndBottom());
  62105. }
  62106. }
  62107. void ResizableWindow::activeWindowStatusChanged()
  62108. {
  62109. const BorderSize borders (getContentComponentBorder());
  62110. repaint (0, 0, getWidth(), borders.getTop());
  62111. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62112. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62113. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62114. }
  62115. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62116. const bool useBottomRightCornerResizer)
  62117. {
  62118. if (shouldBeResizable)
  62119. {
  62120. if (useBottomRightCornerResizer)
  62121. {
  62122. resizableBorder = 0;
  62123. if (resizableCorner == 0)
  62124. {
  62125. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62126. resizableCorner->setAlwaysOnTop (true);
  62127. }
  62128. }
  62129. else
  62130. {
  62131. resizableCorner = 0;
  62132. if (resizableBorder == 0)
  62133. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62134. }
  62135. }
  62136. else
  62137. {
  62138. resizableCorner = 0;
  62139. resizableBorder = 0;
  62140. }
  62141. if (isUsingNativeTitleBar())
  62142. recreateDesktopWindow();
  62143. childBoundsChanged (contentComponent);
  62144. resized();
  62145. }
  62146. bool ResizableWindow::isResizable() const throw()
  62147. {
  62148. return resizableCorner != 0
  62149. || resizableBorder != 0;
  62150. }
  62151. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62152. const int newMinimumHeight,
  62153. const int newMaximumWidth,
  62154. const int newMaximumHeight) throw()
  62155. {
  62156. // if you've set up a custom constrainer then these settings won't have any effect..
  62157. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62158. if (constrainer == 0)
  62159. setConstrainer (&defaultConstrainer);
  62160. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62161. newMaximumWidth, newMaximumHeight);
  62162. setBoundsConstrained (getBounds());
  62163. }
  62164. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62165. {
  62166. if (constrainer != newConstrainer)
  62167. {
  62168. constrainer = newConstrainer;
  62169. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62170. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62171. resizableCorner = 0;
  62172. resizableBorder = 0;
  62173. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62174. ComponentPeer* const peer = getPeer();
  62175. if (peer != 0)
  62176. peer->setConstrainer (newConstrainer);
  62177. }
  62178. }
  62179. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62180. {
  62181. if (constrainer != 0)
  62182. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62183. else
  62184. setBounds (bounds);
  62185. }
  62186. void ResizableWindow::paint (Graphics& g)
  62187. {
  62188. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62189. getBorderThickness(), *this);
  62190. if (! isFullScreen())
  62191. {
  62192. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62193. getBorderThickness(), *this);
  62194. }
  62195. #ifdef JUCE_DEBUG
  62196. /* If this fails, then you've probably written a subclass with a resized()
  62197. callback but forgotten to make it call its parent class's resized() method.
  62198. It's important when you override methods like resized(), moved(),
  62199. etc., that you make sure the base class methods also get called.
  62200. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62201. because your content should all be inside the content component - and it's the
  62202. content component's resized() method that you should be using to do your
  62203. layout.
  62204. */
  62205. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62206. #endif
  62207. }
  62208. void ResizableWindow::lookAndFeelChanged()
  62209. {
  62210. resized();
  62211. if (isOnDesktop())
  62212. {
  62213. Component::addToDesktop (getDesktopWindowStyleFlags());
  62214. ComponentPeer* const peer = getPeer();
  62215. if (peer != 0)
  62216. peer->setConstrainer (constrainer);
  62217. }
  62218. }
  62219. const Colour ResizableWindow::getBackgroundColour() const throw()
  62220. {
  62221. return findColour (backgroundColourId, false);
  62222. }
  62223. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62224. {
  62225. Colour backgroundColour (newColour);
  62226. if (! Desktop::canUseSemiTransparentWindows())
  62227. backgroundColour = newColour.withAlpha (1.0f);
  62228. setColour (backgroundColourId, backgroundColour);
  62229. setOpaque (backgroundColour.isOpaque());
  62230. repaint();
  62231. }
  62232. bool ResizableWindow::isFullScreen() const
  62233. {
  62234. if (isOnDesktop())
  62235. {
  62236. ComponentPeer* const peer = getPeer();
  62237. return peer != 0 && peer->isFullScreen();
  62238. }
  62239. return fullscreen;
  62240. }
  62241. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62242. {
  62243. if (shouldBeFullScreen != isFullScreen())
  62244. {
  62245. updateLastPos();
  62246. fullscreen = shouldBeFullScreen;
  62247. if (isOnDesktop())
  62248. {
  62249. ComponentPeer* const peer = getPeer();
  62250. if (peer != 0)
  62251. {
  62252. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62253. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62254. peer->setFullScreen (shouldBeFullScreen);
  62255. if (! shouldBeFullScreen)
  62256. setBounds (lastPos);
  62257. }
  62258. else
  62259. {
  62260. jassertfalse
  62261. }
  62262. }
  62263. else
  62264. {
  62265. if (shouldBeFullScreen)
  62266. setBounds (0, 0, getParentWidth(), getParentHeight());
  62267. else
  62268. setBounds (lastNonFullScreenPos);
  62269. }
  62270. resized();
  62271. }
  62272. }
  62273. bool ResizableWindow::isMinimised() const
  62274. {
  62275. ComponentPeer* const peer = getPeer();
  62276. return (peer != 0) && peer->isMinimised();
  62277. }
  62278. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62279. {
  62280. if (shouldMinimise != isMinimised())
  62281. {
  62282. ComponentPeer* const peer = getPeer();
  62283. if (peer != 0)
  62284. {
  62285. updateLastPos();
  62286. peer->setMinimised (shouldMinimise);
  62287. }
  62288. else
  62289. {
  62290. jassertfalse
  62291. }
  62292. }
  62293. }
  62294. void ResizableWindow::updateLastPos()
  62295. {
  62296. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62297. {
  62298. lastNonFullScreenPos = getBounds();
  62299. }
  62300. }
  62301. void ResizableWindow::parentSizeChanged()
  62302. {
  62303. if (isFullScreen() && getParentComponent() != 0)
  62304. {
  62305. setBounds (0, 0, getParentWidth(), getParentHeight());
  62306. }
  62307. }
  62308. const String ResizableWindow::getWindowStateAsString()
  62309. {
  62310. updateLastPos();
  62311. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62312. }
  62313. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62314. {
  62315. StringArray tokens;
  62316. tokens.addTokens (s, false);
  62317. tokens.removeEmptyStrings();
  62318. tokens.trim();
  62319. const bool fs = tokens[0].startsWithIgnoreCase ("fs");
  62320. const int firstCoord = fs ? 1 : 0;
  62321. if (tokens.size() != firstCoord + 4)
  62322. return false;
  62323. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62324. tokens[firstCoord + 1].getIntValue(),
  62325. tokens[firstCoord + 2].getIntValue(),
  62326. tokens[firstCoord + 3].getIntValue());
  62327. if (newPos.isEmpty())
  62328. return false;
  62329. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62330. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62331. if (peer != 0)
  62332. peer->getFrameSize().addTo (newPos);
  62333. if (! screen.contains (newPos))
  62334. {
  62335. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62336. jmin (newPos.getHeight(), screen.getHeight()));
  62337. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62338. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62339. }
  62340. if (peer != 0)
  62341. {
  62342. peer->getFrameSize().subtractFrom (newPos);
  62343. peer->setNonFullScreenBounds (newPos);
  62344. }
  62345. lastNonFullScreenPos = newPos;
  62346. setFullScreen (fs);
  62347. if (! fs)
  62348. setBoundsConstrained (newPos);
  62349. return true;
  62350. }
  62351. void ResizableWindow::mouseDown (const MouseEvent&)
  62352. {
  62353. if (! isFullScreen())
  62354. dragger.startDraggingComponent (this, constrainer);
  62355. }
  62356. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62357. {
  62358. if (! isFullScreen())
  62359. dragger.dragComponent (this, e);
  62360. }
  62361. #ifdef JUCE_DEBUG
  62362. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62363. {
  62364. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62365. manages its child components automatically, and if you add your own it'll cause
  62366. trouble. Instead, use setContentComponent() to give it a component which
  62367. will be automatically resized and kept in the right place - then you can add
  62368. subcomponents to the content comp. See the notes for the ResizableWindow class
  62369. for more info.
  62370. If you really know what you're doing and want to avoid this assertion, just call
  62371. Component::addChildComponent directly.
  62372. */
  62373. jassertfalse
  62374. Component::addChildComponent (child, zOrder);
  62375. }
  62376. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62377. {
  62378. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62379. manages its child components automatically, and if you add your own it'll cause
  62380. trouble. Instead, use setContentComponent() to give it a component which
  62381. will be automatically resized and kept in the right place - then you can add
  62382. subcomponents to the content comp. See the notes for the ResizableWindow class
  62383. for more info.
  62384. If you really know what you're doing and want to avoid this assertion, just call
  62385. Component::addAndMakeVisible directly.
  62386. */
  62387. jassertfalse
  62388. Component::addAndMakeVisible (child, zOrder);
  62389. }
  62390. #endif
  62391. END_JUCE_NAMESPACE
  62392. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62393. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62394. BEGIN_JUCE_NAMESPACE
  62395. SplashScreen::SplashScreen()
  62396. : backgroundImage (0)
  62397. {
  62398. setOpaque (true);
  62399. }
  62400. SplashScreen::~SplashScreen()
  62401. {
  62402. ImageCache::releaseOrDelete (backgroundImage);
  62403. }
  62404. void SplashScreen::show (const String& title,
  62405. Image* const backgroundImage_,
  62406. const int minimumTimeToDisplayFor,
  62407. const bool useDropShadow,
  62408. const bool removeOnMouseClick)
  62409. {
  62410. backgroundImage = backgroundImage_;
  62411. jassert (backgroundImage_ != 0);
  62412. if (backgroundImage_ != 0)
  62413. {
  62414. setOpaque (! backgroundImage_->hasAlphaChannel());
  62415. show (title,
  62416. backgroundImage_->getWidth(),
  62417. backgroundImage_->getHeight(),
  62418. minimumTimeToDisplayFor,
  62419. useDropShadow,
  62420. removeOnMouseClick);
  62421. }
  62422. }
  62423. void SplashScreen::show (const String& title,
  62424. const int width,
  62425. const int height,
  62426. const int minimumTimeToDisplayFor,
  62427. const bool useDropShadow,
  62428. const bool removeOnMouseClick)
  62429. {
  62430. setName (title);
  62431. setAlwaysOnTop (true);
  62432. setVisible (true);
  62433. centreWithSize (width, height);
  62434. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62435. toFront (false);
  62436. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62437. repaint();
  62438. originalClickCounter = removeOnMouseClick
  62439. ? Desktop::getMouseButtonClickCounter()
  62440. : std::numeric_limits<int>::max();
  62441. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62442. startTimer (50);
  62443. }
  62444. void SplashScreen::paint (Graphics& g)
  62445. {
  62446. if (backgroundImage != 0)
  62447. {
  62448. g.setOpacity (1.0f);
  62449. g.drawImage (backgroundImage,
  62450. 0, 0, getWidth(), getHeight(),
  62451. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62452. }
  62453. }
  62454. void SplashScreen::timerCallback()
  62455. {
  62456. if (Time::getCurrentTime() > earliestTimeToDelete
  62457. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62458. {
  62459. delete this;
  62460. }
  62461. }
  62462. END_JUCE_NAMESPACE
  62463. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62464. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62465. BEGIN_JUCE_NAMESPACE
  62466. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62467. const bool hasProgressBar,
  62468. const bool hasCancelButton,
  62469. const int timeOutMsWhenCancelling_,
  62470. const String& cancelButtonText)
  62471. : Thread ("Juce Progress Window"),
  62472. progress (0.0),
  62473. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62474. {
  62475. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62476. .createAlertWindow (title, String::empty, cancelButtonText,
  62477. String::empty, String::empty,
  62478. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62479. if (hasProgressBar)
  62480. alertWindow->addProgressBarComponent (progress);
  62481. }
  62482. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62483. {
  62484. stopThread (timeOutMsWhenCancelling);
  62485. }
  62486. bool ThreadWithProgressWindow::runThread (const int priority)
  62487. {
  62488. startThread (priority);
  62489. startTimer (100);
  62490. {
  62491. const ScopedLock sl (messageLock);
  62492. alertWindow->setMessage (message);
  62493. }
  62494. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62495. stopThread (timeOutMsWhenCancelling);
  62496. alertWindow->setVisible (false);
  62497. return finishedNaturally;
  62498. }
  62499. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62500. {
  62501. progress = newProgress;
  62502. }
  62503. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62504. {
  62505. const ScopedLock sl (messageLock);
  62506. message = newStatusMessage;
  62507. }
  62508. void ThreadWithProgressWindow::timerCallback()
  62509. {
  62510. if (! isThreadRunning())
  62511. {
  62512. // thread has finished normally..
  62513. alertWindow->exitModalState (1);
  62514. alertWindow->setVisible (false);
  62515. }
  62516. else
  62517. {
  62518. const ScopedLock sl (messageLock);
  62519. alertWindow->setMessage (message);
  62520. }
  62521. }
  62522. END_JUCE_NAMESPACE
  62523. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62524. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62525. BEGIN_JUCE_NAMESPACE
  62526. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62527. const int millisecondsBeforeTipAppears_)
  62528. : Component ("tooltip"),
  62529. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62530. mouseClicks (0),
  62531. lastHideTime (0),
  62532. lastComponentUnderMouse (0),
  62533. changedCompsSinceShown (true)
  62534. {
  62535. if (Desktop::getInstance().getMainMouseSource().canHover())
  62536. startTimer (123);
  62537. setAlwaysOnTop (true);
  62538. setOpaque (true);
  62539. if (parentComponent != 0)
  62540. parentComponent->addChildComponent (this);
  62541. }
  62542. TooltipWindow::~TooltipWindow()
  62543. {
  62544. hide();
  62545. }
  62546. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62547. {
  62548. millisecondsBeforeTipAppears = newTimeMs;
  62549. }
  62550. void TooltipWindow::paint (Graphics& g)
  62551. {
  62552. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62553. }
  62554. void TooltipWindow::mouseEnter (const MouseEvent&)
  62555. {
  62556. hide();
  62557. }
  62558. void TooltipWindow::showFor (const String& tip)
  62559. {
  62560. jassert (tip.isNotEmpty());
  62561. tipShowing = tip;
  62562. Point<int> mousePos (Desktop::getMousePosition());
  62563. if (getParentComponent() != 0)
  62564. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62565. int x, y, w, h;
  62566. getLookAndFeel().getTooltipSize (tip, w, h);
  62567. if (mousePos.getX() > getParentWidth() / 2)
  62568. x = mousePos.getX() - (w + 12);
  62569. else
  62570. x = mousePos.getX() + 24;
  62571. if (mousePos.getY() > getParentHeight() / 2)
  62572. y = mousePos.getY() - (h + 6);
  62573. else
  62574. y = mousePos.getY() + 6;
  62575. setBounds (x, y, w, h);
  62576. setVisible (true);
  62577. if (getParentComponent() == 0)
  62578. {
  62579. addToDesktop (ComponentPeer::windowHasDropShadow
  62580. | ComponentPeer::windowIsTemporary
  62581. | ComponentPeer::windowIgnoresKeyPresses);
  62582. }
  62583. toFront (false);
  62584. }
  62585. const String TooltipWindow::getTipFor (Component* const c)
  62586. {
  62587. if (c != 0
  62588. && Process::isForegroundProcess()
  62589. && ! Component::isMouseButtonDownAnywhere())
  62590. {
  62591. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62592. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62593. return ttc->getTooltip();
  62594. }
  62595. return String::empty;
  62596. }
  62597. void TooltipWindow::hide()
  62598. {
  62599. tipShowing = String::empty;
  62600. removeFromDesktop();
  62601. setVisible (false);
  62602. }
  62603. void TooltipWindow::timerCallback()
  62604. {
  62605. const unsigned int now = Time::getApproximateMillisecondCounter();
  62606. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62607. const String newTip (getTipFor (newComp));
  62608. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62609. lastComponentUnderMouse = newComp;
  62610. lastTipUnderMouse = newTip;
  62611. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62612. const bool mouseWasClicked = clickCount > mouseClicks;
  62613. mouseClicks = clickCount;
  62614. const Point<int> mousePos (Desktop::getMousePosition());
  62615. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62616. lastMousePos = mousePos;
  62617. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62618. lastCompChangeTime = now;
  62619. if (isVisible() || now < lastHideTime + 500)
  62620. {
  62621. // if a tip is currently visible (or has just disappeared), update to a new one
  62622. // immediately if needed..
  62623. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62624. {
  62625. if (isVisible())
  62626. {
  62627. lastHideTime = now;
  62628. hide();
  62629. }
  62630. }
  62631. else if (tipChanged)
  62632. {
  62633. showFor (newTip);
  62634. }
  62635. }
  62636. else
  62637. {
  62638. // if there isn't currently a tip, but one is needed, only let it
  62639. // appear after a timeout..
  62640. if (newTip.isNotEmpty()
  62641. && newTip != tipShowing
  62642. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62643. {
  62644. showFor (newTip);
  62645. }
  62646. }
  62647. }
  62648. END_JUCE_NAMESPACE
  62649. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62650. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62651. BEGIN_JUCE_NAMESPACE
  62652. class TopLevelWindowManager : public Timer,
  62653. public DeletedAtShutdown
  62654. {
  62655. public:
  62656. TopLevelWindowManager()
  62657. : currentActive (0)
  62658. {
  62659. }
  62660. ~TopLevelWindowManager()
  62661. {
  62662. clearSingletonInstance();
  62663. }
  62664. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62665. void timerCallback()
  62666. {
  62667. startTimer (jmin (1731, getTimerInterval() * 2));
  62668. TopLevelWindow* active = 0;
  62669. if (Process::isForegroundProcess())
  62670. {
  62671. active = currentActive;
  62672. Component* const c = Component::getCurrentlyFocusedComponent();
  62673. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62674. if (tlw == 0 && c != 0)
  62675. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62676. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62677. if (tlw != 0)
  62678. active = tlw;
  62679. }
  62680. if (active != currentActive)
  62681. {
  62682. currentActive = active;
  62683. for (int i = windows.size(); --i >= 0;)
  62684. {
  62685. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62686. tlw->setWindowActive (isWindowActive (tlw));
  62687. i = jmin (i, windows.size() - 1);
  62688. }
  62689. Desktop::getInstance().triggerFocusCallback();
  62690. }
  62691. }
  62692. bool addWindow (TopLevelWindow* const w) throw()
  62693. {
  62694. windows.add (w);
  62695. startTimer (10);
  62696. return isWindowActive (w);
  62697. }
  62698. void removeWindow (TopLevelWindow* const w) throw()
  62699. {
  62700. startTimer (10);
  62701. if (currentActive == w)
  62702. currentActive = 0;
  62703. windows.removeValue (w);
  62704. if (windows.size() == 0)
  62705. deleteInstance();
  62706. }
  62707. VoidArray windows;
  62708. private:
  62709. TopLevelWindow* currentActive;
  62710. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62711. {
  62712. return (tlw == currentActive
  62713. || tlw->isParentOf (currentActive)
  62714. || tlw->hasKeyboardFocus (true))
  62715. && tlw->isShowing();
  62716. }
  62717. TopLevelWindowManager (const TopLevelWindowManager&);
  62718. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62719. };
  62720. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62721. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62722. {
  62723. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62724. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62725. }
  62726. TopLevelWindow::TopLevelWindow (const String& name,
  62727. const bool addToDesktop_)
  62728. : Component (name),
  62729. useDropShadow (true),
  62730. useNativeTitleBar (false),
  62731. windowIsActive_ (false)
  62732. {
  62733. setOpaque (true);
  62734. if (addToDesktop_)
  62735. Component::addToDesktop (getDesktopWindowStyleFlags());
  62736. else
  62737. setDropShadowEnabled (true);
  62738. setWantsKeyboardFocus (true);
  62739. setBroughtToFrontOnMouseClick (true);
  62740. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62741. }
  62742. TopLevelWindow::~TopLevelWindow()
  62743. {
  62744. shadower = 0;
  62745. TopLevelWindowManager::getInstance()->removeWindow (this);
  62746. }
  62747. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62748. {
  62749. if (hasKeyboardFocus (true))
  62750. TopLevelWindowManager::getInstance()->timerCallback();
  62751. else
  62752. TopLevelWindowManager::getInstance()->startTimer (10);
  62753. }
  62754. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62755. {
  62756. if (windowIsActive_ != isNowActive)
  62757. {
  62758. windowIsActive_ = isNowActive;
  62759. activeWindowStatusChanged();
  62760. }
  62761. }
  62762. void TopLevelWindow::activeWindowStatusChanged()
  62763. {
  62764. }
  62765. void TopLevelWindow::parentHierarchyChanged()
  62766. {
  62767. setDropShadowEnabled (useDropShadow);
  62768. }
  62769. void TopLevelWindow::visibilityChanged()
  62770. {
  62771. if (isShowing())
  62772. toFront (true);
  62773. }
  62774. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62775. {
  62776. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62777. if (useDropShadow)
  62778. flags |= ComponentPeer::windowHasDropShadow;
  62779. if (useNativeTitleBar)
  62780. flags |= ComponentPeer::windowHasTitleBar;
  62781. return flags;
  62782. }
  62783. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62784. {
  62785. useDropShadow = useShadow;
  62786. if (isOnDesktop())
  62787. {
  62788. shadower = 0;
  62789. Component::addToDesktop (getDesktopWindowStyleFlags());
  62790. }
  62791. else
  62792. {
  62793. if (useShadow && isOpaque())
  62794. {
  62795. if (shadower == 0)
  62796. {
  62797. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62798. if (shadower != 0)
  62799. shadower->setOwner (this);
  62800. }
  62801. }
  62802. else
  62803. {
  62804. shadower = 0;
  62805. }
  62806. }
  62807. }
  62808. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62809. {
  62810. if (useNativeTitleBar != useNativeTitleBar_)
  62811. {
  62812. useNativeTitleBar = useNativeTitleBar_;
  62813. recreateDesktopWindow();
  62814. sendLookAndFeelChange();
  62815. }
  62816. }
  62817. void TopLevelWindow::recreateDesktopWindow()
  62818. {
  62819. if (isOnDesktop())
  62820. {
  62821. Component::addToDesktop (getDesktopWindowStyleFlags());
  62822. toFront (true);
  62823. }
  62824. }
  62825. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62826. {
  62827. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62828. because this class needs to make sure its layout corresponds with settings like whether
  62829. it's got a native title bar or not.
  62830. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62831. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62832. method, then add or remove whatever flags are necessary from this value before returning it.
  62833. */
  62834. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62835. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62836. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62837. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62838. sendLookAndFeelChange();
  62839. }
  62840. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62841. {
  62842. if (c == 0)
  62843. c = TopLevelWindow::getActiveTopLevelWindow();
  62844. if (c == 0)
  62845. {
  62846. centreWithSize (width, height);
  62847. }
  62848. else
  62849. {
  62850. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62851. (c->getHeight() - height) / 2)));
  62852. Rectangle<int> parentArea (c->getParentMonitorArea());
  62853. if (getParentComponent() != 0)
  62854. {
  62855. p = getParentComponent()->globalPositionToRelative (p);
  62856. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62857. }
  62858. parentArea.reduce (12, 12);
  62859. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62860. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62861. width, height);
  62862. }
  62863. }
  62864. int TopLevelWindow::getNumTopLevelWindows() throw()
  62865. {
  62866. return TopLevelWindowManager::getInstance()->windows.size();
  62867. }
  62868. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62869. {
  62870. return static_cast <TopLevelWindow*> (TopLevelWindowManager::getInstance()->windows [index]);
  62871. }
  62872. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62873. {
  62874. TopLevelWindow* best = 0;
  62875. int bestNumTWLParents = -1;
  62876. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62877. {
  62878. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62879. if (tlw->isActiveWindow())
  62880. {
  62881. int numTWLParents = 0;
  62882. const Component* c = tlw->getParentComponent();
  62883. while (c != 0)
  62884. {
  62885. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62886. ++numTWLParents;
  62887. c = c->getParentComponent();
  62888. }
  62889. if (bestNumTWLParents < numTWLParents)
  62890. {
  62891. best = tlw;
  62892. bestNumTWLParents = numTWLParents;
  62893. }
  62894. }
  62895. }
  62896. return best;
  62897. }
  62898. END_JUCE_NAMESPACE
  62899. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62900. /*** Start of inlined file: juce_Colour.cpp ***/
  62901. BEGIN_JUCE_NAMESPACE
  62902. namespace ColourHelpers
  62903. {
  62904. static uint8 floatAlphaToInt (const float alpha) throw()
  62905. {
  62906. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62907. }
  62908. static void convertHSBtoRGB (float h, float s, float v,
  62909. uint8& r, uint8& g, uint8& b) throw()
  62910. {
  62911. v = jlimit (0.0f, 1.0f, v);
  62912. v *= 255.0f;
  62913. const uint8 intV = (uint8) roundToInt (v);
  62914. if (s <= 0)
  62915. {
  62916. r = intV;
  62917. g = intV;
  62918. b = intV;
  62919. }
  62920. else
  62921. {
  62922. s = jmin (1.0f, s);
  62923. h = jlimit (0.0f, 1.0f, h);
  62924. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62925. const float f = h - floorf (h);
  62926. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62927. const float y = v * (1.0f - s * f);
  62928. const float z = v * (1.0f - (s * (1.0f - f)));
  62929. if (h < 1.0f)
  62930. {
  62931. r = intV;
  62932. g = (uint8) roundToInt (z);
  62933. b = x;
  62934. }
  62935. else if (h < 2.0f)
  62936. {
  62937. r = (uint8) roundToInt (y);
  62938. g = intV;
  62939. b = x;
  62940. }
  62941. else if (h < 3.0f)
  62942. {
  62943. r = x;
  62944. g = intV;
  62945. b = (uint8) roundToInt (z);
  62946. }
  62947. else if (h < 4.0f)
  62948. {
  62949. r = x;
  62950. g = (uint8) roundToInt (y);
  62951. b = intV;
  62952. }
  62953. else if (h < 5.0f)
  62954. {
  62955. r = (uint8) roundToInt (z);
  62956. g = x;
  62957. b = intV;
  62958. }
  62959. else if (h < 6.0f)
  62960. {
  62961. r = intV;
  62962. g = x;
  62963. b = (uint8) roundToInt (y);
  62964. }
  62965. else
  62966. {
  62967. r = 0;
  62968. g = 0;
  62969. b = 0;
  62970. }
  62971. }
  62972. }
  62973. }
  62974. Colour::Colour() throw()
  62975. : argb (0)
  62976. {
  62977. }
  62978. Colour::Colour (const Colour& other) throw()
  62979. : argb (other.argb)
  62980. {
  62981. }
  62982. Colour& Colour::operator= (const Colour& other) throw()
  62983. {
  62984. argb = other.argb;
  62985. return *this;
  62986. }
  62987. bool Colour::operator== (const Colour& other) const throw()
  62988. {
  62989. return argb.getARGB() == other.argb.getARGB();
  62990. }
  62991. bool Colour::operator!= (const Colour& other) const throw()
  62992. {
  62993. return argb.getARGB() != other.argb.getARGB();
  62994. }
  62995. Colour::Colour (const uint32 argb_) throw()
  62996. : argb (argb_)
  62997. {
  62998. }
  62999. Colour::Colour (const uint8 red,
  63000. const uint8 green,
  63001. const uint8 blue) throw()
  63002. {
  63003. argb.setARGB (0xff, red, green, blue);
  63004. }
  63005. const Colour Colour::fromRGB (const uint8 red,
  63006. const uint8 green,
  63007. const uint8 blue) throw()
  63008. {
  63009. return Colour (red, green, blue);
  63010. }
  63011. Colour::Colour (const uint8 red,
  63012. const uint8 green,
  63013. const uint8 blue,
  63014. const uint8 alpha) throw()
  63015. {
  63016. argb.setARGB (alpha, red, green, blue);
  63017. }
  63018. const Colour Colour::fromRGBA (const uint8 red,
  63019. const uint8 green,
  63020. const uint8 blue,
  63021. const uint8 alpha) throw()
  63022. {
  63023. return Colour (red, green, blue, alpha);
  63024. }
  63025. Colour::Colour (const uint8 red,
  63026. const uint8 green,
  63027. const uint8 blue,
  63028. const float alpha) throw()
  63029. {
  63030. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  63031. }
  63032. const Colour Colour::fromRGBAFloat (const uint8 red,
  63033. const uint8 green,
  63034. const uint8 blue,
  63035. const float alpha) throw()
  63036. {
  63037. return Colour (red, green, blue, alpha);
  63038. }
  63039. Colour::Colour (const float hue,
  63040. const float saturation,
  63041. const float brightness,
  63042. const float alpha) throw()
  63043. {
  63044. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63045. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63046. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  63047. }
  63048. const Colour Colour::fromHSV (const float hue,
  63049. const float saturation,
  63050. const float brightness,
  63051. const float alpha) throw()
  63052. {
  63053. return Colour (hue, saturation, brightness, alpha);
  63054. }
  63055. Colour::Colour (const float hue,
  63056. const float saturation,
  63057. const float brightness,
  63058. const uint8 alpha) throw()
  63059. {
  63060. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63061. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63062. argb.setARGB (alpha, r, g, b);
  63063. }
  63064. Colour::~Colour() throw()
  63065. {
  63066. }
  63067. const PixelARGB Colour::getPixelARGB() const throw()
  63068. {
  63069. PixelARGB p (argb);
  63070. p.premultiply();
  63071. return p;
  63072. }
  63073. uint32 Colour::getARGB() const throw()
  63074. {
  63075. return argb.getARGB();
  63076. }
  63077. bool Colour::isTransparent() const throw()
  63078. {
  63079. return getAlpha() == 0;
  63080. }
  63081. bool Colour::isOpaque() const throw()
  63082. {
  63083. return getAlpha() == 0xff;
  63084. }
  63085. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63086. {
  63087. PixelARGB newCol (argb);
  63088. newCol.setAlpha (newAlpha);
  63089. return Colour (newCol.getARGB());
  63090. }
  63091. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63092. {
  63093. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63094. PixelARGB newCol (argb);
  63095. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  63096. return Colour (newCol.getARGB());
  63097. }
  63098. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63099. {
  63100. jassert (alphaMultiplier >= 0);
  63101. PixelARGB newCol (argb);
  63102. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63103. return Colour (newCol.getARGB());
  63104. }
  63105. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63106. {
  63107. const int destAlpha = getAlpha();
  63108. if (destAlpha > 0)
  63109. {
  63110. const int invA = 0xff - (int) src.getAlpha();
  63111. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63112. if (resA > 0)
  63113. {
  63114. const int da = (invA * destAlpha) / resA;
  63115. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63116. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63117. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63118. (uint8) resA);
  63119. }
  63120. return *this;
  63121. }
  63122. else
  63123. {
  63124. return src;
  63125. }
  63126. }
  63127. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63128. {
  63129. if (proportionOfOther <= 0)
  63130. return *this;
  63131. if (proportionOfOther >= 1.0f)
  63132. return other;
  63133. PixelARGB c1 (getPixelARGB());
  63134. const PixelARGB c2 (other.getPixelARGB());
  63135. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63136. c1.unpremultiply();
  63137. return Colour (c1.getARGB());
  63138. }
  63139. float Colour::getFloatRed() const throw()
  63140. {
  63141. return getRed() / 255.0f;
  63142. }
  63143. float Colour::getFloatGreen() const throw()
  63144. {
  63145. return getGreen() / 255.0f;
  63146. }
  63147. float Colour::getFloatBlue() const throw()
  63148. {
  63149. return getBlue() / 255.0f;
  63150. }
  63151. float Colour::getFloatAlpha() const throw()
  63152. {
  63153. return getAlpha() / 255.0f;
  63154. }
  63155. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63156. {
  63157. const int r = getRed();
  63158. const int g = getGreen();
  63159. const int b = getBlue();
  63160. const int hi = jmax (r, g, b);
  63161. const int lo = jmin (r, g, b);
  63162. if (hi != 0)
  63163. {
  63164. s = (hi - lo) / (float) hi;
  63165. if (s != 0)
  63166. {
  63167. const float invDiff = 1.0f / (hi - lo);
  63168. const float red = (hi - r) * invDiff;
  63169. const float green = (hi - g) * invDiff;
  63170. const float blue = (hi - b) * invDiff;
  63171. if (r == hi)
  63172. h = blue - green;
  63173. else if (g == hi)
  63174. h = 2.0f + red - blue;
  63175. else
  63176. h = 4.0f + green - red;
  63177. h *= 1.0f / 6.0f;
  63178. if (h < 0)
  63179. ++h;
  63180. }
  63181. else
  63182. {
  63183. h = 0;
  63184. }
  63185. }
  63186. else
  63187. {
  63188. s = 0;
  63189. h = 0;
  63190. }
  63191. v = hi / 255.0f;
  63192. }
  63193. float Colour::getHue() const throw()
  63194. {
  63195. float h, s, b;
  63196. getHSB (h, s, b);
  63197. return h;
  63198. }
  63199. const Colour Colour::withHue (const float hue) const throw()
  63200. {
  63201. float h, s, b;
  63202. getHSB (h, s, b);
  63203. return Colour (hue, s, b, getAlpha());
  63204. }
  63205. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63206. {
  63207. float h, s, b;
  63208. getHSB (h, s, b);
  63209. h += amountToRotate;
  63210. h -= floorf (h);
  63211. return Colour (h, s, b, getAlpha());
  63212. }
  63213. float Colour::getSaturation() const throw()
  63214. {
  63215. float h, s, b;
  63216. getHSB (h, s, b);
  63217. return s;
  63218. }
  63219. const Colour Colour::withSaturation (const float saturation) const throw()
  63220. {
  63221. float h, s, b;
  63222. getHSB (h, s, b);
  63223. return Colour (h, saturation, b, getAlpha());
  63224. }
  63225. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63226. {
  63227. float h, s, b;
  63228. getHSB (h, s, b);
  63229. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63230. }
  63231. float Colour::getBrightness() const throw()
  63232. {
  63233. float h, s, b;
  63234. getHSB (h, s, b);
  63235. return b;
  63236. }
  63237. const Colour Colour::withBrightness (const float brightness) const throw()
  63238. {
  63239. float h, s, b;
  63240. getHSB (h, s, b);
  63241. return Colour (h, s, brightness, getAlpha());
  63242. }
  63243. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63244. {
  63245. float h, s, b;
  63246. getHSB (h, s, b);
  63247. b *= amount;
  63248. if (b > 1.0f)
  63249. b = 1.0f;
  63250. return Colour (h, s, b, getAlpha());
  63251. }
  63252. const Colour Colour::brighter (float amount) const throw()
  63253. {
  63254. amount = 1.0f / (1.0f + amount);
  63255. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63256. (uint8) (255 - (amount * (255 - getGreen()))),
  63257. (uint8) (255 - (amount * (255 - getBlue()))),
  63258. getAlpha());
  63259. }
  63260. const Colour Colour::darker (float amount) const throw()
  63261. {
  63262. amount = 1.0f / (1.0f + amount);
  63263. return Colour ((uint8) (amount * getRed()),
  63264. (uint8) (amount * getGreen()),
  63265. (uint8) (amount * getBlue()),
  63266. getAlpha());
  63267. }
  63268. const Colour Colour::greyLevel (const float brightness) throw()
  63269. {
  63270. const uint8 level
  63271. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63272. return Colour (level, level, level);
  63273. }
  63274. const Colour Colour::contrasting (const float amount) const throw()
  63275. {
  63276. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63277. ? Colours::black
  63278. : Colours::white).withAlpha (amount));
  63279. }
  63280. const Colour Colour::contrasting (const Colour& colour1,
  63281. const Colour& colour2) throw()
  63282. {
  63283. const float b1 = colour1.getBrightness();
  63284. const float b2 = colour2.getBrightness();
  63285. float best = 0.0f;
  63286. float bestDist = 0.0f;
  63287. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63288. {
  63289. const float d1 = fabsf (i - b1);
  63290. const float d2 = fabsf (i - b2);
  63291. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63292. if (dist > bestDist)
  63293. {
  63294. best = i;
  63295. bestDist = dist;
  63296. }
  63297. }
  63298. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63299. .withBrightness (best);
  63300. }
  63301. const String Colour::toString() const
  63302. {
  63303. return String::toHexString ((int) argb.getARGB());
  63304. }
  63305. const Colour Colour::fromString (const String& encodedColourString)
  63306. {
  63307. return Colour ((uint32) encodedColourString.getHexValue32());
  63308. }
  63309. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63310. {
  63311. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63312. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63313. .toUpperCase();
  63314. }
  63315. END_JUCE_NAMESPACE
  63316. /*** End of inlined file: juce_Colour.cpp ***/
  63317. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63318. BEGIN_JUCE_NAMESPACE
  63319. ColourGradient::ColourGradient() throw()
  63320. {
  63321. #ifdef JUCE_DEBUG
  63322. x1 = 987654.0f;
  63323. #endif
  63324. }
  63325. ColourGradient::ColourGradient (const Colour& colour1,
  63326. const float x1_,
  63327. const float y1_,
  63328. const Colour& colour2,
  63329. const float x2_,
  63330. const float y2_,
  63331. const bool isRadial_) throw()
  63332. : x1 (x1_),
  63333. y1 (y1_),
  63334. x2 (x2_),
  63335. y2 (y2_),
  63336. isRadial (isRadial_)
  63337. {
  63338. colours.add (0);
  63339. colours.add (colour1.getARGB());
  63340. colours.add (1 << 16);
  63341. colours.add (colour2.getARGB());
  63342. }
  63343. ColourGradient::~ColourGradient() throw()
  63344. {
  63345. }
  63346. void ColourGradient::clearColours() throw()
  63347. {
  63348. colours.clear();
  63349. }
  63350. void ColourGradient::addColour (const double proportionAlongGradient,
  63351. const Colour& colour) throw()
  63352. {
  63353. // must be within the two end-points
  63354. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63355. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63356. int i;
  63357. for (i = 0; i < colours.size(); i += 2)
  63358. if (colours.getUnchecked(i) > pos)
  63359. break;
  63360. colours.insert (i, pos);
  63361. colours.insert (i + 1, colour.getARGB());
  63362. }
  63363. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63364. {
  63365. for (int i = 1; i < colours.size(); i += 2)
  63366. {
  63367. const Colour c (colours.getUnchecked(i));
  63368. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63369. }
  63370. }
  63371. int ColourGradient::getNumColours() const throw()
  63372. {
  63373. return colours.size() >> 1;
  63374. }
  63375. double ColourGradient::getColourPosition (const int index) const throw()
  63376. {
  63377. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63378. }
  63379. const Colour ColourGradient::getColour (const int index) const throw()
  63380. {
  63381. return Colour (colours [(index << 1) + 1]);
  63382. }
  63383. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63384. {
  63385. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63386. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63387. if (integerPos <= 0 || colours.size() <= 2)
  63388. return getColour (0);
  63389. int i = colours.size() - 2;
  63390. while (integerPos < (int) colours.getUnchecked(i))
  63391. i -= 2;
  63392. if (i >= colours.size() - 2)
  63393. return Colour (colours.getUnchecked(i));
  63394. const int pos1 = colours.getUnchecked (i);
  63395. const Colour col1 (colours.getUnchecked (i + 1));
  63396. const int pos2 = colours.getUnchecked (i + 2);
  63397. const Colour col2 (colours.getUnchecked (i + 3));
  63398. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63399. }
  63400. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63401. {
  63402. #ifdef JUCE_DEBUG
  63403. // trying to use the object without setting its co-ordinates? Have a careful read of
  63404. // the comments for the constructors.
  63405. jassert (x1 != 987654.0f);
  63406. #endif
  63407. const int numColours = colours.size() >> 1;
  63408. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63409. transform.transformPoint (tx1, ty1);
  63410. transform.transformPoint (tx2, ty2);
  63411. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63412. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63413. lookupTable.malloc (numEntries);
  63414. if (numColours >= 2)
  63415. {
  63416. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63417. PixelARGB pix1 (colours.getUnchecked (1));
  63418. pix1.premultiply();
  63419. int index = 0;
  63420. for (int j = 2; j < colours.size(); j += 2)
  63421. {
  63422. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63423. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63424. pix2.premultiply();
  63425. for (int i = 0; i < numToDo; ++i)
  63426. {
  63427. jassert (index >= 0 && index < numEntries);
  63428. lookupTable[index] = pix1;
  63429. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63430. ++index;
  63431. }
  63432. pix1 = pix2;
  63433. }
  63434. while (index < numEntries)
  63435. lookupTable [index++] = pix1;
  63436. }
  63437. else
  63438. {
  63439. jassertfalse // no colours specified!
  63440. }
  63441. return numEntries;
  63442. }
  63443. bool ColourGradient::isOpaque() const throw()
  63444. {
  63445. for (int i = 1; i < colours.size(); i += 2)
  63446. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63447. return false;
  63448. return true;
  63449. }
  63450. bool ColourGradient::isInvisible() const throw()
  63451. {
  63452. for (int i = 1; i < colours.size(); i += 2)
  63453. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63454. return false;
  63455. return true;
  63456. }
  63457. END_JUCE_NAMESPACE
  63458. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63459. /*** Start of inlined file: juce_Colours.cpp ***/
  63460. BEGIN_JUCE_NAMESPACE
  63461. const Colour Colours::transparentBlack (0);
  63462. const Colour Colours::transparentWhite (0x00ffffff);
  63463. const Colour Colours::aliceblue (0xfff0f8ff);
  63464. const Colour Colours::antiquewhite (0xfffaebd7);
  63465. const Colour Colours::aqua (0xff00ffff);
  63466. const Colour Colours::aquamarine (0xff7fffd4);
  63467. const Colour Colours::azure (0xfff0ffff);
  63468. const Colour Colours::beige (0xfff5f5dc);
  63469. const Colour Colours::bisque (0xffffe4c4);
  63470. const Colour Colours::black (0xff000000);
  63471. const Colour Colours::blanchedalmond (0xffffebcd);
  63472. const Colour Colours::blue (0xff0000ff);
  63473. const Colour Colours::blueviolet (0xff8a2be2);
  63474. const Colour Colours::brown (0xffa52a2a);
  63475. const Colour Colours::burlywood (0xffdeb887);
  63476. const Colour Colours::cadetblue (0xff5f9ea0);
  63477. const Colour Colours::chartreuse (0xff7fff00);
  63478. const Colour Colours::chocolate (0xffd2691e);
  63479. const Colour Colours::coral (0xffff7f50);
  63480. const Colour Colours::cornflowerblue (0xff6495ed);
  63481. const Colour Colours::cornsilk (0xfffff8dc);
  63482. const Colour Colours::crimson (0xffdc143c);
  63483. const Colour Colours::cyan (0xff00ffff);
  63484. const Colour Colours::darkblue (0xff00008b);
  63485. const Colour Colours::darkcyan (0xff008b8b);
  63486. const Colour Colours::darkgoldenrod (0xffb8860b);
  63487. const Colour Colours::darkgrey (0xff555555);
  63488. const Colour Colours::darkgreen (0xff006400);
  63489. const Colour Colours::darkkhaki (0xffbdb76b);
  63490. const Colour Colours::darkmagenta (0xff8b008b);
  63491. const Colour Colours::darkolivegreen (0xff556b2f);
  63492. const Colour Colours::darkorange (0xffff8c00);
  63493. const Colour Colours::darkorchid (0xff9932cc);
  63494. const Colour Colours::darkred (0xff8b0000);
  63495. const Colour Colours::darksalmon (0xffe9967a);
  63496. const Colour Colours::darkseagreen (0xff8fbc8f);
  63497. const Colour Colours::darkslateblue (0xff483d8b);
  63498. const Colour Colours::darkslategrey (0xff2f4f4f);
  63499. const Colour Colours::darkturquoise (0xff00ced1);
  63500. const Colour Colours::darkviolet (0xff9400d3);
  63501. const Colour Colours::deeppink (0xffff1493);
  63502. const Colour Colours::deepskyblue (0xff00bfff);
  63503. const Colour Colours::dimgrey (0xff696969);
  63504. const Colour Colours::dodgerblue (0xff1e90ff);
  63505. const Colour Colours::firebrick (0xffb22222);
  63506. const Colour Colours::floralwhite (0xfffffaf0);
  63507. const Colour Colours::forestgreen (0xff228b22);
  63508. const Colour Colours::fuchsia (0xffff00ff);
  63509. const Colour Colours::gainsboro (0xffdcdcdc);
  63510. const Colour Colours::gold (0xffffd700);
  63511. const Colour Colours::goldenrod (0xffdaa520);
  63512. const Colour Colours::grey (0xff808080);
  63513. const Colour Colours::green (0xff008000);
  63514. const Colour Colours::greenyellow (0xffadff2f);
  63515. const Colour Colours::honeydew (0xfff0fff0);
  63516. const Colour Colours::hotpink (0xffff69b4);
  63517. const Colour Colours::indianred (0xffcd5c5c);
  63518. const Colour Colours::indigo (0xff4b0082);
  63519. const Colour Colours::ivory (0xfffffff0);
  63520. const Colour Colours::khaki (0xfff0e68c);
  63521. const Colour Colours::lavender (0xffe6e6fa);
  63522. const Colour Colours::lavenderblush (0xfffff0f5);
  63523. const Colour Colours::lemonchiffon (0xfffffacd);
  63524. const Colour Colours::lightblue (0xffadd8e6);
  63525. const Colour Colours::lightcoral (0xfff08080);
  63526. const Colour Colours::lightcyan (0xffe0ffff);
  63527. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63528. const Colour Colours::lightgreen (0xff90ee90);
  63529. const Colour Colours::lightgrey (0xffd3d3d3);
  63530. const Colour Colours::lightpink (0xffffb6c1);
  63531. const Colour Colours::lightsalmon (0xffffa07a);
  63532. const Colour Colours::lightseagreen (0xff20b2aa);
  63533. const Colour Colours::lightskyblue (0xff87cefa);
  63534. const Colour Colours::lightslategrey (0xff778899);
  63535. const Colour Colours::lightsteelblue (0xffb0c4de);
  63536. const Colour Colours::lightyellow (0xffffffe0);
  63537. const Colour Colours::lime (0xff00ff00);
  63538. const Colour Colours::limegreen (0xff32cd32);
  63539. const Colour Colours::linen (0xfffaf0e6);
  63540. const Colour Colours::magenta (0xffff00ff);
  63541. const Colour Colours::maroon (0xff800000);
  63542. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63543. const Colour Colours::mediumblue (0xff0000cd);
  63544. const Colour Colours::mediumorchid (0xffba55d3);
  63545. const Colour Colours::mediumpurple (0xff9370db);
  63546. const Colour Colours::mediumseagreen (0xff3cb371);
  63547. const Colour Colours::mediumslateblue (0xff7b68ee);
  63548. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63549. const Colour Colours::mediumturquoise (0xff48d1cc);
  63550. const Colour Colours::mediumvioletred (0xffc71585);
  63551. const Colour Colours::midnightblue (0xff191970);
  63552. const Colour Colours::mintcream (0xfff5fffa);
  63553. const Colour Colours::mistyrose (0xffffe4e1);
  63554. const Colour Colours::navajowhite (0xffffdead);
  63555. const Colour Colours::navy (0xff000080);
  63556. const Colour Colours::oldlace (0xfffdf5e6);
  63557. const Colour Colours::olive (0xff808000);
  63558. const Colour Colours::olivedrab (0xff6b8e23);
  63559. const Colour Colours::orange (0xffffa500);
  63560. const Colour Colours::orangered (0xffff4500);
  63561. const Colour Colours::orchid (0xffda70d6);
  63562. const Colour Colours::palegoldenrod (0xffeee8aa);
  63563. const Colour Colours::palegreen (0xff98fb98);
  63564. const Colour Colours::paleturquoise (0xffafeeee);
  63565. const Colour Colours::palevioletred (0xffdb7093);
  63566. const Colour Colours::papayawhip (0xffffefd5);
  63567. const Colour Colours::peachpuff (0xffffdab9);
  63568. const Colour Colours::peru (0xffcd853f);
  63569. const Colour Colours::pink (0xffffc0cb);
  63570. const Colour Colours::plum (0xffdda0dd);
  63571. const Colour Colours::powderblue (0xffb0e0e6);
  63572. const Colour Colours::purple (0xff800080);
  63573. const Colour Colours::red (0xffff0000);
  63574. const Colour Colours::rosybrown (0xffbc8f8f);
  63575. const Colour Colours::royalblue (0xff4169e1);
  63576. const Colour Colours::saddlebrown (0xff8b4513);
  63577. const Colour Colours::salmon (0xfffa8072);
  63578. const Colour Colours::sandybrown (0xfff4a460);
  63579. const Colour Colours::seagreen (0xff2e8b57);
  63580. const Colour Colours::seashell (0xfffff5ee);
  63581. const Colour Colours::sienna (0xffa0522d);
  63582. const Colour Colours::silver (0xffc0c0c0);
  63583. const Colour Colours::skyblue (0xff87ceeb);
  63584. const Colour Colours::slateblue (0xff6a5acd);
  63585. const Colour Colours::slategrey (0xff708090);
  63586. const Colour Colours::snow (0xfffffafa);
  63587. const Colour Colours::springgreen (0xff00ff7f);
  63588. const Colour Colours::steelblue (0xff4682b4);
  63589. const Colour Colours::tan (0xffd2b48c);
  63590. const Colour Colours::teal (0xff008080);
  63591. const Colour Colours::thistle (0xffd8bfd8);
  63592. const Colour Colours::tomato (0xffff6347);
  63593. const Colour Colours::turquoise (0xff40e0d0);
  63594. const Colour Colours::violet (0xffee82ee);
  63595. const Colour Colours::wheat (0xfff5deb3);
  63596. const Colour Colours::white (0xffffffff);
  63597. const Colour Colours::whitesmoke (0xfff5f5f5);
  63598. const Colour Colours::yellow (0xffffff00);
  63599. const Colour Colours::yellowgreen (0xff9acd32);
  63600. const Colour Colours::findColourForName (const String& colourName,
  63601. const Colour& defaultColour)
  63602. {
  63603. static const int presets[] =
  63604. {
  63605. // (first value is the string's hashcode, second is ARGB)
  63606. 0x05978fff, 0xff000000, /* black */
  63607. 0x06bdcc29, 0xffffffff, /* white */
  63608. 0x002e305a, 0xff0000ff, /* blue */
  63609. 0x00308adf, 0xff808080, /* grey */
  63610. 0x05e0cf03, 0xff008000, /* green */
  63611. 0x0001b891, 0xffff0000, /* red */
  63612. 0xd43c6474, 0xffffff00, /* yellow */
  63613. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63614. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63615. 0x002dcebc, 0xff00ffff, /* aqua */
  63616. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63617. 0x0590228f, 0xfff0ffff, /* azure */
  63618. 0x05947fe4, 0xfff5f5dc, /* beige */
  63619. 0xad388e35, 0xffffe4c4, /* bisque */
  63620. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63621. 0x39129959, 0xff8a2be2, /* blueviolet */
  63622. 0x059a8136, 0xffa52a2a, /* brown */
  63623. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63624. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63625. 0x6b748956, 0xff7fff00, /* chartreuse */
  63626. 0x2903623c, 0xffd2691e, /* chocolate */
  63627. 0x05a74431, 0xffff7f50, /* coral */
  63628. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63629. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63630. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63631. 0x002ed323, 0xff00ffff, /* cyan */
  63632. 0x67cc74d0, 0xff00008b, /* darkblue */
  63633. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63634. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63635. 0x67cecf55, 0xff555555, /* darkgrey */
  63636. 0x920b194d, 0xff006400, /* darkgreen */
  63637. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63638. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63639. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63640. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63641. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63642. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63643. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63644. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63645. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63646. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63647. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63648. 0xc8769375, 0xff9400d3, /* darkviolet */
  63649. 0x25832862, 0xffff1493, /* deeppink */
  63650. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63651. 0x634c8b67, 0xff696969, /* dimgrey */
  63652. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63653. 0xef19e3cb, 0xffb22222, /* firebrick */
  63654. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63655. 0xd086fd06, 0xff228b22, /* forestgreen */
  63656. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63657. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63658. 0x00308060, 0xffffd700, /* gold */
  63659. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63660. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63661. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63662. 0x41892743, 0xffff69b4, /* hotpink */
  63663. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63664. 0xb969fed2, 0xff4b0082, /* indigo */
  63665. 0x05fef6a9, 0xfffffff0, /* ivory */
  63666. 0x06149302, 0xfff0e68c, /* khaki */
  63667. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63668. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63669. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63670. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63671. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63672. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63673. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63674. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63675. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63676. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63677. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63678. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63679. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63680. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63681. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63682. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63683. 0x0032afd5, 0xff00ff00, /* lime */
  63684. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63685. 0x06234efa, 0xfffaf0e6, /* linen */
  63686. 0x316858a9, 0xffff00ff, /* magenta */
  63687. 0xbf8ca470, 0xff800000, /* maroon */
  63688. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63689. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63690. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63691. 0x07556b71, 0xff9370db, /* mediumpurple */
  63692. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63693. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63694. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63695. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63696. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63697. 0x168eb32a, 0xff191970, /* midnightblue */
  63698. 0x4306b960, 0xfff5fffa, /* mintcream */
  63699. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63700. 0xe97218a6, 0xffffdead, /* navajowhite */
  63701. 0x00337bb6, 0xff000080, /* navy */
  63702. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63703. 0x064ee1db, 0xff808000, /* olive */
  63704. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63705. 0xc3de262e, 0xffffa500, /* orange */
  63706. 0x58bebba3, 0xffff4500, /* orangered */
  63707. 0xc3def8a3, 0xffda70d6, /* orchid */
  63708. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63709. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63710. 0x74022737, 0xffafeeee, /* paleturquoise */
  63711. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63712. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63713. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63714. 0x003472f8, 0xffcd853f, /* peru */
  63715. 0x00348176, 0xffffc0cb, /* pink */
  63716. 0x00348d94, 0xffdda0dd, /* plum */
  63717. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63718. 0xc5c507bc, 0xff800080, /* purple */
  63719. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63720. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63721. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63722. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63723. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63724. 0x34636c14, 0xff2e8b57, /* seagreen */
  63725. 0x3507fb41, 0xfffff5ee, /* seashell */
  63726. 0xca348772, 0xffa0522d, /* sienna */
  63727. 0xca37d30d, 0xffc0c0c0, /* silver */
  63728. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63729. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63730. 0x44ab37f8, 0xff708090, /* slategrey */
  63731. 0x0035f183, 0xfffffafa, /* snow */
  63732. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63733. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63734. 0x0001bfa1, 0xffd2b48c, /* tan */
  63735. 0x0036425c, 0xff008080, /* teal */
  63736. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63737. 0xcc41600a, 0xffff6347, /* tomato */
  63738. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63739. 0xcf57947f, 0xffee82ee, /* violet */
  63740. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63741. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63742. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63743. };
  63744. const int hash = colourName.trim().toLowerCase().hashCode();
  63745. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63746. if (presets [i] == hash)
  63747. return Colour (presets [i + 1]);
  63748. return defaultColour;
  63749. }
  63750. END_JUCE_NAMESPACE
  63751. /*** End of inlined file: juce_Colours.cpp ***/
  63752. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63753. BEGIN_JUCE_NAMESPACE
  63754. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63755. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63756. const Path& path, const AffineTransform& transform)
  63757. : bounds (bounds_),
  63758. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63759. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63760. needToCheckEmptinesss (true)
  63761. {
  63762. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63763. int* t = table;
  63764. for (int i = bounds.getHeight(); --i >= 0;)
  63765. {
  63766. *t = 0;
  63767. t += lineStrideElements;
  63768. }
  63769. const int topLimit = bounds.getY() << 8;
  63770. const int heightLimit = bounds.getHeight() << 8;
  63771. const int leftLimit = bounds.getX() << 8;
  63772. const int rightLimit = bounds.getRight() << 8;
  63773. PathFlatteningIterator iter (path, transform);
  63774. while (iter.next())
  63775. {
  63776. int y1 = roundToInt (iter.y1 * 256.0f);
  63777. int y2 = roundToInt (iter.y2 * 256.0f);
  63778. if (y1 != y2)
  63779. {
  63780. y1 -= topLimit;
  63781. y2 -= topLimit;
  63782. const int startY = y1;
  63783. int direction = -1;
  63784. if (y1 > y2)
  63785. {
  63786. swapVariables (y1, y2);
  63787. direction = 1;
  63788. }
  63789. if (y1 < 0)
  63790. y1 = 0;
  63791. if (y2 > heightLimit)
  63792. y2 = heightLimit;
  63793. if (y1 < y2)
  63794. {
  63795. const double startX = 256.0f * iter.x1;
  63796. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63797. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63798. do
  63799. {
  63800. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63801. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63802. if (x < leftLimit)
  63803. x = leftLimit;
  63804. else if (x >= rightLimit)
  63805. x = rightLimit - 1;
  63806. addEdgePoint (x, y1 >> 8, direction * step);
  63807. y1 += step;
  63808. }
  63809. while (y1 < y2);
  63810. }
  63811. }
  63812. }
  63813. sanitiseLevels (path.isUsingNonZeroWinding());
  63814. }
  63815. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63816. : bounds (rectangleToAdd),
  63817. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63818. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63819. needToCheckEmptinesss (true)
  63820. {
  63821. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63822. table[0] = 0;
  63823. const int x1 = rectangleToAdd.getX() << 8;
  63824. const int x2 = rectangleToAdd.getRight() << 8;
  63825. int* t = table;
  63826. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63827. {
  63828. t[0] = 2;
  63829. t[1] = x1;
  63830. t[2] = 255;
  63831. t[3] = x2;
  63832. t[4] = 0;
  63833. t += lineStrideElements;
  63834. }
  63835. }
  63836. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63837. : bounds (rectanglesToAdd.getBounds()),
  63838. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63839. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63840. needToCheckEmptinesss (true)
  63841. {
  63842. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63843. int* t = table;
  63844. for (int i = bounds.getHeight(); --i >= 0;)
  63845. {
  63846. *t = 0;
  63847. t += lineStrideElements;
  63848. }
  63849. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63850. {
  63851. const Rectangle<int>* const r = iter.getRectangle();
  63852. const int x1 = r->getX() << 8;
  63853. const int x2 = r->getRight() << 8;
  63854. int y = r->getY() - bounds.getY();
  63855. for (int j = r->getHeight(); --j >= 0;)
  63856. {
  63857. addEdgePoint (x1, y, 255);
  63858. addEdgePoint (x2, y, -255);
  63859. ++y;
  63860. }
  63861. }
  63862. sanitiseLevels (true);
  63863. }
  63864. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63865. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63866. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63867. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63868. needToCheckEmptinesss (true)
  63869. {
  63870. jassert (w > 0 && h > 0);
  63871. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63872. table[0] = 0;
  63873. const int x1 = roundToInt (x * 256.0f);
  63874. const int x2 = roundToInt ((x + w) * 256.0f);
  63875. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63876. jassert (y1 < 256);
  63877. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63878. if (x2 <= x1 || y2 <= y1)
  63879. {
  63880. bounds.setHeight (0);
  63881. return;
  63882. }
  63883. int lineY = 0;
  63884. int* t = table;
  63885. if ((y1 >> 8) == (y2 >> 8))
  63886. {
  63887. t[0] = 2;
  63888. t[1] = x1;
  63889. t[2] = y2 - y1;
  63890. t[3] = x2;
  63891. t[4] = 0;
  63892. ++lineY;
  63893. t += lineStrideElements;
  63894. }
  63895. else
  63896. {
  63897. t[0] = 2;
  63898. t[1] = x1;
  63899. t[2] = 255 - (y1 & 255);
  63900. t[3] = x2;
  63901. t[4] = 0;
  63902. ++lineY;
  63903. t += lineStrideElements;
  63904. while (lineY < (y2 >> 8))
  63905. {
  63906. t[0] = 2;
  63907. t[1] = x1;
  63908. t[2] = 255;
  63909. t[3] = x2;
  63910. t[4] = 0;
  63911. ++lineY;
  63912. t += lineStrideElements;
  63913. }
  63914. jassert (lineY < bounds.getHeight());
  63915. t[0] = 2;
  63916. t[1] = x1;
  63917. t[2] = y2 & 255;
  63918. t[3] = x2;
  63919. t[4] = 0;
  63920. ++lineY;
  63921. t += lineStrideElements;
  63922. }
  63923. while (lineY < bounds.getHeight())
  63924. {
  63925. t[0] = 0;
  63926. t += lineStrideElements;
  63927. ++lineY;
  63928. }
  63929. }
  63930. EdgeTable::EdgeTable (const EdgeTable& other)
  63931. : table (0)
  63932. {
  63933. operator= (other);
  63934. }
  63935. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63936. {
  63937. bounds = other.bounds;
  63938. maxEdgesPerLine = other.maxEdgesPerLine;
  63939. lineStrideElements = other.lineStrideElements;
  63940. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63941. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63942. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63943. return *this;
  63944. }
  63945. EdgeTable::~EdgeTable()
  63946. {
  63947. }
  63948. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63949. {
  63950. while (--numLines >= 0)
  63951. {
  63952. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63953. src += srcLineStride;
  63954. dest += destLineStride;
  63955. }
  63956. }
  63957. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63958. {
  63959. // Convert the table from relative windings to absolute levels..
  63960. int* lineStart = table;
  63961. for (int i = bounds.getHeight(); --i >= 0;)
  63962. {
  63963. int* line = lineStart;
  63964. lineStart += lineStrideElements;
  63965. int num = *line;
  63966. if (num == 0)
  63967. continue;
  63968. int level = 0;
  63969. if (useNonZeroWinding)
  63970. {
  63971. while (--num > 0)
  63972. {
  63973. line += 2;
  63974. level += *line;
  63975. int corrected = abs (level);
  63976. if (corrected >> 8)
  63977. corrected = 255;
  63978. *line = corrected;
  63979. }
  63980. }
  63981. else
  63982. {
  63983. while (--num > 0)
  63984. {
  63985. line += 2;
  63986. level += *line;
  63987. int corrected = abs (level);
  63988. if (corrected >> 8)
  63989. {
  63990. corrected &= 511;
  63991. if (corrected >> 8)
  63992. corrected = 511 - corrected;
  63993. }
  63994. *line = corrected;
  63995. }
  63996. }
  63997. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  63998. }
  63999. }
  64000. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64001. {
  64002. if (newNumEdgesPerLine != maxEdgesPerLine)
  64003. {
  64004. maxEdgesPerLine = newNumEdgesPerLine;
  64005. jassert (bounds.getHeight() > 0);
  64006. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64007. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64008. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64009. table.swapWith (newTable);
  64010. lineStrideElements = newLineStrideElements;
  64011. }
  64012. }
  64013. void EdgeTable::optimiseTable() throw()
  64014. {
  64015. int maxLineElements = 0;
  64016. for (int i = bounds.getHeight(); --i >= 0;)
  64017. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64018. remapTableForNumEdges (maxLineElements);
  64019. }
  64020. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64021. {
  64022. jassert (y >= 0 && y < bounds.getHeight());
  64023. int* line = table + lineStrideElements * y;
  64024. const int numPoints = line[0];
  64025. int n = numPoints << 1;
  64026. if (n > 0)
  64027. {
  64028. while (n > 0)
  64029. {
  64030. const int cx = line [n - 1];
  64031. if (cx <= x)
  64032. {
  64033. if (cx == x)
  64034. {
  64035. line [n] += winding;
  64036. return;
  64037. }
  64038. break;
  64039. }
  64040. n -= 2;
  64041. }
  64042. if (numPoints >= maxEdgesPerLine)
  64043. {
  64044. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64045. jassert (numPoints < maxEdgesPerLine);
  64046. line = table + lineStrideElements * y;
  64047. }
  64048. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64049. }
  64050. line [n + 1] = x;
  64051. line [n + 2] = winding;
  64052. line[0]++;
  64053. }
  64054. void EdgeTable::translate (float dx, int dy) throw()
  64055. {
  64056. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64057. int* lineStart = table;
  64058. const int intDx = (int) (dx * 256.0f);
  64059. for (int i = bounds.getHeight(); --i >= 0;)
  64060. {
  64061. int* line = lineStart;
  64062. lineStart += lineStrideElements;
  64063. int num = *line++;
  64064. while (--num >= 0)
  64065. {
  64066. *line += intDx;
  64067. line += 2;
  64068. }
  64069. }
  64070. }
  64071. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64072. {
  64073. jassert (y >= 0 && y < bounds.getHeight());
  64074. int* dest = table + lineStrideElements * y;
  64075. if (dest[0] == 0)
  64076. return;
  64077. int otherNumPoints = *otherLine;
  64078. if (otherNumPoints == 0)
  64079. {
  64080. *dest = 0;
  64081. return;
  64082. }
  64083. const int right = bounds.getRight() << 8;
  64084. // optimise for the common case where our line lies entirely within a
  64085. // single pair of points, as happens when clipping to a simple rect.
  64086. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64087. {
  64088. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64089. return;
  64090. }
  64091. ++otherLine;
  64092. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64093. int* temp = (int*) alloca (lineSizeBytes);
  64094. memcpy (temp, dest, lineSizeBytes);
  64095. const int* src1 = temp;
  64096. int srcNum1 = *src1++;
  64097. int x1 = *src1++;
  64098. const int* src2 = otherLine;
  64099. int srcNum2 = otherNumPoints;
  64100. int x2 = *src2++;
  64101. int destIndex = 0, destTotal = 0;
  64102. int level1 = 0, level2 = 0;
  64103. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64104. while (srcNum1 > 0 && srcNum2 > 0)
  64105. {
  64106. int nextX;
  64107. if (x1 < x2)
  64108. {
  64109. nextX = x1;
  64110. level1 = *src1++;
  64111. x1 = *src1++;
  64112. --srcNum1;
  64113. }
  64114. else if (x1 == x2)
  64115. {
  64116. nextX = x1;
  64117. level1 = *src1++;
  64118. level2 = *src2++;
  64119. x1 = *src1++;
  64120. x2 = *src2++;
  64121. --srcNum1;
  64122. --srcNum2;
  64123. }
  64124. else
  64125. {
  64126. nextX = x2;
  64127. level2 = *src2++;
  64128. x2 = *src2++;
  64129. --srcNum2;
  64130. }
  64131. if (nextX > lastX)
  64132. {
  64133. if (nextX >= right)
  64134. break;
  64135. lastX = nextX;
  64136. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64137. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64138. if (nextLevel != lastLevel)
  64139. {
  64140. if (destTotal >= maxEdgesPerLine)
  64141. {
  64142. dest[0] = destTotal;
  64143. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64144. dest = table + lineStrideElements * y;
  64145. }
  64146. ++destTotal;
  64147. lastLevel = nextLevel;
  64148. dest[++destIndex] = nextX;
  64149. dest[++destIndex] = nextLevel;
  64150. }
  64151. }
  64152. }
  64153. if (lastLevel > 0)
  64154. {
  64155. if (destTotal >= maxEdgesPerLine)
  64156. {
  64157. dest[0] = destTotal;
  64158. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64159. dest = table + lineStrideElements * y;
  64160. }
  64161. ++destTotal;
  64162. dest[++destIndex] = right;
  64163. dest[++destIndex] = 0;
  64164. }
  64165. dest[0] = destTotal;
  64166. #if JUCE_DEBUG
  64167. int last = std::numeric_limits<int>::min();
  64168. for (int i = 0; i < dest[0]; ++i)
  64169. {
  64170. jassert (dest[i * 2 + 1] > last);
  64171. last = dest[i * 2 + 1];
  64172. }
  64173. jassert (dest [dest[0] * 2] == 0);
  64174. #endif
  64175. }
  64176. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64177. {
  64178. int* lastItem = dest + (dest[0] * 2 - 1);
  64179. if (x2 < lastItem[0])
  64180. {
  64181. if (x2 <= dest[1])
  64182. {
  64183. dest[0] = 0;
  64184. return;
  64185. }
  64186. while (x2 < lastItem[-2])
  64187. {
  64188. --(dest[0]);
  64189. lastItem -= 2;
  64190. }
  64191. lastItem[0] = x2;
  64192. lastItem[1] = 0;
  64193. }
  64194. if (x1 > dest[1])
  64195. {
  64196. while (lastItem[0] > x1)
  64197. lastItem -= 2;
  64198. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64199. if (itemsRemoved > 0)
  64200. {
  64201. dest[0] -= itemsRemoved;
  64202. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64203. }
  64204. dest[1] = x1;
  64205. }
  64206. }
  64207. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64208. {
  64209. const Rectangle<int> clipped (r.getIntersection (bounds));
  64210. if (clipped.isEmpty())
  64211. {
  64212. needToCheckEmptinesss = false;
  64213. bounds.setHeight (0);
  64214. }
  64215. else
  64216. {
  64217. const int top = clipped.getY() - bounds.getY();
  64218. const int bottom = clipped.getBottom() - bounds.getY();
  64219. if (bottom < bounds.getHeight())
  64220. bounds.setHeight (bottom);
  64221. if (clipped.getRight() < bounds.getRight())
  64222. bounds.setRight (clipped.getRight());
  64223. for (int i = top; --i >= 0;)
  64224. table [lineStrideElements * i] = 0;
  64225. if (clipped.getX() > bounds.getX())
  64226. {
  64227. const int x1 = clipped.getX() << 8;
  64228. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64229. int* line = table + lineStrideElements * top;
  64230. for (int i = bottom - top; --i >= 0;)
  64231. {
  64232. if (line[0] != 0)
  64233. clipEdgeTableLineToRange (line, x1, x2);
  64234. line += lineStrideElements;
  64235. }
  64236. }
  64237. needToCheckEmptinesss = true;
  64238. }
  64239. }
  64240. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64241. {
  64242. const Rectangle<int> clipped (r.getIntersection (bounds));
  64243. if (! clipped.isEmpty())
  64244. {
  64245. const int top = clipped.getY() - bounds.getY();
  64246. const int bottom = clipped.getBottom() - bounds.getY();
  64247. //XXX optimise here by shortening the table if it fills top or bottom
  64248. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64249. clipped.getX() << 8, 0,
  64250. clipped.getRight() << 8, 255,
  64251. std::numeric_limits<int>::max(), 0 };
  64252. for (int i = top; i < bottom; ++i)
  64253. intersectWithEdgeTableLine (i, rectLine);
  64254. needToCheckEmptinesss = true;
  64255. }
  64256. }
  64257. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64258. {
  64259. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64260. if (clipped.isEmpty())
  64261. {
  64262. needToCheckEmptinesss = false;
  64263. bounds.setHeight (0);
  64264. }
  64265. else
  64266. {
  64267. const int top = clipped.getY() - bounds.getY();
  64268. const int bottom = clipped.getBottom() - bounds.getY();
  64269. if (bottom < bounds.getHeight())
  64270. bounds.setHeight (bottom);
  64271. if (clipped.getRight() < bounds.getRight())
  64272. bounds.setRight (clipped.getRight());
  64273. int i = 0;
  64274. for (i = top; --i >= 0;)
  64275. table [lineStrideElements * i] = 0;
  64276. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64277. for (i = top; i < bottom; ++i)
  64278. {
  64279. intersectWithEdgeTableLine (i, otherLine);
  64280. otherLine += other.lineStrideElements;
  64281. }
  64282. needToCheckEmptinesss = true;
  64283. }
  64284. }
  64285. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64286. {
  64287. y -= bounds.getY();
  64288. if (y < 0 || y >= bounds.getHeight())
  64289. return;
  64290. needToCheckEmptinesss = true;
  64291. if (numPixels <= 0)
  64292. {
  64293. table [lineStrideElements * y] = 0;
  64294. return;
  64295. }
  64296. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64297. int destIndex = 0, lastLevel = 0;
  64298. while (--numPixels >= 0)
  64299. {
  64300. const int alpha = *mask;
  64301. mask += maskStride;
  64302. if (alpha != lastLevel)
  64303. {
  64304. tempLine[++destIndex] = (x << 8);
  64305. tempLine[++destIndex] = alpha;
  64306. lastLevel = alpha;
  64307. }
  64308. ++x;
  64309. }
  64310. if (lastLevel > 0)
  64311. {
  64312. tempLine[++destIndex] = (x << 8);
  64313. tempLine[++destIndex] = 0;
  64314. }
  64315. tempLine[0] = destIndex >> 1;
  64316. intersectWithEdgeTableLine (y, tempLine);
  64317. }
  64318. bool EdgeTable::isEmpty() throw()
  64319. {
  64320. if (needToCheckEmptinesss)
  64321. {
  64322. needToCheckEmptinesss = false;
  64323. int* t = table;
  64324. for (int i = bounds.getHeight(); --i >= 0;)
  64325. {
  64326. if (t[0] > 1)
  64327. return false;
  64328. t += lineStrideElements;
  64329. }
  64330. bounds.setHeight (0);
  64331. }
  64332. return bounds.getHeight() == 0;
  64333. }
  64334. END_JUCE_NAMESPACE
  64335. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64336. /*** Start of inlined file: juce_FillType.cpp ***/
  64337. BEGIN_JUCE_NAMESPACE
  64338. FillType::FillType() throw()
  64339. : colour (0xff000000), image (0)
  64340. {
  64341. }
  64342. FillType::FillType (const Colour& colour_) throw()
  64343. : colour (colour_), image (0)
  64344. {
  64345. }
  64346. FillType::FillType (const ColourGradient& gradient_) throw()
  64347. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64348. {
  64349. }
  64350. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64351. : colour (0xff000000), image (&image_), transform (transform_)
  64352. {
  64353. }
  64354. FillType::FillType (const FillType& other) throw()
  64355. : colour (other.colour),
  64356. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64357. image (other.image), transform (other.transform)
  64358. {
  64359. }
  64360. FillType& FillType::operator= (const FillType& other) throw()
  64361. {
  64362. if (this != &other)
  64363. {
  64364. colour = other.colour;
  64365. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64366. image = other.image;
  64367. transform = other.transform;
  64368. }
  64369. return *this;
  64370. }
  64371. FillType::~FillType() throw()
  64372. {
  64373. }
  64374. void FillType::setColour (const Colour& newColour) throw()
  64375. {
  64376. gradient = 0;
  64377. image = 0;
  64378. colour = newColour;
  64379. }
  64380. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64381. {
  64382. if (gradient != 0)
  64383. {
  64384. *gradient = newGradient;
  64385. }
  64386. else
  64387. {
  64388. image = 0;
  64389. gradient = new ColourGradient (newGradient);
  64390. colour = Colours::black;
  64391. }
  64392. }
  64393. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64394. {
  64395. gradient = 0;
  64396. image = &image_;
  64397. transform = transform_;
  64398. colour = Colours::black;
  64399. }
  64400. void FillType::setOpacity (const float newOpacity) throw()
  64401. {
  64402. colour = colour.withAlpha (newOpacity);
  64403. }
  64404. END_JUCE_NAMESPACE
  64405. /*** End of inlined file: juce_FillType.cpp ***/
  64406. /*** Start of inlined file: juce_Graphics.cpp ***/
  64407. BEGIN_JUCE_NAMESPACE
  64408. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64409. template <typename Type>
  64410. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64411. {
  64412. const int maxVal = 0x3fffffff;
  64413. return (int) x >= -maxVal && (int) x <= maxVal
  64414. && (int) y >= -maxVal && (int) y <= maxVal
  64415. && (int) w >= -maxVal && (int) w <= maxVal
  64416. && (int) h >= -maxVal && (int) h <= maxVal;
  64417. }
  64418. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64419. {
  64420. }
  64421. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64422. {
  64423. }
  64424. Graphics::Graphics (Image& imageToDrawOnto)
  64425. : context (imageToDrawOnto.createLowLevelContext()),
  64426. contextToDelete (context),
  64427. saveStatePending (false)
  64428. {
  64429. }
  64430. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64431. : context (internalContext),
  64432. saveStatePending (false)
  64433. {
  64434. }
  64435. Graphics::~Graphics()
  64436. {
  64437. }
  64438. void Graphics::resetToDefaultState()
  64439. {
  64440. saveStateIfPending();
  64441. context->setFill (FillType());
  64442. context->setFont (Font());
  64443. context->setInterpolationQuality (defaultQuality);
  64444. }
  64445. bool Graphics::isVectorDevice() const
  64446. {
  64447. return context->isVectorDevice();
  64448. }
  64449. bool Graphics::reduceClipRegion (const int x, const int y, const int w, const int h)
  64450. {
  64451. saveStateIfPending();
  64452. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64453. }
  64454. bool Graphics::reduceClipRegion (const RectangleList& clipRegion)
  64455. {
  64456. saveStateIfPending();
  64457. return context->clipToRectangleList (clipRegion);
  64458. }
  64459. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform)
  64460. {
  64461. saveStateIfPending();
  64462. context->clipToPath (path, transform);
  64463. return ! context->isClipEmpty();
  64464. }
  64465. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform)
  64466. {
  64467. saveStateIfPending();
  64468. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64469. return ! context->isClipEmpty();
  64470. }
  64471. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude)
  64472. {
  64473. saveStateIfPending();
  64474. context->excludeClipRectangle (rectangleToExclude);
  64475. }
  64476. bool Graphics::isClipEmpty() const
  64477. {
  64478. return context->isClipEmpty();
  64479. }
  64480. const Rectangle<int> Graphics::getClipBounds() const
  64481. {
  64482. return context->getClipBounds();
  64483. }
  64484. void Graphics::saveState()
  64485. {
  64486. saveStateIfPending();
  64487. saveStatePending = true;
  64488. }
  64489. void Graphics::restoreState()
  64490. {
  64491. if (saveStatePending)
  64492. saveStatePending = false;
  64493. else
  64494. context->restoreState();
  64495. }
  64496. void Graphics::saveStateIfPending()
  64497. {
  64498. if (saveStatePending)
  64499. {
  64500. saveStatePending = false;
  64501. context->saveState();
  64502. }
  64503. }
  64504. void Graphics::setOrigin (const int newOriginX, const int newOriginY)
  64505. {
  64506. saveStateIfPending();
  64507. context->setOrigin (newOriginX, newOriginY);
  64508. }
  64509. bool Graphics::clipRegionIntersects (const int x, const int y, const int w, const int h) const
  64510. {
  64511. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64512. }
  64513. void Graphics::setColour (const Colour& newColour)
  64514. {
  64515. saveStateIfPending();
  64516. context->setFill (newColour);
  64517. }
  64518. void Graphics::setOpacity (const float newOpacity)
  64519. {
  64520. saveStateIfPending();
  64521. context->setOpacity (newOpacity);
  64522. }
  64523. void Graphics::setGradientFill (const ColourGradient& gradient)
  64524. {
  64525. setFillType (gradient);
  64526. }
  64527. void Graphics::setTiledImageFill (const Image& imageToUse, const int anchorX, const int anchorY, const float opacity)
  64528. {
  64529. saveStateIfPending();
  64530. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64531. context->setOpacity (opacity);
  64532. }
  64533. void Graphics::setFillType (const FillType& newFill)
  64534. {
  64535. saveStateIfPending();
  64536. context->setFill (newFill);
  64537. }
  64538. void Graphics::setFont (const Font& newFont)
  64539. {
  64540. saveStateIfPending();
  64541. context->setFont (newFont);
  64542. }
  64543. void Graphics::setFont (const float newFontHeight, const int newFontStyleFlags)
  64544. {
  64545. saveStateIfPending();
  64546. Font f (context->getFont());
  64547. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64548. context->setFont (f);
  64549. }
  64550. void Graphics::drawSingleLineText (const String& text, const int startX, const int baselineY) const
  64551. {
  64552. if (text.isNotEmpty()
  64553. && startX < context->getClipBounds().getRight())
  64554. {
  64555. GlyphArrangement arr;
  64556. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64557. arr.draw (*this);
  64558. }
  64559. }
  64560. void Graphics::drawTextAsPath (const String& text, const AffineTransform& transform) const
  64561. {
  64562. if (text.isNotEmpty())
  64563. {
  64564. GlyphArrangement arr;
  64565. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64566. arr.draw (*this, transform);
  64567. }
  64568. }
  64569. void Graphics::drawMultiLineText (const String& text, const int startX, const int baselineY, const int maximumLineWidth) const
  64570. {
  64571. if (text.isNotEmpty()
  64572. && startX < context->getClipBounds().getRight())
  64573. {
  64574. GlyphArrangement arr;
  64575. arr.addJustifiedText (context->getFont(), text,
  64576. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64577. Justification::left);
  64578. arr.draw (*this);
  64579. }
  64580. }
  64581. void Graphics::drawText (const String& text,
  64582. const int x, const int y, const int width, const int height,
  64583. const Justification& justificationType,
  64584. const bool useEllipsesIfTooBig) const
  64585. {
  64586. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64587. {
  64588. GlyphArrangement arr;
  64589. arr.addCurtailedLineOfText (context->getFont(), text,
  64590. 0.0f, 0.0f, (float) width,
  64591. useEllipsesIfTooBig);
  64592. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64593. (float) x, (float) y, (float) width, (float) height,
  64594. justificationType);
  64595. arr.draw (*this);
  64596. }
  64597. }
  64598. void Graphics::drawFittedText (const String& text,
  64599. const int x, const int y, const int width, const int height,
  64600. const Justification& justification,
  64601. const int maximumNumberOfLines,
  64602. const float minimumHorizontalScale) const
  64603. {
  64604. if (text.isNotEmpty()
  64605. && width > 0 && height > 0
  64606. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64607. {
  64608. GlyphArrangement arr;
  64609. arr.addFittedText (context->getFont(), text,
  64610. (float) x, (float) y, (float) width, (float) height,
  64611. justification,
  64612. maximumNumberOfLines,
  64613. minimumHorizontalScale);
  64614. arr.draw (*this);
  64615. }
  64616. }
  64617. void Graphics::fillRect (int x, int y, int width, int height) const
  64618. {
  64619. // passing in a silly number can cause maths problems in rendering!
  64620. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64621. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64622. }
  64623. void Graphics::fillRect (const Rectangle<int>& r) const
  64624. {
  64625. context->fillRect (r, false);
  64626. }
  64627. void Graphics::fillRect (const float x, const float y, const float width, const float height) const
  64628. {
  64629. // passing in a silly number can cause maths problems in rendering!
  64630. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64631. Path p;
  64632. p.addRectangle (x, y, width, height);
  64633. fillPath (p);
  64634. }
  64635. void Graphics::setPixel (int x, int y) const
  64636. {
  64637. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64638. }
  64639. void Graphics::fillAll() const
  64640. {
  64641. fillRect (context->getClipBounds());
  64642. }
  64643. void Graphics::fillAll (const Colour& colourToUse) const
  64644. {
  64645. if (! colourToUse.isTransparent())
  64646. {
  64647. const Rectangle<int> clip (context->getClipBounds());
  64648. context->saveState();
  64649. context->setFill (colourToUse);
  64650. context->fillRect (clip, false);
  64651. context->restoreState();
  64652. }
  64653. }
  64654. void Graphics::fillPath (const Path& path, const AffineTransform& transform) const
  64655. {
  64656. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64657. context->fillPath (path, transform);
  64658. }
  64659. void Graphics::strokePath (const Path& path,
  64660. const PathStrokeType& strokeType,
  64661. const AffineTransform& transform) const
  64662. {
  64663. Path stroke;
  64664. strokeType.createStrokedPath (stroke, path, transform);
  64665. fillPath (stroke);
  64666. }
  64667. void Graphics::drawRect (const int x, const int y, const int width, const int height,
  64668. const int lineThickness) const
  64669. {
  64670. // passing in a silly number can cause maths problems in rendering!
  64671. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64672. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64673. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64674. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64675. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64676. }
  64677. void Graphics::drawRect (const float x, const float y, const float width, const float height, const float lineThickness) const
  64678. {
  64679. // passing in a silly number can cause maths problems in rendering!
  64680. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64681. Path p;
  64682. p.addRectangle (x, y, width, lineThickness);
  64683. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64684. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64685. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64686. fillPath (p);
  64687. }
  64688. void Graphics::drawRect (const Rectangle<int>& r, const int lineThickness) const
  64689. {
  64690. drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight(), lineThickness);
  64691. }
  64692. void Graphics::drawBevel (const int x, const int y, const int width, const int height,
  64693. const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
  64694. const bool useGradient, const bool sharpEdgeOnOutside) const
  64695. {
  64696. // passing in a silly number can cause maths problems in rendering!
  64697. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64698. if (clipRegionIntersects (x, y, width, height))
  64699. {
  64700. context->saveState();
  64701. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64702. const float ramp = oldOpacity / bevelThickness;
  64703. for (int i = bevelThickness; --i >= 0;)
  64704. {
  64705. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64706. : oldOpacity;
  64707. context->setFill (topLeftColour.withMultipliedAlpha (op));
  64708. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64709. context->setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
  64710. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64711. context->setFill (bottomRightColour.withMultipliedAlpha (op));
  64712. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64713. context->setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
  64714. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64715. }
  64716. context->restoreState();
  64717. }
  64718. }
  64719. void Graphics::fillEllipse (const float x, const float y, const float width, const float height) const
  64720. {
  64721. // passing in a silly number can cause maths problems in rendering!
  64722. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64723. Path p;
  64724. p.addEllipse (x, y, width, height);
  64725. fillPath (p);
  64726. }
  64727. void Graphics::drawEllipse (const float x, const float y, const float width, const float height,
  64728. const float lineThickness) const
  64729. {
  64730. // passing in a silly number can cause maths problems in rendering!
  64731. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64732. Path p;
  64733. p.addEllipse (x, y, width, height);
  64734. strokePath (p, PathStrokeType (lineThickness));
  64735. }
  64736. void Graphics::fillRoundedRectangle (const float x, const float y, const float width, const float height, const float cornerSize) const
  64737. {
  64738. // passing in a silly number can cause maths problems in rendering!
  64739. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64740. Path p;
  64741. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64742. fillPath (p);
  64743. }
  64744. void Graphics::fillRoundedRectangle (const Rectangle<float>& r, const float cornerSize) const
  64745. {
  64746. fillRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize);
  64747. }
  64748. void Graphics::drawRoundedRectangle (const float x, const float y, const float width, const float height,
  64749. const float cornerSize, const float lineThickness) const
  64750. {
  64751. // passing in a silly number can cause maths problems in rendering!
  64752. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64753. Path p;
  64754. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64755. strokePath (p, PathStrokeType (lineThickness));
  64756. }
  64757. void Graphics::drawRoundedRectangle (const Rectangle<float>& r, const float cornerSize, const float lineThickness) const
  64758. {
  64759. drawRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize, lineThickness);
  64760. }
  64761. void Graphics::drawArrow (const float startX, const float startY, const float endX, const float endY,
  64762. const float lineThickness, const float arrowheadWidth, const float arrowheadLength) const
  64763. {
  64764. Path p;
  64765. p.addArrow (startX, startY, endX, endY,
  64766. lineThickness, arrowheadWidth, arrowheadLength);
  64767. fillPath (p);
  64768. }
  64769. void Graphics::fillCheckerBoard (int x, int y, int width, int height,
  64770. const int checkWidth, const int checkHeight,
  64771. const Colour& colour1, const Colour& colour2) const
  64772. {
  64773. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64774. if (checkWidth > 0 && checkHeight > 0)
  64775. {
  64776. context->saveState();
  64777. if (colour1 == colour2)
  64778. {
  64779. context->setFill (colour1);
  64780. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64781. }
  64782. else
  64783. {
  64784. const Rectangle<int> clip (context->getClipBounds());
  64785. const int right = jmin (x + width, clip.getRight());
  64786. const int bottom = jmin (y + height, clip.getBottom());
  64787. int cy = 0;
  64788. while (y < bottom)
  64789. {
  64790. int cx = cy;
  64791. for (int xx = x; xx < right; xx += checkWidth)
  64792. {
  64793. context->setFill (((cx++ & 1) == 0) ? colour1 : colour2);
  64794. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64795. false);
  64796. }
  64797. ++cy;
  64798. y += checkHeight;
  64799. }
  64800. }
  64801. context->restoreState();
  64802. }
  64803. }
  64804. void Graphics::drawVerticalLine (const int x, float top, float bottom) const
  64805. {
  64806. context->drawVerticalLine (x, top, bottom);
  64807. }
  64808. void Graphics::drawHorizontalLine (const int y, float left, float right) const
  64809. {
  64810. context->drawHorizontalLine (y, left, right);
  64811. }
  64812. void Graphics::drawLine (float x1, float y1, float x2, float y2) const
  64813. {
  64814. context->drawLine (x1, y1, x2, y2);
  64815. }
  64816. void Graphics::drawLine (const float startX, const float startY,
  64817. const float endX, const float endY,
  64818. const float lineThickness) const
  64819. {
  64820. Path p;
  64821. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64822. fillPath (p);
  64823. }
  64824. void Graphics::drawLine (const Line& line) const
  64825. {
  64826. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64827. }
  64828. void Graphics::drawLine (const Line& line, const float lineThickness) const
  64829. {
  64830. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64831. }
  64832. void Graphics::drawDashedLine (const float startX, const float startY,
  64833. const float endX, const float endY,
  64834. const float* const dashLengths,
  64835. const int numDashLengths,
  64836. const float lineThickness) const
  64837. {
  64838. const double dx = endX - startX;
  64839. const double dy = endY - startY;
  64840. const double totalLen = juce_hypot (dx, dy);
  64841. if (totalLen >= 0.5)
  64842. {
  64843. const double onePixAlpha = 1.0 / totalLen;
  64844. double alpha = 0.0;
  64845. float x = startX;
  64846. float y = startY;
  64847. int n = 0;
  64848. while (alpha < 1.0f)
  64849. {
  64850. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64851. n = n % numDashLengths;
  64852. const float oldX = x;
  64853. const float oldY = y;
  64854. x = (float) (startX + dx * alpha);
  64855. y = (float) (startY + dy * alpha);
  64856. if ((n & 1) != 0)
  64857. {
  64858. if (lineThickness != 1.0f)
  64859. drawLine (oldX, oldY, x, y, lineThickness);
  64860. else
  64861. drawLine (oldX, oldY, x, y);
  64862. }
  64863. }
  64864. }
  64865. }
  64866. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality)
  64867. {
  64868. saveStateIfPending();
  64869. context->setInterpolationQuality (newQuality);
  64870. }
  64871. void Graphics::drawImageAt (const Image* const imageToDraw,
  64872. const int topLeftX, const int topLeftY,
  64873. const bool fillAlphaChannelWithCurrentBrush) const
  64874. {
  64875. if (imageToDraw != 0)
  64876. {
  64877. const int imageW = imageToDraw->getWidth();
  64878. const int imageH = imageToDraw->getHeight();
  64879. drawImage (imageToDraw,
  64880. topLeftX, topLeftY, imageW, imageH,
  64881. 0, 0, imageW, imageH,
  64882. fillAlphaChannelWithCurrentBrush);
  64883. }
  64884. }
  64885. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64886. const int destX, const int destY,
  64887. const int destW, const int destH,
  64888. const RectanglePlacement& placementWithinTarget,
  64889. const bool fillAlphaChannelWithCurrentBrush) const
  64890. {
  64891. // passing in a silly number can cause maths problems in rendering!
  64892. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64893. if (imageToDraw != 0)
  64894. {
  64895. const int imageW = imageToDraw->getWidth();
  64896. const int imageH = imageToDraw->getHeight();
  64897. if (imageW > 0 && imageH > 0)
  64898. {
  64899. double newX = 0.0, newY = 0.0;
  64900. double newW = imageW;
  64901. double newH = imageH;
  64902. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64903. destX, destY, destW, destH);
  64904. if (newW > 0 && newH > 0)
  64905. {
  64906. drawImage (imageToDraw,
  64907. roundToInt (newX), roundToInt (newY),
  64908. roundToInt (newW), roundToInt (newH),
  64909. 0, 0, imageW, imageH,
  64910. fillAlphaChannelWithCurrentBrush);
  64911. }
  64912. }
  64913. }
  64914. }
  64915. void Graphics::drawImage (const Image* const imageToDraw,
  64916. int dx, int dy, int dw, int dh,
  64917. int sx, int sy, int sw, int sh,
  64918. const bool fillAlphaChannelWithCurrentBrush) const
  64919. {
  64920. // passing in a silly number can cause maths problems in rendering!
  64921. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64922. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64923. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64924. {
  64925. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64926. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64927. .translated ((float) dx, (float) dy),
  64928. fillAlphaChannelWithCurrentBrush);
  64929. }
  64930. }
  64931. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64932. const Rectangle<int>& imageSubRegion,
  64933. const AffineTransform& transform,
  64934. const bool fillAlphaChannelWithCurrentBrush) const
  64935. {
  64936. if (imageToDraw != 0 && ! context->isClipEmpty())
  64937. {
  64938. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64939. if (fillAlphaChannelWithCurrentBrush)
  64940. {
  64941. context->saveState();
  64942. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64943. fillAll();
  64944. context->restoreState();
  64945. }
  64946. else
  64947. {
  64948. context->drawImage (*imageToDraw, srcClip, transform, false);
  64949. }
  64950. }
  64951. }
  64952. END_JUCE_NAMESPACE
  64953. /*** End of inlined file: juce_Graphics.cpp ***/
  64954. /*** Start of inlined file: juce_Justification.cpp ***/
  64955. BEGIN_JUCE_NAMESPACE
  64956. Justification::Justification (const Justification& other) throw()
  64957. : flags (other.flags)
  64958. {
  64959. }
  64960. Justification& Justification::operator= (const Justification& other) throw()
  64961. {
  64962. flags = other.flags;
  64963. return *this;
  64964. }
  64965. int Justification::getOnlyVerticalFlags() const throw()
  64966. {
  64967. return flags & (top | bottom | verticallyCentred);
  64968. }
  64969. int Justification::getOnlyHorizontalFlags() const throw()
  64970. {
  64971. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  64972. }
  64973. void Justification::applyToRectangle (int& x, int& y,
  64974. const int w, const int h,
  64975. const int spaceX, const int spaceY,
  64976. const int spaceW, const int spaceH) const throw()
  64977. {
  64978. if ((flags & horizontallyCentred) != 0)
  64979. {
  64980. x = spaceX + ((spaceW - w) >> 1);
  64981. }
  64982. else if ((flags & right) != 0)
  64983. {
  64984. x = spaceX + spaceW - w;
  64985. }
  64986. else
  64987. {
  64988. x = spaceX;
  64989. }
  64990. if ((flags & verticallyCentred) != 0)
  64991. {
  64992. y = spaceY + ((spaceH - h) >> 1);
  64993. }
  64994. else if ((flags & bottom) != 0)
  64995. {
  64996. y = spaceY + spaceH - h;
  64997. }
  64998. else
  64999. {
  65000. y = spaceY;
  65001. }
  65002. }
  65003. END_JUCE_NAMESPACE
  65004. /*** End of inlined file: juce_Justification.cpp ***/
  65005. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65006. BEGIN_JUCE_NAMESPACE
  65007. // this will throw an assertion if you try to draw something that's not
  65008. // possible in postscript
  65009. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65010. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65011. #define notPossibleInPostscriptAssert jassertfalse
  65012. #else
  65013. #define notPossibleInPostscriptAssert
  65014. #endif
  65015. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65016. const String& documentTitle,
  65017. const int totalWidth_,
  65018. const int totalHeight_)
  65019. : out (resultingPostScript),
  65020. totalWidth (totalWidth_),
  65021. totalHeight (totalHeight_),
  65022. needToClip (true)
  65023. {
  65024. stateStack.add (new SavedState());
  65025. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65026. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65027. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65028. "\n%%BoundingBox: 0 0 600 824"
  65029. "\n%%Pages: 0"
  65030. "\n%%Creator: Raw Material Software JUCE"
  65031. "\n%%Title: " << documentTitle <<
  65032. "\n%%CreationDate: none"
  65033. "\n%%LanguageLevel: 2"
  65034. "\n%%EndComments"
  65035. "\n%%BeginProlog"
  65036. "\n%%BeginResource: JRes"
  65037. "\n/bd {bind def} bind def"
  65038. "\n/c {setrgbcolor} bd"
  65039. "\n/m {moveto} bd"
  65040. "\n/l {lineto} bd"
  65041. "\n/rl {rlineto} bd"
  65042. "\n/ct {curveto} bd"
  65043. "\n/cp {closepath} bd"
  65044. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65045. "\n/doclip {initclip newpath} bd"
  65046. "\n/endclip {clip newpath} bd"
  65047. "\n%%EndResource"
  65048. "\n%%EndProlog"
  65049. "\n%%BeginSetup"
  65050. "\n%%EndSetup"
  65051. "\n%%Page: 1 1"
  65052. "\n%%BeginPageSetup"
  65053. "\n%%EndPageSetup\n\n"
  65054. << "40 800 translate\n"
  65055. << scale << ' ' << scale << " scale\n\n";
  65056. }
  65057. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65058. {
  65059. }
  65060. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65061. {
  65062. return true;
  65063. }
  65064. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65065. {
  65066. if (x != 0 || y != 0)
  65067. {
  65068. stateStack.getLast()->xOffset += x;
  65069. stateStack.getLast()->yOffset += y;
  65070. needToClip = true;
  65071. }
  65072. }
  65073. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65074. {
  65075. needToClip = true;
  65076. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65077. }
  65078. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65079. {
  65080. needToClip = true;
  65081. return stateStack.getLast()->clip.clipTo (clipRegion);
  65082. }
  65083. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65084. {
  65085. needToClip = true;
  65086. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65087. }
  65088. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65089. {
  65090. writeClip();
  65091. Path p (path);
  65092. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65093. writePath (p);
  65094. out << "clip\n";
  65095. }
  65096. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65097. {
  65098. needToClip = true;
  65099. jassertfalse // xxx
  65100. }
  65101. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65102. {
  65103. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65104. }
  65105. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65106. {
  65107. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65108. -stateStack.getLast()->yOffset);
  65109. }
  65110. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65111. {
  65112. return stateStack.getLast()->clip.isEmpty();
  65113. }
  65114. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65115. : xOffset (0),
  65116. yOffset (0)
  65117. {
  65118. }
  65119. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65120. {
  65121. }
  65122. void LowLevelGraphicsPostScriptRenderer::saveState()
  65123. {
  65124. stateStack.add (new SavedState (*stateStack.getLast()));
  65125. }
  65126. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65127. {
  65128. jassert (stateStack.size() > 0);
  65129. if (stateStack.size() > 0)
  65130. stateStack.removeLast();
  65131. }
  65132. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65133. {
  65134. if (needToClip)
  65135. {
  65136. needToClip = false;
  65137. out << "doclip ";
  65138. int itemsOnLine = 0;
  65139. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65140. {
  65141. if (++itemsOnLine == 6)
  65142. {
  65143. itemsOnLine = 0;
  65144. out << '\n';
  65145. }
  65146. const Rectangle<int>& r = *i.getRectangle();
  65147. out << r.getX() << ' ' << -r.getY() << ' '
  65148. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65149. }
  65150. out << "endclip\n";
  65151. }
  65152. }
  65153. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65154. {
  65155. Colour c (Colours::white.overlaidWith (colour));
  65156. if (lastColour != c)
  65157. {
  65158. lastColour = c;
  65159. out << String (c.getFloatRed(), 3) << ' '
  65160. << String (c.getFloatGreen(), 3) << ' '
  65161. << String (c.getFloatBlue(), 3) << " c\n";
  65162. }
  65163. }
  65164. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65165. {
  65166. out << String (x, 2) << ' '
  65167. << String (-y, 2) << ' ';
  65168. }
  65169. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65170. {
  65171. out << "newpath ";
  65172. float lastX = 0.0f;
  65173. float lastY = 0.0f;
  65174. int itemsOnLine = 0;
  65175. Path::Iterator i (path);
  65176. while (i.next())
  65177. {
  65178. if (++itemsOnLine == 4)
  65179. {
  65180. itemsOnLine = 0;
  65181. out << '\n';
  65182. }
  65183. switch (i.elementType)
  65184. {
  65185. case Path::Iterator::startNewSubPath:
  65186. writeXY (i.x1, i.y1);
  65187. lastX = i.x1;
  65188. lastY = i.y1;
  65189. out << "m ";
  65190. break;
  65191. case Path::Iterator::lineTo:
  65192. writeXY (i.x1, i.y1);
  65193. lastX = i.x1;
  65194. lastY = i.y1;
  65195. out << "l ";
  65196. break;
  65197. case Path::Iterator::quadraticTo:
  65198. {
  65199. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65200. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65201. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65202. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65203. writeXY (cp1x, cp1y);
  65204. writeXY (cp2x, cp2y);
  65205. writeXY (i.x2, i.y2);
  65206. out << "ct ";
  65207. lastX = i.x2;
  65208. lastY = i.y2;
  65209. }
  65210. break;
  65211. case Path::Iterator::cubicTo:
  65212. writeXY (i.x1, i.y1);
  65213. writeXY (i.x2, i.y2);
  65214. writeXY (i.x3, i.y3);
  65215. out << "ct ";
  65216. lastX = i.x3;
  65217. lastY = i.y3;
  65218. break;
  65219. case Path::Iterator::closePath:
  65220. out << "cp ";
  65221. break;
  65222. default:
  65223. jassertfalse
  65224. break;
  65225. }
  65226. }
  65227. out << '\n';
  65228. }
  65229. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65230. {
  65231. out << "[ "
  65232. << trans.mat00 << ' '
  65233. << trans.mat10 << ' '
  65234. << trans.mat01 << ' '
  65235. << trans.mat11 << ' '
  65236. << trans.mat02 << ' '
  65237. << trans.mat12 << " ] concat ";
  65238. }
  65239. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65240. {
  65241. stateStack.getLast()->fillType = fillType;
  65242. }
  65243. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65244. {
  65245. }
  65246. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65247. {
  65248. }
  65249. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65250. {
  65251. if (stateStack.getLast()->fillType.isColour())
  65252. {
  65253. writeClip();
  65254. writeColour (stateStack.getLast()->fillType.colour);
  65255. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65256. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65257. }
  65258. else
  65259. {
  65260. Path p;
  65261. p.addRectangle (r);
  65262. fillPath (p, AffineTransform::identity);
  65263. }
  65264. }
  65265. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65266. {
  65267. if (stateStack.getLast()->fillType.isColour())
  65268. {
  65269. writeClip();
  65270. Path p (path);
  65271. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65272. (float) stateStack.getLast()->yOffset));
  65273. writePath (p);
  65274. writeColour (stateStack.getLast()->fillType.colour);
  65275. out << "fill\n";
  65276. }
  65277. else if (stateStack.getLast()->fillType.isGradient())
  65278. {
  65279. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65280. // postscript can't do semi-transparent ones.
  65281. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65282. writeClip();
  65283. out << "gsave ";
  65284. {
  65285. Path p (path);
  65286. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65287. writePath (p);
  65288. out << "clip\n";
  65289. }
  65290. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65291. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65292. // time-being, this just fills it with the average colour..
  65293. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65294. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65295. out << "grestore\n";
  65296. }
  65297. }
  65298. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65299. const int sx, const int sy,
  65300. const int maxW, const int maxH) const
  65301. {
  65302. out << "{<\n";
  65303. const int w = jmin (maxW, im.getWidth());
  65304. const int h = jmin (maxH, im.getHeight());
  65305. int charsOnLine = 0;
  65306. const Image::BitmapData srcData (im, 0, 0, w, h);
  65307. Colour pixel;
  65308. for (int y = h; --y >= 0;)
  65309. {
  65310. for (int x = 0; x < w; ++x)
  65311. {
  65312. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65313. if (x >= sx && y >= sy)
  65314. {
  65315. if (im.isARGB())
  65316. {
  65317. PixelARGB p (*(const PixelARGB*) pixelData);
  65318. p.unpremultiply();
  65319. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65320. }
  65321. else if (im.isRGB())
  65322. {
  65323. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65324. }
  65325. else
  65326. {
  65327. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65328. }
  65329. }
  65330. else
  65331. {
  65332. pixel = Colours::transparentWhite;
  65333. }
  65334. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65335. out << String::toHexString (pixelValues, 3, 0);
  65336. charsOnLine += 3;
  65337. if (charsOnLine > 100)
  65338. {
  65339. out << '\n';
  65340. charsOnLine = 0;
  65341. }
  65342. }
  65343. }
  65344. out << "\n>}\n";
  65345. }
  65346. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65347. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65348. {
  65349. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65350. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65351. writeClip();
  65352. out << "gsave ";
  65353. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65354. .scaled (1.0f, -1.0f));
  65355. RectangleList imageClip;
  65356. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65357. imageClip.clipTo (srcClip);
  65358. out << "newpath ";
  65359. int itemsOnLine = 0;
  65360. for (RectangleList::Iterator i (imageClip); i.next();)
  65361. {
  65362. if (++itemsOnLine == 6)
  65363. {
  65364. out << '\n';
  65365. itemsOnLine = 0;
  65366. }
  65367. const Rectangle<int>& r = *i.getRectangle();
  65368. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65369. }
  65370. out << " clip newpath\n";
  65371. out << w << ' ' << h << " scale\n";
  65372. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65373. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65374. out << "false 3 colorimage grestore\n";
  65375. needToClip = true;
  65376. }
  65377. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65378. {
  65379. Path p;
  65380. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65381. fillPath (p, AffineTransform::identity);
  65382. }
  65383. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65384. {
  65385. drawLine (x, top, x, bottom);
  65386. }
  65387. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65388. {
  65389. drawLine (left, y, right, y);
  65390. }
  65391. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65392. {
  65393. stateStack.getLast()->font = newFont;
  65394. }
  65395. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65396. {
  65397. return stateStack.getLast()->font;
  65398. }
  65399. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65400. {
  65401. Path p;
  65402. Font& font = stateStack.getLast()->font;
  65403. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65404. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65405. }
  65406. END_JUCE_NAMESPACE
  65407. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65408. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65409. BEGIN_JUCE_NAMESPACE
  65410. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65411. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65412. #endif
  65413. #if JUCE_MSVC
  65414. #if JUCE_DEBUG
  65415. #pragma optimize ("t", on) // optimise just this file, to avoid sluggish graphics when debugging
  65416. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65417. #endif
  65418. #pragma warning (push)
  65419. #pragma warning (disable: 4127) // "expression is constant" warning
  65420. #endif
  65421. template <class PixelType, bool replaceExisting = false>
  65422. class SolidColourEdgeTableRenderer
  65423. {
  65424. public:
  65425. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65426. : data (data_),
  65427. sourceColour (colour)
  65428. {
  65429. if (sizeof (PixelType) == 3)
  65430. {
  65431. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65432. && sourceColour.getGreen() == sourceColour.getBlue();
  65433. filler[0].set (sourceColour);
  65434. filler[1].set (sourceColour);
  65435. filler[2].set (sourceColour);
  65436. filler[3].set (sourceColour);
  65437. }
  65438. }
  65439. forcedinline void setEdgeTableYPos (const int y) throw()
  65440. {
  65441. linePixels = (PixelType*) data.getLinePointer (y);
  65442. }
  65443. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65444. {
  65445. if (replaceExisting)
  65446. linePixels[x].set (sourceColour);
  65447. else
  65448. linePixels[x].blend (sourceColour, alphaLevel);
  65449. }
  65450. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65451. {
  65452. PixelARGB p (sourceColour);
  65453. p.multiplyAlpha (alphaLevel);
  65454. PixelType* dest = linePixels + x;
  65455. if (replaceExisting || p.getAlpha() >= 0xff)
  65456. replaceLine (dest, p, width);
  65457. else
  65458. blendLine (dest, p, width);
  65459. }
  65460. private:
  65461. const Image::BitmapData& data;
  65462. PixelType* linePixels;
  65463. PixelARGB sourceColour;
  65464. PixelRGB filler [4];
  65465. bool areRGBComponentsEqual;
  65466. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65467. {
  65468. do
  65469. {
  65470. dest->blend (colour);
  65471. ++dest;
  65472. } while (--width > 0);
  65473. }
  65474. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65475. {
  65476. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65477. {
  65478. memset (dest, colour.getRed(), width * 3);
  65479. }
  65480. else
  65481. {
  65482. if (width >> 5)
  65483. {
  65484. const int* const intFiller = (const int*) filler;
  65485. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65486. {
  65487. dest->set (colour);
  65488. ++dest;
  65489. --width;
  65490. }
  65491. while (width > 4)
  65492. {
  65493. ((int*) dest) [0] = intFiller[0];
  65494. ((int*) dest) [1] = intFiller[1];
  65495. ((int*) dest) [2] = intFiller[2];
  65496. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65497. width -= 4;
  65498. }
  65499. }
  65500. while (--width >= 0)
  65501. {
  65502. dest->set (colour);
  65503. ++dest;
  65504. }
  65505. }
  65506. }
  65507. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65508. {
  65509. memset (dest, colour.getAlpha(), width);
  65510. }
  65511. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65512. {
  65513. do
  65514. {
  65515. dest->set (colour);
  65516. ++dest;
  65517. } while (--width > 0);
  65518. }
  65519. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65520. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65521. };
  65522. class LinearGradientPixelGenerator
  65523. {
  65524. public:
  65525. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65526. : lookupTable (lookupTable_), numEntries (numEntries_)
  65527. {
  65528. jassert (numEntries_ >= 0);
  65529. float x1 = gradient.x1;
  65530. float y1 = gradient.y1;
  65531. float x2 = gradient.x2;
  65532. float y2 = gradient.y2;
  65533. if (! transform.isIdentity())
  65534. {
  65535. const Line l (x2, y2, x1, y1);
  65536. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65537. float x3 = p3.getX();
  65538. float y3 = p3.getY();
  65539. transform.transformPoint (x1, y1);
  65540. transform.transformPoint (x2, y2);
  65541. transform.transformPoint (x3, y3);
  65542. const Line l2 (x2, y2, x3, y3);
  65543. const float prop = l2.findNearestPointTo (x1, y1);
  65544. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65545. x2 = newP2.getX();
  65546. y2 = newP2.getY();
  65547. }
  65548. vertical = fabs (x1 - x2) < 0.001f;
  65549. horizontal = fabs (y1 - y2) < 0.001f;
  65550. if (vertical)
  65551. {
  65552. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65553. start = roundToInt (y1 * scale);
  65554. }
  65555. else if (horizontal)
  65556. {
  65557. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65558. start = roundToInt (x1 * scale);
  65559. }
  65560. else
  65561. {
  65562. grad = (y2 - y1) / (double) (x1 - x2);
  65563. yTerm = y1 - x1 / grad;
  65564. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65565. grad *= scale;
  65566. }
  65567. }
  65568. forcedinline void setY (const int y) throw()
  65569. {
  65570. if (vertical)
  65571. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65572. else if (! horizontal)
  65573. start = roundToInt ((y - yTerm) * grad);
  65574. }
  65575. inline const PixelARGB getPixel (const int x) const throw()
  65576. {
  65577. return vertical ? linePix
  65578. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65579. }
  65580. private:
  65581. const PixelARGB* const lookupTable;
  65582. const int numEntries;
  65583. PixelARGB linePix;
  65584. int start, scale;
  65585. double grad, yTerm;
  65586. bool vertical, horizontal;
  65587. enum { numScaleBits = 12 };
  65588. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65589. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65590. };
  65591. class RadialGradientPixelGenerator
  65592. {
  65593. public:
  65594. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65595. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65596. : lookupTable (lookupTable_),
  65597. numEntries (numEntries_),
  65598. gx1 (gradient.x1),
  65599. gy1 (gradient.y1)
  65600. {
  65601. jassert (numEntries_ >= 0);
  65602. const float gdx = gradient.x1 - gradient.x2;
  65603. const float gdy = gradient.y1 - gradient.y2;
  65604. maxDist = gdx * gdx + gdy * gdy;
  65605. invScale = numEntries / sqrt (maxDist);
  65606. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65607. }
  65608. forcedinline void setY (const int y) throw()
  65609. {
  65610. dy = y - gy1;
  65611. dy *= dy;
  65612. }
  65613. inline const PixelARGB getPixel (const int px) const throw()
  65614. {
  65615. double x = px - gx1;
  65616. x *= x;
  65617. x += dy;
  65618. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65619. }
  65620. protected:
  65621. const PixelARGB* const lookupTable;
  65622. const int numEntries;
  65623. const double gx1, gy1;
  65624. double maxDist, invScale, dy;
  65625. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65626. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65627. };
  65628. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65629. {
  65630. public:
  65631. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65632. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65633. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65634. inverseTransform (transform.inverted())
  65635. {
  65636. tM10 = inverseTransform.mat10;
  65637. tM00 = inverseTransform.mat00;
  65638. }
  65639. forcedinline void setY (const int y) throw()
  65640. {
  65641. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65642. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65643. }
  65644. inline const PixelARGB getPixel (const int px) const throw()
  65645. {
  65646. double x = px;
  65647. const double y = tM10 * x + lineYM11;
  65648. x = tM00 * x + lineYM01;
  65649. x *= x;
  65650. x += y * y;
  65651. if (x >= maxDist)
  65652. return lookupTable [numEntries];
  65653. else
  65654. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65655. }
  65656. private:
  65657. double tM10, tM00, lineYM01, lineYM11;
  65658. const AffineTransform inverseTransform;
  65659. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65660. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65661. };
  65662. template <class PixelType, class GradientType>
  65663. class GradientEdgeTableRenderer : public GradientType
  65664. {
  65665. public:
  65666. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65667. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65668. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65669. destData (destData_)
  65670. {
  65671. }
  65672. forcedinline void setEdgeTableYPos (const int y) throw()
  65673. {
  65674. linePixels = (PixelType*) destData.getLinePointer (y);
  65675. GradientType::setY (y);
  65676. }
  65677. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65678. {
  65679. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65680. }
  65681. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65682. {
  65683. PixelType* dest = linePixels + x;
  65684. if (alphaLevel < 0xff)
  65685. {
  65686. do
  65687. {
  65688. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65689. } while (--width > 0);
  65690. }
  65691. else
  65692. {
  65693. do
  65694. {
  65695. (dest++)->blend (GradientType::getPixel (x++));
  65696. } while (--width > 0);
  65697. }
  65698. }
  65699. private:
  65700. const Image::BitmapData& destData;
  65701. PixelType* linePixels;
  65702. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65703. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65704. };
  65705. static forcedinline int safeModulo (int n, const int divisor) throw()
  65706. {
  65707. jassert (divisor > 0);
  65708. n %= divisor;
  65709. return (n < 0) ? (n + divisor) : n;
  65710. }
  65711. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65712. class ImageFillEdgeTableRenderer
  65713. {
  65714. public:
  65715. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65716. const Image::BitmapData& srcData_,
  65717. const int extraAlpha_,
  65718. const int x, const int y) throw()
  65719. : destData (destData_),
  65720. srcData (srcData_),
  65721. extraAlpha (extraAlpha_ + 1),
  65722. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65723. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65724. {
  65725. }
  65726. forcedinline void setEdgeTableYPos (int y) throw()
  65727. {
  65728. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65729. y -= yOffset;
  65730. if (repeatPattern)
  65731. {
  65732. jassert (y >= 0);
  65733. y %= srcData.height;
  65734. }
  65735. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65736. }
  65737. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65738. {
  65739. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65740. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65741. }
  65742. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65743. {
  65744. DestPixelType* dest = linePixels + x;
  65745. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65746. x -= xOffset;
  65747. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65748. if (alphaLevel < 0xfe)
  65749. {
  65750. do
  65751. {
  65752. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65753. } while (--width > 0);
  65754. }
  65755. else
  65756. {
  65757. if (repeatPattern)
  65758. {
  65759. do
  65760. {
  65761. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65762. } while (--width > 0);
  65763. }
  65764. else
  65765. {
  65766. copyRow (dest, sourceLineStart + x, width);
  65767. }
  65768. }
  65769. }
  65770. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65771. {
  65772. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65773. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65774. uint8* mask = (uint8*) (s + x - xOffset);
  65775. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65776. mask += PixelARGB::indexA;
  65777. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65778. }
  65779. private:
  65780. const Image::BitmapData& destData;
  65781. const Image::BitmapData& srcData;
  65782. const int extraAlpha, xOffset, yOffset;
  65783. DestPixelType* linePixels;
  65784. SrcPixelType* sourceLineStart;
  65785. template <class PixelType1, class PixelType2>
  65786. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65787. {
  65788. do
  65789. {
  65790. dest++ ->blend (*src++);
  65791. } while (--width > 0);
  65792. }
  65793. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65794. {
  65795. memcpy (dest, src, width * sizeof (PixelRGB));
  65796. }
  65797. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65798. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65799. };
  65800. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65801. class TransformedImageFillEdgeTableRenderer
  65802. {
  65803. public:
  65804. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65805. const Image::BitmapData& srcData_,
  65806. const AffineTransform& transform,
  65807. const int extraAlpha_,
  65808. const bool betterQuality_) throw()
  65809. : interpolator (transform),
  65810. destData (destData_),
  65811. srcData (srcData_),
  65812. extraAlpha (extraAlpha_ + 1),
  65813. betterQuality (betterQuality_),
  65814. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65815. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65816. maxX (srcData_.width - 1),
  65817. maxY (srcData_.height - 1),
  65818. scratchSize (2048)
  65819. {
  65820. scratchBuffer.malloc (scratchSize);
  65821. }
  65822. ~TransformedImageFillEdgeTableRenderer() throw()
  65823. {
  65824. }
  65825. forcedinline void setEdgeTableYPos (const int newY) throw()
  65826. {
  65827. y = newY;
  65828. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65829. }
  65830. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65831. {
  65832. alphaLevel *= extraAlpha;
  65833. alphaLevel >>= 8;
  65834. SrcPixelType p;
  65835. generate (&p, x, 1);
  65836. linePixels[x].blend (p, alphaLevel);
  65837. }
  65838. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65839. {
  65840. if (width > scratchSize)
  65841. {
  65842. scratchSize = width;
  65843. scratchBuffer.malloc (scratchSize);
  65844. }
  65845. SrcPixelType* span = scratchBuffer;
  65846. generate (span, x, width);
  65847. DestPixelType* dest = linePixels + x;
  65848. alphaLevel *= extraAlpha;
  65849. alphaLevel >>= 8;
  65850. if (alphaLevel < 0xfe)
  65851. {
  65852. do
  65853. {
  65854. dest++ ->blend (*span++, alphaLevel);
  65855. } while (--width > 0);
  65856. }
  65857. else
  65858. {
  65859. do
  65860. {
  65861. dest++ ->blend (*span++);
  65862. } while (--width > 0);
  65863. }
  65864. }
  65865. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65866. {
  65867. if (width > scratchSize)
  65868. {
  65869. scratchSize = width;
  65870. scratchBuffer.malloc (scratchSize);
  65871. }
  65872. y = y_;
  65873. generate (scratchBuffer, x, width);
  65874. et.clipLineToMask (x, y_,
  65875. reinterpret_cast<uint8*> (scratchBuffer.getData()) + SrcPixelType::indexA,
  65876. sizeof (SrcPixelType), width);
  65877. }
  65878. private:
  65879. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65880. {
  65881. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65882. do
  65883. {
  65884. int hiResX, hiResY;
  65885. this->interpolator.next (hiResX, hiResY);
  65886. hiResX += pixelOffsetInt;
  65887. hiResY += pixelOffsetInt;
  65888. int loResX = hiResX >> 8;
  65889. int loResY = hiResY >> 8;
  65890. if (repeatPattern)
  65891. {
  65892. loResX = safeModulo (loResX, srcData.width);
  65893. loResY = safeModulo (loResY, srcData.height);
  65894. }
  65895. if (betterQuality
  65896. && ((unsigned int) loResX) < (unsigned int) maxX
  65897. && ((unsigned int) loResY) < (unsigned int) maxY)
  65898. {
  65899. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65900. hiResX &= 255;
  65901. hiResY &= 255;
  65902. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65903. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65904. c[0] += weight * src[0];
  65905. c[1] += weight * src[1];
  65906. c[2] += weight * src[2];
  65907. c[3] += weight * src[3];
  65908. weight = hiResX * (256 - hiResY);
  65909. c[0] += weight * src[4];
  65910. c[1] += weight * src[5];
  65911. c[2] += weight * src[6];
  65912. c[3] += weight * src[7];
  65913. src += this->srcData.lineStride;
  65914. weight = (256 - hiResX) * hiResY;
  65915. c[0] += weight * src[0];
  65916. c[1] += weight * src[1];
  65917. c[2] += weight * src[2];
  65918. c[3] += weight * src[3];
  65919. weight = hiResX * hiResY;
  65920. c[0] += weight * src[4];
  65921. c[1] += weight * src[5];
  65922. c[2] += weight * src[6];
  65923. c[3] += weight * src[7];
  65924. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65925. (uint8) (c[PixelARGB::indexR] >> 16),
  65926. (uint8) (c[PixelARGB::indexG] >> 16),
  65927. (uint8) (c[PixelARGB::indexB] >> 16));
  65928. }
  65929. else
  65930. {
  65931. if (! repeatPattern)
  65932. {
  65933. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65934. if (loResX < 0) loResX = 0;
  65935. if (loResY < 0) loResY = 0;
  65936. if (loResX > maxX) loResX = maxX;
  65937. if (loResY > maxY) loResY = maxY;
  65938. }
  65939. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65940. }
  65941. ++dest;
  65942. } while (--numPixels > 0);
  65943. }
  65944. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65945. {
  65946. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65947. do
  65948. {
  65949. int hiResX, hiResY;
  65950. this->interpolator.next (hiResX, hiResY);
  65951. hiResX += pixelOffsetInt;
  65952. hiResY += pixelOffsetInt;
  65953. int loResX = hiResX >> 8;
  65954. int loResY = hiResY >> 8;
  65955. if (repeatPattern)
  65956. {
  65957. loResX = safeModulo (loResX, srcData.width);
  65958. loResY = safeModulo (loResY, srcData.height);
  65959. }
  65960. if (betterQuality
  65961. && ((unsigned int) loResX) < (unsigned int) maxX
  65962. && ((unsigned int) loResY) < (unsigned int) maxY)
  65963. {
  65964. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  65965. hiResX &= 255;
  65966. hiResY &= 255;
  65967. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65968. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  65969. c[0] += weight * src[0];
  65970. c[1] += weight * src[1];
  65971. c[2] += weight * src[2];
  65972. weight = hiResX * (256 - hiResY);
  65973. c[0] += weight * src[3];
  65974. c[1] += weight * src[4];
  65975. c[2] += weight * src[5];
  65976. src += this->srcData.lineStride;
  65977. weight = (256 - hiResX) * hiResY;
  65978. c[0] += weight * src[0];
  65979. c[1] += weight * src[1];
  65980. c[2] += weight * src[2];
  65981. weight = hiResX * hiResY;
  65982. c[0] += weight * src[3];
  65983. c[1] += weight * src[4];
  65984. c[2] += weight * src[5];
  65985. dest->setARGB ((uint8) 255,
  65986. (uint8) (c[PixelRGB::indexR] >> 16),
  65987. (uint8) (c[PixelRGB::indexG] >> 16),
  65988. (uint8) (c[PixelRGB::indexB] >> 16));
  65989. }
  65990. else
  65991. {
  65992. if (! repeatPattern)
  65993. {
  65994. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65995. if (loResX < 0) loResX = 0;
  65996. if (loResY < 0) loResY = 0;
  65997. if (loResX > maxX) loResX = maxX;
  65998. if (loResY > maxY) loResY = maxY;
  65999. }
  66000. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66001. }
  66002. ++dest;
  66003. } while (--numPixels > 0);
  66004. }
  66005. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66006. {
  66007. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66008. do
  66009. {
  66010. int hiResX, hiResY;
  66011. this->interpolator.next (hiResX, hiResY);
  66012. hiResX += pixelOffsetInt;
  66013. hiResY += pixelOffsetInt;
  66014. int loResX = hiResX >> 8;
  66015. int loResY = hiResY >> 8;
  66016. if (repeatPattern)
  66017. {
  66018. loResX = safeModulo (loResX, srcData.width);
  66019. loResY = safeModulo (loResY, srcData.height);
  66020. }
  66021. if (betterQuality
  66022. && ((unsigned int) loResX) < (unsigned int) maxX
  66023. && ((unsigned int) loResY) < (unsigned int) maxY)
  66024. {
  66025. hiResX &= 255;
  66026. hiResY &= 255;
  66027. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66028. uint32 c = 256 * 128;
  66029. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66030. c += src[1] * (hiResX * (256 - hiResY));
  66031. src += this->srcData.lineStride;
  66032. c += src[0] * ((256 - hiResX) * hiResY);
  66033. c += src[1] * (hiResX * hiResY);
  66034. *((uint8*) dest) = (uint8) c;
  66035. }
  66036. else
  66037. {
  66038. if (! repeatPattern)
  66039. {
  66040. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66041. if (loResX < 0) loResX = 0;
  66042. if (loResY < 0) loResY = 0;
  66043. if (loResX > maxX) loResX = maxX;
  66044. if (loResY > maxY) loResY = maxY;
  66045. }
  66046. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66047. }
  66048. ++dest;
  66049. } while (--numPixels > 0);
  66050. }
  66051. class TransformedImageSpanInterpolator
  66052. {
  66053. public:
  66054. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66055. : inverseTransform (transform.inverted())
  66056. {}
  66057. void setStartOfLine (float x, float y, const int numPixels) throw()
  66058. {
  66059. float x1 = x, y1 = y;
  66060. inverseTransform.transformPoint (x1, y1);
  66061. x += numPixels;
  66062. inverseTransform.transformPoint (x, y);
  66063. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66064. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66065. }
  66066. void next (int& x, int& y) throw()
  66067. {
  66068. x = xBresenham.n;
  66069. xBresenham.stepToNext();
  66070. y = yBresenham.n;
  66071. yBresenham.stepToNext();
  66072. }
  66073. private:
  66074. class BresenhamInterpolator
  66075. {
  66076. public:
  66077. BresenhamInterpolator() throw() {}
  66078. void set (const int n1, const int n2, const int numSteps_) throw()
  66079. {
  66080. numSteps = jmax (1, numSteps_);
  66081. step = (n2 - n1) / numSteps;
  66082. remainder = modulo = (n2 - n1) % numSteps;
  66083. n = n1;
  66084. if (modulo <= 0)
  66085. {
  66086. modulo += numSteps;
  66087. remainder += numSteps;
  66088. --step;
  66089. }
  66090. modulo -= numSteps;
  66091. }
  66092. forcedinline void stepToNext() throw()
  66093. {
  66094. modulo += remainder;
  66095. n += step;
  66096. if (modulo > 0)
  66097. {
  66098. modulo -= numSteps;
  66099. ++n;
  66100. }
  66101. }
  66102. int n;
  66103. private:
  66104. int numSteps, step, modulo, remainder;
  66105. };
  66106. const AffineTransform inverseTransform;
  66107. BresenhamInterpolator xBresenham, yBresenham;
  66108. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66109. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66110. };
  66111. TransformedImageSpanInterpolator interpolator;
  66112. const Image::BitmapData& destData;
  66113. const Image::BitmapData& srcData;
  66114. const int extraAlpha;
  66115. const bool betterQuality;
  66116. const float pixelOffset;
  66117. const int pixelOffsetInt, maxX, maxY;
  66118. int y;
  66119. DestPixelType* linePixels;
  66120. HeapBlock <SrcPixelType> scratchBuffer;
  66121. int scratchSize;
  66122. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66123. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66124. };
  66125. class LLGCSavedState
  66126. {
  66127. public:
  66128. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66129. const Font& font_, const FillType& fillType_,
  66130. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66131. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66132. xOffset (xOffset_), yOffset (yOffset_),
  66133. font (font_), fillType (fillType_),
  66134. interpolationQuality (interpolationQuality_)
  66135. {
  66136. }
  66137. LLGCSavedState (const LLGCSavedState& other) throw()
  66138. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66139. yOffset (other.yOffset), font (other.font),
  66140. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66141. {
  66142. }
  66143. ~LLGCSavedState() throw()
  66144. {
  66145. }
  66146. bool clipToRectangle (const Rectangle<int>& r) throw()
  66147. {
  66148. dupeEdgeTableIfMultiplyReferenced();
  66149. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66150. return ! edgeTable->edgeTable.isEmpty();
  66151. }
  66152. bool clipToRectangleList (const RectangleList& r) throw()
  66153. {
  66154. dupeEdgeTableIfMultiplyReferenced();
  66155. RectangleList offsetList (r);
  66156. offsetList.offsetAll (xOffset, yOffset);
  66157. EdgeTable e2 (offsetList);
  66158. edgeTable->edgeTable.clipToEdgeTable (e2);
  66159. return ! edgeTable->edgeTable.isEmpty();
  66160. }
  66161. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66162. {
  66163. dupeEdgeTableIfMultiplyReferenced();
  66164. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66165. return ! edgeTable->edgeTable.isEmpty();
  66166. }
  66167. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66168. {
  66169. dupeEdgeTableIfMultiplyReferenced();
  66170. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66171. edgeTable->edgeTable.clipToEdgeTable (et);
  66172. }
  66173. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66174. {
  66175. et.clipToEdgeTable (edgeTable->edgeTable);
  66176. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66177. if (fillType.isGradient())
  66178. {
  66179. jassert (! replaceContents); // that option is just for solid colours
  66180. ColourGradient g2 (*(fillType.gradient));
  66181. g2.multiplyOpacity (fillType.getOpacity());
  66182. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66183. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66184. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66185. const bool isIdentity = transform.isOnlyTranslation();
  66186. if (isIdentity)
  66187. {
  66188. // If our translation doesn't involve any distortion, we can speed it up..
  66189. transform.transformPoint (g2.x1, g2.y1);
  66190. transform.transformPoint (g2.x2, g2.y2);
  66191. transform = AffineTransform::identity;
  66192. }
  66193. HeapBlock <PixelARGB> lookupTable;
  66194. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66195. jassert (numLookupEntries > 0);
  66196. switch (image.getFormat())
  66197. {
  66198. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66199. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66200. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66201. }
  66202. }
  66203. else if (fillType.isTiledImage())
  66204. {
  66205. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66206. }
  66207. else
  66208. {
  66209. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66210. switch (image.getFormat())
  66211. {
  66212. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66213. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66214. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66215. }
  66216. }
  66217. }
  66218. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66219. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66220. {
  66221. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66222. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66223. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66224. const int alpha = fillType.colour.getAlpha();
  66225. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66226. if (transform.isOnlyTranslation())
  66227. {
  66228. // If our translation doesn't involve any distortion, just use a simple blit..
  66229. int tx = (int) (transform.getTranslationX() * 256.0f);
  66230. int ty = (int) (transform.getTranslationY() * 256.0f);
  66231. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66232. {
  66233. tx = ((tx + 128) >> 8);
  66234. ty = ((ty + 128) >> 8);
  66235. if (tiledFillClipRegion != 0)
  66236. {
  66237. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66238. }
  66239. else
  66240. {
  66241. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66242. et.clipToEdgeTable (edgeTable->edgeTable);
  66243. if (! et.isEmpty())
  66244. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66245. }
  66246. return;
  66247. }
  66248. }
  66249. if (transform.isSingularity())
  66250. return;
  66251. if (tiledFillClipRegion != 0)
  66252. {
  66253. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66254. }
  66255. else
  66256. {
  66257. Path p;
  66258. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66259. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66260. et.clipToEdgeTable (edgeTable->edgeTable);
  66261. if (! et.isEmpty())
  66262. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66263. }
  66264. }
  66265. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66266. {
  66267. if (! image.hasAlphaChannel())
  66268. {
  66269. Path p;
  66270. p.addRectangle (srcClip);
  66271. clipToPath (p, t);
  66272. return;
  66273. }
  66274. dupeEdgeTableIfMultiplyReferenced();
  66275. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66276. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66277. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66278. EdgeTable& et = edgeTable->edgeTable;
  66279. if (transform.isOnlyTranslation())
  66280. {
  66281. // If our translation doesn't involve any distortion, just use a simple blit..
  66282. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66283. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66284. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66285. {
  66286. const int imageX = ((tx + 128) >> 8);
  66287. const int imageY = ((ty + 128) >> 8);
  66288. if (image.getFormat() == Image::ARGB)
  66289. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66290. else
  66291. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66292. return;
  66293. }
  66294. }
  66295. if (transform.isSingularity())
  66296. {
  66297. et.clipToRectangle (Rectangle<int>());
  66298. return;
  66299. }
  66300. {
  66301. Path p;
  66302. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66303. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66304. et.clipToEdgeTable (et2);
  66305. }
  66306. if (! et.isEmpty())
  66307. {
  66308. if (image.getFormat() == Image::ARGB)
  66309. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66310. else
  66311. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66312. }
  66313. }
  66314. template <class SrcPixelType>
  66315. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66316. {
  66317. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66318. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66319. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66320. et.getMaximumBounds().getWidth());
  66321. }
  66322. template <class SrcPixelType>
  66323. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66324. {
  66325. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66326. et.clipToRectangle (r);
  66327. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66328. for (int y = 0; y < r.getHeight(); ++y)
  66329. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66330. }
  66331. class EdgeTableHolder : public ReferenceCountedObject
  66332. {
  66333. public:
  66334. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66335. EdgeTable edgeTable;
  66336. };
  66337. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66338. int xOffset, yOffset;
  66339. Font font;
  66340. FillType fillType;
  66341. Graphics::ResamplingQuality interpolationQuality;
  66342. private:
  66343. LLGCSavedState& operator= (const LLGCSavedState&);
  66344. void dupeEdgeTableIfMultiplyReferenced() throw()
  66345. {
  66346. if (edgeTable->getReferenceCount() > 1)
  66347. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66348. }
  66349. template <class DestPixelType>
  66350. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66351. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66352. {
  66353. jassert (destData.pixelStride == sizeof (DestPixelType));
  66354. if (g.isRadial)
  66355. {
  66356. if (isIdentity)
  66357. {
  66358. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66359. et.iterate (renderer);
  66360. }
  66361. else
  66362. {
  66363. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66364. et.iterate (renderer);
  66365. }
  66366. }
  66367. else
  66368. {
  66369. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66370. et.iterate (renderer);
  66371. }
  66372. }
  66373. template <class DestPixelType>
  66374. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66375. {
  66376. jassert (destData.pixelStride == sizeof (DestPixelType));
  66377. if (replaceContents)
  66378. {
  66379. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66380. et.iterate (r);
  66381. }
  66382. else
  66383. {
  66384. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66385. et.iterate (r);
  66386. }
  66387. }
  66388. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66389. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66390. {
  66391. switch (destImage.getFormat())
  66392. {
  66393. case Image::ARGB:
  66394. switch (srcImage.getFormat())
  66395. {
  66396. case Image::ARGB:
  66397. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66398. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66399. break;
  66400. case Image::RGB:
  66401. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66402. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66403. break;
  66404. default:
  66405. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66406. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66407. break;
  66408. }
  66409. break;
  66410. case Image::RGB:
  66411. switch (srcImage.getFormat())
  66412. {
  66413. case Image::ARGB:
  66414. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66415. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66416. break;
  66417. case Image::RGB:
  66418. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66419. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66420. break;
  66421. default:
  66422. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66423. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66424. break;
  66425. }
  66426. break;
  66427. default:
  66428. switch (srcImage.getFormat())
  66429. {
  66430. case Image::ARGB:
  66431. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66432. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66433. break;
  66434. case Image::RGB:
  66435. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66436. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66437. break;
  66438. default:
  66439. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66440. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66441. break;
  66442. }
  66443. break;
  66444. }
  66445. }
  66446. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66447. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66448. {
  66449. switch (destImage.getFormat())
  66450. {
  66451. case Image::ARGB:
  66452. switch (srcImage.getFormat())
  66453. {
  66454. case Image::ARGB:
  66455. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66456. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66457. break;
  66458. case Image::RGB:
  66459. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66460. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66461. break;
  66462. default:
  66463. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66464. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66465. break;
  66466. }
  66467. break;
  66468. case Image::RGB:
  66469. switch (srcImage.getFormat())
  66470. {
  66471. case Image::ARGB:
  66472. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66473. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66474. break;
  66475. case Image::RGB:
  66476. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66477. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66478. break;
  66479. default:
  66480. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66481. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66482. break;
  66483. }
  66484. break;
  66485. default:
  66486. switch (srcImage.getFormat())
  66487. {
  66488. case Image::ARGB:
  66489. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66490. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66491. break;
  66492. case Image::RGB:
  66493. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66494. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66495. break;
  66496. default:
  66497. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66498. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66499. break;
  66500. }
  66501. break;
  66502. }
  66503. }
  66504. };
  66505. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66506. : image (image_)
  66507. {
  66508. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66509. FillType(), Graphics::mediumResamplingQuality);
  66510. }
  66511. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66512. {
  66513. }
  66514. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66515. {
  66516. return false;
  66517. }
  66518. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66519. {
  66520. currentState->xOffset += x;
  66521. currentState->yOffset += y;
  66522. }
  66523. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66524. {
  66525. return currentState->clipToRectangle (r);
  66526. }
  66527. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66528. {
  66529. return currentState->clipToRectangleList (clipRegion);
  66530. }
  66531. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66532. {
  66533. currentState->excludeClipRectangle (r);
  66534. }
  66535. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66536. {
  66537. currentState->clipToPath (path, transform);
  66538. }
  66539. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66540. {
  66541. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66542. }
  66543. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66544. {
  66545. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66546. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66547. }
  66548. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66549. {
  66550. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66551. }
  66552. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66553. {
  66554. return currentState->edgeTable->edgeTable.isEmpty();
  66555. }
  66556. void LowLevelGraphicsSoftwareRenderer::saveState()
  66557. {
  66558. stateStack.add (new LLGCSavedState (*currentState));
  66559. }
  66560. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66561. {
  66562. LLGCSavedState* const top = stateStack.getLast();
  66563. if (top != 0)
  66564. {
  66565. currentState = top;
  66566. stateStack.removeLast (1, false);
  66567. }
  66568. else
  66569. {
  66570. jassertfalse // trying to pop with an empty stack!
  66571. }
  66572. }
  66573. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66574. {
  66575. currentState->fillType = fillType;
  66576. }
  66577. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66578. {
  66579. currentState->fillType.setOpacity (newOpacity);
  66580. }
  66581. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66582. {
  66583. currentState->interpolationQuality = quality;
  66584. }
  66585. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66586. {
  66587. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66588. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66589. if (! clipped.isEmpty())
  66590. {
  66591. EdgeTable et (clipped);
  66592. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66593. }
  66594. }
  66595. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66596. {
  66597. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66598. path, transform.translated ((float) currentState->xOffset,
  66599. (float) currentState->yOffset));
  66600. currentState->fillEdgeTable (image, et);
  66601. }
  66602. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66603. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66604. {
  66605. jassert (sourceImage.getBounds().contains (srcClip));
  66606. currentState->renderImage (image, sourceImage, srcClip, transform,
  66607. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66608. }
  66609. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66610. {
  66611. Path p;
  66612. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66613. fillPath (p, AffineTransform::identity);
  66614. }
  66615. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66616. {
  66617. if (bottom > top)
  66618. {
  66619. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66620. currentState->fillEdgeTable (image, et);
  66621. }
  66622. }
  66623. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66624. {
  66625. if (right > left)
  66626. {
  66627. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66628. (float) (right - left), 1.0f);
  66629. currentState->fillEdgeTable (image, et);
  66630. }
  66631. }
  66632. class GlyphCache : private DeletedAtShutdown
  66633. {
  66634. public:
  66635. GlyphCache() throw()
  66636. : accessCounter (0), hits (0), misses (0)
  66637. {
  66638. for (int i = 120; --i >= 0;)
  66639. glyphs.add (new CachedGlyph());
  66640. }
  66641. ~GlyphCache() throw()
  66642. {
  66643. clearSingletonInstance();
  66644. }
  66645. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66646. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66647. {
  66648. ++accessCounter;
  66649. int oldestCounter = std::numeric_limits<int>::max();
  66650. CachedGlyph* oldest = 0;
  66651. for (int i = glyphs.size(); --i >= 0;)
  66652. {
  66653. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66654. if (glyph->glyph == glyphNumber && glyph->font == font)
  66655. {
  66656. ++hits;
  66657. glyph->lastAccessCount = accessCounter;
  66658. glyph->draw (state, image, x, y);
  66659. return;
  66660. }
  66661. if (glyph->lastAccessCount <= oldestCounter)
  66662. {
  66663. oldestCounter = glyph->lastAccessCount;
  66664. oldest = glyph;
  66665. }
  66666. }
  66667. if (hits + ++misses > (glyphs.size() << 4))
  66668. {
  66669. if (misses * 2 > hits)
  66670. {
  66671. for (int i = 32; --i >= 0;)
  66672. glyphs.add (new CachedGlyph());
  66673. }
  66674. hits = misses = 0;
  66675. oldest = glyphs.getLast();
  66676. }
  66677. jassert (oldest != 0);
  66678. oldest->lastAccessCount = accessCounter;
  66679. oldest->generate (font, glyphNumber);
  66680. oldest->draw (state, image, x, y);
  66681. }
  66682. class CachedGlyph
  66683. {
  66684. public:
  66685. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66686. ~CachedGlyph() {}
  66687. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66688. {
  66689. if (edgeTable != 0)
  66690. {
  66691. EdgeTable et (*edgeTable);
  66692. et.translate (x, roundToInt (y));
  66693. state.fillEdgeTable (image, et, false);
  66694. }
  66695. }
  66696. void generate (const Font& newFont, const int glyphNumber) throw()
  66697. {
  66698. font = newFont;
  66699. glyph = glyphNumber;
  66700. edgeTable = 0;
  66701. Path glyphPath;
  66702. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66703. if (! glyphPath.isEmpty())
  66704. {
  66705. const float fontHeight = font.getHeight();
  66706. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66707. .translated (0.0f, -0.5f));
  66708. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66709. glyphPath, transform);
  66710. }
  66711. }
  66712. int glyph, lastAccessCount;
  66713. Font font;
  66714. juce_UseDebuggingNewOperator
  66715. private:
  66716. ScopedPointer <EdgeTable> edgeTable;
  66717. CachedGlyph (const CachedGlyph&);
  66718. CachedGlyph& operator= (const CachedGlyph&);
  66719. };
  66720. juce_UseDebuggingNewOperator
  66721. private:
  66722. OwnedArray <CachedGlyph> glyphs;
  66723. int accessCounter, hits, misses;
  66724. GlyphCache (const GlyphCache&);
  66725. GlyphCache& operator= (const GlyphCache&);
  66726. };
  66727. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66728. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66729. {
  66730. currentState->font = newFont;
  66731. }
  66732. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66733. {
  66734. return currentState->font;
  66735. }
  66736. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66737. {
  66738. Font& f = currentState->font;
  66739. if (transform.isOnlyTranslation())
  66740. {
  66741. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66742. transform.getTranslationX() + (float) currentState->xOffset,
  66743. transform.getTranslationY() + (float) currentState->yOffset);
  66744. }
  66745. else
  66746. {
  66747. Path p;
  66748. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66749. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66750. }
  66751. }
  66752. #if JUCE_MSVC
  66753. #pragma warning (pop)
  66754. #if JUCE_DEBUG
  66755. #pragma optimize ("", on) // resets optimisations to the project defaults
  66756. #endif
  66757. #endif
  66758. END_JUCE_NAMESPACE
  66759. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66760. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66761. BEGIN_JUCE_NAMESPACE
  66762. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66763. : flags (other.flags)
  66764. {
  66765. }
  66766. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66767. {
  66768. flags = other.flags;
  66769. return *this;
  66770. }
  66771. void RectanglePlacement::applyTo (double& x, double& y,
  66772. double& w, double& h,
  66773. const double dx, const double dy,
  66774. const double dw, const double dh) const throw()
  66775. {
  66776. if (w == 0 || h == 0)
  66777. return;
  66778. if ((flags & stretchToFit) != 0)
  66779. {
  66780. x = dx;
  66781. y = dy;
  66782. w = dw;
  66783. h = dh;
  66784. }
  66785. else
  66786. {
  66787. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66788. : jmin (dw / w, dh / h);
  66789. if ((flags & onlyReduceInSize) != 0)
  66790. scale = jmin (scale, 1.0);
  66791. if ((flags & onlyIncreaseInSize) != 0)
  66792. scale = jmax (scale, 1.0);
  66793. w *= scale;
  66794. h *= scale;
  66795. if ((flags & xLeft) != 0)
  66796. x = dx;
  66797. else if ((flags & xRight) != 0)
  66798. x = dx + dw - w;
  66799. else
  66800. x = dx + (dw - w) * 0.5;
  66801. if ((flags & yTop) != 0)
  66802. y = dy;
  66803. else if ((flags & yBottom) != 0)
  66804. y = dy + dh - h;
  66805. else
  66806. y = dy + (dh - h) * 0.5;
  66807. }
  66808. }
  66809. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66810. float w, float h,
  66811. const float dx, const float dy,
  66812. const float dw, const float dh) const throw()
  66813. {
  66814. if (w == 0 || h == 0)
  66815. return AffineTransform::identity;
  66816. const float scaleX = dw / w;
  66817. const float scaleY = dh / h;
  66818. if ((flags & stretchToFit) != 0)
  66819. return AffineTransform::translation (-x, -y)
  66820. .scaled (scaleX, scaleY)
  66821. .translated (dx, dy);
  66822. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66823. : jmin (scaleX, scaleY);
  66824. if ((flags & onlyReduceInSize) != 0)
  66825. scale = jmin (scale, 1.0f);
  66826. if ((flags & onlyIncreaseInSize) != 0)
  66827. scale = jmax (scale, 1.0f);
  66828. w *= scale;
  66829. h *= scale;
  66830. float newX = dx;
  66831. if ((flags & xRight) != 0)
  66832. newX += dw - w; // right
  66833. else if ((flags & xLeft) == 0)
  66834. newX += (dw - w) / 2.0f; // centre
  66835. float newY = dy;
  66836. if ((flags & yBottom) != 0)
  66837. newY += dh - h; // bottom
  66838. else if ((flags & yTop) == 0)
  66839. newY += (dh - h) / 2.0f; // centre
  66840. return AffineTransform::translation (-x, -y)
  66841. .scaled (scale, scale)
  66842. .translated (newX, newY);
  66843. }
  66844. END_JUCE_NAMESPACE
  66845. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66846. /*** Start of inlined file: juce_Drawable.cpp ***/
  66847. BEGIN_JUCE_NAMESPACE
  66848. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66849. const AffineTransform& transform_,
  66850. const float opacity_) throw()
  66851. : g (g_),
  66852. transform (transform_),
  66853. opacity (opacity_)
  66854. {
  66855. }
  66856. Drawable::Drawable()
  66857. {
  66858. }
  66859. Drawable::~Drawable()
  66860. {
  66861. }
  66862. void Drawable::draw (Graphics& g, const float opacity,
  66863. const AffineTransform& transform) const
  66864. {
  66865. render (RenderingContext (g, transform, opacity));
  66866. }
  66867. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66868. {
  66869. draw (g, opacity, AffineTransform::translation (x, y));
  66870. }
  66871. void Drawable::drawWithin (Graphics& g,
  66872. const int destX,
  66873. const int destY,
  66874. const int destW,
  66875. const int destH,
  66876. const RectanglePlacement& placement,
  66877. const float opacity) const
  66878. {
  66879. if (destW > 0 && destH > 0)
  66880. {
  66881. Rectangle<float> bounds (getBounds());
  66882. draw (g, opacity,
  66883. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66884. (float) destX, (float) destY,
  66885. (float) destW, (float) destH));
  66886. }
  66887. }
  66888. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66889. {
  66890. Drawable* result = 0;
  66891. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66892. if (image != 0)
  66893. {
  66894. DrawableImage* const di = new DrawableImage();
  66895. di->setImage (image, true);
  66896. result = di;
  66897. }
  66898. else
  66899. {
  66900. const String asString (String::createStringFromData (data, (int) numBytes));
  66901. XmlDocument doc (asString);
  66902. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66903. if (outer != 0 && outer->hasTagName ("svg"))
  66904. {
  66905. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66906. if (svg != 0)
  66907. result = Drawable::createFromSVG (*svg);
  66908. }
  66909. }
  66910. return result;
  66911. }
  66912. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66913. {
  66914. MemoryBlock mb;
  66915. dataSource.readIntoMemoryBlock (mb);
  66916. return createFromImageData (mb.getData(), mb.getSize());
  66917. }
  66918. Drawable* Drawable::createFromImageFile (const File& file)
  66919. {
  66920. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66921. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66922. }
  66923. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66924. {
  66925. Drawable* d = DrawablePath::createFromValueTree (tree);
  66926. if (d == 0)
  66927. {
  66928. d = DrawableComposite::createFromValueTree (tree);
  66929. if (d == 0)
  66930. {
  66931. d = DrawableImage::createFromValueTree (tree);
  66932. if (d == 0)
  66933. d = DrawableText::createFromValueTree (tree);
  66934. }
  66935. }
  66936. return d;
  66937. }
  66938. END_JUCE_NAMESPACE
  66939. /*** End of inlined file: juce_Drawable.cpp ***/
  66940. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66941. BEGIN_JUCE_NAMESPACE
  66942. DrawableComposite::DrawableComposite()
  66943. {
  66944. }
  66945. DrawableComposite::~DrawableComposite()
  66946. {
  66947. }
  66948. void DrawableComposite::insertDrawable (Drawable* drawable,
  66949. const AffineTransform& transform,
  66950. const int index)
  66951. {
  66952. if (drawable != 0)
  66953. {
  66954. if (! drawables.contains (drawable))
  66955. {
  66956. drawables.insert (index, drawable);
  66957. if (transform.isIdentity())
  66958. transforms.insert (index, 0);
  66959. else
  66960. transforms.insert (index, new AffineTransform (transform));
  66961. }
  66962. else
  66963. {
  66964. jassertfalse // trying to add a drawable that's already in here!
  66965. }
  66966. }
  66967. }
  66968. void DrawableComposite::insertDrawable (const Drawable& drawable,
  66969. const AffineTransform& transform,
  66970. const int index)
  66971. {
  66972. insertDrawable (drawable.createCopy(), transform, index);
  66973. }
  66974. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  66975. {
  66976. drawables.remove (index, deleteDrawable);
  66977. transforms.remove (index);
  66978. }
  66979. void DrawableComposite::bringToFront (const int index)
  66980. {
  66981. if (index >= 0 && index < drawables.size() - 1)
  66982. {
  66983. drawables.move (index, -1);
  66984. transforms.move (index, -1);
  66985. }
  66986. }
  66987. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  66988. {
  66989. if (drawables.size() > 0 && context.opacity > 0)
  66990. {
  66991. if (context.opacity >= 1.0f || drawables.size() == 1)
  66992. {
  66993. Drawable::RenderingContext contextCopy (context);
  66994. for (int i = 0; i < drawables.size(); ++i)
  66995. {
  66996. const AffineTransform* const t = transforms.getUnchecked(i);
  66997. contextCopy.transform = (t == 0) ? context.transform
  66998. : t->followedBy (context.transform);
  66999. drawables.getUnchecked(i)->render (contextCopy);
  67000. }
  67001. }
  67002. else
  67003. {
  67004. // To correctly render a whole composite layer with an overall transparency,
  67005. // we need to render everything opaquely into a temp buffer, then blend that
  67006. // with the target opacity...
  67007. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67008. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67009. {
  67010. Graphics tempG (tempImage);
  67011. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67012. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67013. render (tempContext);
  67014. }
  67015. context.g.setOpacity (context.opacity);
  67016. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67017. }
  67018. }
  67019. }
  67020. const Rectangle<float> DrawableComposite::getBounds() const
  67021. {
  67022. Rectangle<float> bounds;
  67023. for (int i = 0; i < drawables.size(); ++i)
  67024. {
  67025. const Drawable* const d = drawables.getUnchecked(i);
  67026. const AffineTransform* const t = transforms.getUnchecked(i);
  67027. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  67028. : d->getBounds().transformed (*t));
  67029. if (bounds.isEmpty())
  67030. bounds = childBounds;
  67031. else if (! childBounds.isEmpty())
  67032. bounds = bounds.getUnion (childBounds);
  67033. }
  67034. return bounds;
  67035. }
  67036. bool DrawableComposite::hitTest (float x, float y) const
  67037. {
  67038. for (int i = 0; i < drawables.size(); ++i)
  67039. {
  67040. float tx = x;
  67041. float ty = y;
  67042. const AffineTransform* const t = transforms.getUnchecked(i);
  67043. if (t != 0)
  67044. t->inverted().transformPoint (tx, ty);
  67045. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67046. return true;
  67047. }
  67048. return false;
  67049. }
  67050. Drawable* DrawableComposite::createCopy() const
  67051. {
  67052. DrawableComposite* const dc = new DrawableComposite();
  67053. for (int i = 0; i < drawables.size(); ++i)
  67054. {
  67055. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67056. const AffineTransform* const t = transforms.getUnchecked(i);
  67057. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67058. }
  67059. return dc;
  67060. }
  67061. ValueTree DrawableComposite::createValueTree() const throw()
  67062. {
  67063. ValueTree v ("Group");
  67064. if (getName().isNotEmpty())
  67065. v.setProperty ("id", getName(), 0);
  67066. for (int i = 0; i < drawables.size(); ++i)
  67067. {
  67068. Drawable* const d = drawables.getUnchecked(i);
  67069. ValueTree child (d->createValueTree());
  67070. AffineTransform* transform = transforms.getUnchecked(i);
  67071. if (transform != 0)
  67072. {
  67073. String t;
  67074. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67075. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67076. child.setProperty ("transform", t, 0);
  67077. }
  67078. v.addChild (child, -1, 0);
  67079. }
  67080. return v;
  67081. }
  67082. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67083. {
  67084. if (! tree.hasType ("Group"))
  67085. return 0;
  67086. DrawableComposite* dc = new DrawableComposite();
  67087. dc->setName (tree ["id"]);
  67088. for (int i = 0; i < tree.getNumChildren(); ++i)
  67089. {
  67090. ValueTree childTree (tree.getChild (i));
  67091. Drawable* d = Drawable::createFromValueTree (childTree);
  67092. if (d != 0)
  67093. {
  67094. AffineTransform transform;
  67095. const String transformAtt (childTree ["transform"].toString());
  67096. if (transformAtt.isNotEmpty())
  67097. {
  67098. StringArray tokens;
  67099. tokens.addTokens (transformAtt.trim(), false);
  67100. tokens.removeEmptyStrings (true);
  67101. if (tokens.size() == 6)
  67102. {
  67103. float f[6];
  67104. for (int j = 0; j < 6; ++j)
  67105. f[j] = (float) tokens[j].getDoubleValue();
  67106. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67107. }
  67108. }
  67109. dc->insertDrawable (d, transform);
  67110. }
  67111. }
  67112. return dc;
  67113. }
  67114. END_JUCE_NAMESPACE
  67115. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67116. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67117. BEGIN_JUCE_NAMESPACE
  67118. DrawableImage::DrawableImage()
  67119. : image (0),
  67120. canDeleteImage (false),
  67121. opacity (1.0f),
  67122. overlayColour (0x00000000)
  67123. {
  67124. }
  67125. DrawableImage::~DrawableImage()
  67126. {
  67127. clearImage();
  67128. }
  67129. void DrawableImage::clearImage()
  67130. {
  67131. if (canDeleteImage && image != 0)
  67132. ImageCache::releaseOrDelete (image);
  67133. image = 0;
  67134. }
  67135. void DrawableImage::setImage (const Image& imageToCopy)
  67136. {
  67137. clearImage();
  67138. image = new Image (imageToCopy);
  67139. canDeleteImage = true;
  67140. }
  67141. void DrawableImage::setImage (Image* imageToUse,
  67142. const bool releaseWhenNotNeeded)
  67143. {
  67144. clearImage();
  67145. image = imageToUse;
  67146. canDeleteImage = releaseWhenNotNeeded;
  67147. }
  67148. void DrawableImage::setOpacity (const float newOpacity)
  67149. {
  67150. opacity = newOpacity;
  67151. }
  67152. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67153. {
  67154. overlayColour = newOverlayColour;
  67155. }
  67156. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67157. {
  67158. if (image != 0)
  67159. {
  67160. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67161. {
  67162. context.g.setOpacity (context.opacity * opacity);
  67163. context.g.drawImageTransformed (image, image->getBounds(),
  67164. context.transform, false);
  67165. }
  67166. if (! overlayColour.isTransparent())
  67167. {
  67168. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67169. context.g.drawImageTransformed (image, image->getBounds(),
  67170. context.transform, true);
  67171. }
  67172. }
  67173. }
  67174. const Rectangle<float> DrawableImage::getBounds() const
  67175. {
  67176. if (image == 0)
  67177. return Rectangle<float>();
  67178. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67179. }
  67180. bool DrawableImage::hitTest (float x, float y) const
  67181. {
  67182. return image != 0
  67183. && x >= 0.0f
  67184. && y >= 0.0f
  67185. && x < image->getWidth()
  67186. && y < image->getHeight()
  67187. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67188. }
  67189. Drawable* DrawableImage::createCopy() const
  67190. {
  67191. DrawableImage* const di = new DrawableImage();
  67192. di->opacity = opacity;
  67193. di->overlayColour = overlayColour;
  67194. if (image != 0)
  67195. {
  67196. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67197. {
  67198. di->setImage (*image);
  67199. }
  67200. else
  67201. {
  67202. ImageCache::incReferenceCount (image);
  67203. di->setImage (image, true);
  67204. }
  67205. }
  67206. return di;
  67207. }
  67208. ValueTree DrawableImage::createValueTree() const throw()
  67209. {
  67210. ValueTree v ("Image");
  67211. if (getName().isNotEmpty())
  67212. v.setProperty ("id", getName(), 0);
  67213. if (opacity < 1.0f)
  67214. v.setProperty ("opacity", (double) opacity, 0);
  67215. if (! overlayColour.isTransparent())
  67216. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67217. if (image != 0)
  67218. {
  67219. MemoryOutputStream imageData;
  67220. PNGImageFormat pngFormat;
  67221. if (pngFormat.writeImageToStream (*image, imageData))
  67222. {
  67223. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67224. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67225. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67226. v.setProperty ("data", base64, 0);
  67227. }
  67228. }
  67229. return v;
  67230. }
  67231. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67232. {
  67233. if (! tree.hasType ("Image"))
  67234. return 0;
  67235. DrawableImage* di = new DrawableImage();
  67236. di->setName (tree ["id"]);
  67237. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67238. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67239. MemoryBlock imageData;
  67240. if (imageData.fromBase64Encoding (tree ["data"]))
  67241. {
  67242. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67243. if (im == 0)
  67244. return false;
  67245. di->setImage (im, true);
  67246. }
  67247. return di;
  67248. }
  67249. END_JUCE_NAMESPACE
  67250. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67251. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67252. BEGIN_JUCE_NAMESPACE
  67253. DrawablePath::DrawablePath()
  67254. : mainFill (Colours::black),
  67255. strokeFill (Colours::transparentBlack),
  67256. strokeType (0.0f)
  67257. {
  67258. }
  67259. DrawablePath::~DrawablePath()
  67260. {
  67261. }
  67262. void DrawablePath::setPath (const Path& newPath) throw()
  67263. {
  67264. path = newPath;
  67265. updateOutline();
  67266. }
  67267. void DrawablePath::setFill (const FillType& newFill) throw()
  67268. {
  67269. mainFill = newFill;
  67270. }
  67271. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67272. {
  67273. strokeFill = newFill;
  67274. }
  67275. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67276. {
  67277. strokeType = newStrokeType;
  67278. updateOutline();
  67279. }
  67280. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67281. {
  67282. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67283. }
  67284. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67285. {
  67286. {
  67287. FillType f (mainFill);
  67288. if (f.isGradient())
  67289. f.gradient->multiplyOpacity (context.opacity);
  67290. f.transform = f.transform.followedBy (context.transform);
  67291. context.g.setFillType (f);
  67292. context.g.fillPath (path, context.transform);
  67293. }
  67294. if (strokeType.getStrokeThickness() > 0.0f)
  67295. {
  67296. FillType f (strokeFill);
  67297. if (f.isGradient())
  67298. f.gradient->multiplyOpacity (context.opacity);
  67299. f.transform = f.transform.followedBy (context.transform);
  67300. context.g.setFillType (f);
  67301. context.g.fillPath (stroke, context.transform);
  67302. }
  67303. }
  67304. void DrawablePath::updateOutline()
  67305. {
  67306. stroke.clear();
  67307. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67308. }
  67309. const Rectangle<float> DrawablePath::getBounds() const
  67310. {
  67311. if (strokeType.getStrokeThickness() > 0.0f)
  67312. return stroke.getBounds();
  67313. else
  67314. return path.getBounds();
  67315. }
  67316. bool DrawablePath::hitTest (float x, float y) const
  67317. {
  67318. return path.contains (x, y)
  67319. || stroke.contains (x, y);
  67320. }
  67321. Drawable* DrawablePath::createCopy() const
  67322. {
  67323. DrawablePath* const dp = new DrawablePath();
  67324. dp->path = path;
  67325. dp->stroke = stroke;
  67326. dp->mainFill = mainFill;
  67327. dp->strokeFill = strokeFill;
  67328. dp->strokeType = strokeType;
  67329. return dp;
  67330. }
  67331. static const FillType readFillTypeFromTree (const ValueTree& v)
  67332. {
  67333. const String type (v["type"].toString());
  67334. if (type.equalsIgnoreCase ("solid"))
  67335. {
  67336. const String colour (v ["colour"].toString());
  67337. return Colour (colour.isEmpty() ? (uint32) 0xff000000
  67338. : (uint32) colour.getHexValue32());
  67339. }
  67340. else if (type.equalsIgnoreCase ("gradient"))
  67341. {
  67342. ColourGradient g;
  67343. g.x1 = v["x1"];
  67344. g.y1 = v["y1"];
  67345. g.x2 = v["x2"];
  67346. g.y2 = v["y2"];
  67347. g.isRadial = v["radial"];
  67348. StringArray colours;
  67349. colours.addTokens (v["colours"].toString(), false);
  67350. for (int i = 0; i < colours.size() / 2; ++i)
  67351. g.addColour (colours[i * 2].getDoubleValue(),
  67352. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67353. return g;
  67354. }
  67355. jassertfalse
  67356. return FillType();
  67357. }
  67358. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67359. {
  67360. ValueTree v (tagName);
  67361. if (fillType.isColour())
  67362. {
  67363. v.setProperty ("type", "solid", 0);
  67364. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67365. }
  67366. else if (fillType.isGradient())
  67367. {
  67368. v.setProperty ("type", "gradient", 0);
  67369. v.setProperty ("x1", fillType.gradient->x1, 0);
  67370. v.setProperty ("y1", fillType.gradient->y1, 0);
  67371. v.setProperty ("x2", fillType.gradient->x2, 0);
  67372. v.setProperty ("y2", fillType.gradient->y2, 0);
  67373. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67374. String s;
  67375. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67376. s << " " << fillType.gradient->getColourPosition (i)
  67377. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67378. v.setProperty ("colours", s.trimStart(), 0);
  67379. }
  67380. else
  67381. {
  67382. jassertfalse //xxx
  67383. }
  67384. return v;
  67385. }
  67386. ValueTree DrawablePath::createValueTree() const throw()
  67387. {
  67388. ValueTree v ("Path");
  67389. v.addChild (createTreeForFillType ("fill", mainFill), -1, 0);
  67390. v.addChild (createTreeForFillType ("stroke", strokeFill), -1, 0);
  67391. if (getName().isNotEmpty())
  67392. v.setProperty ("id", getName(), 0);
  67393. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67394. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67395. ? "miter" : (strokeType.getJointStyle() == PathStrokeType::curved ? "curved" : "bevel"), 0);
  67396. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67397. ? "butt" : (strokeType.getEndStyle() == PathStrokeType::square ? "square" : "round"), 0);
  67398. v.setProperty ("path", path.toString(), 0);
  67399. return v;
  67400. }
  67401. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67402. {
  67403. if (! tree.hasType ("Path"))
  67404. return 0;
  67405. DrawablePath* p = new DrawablePath();
  67406. p->setName (tree ["id"]);
  67407. p->mainFill = readFillTypeFromTree (tree.getChildWithName ("fill"));
  67408. p->strokeFill = readFillTypeFromTree (tree.getChildWithName ("stroke"));
  67409. const String jointStyle (tree ["jointStyle"].toString());
  67410. const String endStyle (tree ["capStyle"].toString());
  67411. p->strokeType
  67412. = PathStrokeType (tree ["strokeWidth"],
  67413. jointStyle.equalsIgnoreCase ("curved") ? PathStrokeType::curved
  67414. : (jointStyle.equalsIgnoreCase ("bevel") ? PathStrokeType::beveled
  67415. : PathStrokeType::mitered),
  67416. endStyle.equalsIgnoreCase ("square") ? PathStrokeType::square
  67417. : (endStyle.equalsIgnoreCase ("round") ? PathStrokeType::rounded
  67418. : PathStrokeType::butt));
  67419. p->path.clear();
  67420. p->path.restoreFromString (tree ["path"]);
  67421. p->updateOutline();
  67422. return p;
  67423. }
  67424. END_JUCE_NAMESPACE
  67425. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67426. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67427. BEGIN_JUCE_NAMESPACE
  67428. DrawableText::DrawableText()
  67429. : colour (Colours::white)
  67430. {
  67431. }
  67432. DrawableText::~DrawableText()
  67433. {
  67434. }
  67435. void DrawableText::setText (const GlyphArrangement& newText)
  67436. {
  67437. text = newText;
  67438. }
  67439. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67440. {
  67441. text.clear();
  67442. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67443. }
  67444. void DrawableText::setColour (const Colour& newColour)
  67445. {
  67446. colour = newColour;
  67447. }
  67448. void DrawableText::render (const Drawable::RenderingContext& context) const
  67449. {
  67450. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67451. text.draw (context.g, context.transform);
  67452. }
  67453. const Rectangle<float> DrawableText::getBounds() const
  67454. {
  67455. return text.getBoundingBox (0, -1, false);
  67456. }
  67457. bool DrawableText::hitTest (float x, float y) const
  67458. {
  67459. return text.findGlyphIndexAt (x, y) >= 0;
  67460. }
  67461. Drawable* DrawableText::createCopy() const
  67462. {
  67463. DrawableText* const dt = new DrawableText();
  67464. dt->text = text;
  67465. dt->colour = colour;
  67466. return dt;
  67467. }
  67468. ValueTree DrawableText::createValueTree() const throw()
  67469. {
  67470. ValueTree v ("Text");
  67471. if (getName().isNotEmpty())
  67472. v.setProperty ("id", getName(), 0);
  67473. jassertfalse // xxx not finished!
  67474. return v;
  67475. }
  67476. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67477. {
  67478. if (! tree.hasType ("Text"))
  67479. return 0;
  67480. DrawableText* dt = new DrawableText();
  67481. dt->setName (tree ["id"]);
  67482. jassertfalse // xxx not finished!
  67483. return dt;
  67484. }
  67485. END_JUCE_NAMESPACE
  67486. /*** End of inlined file: juce_DrawableText.cpp ***/
  67487. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67488. BEGIN_JUCE_NAMESPACE
  67489. class SVGState
  67490. {
  67491. public:
  67492. SVGState (const XmlElement* const topLevel)
  67493. : topLevelXml (topLevel),
  67494. elementX (0), elementY (0),
  67495. width (512), height (512),
  67496. viewBoxW (0), viewBoxH (0)
  67497. {
  67498. }
  67499. ~SVGState()
  67500. {
  67501. }
  67502. Drawable* parseSVGElement (const XmlElement& xml)
  67503. {
  67504. if (! xml.hasTagName ("svg"))
  67505. return 0;
  67506. DrawableComposite* const drawable = new DrawableComposite();
  67507. drawable->setName (xml.getStringAttribute ("id"));
  67508. SVGState newState (*this);
  67509. if (xml.hasAttribute ("transform"))
  67510. newState.addTransform (xml);
  67511. newState.elementX = getCoordLength (xml.getStringAttribute ("x", String (newState.elementX)), viewBoxW);
  67512. newState.elementY = getCoordLength (xml.getStringAttribute ("y", String (newState.elementY)), viewBoxH);
  67513. newState.width = getCoordLength (xml.getStringAttribute ("width", String (newState.width)), viewBoxW);
  67514. newState.height = getCoordLength (xml.getStringAttribute ("height", String (newState.height)), viewBoxH);
  67515. if (xml.hasAttribute ("viewBox"))
  67516. {
  67517. const String viewParams (xml.getStringAttribute ("viewBox"));
  67518. int i = 0;
  67519. float vx, vy, vw, vh;
  67520. if (parseCoords (viewParams, vx, vy, i, true)
  67521. && parseCoords (viewParams, vw, vh, i, true)
  67522. && vw > 0
  67523. && vh > 0)
  67524. {
  67525. newState.viewBoxW = vw;
  67526. newState.viewBoxH = vh;
  67527. int placementFlags = 0;
  67528. const String aspect (xml.getStringAttribute ("preserveAspectRatio"));
  67529. if (aspect.containsIgnoreCase ("none"))
  67530. {
  67531. placementFlags = RectanglePlacement::stretchToFit;
  67532. }
  67533. else
  67534. {
  67535. if (aspect.containsIgnoreCase ("slice"))
  67536. placementFlags |= RectanglePlacement::fillDestination;
  67537. if (aspect.containsIgnoreCase ("xMin"))
  67538. placementFlags |= RectanglePlacement::xLeft;
  67539. else if (aspect.containsIgnoreCase ("xMax"))
  67540. placementFlags |= RectanglePlacement::xRight;
  67541. else
  67542. placementFlags |= RectanglePlacement::xMid;
  67543. if (aspect.containsIgnoreCase ("yMin"))
  67544. placementFlags |= RectanglePlacement::yTop;
  67545. else if (aspect.containsIgnoreCase ("yMax"))
  67546. placementFlags |= RectanglePlacement::yBottom;
  67547. else
  67548. placementFlags |= RectanglePlacement::yMid;
  67549. }
  67550. const RectanglePlacement placement (placementFlags);
  67551. newState.transform
  67552. = placement.getTransformToFit (vx, vy, vw, vh,
  67553. 0.0f, 0.0f, newState.width, newState.height)
  67554. .followedBy (newState.transform);
  67555. }
  67556. }
  67557. else
  67558. {
  67559. if (viewBoxW == 0)
  67560. newState.viewBoxW = newState.width;
  67561. if (viewBoxH == 0)
  67562. newState.viewBoxH = newState.height;
  67563. }
  67564. newState.parseSubElements (xml, drawable);
  67565. return drawable;
  67566. }
  67567. private:
  67568. const XmlElement* const topLevelXml;
  67569. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67570. AffineTransform transform;
  67571. String cssStyleText;
  67572. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67573. {
  67574. forEachXmlChildElement (xml, e)
  67575. {
  67576. Drawable* d = 0;
  67577. if (e->hasTagName ("g"))
  67578. d = parseGroupElement (*e);
  67579. else if (e->hasTagName ("svg"))
  67580. d = parseSVGElement (*e);
  67581. else if (e->hasTagName ("path"))
  67582. d = parsePath (*e);
  67583. else if (e->hasTagName ("rect"))
  67584. d = parseRect (*e);
  67585. else if (e->hasTagName ("circle"))
  67586. d = parseCircle (*e);
  67587. else if (e->hasTagName ("ellipse"))
  67588. d = parseEllipse (*e);
  67589. else if (e->hasTagName ("line"))
  67590. d = parseLine (*e);
  67591. else if (e->hasTagName ("polyline"))
  67592. d = parsePolygon (*e, true);
  67593. else if (e->hasTagName ("polygon"))
  67594. d = parsePolygon (*e, false);
  67595. else if (e->hasTagName ("text"))
  67596. d = parseText (*e);
  67597. else if (e->hasTagName ("switch"))
  67598. d = parseSwitch (*e);
  67599. else if (e->hasTagName ("style"))
  67600. parseCSSStyle (*e);
  67601. parentDrawable->insertDrawable (d);
  67602. }
  67603. }
  67604. DrawableComposite* parseSwitch (const XmlElement& xml)
  67605. {
  67606. const XmlElement* const group = xml.getChildByName ("g");
  67607. if (group != 0)
  67608. return parseGroupElement (*group);
  67609. return 0;
  67610. }
  67611. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67612. {
  67613. DrawableComposite* const drawable = new DrawableComposite();
  67614. drawable->setName (xml.getStringAttribute ("id"));
  67615. if (xml.hasAttribute ("transform"))
  67616. {
  67617. SVGState newState (*this);
  67618. newState.addTransform (xml);
  67619. newState.parseSubElements (xml, drawable);
  67620. }
  67621. else
  67622. {
  67623. parseSubElements (xml, drawable);
  67624. }
  67625. return drawable;
  67626. }
  67627. Drawable* parsePath (const XmlElement& xml) const
  67628. {
  67629. const String d (xml.getStringAttribute ("d").trimStart());
  67630. Path path;
  67631. if (getStyleAttribute (&xml, "fill-rule").trim().equalsIgnoreCase ("evenodd"))
  67632. path.setUsingNonZeroWinding (false);
  67633. int index = 0;
  67634. float lastX = 0, lastY = 0;
  67635. float lastX2 = 0, lastY2 = 0;
  67636. juce_wchar lastCommandChar = 0;
  67637. bool isRelative = true;
  67638. bool carryOn = true;
  67639. const String validCommandChars ("MmLlHhVvCcSsQqTtAaZz");
  67640. while (d[index] != 0)
  67641. {
  67642. float x, y, x2, y2, x3, y3;
  67643. if (validCommandChars.containsChar (d[index]))
  67644. {
  67645. lastCommandChar = d [index++];
  67646. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67647. }
  67648. switch (lastCommandChar)
  67649. {
  67650. case 'M':
  67651. case 'm':
  67652. case 'L':
  67653. case 'l':
  67654. if (parseCoords (d, x, y, index, false))
  67655. {
  67656. if (isRelative)
  67657. {
  67658. x += lastX;
  67659. y += lastY;
  67660. }
  67661. if (lastCommandChar == 'M' || lastCommandChar == 'm')
  67662. {
  67663. path.startNewSubPath (x, y);
  67664. lastCommandChar = 'l';
  67665. }
  67666. else
  67667. path.lineTo (x, y);
  67668. lastX2 = lastX;
  67669. lastY2 = lastY;
  67670. lastX = x;
  67671. lastY = y;
  67672. }
  67673. else
  67674. {
  67675. ++index;
  67676. }
  67677. break;
  67678. case 'H':
  67679. case 'h':
  67680. if (parseCoord (d, x, index, false, true))
  67681. {
  67682. if (isRelative)
  67683. x += lastX;
  67684. path.lineTo (x, lastY);
  67685. lastX2 = lastX;
  67686. lastX = x;
  67687. }
  67688. else
  67689. {
  67690. ++index;
  67691. }
  67692. break;
  67693. case 'V':
  67694. case 'v':
  67695. if (parseCoord (d, y, index, false, false))
  67696. {
  67697. if (isRelative)
  67698. y += lastY;
  67699. path.lineTo (lastX, y);
  67700. lastY2 = lastY;
  67701. lastY = y;
  67702. }
  67703. else
  67704. {
  67705. ++index;
  67706. }
  67707. break;
  67708. case 'C':
  67709. case 'c':
  67710. if (parseCoords (d, x, y, index, false)
  67711. && parseCoords (d, x2, y2, index, false)
  67712. && parseCoords (d, x3, y3, index, false))
  67713. {
  67714. if (isRelative)
  67715. {
  67716. x += lastX;
  67717. y += lastY;
  67718. x2 += lastX;
  67719. y2 += lastY;
  67720. x3 += lastX;
  67721. y3 += lastY;
  67722. }
  67723. path.cubicTo (x, y, x2, y2, x3, y3);
  67724. lastX2 = x2;
  67725. lastY2 = y2;
  67726. lastX = x3;
  67727. lastY = y3;
  67728. }
  67729. else
  67730. {
  67731. ++index;
  67732. }
  67733. break;
  67734. case 'S':
  67735. case 's':
  67736. if (parseCoords (d, x, y, index, false)
  67737. && parseCoords (d, x3, y3, index, false))
  67738. {
  67739. if (isRelative)
  67740. {
  67741. x += lastX;
  67742. y += lastY;
  67743. x3 += lastX;
  67744. y3 += lastY;
  67745. }
  67746. x2 = lastX + (lastX - lastX2);
  67747. y2 = lastY + (lastY - lastY2);
  67748. path.cubicTo (x2, y2, x, y, x3, y3);
  67749. lastX2 = x;
  67750. lastY2 = y;
  67751. lastX = x3;
  67752. lastY = y3;
  67753. }
  67754. else
  67755. {
  67756. ++index;
  67757. }
  67758. break;
  67759. case 'Q':
  67760. case 'q':
  67761. if (parseCoords (d, x, y, index, false)
  67762. && parseCoords (d, x2, y2, index, false))
  67763. {
  67764. if (isRelative)
  67765. {
  67766. x += lastX;
  67767. y += lastY;
  67768. x2 += lastX;
  67769. y2 += lastY;
  67770. }
  67771. path.quadraticTo (x, y, x2, y2);
  67772. lastX2 = x;
  67773. lastY2 = y;
  67774. lastX = x2;
  67775. lastY = y2;
  67776. }
  67777. else
  67778. {
  67779. ++index;
  67780. }
  67781. break;
  67782. case 'T':
  67783. case 't':
  67784. if (parseCoords (d, x, y, index, false))
  67785. {
  67786. if (isRelative)
  67787. {
  67788. x += lastX;
  67789. y += lastY;
  67790. }
  67791. x2 = lastX + (lastX - lastX2);
  67792. y2 = lastY + (lastY - lastY2);
  67793. path.quadraticTo (x2, y2, x, y);
  67794. lastX2 = x2;
  67795. lastY2 = y2;
  67796. lastX = x;
  67797. lastY = y;
  67798. }
  67799. else
  67800. {
  67801. ++index;
  67802. }
  67803. break;
  67804. case 'A':
  67805. case 'a':
  67806. if (parseCoords (d, x, y, index, false))
  67807. {
  67808. String num;
  67809. if (parseNextNumber (d, num, index, false))
  67810. {
  67811. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67812. if (parseNextNumber (d, num, index, false))
  67813. {
  67814. const bool largeArc = num.getIntValue() != 0;
  67815. if (parseNextNumber (d, num, index, false))
  67816. {
  67817. const bool sweep = num.getIntValue() != 0;
  67818. if (parseCoords (d, x2, y2, index, false))
  67819. {
  67820. if (isRelative)
  67821. {
  67822. x2 += lastX;
  67823. y2 += lastY;
  67824. }
  67825. if (lastX != x2 || lastY != y2)
  67826. {
  67827. double centreX, centreY, startAngle, deltaAngle;
  67828. double rx = x, ry = y;
  67829. endpointToCentreParameters (lastX, lastY, x2, y2,
  67830. angle, largeArc, sweep,
  67831. rx, ry, centreX, centreY,
  67832. startAngle, deltaAngle);
  67833. path.addCentredArc ((float) centreX, (float) centreY,
  67834. (float) rx, (float) ry,
  67835. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67836. false);
  67837. path.lineTo (x2, y2);
  67838. }
  67839. lastX2 = lastX;
  67840. lastY2 = lastY;
  67841. lastX = x2;
  67842. lastY = y2;
  67843. }
  67844. }
  67845. }
  67846. }
  67847. }
  67848. else
  67849. {
  67850. ++index;
  67851. }
  67852. break;
  67853. case 'Z':
  67854. case 'z':
  67855. path.closeSubPath();
  67856. while (CharacterFunctions::isWhitespace (d [index]))
  67857. ++index;
  67858. break;
  67859. default:
  67860. carryOn = false;
  67861. break;
  67862. }
  67863. if (! carryOn)
  67864. break;
  67865. }
  67866. return parseShape (xml, path);
  67867. }
  67868. Drawable* parseRect (const XmlElement& xml) const
  67869. {
  67870. Path rect;
  67871. const bool hasRX = xml.hasAttribute ("rx");
  67872. const bool hasRY = xml.hasAttribute ("ry");
  67873. if (hasRX || hasRY)
  67874. {
  67875. float rx = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67876. float ry = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67877. if (! hasRX)
  67878. rx = ry;
  67879. else if (! hasRY)
  67880. ry = rx;
  67881. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67882. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67883. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67884. getCoordLength (xml.getStringAttribute ("height"), viewBoxH),
  67885. rx, ry);
  67886. }
  67887. else
  67888. {
  67889. rect.addRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67890. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67891. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67892. getCoordLength (xml.getStringAttribute ("height"), viewBoxH));
  67893. }
  67894. return parseShape (xml, rect);
  67895. }
  67896. Drawable* parseCircle (const XmlElement& xml) const
  67897. {
  67898. Path circle;
  67899. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67900. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67901. const float radius = getCoordLength (xml.getStringAttribute ("r"), viewBoxW);
  67902. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67903. return parseShape (xml, circle);
  67904. }
  67905. Drawable* parseEllipse (const XmlElement& xml) const
  67906. {
  67907. Path ellipse;
  67908. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67909. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67910. const float radiusX = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67911. const float radiusY = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67912. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67913. return parseShape (xml, ellipse);
  67914. }
  67915. Drawable* parseLine (const XmlElement& xml) const
  67916. {
  67917. Path line;
  67918. const float x1 = getCoordLength (xml.getStringAttribute ("x1"), viewBoxW);
  67919. const float y1 = getCoordLength (xml.getStringAttribute ("y1"), viewBoxH);
  67920. const float x2 = getCoordLength (xml.getStringAttribute ("x2"), viewBoxW);
  67921. const float y2 = getCoordLength (xml.getStringAttribute ("y2"), viewBoxH);
  67922. line.startNewSubPath (x1, y1);
  67923. line.lineTo (x2, y2);
  67924. return parseShape (xml, line);
  67925. }
  67926. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67927. {
  67928. const String points (xml.getStringAttribute ("points"));
  67929. Path path;
  67930. int index = 0;
  67931. float x, y;
  67932. if (parseCoords (points, x, y, index, true))
  67933. {
  67934. float firstX = x;
  67935. float firstY = y;
  67936. float lastX = 0, lastY = 0;
  67937. path.startNewSubPath (x, y);
  67938. while (parseCoords (points, x, y, index, true))
  67939. {
  67940. lastX = x;
  67941. lastY = y;
  67942. path.lineTo (x, y);
  67943. }
  67944. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67945. path.closeSubPath();
  67946. }
  67947. return parseShape (xml, path);
  67948. }
  67949. Drawable* parseShape (const XmlElement& xml, Path& path,
  67950. const bool shouldParseTransform = true) const
  67951. {
  67952. if (shouldParseTransform && xml.hasAttribute ("transform"))
  67953. {
  67954. SVGState newState (*this);
  67955. newState.addTransform (xml);
  67956. return newState.parseShape (xml, path, false);
  67957. }
  67958. DrawablePath* dp = new DrawablePath();
  67959. dp->setName (xml.getStringAttribute ("id"));
  67960. dp->setFill (Colours::transparentBlack);
  67961. path.applyTransform (transform);
  67962. dp->setPath (path);
  67963. Path::Iterator iter (path);
  67964. bool containsClosedSubPath = false;
  67965. while (iter.next())
  67966. {
  67967. if (iter.elementType == Path::Iterator::closePath)
  67968. {
  67969. containsClosedSubPath = true;
  67970. break;
  67971. }
  67972. }
  67973. dp->setFill (getPathFillType (path,
  67974. getStyleAttribute (&xml, "fill"),
  67975. getStyleAttribute (&xml, "fill-opacity"),
  67976. getStyleAttribute (&xml, "opacity"),
  67977. containsClosedSubPath ? Colours::black
  67978. : Colours::transparentBlack));
  67979. const String strokeType (getStyleAttribute (&xml, "stroke"));
  67980. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase ("none"))
  67981. {
  67982. dp->setStrokeFill (getPathFillType (path, strokeType,
  67983. getStyleAttribute (&xml, "stroke-opacity"),
  67984. getStyleAttribute (&xml, "opacity"),
  67985. Colours::transparentBlack));
  67986. dp->setStrokeType (getStrokeFor (&xml));
  67987. }
  67988. return dp;
  67989. }
  67990. const XmlElement* findLinkedElement (const XmlElement* e) const
  67991. {
  67992. const String id (e->getStringAttribute ("xlink:href"));
  67993. if (! id.startsWithChar ('#'))
  67994. return 0;
  67995. return findElementForId (topLevelXml, id.substring (1));
  67996. }
  67997. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  67998. {
  67999. if (fillXml == 0)
  68000. return;
  68001. forEachXmlChildElementWithTagName (*fillXml, e, "stop")
  68002. {
  68003. int index = 0;
  68004. Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
  68005. const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
  68006. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68007. double offset = e->getDoubleAttribute ("offset");
  68008. if (e->getStringAttribute ("offset").containsChar ('%'))
  68009. offset *= 0.01;
  68010. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68011. }
  68012. }
  68013. const FillType getPathFillType (const Path& path,
  68014. const String& fill,
  68015. const String& fillOpacity,
  68016. const String& overallOpacity,
  68017. const Colour& defaultColour) const
  68018. {
  68019. float opacity = 1.0f;
  68020. if (overallOpacity.isNotEmpty())
  68021. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68022. if (fillOpacity.isNotEmpty())
  68023. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68024. if (fill.startsWithIgnoreCase ("url"))
  68025. {
  68026. const String id (fill.fromFirstOccurrenceOf ("#", false, false)
  68027. .upToLastOccurrenceOf (")", false, false).trim());
  68028. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68029. if (fillXml != 0
  68030. && (fillXml->hasTagName ("linearGradient")
  68031. || fillXml->hasTagName ("radialGradient")))
  68032. {
  68033. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68034. ColourGradient gradient;
  68035. addGradientStopsIn (gradient, inheritedFrom);
  68036. addGradientStopsIn (gradient, fillXml);
  68037. if (gradient.getNumColours() > 0)
  68038. {
  68039. gradient.addColour (0.0, gradient.getColour (0));
  68040. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68041. }
  68042. else
  68043. {
  68044. gradient.addColour (0.0, Colours::black);
  68045. gradient.addColour (1.0, Colours::black);
  68046. }
  68047. if (overallOpacity.isNotEmpty())
  68048. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68049. jassert (gradient.getNumColours() > 0);
  68050. gradient.isRadial = fillXml->hasTagName ("radialGradient");
  68051. float width = viewBoxW;
  68052. float height = viewBoxH;
  68053. float dx = 0.0f;
  68054. float dy = 0.0f;
  68055. const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
  68056. if (! userSpace)
  68057. {
  68058. const Rectangle<float> bounds (path.getBounds());
  68059. dx = bounds.getX();
  68060. dy = bounds.getY();
  68061. width = bounds.getWidth();
  68062. height = bounds.getHeight();
  68063. }
  68064. if (gradient.isRadial)
  68065. {
  68066. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), width);
  68067. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), height);
  68068. const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), width);
  68069. gradient.x2 = gradient.x1 + radius;
  68070. gradient.y2 = gradient.y1;
  68071. //xxx (the fx, fy focal point isn't handled properly here..)
  68072. }
  68073. else
  68074. {
  68075. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), width);
  68076. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), height);
  68077. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), width);
  68078. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), height);
  68079. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68080. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68081. }
  68082. FillType type (gradient);
  68083. type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
  68084. .followedBy (transform);
  68085. return type;
  68086. }
  68087. }
  68088. if (fill.equalsIgnoreCase ("none"))
  68089. return Colours::transparentBlack;
  68090. int i = 0;
  68091. const Colour colour (parseColour (fill, i, defaultColour));
  68092. return colour.withMultipliedAlpha (opacity);
  68093. }
  68094. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68095. {
  68096. const String width (getStyleAttribute (xml, "stroke-width"));
  68097. const String cap (getStyleAttribute (xml, "stroke-linecap"));
  68098. const String join (getStyleAttribute (xml, "stroke-linejoin"));
  68099. //const String mitreLimit (getStyleAttribute (xml, "stroke-miterlimit"));
  68100. //const String dashArray (getStyleAttribute (xml, "stroke-dasharray"));
  68101. //const String dashOffset (getStyleAttribute (xml, "stroke-dashoffset"));
  68102. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68103. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68104. if (join.equalsIgnoreCase ("round"))
  68105. joinStyle = PathStrokeType::curved;
  68106. else if (join.equalsIgnoreCase ("bevel"))
  68107. joinStyle = PathStrokeType::beveled;
  68108. if (cap.equalsIgnoreCase ("round"))
  68109. capStyle = PathStrokeType::rounded;
  68110. else if (cap.equalsIgnoreCase ("square"))
  68111. capStyle = PathStrokeType::square;
  68112. float ox = 0.0f, oy = 0.0f;
  68113. transform.transformPoint (ox, oy);
  68114. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68115. transform.transformPoint (x, y);
  68116. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68117. joinStyle, capStyle);
  68118. }
  68119. Drawable* parseText (const XmlElement& xml)
  68120. {
  68121. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68122. getCoordList (xCoords, getInheritedAttribute (&xml, "x"), true, true);
  68123. getCoordList (yCoords, getInheritedAttribute (&xml, "y"), true, false);
  68124. getCoordList (dxCoords, getInheritedAttribute (&xml, "dx"), true, true);
  68125. getCoordList (dyCoords, getInheritedAttribute (&xml, "dy"), true, false);
  68126. //xxx not done text yet!
  68127. forEachXmlChildElement (xml, e)
  68128. {
  68129. if (e->isTextElement())
  68130. {
  68131. const String text (e->getText());
  68132. Path path;
  68133. Drawable* s = parseShape (*e, path);
  68134. delete s;
  68135. }
  68136. else if (e->hasTagName ("tspan"))
  68137. {
  68138. Drawable* s = parseText (*e);
  68139. delete s;
  68140. }
  68141. }
  68142. return 0;
  68143. }
  68144. void addTransform (const XmlElement& xml)
  68145. {
  68146. transform = parseTransform (xml.getStringAttribute ("transform"))
  68147. .followedBy (transform);
  68148. }
  68149. bool parseCoord (const String& s, float& value, int& index,
  68150. const bool allowUnits, const bool isX) const
  68151. {
  68152. String number;
  68153. if (! parseNextNumber (s, number, index, allowUnits))
  68154. {
  68155. value = 0;
  68156. return false;
  68157. }
  68158. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68159. return true;
  68160. }
  68161. bool parseCoords (const String& s, float& x, float& y,
  68162. int& index, const bool allowUnits) const
  68163. {
  68164. return parseCoord (s, x, index, allowUnits, true)
  68165. && parseCoord (s, y, index, allowUnits, false);
  68166. }
  68167. float getCoordLength (const String& s, const float sizeForProportions) const
  68168. {
  68169. float n = s.getFloatValue();
  68170. const int len = s.length();
  68171. if (len > 2)
  68172. {
  68173. const float dpi = 96.0f;
  68174. const juce_wchar n1 = s [len - 2];
  68175. const juce_wchar n2 = s [len - 1];
  68176. if (n1 == 'i' && n2 == 'n')
  68177. n *= dpi;
  68178. else if (n1 == 'm' && n2 == 'm')
  68179. n *= dpi / 25.4f;
  68180. else if (n1 == 'c' && n2 == 'm')
  68181. n *= dpi / 2.54f;
  68182. else if (n1 == 'p' && n2 == 'c')
  68183. n *= 15.0f;
  68184. else if (n2 == '%')
  68185. n *= 0.01f * sizeForProportions;
  68186. }
  68187. return n;
  68188. }
  68189. void getCoordList (Array <float>& coords, const String& list,
  68190. const bool allowUnits, const bool isX) const
  68191. {
  68192. int index = 0;
  68193. float value;
  68194. while (parseCoord (list, value, index, allowUnits, isX))
  68195. coords.add (value);
  68196. }
  68197. void parseCSSStyle (const XmlElement& xml)
  68198. {
  68199. cssStyleText = xml.getAllSubText() + "\n" + cssStyleText;
  68200. }
  68201. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68202. const String& defaultValue = String::empty) const
  68203. {
  68204. if (xml->hasAttribute (attributeName))
  68205. return xml->getStringAttribute (attributeName, defaultValue);
  68206. const String styleAtt (xml->getStringAttribute ("style"));
  68207. if (styleAtt.isNotEmpty())
  68208. {
  68209. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68210. if (value.isNotEmpty())
  68211. return value;
  68212. }
  68213. else if (xml->hasAttribute ("class"))
  68214. {
  68215. const String className ("." + xml->getStringAttribute ("class"));
  68216. int index = cssStyleText.indexOfIgnoreCase (className + " ");
  68217. if (index < 0)
  68218. index = cssStyleText.indexOfIgnoreCase (className + "{");
  68219. if (index >= 0)
  68220. {
  68221. const int openBracket = cssStyleText.indexOfChar (index, '{');
  68222. if (openBracket > index)
  68223. {
  68224. const int closeBracket = cssStyleText.indexOfChar (openBracket, '}');
  68225. if (closeBracket > openBracket)
  68226. {
  68227. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68228. if (value.isNotEmpty())
  68229. return value;
  68230. }
  68231. }
  68232. }
  68233. }
  68234. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68235. if (xml != 0)
  68236. return getStyleAttribute (xml, attributeName, defaultValue);
  68237. return defaultValue;
  68238. }
  68239. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68240. {
  68241. if (xml->hasAttribute (attributeName))
  68242. return xml->getStringAttribute (attributeName);
  68243. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68244. if (xml != 0)
  68245. return getInheritedAttribute (xml, attributeName);
  68246. return String::empty;
  68247. }
  68248. static bool isIdentifierChar (const juce_wchar c)
  68249. {
  68250. return CharacterFunctions::isLetter (c) || c == '-';
  68251. }
  68252. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68253. {
  68254. int i = 0;
  68255. for (;;)
  68256. {
  68257. i = list.indexOf (i, attributeName);
  68258. if (i < 0)
  68259. break;
  68260. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68261. && ! isIdentifierChar (list [i + attributeName.length()]))
  68262. {
  68263. i = list.indexOfChar (i, ':');
  68264. if (i < 0)
  68265. break;
  68266. int end = list.indexOfChar (i, ';');
  68267. if (end < 0)
  68268. end = 0x7ffff;
  68269. return list.substring (i + 1, end).trim();
  68270. }
  68271. ++i;
  68272. }
  68273. return defaultValue;
  68274. }
  68275. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68276. {
  68277. const juce_wchar* const s = source;
  68278. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68279. ++index;
  68280. int start = index;
  68281. if (CharacterFunctions::isDigit (s[index]) || s[index] == '.' || s[index] == '-')
  68282. ++index;
  68283. while (CharacterFunctions::isDigit (s[index]) || s[index] == '.')
  68284. ++index;
  68285. if ((s[index] == 'e' || s[index] == 'E')
  68286. && (CharacterFunctions::isDigit (s[index + 1])
  68287. || s[index + 1] == '-'
  68288. || s[index + 1] == '+'))
  68289. {
  68290. index += 2;
  68291. while (CharacterFunctions::isDigit (s[index]))
  68292. ++index;
  68293. }
  68294. if (allowUnits)
  68295. {
  68296. while (CharacterFunctions::isLetter (s[index]))
  68297. ++index;
  68298. }
  68299. if (index == start)
  68300. return false;
  68301. value = String (s + start, index - start);
  68302. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68303. ++index;
  68304. return true;
  68305. }
  68306. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68307. {
  68308. if (s [index] == '#')
  68309. {
  68310. uint32 hex [6];
  68311. zeromem (hex, sizeof (hex));
  68312. int numChars = 0;
  68313. for (int i = 6; --i >= 0;)
  68314. {
  68315. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68316. if (hexValue >= 0)
  68317. hex [numChars++] = hexValue;
  68318. else
  68319. break;
  68320. }
  68321. if (numChars <= 3)
  68322. return Colour ((uint8) (hex [0] * 0x11),
  68323. (uint8) (hex [1] * 0x11),
  68324. (uint8) (hex [2] * 0x11));
  68325. else
  68326. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68327. (uint8) ((hex [2] << 4) + hex [3]),
  68328. (uint8) ((hex [4] << 4) + hex [5]));
  68329. }
  68330. else if (s [index] == 'r'
  68331. && s [index + 1] == 'g'
  68332. && s [index + 2] == 'b')
  68333. {
  68334. const int openBracket = s.indexOfChar (index, '(');
  68335. const int closeBracket = s.indexOfChar (openBracket, ')');
  68336. if (openBracket >= 3 && closeBracket > openBracket)
  68337. {
  68338. index = closeBracket;
  68339. StringArray tokens;
  68340. tokens.addTokens (s.substring (openBracket + 1, closeBracket), ",", "");
  68341. tokens.trim();
  68342. tokens.removeEmptyStrings();
  68343. if (tokens[0].containsChar ('%'))
  68344. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68345. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68346. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68347. else
  68348. return Colour ((uint8) tokens[0].getIntValue(),
  68349. (uint8) tokens[1].getIntValue(),
  68350. (uint8) tokens[2].getIntValue());
  68351. }
  68352. }
  68353. return Colours::findColourForName (s, defaultColour);
  68354. }
  68355. static const AffineTransform parseTransform (String t)
  68356. {
  68357. AffineTransform result;
  68358. while (t.isNotEmpty())
  68359. {
  68360. StringArray tokens;
  68361. tokens.addTokens (t.fromFirstOccurrenceOf ("(", false, false)
  68362. .upToFirstOccurrenceOf (")", false, false),
  68363. ", ", String::empty);
  68364. tokens.removeEmptyStrings (true);
  68365. float numbers [6];
  68366. for (int i = 0; i < 6; ++i)
  68367. numbers[i] = tokens[i].getFloatValue();
  68368. AffineTransform trans;
  68369. if (t.startsWithIgnoreCase ("matrix"))
  68370. {
  68371. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68372. numbers[1], numbers[3], numbers[5]);
  68373. }
  68374. else if (t.startsWithIgnoreCase ("translate"))
  68375. {
  68376. jassert (tokens.size() == 2);
  68377. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68378. }
  68379. else if (t.startsWithIgnoreCase ("scale"))
  68380. {
  68381. if (tokens.size() == 1)
  68382. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68383. else
  68384. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68385. }
  68386. else if (t.startsWithIgnoreCase ("rotate"))
  68387. {
  68388. if (tokens.size() != 3)
  68389. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68390. else
  68391. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68392. numbers[1], numbers[2]);
  68393. }
  68394. else if (t.startsWithIgnoreCase ("skewX"))
  68395. {
  68396. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68397. 0.0f, 1.0f, 0.0f);
  68398. }
  68399. else if (t.startsWithIgnoreCase ("skewY"))
  68400. {
  68401. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68402. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68403. }
  68404. result = trans.followedBy (result);
  68405. t = t.fromFirstOccurrenceOf (")", false, false).trimStart();
  68406. }
  68407. return result;
  68408. }
  68409. static void endpointToCentreParameters (const double x1, const double y1,
  68410. const double x2, const double y2,
  68411. const double angle,
  68412. const bool largeArc, const bool sweep,
  68413. double& rx, double& ry,
  68414. double& centreX, double& centreY,
  68415. double& startAngle, double& deltaAngle)
  68416. {
  68417. const double midX = (x1 - x2) * 0.5;
  68418. const double midY = (y1 - y2) * 0.5;
  68419. const double cosAngle = cos (angle);
  68420. const double sinAngle = sin (angle);
  68421. const double xp = cosAngle * midX + sinAngle * midY;
  68422. const double yp = cosAngle * midY - sinAngle * midX;
  68423. const double xp2 = xp * xp;
  68424. const double yp2 = yp * yp;
  68425. double rx2 = rx * rx;
  68426. double ry2 = ry * ry;
  68427. const double s = (xp2 / rx2) + (yp2 / ry2);
  68428. double c;
  68429. if (s <= 1.0)
  68430. {
  68431. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68432. / (( rx2 * yp2) + (ry2 * xp2))));
  68433. if (largeArc == sweep)
  68434. c = -c;
  68435. }
  68436. else
  68437. {
  68438. const double s2 = sqrt (s);
  68439. rx *= s2;
  68440. ry *= s2;
  68441. rx2 = rx * rx;
  68442. ry2 = ry * ry;
  68443. c = 0;
  68444. }
  68445. const double cpx = ((rx * yp) / ry) * c;
  68446. const double cpy = ((-ry * xp) / rx) * c;
  68447. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68448. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68449. const double ux = (xp - cpx) / rx;
  68450. const double uy = (yp - cpy) / ry;
  68451. const double vx = (-xp - cpx) / rx;
  68452. const double vy = (-yp - cpy) / ry;
  68453. const double length = juce_hypot (ux, uy);
  68454. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68455. if (uy < 0)
  68456. startAngle = -startAngle;
  68457. startAngle += double_Pi * 0.5;
  68458. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68459. / (length * juce_hypot (vx, vy))));
  68460. if ((ux * vy) - (uy * vx) < 0)
  68461. deltaAngle = -deltaAngle;
  68462. if (sweep)
  68463. {
  68464. if (deltaAngle < 0)
  68465. deltaAngle += double_Pi * 2.0;
  68466. }
  68467. else
  68468. {
  68469. if (deltaAngle > 0)
  68470. deltaAngle -= double_Pi * 2.0;
  68471. }
  68472. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68473. }
  68474. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68475. {
  68476. forEachXmlChildElement (*parent, e)
  68477. {
  68478. if (e->compareAttribute ("id", id))
  68479. return e;
  68480. const XmlElement* const found = findElementForId (e, id);
  68481. if (found != 0)
  68482. return found;
  68483. }
  68484. return 0;
  68485. }
  68486. SVGState& operator= (const SVGState&);
  68487. };
  68488. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68489. {
  68490. SVGState state (&svgDocument);
  68491. return state.parseSVGElement (svgDocument);
  68492. }
  68493. END_JUCE_NAMESPACE
  68494. /*** End of inlined file: juce_SVGParser.cpp ***/
  68495. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68496. BEGIN_JUCE_NAMESPACE
  68497. #if JUCE_MSVC
  68498. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68499. #endif
  68500. DropShadowEffect::DropShadowEffect()
  68501. : offsetX (0),
  68502. offsetY (0),
  68503. radius (4),
  68504. opacity (0.6f)
  68505. {
  68506. }
  68507. DropShadowEffect::~DropShadowEffect()
  68508. {
  68509. }
  68510. void DropShadowEffect::setShadowProperties (const float newRadius,
  68511. const float newOpacity,
  68512. const int newShadowOffsetX,
  68513. const int newShadowOffsetY)
  68514. {
  68515. radius = jmax (1.1f, newRadius);
  68516. offsetX = newShadowOffsetX;
  68517. offsetY = newShadowOffsetY;
  68518. opacity = newOpacity;
  68519. }
  68520. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68521. {
  68522. const int w = image.getWidth();
  68523. const int h = image.getHeight();
  68524. Image shadowImage (Image::SingleChannel, w, h, false);
  68525. const Image::BitmapData srcData (image, 0, 0, w, h);
  68526. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68527. const int filter = roundToInt (63.0f / radius);
  68528. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68529. for (int x = w; --x >= 0;)
  68530. {
  68531. int shadowAlpha = 0;
  68532. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68533. uint8* shadowPix = destData.data + x;
  68534. for (int y = h; --y >= 0;)
  68535. {
  68536. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68537. *shadowPix = (uint8) shadowAlpha;
  68538. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68539. shadowPix += destData.lineStride;
  68540. }
  68541. }
  68542. for (int y = h; --y >= 0;)
  68543. {
  68544. int shadowAlpha = 0;
  68545. uint8* shadowPix = destData.getLinePointer (y);
  68546. for (int x = w; --x >= 0;)
  68547. {
  68548. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68549. *shadowPix++ = (uint8) shadowAlpha;
  68550. }
  68551. }
  68552. g.setColour (Colours::black.withAlpha (opacity));
  68553. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68554. g.setOpacity (1.0f);
  68555. g.drawImageAt (&image, 0, 0);
  68556. }
  68557. END_JUCE_NAMESPACE
  68558. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68559. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68560. BEGIN_JUCE_NAMESPACE
  68561. GlowEffect::GlowEffect()
  68562. : radius (2.0f),
  68563. colour (Colours::white)
  68564. {
  68565. }
  68566. GlowEffect::~GlowEffect()
  68567. {
  68568. }
  68569. void GlowEffect::setGlowProperties (const float newRadius,
  68570. const Colour& newColour)
  68571. {
  68572. radius = newRadius;
  68573. colour = newColour;
  68574. }
  68575. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68576. {
  68577. Image temp (image.getFormat(), image.getWidth(), image.getHeight(), true);
  68578. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68579. blurKernel.createGaussianBlur (radius);
  68580. blurKernel.rescaleAllValues (radius);
  68581. blurKernel.applyToImage (temp, &image, image.getBounds());
  68582. g.setColour (colour);
  68583. g.drawImageAt (&temp, 0, 0, true);
  68584. g.setOpacity (1.0f);
  68585. g.drawImageAt (&image, 0, 0, false);
  68586. }
  68587. END_JUCE_NAMESPACE
  68588. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68589. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68590. BEGIN_JUCE_NAMESPACE
  68591. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68592. : opacity (opacity_)
  68593. {
  68594. }
  68595. ReduceOpacityEffect::~ReduceOpacityEffect()
  68596. {
  68597. }
  68598. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68599. {
  68600. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68601. }
  68602. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68603. {
  68604. g.setOpacity (opacity);
  68605. g.drawImageAt (&image, 0, 0);
  68606. }
  68607. END_JUCE_NAMESPACE
  68608. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68609. /*** Start of inlined file: juce_Font.cpp ***/
  68610. BEGIN_JUCE_NAMESPACE
  68611. namespace FontValues
  68612. {
  68613. static float limitFontHeight (const float height) throw()
  68614. {
  68615. return jlimit (0.1f, 10000.0f, height);
  68616. }
  68617. static const float defaultFontHeight = 14.0f;
  68618. }
  68619. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68620. const float kerning_, const float ascent_, const int styleFlags_,
  68621. Typeface* const typeface_) throw()
  68622. : typefaceName (typefaceName_),
  68623. height (height_),
  68624. horizontalScale (horizontalScale_),
  68625. kerning (kerning_),
  68626. ascent (ascent_),
  68627. styleFlags (styleFlags_),
  68628. typeface (typeface_)
  68629. {
  68630. }
  68631. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68632. : typefaceName (other.typefaceName),
  68633. height (other.height),
  68634. horizontalScale (other.horizontalScale),
  68635. kerning (other.kerning),
  68636. ascent (other.ascent),
  68637. styleFlags (other.styleFlags),
  68638. typeface (other.typeface)
  68639. {
  68640. }
  68641. Font::Font() throw()
  68642. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::defaultFontHeight,
  68643. 1.0f, 0, 0, Font::plain, 0))
  68644. {
  68645. }
  68646. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68647. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::limitFontHeight (fontHeight),
  68648. 1.0f, 0, 0, styleFlags_, 0))
  68649. {
  68650. }
  68651. Font::Font (const String& typefaceName_,
  68652. const float fontHeight,
  68653. const int styleFlags_) throw()
  68654. : font (new SharedFontInternal (typefaceName_, FontValues::limitFontHeight (fontHeight),
  68655. 1.0f, 0, 0, styleFlags_, 0))
  68656. {
  68657. }
  68658. Font::Font (const Font& other) throw()
  68659. : font (other.font)
  68660. {
  68661. }
  68662. Font& Font::operator= (const Font& other) throw()
  68663. {
  68664. font = other.font;
  68665. return *this;
  68666. }
  68667. Font::~Font() throw()
  68668. {
  68669. }
  68670. Font::Font (const Typeface::Ptr& typeface) throw()
  68671. : font (new SharedFontInternal (typeface->getName(), FontValues::defaultFontHeight,
  68672. 1.0f, 0, 0, Font::plain, typeface))
  68673. {
  68674. }
  68675. bool Font::operator== (const Font& other) const throw()
  68676. {
  68677. return font == other.font
  68678. || (font->height == other.font->height
  68679. && font->styleFlags == other.font->styleFlags
  68680. && font->horizontalScale == other.font->horizontalScale
  68681. && font->kerning == other.font->kerning
  68682. && font->typefaceName == other.font->typefaceName);
  68683. }
  68684. bool Font::operator!= (const Font& other) const throw()
  68685. {
  68686. return ! operator== (other);
  68687. }
  68688. void Font::dupeInternalIfShared() throw()
  68689. {
  68690. if (font->getReferenceCount() > 1)
  68691. font = new SharedFontInternal (*font);
  68692. }
  68693. const String Font::getDefaultSansSerifFontName() throw()
  68694. {
  68695. static const String name ("<Sans-Serif>");
  68696. return name;
  68697. }
  68698. const String Font::getDefaultSerifFontName() throw()
  68699. {
  68700. static const String name ("<Serif>");
  68701. return name;
  68702. }
  68703. const String Font::getDefaultMonospacedFontName() throw()
  68704. {
  68705. static const String name ("<Monospaced>");
  68706. return name;
  68707. }
  68708. void Font::setTypefaceName (const String& faceName) throw()
  68709. {
  68710. if (faceName != font->typefaceName)
  68711. {
  68712. dupeInternalIfShared();
  68713. font->typefaceName = faceName;
  68714. font->typeface = 0;
  68715. font->ascent = 0;
  68716. }
  68717. }
  68718. static String fallbackFont;
  68719. const String Font::getFallbackFontName() throw()
  68720. {
  68721. return fallbackFont;
  68722. }
  68723. void Font::setFallbackFontName (const String& name) throw()
  68724. {
  68725. fallbackFont = name;
  68726. }
  68727. void Font::setHeight (float newHeight) throw()
  68728. {
  68729. newHeight = FontValues::limitFontHeight (newHeight);
  68730. if (font->height != newHeight)
  68731. {
  68732. dupeInternalIfShared();
  68733. font->height = newHeight;
  68734. }
  68735. }
  68736. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68737. {
  68738. newHeight = FontValues::limitFontHeight (newHeight);
  68739. if (font->height != newHeight)
  68740. {
  68741. dupeInternalIfShared();
  68742. font->horizontalScale *= (font->height / newHeight);
  68743. font->height = newHeight;
  68744. }
  68745. }
  68746. void Font::setStyleFlags (const int newFlags) throw()
  68747. {
  68748. if (font->styleFlags != newFlags)
  68749. {
  68750. dupeInternalIfShared();
  68751. font->styleFlags = newFlags;
  68752. font->typeface = 0;
  68753. font->ascent = 0;
  68754. }
  68755. }
  68756. void Font::setSizeAndStyle (float newHeight,
  68757. const int newStyleFlags,
  68758. const float newHorizontalScale,
  68759. const float newKerningAmount) throw()
  68760. {
  68761. newHeight = FontValues::limitFontHeight (newHeight);
  68762. if (font->height != newHeight
  68763. || font->horizontalScale != newHorizontalScale
  68764. || font->kerning != newKerningAmount)
  68765. {
  68766. dupeInternalIfShared();
  68767. font->height = newHeight;
  68768. font->horizontalScale = newHorizontalScale;
  68769. font->kerning = newKerningAmount;
  68770. }
  68771. setStyleFlags (newStyleFlags);
  68772. }
  68773. void Font::setHorizontalScale (const float scaleFactor) throw()
  68774. {
  68775. dupeInternalIfShared();
  68776. font->horizontalScale = scaleFactor;
  68777. }
  68778. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68779. {
  68780. dupeInternalIfShared();
  68781. font->kerning = extraKerning;
  68782. }
  68783. void Font::setBold (const bool shouldBeBold) throw()
  68784. {
  68785. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68786. : (font->styleFlags & ~bold));
  68787. }
  68788. bool Font::isBold() const throw()
  68789. {
  68790. return (font->styleFlags & bold) != 0;
  68791. }
  68792. void Font::setItalic (const bool shouldBeItalic) throw()
  68793. {
  68794. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68795. : (font->styleFlags & ~italic));
  68796. }
  68797. bool Font::isItalic() const throw()
  68798. {
  68799. return (font->styleFlags & italic) != 0;
  68800. }
  68801. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68802. {
  68803. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68804. : (font->styleFlags & ~underlined));
  68805. }
  68806. bool Font::isUnderlined() const throw()
  68807. {
  68808. return (font->styleFlags & underlined) != 0;
  68809. }
  68810. float Font::getAscent() const throw()
  68811. {
  68812. if (font->ascent == 0)
  68813. font->ascent = getTypeface()->getAscent();
  68814. return font->height * font->ascent;
  68815. }
  68816. float Font::getDescent() const throw()
  68817. {
  68818. return font->height - getAscent();
  68819. }
  68820. int Font::getStringWidth (const String& text) const throw()
  68821. {
  68822. return roundToInt (getStringWidthFloat (text));
  68823. }
  68824. float Font::getStringWidthFloat (const String& text) const throw()
  68825. {
  68826. float w = getTypeface()->getStringWidth (text);
  68827. if (font->kerning != 0)
  68828. w += font->kerning * text.length();
  68829. return w * font->height * font->horizontalScale;
  68830. }
  68831. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68832. {
  68833. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68834. const float scale = font->height * font->horizontalScale;
  68835. const int num = xOffsets.size();
  68836. if (num > 0)
  68837. {
  68838. float* const x = &(xOffsets.getReference(0));
  68839. if (font->kerning != 0)
  68840. {
  68841. for (int i = 0; i < num; ++i)
  68842. x[i] = (x[i] + i * font->kerning) * scale;
  68843. }
  68844. else
  68845. {
  68846. for (int i = 0; i < num; ++i)
  68847. x[i] *= scale;
  68848. }
  68849. }
  68850. }
  68851. void Font::findFonts (Array<Font>& destArray) throw()
  68852. {
  68853. const StringArray names (findAllTypefaceNames());
  68854. for (int i = 0; i < names.size(); ++i)
  68855. destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain));
  68856. }
  68857. class TypefaceCache : public DeletedAtShutdown
  68858. {
  68859. public:
  68860. TypefaceCache (int numToCache = 10) throw()
  68861. : counter (1)
  68862. {
  68863. while (--numToCache >= 0)
  68864. faces.add (new CachedFace());
  68865. }
  68866. ~TypefaceCache()
  68867. {
  68868. clearSingletonInstance();
  68869. }
  68870. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68871. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68872. {
  68873. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68874. const String faceName (font.getTypefaceName());
  68875. int i;
  68876. for (i = faces.size(); --i >= 0;)
  68877. {
  68878. CachedFace* const face = faces.getUnchecked(i);
  68879. if (face->flags == flags
  68880. && face->typefaceName == faceName)
  68881. {
  68882. face->lastUsageCount = ++counter;
  68883. return face->typeFace;
  68884. }
  68885. }
  68886. int replaceIndex = 0;
  68887. int bestLastUsageCount = std::numeric_limits<int>::max();
  68888. for (i = faces.size(); --i >= 0;)
  68889. {
  68890. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68891. if (bestLastUsageCount > lu)
  68892. {
  68893. bestLastUsageCount = lu;
  68894. replaceIndex = i;
  68895. }
  68896. }
  68897. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68898. face->typefaceName = faceName;
  68899. face->flags = flags;
  68900. face->lastUsageCount = ++counter;
  68901. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68902. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68903. return face->typeFace;
  68904. }
  68905. juce_UseDebuggingNewOperator
  68906. private:
  68907. struct CachedFace
  68908. {
  68909. CachedFace() throw()
  68910. : lastUsageCount (0), flags (-1)
  68911. {
  68912. }
  68913. String typefaceName;
  68914. int lastUsageCount;
  68915. int flags;
  68916. Typeface::Ptr typeFace;
  68917. };
  68918. int counter;
  68919. OwnedArray <CachedFace> faces;
  68920. TypefaceCache (const TypefaceCache&);
  68921. TypefaceCache& operator= (const TypefaceCache&);
  68922. };
  68923. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68924. Typeface* Font::getTypeface() const throw()
  68925. {
  68926. if (font->typeface == 0)
  68927. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68928. return font->typeface;
  68929. }
  68930. END_JUCE_NAMESPACE
  68931. /*** End of inlined file: juce_Font.cpp ***/
  68932. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68933. BEGIN_JUCE_NAMESPACE
  68934. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68935. const juce_wchar character_, const int glyph_)
  68936. : x (x_),
  68937. y (y_),
  68938. w (w_),
  68939. font (font_),
  68940. character (character_),
  68941. glyph (glyph_)
  68942. {
  68943. }
  68944. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68945. : x (other.x),
  68946. y (other.y),
  68947. w (other.w),
  68948. font (other.font),
  68949. character (other.character),
  68950. glyph (other.glyph)
  68951. {
  68952. }
  68953. void PositionedGlyph::draw (const Graphics& g) const
  68954. {
  68955. if (! isWhitespace())
  68956. {
  68957. g.getInternalContext()->setFont (font);
  68958. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68959. }
  68960. }
  68961. void PositionedGlyph::draw (const Graphics& g,
  68962. const AffineTransform& transform) const
  68963. {
  68964. if (! isWhitespace())
  68965. {
  68966. g.getInternalContext()->setFont (font);
  68967. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  68968. .followedBy (transform));
  68969. }
  68970. }
  68971. void PositionedGlyph::createPath (Path& path) const
  68972. {
  68973. if (! isWhitespace())
  68974. {
  68975. Typeface* const t = font.getTypeface();
  68976. if (t != 0)
  68977. {
  68978. Path p;
  68979. t->getOutlineForGlyph (glyph, p);
  68980. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  68981. .translated (x, y));
  68982. }
  68983. }
  68984. }
  68985. bool PositionedGlyph::hitTest (float px, float py) const
  68986. {
  68987. if (getBounds().contains (px, py) && ! isWhitespace())
  68988. {
  68989. Typeface* const t = font.getTypeface();
  68990. if (t != 0)
  68991. {
  68992. Path p;
  68993. t->getOutlineForGlyph (glyph, p);
  68994. AffineTransform::translation (-x, -y)
  68995. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  68996. .transformPoint (px, py);
  68997. return p.contains (px, py);
  68998. }
  68999. }
  69000. return false;
  69001. }
  69002. void PositionedGlyph::moveBy (const float deltaX,
  69003. const float deltaY)
  69004. {
  69005. x += deltaX;
  69006. y += deltaY;
  69007. }
  69008. GlyphArrangement::GlyphArrangement()
  69009. {
  69010. glyphs.ensureStorageAllocated (128);
  69011. }
  69012. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69013. {
  69014. addGlyphArrangement (other);
  69015. }
  69016. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69017. {
  69018. if (this != &other)
  69019. {
  69020. clear();
  69021. addGlyphArrangement (other);
  69022. }
  69023. return *this;
  69024. }
  69025. GlyphArrangement::~GlyphArrangement()
  69026. {
  69027. }
  69028. void GlyphArrangement::clear()
  69029. {
  69030. glyphs.clear();
  69031. }
  69032. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69033. {
  69034. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69035. return *glyphs [index];
  69036. }
  69037. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69038. {
  69039. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69040. for (int i = 0; i < other.glyphs.size(); ++i)
  69041. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69042. }
  69043. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69044. {
  69045. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69046. }
  69047. void GlyphArrangement::addLineOfText (const Font& font,
  69048. const String& text,
  69049. const float xOffset,
  69050. const float yOffset)
  69051. {
  69052. addCurtailedLineOfText (font, text,
  69053. xOffset, yOffset,
  69054. 1.0e10f, false);
  69055. }
  69056. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69057. const String& text,
  69058. float xOffset,
  69059. const float yOffset,
  69060. const float maxWidthPixels,
  69061. const bool useEllipsis)
  69062. {
  69063. if (text.isNotEmpty())
  69064. {
  69065. Array <int> newGlyphs;
  69066. Array <float> xOffsets;
  69067. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69068. const int textLen = newGlyphs.size();
  69069. const juce_wchar* const unicodeText = text;
  69070. for (int i = 0; i < textLen; ++i)
  69071. {
  69072. const float thisX = xOffsets.getUnchecked (i);
  69073. const float nextX = xOffsets.getUnchecked (i + 1);
  69074. if (nextX > maxWidthPixels + 1.0f)
  69075. {
  69076. // curtail the string if it's too wide..
  69077. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69078. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69079. break;
  69080. }
  69081. else
  69082. {
  69083. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  69084. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  69085. }
  69086. }
  69087. }
  69088. }
  69089. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69090. const int startIndex, int endIndex)
  69091. {
  69092. int numDeleted = 0;
  69093. if (glyphs.size() > 0)
  69094. {
  69095. Array<int> dotGlyphs;
  69096. Array<float> dotXs;
  69097. font.getGlyphPositions ("..", dotGlyphs, dotXs);
  69098. const float dx = dotXs[1];
  69099. float xOffset = 0.0f, yOffset = 0.0f;
  69100. while (endIndex > startIndex)
  69101. {
  69102. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69103. xOffset = pg->x;
  69104. yOffset = pg->y;
  69105. glyphs.remove (endIndex);
  69106. ++numDeleted;
  69107. if (xOffset + dx * 3 <= maxXPos)
  69108. break;
  69109. }
  69110. for (int i = 3; --i >= 0;)
  69111. {
  69112. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69113. font, '.', dotGlyphs.getFirst()));
  69114. --numDeleted;
  69115. xOffset += dx;
  69116. if (xOffset > maxXPos)
  69117. break;
  69118. }
  69119. }
  69120. return numDeleted;
  69121. }
  69122. void GlyphArrangement::addJustifiedText (const Font& font,
  69123. const String& text,
  69124. float x, float y,
  69125. const float maxLineWidth,
  69126. const Justification& horizontalLayout)
  69127. {
  69128. int lineStartIndex = glyphs.size();
  69129. addLineOfText (font, text, x, y);
  69130. const float originalY = y;
  69131. while (lineStartIndex < glyphs.size())
  69132. {
  69133. int i = lineStartIndex;
  69134. if (glyphs.getUnchecked(i)->getCharacter() != '\n'
  69135. && glyphs.getUnchecked(i)->getCharacter() != '\r')
  69136. ++i;
  69137. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69138. int lastWordBreakIndex = -1;
  69139. while (i < glyphs.size())
  69140. {
  69141. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69142. const juce_wchar c = pg->getCharacter();
  69143. if (c == '\r' || c == '\n')
  69144. {
  69145. ++i;
  69146. if (c == '\r' && i < glyphs.size()
  69147. && glyphs.getUnchecked(i)->getCharacter() == '\n')
  69148. ++i;
  69149. break;
  69150. }
  69151. else if (pg->isWhitespace())
  69152. {
  69153. lastWordBreakIndex = i + 1;
  69154. }
  69155. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69156. {
  69157. if (lastWordBreakIndex >= 0)
  69158. i = lastWordBreakIndex;
  69159. break;
  69160. }
  69161. ++i;
  69162. }
  69163. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69164. float currentLineEndX = currentLineStartX;
  69165. for (int j = i; --j >= lineStartIndex;)
  69166. {
  69167. if (! glyphs.getUnchecked (j)->isWhitespace())
  69168. {
  69169. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69170. break;
  69171. }
  69172. }
  69173. float deltaX = 0.0f;
  69174. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69175. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69176. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69177. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69178. else if (horizontalLayout.testFlags (Justification::right))
  69179. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69180. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69181. x + deltaX - currentLineStartX, y - originalY);
  69182. lineStartIndex = i;
  69183. y += font.getHeight();
  69184. }
  69185. }
  69186. void GlyphArrangement::addFittedText (const Font& f,
  69187. const String& text,
  69188. const float x, const float y,
  69189. const float width, const float height,
  69190. const Justification& layout,
  69191. int maximumLines,
  69192. const float minimumHorizontalScale)
  69193. {
  69194. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69195. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69196. if (text.containsAnyOf ("\r\n"))
  69197. {
  69198. GlyphArrangement ga;
  69199. ga.addJustifiedText (f, text, x, y, width, layout);
  69200. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  69201. float dy = y - bb.getY();
  69202. if (layout.testFlags (Justification::verticallyCentred))
  69203. dy += (height - bb.getHeight()) * 0.5f;
  69204. else if (layout.testFlags (Justification::bottom))
  69205. dy += height - bb.getHeight();
  69206. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69207. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69208. for (int i = 0; i < ga.glyphs.size(); ++i)
  69209. glyphs.add (ga.glyphs.getUnchecked (i));
  69210. ga.glyphs.clear (false);
  69211. return;
  69212. }
  69213. int startIndex = glyphs.size();
  69214. addLineOfText (f, text.trim(), x, y);
  69215. if (glyphs.size() > startIndex)
  69216. {
  69217. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69218. - glyphs.getUnchecked (startIndex)->getLeft();
  69219. if (lineWidth <= 0)
  69220. return;
  69221. if (lineWidth * minimumHorizontalScale < width)
  69222. {
  69223. if (lineWidth > width)
  69224. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69225. width / lineWidth);
  69226. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69227. x, y, width, height, layout);
  69228. }
  69229. else if (maximumLines <= 1)
  69230. {
  69231. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69232. x, y, width, height, f, layout, minimumHorizontalScale);
  69233. }
  69234. else
  69235. {
  69236. Font font (f);
  69237. String txt (text.trim());
  69238. const int length = txt.length();
  69239. const int originalStartIndex = startIndex;
  69240. int numLines = 1;
  69241. if (length <= 12 && ! txt.containsAnyOf (" -\t\r\n"))
  69242. maximumLines = 1;
  69243. maximumLines = jmin (maximumLines, length);
  69244. while (numLines < maximumLines)
  69245. {
  69246. ++numLines;
  69247. const float newFontHeight = height / (float) numLines;
  69248. if (newFontHeight < font.getHeight())
  69249. {
  69250. font.setHeight (jmax (8.0f, newFontHeight));
  69251. removeRangeOfGlyphs (startIndex, -1);
  69252. addLineOfText (font, txt, x, y);
  69253. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69254. - glyphs.getUnchecked (startIndex)->getLeft();
  69255. }
  69256. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69257. break;
  69258. }
  69259. if (numLines < 1)
  69260. numLines = 1;
  69261. float lineY = y;
  69262. float widthPerLine = lineWidth / numLines;
  69263. int lastLineStartIndex = 0;
  69264. for (int line = 0; line < numLines; ++line)
  69265. {
  69266. int i = startIndex;
  69267. lastLineStartIndex = i;
  69268. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69269. if (line == numLines - 1)
  69270. {
  69271. widthPerLine = width;
  69272. i = glyphs.size();
  69273. }
  69274. else
  69275. {
  69276. while (i < glyphs.size())
  69277. {
  69278. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69279. if (lineWidth > widthPerLine)
  69280. {
  69281. // got to a point where the line's too long, so skip forward to find a
  69282. // good place to break it..
  69283. const int searchStartIndex = i;
  69284. while (i < glyphs.size())
  69285. {
  69286. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69287. {
  69288. if (glyphs.getUnchecked (i)->isWhitespace()
  69289. || glyphs.getUnchecked (i)->getCharacter() == '-')
  69290. {
  69291. ++i;
  69292. break;
  69293. }
  69294. }
  69295. else
  69296. {
  69297. // can't find a suitable break, so try looking backwards..
  69298. i = searchStartIndex;
  69299. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69300. {
  69301. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69302. || glyphs.getUnchecked (i - back)->getCharacter() == '-')
  69303. {
  69304. i -= back - 1;
  69305. break;
  69306. }
  69307. }
  69308. break;
  69309. }
  69310. ++i;
  69311. }
  69312. break;
  69313. }
  69314. ++i;
  69315. }
  69316. int wsStart = i;
  69317. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69318. --wsStart;
  69319. int wsEnd = i;
  69320. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69321. ++wsEnd;
  69322. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69323. i = jmax (wsStart, startIndex + 1);
  69324. }
  69325. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69326. x, lineY, width, font.getHeight(), font,
  69327. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69328. minimumHorizontalScale);
  69329. startIndex = i;
  69330. lineY += font.getHeight();
  69331. if (startIndex >= glyphs.size())
  69332. break;
  69333. }
  69334. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69335. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69336. }
  69337. }
  69338. }
  69339. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69340. const float dx, const float dy)
  69341. {
  69342. jassert (startIndex >= 0);
  69343. if (dx != 0.0f || dy != 0.0f)
  69344. {
  69345. if (num < 0 || startIndex + num > glyphs.size())
  69346. num = glyphs.size() - startIndex;
  69347. while (--num >= 0)
  69348. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69349. }
  69350. }
  69351. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69352. const Justification& justification, float minimumHorizontalScale)
  69353. {
  69354. int numDeleted = 0;
  69355. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69356. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69357. if (lineWidth > w)
  69358. {
  69359. if (minimumHorizontalScale < 1.0f)
  69360. {
  69361. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69362. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69363. }
  69364. if (lineWidth > w)
  69365. {
  69366. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69367. numGlyphs -= numDeleted;
  69368. }
  69369. }
  69370. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69371. return numDeleted;
  69372. }
  69373. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69374. const float horizontalScaleFactor)
  69375. {
  69376. jassert (startIndex >= 0);
  69377. if (num < 0 || startIndex + num > glyphs.size())
  69378. num = glyphs.size() - startIndex;
  69379. if (num > 0)
  69380. {
  69381. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69382. while (--num >= 0)
  69383. {
  69384. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69385. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69386. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69387. pg->w *= horizontalScaleFactor;
  69388. }
  69389. }
  69390. }
  69391. const Rectangle<float> GlyphArrangement::getBoundingBox (int startIndex, int num, const bool includeWhitespace) const
  69392. {
  69393. jassert (startIndex >= 0);
  69394. if (num < 0 || startIndex + num > glyphs.size())
  69395. num = glyphs.size() - startIndex;
  69396. Rectangle<float> result;
  69397. bool isFirst = true;
  69398. while (--num >= 0)
  69399. {
  69400. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69401. if (includeWhitespace || ! pg->isWhitespace())
  69402. {
  69403. if (isFirst)
  69404. {
  69405. isFirst = false;
  69406. result = pg->getBounds();
  69407. }
  69408. else
  69409. {
  69410. result = result.getUnion (pg->getBounds());
  69411. }
  69412. }
  69413. }
  69414. return result;
  69415. }
  69416. void GlyphArrangement::justifyGlyphs (const int startIndex, const int num,
  69417. const float x, const float y, const float width, const float height,
  69418. const Justification& justification)
  69419. {
  69420. jassert (num >= 0 && startIndex >= 0);
  69421. if (glyphs.size() > 0 && num > 0)
  69422. {
  69423. const Rectangle<float> bb (getBoundingBox (startIndex, num, ! justification.testFlags (Justification::horizontallyJustified
  69424. | Justification::horizontallyCentred)));
  69425. float deltaX = 0.0f;
  69426. if (justification.testFlags (Justification::horizontallyJustified))
  69427. deltaX = x - bb.getX();
  69428. else if (justification.testFlags (Justification::horizontallyCentred))
  69429. deltaX = x + (width - bb.getWidth()) * 0.5f - bb.getX();
  69430. else if (justification.testFlags (Justification::right))
  69431. deltaX = (x + width) - bb.getRight();
  69432. else
  69433. deltaX = x - bb.getX();
  69434. float deltaY = 0.0f;
  69435. if (justification.testFlags (Justification::top))
  69436. deltaY = y - bb.getY();
  69437. else if (justification.testFlags (Justification::bottom))
  69438. deltaY = (y + height) - bb.getBottom();
  69439. else
  69440. deltaY = y + (height - bb.getHeight()) * 0.5f - bb.getY();
  69441. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69442. if (justification.testFlags (Justification::horizontallyJustified))
  69443. {
  69444. int lineStart = 0;
  69445. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69446. int i;
  69447. for (i = 0; i < num; ++i)
  69448. {
  69449. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69450. if (glyphY != baseY)
  69451. {
  69452. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69453. lineStart = i;
  69454. baseY = glyphY;
  69455. }
  69456. }
  69457. if (i > lineStart)
  69458. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69459. }
  69460. }
  69461. }
  69462. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69463. {
  69464. if (start + num < glyphs.size()
  69465. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\r'
  69466. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\n')
  69467. {
  69468. int numSpaces = 0;
  69469. int spacesAtEnd = 0;
  69470. for (int i = 0; i < num; ++i)
  69471. {
  69472. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69473. {
  69474. ++spacesAtEnd;
  69475. ++numSpaces;
  69476. }
  69477. else
  69478. {
  69479. spacesAtEnd = 0;
  69480. }
  69481. }
  69482. numSpaces -= spacesAtEnd;
  69483. if (numSpaces > 0)
  69484. {
  69485. const float startX = glyphs.getUnchecked (start)->getLeft();
  69486. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69487. const float extraPaddingBetweenWords
  69488. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69489. float deltaX = 0.0f;
  69490. for (int i = 0; i < num; ++i)
  69491. {
  69492. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69493. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69494. deltaX += extraPaddingBetweenWords;
  69495. }
  69496. }
  69497. }
  69498. }
  69499. void GlyphArrangement::draw (const Graphics& g) const
  69500. {
  69501. for (int i = 0; i < glyphs.size(); ++i)
  69502. {
  69503. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69504. if (pg->font.isUnderlined())
  69505. {
  69506. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69507. float nextX = pg->x + pg->w;
  69508. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69509. nextX = glyphs.getUnchecked (i + 1)->x;
  69510. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69511. nextX - pg->x, lineThickness);
  69512. }
  69513. pg->draw (g);
  69514. }
  69515. }
  69516. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69517. {
  69518. for (int i = 0; i < glyphs.size(); ++i)
  69519. {
  69520. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69521. if (pg->font.isUnderlined())
  69522. {
  69523. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69524. float nextX = pg->x + pg->w;
  69525. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69526. nextX = glyphs.getUnchecked (i + 1)->x;
  69527. Path p;
  69528. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69529. nextX, pg->y + lineThickness * 2.0f,
  69530. lineThickness);
  69531. g.fillPath (p, transform);
  69532. }
  69533. pg->draw (g, transform);
  69534. }
  69535. }
  69536. void GlyphArrangement::createPath (Path& path) const
  69537. {
  69538. for (int i = 0; i < glyphs.size(); ++i)
  69539. glyphs.getUnchecked (i)->createPath (path);
  69540. }
  69541. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69542. {
  69543. for (int i = 0; i < glyphs.size(); ++i)
  69544. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69545. return i;
  69546. return -1;
  69547. }
  69548. END_JUCE_NAMESPACE
  69549. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69550. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69551. BEGIN_JUCE_NAMESPACE
  69552. class TextLayout::Token
  69553. {
  69554. public:
  69555. String text;
  69556. Font font;
  69557. int x, y, w, h;
  69558. int line, lineHeight;
  69559. bool isWhitespace, isNewLine;
  69560. Token (const String& t,
  69561. const Font& f,
  69562. const bool isWhitespace_)
  69563. : text (t),
  69564. font (f),
  69565. x(0),
  69566. y(0),
  69567. isWhitespace (isWhitespace_)
  69568. {
  69569. w = font.getStringWidth (t);
  69570. h = roundToInt (f.getHeight());
  69571. isNewLine = t.containsChar ('\n') || t.containsChar ('\r');
  69572. }
  69573. Token (const Token& other)
  69574. : text (other.text),
  69575. font (other.font),
  69576. x (other.x),
  69577. y (other.y),
  69578. w (other.w),
  69579. h (other.h),
  69580. line (other.line),
  69581. lineHeight (other.lineHeight),
  69582. isWhitespace (other.isWhitespace),
  69583. isNewLine (other.isNewLine)
  69584. {
  69585. }
  69586. ~Token()
  69587. {
  69588. }
  69589. void draw (Graphics& g,
  69590. const int xOffset,
  69591. const int yOffset)
  69592. {
  69593. if (! isWhitespace)
  69594. {
  69595. g.setFont (font);
  69596. g.drawSingleLineText (text.trimEnd(),
  69597. xOffset + x,
  69598. yOffset + y + (lineHeight - h)
  69599. + roundToInt (font.getAscent()));
  69600. }
  69601. }
  69602. juce_UseDebuggingNewOperator
  69603. };
  69604. TextLayout::TextLayout()
  69605. : totalLines (0)
  69606. {
  69607. tokens.ensureStorageAllocated (64);
  69608. }
  69609. TextLayout::TextLayout (const String& text, const Font& font)
  69610. : totalLines (0)
  69611. {
  69612. tokens.ensureStorageAllocated (64);
  69613. appendText (text, font);
  69614. }
  69615. TextLayout::TextLayout (const TextLayout& other)
  69616. : totalLines (0)
  69617. {
  69618. *this = other;
  69619. }
  69620. TextLayout& TextLayout::operator= (const TextLayout& other)
  69621. {
  69622. if (this != &other)
  69623. {
  69624. clear();
  69625. totalLines = other.totalLines;
  69626. for (int i = 0; i < other.tokens.size(); ++i)
  69627. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69628. }
  69629. return *this;
  69630. }
  69631. TextLayout::~TextLayout()
  69632. {
  69633. clear();
  69634. }
  69635. void TextLayout::clear()
  69636. {
  69637. tokens.clear();
  69638. totalLines = 0;
  69639. }
  69640. void TextLayout::appendText (const String& text, const Font& font)
  69641. {
  69642. const juce_wchar* t = text;
  69643. String currentString;
  69644. int lastCharType = 0;
  69645. for (;;)
  69646. {
  69647. const juce_wchar c = *t++;
  69648. if (c == 0)
  69649. break;
  69650. int charType;
  69651. if (c == '\r' || c == '\n')
  69652. {
  69653. charType = 0;
  69654. }
  69655. else if (CharacterFunctions::isWhitespace (c))
  69656. {
  69657. charType = 2;
  69658. }
  69659. else
  69660. {
  69661. charType = 1;
  69662. }
  69663. if (charType == 0 || charType != lastCharType)
  69664. {
  69665. if (currentString.isNotEmpty())
  69666. {
  69667. tokens.add (new Token (currentString, font,
  69668. lastCharType == 2 || lastCharType == 0));
  69669. }
  69670. currentString = String::charToString (c);
  69671. if (c == '\r' && *t == '\n')
  69672. currentString += *t++;
  69673. }
  69674. else
  69675. {
  69676. currentString += c;
  69677. }
  69678. lastCharType = charType;
  69679. }
  69680. if (currentString.isNotEmpty())
  69681. tokens.add (new Token (currentString, font, lastCharType == 2));
  69682. }
  69683. void TextLayout::setText (const String& text, const Font& font)
  69684. {
  69685. clear();
  69686. appendText (text, font);
  69687. }
  69688. void TextLayout::layout (int maxWidth,
  69689. const Justification& justification,
  69690. const bool attemptToBalanceLineLengths)
  69691. {
  69692. if (attemptToBalanceLineLengths)
  69693. {
  69694. const int originalW = maxWidth;
  69695. int bestWidth = maxWidth;
  69696. float bestLineProportion = 0.0f;
  69697. while (maxWidth > originalW / 2)
  69698. {
  69699. layout (maxWidth, justification, false);
  69700. if (getNumLines() <= 1)
  69701. return;
  69702. const int lastLineW = getLineWidth (getNumLines() - 1);
  69703. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69704. const float prop = lastLineW / (float) lastButOneLineW;
  69705. if (prop > 0.9f)
  69706. return;
  69707. if (prop > bestLineProportion)
  69708. {
  69709. bestLineProportion = prop;
  69710. bestWidth = maxWidth;
  69711. }
  69712. maxWidth -= 10;
  69713. }
  69714. layout (bestWidth, justification, false);
  69715. }
  69716. else
  69717. {
  69718. int x = 0;
  69719. int y = 0;
  69720. int h = 0;
  69721. totalLines = 0;
  69722. int i;
  69723. for (i = 0; i < tokens.size(); ++i)
  69724. {
  69725. Token* const t = tokens.getUnchecked(i);
  69726. t->x = x;
  69727. t->y = y;
  69728. t->line = totalLines;
  69729. x += t->w;
  69730. h = jmax (h, t->h);
  69731. const Token* nextTok = tokens [i + 1];
  69732. if (nextTok == 0)
  69733. break;
  69734. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69735. {
  69736. // finished a line, so go back and update the heights of the things on it
  69737. for (int j = i; j >= 0; --j)
  69738. {
  69739. Token* const tok = tokens.getUnchecked(j);
  69740. if (tok->line == totalLines)
  69741. tok->lineHeight = h;
  69742. else
  69743. break;
  69744. }
  69745. x = 0;
  69746. y += h;
  69747. h = 0;
  69748. ++totalLines;
  69749. }
  69750. }
  69751. // finished a line, so go back and update the heights of the things on it
  69752. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69753. {
  69754. Token* const t = tokens.getUnchecked(j);
  69755. if (t->line == totalLines)
  69756. t->lineHeight = h;
  69757. else
  69758. break;
  69759. }
  69760. ++totalLines;
  69761. if (! justification.testFlags (Justification::left))
  69762. {
  69763. int totalW = getWidth();
  69764. for (i = totalLines; --i >= 0;)
  69765. {
  69766. const int lineW = getLineWidth (i);
  69767. int dx = 0;
  69768. if (justification.testFlags (Justification::horizontallyCentred))
  69769. dx = (totalW - lineW) / 2;
  69770. else if (justification.testFlags (Justification::right))
  69771. dx = totalW - lineW;
  69772. for (int j = tokens.size(); --j >= 0;)
  69773. {
  69774. Token* const t = tokens.getUnchecked(j);
  69775. if (t->line == i)
  69776. t->x += dx;
  69777. }
  69778. }
  69779. }
  69780. }
  69781. }
  69782. int TextLayout::getLineWidth (const int lineNumber) const
  69783. {
  69784. int maxW = 0;
  69785. for (int i = tokens.size(); --i >= 0;)
  69786. {
  69787. const Token* const t = tokens.getUnchecked(i);
  69788. if (t->line == lineNumber && ! t->isWhitespace)
  69789. maxW = jmax (maxW, t->x + t->w);
  69790. }
  69791. return maxW;
  69792. }
  69793. int TextLayout::getWidth() const
  69794. {
  69795. int maxW = 0;
  69796. for (int i = tokens.size(); --i >= 0;)
  69797. {
  69798. const Token* const t = tokens.getUnchecked(i);
  69799. if (! t->isWhitespace)
  69800. maxW = jmax (maxW, t->x + t->w);
  69801. }
  69802. return maxW;
  69803. }
  69804. int TextLayout::getHeight() const
  69805. {
  69806. int maxH = 0;
  69807. for (int i = tokens.size(); --i >= 0;)
  69808. {
  69809. const Token* const t = tokens.getUnchecked(i);
  69810. if (! t->isWhitespace)
  69811. maxH = jmax (maxH, t->y + t->h);
  69812. }
  69813. return maxH;
  69814. }
  69815. void TextLayout::draw (Graphics& g,
  69816. const int xOffset,
  69817. const int yOffset) const
  69818. {
  69819. for (int i = tokens.size(); --i >= 0;)
  69820. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69821. }
  69822. void TextLayout::drawWithin (Graphics& g,
  69823. int x, int y, int w, int h,
  69824. const Justification& justification) const
  69825. {
  69826. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69827. x, y, w, h);
  69828. draw (g, x, y);
  69829. }
  69830. END_JUCE_NAMESPACE
  69831. /*** End of inlined file: juce_TextLayout.cpp ***/
  69832. /*** Start of inlined file: juce_Typeface.cpp ***/
  69833. BEGIN_JUCE_NAMESPACE
  69834. Typeface::Typeface (const String& name_) throw()
  69835. : name (name_)
  69836. {
  69837. }
  69838. Typeface::~Typeface()
  69839. {
  69840. }
  69841. class CustomTypeface::GlyphInfo
  69842. {
  69843. public:
  69844. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69845. : character (character_), path (path_), width (width_)
  69846. {
  69847. }
  69848. ~GlyphInfo() throw()
  69849. {
  69850. }
  69851. struct KerningPair
  69852. {
  69853. juce_wchar character2;
  69854. float kerningAmount;
  69855. };
  69856. void addKerningPair (const juce_wchar subsequentCharacter,
  69857. const float extraKerningAmount) throw()
  69858. {
  69859. KerningPair kp;
  69860. kp.character2 = subsequentCharacter;
  69861. kp.kerningAmount = extraKerningAmount;
  69862. kerningPairs.add (kp);
  69863. }
  69864. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69865. {
  69866. if (subsequentCharacter != 0)
  69867. {
  69868. for (int i = kerningPairs.size(); --i >= 0;)
  69869. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69870. return width + kerningPairs.getReference(i).kerningAmount;
  69871. }
  69872. return width;
  69873. }
  69874. const juce_wchar character;
  69875. const Path path;
  69876. float width;
  69877. Array <KerningPair> kerningPairs;
  69878. juce_UseDebuggingNewOperator
  69879. private:
  69880. GlyphInfo (const GlyphInfo&);
  69881. GlyphInfo& operator= (const GlyphInfo&);
  69882. };
  69883. CustomTypeface::CustomTypeface()
  69884. : Typeface (String::empty)
  69885. {
  69886. clear();
  69887. }
  69888. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69889. : Typeface (String::empty)
  69890. {
  69891. clear();
  69892. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69893. BufferedInputStream in (&gzin, 32768, false);
  69894. name = in.readString();
  69895. isBold = in.readBool();
  69896. isItalic = in.readBool();
  69897. ascent = in.readFloat();
  69898. defaultCharacter = (juce_wchar) in.readShort();
  69899. int i, numChars = in.readInt();
  69900. for (i = 0; i < numChars; ++i)
  69901. {
  69902. const juce_wchar c = (juce_wchar) in.readShort();
  69903. const float width = in.readFloat();
  69904. Path p;
  69905. p.loadPathFromStream (in);
  69906. addGlyph (c, p, width);
  69907. }
  69908. const int numKerningPairs = in.readInt();
  69909. for (i = 0; i < numKerningPairs; ++i)
  69910. {
  69911. const juce_wchar char1 = (juce_wchar) in.readShort();
  69912. const juce_wchar char2 = (juce_wchar) in.readShort();
  69913. addKerningPair (char1, char2, in.readFloat());
  69914. }
  69915. }
  69916. CustomTypeface::~CustomTypeface()
  69917. {
  69918. }
  69919. void CustomTypeface::clear()
  69920. {
  69921. defaultCharacter = 0;
  69922. ascent = 1.0f;
  69923. isBold = isItalic = false;
  69924. zeromem (lookupTable, sizeof (lookupTable));
  69925. glyphs.clear();
  69926. }
  69927. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69928. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69929. {
  69930. name = name_;
  69931. defaultCharacter = defaultCharacter_;
  69932. ascent = ascent_;
  69933. isBold = isBold_;
  69934. isItalic = isItalic_;
  69935. }
  69936. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69937. {
  69938. // Check that you're not trying to add the same character twice..
  69939. jassert (findGlyph (character, false) == 0);
  69940. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  69941. lookupTable [character] = (short) glyphs.size();
  69942. glyphs.add (new GlyphInfo (character, path, width));
  69943. }
  69944. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  69945. {
  69946. if (extraAmount != 0)
  69947. {
  69948. GlyphInfo* const g = findGlyph (char1, true);
  69949. jassert (g != 0); // can only add kerning pairs for characters that exist!
  69950. if (g != 0)
  69951. g->addKerningPair (char2, extraAmount);
  69952. }
  69953. }
  69954. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  69955. {
  69956. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  69957. return glyphs [(int) lookupTable [(int) character]];
  69958. for (int i = 0; i < glyphs.size(); ++i)
  69959. {
  69960. GlyphInfo* const g = glyphs.getUnchecked(i);
  69961. if (g->character == character)
  69962. return g;
  69963. }
  69964. if (loadIfNeeded && loadGlyphIfPossible (character))
  69965. return findGlyph (character, false);
  69966. return 0;
  69967. }
  69968. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  69969. {
  69970. GlyphInfo* glyph = findGlyph (character, true);
  69971. if (glyph == 0)
  69972. {
  69973. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  69974. glyph = findGlyph (L' ', true);
  69975. if (glyph == 0)
  69976. {
  69977. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  69978. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  69979. if (fallbackTypeface != 0 && fallbackTypeface != this)
  69980. {
  69981. //xxx
  69982. }
  69983. if (glyph == 0)
  69984. glyph = findGlyph (defaultCharacter, true);
  69985. }
  69986. }
  69987. return glyph;
  69988. }
  69989. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  69990. {
  69991. return false;
  69992. }
  69993. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  69994. {
  69995. setCharacteristics (name, typefaceToCopy.getAscent(), isBold, isItalic, defaultCharacter);
  69996. for (int i = 0; i < numCharacters; ++i)
  69997. {
  69998. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  69999. Array <int> glyphIndexes;
  70000. Array <float> offsets;
  70001. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70002. const int glyphIndex = glyphIndexes.getFirst();
  70003. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70004. {
  70005. const float glyphWidth = offsets[1];
  70006. Path p;
  70007. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70008. addGlyph (c, p, glyphWidth);
  70009. for (int j = glyphs.size() - 1; --j >= 0;)
  70010. {
  70011. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70012. glyphIndexes.clearQuick();
  70013. offsets.clearQuick();
  70014. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70015. if (offsets.size() > 1)
  70016. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70017. }
  70018. }
  70019. }
  70020. }
  70021. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70022. {
  70023. GZIPCompressorOutputStream out (&outputStream);
  70024. out.writeString (name);
  70025. out.writeBool (isBold);
  70026. out.writeBool (isItalic);
  70027. out.writeFloat (ascent);
  70028. out.writeShort ((short) (unsigned short) defaultCharacter);
  70029. out.writeInt (glyphs.size());
  70030. int i, numKerningPairs = 0;
  70031. for (i = 0; i < glyphs.size(); ++i)
  70032. {
  70033. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70034. out.writeShort ((short) (unsigned short) g->character);
  70035. out.writeFloat (g->width);
  70036. g->path.writePathToStream (out);
  70037. numKerningPairs += g->kerningPairs.size();
  70038. }
  70039. out.writeInt (numKerningPairs);
  70040. for (i = 0; i < glyphs.size(); ++i)
  70041. {
  70042. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70043. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70044. {
  70045. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70046. out.writeShort ((short) (unsigned short) g->character);
  70047. out.writeShort ((short) (unsigned short) p.character2);
  70048. out.writeFloat (p.kerningAmount);
  70049. }
  70050. }
  70051. return true;
  70052. }
  70053. float CustomTypeface::getAscent() const
  70054. {
  70055. return ascent;
  70056. }
  70057. float CustomTypeface::getDescent() const
  70058. {
  70059. return 1.0f - ascent;
  70060. }
  70061. float CustomTypeface::getStringWidth (const String& text)
  70062. {
  70063. float x = 0;
  70064. const juce_wchar* t = text;
  70065. while (*t != 0)
  70066. {
  70067. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70068. if (glyph != 0)
  70069. x += glyph->getHorizontalSpacing (*t);
  70070. }
  70071. return x;
  70072. }
  70073. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70074. {
  70075. xOffsets.add (0);
  70076. float x = 0;
  70077. const juce_wchar* t = text;
  70078. while (*t != 0)
  70079. {
  70080. const juce_wchar c = *t++;
  70081. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70082. if (glyph != 0)
  70083. {
  70084. x += glyph->getHorizontalSpacing (*t);
  70085. resultGlyphs.add ((int) glyph->character);
  70086. xOffsets.add (x);
  70087. }
  70088. }
  70089. }
  70090. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70091. {
  70092. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70093. if (glyph != 0)
  70094. {
  70095. path = glyph->path;
  70096. return true;
  70097. }
  70098. return false;
  70099. }
  70100. END_JUCE_NAMESPACE
  70101. /*** End of inlined file: juce_Typeface.cpp ***/
  70102. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70103. BEGIN_JUCE_NAMESPACE
  70104. AffineTransform::AffineTransform() throw()
  70105. : mat00 (1.0f),
  70106. mat01 (0),
  70107. mat02 (0),
  70108. mat10 (0),
  70109. mat11 (1.0f),
  70110. mat12 (0)
  70111. {
  70112. }
  70113. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70114. : mat00 (other.mat00),
  70115. mat01 (other.mat01),
  70116. mat02 (other.mat02),
  70117. mat10 (other.mat10),
  70118. mat11 (other.mat11),
  70119. mat12 (other.mat12)
  70120. {
  70121. }
  70122. AffineTransform::AffineTransform (const float mat00_,
  70123. const float mat01_,
  70124. const float mat02_,
  70125. const float mat10_,
  70126. const float mat11_,
  70127. const float mat12_) throw()
  70128. : mat00 (mat00_),
  70129. mat01 (mat01_),
  70130. mat02 (mat02_),
  70131. mat10 (mat10_),
  70132. mat11 (mat11_),
  70133. mat12 (mat12_)
  70134. {
  70135. }
  70136. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70137. {
  70138. mat00 = other.mat00;
  70139. mat01 = other.mat01;
  70140. mat02 = other.mat02;
  70141. mat10 = other.mat10;
  70142. mat11 = other.mat11;
  70143. mat12 = other.mat12;
  70144. return *this;
  70145. }
  70146. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70147. {
  70148. return mat00 == other.mat00
  70149. && mat01 == other.mat01
  70150. && mat02 == other.mat02
  70151. && mat10 == other.mat10
  70152. && mat11 == other.mat11
  70153. && mat12 == other.mat12;
  70154. }
  70155. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70156. {
  70157. return ! operator== (other);
  70158. }
  70159. bool AffineTransform::isIdentity() const throw()
  70160. {
  70161. return (mat01 == 0)
  70162. && (mat02 == 0)
  70163. && (mat10 == 0)
  70164. && (mat12 == 0)
  70165. && (mat00 == 1.0f)
  70166. && (mat11 == 1.0f);
  70167. }
  70168. const AffineTransform AffineTransform::identity;
  70169. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70170. {
  70171. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70172. other.mat00 * mat01 + other.mat01 * mat11,
  70173. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70174. other.mat10 * mat00 + other.mat11 * mat10,
  70175. other.mat10 * mat01 + other.mat11 * mat11,
  70176. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70177. }
  70178. const AffineTransform AffineTransform::followedBy (const float omat00,
  70179. const float omat01,
  70180. const float omat02,
  70181. const float omat10,
  70182. const float omat11,
  70183. const float omat12) const throw()
  70184. {
  70185. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70186. omat00 * mat01 + omat01 * mat11,
  70187. omat00 * mat02 + omat01 * mat12 + omat02,
  70188. omat10 * mat00 + omat11 * mat10,
  70189. omat10 * mat01 + omat11 * mat11,
  70190. omat10 * mat02 + omat11 * mat12 + omat12);
  70191. }
  70192. const AffineTransform AffineTransform::translated (const float dx,
  70193. const float dy) const throw()
  70194. {
  70195. return AffineTransform (mat00, mat01, mat02 + dx,
  70196. mat10, mat11, mat12 + dy);
  70197. }
  70198. const AffineTransform AffineTransform::translation (const float dx,
  70199. const float dy) throw()
  70200. {
  70201. return AffineTransform (1.0f, 0, dx,
  70202. 0, 1.0f, dy);
  70203. }
  70204. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70205. {
  70206. const float cosRad = cosf (rad);
  70207. const float sinRad = sinf (rad);
  70208. return followedBy (cosRad, -sinRad, 0,
  70209. sinRad, cosRad, 0);
  70210. }
  70211. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70212. {
  70213. const float cosRad = cosf (rad);
  70214. const float sinRad = sinf (rad);
  70215. return AffineTransform (cosRad, -sinRad, 0,
  70216. sinRad, cosRad, 0);
  70217. }
  70218. const AffineTransform AffineTransform::rotated (const float angle,
  70219. const float pivotX,
  70220. const float pivotY) const throw()
  70221. {
  70222. return translated (-pivotX, -pivotY)
  70223. .rotated (angle)
  70224. .translated (pivotX, pivotY);
  70225. }
  70226. const AffineTransform AffineTransform::rotation (const float angle,
  70227. const float pivotX,
  70228. const float pivotY) throw()
  70229. {
  70230. return translation (-pivotX, -pivotY)
  70231. .rotated (angle)
  70232. .translated (pivotX, pivotY);
  70233. }
  70234. const AffineTransform AffineTransform::scaled (const float factorX,
  70235. const float factorY) const throw()
  70236. {
  70237. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70238. factorY * mat10, factorY * mat11, factorY * mat12);
  70239. }
  70240. const AffineTransform AffineTransform::scale (const float factorX,
  70241. const float factorY) throw()
  70242. {
  70243. return AffineTransform (factorX, 0, 0,
  70244. 0, factorY, 0);
  70245. }
  70246. const AffineTransform AffineTransform::sheared (const float shearX,
  70247. const float shearY) const throw()
  70248. {
  70249. return followedBy (1.0f, shearX, 0,
  70250. shearY, 1.0f, 0);
  70251. }
  70252. const AffineTransform AffineTransform::inverted() const throw()
  70253. {
  70254. double determinant = (mat00 * mat11 - mat10 * mat01);
  70255. if (determinant != 0.0)
  70256. {
  70257. determinant = 1.0 / determinant;
  70258. const float dst00 = (float) (mat11 * determinant);
  70259. const float dst10 = (float) (-mat10 * determinant);
  70260. const float dst01 = (float) (-mat01 * determinant);
  70261. const float dst11 = (float) (mat00 * determinant);
  70262. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70263. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70264. }
  70265. else
  70266. {
  70267. // singularity..
  70268. return *this;
  70269. }
  70270. }
  70271. bool AffineTransform::isSingularity() const throw()
  70272. {
  70273. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70274. }
  70275. bool AffineTransform::isOnlyTranslation() const throw()
  70276. {
  70277. return (mat01 == 0)
  70278. && (mat10 == 0)
  70279. && (mat00 == 1.0f)
  70280. && (mat11 == 1.0f);
  70281. }
  70282. void AffineTransform::transformPoint (float& x,
  70283. float& y) const throw()
  70284. {
  70285. const float oldX = x;
  70286. x = mat00 * oldX + mat01 * y + mat02;
  70287. y = mat10 * oldX + mat11 * y + mat12;
  70288. }
  70289. void AffineTransform::transformPoint (double& x,
  70290. double& y) const throw()
  70291. {
  70292. const double oldX = x;
  70293. x = mat00 * oldX + mat01 * y + mat02;
  70294. y = mat10 * oldX + mat11 * y + mat12;
  70295. }
  70296. END_JUCE_NAMESPACE
  70297. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70298. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70299. BEGIN_JUCE_NAMESPACE
  70300. BorderSize::BorderSize() throw()
  70301. : top (0),
  70302. left (0),
  70303. bottom (0),
  70304. right (0)
  70305. {
  70306. }
  70307. BorderSize::BorderSize (const BorderSize& other) throw()
  70308. : top (other.top),
  70309. left (other.left),
  70310. bottom (other.bottom),
  70311. right (other.right)
  70312. {
  70313. }
  70314. BorderSize::BorderSize (const int topGap,
  70315. const int leftGap,
  70316. const int bottomGap,
  70317. const int rightGap) throw()
  70318. : top (topGap),
  70319. left (leftGap),
  70320. bottom (bottomGap),
  70321. right (rightGap)
  70322. {
  70323. }
  70324. BorderSize::BorderSize (const int allGaps) throw()
  70325. : top (allGaps),
  70326. left (allGaps),
  70327. bottom (allGaps),
  70328. right (allGaps)
  70329. {
  70330. }
  70331. BorderSize::~BorderSize() throw()
  70332. {
  70333. }
  70334. void BorderSize::setTop (const int newTopGap) throw()
  70335. {
  70336. top = newTopGap;
  70337. }
  70338. void BorderSize::setLeft (const int newLeftGap) throw()
  70339. {
  70340. left = newLeftGap;
  70341. }
  70342. void BorderSize::setBottom (const int newBottomGap) throw()
  70343. {
  70344. bottom = newBottomGap;
  70345. }
  70346. void BorderSize::setRight (const int newRightGap) throw()
  70347. {
  70348. right = newRightGap;
  70349. }
  70350. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70351. {
  70352. return Rectangle<int> (r.getX() + left,
  70353. r.getY() + top,
  70354. r.getWidth() - (left + right),
  70355. r.getHeight() - (top + bottom));
  70356. }
  70357. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70358. {
  70359. r.setBounds (r.getX() + left,
  70360. r.getY() + top,
  70361. r.getWidth() - (left + right),
  70362. r.getHeight() - (top + bottom));
  70363. }
  70364. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70365. {
  70366. return Rectangle<int> (r.getX() - left,
  70367. r.getY() - top,
  70368. r.getWidth() + (left + right),
  70369. r.getHeight() + (top + bottom));
  70370. }
  70371. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70372. {
  70373. r.setBounds (r.getX() - left,
  70374. r.getY() - top,
  70375. r.getWidth() + (left + right),
  70376. r.getHeight() + (top + bottom));
  70377. }
  70378. bool BorderSize::operator== (const BorderSize& other) const throw()
  70379. {
  70380. return top == other.top
  70381. && left == other.left
  70382. && bottom == other.bottom
  70383. && right == other.right;
  70384. }
  70385. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70386. {
  70387. return ! operator== (other);
  70388. }
  70389. END_JUCE_NAMESPACE
  70390. /*** End of inlined file: juce_BorderSize.cpp ***/
  70391. /*** Start of inlined file: juce_Line.cpp ***/
  70392. BEGIN_JUCE_NAMESPACE
  70393. static bool juce_lineIntersection (const float x1, const float y1,
  70394. const float x2, const float y2,
  70395. const float x3, const float y3,
  70396. const float x4, const float y4,
  70397. float& intersectionX,
  70398. float& intersectionY) throw()
  70399. {
  70400. if (x2 != x3 || y2 != y3)
  70401. {
  70402. const float dx1 = x2 - x1;
  70403. const float dy1 = y2 - y1;
  70404. const float dx2 = x4 - x3;
  70405. const float dy2 = y4 - y3;
  70406. const float divisor = dx1 * dy2 - dx2 * dy1;
  70407. if (divisor == 0)
  70408. {
  70409. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70410. {
  70411. if (dy1 == 0 && dy2 != 0)
  70412. {
  70413. const float along = (y1 - y3) / dy2;
  70414. intersectionX = x3 + along * dx2;
  70415. intersectionY = y1;
  70416. return along >= 0 && along <= 1.0f;
  70417. }
  70418. else if (dy2 == 0 && dy1 != 0)
  70419. {
  70420. const float along = (y3 - y1) / dy1;
  70421. intersectionX = x1 + along * dx1;
  70422. intersectionY = y3;
  70423. return along >= 0 && along <= 1.0f;
  70424. }
  70425. else if (dx1 == 0 && dx2 != 0)
  70426. {
  70427. const float along = (x1 - x3) / dx2;
  70428. intersectionX = x1;
  70429. intersectionY = y3 + along * dy2;
  70430. return along >= 0 && along <= 1.0f;
  70431. }
  70432. else if (dx2 == 0 && dx1 != 0)
  70433. {
  70434. const float along = (x3 - x1) / dx1;
  70435. intersectionX = x3;
  70436. intersectionY = y1 + along * dy1;
  70437. return along >= 0 && along <= 1.0f;
  70438. }
  70439. }
  70440. intersectionX = 0.5f * (x2 + x3);
  70441. intersectionY = 0.5f * (y2 + y3);
  70442. return false;
  70443. }
  70444. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70445. intersectionX = x1 + along1 * dx1;
  70446. intersectionY = y1 + along1 * dy1;
  70447. if (along1 < 0 || along1 > 1.0f)
  70448. return false;
  70449. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70450. return along2 >= 0 && along2 <= 1.0f;
  70451. }
  70452. intersectionX = x2;
  70453. intersectionY = y2;
  70454. return true;
  70455. }
  70456. Line::Line() throw()
  70457. : startX (0.0f),
  70458. startY (0.0f),
  70459. endX (0.0f),
  70460. endY (0.0f)
  70461. {
  70462. }
  70463. Line::Line (const Line& other) throw()
  70464. : startX (other.startX),
  70465. startY (other.startY),
  70466. endX (other.endX),
  70467. endY (other.endY)
  70468. {
  70469. }
  70470. Line::Line (const float startX_, const float startY_,
  70471. const float endX_, const float endY_) throw()
  70472. : startX (startX_),
  70473. startY (startY_),
  70474. endX (endX_),
  70475. endY (endY_)
  70476. {
  70477. }
  70478. Line::Line (const Point<float>& start,
  70479. const Point<float>& end) throw()
  70480. : startX (start.getX()),
  70481. startY (start.getY()),
  70482. endX (end.getX()),
  70483. endY (end.getY())
  70484. {
  70485. }
  70486. Line& Line::operator= (const Line& other) throw()
  70487. {
  70488. startX = other.startX;
  70489. startY = other.startY;
  70490. endX = other.endX;
  70491. endY = other.endY;
  70492. return *this;
  70493. }
  70494. Line::~Line() throw()
  70495. {
  70496. }
  70497. const Point<float> Line::getStart() const throw()
  70498. {
  70499. return Point<float> (startX, startY);
  70500. }
  70501. const Point<float> Line::getEnd() const throw()
  70502. {
  70503. return Point<float> (endX, endY);
  70504. }
  70505. void Line::setStart (const float newStartX,
  70506. const float newStartY) throw()
  70507. {
  70508. startX = newStartX;
  70509. startY = newStartY;
  70510. }
  70511. void Line::setStart (const Point<float>& newStart) throw()
  70512. {
  70513. startX = newStart.getX();
  70514. startY = newStart.getY();
  70515. }
  70516. void Line::setEnd (const float newEndX,
  70517. const float newEndY) throw()
  70518. {
  70519. endX = newEndX;
  70520. endY = newEndY;
  70521. }
  70522. void Line::setEnd (const Point<float>& newEnd) throw()
  70523. {
  70524. endX = newEnd.getX();
  70525. endY = newEnd.getY();
  70526. }
  70527. bool Line::operator== (const Line& other) const throw()
  70528. {
  70529. return startX == other.startX
  70530. && startY == other.startY
  70531. && endX == other.endX
  70532. && endY == other.endY;
  70533. }
  70534. bool Line::operator!= (const Line& other) const throw()
  70535. {
  70536. return startX != other.startX
  70537. || startY != other.startY
  70538. || endX != other.endX
  70539. || endY != other.endY;
  70540. }
  70541. void Line::applyTransform (const AffineTransform& transform) throw()
  70542. {
  70543. transform.transformPoint (startX, startY);
  70544. transform.transformPoint (endX, endY);
  70545. }
  70546. float Line::getLength() const throw()
  70547. {
  70548. return (float) juce_hypot (startX - endX,
  70549. startY - endY);
  70550. }
  70551. float Line::getAngle() const throw()
  70552. {
  70553. return atan2f (endX - startX,
  70554. endY - startY);
  70555. }
  70556. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70557. {
  70558. const float alpha = distanceFromStart / getLength();
  70559. return Point<float> (startX + (endX - startX) * alpha,
  70560. startY + (endY - startY) * alpha);
  70561. }
  70562. const Point<float> Line::getPointAlongLine (const float offsetX,
  70563. const float offsetY) const throw()
  70564. {
  70565. const float dx = endX - startX;
  70566. const float dy = endY - startY;
  70567. const double length = juce_hypot (dx, dy);
  70568. if (length == 0)
  70569. return Point<float> (startX, startY);
  70570. else
  70571. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70572. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70573. }
  70574. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70575. {
  70576. return Point<float> (startX + (endX - startX) * alpha,
  70577. startY + (endY - startY) * alpha);
  70578. }
  70579. float Line::getDistanceFromLine (const float x,
  70580. const float y) const throw()
  70581. {
  70582. const double dx = endX - startX;
  70583. const double dy = endY - startY;
  70584. const double length = dx * dx + dy * dy;
  70585. if (length > 0)
  70586. {
  70587. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70588. if (prop >= 0.0f && prop < 1.0f)
  70589. {
  70590. return (float) juce_hypot (x - (startX + prop * dx),
  70591. y - (startY + prop * dy));
  70592. }
  70593. }
  70594. return (float) jmin (juce_hypot (x - startX, y - startY),
  70595. juce_hypot (x - endX, y - endY));
  70596. }
  70597. float Line::findNearestPointTo (const float x,
  70598. const float y) const throw()
  70599. {
  70600. const double dx = endX - startX;
  70601. const double dy = endY - startY;
  70602. const double length = dx * dx + dy * dy;
  70603. if (length <= 0.0)
  70604. return 0.0f;
  70605. return jlimit (0.0f, 1.0f,
  70606. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70607. }
  70608. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70609. {
  70610. const float length = getLength();
  70611. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70612. getEnd());
  70613. }
  70614. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70615. {
  70616. const float length = getLength();
  70617. return Line (getStart(),
  70618. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70619. }
  70620. bool Line::clipToPath (const Path& path,
  70621. const bool keepSectionOutsidePath) throw()
  70622. {
  70623. const bool startInside = path.contains (startX, startY);
  70624. const bool endInside = path.contains (endX, endY);
  70625. if (startInside == endInside)
  70626. {
  70627. if (keepSectionOutsidePath != startInside)
  70628. {
  70629. // entirely outside the path
  70630. return false;
  70631. }
  70632. else
  70633. {
  70634. // entirely inside the path
  70635. startX = 0.0f;
  70636. startY = 0.0f;
  70637. endX = 0.0f;
  70638. endY = 0.0f;
  70639. return true;
  70640. }
  70641. }
  70642. else
  70643. {
  70644. bool changed = false;
  70645. PathFlatteningIterator iter (path, AffineTransform::identity);
  70646. while (iter.next())
  70647. {
  70648. float ix, iy;
  70649. if (intersects (Line (iter.x1, iter.y1,
  70650. iter.x2, iter.y2),
  70651. ix, iy))
  70652. {
  70653. if ((startInside && keepSectionOutsidePath)
  70654. || (endInside && ! keepSectionOutsidePath))
  70655. {
  70656. setStart (ix, iy);
  70657. }
  70658. else
  70659. {
  70660. setEnd (ix, iy);
  70661. }
  70662. changed = true;
  70663. }
  70664. }
  70665. return changed;
  70666. }
  70667. }
  70668. bool Line::intersects (const Line& line,
  70669. float& intersectionX,
  70670. float& intersectionY) const throw()
  70671. {
  70672. return juce_lineIntersection (startX, startY,
  70673. endX, endY,
  70674. line.startX, line.startY,
  70675. line.endX, line.endY,
  70676. intersectionX,
  70677. intersectionY);
  70678. }
  70679. bool Line::isVertical() const throw()
  70680. {
  70681. return startX == endX;
  70682. }
  70683. bool Line::isHorizontal() const throw()
  70684. {
  70685. return startY == endY;
  70686. }
  70687. bool Line::isPointAbove (const float x, const float y) const throw()
  70688. {
  70689. return startX != endX
  70690. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70691. }
  70692. END_JUCE_NAMESPACE
  70693. /*** End of inlined file: juce_Line.cpp ***/
  70694. /*** Start of inlined file: juce_Path.cpp ***/
  70695. BEGIN_JUCE_NAMESPACE
  70696. // tests that some co-ords aren't NaNs
  70697. #define CHECK_COORDS_ARE_VALID(x, y) \
  70698. jassert (x == x && y == y);
  70699. namespace PathHelpers
  70700. {
  70701. static const float ellipseAngularIncrement = 0.05f;
  70702. static void perpendicularOffset (const float x1, const float y1,
  70703. const float x2, const float y2,
  70704. const float offsetX, const float offsetY,
  70705. float& resultX, float& resultY) throw()
  70706. {
  70707. const float dx = x2 - x1;
  70708. const float dy = y2 - y1;
  70709. const float len = juce_hypotf (dx, dy);
  70710. if (len == 0)
  70711. {
  70712. resultX = x1;
  70713. resultY = y1;
  70714. }
  70715. else
  70716. {
  70717. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70718. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70719. }
  70720. }
  70721. static const String nextToken (const juce_wchar*& t)
  70722. {
  70723. while (CharacterFunctions::isWhitespace (*t))
  70724. ++t;
  70725. const juce_wchar* const start = t;
  70726. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70727. ++t;
  70728. const int length = (int) (t - start);
  70729. while (CharacterFunctions::isWhitespace (*t))
  70730. ++t;
  70731. return String (start, length);
  70732. }
  70733. }
  70734. const float Path::lineMarker = 100001.0f;
  70735. const float Path::moveMarker = 100002.0f;
  70736. const float Path::quadMarker = 100003.0f;
  70737. const float Path::cubicMarker = 100004.0f;
  70738. const float Path::closeSubPathMarker = 100005.0f;
  70739. Path::Path()
  70740. : numElements (0),
  70741. pathXMin (0),
  70742. pathXMax (0),
  70743. pathYMin (0),
  70744. pathYMax (0),
  70745. useNonZeroWinding (true)
  70746. {
  70747. }
  70748. Path::~Path()
  70749. {
  70750. }
  70751. Path::Path (const Path& other)
  70752. : numElements (other.numElements),
  70753. pathXMin (other.pathXMin),
  70754. pathXMax (other.pathXMax),
  70755. pathYMin (other.pathYMin),
  70756. pathYMax (other.pathYMax),
  70757. useNonZeroWinding (other.useNonZeroWinding)
  70758. {
  70759. if (numElements > 0)
  70760. {
  70761. data.setAllocatedSize (numElements);
  70762. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70763. }
  70764. }
  70765. Path& Path::operator= (const Path& other)
  70766. {
  70767. if (this != &other)
  70768. {
  70769. data.ensureAllocatedSize (other.numElements);
  70770. numElements = other.numElements;
  70771. pathXMin = other.pathXMin;
  70772. pathXMax = other.pathXMax;
  70773. pathYMin = other.pathYMin;
  70774. pathYMax = other.pathYMax;
  70775. useNonZeroWinding = other.useNonZeroWinding;
  70776. if (numElements > 0)
  70777. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70778. }
  70779. return *this;
  70780. }
  70781. void Path::clear() throw()
  70782. {
  70783. numElements = 0;
  70784. pathXMin = 0;
  70785. pathYMin = 0;
  70786. pathYMax = 0;
  70787. pathXMax = 0;
  70788. }
  70789. void Path::swapWithPath (Path& other)
  70790. {
  70791. data.swapWith (other.data);
  70792. swapVariables <size_t> (numElements, other.numElements);
  70793. swapVariables <float> (pathXMin, other.pathXMin);
  70794. swapVariables <float> (pathXMax, other.pathXMax);
  70795. swapVariables <float> (pathYMin, other.pathYMin);
  70796. swapVariables <float> (pathYMax, other.pathYMax);
  70797. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70798. }
  70799. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70800. {
  70801. useNonZeroWinding = isNonZero;
  70802. }
  70803. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70804. const bool preserveProportions) throw()
  70805. {
  70806. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70807. }
  70808. bool Path::isEmpty() const throw()
  70809. {
  70810. size_t i = 0;
  70811. while (i < numElements)
  70812. {
  70813. const float type = data.elements [i++];
  70814. if (type == moveMarker)
  70815. {
  70816. i += 2;
  70817. }
  70818. else if (type == lineMarker
  70819. || type == quadMarker
  70820. || type == cubicMarker)
  70821. {
  70822. return false;
  70823. }
  70824. }
  70825. return true;
  70826. }
  70827. const Rectangle<float> Path::getBounds() const throw()
  70828. {
  70829. return Rectangle<float> (pathXMin, pathYMin,
  70830. pathXMax - pathXMin,
  70831. pathYMax - pathYMin);
  70832. }
  70833. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70834. {
  70835. return getBounds().transformed (transform);
  70836. }
  70837. void Path::startNewSubPath (const float x, const float y)
  70838. {
  70839. CHECK_COORDS_ARE_VALID (x, y);
  70840. if (numElements == 0)
  70841. {
  70842. pathXMin = pathXMax = x;
  70843. pathYMin = pathYMax = y;
  70844. }
  70845. else
  70846. {
  70847. pathXMin = jmin (pathXMin, x);
  70848. pathXMax = jmax (pathXMax, x);
  70849. pathYMin = jmin (pathYMin, y);
  70850. pathYMax = jmax (pathYMax, y);
  70851. }
  70852. data.ensureAllocatedSize (numElements + 3);
  70853. data.elements [numElements++] = moveMarker;
  70854. data.elements [numElements++] = x;
  70855. data.elements [numElements++] = y;
  70856. }
  70857. void Path::lineTo (const float x, const float y)
  70858. {
  70859. CHECK_COORDS_ARE_VALID (x, y);
  70860. if (numElements == 0)
  70861. startNewSubPath (0, 0);
  70862. data.ensureAllocatedSize (numElements + 3);
  70863. data.elements [numElements++] = lineMarker;
  70864. data.elements [numElements++] = x;
  70865. data.elements [numElements++] = y;
  70866. pathXMin = jmin (pathXMin, x);
  70867. pathXMax = jmax (pathXMax, x);
  70868. pathYMin = jmin (pathYMin, y);
  70869. pathYMax = jmax (pathYMax, y);
  70870. }
  70871. void Path::quadraticTo (const float x1, const float y1,
  70872. const float x2, const float y2)
  70873. {
  70874. CHECK_COORDS_ARE_VALID (x1, y1);
  70875. CHECK_COORDS_ARE_VALID (x2, y2);
  70876. if (numElements == 0)
  70877. startNewSubPath (0, 0);
  70878. data.ensureAllocatedSize (numElements + 5);
  70879. data.elements [numElements++] = quadMarker;
  70880. data.elements [numElements++] = x1;
  70881. data.elements [numElements++] = y1;
  70882. data.elements [numElements++] = x2;
  70883. data.elements [numElements++] = y2;
  70884. pathXMin = jmin (pathXMin, x1, x2);
  70885. pathXMax = jmax (pathXMax, x1, x2);
  70886. pathYMin = jmin (pathYMin, y1, y2);
  70887. pathYMax = jmax (pathYMax, y1, y2);
  70888. }
  70889. void Path::cubicTo (const float x1, const float y1,
  70890. const float x2, const float y2,
  70891. const float x3, const float y3)
  70892. {
  70893. CHECK_COORDS_ARE_VALID (x1, y1);
  70894. CHECK_COORDS_ARE_VALID (x2, y2);
  70895. CHECK_COORDS_ARE_VALID (x3, y3);
  70896. if (numElements == 0)
  70897. startNewSubPath (0, 0);
  70898. data.ensureAllocatedSize (numElements + 7);
  70899. data.elements [numElements++] = cubicMarker;
  70900. data.elements [numElements++] = x1;
  70901. data.elements [numElements++] = y1;
  70902. data.elements [numElements++] = x2;
  70903. data.elements [numElements++] = y2;
  70904. data.elements [numElements++] = x3;
  70905. data.elements [numElements++] = y3;
  70906. pathXMin = jmin (pathXMin, x1, x2, x3);
  70907. pathXMax = jmax (pathXMax, x1, x2, x3);
  70908. pathYMin = jmin (pathYMin, y1, y2, y3);
  70909. pathYMax = jmax (pathYMax, y1, y2, y3);
  70910. }
  70911. void Path::closeSubPath()
  70912. {
  70913. if (numElements > 0
  70914. && data.elements [numElements - 1] != closeSubPathMarker)
  70915. {
  70916. data.ensureAllocatedSize (numElements + 1);
  70917. data.elements [numElements++] = closeSubPathMarker;
  70918. }
  70919. }
  70920. const Point<float> Path::getCurrentPosition() const
  70921. {
  70922. int i = numElements - 1;
  70923. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70924. {
  70925. while (i >= 0)
  70926. {
  70927. if (data.elements[i] == moveMarker)
  70928. {
  70929. i += 2;
  70930. break;
  70931. }
  70932. --i;
  70933. }
  70934. }
  70935. if (i > 0)
  70936. return Point<float> (data.elements [i - 1], data.elements [i]);
  70937. return Point<float>();
  70938. }
  70939. void Path::addRectangle (const float x, const float y,
  70940. const float w, const float h)
  70941. {
  70942. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  70943. if (w < 0)
  70944. swapVariables (x1, x2);
  70945. if (h < 0)
  70946. swapVariables (y1, y2);
  70947. data.ensureAllocatedSize (numElements + 13);
  70948. if (numElements == 0)
  70949. {
  70950. pathXMin = x1;
  70951. pathXMax = x2;
  70952. pathYMin = y1;
  70953. pathYMax = y2;
  70954. }
  70955. else
  70956. {
  70957. pathXMin = jmin (pathXMin, x1);
  70958. pathXMax = jmax (pathXMax, x2);
  70959. pathYMin = jmin (pathYMin, y1);
  70960. pathYMax = jmax (pathYMax, y2);
  70961. }
  70962. data.elements [numElements++] = moveMarker;
  70963. data.elements [numElements++] = x1;
  70964. data.elements [numElements++] = y2;
  70965. data.elements [numElements++] = lineMarker;
  70966. data.elements [numElements++] = x1;
  70967. data.elements [numElements++] = y1;
  70968. data.elements [numElements++] = lineMarker;
  70969. data.elements [numElements++] = x2;
  70970. data.elements [numElements++] = y1;
  70971. data.elements [numElements++] = lineMarker;
  70972. data.elements [numElements++] = x2;
  70973. data.elements [numElements++] = y2;
  70974. data.elements [numElements++] = closeSubPathMarker;
  70975. }
  70976. void Path::addRectangle (const Rectangle<int>& rectangle)
  70977. {
  70978. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  70979. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  70980. }
  70981. void Path::addRoundedRectangle (const float x, const float y,
  70982. const float w, const float h,
  70983. float csx,
  70984. float csy)
  70985. {
  70986. csx = jmin (csx, w * 0.5f);
  70987. csy = jmin (csy, h * 0.5f);
  70988. const float cs45x = csx * 0.45f;
  70989. const float cs45y = csy * 0.45f;
  70990. const float x2 = x + w;
  70991. const float y2 = y + h;
  70992. startNewSubPath (x + csx, y);
  70993. lineTo (x2 - csx, y);
  70994. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  70995. lineTo (x2, y2 - csy);
  70996. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  70997. lineTo (x + csx, y2);
  70998. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  70999. lineTo (x, y + csy);
  71000. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71001. closeSubPath();
  71002. }
  71003. void Path::addRoundedRectangle (const float x, const float y,
  71004. const float w, const float h,
  71005. float cs)
  71006. {
  71007. addRoundedRectangle (x, y, w, h, cs, cs);
  71008. }
  71009. void Path::addTriangle (const float x1, const float y1,
  71010. const float x2, const float y2,
  71011. const float x3, const float y3)
  71012. {
  71013. startNewSubPath (x1, y1);
  71014. lineTo (x2, y2);
  71015. lineTo (x3, y3);
  71016. closeSubPath();
  71017. }
  71018. void Path::addQuadrilateral (const float x1, const float y1,
  71019. const float x2, const float y2,
  71020. const float x3, const float y3,
  71021. const float x4, const float y4)
  71022. {
  71023. startNewSubPath (x1, y1);
  71024. lineTo (x2, y2);
  71025. lineTo (x3, y3);
  71026. lineTo (x4, y4);
  71027. closeSubPath();
  71028. }
  71029. void Path::addEllipse (const float x, const float y,
  71030. const float w, const float h)
  71031. {
  71032. const float hw = w * 0.5f;
  71033. const float hw55 = hw * 0.55f;
  71034. const float hh = h * 0.5f;
  71035. const float hh45 = hh * 0.55f;
  71036. const float cx = x + hw;
  71037. const float cy = y + hh;
  71038. startNewSubPath (cx, cy - hh);
  71039. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71040. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71041. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71042. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71043. closeSubPath();
  71044. }
  71045. void Path::addArc (const float x, const float y,
  71046. const float w, const float h,
  71047. const float fromRadians,
  71048. const float toRadians,
  71049. const bool startAsNewSubPath)
  71050. {
  71051. const float radiusX = w / 2.0f;
  71052. const float radiusY = h / 2.0f;
  71053. addCentredArc (x + radiusX,
  71054. y + radiusY,
  71055. radiusX, radiusY,
  71056. 0.0f,
  71057. fromRadians, toRadians,
  71058. startAsNewSubPath);
  71059. }
  71060. void Path::addCentredArc (const float centreX, const float centreY,
  71061. const float radiusX, const float radiusY,
  71062. const float rotationOfEllipse,
  71063. const float fromRadians,
  71064. const float toRadians,
  71065. const bool startAsNewSubPath)
  71066. {
  71067. if (radiusX > 0.0f && radiusY > 0.0f)
  71068. {
  71069. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71070. float angle = fromRadians;
  71071. if (startAsNewSubPath)
  71072. {
  71073. float x = centreX + radiusX * sinf (angle);
  71074. float y = centreY - radiusY * cosf (angle);
  71075. if (rotationOfEllipse != 0)
  71076. rotation.transformPoint (x, y);
  71077. startNewSubPath (x, y);
  71078. }
  71079. if (fromRadians < toRadians)
  71080. {
  71081. if (startAsNewSubPath)
  71082. angle += PathHelpers::ellipseAngularIncrement;
  71083. while (angle < toRadians)
  71084. {
  71085. float x = centreX + radiusX * sinf (angle);
  71086. float y = centreY - radiusY * cosf (angle);
  71087. if (rotationOfEllipse != 0)
  71088. rotation.transformPoint (x, y);
  71089. lineTo (x, y);
  71090. angle += PathHelpers::ellipseAngularIncrement;
  71091. }
  71092. }
  71093. else
  71094. {
  71095. if (startAsNewSubPath)
  71096. angle -= PathHelpers::ellipseAngularIncrement;
  71097. while (angle > toRadians)
  71098. {
  71099. float x = centreX + radiusX * sinf (angle);
  71100. float y = centreY - radiusY * cosf (angle);
  71101. if (rotationOfEllipse != 0)
  71102. rotation.transformPoint (x, y);
  71103. lineTo (x, y);
  71104. angle -= PathHelpers::ellipseAngularIncrement;
  71105. }
  71106. }
  71107. float x = centreX + radiusX * sinf (toRadians);
  71108. float y = centreY - radiusY * cosf (toRadians);
  71109. if (rotationOfEllipse != 0)
  71110. rotation.transformPoint (x, y);
  71111. lineTo (x, y);
  71112. }
  71113. }
  71114. void Path::addPieSegment (const float x, const float y,
  71115. const float width, const float height,
  71116. const float fromRadians,
  71117. const float toRadians,
  71118. const float innerCircleProportionalSize)
  71119. {
  71120. float hw = width * 0.5f;
  71121. float hh = height * 0.5f;
  71122. const float centreX = x + hw;
  71123. const float centreY = y + hh;
  71124. startNewSubPath (centreX + hw * sinf (fromRadians),
  71125. centreY - hh * cosf (fromRadians));
  71126. addArc (x, y, width, height, fromRadians, toRadians);
  71127. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71128. {
  71129. closeSubPath();
  71130. if (innerCircleProportionalSize > 0)
  71131. {
  71132. hw *= innerCircleProportionalSize;
  71133. hh *= innerCircleProportionalSize;
  71134. startNewSubPath (centreX + hw * sinf (toRadians),
  71135. centreY - hh * cosf (toRadians));
  71136. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71137. toRadians, fromRadians);
  71138. }
  71139. }
  71140. else
  71141. {
  71142. if (innerCircleProportionalSize > 0)
  71143. {
  71144. hw *= innerCircleProportionalSize;
  71145. hh *= innerCircleProportionalSize;
  71146. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71147. toRadians, fromRadians);
  71148. }
  71149. else
  71150. {
  71151. lineTo (centreX, centreY);
  71152. }
  71153. }
  71154. closeSubPath();
  71155. }
  71156. void Path::addLineSegment (const float startX, const float startY,
  71157. const float endX, const float endY,
  71158. float lineThickness)
  71159. {
  71160. lineThickness *= 0.5f;
  71161. float x, y;
  71162. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71163. 0, lineThickness, x, y);
  71164. startNewSubPath (x, y);
  71165. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71166. 0, -lineThickness, x, y);
  71167. lineTo (x, y);
  71168. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71169. 0, lineThickness, x, y);
  71170. lineTo (x, y);
  71171. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71172. 0, -lineThickness, x, y);
  71173. lineTo (x, y);
  71174. closeSubPath();
  71175. }
  71176. void Path::addArrow (const float startX, const float startY,
  71177. const float endX, const float endY,
  71178. float lineThickness,
  71179. float arrowheadWidth,
  71180. float arrowheadLength)
  71181. {
  71182. lineThickness *= 0.5f;
  71183. arrowheadWidth *= 0.5f;
  71184. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71185. startY - endY));
  71186. float x, y;
  71187. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71188. 0, lineThickness, x, y);
  71189. startNewSubPath (x, y);
  71190. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71191. 0, -lineThickness, x, y);
  71192. lineTo (x, y);
  71193. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71194. arrowheadLength, lineThickness, x, y);
  71195. lineTo (x, y);
  71196. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71197. arrowheadLength, arrowheadWidth, x, y);
  71198. lineTo (x, y);
  71199. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71200. 0, 0, x, y);
  71201. lineTo (x, y);
  71202. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71203. arrowheadLength, -arrowheadWidth, x, y);
  71204. lineTo (x, y);
  71205. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71206. arrowheadLength, -lineThickness, x, y);
  71207. lineTo (x, y);
  71208. closeSubPath();
  71209. }
  71210. void Path::addStar (const float centreX,
  71211. const float centreY,
  71212. const int numberOfPoints,
  71213. const float innerRadius,
  71214. const float outerRadius,
  71215. const float startAngle)
  71216. {
  71217. jassert (numberOfPoints > 1); // this would be silly.
  71218. if (numberOfPoints > 1)
  71219. {
  71220. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71221. for (int i = 0; i < numberOfPoints; ++i)
  71222. {
  71223. float angle = startAngle + i * angleBetweenPoints;
  71224. const float x = centreX + outerRadius * sinf (angle);
  71225. const float y = centreY - outerRadius * cosf (angle);
  71226. if (i == 0)
  71227. startNewSubPath (x, y);
  71228. else
  71229. lineTo (x, y);
  71230. angle += angleBetweenPoints * 0.5f;
  71231. lineTo (centreX + innerRadius * sinf (angle),
  71232. centreY - innerRadius * cosf (angle));
  71233. }
  71234. closeSubPath();
  71235. }
  71236. }
  71237. void Path::addBubble (float x, float y,
  71238. float w, float h,
  71239. float cs,
  71240. float tipX,
  71241. float tipY,
  71242. int whichSide,
  71243. float arrowPos,
  71244. float arrowWidth)
  71245. {
  71246. if (w > 1.0f && h > 1.0f)
  71247. {
  71248. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71249. const float cs2 = 2.0f * cs;
  71250. startNewSubPath (x + cs, y);
  71251. if (whichSide == 0)
  71252. {
  71253. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71254. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71255. lineTo (arrowX1, y);
  71256. lineTo (tipX, tipY);
  71257. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71258. }
  71259. lineTo (x + w - cs, y);
  71260. if (cs > 0.0f)
  71261. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71262. if (whichSide == 3)
  71263. {
  71264. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71265. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71266. lineTo (x + w, arrowY1);
  71267. lineTo (tipX, tipY);
  71268. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71269. }
  71270. lineTo (x + w, y + h - cs);
  71271. if (cs > 0.0f)
  71272. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71273. if (whichSide == 2)
  71274. {
  71275. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71276. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71277. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71278. lineTo (tipX, tipY);
  71279. lineTo (arrowX1, y + h);
  71280. }
  71281. lineTo (x + cs, y + h);
  71282. if (cs > 0.0f)
  71283. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71284. if (whichSide == 1)
  71285. {
  71286. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71287. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71288. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71289. lineTo (tipX, tipY);
  71290. lineTo (x, arrowY1);
  71291. }
  71292. lineTo (x, y + cs);
  71293. if (cs > 0.0f)
  71294. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71295. closeSubPath();
  71296. }
  71297. }
  71298. void Path::addPath (const Path& other)
  71299. {
  71300. size_t i = 0;
  71301. while (i < other.numElements)
  71302. {
  71303. const float type = other.data.elements [i++];
  71304. if (type == moveMarker)
  71305. {
  71306. startNewSubPath (other.data.elements [i],
  71307. other.data.elements [i + 1]);
  71308. i += 2;
  71309. }
  71310. else if (type == lineMarker)
  71311. {
  71312. lineTo (other.data.elements [i],
  71313. other.data.elements [i + 1]);
  71314. i += 2;
  71315. }
  71316. else if (type == quadMarker)
  71317. {
  71318. quadraticTo (other.data.elements [i],
  71319. other.data.elements [i + 1],
  71320. other.data.elements [i + 2],
  71321. other.data.elements [i + 3]);
  71322. i += 4;
  71323. }
  71324. else if (type == cubicMarker)
  71325. {
  71326. cubicTo (other.data.elements [i],
  71327. other.data.elements [i + 1],
  71328. other.data.elements [i + 2],
  71329. other.data.elements [i + 3],
  71330. other.data.elements [i + 4],
  71331. other.data.elements [i + 5]);
  71332. i += 6;
  71333. }
  71334. else if (type == closeSubPathMarker)
  71335. {
  71336. closeSubPath();
  71337. }
  71338. else
  71339. {
  71340. // something's gone wrong with the element list!
  71341. jassertfalse
  71342. }
  71343. }
  71344. }
  71345. void Path::addPath (const Path& other,
  71346. const AffineTransform& transformToApply)
  71347. {
  71348. size_t i = 0;
  71349. while (i < other.numElements)
  71350. {
  71351. const float type = other.data.elements [i++];
  71352. if (type == closeSubPathMarker)
  71353. {
  71354. closeSubPath();
  71355. }
  71356. else
  71357. {
  71358. float x = other.data.elements [i++];
  71359. float y = other.data.elements [i++];
  71360. transformToApply.transformPoint (x, y);
  71361. if (type == moveMarker)
  71362. {
  71363. startNewSubPath (x, y);
  71364. }
  71365. else if (type == lineMarker)
  71366. {
  71367. lineTo (x, y);
  71368. }
  71369. else if (type == quadMarker)
  71370. {
  71371. float x2 = other.data.elements [i++];
  71372. float y2 = other.data.elements [i++];
  71373. transformToApply.transformPoint (x2, y2);
  71374. quadraticTo (x, y, x2, y2);
  71375. }
  71376. else if (type == cubicMarker)
  71377. {
  71378. float x2 = other.data.elements [i++];
  71379. float y2 = other.data.elements [i++];
  71380. float x3 = other.data.elements [i++];
  71381. float y3 = other.data.elements [i++];
  71382. transformToApply.transformPoint (x2, y2);
  71383. transformToApply.transformPoint (x3, y3);
  71384. cubicTo (x, y, x2, y2, x3, y3);
  71385. }
  71386. else
  71387. {
  71388. // something's gone wrong with the element list!
  71389. jassertfalse
  71390. }
  71391. }
  71392. }
  71393. }
  71394. void Path::applyTransform (const AffineTransform& transform) throw()
  71395. {
  71396. size_t i = 0;
  71397. pathYMin = pathXMin = 0;
  71398. pathYMax = pathXMax = 0;
  71399. bool setMaxMin = false;
  71400. while (i < numElements)
  71401. {
  71402. const float type = data.elements [i++];
  71403. if (type == moveMarker)
  71404. {
  71405. transform.transformPoint (data.elements [i],
  71406. data.elements [i + 1]);
  71407. if (setMaxMin)
  71408. {
  71409. pathXMin = jmin (pathXMin, data.elements [i]);
  71410. pathXMax = jmax (pathXMax, data.elements [i]);
  71411. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71412. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71413. }
  71414. else
  71415. {
  71416. pathXMin = pathXMax = data.elements [i];
  71417. pathYMin = pathYMax = data.elements [i + 1];
  71418. setMaxMin = true;
  71419. }
  71420. i += 2;
  71421. }
  71422. else if (type == lineMarker)
  71423. {
  71424. transform.transformPoint (data.elements [i],
  71425. data.elements [i + 1]);
  71426. pathXMin = jmin (pathXMin, data.elements [i]);
  71427. pathXMax = jmax (pathXMax, data.elements [i]);
  71428. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71429. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71430. i += 2;
  71431. }
  71432. else if (type == quadMarker)
  71433. {
  71434. transform.transformPoint (data.elements [i],
  71435. data.elements [i + 1]);
  71436. transform.transformPoint (data.elements [i + 2],
  71437. data.elements [i + 3]);
  71438. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71439. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71440. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71441. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71442. i += 4;
  71443. }
  71444. else if (type == cubicMarker)
  71445. {
  71446. transform.transformPoint (data.elements [i],
  71447. data.elements [i + 1]);
  71448. transform.transformPoint (data.elements [i + 2],
  71449. data.elements [i + 3]);
  71450. transform.transformPoint (data.elements [i + 4],
  71451. data.elements [i + 5]);
  71452. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71453. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71454. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71455. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71456. i += 6;
  71457. }
  71458. }
  71459. }
  71460. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71461. const float w, const float h,
  71462. const bool preserveProportions,
  71463. const Justification& justification) const
  71464. {
  71465. Rectangle<float> bounds (getBounds());
  71466. if (preserveProportions)
  71467. {
  71468. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71469. return AffineTransform::identity;
  71470. float newW, newH;
  71471. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71472. if (srcRatio > h / w)
  71473. {
  71474. newW = h / srcRatio;
  71475. newH = h;
  71476. }
  71477. else
  71478. {
  71479. newW = w;
  71480. newH = w * srcRatio;
  71481. }
  71482. float newXCentre = x;
  71483. float newYCentre = y;
  71484. if (justification.testFlags (Justification::left))
  71485. newXCentre += newW * 0.5f;
  71486. else if (justification.testFlags (Justification::right))
  71487. newXCentre += w - newW * 0.5f;
  71488. else
  71489. newXCentre += w * 0.5f;
  71490. if (justification.testFlags (Justification::top))
  71491. newYCentre += newH * 0.5f;
  71492. else if (justification.testFlags (Justification::bottom))
  71493. newYCentre += h - newH * 0.5f;
  71494. else
  71495. newYCentre += h * 0.5f;
  71496. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71497. bounds.getHeight() * -0.5f - bounds.getY())
  71498. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71499. .translated (newXCentre, newYCentre);
  71500. }
  71501. else
  71502. {
  71503. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71504. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71505. .translated (x, y);
  71506. }
  71507. }
  71508. bool Path::contains (const float x, const float y, const float tolerence) const
  71509. {
  71510. if (x <= pathXMin || x >= pathXMax
  71511. || y <= pathYMin || y >= pathYMax)
  71512. return false;
  71513. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71514. int positiveCrossings = 0;
  71515. int negativeCrossings = 0;
  71516. while (i.next())
  71517. {
  71518. if ((i.y1 <= y && i.y2 > y)
  71519. || (i.y2 <= y && i.y1 > y))
  71520. {
  71521. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71522. if (intersectX <= x)
  71523. {
  71524. if (i.y1 < i.y2)
  71525. ++positiveCrossings;
  71526. else
  71527. ++negativeCrossings;
  71528. }
  71529. }
  71530. }
  71531. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71532. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71533. }
  71534. bool Path::intersectsLine (const float x1, const float y1,
  71535. const float x2, const float y2,
  71536. const float tolerence)
  71537. {
  71538. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71539. const Line line1 (x1, y1, x2, y2);
  71540. while (i.next())
  71541. {
  71542. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71543. float ix, iy;
  71544. if (line1.intersects (line2, ix, iy))
  71545. return true;
  71546. }
  71547. return false;
  71548. }
  71549. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71550. {
  71551. if (cornerRadius <= 0.01f)
  71552. return *this;
  71553. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71554. size_t n = 0;
  71555. bool lastWasLine = false, firstWasLine = false;
  71556. Path p;
  71557. while (n < numElements)
  71558. {
  71559. const float type = data.elements [n++];
  71560. if (type == moveMarker)
  71561. {
  71562. indexOfPathStart = p.numElements;
  71563. indexOfPathStartThis = n - 1;
  71564. const float x = data.elements [n++];
  71565. const float y = data.elements [n++];
  71566. p.startNewSubPath (x, y);
  71567. lastWasLine = false;
  71568. firstWasLine = (data.elements [n] == lineMarker);
  71569. }
  71570. else if (type == lineMarker || type == closeSubPathMarker)
  71571. {
  71572. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71573. if (type == lineMarker)
  71574. {
  71575. endX = data.elements [n++];
  71576. endY = data.elements [n++];
  71577. if (n > 8)
  71578. {
  71579. startX = data.elements [n - 8];
  71580. startY = data.elements [n - 7];
  71581. joinX = data.elements [n - 5];
  71582. joinY = data.elements [n - 4];
  71583. }
  71584. }
  71585. else
  71586. {
  71587. endX = data.elements [indexOfPathStartThis + 1];
  71588. endY = data.elements [indexOfPathStartThis + 2];
  71589. if (n > 6)
  71590. {
  71591. startX = data.elements [n - 6];
  71592. startY = data.elements [n - 5];
  71593. joinX = data.elements [n - 3];
  71594. joinY = data.elements [n - 2];
  71595. }
  71596. }
  71597. if (lastWasLine)
  71598. {
  71599. const double len1 = juce_hypot (startX - joinX,
  71600. startY - joinY);
  71601. if (len1 > 0)
  71602. {
  71603. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71604. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71605. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71606. }
  71607. const double len2 = juce_hypot (endX - joinX,
  71608. endY - joinY);
  71609. if (len2 > 0)
  71610. {
  71611. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71612. p.quadraticTo (joinX, joinY,
  71613. (float) (joinX + (endX - joinX) * propNeeded),
  71614. (float) (joinY + (endY - joinY) * propNeeded));
  71615. }
  71616. p.lineTo (endX, endY);
  71617. }
  71618. else if (type == lineMarker)
  71619. {
  71620. p.lineTo (endX, endY);
  71621. lastWasLine = true;
  71622. }
  71623. if (type == closeSubPathMarker)
  71624. {
  71625. if (firstWasLine)
  71626. {
  71627. startX = data.elements [n - 3];
  71628. startY = data.elements [n - 2];
  71629. joinX = endX;
  71630. joinY = endY;
  71631. endX = data.elements [indexOfPathStartThis + 4];
  71632. endY = data.elements [indexOfPathStartThis + 5];
  71633. const double len1 = juce_hypot (startX - joinX,
  71634. startY - joinY);
  71635. if (len1 > 0)
  71636. {
  71637. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71638. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71639. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71640. }
  71641. const double len2 = juce_hypot (endX - joinX,
  71642. endY - joinY);
  71643. if (len2 > 0)
  71644. {
  71645. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71646. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71647. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71648. p.quadraticTo (joinX, joinY, endX, endY);
  71649. p.data.elements [indexOfPathStart + 1] = endX;
  71650. p.data.elements [indexOfPathStart + 2] = endY;
  71651. }
  71652. }
  71653. p.closeSubPath();
  71654. }
  71655. }
  71656. else if (type == quadMarker)
  71657. {
  71658. lastWasLine = false;
  71659. const float x1 = data.elements [n++];
  71660. const float y1 = data.elements [n++];
  71661. const float x2 = data.elements [n++];
  71662. const float y2 = data.elements [n++];
  71663. p.quadraticTo (x1, y1, x2, y2);
  71664. }
  71665. else if (type == cubicMarker)
  71666. {
  71667. lastWasLine = false;
  71668. const float x1 = data.elements [n++];
  71669. const float y1 = data.elements [n++];
  71670. const float x2 = data.elements [n++];
  71671. const float y2 = data.elements [n++];
  71672. const float x3 = data.elements [n++];
  71673. const float y3 = data.elements [n++];
  71674. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71675. }
  71676. }
  71677. return p;
  71678. }
  71679. void Path::loadPathFromStream (InputStream& source)
  71680. {
  71681. while (! source.isExhausted())
  71682. {
  71683. switch (source.readByte())
  71684. {
  71685. case 'm':
  71686. {
  71687. const float x = source.readFloat();
  71688. const float y = source.readFloat();
  71689. startNewSubPath (x, y);
  71690. break;
  71691. }
  71692. case 'l':
  71693. {
  71694. const float x = source.readFloat();
  71695. const float y = source.readFloat();
  71696. lineTo (x, y);
  71697. break;
  71698. }
  71699. case 'q':
  71700. {
  71701. const float x1 = source.readFloat();
  71702. const float y1 = source.readFloat();
  71703. const float x2 = source.readFloat();
  71704. const float y2 = source.readFloat();
  71705. quadraticTo (x1, y1, x2, y2);
  71706. break;
  71707. }
  71708. case 'b':
  71709. {
  71710. const float x1 = source.readFloat();
  71711. const float y1 = source.readFloat();
  71712. const float x2 = source.readFloat();
  71713. const float y2 = source.readFloat();
  71714. const float x3 = source.readFloat();
  71715. const float y3 = source.readFloat();
  71716. cubicTo (x1, y1, x2, y2, x3, y3);
  71717. break;
  71718. }
  71719. case 'c':
  71720. closeSubPath();
  71721. break;
  71722. case 'n':
  71723. useNonZeroWinding = true;
  71724. break;
  71725. case 'z':
  71726. useNonZeroWinding = false;
  71727. break;
  71728. case 'e':
  71729. return; // end of path marker
  71730. default:
  71731. jassertfalse // illegal char in the stream
  71732. break;
  71733. }
  71734. }
  71735. }
  71736. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71737. {
  71738. MemoryInputStream in (data, numberOfBytes, false);
  71739. loadPathFromStream (in);
  71740. }
  71741. void Path::writePathToStream (OutputStream& dest) const
  71742. {
  71743. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71744. size_t i = 0;
  71745. while (i < numElements)
  71746. {
  71747. const float type = data.elements [i++];
  71748. if (type == moveMarker)
  71749. {
  71750. dest.writeByte ('m');
  71751. dest.writeFloat (data.elements [i++]);
  71752. dest.writeFloat (data.elements [i++]);
  71753. }
  71754. else if (type == lineMarker)
  71755. {
  71756. dest.writeByte ('l');
  71757. dest.writeFloat (data.elements [i++]);
  71758. dest.writeFloat (data.elements [i++]);
  71759. }
  71760. else if (type == quadMarker)
  71761. {
  71762. dest.writeByte ('q');
  71763. dest.writeFloat (data.elements [i++]);
  71764. dest.writeFloat (data.elements [i++]);
  71765. dest.writeFloat (data.elements [i++]);
  71766. dest.writeFloat (data.elements [i++]);
  71767. }
  71768. else if (type == cubicMarker)
  71769. {
  71770. dest.writeByte ('b');
  71771. dest.writeFloat (data.elements [i++]);
  71772. dest.writeFloat (data.elements [i++]);
  71773. dest.writeFloat (data.elements [i++]);
  71774. dest.writeFloat (data.elements [i++]);
  71775. dest.writeFloat (data.elements [i++]);
  71776. dest.writeFloat (data.elements [i++]);
  71777. }
  71778. else if (type == closeSubPathMarker)
  71779. {
  71780. dest.writeByte ('c');
  71781. }
  71782. }
  71783. dest.writeByte ('e'); // marks the end-of-path
  71784. }
  71785. const String Path::toString() const
  71786. {
  71787. MemoryOutputStream s (2048, 2048);
  71788. if (! useNonZeroWinding)
  71789. s << 'a';
  71790. size_t i = 0;
  71791. float lastMarker = 0.0f;
  71792. while (i < numElements)
  71793. {
  71794. const float marker = data.elements [i++];
  71795. char markerChar = 0;
  71796. int numCoords = 0;
  71797. if (marker == moveMarker)
  71798. {
  71799. markerChar = 'm';
  71800. numCoords = 2;
  71801. }
  71802. else if (marker == lineMarker)
  71803. {
  71804. markerChar = 'l';
  71805. numCoords = 2;
  71806. }
  71807. else if (marker == quadMarker)
  71808. {
  71809. markerChar = 'q';
  71810. numCoords = 4;
  71811. }
  71812. else if (marker == cubicMarker)
  71813. {
  71814. markerChar = 'c';
  71815. numCoords = 6;
  71816. }
  71817. else
  71818. {
  71819. jassert (marker == closeSubPathMarker);
  71820. markerChar = 'z';
  71821. }
  71822. if (marker != lastMarker)
  71823. {
  71824. if (s.getDataSize() != 0)
  71825. s << ' ';
  71826. s << markerChar;
  71827. lastMarker = marker;
  71828. }
  71829. while (--numCoords >= 0 && i < numElements)
  71830. {
  71831. String coord (data.elements [i++], 3);
  71832. while (coord.endsWithChar ('0') && coord != "0")
  71833. coord = coord.dropLastCharacters (1);
  71834. if (coord.endsWithChar ('.'))
  71835. coord = coord.dropLastCharacters (1);
  71836. if (s.getDataSize() != 0)
  71837. s << ' ';
  71838. s << coord;
  71839. }
  71840. }
  71841. return s.toUTF8();
  71842. }
  71843. void Path::restoreFromString (const String& stringVersion)
  71844. {
  71845. clear();
  71846. setUsingNonZeroWinding (true);
  71847. const juce_wchar* t = stringVersion;
  71848. juce_wchar marker = 'm';
  71849. int numValues = 2;
  71850. float values [6];
  71851. while (*t != 0)
  71852. {
  71853. const String token (PathHelpers::nextToken (t));
  71854. const juce_wchar firstChar = token[0];
  71855. int startNum = 0;
  71856. if (firstChar == 'm' || firstChar == 'l')
  71857. {
  71858. marker = firstChar;
  71859. numValues = 2;
  71860. }
  71861. else if (firstChar == 'q')
  71862. {
  71863. marker = firstChar;
  71864. numValues = 4;
  71865. }
  71866. else if (firstChar == 'c')
  71867. {
  71868. marker = firstChar;
  71869. numValues = 6;
  71870. }
  71871. else if (firstChar == 'z')
  71872. {
  71873. marker = firstChar;
  71874. numValues = 0;
  71875. }
  71876. else if (firstChar == 'a')
  71877. {
  71878. setUsingNonZeroWinding (false);
  71879. continue;
  71880. }
  71881. else
  71882. {
  71883. ++startNum;
  71884. values [0] = token.getFloatValue();
  71885. }
  71886. for (int i = startNum; i < numValues; ++i)
  71887. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71888. switch (marker)
  71889. {
  71890. case 'm':
  71891. startNewSubPath (values[0], values[1]);
  71892. break;
  71893. case 'l':
  71894. lineTo (values[0], values[1]);
  71895. break;
  71896. case 'q':
  71897. quadraticTo (values[0], values[1],
  71898. values[2], values[3]);
  71899. break;
  71900. case 'c':
  71901. cubicTo (values[0], values[1],
  71902. values[2], values[3],
  71903. values[4], values[5]);
  71904. break;
  71905. case 'z':
  71906. closeSubPath();
  71907. break;
  71908. default:
  71909. jassertfalse // illegal string format?
  71910. break;
  71911. }
  71912. }
  71913. }
  71914. Path::Iterator::Iterator (const Path& path_)
  71915. : path (path_),
  71916. index (0)
  71917. {
  71918. }
  71919. Path::Iterator::~Iterator()
  71920. {
  71921. }
  71922. bool Path::Iterator::next()
  71923. {
  71924. const float* const elements = path.data.elements;
  71925. if (index < path.numElements)
  71926. {
  71927. const float type = elements [index++];
  71928. if (type == moveMarker)
  71929. {
  71930. elementType = startNewSubPath;
  71931. x1 = elements [index++];
  71932. y1 = elements [index++];
  71933. }
  71934. else if (type == lineMarker)
  71935. {
  71936. elementType = lineTo;
  71937. x1 = elements [index++];
  71938. y1 = elements [index++];
  71939. }
  71940. else if (type == quadMarker)
  71941. {
  71942. elementType = quadraticTo;
  71943. x1 = elements [index++];
  71944. y1 = elements [index++];
  71945. x2 = elements [index++];
  71946. y2 = elements [index++];
  71947. }
  71948. else if (type == cubicMarker)
  71949. {
  71950. elementType = cubicTo;
  71951. x1 = elements [index++];
  71952. y1 = elements [index++];
  71953. x2 = elements [index++];
  71954. y2 = elements [index++];
  71955. x3 = elements [index++];
  71956. y3 = elements [index++];
  71957. }
  71958. else if (type == closeSubPathMarker)
  71959. {
  71960. elementType = closePath;
  71961. }
  71962. return true;
  71963. }
  71964. return false;
  71965. }
  71966. END_JUCE_NAMESPACE
  71967. /*** End of inlined file: juce_Path.cpp ***/
  71968. /*** Start of inlined file: juce_PathIterator.cpp ***/
  71969. BEGIN_JUCE_NAMESPACE
  71970. #if JUCE_MSVC
  71971. #pragma optimize ("t", on)
  71972. #endif
  71973. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  71974. const AffineTransform& transform_,
  71975. float tolerence_)
  71976. : x2 (0),
  71977. y2 (0),
  71978. closesSubPath (false),
  71979. subPathIndex (-1),
  71980. path (path_),
  71981. transform (transform_),
  71982. points (path_.data.elements),
  71983. tolerence (tolerence_ * tolerence_),
  71984. subPathCloseX (0),
  71985. subPathCloseY (0),
  71986. isIdentityTransform (transform_.isIdentity()),
  71987. stackBase (32),
  71988. index (0),
  71989. stackSize (32)
  71990. {
  71991. stackPos = stackBase;
  71992. }
  71993. PathFlatteningIterator::~PathFlatteningIterator()
  71994. {
  71995. }
  71996. bool PathFlatteningIterator::next()
  71997. {
  71998. x1 = x2;
  71999. y1 = y2;
  72000. float x3 = 0;
  72001. float y3 = 0;
  72002. float x4 = 0;
  72003. float y4 = 0;
  72004. float type;
  72005. for (;;)
  72006. {
  72007. if (stackPos == stackBase)
  72008. {
  72009. if (index >= path.numElements)
  72010. {
  72011. return false;
  72012. }
  72013. else
  72014. {
  72015. type = points [index++];
  72016. if (type != Path::closeSubPathMarker)
  72017. {
  72018. x2 = points [index++];
  72019. y2 = points [index++];
  72020. if (! isIdentityTransform)
  72021. transform.transformPoint (x2, y2);
  72022. if (type == Path::quadMarker)
  72023. {
  72024. x3 = points [index++];
  72025. y3 = points [index++];
  72026. if (! isIdentityTransform)
  72027. transform.transformPoint (x3, y3);
  72028. }
  72029. else if (type == Path::cubicMarker)
  72030. {
  72031. x3 = points [index++];
  72032. y3 = points [index++];
  72033. x4 = points [index++];
  72034. y4 = points [index++];
  72035. if (! isIdentityTransform)
  72036. {
  72037. transform.transformPoint (x3, y3);
  72038. transform.transformPoint (x4, y4);
  72039. }
  72040. }
  72041. }
  72042. }
  72043. }
  72044. else
  72045. {
  72046. type = *--stackPos;
  72047. if (type != Path::closeSubPathMarker)
  72048. {
  72049. x2 = *--stackPos;
  72050. y2 = *--stackPos;
  72051. if (type == Path::quadMarker)
  72052. {
  72053. x3 = *--stackPos;
  72054. y3 = *--stackPos;
  72055. }
  72056. else if (type == Path::cubicMarker)
  72057. {
  72058. x3 = *--stackPos;
  72059. y3 = *--stackPos;
  72060. x4 = *--stackPos;
  72061. y4 = *--stackPos;
  72062. }
  72063. }
  72064. }
  72065. if (type == Path::lineMarker)
  72066. {
  72067. ++subPathIndex;
  72068. closesSubPath = (stackPos == stackBase)
  72069. && (index < path.numElements)
  72070. && (points [index] == Path::closeSubPathMarker)
  72071. && x2 == subPathCloseX
  72072. && y2 == subPathCloseY;
  72073. return true;
  72074. }
  72075. else if (type == Path::quadMarker)
  72076. {
  72077. const size_t offset = (size_t) (stackPos - stackBase);
  72078. if (offset >= stackSize - 10)
  72079. {
  72080. stackSize <<= 1;
  72081. stackBase.realloc (stackSize);
  72082. stackPos = stackBase + offset;
  72083. }
  72084. const float dx1 = x1 - x2;
  72085. const float dy1 = y1 - y2;
  72086. const float dx2 = x2 - x3;
  72087. const float dy2 = y2 - y3;
  72088. const float m1x = (x1 + x2) * 0.5f;
  72089. const float m1y = (y1 + y2) * 0.5f;
  72090. const float m2x = (x2 + x3) * 0.5f;
  72091. const float m2y = (y2 + y3) * 0.5f;
  72092. const float m3x = (m1x + m2x) * 0.5f;
  72093. const float m3y = (m1y + m2y) * 0.5f;
  72094. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72095. {
  72096. *stackPos++ = y3;
  72097. *stackPos++ = x3;
  72098. *stackPos++ = m2y;
  72099. *stackPos++ = m2x;
  72100. *stackPos++ = Path::quadMarker;
  72101. *stackPos++ = m3y;
  72102. *stackPos++ = m3x;
  72103. *stackPos++ = m1y;
  72104. *stackPos++ = m1x;
  72105. *stackPos++ = Path::quadMarker;
  72106. }
  72107. else
  72108. {
  72109. *stackPos++ = y3;
  72110. *stackPos++ = x3;
  72111. *stackPos++ = Path::lineMarker;
  72112. *stackPos++ = m3y;
  72113. *stackPos++ = m3x;
  72114. *stackPos++ = Path::lineMarker;
  72115. }
  72116. jassert (stackPos < stackBase + stackSize);
  72117. }
  72118. else if (type == Path::cubicMarker)
  72119. {
  72120. const size_t offset = (size_t) (stackPos - stackBase);
  72121. if (offset >= stackSize - 16)
  72122. {
  72123. stackSize <<= 1;
  72124. stackBase.realloc (stackSize);
  72125. stackPos = stackBase + offset;
  72126. }
  72127. const float dx1 = x1 - x2;
  72128. const float dy1 = y1 - y2;
  72129. const float dx2 = x2 - x3;
  72130. const float dy2 = y2 - y3;
  72131. const float dx3 = x3 - x4;
  72132. const float dy3 = y3 - y4;
  72133. const float m1x = (x1 + x2) * 0.5f;
  72134. const float m1y = (y1 + y2) * 0.5f;
  72135. const float m2x = (x3 + x2) * 0.5f;
  72136. const float m2y = (y3 + y2) * 0.5f;
  72137. const float m3x = (x3 + x4) * 0.5f;
  72138. const float m3y = (y3 + y4) * 0.5f;
  72139. const float m4x = (m1x + m2x) * 0.5f;
  72140. const float m4y = (m1y + m2y) * 0.5f;
  72141. const float m5x = (m3x + m2x) * 0.5f;
  72142. const float m5y = (m3y + m2y) * 0.5f;
  72143. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72144. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72145. {
  72146. *stackPos++ = y4;
  72147. *stackPos++ = x4;
  72148. *stackPos++ = m3y;
  72149. *stackPos++ = m3x;
  72150. *stackPos++ = m5y;
  72151. *stackPos++ = m5x;
  72152. *stackPos++ = Path::cubicMarker;
  72153. *stackPos++ = (m4y + m5y) * 0.5f;
  72154. *stackPos++ = (m4x + m5x) * 0.5f;
  72155. *stackPos++ = m4y;
  72156. *stackPos++ = m4x;
  72157. *stackPos++ = m1y;
  72158. *stackPos++ = m1x;
  72159. *stackPos++ = Path::cubicMarker;
  72160. }
  72161. else
  72162. {
  72163. *stackPos++ = y4;
  72164. *stackPos++ = x4;
  72165. *stackPos++ = Path::lineMarker;
  72166. *stackPos++ = m5y;
  72167. *stackPos++ = m5x;
  72168. *stackPos++ = Path::lineMarker;
  72169. *stackPos++ = m4y;
  72170. *stackPos++ = m4x;
  72171. *stackPos++ = Path::lineMarker;
  72172. }
  72173. }
  72174. else if (type == Path::closeSubPathMarker)
  72175. {
  72176. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72177. {
  72178. x1 = x2;
  72179. y1 = y2;
  72180. x2 = subPathCloseX;
  72181. y2 = subPathCloseY;
  72182. closesSubPath = true;
  72183. return true;
  72184. }
  72185. }
  72186. else
  72187. {
  72188. jassert (type == Path::moveMarker);
  72189. subPathIndex = -1;
  72190. subPathCloseX = x1 = x2;
  72191. subPathCloseY = y1 = y2;
  72192. }
  72193. }
  72194. }
  72195. END_JUCE_NAMESPACE
  72196. /*** End of inlined file: juce_PathIterator.cpp ***/
  72197. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72198. BEGIN_JUCE_NAMESPACE
  72199. PathStrokeType::PathStrokeType (const float strokeThickness,
  72200. const JointStyle jointStyle_,
  72201. const EndCapStyle endStyle_) throw()
  72202. : thickness (strokeThickness),
  72203. jointStyle (jointStyle_),
  72204. endStyle (endStyle_)
  72205. {
  72206. }
  72207. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72208. : thickness (other.thickness),
  72209. jointStyle (other.jointStyle),
  72210. endStyle (other.endStyle)
  72211. {
  72212. }
  72213. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72214. {
  72215. thickness = other.thickness;
  72216. jointStyle = other.jointStyle;
  72217. endStyle = other.endStyle;
  72218. return *this;
  72219. }
  72220. PathStrokeType::~PathStrokeType() throw()
  72221. {
  72222. }
  72223. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72224. {
  72225. return thickness == other.thickness
  72226. && jointStyle == other.jointStyle
  72227. && endStyle == other.endStyle;
  72228. }
  72229. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72230. {
  72231. return ! operator== (other);
  72232. }
  72233. static bool lineIntersection (const float x1, const float y1,
  72234. const float x2, const float y2,
  72235. const float x3, const float y3,
  72236. const float x4, const float y4,
  72237. float& intersectionX,
  72238. float& intersectionY,
  72239. float& distanceBeyondLine1EndSquared) throw()
  72240. {
  72241. if (x2 != x3 || y2 != y3)
  72242. {
  72243. const float dx1 = x2 - x1;
  72244. const float dy1 = y2 - y1;
  72245. const float dx2 = x4 - x3;
  72246. const float dy2 = y4 - y3;
  72247. const float divisor = dx1 * dy2 - dx2 * dy1;
  72248. if (divisor == 0)
  72249. {
  72250. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72251. {
  72252. if (dy1 == 0 && dy2 != 0)
  72253. {
  72254. const float along = (y1 - y3) / dy2;
  72255. intersectionX = x3 + along * dx2;
  72256. intersectionY = y1;
  72257. distanceBeyondLine1EndSquared = intersectionX - x2;
  72258. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72259. if ((x2 > x1) == (intersectionX < x2))
  72260. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72261. return along >= 0 && along <= 1.0f;
  72262. }
  72263. else if (dy2 == 0 && dy1 != 0)
  72264. {
  72265. const float along = (y3 - y1) / dy1;
  72266. intersectionX = x1 + along * dx1;
  72267. intersectionY = y3;
  72268. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72269. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72270. if (along < 1.0f)
  72271. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72272. return along >= 0 && along <= 1.0f;
  72273. }
  72274. else if (dx1 == 0 && dx2 != 0)
  72275. {
  72276. const float along = (x1 - x3) / dx2;
  72277. intersectionX = x1;
  72278. intersectionY = y3 + along * dy2;
  72279. distanceBeyondLine1EndSquared = intersectionY - y2;
  72280. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72281. if ((y2 > y1) == (intersectionY < y2))
  72282. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72283. return along >= 0 && along <= 1.0f;
  72284. }
  72285. else if (dx2 == 0 && dx1 != 0)
  72286. {
  72287. const float along = (x3 - x1) / dx1;
  72288. intersectionX = x3;
  72289. intersectionY = y1 + along * dy1;
  72290. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72291. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72292. if (along < 1.0f)
  72293. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72294. return along >= 0 && along <= 1.0f;
  72295. }
  72296. }
  72297. intersectionX = 0.5f * (x2 + x3);
  72298. intersectionY = 0.5f * (y2 + y3);
  72299. distanceBeyondLine1EndSquared = 0.0f;
  72300. return false;
  72301. }
  72302. else
  72303. {
  72304. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72305. intersectionX = x1 + along1 * dx1;
  72306. intersectionY = y1 + along1 * dy1;
  72307. if (along1 >= 0 && along1 <= 1.0f)
  72308. {
  72309. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72310. if (along2 >= 0 && along2 <= divisor)
  72311. {
  72312. distanceBeyondLine1EndSquared = 0.0f;
  72313. return true;
  72314. }
  72315. }
  72316. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72317. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72318. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72319. if (along1 < 1.0f)
  72320. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72321. return false;
  72322. }
  72323. }
  72324. intersectionX = x2;
  72325. intersectionY = y2;
  72326. distanceBeyondLine1EndSquared = 0.0f;
  72327. return true;
  72328. }
  72329. namespace PathFunctions
  72330. {
  72331. // part of stroke drawing stuff
  72332. static void addEdgeAndJoint (Path& destPath,
  72333. const PathStrokeType::JointStyle style,
  72334. const float maxMiterExtensionSquared, const float width,
  72335. const float x1, const float y1,
  72336. const float x2, const float y2,
  72337. const float x3, const float y3,
  72338. const float x4, const float y4,
  72339. const float midX, const float midY)
  72340. {
  72341. if (style == PathStrokeType::beveled
  72342. || (x3 == x4 && y3 == y4)
  72343. || (x1 == x2 && y1 == y2))
  72344. {
  72345. destPath.lineTo (x2, y2);
  72346. destPath.lineTo (x3, y3);
  72347. }
  72348. else
  72349. {
  72350. float jx, jy, distanceBeyondLine1EndSquared;
  72351. // if they intersect, use this point..
  72352. if (lineIntersection (x1, y1, x2, y2,
  72353. x3, y3, x4, y4,
  72354. jx, jy, distanceBeyondLine1EndSquared))
  72355. {
  72356. destPath.lineTo (jx, jy);
  72357. }
  72358. else
  72359. {
  72360. if (style == PathStrokeType::mitered)
  72361. {
  72362. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72363. && distanceBeyondLine1EndSquared > 0.0f)
  72364. {
  72365. destPath.lineTo (jx, jy);
  72366. }
  72367. else
  72368. {
  72369. // the end sticks out too far, so just use a blunt joint
  72370. destPath.lineTo (x2, y2);
  72371. destPath.lineTo (x3, y3);
  72372. }
  72373. }
  72374. else
  72375. {
  72376. // curved joints
  72377. float angle1 = atan2f (x2 - midX, y2 - midY);
  72378. float angle2 = atan2f (x3 - midX, y3 - midY);
  72379. const float angleIncrement = 0.1f;
  72380. destPath.lineTo (x2, y2);
  72381. if (fabs (angle1 - angle2) > angleIncrement)
  72382. {
  72383. if (angle2 > angle1 + float_Pi
  72384. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72385. {
  72386. if (angle2 > angle1)
  72387. angle2 -= float_Pi * 2.0f;
  72388. jassert (angle1 <= angle2 + float_Pi);
  72389. angle1 -= angleIncrement;
  72390. while (angle1 > angle2)
  72391. {
  72392. destPath.lineTo (midX + width * sinf (angle1),
  72393. midY + width * cosf (angle1));
  72394. angle1 -= angleIncrement;
  72395. }
  72396. }
  72397. else
  72398. {
  72399. if (angle1 > angle2)
  72400. angle1 -= float_Pi * 2.0f;
  72401. jassert (angle1 >= angle2 - float_Pi);
  72402. angle1 += angleIncrement;
  72403. while (angle1 < angle2)
  72404. {
  72405. destPath.lineTo (midX + width * sinf (angle1),
  72406. midY + width * cosf (angle1));
  72407. angle1 += angleIncrement;
  72408. }
  72409. }
  72410. }
  72411. destPath.lineTo (x3, y3);
  72412. }
  72413. }
  72414. }
  72415. }
  72416. static void addLineEnd (Path& destPath,
  72417. const PathStrokeType::EndCapStyle style,
  72418. const float x1, const float y1,
  72419. const float x2, const float y2,
  72420. const float width)
  72421. {
  72422. if (style == PathStrokeType::butt)
  72423. {
  72424. destPath.lineTo (x2, y2);
  72425. }
  72426. else
  72427. {
  72428. float offx1, offy1, offx2, offy2;
  72429. float dx = x2 - x1;
  72430. float dy = y2 - y1;
  72431. const float len = juce_hypotf (dx, dy);
  72432. if (len == 0)
  72433. {
  72434. offx1 = offx2 = x1;
  72435. offy1 = offy2 = y1;
  72436. }
  72437. else
  72438. {
  72439. const float offset = width / len;
  72440. dx *= offset;
  72441. dy *= offset;
  72442. offx1 = x1 + dy;
  72443. offy1 = y1 - dx;
  72444. offx2 = x2 + dy;
  72445. offy2 = y2 - dx;
  72446. }
  72447. if (style == PathStrokeType::square)
  72448. {
  72449. // sqaure ends
  72450. destPath.lineTo (offx1, offy1);
  72451. destPath.lineTo (offx2, offy2);
  72452. destPath.lineTo (x2, y2);
  72453. }
  72454. else
  72455. {
  72456. // rounded ends
  72457. const float midx = (offx1 + offx2) * 0.5f;
  72458. const float midy = (offy1 + offy2) * 0.5f;
  72459. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72460. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72461. midx, midy);
  72462. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72463. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72464. x2, y2);
  72465. }
  72466. }
  72467. }
  72468. struct LineSection
  72469. {
  72470. LineSection() {}
  72471. LineSection (int) {}
  72472. float x1, y1, x2, y2; // original line
  72473. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72474. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72475. };
  72476. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72477. const bool isClosed,
  72478. const float width, const float maxMiterExtensionSquared,
  72479. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72480. {
  72481. jassert (subPath.size() > 0);
  72482. const LineSection& firstLine = subPath.getReference (0);
  72483. float lastX1 = firstLine.lx1;
  72484. float lastY1 = firstLine.ly1;
  72485. float lastX2 = firstLine.lx2;
  72486. float lastY2 = firstLine.ly2;
  72487. if (isClosed)
  72488. {
  72489. destPath.startNewSubPath (lastX1, lastY1);
  72490. }
  72491. else
  72492. {
  72493. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72494. addLineEnd (destPath, endStyle,
  72495. firstLine.rx2, firstLine.ry2,
  72496. lastX1, lastY1,
  72497. width);
  72498. }
  72499. int i;
  72500. for (i = 1; i < subPath.size(); ++i)
  72501. {
  72502. const LineSection& l = subPath.getReference (i);
  72503. addEdgeAndJoint (destPath, jointStyle,
  72504. maxMiterExtensionSquared, width,
  72505. lastX1, lastY1, lastX2, lastY2,
  72506. l.lx1, l.ly1, l.lx2, l.ly2,
  72507. l.x1, l.y1);
  72508. lastX1 = l.lx1;
  72509. lastY1 = l.ly1;
  72510. lastX2 = l.lx2;
  72511. lastY2 = l.ly2;
  72512. }
  72513. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72514. if (isClosed)
  72515. {
  72516. const LineSection& l = subPath.getReference (0);
  72517. addEdgeAndJoint (destPath, jointStyle,
  72518. maxMiterExtensionSquared, width,
  72519. lastX1, lastY1, lastX2, lastY2,
  72520. l.lx1, l.ly1, l.lx2, l.ly2,
  72521. l.x1, l.y1);
  72522. destPath.closeSubPath();
  72523. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72524. }
  72525. else
  72526. {
  72527. destPath.lineTo (lastX2, lastY2);
  72528. addLineEnd (destPath, endStyle,
  72529. lastX2, lastY2,
  72530. lastLine.rx1, lastLine.ry1,
  72531. width);
  72532. }
  72533. lastX1 = lastLine.rx1;
  72534. lastY1 = lastLine.ry1;
  72535. lastX2 = lastLine.rx2;
  72536. lastY2 = lastLine.ry2;
  72537. for (i = subPath.size() - 1; --i >= 0;)
  72538. {
  72539. const LineSection& l = subPath.getReference (i);
  72540. addEdgeAndJoint (destPath, jointStyle,
  72541. maxMiterExtensionSquared, width,
  72542. lastX1, lastY1, lastX2, lastY2,
  72543. l.rx1, l.ry1, l.rx2, l.ry2,
  72544. l.x2, l.y2);
  72545. lastX1 = l.rx1;
  72546. lastY1 = l.ry1;
  72547. lastX2 = l.rx2;
  72548. lastY2 = l.ry2;
  72549. }
  72550. if (isClosed)
  72551. {
  72552. addEdgeAndJoint (destPath, jointStyle,
  72553. maxMiterExtensionSquared, width,
  72554. lastX1, lastY1, lastX2, lastY2,
  72555. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72556. lastLine.x2, lastLine.y2);
  72557. }
  72558. else
  72559. {
  72560. // do the last line
  72561. destPath.lineTo (lastX2, lastY2);
  72562. }
  72563. destPath.closeSubPath();
  72564. }
  72565. }
  72566. void PathStrokeType::createStrokedPath (Path& destPath,
  72567. const Path& source,
  72568. const AffineTransform& transform,
  72569. const float extraAccuracy) const
  72570. {
  72571. if (thickness <= 0)
  72572. {
  72573. destPath.clear();
  72574. return;
  72575. }
  72576. const Path* sourcePath = &source;
  72577. Path temp;
  72578. if (sourcePath == &destPath)
  72579. {
  72580. destPath.swapWithPath (temp);
  72581. sourcePath = &temp;
  72582. }
  72583. else
  72584. {
  72585. destPath.clear();
  72586. }
  72587. destPath.setUsingNonZeroWinding (true);
  72588. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72589. const float width = 0.5f * thickness;
  72590. // Iterate the path, creating a list of the
  72591. // left/right-hand lines along either side of it...
  72592. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72593. using namespace PathFunctions;
  72594. Array <LineSection> subPath;
  72595. LineSection l;
  72596. l.x1 = 0;
  72597. l.y1 = 0;
  72598. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72599. while (it.next())
  72600. {
  72601. if (it.subPathIndex == 0)
  72602. {
  72603. if (subPath.size() > 0)
  72604. {
  72605. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72606. subPath.clearQuick();
  72607. }
  72608. l.x1 = it.x1;
  72609. l.y1 = it.y1;
  72610. }
  72611. l.x2 = it.x2;
  72612. l.y2 = it.y2;
  72613. float dx = l.x2 - l.x1;
  72614. float dy = l.y2 - l.y1;
  72615. const float hypotSquared = dx*dx + dy*dy;
  72616. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72617. {
  72618. const float len = sqrtf (hypotSquared);
  72619. if (len == 0)
  72620. {
  72621. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72622. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72623. }
  72624. else
  72625. {
  72626. const float offset = width / len;
  72627. dx *= offset;
  72628. dy *= offset;
  72629. l.rx2 = l.x1 - dy;
  72630. l.ry2 = l.y1 + dx;
  72631. l.lx1 = l.x1 + dy;
  72632. l.ly1 = l.y1 - dx;
  72633. l.lx2 = l.x2 + dy;
  72634. l.ly2 = l.y2 - dx;
  72635. l.rx1 = l.x2 - dy;
  72636. l.ry1 = l.y2 + dx;
  72637. }
  72638. subPath.add (l);
  72639. if (it.closesSubPath)
  72640. {
  72641. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72642. subPath.clearQuick();
  72643. }
  72644. else
  72645. {
  72646. l.x1 = it.x2;
  72647. l.y1 = it.y2;
  72648. }
  72649. }
  72650. }
  72651. if (subPath.size() > 0)
  72652. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72653. }
  72654. void PathStrokeType::createDashedStroke (Path& destPath,
  72655. const Path& sourcePath,
  72656. const float* dashLengths,
  72657. int numDashLengths,
  72658. const AffineTransform& transform,
  72659. const float extraAccuracy) const
  72660. {
  72661. if (thickness <= 0)
  72662. return;
  72663. // this should really be an even number..
  72664. jassert ((numDashLengths & 1) == 0);
  72665. Path newDestPath;
  72666. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72667. bool first = true;
  72668. int dashNum = 0;
  72669. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72670. float dx = 0.0f, dy = 0.0f;
  72671. for (;;)
  72672. {
  72673. const bool isSolid = ((dashNum & 1) == 0);
  72674. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72675. jassert (dashLen > 0); // must be a positive increment!
  72676. if (dashLen <= 0)
  72677. break;
  72678. pos += dashLen;
  72679. while (pos > lineEndPos)
  72680. {
  72681. if (! it.next())
  72682. {
  72683. if (isSolid && ! first)
  72684. newDestPath.lineTo (it.x2, it.y2);
  72685. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72686. return;
  72687. }
  72688. if (isSolid && ! first)
  72689. newDestPath.lineTo (it.x1, it.y1);
  72690. else
  72691. newDestPath.startNewSubPath (it.x1, it.y1);
  72692. dx = it.x2 - it.x1;
  72693. dy = it.y2 - it.y1;
  72694. lineLen = juce_hypotf (dx, dy);
  72695. lineEndPos += lineLen;
  72696. first = it.closesSubPath;
  72697. }
  72698. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72699. if (isSolid)
  72700. newDestPath.lineTo (it.x1 + dx * alpha,
  72701. it.y1 + dy * alpha);
  72702. else
  72703. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72704. it.y1 + dy * alpha);
  72705. }
  72706. }
  72707. END_JUCE_NAMESPACE
  72708. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72709. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72710. BEGIN_JUCE_NAMESPACE
  72711. PositionedRectangle::PositionedRectangle() throw()
  72712. : x (0.0),
  72713. y (0.0),
  72714. w (0.0),
  72715. h (0.0),
  72716. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72717. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72718. wMode (absoluteSize),
  72719. hMode (absoluteSize)
  72720. {
  72721. }
  72722. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72723. : x (other.x),
  72724. y (other.y),
  72725. w (other.w),
  72726. h (other.h),
  72727. xMode (other.xMode),
  72728. yMode (other.yMode),
  72729. wMode (other.wMode),
  72730. hMode (other.hMode)
  72731. {
  72732. }
  72733. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72734. {
  72735. x = other.x;
  72736. y = other.y;
  72737. w = other.w;
  72738. h = other.h;
  72739. xMode = other.xMode;
  72740. yMode = other.yMode;
  72741. wMode = other.wMode;
  72742. hMode = other.hMode;
  72743. return *this;
  72744. }
  72745. PositionedRectangle::~PositionedRectangle() throw()
  72746. {
  72747. }
  72748. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72749. {
  72750. return x == other.x
  72751. && y == other.y
  72752. && w == other.w
  72753. && h == other.h
  72754. && xMode == other.xMode
  72755. && yMode == other.yMode
  72756. && wMode == other.wMode
  72757. && hMode == other.hMode;
  72758. }
  72759. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72760. {
  72761. return ! operator== (other);
  72762. }
  72763. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72764. {
  72765. StringArray tokens;
  72766. tokens.addTokens (stringVersion, false);
  72767. decodePosString (tokens [0], xMode, x);
  72768. decodePosString (tokens [1], yMode, y);
  72769. decodeSizeString (tokens [2], wMode, w);
  72770. decodeSizeString (tokens [3], hMode, h);
  72771. }
  72772. const String PositionedRectangle::toString() const throw()
  72773. {
  72774. String s;
  72775. s.preallocateStorage (12);
  72776. addPosDescription (s, xMode, x);
  72777. s << ' ';
  72778. addPosDescription (s, yMode, y);
  72779. s << ' ';
  72780. addSizeDescription (s, wMode, w);
  72781. s << ' ';
  72782. addSizeDescription (s, hMode, h);
  72783. return s;
  72784. }
  72785. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72786. {
  72787. jassert (! target.isEmpty());
  72788. double x_, y_, w_, h_;
  72789. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72790. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72791. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72792. roundToInt (w_), roundToInt (h_));
  72793. }
  72794. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72795. double& x_, double& y_,
  72796. double& w_, double& h_) const throw()
  72797. {
  72798. jassert (! target.isEmpty());
  72799. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72800. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72801. }
  72802. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72803. {
  72804. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72805. }
  72806. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72807. const Rectangle<int>& target) throw()
  72808. {
  72809. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72810. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72811. }
  72812. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72813. const double newW, const double newH,
  72814. const Rectangle<int>& target) throw()
  72815. {
  72816. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72817. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72818. }
  72819. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72820. {
  72821. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72822. updateFrom (comp.getBounds(), Rectangle<int>());
  72823. else
  72824. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72825. }
  72826. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72827. {
  72828. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72829. }
  72830. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72831. {
  72832. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72833. | absoluteFromParentBottomRight
  72834. | absoluteFromParentCentre
  72835. | proportionOfParentSize));
  72836. }
  72837. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72838. {
  72839. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72840. }
  72841. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72842. {
  72843. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72844. | absoluteFromParentBottomRight
  72845. | absoluteFromParentCentre
  72846. | proportionOfParentSize));
  72847. }
  72848. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72849. {
  72850. return (SizeMode) wMode;
  72851. }
  72852. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72853. {
  72854. return (SizeMode) hMode;
  72855. }
  72856. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72857. const PositionMode xMode_,
  72858. const AnchorPoint yAnchor,
  72859. const PositionMode yMode_,
  72860. const SizeMode widthMode,
  72861. const SizeMode heightMode,
  72862. const Rectangle<int>& target) throw()
  72863. {
  72864. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72865. {
  72866. double tx, tw;
  72867. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72868. xMode = (uint8) (xAnchor | xMode_);
  72869. wMode = (uint8) widthMode;
  72870. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72871. }
  72872. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72873. {
  72874. double ty, th;
  72875. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72876. yMode = (uint8) (yAnchor | yMode_);
  72877. hMode = (uint8) heightMode;
  72878. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72879. }
  72880. }
  72881. bool PositionedRectangle::isPositionAbsolute() const throw()
  72882. {
  72883. return xMode == absoluteFromParentTopLeft
  72884. && yMode == absoluteFromParentTopLeft
  72885. && wMode == absoluteSize
  72886. && hMode == absoluteSize;
  72887. }
  72888. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72889. {
  72890. if ((mode & proportionOfParentSize) != 0)
  72891. {
  72892. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72893. }
  72894. else
  72895. {
  72896. s << (roundToInt (value * 100.0) / 100.0);
  72897. if ((mode & absoluteFromParentBottomRight) != 0)
  72898. s << 'R';
  72899. else if ((mode & absoluteFromParentCentre) != 0)
  72900. s << 'C';
  72901. }
  72902. if ((mode & anchorAtRightOrBottom) != 0)
  72903. s << 'r';
  72904. else if ((mode & anchorAtCentre) != 0)
  72905. s << 'c';
  72906. }
  72907. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72908. {
  72909. if (mode == proportionalSize)
  72910. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72911. else if (mode == parentSizeMinusAbsolute)
  72912. s << (roundToInt (value * 100.0) / 100.0) << 'M';
  72913. else
  72914. s << (roundToInt (value * 100.0) / 100.0);
  72915. }
  72916. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72917. {
  72918. if (s.containsChar ('r'))
  72919. mode = anchorAtRightOrBottom;
  72920. else if (s.containsChar ('c'))
  72921. mode = anchorAtCentre;
  72922. else
  72923. mode = anchorAtLeftOrTop;
  72924. if (s.containsChar ('%'))
  72925. {
  72926. mode |= proportionOfParentSize;
  72927. value = s.removeCharacters ("%rcRC").getDoubleValue() / 100.0;
  72928. }
  72929. else
  72930. {
  72931. if (s.containsChar ('R'))
  72932. mode |= absoluteFromParentBottomRight;
  72933. else if (s.containsChar ('C'))
  72934. mode |= absoluteFromParentCentre;
  72935. else
  72936. mode |= absoluteFromParentTopLeft;
  72937. value = s.removeCharacters ("rcRC").getDoubleValue();
  72938. }
  72939. }
  72940. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  72941. {
  72942. if (s.containsChar ('%'))
  72943. {
  72944. mode = proportionalSize;
  72945. value = s.upToFirstOccurrenceOf ("%", false, false).getDoubleValue() / 100.0;
  72946. }
  72947. else if (s.containsChar ('M'))
  72948. {
  72949. mode = parentSizeMinusAbsolute;
  72950. value = s.getDoubleValue();
  72951. }
  72952. else
  72953. {
  72954. mode = absoluteSize;
  72955. value = s.getDoubleValue();
  72956. }
  72957. }
  72958. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  72959. const double x_, const double w_,
  72960. const uint8 xMode_, const uint8 wMode_,
  72961. const int parentPos,
  72962. const int parentSize) const throw()
  72963. {
  72964. if (wMode_ == proportionalSize)
  72965. wOut = roundToInt (w_ * parentSize);
  72966. else if (wMode_ == parentSizeMinusAbsolute)
  72967. wOut = jmax (0, parentSize - roundToInt (w_));
  72968. else
  72969. wOut = roundToInt (w_);
  72970. if ((xMode_ & proportionOfParentSize) != 0)
  72971. xOut = parentPos + x_ * parentSize;
  72972. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72973. xOut = (parentPos + parentSize) - x_;
  72974. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72975. xOut = x_ + (parentPos + parentSize / 2);
  72976. else
  72977. xOut = x_ + parentPos;
  72978. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72979. xOut -= wOut;
  72980. else if ((xMode_ & anchorAtCentre) != 0)
  72981. xOut -= wOut / 2;
  72982. }
  72983. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  72984. double x_, const double w_,
  72985. const uint8 xMode_, const uint8 wMode_,
  72986. const int parentPos,
  72987. const int parentSize) const throw()
  72988. {
  72989. if (wMode_ == proportionalSize)
  72990. {
  72991. if (parentSize > 0)
  72992. wOut = w_ / parentSize;
  72993. }
  72994. else if (wMode_ == parentSizeMinusAbsolute)
  72995. wOut = parentSize - w_;
  72996. else
  72997. wOut = w_;
  72998. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72999. x_ += w_;
  73000. else if ((xMode_ & anchorAtCentre) != 0)
  73001. x_ += w_ / 2;
  73002. if ((xMode_ & proportionOfParentSize) != 0)
  73003. {
  73004. if (parentSize > 0)
  73005. xOut = (x_ - parentPos) / parentSize;
  73006. }
  73007. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73008. xOut = (parentPos + parentSize) - x_;
  73009. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73010. xOut = x_ - (parentPos + parentSize / 2);
  73011. else
  73012. xOut = x_ - parentPos;
  73013. }
  73014. END_JUCE_NAMESPACE
  73015. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73016. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73017. BEGIN_JUCE_NAMESPACE
  73018. RectangleList::RectangleList() throw()
  73019. {
  73020. }
  73021. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73022. {
  73023. if (! rect.isEmpty())
  73024. rects.add (rect);
  73025. }
  73026. RectangleList::RectangleList (const RectangleList& other) throw()
  73027. : rects (other.rects)
  73028. {
  73029. }
  73030. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73031. {
  73032. rects = other.rects;
  73033. return *this;
  73034. }
  73035. RectangleList::~RectangleList() throw()
  73036. {
  73037. }
  73038. void RectangleList::clear() throw()
  73039. {
  73040. rects.clearQuick();
  73041. }
  73042. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73043. {
  73044. if (((unsigned int) index) < (unsigned int) rects.size())
  73045. return rects.getReference (index);
  73046. return Rectangle<int>();
  73047. }
  73048. bool RectangleList::isEmpty() const throw()
  73049. {
  73050. return rects.size() == 0;
  73051. }
  73052. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73053. : current (0),
  73054. owner (list),
  73055. index (list.rects.size())
  73056. {
  73057. }
  73058. RectangleList::Iterator::~Iterator() throw()
  73059. {
  73060. }
  73061. bool RectangleList::Iterator::next() throw()
  73062. {
  73063. if (--index >= 0)
  73064. {
  73065. current = & (owner.rects.getReference (index));
  73066. return true;
  73067. }
  73068. return false;
  73069. }
  73070. void RectangleList::add (const Rectangle<int>& rect) throw()
  73071. {
  73072. if (! rect.isEmpty())
  73073. {
  73074. if (rects.size() == 0)
  73075. {
  73076. rects.add (rect);
  73077. }
  73078. else
  73079. {
  73080. bool anyOverlaps = false;
  73081. int i;
  73082. for (i = rects.size(); --i >= 0;)
  73083. {
  73084. Rectangle<int>& ourRect = rects.getReference (i);
  73085. if (rect.intersects (ourRect))
  73086. {
  73087. if (rect.contains (ourRect))
  73088. rects.remove (i);
  73089. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73090. anyOverlaps = true;
  73091. }
  73092. }
  73093. if (anyOverlaps && rects.size() > 0)
  73094. {
  73095. RectangleList r (rect);
  73096. for (i = rects.size(); --i >= 0;)
  73097. {
  73098. const Rectangle<int>& ourRect = rects.getReference (i);
  73099. if (rect.intersects (ourRect))
  73100. {
  73101. r.subtract (ourRect);
  73102. if (r.rects.size() == 0)
  73103. return;
  73104. }
  73105. }
  73106. for (i = r.getNumRectangles(); --i >= 0;)
  73107. rects.add (r.rects.getReference (i));
  73108. }
  73109. else
  73110. {
  73111. rects.add (rect);
  73112. }
  73113. }
  73114. }
  73115. }
  73116. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73117. {
  73118. rects.add (rect);
  73119. }
  73120. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73121. {
  73122. if (rects.size() == 0)
  73123. {
  73124. if (w > 0 && h > 0)
  73125. rects.add (Rectangle<int> (x, y, w, h));
  73126. }
  73127. else
  73128. {
  73129. add (Rectangle<int> (x, y, w, h));
  73130. }
  73131. }
  73132. void RectangleList::add (const RectangleList& other) throw()
  73133. {
  73134. for (int i = 0; i < other.rects.size(); ++i)
  73135. add (other.rects.getReference (i));
  73136. }
  73137. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73138. {
  73139. const int originalNumRects = rects.size();
  73140. if (originalNumRects > 0)
  73141. {
  73142. const int x1 = rect.x;
  73143. const int y1 = rect.y;
  73144. const int x2 = x1 + rect.w;
  73145. const int y2 = y1 + rect.h;
  73146. for (int i = getNumRectangles(); --i >= 0;)
  73147. {
  73148. Rectangle<int>& r = rects.getReference (i);
  73149. const int rx1 = r.x;
  73150. const int ry1 = r.y;
  73151. const int rx2 = rx1 + r.w;
  73152. const int ry2 = ry1 + r.h;
  73153. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73154. {
  73155. if (x1 > rx1 && x1 < rx2)
  73156. {
  73157. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73158. {
  73159. r.w = x1 - rx1;
  73160. }
  73161. else
  73162. {
  73163. r.x = x1;
  73164. r.w = rx2 - x1;
  73165. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73166. i += 2;
  73167. }
  73168. }
  73169. else if (x2 > rx1 && x2 < rx2)
  73170. {
  73171. r.x = x2;
  73172. r.w = rx2 - x2;
  73173. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73174. {
  73175. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73176. i += 2;
  73177. }
  73178. }
  73179. else if (y1 > ry1 && y1 < ry2)
  73180. {
  73181. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73182. {
  73183. r.h = y1 - ry1;
  73184. }
  73185. else
  73186. {
  73187. r.y = y1;
  73188. r.h = ry2 - y1;
  73189. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73190. i += 2;
  73191. }
  73192. }
  73193. else if (y2 > ry1 && y2 < ry2)
  73194. {
  73195. r.y = y2;
  73196. r.h = ry2 - y2;
  73197. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73198. {
  73199. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73200. i += 2;
  73201. }
  73202. }
  73203. else
  73204. {
  73205. rects.remove (i);
  73206. }
  73207. }
  73208. }
  73209. if (rects.size() > originalNumRects + 10)
  73210. consolidate();
  73211. }
  73212. }
  73213. void RectangleList::subtract (const RectangleList& otherList) throw()
  73214. {
  73215. for (int i = otherList.rects.size(); --i >= 0;)
  73216. subtract (otherList.rects.getReference (i));
  73217. }
  73218. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73219. {
  73220. bool notEmpty = false;
  73221. if (rect.isEmpty())
  73222. {
  73223. clear();
  73224. }
  73225. else
  73226. {
  73227. for (int i = rects.size(); --i >= 0;)
  73228. {
  73229. Rectangle<int>& r = rects.getReference (i);
  73230. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73231. rects.remove (i);
  73232. else
  73233. notEmpty = true;
  73234. }
  73235. }
  73236. return notEmpty;
  73237. }
  73238. bool RectangleList::clipTo (const RectangleList& other) throw()
  73239. {
  73240. if (rects.size() == 0)
  73241. return false;
  73242. RectangleList result;
  73243. for (int j = 0; j < rects.size(); ++j)
  73244. {
  73245. const Rectangle<int>& rect = rects.getReference (j);
  73246. for (int i = other.rects.size(); --i >= 0;)
  73247. {
  73248. Rectangle<int> r (other.rects.getReference (i));
  73249. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73250. result.rects.add (r);
  73251. }
  73252. }
  73253. swapWith (result);
  73254. return ! isEmpty();
  73255. }
  73256. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73257. {
  73258. destRegion.clear();
  73259. if (! rect.isEmpty())
  73260. {
  73261. for (int i = rects.size(); --i >= 0;)
  73262. {
  73263. Rectangle<int> r (rects.getReference (i));
  73264. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73265. destRegion.rects.add (r);
  73266. }
  73267. }
  73268. return destRegion.rects.size() > 0;
  73269. }
  73270. void RectangleList::swapWith (RectangleList& otherList) throw()
  73271. {
  73272. rects.swapWithArray (otherList.rects);
  73273. }
  73274. void RectangleList::consolidate() throw()
  73275. {
  73276. int i;
  73277. for (i = 0; i < getNumRectangles() - 1; ++i)
  73278. {
  73279. Rectangle<int>& r = rects.getReference (i);
  73280. const int rx1 = r.x;
  73281. const int ry1 = r.y;
  73282. const int rx2 = rx1 + r.w;
  73283. const int ry2 = ry1 + r.h;
  73284. for (int j = rects.size(); --j > i;)
  73285. {
  73286. Rectangle<int>& r2 = rects.getReference (j);
  73287. const int jrx1 = r2.x;
  73288. const int jry1 = r2.y;
  73289. const int jrx2 = jrx1 + r2.w;
  73290. const int jry2 = jry1 + r2.h;
  73291. // if the vertical edges of any blocks are touching and their horizontals don't
  73292. // line up, split them horizontally..
  73293. if (jrx1 == rx2 || jrx2 == rx1)
  73294. {
  73295. if (jry1 > ry1 && jry1 < ry2)
  73296. {
  73297. r.h = jry1 - ry1;
  73298. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73299. i = -1;
  73300. break;
  73301. }
  73302. if (jry2 > ry1 && jry2 < ry2)
  73303. {
  73304. r.h = jry2 - ry1;
  73305. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73306. i = -1;
  73307. break;
  73308. }
  73309. else if (ry1 > jry1 && ry1 < jry2)
  73310. {
  73311. r2.h = ry1 - jry1;
  73312. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73313. i = -1;
  73314. break;
  73315. }
  73316. else if (ry2 > jry1 && ry2 < jry2)
  73317. {
  73318. r2.h = ry2 - jry1;
  73319. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73320. i = -1;
  73321. break;
  73322. }
  73323. }
  73324. }
  73325. }
  73326. for (i = 0; i < rects.size() - 1; ++i)
  73327. {
  73328. Rectangle<int>& r = rects.getReference (i);
  73329. for (int j = rects.size(); --j > i;)
  73330. {
  73331. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73332. {
  73333. rects.remove (j);
  73334. i = -1;
  73335. break;
  73336. }
  73337. }
  73338. }
  73339. }
  73340. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73341. {
  73342. for (int i = getNumRectangles(); --i >= 0;)
  73343. if (rects.getReference (i).contains (x, y))
  73344. return true;
  73345. return false;
  73346. }
  73347. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73348. {
  73349. if (rects.size() > 1)
  73350. {
  73351. RectangleList r (rectangleToCheck);
  73352. for (int i = rects.size(); --i >= 0;)
  73353. {
  73354. r.subtract (rects.getReference (i));
  73355. if (r.rects.size() == 0)
  73356. return true;
  73357. }
  73358. }
  73359. else if (rects.size() > 0)
  73360. {
  73361. return rects.getReference (0).contains (rectangleToCheck);
  73362. }
  73363. return false;
  73364. }
  73365. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73366. {
  73367. for (int i = rects.size(); --i >= 0;)
  73368. if (rects.getReference (i).intersects (rectangleToCheck))
  73369. return true;
  73370. return false;
  73371. }
  73372. bool RectangleList::intersects (const RectangleList& other) const throw()
  73373. {
  73374. for (int i = rects.size(); --i >= 0;)
  73375. if (other.intersectsRectangle (rects.getReference (i)))
  73376. return true;
  73377. return false;
  73378. }
  73379. const Rectangle<int> RectangleList::getBounds() const throw()
  73380. {
  73381. if (rects.size() <= 1)
  73382. {
  73383. if (rects.size() == 0)
  73384. return Rectangle<int>();
  73385. else
  73386. return rects.getReference (0);
  73387. }
  73388. else
  73389. {
  73390. const Rectangle<int>& r = rects.getReference (0);
  73391. int minX = r.x;
  73392. int minY = r.y;
  73393. int maxX = minX + r.w;
  73394. int maxY = minY + r.h;
  73395. for (int i = rects.size(); --i > 0;)
  73396. {
  73397. const Rectangle<int>& r2 = rects.getReference (i);
  73398. minX = jmin (minX, r2.x);
  73399. minY = jmin (minY, r2.y);
  73400. maxX = jmax (maxX, r2.getRight());
  73401. maxY = jmax (maxY, r2.getBottom());
  73402. }
  73403. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73404. }
  73405. }
  73406. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73407. {
  73408. for (int i = rects.size(); --i >= 0;)
  73409. {
  73410. Rectangle<int>& r = rects.getReference (i);
  73411. r.x += dx;
  73412. r.y += dy;
  73413. }
  73414. }
  73415. const Path RectangleList::toPath() const throw()
  73416. {
  73417. Path p;
  73418. for (int i = rects.size(); --i >= 0;)
  73419. {
  73420. const Rectangle<int>& r = rects.getReference (i);
  73421. p.addRectangle ((float) r.x,
  73422. (float) r.y,
  73423. (float) r.w,
  73424. (float) r.h);
  73425. }
  73426. return p;
  73427. }
  73428. END_JUCE_NAMESPACE
  73429. /*** End of inlined file: juce_RectangleList.cpp ***/
  73430. /*** Start of inlined file: juce_Image.cpp ***/
  73431. BEGIN_JUCE_NAMESPACE
  73432. static const int fullAlphaThreshold = 253;
  73433. Image::Image (const PixelFormat format_,
  73434. const int imageWidth_,
  73435. const int imageHeight_)
  73436. : format (format_),
  73437. imageWidth (imageWidth_),
  73438. imageHeight (imageHeight_),
  73439. imageData (0)
  73440. {
  73441. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73442. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73443. // actual image will be at least 1x1.
  73444. }
  73445. Image::Image (const PixelFormat format_,
  73446. const int imageWidth_,
  73447. const int imageHeight_,
  73448. const bool clearImage)
  73449. : format (format_),
  73450. imageWidth (imageWidth_),
  73451. imageHeight (imageHeight_)
  73452. {
  73453. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73454. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73455. // actual image will be at least 1x1.
  73456. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73457. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73458. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73459. imageData = imageDataAllocated;
  73460. }
  73461. Image::Image (const Image& other)
  73462. : format (other.format),
  73463. imageWidth (other.imageWidth),
  73464. imageHeight (other.imageHeight)
  73465. {
  73466. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73467. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73468. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73469. imageData = imageDataAllocated;
  73470. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73471. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73472. }
  73473. Image::~Image()
  73474. {
  73475. }
  73476. LowLevelGraphicsContext* Image::createLowLevelContext()
  73477. {
  73478. return new LowLevelGraphicsSoftwareRenderer (*this);
  73479. }
  73480. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73481. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73482. lineStride (image.lineStride),
  73483. pixelStride (image.pixelStride),
  73484. width (w),
  73485. height (h)
  73486. {
  73487. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73488. }
  73489. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73490. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73491. lineStride (image.lineStride),
  73492. pixelStride (image.pixelStride),
  73493. width (w),
  73494. height (h)
  73495. {
  73496. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73497. }
  73498. Image::BitmapData::~BitmapData()
  73499. {
  73500. }
  73501. void Image::setPixelData (int x, int y, int w, int h,
  73502. const uint8* sourcePixelData, int sourceLineStride)
  73503. {
  73504. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73505. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73506. {
  73507. const BitmapData dest (*this, x, y, w, h, true);
  73508. for (int i = 0; i < h; ++i)
  73509. {
  73510. memcpy (dest.getLinePointer(i),
  73511. sourcePixelData + sourceLineStride * i,
  73512. w * dest.pixelStride);
  73513. }
  73514. }
  73515. }
  73516. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73517. {
  73518. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73519. {
  73520. const PixelARGB col (colourToClearTo.getPixelARGB());
  73521. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73522. uint8* dest = destData.data;
  73523. while (--dh >= 0)
  73524. {
  73525. uint8* line = dest;
  73526. dest += destData.lineStride;
  73527. if (isARGB())
  73528. {
  73529. for (int x = dw; --x >= 0;)
  73530. {
  73531. ((PixelARGB*) line)->set (col);
  73532. line += destData.pixelStride;
  73533. }
  73534. }
  73535. else if (isRGB())
  73536. {
  73537. for (int x = dw; --x >= 0;)
  73538. {
  73539. ((PixelRGB*) line)->set (col);
  73540. line += destData.pixelStride;
  73541. }
  73542. }
  73543. else
  73544. {
  73545. for (int x = dw; --x >= 0;)
  73546. {
  73547. *line = col.getAlpha();
  73548. line += destData.pixelStride;
  73549. }
  73550. }
  73551. }
  73552. }
  73553. }
  73554. Image* Image::createCopy (int newWidth, int newHeight,
  73555. const Graphics::ResamplingQuality quality) const
  73556. {
  73557. if (newWidth < 0)
  73558. newWidth = imageWidth;
  73559. if (newHeight < 0)
  73560. newHeight = imageHeight;
  73561. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73562. Graphics g (*newImage);
  73563. g.setImageResamplingQuality (quality);
  73564. g.drawImage (this,
  73565. 0, 0, newWidth, newHeight,
  73566. 0, 0, imageWidth, imageHeight,
  73567. false);
  73568. return newImage;
  73569. }
  73570. Image* Image::createCopyOfAlphaChannel() const
  73571. {
  73572. jassert (format != SingleChannel);
  73573. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73574. if (! hasAlphaChannel())
  73575. {
  73576. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73577. }
  73578. else
  73579. {
  73580. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73581. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73582. for (int y = 0; y < imageHeight; ++y)
  73583. {
  73584. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73585. uint8* dst = destData.getLinePointer (y);
  73586. for (int x = imageWidth; --x >= 0;)
  73587. {
  73588. *dst++ = src->getAlpha();
  73589. ++src;
  73590. }
  73591. }
  73592. }
  73593. return newImage;
  73594. }
  73595. const Colour Image::getPixelAt (const int x, const int y) const
  73596. {
  73597. Colour c;
  73598. if (((unsigned int) x) < (unsigned int) imageWidth
  73599. && ((unsigned int) y) < (unsigned int) imageHeight)
  73600. {
  73601. const BitmapData srcData (*this, x, y, 1, 1);
  73602. if (isARGB())
  73603. {
  73604. PixelARGB p (*(const PixelARGB*) srcData.data);
  73605. p.unpremultiply();
  73606. c = Colour (p.getARGB());
  73607. }
  73608. else if (isRGB())
  73609. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73610. else
  73611. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73612. }
  73613. return c;
  73614. }
  73615. void Image::setPixelAt (const int x, const int y,
  73616. const Colour& colour)
  73617. {
  73618. if (((unsigned int) x) < (unsigned int) imageWidth
  73619. && ((unsigned int) y) < (unsigned int) imageHeight)
  73620. {
  73621. const BitmapData destData (*this, x, y, 1, 1, true);
  73622. const PixelARGB col (colour.getPixelARGB());
  73623. if (isARGB())
  73624. ((PixelARGB*) destData.data)->set (col);
  73625. else if (isRGB())
  73626. ((PixelRGB*) destData.data)->set (col);
  73627. else
  73628. *(destData.data) = col.getAlpha();
  73629. }
  73630. }
  73631. void Image::multiplyAlphaAt (const int x, const int y,
  73632. const float multiplier)
  73633. {
  73634. if (((unsigned int) x) < (unsigned int) imageWidth
  73635. && ((unsigned int) y) < (unsigned int) imageHeight
  73636. && hasAlphaChannel())
  73637. {
  73638. const BitmapData destData (*this, x, y, 1, 1, true);
  73639. if (isARGB())
  73640. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73641. else
  73642. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73643. }
  73644. }
  73645. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73646. {
  73647. if (hasAlphaChannel())
  73648. {
  73649. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73650. if (isARGB())
  73651. {
  73652. for (int y = 0; y < imageHeight; ++y)
  73653. {
  73654. uint8* p = destData.getLinePointer (y);
  73655. for (int x = 0; x < imageWidth; ++x)
  73656. {
  73657. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73658. p += destData.pixelStride;
  73659. }
  73660. }
  73661. }
  73662. else
  73663. {
  73664. for (int y = 0; y < imageHeight; ++y)
  73665. {
  73666. uint8* p = destData.getLinePointer (y);
  73667. for (int x = 0; x < imageWidth; ++x)
  73668. {
  73669. *p = (uint8) (*p * amountToMultiplyBy);
  73670. p += destData.pixelStride;
  73671. }
  73672. }
  73673. }
  73674. }
  73675. else
  73676. {
  73677. jassertfalse // can't do this without an alpha-channel!
  73678. }
  73679. }
  73680. void Image::desaturate()
  73681. {
  73682. if (isARGB() || isRGB())
  73683. {
  73684. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73685. if (isARGB())
  73686. {
  73687. for (int y = 0; y < imageHeight; ++y)
  73688. {
  73689. uint8* p = destData.getLinePointer (y);
  73690. for (int x = 0; x < imageWidth; ++x)
  73691. {
  73692. ((PixelARGB*) p)->desaturate();
  73693. p += destData.pixelStride;
  73694. }
  73695. }
  73696. }
  73697. else
  73698. {
  73699. for (int y = 0; y < imageHeight; ++y)
  73700. {
  73701. uint8* p = destData.getLinePointer (y);
  73702. for (int x = 0; x < imageWidth; ++x)
  73703. {
  73704. ((PixelRGB*) p)->desaturate();
  73705. p += destData.pixelStride;
  73706. }
  73707. }
  73708. }
  73709. }
  73710. }
  73711. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73712. {
  73713. if (hasAlphaChannel())
  73714. {
  73715. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73716. SparseSet <int> pixelsOnRow;
  73717. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73718. for (int y = 0; y < imageHeight; ++y)
  73719. {
  73720. pixelsOnRow.clear();
  73721. const uint8* lineData = srcData.getLinePointer (y);
  73722. if (isARGB())
  73723. {
  73724. for (int x = 0; x < imageWidth; ++x)
  73725. {
  73726. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73727. pixelsOnRow.addRange (x, 1);
  73728. lineData += srcData.pixelStride;
  73729. }
  73730. }
  73731. else
  73732. {
  73733. for (int x = 0; x < imageWidth; ++x)
  73734. {
  73735. if (*lineData >= threshold)
  73736. pixelsOnRow.addRange (x, 1);
  73737. lineData += srcData.pixelStride;
  73738. }
  73739. }
  73740. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73741. {
  73742. int x, w;
  73743. if (pixelsOnRow.getRange (i, x, w))
  73744. result.add (Rectangle<int> (x, y, w, 1));
  73745. }
  73746. result.consolidate();
  73747. }
  73748. }
  73749. else
  73750. {
  73751. result.add (0, 0, imageWidth, imageHeight);
  73752. }
  73753. }
  73754. void Image::moveImageSection (int dx, int dy,
  73755. int sx, int sy,
  73756. int w, int h)
  73757. {
  73758. if (dx < 0)
  73759. {
  73760. w += dx;
  73761. sx -= dx;
  73762. dx = 0;
  73763. }
  73764. if (dy < 0)
  73765. {
  73766. h += dy;
  73767. sy -= dy;
  73768. dy = 0;
  73769. }
  73770. if (sx < 0)
  73771. {
  73772. w += sx;
  73773. dx -= sx;
  73774. sx = 0;
  73775. }
  73776. if (sy < 0)
  73777. {
  73778. h += sy;
  73779. dy -= sy;
  73780. sy = 0;
  73781. }
  73782. const int minX = jmin (dx, sx);
  73783. const int minY = jmin (dy, sy);
  73784. w = jmin (w, getWidth() - jmax (sx, dx));
  73785. h = jmin (h, getHeight() - jmax (sy, dy));
  73786. if (w > 0 && h > 0)
  73787. {
  73788. const int maxX = jmax (dx, sx) + w;
  73789. const int maxY = jmax (dy, sy) + h;
  73790. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73791. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73792. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73793. const int lineSize = destData.pixelStride * w;
  73794. if (dy > sy)
  73795. {
  73796. while (--h >= 0)
  73797. {
  73798. const int offset = h * destData.lineStride;
  73799. memmove (dst + offset, src + offset, lineSize);
  73800. }
  73801. }
  73802. else if (dst != src)
  73803. {
  73804. while (--h >= 0)
  73805. {
  73806. memmove (dst, src, lineSize);
  73807. dst += destData.lineStride;
  73808. src += destData.lineStride;
  73809. }
  73810. }
  73811. }
  73812. }
  73813. END_JUCE_NAMESPACE
  73814. /*** End of inlined file: juce_Image.cpp ***/
  73815. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73816. BEGIN_JUCE_NAMESPACE
  73817. struct ImageCache::Item
  73818. {
  73819. ScopedPointer <Image> image;
  73820. int64 hashCode;
  73821. int refCount;
  73822. uint32 releaseTime;
  73823. juce_UseDebuggingNewOperator
  73824. };
  73825. ImageCache* ImageCache::instance = 0;
  73826. int ImageCache::cacheTimeout = 5000;
  73827. ImageCache::ImageCache()
  73828. {
  73829. }
  73830. ImageCache::~ImageCache()
  73831. {
  73832. jassert (instance == this);
  73833. instance = 0;
  73834. }
  73835. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73836. {
  73837. if (instance != 0)
  73838. {
  73839. const ScopedLock sl (instance->lock);
  73840. for (int i = instance->images.size(); --i >= 0;)
  73841. {
  73842. Item* const ci = instance->images.getUnchecked(i);
  73843. if (ci->hashCode == hashCode)
  73844. {
  73845. ci->refCount++;
  73846. return ci->image;
  73847. }
  73848. }
  73849. }
  73850. return 0;
  73851. }
  73852. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73853. {
  73854. if (image != 0)
  73855. {
  73856. if (instance == 0)
  73857. instance = new ImageCache();
  73858. Item* const newC = new Item();
  73859. newC->hashCode = hashCode;
  73860. newC->image = image;
  73861. newC->refCount = 1;
  73862. newC->releaseTime = 0;
  73863. const ScopedLock sl (instance->lock);
  73864. instance->images.add (newC);
  73865. }
  73866. }
  73867. void ImageCache::release (Image* const imageToRelease)
  73868. {
  73869. if (imageToRelease != 0 && instance != 0)
  73870. {
  73871. const ScopedLock sl (instance->lock);
  73872. for (int i = instance->images.size(); --i >= 0;)
  73873. {
  73874. Item* const ci = instance->images.getUnchecked(i);
  73875. if (static_cast <Image*> (ci->image) == imageToRelease)
  73876. {
  73877. if (--(ci->refCount) == 0)
  73878. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73879. if (! instance->isTimerRunning())
  73880. instance->startTimer (999);
  73881. break;
  73882. }
  73883. }
  73884. }
  73885. }
  73886. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73887. {
  73888. if (isImageInCache (imageToRelease))
  73889. release (imageToRelease);
  73890. else
  73891. delete imageToRelease;
  73892. }
  73893. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73894. {
  73895. if (instance != 0)
  73896. {
  73897. const ScopedLock sl (instance->lock);
  73898. for (int i = instance->images.size(); --i >= 0;)
  73899. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73900. return true;
  73901. }
  73902. return false;
  73903. }
  73904. void ImageCache::incReferenceCount (Image* const image)
  73905. {
  73906. if (instance != 0)
  73907. {
  73908. const ScopedLock sl (instance->lock);
  73909. for (int i = instance->images.size(); --i >= 0;)
  73910. {
  73911. Item* const ci = instance->images.getUnchecked(i);
  73912. if (static_cast <Image*> (ci->image) == image)
  73913. {
  73914. ci->refCount++;
  73915. return;
  73916. }
  73917. }
  73918. }
  73919. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73920. }
  73921. void ImageCache::timerCallback()
  73922. {
  73923. int numberStillNeedingReleasing = 0;
  73924. const uint32 now = Time::getApproximateMillisecondCounter();
  73925. const ScopedLock sl (lock);
  73926. for (int i = images.size(); --i >= 0;)
  73927. {
  73928. Item* const ci = images.getUnchecked(i);
  73929. if (ci->refCount <= 0)
  73930. {
  73931. if (now > ci->releaseTime + cacheTimeout
  73932. || now < ci->releaseTime - 1000)
  73933. {
  73934. images.remove (i);
  73935. }
  73936. else
  73937. {
  73938. ++numberStillNeedingReleasing;
  73939. }
  73940. }
  73941. }
  73942. if (numberStillNeedingReleasing == 0)
  73943. stopTimer();
  73944. }
  73945. Image* ImageCache::getFromFile (const File& file)
  73946. {
  73947. const int64 hashCode = file.hashCode64();
  73948. Image* image = getFromHashCode (hashCode);
  73949. if (image == 0)
  73950. {
  73951. image = ImageFileFormat::loadFrom (file);
  73952. addImageToCache (image, hashCode);
  73953. }
  73954. return image;
  73955. }
  73956. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  73957. {
  73958. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  73959. Image* image = getFromHashCode (hashCode);
  73960. if (image == 0)
  73961. {
  73962. image = ImageFileFormat::loadFrom (imageData, dataSize);
  73963. addImageToCache (image, hashCode);
  73964. }
  73965. return image;
  73966. }
  73967. void ImageCache::setCacheTimeout (const int millisecs)
  73968. {
  73969. cacheTimeout = millisecs;
  73970. }
  73971. END_JUCE_NAMESPACE
  73972. /*** End of inlined file: juce_ImageCache.cpp ***/
  73973. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  73974. BEGIN_JUCE_NAMESPACE
  73975. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  73976. : values (size_ * size_),
  73977. size (size_)
  73978. {
  73979. clear();
  73980. }
  73981. ImageConvolutionKernel::~ImageConvolutionKernel()
  73982. {
  73983. }
  73984. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  73985. {
  73986. if (((unsigned int) x) < (unsigned int) size
  73987. && ((unsigned int) y) < (unsigned int) size)
  73988. {
  73989. return values [x + y * size];
  73990. }
  73991. else
  73992. {
  73993. jassertfalse;
  73994. return 0;
  73995. }
  73996. }
  73997. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  73998. {
  73999. if (((unsigned int) x) < (unsigned int) size
  74000. && ((unsigned int) y) < (unsigned int) size)
  74001. {
  74002. values [x + y * size] = value;
  74003. }
  74004. else
  74005. {
  74006. jassertfalse;
  74007. }
  74008. }
  74009. void ImageConvolutionKernel::clear()
  74010. {
  74011. for (int i = size * size; --i >= 0;)
  74012. values[i] = 0;
  74013. }
  74014. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74015. {
  74016. double currentTotal = 0.0;
  74017. for (int i = size * size; --i >= 0;)
  74018. currentTotal += values[i];
  74019. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74020. }
  74021. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74022. {
  74023. for (int i = size * size; --i >= 0;)
  74024. values[i] *= multiplier;
  74025. }
  74026. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74027. {
  74028. const double radiusFactor = -1.0 / (radius * radius * 2);
  74029. const int centre = size >> 1;
  74030. for (int y = size; --y >= 0;)
  74031. {
  74032. for (int x = size; --x >= 0;)
  74033. {
  74034. const int cx = x - centre;
  74035. const int cy = y - centre;
  74036. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74037. }
  74038. }
  74039. setOverallSum (1.0f);
  74040. }
  74041. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74042. const Image* sourceImage,
  74043. const Rectangle<int>& destinationArea) const
  74044. {
  74045. ScopedPointer <Image> imageCreated;
  74046. if (sourceImage == 0)
  74047. {
  74048. sourceImage = imageCreated = destImage.createCopy();
  74049. }
  74050. else
  74051. {
  74052. jassert (sourceImage->getWidth() == destImage.getWidth()
  74053. && sourceImage->getHeight() == destImage.getHeight()
  74054. && sourceImage->getFormat() == destImage.getFormat());
  74055. if (sourceImage->getWidth() != destImage.getWidth()
  74056. || sourceImage->getHeight() != destImage.getHeight()
  74057. || sourceImage->getFormat() != destImage.getFormat())
  74058. return;
  74059. }
  74060. const Rectangle<int> area (destinationArea.getIntersection (destImage.getBounds()));
  74061. if (area.isEmpty())
  74062. return;
  74063. const int right = area.getRight();
  74064. const int bottom = area.getBottom();
  74065. const Image::BitmapData destData (destImage, area.getX(), area.getY(), area.getWidth(), area.getHeight(), true);
  74066. uint8* line = destData.data;
  74067. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74068. if (destData.pixelStride == 4)
  74069. {
  74070. for (int y = area.getY(); y < bottom; ++y)
  74071. {
  74072. uint8* dest = line;
  74073. line += destData.lineStride;
  74074. for (int x = area.getX(); x < right; ++x)
  74075. {
  74076. float c1 = 0;
  74077. float c2 = 0;
  74078. float c3 = 0;
  74079. float c4 = 0;
  74080. for (int yy = 0; yy < size; ++yy)
  74081. {
  74082. const int sy = y + yy - (size >> 1);
  74083. if (sy >= srcData.height)
  74084. break;
  74085. if (sy >= 0)
  74086. {
  74087. int sx = x - (size >> 1);
  74088. const uint8* src = srcData.getPixelPointer (sx, sy);
  74089. for (int xx = 0; xx < size; ++xx)
  74090. {
  74091. if (sx >= srcData.width)
  74092. break;
  74093. if (sx >= 0)
  74094. {
  74095. const float kernelMult = values [xx + yy * size];
  74096. c1 += kernelMult * *src++;
  74097. c2 += kernelMult * *src++;
  74098. c3 += kernelMult * *src++;
  74099. c4 += kernelMult * *src++;
  74100. }
  74101. else
  74102. {
  74103. src += 4;
  74104. }
  74105. ++sx;
  74106. }
  74107. }
  74108. }
  74109. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74110. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74111. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74112. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74113. }
  74114. }
  74115. }
  74116. else if (destData.pixelStride == 3)
  74117. {
  74118. for (int y = area.getY(); y < bottom; ++y)
  74119. {
  74120. uint8* dest = line;
  74121. line += destData.lineStride;
  74122. for (int x = area.getX(); x < right; ++x)
  74123. {
  74124. float c1 = 0;
  74125. float c2 = 0;
  74126. float c3 = 0;
  74127. for (int yy = 0; yy < size; ++yy)
  74128. {
  74129. const int sy = y + yy - (size >> 1);
  74130. if (sy >= srcData.height)
  74131. break;
  74132. if (sy >= 0)
  74133. {
  74134. int sx = x - (size >> 1);
  74135. const uint8* src = srcData.getPixelPointer (sx, sy);
  74136. for (int xx = 0; xx < size; ++xx)
  74137. {
  74138. if (sx >= srcData.width)
  74139. break;
  74140. if (sx >= 0)
  74141. {
  74142. const float kernelMult = values [xx + yy * size];
  74143. c1 += kernelMult * *src++;
  74144. c2 += kernelMult * *src++;
  74145. c3 += kernelMult * *src++;
  74146. }
  74147. else
  74148. {
  74149. src += 3;
  74150. }
  74151. ++sx;
  74152. }
  74153. }
  74154. }
  74155. *dest++ = (uint8) roundToInt (c1);
  74156. *dest++ = (uint8) roundToInt (c2);
  74157. *dest++ = (uint8) roundToInt (c3);
  74158. }
  74159. }
  74160. }
  74161. }
  74162. END_JUCE_NAMESPACE
  74163. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74164. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74165. BEGIN_JUCE_NAMESPACE
  74166. /*** Start of inlined file: juce_GIFLoader.h ***/
  74167. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74168. #define __JUCE_GIFLOADER_JUCEHEADER__
  74169. #ifndef DOXYGEN
  74170. class GIFLoader
  74171. {
  74172. public:
  74173. GIFLoader (InputStream& in);
  74174. ~GIFLoader();
  74175. Image* getImage() const { return image; }
  74176. private:
  74177. Image* image;
  74178. InputStream& input;
  74179. uint8 buffer [300];
  74180. uint8 palette [256][4];
  74181. bool dataBlockIsZero, fresh, finished;
  74182. int currentBit, lastBit, lastByteIndex;
  74183. int codeSize, setCodeSize;
  74184. int maxCode, maxCodeSize;
  74185. int firstcode, oldcode;
  74186. int clearCode, end_code;
  74187. enum { maxGifCode = 1 << 12 };
  74188. int table [2] [maxGifCode];
  74189. int stack [2 * maxGifCode];
  74190. int *sp;
  74191. bool getSizeFromHeader (int& width, int& height);
  74192. bool readPalette (const int numCols);
  74193. int readDataBlock (unsigned char* dest);
  74194. int processExtension (int type, int& transparent);
  74195. int readLZWByte (bool initialise, int input_code_size);
  74196. int getCode (int code_size, bool initialise);
  74197. bool readImage (int width, int height, int interlace, int transparent);
  74198. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74199. GIFLoader (const GIFLoader&);
  74200. GIFLoader& operator= (const GIFLoader&);
  74201. };
  74202. #endif // DOXYGEN
  74203. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74204. /*** End of inlined file: juce_GIFLoader.h ***/
  74205. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74206. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74207. PNGImageFormat::PNGImageFormat() {}
  74208. PNGImageFormat::~PNGImageFormat() {}
  74209. const String PNGImageFormat::getFormatName()
  74210. {
  74211. return "PNG";
  74212. }
  74213. bool PNGImageFormat::canUnderstand (InputStream& in)
  74214. {
  74215. const int bytesNeeded = 4;
  74216. char header [bytesNeeded];
  74217. return in.read (header, bytesNeeded) == bytesNeeded
  74218. && header[1] == 'P'
  74219. && header[2] == 'N'
  74220. && header[3] == 'G';
  74221. }
  74222. Image* PNGImageFormat::decodeImage (InputStream& in)
  74223. {
  74224. return juce_loadPNGImageFromStream (in);
  74225. }
  74226. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74227. OutputStream& destStream)
  74228. {
  74229. return juce_writePNGImageToStream (sourceImage, destStream);
  74230. }
  74231. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74232. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74233. JPEGImageFormat::JPEGImageFormat()
  74234. : quality (-1.0f)
  74235. {
  74236. }
  74237. JPEGImageFormat::~JPEGImageFormat() {}
  74238. void JPEGImageFormat::setQuality (const float newQuality)
  74239. {
  74240. quality = newQuality;
  74241. }
  74242. const String JPEGImageFormat::getFormatName()
  74243. {
  74244. return "JPEG";
  74245. }
  74246. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74247. {
  74248. const int bytesNeeded = 10;
  74249. uint8 header [bytesNeeded];
  74250. if (in.read (header, bytesNeeded) == bytesNeeded)
  74251. {
  74252. return header[0] == 0xff
  74253. && header[1] == 0xd8
  74254. && header[2] == 0xff
  74255. && (header[3] == 0xe0 || header[3] == 0xe1);
  74256. }
  74257. return false;
  74258. }
  74259. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74260. {
  74261. return juce_loadJPEGImageFromStream (in);
  74262. }
  74263. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74264. OutputStream& destStream)
  74265. {
  74266. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74267. }
  74268. class GIFImageFormat : public ImageFileFormat
  74269. {
  74270. public:
  74271. GIFImageFormat() {}
  74272. ~GIFImageFormat() {}
  74273. const String getFormatName()
  74274. {
  74275. return "GIF";
  74276. }
  74277. bool canUnderstand (InputStream& in)
  74278. {
  74279. const int bytesNeeded = 4;
  74280. char header [bytesNeeded];
  74281. return (in.read (header, bytesNeeded) == bytesNeeded)
  74282. && header[0] == 'G'
  74283. && header[1] == 'I'
  74284. && header[2] == 'F';
  74285. }
  74286. Image* decodeImage (InputStream& in)
  74287. {
  74288. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74289. return loader->getImage();
  74290. }
  74291. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74292. {
  74293. return false;
  74294. }
  74295. };
  74296. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74297. {
  74298. static PNGImageFormat png;
  74299. static JPEGImageFormat jpg;
  74300. static GIFImageFormat gif;
  74301. ImageFileFormat* formats[4];
  74302. int numFormats = 0;
  74303. formats [numFormats++] = &png;
  74304. formats [numFormats++] = &jpg;
  74305. formats [numFormats++] = &gif;
  74306. const int64 streamPos = input.getPosition();
  74307. for (int i = 0; i < numFormats; ++i)
  74308. {
  74309. const bool found = formats[i]->canUnderstand (input);
  74310. input.setPosition (streamPos);
  74311. if (found)
  74312. return formats[i];
  74313. }
  74314. return 0;
  74315. }
  74316. Image* ImageFileFormat::loadFrom (InputStream& input)
  74317. {
  74318. ImageFileFormat* const format = findImageFormatForStream (input);
  74319. if (format != 0)
  74320. return format->decodeImage (input);
  74321. return 0;
  74322. }
  74323. Image* ImageFileFormat::loadFrom (const File& file)
  74324. {
  74325. InputStream* const in = file.createInputStream();
  74326. if (in != 0)
  74327. {
  74328. BufferedInputStream b (in, 8192, true);
  74329. return loadFrom (b);
  74330. }
  74331. return 0;
  74332. }
  74333. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74334. {
  74335. if (rawData != 0 && numBytes > 4)
  74336. {
  74337. MemoryInputStream stream (rawData, numBytes, false);
  74338. return loadFrom (stream);
  74339. }
  74340. return 0;
  74341. }
  74342. END_JUCE_NAMESPACE
  74343. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74344. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74345. BEGIN_JUCE_NAMESPACE
  74346. GIFLoader::GIFLoader (InputStream& in)
  74347. : image (0),
  74348. input (in),
  74349. dataBlockIsZero (false),
  74350. fresh (false),
  74351. finished (false)
  74352. {
  74353. currentBit = lastBit = lastByteIndex = 0;
  74354. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74355. firstcode = oldcode = 0;
  74356. clearCode = end_code = 0;
  74357. int imageWidth, imageHeight;
  74358. int transparent = -1;
  74359. if (! getSizeFromHeader (imageWidth, imageHeight))
  74360. return;
  74361. if ((imageWidth <= 0) || (imageHeight <= 0))
  74362. return;
  74363. unsigned char buf [16];
  74364. if (in.read (buf, 3) != 3)
  74365. return;
  74366. int numColours = 2 << (buf[0] & 7);
  74367. if ((buf[0] & 0x80) != 0)
  74368. readPalette (numColours);
  74369. for (;;)
  74370. {
  74371. if (input.read (buf, 1) != 1)
  74372. break;
  74373. if (buf[0] == ';')
  74374. break;
  74375. if (buf[0] == '!')
  74376. {
  74377. if (input.read (buf, 1) != 1)
  74378. break;
  74379. if (processExtension (buf[0], transparent) < 0)
  74380. break;
  74381. continue;
  74382. }
  74383. if (buf[0] != ',')
  74384. continue;
  74385. if (input.read (buf, 9) != 9)
  74386. break;
  74387. imageWidth = makeWord (buf[4], buf[5]);
  74388. imageHeight = makeWord (buf[6], buf[7]);
  74389. numColours = 2 << (buf[8] & 7);
  74390. if ((buf[8] & 0x80) != 0)
  74391. if (! readPalette (numColours))
  74392. break;
  74393. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74394. imageWidth, imageHeight, (transparent >= 0));
  74395. readImage (imageWidth, imageHeight,
  74396. (buf[8] & 0x40) != 0,
  74397. transparent);
  74398. break;
  74399. }
  74400. }
  74401. GIFLoader::~GIFLoader()
  74402. {
  74403. }
  74404. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74405. {
  74406. char b[8];
  74407. if (input.read (b, 6) == 6)
  74408. {
  74409. if ((strncmp ("GIF87a", b, 6) == 0)
  74410. || (strncmp ("GIF89a", b, 6) == 0))
  74411. {
  74412. if (input.read (b, 4) == 4)
  74413. {
  74414. w = makeWord (b[0], b[1]);
  74415. h = makeWord (b[2], b[3]);
  74416. return true;
  74417. }
  74418. }
  74419. }
  74420. return false;
  74421. }
  74422. bool GIFLoader::readPalette (const int numCols)
  74423. {
  74424. unsigned char rgb[4];
  74425. for (int i = 0; i < numCols; ++i)
  74426. {
  74427. input.read (rgb, 3);
  74428. palette [i][0] = rgb[0];
  74429. palette [i][1] = rgb[1];
  74430. palette [i][2] = rgb[2];
  74431. palette [i][3] = 0xff;
  74432. }
  74433. return true;
  74434. }
  74435. int GIFLoader::readDataBlock (unsigned char* const dest)
  74436. {
  74437. unsigned char n;
  74438. if (input.read (&n, 1) == 1)
  74439. {
  74440. dataBlockIsZero = (n == 0);
  74441. if (dataBlockIsZero || (input.read (dest, n) == n))
  74442. return n;
  74443. }
  74444. return -1;
  74445. }
  74446. int GIFLoader::processExtension (const int type, int& transparent)
  74447. {
  74448. unsigned char b [300];
  74449. int n = 0;
  74450. if (type == 0xf9)
  74451. {
  74452. n = readDataBlock (b);
  74453. if (n < 0)
  74454. return 1;
  74455. if ((b[0] & 0x1) != 0)
  74456. transparent = b[3];
  74457. }
  74458. do
  74459. {
  74460. n = readDataBlock (b);
  74461. }
  74462. while (n > 0);
  74463. return n;
  74464. }
  74465. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74466. {
  74467. if (initialise)
  74468. {
  74469. currentBit = 0;
  74470. lastBit = 0;
  74471. finished = false;
  74472. return 0;
  74473. }
  74474. if ((currentBit + codeSize_) >= lastBit)
  74475. {
  74476. if (finished)
  74477. return -1;
  74478. buffer[0] = buffer [lastByteIndex - 2];
  74479. buffer[1] = buffer [lastByteIndex - 1];
  74480. const int n = readDataBlock (&buffer[2]);
  74481. if (n == 0)
  74482. finished = true;
  74483. lastByteIndex = 2 + n;
  74484. currentBit = (currentBit - lastBit) + 16;
  74485. lastBit = (2 + n) * 8 ;
  74486. }
  74487. int result = 0;
  74488. int i = currentBit;
  74489. for (int j = 0; j < codeSize_; ++j)
  74490. {
  74491. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74492. ++i;
  74493. }
  74494. currentBit += codeSize_;
  74495. return result;
  74496. }
  74497. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74498. {
  74499. int code, incode, i;
  74500. if (initialise)
  74501. {
  74502. setCodeSize = inputCodeSize;
  74503. codeSize = setCodeSize + 1;
  74504. clearCode = 1 << setCodeSize;
  74505. end_code = clearCode + 1;
  74506. maxCodeSize = 2 * clearCode;
  74507. maxCode = clearCode + 2;
  74508. getCode (0, true);
  74509. fresh = true;
  74510. for (i = 0; i < clearCode; ++i)
  74511. {
  74512. table[0][i] = 0;
  74513. table[1][i] = i;
  74514. }
  74515. for (; i < maxGifCode; ++i)
  74516. {
  74517. table[0][i] = 0;
  74518. table[1][i] = 0;
  74519. }
  74520. sp = stack;
  74521. return 0;
  74522. }
  74523. else if (fresh)
  74524. {
  74525. fresh = false;
  74526. do
  74527. {
  74528. firstcode = oldcode
  74529. = getCode (codeSize, false);
  74530. }
  74531. while (firstcode == clearCode);
  74532. return firstcode;
  74533. }
  74534. if (sp > stack)
  74535. return *--sp;
  74536. while ((code = getCode (codeSize, false)) >= 0)
  74537. {
  74538. if (code == clearCode)
  74539. {
  74540. for (i = 0; i < clearCode; ++i)
  74541. {
  74542. table[0][i] = 0;
  74543. table[1][i] = i;
  74544. }
  74545. for (; i < maxGifCode; ++i)
  74546. {
  74547. table[0][i] = 0;
  74548. table[1][i] = 0;
  74549. }
  74550. codeSize = setCodeSize + 1;
  74551. maxCodeSize = 2 * clearCode;
  74552. maxCode = clearCode + 2;
  74553. sp = stack;
  74554. firstcode = oldcode = getCode (codeSize, false);
  74555. return firstcode;
  74556. }
  74557. else if (code == end_code)
  74558. {
  74559. if (dataBlockIsZero)
  74560. return -2;
  74561. unsigned char buf [260];
  74562. int n;
  74563. while ((n = readDataBlock (buf)) > 0)
  74564. {}
  74565. if (n != 0)
  74566. return -2;
  74567. }
  74568. incode = code;
  74569. if (code >= maxCode)
  74570. {
  74571. *sp++ = firstcode;
  74572. code = oldcode;
  74573. }
  74574. while (code >= clearCode)
  74575. {
  74576. *sp++ = table[1][code];
  74577. if (code == table[0][code])
  74578. return -2;
  74579. code = table[0][code];
  74580. }
  74581. *sp++ = firstcode = table[1][code];
  74582. if ((code = maxCode) < maxGifCode)
  74583. {
  74584. table[0][code] = oldcode;
  74585. table[1][code] = firstcode;
  74586. ++maxCode;
  74587. if ((maxCode >= maxCodeSize)
  74588. && (maxCodeSize < maxGifCode))
  74589. {
  74590. maxCodeSize <<= 1;
  74591. ++codeSize;
  74592. }
  74593. }
  74594. oldcode = incode;
  74595. if (sp > stack)
  74596. return *--sp;
  74597. }
  74598. return code;
  74599. }
  74600. bool GIFLoader::readImage (const int width, const int height,
  74601. const int interlace, const int transparent)
  74602. {
  74603. unsigned char c;
  74604. if (input.read (&c, 1) != 1
  74605. || readLZWByte (true, c) < 0)
  74606. return false;
  74607. if (transparent >= 0)
  74608. {
  74609. palette [transparent][0] = 0;
  74610. palette [transparent][1] = 0;
  74611. palette [transparent][2] = 0;
  74612. palette [transparent][3] = 0;
  74613. }
  74614. int index;
  74615. int xpos = 0, ypos = 0, pass = 0;
  74616. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74617. uint8* p = destData.data;
  74618. const bool hasAlpha = image->hasAlphaChannel();
  74619. while ((index = readLZWByte (false, c)) >= 0)
  74620. {
  74621. const uint8* const paletteEntry = palette [index];
  74622. if (hasAlpha)
  74623. {
  74624. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74625. paletteEntry[0],
  74626. paletteEntry[1],
  74627. paletteEntry[2]);
  74628. ((PixelARGB*) p)->premultiply();
  74629. }
  74630. else
  74631. {
  74632. ((PixelRGB*) p)->setARGB (0,
  74633. paletteEntry[0],
  74634. paletteEntry[1],
  74635. paletteEntry[2]);
  74636. }
  74637. p += destData.pixelStride;
  74638. ++xpos;
  74639. if (xpos == width)
  74640. {
  74641. xpos = 0;
  74642. if (interlace)
  74643. {
  74644. switch (pass)
  74645. {
  74646. case 0:
  74647. case 1:
  74648. ypos += 8;
  74649. break;
  74650. case 2:
  74651. ypos += 4;
  74652. break;
  74653. case 3:
  74654. ypos += 2;
  74655. break;
  74656. }
  74657. while (ypos >= height)
  74658. {
  74659. ++pass;
  74660. switch (pass)
  74661. {
  74662. case 1:
  74663. ypos = 4;
  74664. break;
  74665. case 2:
  74666. ypos = 2;
  74667. break;
  74668. case 3:
  74669. ypos = 1;
  74670. break;
  74671. default:
  74672. return true;
  74673. }
  74674. }
  74675. }
  74676. else
  74677. {
  74678. ++ypos;
  74679. }
  74680. p = destData.getPixelPointer (xpos, ypos);
  74681. }
  74682. if (ypos >= height)
  74683. break;
  74684. }
  74685. return true;
  74686. }
  74687. END_JUCE_NAMESPACE
  74688. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74689. #endif
  74690. //==============================================================================
  74691. // some files include lots of library code, so leave them to the end to avoid cluttering
  74692. // up the build for the clean files.
  74693. #if JUCE_BUILD_CORE
  74694. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74695. namespace zlibNamespace
  74696. {
  74697. #if JUCE_INCLUDE_ZLIB_CODE
  74698. #undef OS_CODE
  74699. #undef fdopen
  74700. /*** Start of inlined file: zlib.h ***/
  74701. #ifndef ZLIB_H
  74702. #define ZLIB_H
  74703. /*** Start of inlined file: zconf.h ***/
  74704. #ifndef ZCONF_H
  74705. #define ZCONF_H
  74706. // *** Just a few hacks here to make it compile nicely with Juce..
  74707. #define Z_PREFIX 1
  74708. #undef __MACTYPES__
  74709. #ifdef _MSC_VER
  74710. #pragma warning (disable : 4131 4127 4244 4267)
  74711. #endif
  74712. #ifdef Z_PREFIX
  74713. # define deflateInit_ z_deflateInit_
  74714. # define deflate z_deflate
  74715. # define deflateEnd z_deflateEnd
  74716. # define inflateInit_ z_inflateInit_
  74717. # define inflate z_inflate
  74718. # define inflateEnd z_inflateEnd
  74719. # define inflatePrime z_inflatePrime
  74720. # define inflateGetHeader z_inflateGetHeader
  74721. # define adler32_combine z_adler32_combine
  74722. # define crc32_combine z_crc32_combine
  74723. # define deflateInit2_ z_deflateInit2_
  74724. # define deflateSetDictionary z_deflateSetDictionary
  74725. # define deflateCopy z_deflateCopy
  74726. # define deflateReset z_deflateReset
  74727. # define deflateParams z_deflateParams
  74728. # define deflateBound z_deflateBound
  74729. # define deflatePrime z_deflatePrime
  74730. # define inflateInit2_ z_inflateInit2_
  74731. # define inflateSetDictionary z_inflateSetDictionary
  74732. # define inflateSync z_inflateSync
  74733. # define inflateSyncPoint z_inflateSyncPoint
  74734. # define inflateCopy z_inflateCopy
  74735. # define inflateReset z_inflateReset
  74736. # define inflateBack z_inflateBack
  74737. # define inflateBackEnd z_inflateBackEnd
  74738. # define compress z_compress
  74739. # define compress2 z_compress2
  74740. # define compressBound z_compressBound
  74741. # define uncompress z_uncompress
  74742. # define adler32 z_adler32
  74743. # define crc32 z_crc32
  74744. # define get_crc_table z_get_crc_table
  74745. # define zError z_zError
  74746. # define alloc_func z_alloc_func
  74747. # define free_func z_free_func
  74748. # define in_func z_in_func
  74749. # define out_func z_out_func
  74750. # define Byte z_Byte
  74751. # define uInt z_uInt
  74752. # define uLong z_uLong
  74753. # define Bytef z_Bytef
  74754. # define charf z_charf
  74755. # define intf z_intf
  74756. # define uIntf z_uIntf
  74757. # define uLongf z_uLongf
  74758. # define voidpf z_voidpf
  74759. # define voidp z_voidp
  74760. #endif
  74761. #if defined(__MSDOS__) && !defined(MSDOS)
  74762. # define MSDOS
  74763. #endif
  74764. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74765. # define OS2
  74766. #endif
  74767. #if defined(_WINDOWS) && !defined(WINDOWS)
  74768. # define WINDOWS
  74769. #endif
  74770. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74771. # ifndef WIN32
  74772. # define WIN32
  74773. # endif
  74774. #endif
  74775. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74776. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74777. # ifndef SYS16BIT
  74778. # define SYS16BIT
  74779. # endif
  74780. # endif
  74781. #endif
  74782. #ifdef SYS16BIT
  74783. # define MAXSEG_64K
  74784. #endif
  74785. #ifdef MSDOS
  74786. # define UNALIGNED_OK
  74787. #endif
  74788. #ifdef __STDC_VERSION__
  74789. # ifndef STDC
  74790. # define STDC
  74791. # endif
  74792. # if __STDC_VERSION__ >= 199901L
  74793. # ifndef STDC99
  74794. # define STDC99
  74795. # endif
  74796. # endif
  74797. #endif
  74798. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74799. # define STDC
  74800. #endif
  74801. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74802. # define STDC
  74803. #endif
  74804. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74805. # define STDC
  74806. #endif
  74807. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74808. # define STDC
  74809. #endif
  74810. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74811. # define STDC
  74812. #endif
  74813. #ifndef STDC
  74814. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74815. # define const /* note: need a more gentle solution here */
  74816. # endif
  74817. #endif
  74818. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74819. # define NO_DUMMY_DECL
  74820. #endif
  74821. #ifndef MAX_MEM_LEVEL
  74822. # ifdef MAXSEG_64K
  74823. # define MAX_MEM_LEVEL 8
  74824. # else
  74825. # define MAX_MEM_LEVEL 9
  74826. # endif
  74827. #endif
  74828. #ifndef MAX_WBITS
  74829. # define MAX_WBITS 15 /* 32K LZ77 window */
  74830. #endif
  74831. #ifndef OF /* function prototypes */
  74832. # ifdef STDC
  74833. # define OF(args) args
  74834. # else
  74835. # define OF(args) ()
  74836. # endif
  74837. #endif
  74838. #ifdef SYS16BIT
  74839. # if defined(M_I86SM) || defined(M_I86MM)
  74840. # define SMALL_MEDIUM
  74841. # ifdef _MSC_VER
  74842. # define FAR _far
  74843. # else
  74844. # define FAR far
  74845. # endif
  74846. # endif
  74847. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74848. # define SMALL_MEDIUM
  74849. # ifdef __BORLANDC__
  74850. # define FAR _far
  74851. # else
  74852. # define FAR far
  74853. # endif
  74854. # endif
  74855. #endif
  74856. #if defined(WINDOWS) || defined(WIN32)
  74857. # ifdef ZLIB_DLL
  74858. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74859. # ifdef ZLIB_INTERNAL
  74860. # define ZEXTERN extern __declspec(dllexport)
  74861. # else
  74862. # define ZEXTERN extern __declspec(dllimport)
  74863. # endif
  74864. # endif
  74865. # endif /* ZLIB_DLL */
  74866. # ifdef ZLIB_WINAPI
  74867. # ifdef FAR
  74868. # undef FAR
  74869. # endif
  74870. # include <windows.h>
  74871. # define ZEXPORT WINAPI
  74872. # ifdef WIN32
  74873. # define ZEXPORTVA WINAPIV
  74874. # else
  74875. # define ZEXPORTVA FAR CDECL
  74876. # endif
  74877. # endif
  74878. #endif
  74879. #if defined (__BEOS__)
  74880. # ifdef ZLIB_DLL
  74881. # ifdef ZLIB_INTERNAL
  74882. # define ZEXPORT __declspec(dllexport)
  74883. # define ZEXPORTVA __declspec(dllexport)
  74884. # else
  74885. # define ZEXPORT __declspec(dllimport)
  74886. # define ZEXPORTVA __declspec(dllimport)
  74887. # endif
  74888. # endif
  74889. #endif
  74890. #ifndef ZEXTERN
  74891. # define ZEXTERN extern
  74892. #endif
  74893. #ifndef ZEXPORT
  74894. # define ZEXPORT
  74895. #endif
  74896. #ifndef ZEXPORTVA
  74897. # define ZEXPORTVA
  74898. #endif
  74899. #ifndef FAR
  74900. # define FAR
  74901. #endif
  74902. #if !defined(__MACTYPES__)
  74903. typedef unsigned char Byte; /* 8 bits */
  74904. #endif
  74905. typedef unsigned int uInt; /* 16 bits or more */
  74906. typedef unsigned long uLong; /* 32 bits or more */
  74907. #ifdef SMALL_MEDIUM
  74908. # define Bytef Byte FAR
  74909. #else
  74910. typedef Byte FAR Bytef;
  74911. #endif
  74912. typedef char FAR charf;
  74913. typedef int FAR intf;
  74914. typedef uInt FAR uIntf;
  74915. typedef uLong FAR uLongf;
  74916. #ifdef STDC
  74917. typedef void const *voidpc;
  74918. typedef void FAR *voidpf;
  74919. typedef void *voidp;
  74920. #else
  74921. typedef Byte const *voidpc;
  74922. typedef Byte FAR *voidpf;
  74923. typedef Byte *voidp;
  74924. #endif
  74925. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74926. # include <sys/types.h> /* for off_t */
  74927. # include <unistd.h> /* for SEEK_* and off_t */
  74928. # ifdef VMS
  74929. # include <unixio.h> /* for off_t */
  74930. # endif
  74931. # define z_off_t off_t
  74932. #endif
  74933. #ifndef SEEK_SET
  74934. # define SEEK_SET 0 /* Seek from beginning of file. */
  74935. # define SEEK_CUR 1 /* Seek from current position. */
  74936. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  74937. #endif
  74938. #ifndef z_off_t
  74939. # define z_off_t long
  74940. #endif
  74941. #if defined(__OS400__)
  74942. # define NO_vsnprintf
  74943. #endif
  74944. #if defined(__MVS__)
  74945. # define NO_vsnprintf
  74946. # ifdef FAR
  74947. # undef FAR
  74948. # endif
  74949. #endif
  74950. #if defined(__MVS__)
  74951. # pragma map(deflateInit_,"DEIN")
  74952. # pragma map(deflateInit2_,"DEIN2")
  74953. # pragma map(deflateEnd,"DEEND")
  74954. # pragma map(deflateBound,"DEBND")
  74955. # pragma map(inflateInit_,"ININ")
  74956. # pragma map(inflateInit2_,"ININ2")
  74957. # pragma map(inflateEnd,"INEND")
  74958. # pragma map(inflateSync,"INSY")
  74959. # pragma map(inflateSetDictionary,"INSEDI")
  74960. # pragma map(compressBound,"CMBND")
  74961. # pragma map(inflate_table,"INTABL")
  74962. # pragma map(inflate_fast,"INFA")
  74963. # pragma map(inflate_copyright,"INCOPY")
  74964. #endif
  74965. #endif /* ZCONF_H */
  74966. /*** End of inlined file: zconf.h ***/
  74967. #ifdef __cplusplus
  74968. extern "C" {
  74969. #endif
  74970. #define ZLIB_VERSION "1.2.3"
  74971. #define ZLIB_VERNUM 0x1230
  74972. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  74973. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  74974. struct internal_state;
  74975. typedef struct z_stream_s {
  74976. Bytef *next_in; /* next input byte */
  74977. uInt avail_in; /* number of bytes available at next_in */
  74978. uLong total_in; /* total nb of input bytes read so far */
  74979. Bytef *next_out; /* next output byte should be put there */
  74980. uInt avail_out; /* remaining free space at next_out */
  74981. uLong total_out; /* total nb of bytes output so far */
  74982. char *msg; /* last error message, NULL if no error */
  74983. struct internal_state FAR *state; /* not visible by applications */
  74984. alloc_func zalloc; /* used to allocate the internal state */
  74985. free_func zfree; /* used to free the internal state */
  74986. voidpf opaque; /* private data object passed to zalloc and zfree */
  74987. int data_type; /* best guess about the data type: binary or text */
  74988. uLong adler; /* adler32 value of the uncompressed data */
  74989. uLong reserved; /* reserved for future use */
  74990. } z_stream;
  74991. typedef z_stream FAR *z_streamp;
  74992. typedef struct gz_header_s {
  74993. int text; /* true if compressed data believed to be text */
  74994. uLong time; /* modification time */
  74995. int xflags; /* extra flags (not used when writing a gzip file) */
  74996. int os; /* operating system */
  74997. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  74998. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  74999. uInt extra_max; /* space at extra (only when reading header) */
  75000. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75001. uInt name_max; /* space at name (only when reading header) */
  75002. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75003. uInt comm_max; /* space at comment (only when reading header) */
  75004. int hcrc; /* true if there was or will be a header crc */
  75005. int done; /* true when done reading gzip header (not used
  75006. when writing a gzip file) */
  75007. } gz_header;
  75008. typedef gz_header FAR *gz_headerp;
  75009. #define Z_NO_FLUSH 0
  75010. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75011. #define Z_SYNC_FLUSH 2
  75012. #define Z_FULL_FLUSH 3
  75013. #define Z_FINISH 4
  75014. #define Z_BLOCK 5
  75015. #define Z_OK 0
  75016. #define Z_STREAM_END 1
  75017. #define Z_NEED_DICT 2
  75018. #define Z_ERRNO (-1)
  75019. #define Z_STREAM_ERROR (-2)
  75020. #define Z_DATA_ERROR (-3)
  75021. #define Z_MEM_ERROR (-4)
  75022. #define Z_BUF_ERROR (-5)
  75023. #define Z_VERSION_ERROR (-6)
  75024. #define Z_NO_COMPRESSION 0
  75025. #define Z_BEST_SPEED 1
  75026. #define Z_BEST_COMPRESSION 9
  75027. #define Z_DEFAULT_COMPRESSION (-1)
  75028. #define Z_FILTERED 1
  75029. #define Z_HUFFMAN_ONLY 2
  75030. #define Z_RLE 3
  75031. #define Z_FIXED 4
  75032. #define Z_DEFAULT_STRATEGY 0
  75033. #define Z_BINARY 0
  75034. #define Z_TEXT 1
  75035. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75036. #define Z_UNKNOWN 2
  75037. #define Z_DEFLATED 8
  75038. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75039. #define zlib_version zlibVersion()
  75040. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75041. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75042. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75043. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75044. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75045. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75046. const Bytef *dictionary,
  75047. uInt dictLength));
  75048. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75049. z_streamp source));
  75050. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75051. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75052. int level,
  75053. int strategy));
  75054. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75055. int good_length,
  75056. int max_lazy,
  75057. int nice_length,
  75058. int max_chain));
  75059. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75060. uLong sourceLen));
  75061. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75062. int bits,
  75063. int value));
  75064. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75065. gz_headerp head));
  75066. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75067. const Bytef *dictionary,
  75068. uInt dictLength));
  75069. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75070. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75071. z_streamp source));
  75072. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75073. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75074. int bits,
  75075. int value));
  75076. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75077. gz_headerp head));
  75078. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75079. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75080. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75081. in_func in, void FAR *in_desc,
  75082. out_func out, void FAR *out_desc));
  75083. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75084. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75085. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75086. const Bytef *source, uLong sourceLen));
  75087. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75088. const Bytef *source, uLong sourceLen,
  75089. int level));
  75090. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75091. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75092. const Bytef *source, uLong sourceLen));
  75093. typedef voidp gzFile;
  75094. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75095. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75096. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75097. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75098. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75099. voidpc buf, unsigned len));
  75100. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75101. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75102. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75103. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75104. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75105. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75106. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75107. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75108. z_off_t offset, int whence));
  75109. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75110. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75111. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75112. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75113. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75114. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75115. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75116. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75117. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75118. z_off_t len2));
  75119. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75120. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75121. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75122. const char *version, int stream_size));
  75123. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75124. const char *version, int stream_size));
  75125. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75126. int windowBits, int memLevel,
  75127. int strategy, const char *version,
  75128. int stream_size));
  75129. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75130. const char *version, int stream_size));
  75131. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75132. unsigned char FAR *window,
  75133. const char *version,
  75134. int stream_size));
  75135. #define deflateInit(strm, level) \
  75136. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75137. #define inflateInit(strm) \
  75138. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75139. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75140. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75141. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75142. #define inflateInit2(strm, windowBits) \
  75143. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75144. #define inflateBackInit(strm, windowBits, window) \
  75145. inflateBackInit_((strm), (windowBits), (window), \
  75146. ZLIB_VERSION, sizeof(z_stream))
  75147. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75148. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75149. #endif
  75150. ZEXTERN const char * ZEXPORT zError OF((int));
  75151. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75152. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75153. #ifdef __cplusplus
  75154. }
  75155. #endif
  75156. #endif /* ZLIB_H */
  75157. /*** End of inlined file: zlib.h ***/
  75158. #undef OS_CODE
  75159. #else
  75160. #include <zlib.h>
  75161. #endif
  75162. }
  75163. BEGIN_JUCE_NAMESPACE
  75164. // internal helper object that holds the zlib structures so they don't have to be
  75165. // included publicly.
  75166. class GZIPCompressorHelper
  75167. {
  75168. public:
  75169. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75170. : data (0),
  75171. dataSize (0),
  75172. compLevel (compressionLevel),
  75173. strategy (0),
  75174. setParams (true),
  75175. streamIsValid (false),
  75176. finished (false),
  75177. shouldFinish (false)
  75178. {
  75179. using namespace zlibNamespace;
  75180. zerostruct (stream);
  75181. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75182. nowrap ? -MAX_WBITS : MAX_WBITS,
  75183. 8, strategy) == Z_OK);
  75184. }
  75185. ~GZIPCompressorHelper()
  75186. {
  75187. using namespace zlibNamespace;
  75188. if (streamIsValid)
  75189. deflateEnd (&stream);
  75190. }
  75191. bool needsInput() const throw()
  75192. {
  75193. return dataSize <= 0;
  75194. }
  75195. void setInput (const uint8* const newData, const int size) throw()
  75196. {
  75197. data = newData;
  75198. dataSize = size;
  75199. }
  75200. int doNextBlock (uint8* const dest, const int destSize) throw()
  75201. {
  75202. using namespace zlibNamespace;
  75203. if (streamIsValid)
  75204. {
  75205. stream.next_in = const_cast <uint8*> (data);
  75206. stream.next_out = dest;
  75207. stream.avail_in = dataSize;
  75208. stream.avail_out = destSize;
  75209. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75210. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75211. setParams = false;
  75212. switch (result)
  75213. {
  75214. case Z_STREAM_END:
  75215. finished = true;
  75216. // Deliberate fall-through..
  75217. case Z_OK:
  75218. data += dataSize - stream.avail_in;
  75219. dataSize = stream.avail_in;
  75220. return destSize - stream.avail_out;
  75221. default:
  75222. break;
  75223. }
  75224. }
  75225. return 0;
  75226. }
  75227. private:
  75228. zlibNamespace::z_stream stream;
  75229. const uint8* data;
  75230. int dataSize, compLevel, strategy;
  75231. bool setParams, streamIsValid;
  75232. public:
  75233. bool finished, shouldFinish;
  75234. };
  75235. const int gzipCompBufferSize = 32768;
  75236. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75237. int compressionLevel,
  75238. const bool deleteDestStream,
  75239. const bool noWrap)
  75240. : destStream (destStream_),
  75241. streamToDelete (deleteDestStream ? destStream_ : 0),
  75242. buffer (gzipCompBufferSize)
  75243. {
  75244. if (compressionLevel < 1 || compressionLevel > 9)
  75245. compressionLevel = -1;
  75246. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75247. }
  75248. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75249. {
  75250. flush();
  75251. }
  75252. void GZIPCompressorOutputStream::flush()
  75253. {
  75254. if (! helper->finished)
  75255. {
  75256. helper->shouldFinish = true;
  75257. while (! helper->finished)
  75258. doNextBlock();
  75259. }
  75260. destStream->flush();
  75261. }
  75262. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75263. {
  75264. if (! helper->finished)
  75265. {
  75266. helper->setInput (static_cast <const uint8*> (destBuffer), howMany);
  75267. while (! helper->needsInput())
  75268. {
  75269. if (! doNextBlock())
  75270. return false;
  75271. }
  75272. }
  75273. return true;
  75274. }
  75275. bool GZIPCompressorOutputStream::doNextBlock()
  75276. {
  75277. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75278. if (len > 0)
  75279. return destStream->write (buffer, len);
  75280. else
  75281. return true;
  75282. }
  75283. int64 GZIPCompressorOutputStream::getPosition()
  75284. {
  75285. return destStream->getPosition();
  75286. }
  75287. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75288. {
  75289. jassertfalse // can't do it!
  75290. return false;
  75291. }
  75292. END_JUCE_NAMESPACE
  75293. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75294. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75295. #if JUCE_MSVC
  75296. #pragma warning (push)
  75297. #pragma warning (disable: 4309 4305)
  75298. #endif
  75299. namespace zlibNamespace
  75300. {
  75301. #if JUCE_INCLUDE_ZLIB_CODE
  75302. extern "C"
  75303. {
  75304. #undef OS_CODE
  75305. #undef fdopen
  75306. #define ZLIB_INTERNAL
  75307. #define NO_DUMMY_DECL
  75308. /*** Start of inlined file: adler32.c ***/
  75309. #define ZLIB_INTERNAL
  75310. #define BASE 65521UL /* largest prime smaller than 65536 */
  75311. #define NMAX 5552
  75312. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75313. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75314. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75315. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75316. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75317. #ifdef NO_DIVIDE
  75318. # define MOD(a) \
  75319. do { \
  75320. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75321. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75322. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75323. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75324. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75325. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75326. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75327. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75328. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75329. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75330. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75331. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75332. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75333. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75334. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75335. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75336. if (a >= BASE) a -= BASE; \
  75337. } while (0)
  75338. # define MOD4(a) \
  75339. do { \
  75340. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75341. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75342. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75343. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75344. if (a >= BASE) a -= BASE; \
  75345. } while (0)
  75346. #else
  75347. # define MOD(a) a %= BASE
  75348. # define MOD4(a) a %= BASE
  75349. #endif
  75350. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75351. {
  75352. unsigned long sum2;
  75353. unsigned n;
  75354. sum2 = (adler >> 16) & 0xffff;
  75355. adler &= 0xffff;
  75356. if (len == 1) {
  75357. adler += buf[0];
  75358. if (adler >= BASE)
  75359. adler -= BASE;
  75360. sum2 += adler;
  75361. if (sum2 >= BASE)
  75362. sum2 -= BASE;
  75363. return adler | (sum2 << 16);
  75364. }
  75365. if (buf == Z_NULL)
  75366. return 1L;
  75367. if (len < 16) {
  75368. while (len--) {
  75369. adler += *buf++;
  75370. sum2 += adler;
  75371. }
  75372. if (adler >= BASE)
  75373. adler -= BASE;
  75374. MOD4(sum2); /* only added so many BASE's */
  75375. return adler | (sum2 << 16);
  75376. }
  75377. while (len >= NMAX) {
  75378. len -= NMAX;
  75379. n = NMAX / 16; /* NMAX is divisible by 16 */
  75380. do {
  75381. DO16(buf); /* 16 sums unrolled */
  75382. buf += 16;
  75383. } while (--n);
  75384. MOD(adler);
  75385. MOD(sum2);
  75386. }
  75387. if (len) { /* avoid modulos if none remaining */
  75388. while (len >= 16) {
  75389. len -= 16;
  75390. DO16(buf);
  75391. buf += 16;
  75392. }
  75393. while (len--) {
  75394. adler += *buf++;
  75395. sum2 += adler;
  75396. }
  75397. MOD(adler);
  75398. MOD(sum2);
  75399. }
  75400. return adler | (sum2 << 16);
  75401. }
  75402. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75403. {
  75404. unsigned long sum1;
  75405. unsigned long sum2;
  75406. unsigned rem;
  75407. rem = (unsigned)(len2 % BASE);
  75408. sum1 = adler1 & 0xffff;
  75409. sum2 = rem * sum1;
  75410. MOD(sum2);
  75411. sum1 += (adler2 & 0xffff) + BASE - 1;
  75412. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75413. if (sum1 > BASE) sum1 -= BASE;
  75414. if (sum1 > BASE) sum1 -= BASE;
  75415. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75416. if (sum2 > BASE) sum2 -= BASE;
  75417. return sum1 | (sum2 << 16);
  75418. }
  75419. /*** End of inlined file: adler32.c ***/
  75420. /*** Start of inlined file: compress.c ***/
  75421. #define ZLIB_INTERNAL
  75422. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75423. uLong sourceLen, int level)
  75424. {
  75425. z_stream stream;
  75426. int err;
  75427. stream.next_in = (Bytef*)source;
  75428. stream.avail_in = (uInt)sourceLen;
  75429. #ifdef MAXSEG_64K
  75430. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75431. #endif
  75432. stream.next_out = dest;
  75433. stream.avail_out = (uInt)*destLen;
  75434. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75435. stream.zalloc = (alloc_func)0;
  75436. stream.zfree = (free_func)0;
  75437. stream.opaque = (voidpf)0;
  75438. err = deflateInit(&stream, level);
  75439. if (err != Z_OK) return err;
  75440. err = deflate(&stream, Z_FINISH);
  75441. if (err != Z_STREAM_END) {
  75442. deflateEnd(&stream);
  75443. return err == Z_OK ? Z_BUF_ERROR : err;
  75444. }
  75445. *destLen = stream.total_out;
  75446. err = deflateEnd(&stream);
  75447. return err;
  75448. }
  75449. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75450. {
  75451. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75452. }
  75453. uLong ZEXPORT compressBound (uLong sourceLen)
  75454. {
  75455. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75456. }
  75457. /*** End of inlined file: compress.c ***/
  75458. #undef DO1
  75459. #undef DO8
  75460. /*** Start of inlined file: crc32.c ***/
  75461. #ifdef MAKECRCH
  75462. # include <stdio.h>
  75463. # ifndef DYNAMIC_CRC_TABLE
  75464. # define DYNAMIC_CRC_TABLE
  75465. # endif /* !DYNAMIC_CRC_TABLE */
  75466. #endif /* MAKECRCH */
  75467. /*** Start of inlined file: zutil.h ***/
  75468. #ifndef ZUTIL_H
  75469. #define ZUTIL_H
  75470. #define ZLIB_INTERNAL
  75471. #ifdef STDC
  75472. # ifndef _WIN32_WCE
  75473. # include <stddef.h>
  75474. # endif
  75475. # include <string.h>
  75476. # include <stdlib.h>
  75477. #endif
  75478. #ifdef NO_ERRNO_H
  75479. # ifdef _WIN32_WCE
  75480. # define errno z_errno
  75481. # endif
  75482. extern int errno;
  75483. #else
  75484. # ifndef _WIN32_WCE
  75485. # include <errno.h>
  75486. # endif
  75487. #endif
  75488. #ifndef local
  75489. # define local static
  75490. #endif
  75491. typedef unsigned char uch;
  75492. typedef uch FAR uchf;
  75493. typedef unsigned short ush;
  75494. typedef ush FAR ushf;
  75495. typedef unsigned long ulg;
  75496. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75497. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75498. #define ERR_RETURN(strm,err) \
  75499. return (strm->msg = (char*)ERR_MSG(err), (err))
  75500. #ifndef DEF_WBITS
  75501. # define DEF_WBITS MAX_WBITS
  75502. #endif
  75503. #if MAX_MEM_LEVEL >= 8
  75504. # define DEF_MEM_LEVEL 8
  75505. #else
  75506. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75507. #endif
  75508. #define STORED_BLOCK 0
  75509. #define STATIC_TREES 1
  75510. #define DYN_TREES 2
  75511. #define MIN_MATCH 3
  75512. #define MAX_MATCH 258
  75513. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75514. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75515. # define OS_CODE 0x00
  75516. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75517. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75518. void _Cdecl farfree( void *block );
  75519. void *_Cdecl farmalloc( unsigned long nbytes );
  75520. # else
  75521. # include <alloc.h>
  75522. # endif
  75523. # else /* MSC or DJGPP */
  75524. # include <malloc.h>
  75525. # endif
  75526. #endif
  75527. #ifdef AMIGA
  75528. # define OS_CODE 0x01
  75529. #endif
  75530. #if defined(VAXC) || defined(VMS)
  75531. # define OS_CODE 0x02
  75532. # define F_OPEN(name, mode) \
  75533. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75534. #endif
  75535. #if defined(ATARI) || defined(atarist)
  75536. # define OS_CODE 0x05
  75537. #endif
  75538. #ifdef OS2
  75539. # define OS_CODE 0x06
  75540. # ifdef M_I86
  75541. #include <malloc.h>
  75542. # endif
  75543. #endif
  75544. #if defined(MACOS) || TARGET_OS_MAC
  75545. # define OS_CODE 0x07
  75546. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75547. # include <unix.h> /* for fdopen */
  75548. # else
  75549. # ifndef fdopen
  75550. # define fdopen(fd,mode) NULL /* No fdopen() */
  75551. # endif
  75552. # endif
  75553. #endif
  75554. #ifdef TOPS20
  75555. # define OS_CODE 0x0a
  75556. #endif
  75557. #ifdef WIN32
  75558. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75559. # define OS_CODE 0x0b
  75560. # endif
  75561. #endif
  75562. #ifdef __50SERIES /* Prime/PRIMOS */
  75563. # define OS_CODE 0x0f
  75564. #endif
  75565. #if defined(_BEOS_) || defined(RISCOS)
  75566. # define fdopen(fd,mode) NULL /* No fdopen() */
  75567. #endif
  75568. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75569. # if defined(_WIN32_WCE)
  75570. # define fdopen(fd,mode) NULL /* No fdopen() */
  75571. # ifndef _PTRDIFF_T_DEFINED
  75572. typedef int ptrdiff_t;
  75573. # define _PTRDIFF_T_DEFINED
  75574. # endif
  75575. # else
  75576. # define fdopen(fd,type) _fdopen(fd,type)
  75577. # endif
  75578. #endif
  75579. #ifndef OS_CODE
  75580. # define OS_CODE 0x03 /* assume Unix */
  75581. #endif
  75582. #ifndef F_OPEN
  75583. # define F_OPEN(name, mode) fopen((name), (mode))
  75584. #endif
  75585. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75586. # ifndef HAVE_VSNPRINTF
  75587. # define HAVE_VSNPRINTF
  75588. # endif
  75589. #endif
  75590. #if defined(__CYGWIN__)
  75591. # ifndef HAVE_VSNPRINTF
  75592. # define HAVE_VSNPRINTF
  75593. # endif
  75594. #endif
  75595. #ifndef HAVE_VSNPRINTF
  75596. # ifdef MSDOS
  75597. # define NO_vsnprintf
  75598. # endif
  75599. # ifdef __TURBOC__
  75600. # define NO_vsnprintf
  75601. # endif
  75602. # ifdef WIN32
  75603. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75604. # define vsnprintf _vsnprintf
  75605. # endif
  75606. # endif
  75607. # ifdef __SASC
  75608. # define NO_vsnprintf
  75609. # endif
  75610. #endif
  75611. #ifdef VMS
  75612. # define NO_vsnprintf
  75613. #endif
  75614. #if defined(pyr)
  75615. # define NO_MEMCPY
  75616. #endif
  75617. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75618. # define NO_MEMCPY
  75619. #endif
  75620. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75621. # define HAVE_MEMCPY
  75622. #endif
  75623. #ifdef HAVE_MEMCPY
  75624. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75625. # define zmemcpy _fmemcpy
  75626. # define zmemcmp _fmemcmp
  75627. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75628. # else
  75629. # define zmemcpy memcpy
  75630. # define zmemcmp memcmp
  75631. # define zmemzero(dest, len) memset(dest, 0, len)
  75632. # endif
  75633. #else
  75634. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75635. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75636. extern void zmemzero OF((Bytef* dest, uInt len));
  75637. #endif
  75638. #ifdef DEBUG
  75639. # include <stdio.h>
  75640. extern int z_verbose;
  75641. extern void z_error OF((const char *m));
  75642. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75643. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75644. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75645. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75646. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75647. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75648. #else
  75649. # define Assert(cond,msg)
  75650. # define Trace(x)
  75651. # define Tracev(x)
  75652. # define Tracevv(x)
  75653. # define Tracec(c,x)
  75654. # define Tracecv(c,x)
  75655. #endif
  75656. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75657. void zcfree OF((voidpf opaque, voidpf ptr));
  75658. #define ZALLOC(strm, items, size) \
  75659. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75660. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75661. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75662. #endif /* ZUTIL_H */
  75663. /*** End of inlined file: zutil.h ***/
  75664. /* for STDC and FAR definitions */
  75665. #define local static
  75666. #ifndef NOBYFOUR
  75667. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75668. # include <limits.h>
  75669. # define BYFOUR
  75670. # if (UINT_MAX == 0xffffffffUL)
  75671. typedef unsigned int u4;
  75672. # else
  75673. # if (ULONG_MAX == 0xffffffffUL)
  75674. typedef unsigned long u4;
  75675. # else
  75676. # if (USHRT_MAX == 0xffffffffUL)
  75677. typedef unsigned short u4;
  75678. # else
  75679. # undef BYFOUR /* can't find a four-byte integer type! */
  75680. # endif
  75681. # endif
  75682. # endif
  75683. # endif /* STDC */
  75684. #endif /* !NOBYFOUR */
  75685. #ifdef BYFOUR
  75686. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75687. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75688. local unsigned long crc32_little OF((unsigned long,
  75689. const unsigned char FAR *, unsigned));
  75690. local unsigned long crc32_big OF((unsigned long,
  75691. const unsigned char FAR *, unsigned));
  75692. # define TBLS 8
  75693. #else
  75694. # define TBLS 1
  75695. #endif /* BYFOUR */
  75696. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75697. unsigned long vec));
  75698. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75699. #ifdef DYNAMIC_CRC_TABLE
  75700. local volatile int crc_table_empty = 1;
  75701. local unsigned long FAR crc_table[TBLS][256];
  75702. local void make_crc_table OF((void));
  75703. #ifdef MAKECRCH
  75704. local void write_table OF((FILE *, const unsigned long FAR *));
  75705. #endif /* MAKECRCH */
  75706. local void make_crc_table()
  75707. {
  75708. unsigned long c;
  75709. int n, k;
  75710. unsigned long poly; /* polynomial exclusive-or pattern */
  75711. static volatile int first = 1; /* flag to limit concurrent making */
  75712. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75713. if (first) {
  75714. first = 0;
  75715. poly = 0UL;
  75716. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75717. poly |= 1UL << (31 - p[n]);
  75718. for (n = 0; n < 256; n++) {
  75719. c = (unsigned long)n;
  75720. for (k = 0; k < 8; k++)
  75721. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75722. crc_table[0][n] = c;
  75723. }
  75724. #ifdef BYFOUR
  75725. for (n = 0; n < 256; n++) {
  75726. c = crc_table[0][n];
  75727. crc_table[4][n] = REV(c);
  75728. for (k = 1; k < 4; k++) {
  75729. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75730. crc_table[k][n] = c;
  75731. crc_table[k + 4][n] = REV(c);
  75732. }
  75733. }
  75734. #endif /* BYFOUR */
  75735. crc_table_empty = 0;
  75736. }
  75737. else { /* not first */
  75738. while (crc_table_empty)
  75739. ;
  75740. }
  75741. #ifdef MAKECRCH
  75742. {
  75743. FILE *out;
  75744. out = fopen("crc32.h", "w");
  75745. if (out == NULL) return;
  75746. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75747. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75748. fprintf(out, "local const unsigned long FAR ");
  75749. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75750. write_table(out, crc_table[0]);
  75751. # ifdef BYFOUR
  75752. fprintf(out, "#ifdef BYFOUR\n");
  75753. for (k = 1; k < 8; k++) {
  75754. fprintf(out, " },\n {\n");
  75755. write_table(out, crc_table[k]);
  75756. }
  75757. fprintf(out, "#endif\n");
  75758. # endif /* BYFOUR */
  75759. fprintf(out, " }\n};\n");
  75760. fclose(out);
  75761. }
  75762. #endif /* MAKECRCH */
  75763. }
  75764. #ifdef MAKECRCH
  75765. local void write_table(out, table)
  75766. FILE *out;
  75767. const unsigned long FAR *table;
  75768. {
  75769. int n;
  75770. for (n = 0; n < 256; n++)
  75771. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75772. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75773. }
  75774. #endif /* MAKECRCH */
  75775. #else /* !DYNAMIC_CRC_TABLE */
  75776. /*** Start of inlined file: crc32.h ***/
  75777. local const unsigned long FAR crc_table[TBLS][256] =
  75778. {
  75779. {
  75780. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75781. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75782. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75783. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75784. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75785. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75786. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75787. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75788. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75789. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75790. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75791. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75792. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75793. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75794. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75795. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75796. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75797. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75798. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75799. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75800. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75801. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75802. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75803. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75804. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75805. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75806. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75807. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75808. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75809. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75810. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75811. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75812. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75813. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75814. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75815. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75816. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75817. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75818. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75819. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75820. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75821. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75822. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75823. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75824. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75825. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75826. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75827. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75828. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75829. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75830. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75831. 0x2d02ef8dUL
  75832. #ifdef BYFOUR
  75833. },
  75834. {
  75835. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75836. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75837. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75838. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75839. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75840. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75841. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75842. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75843. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75844. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75845. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75846. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75847. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75848. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75849. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75850. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75851. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75852. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75853. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75854. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75855. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75856. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75857. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75858. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75859. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75860. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75861. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75862. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75863. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75864. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75865. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75866. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75867. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75868. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75869. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75870. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75871. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75872. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75873. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75874. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75875. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75876. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75877. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75878. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75879. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75880. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75881. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75882. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75883. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75884. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75885. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75886. 0x9324fd72UL
  75887. },
  75888. {
  75889. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75890. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75891. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75892. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75893. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75894. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75895. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75896. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75897. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75898. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75899. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75900. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75901. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75902. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75903. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75904. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75905. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75906. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75907. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75908. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75909. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75910. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75911. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75912. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75913. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75914. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75915. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75916. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75917. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75918. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75919. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75920. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75921. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75922. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75923. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75924. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75925. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75926. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75927. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75928. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75929. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75930. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  75931. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  75932. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  75933. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  75934. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  75935. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  75936. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  75937. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  75938. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  75939. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  75940. 0xbe9834edUL
  75941. },
  75942. {
  75943. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  75944. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  75945. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  75946. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  75947. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  75948. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  75949. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  75950. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  75951. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  75952. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  75953. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  75954. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  75955. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  75956. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  75957. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  75958. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  75959. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  75960. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  75961. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  75962. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  75963. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  75964. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  75965. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  75966. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  75967. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  75968. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  75969. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  75970. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  75971. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  75972. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  75973. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  75974. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  75975. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  75976. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  75977. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  75978. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  75979. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  75980. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  75981. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  75982. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  75983. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  75984. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  75985. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  75986. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  75987. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  75988. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  75989. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  75990. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  75991. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  75992. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  75993. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  75994. 0xde0506f1UL
  75995. },
  75996. {
  75997. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  75998. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  75999. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76000. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76001. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76002. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76003. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76004. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76005. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76006. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76007. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76008. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76009. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76010. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76011. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76012. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76013. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76014. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76015. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76016. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76017. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76018. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76019. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76020. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76021. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76022. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76023. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76024. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76025. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76026. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76027. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76028. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76029. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76030. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76031. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76032. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76033. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76034. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76035. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76036. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76037. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76038. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76039. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76040. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76041. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76042. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76043. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76044. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76045. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76046. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76047. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76048. 0x8def022dUL
  76049. },
  76050. {
  76051. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76052. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76053. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76054. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76055. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76056. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76057. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76058. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76059. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76060. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76061. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76062. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76063. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76064. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76065. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76066. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76067. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76068. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76069. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76070. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76071. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76072. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76073. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76074. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76075. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76076. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76077. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76078. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76079. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76080. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76081. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76082. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76083. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76084. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76085. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76086. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76087. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76088. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76089. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76090. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76091. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76092. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76093. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76094. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76095. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76096. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76097. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76098. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76099. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76100. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76101. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76102. 0x72fd2493UL
  76103. },
  76104. {
  76105. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76106. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76107. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76108. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76109. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76110. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76111. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76112. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76113. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76114. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76115. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76116. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76117. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76118. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76119. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76120. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76121. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76122. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76123. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76124. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76125. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76126. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76127. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76128. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76129. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76130. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76131. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76132. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76133. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76134. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76135. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76136. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76137. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76138. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76139. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76140. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76141. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76142. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76143. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76144. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76145. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76146. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76147. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76148. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76149. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76150. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76151. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76152. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76153. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76154. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76155. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76156. 0xed3498beUL
  76157. },
  76158. {
  76159. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76160. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76161. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76162. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76163. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76164. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76165. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76166. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76167. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76168. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76169. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76170. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76171. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76172. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76173. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76174. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76175. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76176. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76177. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76178. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76179. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76180. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76181. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76182. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76183. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76184. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76185. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76186. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76187. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76188. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76189. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76190. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76191. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76192. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76193. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76194. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76195. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76196. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76197. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76198. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76199. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76200. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76201. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76202. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76203. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76204. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76205. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76206. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76207. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76208. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76209. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76210. 0xf10605deUL
  76211. #endif
  76212. }
  76213. };
  76214. /*** End of inlined file: crc32.h ***/
  76215. #endif /* DYNAMIC_CRC_TABLE */
  76216. const unsigned long FAR * ZEXPORT get_crc_table()
  76217. {
  76218. #ifdef DYNAMIC_CRC_TABLE
  76219. if (crc_table_empty)
  76220. make_crc_table();
  76221. #endif /* DYNAMIC_CRC_TABLE */
  76222. return (const unsigned long FAR *)crc_table;
  76223. }
  76224. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76225. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76226. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76227. {
  76228. if (buf == Z_NULL) return 0UL;
  76229. #ifdef DYNAMIC_CRC_TABLE
  76230. if (crc_table_empty)
  76231. make_crc_table();
  76232. #endif /* DYNAMIC_CRC_TABLE */
  76233. #ifdef BYFOUR
  76234. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76235. u4 endian;
  76236. endian = 1;
  76237. if (*((unsigned char *)(&endian)))
  76238. return crc32_little(crc, buf, len);
  76239. else
  76240. return crc32_big(crc, buf, len);
  76241. }
  76242. #endif /* BYFOUR */
  76243. crc = crc ^ 0xffffffffUL;
  76244. while (len >= 8) {
  76245. DO8;
  76246. len -= 8;
  76247. }
  76248. if (len) do {
  76249. DO1;
  76250. } while (--len);
  76251. return crc ^ 0xffffffffUL;
  76252. }
  76253. #ifdef BYFOUR
  76254. #define DOLIT4 c ^= *buf4++; \
  76255. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76256. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76257. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76258. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76259. {
  76260. register u4 c;
  76261. register const u4 FAR *buf4;
  76262. c = (u4)crc;
  76263. c = ~c;
  76264. while (len && ((ptrdiff_t)buf & 3)) {
  76265. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76266. len--;
  76267. }
  76268. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76269. while (len >= 32) {
  76270. DOLIT32;
  76271. len -= 32;
  76272. }
  76273. while (len >= 4) {
  76274. DOLIT4;
  76275. len -= 4;
  76276. }
  76277. buf = (const unsigned char FAR *)buf4;
  76278. if (len) do {
  76279. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76280. } while (--len);
  76281. c = ~c;
  76282. return (unsigned long)c;
  76283. }
  76284. #define DOBIG4 c ^= *++buf4; \
  76285. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76286. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76287. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76288. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76289. {
  76290. register u4 c;
  76291. register const u4 FAR *buf4;
  76292. c = REV((u4)crc);
  76293. c = ~c;
  76294. while (len && ((ptrdiff_t)buf & 3)) {
  76295. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76296. len--;
  76297. }
  76298. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76299. buf4--;
  76300. while (len >= 32) {
  76301. DOBIG32;
  76302. len -= 32;
  76303. }
  76304. while (len >= 4) {
  76305. DOBIG4;
  76306. len -= 4;
  76307. }
  76308. buf4++;
  76309. buf = (const unsigned char FAR *)buf4;
  76310. if (len) do {
  76311. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76312. } while (--len);
  76313. c = ~c;
  76314. return (unsigned long)(REV(c));
  76315. }
  76316. #endif /* BYFOUR */
  76317. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76318. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76319. {
  76320. unsigned long sum;
  76321. sum = 0;
  76322. while (vec) {
  76323. if (vec & 1)
  76324. sum ^= *mat;
  76325. vec >>= 1;
  76326. mat++;
  76327. }
  76328. return sum;
  76329. }
  76330. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76331. {
  76332. int n;
  76333. for (n = 0; n < GF2_DIM; n++)
  76334. square[n] = gf2_matrix_times(mat, mat[n]);
  76335. }
  76336. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76337. {
  76338. int n;
  76339. unsigned long row;
  76340. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76341. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76342. if (len2 == 0)
  76343. return crc1;
  76344. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76345. row = 1;
  76346. for (n = 1; n < GF2_DIM; n++) {
  76347. odd[n] = row;
  76348. row <<= 1;
  76349. }
  76350. gf2_matrix_square(even, odd);
  76351. gf2_matrix_square(odd, even);
  76352. do {
  76353. gf2_matrix_square(even, odd);
  76354. if (len2 & 1)
  76355. crc1 = gf2_matrix_times(even, crc1);
  76356. len2 >>= 1;
  76357. if (len2 == 0)
  76358. break;
  76359. gf2_matrix_square(odd, even);
  76360. if (len2 & 1)
  76361. crc1 = gf2_matrix_times(odd, crc1);
  76362. len2 >>= 1;
  76363. } while (len2 != 0);
  76364. crc1 ^= crc2;
  76365. return crc1;
  76366. }
  76367. /*** End of inlined file: crc32.c ***/
  76368. /*** Start of inlined file: deflate.c ***/
  76369. /*** Start of inlined file: deflate.h ***/
  76370. #ifndef DEFLATE_H
  76371. #define DEFLATE_H
  76372. #ifndef NO_GZIP
  76373. # define GZIP
  76374. #endif
  76375. #define NO_DUMMY_DECL
  76376. #define LENGTH_CODES 29
  76377. #define LITERALS 256
  76378. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76379. #define D_CODES 30
  76380. #define BL_CODES 19
  76381. #define HEAP_SIZE (2*L_CODES+1)
  76382. #define MAX_BITS 15
  76383. #define INIT_STATE 42
  76384. #define EXTRA_STATE 69
  76385. #define NAME_STATE 73
  76386. #define COMMENT_STATE 91
  76387. #define HCRC_STATE 103
  76388. #define BUSY_STATE 113
  76389. #define FINISH_STATE 666
  76390. typedef struct ct_data_s {
  76391. union {
  76392. ush freq; /* frequency count */
  76393. ush code; /* bit string */
  76394. } fc;
  76395. union {
  76396. ush dad; /* father node in Huffman tree */
  76397. ush len; /* length of bit string */
  76398. } dl;
  76399. } FAR ct_data;
  76400. #define Freq fc.freq
  76401. #define Code fc.code
  76402. #define Dad dl.dad
  76403. #define Len dl.len
  76404. typedef struct static_tree_desc_s static_tree_desc;
  76405. typedef struct tree_desc_s {
  76406. ct_data *dyn_tree; /* the dynamic tree */
  76407. int max_code; /* largest code with non zero frequency */
  76408. static_tree_desc *stat_desc; /* the corresponding static tree */
  76409. } FAR tree_desc;
  76410. typedef ush Pos;
  76411. typedef Pos FAR Posf;
  76412. typedef unsigned IPos;
  76413. typedef struct internal_state {
  76414. z_streamp strm; /* pointer back to this zlib stream */
  76415. int status; /* as the name implies */
  76416. Bytef *pending_buf; /* output still pending */
  76417. ulg pending_buf_size; /* size of pending_buf */
  76418. Bytef *pending_out; /* next pending byte to output to the stream */
  76419. uInt pending; /* nb of bytes in the pending buffer */
  76420. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76421. gz_headerp gzhead; /* gzip header information to write */
  76422. uInt gzindex; /* where in extra, name, or comment */
  76423. Byte method; /* STORED (for zip only) or DEFLATED */
  76424. int last_flush; /* value of flush param for previous deflate call */
  76425. uInt w_size; /* LZ77 window size (32K by default) */
  76426. uInt w_bits; /* log2(w_size) (8..16) */
  76427. uInt w_mask; /* w_size - 1 */
  76428. Bytef *window;
  76429. ulg window_size;
  76430. Posf *prev;
  76431. Posf *head; /* Heads of the hash chains or NIL. */
  76432. uInt ins_h; /* hash index of string to be inserted */
  76433. uInt hash_size; /* number of elements in hash table */
  76434. uInt hash_bits; /* log2(hash_size) */
  76435. uInt hash_mask; /* hash_size-1 */
  76436. uInt hash_shift;
  76437. long block_start;
  76438. uInt match_length; /* length of best match */
  76439. IPos prev_match; /* previous match */
  76440. int match_available; /* set if previous match exists */
  76441. uInt strstart; /* start of string to insert */
  76442. uInt match_start; /* start of matching string */
  76443. uInt lookahead; /* number of valid bytes ahead in window */
  76444. uInt prev_length;
  76445. uInt max_chain_length;
  76446. uInt max_lazy_match;
  76447. # define max_insert_length max_lazy_match
  76448. int level; /* compression level (1..9) */
  76449. int strategy; /* favor or force Huffman coding*/
  76450. uInt good_match;
  76451. int nice_match; /* Stop searching when current match exceeds this */
  76452. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76453. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76454. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76455. struct tree_desc_s l_desc; /* desc. for literal tree */
  76456. struct tree_desc_s d_desc; /* desc. for distance tree */
  76457. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76458. ush bl_count[MAX_BITS+1];
  76459. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76460. int heap_len; /* number of elements in the heap */
  76461. int heap_max; /* element of largest frequency */
  76462. uch depth[2*L_CODES+1];
  76463. uchf *l_buf; /* buffer for literals or lengths */
  76464. uInt lit_bufsize;
  76465. uInt last_lit; /* running index in l_buf */
  76466. ushf *d_buf;
  76467. ulg opt_len; /* bit length of current block with optimal trees */
  76468. ulg static_len; /* bit length of current block with static trees */
  76469. uInt matches; /* number of string matches in current block */
  76470. int last_eob_len; /* bit length of EOB code for last block */
  76471. #ifdef DEBUG
  76472. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76473. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76474. #endif
  76475. ush bi_buf;
  76476. int bi_valid;
  76477. } FAR deflate_state;
  76478. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76479. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76480. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76481. void _tr_init OF((deflate_state *s));
  76482. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76483. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76484. int eof));
  76485. void _tr_align OF((deflate_state *s));
  76486. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76487. int eof));
  76488. #define d_code(dist) \
  76489. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76490. #ifndef DEBUG
  76491. #if defined(GEN_TREES_H) || !defined(STDC)
  76492. extern uch _length_code[];
  76493. extern uch _dist_code[];
  76494. #else
  76495. extern const uch _length_code[];
  76496. extern const uch _dist_code[];
  76497. #endif
  76498. # define _tr_tally_lit(s, c, flush) \
  76499. { uch cc = (c); \
  76500. s->d_buf[s->last_lit] = 0; \
  76501. s->l_buf[s->last_lit++] = cc; \
  76502. s->dyn_ltree[cc].Freq++; \
  76503. flush = (s->last_lit == s->lit_bufsize-1); \
  76504. }
  76505. # define _tr_tally_dist(s, distance, length, flush) \
  76506. { uch len = (length); \
  76507. ush dist = (distance); \
  76508. s->d_buf[s->last_lit] = dist; \
  76509. s->l_buf[s->last_lit++] = len; \
  76510. dist--; \
  76511. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76512. s->dyn_dtree[d_code(dist)].Freq++; \
  76513. flush = (s->last_lit == s->lit_bufsize-1); \
  76514. }
  76515. #else
  76516. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76517. # define _tr_tally_dist(s, distance, length, flush) \
  76518. flush = _tr_tally(s, distance, length)
  76519. #endif
  76520. #endif /* DEFLATE_H */
  76521. /*** End of inlined file: deflate.h ***/
  76522. const char deflate_copyright[] =
  76523. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76524. typedef enum {
  76525. need_more, /* block not completed, need more input or more output */
  76526. block_done, /* block flush performed */
  76527. finish_started, /* finish started, need only more output at next deflate */
  76528. finish_done /* finish done, accept no more input or output */
  76529. } block_state;
  76530. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76531. local void fill_window OF((deflate_state *s));
  76532. local block_state deflate_stored OF((deflate_state *s, int flush));
  76533. local block_state deflate_fast OF((deflate_state *s, int flush));
  76534. #ifndef FASTEST
  76535. local block_state deflate_slow OF((deflate_state *s, int flush));
  76536. #endif
  76537. local void lm_init OF((deflate_state *s));
  76538. local void putShortMSB OF((deflate_state *s, uInt b));
  76539. local void flush_pending OF((z_streamp strm));
  76540. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76541. #ifndef FASTEST
  76542. #ifdef ASMV
  76543. void match_init OF((void)); /* asm code initialization */
  76544. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76545. #else
  76546. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76547. #endif
  76548. #endif
  76549. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76550. #ifdef DEBUG
  76551. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76552. int length));
  76553. #endif
  76554. #define NIL 0
  76555. #ifndef TOO_FAR
  76556. # define TOO_FAR 4096
  76557. #endif
  76558. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76559. typedef struct config_s {
  76560. ush good_length; /* reduce lazy search above this match length */
  76561. ush max_lazy; /* do not perform lazy search above this match length */
  76562. ush nice_length; /* quit search above this match length */
  76563. ush max_chain;
  76564. compress_func func;
  76565. } config;
  76566. #ifdef FASTEST
  76567. local const config configuration_table[2] = {
  76568. {0, 0, 0, 0, deflate_stored}, /* store only */
  76569. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76570. #else
  76571. local const config configuration_table[10] = {
  76572. {0, 0, 0, 0, deflate_stored}, /* store only */
  76573. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76574. {4, 5, 16, 8, deflate_fast},
  76575. {4, 6, 32, 32, deflate_fast},
  76576. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76577. {8, 16, 32, 32, deflate_slow},
  76578. {8, 16, 128, 128, deflate_slow},
  76579. {8, 32, 128, 256, deflate_slow},
  76580. {32, 128, 258, 1024, deflate_slow},
  76581. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76582. #endif
  76583. #define EQUAL 0
  76584. #ifndef NO_DUMMY_DECL
  76585. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76586. #endif
  76587. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76588. #ifdef FASTEST
  76589. #define INSERT_STRING(s, str, match_head) \
  76590. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76591. match_head = s->head[s->ins_h], \
  76592. s->head[s->ins_h] = (Pos)(str))
  76593. #else
  76594. #define INSERT_STRING(s, str, match_head) \
  76595. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76596. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76597. s->head[s->ins_h] = (Pos)(str))
  76598. #endif
  76599. #define CLEAR_HASH(s) \
  76600. s->head[s->hash_size-1] = NIL; \
  76601. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76602. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76603. {
  76604. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76605. Z_DEFAULT_STRATEGY, version, stream_size);
  76606. }
  76607. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76608. {
  76609. deflate_state *s;
  76610. int wrap = 1;
  76611. static const char my_version[] = ZLIB_VERSION;
  76612. ushf *overlay;
  76613. if (version == Z_NULL || version[0] != my_version[0] ||
  76614. stream_size != sizeof(z_stream)) {
  76615. return Z_VERSION_ERROR;
  76616. }
  76617. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76618. strm->msg = Z_NULL;
  76619. if (strm->zalloc == (alloc_func)0) {
  76620. strm->zalloc = zcalloc;
  76621. strm->opaque = (voidpf)0;
  76622. }
  76623. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76624. #ifdef FASTEST
  76625. if (level != 0) level = 1;
  76626. #else
  76627. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76628. #endif
  76629. if (windowBits < 0) { /* suppress zlib wrapper */
  76630. wrap = 0;
  76631. windowBits = -windowBits;
  76632. }
  76633. #ifdef GZIP
  76634. else if (windowBits > 15) {
  76635. wrap = 2; /* write gzip wrapper instead */
  76636. windowBits -= 16;
  76637. }
  76638. #endif
  76639. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76640. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76641. strategy < 0 || strategy > Z_FIXED) {
  76642. return Z_STREAM_ERROR;
  76643. }
  76644. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76645. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76646. if (s == Z_NULL) return Z_MEM_ERROR;
  76647. strm->state = (struct internal_state FAR *)s;
  76648. s->strm = strm;
  76649. s->wrap = wrap;
  76650. s->gzhead = Z_NULL;
  76651. s->w_bits = windowBits;
  76652. s->w_size = 1 << s->w_bits;
  76653. s->w_mask = s->w_size - 1;
  76654. s->hash_bits = memLevel + 7;
  76655. s->hash_size = 1 << s->hash_bits;
  76656. s->hash_mask = s->hash_size - 1;
  76657. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76658. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76659. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76660. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76661. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76662. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76663. s->pending_buf = (uchf *) overlay;
  76664. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76665. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76666. s->pending_buf == Z_NULL) {
  76667. s->status = FINISH_STATE;
  76668. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76669. deflateEnd (strm);
  76670. return Z_MEM_ERROR;
  76671. }
  76672. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76673. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76674. s->level = level;
  76675. s->strategy = strategy;
  76676. s->method = (Byte)method;
  76677. return deflateReset(strm);
  76678. }
  76679. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76680. {
  76681. deflate_state *s;
  76682. uInt length = dictLength;
  76683. uInt n;
  76684. IPos hash_head = 0;
  76685. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76686. strm->state->wrap == 2 ||
  76687. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76688. return Z_STREAM_ERROR;
  76689. s = strm->state;
  76690. if (s->wrap)
  76691. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76692. if (length < MIN_MATCH) return Z_OK;
  76693. if (length > MAX_DIST(s)) {
  76694. length = MAX_DIST(s);
  76695. dictionary += dictLength - length; /* use the tail of the dictionary */
  76696. }
  76697. zmemcpy(s->window, dictionary, length);
  76698. s->strstart = length;
  76699. s->block_start = (long)length;
  76700. s->ins_h = s->window[0];
  76701. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76702. for (n = 0; n <= length - MIN_MATCH; n++) {
  76703. INSERT_STRING(s, n, hash_head);
  76704. }
  76705. if (hash_head) hash_head = 0; /* to make compiler happy */
  76706. return Z_OK;
  76707. }
  76708. int ZEXPORT deflateReset (z_streamp strm)
  76709. {
  76710. deflate_state *s;
  76711. if (strm == Z_NULL || strm->state == Z_NULL ||
  76712. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76713. return Z_STREAM_ERROR;
  76714. }
  76715. strm->total_in = strm->total_out = 0;
  76716. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76717. strm->data_type = Z_UNKNOWN;
  76718. s = (deflate_state *)strm->state;
  76719. s->pending = 0;
  76720. s->pending_out = s->pending_buf;
  76721. if (s->wrap < 0) {
  76722. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76723. }
  76724. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76725. strm->adler =
  76726. #ifdef GZIP
  76727. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76728. #endif
  76729. adler32(0L, Z_NULL, 0);
  76730. s->last_flush = Z_NO_FLUSH;
  76731. _tr_init(s);
  76732. lm_init(s);
  76733. return Z_OK;
  76734. }
  76735. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76736. {
  76737. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76738. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76739. strm->state->gzhead = head;
  76740. return Z_OK;
  76741. }
  76742. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76743. {
  76744. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76745. strm->state->bi_valid = bits;
  76746. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76747. return Z_OK;
  76748. }
  76749. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76750. {
  76751. deflate_state *s;
  76752. compress_func func;
  76753. int err = Z_OK;
  76754. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76755. s = strm->state;
  76756. #ifdef FASTEST
  76757. if (level != 0) level = 1;
  76758. #else
  76759. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76760. #endif
  76761. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76762. return Z_STREAM_ERROR;
  76763. }
  76764. func = configuration_table[s->level].func;
  76765. if (func != configuration_table[level].func && strm->total_in != 0) {
  76766. err = deflate(strm, Z_PARTIAL_FLUSH);
  76767. }
  76768. if (s->level != level) {
  76769. s->level = level;
  76770. s->max_lazy_match = configuration_table[level].max_lazy;
  76771. s->good_match = configuration_table[level].good_length;
  76772. s->nice_match = configuration_table[level].nice_length;
  76773. s->max_chain_length = configuration_table[level].max_chain;
  76774. }
  76775. s->strategy = strategy;
  76776. return err;
  76777. }
  76778. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76779. {
  76780. deflate_state *s;
  76781. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76782. s = strm->state;
  76783. s->good_match = good_length;
  76784. s->max_lazy_match = max_lazy;
  76785. s->nice_match = nice_length;
  76786. s->max_chain_length = max_chain;
  76787. return Z_OK;
  76788. }
  76789. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76790. {
  76791. deflate_state *s;
  76792. uLong destLen;
  76793. destLen = sourceLen +
  76794. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76795. if (strm == Z_NULL || strm->state == Z_NULL)
  76796. return destLen;
  76797. s = strm->state;
  76798. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76799. return destLen;
  76800. return compressBound(sourceLen);
  76801. }
  76802. local void putShortMSB (deflate_state *s, uInt b)
  76803. {
  76804. put_byte(s, (Byte)(b >> 8));
  76805. put_byte(s, (Byte)(b & 0xff));
  76806. }
  76807. local void flush_pending (z_streamp strm)
  76808. {
  76809. unsigned len = strm->state->pending;
  76810. if (len > strm->avail_out) len = strm->avail_out;
  76811. if (len == 0) return;
  76812. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76813. strm->next_out += len;
  76814. strm->state->pending_out += len;
  76815. strm->total_out += len;
  76816. strm->avail_out -= len;
  76817. strm->state->pending -= len;
  76818. if (strm->state->pending == 0) {
  76819. strm->state->pending_out = strm->state->pending_buf;
  76820. }
  76821. }
  76822. int ZEXPORT deflate (z_streamp strm, int flush)
  76823. {
  76824. int old_flush; /* value of flush param for previous deflate call */
  76825. deflate_state *s;
  76826. if (strm == Z_NULL || strm->state == Z_NULL ||
  76827. flush > Z_FINISH || flush < 0) {
  76828. return Z_STREAM_ERROR;
  76829. }
  76830. s = strm->state;
  76831. if (strm->next_out == Z_NULL ||
  76832. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76833. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76834. ERR_RETURN(strm, Z_STREAM_ERROR);
  76835. }
  76836. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76837. s->strm = strm; /* just in case */
  76838. old_flush = s->last_flush;
  76839. s->last_flush = flush;
  76840. if (s->status == INIT_STATE) {
  76841. #ifdef GZIP
  76842. if (s->wrap == 2) {
  76843. strm->adler = crc32(0L, Z_NULL, 0);
  76844. put_byte(s, 31);
  76845. put_byte(s, 139);
  76846. put_byte(s, 8);
  76847. if (s->gzhead == NULL) {
  76848. put_byte(s, 0);
  76849. put_byte(s, 0);
  76850. put_byte(s, 0);
  76851. put_byte(s, 0);
  76852. put_byte(s, 0);
  76853. put_byte(s, s->level == 9 ? 2 :
  76854. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76855. 4 : 0));
  76856. put_byte(s, OS_CODE);
  76857. s->status = BUSY_STATE;
  76858. }
  76859. else {
  76860. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76861. (s->gzhead->hcrc ? 2 : 0) +
  76862. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76863. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76864. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76865. );
  76866. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76867. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76868. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76869. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76870. put_byte(s, s->level == 9 ? 2 :
  76871. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76872. 4 : 0));
  76873. put_byte(s, s->gzhead->os & 0xff);
  76874. if (s->gzhead->extra != NULL) {
  76875. put_byte(s, s->gzhead->extra_len & 0xff);
  76876. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76877. }
  76878. if (s->gzhead->hcrc)
  76879. strm->adler = crc32(strm->adler, s->pending_buf,
  76880. s->pending);
  76881. s->gzindex = 0;
  76882. s->status = EXTRA_STATE;
  76883. }
  76884. }
  76885. else
  76886. #endif
  76887. {
  76888. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76889. uInt level_flags;
  76890. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76891. level_flags = 0;
  76892. else if (s->level < 6)
  76893. level_flags = 1;
  76894. else if (s->level == 6)
  76895. level_flags = 2;
  76896. else
  76897. level_flags = 3;
  76898. header |= (level_flags << 6);
  76899. if (s->strstart != 0) header |= PRESET_DICT;
  76900. header += 31 - (header % 31);
  76901. s->status = BUSY_STATE;
  76902. putShortMSB(s, header);
  76903. if (s->strstart != 0) {
  76904. putShortMSB(s, (uInt)(strm->adler >> 16));
  76905. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76906. }
  76907. strm->adler = adler32(0L, Z_NULL, 0);
  76908. }
  76909. }
  76910. #ifdef GZIP
  76911. if (s->status == EXTRA_STATE) {
  76912. if (s->gzhead->extra != NULL) {
  76913. uInt beg = s->pending; /* start of bytes to update crc */
  76914. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76915. if (s->pending == s->pending_buf_size) {
  76916. if (s->gzhead->hcrc && s->pending > beg)
  76917. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76918. s->pending - beg);
  76919. flush_pending(strm);
  76920. beg = s->pending;
  76921. if (s->pending == s->pending_buf_size)
  76922. break;
  76923. }
  76924. put_byte(s, s->gzhead->extra[s->gzindex]);
  76925. s->gzindex++;
  76926. }
  76927. if (s->gzhead->hcrc && s->pending > beg)
  76928. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76929. s->pending - beg);
  76930. if (s->gzindex == s->gzhead->extra_len) {
  76931. s->gzindex = 0;
  76932. s->status = NAME_STATE;
  76933. }
  76934. }
  76935. else
  76936. s->status = NAME_STATE;
  76937. }
  76938. if (s->status == NAME_STATE) {
  76939. if (s->gzhead->name != NULL) {
  76940. uInt beg = s->pending; /* start of bytes to update crc */
  76941. int val;
  76942. do {
  76943. if (s->pending == s->pending_buf_size) {
  76944. if (s->gzhead->hcrc && s->pending > beg)
  76945. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76946. s->pending - beg);
  76947. flush_pending(strm);
  76948. beg = s->pending;
  76949. if (s->pending == s->pending_buf_size) {
  76950. val = 1;
  76951. break;
  76952. }
  76953. }
  76954. val = s->gzhead->name[s->gzindex++];
  76955. put_byte(s, val);
  76956. } while (val != 0);
  76957. if (s->gzhead->hcrc && s->pending > beg)
  76958. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76959. s->pending - beg);
  76960. if (val == 0) {
  76961. s->gzindex = 0;
  76962. s->status = COMMENT_STATE;
  76963. }
  76964. }
  76965. else
  76966. s->status = COMMENT_STATE;
  76967. }
  76968. if (s->status == COMMENT_STATE) {
  76969. if (s->gzhead->comment != NULL) {
  76970. uInt beg = s->pending; /* start of bytes to update crc */
  76971. int val;
  76972. do {
  76973. if (s->pending == s->pending_buf_size) {
  76974. if (s->gzhead->hcrc && s->pending > beg)
  76975. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76976. s->pending - beg);
  76977. flush_pending(strm);
  76978. beg = s->pending;
  76979. if (s->pending == s->pending_buf_size) {
  76980. val = 1;
  76981. break;
  76982. }
  76983. }
  76984. val = s->gzhead->comment[s->gzindex++];
  76985. put_byte(s, val);
  76986. } while (val != 0);
  76987. if (s->gzhead->hcrc && s->pending > beg)
  76988. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76989. s->pending - beg);
  76990. if (val == 0)
  76991. s->status = HCRC_STATE;
  76992. }
  76993. else
  76994. s->status = HCRC_STATE;
  76995. }
  76996. if (s->status == HCRC_STATE) {
  76997. if (s->gzhead->hcrc) {
  76998. if (s->pending + 2 > s->pending_buf_size)
  76999. flush_pending(strm);
  77000. if (s->pending + 2 <= s->pending_buf_size) {
  77001. put_byte(s, (Byte)(strm->adler & 0xff));
  77002. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77003. strm->adler = crc32(0L, Z_NULL, 0);
  77004. s->status = BUSY_STATE;
  77005. }
  77006. }
  77007. else
  77008. s->status = BUSY_STATE;
  77009. }
  77010. #endif
  77011. if (s->pending != 0) {
  77012. flush_pending(strm);
  77013. if (strm->avail_out == 0) {
  77014. s->last_flush = -1;
  77015. return Z_OK;
  77016. }
  77017. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77018. flush != Z_FINISH) {
  77019. ERR_RETURN(strm, Z_BUF_ERROR);
  77020. }
  77021. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77022. ERR_RETURN(strm, Z_BUF_ERROR);
  77023. }
  77024. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77025. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77026. block_state bstate;
  77027. bstate = (*(configuration_table[s->level].func))(s, flush);
  77028. if (bstate == finish_started || bstate == finish_done) {
  77029. s->status = FINISH_STATE;
  77030. }
  77031. if (bstate == need_more || bstate == finish_started) {
  77032. if (strm->avail_out == 0) {
  77033. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77034. }
  77035. return Z_OK;
  77036. }
  77037. if (bstate == block_done) {
  77038. if (flush == Z_PARTIAL_FLUSH) {
  77039. _tr_align(s);
  77040. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77041. _tr_stored_block(s, (char*)0, 0L, 0);
  77042. if (flush == Z_FULL_FLUSH) {
  77043. CLEAR_HASH(s); /* forget history */
  77044. }
  77045. }
  77046. flush_pending(strm);
  77047. if (strm->avail_out == 0) {
  77048. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77049. return Z_OK;
  77050. }
  77051. }
  77052. }
  77053. Assert(strm->avail_out > 0, "bug2");
  77054. if (flush != Z_FINISH) return Z_OK;
  77055. if (s->wrap <= 0) return Z_STREAM_END;
  77056. #ifdef GZIP
  77057. if (s->wrap == 2) {
  77058. put_byte(s, (Byte)(strm->adler & 0xff));
  77059. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77060. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77061. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77062. put_byte(s, (Byte)(strm->total_in & 0xff));
  77063. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77064. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77065. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77066. }
  77067. else
  77068. #endif
  77069. {
  77070. putShortMSB(s, (uInt)(strm->adler >> 16));
  77071. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77072. }
  77073. flush_pending(strm);
  77074. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77075. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77076. }
  77077. int ZEXPORT deflateEnd (z_streamp strm)
  77078. {
  77079. int status;
  77080. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77081. status = strm->state->status;
  77082. if (status != INIT_STATE &&
  77083. status != EXTRA_STATE &&
  77084. status != NAME_STATE &&
  77085. status != COMMENT_STATE &&
  77086. status != HCRC_STATE &&
  77087. status != BUSY_STATE &&
  77088. status != FINISH_STATE) {
  77089. return Z_STREAM_ERROR;
  77090. }
  77091. TRY_FREE(strm, strm->state->pending_buf);
  77092. TRY_FREE(strm, strm->state->head);
  77093. TRY_FREE(strm, strm->state->prev);
  77094. TRY_FREE(strm, strm->state->window);
  77095. ZFREE(strm, strm->state);
  77096. strm->state = Z_NULL;
  77097. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77098. }
  77099. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77100. {
  77101. #ifdef MAXSEG_64K
  77102. return Z_STREAM_ERROR;
  77103. #else
  77104. deflate_state *ds;
  77105. deflate_state *ss;
  77106. ushf *overlay;
  77107. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77108. return Z_STREAM_ERROR;
  77109. }
  77110. ss = source->state;
  77111. zmemcpy(dest, source, sizeof(z_stream));
  77112. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77113. if (ds == Z_NULL) return Z_MEM_ERROR;
  77114. dest->state = (struct internal_state FAR *) ds;
  77115. zmemcpy(ds, ss, sizeof(deflate_state));
  77116. ds->strm = dest;
  77117. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77118. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77119. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77120. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77121. ds->pending_buf = (uchf *) overlay;
  77122. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77123. ds->pending_buf == Z_NULL) {
  77124. deflateEnd (dest);
  77125. return Z_MEM_ERROR;
  77126. }
  77127. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77128. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77129. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77130. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77131. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77132. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77133. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77134. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77135. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77136. ds->bl_desc.dyn_tree = ds->bl_tree;
  77137. return Z_OK;
  77138. #endif /* MAXSEG_64K */
  77139. }
  77140. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77141. {
  77142. unsigned len = strm->avail_in;
  77143. if (len > size) len = size;
  77144. if (len == 0) return 0;
  77145. strm->avail_in -= len;
  77146. if (strm->state->wrap == 1) {
  77147. strm->adler = adler32(strm->adler, strm->next_in, len);
  77148. }
  77149. #ifdef GZIP
  77150. else if (strm->state->wrap == 2) {
  77151. strm->adler = crc32(strm->adler, strm->next_in, len);
  77152. }
  77153. #endif
  77154. zmemcpy(buf, strm->next_in, len);
  77155. strm->next_in += len;
  77156. strm->total_in += len;
  77157. return (int)len;
  77158. }
  77159. local void lm_init (deflate_state *s)
  77160. {
  77161. s->window_size = (ulg)2L*s->w_size;
  77162. CLEAR_HASH(s);
  77163. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77164. s->good_match = configuration_table[s->level].good_length;
  77165. s->nice_match = configuration_table[s->level].nice_length;
  77166. s->max_chain_length = configuration_table[s->level].max_chain;
  77167. s->strstart = 0;
  77168. s->block_start = 0L;
  77169. s->lookahead = 0;
  77170. s->match_length = s->prev_length = MIN_MATCH-1;
  77171. s->match_available = 0;
  77172. s->ins_h = 0;
  77173. #ifndef FASTEST
  77174. #ifdef ASMV
  77175. match_init(); /* initialize the asm code */
  77176. #endif
  77177. #endif
  77178. }
  77179. #ifndef FASTEST
  77180. #ifndef ASMV
  77181. local uInt longest_match(deflate_state *s, IPos cur_match)
  77182. {
  77183. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77184. register Bytef *scan = s->window + s->strstart; /* current string */
  77185. register Bytef *match; /* matched string */
  77186. register int len; /* length of current match */
  77187. int best_len = s->prev_length; /* best match length so far */
  77188. int nice_match = s->nice_match; /* stop if match long enough */
  77189. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77190. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77191. Posf *prev = s->prev;
  77192. uInt wmask = s->w_mask;
  77193. #ifdef UNALIGNED_OK
  77194. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77195. register ush scan_start = *(ushf*)scan;
  77196. register ush scan_end = *(ushf*)(scan+best_len-1);
  77197. #else
  77198. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77199. register Byte scan_end1 = scan[best_len-1];
  77200. register Byte scan_end = scan[best_len];
  77201. #endif
  77202. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77203. if (s->prev_length >= s->good_match) {
  77204. chain_length >>= 2;
  77205. }
  77206. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77207. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77208. do {
  77209. Assert(cur_match < s->strstart, "no future");
  77210. match = s->window + cur_match;
  77211. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77212. if (*(ushf*)(match+best_len-1) != scan_end ||
  77213. *(ushf*)match != scan_start) continue;
  77214. Assert(scan[2] == match[2], "scan[2]?");
  77215. scan++, match++;
  77216. do {
  77217. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77218. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77219. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77220. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77221. scan < strend);
  77222. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77223. if (*scan == *match) scan++;
  77224. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77225. scan = strend - (MAX_MATCH-1);
  77226. #else /* UNALIGNED_OK */
  77227. if (match[best_len] != scan_end ||
  77228. match[best_len-1] != scan_end1 ||
  77229. *match != *scan ||
  77230. *++match != scan[1]) continue;
  77231. scan += 2, match++;
  77232. Assert(*scan == *match, "match[2]?");
  77233. do {
  77234. } while (*++scan == *++match && *++scan == *++match &&
  77235. *++scan == *++match && *++scan == *++match &&
  77236. *++scan == *++match && *++scan == *++match &&
  77237. *++scan == *++match && *++scan == *++match &&
  77238. scan < strend);
  77239. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77240. len = MAX_MATCH - (int)(strend - scan);
  77241. scan = strend - MAX_MATCH;
  77242. #endif /* UNALIGNED_OK */
  77243. if (len > best_len) {
  77244. s->match_start = cur_match;
  77245. best_len = len;
  77246. if (len >= nice_match) break;
  77247. #ifdef UNALIGNED_OK
  77248. scan_end = *(ushf*)(scan+best_len-1);
  77249. #else
  77250. scan_end1 = scan[best_len-1];
  77251. scan_end = scan[best_len];
  77252. #endif
  77253. }
  77254. } while ((cur_match = prev[cur_match & wmask]) > limit
  77255. && --chain_length != 0);
  77256. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77257. return s->lookahead;
  77258. }
  77259. #endif /* ASMV */
  77260. #endif /* FASTEST */
  77261. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77262. {
  77263. register Bytef *scan = s->window + s->strstart; /* current string */
  77264. register Bytef *match; /* matched string */
  77265. register int len; /* length of current match */
  77266. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77267. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77268. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77269. Assert(cur_match < s->strstart, "no future");
  77270. match = s->window + cur_match;
  77271. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77272. scan += 2, match += 2;
  77273. Assert(*scan == *match, "match[2]?");
  77274. do {
  77275. } while (*++scan == *++match && *++scan == *++match &&
  77276. *++scan == *++match && *++scan == *++match &&
  77277. *++scan == *++match && *++scan == *++match &&
  77278. *++scan == *++match && *++scan == *++match &&
  77279. scan < strend);
  77280. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77281. len = MAX_MATCH - (int)(strend - scan);
  77282. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77283. s->match_start = cur_match;
  77284. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77285. }
  77286. #ifdef DEBUG
  77287. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77288. {
  77289. if (zmemcmp(s->window + match,
  77290. s->window + start, length) != EQUAL) {
  77291. fprintf(stderr, " start %u, match %u, length %d\n",
  77292. start, match, length);
  77293. do {
  77294. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77295. } while (--length != 0);
  77296. z_error("invalid match");
  77297. }
  77298. if (z_verbose > 1) {
  77299. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77300. do { putc(s->window[start++], stderr); } while (--length != 0);
  77301. }
  77302. }
  77303. #else
  77304. # define check_match(s, start, match, length)
  77305. #endif /* DEBUG */
  77306. local void fill_window (deflate_state *s)
  77307. {
  77308. register unsigned n, m;
  77309. register Posf *p;
  77310. unsigned more; /* Amount of free space at the end of the window. */
  77311. uInt wsize = s->w_size;
  77312. do {
  77313. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77314. if (sizeof(int) <= 2) {
  77315. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77316. more = wsize;
  77317. } else if (more == (unsigned)(-1)) {
  77318. more--;
  77319. }
  77320. }
  77321. if (s->strstart >= wsize+MAX_DIST(s)) {
  77322. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77323. s->match_start -= wsize;
  77324. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77325. s->block_start -= (long) wsize;
  77326. n = s->hash_size;
  77327. p = &s->head[n];
  77328. do {
  77329. m = *--p;
  77330. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77331. } while (--n);
  77332. n = wsize;
  77333. #ifndef FASTEST
  77334. p = &s->prev[n];
  77335. do {
  77336. m = *--p;
  77337. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77338. } while (--n);
  77339. #endif
  77340. more += wsize;
  77341. }
  77342. if (s->strm->avail_in == 0) return;
  77343. Assert(more >= 2, "more < 2");
  77344. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77345. s->lookahead += n;
  77346. if (s->lookahead >= MIN_MATCH) {
  77347. s->ins_h = s->window[s->strstart];
  77348. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77349. #if MIN_MATCH != 3
  77350. Call UPDATE_HASH() MIN_MATCH-3 more times
  77351. #endif
  77352. }
  77353. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77354. }
  77355. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77356. _tr_flush_block(s, (s->block_start >= 0L ? \
  77357. (charf *)&s->window[(unsigned)s->block_start] : \
  77358. (charf *)Z_NULL), \
  77359. (ulg)((long)s->strstart - s->block_start), \
  77360. (eof)); \
  77361. s->block_start = s->strstart; \
  77362. flush_pending(s->strm); \
  77363. Tracev((stderr,"[FLUSH]")); \
  77364. }
  77365. #define FLUSH_BLOCK(s, eof) { \
  77366. FLUSH_BLOCK_ONLY(s, eof); \
  77367. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77368. }
  77369. local block_state deflate_stored(deflate_state *s, int flush)
  77370. {
  77371. ulg max_block_size = 0xffff;
  77372. ulg max_start;
  77373. if (max_block_size > s->pending_buf_size - 5) {
  77374. max_block_size = s->pending_buf_size - 5;
  77375. }
  77376. for (;;) {
  77377. if (s->lookahead <= 1) {
  77378. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77379. s->block_start >= (long)s->w_size, "slide too late");
  77380. fill_window(s);
  77381. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77382. if (s->lookahead == 0) break; /* flush the current block */
  77383. }
  77384. Assert(s->block_start >= 0L, "block gone");
  77385. s->strstart += s->lookahead;
  77386. s->lookahead = 0;
  77387. max_start = s->block_start + max_block_size;
  77388. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77389. s->lookahead = (uInt)(s->strstart - max_start);
  77390. s->strstart = (uInt)max_start;
  77391. FLUSH_BLOCK(s, 0);
  77392. }
  77393. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77394. FLUSH_BLOCK(s, 0);
  77395. }
  77396. }
  77397. FLUSH_BLOCK(s, flush == Z_FINISH);
  77398. return flush == Z_FINISH ? finish_done : block_done;
  77399. }
  77400. local block_state deflate_fast(deflate_state *s, int flush)
  77401. {
  77402. IPos hash_head = NIL; /* head of the hash chain */
  77403. int bflush; /* set if current block must be flushed */
  77404. for (;;) {
  77405. if (s->lookahead < MIN_LOOKAHEAD) {
  77406. fill_window(s);
  77407. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77408. return need_more;
  77409. }
  77410. if (s->lookahead == 0) break; /* flush the current block */
  77411. }
  77412. if (s->lookahead >= MIN_MATCH) {
  77413. INSERT_STRING(s, s->strstart, hash_head);
  77414. }
  77415. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77416. #ifdef FASTEST
  77417. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77418. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77419. s->match_length = longest_match_fast (s, hash_head);
  77420. }
  77421. #else
  77422. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77423. s->match_length = longest_match (s, hash_head);
  77424. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77425. s->match_length = longest_match_fast (s, hash_head);
  77426. }
  77427. #endif
  77428. }
  77429. if (s->match_length >= MIN_MATCH) {
  77430. check_match(s, s->strstart, s->match_start, s->match_length);
  77431. _tr_tally_dist(s, s->strstart - s->match_start,
  77432. s->match_length - MIN_MATCH, bflush);
  77433. s->lookahead -= s->match_length;
  77434. #ifndef FASTEST
  77435. if (s->match_length <= s->max_insert_length &&
  77436. s->lookahead >= MIN_MATCH) {
  77437. s->match_length--; /* string at strstart already in table */
  77438. do {
  77439. s->strstart++;
  77440. INSERT_STRING(s, s->strstart, hash_head);
  77441. } while (--s->match_length != 0);
  77442. s->strstart++;
  77443. } else
  77444. #endif
  77445. {
  77446. s->strstart += s->match_length;
  77447. s->match_length = 0;
  77448. s->ins_h = s->window[s->strstart];
  77449. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77450. #if MIN_MATCH != 3
  77451. Call UPDATE_HASH() MIN_MATCH-3 more times
  77452. #endif
  77453. }
  77454. } else {
  77455. Tracevv((stderr,"%c", s->window[s->strstart]));
  77456. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77457. s->lookahead--;
  77458. s->strstart++;
  77459. }
  77460. if (bflush) FLUSH_BLOCK(s, 0);
  77461. }
  77462. FLUSH_BLOCK(s, flush == Z_FINISH);
  77463. return flush == Z_FINISH ? finish_done : block_done;
  77464. }
  77465. #ifndef FASTEST
  77466. local block_state deflate_slow(deflate_state *s, int flush)
  77467. {
  77468. IPos hash_head = NIL; /* head of hash chain */
  77469. int bflush; /* set if current block must be flushed */
  77470. for (;;) {
  77471. if (s->lookahead < MIN_LOOKAHEAD) {
  77472. fill_window(s);
  77473. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77474. return need_more;
  77475. }
  77476. if (s->lookahead == 0) break; /* flush the current block */
  77477. }
  77478. if (s->lookahead >= MIN_MATCH) {
  77479. INSERT_STRING(s, s->strstart, hash_head);
  77480. }
  77481. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77482. s->match_length = MIN_MATCH-1;
  77483. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77484. s->strstart - hash_head <= MAX_DIST(s)) {
  77485. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77486. s->match_length = longest_match (s, hash_head);
  77487. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77488. s->match_length = longest_match_fast (s, hash_head);
  77489. }
  77490. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77491. #if TOO_FAR <= 32767
  77492. || (s->match_length == MIN_MATCH &&
  77493. s->strstart - s->match_start > TOO_FAR)
  77494. #endif
  77495. )) {
  77496. s->match_length = MIN_MATCH-1;
  77497. }
  77498. }
  77499. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77500. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77501. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77502. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77503. s->prev_length - MIN_MATCH, bflush);
  77504. s->lookahead -= s->prev_length-1;
  77505. s->prev_length -= 2;
  77506. do {
  77507. if (++s->strstart <= max_insert) {
  77508. INSERT_STRING(s, s->strstart, hash_head);
  77509. }
  77510. } while (--s->prev_length != 0);
  77511. s->match_available = 0;
  77512. s->match_length = MIN_MATCH-1;
  77513. s->strstart++;
  77514. if (bflush) FLUSH_BLOCK(s, 0);
  77515. } else if (s->match_available) {
  77516. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77517. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77518. if (bflush) {
  77519. FLUSH_BLOCK_ONLY(s, 0);
  77520. }
  77521. s->strstart++;
  77522. s->lookahead--;
  77523. if (s->strm->avail_out == 0) return need_more;
  77524. } else {
  77525. s->match_available = 1;
  77526. s->strstart++;
  77527. s->lookahead--;
  77528. }
  77529. }
  77530. Assert (flush != Z_NO_FLUSH, "no flush?");
  77531. if (s->match_available) {
  77532. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77533. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77534. s->match_available = 0;
  77535. }
  77536. FLUSH_BLOCK(s, flush == Z_FINISH);
  77537. return flush == Z_FINISH ? finish_done : block_done;
  77538. }
  77539. #endif /* FASTEST */
  77540. #if 0
  77541. local block_state deflate_rle(s, flush)
  77542. deflate_state *s;
  77543. int flush;
  77544. {
  77545. int bflush; /* set if current block must be flushed */
  77546. uInt run; /* length of run */
  77547. uInt max; /* maximum length of run */
  77548. uInt prev; /* byte at distance one to match */
  77549. Bytef *scan; /* scan for end of run */
  77550. for (;;) {
  77551. if (s->lookahead < MAX_MATCH) {
  77552. fill_window(s);
  77553. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77554. return need_more;
  77555. }
  77556. if (s->lookahead == 0) break; /* flush the current block */
  77557. }
  77558. run = 0;
  77559. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77560. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77561. scan = s->window + s->strstart - 1;
  77562. prev = *scan++;
  77563. do {
  77564. if (*scan++ != prev)
  77565. break;
  77566. } while (++run < max);
  77567. }
  77568. if (run >= MIN_MATCH) {
  77569. check_match(s, s->strstart, s->strstart - 1, run);
  77570. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77571. s->lookahead -= run;
  77572. s->strstart += run;
  77573. } else {
  77574. Tracevv((stderr,"%c", s->window[s->strstart]));
  77575. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77576. s->lookahead--;
  77577. s->strstart++;
  77578. }
  77579. if (bflush) FLUSH_BLOCK(s, 0);
  77580. }
  77581. FLUSH_BLOCK(s, flush == Z_FINISH);
  77582. return flush == Z_FINISH ? finish_done : block_done;
  77583. }
  77584. #endif
  77585. /*** End of inlined file: deflate.c ***/
  77586. /*** Start of inlined file: inffast.c ***/
  77587. /*** Start of inlined file: inftrees.h ***/
  77588. #ifndef _INFTREES_H_
  77589. #define _INFTREES_H_
  77590. typedef struct {
  77591. unsigned char op; /* operation, extra bits, table bits */
  77592. unsigned char bits; /* bits in this part of the code */
  77593. unsigned short val; /* offset in table or code value */
  77594. } code;
  77595. #define ENOUGH 2048
  77596. #define MAXD 592
  77597. typedef enum {
  77598. CODES,
  77599. LENS,
  77600. DISTS
  77601. } codetype;
  77602. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77603. unsigned codes, code FAR * FAR *table,
  77604. unsigned FAR *bits, unsigned short FAR *work));
  77605. #endif
  77606. /*** End of inlined file: inftrees.h ***/
  77607. /*** Start of inlined file: inflate.h ***/
  77608. #ifndef _INFLATE_H_
  77609. #define _INFLATE_H_
  77610. #ifndef NO_GZIP
  77611. # define GUNZIP
  77612. #endif
  77613. typedef enum {
  77614. HEAD, /* i: waiting for magic header */
  77615. FLAGS, /* i: waiting for method and flags (gzip) */
  77616. TIME, /* i: waiting for modification time (gzip) */
  77617. OS, /* i: waiting for extra flags and operating system (gzip) */
  77618. EXLEN, /* i: waiting for extra length (gzip) */
  77619. EXTRA, /* i: waiting for extra bytes (gzip) */
  77620. NAME, /* i: waiting for end of file name (gzip) */
  77621. COMMENT, /* i: waiting for end of comment (gzip) */
  77622. HCRC, /* i: waiting for header crc (gzip) */
  77623. DICTID, /* i: waiting for dictionary check value */
  77624. DICT, /* waiting for inflateSetDictionary() call */
  77625. TYPE, /* i: waiting for type bits, including last-flag bit */
  77626. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77627. STORED, /* i: waiting for stored size (length and complement) */
  77628. COPY, /* i/o: waiting for input or output to copy stored block */
  77629. TABLE, /* i: waiting for dynamic block table lengths */
  77630. LENLENS, /* i: waiting for code length code lengths */
  77631. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77632. LEN, /* i: waiting for length/lit code */
  77633. LENEXT, /* i: waiting for length extra bits */
  77634. DIST, /* i: waiting for distance code */
  77635. DISTEXT, /* i: waiting for distance extra bits */
  77636. MATCH, /* o: waiting for output space to copy string */
  77637. LIT, /* o: waiting for output space to write literal */
  77638. CHECK, /* i: waiting for 32-bit check value */
  77639. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77640. DONE, /* finished check, done -- remain here until reset */
  77641. BAD, /* got a data error -- remain here until reset */
  77642. MEM, /* got an inflate() memory error -- remain here until reset */
  77643. SYNC /* looking for synchronization bytes to restart inflate() */
  77644. } inflate_mode;
  77645. struct inflate_state {
  77646. inflate_mode mode; /* current inflate mode */
  77647. int last; /* true if processing last block */
  77648. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77649. int havedict; /* true if dictionary provided */
  77650. int flags; /* gzip header method and flags (0 if zlib) */
  77651. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77652. unsigned long check; /* protected copy of check value */
  77653. unsigned long total; /* protected copy of output count */
  77654. gz_headerp head; /* where to save gzip header information */
  77655. unsigned wbits; /* log base 2 of requested window size */
  77656. unsigned wsize; /* window size or zero if not using window */
  77657. unsigned whave; /* valid bytes in the window */
  77658. unsigned write; /* window write index */
  77659. unsigned char FAR *window; /* allocated sliding window, if needed */
  77660. unsigned long hold; /* input bit accumulator */
  77661. unsigned bits; /* number of bits in "in" */
  77662. unsigned length; /* literal or length of data to copy */
  77663. unsigned offset; /* distance back to copy string from */
  77664. unsigned extra; /* extra bits needed */
  77665. code const FAR *lencode; /* starting table for length/literal codes */
  77666. code const FAR *distcode; /* starting table for distance codes */
  77667. unsigned lenbits; /* index bits for lencode */
  77668. unsigned distbits; /* index bits for distcode */
  77669. unsigned ncode; /* number of code length code lengths */
  77670. unsigned nlen; /* number of length code lengths */
  77671. unsigned ndist; /* number of distance code lengths */
  77672. unsigned have; /* number of code lengths in lens[] */
  77673. code FAR *next; /* next available space in codes[] */
  77674. unsigned short lens[320]; /* temporary storage for code lengths */
  77675. unsigned short work[288]; /* work area for code table building */
  77676. code codes[ENOUGH]; /* space for code tables */
  77677. };
  77678. #endif
  77679. /*** End of inlined file: inflate.h ***/
  77680. /*** Start of inlined file: inffast.h ***/
  77681. void inflate_fast OF((z_streamp strm, unsigned start));
  77682. /*** End of inlined file: inffast.h ***/
  77683. #ifndef ASMINF
  77684. #ifdef POSTINC
  77685. # define OFF 0
  77686. # define PUP(a) *(a)++
  77687. #else
  77688. # define OFF 1
  77689. # define PUP(a) *++(a)
  77690. #endif
  77691. void inflate_fast (z_streamp strm, unsigned start)
  77692. {
  77693. struct inflate_state FAR *state;
  77694. unsigned char FAR *in; /* local strm->next_in */
  77695. unsigned char FAR *last; /* while in < last, enough input available */
  77696. unsigned char FAR *out; /* local strm->next_out */
  77697. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77698. unsigned char FAR *end; /* while out < end, enough space available */
  77699. #ifdef INFLATE_STRICT
  77700. unsigned dmax; /* maximum distance from zlib header */
  77701. #endif
  77702. unsigned wsize; /* window size or zero if not using window */
  77703. unsigned whave; /* valid bytes in the window */
  77704. unsigned write; /* window write index */
  77705. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77706. unsigned long hold; /* local strm->hold */
  77707. unsigned bits; /* local strm->bits */
  77708. code const FAR *lcode; /* local strm->lencode */
  77709. code const FAR *dcode; /* local strm->distcode */
  77710. unsigned lmask; /* mask for first level of length codes */
  77711. unsigned dmask; /* mask for first level of distance codes */
  77712. code thisx; /* retrieved table entry */
  77713. unsigned op; /* code bits, operation, extra bits, or */
  77714. unsigned len; /* match length, unused bytes */
  77715. unsigned dist; /* match distance */
  77716. unsigned char FAR *from; /* where to copy match from */
  77717. state = (struct inflate_state FAR *)strm->state;
  77718. in = strm->next_in - OFF;
  77719. last = in + (strm->avail_in - 5);
  77720. out = strm->next_out - OFF;
  77721. beg = out - (start - strm->avail_out);
  77722. end = out + (strm->avail_out - 257);
  77723. #ifdef INFLATE_STRICT
  77724. dmax = state->dmax;
  77725. #endif
  77726. wsize = state->wsize;
  77727. whave = state->whave;
  77728. write = state->write;
  77729. window = state->window;
  77730. hold = state->hold;
  77731. bits = state->bits;
  77732. lcode = state->lencode;
  77733. dcode = state->distcode;
  77734. lmask = (1U << state->lenbits) - 1;
  77735. dmask = (1U << state->distbits) - 1;
  77736. do {
  77737. if (bits < 15) {
  77738. hold += (unsigned long)(PUP(in)) << bits;
  77739. bits += 8;
  77740. hold += (unsigned long)(PUP(in)) << bits;
  77741. bits += 8;
  77742. }
  77743. thisx = lcode[hold & lmask];
  77744. dolen:
  77745. op = (unsigned)(thisx.bits);
  77746. hold >>= op;
  77747. bits -= op;
  77748. op = (unsigned)(thisx.op);
  77749. if (op == 0) { /* literal */
  77750. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77751. "inflate: literal '%c'\n" :
  77752. "inflate: literal 0x%02x\n", thisx.val));
  77753. PUP(out) = (unsigned char)(thisx.val);
  77754. }
  77755. else if (op & 16) { /* length base */
  77756. len = (unsigned)(thisx.val);
  77757. op &= 15; /* number of extra bits */
  77758. if (op) {
  77759. if (bits < op) {
  77760. hold += (unsigned long)(PUP(in)) << bits;
  77761. bits += 8;
  77762. }
  77763. len += (unsigned)hold & ((1U << op) - 1);
  77764. hold >>= op;
  77765. bits -= op;
  77766. }
  77767. Tracevv((stderr, "inflate: length %u\n", len));
  77768. if (bits < 15) {
  77769. hold += (unsigned long)(PUP(in)) << bits;
  77770. bits += 8;
  77771. hold += (unsigned long)(PUP(in)) << bits;
  77772. bits += 8;
  77773. }
  77774. thisx = dcode[hold & dmask];
  77775. dodist:
  77776. op = (unsigned)(thisx.bits);
  77777. hold >>= op;
  77778. bits -= op;
  77779. op = (unsigned)(thisx.op);
  77780. if (op & 16) { /* distance base */
  77781. dist = (unsigned)(thisx.val);
  77782. op &= 15; /* number of extra bits */
  77783. if (bits < op) {
  77784. hold += (unsigned long)(PUP(in)) << bits;
  77785. bits += 8;
  77786. if (bits < op) {
  77787. hold += (unsigned long)(PUP(in)) << bits;
  77788. bits += 8;
  77789. }
  77790. }
  77791. dist += (unsigned)hold & ((1U << op) - 1);
  77792. #ifdef INFLATE_STRICT
  77793. if (dist > dmax) {
  77794. strm->msg = (char *)"invalid distance too far back";
  77795. state->mode = BAD;
  77796. break;
  77797. }
  77798. #endif
  77799. hold >>= op;
  77800. bits -= op;
  77801. Tracevv((stderr, "inflate: distance %u\n", dist));
  77802. op = (unsigned)(out - beg); /* max distance in output */
  77803. if (dist > op) { /* see if copy from window */
  77804. op = dist - op; /* distance back in window */
  77805. if (op > whave) {
  77806. strm->msg = (char *)"invalid distance too far back";
  77807. state->mode = BAD;
  77808. break;
  77809. }
  77810. from = window - OFF;
  77811. if (write == 0) { /* very common case */
  77812. from += wsize - op;
  77813. if (op < len) { /* some from window */
  77814. len -= op;
  77815. do {
  77816. PUP(out) = PUP(from);
  77817. } while (--op);
  77818. from = out - dist; /* rest from output */
  77819. }
  77820. }
  77821. else if (write < op) { /* wrap around window */
  77822. from += wsize + write - op;
  77823. op -= write;
  77824. if (op < len) { /* some from end of window */
  77825. len -= op;
  77826. do {
  77827. PUP(out) = PUP(from);
  77828. } while (--op);
  77829. from = window - OFF;
  77830. if (write < len) { /* some from start of window */
  77831. op = write;
  77832. len -= op;
  77833. do {
  77834. PUP(out) = PUP(from);
  77835. } while (--op);
  77836. from = out - dist; /* rest from output */
  77837. }
  77838. }
  77839. }
  77840. else { /* contiguous in window */
  77841. from += write - op;
  77842. if (op < len) { /* some from window */
  77843. len -= op;
  77844. do {
  77845. PUP(out) = PUP(from);
  77846. } while (--op);
  77847. from = out - dist; /* rest from output */
  77848. }
  77849. }
  77850. while (len > 2) {
  77851. PUP(out) = PUP(from);
  77852. PUP(out) = PUP(from);
  77853. PUP(out) = PUP(from);
  77854. len -= 3;
  77855. }
  77856. if (len) {
  77857. PUP(out) = PUP(from);
  77858. if (len > 1)
  77859. PUP(out) = PUP(from);
  77860. }
  77861. }
  77862. else {
  77863. from = out - dist; /* copy direct from output */
  77864. do { /* minimum length is three */
  77865. PUP(out) = PUP(from);
  77866. PUP(out) = PUP(from);
  77867. PUP(out) = PUP(from);
  77868. len -= 3;
  77869. } while (len > 2);
  77870. if (len) {
  77871. PUP(out) = PUP(from);
  77872. if (len > 1)
  77873. PUP(out) = PUP(from);
  77874. }
  77875. }
  77876. }
  77877. else if ((op & 64) == 0) { /* 2nd level distance code */
  77878. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77879. goto dodist;
  77880. }
  77881. else {
  77882. strm->msg = (char *)"invalid distance code";
  77883. state->mode = BAD;
  77884. break;
  77885. }
  77886. }
  77887. else if ((op & 64) == 0) { /* 2nd level length code */
  77888. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77889. goto dolen;
  77890. }
  77891. else if (op & 32) { /* end-of-block */
  77892. Tracevv((stderr, "inflate: end of block\n"));
  77893. state->mode = TYPE;
  77894. break;
  77895. }
  77896. else {
  77897. strm->msg = (char *)"invalid literal/length code";
  77898. state->mode = BAD;
  77899. break;
  77900. }
  77901. } while (in < last && out < end);
  77902. len = bits >> 3;
  77903. in -= len;
  77904. bits -= len << 3;
  77905. hold &= (1U << bits) - 1;
  77906. strm->next_in = in + OFF;
  77907. strm->next_out = out + OFF;
  77908. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77909. strm->avail_out = (unsigned)(out < end ?
  77910. 257 + (end - out) : 257 - (out - end));
  77911. state->hold = hold;
  77912. state->bits = bits;
  77913. return;
  77914. }
  77915. #endif /* !ASMINF */
  77916. /*** End of inlined file: inffast.c ***/
  77917. #undef PULLBYTE
  77918. #undef LOAD
  77919. #undef RESTORE
  77920. #undef INITBITS
  77921. #undef NEEDBITS
  77922. #undef DROPBITS
  77923. #undef BYTEBITS
  77924. /*** Start of inlined file: inflate.c ***/
  77925. /*** Start of inlined file: inffast.h ***/
  77926. void inflate_fast OF((z_streamp strm, unsigned start));
  77927. /*** End of inlined file: inffast.h ***/
  77928. #ifdef MAKEFIXED
  77929. # ifndef BUILDFIXED
  77930. # define BUILDFIXED
  77931. # endif
  77932. #endif
  77933. local void fixedtables OF((struct inflate_state FAR *state));
  77934. local int updatewindow OF((z_streamp strm, unsigned out));
  77935. #ifdef BUILDFIXED
  77936. void makefixed OF((void));
  77937. #endif
  77938. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  77939. unsigned len));
  77940. int ZEXPORT inflateReset (z_streamp strm)
  77941. {
  77942. struct inflate_state FAR *state;
  77943. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77944. state = (struct inflate_state FAR *)strm->state;
  77945. strm->total_in = strm->total_out = state->total = 0;
  77946. strm->msg = Z_NULL;
  77947. strm->adler = 1; /* to support ill-conceived Java test suite */
  77948. state->mode = HEAD;
  77949. state->last = 0;
  77950. state->havedict = 0;
  77951. state->dmax = 32768U;
  77952. state->head = Z_NULL;
  77953. state->wsize = 0;
  77954. state->whave = 0;
  77955. state->write = 0;
  77956. state->hold = 0;
  77957. state->bits = 0;
  77958. state->lencode = state->distcode = state->next = state->codes;
  77959. Tracev((stderr, "inflate: reset\n"));
  77960. return Z_OK;
  77961. }
  77962. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  77963. {
  77964. struct inflate_state FAR *state;
  77965. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77966. state = (struct inflate_state FAR *)strm->state;
  77967. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  77968. value &= (1L << bits) - 1;
  77969. state->hold += value << state->bits;
  77970. state->bits += bits;
  77971. return Z_OK;
  77972. }
  77973. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  77974. {
  77975. struct inflate_state FAR *state;
  77976. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  77977. stream_size != (int)(sizeof(z_stream)))
  77978. return Z_VERSION_ERROR;
  77979. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77980. strm->msg = Z_NULL; /* in case we return an error */
  77981. if (strm->zalloc == (alloc_func)0) {
  77982. strm->zalloc = zcalloc;
  77983. strm->opaque = (voidpf)0;
  77984. }
  77985. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77986. state = (struct inflate_state FAR *)
  77987. ZALLOC(strm, 1, sizeof(struct inflate_state));
  77988. if (state == Z_NULL) return Z_MEM_ERROR;
  77989. Tracev((stderr, "inflate: allocated\n"));
  77990. strm->state = (struct internal_state FAR *)state;
  77991. if (windowBits < 0) {
  77992. state->wrap = 0;
  77993. windowBits = -windowBits;
  77994. }
  77995. else {
  77996. state->wrap = (windowBits >> 4) + 1;
  77997. #ifdef GUNZIP
  77998. if (windowBits < 48) windowBits &= 15;
  77999. #endif
  78000. }
  78001. if (windowBits < 8 || windowBits > 15) {
  78002. ZFREE(strm, state);
  78003. strm->state = Z_NULL;
  78004. return Z_STREAM_ERROR;
  78005. }
  78006. state->wbits = (unsigned)windowBits;
  78007. state->window = Z_NULL;
  78008. return inflateReset(strm);
  78009. }
  78010. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78011. {
  78012. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78013. }
  78014. local void fixedtables (struct inflate_state FAR *state)
  78015. {
  78016. #ifdef BUILDFIXED
  78017. static int virgin = 1;
  78018. static code *lenfix, *distfix;
  78019. static code fixed[544];
  78020. if (virgin) {
  78021. unsigned sym, bits;
  78022. static code *next;
  78023. sym = 0;
  78024. while (sym < 144) state->lens[sym++] = 8;
  78025. while (sym < 256) state->lens[sym++] = 9;
  78026. while (sym < 280) state->lens[sym++] = 7;
  78027. while (sym < 288) state->lens[sym++] = 8;
  78028. next = fixed;
  78029. lenfix = next;
  78030. bits = 9;
  78031. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78032. sym = 0;
  78033. while (sym < 32) state->lens[sym++] = 5;
  78034. distfix = next;
  78035. bits = 5;
  78036. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78037. virgin = 0;
  78038. }
  78039. #else /* !BUILDFIXED */
  78040. /*** Start of inlined file: inffixed.h ***/
  78041. static const code lenfix[512] = {
  78042. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78043. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78044. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78045. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78046. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78047. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78048. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78049. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78050. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78051. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78052. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78053. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78054. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78055. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78056. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78057. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78058. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78059. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78060. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78061. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78062. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78063. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78064. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78065. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78066. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78067. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78068. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78069. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78070. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78071. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78072. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78073. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78074. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78075. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78076. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78077. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78078. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78079. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78080. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78081. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78082. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78083. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78084. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78085. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78086. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78087. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78088. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78089. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78090. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78091. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78092. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78093. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78094. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78095. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78096. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78097. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78098. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78099. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78100. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78101. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78102. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78103. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78104. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78105. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78106. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78107. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78108. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78109. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78110. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78111. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78112. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78113. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78114. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78115. {0,9,255}
  78116. };
  78117. static const code distfix[32] = {
  78118. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78119. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78120. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78121. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78122. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78123. {22,5,193},{64,5,0}
  78124. };
  78125. /*** End of inlined file: inffixed.h ***/
  78126. #endif /* BUILDFIXED */
  78127. state->lencode = lenfix;
  78128. state->lenbits = 9;
  78129. state->distcode = distfix;
  78130. state->distbits = 5;
  78131. }
  78132. #ifdef MAKEFIXED
  78133. #include <stdio.h>
  78134. void makefixed()
  78135. {
  78136. unsigned low, size;
  78137. struct inflate_state state;
  78138. fixedtables(&state);
  78139. puts(" /* inffixed.h -- table for decoding fixed codes");
  78140. puts(" * Generated automatically by makefixed().");
  78141. puts(" */");
  78142. puts("");
  78143. puts(" /* WARNING: this file should *not* be used by applications.");
  78144. puts(" It is part of the implementation of this library and is");
  78145. puts(" subject to change. Applications should only use zlib.h.");
  78146. puts(" */");
  78147. puts("");
  78148. size = 1U << 9;
  78149. printf(" static const code lenfix[%u] = {", size);
  78150. low = 0;
  78151. for (;;) {
  78152. if ((low % 7) == 0) printf("\n ");
  78153. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78154. state.lencode[low].val);
  78155. if (++low == size) break;
  78156. putchar(',');
  78157. }
  78158. puts("\n };");
  78159. size = 1U << 5;
  78160. printf("\n static const code distfix[%u] = {", size);
  78161. low = 0;
  78162. for (;;) {
  78163. if ((low % 6) == 0) printf("\n ");
  78164. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78165. state.distcode[low].val);
  78166. if (++low == size) break;
  78167. putchar(',');
  78168. }
  78169. puts("\n };");
  78170. }
  78171. #endif /* MAKEFIXED */
  78172. local int updatewindow (z_streamp strm, unsigned out)
  78173. {
  78174. struct inflate_state FAR *state;
  78175. unsigned copy, dist;
  78176. state = (struct inflate_state FAR *)strm->state;
  78177. if (state->window == Z_NULL) {
  78178. state->window = (unsigned char FAR *)
  78179. ZALLOC(strm, 1U << state->wbits,
  78180. sizeof(unsigned char));
  78181. if (state->window == Z_NULL) return 1;
  78182. }
  78183. if (state->wsize == 0) {
  78184. state->wsize = 1U << state->wbits;
  78185. state->write = 0;
  78186. state->whave = 0;
  78187. }
  78188. copy = out - strm->avail_out;
  78189. if (copy >= state->wsize) {
  78190. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78191. state->write = 0;
  78192. state->whave = state->wsize;
  78193. }
  78194. else {
  78195. dist = state->wsize - state->write;
  78196. if (dist > copy) dist = copy;
  78197. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78198. copy -= dist;
  78199. if (copy) {
  78200. zmemcpy(state->window, strm->next_out - copy, copy);
  78201. state->write = copy;
  78202. state->whave = state->wsize;
  78203. }
  78204. else {
  78205. state->write += dist;
  78206. if (state->write == state->wsize) state->write = 0;
  78207. if (state->whave < state->wsize) state->whave += dist;
  78208. }
  78209. }
  78210. return 0;
  78211. }
  78212. #ifdef GUNZIP
  78213. # define UPDATE(check, buf, len) \
  78214. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78215. #else
  78216. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78217. #endif
  78218. #ifdef GUNZIP
  78219. # define CRC2(check, word) \
  78220. do { \
  78221. hbuf[0] = (unsigned char)(word); \
  78222. hbuf[1] = (unsigned char)((word) >> 8); \
  78223. check = crc32(check, hbuf, 2); \
  78224. } while (0)
  78225. # define CRC4(check, word) \
  78226. do { \
  78227. hbuf[0] = (unsigned char)(word); \
  78228. hbuf[1] = (unsigned char)((word) >> 8); \
  78229. hbuf[2] = (unsigned char)((word) >> 16); \
  78230. hbuf[3] = (unsigned char)((word) >> 24); \
  78231. check = crc32(check, hbuf, 4); \
  78232. } while (0)
  78233. #endif
  78234. #define LOAD() \
  78235. do { \
  78236. put = strm->next_out; \
  78237. left = strm->avail_out; \
  78238. next = strm->next_in; \
  78239. have = strm->avail_in; \
  78240. hold = state->hold; \
  78241. bits = state->bits; \
  78242. } while (0)
  78243. #define RESTORE() \
  78244. do { \
  78245. strm->next_out = put; \
  78246. strm->avail_out = left; \
  78247. strm->next_in = next; \
  78248. strm->avail_in = have; \
  78249. state->hold = hold; \
  78250. state->bits = bits; \
  78251. } while (0)
  78252. #define INITBITS() \
  78253. do { \
  78254. hold = 0; \
  78255. bits = 0; \
  78256. } while (0)
  78257. #define PULLBYTE() \
  78258. do { \
  78259. if (have == 0) goto inf_leave; \
  78260. have--; \
  78261. hold += (unsigned long)(*next++) << bits; \
  78262. bits += 8; \
  78263. } while (0)
  78264. #define NEEDBITS(n) \
  78265. do { \
  78266. while (bits < (unsigned)(n)) \
  78267. PULLBYTE(); \
  78268. } while (0)
  78269. #define BITS(n) \
  78270. ((unsigned)hold & ((1U << (n)) - 1))
  78271. #define DROPBITS(n) \
  78272. do { \
  78273. hold >>= (n); \
  78274. bits -= (unsigned)(n); \
  78275. } while (0)
  78276. #define BYTEBITS() \
  78277. do { \
  78278. hold >>= bits & 7; \
  78279. bits -= bits & 7; \
  78280. } while (0)
  78281. #define REVERSE(q) \
  78282. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78283. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78284. int ZEXPORT inflate (z_streamp strm, int flush)
  78285. {
  78286. struct inflate_state FAR *state;
  78287. unsigned char FAR *next; /* next input */
  78288. unsigned char FAR *put; /* next output */
  78289. unsigned have, left; /* available input and output */
  78290. unsigned long hold; /* bit buffer */
  78291. unsigned bits; /* bits in bit buffer */
  78292. unsigned in, out; /* save starting available input and output */
  78293. unsigned copy; /* number of stored or match bytes to copy */
  78294. unsigned char FAR *from; /* where to copy match bytes from */
  78295. code thisx; /* current decoding table entry */
  78296. code last; /* parent table entry */
  78297. unsigned len; /* length to copy for repeats, bits to drop */
  78298. int ret; /* return code */
  78299. #ifdef GUNZIP
  78300. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78301. #endif
  78302. static const unsigned short order[19] = /* permutation of code lengths */
  78303. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78304. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78305. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78306. return Z_STREAM_ERROR;
  78307. state = (struct inflate_state FAR *)strm->state;
  78308. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78309. LOAD();
  78310. in = have;
  78311. out = left;
  78312. ret = Z_OK;
  78313. for (;;)
  78314. switch (state->mode) {
  78315. case HEAD:
  78316. if (state->wrap == 0) {
  78317. state->mode = TYPEDO;
  78318. break;
  78319. }
  78320. NEEDBITS(16);
  78321. #ifdef GUNZIP
  78322. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78323. state->check = crc32(0L, Z_NULL, 0);
  78324. CRC2(state->check, hold);
  78325. INITBITS();
  78326. state->mode = FLAGS;
  78327. break;
  78328. }
  78329. state->flags = 0; /* expect zlib header */
  78330. if (state->head != Z_NULL)
  78331. state->head->done = -1;
  78332. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78333. #else
  78334. if (
  78335. #endif
  78336. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78337. strm->msg = (char *)"incorrect header check";
  78338. state->mode = BAD;
  78339. break;
  78340. }
  78341. if (BITS(4) != Z_DEFLATED) {
  78342. strm->msg = (char *)"unknown compression method";
  78343. state->mode = BAD;
  78344. break;
  78345. }
  78346. DROPBITS(4);
  78347. len = BITS(4) + 8;
  78348. if (len > state->wbits) {
  78349. strm->msg = (char *)"invalid window size";
  78350. state->mode = BAD;
  78351. break;
  78352. }
  78353. state->dmax = 1U << len;
  78354. Tracev((stderr, "inflate: zlib header ok\n"));
  78355. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78356. state->mode = hold & 0x200 ? DICTID : TYPE;
  78357. INITBITS();
  78358. break;
  78359. #ifdef GUNZIP
  78360. case FLAGS:
  78361. NEEDBITS(16);
  78362. state->flags = (int)(hold);
  78363. if ((state->flags & 0xff) != Z_DEFLATED) {
  78364. strm->msg = (char *)"unknown compression method";
  78365. state->mode = BAD;
  78366. break;
  78367. }
  78368. if (state->flags & 0xe000) {
  78369. strm->msg = (char *)"unknown header flags set";
  78370. state->mode = BAD;
  78371. break;
  78372. }
  78373. if (state->head != Z_NULL)
  78374. state->head->text = (int)((hold >> 8) & 1);
  78375. if (state->flags & 0x0200) CRC2(state->check, hold);
  78376. INITBITS();
  78377. state->mode = TIME;
  78378. case TIME:
  78379. NEEDBITS(32);
  78380. if (state->head != Z_NULL)
  78381. state->head->time = hold;
  78382. if (state->flags & 0x0200) CRC4(state->check, hold);
  78383. INITBITS();
  78384. state->mode = OS;
  78385. case OS:
  78386. NEEDBITS(16);
  78387. if (state->head != Z_NULL) {
  78388. state->head->xflags = (int)(hold & 0xff);
  78389. state->head->os = (int)(hold >> 8);
  78390. }
  78391. if (state->flags & 0x0200) CRC2(state->check, hold);
  78392. INITBITS();
  78393. state->mode = EXLEN;
  78394. case EXLEN:
  78395. if (state->flags & 0x0400) {
  78396. NEEDBITS(16);
  78397. state->length = (unsigned)(hold);
  78398. if (state->head != Z_NULL)
  78399. state->head->extra_len = (unsigned)hold;
  78400. if (state->flags & 0x0200) CRC2(state->check, hold);
  78401. INITBITS();
  78402. }
  78403. else if (state->head != Z_NULL)
  78404. state->head->extra = Z_NULL;
  78405. state->mode = EXTRA;
  78406. case EXTRA:
  78407. if (state->flags & 0x0400) {
  78408. copy = state->length;
  78409. if (copy > have) copy = have;
  78410. if (copy) {
  78411. if (state->head != Z_NULL &&
  78412. state->head->extra != Z_NULL) {
  78413. len = state->head->extra_len - state->length;
  78414. zmemcpy(state->head->extra + len, next,
  78415. len + copy > state->head->extra_max ?
  78416. state->head->extra_max - len : copy);
  78417. }
  78418. if (state->flags & 0x0200)
  78419. state->check = crc32(state->check, next, copy);
  78420. have -= copy;
  78421. next += copy;
  78422. state->length -= copy;
  78423. }
  78424. if (state->length) goto inf_leave;
  78425. }
  78426. state->length = 0;
  78427. state->mode = NAME;
  78428. case NAME:
  78429. if (state->flags & 0x0800) {
  78430. if (have == 0) goto inf_leave;
  78431. copy = 0;
  78432. do {
  78433. len = (unsigned)(next[copy++]);
  78434. if (state->head != Z_NULL &&
  78435. state->head->name != Z_NULL &&
  78436. state->length < state->head->name_max)
  78437. state->head->name[state->length++] = len;
  78438. } while (len && copy < have);
  78439. if (state->flags & 0x0200)
  78440. state->check = crc32(state->check, next, copy);
  78441. have -= copy;
  78442. next += copy;
  78443. if (len) goto inf_leave;
  78444. }
  78445. else if (state->head != Z_NULL)
  78446. state->head->name = Z_NULL;
  78447. state->length = 0;
  78448. state->mode = COMMENT;
  78449. case COMMENT:
  78450. if (state->flags & 0x1000) {
  78451. if (have == 0) goto inf_leave;
  78452. copy = 0;
  78453. do {
  78454. len = (unsigned)(next[copy++]);
  78455. if (state->head != Z_NULL &&
  78456. state->head->comment != Z_NULL &&
  78457. state->length < state->head->comm_max)
  78458. state->head->comment[state->length++] = len;
  78459. } while (len && copy < have);
  78460. if (state->flags & 0x0200)
  78461. state->check = crc32(state->check, next, copy);
  78462. have -= copy;
  78463. next += copy;
  78464. if (len) goto inf_leave;
  78465. }
  78466. else if (state->head != Z_NULL)
  78467. state->head->comment = Z_NULL;
  78468. state->mode = HCRC;
  78469. case HCRC:
  78470. if (state->flags & 0x0200) {
  78471. NEEDBITS(16);
  78472. if (hold != (state->check & 0xffff)) {
  78473. strm->msg = (char *)"header crc mismatch";
  78474. state->mode = BAD;
  78475. break;
  78476. }
  78477. INITBITS();
  78478. }
  78479. if (state->head != Z_NULL) {
  78480. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78481. state->head->done = 1;
  78482. }
  78483. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78484. state->mode = TYPE;
  78485. break;
  78486. #endif
  78487. case DICTID:
  78488. NEEDBITS(32);
  78489. strm->adler = state->check = REVERSE(hold);
  78490. INITBITS();
  78491. state->mode = DICT;
  78492. case DICT:
  78493. if (state->havedict == 0) {
  78494. RESTORE();
  78495. return Z_NEED_DICT;
  78496. }
  78497. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78498. state->mode = TYPE;
  78499. case TYPE:
  78500. if (flush == Z_BLOCK) goto inf_leave;
  78501. case TYPEDO:
  78502. if (state->last) {
  78503. BYTEBITS();
  78504. state->mode = CHECK;
  78505. break;
  78506. }
  78507. NEEDBITS(3);
  78508. state->last = BITS(1);
  78509. DROPBITS(1);
  78510. switch (BITS(2)) {
  78511. case 0: /* stored block */
  78512. Tracev((stderr, "inflate: stored block%s\n",
  78513. state->last ? " (last)" : ""));
  78514. state->mode = STORED;
  78515. break;
  78516. case 1: /* fixed block */
  78517. fixedtables(state);
  78518. Tracev((stderr, "inflate: fixed codes block%s\n",
  78519. state->last ? " (last)" : ""));
  78520. state->mode = LEN; /* decode codes */
  78521. break;
  78522. case 2: /* dynamic block */
  78523. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78524. state->last ? " (last)" : ""));
  78525. state->mode = TABLE;
  78526. break;
  78527. case 3:
  78528. strm->msg = (char *)"invalid block type";
  78529. state->mode = BAD;
  78530. }
  78531. DROPBITS(2);
  78532. break;
  78533. case STORED:
  78534. BYTEBITS(); /* go to byte boundary */
  78535. NEEDBITS(32);
  78536. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78537. strm->msg = (char *)"invalid stored block lengths";
  78538. state->mode = BAD;
  78539. break;
  78540. }
  78541. state->length = (unsigned)hold & 0xffff;
  78542. Tracev((stderr, "inflate: stored length %u\n",
  78543. state->length));
  78544. INITBITS();
  78545. state->mode = COPY;
  78546. case COPY:
  78547. copy = state->length;
  78548. if (copy) {
  78549. if (copy > have) copy = have;
  78550. if (copy > left) copy = left;
  78551. if (copy == 0) goto inf_leave;
  78552. zmemcpy(put, next, copy);
  78553. have -= copy;
  78554. next += copy;
  78555. left -= copy;
  78556. put += copy;
  78557. state->length -= copy;
  78558. break;
  78559. }
  78560. Tracev((stderr, "inflate: stored end\n"));
  78561. state->mode = TYPE;
  78562. break;
  78563. case TABLE:
  78564. NEEDBITS(14);
  78565. state->nlen = BITS(5) + 257;
  78566. DROPBITS(5);
  78567. state->ndist = BITS(5) + 1;
  78568. DROPBITS(5);
  78569. state->ncode = BITS(4) + 4;
  78570. DROPBITS(4);
  78571. #ifndef PKZIP_BUG_WORKAROUND
  78572. if (state->nlen > 286 || state->ndist > 30) {
  78573. strm->msg = (char *)"too many length or distance symbols";
  78574. state->mode = BAD;
  78575. break;
  78576. }
  78577. #endif
  78578. Tracev((stderr, "inflate: table sizes ok\n"));
  78579. state->have = 0;
  78580. state->mode = LENLENS;
  78581. case LENLENS:
  78582. while (state->have < state->ncode) {
  78583. NEEDBITS(3);
  78584. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78585. DROPBITS(3);
  78586. }
  78587. while (state->have < 19)
  78588. state->lens[order[state->have++]] = 0;
  78589. state->next = state->codes;
  78590. state->lencode = (code const FAR *)(state->next);
  78591. state->lenbits = 7;
  78592. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78593. &(state->lenbits), state->work);
  78594. if (ret) {
  78595. strm->msg = (char *)"invalid code lengths set";
  78596. state->mode = BAD;
  78597. break;
  78598. }
  78599. Tracev((stderr, "inflate: code lengths ok\n"));
  78600. state->have = 0;
  78601. state->mode = CODELENS;
  78602. case CODELENS:
  78603. while (state->have < state->nlen + state->ndist) {
  78604. for (;;) {
  78605. thisx = state->lencode[BITS(state->lenbits)];
  78606. if ((unsigned)(thisx.bits) <= bits) break;
  78607. PULLBYTE();
  78608. }
  78609. if (thisx.val < 16) {
  78610. NEEDBITS(thisx.bits);
  78611. DROPBITS(thisx.bits);
  78612. state->lens[state->have++] = thisx.val;
  78613. }
  78614. else {
  78615. if (thisx.val == 16) {
  78616. NEEDBITS(thisx.bits + 2);
  78617. DROPBITS(thisx.bits);
  78618. if (state->have == 0) {
  78619. strm->msg = (char *)"invalid bit length repeat";
  78620. state->mode = BAD;
  78621. break;
  78622. }
  78623. len = state->lens[state->have - 1];
  78624. copy = 3 + BITS(2);
  78625. DROPBITS(2);
  78626. }
  78627. else if (thisx.val == 17) {
  78628. NEEDBITS(thisx.bits + 3);
  78629. DROPBITS(thisx.bits);
  78630. len = 0;
  78631. copy = 3 + BITS(3);
  78632. DROPBITS(3);
  78633. }
  78634. else {
  78635. NEEDBITS(thisx.bits + 7);
  78636. DROPBITS(thisx.bits);
  78637. len = 0;
  78638. copy = 11 + BITS(7);
  78639. DROPBITS(7);
  78640. }
  78641. if (state->have + copy > state->nlen + state->ndist) {
  78642. strm->msg = (char *)"invalid bit length repeat";
  78643. state->mode = BAD;
  78644. break;
  78645. }
  78646. while (copy--)
  78647. state->lens[state->have++] = (unsigned short)len;
  78648. }
  78649. }
  78650. if (state->mode == BAD) break;
  78651. state->next = state->codes;
  78652. state->lencode = (code const FAR *)(state->next);
  78653. state->lenbits = 9;
  78654. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78655. &(state->lenbits), state->work);
  78656. if (ret) {
  78657. strm->msg = (char *)"invalid literal/lengths set";
  78658. state->mode = BAD;
  78659. break;
  78660. }
  78661. state->distcode = (code const FAR *)(state->next);
  78662. state->distbits = 6;
  78663. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78664. &(state->next), &(state->distbits), state->work);
  78665. if (ret) {
  78666. strm->msg = (char *)"invalid distances set";
  78667. state->mode = BAD;
  78668. break;
  78669. }
  78670. Tracev((stderr, "inflate: codes ok\n"));
  78671. state->mode = LEN;
  78672. case LEN:
  78673. if (have >= 6 && left >= 258) {
  78674. RESTORE();
  78675. inflate_fast(strm, out);
  78676. LOAD();
  78677. break;
  78678. }
  78679. for (;;) {
  78680. thisx = state->lencode[BITS(state->lenbits)];
  78681. if ((unsigned)(thisx.bits) <= bits) break;
  78682. PULLBYTE();
  78683. }
  78684. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78685. last = thisx;
  78686. for (;;) {
  78687. thisx = state->lencode[last.val +
  78688. (BITS(last.bits + last.op) >> last.bits)];
  78689. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78690. PULLBYTE();
  78691. }
  78692. DROPBITS(last.bits);
  78693. }
  78694. DROPBITS(thisx.bits);
  78695. state->length = (unsigned)thisx.val;
  78696. if ((int)(thisx.op) == 0) {
  78697. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78698. "inflate: literal '%c'\n" :
  78699. "inflate: literal 0x%02x\n", thisx.val));
  78700. state->mode = LIT;
  78701. break;
  78702. }
  78703. if (thisx.op & 32) {
  78704. Tracevv((stderr, "inflate: end of block\n"));
  78705. state->mode = TYPE;
  78706. break;
  78707. }
  78708. if (thisx.op & 64) {
  78709. strm->msg = (char *)"invalid literal/length code";
  78710. state->mode = BAD;
  78711. break;
  78712. }
  78713. state->extra = (unsigned)(thisx.op) & 15;
  78714. state->mode = LENEXT;
  78715. case LENEXT:
  78716. if (state->extra) {
  78717. NEEDBITS(state->extra);
  78718. state->length += BITS(state->extra);
  78719. DROPBITS(state->extra);
  78720. }
  78721. Tracevv((stderr, "inflate: length %u\n", state->length));
  78722. state->mode = DIST;
  78723. case DIST:
  78724. for (;;) {
  78725. thisx = state->distcode[BITS(state->distbits)];
  78726. if ((unsigned)(thisx.bits) <= bits) break;
  78727. PULLBYTE();
  78728. }
  78729. if ((thisx.op & 0xf0) == 0) {
  78730. last = thisx;
  78731. for (;;) {
  78732. thisx = state->distcode[last.val +
  78733. (BITS(last.bits + last.op) >> last.bits)];
  78734. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78735. PULLBYTE();
  78736. }
  78737. DROPBITS(last.bits);
  78738. }
  78739. DROPBITS(thisx.bits);
  78740. if (thisx.op & 64) {
  78741. strm->msg = (char *)"invalid distance code";
  78742. state->mode = BAD;
  78743. break;
  78744. }
  78745. state->offset = (unsigned)thisx.val;
  78746. state->extra = (unsigned)(thisx.op) & 15;
  78747. state->mode = DISTEXT;
  78748. case DISTEXT:
  78749. if (state->extra) {
  78750. NEEDBITS(state->extra);
  78751. state->offset += BITS(state->extra);
  78752. DROPBITS(state->extra);
  78753. }
  78754. #ifdef INFLATE_STRICT
  78755. if (state->offset > state->dmax) {
  78756. strm->msg = (char *)"invalid distance too far back";
  78757. state->mode = BAD;
  78758. break;
  78759. }
  78760. #endif
  78761. if (state->offset > state->whave + out - left) {
  78762. strm->msg = (char *)"invalid distance too far back";
  78763. state->mode = BAD;
  78764. break;
  78765. }
  78766. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78767. state->mode = MATCH;
  78768. case MATCH:
  78769. if (left == 0) goto inf_leave;
  78770. copy = out - left;
  78771. if (state->offset > copy) { /* copy from window */
  78772. copy = state->offset - copy;
  78773. if (copy > state->write) {
  78774. copy -= state->write;
  78775. from = state->window + (state->wsize - copy);
  78776. }
  78777. else
  78778. from = state->window + (state->write - copy);
  78779. if (copy > state->length) copy = state->length;
  78780. }
  78781. else { /* copy from output */
  78782. from = put - state->offset;
  78783. copy = state->length;
  78784. }
  78785. if (copy > left) copy = left;
  78786. left -= copy;
  78787. state->length -= copy;
  78788. do {
  78789. *put++ = *from++;
  78790. } while (--copy);
  78791. if (state->length == 0) state->mode = LEN;
  78792. break;
  78793. case LIT:
  78794. if (left == 0) goto inf_leave;
  78795. *put++ = (unsigned char)(state->length);
  78796. left--;
  78797. state->mode = LEN;
  78798. break;
  78799. case CHECK:
  78800. if (state->wrap) {
  78801. NEEDBITS(32);
  78802. out -= left;
  78803. strm->total_out += out;
  78804. state->total += out;
  78805. if (out)
  78806. strm->adler = state->check =
  78807. UPDATE(state->check, put - out, out);
  78808. out = left;
  78809. if ((
  78810. #ifdef GUNZIP
  78811. state->flags ? hold :
  78812. #endif
  78813. REVERSE(hold)) != state->check) {
  78814. strm->msg = (char *)"incorrect data check";
  78815. state->mode = BAD;
  78816. break;
  78817. }
  78818. INITBITS();
  78819. Tracev((stderr, "inflate: check matches trailer\n"));
  78820. }
  78821. #ifdef GUNZIP
  78822. state->mode = LENGTH;
  78823. case LENGTH:
  78824. if (state->wrap && state->flags) {
  78825. NEEDBITS(32);
  78826. if (hold != (state->total & 0xffffffffUL)) {
  78827. strm->msg = (char *)"incorrect length check";
  78828. state->mode = BAD;
  78829. break;
  78830. }
  78831. INITBITS();
  78832. Tracev((stderr, "inflate: length matches trailer\n"));
  78833. }
  78834. #endif
  78835. state->mode = DONE;
  78836. case DONE:
  78837. ret = Z_STREAM_END;
  78838. goto inf_leave;
  78839. case BAD:
  78840. ret = Z_DATA_ERROR;
  78841. goto inf_leave;
  78842. case MEM:
  78843. return Z_MEM_ERROR;
  78844. case SYNC:
  78845. default:
  78846. return Z_STREAM_ERROR;
  78847. }
  78848. inf_leave:
  78849. RESTORE();
  78850. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78851. if (updatewindow(strm, out)) {
  78852. state->mode = MEM;
  78853. return Z_MEM_ERROR;
  78854. }
  78855. in -= strm->avail_in;
  78856. out -= strm->avail_out;
  78857. strm->total_in += in;
  78858. strm->total_out += out;
  78859. state->total += out;
  78860. if (state->wrap && out)
  78861. strm->adler = state->check =
  78862. UPDATE(state->check, strm->next_out - out, out);
  78863. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78864. (state->mode == TYPE ? 128 : 0);
  78865. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78866. ret = Z_BUF_ERROR;
  78867. return ret;
  78868. }
  78869. int ZEXPORT inflateEnd (z_streamp strm)
  78870. {
  78871. struct inflate_state FAR *state;
  78872. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78873. return Z_STREAM_ERROR;
  78874. state = (struct inflate_state FAR *)strm->state;
  78875. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78876. ZFREE(strm, strm->state);
  78877. strm->state = Z_NULL;
  78878. Tracev((stderr, "inflate: end\n"));
  78879. return Z_OK;
  78880. }
  78881. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78882. {
  78883. struct inflate_state FAR *state;
  78884. unsigned long id_;
  78885. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78886. state = (struct inflate_state FAR *)strm->state;
  78887. if (state->wrap != 0 && state->mode != DICT)
  78888. return Z_STREAM_ERROR;
  78889. if (state->mode == DICT) {
  78890. id_ = adler32(0L, Z_NULL, 0);
  78891. id_ = adler32(id_, dictionary, dictLength);
  78892. if (id_ != state->check)
  78893. return Z_DATA_ERROR;
  78894. }
  78895. if (updatewindow(strm, strm->avail_out)) {
  78896. state->mode = MEM;
  78897. return Z_MEM_ERROR;
  78898. }
  78899. if (dictLength > state->wsize) {
  78900. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78901. state->wsize);
  78902. state->whave = state->wsize;
  78903. }
  78904. else {
  78905. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78906. dictLength);
  78907. state->whave = dictLength;
  78908. }
  78909. state->havedict = 1;
  78910. Tracev((stderr, "inflate: dictionary set\n"));
  78911. return Z_OK;
  78912. }
  78913. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78914. {
  78915. struct inflate_state FAR *state;
  78916. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78917. state = (struct inflate_state FAR *)strm->state;
  78918. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78919. state->head = head;
  78920. head->done = 0;
  78921. return Z_OK;
  78922. }
  78923. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78924. {
  78925. unsigned got;
  78926. unsigned next;
  78927. got = *have;
  78928. next = 0;
  78929. while (next < len && got < 4) {
  78930. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  78931. got++;
  78932. else if (buf[next])
  78933. got = 0;
  78934. else
  78935. got = 4 - got;
  78936. next++;
  78937. }
  78938. *have = got;
  78939. return next;
  78940. }
  78941. int ZEXPORT inflateSync (z_streamp strm)
  78942. {
  78943. unsigned len; /* number of bytes to look at or looked at */
  78944. unsigned long in, out; /* temporary to save total_in and total_out */
  78945. unsigned char buf[4]; /* to restore bit buffer to byte string */
  78946. struct inflate_state FAR *state;
  78947. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78948. state = (struct inflate_state FAR *)strm->state;
  78949. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  78950. if (state->mode != SYNC) {
  78951. state->mode = SYNC;
  78952. state->hold <<= state->bits & 7;
  78953. state->bits -= state->bits & 7;
  78954. len = 0;
  78955. while (state->bits >= 8) {
  78956. buf[len++] = (unsigned char)(state->hold);
  78957. state->hold >>= 8;
  78958. state->bits -= 8;
  78959. }
  78960. state->have = 0;
  78961. syncsearch(&(state->have), buf, len);
  78962. }
  78963. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  78964. strm->avail_in -= len;
  78965. strm->next_in += len;
  78966. strm->total_in += len;
  78967. if (state->have != 4) return Z_DATA_ERROR;
  78968. in = strm->total_in; out = strm->total_out;
  78969. inflateReset(strm);
  78970. strm->total_in = in; strm->total_out = out;
  78971. state->mode = TYPE;
  78972. return Z_OK;
  78973. }
  78974. int ZEXPORT inflateSyncPoint (z_streamp strm)
  78975. {
  78976. struct inflate_state FAR *state;
  78977. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78978. state = (struct inflate_state FAR *)strm->state;
  78979. return state->mode == STORED && state->bits == 0;
  78980. }
  78981. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  78982. {
  78983. struct inflate_state FAR *state;
  78984. struct inflate_state FAR *copy;
  78985. unsigned char FAR *window;
  78986. unsigned wsize;
  78987. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  78988. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  78989. return Z_STREAM_ERROR;
  78990. state = (struct inflate_state FAR *)source->state;
  78991. copy = (struct inflate_state FAR *)
  78992. ZALLOC(source, 1, sizeof(struct inflate_state));
  78993. if (copy == Z_NULL) return Z_MEM_ERROR;
  78994. window = Z_NULL;
  78995. if (state->window != Z_NULL) {
  78996. window = (unsigned char FAR *)
  78997. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  78998. if (window == Z_NULL) {
  78999. ZFREE(source, copy);
  79000. return Z_MEM_ERROR;
  79001. }
  79002. }
  79003. zmemcpy(dest, source, sizeof(z_stream));
  79004. zmemcpy(copy, state, sizeof(struct inflate_state));
  79005. if (state->lencode >= state->codes &&
  79006. state->lencode <= state->codes + ENOUGH - 1) {
  79007. copy->lencode = copy->codes + (state->lencode - state->codes);
  79008. copy->distcode = copy->codes + (state->distcode - state->codes);
  79009. }
  79010. copy->next = copy->codes + (state->next - state->codes);
  79011. if (window != Z_NULL) {
  79012. wsize = 1U << state->wbits;
  79013. zmemcpy(window, state->window, wsize);
  79014. }
  79015. copy->window = window;
  79016. dest->state = (struct internal_state FAR *)copy;
  79017. return Z_OK;
  79018. }
  79019. /*** End of inlined file: inflate.c ***/
  79020. /*** Start of inlined file: inftrees.c ***/
  79021. #define MAXBITS 15
  79022. const char inflate_copyright[] =
  79023. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79024. int inflate_table (codetype type,
  79025. unsigned short FAR *lens,
  79026. unsigned codes,
  79027. code FAR * FAR *table,
  79028. unsigned FAR *bits,
  79029. unsigned short FAR *work)
  79030. {
  79031. unsigned len; /* a code's length in bits */
  79032. unsigned sym; /* index of code symbols */
  79033. unsigned min, max; /* minimum and maximum code lengths */
  79034. unsigned root; /* number of index bits for root table */
  79035. unsigned curr; /* number of index bits for current table */
  79036. unsigned drop; /* code bits to drop for sub-table */
  79037. int left; /* number of prefix codes available */
  79038. unsigned used; /* code entries in table used */
  79039. unsigned huff; /* Huffman code */
  79040. unsigned incr; /* for incrementing code, index */
  79041. unsigned fill; /* index for replicating entries */
  79042. unsigned low; /* low bits for current root entry */
  79043. unsigned mask; /* mask for low root bits */
  79044. code thisx; /* table entry for duplication */
  79045. code FAR *next; /* next available space in table */
  79046. const unsigned short FAR *base; /* base value table to use */
  79047. const unsigned short FAR *extra; /* extra bits table to use */
  79048. int end; /* use base and extra for symbol > end */
  79049. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79050. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79051. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79052. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79053. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79054. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79055. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79056. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79057. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79058. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79059. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79060. 8193, 12289, 16385, 24577, 0, 0};
  79061. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79062. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79063. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79064. 28, 28, 29, 29, 64, 64};
  79065. for (len = 0; len <= MAXBITS; len++)
  79066. count[len] = 0;
  79067. for (sym = 0; sym < codes; sym++)
  79068. count[lens[sym]]++;
  79069. root = *bits;
  79070. for (max = MAXBITS; max >= 1; max--)
  79071. if (count[max] != 0) break;
  79072. if (root > max) root = max;
  79073. if (max == 0) { /* no symbols to code at all */
  79074. thisx.op = (unsigned char)64; /* invalid code marker */
  79075. thisx.bits = (unsigned char)1;
  79076. thisx.val = (unsigned short)0;
  79077. *(*table)++ = thisx; /* make a table to force an error */
  79078. *(*table)++ = thisx;
  79079. *bits = 1;
  79080. return 0; /* no symbols, but wait for decoding to report error */
  79081. }
  79082. for (min = 1; min <= MAXBITS; min++)
  79083. if (count[min] != 0) break;
  79084. if (root < min) root = min;
  79085. left = 1;
  79086. for (len = 1; len <= MAXBITS; len++) {
  79087. left <<= 1;
  79088. left -= count[len];
  79089. if (left < 0) return -1; /* over-subscribed */
  79090. }
  79091. if (left > 0 && (type == CODES || max != 1))
  79092. return -1; /* incomplete set */
  79093. offs[1] = 0;
  79094. for (len = 1; len < MAXBITS; len++)
  79095. offs[len + 1] = offs[len] + count[len];
  79096. for (sym = 0; sym < codes; sym++)
  79097. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79098. switch (type) {
  79099. case CODES:
  79100. base = extra = work; /* dummy value--not used */
  79101. end = 19;
  79102. break;
  79103. case LENS:
  79104. base = lbase;
  79105. base -= 257;
  79106. extra = lext;
  79107. extra -= 257;
  79108. end = 256;
  79109. break;
  79110. default: /* DISTS */
  79111. base = dbase;
  79112. extra = dext;
  79113. end = -1;
  79114. }
  79115. huff = 0; /* starting code */
  79116. sym = 0; /* starting code symbol */
  79117. len = min; /* starting code length */
  79118. next = *table; /* current table to fill in */
  79119. curr = root; /* current table index bits */
  79120. drop = 0; /* current bits to drop from code for index */
  79121. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79122. used = 1U << root; /* use root table entries */
  79123. mask = used - 1; /* mask for comparing low */
  79124. if (type == LENS && used >= ENOUGH - MAXD)
  79125. return 1;
  79126. for (;;) {
  79127. thisx.bits = (unsigned char)(len - drop);
  79128. if ((int)(work[sym]) < end) {
  79129. thisx.op = (unsigned char)0;
  79130. thisx.val = work[sym];
  79131. }
  79132. else if ((int)(work[sym]) > end) {
  79133. thisx.op = (unsigned char)(extra[work[sym]]);
  79134. thisx.val = base[work[sym]];
  79135. }
  79136. else {
  79137. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79138. thisx.val = 0;
  79139. }
  79140. incr = 1U << (len - drop);
  79141. fill = 1U << curr;
  79142. min = fill; /* save offset to next table */
  79143. do {
  79144. fill -= incr;
  79145. next[(huff >> drop) + fill] = thisx;
  79146. } while (fill != 0);
  79147. incr = 1U << (len - 1);
  79148. while (huff & incr)
  79149. incr >>= 1;
  79150. if (incr != 0) {
  79151. huff &= incr - 1;
  79152. huff += incr;
  79153. }
  79154. else
  79155. huff = 0;
  79156. sym++;
  79157. if (--(count[len]) == 0) {
  79158. if (len == max) break;
  79159. len = lens[work[sym]];
  79160. }
  79161. if (len > root && (huff & mask) != low) {
  79162. if (drop == 0)
  79163. drop = root;
  79164. next += min; /* here min is 1 << curr */
  79165. curr = len - drop;
  79166. left = (int)(1 << curr);
  79167. while (curr + drop < max) {
  79168. left -= count[curr + drop];
  79169. if (left <= 0) break;
  79170. curr++;
  79171. left <<= 1;
  79172. }
  79173. used += 1U << curr;
  79174. if (type == LENS && used >= ENOUGH - MAXD)
  79175. return 1;
  79176. low = huff & mask;
  79177. (*table)[low].op = (unsigned char)curr;
  79178. (*table)[low].bits = (unsigned char)root;
  79179. (*table)[low].val = (unsigned short)(next - *table);
  79180. }
  79181. }
  79182. thisx.op = (unsigned char)64; /* invalid code marker */
  79183. thisx.bits = (unsigned char)(len - drop);
  79184. thisx.val = (unsigned short)0;
  79185. while (huff != 0) {
  79186. if (drop != 0 && (huff & mask) != low) {
  79187. drop = 0;
  79188. len = root;
  79189. next = *table;
  79190. thisx.bits = (unsigned char)len;
  79191. }
  79192. next[huff >> drop] = thisx;
  79193. incr = 1U << (len - 1);
  79194. while (huff & incr)
  79195. incr >>= 1;
  79196. if (incr != 0) {
  79197. huff &= incr - 1;
  79198. huff += incr;
  79199. }
  79200. else
  79201. huff = 0;
  79202. }
  79203. *table += used;
  79204. *bits = root;
  79205. return 0;
  79206. }
  79207. /*** End of inlined file: inftrees.c ***/
  79208. /*** Start of inlined file: trees.c ***/
  79209. #ifdef DEBUG
  79210. # include <ctype.h>
  79211. #endif
  79212. #define MAX_BL_BITS 7
  79213. #define END_BLOCK 256
  79214. #define REP_3_6 16
  79215. #define REPZ_3_10 17
  79216. #define REPZ_11_138 18
  79217. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79218. = {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};
  79219. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79220. = {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};
  79221. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79222. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79223. local const uch bl_order[BL_CODES]
  79224. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79225. #define Buf_size (8 * 2*sizeof(char))
  79226. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79227. #if defined(GEN_TREES_H) || !defined(STDC)
  79228. local ct_data static_ltree[L_CODES+2];
  79229. local ct_data static_dtree[D_CODES];
  79230. uch _dist_code[DIST_CODE_LEN];
  79231. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79232. local int base_length[LENGTH_CODES];
  79233. local int base_dist[D_CODES];
  79234. #else
  79235. /*** Start of inlined file: trees.h ***/
  79236. local const ct_data static_ltree[L_CODES+2] = {
  79237. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79238. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79239. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79240. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79241. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79242. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79243. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79244. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79245. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79246. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79247. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79248. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79249. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79250. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79251. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79252. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79253. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79254. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79255. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79256. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79257. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79258. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79259. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79260. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79261. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79262. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79263. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79264. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79265. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79266. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79267. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79268. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79269. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79270. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79271. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79272. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79273. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79274. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79275. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79276. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79277. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79278. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79279. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79280. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79281. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79282. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79283. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79284. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79285. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79286. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79287. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79288. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79289. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79290. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79291. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79292. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79293. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79294. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79295. };
  79296. local const ct_data static_dtree[D_CODES] = {
  79297. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79298. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79299. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79300. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79301. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79302. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79303. };
  79304. const uch _dist_code[DIST_CODE_LEN] = {
  79305. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79306. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79307. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79308. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79309. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79310. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79311. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79312. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79313. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79314. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79315. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79316. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79317. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79318. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79319. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79320. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79321. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79322. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79323. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79324. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79325. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79326. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79327. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79328. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79329. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79330. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79331. };
  79332. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79333. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79334. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79335. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79336. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79337. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79338. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79339. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79340. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79341. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79342. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79343. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79344. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79345. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79346. };
  79347. local const int base_length[LENGTH_CODES] = {
  79348. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79349. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79350. };
  79351. local const int base_dist[D_CODES] = {
  79352. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79353. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79354. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79355. };
  79356. /*** End of inlined file: trees.h ***/
  79357. #endif /* GEN_TREES_H */
  79358. struct static_tree_desc_s {
  79359. const ct_data *static_tree; /* static tree or NULL */
  79360. const intf *extra_bits; /* extra bits for each code or NULL */
  79361. int extra_base; /* base index for extra_bits */
  79362. int elems; /* max number of elements in the tree */
  79363. int max_length; /* max bit length for the codes */
  79364. };
  79365. local static_tree_desc static_l_desc =
  79366. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79367. local static_tree_desc static_d_desc =
  79368. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79369. local static_tree_desc static_bl_desc =
  79370. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79371. local void tr_static_init OF((void));
  79372. local void init_block OF((deflate_state *s));
  79373. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79374. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79375. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79376. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79377. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79378. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79379. local int build_bl_tree OF((deflate_state *s));
  79380. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79381. int blcodes));
  79382. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79383. ct_data *dtree));
  79384. local void set_data_type OF((deflate_state *s));
  79385. local unsigned bi_reverse OF((unsigned value, int length));
  79386. local void bi_windup OF((deflate_state *s));
  79387. local void bi_flush OF((deflate_state *s));
  79388. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79389. int header));
  79390. #ifdef GEN_TREES_H
  79391. local void gen_trees_header OF((void));
  79392. #endif
  79393. #ifndef DEBUG
  79394. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79395. #else /* DEBUG */
  79396. # define send_code(s, c, tree) \
  79397. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79398. send_bits(s, tree[c].Code, tree[c].Len); }
  79399. #endif
  79400. #define put_short(s, w) { \
  79401. put_byte(s, (uch)((w) & 0xff)); \
  79402. put_byte(s, (uch)((ush)(w) >> 8)); \
  79403. }
  79404. #ifdef DEBUG
  79405. local void send_bits OF((deflate_state *s, int value, int length));
  79406. local void send_bits (deflate_state *s, int value, int length)
  79407. {
  79408. Tracevv((stderr," l %2d v %4x ", length, value));
  79409. Assert(length > 0 && length <= 15, "invalid length");
  79410. s->bits_sent += (ulg)length;
  79411. if (s->bi_valid > (int)Buf_size - length) {
  79412. s->bi_buf |= (value << s->bi_valid);
  79413. put_short(s, s->bi_buf);
  79414. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79415. s->bi_valid += length - Buf_size;
  79416. } else {
  79417. s->bi_buf |= value << s->bi_valid;
  79418. s->bi_valid += length;
  79419. }
  79420. }
  79421. #else /* !DEBUG */
  79422. #define send_bits(s, value, length) \
  79423. { int len = length;\
  79424. if (s->bi_valid > (int)Buf_size - len) {\
  79425. int val = value;\
  79426. s->bi_buf |= (val << s->bi_valid);\
  79427. put_short(s, s->bi_buf);\
  79428. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79429. s->bi_valid += len - Buf_size;\
  79430. } else {\
  79431. s->bi_buf |= (value) << s->bi_valid;\
  79432. s->bi_valid += len;\
  79433. }\
  79434. }
  79435. #endif /* DEBUG */
  79436. local void tr_static_init()
  79437. {
  79438. #if defined(GEN_TREES_H) || !defined(STDC)
  79439. static int static_init_done = 0;
  79440. int n; /* iterates over tree elements */
  79441. int bits; /* bit counter */
  79442. int length; /* length value */
  79443. int code; /* code value */
  79444. int dist; /* distance index */
  79445. ush bl_count[MAX_BITS+1];
  79446. if (static_init_done) return;
  79447. static_l_desc.static_tree = static_ltree;
  79448. static_l_desc.extra_bits = extra_lbits;
  79449. static_d_desc.static_tree = static_dtree;
  79450. static_d_desc.extra_bits = extra_dbits;
  79451. static_bl_desc.extra_bits = extra_blbits;
  79452. length = 0;
  79453. for (code = 0; code < LENGTH_CODES-1; code++) {
  79454. base_length[code] = length;
  79455. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79456. _length_code[length++] = (uch)code;
  79457. }
  79458. }
  79459. Assert (length == 256, "tr_static_init: length != 256");
  79460. _length_code[length-1] = (uch)code;
  79461. dist = 0;
  79462. for (code = 0 ; code < 16; code++) {
  79463. base_dist[code] = dist;
  79464. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79465. _dist_code[dist++] = (uch)code;
  79466. }
  79467. }
  79468. Assert (dist == 256, "tr_static_init: dist != 256");
  79469. dist >>= 7; /* from now on, all distances are divided by 128 */
  79470. for ( ; code < D_CODES; code++) {
  79471. base_dist[code] = dist << 7;
  79472. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79473. _dist_code[256 + dist++] = (uch)code;
  79474. }
  79475. }
  79476. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79477. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79478. n = 0;
  79479. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79480. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79481. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79482. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79483. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79484. for (n = 0; n < D_CODES; n++) {
  79485. static_dtree[n].Len = 5;
  79486. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79487. }
  79488. static_init_done = 1;
  79489. # ifdef GEN_TREES_H
  79490. gen_trees_header();
  79491. # endif
  79492. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79493. }
  79494. #ifdef GEN_TREES_H
  79495. # ifndef DEBUG
  79496. # include <stdio.h>
  79497. # endif
  79498. # define SEPARATOR(i, last, width) \
  79499. ((i) == (last)? "\n};\n\n" : \
  79500. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79501. void gen_trees_header()
  79502. {
  79503. FILE *header = fopen("trees.h", "w");
  79504. int i;
  79505. Assert (header != NULL, "Can't open trees.h");
  79506. fprintf(header,
  79507. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79508. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79509. for (i = 0; i < L_CODES+2; i++) {
  79510. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79511. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79512. }
  79513. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79514. for (i = 0; i < D_CODES; i++) {
  79515. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79516. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79517. }
  79518. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79519. for (i = 0; i < DIST_CODE_LEN; i++) {
  79520. fprintf(header, "%2u%s", _dist_code[i],
  79521. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79522. }
  79523. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79524. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79525. fprintf(header, "%2u%s", _length_code[i],
  79526. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79527. }
  79528. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79529. for (i = 0; i < LENGTH_CODES; i++) {
  79530. fprintf(header, "%1u%s", base_length[i],
  79531. SEPARATOR(i, LENGTH_CODES-1, 20));
  79532. }
  79533. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79534. for (i = 0; i < D_CODES; i++) {
  79535. fprintf(header, "%5u%s", base_dist[i],
  79536. SEPARATOR(i, D_CODES-1, 10));
  79537. }
  79538. fclose(header);
  79539. }
  79540. #endif /* GEN_TREES_H */
  79541. void _tr_init(deflate_state *s)
  79542. {
  79543. tr_static_init();
  79544. s->l_desc.dyn_tree = s->dyn_ltree;
  79545. s->l_desc.stat_desc = &static_l_desc;
  79546. s->d_desc.dyn_tree = s->dyn_dtree;
  79547. s->d_desc.stat_desc = &static_d_desc;
  79548. s->bl_desc.dyn_tree = s->bl_tree;
  79549. s->bl_desc.stat_desc = &static_bl_desc;
  79550. s->bi_buf = 0;
  79551. s->bi_valid = 0;
  79552. s->last_eob_len = 8; /* enough lookahead for inflate */
  79553. #ifdef DEBUG
  79554. s->compressed_len = 0L;
  79555. s->bits_sent = 0L;
  79556. #endif
  79557. init_block(s);
  79558. }
  79559. local void init_block (deflate_state *s)
  79560. {
  79561. int n; /* iterates over tree elements */
  79562. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79563. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79564. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79565. s->dyn_ltree[END_BLOCK].Freq = 1;
  79566. s->opt_len = s->static_len = 0L;
  79567. s->last_lit = s->matches = 0;
  79568. }
  79569. #define SMALLEST 1
  79570. #define pqremove(s, tree, top) \
  79571. {\
  79572. top = s->heap[SMALLEST]; \
  79573. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79574. pqdownheap(s, tree, SMALLEST); \
  79575. }
  79576. #define smaller(tree, n, m, depth) \
  79577. (tree[n].Freq < tree[m].Freq || \
  79578. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79579. local void pqdownheap (deflate_state *s,
  79580. ct_data *tree, /* the tree to restore */
  79581. int k) /* node to move down */
  79582. {
  79583. int v = s->heap[k];
  79584. int j = k << 1; /* left son of k */
  79585. while (j <= s->heap_len) {
  79586. if (j < s->heap_len &&
  79587. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79588. j++;
  79589. }
  79590. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79591. s->heap[k] = s->heap[j]; k = j;
  79592. j <<= 1;
  79593. }
  79594. s->heap[k] = v;
  79595. }
  79596. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79597. {
  79598. ct_data *tree = desc->dyn_tree;
  79599. int max_code = desc->max_code;
  79600. const ct_data *stree = desc->stat_desc->static_tree;
  79601. const intf *extra = desc->stat_desc->extra_bits;
  79602. int base = desc->stat_desc->extra_base;
  79603. int max_length = desc->stat_desc->max_length;
  79604. int h; /* heap index */
  79605. int n, m; /* iterate over the tree elements */
  79606. int bits; /* bit length */
  79607. int xbits; /* extra bits */
  79608. ush f; /* frequency */
  79609. int overflow = 0; /* number of elements with bit length too large */
  79610. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79611. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79612. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79613. n = s->heap[h];
  79614. bits = tree[tree[n].Dad].Len + 1;
  79615. if (bits > max_length) bits = max_length, overflow++;
  79616. tree[n].Len = (ush)bits;
  79617. if (n > max_code) continue; /* not a leaf node */
  79618. s->bl_count[bits]++;
  79619. xbits = 0;
  79620. if (n >= base) xbits = extra[n-base];
  79621. f = tree[n].Freq;
  79622. s->opt_len += (ulg)f * (bits + xbits);
  79623. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79624. }
  79625. if (overflow == 0) return;
  79626. Trace((stderr,"\nbit length overflow\n"));
  79627. do {
  79628. bits = max_length-1;
  79629. while (s->bl_count[bits] == 0) bits--;
  79630. s->bl_count[bits]--; /* move one leaf down the tree */
  79631. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79632. s->bl_count[max_length]--;
  79633. overflow -= 2;
  79634. } while (overflow > 0);
  79635. for (bits = max_length; bits != 0; bits--) {
  79636. n = s->bl_count[bits];
  79637. while (n != 0) {
  79638. m = s->heap[--h];
  79639. if (m > max_code) continue;
  79640. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79641. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79642. s->opt_len += ((long)bits - (long)tree[m].Len)
  79643. *(long)tree[m].Freq;
  79644. tree[m].Len = (ush)bits;
  79645. }
  79646. n--;
  79647. }
  79648. }
  79649. }
  79650. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79651. int max_code, /* largest code with non zero frequency */
  79652. ushf *bl_count) /* number of codes at each bit length */
  79653. {
  79654. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79655. ush code = 0; /* running code value */
  79656. int bits; /* bit index */
  79657. int n; /* code index */
  79658. for (bits = 1; bits <= MAX_BITS; bits++) {
  79659. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79660. }
  79661. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79662. "inconsistent bit counts");
  79663. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79664. for (n = 0; n <= max_code; n++) {
  79665. int len = tree[n].Len;
  79666. if (len == 0) continue;
  79667. tree[n].Code = bi_reverse(next_code[len]++, len);
  79668. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79669. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79670. }
  79671. }
  79672. local void build_tree (deflate_state *s,
  79673. tree_desc *desc) /* the tree descriptor */
  79674. {
  79675. ct_data *tree = desc->dyn_tree;
  79676. const ct_data *stree = desc->stat_desc->static_tree;
  79677. int elems = desc->stat_desc->elems;
  79678. int n, m; /* iterate over heap elements */
  79679. int max_code = -1; /* largest code with non zero frequency */
  79680. int node; /* new node being created */
  79681. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79682. for (n = 0; n < elems; n++) {
  79683. if (tree[n].Freq != 0) {
  79684. s->heap[++(s->heap_len)] = max_code = n;
  79685. s->depth[n] = 0;
  79686. } else {
  79687. tree[n].Len = 0;
  79688. }
  79689. }
  79690. while (s->heap_len < 2) {
  79691. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79692. tree[node].Freq = 1;
  79693. s->depth[node] = 0;
  79694. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79695. }
  79696. desc->max_code = max_code;
  79697. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79698. node = elems; /* next internal node of the tree */
  79699. do {
  79700. pqremove(s, tree, n); /* n = node of least frequency */
  79701. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79702. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79703. s->heap[--(s->heap_max)] = m;
  79704. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79705. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79706. s->depth[n] : s->depth[m]) + 1);
  79707. tree[n].Dad = tree[m].Dad = (ush)node;
  79708. #ifdef DUMP_BL_TREE
  79709. if (tree == s->bl_tree) {
  79710. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79711. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79712. }
  79713. #endif
  79714. s->heap[SMALLEST] = node++;
  79715. pqdownheap(s, tree, SMALLEST);
  79716. } while (s->heap_len >= 2);
  79717. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79718. gen_bitlen(s, (tree_desc *)desc);
  79719. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79720. }
  79721. local void scan_tree (deflate_state *s,
  79722. ct_data *tree, /* the tree to be scanned */
  79723. int max_code) /* and its largest code of non zero frequency */
  79724. {
  79725. int n; /* iterates over all tree elements */
  79726. int prevlen = -1; /* last emitted length */
  79727. int curlen; /* length of current code */
  79728. int nextlen = tree[0].Len; /* length of next code */
  79729. int count = 0; /* repeat count of the current code */
  79730. int max_count = 7; /* max repeat count */
  79731. int min_count = 4; /* min repeat count */
  79732. if (nextlen == 0) max_count = 138, min_count = 3;
  79733. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79734. for (n = 0; n <= max_code; n++) {
  79735. curlen = nextlen; nextlen = tree[n+1].Len;
  79736. if (++count < max_count && curlen == nextlen) {
  79737. continue;
  79738. } else if (count < min_count) {
  79739. s->bl_tree[curlen].Freq += count;
  79740. } else if (curlen != 0) {
  79741. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79742. s->bl_tree[REP_3_6].Freq++;
  79743. } else if (count <= 10) {
  79744. s->bl_tree[REPZ_3_10].Freq++;
  79745. } else {
  79746. s->bl_tree[REPZ_11_138].Freq++;
  79747. }
  79748. count = 0; prevlen = curlen;
  79749. if (nextlen == 0) {
  79750. max_count = 138, min_count = 3;
  79751. } else if (curlen == nextlen) {
  79752. max_count = 6, min_count = 3;
  79753. } else {
  79754. max_count = 7, min_count = 4;
  79755. }
  79756. }
  79757. }
  79758. local void send_tree (deflate_state *s,
  79759. ct_data *tree, /* the tree to be scanned */
  79760. int max_code) /* and its largest code of non zero frequency */
  79761. {
  79762. int n; /* iterates over all tree elements */
  79763. int prevlen = -1; /* last emitted length */
  79764. int curlen; /* length of current code */
  79765. int nextlen = tree[0].Len; /* length of next code */
  79766. int count = 0; /* repeat count of the current code */
  79767. int max_count = 7; /* max repeat count */
  79768. int min_count = 4; /* min repeat count */
  79769. /* guard already set */
  79770. if (nextlen == 0) max_count = 138, min_count = 3;
  79771. for (n = 0; n <= max_code; n++) {
  79772. curlen = nextlen; nextlen = tree[n+1].Len;
  79773. if (++count < max_count && curlen == nextlen) {
  79774. continue;
  79775. } else if (count < min_count) {
  79776. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79777. } else if (curlen != 0) {
  79778. if (curlen != prevlen) {
  79779. send_code(s, curlen, s->bl_tree); count--;
  79780. }
  79781. Assert(count >= 3 && count <= 6, " 3_6?");
  79782. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79783. } else if (count <= 10) {
  79784. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79785. } else {
  79786. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79787. }
  79788. count = 0; prevlen = curlen;
  79789. if (nextlen == 0) {
  79790. max_count = 138, min_count = 3;
  79791. } else if (curlen == nextlen) {
  79792. max_count = 6, min_count = 3;
  79793. } else {
  79794. max_count = 7, min_count = 4;
  79795. }
  79796. }
  79797. }
  79798. local int build_bl_tree (deflate_state *s)
  79799. {
  79800. int max_blindex; /* index of last bit length code of non zero freq */
  79801. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79802. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79803. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79804. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79805. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79806. }
  79807. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79808. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79809. s->opt_len, s->static_len));
  79810. return max_blindex;
  79811. }
  79812. local void send_all_trees (deflate_state *s,
  79813. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79814. {
  79815. int rank; /* index in bl_order */
  79816. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79817. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79818. "too many codes");
  79819. Tracev((stderr, "\nbl counts: "));
  79820. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79821. send_bits(s, dcodes-1, 5);
  79822. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79823. for (rank = 0; rank < blcodes; rank++) {
  79824. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79825. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79826. }
  79827. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79828. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79829. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79830. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79831. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79832. }
  79833. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79834. {
  79835. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79836. #ifdef DEBUG
  79837. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79838. s->compressed_len += (stored_len + 4) << 3;
  79839. #endif
  79840. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79841. }
  79842. void _tr_align (deflate_state *s)
  79843. {
  79844. send_bits(s, STATIC_TREES<<1, 3);
  79845. send_code(s, END_BLOCK, static_ltree);
  79846. #ifdef DEBUG
  79847. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79848. #endif
  79849. bi_flush(s);
  79850. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79851. send_bits(s, STATIC_TREES<<1, 3);
  79852. send_code(s, END_BLOCK, static_ltree);
  79853. #ifdef DEBUG
  79854. s->compressed_len += 10L;
  79855. #endif
  79856. bi_flush(s);
  79857. }
  79858. s->last_eob_len = 7;
  79859. }
  79860. void _tr_flush_block (deflate_state *s,
  79861. charf *buf, /* input block, or NULL if too old */
  79862. ulg stored_len, /* length of input block */
  79863. int eof) /* true if this is the last block for a file */
  79864. {
  79865. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79866. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79867. if (s->level > 0) {
  79868. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79869. set_data_type(s);
  79870. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79871. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79872. s->static_len));
  79873. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79874. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79875. s->static_len));
  79876. max_blindex = build_bl_tree(s);
  79877. opt_lenb = (s->opt_len+3+7)>>3;
  79878. static_lenb = (s->static_len+3+7)>>3;
  79879. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79880. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79881. s->last_lit));
  79882. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79883. } else {
  79884. Assert(buf != (char*)0, "lost buf");
  79885. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79886. }
  79887. #ifdef FORCE_STORED
  79888. if (buf != (char*)0) { /* force stored block */
  79889. #else
  79890. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79891. #endif
  79892. _tr_stored_block(s, buf, stored_len, eof);
  79893. #ifdef FORCE_STATIC
  79894. } else if (static_lenb >= 0) { /* force static trees */
  79895. #else
  79896. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79897. #endif
  79898. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79899. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79900. #ifdef DEBUG
  79901. s->compressed_len += 3 + s->static_len;
  79902. #endif
  79903. } else {
  79904. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79905. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79906. max_blindex+1);
  79907. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79908. #ifdef DEBUG
  79909. s->compressed_len += 3 + s->opt_len;
  79910. #endif
  79911. }
  79912. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79913. init_block(s);
  79914. if (eof) {
  79915. bi_windup(s);
  79916. #ifdef DEBUG
  79917. s->compressed_len += 7; /* align on byte boundary */
  79918. #endif
  79919. }
  79920. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79921. s->compressed_len-7*eof));
  79922. }
  79923. int _tr_tally (deflate_state *s,
  79924. unsigned dist, /* distance of matched string */
  79925. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79926. {
  79927. s->d_buf[s->last_lit] = (ush)dist;
  79928. s->l_buf[s->last_lit++] = (uch)lc;
  79929. if (dist == 0) {
  79930. s->dyn_ltree[lc].Freq++;
  79931. } else {
  79932. s->matches++;
  79933. dist--; /* dist = match distance - 1 */
  79934. Assert((ush)dist < (ush)MAX_DIST(s) &&
  79935. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  79936. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  79937. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  79938. s->dyn_dtree[d_code(dist)].Freq++;
  79939. }
  79940. #ifdef TRUNCATE_BLOCK
  79941. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  79942. ulg out_length = (ulg)s->last_lit*8L;
  79943. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  79944. int dcode;
  79945. for (dcode = 0; dcode < D_CODES; dcode++) {
  79946. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  79947. (5L+extra_dbits[dcode]);
  79948. }
  79949. out_length >>= 3;
  79950. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  79951. s->last_lit, in_length, out_length,
  79952. 100L - out_length*100L/in_length));
  79953. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  79954. }
  79955. #endif
  79956. return (s->last_lit == s->lit_bufsize-1);
  79957. }
  79958. local void compress_block (deflate_state *s,
  79959. ct_data *ltree, /* literal tree */
  79960. ct_data *dtree) /* distance tree */
  79961. {
  79962. unsigned dist; /* distance of matched string */
  79963. int lc; /* match length or unmatched char (if dist == 0) */
  79964. unsigned lx = 0; /* running index in l_buf */
  79965. unsigned code; /* the code to send */
  79966. int extra; /* number of extra bits to send */
  79967. if (s->last_lit != 0) do {
  79968. dist = s->d_buf[lx];
  79969. lc = s->l_buf[lx++];
  79970. if (dist == 0) {
  79971. send_code(s, lc, ltree); /* send a literal byte */
  79972. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  79973. } else {
  79974. code = _length_code[lc];
  79975. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  79976. extra = extra_lbits[code];
  79977. if (extra != 0) {
  79978. lc -= base_length[code];
  79979. send_bits(s, lc, extra); /* send the extra length bits */
  79980. }
  79981. dist--; /* dist is now the match distance - 1 */
  79982. code = d_code(dist);
  79983. Assert (code < D_CODES, "bad d_code");
  79984. send_code(s, code, dtree); /* send the distance code */
  79985. extra = extra_dbits[code];
  79986. if (extra != 0) {
  79987. dist -= base_dist[code];
  79988. send_bits(s, dist, extra); /* send the extra distance bits */
  79989. }
  79990. } /* literal or match pair ? */
  79991. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  79992. "pendingBuf overflow");
  79993. } while (lx < s->last_lit);
  79994. send_code(s, END_BLOCK, ltree);
  79995. s->last_eob_len = ltree[END_BLOCK].Len;
  79996. }
  79997. local void set_data_type (deflate_state *s)
  79998. {
  79999. int n;
  80000. for (n = 0; n < 9; n++)
  80001. if (s->dyn_ltree[n].Freq != 0)
  80002. break;
  80003. if (n == 9)
  80004. for (n = 14; n < 32; n++)
  80005. if (s->dyn_ltree[n].Freq != 0)
  80006. break;
  80007. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80008. }
  80009. local unsigned bi_reverse (unsigned code, int len)
  80010. {
  80011. register unsigned res = 0;
  80012. do {
  80013. res |= code & 1;
  80014. code >>= 1, res <<= 1;
  80015. } while (--len > 0);
  80016. return res >> 1;
  80017. }
  80018. local void bi_flush (deflate_state *s)
  80019. {
  80020. if (s->bi_valid == 16) {
  80021. put_short(s, s->bi_buf);
  80022. s->bi_buf = 0;
  80023. s->bi_valid = 0;
  80024. } else if (s->bi_valid >= 8) {
  80025. put_byte(s, (Byte)s->bi_buf);
  80026. s->bi_buf >>= 8;
  80027. s->bi_valid -= 8;
  80028. }
  80029. }
  80030. local void bi_windup (deflate_state *s)
  80031. {
  80032. if (s->bi_valid > 8) {
  80033. put_short(s, s->bi_buf);
  80034. } else if (s->bi_valid > 0) {
  80035. put_byte(s, (Byte)s->bi_buf);
  80036. }
  80037. s->bi_buf = 0;
  80038. s->bi_valid = 0;
  80039. #ifdef DEBUG
  80040. s->bits_sent = (s->bits_sent+7) & ~7;
  80041. #endif
  80042. }
  80043. local void copy_block(deflate_state *s,
  80044. charf *buf, /* the input data */
  80045. unsigned len, /* its length */
  80046. int header) /* true if block header must be written */
  80047. {
  80048. bi_windup(s); /* align on byte boundary */
  80049. s->last_eob_len = 8; /* enough lookahead for inflate */
  80050. if (header) {
  80051. put_short(s, (ush)len);
  80052. put_short(s, (ush)~len);
  80053. #ifdef DEBUG
  80054. s->bits_sent += 2*16;
  80055. #endif
  80056. }
  80057. #ifdef DEBUG
  80058. s->bits_sent += (ulg)len<<3;
  80059. #endif
  80060. while (len--) {
  80061. put_byte(s, *buf++);
  80062. }
  80063. }
  80064. /*** End of inlined file: trees.c ***/
  80065. /*** Start of inlined file: zutil.c ***/
  80066. #ifndef NO_DUMMY_DECL
  80067. struct internal_state {int dummy;}; /* for buggy compilers */
  80068. #endif
  80069. const char * const z_errmsg[10] = {
  80070. "need dictionary", /* Z_NEED_DICT 2 */
  80071. "stream end", /* Z_STREAM_END 1 */
  80072. "", /* Z_OK 0 */
  80073. "file error", /* Z_ERRNO (-1) */
  80074. "stream error", /* Z_STREAM_ERROR (-2) */
  80075. "data error", /* Z_DATA_ERROR (-3) */
  80076. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80077. "buffer error", /* Z_BUF_ERROR (-5) */
  80078. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80079. ""};
  80080. #ifdef DEBUG
  80081. # ifndef verbose
  80082. # define verbose 0
  80083. # endif
  80084. int z_verbose = verbose;
  80085. void z_error (const char *m)
  80086. {
  80087. fprintf(stderr, "%s\n", m);
  80088. exit(1);
  80089. }
  80090. #endif
  80091. const char * ZEXPORT zError(int err)
  80092. {
  80093. return ERR_MSG(err);
  80094. }
  80095. #if defined(_WIN32_WCE)
  80096. int errno = 0;
  80097. #endif
  80098. #ifndef HAVE_MEMCPY
  80099. void zmemcpy(dest, source, len)
  80100. Bytef* dest;
  80101. const Bytef* source;
  80102. uInt len;
  80103. {
  80104. if (len == 0) return;
  80105. do {
  80106. *dest++ = *source++; /* ??? to be unrolled */
  80107. } while (--len != 0);
  80108. }
  80109. int zmemcmp(s1, s2, len)
  80110. const Bytef* s1;
  80111. const Bytef* s2;
  80112. uInt len;
  80113. {
  80114. uInt j;
  80115. for (j = 0; j < len; j++) {
  80116. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80117. }
  80118. return 0;
  80119. }
  80120. void zmemzero(dest, len)
  80121. Bytef* dest;
  80122. uInt len;
  80123. {
  80124. if (len == 0) return;
  80125. do {
  80126. *dest++ = 0; /* ??? to be unrolled */
  80127. } while (--len != 0);
  80128. }
  80129. #endif
  80130. #ifdef SYS16BIT
  80131. #ifdef __TURBOC__
  80132. # define MY_ZCALLOC
  80133. #define MAX_PTR 10
  80134. local int next_ptr = 0;
  80135. typedef struct ptr_table_s {
  80136. voidpf org_ptr;
  80137. voidpf new_ptr;
  80138. } ptr_table;
  80139. local ptr_table table[MAX_PTR];
  80140. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80141. {
  80142. voidpf buf = opaque; /* just to make some compilers happy */
  80143. ulg bsize = (ulg)items*size;
  80144. if (bsize < 65520L) {
  80145. buf = farmalloc(bsize);
  80146. if (*(ush*)&buf != 0) return buf;
  80147. } else {
  80148. buf = farmalloc(bsize + 16L);
  80149. }
  80150. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80151. table[next_ptr].org_ptr = buf;
  80152. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80153. *(ush*)&buf = 0;
  80154. table[next_ptr++].new_ptr = buf;
  80155. return buf;
  80156. }
  80157. void zcfree (voidpf opaque, voidpf ptr)
  80158. {
  80159. int n;
  80160. if (*(ush*)&ptr != 0) { /* object < 64K */
  80161. farfree(ptr);
  80162. return;
  80163. }
  80164. for (n = 0; n < next_ptr; n++) {
  80165. if (ptr != table[n].new_ptr) continue;
  80166. farfree(table[n].org_ptr);
  80167. while (++n < next_ptr) {
  80168. table[n-1] = table[n];
  80169. }
  80170. next_ptr--;
  80171. return;
  80172. }
  80173. ptr = opaque; /* just to make some compilers happy */
  80174. Assert(0, "zcfree: ptr not found");
  80175. }
  80176. #endif /* __TURBOC__ */
  80177. #ifdef M_I86
  80178. # define MY_ZCALLOC
  80179. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80180. # define _halloc halloc
  80181. # define _hfree hfree
  80182. #endif
  80183. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80184. {
  80185. if (opaque) opaque = 0; /* to make compiler happy */
  80186. return _halloc((long)items, size);
  80187. }
  80188. void zcfree (voidpf opaque, voidpf ptr)
  80189. {
  80190. if (opaque) opaque = 0; /* to make compiler happy */
  80191. _hfree(ptr);
  80192. }
  80193. #endif /* M_I86 */
  80194. #endif /* SYS16BIT */
  80195. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80196. #ifndef STDC
  80197. extern voidp malloc OF((uInt size));
  80198. extern voidp calloc OF((uInt items, uInt size));
  80199. extern void free OF((voidpf ptr));
  80200. #endif
  80201. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80202. {
  80203. if (opaque) items += size - size; /* make compiler happy */
  80204. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80205. (voidpf)calloc(items, size);
  80206. }
  80207. void zcfree (voidpf opaque, voidpf ptr)
  80208. {
  80209. free(ptr);
  80210. if (opaque) return; /* make compiler happy */
  80211. }
  80212. #endif /* MY_ZCALLOC */
  80213. /*** End of inlined file: zutil.c ***/
  80214. #undef Byte
  80215. }
  80216. #else
  80217. #include <zlib.h>
  80218. #endif
  80219. }
  80220. #if JUCE_MSVC
  80221. #pragma warning (pop)
  80222. #endif
  80223. BEGIN_JUCE_NAMESPACE
  80224. // internal helper object that holds the zlib structures so they don't have to be
  80225. // included publicly.
  80226. class GZIPDecompressHelper
  80227. {
  80228. public:
  80229. GZIPDecompressHelper (const bool noWrap)
  80230. : finished (true),
  80231. needsDictionary (false),
  80232. error (true),
  80233. streamIsValid (false),
  80234. data (0),
  80235. dataSize (0)
  80236. {
  80237. using namespace zlibNamespace;
  80238. zerostruct (stream);
  80239. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80240. finished = error = ! streamIsValid;
  80241. }
  80242. ~GZIPDecompressHelper()
  80243. {
  80244. using namespace zlibNamespace;
  80245. if (streamIsValid)
  80246. inflateEnd (&stream);
  80247. }
  80248. bool needsInput() const throw() { return dataSize <= 0; }
  80249. void setInput (uint8* const data_, const int size) throw()
  80250. {
  80251. data = data_;
  80252. dataSize = size;
  80253. }
  80254. int doNextBlock (uint8* const dest, const int destSize)
  80255. {
  80256. using namespace zlibNamespace;
  80257. if (streamIsValid && data != 0 && ! finished)
  80258. {
  80259. stream.next_in = data;
  80260. stream.next_out = dest;
  80261. stream.avail_in = dataSize;
  80262. stream.avail_out = destSize;
  80263. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80264. {
  80265. case Z_STREAM_END:
  80266. finished = true;
  80267. // deliberate fall-through
  80268. case Z_OK:
  80269. data += dataSize - stream.avail_in;
  80270. dataSize = stream.avail_in;
  80271. return destSize - stream.avail_out;
  80272. case Z_NEED_DICT:
  80273. needsDictionary = true;
  80274. data += dataSize - stream.avail_in;
  80275. dataSize = stream.avail_in;
  80276. break;
  80277. case Z_DATA_ERROR:
  80278. case Z_MEM_ERROR:
  80279. error = true;
  80280. default:
  80281. break;
  80282. }
  80283. }
  80284. return 0;
  80285. }
  80286. bool finished, needsDictionary, error, streamIsValid;
  80287. private:
  80288. zlibNamespace::z_stream stream;
  80289. uint8* data;
  80290. int dataSize;
  80291. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80292. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80293. };
  80294. const int gzipDecompBufferSize = 32768;
  80295. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80296. const bool deleteSourceWhenDestroyed,
  80297. const bool noWrap_,
  80298. const int64 uncompressedStreamLength_)
  80299. : sourceStream (sourceStream_),
  80300. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80301. uncompressedStreamLength (uncompressedStreamLength_),
  80302. noWrap (noWrap_),
  80303. isEof (false),
  80304. activeBufferSize (0),
  80305. originalSourcePos (sourceStream_->getPosition()),
  80306. currentPos (0),
  80307. buffer (gzipDecompBufferSize),
  80308. helper (new GZIPDecompressHelper (noWrap_))
  80309. {
  80310. }
  80311. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80312. {
  80313. }
  80314. int64 GZIPDecompressorInputStream::getTotalLength()
  80315. {
  80316. return uncompressedStreamLength;
  80317. }
  80318. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80319. {
  80320. if ((howMany > 0) && ! isEof)
  80321. {
  80322. jassert (destBuffer != 0);
  80323. if (destBuffer != 0)
  80324. {
  80325. int numRead = 0;
  80326. uint8* d = static_cast <uint8*> (destBuffer);
  80327. while (! helper->error)
  80328. {
  80329. const int n = helper->doNextBlock (d, howMany);
  80330. currentPos += n;
  80331. if (n == 0)
  80332. {
  80333. if (helper->finished || helper->needsDictionary)
  80334. {
  80335. isEof = true;
  80336. return numRead;
  80337. }
  80338. if (helper->needsInput())
  80339. {
  80340. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80341. if (activeBufferSize > 0)
  80342. {
  80343. helper->setInput (buffer, activeBufferSize);
  80344. }
  80345. else
  80346. {
  80347. isEof = true;
  80348. return numRead;
  80349. }
  80350. }
  80351. }
  80352. else
  80353. {
  80354. numRead += n;
  80355. howMany -= n;
  80356. d += n;
  80357. if (howMany <= 0)
  80358. return numRead;
  80359. }
  80360. }
  80361. }
  80362. }
  80363. return 0;
  80364. }
  80365. bool GZIPDecompressorInputStream::isExhausted()
  80366. {
  80367. return helper->error || isEof;
  80368. }
  80369. int64 GZIPDecompressorInputStream::getPosition()
  80370. {
  80371. return currentPos;
  80372. }
  80373. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80374. {
  80375. if (newPos < currentPos)
  80376. {
  80377. // to go backwards, reset the stream and start again..
  80378. isEof = false;
  80379. activeBufferSize = 0;
  80380. currentPos = 0;
  80381. helper = new GZIPDecompressHelper (noWrap);
  80382. sourceStream->setPosition (originalSourcePos);
  80383. }
  80384. skipNextBytes (newPos - currentPos);
  80385. return true;
  80386. }
  80387. END_JUCE_NAMESPACE
  80388. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80389. #endif
  80390. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80391. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80392. #if JUCE_USE_FLAC
  80393. #if JUCE_WINDOWS
  80394. #include <windows.h>
  80395. #endif
  80396. #ifdef _MSC_VER
  80397. #pragma warning (disable : 4505)
  80398. #pragma warning (push)
  80399. #endif
  80400. namespace FlacNamespace
  80401. {
  80402. #if JUCE_INCLUDE_FLAC_CODE
  80403. #define FLAC__NO_DLL 1
  80404. #if ! defined (SIZE_MAX)
  80405. #define SIZE_MAX 0xffffffff
  80406. #endif
  80407. #define __STDC_LIMIT_MACROS 1
  80408. /*** Start of inlined file: all.h ***/
  80409. #ifndef FLAC__ALL_H
  80410. #define FLAC__ALL_H
  80411. /*** Start of inlined file: export.h ***/
  80412. #ifndef FLAC__EXPORT_H
  80413. #define FLAC__EXPORT_H
  80414. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80415. #define FLAC_API
  80416. #else
  80417. #ifdef FLAC_API_EXPORTS
  80418. #define FLAC_API _declspec(dllexport)
  80419. #else
  80420. #define FLAC_API _declspec(dllimport)
  80421. #endif
  80422. #endif
  80423. #define FLAC_API_VERSION_CURRENT 10
  80424. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80425. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80426. #ifdef __cplusplus
  80427. extern "C" {
  80428. #endif
  80429. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80430. #ifdef __cplusplus
  80431. }
  80432. #endif
  80433. #endif
  80434. /*** End of inlined file: export.h ***/
  80435. /*** Start of inlined file: assert.h ***/
  80436. #ifndef FLAC__ASSERT_H
  80437. #define FLAC__ASSERT_H
  80438. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80439. #ifdef DEBUG
  80440. #include <assert.h>
  80441. #define FLAC__ASSERT(x) assert(x)
  80442. #define FLAC__ASSERT_DECLARATION(x) x
  80443. #else
  80444. #define FLAC__ASSERT(x)
  80445. #define FLAC__ASSERT_DECLARATION(x)
  80446. #endif
  80447. #endif
  80448. /*** End of inlined file: assert.h ***/
  80449. /*** Start of inlined file: callback.h ***/
  80450. #ifndef FLAC__CALLBACK_H
  80451. #define FLAC__CALLBACK_H
  80452. /*** Start of inlined file: ordinals.h ***/
  80453. #ifndef FLAC__ORDINALS_H
  80454. #define FLAC__ORDINALS_H
  80455. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80456. #include <inttypes.h>
  80457. #endif
  80458. typedef signed char FLAC__int8;
  80459. typedef unsigned char FLAC__uint8;
  80460. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80461. typedef __int16 FLAC__int16;
  80462. typedef __int32 FLAC__int32;
  80463. typedef __int64 FLAC__int64;
  80464. typedef unsigned __int16 FLAC__uint16;
  80465. typedef unsigned __int32 FLAC__uint32;
  80466. typedef unsigned __int64 FLAC__uint64;
  80467. #elif defined(__EMX__)
  80468. typedef short FLAC__int16;
  80469. typedef long FLAC__int32;
  80470. typedef long long FLAC__int64;
  80471. typedef unsigned short FLAC__uint16;
  80472. typedef unsigned long FLAC__uint32;
  80473. typedef unsigned long long FLAC__uint64;
  80474. #else
  80475. typedef int16_t FLAC__int16;
  80476. typedef int32_t FLAC__int32;
  80477. typedef int64_t FLAC__int64;
  80478. typedef uint16_t FLAC__uint16;
  80479. typedef uint32_t FLAC__uint32;
  80480. typedef uint64_t FLAC__uint64;
  80481. #endif
  80482. typedef int FLAC__bool;
  80483. typedef FLAC__uint8 FLAC__byte;
  80484. #ifdef true
  80485. #undef true
  80486. #endif
  80487. #ifdef false
  80488. #undef false
  80489. #endif
  80490. #ifndef __cplusplus
  80491. #define true 1
  80492. #define false 0
  80493. #endif
  80494. #endif
  80495. /*** End of inlined file: ordinals.h ***/
  80496. #include <stdlib.h> /* for size_t */
  80497. #ifdef __cplusplus
  80498. extern "C" {
  80499. #endif
  80500. typedef void* FLAC__IOHandle;
  80501. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80502. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80503. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80504. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80505. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80506. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80507. typedef struct {
  80508. FLAC__IOCallback_Read read;
  80509. FLAC__IOCallback_Write write;
  80510. FLAC__IOCallback_Seek seek;
  80511. FLAC__IOCallback_Tell tell;
  80512. FLAC__IOCallback_Eof eof;
  80513. FLAC__IOCallback_Close close;
  80514. } FLAC__IOCallbacks;
  80515. #ifdef __cplusplus
  80516. }
  80517. #endif
  80518. #endif
  80519. /*** End of inlined file: callback.h ***/
  80520. /*** Start of inlined file: format.h ***/
  80521. #ifndef FLAC__FORMAT_H
  80522. #define FLAC__FORMAT_H
  80523. #ifdef __cplusplus
  80524. extern "C" {
  80525. #endif
  80526. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80527. #define FLAC__MIN_BLOCK_SIZE (16u)
  80528. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80529. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80530. #define FLAC__MAX_CHANNELS (8u)
  80531. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80532. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80533. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80534. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80535. #define FLAC__MAX_LPC_ORDER (32u)
  80536. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80537. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80538. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80539. #define FLAC__MAX_FIXED_ORDER (4u)
  80540. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80541. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80542. extern FLAC_API const char *FLAC__VERSION_STRING;
  80543. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80544. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80545. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80546. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80547. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80548. typedef enum {
  80549. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80550. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80551. } FLAC__EntropyCodingMethodType;
  80552. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80553. typedef struct {
  80554. unsigned *parameters;
  80555. unsigned *raw_bits;
  80556. unsigned capacity_by_order;
  80557. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80558. typedef struct {
  80559. unsigned order;
  80560. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80561. } FLAC__EntropyCodingMethod_PartitionedRice;
  80562. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80563. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80564. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80565. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80566. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80567. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80568. typedef struct {
  80569. FLAC__EntropyCodingMethodType type;
  80570. union {
  80571. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80572. } data;
  80573. } FLAC__EntropyCodingMethod;
  80574. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80575. typedef enum {
  80576. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80577. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80578. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80579. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80580. } FLAC__SubframeType;
  80581. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80582. typedef struct {
  80583. FLAC__int32 value; /**< The constant signal value. */
  80584. } FLAC__Subframe_Constant;
  80585. typedef struct {
  80586. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80587. } FLAC__Subframe_Verbatim;
  80588. typedef struct {
  80589. FLAC__EntropyCodingMethod entropy_coding_method;
  80590. unsigned order;
  80591. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80592. const FLAC__int32 *residual;
  80593. } FLAC__Subframe_Fixed;
  80594. typedef struct {
  80595. FLAC__EntropyCodingMethod entropy_coding_method;
  80596. unsigned order;
  80597. unsigned qlp_coeff_precision;
  80598. int quantization_level;
  80599. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80600. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80601. const FLAC__int32 *residual;
  80602. } FLAC__Subframe_LPC;
  80603. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80604. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80605. typedef struct {
  80606. FLAC__SubframeType type;
  80607. union {
  80608. FLAC__Subframe_Constant constant;
  80609. FLAC__Subframe_Fixed fixed;
  80610. FLAC__Subframe_LPC lpc;
  80611. FLAC__Subframe_Verbatim verbatim;
  80612. } data;
  80613. unsigned wasted_bits;
  80614. } FLAC__Subframe;
  80615. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80616. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80617. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80618. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80619. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80620. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80621. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80622. typedef enum {
  80623. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80624. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80625. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80626. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80627. } FLAC__ChannelAssignment;
  80628. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80629. typedef enum {
  80630. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80631. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80632. } FLAC__FrameNumberType;
  80633. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80634. typedef struct {
  80635. unsigned blocksize;
  80636. unsigned sample_rate;
  80637. unsigned channels;
  80638. FLAC__ChannelAssignment channel_assignment;
  80639. unsigned bits_per_sample;
  80640. FLAC__FrameNumberType number_type;
  80641. union {
  80642. FLAC__uint32 frame_number;
  80643. FLAC__uint64 sample_number;
  80644. } number;
  80645. FLAC__uint8 crc;
  80646. } FLAC__FrameHeader;
  80647. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80648. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80649. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80650. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80651. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80652. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80653. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80654. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80655. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80656. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80657. typedef struct {
  80658. FLAC__uint16 crc;
  80659. } FLAC__FrameFooter;
  80660. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80661. typedef struct {
  80662. FLAC__FrameHeader header;
  80663. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80664. FLAC__FrameFooter footer;
  80665. } FLAC__Frame;
  80666. typedef enum {
  80667. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80668. FLAC__METADATA_TYPE_PADDING = 1,
  80669. FLAC__METADATA_TYPE_APPLICATION = 2,
  80670. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80671. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80672. FLAC__METADATA_TYPE_CUESHEET = 5,
  80673. FLAC__METADATA_TYPE_PICTURE = 6,
  80674. FLAC__METADATA_TYPE_UNDEFINED = 7
  80675. } FLAC__MetadataType;
  80676. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80677. typedef struct {
  80678. unsigned min_blocksize, max_blocksize;
  80679. unsigned min_framesize, max_framesize;
  80680. unsigned sample_rate;
  80681. unsigned channels;
  80682. unsigned bits_per_sample;
  80683. FLAC__uint64 total_samples;
  80684. FLAC__byte md5sum[16];
  80685. } FLAC__StreamMetadata_StreamInfo;
  80686. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80687. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80688. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80689. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80690. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80691. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80692. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80693. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80694. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80695. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80696. typedef struct {
  80697. int dummy;
  80698. } FLAC__StreamMetadata_Padding;
  80699. typedef struct {
  80700. FLAC__byte id[4];
  80701. FLAC__byte *data;
  80702. } FLAC__StreamMetadata_Application;
  80703. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80704. typedef struct {
  80705. FLAC__uint64 sample_number;
  80706. FLAC__uint64 stream_offset;
  80707. unsigned frame_samples;
  80708. } FLAC__StreamMetadata_SeekPoint;
  80709. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80710. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80711. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80712. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80713. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80714. typedef struct {
  80715. unsigned num_points;
  80716. FLAC__StreamMetadata_SeekPoint *points;
  80717. } FLAC__StreamMetadata_SeekTable;
  80718. typedef struct {
  80719. FLAC__uint32 length;
  80720. FLAC__byte *entry;
  80721. } FLAC__StreamMetadata_VorbisComment_Entry;
  80722. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80723. typedef struct {
  80724. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80725. FLAC__uint32 num_comments;
  80726. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80727. } FLAC__StreamMetadata_VorbisComment;
  80728. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80729. typedef struct {
  80730. FLAC__uint64 offset;
  80731. FLAC__byte number;
  80732. } FLAC__StreamMetadata_CueSheet_Index;
  80733. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80734. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80735. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80736. typedef struct {
  80737. FLAC__uint64 offset;
  80738. FLAC__byte number;
  80739. char isrc[13];
  80740. unsigned type:1;
  80741. unsigned pre_emphasis:1;
  80742. FLAC__byte num_indices;
  80743. FLAC__StreamMetadata_CueSheet_Index *indices;
  80744. } FLAC__StreamMetadata_CueSheet_Track;
  80745. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80746. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80747. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80748. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80749. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80750. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80751. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80752. typedef struct {
  80753. char media_catalog_number[129];
  80754. FLAC__uint64 lead_in;
  80755. FLAC__bool is_cd;
  80756. unsigned num_tracks;
  80757. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80758. } FLAC__StreamMetadata_CueSheet;
  80759. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80760. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80761. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80762. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80763. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80764. typedef enum {
  80765. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80766. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80767. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80768. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80769. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80770. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80771. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80772. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80773. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80774. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80775. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80776. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80777. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80778. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80779. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80780. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80781. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80782. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80783. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80784. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80785. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80786. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80787. } FLAC__StreamMetadata_Picture_Type;
  80788. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80789. typedef struct {
  80790. FLAC__StreamMetadata_Picture_Type type;
  80791. char *mime_type;
  80792. FLAC__byte *description;
  80793. FLAC__uint32 width;
  80794. FLAC__uint32 height;
  80795. FLAC__uint32 depth;
  80796. FLAC__uint32 colors;
  80797. FLAC__uint32 data_length;
  80798. FLAC__byte *data;
  80799. } FLAC__StreamMetadata_Picture;
  80800. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80801. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80802. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80803. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80804. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80805. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80806. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80807. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80808. typedef struct {
  80809. FLAC__byte *data;
  80810. } FLAC__StreamMetadata_Unknown;
  80811. typedef struct {
  80812. FLAC__MetadataType type;
  80813. FLAC__bool is_last;
  80814. unsigned length;
  80815. union {
  80816. FLAC__StreamMetadata_StreamInfo stream_info;
  80817. FLAC__StreamMetadata_Padding padding;
  80818. FLAC__StreamMetadata_Application application;
  80819. FLAC__StreamMetadata_SeekTable seek_table;
  80820. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80821. FLAC__StreamMetadata_CueSheet cue_sheet;
  80822. FLAC__StreamMetadata_Picture picture;
  80823. FLAC__StreamMetadata_Unknown unknown;
  80824. } data;
  80825. } FLAC__StreamMetadata;
  80826. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80827. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80828. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80829. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80830. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80831. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80832. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80833. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80834. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80835. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80836. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80837. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80838. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80839. #ifdef __cplusplus
  80840. }
  80841. #endif
  80842. #endif
  80843. /*** End of inlined file: format.h ***/
  80844. /*** Start of inlined file: metadata.h ***/
  80845. #ifndef FLAC__METADATA_H
  80846. #define FLAC__METADATA_H
  80847. #include <sys/types.h> /* for off_t */
  80848. #ifdef __cplusplus
  80849. extern "C" {
  80850. #endif
  80851. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80852. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80853. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80854. 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);
  80855. struct FLAC__Metadata_SimpleIterator;
  80856. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80857. typedef enum {
  80858. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80859. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80860. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80861. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80862. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80863. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80864. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80865. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80866. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80867. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80868. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80869. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80870. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80871. } FLAC__Metadata_SimpleIteratorStatus;
  80872. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80873. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80874. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80875. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80876. 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);
  80877. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80878. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80879. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80880. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80881. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80882. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80883. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80884. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80885. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80886. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80887. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80888. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80889. struct FLAC__Metadata_Chain;
  80890. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80891. struct FLAC__Metadata_Iterator;
  80892. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80893. typedef enum {
  80894. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80895. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80896. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80897. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80898. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80899. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80900. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80901. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80902. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80903. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80904. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80905. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80906. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80907. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80908. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80909. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80910. } FLAC__Metadata_ChainStatus;
  80911. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80912. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80913. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80914. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80915. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80916. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80917. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80918. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80919. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80920. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80921. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80922. 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);
  80923. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80924. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80925. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80926. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80927. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80928. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80929. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80930. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  80931. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  80932. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80933. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  80934. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80935. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80936. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  80937. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  80938. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  80939. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  80940. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  80941. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  80942. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80943. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80944. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  80945. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  80946. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  80947. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  80948. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  80949. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  80950. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  80951. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  80952. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80953. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  80954. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80955. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80956. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80957. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  80958. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  80959. 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);
  80960. 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);
  80961. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  80962. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  80963. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  80964. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  80965. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  80966. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  80967. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  80968. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  80969. 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);
  80970. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80971. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80972. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  80973. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80974. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80975. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  80976. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  80977. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  80978. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  80979. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  80980. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  80981. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  80982. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  80983. #ifdef __cplusplus
  80984. }
  80985. #endif
  80986. #endif
  80987. /*** End of inlined file: metadata.h ***/
  80988. /*** Start of inlined file: stream_decoder.h ***/
  80989. #ifndef FLAC__STREAM_DECODER_H
  80990. #define FLAC__STREAM_DECODER_H
  80991. #include <stdio.h> /* for FILE */
  80992. #ifdef __cplusplus
  80993. extern "C" {
  80994. #endif
  80995. typedef enum {
  80996. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  80997. FLAC__STREAM_DECODER_READ_METADATA,
  80998. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  80999. FLAC__STREAM_DECODER_READ_FRAME,
  81000. FLAC__STREAM_DECODER_END_OF_STREAM,
  81001. FLAC__STREAM_DECODER_OGG_ERROR,
  81002. FLAC__STREAM_DECODER_SEEK_ERROR,
  81003. FLAC__STREAM_DECODER_ABORTED,
  81004. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81005. FLAC__STREAM_DECODER_UNINITIALIZED
  81006. } FLAC__StreamDecoderState;
  81007. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81008. typedef enum {
  81009. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81010. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81011. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81012. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81013. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81014. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81015. } FLAC__StreamDecoderInitStatus;
  81016. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81017. typedef enum {
  81018. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81019. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81020. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81021. } FLAC__StreamDecoderReadStatus;
  81022. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81023. typedef enum {
  81024. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81025. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81026. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81027. } FLAC__StreamDecoderSeekStatus;
  81028. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81029. typedef enum {
  81030. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81031. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81032. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81033. } FLAC__StreamDecoderTellStatus;
  81034. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81035. typedef enum {
  81036. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81037. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81038. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81039. } FLAC__StreamDecoderLengthStatus;
  81040. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81041. typedef enum {
  81042. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81043. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81044. } FLAC__StreamDecoderWriteStatus;
  81045. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81046. typedef enum {
  81047. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81048. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81049. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81050. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81051. } FLAC__StreamDecoderErrorStatus;
  81052. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81053. struct FLAC__StreamDecoderProtected;
  81054. struct FLAC__StreamDecoderPrivate;
  81055. typedef struct {
  81056. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81057. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81058. } FLAC__StreamDecoder;
  81059. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81060. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81061. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81062. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81063. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81064. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81065. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81066. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81067. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81068. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81069. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81070. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81071. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81072. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81073. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81074. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81075. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81076. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81077. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81078. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81079. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81080. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81081. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81082. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81083. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81084. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81085. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81086. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81087. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81088. FLAC__StreamDecoder *decoder,
  81089. FLAC__StreamDecoderReadCallback read_callback,
  81090. FLAC__StreamDecoderSeekCallback seek_callback,
  81091. FLAC__StreamDecoderTellCallback tell_callback,
  81092. FLAC__StreamDecoderLengthCallback length_callback,
  81093. FLAC__StreamDecoderEofCallback eof_callback,
  81094. FLAC__StreamDecoderWriteCallback write_callback,
  81095. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81096. FLAC__StreamDecoderErrorCallback error_callback,
  81097. void *client_data
  81098. );
  81099. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81100. FLAC__StreamDecoder *decoder,
  81101. FLAC__StreamDecoderReadCallback read_callback,
  81102. FLAC__StreamDecoderSeekCallback seek_callback,
  81103. FLAC__StreamDecoderTellCallback tell_callback,
  81104. FLAC__StreamDecoderLengthCallback length_callback,
  81105. FLAC__StreamDecoderEofCallback eof_callback,
  81106. FLAC__StreamDecoderWriteCallback write_callback,
  81107. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81108. FLAC__StreamDecoderErrorCallback error_callback,
  81109. void *client_data
  81110. );
  81111. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81112. FLAC__StreamDecoder *decoder,
  81113. FILE *file,
  81114. FLAC__StreamDecoderWriteCallback write_callback,
  81115. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81116. FLAC__StreamDecoderErrorCallback error_callback,
  81117. void *client_data
  81118. );
  81119. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81120. FLAC__StreamDecoder *decoder,
  81121. FILE *file,
  81122. FLAC__StreamDecoderWriteCallback write_callback,
  81123. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81124. FLAC__StreamDecoderErrorCallback error_callback,
  81125. void *client_data
  81126. );
  81127. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81128. FLAC__StreamDecoder *decoder,
  81129. const char *filename,
  81130. FLAC__StreamDecoderWriteCallback write_callback,
  81131. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81132. FLAC__StreamDecoderErrorCallback error_callback,
  81133. void *client_data
  81134. );
  81135. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81136. FLAC__StreamDecoder *decoder,
  81137. const char *filename,
  81138. FLAC__StreamDecoderWriteCallback write_callback,
  81139. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81140. FLAC__StreamDecoderErrorCallback error_callback,
  81141. void *client_data
  81142. );
  81143. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81144. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81145. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81146. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81147. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81148. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81149. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81150. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81151. #ifdef __cplusplus
  81152. }
  81153. #endif
  81154. #endif
  81155. /*** End of inlined file: stream_decoder.h ***/
  81156. /*** Start of inlined file: stream_encoder.h ***/
  81157. #ifndef FLAC__STREAM_ENCODER_H
  81158. #define FLAC__STREAM_ENCODER_H
  81159. #include <stdio.h> /* for FILE */
  81160. #ifdef __cplusplus
  81161. extern "C" {
  81162. #endif
  81163. typedef enum {
  81164. FLAC__STREAM_ENCODER_OK = 0,
  81165. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81166. FLAC__STREAM_ENCODER_OGG_ERROR,
  81167. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81168. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81169. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81170. FLAC__STREAM_ENCODER_IO_ERROR,
  81171. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81172. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81173. } FLAC__StreamEncoderState;
  81174. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81175. typedef enum {
  81176. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81177. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81178. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81179. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81180. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81181. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81182. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81183. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81184. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81185. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81186. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81187. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81188. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81189. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81190. } FLAC__StreamEncoderInitStatus;
  81191. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81192. typedef enum {
  81193. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81194. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81195. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81196. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81197. } FLAC__StreamEncoderReadStatus;
  81198. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81199. typedef enum {
  81200. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81201. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81202. } FLAC__StreamEncoderWriteStatus;
  81203. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81204. typedef enum {
  81205. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81206. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81207. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81208. } FLAC__StreamEncoderSeekStatus;
  81209. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81210. typedef enum {
  81211. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81212. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81213. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81214. } FLAC__StreamEncoderTellStatus;
  81215. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81216. struct FLAC__StreamEncoderProtected;
  81217. struct FLAC__StreamEncoderPrivate;
  81218. typedef struct {
  81219. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81220. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81221. } FLAC__StreamEncoder;
  81222. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81223. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81224. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81225. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81226. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81227. 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);
  81228. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81229. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81230. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81231. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81232. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81233. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81234. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81235. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81236. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81237. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81238. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81239. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81240. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81241. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81242. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81243. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81244. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81245. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81246. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81247. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81248. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81249. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81250. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81251. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81252. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81253. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81254. 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);
  81255. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81256. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81257. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81258. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81259. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81260. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81261. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81262. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81263. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81264. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81265. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81266. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81267. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81268. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81269. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81270. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81271. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81272. 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);
  81273. 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);
  81274. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81275. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81276. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81277. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81278. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81279. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81280. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81281. #ifdef __cplusplus
  81282. }
  81283. #endif
  81284. #endif
  81285. /*** End of inlined file: stream_encoder.h ***/
  81286. #ifdef _MSC_VER
  81287. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81288. {
  81289. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81290. return (x>>16) | (x<<16);
  81291. }
  81292. #endif
  81293. #if defined(_MSC_VER) && defined(_X86_)
  81294. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81295. {
  81296. __asm {
  81297. mov edx, start
  81298. mov ecx, len
  81299. test ecx, ecx
  81300. loop1:
  81301. jz done1
  81302. mov eax, [edx]
  81303. bswap eax
  81304. mov [edx], eax
  81305. add edx, 4
  81306. dec ecx
  81307. jmp short loop1
  81308. done1:
  81309. }
  81310. }
  81311. #endif
  81312. #endif
  81313. /*** End of inlined file: all.h ***/
  81314. /*** Start of inlined file: bitmath.c ***/
  81315. /*** Start of inlined file: juce_FlacHeader.h ***/
  81316. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81317. // tasks..
  81318. #define VERSION "1.2.1"
  81319. #define FLAC__NO_DLL 1
  81320. #if JUCE_MSVC
  81321. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81322. #endif
  81323. #if JUCE_MAC
  81324. #define FLAC__SYS_DARWIN 1
  81325. #endif
  81326. /*** End of inlined file: juce_FlacHeader.h ***/
  81327. #if JUCE_USE_FLAC
  81328. #if HAVE_CONFIG_H
  81329. # include <config.h>
  81330. #endif
  81331. /*** Start of inlined file: bitmath.h ***/
  81332. #ifndef FLAC__PRIVATE__BITMATH_H
  81333. #define FLAC__PRIVATE__BITMATH_H
  81334. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81335. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81336. unsigned FLAC__bitmath_silog2(int v);
  81337. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81338. #endif
  81339. /*** End of inlined file: bitmath.h ***/
  81340. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81341. {
  81342. unsigned l = 0;
  81343. FLAC__ASSERT(v > 0);
  81344. while(v >>= 1)
  81345. l++;
  81346. return l;
  81347. }
  81348. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81349. {
  81350. unsigned l = 0;
  81351. FLAC__ASSERT(v > 0);
  81352. while(v >>= 1)
  81353. l++;
  81354. return l;
  81355. }
  81356. unsigned FLAC__bitmath_silog2(int v)
  81357. {
  81358. while(1) {
  81359. if(v == 0) {
  81360. return 0;
  81361. }
  81362. else if(v > 0) {
  81363. unsigned l = 0;
  81364. while(v) {
  81365. l++;
  81366. v >>= 1;
  81367. }
  81368. return l+1;
  81369. }
  81370. else if(v == -1) {
  81371. return 2;
  81372. }
  81373. else {
  81374. v++;
  81375. v = -v;
  81376. }
  81377. }
  81378. }
  81379. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81380. {
  81381. while(1) {
  81382. if(v == 0) {
  81383. return 0;
  81384. }
  81385. else if(v > 0) {
  81386. unsigned l = 0;
  81387. while(v) {
  81388. l++;
  81389. v >>= 1;
  81390. }
  81391. return l+1;
  81392. }
  81393. else if(v == -1) {
  81394. return 2;
  81395. }
  81396. else {
  81397. v++;
  81398. v = -v;
  81399. }
  81400. }
  81401. }
  81402. #endif
  81403. /*** End of inlined file: bitmath.c ***/
  81404. /*** Start of inlined file: bitreader.c ***/
  81405. /*** Start of inlined file: juce_FlacHeader.h ***/
  81406. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81407. // tasks..
  81408. #define VERSION "1.2.1"
  81409. #define FLAC__NO_DLL 1
  81410. #if JUCE_MSVC
  81411. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81412. #endif
  81413. #if JUCE_MAC
  81414. #define FLAC__SYS_DARWIN 1
  81415. #endif
  81416. /*** End of inlined file: juce_FlacHeader.h ***/
  81417. #if JUCE_USE_FLAC
  81418. #if HAVE_CONFIG_H
  81419. # include <config.h>
  81420. #endif
  81421. #include <stdlib.h> /* for malloc() */
  81422. #include <string.h> /* for memcpy(), memset() */
  81423. #ifdef _MSC_VER
  81424. #include <winsock.h> /* for ntohl() */
  81425. #elif defined FLAC__SYS_DARWIN
  81426. #include <machine/endian.h> /* for ntohl() */
  81427. #elif defined __MINGW32__
  81428. #include <winsock.h> /* for ntohl() */
  81429. #else
  81430. #include <netinet/in.h> /* for ntohl() */
  81431. #endif
  81432. /*** Start of inlined file: bitreader.h ***/
  81433. #ifndef FLAC__PRIVATE__BITREADER_H
  81434. #define FLAC__PRIVATE__BITREADER_H
  81435. #include <stdio.h> /* for FILE */
  81436. /*** Start of inlined file: cpu.h ***/
  81437. #ifndef FLAC__PRIVATE__CPU_H
  81438. #define FLAC__PRIVATE__CPU_H
  81439. #ifdef HAVE_CONFIG_H
  81440. #include <config.h>
  81441. #endif
  81442. typedef enum {
  81443. FLAC__CPUINFO_TYPE_IA32,
  81444. FLAC__CPUINFO_TYPE_PPC,
  81445. FLAC__CPUINFO_TYPE_UNKNOWN
  81446. } FLAC__CPUInfo_Type;
  81447. typedef struct {
  81448. FLAC__bool cpuid;
  81449. FLAC__bool bswap;
  81450. FLAC__bool cmov;
  81451. FLAC__bool mmx;
  81452. FLAC__bool fxsr;
  81453. FLAC__bool sse;
  81454. FLAC__bool sse2;
  81455. FLAC__bool sse3;
  81456. FLAC__bool ssse3;
  81457. FLAC__bool _3dnow;
  81458. FLAC__bool ext3dnow;
  81459. FLAC__bool extmmx;
  81460. } FLAC__CPUInfo_IA32;
  81461. typedef struct {
  81462. FLAC__bool altivec;
  81463. FLAC__bool ppc64;
  81464. } FLAC__CPUInfo_PPC;
  81465. typedef struct {
  81466. FLAC__bool use_asm;
  81467. FLAC__CPUInfo_Type type;
  81468. union {
  81469. FLAC__CPUInfo_IA32 ia32;
  81470. FLAC__CPUInfo_PPC ppc;
  81471. } data;
  81472. } FLAC__CPUInfo;
  81473. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81474. #ifndef FLAC__NO_ASM
  81475. #ifdef FLAC__CPU_IA32
  81476. #ifdef FLAC__HAS_NASM
  81477. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81478. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81479. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81480. #endif
  81481. #endif
  81482. #endif
  81483. #endif
  81484. /*** End of inlined file: cpu.h ***/
  81485. struct FLAC__BitReader;
  81486. typedef struct FLAC__BitReader FLAC__BitReader;
  81487. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81488. FLAC__BitReader *FLAC__bitreader_new(void);
  81489. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81490. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81491. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81492. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81493. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81494. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81495. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81496. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81497. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81498. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81499. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81500. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81501. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81502. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81503. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81504. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81505. 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! */
  81506. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81507. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81508. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81509. #ifndef FLAC__NO_ASM
  81510. # ifdef FLAC__CPU_IA32
  81511. # ifdef FLAC__HAS_NASM
  81512. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81513. # endif
  81514. # endif
  81515. #endif
  81516. #if 0 /* UNUSED */
  81517. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81518. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81519. #endif
  81520. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81521. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81522. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81523. #endif
  81524. /*** End of inlined file: bitreader.h ***/
  81525. /*** Start of inlined file: crc.h ***/
  81526. #ifndef FLAC__PRIVATE__CRC_H
  81527. #define FLAC__PRIVATE__CRC_H
  81528. extern FLAC__byte const FLAC__crc8_table[256];
  81529. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81530. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81531. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81532. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81533. extern unsigned FLAC__crc16_table[256];
  81534. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81535. #if 0
  81536. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81537. #endif
  81538. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81539. #endif
  81540. /*** End of inlined file: crc.h ***/
  81541. typedef FLAC__uint32 brword;
  81542. #define FLAC__BYTES_PER_WORD 4
  81543. #define FLAC__BITS_PER_WORD 32
  81544. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81545. #if WORDS_BIGENDIAN
  81546. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81547. #else
  81548. #if defined (_MSC_VER) && defined (_X86_)
  81549. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81550. #else
  81551. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81552. #endif
  81553. #endif
  81554. #define COUNT_ZERO_MSBS(word) ( \
  81555. (word) <= 0xffff ? \
  81556. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81557. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81558. )
  81559. #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])) )
  81560. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81561. static const unsigned char byte_to_unary_table[] = {
  81562. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81563. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81564. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81565. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81566. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81567. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81568. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81569. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81578. };
  81579. #ifdef min
  81580. #undef min
  81581. #endif
  81582. #define min(x,y) ((x)<(y)?(x):(y))
  81583. #ifdef max
  81584. #undef max
  81585. #endif
  81586. #define max(x,y) ((x)>(y)?(x):(y))
  81587. #ifdef _MSC_VER
  81588. #define FLAC__U64L(x) x
  81589. #else
  81590. #define FLAC__U64L(x) x##LLU
  81591. #endif
  81592. #ifndef FLaC__INLINE
  81593. #define FLaC__INLINE
  81594. #endif
  81595. struct FLAC__BitReader {
  81596. brword *buffer;
  81597. unsigned capacity; /* in words */
  81598. unsigned words; /* # of completed words in buffer */
  81599. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81600. unsigned consumed_words; /* #words ... */
  81601. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81602. unsigned read_crc16; /* the running frame CRC */
  81603. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81604. FLAC__BitReaderReadCallback read_callback;
  81605. void *client_data;
  81606. FLAC__CPUInfo cpu_info;
  81607. };
  81608. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81609. {
  81610. register unsigned crc = br->read_crc16;
  81611. #if FLAC__BYTES_PER_WORD == 4
  81612. switch(br->crc16_align) {
  81613. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81614. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81615. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81616. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81617. }
  81618. #elif FLAC__BYTES_PER_WORD == 8
  81619. switch(br->crc16_align) {
  81620. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81621. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81622. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81623. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81624. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81625. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81626. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81627. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81628. }
  81629. #else
  81630. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81631. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81632. br->read_crc16 = crc;
  81633. #endif
  81634. br->crc16_align = 0;
  81635. }
  81636. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81637. {
  81638. unsigned start, end;
  81639. size_t bytes;
  81640. FLAC__byte *target;
  81641. if(br->consumed_words > 0) {
  81642. start = br->consumed_words;
  81643. end = br->words + (br->bytes? 1:0);
  81644. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81645. br->words -= start;
  81646. br->consumed_words = 0;
  81647. }
  81648. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81649. if(bytes == 0)
  81650. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81651. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81652. #if WORDS_BIGENDIAN
  81653. #else
  81654. if(br->bytes)
  81655. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81656. #endif
  81657. if(!br->read_callback(target, &bytes, br->client_data))
  81658. return false;
  81659. #if WORDS_BIGENDIAN
  81660. #else
  81661. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81662. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81663. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81664. start = br->words;
  81665. local_swap32_block_(br->buffer + start, end - start);
  81666. }
  81667. else
  81668. # endif
  81669. for(start = br->words; start < end; start++)
  81670. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81671. #endif
  81672. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81673. br->words = end / FLAC__BYTES_PER_WORD;
  81674. br->bytes = end % FLAC__BYTES_PER_WORD;
  81675. return true;
  81676. }
  81677. FLAC__BitReader *FLAC__bitreader_new(void)
  81678. {
  81679. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81680. return br;
  81681. }
  81682. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81683. {
  81684. FLAC__ASSERT(0 != br);
  81685. FLAC__bitreader_free(br);
  81686. free(br);
  81687. }
  81688. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81689. {
  81690. FLAC__ASSERT(0 != br);
  81691. br->words = br->bytes = 0;
  81692. br->consumed_words = br->consumed_bits = 0;
  81693. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81694. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81695. if(br->buffer == 0)
  81696. return false;
  81697. br->read_callback = rcb;
  81698. br->client_data = cd;
  81699. br->cpu_info = cpu;
  81700. return true;
  81701. }
  81702. void FLAC__bitreader_free(FLAC__BitReader *br)
  81703. {
  81704. FLAC__ASSERT(0 != br);
  81705. if(0 != br->buffer)
  81706. free(br->buffer);
  81707. br->buffer = 0;
  81708. br->capacity = 0;
  81709. br->words = br->bytes = 0;
  81710. br->consumed_words = br->consumed_bits = 0;
  81711. br->read_callback = 0;
  81712. br->client_data = 0;
  81713. }
  81714. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81715. {
  81716. br->words = br->bytes = 0;
  81717. br->consumed_words = br->consumed_bits = 0;
  81718. return true;
  81719. }
  81720. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81721. {
  81722. unsigned i, j;
  81723. if(br == 0) {
  81724. fprintf(out, "bitreader is NULL\n");
  81725. }
  81726. else {
  81727. 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);
  81728. for(i = 0; i < br->words; i++) {
  81729. fprintf(out, "%08X: ", i);
  81730. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81731. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81732. fprintf(out, ".");
  81733. else
  81734. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81735. fprintf(out, "\n");
  81736. }
  81737. if(br->bytes > 0) {
  81738. fprintf(out, "%08X: ", i);
  81739. for(j = 0; j < br->bytes*8; j++)
  81740. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81741. fprintf(out, ".");
  81742. else
  81743. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81744. fprintf(out, "\n");
  81745. }
  81746. }
  81747. }
  81748. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81749. {
  81750. FLAC__ASSERT(0 != br);
  81751. FLAC__ASSERT(0 != br->buffer);
  81752. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81753. br->read_crc16 = (unsigned)seed;
  81754. br->crc16_align = br->consumed_bits;
  81755. }
  81756. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81757. {
  81758. FLAC__ASSERT(0 != br);
  81759. FLAC__ASSERT(0 != br->buffer);
  81760. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81761. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81762. if(br->consumed_bits) {
  81763. const brword tail = br->buffer[br->consumed_words];
  81764. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81765. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81766. }
  81767. return br->read_crc16;
  81768. }
  81769. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81770. {
  81771. return ((br->consumed_bits & 7) == 0);
  81772. }
  81773. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81774. {
  81775. return 8 - (br->consumed_bits & 7);
  81776. }
  81777. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81778. {
  81779. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81780. }
  81781. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81782. {
  81783. FLAC__ASSERT(0 != br);
  81784. FLAC__ASSERT(0 != br->buffer);
  81785. FLAC__ASSERT(bits <= 32);
  81786. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81787. FLAC__ASSERT(br->consumed_words <= br->words);
  81788. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81789. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81790. *val = 0;
  81791. return true;
  81792. }
  81793. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81794. if(!bitreader_read_from_client_(br))
  81795. return false;
  81796. }
  81797. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81798. if(br->consumed_bits) {
  81799. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81800. const brword word = br->buffer[br->consumed_words];
  81801. if(bits < n) {
  81802. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81803. br->consumed_bits += bits;
  81804. return true;
  81805. }
  81806. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81807. bits -= n;
  81808. crc16_update_word_(br, word);
  81809. br->consumed_words++;
  81810. br->consumed_bits = 0;
  81811. 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 */
  81812. *val <<= bits;
  81813. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81814. br->consumed_bits = bits;
  81815. }
  81816. return true;
  81817. }
  81818. else {
  81819. const brword word = br->buffer[br->consumed_words];
  81820. if(bits < FLAC__BITS_PER_WORD) {
  81821. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81822. br->consumed_bits = bits;
  81823. return true;
  81824. }
  81825. *val = word;
  81826. crc16_update_word_(br, word);
  81827. br->consumed_words++;
  81828. return true;
  81829. }
  81830. }
  81831. else {
  81832. if(br->consumed_bits) {
  81833. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81834. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81835. br->consumed_bits += bits;
  81836. return true;
  81837. }
  81838. else {
  81839. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81840. br->consumed_bits += bits;
  81841. return true;
  81842. }
  81843. }
  81844. }
  81845. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81846. {
  81847. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81848. return false;
  81849. *val <<= (32-bits);
  81850. *val >>= (32-bits);
  81851. return true;
  81852. }
  81853. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81854. {
  81855. FLAC__uint32 hi, lo;
  81856. if(bits > 32) {
  81857. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81858. return false;
  81859. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81860. return false;
  81861. *val = hi;
  81862. *val <<= 32;
  81863. *val |= lo;
  81864. }
  81865. else {
  81866. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81867. return false;
  81868. *val = lo;
  81869. }
  81870. return true;
  81871. }
  81872. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81873. {
  81874. FLAC__uint32 x8, x32 = 0;
  81875. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81876. return false;
  81877. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81878. return false;
  81879. x32 |= (x8 << 8);
  81880. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81881. return false;
  81882. x32 |= (x8 << 16);
  81883. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81884. return false;
  81885. x32 |= (x8 << 24);
  81886. *val = x32;
  81887. return true;
  81888. }
  81889. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81890. {
  81891. FLAC__ASSERT(0 != br);
  81892. FLAC__ASSERT(0 != br->buffer);
  81893. if(bits > 0) {
  81894. const unsigned n = br->consumed_bits & 7;
  81895. unsigned m;
  81896. FLAC__uint32 x;
  81897. if(n != 0) {
  81898. m = min(8-n, bits);
  81899. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81900. return false;
  81901. bits -= m;
  81902. }
  81903. m = bits / 8;
  81904. if(m > 0) {
  81905. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81906. return false;
  81907. bits %= 8;
  81908. }
  81909. if(bits > 0) {
  81910. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81911. return false;
  81912. }
  81913. }
  81914. return true;
  81915. }
  81916. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81917. {
  81918. FLAC__uint32 x;
  81919. FLAC__ASSERT(0 != br);
  81920. FLAC__ASSERT(0 != br->buffer);
  81921. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81922. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81923. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81924. return false;
  81925. nvals--;
  81926. }
  81927. if(0 == nvals)
  81928. return true;
  81929. while(nvals >= FLAC__BYTES_PER_WORD) {
  81930. if(br->consumed_words < br->words) {
  81931. br->consumed_words++;
  81932. nvals -= FLAC__BYTES_PER_WORD;
  81933. }
  81934. else if(!bitreader_read_from_client_(br))
  81935. return false;
  81936. }
  81937. while(nvals) {
  81938. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81939. return false;
  81940. nvals--;
  81941. }
  81942. return true;
  81943. }
  81944. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  81945. {
  81946. FLAC__uint32 x;
  81947. FLAC__ASSERT(0 != br);
  81948. FLAC__ASSERT(0 != br->buffer);
  81949. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81950. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81951. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81952. return false;
  81953. *val++ = (FLAC__byte)x;
  81954. nvals--;
  81955. }
  81956. if(0 == nvals)
  81957. return true;
  81958. while(nvals >= FLAC__BYTES_PER_WORD) {
  81959. if(br->consumed_words < br->words) {
  81960. const brword word = br->buffer[br->consumed_words++];
  81961. #if FLAC__BYTES_PER_WORD == 4
  81962. val[0] = (FLAC__byte)(word >> 24);
  81963. val[1] = (FLAC__byte)(word >> 16);
  81964. val[2] = (FLAC__byte)(word >> 8);
  81965. val[3] = (FLAC__byte)word;
  81966. #elif FLAC__BYTES_PER_WORD == 8
  81967. val[0] = (FLAC__byte)(word >> 56);
  81968. val[1] = (FLAC__byte)(word >> 48);
  81969. val[2] = (FLAC__byte)(word >> 40);
  81970. val[3] = (FLAC__byte)(word >> 32);
  81971. val[4] = (FLAC__byte)(word >> 24);
  81972. val[5] = (FLAC__byte)(word >> 16);
  81973. val[6] = (FLAC__byte)(word >> 8);
  81974. val[7] = (FLAC__byte)word;
  81975. #else
  81976. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  81977. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  81978. #endif
  81979. val += FLAC__BYTES_PER_WORD;
  81980. nvals -= FLAC__BYTES_PER_WORD;
  81981. }
  81982. else if(!bitreader_read_from_client_(br))
  81983. return false;
  81984. }
  81985. while(nvals) {
  81986. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81987. return false;
  81988. *val++ = (FLAC__byte)x;
  81989. nvals--;
  81990. }
  81991. return true;
  81992. }
  81993. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  81994. #if 0 /* slow but readable version */
  81995. {
  81996. unsigned bit;
  81997. FLAC__ASSERT(0 != br);
  81998. FLAC__ASSERT(0 != br->buffer);
  81999. *val = 0;
  82000. while(1) {
  82001. if(!FLAC__bitreader_read_bit(br, &bit))
  82002. return false;
  82003. if(bit)
  82004. break;
  82005. else
  82006. *val++;
  82007. }
  82008. return true;
  82009. }
  82010. #else
  82011. {
  82012. unsigned i;
  82013. FLAC__ASSERT(0 != br);
  82014. FLAC__ASSERT(0 != br->buffer);
  82015. *val = 0;
  82016. while(1) {
  82017. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82018. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82019. if(b) {
  82020. i = COUNT_ZERO_MSBS(b);
  82021. *val += i;
  82022. i++;
  82023. br->consumed_bits += i;
  82024. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82025. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82026. br->consumed_words++;
  82027. br->consumed_bits = 0;
  82028. }
  82029. return true;
  82030. }
  82031. else {
  82032. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82033. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82034. br->consumed_words++;
  82035. br->consumed_bits = 0;
  82036. }
  82037. }
  82038. if(br->bytes) {
  82039. const unsigned end = br->bytes * 8;
  82040. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82041. if(b) {
  82042. i = COUNT_ZERO_MSBS(b);
  82043. *val += i;
  82044. i++;
  82045. br->consumed_bits += i;
  82046. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82047. return true;
  82048. }
  82049. else {
  82050. *val += end - br->consumed_bits;
  82051. br->consumed_bits += end;
  82052. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82053. }
  82054. }
  82055. if(!bitreader_read_from_client_(br))
  82056. return false;
  82057. }
  82058. }
  82059. #endif
  82060. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82061. {
  82062. FLAC__uint32 lsbs = 0, msbs = 0;
  82063. unsigned uval;
  82064. FLAC__ASSERT(0 != br);
  82065. FLAC__ASSERT(0 != br->buffer);
  82066. FLAC__ASSERT(parameter <= 31);
  82067. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82068. return false;
  82069. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82070. return false;
  82071. uval = (msbs << parameter) | lsbs;
  82072. if(uval & 1)
  82073. *val = -((int)(uval >> 1)) - 1;
  82074. else
  82075. *val = (int)(uval >> 1);
  82076. return true;
  82077. }
  82078. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82079. #ifdef _MSC_VER
  82080. {
  82081. unsigned i;
  82082. unsigned uval = 0;
  82083. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82084. register unsigned cwords;
  82085. register unsigned cbits;
  82086. FLAC__ASSERT(0 != br);
  82087. FLAC__ASSERT(0 != br->buffer);
  82088. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82089. FLAC__ASSERT(parameter < 32);
  82090. if(nvals == 0)
  82091. return true;
  82092. cbits = br->consumed_bits;
  82093. cwords = br->consumed_words;
  82094. while(1) {
  82095. while(1) {
  82096. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82097. brword b = br->buffer[cwords] << cbits;
  82098. if(b) {
  82099. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82100. __asm {
  82101. bsr eax, b
  82102. not eax
  82103. and eax, 31
  82104. mov i, eax
  82105. }
  82106. #else
  82107. i = COUNT_ZERO_MSBS(b);
  82108. #endif
  82109. uval += i;
  82110. bits = parameter;
  82111. i++;
  82112. cbits += i;
  82113. if(cbits == FLAC__BITS_PER_WORD) {
  82114. crc16_update_word_(br, br->buffer[cwords]);
  82115. cwords++;
  82116. cbits = 0;
  82117. }
  82118. goto break1;
  82119. }
  82120. else {
  82121. uval += FLAC__BITS_PER_WORD - cbits;
  82122. crc16_update_word_(br, br->buffer[cwords]);
  82123. cwords++;
  82124. cbits = 0;
  82125. }
  82126. }
  82127. if(br->bytes) {
  82128. const unsigned end = br->bytes * 8;
  82129. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82130. if(b) {
  82131. i = COUNT_ZERO_MSBS(b);
  82132. uval += i;
  82133. bits = parameter;
  82134. i++;
  82135. cbits += i;
  82136. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82137. goto break1;
  82138. }
  82139. else {
  82140. uval += end - cbits;
  82141. cbits += end;
  82142. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82143. }
  82144. }
  82145. br->consumed_bits = cbits;
  82146. br->consumed_words = cwords;
  82147. if(!bitreader_read_from_client_(br))
  82148. return false;
  82149. cwords = br->consumed_words;
  82150. }
  82151. break1:
  82152. FLAC__ASSERT(cwords <= br->words);
  82153. if(bits) {
  82154. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82155. br->consumed_bits = cbits;
  82156. br->consumed_words = cwords;
  82157. if(!bitreader_read_from_client_(br))
  82158. return false;
  82159. cwords = br->consumed_words;
  82160. }
  82161. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82162. if(cbits) {
  82163. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82164. const brword word = br->buffer[cwords];
  82165. if(bits < n) {
  82166. uval <<= bits;
  82167. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82168. cbits += bits;
  82169. goto break2;
  82170. }
  82171. uval <<= n;
  82172. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82173. bits -= n;
  82174. crc16_update_word_(br, word);
  82175. cwords++;
  82176. cbits = 0;
  82177. 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 */
  82178. uval <<= bits;
  82179. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82180. cbits = bits;
  82181. }
  82182. goto break2;
  82183. }
  82184. else {
  82185. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82186. uval <<= bits;
  82187. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82188. cbits = bits;
  82189. goto break2;
  82190. }
  82191. }
  82192. else {
  82193. uval <<= bits;
  82194. if(cbits) {
  82195. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82196. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82197. cbits += bits;
  82198. goto break2;
  82199. }
  82200. else {
  82201. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82202. cbits += bits;
  82203. goto break2;
  82204. }
  82205. }
  82206. }
  82207. break2:
  82208. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82209. --nvals;
  82210. if(nvals == 0) {
  82211. br->consumed_bits = cbits;
  82212. br->consumed_words = cwords;
  82213. return true;
  82214. }
  82215. uval = 0;
  82216. ++vals;
  82217. }
  82218. }
  82219. #else
  82220. {
  82221. unsigned i;
  82222. unsigned uval = 0;
  82223. register unsigned cwords;
  82224. register unsigned cbits;
  82225. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82226. FLAC__ASSERT(0 != br);
  82227. FLAC__ASSERT(0 != br->buffer);
  82228. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82229. FLAC__ASSERT(parameter < 32);
  82230. if(nvals == 0)
  82231. return true;
  82232. cbits = br->consumed_bits;
  82233. cwords = br->consumed_words;
  82234. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82235. while(1) {
  82236. while(1) {
  82237. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82238. brword b = br->buffer[cwords] << cbits;
  82239. if(b) {
  82240. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82241. asm volatile (
  82242. "bsrl %1, %0;"
  82243. "notl %0;"
  82244. "andl $31, %0;"
  82245. : "=r"(i)
  82246. : "r"(b)
  82247. );
  82248. #else
  82249. i = COUNT_ZERO_MSBS(b);
  82250. #endif
  82251. uval += i;
  82252. cbits += i;
  82253. cbits++; /* skip over stop bit */
  82254. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82255. crc16_update_word_(br, br->buffer[cwords]);
  82256. cwords++;
  82257. cbits = 0;
  82258. }
  82259. goto break1;
  82260. }
  82261. else {
  82262. uval += FLAC__BITS_PER_WORD - cbits;
  82263. crc16_update_word_(br, br->buffer[cwords]);
  82264. cwords++;
  82265. cbits = 0;
  82266. }
  82267. }
  82268. if(br->bytes) {
  82269. const unsigned end = br->bytes * 8;
  82270. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82271. if(b) {
  82272. i = COUNT_ZERO_MSBS(b);
  82273. uval += i;
  82274. cbits += i;
  82275. cbits++; /* skip over stop bit */
  82276. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82277. goto break1;
  82278. }
  82279. else {
  82280. uval += end - cbits;
  82281. cbits += end;
  82282. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82283. }
  82284. }
  82285. br->consumed_bits = cbits;
  82286. br->consumed_words = cwords;
  82287. if(!bitreader_read_from_client_(br))
  82288. return false;
  82289. cwords = br->consumed_words;
  82290. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82291. }
  82292. break1:
  82293. ucbits -= uval;
  82294. ucbits--; /* account for stop bit */
  82295. FLAC__ASSERT(cwords <= br->words);
  82296. if(parameter) {
  82297. while(ucbits < parameter) {
  82298. br->consumed_bits = cbits;
  82299. br->consumed_words = cwords;
  82300. if(!bitreader_read_from_client_(br))
  82301. return false;
  82302. cwords = br->consumed_words;
  82303. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82304. }
  82305. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82306. if(cbits) {
  82307. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82308. const brword word = br->buffer[cwords];
  82309. if(parameter < n) {
  82310. uval <<= parameter;
  82311. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82312. cbits += parameter;
  82313. }
  82314. else {
  82315. uval <<= n;
  82316. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82317. crc16_update_word_(br, word);
  82318. cwords++;
  82319. cbits = parameter - n;
  82320. 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 */
  82321. uval <<= cbits;
  82322. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82323. }
  82324. }
  82325. }
  82326. else {
  82327. cbits = parameter;
  82328. uval <<= parameter;
  82329. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82330. }
  82331. }
  82332. else {
  82333. uval <<= parameter;
  82334. if(cbits) {
  82335. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82336. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82337. cbits += parameter;
  82338. }
  82339. else {
  82340. cbits = parameter;
  82341. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82342. }
  82343. }
  82344. }
  82345. ucbits -= parameter;
  82346. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82347. --nvals;
  82348. if(nvals == 0) {
  82349. br->consumed_bits = cbits;
  82350. br->consumed_words = cwords;
  82351. return true;
  82352. }
  82353. uval = 0;
  82354. ++vals;
  82355. }
  82356. }
  82357. #endif
  82358. #if 0 /* UNUSED */
  82359. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82360. {
  82361. FLAC__uint32 lsbs = 0, msbs = 0;
  82362. unsigned bit, uval, k;
  82363. FLAC__ASSERT(0 != br);
  82364. FLAC__ASSERT(0 != br->buffer);
  82365. k = FLAC__bitmath_ilog2(parameter);
  82366. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82367. return false;
  82368. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82369. return false;
  82370. if(parameter == 1u<<k) {
  82371. uval = (msbs << k) | lsbs;
  82372. }
  82373. else {
  82374. unsigned d = (1 << (k+1)) - parameter;
  82375. if(lsbs >= d) {
  82376. if(!FLAC__bitreader_read_bit(br, &bit))
  82377. return false;
  82378. lsbs <<= 1;
  82379. lsbs |= bit;
  82380. lsbs -= d;
  82381. }
  82382. uval = msbs * parameter + lsbs;
  82383. }
  82384. if(uval & 1)
  82385. *val = -((int)(uval >> 1)) - 1;
  82386. else
  82387. *val = (int)(uval >> 1);
  82388. return true;
  82389. }
  82390. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82391. {
  82392. FLAC__uint32 lsbs, msbs = 0;
  82393. unsigned bit, k;
  82394. FLAC__ASSERT(0 != br);
  82395. FLAC__ASSERT(0 != br->buffer);
  82396. k = FLAC__bitmath_ilog2(parameter);
  82397. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82398. return false;
  82399. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82400. return false;
  82401. if(parameter == 1u<<k) {
  82402. *val = (msbs << k) | lsbs;
  82403. }
  82404. else {
  82405. unsigned d = (1 << (k+1)) - parameter;
  82406. if(lsbs >= d) {
  82407. if(!FLAC__bitreader_read_bit(br, &bit))
  82408. return false;
  82409. lsbs <<= 1;
  82410. lsbs |= bit;
  82411. lsbs -= d;
  82412. }
  82413. *val = msbs * parameter + lsbs;
  82414. }
  82415. return true;
  82416. }
  82417. #endif /* UNUSED */
  82418. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82419. {
  82420. FLAC__uint32 v = 0;
  82421. FLAC__uint32 x;
  82422. unsigned i;
  82423. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82424. return false;
  82425. if(raw)
  82426. raw[(*rawlen)++] = (FLAC__byte)x;
  82427. if(!(x & 0x80)) { /* 0xxxxxxx */
  82428. v = x;
  82429. i = 0;
  82430. }
  82431. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82432. v = x & 0x1F;
  82433. i = 1;
  82434. }
  82435. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82436. v = x & 0x0F;
  82437. i = 2;
  82438. }
  82439. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82440. v = x & 0x07;
  82441. i = 3;
  82442. }
  82443. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82444. v = x & 0x03;
  82445. i = 4;
  82446. }
  82447. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82448. v = x & 0x01;
  82449. i = 5;
  82450. }
  82451. else {
  82452. *val = 0xffffffff;
  82453. return true;
  82454. }
  82455. for( ; i; i--) {
  82456. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82457. return false;
  82458. if(raw)
  82459. raw[(*rawlen)++] = (FLAC__byte)x;
  82460. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82461. *val = 0xffffffff;
  82462. return true;
  82463. }
  82464. v <<= 6;
  82465. v |= (x & 0x3F);
  82466. }
  82467. *val = v;
  82468. return true;
  82469. }
  82470. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82471. {
  82472. FLAC__uint64 v = 0;
  82473. FLAC__uint32 x;
  82474. unsigned i;
  82475. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82476. return false;
  82477. if(raw)
  82478. raw[(*rawlen)++] = (FLAC__byte)x;
  82479. if(!(x & 0x80)) { /* 0xxxxxxx */
  82480. v = x;
  82481. i = 0;
  82482. }
  82483. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82484. v = x & 0x1F;
  82485. i = 1;
  82486. }
  82487. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82488. v = x & 0x0F;
  82489. i = 2;
  82490. }
  82491. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82492. v = x & 0x07;
  82493. i = 3;
  82494. }
  82495. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82496. v = x & 0x03;
  82497. i = 4;
  82498. }
  82499. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82500. v = x & 0x01;
  82501. i = 5;
  82502. }
  82503. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82504. v = 0;
  82505. i = 6;
  82506. }
  82507. else {
  82508. *val = FLAC__U64L(0xffffffffffffffff);
  82509. return true;
  82510. }
  82511. for( ; i; i--) {
  82512. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82513. return false;
  82514. if(raw)
  82515. raw[(*rawlen)++] = (FLAC__byte)x;
  82516. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82517. *val = FLAC__U64L(0xffffffffffffffff);
  82518. return true;
  82519. }
  82520. v <<= 6;
  82521. v |= (x & 0x3F);
  82522. }
  82523. *val = v;
  82524. return true;
  82525. }
  82526. #endif
  82527. /*** End of inlined file: bitreader.c ***/
  82528. /*** Start of inlined file: bitwriter.c ***/
  82529. /*** Start of inlined file: juce_FlacHeader.h ***/
  82530. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82531. // tasks..
  82532. #define VERSION "1.2.1"
  82533. #define FLAC__NO_DLL 1
  82534. #if JUCE_MSVC
  82535. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82536. #endif
  82537. #if JUCE_MAC
  82538. #define FLAC__SYS_DARWIN 1
  82539. #endif
  82540. /*** End of inlined file: juce_FlacHeader.h ***/
  82541. #if JUCE_USE_FLAC
  82542. #if HAVE_CONFIG_H
  82543. # include <config.h>
  82544. #endif
  82545. #include <stdlib.h> /* for malloc() */
  82546. #include <string.h> /* for memcpy(), memset() */
  82547. #ifdef _MSC_VER
  82548. #include <winsock.h> /* for ntohl() */
  82549. #elif defined FLAC__SYS_DARWIN
  82550. #include <machine/endian.h> /* for ntohl() */
  82551. #elif defined __MINGW32__
  82552. #include <winsock.h> /* for ntohl() */
  82553. #else
  82554. #include <netinet/in.h> /* for ntohl() */
  82555. #endif
  82556. #if 0 /* UNUSED */
  82557. #endif
  82558. /*** Start of inlined file: bitwriter.h ***/
  82559. #ifndef FLAC__PRIVATE__BITWRITER_H
  82560. #define FLAC__PRIVATE__BITWRITER_H
  82561. #include <stdio.h> /* for FILE */
  82562. struct FLAC__BitWriter;
  82563. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82564. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82565. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82566. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82567. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82568. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82569. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82570. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82571. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82572. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82573. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82574. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82575. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82576. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82577. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82578. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82579. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82580. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82581. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82582. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82583. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82584. #if 0 /* UNUSED */
  82585. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82586. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82587. #endif
  82588. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82589. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82590. #if 0 /* UNUSED */
  82591. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82592. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82593. #endif
  82594. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82595. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82596. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82597. #endif
  82598. /*** End of inlined file: bitwriter.h ***/
  82599. /*** Start of inlined file: alloc.h ***/
  82600. #ifndef FLAC__SHARE__ALLOC_H
  82601. #define FLAC__SHARE__ALLOC_H
  82602. #if HAVE_CONFIG_H
  82603. # include <config.h>
  82604. #endif
  82605. #include <limits.h> /* for SIZE_MAX */
  82606. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82607. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82608. #endif
  82609. #include <stdlib.h> /* for size_t, malloc(), etc */
  82610. #ifndef SIZE_MAX
  82611. # ifndef SIZE_T_MAX
  82612. # ifdef _MSC_VER
  82613. # define SIZE_T_MAX UINT_MAX
  82614. # else
  82615. # error
  82616. # endif
  82617. # endif
  82618. # define SIZE_MAX SIZE_T_MAX
  82619. #endif
  82620. #ifndef FLaC__INLINE
  82621. #define FLaC__INLINE
  82622. #endif
  82623. static FLaC__INLINE void *safe_malloc_(size_t size)
  82624. {
  82625. if(!size)
  82626. size++;
  82627. return malloc(size);
  82628. }
  82629. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82630. {
  82631. if(!nmemb || !size)
  82632. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82633. return calloc(nmemb, size);
  82634. }
  82635. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82636. {
  82637. size2 += size1;
  82638. if(size2 < size1)
  82639. return 0;
  82640. return safe_malloc_(size2);
  82641. }
  82642. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82643. {
  82644. size2 += size1;
  82645. if(size2 < size1)
  82646. return 0;
  82647. size3 += size2;
  82648. if(size3 < size2)
  82649. return 0;
  82650. return safe_malloc_(size3);
  82651. }
  82652. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82653. {
  82654. size2 += size1;
  82655. if(size2 < size1)
  82656. return 0;
  82657. size3 += size2;
  82658. if(size3 < size2)
  82659. return 0;
  82660. size4 += size3;
  82661. if(size4 < size3)
  82662. return 0;
  82663. return safe_malloc_(size4);
  82664. }
  82665. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82666. #if 0
  82667. needs support for cases where sizeof(size_t) != 4
  82668. {
  82669. if(sizeof(size_t) == 4) {
  82670. if ((double)size1 * (double)size2 < 4294967296.0)
  82671. return malloc(size1*size2);
  82672. }
  82673. return 0;
  82674. }
  82675. #else
  82676. {
  82677. if(!size1 || !size2)
  82678. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82679. if(size1 > SIZE_MAX / size2)
  82680. return 0;
  82681. return malloc(size1*size2);
  82682. }
  82683. #endif
  82684. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82685. {
  82686. if(!size1 || !size2 || !size3)
  82687. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82688. if(size1 > SIZE_MAX / size2)
  82689. return 0;
  82690. size1 *= size2;
  82691. if(size1 > SIZE_MAX / size3)
  82692. return 0;
  82693. return malloc(size1*size3);
  82694. }
  82695. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82696. {
  82697. if(!size1 || !size2)
  82698. return safe_malloc_(size3);
  82699. if(size1 > SIZE_MAX / size2)
  82700. return 0;
  82701. return safe_malloc_add_2op_(size1*size2, size3);
  82702. }
  82703. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82704. {
  82705. if(!size1 || (!size2 && !size3))
  82706. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82707. size2 += size3;
  82708. if(size2 < size3)
  82709. return 0;
  82710. return safe_malloc_mul_2op_(size1, size2);
  82711. }
  82712. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82713. {
  82714. size2 += size1;
  82715. if(size2 < size1)
  82716. return 0;
  82717. return realloc(ptr, size2);
  82718. }
  82719. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82720. {
  82721. size2 += size1;
  82722. if(size2 < size1)
  82723. return 0;
  82724. size3 += size2;
  82725. if(size3 < size2)
  82726. return 0;
  82727. return realloc(ptr, size3);
  82728. }
  82729. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82730. {
  82731. size2 += size1;
  82732. if(size2 < size1)
  82733. return 0;
  82734. size3 += size2;
  82735. if(size3 < size2)
  82736. return 0;
  82737. size4 += size3;
  82738. if(size4 < size3)
  82739. return 0;
  82740. return realloc(ptr, size4);
  82741. }
  82742. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82743. {
  82744. if(!size1 || !size2)
  82745. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82746. if(size1 > SIZE_MAX / size2)
  82747. return 0;
  82748. return realloc(ptr, size1*size2);
  82749. }
  82750. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82751. {
  82752. if(!size1 || (!size2 && !size3))
  82753. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82754. size2 += size3;
  82755. if(size2 < size3)
  82756. return 0;
  82757. return safe_realloc_mul_2op_(ptr, size1, size2);
  82758. }
  82759. #endif
  82760. /*** End of inlined file: alloc.h ***/
  82761. typedef FLAC__uint32 bwword;
  82762. #define FLAC__BYTES_PER_WORD 4
  82763. #define FLAC__BITS_PER_WORD 32
  82764. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82765. #if WORDS_BIGENDIAN
  82766. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82767. #else
  82768. #ifdef _MSC_VER
  82769. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82770. #else
  82771. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82772. #endif
  82773. #endif
  82774. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82775. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82776. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82777. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82778. #ifdef min
  82779. #undef min
  82780. #endif
  82781. #define min(x,y) ((x)<(y)?(x):(y))
  82782. #ifdef _MSC_VER
  82783. #define FLAC__U64L(x) x
  82784. #else
  82785. #define FLAC__U64L(x) x##LLU
  82786. #endif
  82787. #ifndef FLaC__INLINE
  82788. #define FLaC__INLINE
  82789. #endif
  82790. struct FLAC__BitWriter {
  82791. bwword *buffer;
  82792. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82793. unsigned capacity; /* capacity of buffer in words */
  82794. unsigned words; /* # of complete words in buffer */
  82795. unsigned bits; /* # of used bits in accum */
  82796. };
  82797. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82798. {
  82799. unsigned new_capacity;
  82800. bwword *new_buffer;
  82801. FLAC__ASSERT(0 != bw);
  82802. FLAC__ASSERT(0 != bw->buffer);
  82803. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82804. if(bw->capacity >= new_capacity)
  82805. return true;
  82806. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82807. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82808. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82809. FLAC__ASSERT(new_capacity > bw->capacity);
  82810. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82811. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82812. if(new_buffer == 0)
  82813. return false;
  82814. bw->buffer = new_buffer;
  82815. bw->capacity = new_capacity;
  82816. return true;
  82817. }
  82818. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82819. {
  82820. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82821. return bw;
  82822. }
  82823. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82824. {
  82825. FLAC__ASSERT(0 != bw);
  82826. FLAC__bitwriter_free(bw);
  82827. free(bw);
  82828. }
  82829. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82830. {
  82831. FLAC__ASSERT(0 != bw);
  82832. bw->words = bw->bits = 0;
  82833. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82834. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82835. if(bw->buffer == 0)
  82836. return false;
  82837. return true;
  82838. }
  82839. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82840. {
  82841. FLAC__ASSERT(0 != bw);
  82842. if(0 != bw->buffer)
  82843. free(bw->buffer);
  82844. bw->buffer = 0;
  82845. bw->capacity = 0;
  82846. bw->words = bw->bits = 0;
  82847. }
  82848. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82849. {
  82850. bw->words = bw->bits = 0;
  82851. }
  82852. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82853. {
  82854. unsigned i, j;
  82855. if(bw == 0) {
  82856. fprintf(out, "bitwriter is NULL\n");
  82857. }
  82858. else {
  82859. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82860. for(i = 0; i < bw->words; i++) {
  82861. fprintf(out, "%08X: ", i);
  82862. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82863. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82864. fprintf(out, "\n");
  82865. }
  82866. if(bw->bits > 0) {
  82867. fprintf(out, "%08X: ", i);
  82868. for(j = 0; j < bw->bits; j++)
  82869. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82870. fprintf(out, "\n");
  82871. }
  82872. }
  82873. }
  82874. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82875. {
  82876. const FLAC__byte *buffer;
  82877. size_t bytes;
  82878. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82879. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82880. return false;
  82881. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82882. FLAC__bitwriter_release_buffer(bw);
  82883. return true;
  82884. }
  82885. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  82886. {
  82887. const FLAC__byte *buffer;
  82888. size_t bytes;
  82889. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82890. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82891. return false;
  82892. *crc = FLAC__crc8(buffer, bytes);
  82893. FLAC__bitwriter_release_buffer(bw);
  82894. return true;
  82895. }
  82896. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82897. {
  82898. return ((bw->bits & 7) == 0);
  82899. }
  82900. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82901. {
  82902. return FLAC__TOTAL_BITS(bw);
  82903. }
  82904. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82905. {
  82906. FLAC__ASSERT((bw->bits & 7) == 0);
  82907. if(bw->bits & 7)
  82908. return false;
  82909. if(bw->bits) {
  82910. FLAC__ASSERT(bw->words <= bw->capacity);
  82911. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82912. return false;
  82913. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82914. }
  82915. *buffer = (FLAC__byte*)bw->buffer;
  82916. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82917. return true;
  82918. }
  82919. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82920. {
  82921. (void)bw;
  82922. }
  82923. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82924. {
  82925. unsigned n;
  82926. FLAC__ASSERT(0 != bw);
  82927. FLAC__ASSERT(0 != bw->buffer);
  82928. if(bits == 0)
  82929. return true;
  82930. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82931. return false;
  82932. if(bw->bits) {
  82933. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  82934. bw->accum <<= n;
  82935. bits -= n;
  82936. bw->bits += n;
  82937. if(bw->bits == FLAC__BITS_PER_WORD) {
  82938. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82939. bw->bits = 0;
  82940. }
  82941. else
  82942. return true;
  82943. }
  82944. while(bits >= FLAC__BITS_PER_WORD) {
  82945. bw->buffer[bw->words++] = 0;
  82946. bits -= FLAC__BITS_PER_WORD;
  82947. }
  82948. if(bits > 0) {
  82949. bw->accum = 0;
  82950. bw->bits = bits;
  82951. }
  82952. return true;
  82953. }
  82954. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  82955. {
  82956. register unsigned left;
  82957. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82958. FLAC__ASSERT(0 != bw);
  82959. FLAC__ASSERT(0 != bw->buffer);
  82960. FLAC__ASSERT(bits <= 32);
  82961. if(bits == 0)
  82962. return true;
  82963. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82964. return false;
  82965. left = FLAC__BITS_PER_WORD - bw->bits;
  82966. if(bits < left) {
  82967. bw->accum <<= bits;
  82968. bw->accum |= val;
  82969. bw->bits += bits;
  82970. }
  82971. 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 */
  82972. bw->accum <<= left;
  82973. bw->accum |= val >> (bw->bits = bits - left);
  82974. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82975. bw->accum = val;
  82976. }
  82977. else {
  82978. bw->accum = val;
  82979. bw->bits = 0;
  82980. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  82981. }
  82982. return true;
  82983. }
  82984. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  82985. {
  82986. if(bits < 32)
  82987. val &= (~(0xffffffff << bits));
  82988. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82989. }
  82990. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  82991. {
  82992. if(bits > 32) {
  82993. return
  82994. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  82995. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  82996. }
  82997. else
  82998. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82999. }
  83000. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83001. {
  83002. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83003. return false;
  83004. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83005. return false;
  83006. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83007. return false;
  83008. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83009. return false;
  83010. return true;
  83011. }
  83012. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83013. {
  83014. unsigned i;
  83015. for(i = 0; i < nvals; i++) {
  83016. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83017. return false;
  83018. }
  83019. return true;
  83020. }
  83021. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83022. {
  83023. if(val < 32)
  83024. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83025. else
  83026. return
  83027. FLAC__bitwriter_write_zeroes(bw, val) &&
  83028. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83029. }
  83030. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83031. {
  83032. FLAC__uint32 uval;
  83033. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83034. uval = (val<<1) ^ (val>>31);
  83035. return 1 + parameter + (uval >> parameter);
  83036. }
  83037. #if 0 /* UNUSED */
  83038. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83039. {
  83040. unsigned bits, msbs, uval;
  83041. unsigned k;
  83042. FLAC__ASSERT(parameter > 0);
  83043. if(val < 0)
  83044. uval = (unsigned)(((-(++val)) << 1) + 1);
  83045. else
  83046. uval = (unsigned)(val << 1);
  83047. k = FLAC__bitmath_ilog2(parameter);
  83048. if(parameter == 1u<<k) {
  83049. FLAC__ASSERT(k <= 30);
  83050. msbs = uval >> k;
  83051. bits = 1 + k + msbs;
  83052. }
  83053. else {
  83054. unsigned q, r, d;
  83055. d = (1 << (k+1)) - parameter;
  83056. q = uval / parameter;
  83057. r = uval - (q * parameter);
  83058. bits = 1 + q + k;
  83059. if(r >= d)
  83060. bits++;
  83061. }
  83062. return bits;
  83063. }
  83064. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83065. {
  83066. unsigned bits, msbs;
  83067. unsigned k;
  83068. FLAC__ASSERT(parameter > 0);
  83069. k = FLAC__bitmath_ilog2(parameter);
  83070. if(parameter == 1u<<k) {
  83071. FLAC__ASSERT(k <= 30);
  83072. msbs = uval >> k;
  83073. bits = 1 + k + msbs;
  83074. }
  83075. else {
  83076. unsigned q, r, d;
  83077. d = (1 << (k+1)) - parameter;
  83078. q = uval / parameter;
  83079. r = uval - (q * parameter);
  83080. bits = 1 + q + k;
  83081. if(r >= d)
  83082. bits++;
  83083. }
  83084. return bits;
  83085. }
  83086. #endif /* UNUSED */
  83087. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83088. {
  83089. unsigned total_bits, interesting_bits, msbs;
  83090. FLAC__uint32 uval, pattern;
  83091. FLAC__ASSERT(0 != bw);
  83092. FLAC__ASSERT(0 != bw->buffer);
  83093. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83094. uval = (val<<1) ^ (val>>31);
  83095. msbs = uval >> parameter;
  83096. interesting_bits = 1 + parameter;
  83097. total_bits = interesting_bits + msbs;
  83098. pattern = 1 << parameter; /* the unary end bit */
  83099. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83100. if(total_bits <= 32)
  83101. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83102. else
  83103. return
  83104. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83105. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83106. }
  83107. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83108. {
  83109. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83110. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83111. FLAC__uint32 uval;
  83112. unsigned left;
  83113. const unsigned lsbits = 1 + parameter;
  83114. unsigned msbits;
  83115. FLAC__ASSERT(0 != bw);
  83116. FLAC__ASSERT(0 != bw->buffer);
  83117. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83118. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83119. while(nvals) {
  83120. uval = (*vals<<1) ^ (*vals>>31);
  83121. msbits = uval >> parameter;
  83122. #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) */
  83123. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83124. bw->bits = bw->bits + msbits + lsbits;
  83125. uval |= mask1; /* set stop bit */
  83126. uval &= mask2; /* mask off unused top bits */
  83127. bw->accum <<= msbits;
  83128. bw->accum <<= lsbits;
  83129. bw->accum |= uval;
  83130. if(bw->bits == FLAC__BITS_PER_WORD) {
  83131. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83132. bw->bits = 0;
  83133. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83134. FLAC__ASSERT(bw->capacity == bw->words);
  83135. return false;
  83136. }
  83137. }
  83138. }
  83139. else {
  83140. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83141. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83142. bw->bits = bw->bits + msbits + lsbits;
  83143. uval |= mask1; /* set stop bit */
  83144. uval &= mask2; /* mask off unused top bits */
  83145. bw->accum <<= msbits + lsbits;
  83146. bw->accum |= uval;
  83147. }
  83148. else {
  83149. #endif
  83150. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83151. return false;
  83152. if(msbits) {
  83153. if(bw->bits) {
  83154. left = FLAC__BITS_PER_WORD - bw->bits;
  83155. if(msbits < left) {
  83156. bw->accum <<= msbits;
  83157. bw->bits += msbits;
  83158. goto break1;
  83159. }
  83160. else {
  83161. bw->accum <<= left;
  83162. msbits -= left;
  83163. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83164. bw->bits = 0;
  83165. }
  83166. }
  83167. while(msbits >= FLAC__BITS_PER_WORD) {
  83168. bw->buffer[bw->words++] = 0;
  83169. msbits -= FLAC__BITS_PER_WORD;
  83170. }
  83171. if(msbits > 0) {
  83172. bw->accum = 0;
  83173. bw->bits = msbits;
  83174. }
  83175. }
  83176. break1:
  83177. uval |= mask1; /* set stop bit */
  83178. uval &= mask2; /* mask off unused top bits */
  83179. left = FLAC__BITS_PER_WORD - bw->bits;
  83180. if(lsbits < left) {
  83181. bw->accum <<= lsbits;
  83182. bw->accum |= uval;
  83183. bw->bits += lsbits;
  83184. }
  83185. else {
  83186. FLAC__ASSERT(bw->bits);
  83187. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83188. bw->accum <<= left;
  83189. bw->accum |= uval >> (bw->bits = lsbits - left);
  83190. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83191. bw->accum = uval;
  83192. }
  83193. #if 1
  83194. }
  83195. #endif
  83196. vals++;
  83197. nvals--;
  83198. }
  83199. return true;
  83200. }
  83201. #if 0 /* UNUSED */
  83202. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83203. {
  83204. unsigned total_bits, msbs, uval;
  83205. unsigned k;
  83206. FLAC__ASSERT(0 != bw);
  83207. FLAC__ASSERT(0 != bw->buffer);
  83208. FLAC__ASSERT(parameter > 0);
  83209. if(val < 0)
  83210. uval = (unsigned)(((-(++val)) << 1) + 1);
  83211. else
  83212. uval = (unsigned)(val << 1);
  83213. k = FLAC__bitmath_ilog2(parameter);
  83214. if(parameter == 1u<<k) {
  83215. unsigned pattern;
  83216. FLAC__ASSERT(k <= 30);
  83217. msbs = uval >> k;
  83218. total_bits = 1 + k + msbs;
  83219. pattern = 1 << k; /* the unary end bit */
  83220. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83221. if(total_bits <= 32) {
  83222. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83223. return false;
  83224. }
  83225. else {
  83226. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83227. return false;
  83228. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83229. return false;
  83230. }
  83231. }
  83232. else {
  83233. unsigned q, r, d;
  83234. d = (1 << (k+1)) - parameter;
  83235. q = uval / parameter;
  83236. r = uval - (q * parameter);
  83237. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83238. return false;
  83239. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83240. return false;
  83241. if(r >= d) {
  83242. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83243. return false;
  83244. }
  83245. else {
  83246. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83247. return false;
  83248. }
  83249. }
  83250. return true;
  83251. }
  83252. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83253. {
  83254. unsigned total_bits, msbs;
  83255. unsigned k;
  83256. FLAC__ASSERT(0 != bw);
  83257. FLAC__ASSERT(0 != bw->buffer);
  83258. FLAC__ASSERT(parameter > 0);
  83259. k = FLAC__bitmath_ilog2(parameter);
  83260. if(parameter == 1u<<k) {
  83261. unsigned pattern;
  83262. FLAC__ASSERT(k <= 30);
  83263. msbs = uval >> k;
  83264. total_bits = 1 + k + msbs;
  83265. pattern = 1 << k; /* the unary end bit */
  83266. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83267. if(total_bits <= 32) {
  83268. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83269. return false;
  83270. }
  83271. else {
  83272. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83273. return false;
  83274. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83275. return false;
  83276. }
  83277. }
  83278. else {
  83279. unsigned q, r, d;
  83280. d = (1 << (k+1)) - parameter;
  83281. q = uval / parameter;
  83282. r = uval - (q * parameter);
  83283. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83284. return false;
  83285. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83286. return false;
  83287. if(r >= d) {
  83288. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83289. return false;
  83290. }
  83291. else {
  83292. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83293. return false;
  83294. }
  83295. }
  83296. return true;
  83297. }
  83298. #endif /* UNUSED */
  83299. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83300. {
  83301. FLAC__bool ok = 1;
  83302. FLAC__ASSERT(0 != bw);
  83303. FLAC__ASSERT(0 != bw->buffer);
  83304. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83305. if(val < 0x80) {
  83306. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83307. }
  83308. else if(val < 0x800) {
  83309. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83310. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83311. }
  83312. else if(val < 0x10000) {
  83313. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83314. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83315. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83316. }
  83317. else if(val < 0x200000) {
  83318. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83319. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83320. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83321. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83322. }
  83323. else if(val < 0x4000000) {
  83324. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83325. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83326. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83327. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83328. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83329. }
  83330. else {
  83331. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83332. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83333. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83334. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83335. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83336. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83337. }
  83338. return ok;
  83339. }
  83340. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83341. {
  83342. FLAC__bool ok = 1;
  83343. FLAC__ASSERT(0 != bw);
  83344. FLAC__ASSERT(0 != bw->buffer);
  83345. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83346. if(val < 0x80) {
  83347. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83348. }
  83349. else if(val < 0x800) {
  83350. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83351. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83352. }
  83353. else if(val < 0x10000) {
  83354. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83355. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83356. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83357. }
  83358. else if(val < 0x200000) {
  83359. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83360. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83361. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83362. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83363. }
  83364. else if(val < 0x4000000) {
  83365. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83366. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83367. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83368. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83369. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83370. }
  83371. else if(val < 0x80000000) {
  83372. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83373. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83374. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83375. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83376. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83377. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83378. }
  83379. else {
  83380. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83381. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83382. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83383. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83384. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83385. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83386. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83387. }
  83388. return ok;
  83389. }
  83390. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83391. {
  83392. if(bw->bits & 7u)
  83393. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83394. else
  83395. return true;
  83396. }
  83397. #endif
  83398. /*** End of inlined file: bitwriter.c ***/
  83399. /*** Start of inlined file: cpu.c ***/
  83400. /*** Start of inlined file: juce_FlacHeader.h ***/
  83401. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83402. // tasks..
  83403. #define VERSION "1.2.1"
  83404. #define FLAC__NO_DLL 1
  83405. #if JUCE_MSVC
  83406. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83407. #endif
  83408. #if JUCE_MAC
  83409. #define FLAC__SYS_DARWIN 1
  83410. #endif
  83411. /*** End of inlined file: juce_FlacHeader.h ***/
  83412. #if JUCE_USE_FLAC
  83413. #if HAVE_CONFIG_H
  83414. # include <config.h>
  83415. #endif
  83416. #include <stdlib.h>
  83417. #include <stdio.h>
  83418. #if defined FLAC__CPU_IA32
  83419. # include <signal.h>
  83420. #elif defined FLAC__CPU_PPC
  83421. # if !defined FLAC__NO_ASM
  83422. # if defined FLAC__SYS_DARWIN
  83423. # include <sys/sysctl.h>
  83424. # include <mach/mach.h>
  83425. # include <mach/mach_host.h>
  83426. # include <mach/host_info.h>
  83427. # include <mach/machine.h>
  83428. # ifndef CPU_SUBTYPE_POWERPC_970
  83429. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83430. # endif
  83431. # else /* FLAC__SYS_DARWIN */
  83432. # include <signal.h>
  83433. # include <setjmp.h>
  83434. static sigjmp_buf jmpbuf;
  83435. static volatile sig_atomic_t canjump = 0;
  83436. static void sigill_handler (int sig)
  83437. {
  83438. if (!canjump) {
  83439. signal (sig, SIG_DFL);
  83440. raise (sig);
  83441. }
  83442. canjump = 0;
  83443. siglongjmp (jmpbuf, 1);
  83444. }
  83445. # endif /* FLAC__SYS_DARWIN */
  83446. # endif /* FLAC__NO_ASM */
  83447. #endif /* FLAC__CPU_PPC */
  83448. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83449. #include <sys/param.h>
  83450. #include <sys/sysctl.h>
  83451. #include <machine/cpu.h>
  83452. #endif
  83453. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83454. #include <sys/types.h>
  83455. #include <sys/sysctl.h>
  83456. #endif
  83457. #if defined(__APPLE__)
  83458. #endif
  83459. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83460. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83461. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83462. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83463. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83464. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83465. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83466. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83467. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83468. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83469. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83470. # if defined(__linux__)
  83471. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83472. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83473. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83474. {
  83475. (void)signal;
  83476. sc.eip += 3 + 3 + 6;
  83477. }
  83478. # else
  83479. # include <sys/ucontext.h>
  83480. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83481. {
  83482. (void)signal, (void)si;
  83483. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83484. }
  83485. # endif
  83486. # elif defined(_MSC_VER)
  83487. # include <windows.h>
  83488. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83489. # ifdef USE_TRY_CATCH_FLAVOR
  83490. # else
  83491. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83492. {
  83493. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83494. ep->ContextRecord->Eip += 3 + 3 + 6;
  83495. return EXCEPTION_CONTINUE_EXECUTION;
  83496. }
  83497. return EXCEPTION_CONTINUE_SEARCH;
  83498. }
  83499. # endif
  83500. # endif
  83501. #endif
  83502. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83503. {
  83504. #ifdef FLAC__CPU_IA32
  83505. info->type = FLAC__CPUINFO_TYPE_IA32;
  83506. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83507. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83508. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83509. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83510. info->data.ia32.cmov = false;
  83511. info->data.ia32.mmx = false;
  83512. info->data.ia32.fxsr = false;
  83513. info->data.ia32.sse = false;
  83514. info->data.ia32.sse2 = false;
  83515. info->data.ia32.sse3 = false;
  83516. info->data.ia32.ssse3 = false;
  83517. info->data.ia32._3dnow = false;
  83518. info->data.ia32.ext3dnow = false;
  83519. info->data.ia32.extmmx = false;
  83520. if(info->data.ia32.cpuid) {
  83521. FLAC__uint32 flags_edx, flags_ecx;
  83522. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83523. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83524. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83525. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83526. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83527. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83528. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83529. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83530. #ifdef FLAC__USE_3DNOW
  83531. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83532. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83533. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83534. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83535. #else
  83536. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83537. #endif
  83538. #ifdef DEBUG
  83539. fprintf(stderr, "CPU info (IA-32):\n");
  83540. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83541. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83542. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83543. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83544. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83545. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83546. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83547. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83548. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83549. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83550. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83551. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83552. #endif
  83553. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83554. #if defined FLAC__NO_SSE_OS
  83555. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83556. #elif defined FLAC__SSE_OS
  83557. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83558. int sse = 0;
  83559. size_t len;
  83560. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83561. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83562. if(!sse)
  83563. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83564. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83565. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83566. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83567. size_t len = sizeof(val);
  83568. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83569. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83570. else { /* double-check SSE2 */
  83571. mib[1] = CPU_SSE2;
  83572. len = sizeof(val);
  83573. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83574. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83575. }
  83576. # else
  83577. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83578. # endif
  83579. #elif defined(__linux__)
  83580. int sse = 0;
  83581. struct sigaction sigill_save;
  83582. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83583. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83584. #else
  83585. struct sigaction sigill_sse;
  83586. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83587. __sigemptyset(&sigill_sse.sa_mask);
  83588. 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 */
  83589. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83590. #endif
  83591. {
  83592. asm volatile (
  83593. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83594. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83595. "incl %0\n\t" /* SIGILL handler will jump over this */
  83596. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83597. "nop\n\t"
  83598. "nop\n\t"
  83599. "nop\n\t"
  83600. "nop\n\t"
  83601. "nop\n\t"
  83602. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83603. "nop\n\t"
  83604. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83605. : "=r"(sse)
  83606. : "r"(sse)
  83607. );
  83608. sigaction(SIGILL, &sigill_save, NULL);
  83609. }
  83610. if(!sse)
  83611. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83612. #elif defined(_MSC_VER)
  83613. # ifdef USE_TRY_CATCH_FLAVOR
  83614. _try {
  83615. __asm {
  83616. # if _MSC_VER <= 1200
  83617. _emit 0x0F
  83618. _emit 0x57
  83619. _emit 0xC0
  83620. # else
  83621. xorps xmm0,xmm0
  83622. # endif
  83623. }
  83624. }
  83625. _except(EXCEPTION_EXECUTE_HANDLER) {
  83626. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83627. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83628. }
  83629. # else
  83630. int sse = 0;
  83631. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83632. __asm {
  83633. # if _MSC_VER <= 1200
  83634. _emit 0x0F
  83635. _emit 0x57
  83636. _emit 0xC0
  83637. # else
  83638. xorps xmm0,xmm0
  83639. # endif
  83640. inc sse
  83641. nop
  83642. nop
  83643. nop
  83644. nop
  83645. nop
  83646. nop
  83647. nop
  83648. nop
  83649. nop
  83650. }
  83651. SetUnhandledExceptionFilter(save);
  83652. if(!sse)
  83653. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83654. # endif
  83655. #else
  83656. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83657. #endif
  83658. #ifdef DEBUG
  83659. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83660. #endif
  83661. }
  83662. }
  83663. #else
  83664. info->use_asm = false;
  83665. #endif
  83666. #elif defined FLAC__CPU_PPC
  83667. info->type = FLAC__CPUINFO_TYPE_PPC;
  83668. # if !defined FLAC__NO_ASM
  83669. info->use_asm = true;
  83670. # ifdef FLAC__USE_ALTIVEC
  83671. # if defined FLAC__SYS_DARWIN
  83672. {
  83673. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83674. size_t len = sizeof(val);
  83675. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83676. }
  83677. {
  83678. host_basic_info_data_t hostInfo;
  83679. mach_msg_type_number_t infoCount;
  83680. infoCount = HOST_BASIC_INFO_COUNT;
  83681. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83682. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83683. }
  83684. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83685. {
  83686. info->data.ppc.altivec = 0;
  83687. info->data.ppc.ppc64 = 0;
  83688. signal (SIGILL, sigill_handler);
  83689. canjump = 0;
  83690. if (!sigsetjmp (jmpbuf, 1)) {
  83691. canjump = 1;
  83692. asm volatile (
  83693. "mtspr 256, %0\n\t"
  83694. "vand %%v0, %%v0, %%v0"
  83695. :
  83696. : "r" (-1)
  83697. );
  83698. info->data.ppc.altivec = 1;
  83699. }
  83700. canjump = 0;
  83701. if (!sigsetjmp (jmpbuf, 1)) {
  83702. int x = 0;
  83703. canjump = 1;
  83704. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83705. info->data.ppc.ppc64 = 1;
  83706. }
  83707. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83708. }
  83709. # endif
  83710. # else /* !FLAC__USE_ALTIVEC */
  83711. info->data.ppc.altivec = 0;
  83712. info->data.ppc.ppc64 = 0;
  83713. # endif
  83714. # else
  83715. info->use_asm = false;
  83716. # endif
  83717. #else
  83718. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83719. info->use_asm = false;
  83720. #endif
  83721. }
  83722. #endif
  83723. /*** End of inlined file: cpu.c ***/
  83724. /*** Start of inlined file: crc.c ***/
  83725. /*** Start of inlined file: juce_FlacHeader.h ***/
  83726. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83727. // tasks..
  83728. #define VERSION "1.2.1"
  83729. #define FLAC__NO_DLL 1
  83730. #if JUCE_MSVC
  83731. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83732. #endif
  83733. #if JUCE_MAC
  83734. #define FLAC__SYS_DARWIN 1
  83735. #endif
  83736. /*** End of inlined file: juce_FlacHeader.h ***/
  83737. #if JUCE_USE_FLAC
  83738. #if HAVE_CONFIG_H
  83739. # include <config.h>
  83740. #endif
  83741. FLAC__byte const FLAC__crc8_table[256] = {
  83742. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83743. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83744. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83745. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83746. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83747. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83748. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83749. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83750. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83751. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83752. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83753. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83754. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83755. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83756. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83757. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83758. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83759. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83760. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83761. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83762. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83763. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83764. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83765. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83766. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83767. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83768. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83769. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83770. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83771. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83772. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83773. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83774. };
  83775. unsigned FLAC__crc16_table[256] = {
  83776. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83777. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83778. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83779. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83780. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83781. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83782. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83783. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83784. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83785. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83786. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83787. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83788. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83789. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83790. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83791. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83792. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83793. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83794. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83795. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83796. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83797. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83798. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83799. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83800. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83801. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83802. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83803. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83804. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83805. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83806. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83807. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83808. };
  83809. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83810. {
  83811. *crc = FLAC__crc8_table[*crc ^ data];
  83812. }
  83813. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83814. {
  83815. while(len--)
  83816. *crc = FLAC__crc8_table[*crc ^ *data++];
  83817. }
  83818. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83819. {
  83820. FLAC__uint8 crc = 0;
  83821. while(len--)
  83822. crc = FLAC__crc8_table[crc ^ *data++];
  83823. return crc;
  83824. }
  83825. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83826. {
  83827. unsigned crc = 0;
  83828. while(len--)
  83829. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83830. return crc;
  83831. }
  83832. #endif
  83833. /*** End of inlined file: crc.c ***/
  83834. /*** Start of inlined file: fixed.c ***/
  83835. /*** Start of inlined file: juce_FlacHeader.h ***/
  83836. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83837. // tasks..
  83838. #define VERSION "1.2.1"
  83839. #define FLAC__NO_DLL 1
  83840. #if JUCE_MSVC
  83841. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83842. #endif
  83843. #if JUCE_MAC
  83844. #define FLAC__SYS_DARWIN 1
  83845. #endif
  83846. /*** End of inlined file: juce_FlacHeader.h ***/
  83847. #if JUCE_USE_FLAC
  83848. #if HAVE_CONFIG_H
  83849. # include <config.h>
  83850. #endif
  83851. #include <math.h>
  83852. #include <string.h>
  83853. /*** Start of inlined file: fixed.h ***/
  83854. #ifndef FLAC__PRIVATE__FIXED_H
  83855. #define FLAC__PRIVATE__FIXED_H
  83856. #ifdef HAVE_CONFIG_H
  83857. #include <config.h>
  83858. #endif
  83859. /*** Start of inlined file: float.h ***/
  83860. #ifndef FLAC__PRIVATE__FLOAT_H
  83861. #define FLAC__PRIVATE__FLOAT_H
  83862. #ifdef HAVE_CONFIG_H
  83863. #include <config.h>
  83864. #endif
  83865. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83866. typedef double FLAC__double;
  83867. typedef float FLAC__float;
  83868. typedef float FLAC__real;
  83869. #else
  83870. typedef FLAC__int32 FLAC__fixedpoint;
  83871. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83872. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83873. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83874. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83875. extern const FLAC__fixedpoint FLAC__FP_E;
  83876. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83877. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83878. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83879. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83880. #endif
  83881. #endif
  83882. /*** End of inlined file: float.h ***/
  83883. /*** Start of inlined file: format.h ***/
  83884. #ifndef FLAC__PRIVATE__FORMAT_H
  83885. #define FLAC__PRIVATE__FORMAT_H
  83886. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83887. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83888. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83889. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83890. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83891. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83892. #endif
  83893. /*** End of inlined file: format.h ***/
  83894. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83895. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83896. # ifndef FLAC__NO_ASM
  83897. # ifdef FLAC__CPU_IA32
  83898. # ifdef FLAC__HAS_NASM
  83899. 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]);
  83900. # endif
  83901. # endif
  83902. # endif
  83903. 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]);
  83904. #else
  83905. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83906. 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]);
  83907. #endif
  83908. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83909. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83910. #endif
  83911. /*** End of inlined file: fixed.h ***/
  83912. #ifndef M_LN2
  83913. #define M_LN2 0.69314718055994530942
  83914. #endif
  83915. #ifdef min
  83916. #undef min
  83917. #endif
  83918. #define min(x,y) ((x) < (y)? (x) : (y))
  83919. #ifdef local_abs
  83920. #undef local_abs
  83921. #endif
  83922. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83923. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83924. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83925. {
  83926. FLAC__uint32 rbps;
  83927. unsigned bits; /* the number of bits required to represent a number */
  83928. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83929. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83930. FLAC__ASSERT(err > 0);
  83931. FLAC__ASSERT(n > 0);
  83932. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83933. if(err <= n)
  83934. return 0;
  83935. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  83936. err <<= fracbits;
  83937. err /= n;
  83938. FLAC__ASSERT(err > 0);
  83939. bits = FLAC__bitmath_ilog2(err)+1;
  83940. if(bits > 16) {
  83941. err >>= (bits-16);
  83942. fracbits -= (bits-16);
  83943. }
  83944. rbps = (FLAC__uint32)err;
  83945. rbps *= FLAC__FP_LN2;
  83946. fracbits += 16;
  83947. FLAC__ASSERT(fracbits >= 0);
  83948. {
  83949. const int f = fracbits & 3;
  83950. if(f) {
  83951. rbps >>= f;
  83952. fracbits -= f;
  83953. }
  83954. }
  83955. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83956. if(rbps == 0)
  83957. return 0;
  83958. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83959. FLAC__ASSERT(fracbits >= -3);
  83960. if(fracbits < 16)
  83961. return rbps << (16-fracbits);
  83962. else if(fracbits > 16)
  83963. return rbps >> (fracbits-16);
  83964. else
  83965. return rbps;
  83966. }
  83967. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  83968. {
  83969. FLAC__uint32 rbps;
  83970. unsigned bits; /* the number of bits required to represent a number */
  83971. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83972. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83973. FLAC__ASSERT(err > 0);
  83974. FLAC__ASSERT(n > 0);
  83975. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83976. if(err <= n)
  83977. return 0;
  83978. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  83979. err <<= fracbits;
  83980. err /= n;
  83981. FLAC__ASSERT(err > 0);
  83982. bits = FLAC__bitmath_ilog2_wide(err)+1;
  83983. if(bits > 16) {
  83984. err >>= (bits-16);
  83985. fracbits -= (bits-16);
  83986. }
  83987. rbps = (FLAC__uint32)err;
  83988. rbps *= FLAC__FP_LN2;
  83989. fracbits += 16;
  83990. FLAC__ASSERT(fracbits >= 0);
  83991. {
  83992. const int f = fracbits & 3;
  83993. if(f) {
  83994. rbps >>= f;
  83995. fracbits -= f;
  83996. }
  83997. }
  83998. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83999. if(rbps == 0)
  84000. return 0;
  84001. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84002. FLAC__ASSERT(fracbits >= -3);
  84003. if(fracbits < 16)
  84004. return rbps << (16-fracbits);
  84005. else if(fracbits > 16)
  84006. return rbps >> (fracbits-16);
  84007. else
  84008. return rbps;
  84009. }
  84010. #endif
  84011. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84012. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84013. #else
  84014. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84015. #endif
  84016. {
  84017. FLAC__int32 last_error_0 = data[-1];
  84018. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84019. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84020. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84021. FLAC__int32 error, save;
  84022. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84023. unsigned i, order;
  84024. for(i = 0; i < data_len; i++) {
  84025. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84026. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84027. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84028. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84029. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84030. }
  84031. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84032. order = 0;
  84033. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84034. order = 1;
  84035. else if(total_error_2 < min(total_error_3, total_error_4))
  84036. order = 2;
  84037. else if(total_error_3 < total_error_4)
  84038. order = 3;
  84039. else
  84040. order = 4;
  84041. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84042. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84043. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84044. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84045. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84046. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84047. 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);
  84048. 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);
  84049. 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);
  84050. 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);
  84051. 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);
  84052. #else
  84053. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84054. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84055. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84056. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84057. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84058. #endif
  84059. return order;
  84060. }
  84061. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84062. 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])
  84063. #else
  84064. 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])
  84065. #endif
  84066. {
  84067. FLAC__int32 last_error_0 = data[-1];
  84068. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84069. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84070. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84071. FLAC__int32 error, save;
  84072. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84073. unsigned i, order;
  84074. for(i = 0; i < data_len; i++) {
  84075. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84076. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84077. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84078. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84079. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84080. }
  84081. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84082. order = 0;
  84083. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84084. order = 1;
  84085. else if(total_error_2 < min(total_error_3, total_error_4))
  84086. order = 2;
  84087. else if(total_error_3 < total_error_4)
  84088. order = 3;
  84089. else
  84090. order = 4;
  84091. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84092. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84093. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84094. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84095. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84096. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84097. #if defined _MSC_VER || defined __MINGW32__
  84098. 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);
  84099. 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);
  84100. 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);
  84101. 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);
  84102. 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);
  84103. #else
  84104. 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);
  84105. 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);
  84106. 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);
  84107. 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);
  84108. 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);
  84109. #endif
  84110. #else
  84111. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84112. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84113. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84114. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84115. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84116. #endif
  84117. return order;
  84118. }
  84119. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84120. {
  84121. const int idata_len = (int)data_len;
  84122. int i;
  84123. switch(order) {
  84124. case 0:
  84125. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84126. memcpy(residual, data, sizeof(residual[0])*data_len);
  84127. break;
  84128. case 1:
  84129. for(i = 0; i < idata_len; i++)
  84130. residual[i] = data[i] - data[i-1];
  84131. break;
  84132. case 2:
  84133. for(i = 0; i < idata_len; i++)
  84134. #if 1 /* OPT: may be faster with some compilers on some systems */
  84135. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84136. #else
  84137. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84138. #endif
  84139. break;
  84140. case 3:
  84141. for(i = 0; i < idata_len; i++)
  84142. #if 1 /* OPT: may be faster with some compilers on some systems */
  84143. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84144. #else
  84145. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84146. #endif
  84147. break;
  84148. case 4:
  84149. for(i = 0; i < idata_len; i++)
  84150. #if 1 /* OPT: may be faster with some compilers on some systems */
  84151. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84152. #else
  84153. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84154. #endif
  84155. break;
  84156. default:
  84157. FLAC__ASSERT(0);
  84158. }
  84159. }
  84160. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84161. {
  84162. int i, idata_len = (int)data_len;
  84163. switch(order) {
  84164. case 0:
  84165. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84166. memcpy(data, residual, sizeof(residual[0])*data_len);
  84167. break;
  84168. case 1:
  84169. for(i = 0; i < idata_len; i++)
  84170. data[i] = residual[i] + data[i-1];
  84171. break;
  84172. case 2:
  84173. for(i = 0; i < idata_len; i++)
  84174. #if 1 /* OPT: may be faster with some compilers on some systems */
  84175. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84176. #else
  84177. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84178. #endif
  84179. break;
  84180. case 3:
  84181. for(i = 0; i < idata_len; i++)
  84182. #if 1 /* OPT: may be faster with some compilers on some systems */
  84183. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84184. #else
  84185. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84186. #endif
  84187. break;
  84188. case 4:
  84189. for(i = 0; i < idata_len; i++)
  84190. #if 1 /* OPT: may be faster with some compilers on some systems */
  84191. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84192. #else
  84193. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84194. #endif
  84195. break;
  84196. default:
  84197. FLAC__ASSERT(0);
  84198. }
  84199. }
  84200. #endif
  84201. /*** End of inlined file: fixed.c ***/
  84202. /*** Start of inlined file: float.c ***/
  84203. /*** Start of inlined file: juce_FlacHeader.h ***/
  84204. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84205. // tasks..
  84206. #define VERSION "1.2.1"
  84207. #define FLAC__NO_DLL 1
  84208. #if JUCE_MSVC
  84209. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84210. #endif
  84211. #if JUCE_MAC
  84212. #define FLAC__SYS_DARWIN 1
  84213. #endif
  84214. /*** End of inlined file: juce_FlacHeader.h ***/
  84215. #if JUCE_USE_FLAC
  84216. #if HAVE_CONFIG_H
  84217. # include <config.h>
  84218. #endif
  84219. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84220. #ifdef _MSC_VER
  84221. #define FLAC__U64L(x) x
  84222. #else
  84223. #define FLAC__U64L(x) x##LLU
  84224. #endif
  84225. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84226. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84227. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84228. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84229. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84230. #define LOG2_LOOKUP_PRECISION 16
  84231. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84232. {
  84233. 0x00000000,
  84234. 0x00000001,
  84235. 0x00000000,
  84236. 0x00000000,
  84237. 0x00000000,
  84238. 0x00000000,
  84239. 0x00000000,
  84240. 0x00000000,
  84241. 0x00000000,
  84242. 0x00000000,
  84243. 0x00000000,
  84244. 0x00000000,
  84245. 0x00000000,
  84246. 0x00000000,
  84247. 0x00000000,
  84248. 0x00000000
  84249. },
  84250. {
  84251. 0x00000000,
  84252. 0x00000010,
  84253. 0x00000007,
  84254. 0x00000003,
  84255. 0x00000001,
  84256. 0x00000001,
  84257. 0x00000000,
  84258. 0x00000000,
  84259. 0x00000000,
  84260. 0x00000000,
  84261. 0x00000000,
  84262. 0x00000000,
  84263. 0x00000000,
  84264. 0x00000000,
  84265. 0x00000000,
  84266. 0x00000000
  84267. },
  84268. {
  84269. 0x00000000,
  84270. 0x00000100,
  84271. 0x0000006a,
  84272. 0x00000031,
  84273. 0x00000018,
  84274. 0x0000000c,
  84275. 0x00000006,
  84276. 0x00000003,
  84277. 0x00000001,
  84278. 0x00000001,
  84279. 0x00000000,
  84280. 0x00000000,
  84281. 0x00000000,
  84282. 0x00000000,
  84283. 0x00000000,
  84284. 0x00000000
  84285. },
  84286. {
  84287. 0x00000000,
  84288. 0x00001000,
  84289. 0x000006a4,
  84290. 0x00000315,
  84291. 0x0000017d,
  84292. 0x000000bc,
  84293. 0x0000005d,
  84294. 0x0000002e,
  84295. 0x00000017,
  84296. 0x0000000c,
  84297. 0x00000006,
  84298. 0x00000003,
  84299. 0x00000001,
  84300. 0x00000001,
  84301. 0x00000000,
  84302. 0x00000000
  84303. },
  84304. {
  84305. 0x00000000,
  84306. 0x00010000,
  84307. 0x00006a40,
  84308. 0x00003151,
  84309. 0x000017d6,
  84310. 0x00000bba,
  84311. 0x000005d1,
  84312. 0x000002e6,
  84313. 0x00000172,
  84314. 0x000000b9,
  84315. 0x0000005c,
  84316. 0x0000002e,
  84317. 0x00000017,
  84318. 0x0000000c,
  84319. 0x00000006,
  84320. 0x00000003
  84321. },
  84322. {
  84323. 0x00000000,
  84324. 0x00100000,
  84325. 0x0006a3fe,
  84326. 0x00031513,
  84327. 0x00017d60,
  84328. 0x0000bb9d,
  84329. 0x00005d10,
  84330. 0x00002e59,
  84331. 0x00001721,
  84332. 0x00000b8e,
  84333. 0x000005c6,
  84334. 0x000002e3,
  84335. 0x00000171,
  84336. 0x000000b9,
  84337. 0x0000005c,
  84338. 0x0000002e
  84339. },
  84340. {
  84341. 0x00000000,
  84342. 0x01000000,
  84343. 0x006a3fe6,
  84344. 0x00315130,
  84345. 0x0017d605,
  84346. 0x000bb9ca,
  84347. 0x0005d0fc,
  84348. 0x0002e58f,
  84349. 0x0001720e,
  84350. 0x0000b8d8,
  84351. 0x00005c61,
  84352. 0x00002e2d,
  84353. 0x00001716,
  84354. 0x00000b8b,
  84355. 0x000005c5,
  84356. 0x000002e3
  84357. },
  84358. {
  84359. 0x00000000,
  84360. 0x10000000,
  84361. 0x06a3fe5c,
  84362. 0x03151301,
  84363. 0x017d6049,
  84364. 0x00bb9ca6,
  84365. 0x005d0fba,
  84366. 0x002e58f7,
  84367. 0x001720da,
  84368. 0x000b8d87,
  84369. 0x0005c60b,
  84370. 0x0002e2d7,
  84371. 0x00017160,
  84372. 0x0000b8ad,
  84373. 0x00005c56,
  84374. 0x00002e2b
  84375. }
  84376. };
  84377. #if 0
  84378. static const FLAC__uint64 log2_lookup_wide[] = {
  84379. {
  84380. 0x00000000,
  84381. FLAC__U64L(0x100000000),
  84382. FLAC__U64L(0x6a3fe5c6),
  84383. FLAC__U64L(0x31513015),
  84384. FLAC__U64L(0x17d60497),
  84385. FLAC__U64L(0x0bb9ca65),
  84386. FLAC__U64L(0x05d0fba2),
  84387. FLAC__U64L(0x02e58f74),
  84388. FLAC__U64L(0x01720d9c),
  84389. FLAC__U64L(0x00b8d875),
  84390. FLAC__U64L(0x005c60aa),
  84391. FLAC__U64L(0x002e2d72),
  84392. FLAC__U64L(0x00171600),
  84393. FLAC__U64L(0x000b8ad2),
  84394. FLAC__U64L(0x0005c55d),
  84395. FLAC__U64L(0x0002e2ac)
  84396. },
  84397. {
  84398. 0x00000000,
  84399. FLAC__U64L(0x1000000000000),
  84400. FLAC__U64L(0x6a3fe5c60429),
  84401. FLAC__U64L(0x315130157f7a),
  84402. FLAC__U64L(0x17d60496cfbb),
  84403. FLAC__U64L(0xbb9ca64ecac),
  84404. FLAC__U64L(0x5d0fba187cd),
  84405. FLAC__U64L(0x2e58f7441ee),
  84406. FLAC__U64L(0x1720d9c06a8),
  84407. FLAC__U64L(0xb8d8752173),
  84408. FLAC__U64L(0x5c60aa252e),
  84409. FLAC__U64L(0x2e2d71b0d8),
  84410. FLAC__U64L(0x1716001719),
  84411. FLAC__U64L(0xb8ad1de1b),
  84412. FLAC__U64L(0x5c55d640d),
  84413. FLAC__U64L(0x2e2abcf52)
  84414. }
  84415. };
  84416. #endif
  84417. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84418. {
  84419. const FLAC__uint32 ONE = (1u << fracbits);
  84420. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84421. FLAC__ASSERT(fracbits < 32);
  84422. FLAC__ASSERT((fracbits & 0x3) == 0);
  84423. if(x < ONE)
  84424. return 0;
  84425. if(precision > LOG2_LOOKUP_PRECISION)
  84426. precision = LOG2_LOOKUP_PRECISION;
  84427. {
  84428. FLAC__uint32 y = 0;
  84429. FLAC__uint32 z = x >> 1, k = 1;
  84430. while (x > ONE && k < precision) {
  84431. if (x - z >= ONE) {
  84432. x -= z;
  84433. z = x >> k;
  84434. y += table[k];
  84435. }
  84436. else {
  84437. z >>= 1;
  84438. k++;
  84439. }
  84440. }
  84441. return y;
  84442. }
  84443. }
  84444. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84445. #endif
  84446. /*** End of inlined file: float.c ***/
  84447. /*** Start of inlined file: format.c ***/
  84448. /*** Start of inlined file: juce_FlacHeader.h ***/
  84449. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84450. // tasks..
  84451. #define VERSION "1.2.1"
  84452. #define FLAC__NO_DLL 1
  84453. #if JUCE_MSVC
  84454. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84455. #endif
  84456. #if JUCE_MAC
  84457. #define FLAC__SYS_DARWIN 1
  84458. #endif
  84459. /*** End of inlined file: juce_FlacHeader.h ***/
  84460. #if JUCE_USE_FLAC
  84461. #if HAVE_CONFIG_H
  84462. # include <config.h>
  84463. #endif
  84464. #include <stdio.h>
  84465. #include <stdlib.h> /* for qsort() */
  84466. #include <string.h> /* for memset() */
  84467. #ifndef FLaC__INLINE
  84468. #define FLaC__INLINE
  84469. #endif
  84470. #ifdef min
  84471. #undef min
  84472. #endif
  84473. #define min(a,b) ((a)<(b)?(a):(b))
  84474. #ifdef _MSC_VER
  84475. #define FLAC__U64L(x) x
  84476. #else
  84477. #define FLAC__U64L(x) x##LLU
  84478. #endif
  84479. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84480. ;
  84481. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84482. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84483. #else
  84484. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84485. #endif
  84486. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84487. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84488. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84489. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84490. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84491. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84492. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84493. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84494. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84495. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84496. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84497. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84498. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84499. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84500. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84501. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84502. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84503. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84504. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84505. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84506. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84507. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84508. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84509. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84510. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84511. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84512. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84513. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84514. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84515. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84516. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84517. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84518. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84519. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84520. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84521. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84522. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84523. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84524. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84525. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84526. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84527. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84528. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84529. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84530. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84531. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84532. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84533. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84534. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84535. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84536. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84537. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84538. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84539. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84540. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84541. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84542. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84543. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84544. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84545. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84546. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84547. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84548. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84549. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84550. "PARTITIONED_RICE",
  84551. "PARTITIONED_RICE2"
  84552. };
  84553. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84554. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84555. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84556. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84557. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84558. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84559. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84560. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84561. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84562. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84563. "CONSTANT",
  84564. "VERBATIM",
  84565. "FIXED",
  84566. "LPC"
  84567. };
  84568. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84569. "INDEPENDENT",
  84570. "LEFT_SIDE",
  84571. "RIGHT_SIDE",
  84572. "MID_SIDE"
  84573. };
  84574. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84575. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84576. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84577. };
  84578. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84579. "STREAMINFO",
  84580. "PADDING",
  84581. "APPLICATION",
  84582. "SEEKTABLE",
  84583. "VORBIS_COMMENT",
  84584. "CUESHEET",
  84585. "PICTURE"
  84586. };
  84587. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84588. "Other",
  84589. "32x32 pixels 'file icon' (PNG only)",
  84590. "Other file icon",
  84591. "Cover (front)",
  84592. "Cover (back)",
  84593. "Leaflet page",
  84594. "Media (e.g. label side of CD)",
  84595. "Lead artist/lead performer/soloist",
  84596. "Artist/performer",
  84597. "Conductor",
  84598. "Band/Orchestra",
  84599. "Composer",
  84600. "Lyricist/text writer",
  84601. "Recording Location",
  84602. "During recording",
  84603. "During performance",
  84604. "Movie/video screen capture",
  84605. "A bright coloured fish",
  84606. "Illustration",
  84607. "Band/artist logotype",
  84608. "Publisher/Studio logotype"
  84609. };
  84610. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84611. {
  84612. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84613. return false;
  84614. }
  84615. else
  84616. return true;
  84617. }
  84618. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84619. {
  84620. if(
  84621. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84622. (
  84623. sample_rate >= (1u << 16) &&
  84624. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84625. )
  84626. ) {
  84627. return false;
  84628. }
  84629. else
  84630. return true;
  84631. }
  84632. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84633. {
  84634. unsigned i;
  84635. FLAC__uint64 prev_sample_number = 0;
  84636. FLAC__bool got_prev = false;
  84637. FLAC__ASSERT(0 != seek_table);
  84638. for(i = 0; i < seek_table->num_points; i++) {
  84639. if(got_prev) {
  84640. if(
  84641. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84642. seek_table->points[i].sample_number <= prev_sample_number
  84643. )
  84644. return false;
  84645. }
  84646. prev_sample_number = seek_table->points[i].sample_number;
  84647. got_prev = true;
  84648. }
  84649. return true;
  84650. }
  84651. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84652. {
  84653. if(l->sample_number == r->sample_number)
  84654. return 0;
  84655. else if(l->sample_number < r->sample_number)
  84656. return -1;
  84657. else
  84658. return 1;
  84659. }
  84660. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84661. {
  84662. unsigned i, j;
  84663. FLAC__bool first;
  84664. FLAC__ASSERT(0 != seek_table);
  84665. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84666. first = true;
  84667. for(i = j = 0; i < seek_table->num_points; i++) {
  84668. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84669. if(!first) {
  84670. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84671. continue;
  84672. }
  84673. }
  84674. first = false;
  84675. seek_table->points[j++] = seek_table->points[i];
  84676. }
  84677. for(i = j; i < seek_table->num_points; i++) {
  84678. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84679. seek_table->points[i].stream_offset = 0;
  84680. seek_table->points[i].frame_samples = 0;
  84681. }
  84682. return j;
  84683. }
  84684. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84685. {
  84686. FLAC__ASSERT(0 != utf8);
  84687. if ((utf8[0] & 0x80) == 0) {
  84688. return 1;
  84689. }
  84690. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84691. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84692. return 0;
  84693. return 2;
  84694. }
  84695. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84696. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84697. return 0;
  84698. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84699. return 0;
  84700. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84701. return 0;
  84702. return 3;
  84703. }
  84704. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84705. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84706. return 0;
  84707. return 4;
  84708. }
  84709. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84710. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84711. return 0;
  84712. return 5;
  84713. }
  84714. 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) {
  84715. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84716. return 0;
  84717. return 6;
  84718. }
  84719. else {
  84720. return 0;
  84721. }
  84722. }
  84723. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84724. {
  84725. char c;
  84726. for(c = *name; c; c = *(++name))
  84727. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84728. return false;
  84729. return true;
  84730. }
  84731. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84732. {
  84733. if(length == (unsigned)(-1)) {
  84734. while(*value) {
  84735. unsigned n = utf8len_(value);
  84736. if(n == 0)
  84737. return false;
  84738. value += n;
  84739. }
  84740. }
  84741. else {
  84742. const FLAC__byte *end = value + length;
  84743. while(value < end) {
  84744. unsigned n = utf8len_(value);
  84745. if(n == 0)
  84746. return false;
  84747. value += n;
  84748. }
  84749. if(value != end)
  84750. return false;
  84751. }
  84752. return true;
  84753. }
  84754. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84755. {
  84756. const FLAC__byte *s, *end;
  84757. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84758. if(*s < 0x20 || *s > 0x7D)
  84759. return false;
  84760. }
  84761. if(s == end)
  84762. return false;
  84763. s++; /* skip '=' */
  84764. while(s < end) {
  84765. unsigned n = utf8len_(s);
  84766. if(n == 0)
  84767. return false;
  84768. s += n;
  84769. }
  84770. if(s != end)
  84771. return false;
  84772. return true;
  84773. }
  84774. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84775. {
  84776. unsigned i, j;
  84777. if(check_cd_da_subset) {
  84778. if(cue_sheet->lead_in < 2 * 44100) {
  84779. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84780. return false;
  84781. }
  84782. if(cue_sheet->lead_in % 588 != 0) {
  84783. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84784. return false;
  84785. }
  84786. }
  84787. if(cue_sheet->num_tracks == 0) {
  84788. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84789. return false;
  84790. }
  84791. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84792. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84793. return false;
  84794. }
  84795. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84796. if(cue_sheet->tracks[i].number == 0) {
  84797. if(violation) *violation = "cue sheet may not have a track number 0";
  84798. return false;
  84799. }
  84800. if(check_cd_da_subset) {
  84801. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84802. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84803. return false;
  84804. }
  84805. }
  84806. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84807. if(violation) {
  84808. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84809. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84810. else
  84811. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84812. }
  84813. return false;
  84814. }
  84815. if(i < cue_sheet->num_tracks - 1) {
  84816. if(cue_sheet->tracks[i].num_indices == 0) {
  84817. if(violation) *violation = "cue sheet track must have at least one index point";
  84818. return false;
  84819. }
  84820. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84821. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84822. return false;
  84823. }
  84824. }
  84825. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84826. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84827. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84828. return false;
  84829. }
  84830. if(j > 0) {
  84831. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84832. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84833. return false;
  84834. }
  84835. }
  84836. }
  84837. }
  84838. return true;
  84839. }
  84840. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84841. {
  84842. char *p;
  84843. FLAC__byte *b;
  84844. for(p = picture->mime_type; *p; p++) {
  84845. if(*p < 0x20 || *p > 0x7e) {
  84846. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84847. return false;
  84848. }
  84849. }
  84850. for(b = picture->description; *b; ) {
  84851. unsigned n = utf8len_(b);
  84852. if(n == 0) {
  84853. if(violation) *violation = "description string must be valid UTF-8";
  84854. return false;
  84855. }
  84856. b += n;
  84857. }
  84858. return true;
  84859. }
  84860. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84861. {
  84862. return
  84863. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84864. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84865. blocksize,
  84866. predictor_order
  84867. );
  84868. }
  84869. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84870. {
  84871. unsigned max_rice_partition_order = 0;
  84872. while(!(blocksize & 1)) {
  84873. max_rice_partition_order++;
  84874. blocksize >>= 1;
  84875. }
  84876. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84877. }
  84878. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84879. {
  84880. unsigned max_rice_partition_order = limit;
  84881. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84882. max_rice_partition_order--;
  84883. FLAC__ASSERT(
  84884. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84885. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84886. );
  84887. return max_rice_partition_order;
  84888. }
  84889. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84890. {
  84891. FLAC__ASSERT(0 != object);
  84892. object->parameters = 0;
  84893. object->raw_bits = 0;
  84894. object->capacity_by_order = 0;
  84895. }
  84896. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84897. {
  84898. FLAC__ASSERT(0 != object);
  84899. if(0 != object->parameters)
  84900. free(object->parameters);
  84901. if(0 != object->raw_bits)
  84902. free(object->raw_bits);
  84903. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84904. }
  84905. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84906. {
  84907. FLAC__ASSERT(0 != object);
  84908. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84909. if(object->capacity_by_order < max_partition_order) {
  84910. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84911. return false;
  84912. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84913. return false;
  84914. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84915. object->capacity_by_order = max_partition_order;
  84916. }
  84917. return true;
  84918. }
  84919. #endif
  84920. /*** End of inlined file: format.c ***/
  84921. /*** Start of inlined file: lpc_flac.c ***/
  84922. /*** Start of inlined file: juce_FlacHeader.h ***/
  84923. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84924. // tasks..
  84925. #define VERSION "1.2.1"
  84926. #define FLAC__NO_DLL 1
  84927. #if JUCE_MSVC
  84928. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84929. #endif
  84930. #if JUCE_MAC
  84931. #define FLAC__SYS_DARWIN 1
  84932. #endif
  84933. /*** End of inlined file: juce_FlacHeader.h ***/
  84934. #if JUCE_USE_FLAC
  84935. #if HAVE_CONFIG_H
  84936. # include <config.h>
  84937. #endif
  84938. #include <math.h>
  84939. /*** Start of inlined file: lpc.h ***/
  84940. #ifndef FLAC__PRIVATE__LPC_H
  84941. #define FLAC__PRIVATE__LPC_H
  84942. #ifdef HAVE_CONFIG_H
  84943. #include <config.h>
  84944. #endif
  84945. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84946. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  84947. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84948. #ifndef FLAC__NO_ASM
  84949. # ifdef FLAC__CPU_IA32
  84950. # ifdef FLAC__HAS_NASM
  84951. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84952. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84953. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84954. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84955. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84956. # endif
  84957. # endif
  84958. #endif
  84959. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  84960. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  84961. 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[]);
  84962. 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[]);
  84963. #ifndef FLAC__NO_ASM
  84964. # ifdef FLAC__CPU_IA32
  84965. # ifdef FLAC__HAS_NASM
  84966. 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[]);
  84967. 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[]);
  84968. # endif
  84969. # endif
  84970. #endif
  84971. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84972. 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[]);
  84973. 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[]);
  84974. #ifndef FLAC__NO_ASM
  84975. # ifdef FLAC__CPU_IA32
  84976. # ifdef FLAC__HAS_NASM
  84977. 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[]);
  84978. 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[]);
  84979. # endif /* FLAC__HAS_NASM */
  84980. # elif defined FLAC__CPU_PPC
  84981. 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[]);
  84982. 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[]);
  84983. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  84984. #endif /* FLAC__NO_ASM */
  84985. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84986. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  84987. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  84988. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  84989. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84990. #endif
  84991. /*** End of inlined file: lpc.h ***/
  84992. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  84993. #include <stdio.h>
  84994. #endif
  84995. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84996. #ifndef M_LN2
  84997. #define M_LN2 0.69314718055994530942
  84998. #endif
  84999. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85000. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85001. {
  85002. unsigned i;
  85003. for(i = 0; i < data_len; i++)
  85004. out[i] = in[i] * window[i];
  85005. }
  85006. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85007. {
  85008. #if 0
  85009. FLAC__real d;
  85010. unsigned i;
  85011. FLAC__ASSERT(lag > 0);
  85012. FLAC__ASSERT(lag <= data_len);
  85013. while(lag--) {
  85014. for(i = lag, d = 0.0; i < data_len; i++)
  85015. d += data[i] * data[i - lag];
  85016. autoc[lag] = d;
  85017. }
  85018. #endif
  85019. FLAC__real d;
  85020. unsigned sample, coeff;
  85021. const unsigned limit = data_len - lag;
  85022. FLAC__ASSERT(lag > 0);
  85023. FLAC__ASSERT(lag <= data_len);
  85024. for(coeff = 0; coeff < lag; coeff++)
  85025. autoc[coeff] = 0.0;
  85026. for(sample = 0; sample <= limit; sample++) {
  85027. d = data[sample];
  85028. for(coeff = 0; coeff < lag; coeff++)
  85029. autoc[coeff] += d * data[sample+coeff];
  85030. }
  85031. for(; sample < data_len; sample++) {
  85032. d = data[sample];
  85033. for(coeff = 0; coeff < data_len - sample; coeff++)
  85034. autoc[coeff] += d * data[sample+coeff];
  85035. }
  85036. }
  85037. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85038. {
  85039. unsigned i, j;
  85040. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85041. FLAC__ASSERT(0 != max_order);
  85042. FLAC__ASSERT(0 < *max_order);
  85043. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85044. FLAC__ASSERT(autoc[0] != 0.0);
  85045. err = autoc[0];
  85046. for(i = 0; i < *max_order; i++) {
  85047. r = -autoc[i+1];
  85048. for(j = 0; j < i; j++)
  85049. r -= lpc[j] * autoc[i-j];
  85050. ref[i] = (r/=err);
  85051. lpc[i]=r;
  85052. for(j = 0; j < (i>>1); j++) {
  85053. FLAC__double tmp = lpc[j];
  85054. lpc[j] += r * lpc[i-1-j];
  85055. lpc[i-1-j] += r * tmp;
  85056. }
  85057. if(i & 1)
  85058. lpc[j] += lpc[j] * r;
  85059. err *= (1.0 - r * r);
  85060. for(j = 0; j <= i; j++)
  85061. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85062. error[i] = err;
  85063. if(err == 0.0) {
  85064. *max_order = i+1;
  85065. return;
  85066. }
  85067. }
  85068. }
  85069. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85070. {
  85071. unsigned i;
  85072. FLAC__double cmax;
  85073. FLAC__int32 qmax, qmin;
  85074. FLAC__ASSERT(precision > 0);
  85075. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85076. precision--;
  85077. qmax = 1 << precision;
  85078. qmin = -qmax;
  85079. qmax--;
  85080. cmax = 0.0;
  85081. for(i = 0; i < order; i++) {
  85082. const FLAC__double d = fabs(lp_coeff[i]);
  85083. if(d > cmax)
  85084. cmax = d;
  85085. }
  85086. if(cmax <= 0.0) {
  85087. return 2;
  85088. }
  85089. else {
  85090. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85091. const int min_shiftlimit = -max_shiftlimit - 1;
  85092. int log2cmax;
  85093. (void)frexp(cmax, &log2cmax);
  85094. log2cmax--;
  85095. *shift = (int)precision - log2cmax - 1;
  85096. if(*shift > max_shiftlimit)
  85097. *shift = max_shiftlimit;
  85098. else if(*shift < min_shiftlimit)
  85099. return 1;
  85100. }
  85101. if(*shift >= 0) {
  85102. FLAC__double error = 0.0;
  85103. FLAC__int32 q;
  85104. for(i = 0; i < order; i++) {
  85105. error += lp_coeff[i] * (1 << *shift);
  85106. #if 1 /* unfortunately lround() is C99 */
  85107. if(error >= 0.0)
  85108. q = (FLAC__int32)(error + 0.5);
  85109. else
  85110. q = (FLAC__int32)(error - 0.5);
  85111. #else
  85112. q = lround(error);
  85113. #endif
  85114. #ifdef FLAC__OVERFLOW_DETECT
  85115. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85116. 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]);
  85117. else if(q < qmin)
  85118. 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]);
  85119. #endif
  85120. if(q > qmax)
  85121. q = qmax;
  85122. else if(q < qmin)
  85123. q = qmin;
  85124. error -= q;
  85125. qlp_coeff[i] = q;
  85126. }
  85127. }
  85128. else {
  85129. const int nshift = -(*shift);
  85130. FLAC__double error = 0.0;
  85131. FLAC__int32 q;
  85132. #ifdef DEBUG
  85133. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85134. #endif
  85135. for(i = 0; i < order; i++) {
  85136. error += lp_coeff[i] / (1 << nshift);
  85137. #if 1 /* unfortunately lround() is C99 */
  85138. if(error >= 0.0)
  85139. q = (FLAC__int32)(error + 0.5);
  85140. else
  85141. q = (FLAC__int32)(error - 0.5);
  85142. #else
  85143. q = lround(error);
  85144. #endif
  85145. #ifdef FLAC__OVERFLOW_DETECT
  85146. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85147. 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]);
  85148. else if(q < qmin)
  85149. 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]);
  85150. #endif
  85151. if(q > qmax)
  85152. q = qmax;
  85153. else if(q < qmin)
  85154. q = qmin;
  85155. error -= q;
  85156. qlp_coeff[i] = q;
  85157. }
  85158. *shift = 0;
  85159. }
  85160. return 0;
  85161. }
  85162. 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[])
  85163. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85164. {
  85165. FLAC__int64 sumo;
  85166. unsigned i, j;
  85167. FLAC__int32 sum;
  85168. const FLAC__int32 *history;
  85169. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85170. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85171. for(i=0;i<order;i++)
  85172. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85173. fprintf(stderr,"\n");
  85174. #endif
  85175. FLAC__ASSERT(order > 0);
  85176. for(i = 0; i < data_len; i++) {
  85177. sumo = 0;
  85178. sum = 0;
  85179. history = data;
  85180. for(j = 0; j < order; j++) {
  85181. sum += qlp_coeff[j] * (*(--history));
  85182. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85183. #if defined _MSC_VER
  85184. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85185. 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);
  85186. #else
  85187. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85188. 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);
  85189. #endif
  85190. }
  85191. *(residual++) = *(data++) - (sum >> lp_quantization);
  85192. }
  85193. }
  85194. #else /* fully unrolled version for normal use */
  85195. {
  85196. int i;
  85197. FLAC__int32 sum;
  85198. FLAC__ASSERT(order > 0);
  85199. FLAC__ASSERT(order <= 32);
  85200. if(order <= 12) {
  85201. if(order > 8) {
  85202. if(order > 10) {
  85203. if(order == 12) {
  85204. for(i = 0; i < (int)data_len; i++) {
  85205. sum = 0;
  85206. sum += qlp_coeff[11] * data[i-12];
  85207. sum += qlp_coeff[10] * data[i-11];
  85208. sum += qlp_coeff[9] * data[i-10];
  85209. sum += qlp_coeff[8] * data[i-9];
  85210. sum += qlp_coeff[7] * data[i-8];
  85211. sum += qlp_coeff[6] * data[i-7];
  85212. sum += qlp_coeff[5] * data[i-6];
  85213. sum += qlp_coeff[4] * data[i-5];
  85214. sum += qlp_coeff[3] * data[i-4];
  85215. sum += qlp_coeff[2] * data[i-3];
  85216. sum += qlp_coeff[1] * data[i-2];
  85217. sum += qlp_coeff[0] * data[i-1];
  85218. residual[i] = data[i] - (sum >> lp_quantization);
  85219. }
  85220. }
  85221. else { /* order == 11 */
  85222. for(i = 0; i < (int)data_len; i++) {
  85223. sum = 0;
  85224. sum += qlp_coeff[10] * data[i-11];
  85225. sum += qlp_coeff[9] * data[i-10];
  85226. sum += qlp_coeff[8] * data[i-9];
  85227. sum += qlp_coeff[7] * data[i-8];
  85228. sum += qlp_coeff[6] * data[i-7];
  85229. sum += qlp_coeff[5] * data[i-6];
  85230. sum += qlp_coeff[4] * data[i-5];
  85231. sum += qlp_coeff[3] * data[i-4];
  85232. sum += qlp_coeff[2] * data[i-3];
  85233. sum += qlp_coeff[1] * data[i-2];
  85234. sum += qlp_coeff[0] * data[i-1];
  85235. residual[i] = data[i] - (sum >> lp_quantization);
  85236. }
  85237. }
  85238. }
  85239. else {
  85240. if(order == 10) {
  85241. for(i = 0; i < (int)data_len; i++) {
  85242. sum = 0;
  85243. sum += qlp_coeff[9] * data[i-10];
  85244. sum += qlp_coeff[8] * data[i-9];
  85245. sum += qlp_coeff[7] * data[i-8];
  85246. sum += qlp_coeff[6] * data[i-7];
  85247. sum += qlp_coeff[5] * data[i-6];
  85248. sum += qlp_coeff[4] * data[i-5];
  85249. sum += qlp_coeff[3] * data[i-4];
  85250. sum += qlp_coeff[2] * data[i-3];
  85251. sum += qlp_coeff[1] * data[i-2];
  85252. sum += qlp_coeff[0] * data[i-1];
  85253. residual[i] = data[i] - (sum >> lp_quantization);
  85254. }
  85255. }
  85256. else { /* order == 9 */
  85257. for(i = 0; i < (int)data_len; i++) {
  85258. sum = 0;
  85259. sum += qlp_coeff[8] * data[i-9];
  85260. sum += qlp_coeff[7] * data[i-8];
  85261. sum += qlp_coeff[6] * data[i-7];
  85262. sum += qlp_coeff[5] * data[i-6];
  85263. sum += qlp_coeff[4] * data[i-5];
  85264. sum += qlp_coeff[3] * data[i-4];
  85265. sum += qlp_coeff[2] * data[i-3];
  85266. sum += qlp_coeff[1] * data[i-2];
  85267. sum += qlp_coeff[0] * data[i-1];
  85268. residual[i] = data[i] - (sum >> lp_quantization);
  85269. }
  85270. }
  85271. }
  85272. }
  85273. else if(order > 4) {
  85274. if(order > 6) {
  85275. if(order == 8) {
  85276. for(i = 0; i < (int)data_len; i++) {
  85277. sum = 0;
  85278. sum += qlp_coeff[7] * data[i-8];
  85279. sum += qlp_coeff[6] * data[i-7];
  85280. sum += qlp_coeff[5] * data[i-6];
  85281. sum += qlp_coeff[4] * data[i-5];
  85282. sum += qlp_coeff[3] * data[i-4];
  85283. sum += qlp_coeff[2] * data[i-3];
  85284. sum += qlp_coeff[1] * data[i-2];
  85285. sum += qlp_coeff[0] * data[i-1];
  85286. residual[i] = data[i] - (sum >> lp_quantization);
  85287. }
  85288. }
  85289. else { /* order == 7 */
  85290. for(i = 0; i < (int)data_len; i++) {
  85291. sum = 0;
  85292. sum += qlp_coeff[6] * data[i-7];
  85293. sum += qlp_coeff[5] * data[i-6];
  85294. sum += qlp_coeff[4] * data[i-5];
  85295. sum += qlp_coeff[3] * data[i-4];
  85296. sum += qlp_coeff[2] * data[i-3];
  85297. sum += qlp_coeff[1] * data[i-2];
  85298. sum += qlp_coeff[0] * data[i-1];
  85299. residual[i] = data[i] - (sum >> lp_quantization);
  85300. }
  85301. }
  85302. }
  85303. else {
  85304. if(order == 6) {
  85305. for(i = 0; i < (int)data_len; i++) {
  85306. sum = 0;
  85307. sum += qlp_coeff[5] * data[i-6];
  85308. sum += qlp_coeff[4] * data[i-5];
  85309. sum += qlp_coeff[3] * data[i-4];
  85310. sum += qlp_coeff[2] * data[i-3];
  85311. sum += qlp_coeff[1] * data[i-2];
  85312. sum += qlp_coeff[0] * data[i-1];
  85313. residual[i] = data[i] - (sum >> lp_quantization);
  85314. }
  85315. }
  85316. else { /* order == 5 */
  85317. for(i = 0; i < (int)data_len; i++) {
  85318. sum = 0;
  85319. sum += qlp_coeff[4] * data[i-5];
  85320. sum += qlp_coeff[3] * data[i-4];
  85321. sum += qlp_coeff[2] * data[i-3];
  85322. sum += qlp_coeff[1] * data[i-2];
  85323. sum += qlp_coeff[0] * data[i-1];
  85324. residual[i] = data[i] - (sum >> lp_quantization);
  85325. }
  85326. }
  85327. }
  85328. }
  85329. else {
  85330. if(order > 2) {
  85331. if(order == 4) {
  85332. for(i = 0; i < (int)data_len; i++) {
  85333. sum = 0;
  85334. sum += qlp_coeff[3] * data[i-4];
  85335. sum += qlp_coeff[2] * data[i-3];
  85336. sum += qlp_coeff[1] * data[i-2];
  85337. sum += qlp_coeff[0] * data[i-1];
  85338. residual[i] = data[i] - (sum >> lp_quantization);
  85339. }
  85340. }
  85341. else { /* order == 3 */
  85342. for(i = 0; i < (int)data_len; i++) {
  85343. sum = 0;
  85344. sum += qlp_coeff[2] * data[i-3];
  85345. sum += qlp_coeff[1] * data[i-2];
  85346. sum += qlp_coeff[0] * data[i-1];
  85347. residual[i] = data[i] - (sum >> lp_quantization);
  85348. }
  85349. }
  85350. }
  85351. else {
  85352. if(order == 2) {
  85353. for(i = 0; i < (int)data_len; i++) {
  85354. sum = 0;
  85355. sum += qlp_coeff[1] * data[i-2];
  85356. sum += qlp_coeff[0] * data[i-1];
  85357. residual[i] = data[i] - (sum >> lp_quantization);
  85358. }
  85359. }
  85360. else { /* order == 1 */
  85361. for(i = 0; i < (int)data_len; i++)
  85362. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85363. }
  85364. }
  85365. }
  85366. }
  85367. else { /* order > 12 */
  85368. for(i = 0; i < (int)data_len; i++) {
  85369. sum = 0;
  85370. switch(order) {
  85371. case 32: sum += qlp_coeff[31] * data[i-32];
  85372. case 31: sum += qlp_coeff[30] * data[i-31];
  85373. case 30: sum += qlp_coeff[29] * data[i-30];
  85374. case 29: sum += qlp_coeff[28] * data[i-29];
  85375. case 28: sum += qlp_coeff[27] * data[i-28];
  85376. case 27: sum += qlp_coeff[26] * data[i-27];
  85377. case 26: sum += qlp_coeff[25] * data[i-26];
  85378. case 25: sum += qlp_coeff[24] * data[i-25];
  85379. case 24: sum += qlp_coeff[23] * data[i-24];
  85380. case 23: sum += qlp_coeff[22] * data[i-23];
  85381. case 22: sum += qlp_coeff[21] * data[i-22];
  85382. case 21: sum += qlp_coeff[20] * data[i-21];
  85383. case 20: sum += qlp_coeff[19] * data[i-20];
  85384. case 19: sum += qlp_coeff[18] * data[i-19];
  85385. case 18: sum += qlp_coeff[17] * data[i-18];
  85386. case 17: sum += qlp_coeff[16] * data[i-17];
  85387. case 16: sum += qlp_coeff[15] * data[i-16];
  85388. case 15: sum += qlp_coeff[14] * data[i-15];
  85389. case 14: sum += qlp_coeff[13] * data[i-14];
  85390. case 13: sum += qlp_coeff[12] * data[i-13];
  85391. sum += qlp_coeff[11] * data[i-12];
  85392. sum += qlp_coeff[10] * data[i-11];
  85393. sum += qlp_coeff[ 9] * data[i-10];
  85394. sum += qlp_coeff[ 8] * data[i- 9];
  85395. sum += qlp_coeff[ 7] * data[i- 8];
  85396. sum += qlp_coeff[ 6] * data[i- 7];
  85397. sum += qlp_coeff[ 5] * data[i- 6];
  85398. sum += qlp_coeff[ 4] * data[i- 5];
  85399. sum += qlp_coeff[ 3] * data[i- 4];
  85400. sum += qlp_coeff[ 2] * data[i- 3];
  85401. sum += qlp_coeff[ 1] * data[i- 2];
  85402. sum += qlp_coeff[ 0] * data[i- 1];
  85403. }
  85404. residual[i] = data[i] - (sum >> lp_quantization);
  85405. }
  85406. }
  85407. }
  85408. #endif
  85409. 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[])
  85410. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85411. {
  85412. unsigned i, j;
  85413. FLAC__int64 sum;
  85414. const FLAC__int32 *history;
  85415. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85416. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85417. for(i=0;i<order;i++)
  85418. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85419. fprintf(stderr,"\n");
  85420. #endif
  85421. FLAC__ASSERT(order > 0);
  85422. for(i = 0; i < data_len; i++) {
  85423. sum = 0;
  85424. history = data;
  85425. for(j = 0; j < order; j++)
  85426. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85427. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85428. #if defined _MSC_VER
  85429. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85430. #else
  85431. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85432. #endif
  85433. break;
  85434. }
  85435. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85436. #if defined _MSC_VER
  85437. 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));
  85438. #else
  85439. 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)));
  85440. #endif
  85441. break;
  85442. }
  85443. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85444. }
  85445. }
  85446. #else /* fully unrolled version for normal use */
  85447. {
  85448. int i;
  85449. FLAC__int64 sum;
  85450. FLAC__ASSERT(order > 0);
  85451. FLAC__ASSERT(order <= 32);
  85452. if(order <= 12) {
  85453. if(order > 8) {
  85454. if(order > 10) {
  85455. if(order == 12) {
  85456. for(i = 0; i < (int)data_len; i++) {
  85457. sum = 0;
  85458. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85459. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85460. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85461. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85462. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85463. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85464. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85465. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85466. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85467. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85468. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85469. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85470. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85471. }
  85472. }
  85473. else { /* order == 11 */
  85474. for(i = 0; i < (int)data_len; i++) {
  85475. sum = 0;
  85476. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85477. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85478. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85479. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85480. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85481. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85482. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85483. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85484. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85485. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85486. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85487. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85488. }
  85489. }
  85490. }
  85491. else {
  85492. if(order == 10) {
  85493. for(i = 0; i < (int)data_len; i++) {
  85494. sum = 0;
  85495. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85496. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85497. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85498. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85499. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85500. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85501. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85502. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85503. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85504. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85505. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85506. }
  85507. }
  85508. else { /* order == 9 */
  85509. for(i = 0; i < (int)data_len; i++) {
  85510. sum = 0;
  85511. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85512. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85513. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85514. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85515. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85516. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85517. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85518. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85519. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85520. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85521. }
  85522. }
  85523. }
  85524. }
  85525. else if(order > 4) {
  85526. if(order > 6) {
  85527. if(order == 8) {
  85528. for(i = 0; i < (int)data_len; i++) {
  85529. sum = 0;
  85530. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85531. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85532. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85533. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85534. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85535. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85536. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85537. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85538. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85539. }
  85540. }
  85541. else { /* order == 7 */
  85542. for(i = 0; i < (int)data_len; i++) {
  85543. sum = 0;
  85544. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85545. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85546. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85547. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85548. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85549. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85550. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85551. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85552. }
  85553. }
  85554. }
  85555. else {
  85556. if(order == 6) {
  85557. for(i = 0; i < (int)data_len; i++) {
  85558. sum = 0;
  85559. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85560. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85561. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85562. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85563. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85564. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85565. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85566. }
  85567. }
  85568. else { /* order == 5 */
  85569. for(i = 0; i < (int)data_len; i++) {
  85570. sum = 0;
  85571. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85572. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85573. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85574. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85575. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85576. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85577. }
  85578. }
  85579. }
  85580. }
  85581. else {
  85582. if(order > 2) {
  85583. if(order == 4) {
  85584. for(i = 0; i < (int)data_len; i++) {
  85585. sum = 0;
  85586. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85587. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85588. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85589. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85590. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85591. }
  85592. }
  85593. else { /* order == 3 */
  85594. for(i = 0; i < (int)data_len; i++) {
  85595. sum = 0;
  85596. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85597. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85598. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85599. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85600. }
  85601. }
  85602. }
  85603. else {
  85604. if(order == 2) {
  85605. for(i = 0; i < (int)data_len; i++) {
  85606. sum = 0;
  85607. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85608. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85609. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85610. }
  85611. }
  85612. else { /* order == 1 */
  85613. for(i = 0; i < (int)data_len; i++)
  85614. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85615. }
  85616. }
  85617. }
  85618. }
  85619. else { /* order > 12 */
  85620. for(i = 0; i < (int)data_len; i++) {
  85621. sum = 0;
  85622. switch(order) {
  85623. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85624. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85625. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85626. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85627. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85628. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85629. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85630. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85631. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85632. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85633. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85634. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85635. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85636. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85637. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85638. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85639. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85640. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85641. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85642. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85643. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85644. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85645. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85646. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85647. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85648. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85649. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85650. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85651. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85652. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85653. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85654. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85655. }
  85656. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85657. }
  85658. }
  85659. }
  85660. #endif
  85661. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85662. 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[])
  85663. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85664. {
  85665. FLAC__int64 sumo;
  85666. unsigned i, j;
  85667. FLAC__int32 sum;
  85668. const FLAC__int32 *r = residual, *history;
  85669. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85670. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85671. for(i=0;i<order;i++)
  85672. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85673. fprintf(stderr,"\n");
  85674. #endif
  85675. FLAC__ASSERT(order > 0);
  85676. for(i = 0; i < data_len; i++) {
  85677. sumo = 0;
  85678. sum = 0;
  85679. history = data;
  85680. for(j = 0; j < order; j++) {
  85681. sum += qlp_coeff[j] * (*(--history));
  85682. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85683. #if defined _MSC_VER
  85684. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85685. 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);
  85686. #else
  85687. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85688. 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);
  85689. #endif
  85690. }
  85691. *(data++) = *(r++) + (sum >> lp_quantization);
  85692. }
  85693. }
  85694. #else /* fully unrolled version for normal use */
  85695. {
  85696. int i;
  85697. FLAC__int32 sum;
  85698. FLAC__ASSERT(order > 0);
  85699. FLAC__ASSERT(order <= 32);
  85700. if(order <= 12) {
  85701. if(order > 8) {
  85702. if(order > 10) {
  85703. if(order == 12) {
  85704. for(i = 0; i < (int)data_len; i++) {
  85705. sum = 0;
  85706. sum += qlp_coeff[11] * data[i-12];
  85707. sum += qlp_coeff[10] * data[i-11];
  85708. sum += qlp_coeff[9] * data[i-10];
  85709. sum += qlp_coeff[8] * data[i-9];
  85710. sum += qlp_coeff[7] * data[i-8];
  85711. sum += qlp_coeff[6] * data[i-7];
  85712. sum += qlp_coeff[5] * data[i-6];
  85713. sum += qlp_coeff[4] * data[i-5];
  85714. sum += qlp_coeff[3] * data[i-4];
  85715. sum += qlp_coeff[2] * data[i-3];
  85716. sum += qlp_coeff[1] * data[i-2];
  85717. sum += qlp_coeff[0] * data[i-1];
  85718. data[i] = residual[i] + (sum >> lp_quantization);
  85719. }
  85720. }
  85721. else { /* order == 11 */
  85722. for(i = 0; i < (int)data_len; i++) {
  85723. sum = 0;
  85724. sum += qlp_coeff[10] * data[i-11];
  85725. sum += qlp_coeff[9] * data[i-10];
  85726. sum += qlp_coeff[8] * data[i-9];
  85727. sum += qlp_coeff[7] * data[i-8];
  85728. sum += qlp_coeff[6] * data[i-7];
  85729. sum += qlp_coeff[5] * data[i-6];
  85730. sum += qlp_coeff[4] * data[i-5];
  85731. sum += qlp_coeff[3] * data[i-4];
  85732. sum += qlp_coeff[2] * data[i-3];
  85733. sum += qlp_coeff[1] * data[i-2];
  85734. sum += qlp_coeff[0] * data[i-1];
  85735. data[i] = residual[i] + (sum >> lp_quantization);
  85736. }
  85737. }
  85738. }
  85739. else {
  85740. if(order == 10) {
  85741. for(i = 0; i < (int)data_len; i++) {
  85742. sum = 0;
  85743. sum += qlp_coeff[9] * data[i-10];
  85744. sum += qlp_coeff[8] * data[i-9];
  85745. sum += qlp_coeff[7] * data[i-8];
  85746. sum += qlp_coeff[6] * data[i-7];
  85747. sum += qlp_coeff[5] * data[i-6];
  85748. sum += qlp_coeff[4] * data[i-5];
  85749. sum += qlp_coeff[3] * data[i-4];
  85750. sum += qlp_coeff[2] * data[i-3];
  85751. sum += qlp_coeff[1] * data[i-2];
  85752. sum += qlp_coeff[0] * data[i-1];
  85753. data[i] = residual[i] + (sum >> lp_quantization);
  85754. }
  85755. }
  85756. else { /* order == 9 */
  85757. for(i = 0; i < (int)data_len; i++) {
  85758. sum = 0;
  85759. sum += qlp_coeff[8] * data[i-9];
  85760. sum += qlp_coeff[7] * data[i-8];
  85761. sum += qlp_coeff[6] * data[i-7];
  85762. sum += qlp_coeff[5] * data[i-6];
  85763. sum += qlp_coeff[4] * data[i-5];
  85764. sum += qlp_coeff[3] * data[i-4];
  85765. sum += qlp_coeff[2] * data[i-3];
  85766. sum += qlp_coeff[1] * data[i-2];
  85767. sum += qlp_coeff[0] * data[i-1];
  85768. data[i] = residual[i] + (sum >> lp_quantization);
  85769. }
  85770. }
  85771. }
  85772. }
  85773. else if(order > 4) {
  85774. if(order > 6) {
  85775. if(order == 8) {
  85776. for(i = 0; i < (int)data_len; i++) {
  85777. sum = 0;
  85778. sum += qlp_coeff[7] * data[i-8];
  85779. sum += qlp_coeff[6] * data[i-7];
  85780. sum += qlp_coeff[5] * data[i-6];
  85781. sum += qlp_coeff[4] * data[i-5];
  85782. sum += qlp_coeff[3] * data[i-4];
  85783. sum += qlp_coeff[2] * data[i-3];
  85784. sum += qlp_coeff[1] * data[i-2];
  85785. sum += qlp_coeff[0] * data[i-1];
  85786. data[i] = residual[i] + (sum >> lp_quantization);
  85787. }
  85788. }
  85789. else { /* order == 7 */
  85790. for(i = 0; i < (int)data_len; i++) {
  85791. sum = 0;
  85792. sum += qlp_coeff[6] * data[i-7];
  85793. sum += qlp_coeff[5] * data[i-6];
  85794. sum += qlp_coeff[4] * data[i-5];
  85795. sum += qlp_coeff[3] * data[i-4];
  85796. sum += qlp_coeff[2] * data[i-3];
  85797. sum += qlp_coeff[1] * data[i-2];
  85798. sum += qlp_coeff[0] * data[i-1];
  85799. data[i] = residual[i] + (sum >> lp_quantization);
  85800. }
  85801. }
  85802. }
  85803. else {
  85804. if(order == 6) {
  85805. for(i = 0; i < (int)data_len; i++) {
  85806. sum = 0;
  85807. sum += qlp_coeff[5] * data[i-6];
  85808. sum += qlp_coeff[4] * data[i-5];
  85809. sum += qlp_coeff[3] * data[i-4];
  85810. sum += qlp_coeff[2] * data[i-3];
  85811. sum += qlp_coeff[1] * data[i-2];
  85812. sum += qlp_coeff[0] * data[i-1];
  85813. data[i] = residual[i] + (sum >> lp_quantization);
  85814. }
  85815. }
  85816. else { /* order == 5 */
  85817. for(i = 0; i < (int)data_len; i++) {
  85818. sum = 0;
  85819. sum += qlp_coeff[4] * data[i-5];
  85820. sum += qlp_coeff[3] * data[i-4];
  85821. sum += qlp_coeff[2] * data[i-3];
  85822. sum += qlp_coeff[1] * data[i-2];
  85823. sum += qlp_coeff[0] * data[i-1];
  85824. data[i] = residual[i] + (sum >> lp_quantization);
  85825. }
  85826. }
  85827. }
  85828. }
  85829. else {
  85830. if(order > 2) {
  85831. if(order == 4) {
  85832. for(i = 0; i < (int)data_len; i++) {
  85833. sum = 0;
  85834. sum += qlp_coeff[3] * data[i-4];
  85835. sum += qlp_coeff[2] * data[i-3];
  85836. sum += qlp_coeff[1] * data[i-2];
  85837. sum += qlp_coeff[0] * data[i-1];
  85838. data[i] = residual[i] + (sum >> lp_quantization);
  85839. }
  85840. }
  85841. else { /* order == 3 */
  85842. for(i = 0; i < (int)data_len; i++) {
  85843. sum = 0;
  85844. sum += qlp_coeff[2] * data[i-3];
  85845. sum += qlp_coeff[1] * data[i-2];
  85846. sum += qlp_coeff[0] * data[i-1];
  85847. data[i] = residual[i] + (sum >> lp_quantization);
  85848. }
  85849. }
  85850. }
  85851. else {
  85852. if(order == 2) {
  85853. for(i = 0; i < (int)data_len; i++) {
  85854. sum = 0;
  85855. sum += qlp_coeff[1] * data[i-2];
  85856. sum += qlp_coeff[0] * data[i-1];
  85857. data[i] = residual[i] + (sum >> lp_quantization);
  85858. }
  85859. }
  85860. else { /* order == 1 */
  85861. for(i = 0; i < (int)data_len; i++)
  85862. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85863. }
  85864. }
  85865. }
  85866. }
  85867. else { /* order > 12 */
  85868. for(i = 0; i < (int)data_len; i++) {
  85869. sum = 0;
  85870. switch(order) {
  85871. case 32: sum += qlp_coeff[31] * data[i-32];
  85872. case 31: sum += qlp_coeff[30] * data[i-31];
  85873. case 30: sum += qlp_coeff[29] * data[i-30];
  85874. case 29: sum += qlp_coeff[28] * data[i-29];
  85875. case 28: sum += qlp_coeff[27] * data[i-28];
  85876. case 27: sum += qlp_coeff[26] * data[i-27];
  85877. case 26: sum += qlp_coeff[25] * data[i-26];
  85878. case 25: sum += qlp_coeff[24] * data[i-25];
  85879. case 24: sum += qlp_coeff[23] * data[i-24];
  85880. case 23: sum += qlp_coeff[22] * data[i-23];
  85881. case 22: sum += qlp_coeff[21] * data[i-22];
  85882. case 21: sum += qlp_coeff[20] * data[i-21];
  85883. case 20: sum += qlp_coeff[19] * data[i-20];
  85884. case 19: sum += qlp_coeff[18] * data[i-19];
  85885. case 18: sum += qlp_coeff[17] * data[i-18];
  85886. case 17: sum += qlp_coeff[16] * data[i-17];
  85887. case 16: sum += qlp_coeff[15] * data[i-16];
  85888. case 15: sum += qlp_coeff[14] * data[i-15];
  85889. case 14: sum += qlp_coeff[13] * data[i-14];
  85890. case 13: sum += qlp_coeff[12] * data[i-13];
  85891. sum += qlp_coeff[11] * data[i-12];
  85892. sum += qlp_coeff[10] * data[i-11];
  85893. sum += qlp_coeff[ 9] * data[i-10];
  85894. sum += qlp_coeff[ 8] * data[i- 9];
  85895. sum += qlp_coeff[ 7] * data[i- 8];
  85896. sum += qlp_coeff[ 6] * data[i- 7];
  85897. sum += qlp_coeff[ 5] * data[i- 6];
  85898. sum += qlp_coeff[ 4] * data[i- 5];
  85899. sum += qlp_coeff[ 3] * data[i- 4];
  85900. sum += qlp_coeff[ 2] * data[i- 3];
  85901. sum += qlp_coeff[ 1] * data[i- 2];
  85902. sum += qlp_coeff[ 0] * data[i- 1];
  85903. }
  85904. data[i] = residual[i] + (sum >> lp_quantization);
  85905. }
  85906. }
  85907. }
  85908. #endif
  85909. 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[])
  85910. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85911. {
  85912. unsigned i, j;
  85913. FLAC__int64 sum;
  85914. const FLAC__int32 *r = residual, *history;
  85915. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85916. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85917. for(i=0;i<order;i++)
  85918. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85919. fprintf(stderr,"\n");
  85920. #endif
  85921. FLAC__ASSERT(order > 0);
  85922. for(i = 0; i < data_len; i++) {
  85923. sum = 0;
  85924. history = data;
  85925. for(j = 0; j < order; j++)
  85926. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85927. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85928. #ifdef _MSC_VER
  85929. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85930. #else
  85931. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85932. #endif
  85933. break;
  85934. }
  85935. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  85936. #ifdef _MSC_VER
  85937. 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));
  85938. #else
  85939. 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)));
  85940. #endif
  85941. break;
  85942. }
  85943. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  85944. }
  85945. }
  85946. #else /* fully unrolled version for normal use */
  85947. {
  85948. int i;
  85949. FLAC__int64 sum;
  85950. FLAC__ASSERT(order > 0);
  85951. FLAC__ASSERT(order <= 32);
  85952. if(order <= 12) {
  85953. if(order > 8) {
  85954. if(order > 10) {
  85955. if(order == 12) {
  85956. for(i = 0; i < (int)data_len; i++) {
  85957. sum = 0;
  85958. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85959. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85960. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85961. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85962. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85963. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85964. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85965. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85966. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85967. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85968. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85969. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85970. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85971. }
  85972. }
  85973. else { /* order == 11 */
  85974. for(i = 0; i < (int)data_len; i++) {
  85975. sum = 0;
  85976. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85977. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85978. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85979. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85980. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85981. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85982. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85983. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85984. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85985. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85986. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85987. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85988. }
  85989. }
  85990. }
  85991. else {
  85992. if(order == 10) {
  85993. for(i = 0; i < (int)data_len; i++) {
  85994. sum = 0;
  85995. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85996. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85997. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85998. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85999. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86000. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86001. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86002. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86003. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86004. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86005. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86006. }
  86007. }
  86008. else { /* order == 9 */
  86009. for(i = 0; i < (int)data_len; i++) {
  86010. sum = 0;
  86011. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86012. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86013. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86014. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86015. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86016. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86017. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86018. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86019. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86020. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86021. }
  86022. }
  86023. }
  86024. }
  86025. else if(order > 4) {
  86026. if(order > 6) {
  86027. if(order == 8) {
  86028. for(i = 0; i < (int)data_len; i++) {
  86029. sum = 0;
  86030. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86031. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86032. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86033. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86034. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86035. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86036. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86037. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86038. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86039. }
  86040. }
  86041. else { /* order == 7 */
  86042. for(i = 0; i < (int)data_len; i++) {
  86043. sum = 0;
  86044. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86045. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86046. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86047. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86048. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86049. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86050. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86051. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86052. }
  86053. }
  86054. }
  86055. else {
  86056. if(order == 6) {
  86057. for(i = 0; i < (int)data_len; i++) {
  86058. sum = 0;
  86059. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86060. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86061. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86062. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86063. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86064. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86065. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86066. }
  86067. }
  86068. else { /* order == 5 */
  86069. for(i = 0; i < (int)data_len; i++) {
  86070. sum = 0;
  86071. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86072. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86073. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86074. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86075. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86076. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86077. }
  86078. }
  86079. }
  86080. }
  86081. else {
  86082. if(order > 2) {
  86083. if(order == 4) {
  86084. for(i = 0; i < (int)data_len; i++) {
  86085. sum = 0;
  86086. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86087. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86088. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86089. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86090. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86091. }
  86092. }
  86093. else { /* order == 3 */
  86094. for(i = 0; i < (int)data_len; i++) {
  86095. sum = 0;
  86096. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86097. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86098. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86099. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86100. }
  86101. }
  86102. }
  86103. else {
  86104. if(order == 2) {
  86105. for(i = 0; i < (int)data_len; i++) {
  86106. sum = 0;
  86107. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86108. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86109. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86110. }
  86111. }
  86112. else { /* order == 1 */
  86113. for(i = 0; i < (int)data_len; i++)
  86114. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86115. }
  86116. }
  86117. }
  86118. }
  86119. else { /* order > 12 */
  86120. for(i = 0; i < (int)data_len; i++) {
  86121. sum = 0;
  86122. switch(order) {
  86123. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86124. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86125. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86126. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86127. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86128. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86129. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86130. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86131. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86132. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86133. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86134. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86135. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86136. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86137. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86138. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86139. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86140. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86141. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86142. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86143. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86144. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86145. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86146. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86147. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86148. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86149. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86150. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86151. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86152. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86153. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86154. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86155. }
  86156. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86157. }
  86158. }
  86159. }
  86160. #endif
  86161. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86162. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86163. {
  86164. FLAC__double error_scale;
  86165. FLAC__ASSERT(total_samples > 0);
  86166. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86167. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86168. }
  86169. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86170. {
  86171. if(lpc_error > 0.0) {
  86172. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86173. if(bps >= 0.0)
  86174. return bps;
  86175. else
  86176. return 0.0;
  86177. }
  86178. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86179. return 1e32;
  86180. }
  86181. else {
  86182. return 0.0;
  86183. }
  86184. }
  86185. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86186. {
  86187. 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 */
  86188. FLAC__double bits, best_bits, error_scale;
  86189. FLAC__ASSERT(max_order > 0);
  86190. FLAC__ASSERT(total_samples > 0);
  86191. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86192. best_index = 0;
  86193. best_bits = (unsigned)(-1);
  86194. for(index = 0, order = 1; index < max_order; index++, order++) {
  86195. 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);
  86196. if(bits < best_bits) {
  86197. best_index = index;
  86198. best_bits = bits;
  86199. }
  86200. }
  86201. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86202. }
  86203. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86204. #endif
  86205. /*** End of inlined file: lpc_flac.c ***/
  86206. /*** Start of inlined file: md5.c ***/
  86207. /*** Start of inlined file: juce_FlacHeader.h ***/
  86208. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86209. // tasks..
  86210. #define VERSION "1.2.1"
  86211. #define FLAC__NO_DLL 1
  86212. #if JUCE_MSVC
  86213. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86214. #endif
  86215. #if JUCE_MAC
  86216. #define FLAC__SYS_DARWIN 1
  86217. #endif
  86218. /*** End of inlined file: juce_FlacHeader.h ***/
  86219. #if JUCE_USE_FLAC
  86220. #if HAVE_CONFIG_H
  86221. # include <config.h>
  86222. #endif
  86223. #include <stdlib.h> /* for malloc() */
  86224. #include <string.h> /* for memcpy() */
  86225. /*** Start of inlined file: md5.h ***/
  86226. #ifndef FLAC__PRIVATE__MD5_H
  86227. #define FLAC__PRIVATE__MD5_H
  86228. typedef struct {
  86229. FLAC__uint32 in[16];
  86230. FLAC__uint32 buf[4];
  86231. FLAC__uint32 bytes[2];
  86232. FLAC__byte *internal_buf;
  86233. size_t capacity;
  86234. } FLAC__MD5Context;
  86235. void FLAC__MD5Init(FLAC__MD5Context *context);
  86236. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86237. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86238. #endif
  86239. /*** End of inlined file: md5.h ***/
  86240. #ifndef FLaC__INLINE
  86241. #define FLaC__INLINE
  86242. #endif
  86243. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86244. #define F2(x, y, z) F1(z, x, y)
  86245. #define F3(x, y, z) (x ^ y ^ z)
  86246. #define F4(x, y, z) (y ^ (x | ~z))
  86247. #define MD5STEP(f,w,x,y,z,in,s) \
  86248. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86249. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86250. {
  86251. register FLAC__uint32 a, b, c, d;
  86252. a = buf[0];
  86253. b = buf[1];
  86254. c = buf[2];
  86255. d = buf[3];
  86256. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86257. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86258. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86259. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86260. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86261. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86262. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86263. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86264. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86265. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86266. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86267. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86268. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86269. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86270. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86271. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86272. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86273. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86274. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86275. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86276. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86277. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86278. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86279. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86280. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86281. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86282. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86283. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86284. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86285. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86286. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86287. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86288. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86289. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86290. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86291. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86292. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86293. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86294. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86295. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86296. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86297. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86298. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86299. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86300. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86301. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86302. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86303. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86304. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86305. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86306. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86307. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86308. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86309. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86310. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86311. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86312. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86313. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86314. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86315. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86316. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86317. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86318. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86319. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86320. buf[0] += a;
  86321. buf[1] += b;
  86322. buf[2] += c;
  86323. buf[3] += d;
  86324. }
  86325. #if WORDS_BIGENDIAN
  86326. //@@@@@@ OPT: use bswap/intrinsics
  86327. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86328. {
  86329. register FLAC__uint32 x;
  86330. do {
  86331. x = *buf;
  86332. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86333. *buf++ = (x >> 16) | (x << 16);
  86334. } while (--words);
  86335. }
  86336. static void byteSwapX16(FLAC__uint32 *buf)
  86337. {
  86338. register FLAC__uint32 x;
  86339. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86340. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86341. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86342. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86343. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86344. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86345. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86346. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86347. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86348. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86349. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86350. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86351. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86352. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86353. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86354. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86355. }
  86356. #else
  86357. #define byteSwap(buf, words)
  86358. #define byteSwapX16(buf)
  86359. #endif
  86360. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86361. {
  86362. FLAC__uint32 t;
  86363. t = ctx->bytes[0];
  86364. if ((ctx->bytes[0] = t + len) < t)
  86365. ctx->bytes[1]++; /* Carry from low to high */
  86366. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86367. if (t > len) {
  86368. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86369. return;
  86370. }
  86371. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86372. byteSwapX16(ctx->in);
  86373. FLAC__MD5Transform(ctx->buf, ctx->in);
  86374. buf += t;
  86375. len -= t;
  86376. while (len >= 64) {
  86377. memcpy(ctx->in, buf, 64);
  86378. byteSwapX16(ctx->in);
  86379. FLAC__MD5Transform(ctx->buf, ctx->in);
  86380. buf += 64;
  86381. len -= 64;
  86382. }
  86383. memcpy(ctx->in, buf, len);
  86384. }
  86385. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86386. {
  86387. ctx->buf[0] = 0x67452301;
  86388. ctx->buf[1] = 0xefcdab89;
  86389. ctx->buf[2] = 0x98badcfe;
  86390. ctx->buf[3] = 0x10325476;
  86391. ctx->bytes[0] = 0;
  86392. ctx->bytes[1] = 0;
  86393. ctx->internal_buf = 0;
  86394. ctx->capacity = 0;
  86395. }
  86396. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86397. {
  86398. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86399. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86400. *p++ = 0x80;
  86401. count = 56 - 1 - count;
  86402. if (count < 0) { /* Padding forces an extra block */
  86403. memset(p, 0, count + 8);
  86404. byteSwapX16(ctx->in);
  86405. FLAC__MD5Transform(ctx->buf, ctx->in);
  86406. p = (FLAC__byte *)ctx->in;
  86407. count = 56;
  86408. }
  86409. memset(p, 0, count);
  86410. byteSwap(ctx->in, 14);
  86411. ctx->in[14] = ctx->bytes[0] << 3;
  86412. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86413. FLAC__MD5Transform(ctx->buf, ctx->in);
  86414. byteSwap(ctx->buf, 4);
  86415. memcpy(digest, ctx->buf, 16);
  86416. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86417. if(0 != ctx->internal_buf) {
  86418. free(ctx->internal_buf);
  86419. ctx->internal_buf = 0;
  86420. ctx->capacity = 0;
  86421. }
  86422. }
  86423. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86424. {
  86425. unsigned channel, sample;
  86426. register FLAC__int32 a_word;
  86427. register FLAC__byte *buf_ = buf;
  86428. #if WORDS_BIGENDIAN
  86429. #else
  86430. if(channels == 2 && bytes_per_sample == 2) {
  86431. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86432. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86433. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86434. *buf1_ = (FLAC__int16)signal[1][sample];
  86435. }
  86436. else if(channels == 1 && bytes_per_sample == 2) {
  86437. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86438. for(sample = 0; sample < samples; sample++)
  86439. *buf1_++ = (FLAC__int16)signal[0][sample];
  86440. }
  86441. else
  86442. #endif
  86443. if(bytes_per_sample == 2) {
  86444. if(channels == 2) {
  86445. for(sample = 0; sample < samples; sample++) {
  86446. a_word = signal[0][sample];
  86447. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86448. *buf_++ = (FLAC__byte)a_word;
  86449. a_word = signal[1][sample];
  86450. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86451. *buf_++ = (FLAC__byte)a_word;
  86452. }
  86453. }
  86454. else if(channels == 1) {
  86455. for(sample = 0; sample < samples; sample++) {
  86456. a_word = signal[0][sample];
  86457. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86458. *buf_++ = (FLAC__byte)a_word;
  86459. }
  86460. }
  86461. else {
  86462. for(sample = 0; sample < samples; sample++) {
  86463. for(channel = 0; channel < channels; channel++) {
  86464. a_word = signal[channel][sample];
  86465. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86466. *buf_++ = (FLAC__byte)a_word;
  86467. }
  86468. }
  86469. }
  86470. }
  86471. else if(bytes_per_sample == 3) {
  86472. if(channels == 2) {
  86473. for(sample = 0; sample < samples; sample++) {
  86474. a_word = signal[0][sample];
  86475. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86476. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86477. *buf_++ = (FLAC__byte)a_word;
  86478. a_word = signal[1][sample];
  86479. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86480. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86481. *buf_++ = (FLAC__byte)a_word;
  86482. }
  86483. }
  86484. else if(channels == 1) {
  86485. for(sample = 0; sample < samples; sample++) {
  86486. a_word = signal[0][sample];
  86487. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86488. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86489. *buf_++ = (FLAC__byte)a_word;
  86490. }
  86491. }
  86492. else {
  86493. for(sample = 0; sample < samples; sample++) {
  86494. for(channel = 0; channel < channels; channel++) {
  86495. a_word = signal[channel][sample];
  86496. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86497. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86498. *buf_++ = (FLAC__byte)a_word;
  86499. }
  86500. }
  86501. }
  86502. }
  86503. else if(bytes_per_sample == 1) {
  86504. if(channels == 2) {
  86505. for(sample = 0; sample < samples; sample++) {
  86506. a_word = signal[0][sample];
  86507. *buf_++ = (FLAC__byte)a_word;
  86508. a_word = signal[1][sample];
  86509. *buf_++ = (FLAC__byte)a_word;
  86510. }
  86511. }
  86512. else if(channels == 1) {
  86513. for(sample = 0; sample < samples; sample++) {
  86514. a_word = signal[0][sample];
  86515. *buf_++ = (FLAC__byte)a_word;
  86516. }
  86517. }
  86518. else {
  86519. for(sample = 0; sample < samples; sample++) {
  86520. for(channel = 0; channel < channels; channel++) {
  86521. a_word = signal[channel][sample];
  86522. *buf_++ = (FLAC__byte)a_word;
  86523. }
  86524. }
  86525. }
  86526. }
  86527. else { /* bytes_per_sample == 4, maybe optimize more later */
  86528. for(sample = 0; sample < samples; sample++) {
  86529. for(channel = 0; channel < channels; channel++) {
  86530. a_word = signal[channel][sample];
  86531. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86532. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86533. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86534. *buf_++ = (FLAC__byte)a_word;
  86535. }
  86536. }
  86537. }
  86538. }
  86539. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86540. {
  86541. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86542. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86543. return false;
  86544. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86545. return false;
  86546. if(ctx->capacity < bytes_needed) {
  86547. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86548. if(0 == tmp) {
  86549. free(ctx->internal_buf);
  86550. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86551. return false;
  86552. }
  86553. ctx->internal_buf = tmp;
  86554. ctx->capacity = bytes_needed;
  86555. }
  86556. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86557. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86558. return true;
  86559. }
  86560. #endif
  86561. /*** End of inlined file: md5.c ***/
  86562. /*** Start of inlined file: memory.c ***/
  86563. /*** Start of inlined file: juce_FlacHeader.h ***/
  86564. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86565. // tasks..
  86566. #define VERSION "1.2.1"
  86567. #define FLAC__NO_DLL 1
  86568. #if JUCE_MSVC
  86569. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86570. #endif
  86571. #if JUCE_MAC
  86572. #define FLAC__SYS_DARWIN 1
  86573. #endif
  86574. /*** End of inlined file: juce_FlacHeader.h ***/
  86575. #if JUCE_USE_FLAC
  86576. #if HAVE_CONFIG_H
  86577. # include <config.h>
  86578. #endif
  86579. /*** Start of inlined file: memory.h ***/
  86580. #ifndef FLAC__PRIVATE__MEMORY_H
  86581. #define FLAC__PRIVATE__MEMORY_H
  86582. #ifdef HAVE_CONFIG_H
  86583. #include <config.h>
  86584. #endif
  86585. #include <stdlib.h> /* for size_t */
  86586. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86587. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86588. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86589. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86590. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86591. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86592. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86593. #endif
  86594. #endif
  86595. /*** End of inlined file: memory.h ***/
  86596. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86597. {
  86598. void *x;
  86599. FLAC__ASSERT(0 != aligned_address);
  86600. #ifdef FLAC__ALIGN_MALLOC_DATA
  86601. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86602. #ifdef SIZEOF_VOIDP
  86603. #if SIZEOF_VOIDP == 4
  86604. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86605. #elif SIZEOF_VOIDP == 8
  86606. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86607. #else
  86608. # error Unsupported sizeof(void*)
  86609. #endif
  86610. #else
  86611. if(sizeof(void*) == sizeof(unsigned))
  86612. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86613. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86614. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86615. else
  86616. return 0;
  86617. #endif
  86618. #else
  86619. x = safe_malloc_(bytes);
  86620. *aligned_address = x;
  86621. #endif
  86622. return x;
  86623. }
  86624. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86625. {
  86626. FLAC__int32 *pu; /* unaligned pointer */
  86627. union { /* union needed to comply with C99 pointer aliasing rules */
  86628. FLAC__int32 *pa; /* aligned pointer */
  86629. void *pv; /* aligned pointer alias */
  86630. } u;
  86631. FLAC__ASSERT(elements > 0);
  86632. FLAC__ASSERT(0 != unaligned_pointer);
  86633. FLAC__ASSERT(0 != aligned_pointer);
  86634. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86635. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86636. if(0 == pu) {
  86637. return false;
  86638. }
  86639. else {
  86640. if(*unaligned_pointer != 0)
  86641. free(*unaligned_pointer);
  86642. *unaligned_pointer = pu;
  86643. *aligned_pointer = u.pa;
  86644. return true;
  86645. }
  86646. }
  86647. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86648. {
  86649. FLAC__uint32 *pu; /* unaligned pointer */
  86650. union { /* union needed to comply with C99 pointer aliasing rules */
  86651. FLAC__uint32 *pa; /* aligned pointer */
  86652. void *pv; /* aligned pointer alias */
  86653. } u;
  86654. FLAC__ASSERT(elements > 0);
  86655. FLAC__ASSERT(0 != unaligned_pointer);
  86656. FLAC__ASSERT(0 != aligned_pointer);
  86657. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86658. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86659. if(0 == pu) {
  86660. return false;
  86661. }
  86662. else {
  86663. if(*unaligned_pointer != 0)
  86664. free(*unaligned_pointer);
  86665. *unaligned_pointer = pu;
  86666. *aligned_pointer = u.pa;
  86667. return true;
  86668. }
  86669. }
  86670. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86671. {
  86672. FLAC__uint64 *pu; /* unaligned pointer */
  86673. union { /* union needed to comply with C99 pointer aliasing rules */
  86674. FLAC__uint64 *pa; /* aligned pointer */
  86675. void *pv; /* aligned pointer alias */
  86676. } u;
  86677. FLAC__ASSERT(elements > 0);
  86678. FLAC__ASSERT(0 != unaligned_pointer);
  86679. FLAC__ASSERT(0 != aligned_pointer);
  86680. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86681. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86682. if(0 == pu) {
  86683. return false;
  86684. }
  86685. else {
  86686. if(*unaligned_pointer != 0)
  86687. free(*unaligned_pointer);
  86688. *unaligned_pointer = pu;
  86689. *aligned_pointer = u.pa;
  86690. return true;
  86691. }
  86692. }
  86693. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86694. {
  86695. unsigned *pu; /* unaligned pointer */
  86696. union { /* union needed to comply with C99 pointer aliasing rules */
  86697. unsigned *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 = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * 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. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86717. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86718. {
  86719. FLAC__real *pu; /* unaligned pointer */
  86720. union { /* union needed to comply with C99 pointer aliasing rules */
  86721. FLAC__real *pa; /* aligned pointer */
  86722. void *pv; /* aligned pointer alias */
  86723. } u;
  86724. FLAC__ASSERT(elements > 0);
  86725. FLAC__ASSERT(0 != unaligned_pointer);
  86726. FLAC__ASSERT(0 != aligned_pointer);
  86727. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86728. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86729. if(0 == pu) {
  86730. return false;
  86731. }
  86732. else {
  86733. if(*unaligned_pointer != 0)
  86734. free(*unaligned_pointer);
  86735. *unaligned_pointer = pu;
  86736. *aligned_pointer = u.pa;
  86737. return true;
  86738. }
  86739. }
  86740. #endif
  86741. #endif
  86742. /*** End of inlined file: memory.c ***/
  86743. /*** Start of inlined file: stream_decoder.c ***/
  86744. /*** Start of inlined file: juce_FlacHeader.h ***/
  86745. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86746. // tasks..
  86747. #define VERSION "1.2.1"
  86748. #define FLAC__NO_DLL 1
  86749. #if JUCE_MSVC
  86750. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86751. #endif
  86752. #if JUCE_MAC
  86753. #define FLAC__SYS_DARWIN 1
  86754. #endif
  86755. /*** End of inlined file: juce_FlacHeader.h ***/
  86756. #if JUCE_USE_FLAC
  86757. #if HAVE_CONFIG_H
  86758. # include <config.h>
  86759. #endif
  86760. #if defined _MSC_VER || defined __MINGW32__
  86761. #include <io.h> /* for _setmode() */
  86762. #include <fcntl.h> /* for _O_BINARY */
  86763. #endif
  86764. #if defined __CYGWIN__ || defined __EMX__
  86765. #include <io.h> /* for setmode(), O_BINARY */
  86766. #include <fcntl.h> /* for _O_BINARY */
  86767. #endif
  86768. #include <stdio.h>
  86769. #include <stdlib.h> /* for malloc() */
  86770. #include <string.h> /* for memset/memcpy() */
  86771. #include <sys/stat.h> /* for stat() */
  86772. #include <sys/types.h> /* for off_t */
  86773. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86774. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86775. #define fseeko fseek
  86776. #define ftello ftell
  86777. #endif
  86778. #endif
  86779. /*** Start of inlined file: stream_decoder.h ***/
  86780. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86781. #define FLAC__PROTECTED__STREAM_DECODER_H
  86782. #if FLAC__HAS_OGG
  86783. #include "include/private/ogg_decoder_aspect.h"
  86784. #endif
  86785. typedef struct FLAC__StreamDecoderProtected {
  86786. FLAC__StreamDecoderState state;
  86787. unsigned channels;
  86788. FLAC__ChannelAssignment channel_assignment;
  86789. unsigned bits_per_sample;
  86790. unsigned sample_rate; /* in Hz */
  86791. unsigned blocksize; /* in samples (per channel) */
  86792. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86793. #if FLAC__HAS_OGG
  86794. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86795. #endif
  86796. } FLAC__StreamDecoderProtected;
  86797. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86798. #endif
  86799. /*** End of inlined file: stream_decoder.h ***/
  86800. #ifdef max
  86801. #undef max
  86802. #endif
  86803. #define max(a,b) ((a)>(b)?(a):(b))
  86804. #ifdef _MSC_VER
  86805. #define FLAC__U64L(x) x
  86806. #else
  86807. #define FLAC__U64L(x) x##LLU
  86808. #endif
  86809. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86810. #if FLAC__HAS_OGG
  86811. 1
  86812. #else
  86813. 0
  86814. #endif
  86815. ;
  86816. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86817. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86818. static FILE *get_binary_stdin_(void);
  86819. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86820. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86821. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86822. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86823. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86824. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86825. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86826. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86827. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86828. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86829. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86830. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86831. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86832. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86833. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86834. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86835. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86836. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86837. 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);
  86838. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86839. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86840. #if FLAC__HAS_OGG
  86841. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86842. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86843. #endif
  86844. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86845. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86846. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86847. #if FLAC__HAS_OGG
  86848. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86849. #endif
  86850. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86851. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86852. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86853. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86854. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86855. typedef struct FLAC__StreamDecoderPrivate {
  86856. #if FLAC__HAS_OGG
  86857. FLAC__bool is_ogg;
  86858. #endif
  86859. FLAC__StreamDecoderReadCallback read_callback;
  86860. FLAC__StreamDecoderSeekCallback seek_callback;
  86861. FLAC__StreamDecoderTellCallback tell_callback;
  86862. FLAC__StreamDecoderLengthCallback length_callback;
  86863. FLAC__StreamDecoderEofCallback eof_callback;
  86864. FLAC__StreamDecoderWriteCallback write_callback;
  86865. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86866. FLAC__StreamDecoderErrorCallback error_callback;
  86867. 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[]);
  86868. 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[]);
  86869. 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[]);
  86870. 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[]);
  86871. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86872. void *client_data;
  86873. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86874. FLAC__BitReader *input;
  86875. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86876. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86877. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86878. unsigned output_capacity, output_channels;
  86879. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86880. FLAC__uint64 samples_decoded;
  86881. FLAC__bool has_stream_info, has_seek_table;
  86882. FLAC__StreamMetadata stream_info;
  86883. FLAC__StreamMetadata seek_table;
  86884. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86885. FLAC__byte *metadata_filter_ids;
  86886. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86887. FLAC__Frame frame;
  86888. FLAC__bool cached; /* true if there is a byte in lookahead */
  86889. FLAC__CPUInfo cpuinfo;
  86890. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86891. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86892. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86893. 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 */
  86894. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86895. FLAC__bool is_seeking;
  86896. FLAC__MD5Context md5context;
  86897. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86898. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86899. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86900. FLAC__uint64 target_sample;
  86901. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86902. #if FLAC__HAS_OGG
  86903. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86904. #endif
  86905. } FLAC__StreamDecoderPrivate;
  86906. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86907. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86908. "FLAC__STREAM_DECODER_READ_METADATA",
  86909. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86910. "FLAC__STREAM_DECODER_READ_FRAME",
  86911. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86912. "FLAC__STREAM_DECODER_OGG_ERROR",
  86913. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86914. "FLAC__STREAM_DECODER_ABORTED",
  86915. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86916. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86917. };
  86918. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86919. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86920. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86921. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86922. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86923. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86924. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86925. };
  86926. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86927. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86928. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86929. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86930. };
  86931. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  86932. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  86933. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  86934. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  86935. };
  86936. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  86937. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  86938. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  86939. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  86940. };
  86941. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  86942. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  86943. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  86944. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  86945. };
  86946. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  86947. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  86948. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  86949. };
  86950. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  86951. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  86952. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  86953. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  86954. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  86955. };
  86956. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  86957. {
  86958. FLAC__StreamDecoder *decoder;
  86959. unsigned i;
  86960. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  86961. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  86962. if(decoder == 0) {
  86963. return 0;
  86964. }
  86965. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  86966. if(decoder->protected_ == 0) {
  86967. free(decoder);
  86968. return 0;
  86969. }
  86970. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  86971. if(decoder->private_ == 0) {
  86972. free(decoder->protected_);
  86973. free(decoder);
  86974. return 0;
  86975. }
  86976. decoder->private_->input = FLAC__bitreader_new();
  86977. if(decoder->private_->input == 0) {
  86978. free(decoder->private_);
  86979. free(decoder->protected_);
  86980. free(decoder);
  86981. return 0;
  86982. }
  86983. decoder->private_->metadata_filter_ids_capacity = 16;
  86984. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  86985. FLAC__bitreader_delete(decoder->private_->input);
  86986. free(decoder->private_);
  86987. free(decoder->protected_);
  86988. free(decoder);
  86989. return 0;
  86990. }
  86991. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  86992. decoder->private_->output[i] = 0;
  86993. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  86994. }
  86995. decoder->private_->output_capacity = 0;
  86996. decoder->private_->output_channels = 0;
  86997. decoder->private_->has_seek_table = false;
  86998. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86999. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87000. decoder->private_->file = 0;
  87001. set_defaults_dec(decoder);
  87002. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87003. return decoder;
  87004. }
  87005. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87006. {
  87007. unsigned i;
  87008. FLAC__ASSERT(0 != decoder);
  87009. FLAC__ASSERT(0 != decoder->protected_);
  87010. FLAC__ASSERT(0 != decoder->private_);
  87011. FLAC__ASSERT(0 != decoder->private_->input);
  87012. (void)FLAC__stream_decoder_finish(decoder);
  87013. if(0 != decoder->private_->metadata_filter_ids)
  87014. free(decoder->private_->metadata_filter_ids);
  87015. FLAC__bitreader_delete(decoder->private_->input);
  87016. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87017. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87018. free(decoder->private_);
  87019. free(decoder->protected_);
  87020. free(decoder);
  87021. }
  87022. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87023. FLAC__StreamDecoder *decoder,
  87024. FLAC__StreamDecoderReadCallback read_callback,
  87025. FLAC__StreamDecoderSeekCallback seek_callback,
  87026. FLAC__StreamDecoderTellCallback tell_callback,
  87027. FLAC__StreamDecoderLengthCallback length_callback,
  87028. FLAC__StreamDecoderEofCallback eof_callback,
  87029. FLAC__StreamDecoderWriteCallback write_callback,
  87030. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87031. FLAC__StreamDecoderErrorCallback error_callback,
  87032. void *client_data,
  87033. FLAC__bool is_ogg
  87034. )
  87035. {
  87036. FLAC__ASSERT(0 != decoder);
  87037. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87038. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87039. #if !FLAC__HAS_OGG
  87040. if(is_ogg)
  87041. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87042. #endif
  87043. if(
  87044. 0 == read_callback ||
  87045. 0 == write_callback ||
  87046. 0 == error_callback ||
  87047. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87048. )
  87049. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87050. #if FLAC__HAS_OGG
  87051. decoder->private_->is_ogg = is_ogg;
  87052. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87053. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87054. #endif
  87055. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87056. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87057. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87058. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87059. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87060. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87061. #ifndef FLAC__NO_ASM
  87062. if(decoder->private_->cpuinfo.use_asm) {
  87063. #ifdef FLAC__CPU_IA32
  87064. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87065. #ifdef FLAC__HAS_NASM
  87066. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87067. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87068. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87069. #endif
  87070. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87071. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87072. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87073. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87074. }
  87075. else {
  87076. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87077. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87078. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87079. }
  87080. #endif
  87081. #elif defined FLAC__CPU_PPC
  87082. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87083. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87084. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87085. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87086. }
  87087. #endif
  87088. }
  87089. #endif
  87090. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87091. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87092. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87093. }
  87094. decoder->private_->read_callback = read_callback;
  87095. decoder->private_->seek_callback = seek_callback;
  87096. decoder->private_->tell_callback = tell_callback;
  87097. decoder->private_->length_callback = length_callback;
  87098. decoder->private_->eof_callback = eof_callback;
  87099. decoder->private_->write_callback = write_callback;
  87100. decoder->private_->metadata_callback = metadata_callback;
  87101. decoder->private_->error_callback = error_callback;
  87102. decoder->private_->client_data = client_data;
  87103. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87104. decoder->private_->samples_decoded = 0;
  87105. decoder->private_->has_stream_info = false;
  87106. decoder->private_->cached = false;
  87107. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87108. decoder->private_->is_seeking = false;
  87109. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87110. if(!FLAC__stream_decoder_reset(decoder)) {
  87111. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87112. }
  87113. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87114. }
  87115. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87116. FLAC__StreamDecoder *decoder,
  87117. FLAC__StreamDecoderReadCallback read_callback,
  87118. FLAC__StreamDecoderSeekCallback seek_callback,
  87119. FLAC__StreamDecoderTellCallback tell_callback,
  87120. FLAC__StreamDecoderLengthCallback length_callback,
  87121. FLAC__StreamDecoderEofCallback eof_callback,
  87122. FLAC__StreamDecoderWriteCallback write_callback,
  87123. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87124. FLAC__StreamDecoderErrorCallback error_callback,
  87125. void *client_data
  87126. )
  87127. {
  87128. return init_stream_internal_dec(
  87129. decoder,
  87130. read_callback,
  87131. seek_callback,
  87132. tell_callback,
  87133. length_callback,
  87134. eof_callback,
  87135. write_callback,
  87136. metadata_callback,
  87137. error_callback,
  87138. client_data,
  87139. false
  87140. );
  87141. }
  87142. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87143. FLAC__StreamDecoder *decoder,
  87144. FLAC__StreamDecoderReadCallback read_callback,
  87145. FLAC__StreamDecoderSeekCallback seek_callback,
  87146. FLAC__StreamDecoderTellCallback tell_callback,
  87147. FLAC__StreamDecoderLengthCallback length_callback,
  87148. FLAC__StreamDecoderEofCallback eof_callback,
  87149. FLAC__StreamDecoderWriteCallback write_callback,
  87150. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87151. FLAC__StreamDecoderErrorCallback error_callback,
  87152. void *client_data
  87153. )
  87154. {
  87155. return init_stream_internal_dec(
  87156. decoder,
  87157. read_callback,
  87158. seek_callback,
  87159. tell_callback,
  87160. length_callback,
  87161. eof_callback,
  87162. write_callback,
  87163. metadata_callback,
  87164. error_callback,
  87165. client_data,
  87166. true
  87167. );
  87168. }
  87169. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87170. FLAC__StreamDecoder *decoder,
  87171. FILE *file,
  87172. FLAC__StreamDecoderWriteCallback write_callback,
  87173. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87174. FLAC__StreamDecoderErrorCallback error_callback,
  87175. void *client_data,
  87176. FLAC__bool is_ogg
  87177. )
  87178. {
  87179. FLAC__ASSERT(0 != decoder);
  87180. FLAC__ASSERT(0 != file);
  87181. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87182. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87183. if(0 == write_callback || 0 == error_callback)
  87184. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87185. if(file == stdin)
  87186. file = get_binary_stdin_(); /* just to be safe */
  87187. decoder->private_->file = file;
  87188. return init_stream_internal_dec(
  87189. decoder,
  87190. file_read_callback_dec,
  87191. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87192. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87193. decoder->private_->file == stdin? 0: file_length_callback_,
  87194. file_eof_callback_,
  87195. write_callback,
  87196. metadata_callback,
  87197. error_callback,
  87198. client_data,
  87199. is_ogg
  87200. );
  87201. }
  87202. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87203. FLAC__StreamDecoder *decoder,
  87204. FILE *file,
  87205. FLAC__StreamDecoderWriteCallback write_callback,
  87206. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87207. FLAC__StreamDecoderErrorCallback error_callback,
  87208. void *client_data
  87209. )
  87210. {
  87211. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87212. }
  87213. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87214. FLAC__StreamDecoder *decoder,
  87215. FILE *file,
  87216. FLAC__StreamDecoderWriteCallback write_callback,
  87217. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87218. FLAC__StreamDecoderErrorCallback error_callback,
  87219. void *client_data
  87220. )
  87221. {
  87222. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87223. }
  87224. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87225. FLAC__StreamDecoder *decoder,
  87226. const char *filename,
  87227. FLAC__StreamDecoderWriteCallback write_callback,
  87228. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87229. FLAC__StreamDecoderErrorCallback error_callback,
  87230. void *client_data,
  87231. FLAC__bool is_ogg
  87232. )
  87233. {
  87234. FILE *file;
  87235. FLAC__ASSERT(0 != decoder);
  87236. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87237. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87238. if(0 == write_callback || 0 == error_callback)
  87239. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87240. file = filename? fopen(filename, "rb") : stdin;
  87241. if(0 == file)
  87242. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87243. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87244. }
  87245. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87246. FLAC__StreamDecoder *decoder,
  87247. const char *filename,
  87248. FLAC__StreamDecoderWriteCallback write_callback,
  87249. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87250. FLAC__StreamDecoderErrorCallback error_callback,
  87251. void *client_data
  87252. )
  87253. {
  87254. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87255. }
  87256. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87257. FLAC__StreamDecoder *decoder,
  87258. const char *filename,
  87259. FLAC__StreamDecoderWriteCallback write_callback,
  87260. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87261. FLAC__StreamDecoderErrorCallback error_callback,
  87262. void *client_data
  87263. )
  87264. {
  87265. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87266. }
  87267. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87268. {
  87269. FLAC__bool md5_failed = false;
  87270. unsigned i;
  87271. FLAC__ASSERT(0 != decoder);
  87272. FLAC__ASSERT(0 != decoder->private_);
  87273. FLAC__ASSERT(0 != decoder->protected_);
  87274. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87275. return true;
  87276. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87277. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87278. free(decoder->private_->seek_table.data.seek_table.points);
  87279. decoder->private_->seek_table.data.seek_table.points = 0;
  87280. decoder->private_->has_seek_table = false;
  87281. }
  87282. FLAC__bitreader_free(decoder->private_->input);
  87283. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87284. if(0 != decoder->private_->output[i]) {
  87285. free(decoder->private_->output[i]-4);
  87286. decoder->private_->output[i] = 0;
  87287. }
  87288. if(0 != decoder->private_->residual_unaligned[i]) {
  87289. free(decoder->private_->residual_unaligned[i]);
  87290. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87291. }
  87292. }
  87293. decoder->private_->output_capacity = 0;
  87294. decoder->private_->output_channels = 0;
  87295. #if FLAC__HAS_OGG
  87296. if(decoder->private_->is_ogg)
  87297. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87298. #endif
  87299. if(0 != decoder->private_->file) {
  87300. if(decoder->private_->file != stdin)
  87301. fclose(decoder->private_->file);
  87302. decoder->private_->file = 0;
  87303. }
  87304. if(decoder->private_->do_md5_checking) {
  87305. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87306. md5_failed = true;
  87307. }
  87308. decoder->private_->is_seeking = false;
  87309. set_defaults_dec(decoder);
  87310. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87311. return !md5_failed;
  87312. }
  87313. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87314. {
  87315. FLAC__ASSERT(0 != decoder);
  87316. FLAC__ASSERT(0 != decoder->private_);
  87317. FLAC__ASSERT(0 != decoder->protected_);
  87318. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87319. return false;
  87320. #if FLAC__HAS_OGG
  87321. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87322. return true;
  87323. #else
  87324. (void)value;
  87325. return false;
  87326. #endif
  87327. }
  87328. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87329. {
  87330. FLAC__ASSERT(0 != decoder);
  87331. FLAC__ASSERT(0 != decoder->protected_);
  87332. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87333. return false;
  87334. decoder->protected_->md5_checking = value;
  87335. return true;
  87336. }
  87337. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87338. {
  87339. FLAC__ASSERT(0 != decoder);
  87340. FLAC__ASSERT(0 != decoder->private_);
  87341. FLAC__ASSERT(0 != decoder->protected_);
  87342. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87343. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87344. return false;
  87345. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87346. return false;
  87347. decoder->private_->metadata_filter[type] = true;
  87348. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87349. decoder->private_->metadata_filter_ids_count = 0;
  87350. return true;
  87351. }
  87352. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87353. {
  87354. FLAC__ASSERT(0 != decoder);
  87355. FLAC__ASSERT(0 != decoder->private_);
  87356. FLAC__ASSERT(0 != decoder->protected_);
  87357. FLAC__ASSERT(0 != id);
  87358. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87359. return false;
  87360. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87361. return true;
  87362. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87363. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87364. 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))) {
  87365. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87366. return false;
  87367. }
  87368. decoder->private_->metadata_filter_ids_capacity *= 2;
  87369. }
  87370. 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));
  87371. decoder->private_->metadata_filter_ids_count++;
  87372. return true;
  87373. }
  87374. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87375. {
  87376. unsigned i;
  87377. FLAC__ASSERT(0 != decoder);
  87378. FLAC__ASSERT(0 != decoder->private_);
  87379. FLAC__ASSERT(0 != decoder->protected_);
  87380. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87381. return false;
  87382. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87383. decoder->private_->metadata_filter[i] = true;
  87384. decoder->private_->metadata_filter_ids_count = 0;
  87385. return true;
  87386. }
  87387. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87388. {
  87389. FLAC__ASSERT(0 != decoder);
  87390. FLAC__ASSERT(0 != decoder->private_);
  87391. FLAC__ASSERT(0 != decoder->protected_);
  87392. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87393. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87394. return false;
  87395. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87396. return false;
  87397. decoder->private_->metadata_filter[type] = false;
  87398. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87399. decoder->private_->metadata_filter_ids_count = 0;
  87400. return true;
  87401. }
  87402. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87403. {
  87404. FLAC__ASSERT(0 != decoder);
  87405. FLAC__ASSERT(0 != decoder->private_);
  87406. FLAC__ASSERT(0 != decoder->protected_);
  87407. FLAC__ASSERT(0 != id);
  87408. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87409. return false;
  87410. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87411. return true;
  87412. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87413. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87414. 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))) {
  87415. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87416. return false;
  87417. }
  87418. decoder->private_->metadata_filter_ids_capacity *= 2;
  87419. }
  87420. 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));
  87421. decoder->private_->metadata_filter_ids_count++;
  87422. return true;
  87423. }
  87424. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87425. {
  87426. FLAC__ASSERT(0 != decoder);
  87427. FLAC__ASSERT(0 != decoder->private_);
  87428. FLAC__ASSERT(0 != decoder->protected_);
  87429. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87430. return false;
  87431. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87432. decoder->private_->metadata_filter_ids_count = 0;
  87433. return true;
  87434. }
  87435. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87436. {
  87437. FLAC__ASSERT(0 != decoder);
  87438. FLAC__ASSERT(0 != decoder->protected_);
  87439. return decoder->protected_->state;
  87440. }
  87441. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87442. {
  87443. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87444. }
  87445. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87446. {
  87447. FLAC__ASSERT(0 != decoder);
  87448. FLAC__ASSERT(0 != decoder->protected_);
  87449. return decoder->protected_->md5_checking;
  87450. }
  87451. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87452. {
  87453. FLAC__ASSERT(0 != decoder);
  87454. FLAC__ASSERT(0 != decoder->protected_);
  87455. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87456. }
  87457. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87458. {
  87459. FLAC__ASSERT(0 != decoder);
  87460. FLAC__ASSERT(0 != decoder->protected_);
  87461. return decoder->protected_->channels;
  87462. }
  87463. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87464. {
  87465. FLAC__ASSERT(0 != decoder);
  87466. FLAC__ASSERT(0 != decoder->protected_);
  87467. return decoder->protected_->channel_assignment;
  87468. }
  87469. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87470. {
  87471. FLAC__ASSERT(0 != decoder);
  87472. FLAC__ASSERT(0 != decoder->protected_);
  87473. return decoder->protected_->bits_per_sample;
  87474. }
  87475. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87476. {
  87477. FLAC__ASSERT(0 != decoder);
  87478. FLAC__ASSERT(0 != decoder->protected_);
  87479. return decoder->protected_->sample_rate;
  87480. }
  87481. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87482. {
  87483. FLAC__ASSERT(0 != decoder);
  87484. FLAC__ASSERT(0 != decoder->protected_);
  87485. return decoder->protected_->blocksize;
  87486. }
  87487. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87488. {
  87489. FLAC__ASSERT(0 != decoder);
  87490. FLAC__ASSERT(0 != decoder->private_);
  87491. FLAC__ASSERT(0 != position);
  87492. #if FLAC__HAS_OGG
  87493. if(decoder->private_->is_ogg)
  87494. return false;
  87495. #endif
  87496. if(0 == decoder->private_->tell_callback)
  87497. return false;
  87498. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87499. return false;
  87500. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87501. return false;
  87502. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87503. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87504. return true;
  87505. }
  87506. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87507. {
  87508. FLAC__ASSERT(0 != decoder);
  87509. FLAC__ASSERT(0 != decoder->private_);
  87510. FLAC__ASSERT(0 != decoder->protected_);
  87511. decoder->private_->samples_decoded = 0;
  87512. decoder->private_->do_md5_checking = false;
  87513. #if FLAC__HAS_OGG
  87514. if(decoder->private_->is_ogg)
  87515. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87516. #endif
  87517. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87518. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87519. return false;
  87520. }
  87521. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87522. return true;
  87523. }
  87524. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87525. {
  87526. FLAC__ASSERT(0 != decoder);
  87527. FLAC__ASSERT(0 != decoder->private_);
  87528. FLAC__ASSERT(0 != decoder->protected_);
  87529. if(!FLAC__stream_decoder_flush(decoder)) {
  87530. return false;
  87531. }
  87532. #if FLAC__HAS_OGG
  87533. if(decoder->private_->is_ogg)
  87534. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87535. #endif
  87536. if(!decoder->private_->internal_reset_hack) {
  87537. if(decoder->private_->file == stdin)
  87538. return false; /* can't rewind stdin, reset fails */
  87539. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87540. return false; /* seekable and seek fails, reset fails */
  87541. }
  87542. else
  87543. decoder->private_->internal_reset_hack = false;
  87544. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87545. decoder->private_->has_stream_info = false;
  87546. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87547. free(decoder->private_->seek_table.data.seek_table.points);
  87548. decoder->private_->seek_table.data.seek_table.points = 0;
  87549. decoder->private_->has_seek_table = false;
  87550. }
  87551. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87552. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87553. FLAC__MD5Init(&decoder->private_->md5context);
  87554. decoder->private_->first_frame_offset = 0;
  87555. decoder->private_->unparseable_frame_count = 0;
  87556. return true;
  87557. }
  87558. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87559. {
  87560. FLAC__bool got_a_frame;
  87561. FLAC__ASSERT(0 != decoder);
  87562. FLAC__ASSERT(0 != decoder->protected_);
  87563. while(1) {
  87564. switch(decoder->protected_->state) {
  87565. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87566. if(!find_metadata_(decoder))
  87567. return false; /* above function sets the status for us */
  87568. break;
  87569. case FLAC__STREAM_DECODER_READ_METADATA:
  87570. if(!read_metadata_(decoder))
  87571. return false; /* above function sets the status for us */
  87572. else
  87573. return true;
  87574. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87575. if(!frame_sync_(decoder))
  87576. return true; /* above function sets the status for us */
  87577. break;
  87578. case FLAC__STREAM_DECODER_READ_FRAME:
  87579. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87580. return false; /* above function sets the status for us */
  87581. if(got_a_frame)
  87582. return true; /* above function sets the status for us */
  87583. break;
  87584. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87585. case FLAC__STREAM_DECODER_ABORTED:
  87586. return true;
  87587. default:
  87588. FLAC__ASSERT(0);
  87589. return false;
  87590. }
  87591. }
  87592. }
  87593. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87594. {
  87595. FLAC__ASSERT(0 != decoder);
  87596. FLAC__ASSERT(0 != decoder->protected_);
  87597. while(1) {
  87598. switch(decoder->protected_->state) {
  87599. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87600. if(!find_metadata_(decoder))
  87601. return false; /* above function sets the status for us */
  87602. break;
  87603. case FLAC__STREAM_DECODER_READ_METADATA:
  87604. if(!read_metadata_(decoder))
  87605. return false; /* above function sets the status for us */
  87606. break;
  87607. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87608. case FLAC__STREAM_DECODER_READ_FRAME:
  87609. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87610. case FLAC__STREAM_DECODER_ABORTED:
  87611. return true;
  87612. default:
  87613. FLAC__ASSERT(0);
  87614. return false;
  87615. }
  87616. }
  87617. }
  87618. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87619. {
  87620. FLAC__bool dummy;
  87621. FLAC__ASSERT(0 != decoder);
  87622. FLAC__ASSERT(0 != decoder->protected_);
  87623. while(1) {
  87624. switch(decoder->protected_->state) {
  87625. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87626. if(!find_metadata_(decoder))
  87627. return false; /* above function sets the status for us */
  87628. break;
  87629. case FLAC__STREAM_DECODER_READ_METADATA:
  87630. if(!read_metadata_(decoder))
  87631. return false; /* above function sets the status for us */
  87632. break;
  87633. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87634. if(!frame_sync_(decoder))
  87635. return true; /* above function sets the status for us */
  87636. break;
  87637. case FLAC__STREAM_DECODER_READ_FRAME:
  87638. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87639. return false; /* above function sets the status for us */
  87640. break;
  87641. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87642. case FLAC__STREAM_DECODER_ABORTED:
  87643. return true;
  87644. default:
  87645. FLAC__ASSERT(0);
  87646. return false;
  87647. }
  87648. }
  87649. }
  87650. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87651. {
  87652. FLAC__bool got_a_frame;
  87653. FLAC__ASSERT(0 != decoder);
  87654. FLAC__ASSERT(0 != decoder->protected_);
  87655. while(1) {
  87656. switch(decoder->protected_->state) {
  87657. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87658. case FLAC__STREAM_DECODER_READ_METADATA:
  87659. return false; /* above function sets the status for us */
  87660. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87661. if(!frame_sync_(decoder))
  87662. return true; /* above function sets the status for us */
  87663. break;
  87664. case FLAC__STREAM_DECODER_READ_FRAME:
  87665. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87666. return false; /* above function sets the status for us */
  87667. if(got_a_frame)
  87668. return true; /* above function sets the status for us */
  87669. break;
  87670. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87671. case FLAC__STREAM_DECODER_ABORTED:
  87672. return true;
  87673. default:
  87674. FLAC__ASSERT(0);
  87675. return false;
  87676. }
  87677. }
  87678. }
  87679. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87680. {
  87681. FLAC__uint64 length;
  87682. FLAC__ASSERT(0 != decoder);
  87683. if(
  87684. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87685. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87686. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87687. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87688. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87689. )
  87690. return false;
  87691. if(0 == decoder->private_->seek_callback)
  87692. return false;
  87693. FLAC__ASSERT(decoder->private_->seek_callback);
  87694. FLAC__ASSERT(decoder->private_->tell_callback);
  87695. FLAC__ASSERT(decoder->private_->length_callback);
  87696. FLAC__ASSERT(decoder->private_->eof_callback);
  87697. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87698. return false;
  87699. decoder->private_->is_seeking = true;
  87700. decoder->private_->do_md5_checking = false;
  87701. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87702. decoder->private_->is_seeking = false;
  87703. return false;
  87704. }
  87705. if(
  87706. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87707. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87708. ) {
  87709. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87710. decoder->private_->is_seeking = false;
  87711. return false;
  87712. }
  87713. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87714. decoder->private_->is_seeking = false;
  87715. return false;
  87716. }
  87717. }
  87718. {
  87719. const FLAC__bool ok =
  87720. #if FLAC__HAS_OGG
  87721. decoder->private_->is_ogg?
  87722. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87723. #endif
  87724. seek_to_absolute_sample_(decoder, length, sample)
  87725. ;
  87726. decoder->private_->is_seeking = false;
  87727. return ok;
  87728. }
  87729. }
  87730. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87731. {
  87732. FLAC__ASSERT(0 != decoder);
  87733. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87734. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87735. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87736. }
  87737. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87738. {
  87739. #if FLAC__HAS_OGG
  87740. decoder->private_->is_ogg = false;
  87741. #endif
  87742. decoder->private_->read_callback = 0;
  87743. decoder->private_->seek_callback = 0;
  87744. decoder->private_->tell_callback = 0;
  87745. decoder->private_->length_callback = 0;
  87746. decoder->private_->eof_callback = 0;
  87747. decoder->private_->write_callback = 0;
  87748. decoder->private_->metadata_callback = 0;
  87749. decoder->private_->error_callback = 0;
  87750. decoder->private_->client_data = 0;
  87751. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87752. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87753. decoder->private_->metadata_filter_ids_count = 0;
  87754. decoder->protected_->md5_checking = false;
  87755. #if FLAC__HAS_OGG
  87756. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87757. #endif
  87758. }
  87759. FILE *get_binary_stdin_(void)
  87760. {
  87761. #if defined _MSC_VER || defined __MINGW32__
  87762. _setmode(_fileno(stdin), _O_BINARY);
  87763. #elif defined __CYGWIN__
  87764. setmode(_fileno(stdin), _O_BINARY);
  87765. #elif defined __EMX__
  87766. setmode(fileno(stdin), O_BINARY);
  87767. #endif
  87768. return stdin;
  87769. }
  87770. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87771. {
  87772. unsigned i;
  87773. FLAC__int32 *tmp;
  87774. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87775. return true;
  87776. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87777. if(0 != decoder->private_->output[i]) {
  87778. free(decoder->private_->output[i]-4);
  87779. decoder->private_->output[i] = 0;
  87780. }
  87781. if(0 != decoder->private_->residual_unaligned[i]) {
  87782. free(decoder->private_->residual_unaligned[i]);
  87783. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87784. }
  87785. }
  87786. for(i = 0; i < channels; i++) {
  87787. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87788. if(tmp == 0) {
  87789. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87790. return false;
  87791. }
  87792. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87793. decoder->private_->output[i] = tmp + 4;
  87794. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87795. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87796. return false;
  87797. }
  87798. }
  87799. decoder->private_->output_capacity = size;
  87800. decoder->private_->output_channels = channels;
  87801. return true;
  87802. }
  87803. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87804. {
  87805. size_t i;
  87806. FLAC__ASSERT(0 != decoder);
  87807. FLAC__ASSERT(0 != decoder->private_);
  87808. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87809. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87810. return true;
  87811. return false;
  87812. }
  87813. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87814. {
  87815. FLAC__uint32 x;
  87816. unsigned i, id_;
  87817. FLAC__bool first = true;
  87818. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87819. for(i = id_ = 0; i < 4; ) {
  87820. if(decoder->private_->cached) {
  87821. x = (FLAC__uint32)decoder->private_->lookahead;
  87822. decoder->private_->cached = false;
  87823. }
  87824. else {
  87825. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87826. return false; /* read_callback_ sets the state for us */
  87827. }
  87828. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87829. first = true;
  87830. i++;
  87831. id_ = 0;
  87832. continue;
  87833. }
  87834. if(x == ID3V2_TAG_[id_]) {
  87835. id_++;
  87836. i = 0;
  87837. if(id_ == 3) {
  87838. if(!skip_id3v2_tag_(decoder))
  87839. return false; /* skip_id3v2_tag_ sets the state for us */
  87840. }
  87841. continue;
  87842. }
  87843. id_ = 0;
  87844. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87845. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87846. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87847. return false; /* read_callback_ sets the state for us */
  87848. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87849. decoder->private_->lookahead = (FLAC__byte)x;
  87850. decoder->private_->cached = true;
  87851. }
  87852. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87853. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87854. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87855. return true;
  87856. }
  87857. }
  87858. i = 0;
  87859. if(first) {
  87860. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87861. first = false;
  87862. }
  87863. }
  87864. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87865. return true;
  87866. }
  87867. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87868. {
  87869. FLAC__bool is_last;
  87870. FLAC__uint32 i, x, type, length;
  87871. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87872. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87873. return false; /* read_callback_ sets the state for us */
  87874. is_last = x? true : false;
  87875. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87876. return false; /* read_callback_ sets the state for us */
  87877. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87878. return false; /* read_callback_ sets the state for us */
  87879. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87880. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87881. return false;
  87882. decoder->private_->has_stream_info = true;
  87883. 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))
  87884. decoder->private_->do_md5_checking = false;
  87885. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87886. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87887. }
  87888. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87889. if(!read_metadata_seektable_(decoder, is_last, length))
  87890. return false;
  87891. decoder->private_->has_seek_table = true;
  87892. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87893. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87894. }
  87895. else {
  87896. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87897. unsigned real_length = length;
  87898. FLAC__StreamMetadata block;
  87899. block.is_last = is_last;
  87900. block.type = (FLAC__MetadataType)type;
  87901. block.length = length;
  87902. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87903. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87904. return false; /* read_callback_ sets the state for us */
  87905. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87906. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87907. return false;
  87908. }
  87909. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87910. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87911. skip_it = !skip_it;
  87912. }
  87913. if(skip_it) {
  87914. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87915. return false; /* read_callback_ sets the state for us */
  87916. }
  87917. else {
  87918. switch(type) {
  87919. case FLAC__METADATA_TYPE_PADDING:
  87920. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87921. return false; /* read_callback_ sets the state for us */
  87922. break;
  87923. case FLAC__METADATA_TYPE_APPLICATION:
  87924. if(real_length > 0) {
  87925. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87926. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87927. return false;
  87928. }
  87929. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87930. return false; /* read_callback_ sets the state for us */
  87931. }
  87932. else
  87933. block.data.application.data = 0;
  87934. break;
  87935. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87936. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  87937. return false;
  87938. break;
  87939. case FLAC__METADATA_TYPE_CUESHEET:
  87940. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  87941. return false;
  87942. break;
  87943. case FLAC__METADATA_TYPE_PICTURE:
  87944. if(!read_metadata_picture_(decoder, &block.data.picture))
  87945. return false;
  87946. break;
  87947. case FLAC__METADATA_TYPE_STREAMINFO:
  87948. case FLAC__METADATA_TYPE_SEEKTABLE:
  87949. FLAC__ASSERT(0);
  87950. break;
  87951. default:
  87952. if(real_length > 0) {
  87953. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  87954. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87955. return false;
  87956. }
  87957. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  87958. return false; /* read_callback_ sets the state for us */
  87959. }
  87960. else
  87961. block.data.unknown.data = 0;
  87962. break;
  87963. }
  87964. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  87965. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  87966. switch(type) {
  87967. case FLAC__METADATA_TYPE_PADDING:
  87968. break;
  87969. case FLAC__METADATA_TYPE_APPLICATION:
  87970. if(0 != block.data.application.data)
  87971. free(block.data.application.data);
  87972. break;
  87973. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87974. if(0 != block.data.vorbis_comment.vendor_string.entry)
  87975. free(block.data.vorbis_comment.vendor_string.entry);
  87976. if(block.data.vorbis_comment.num_comments > 0)
  87977. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  87978. if(0 != block.data.vorbis_comment.comments[i].entry)
  87979. free(block.data.vorbis_comment.comments[i].entry);
  87980. if(0 != block.data.vorbis_comment.comments)
  87981. free(block.data.vorbis_comment.comments);
  87982. break;
  87983. case FLAC__METADATA_TYPE_CUESHEET:
  87984. if(block.data.cue_sheet.num_tracks > 0)
  87985. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  87986. if(0 != block.data.cue_sheet.tracks[i].indices)
  87987. free(block.data.cue_sheet.tracks[i].indices);
  87988. if(0 != block.data.cue_sheet.tracks)
  87989. free(block.data.cue_sheet.tracks);
  87990. break;
  87991. case FLAC__METADATA_TYPE_PICTURE:
  87992. if(0 != block.data.picture.mime_type)
  87993. free(block.data.picture.mime_type);
  87994. if(0 != block.data.picture.description)
  87995. free(block.data.picture.description);
  87996. if(0 != block.data.picture.data)
  87997. free(block.data.picture.data);
  87998. break;
  87999. case FLAC__METADATA_TYPE_STREAMINFO:
  88000. case FLAC__METADATA_TYPE_SEEKTABLE:
  88001. FLAC__ASSERT(0);
  88002. default:
  88003. if(0 != block.data.unknown.data)
  88004. free(block.data.unknown.data);
  88005. break;
  88006. }
  88007. }
  88008. }
  88009. if(is_last) {
  88010. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88011. decoder->private_->first_frame_offset = 0;
  88012. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88013. }
  88014. return true;
  88015. }
  88016. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88017. {
  88018. FLAC__uint32 x;
  88019. unsigned bits, used_bits = 0;
  88020. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88021. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88022. decoder->private_->stream_info.is_last = is_last;
  88023. decoder->private_->stream_info.length = length;
  88024. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88025. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88026. return false; /* read_callback_ sets the state for us */
  88027. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88028. used_bits += bits;
  88029. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88030. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88031. return false; /* read_callback_ sets the state for us */
  88032. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88033. used_bits += bits;
  88034. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88035. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88036. return false; /* read_callback_ sets the state for us */
  88037. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88038. used_bits += bits;
  88039. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88040. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88041. return false; /* read_callback_ sets the state for us */
  88042. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88043. used_bits += bits;
  88044. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88045. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88046. return false; /* read_callback_ sets the state for us */
  88047. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88048. used_bits += bits;
  88049. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88050. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88051. return false; /* read_callback_ sets the state for us */
  88052. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88053. used_bits += bits;
  88054. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88055. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88056. return false; /* read_callback_ sets the state for us */
  88057. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88058. used_bits += bits;
  88059. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88060. 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))
  88061. return false; /* read_callback_ sets the state for us */
  88062. used_bits += bits;
  88063. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88064. return false; /* read_callback_ sets the state for us */
  88065. used_bits += 16*8;
  88066. FLAC__ASSERT(used_bits % 8 == 0);
  88067. length -= (used_bits / 8);
  88068. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88069. return false; /* read_callback_ sets the state for us */
  88070. return true;
  88071. }
  88072. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88073. {
  88074. FLAC__uint32 i, x;
  88075. FLAC__uint64 xx;
  88076. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88077. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88078. decoder->private_->seek_table.is_last = is_last;
  88079. decoder->private_->seek_table.length = length;
  88080. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88081. 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)))) {
  88082. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88083. return false;
  88084. }
  88085. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88086. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88087. return false; /* read_callback_ sets the state for us */
  88088. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88089. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88090. return false; /* read_callback_ sets the state for us */
  88091. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88092. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88093. return false; /* read_callback_ sets the state for us */
  88094. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88095. }
  88096. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88097. if(length > 0) {
  88098. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88099. return false; /* read_callback_ sets the state for us */
  88100. }
  88101. return true;
  88102. }
  88103. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88104. {
  88105. FLAC__uint32 i;
  88106. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88107. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88108. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88109. return false; /* read_callback_ sets the state for us */
  88110. if(obj->vendor_string.length > 0) {
  88111. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88112. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88113. return false;
  88114. }
  88115. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88116. return false; /* read_callback_ sets the state for us */
  88117. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88118. }
  88119. else
  88120. obj->vendor_string.entry = 0;
  88121. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88122. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88123. return false; /* read_callback_ sets the state for us */
  88124. if(obj->num_comments > 0) {
  88125. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88126. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88127. return false;
  88128. }
  88129. for(i = 0; i < obj->num_comments; i++) {
  88130. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88131. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88132. return false; /* read_callback_ sets the state for us */
  88133. if(obj->comments[i].length > 0) {
  88134. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88135. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88136. return false;
  88137. }
  88138. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88139. return false; /* read_callback_ sets the state for us */
  88140. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88141. }
  88142. else
  88143. obj->comments[i].entry = 0;
  88144. }
  88145. }
  88146. else {
  88147. obj->comments = 0;
  88148. }
  88149. return true;
  88150. }
  88151. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88152. {
  88153. FLAC__uint32 i, j, x;
  88154. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88155. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88156. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88157. 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))
  88158. return false; /* read_callback_ sets the state for us */
  88159. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88160. return false; /* read_callback_ sets the state for us */
  88161. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88162. return false; /* read_callback_ sets the state for us */
  88163. obj->is_cd = x? true : false;
  88164. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88165. return false; /* read_callback_ sets the state for us */
  88166. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88167. return false; /* read_callback_ sets the state for us */
  88168. obj->num_tracks = x;
  88169. if(obj->num_tracks > 0) {
  88170. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88171. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88172. return false;
  88173. }
  88174. for(i = 0; i < obj->num_tracks; i++) {
  88175. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88176. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88177. return false; /* read_callback_ sets the state for us */
  88178. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88179. return false; /* read_callback_ sets the state for us */
  88180. track->number = (FLAC__byte)x;
  88181. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88182. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88183. return false; /* read_callback_ sets the state for us */
  88184. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88185. return false; /* read_callback_ sets the state for us */
  88186. track->type = x;
  88187. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88188. return false; /* read_callback_ sets the state for us */
  88189. track->pre_emphasis = x;
  88190. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88191. return false; /* read_callback_ sets the state for us */
  88192. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88193. return false; /* read_callback_ sets the state for us */
  88194. track->num_indices = (FLAC__byte)x;
  88195. if(track->num_indices > 0) {
  88196. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88197. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88198. return false;
  88199. }
  88200. for(j = 0; j < track->num_indices; j++) {
  88201. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88202. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88203. return false; /* read_callback_ sets the state for us */
  88204. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88205. return false; /* read_callback_ sets the state for us */
  88206. index->number = (FLAC__byte)x;
  88207. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88208. return false; /* read_callback_ sets the state for us */
  88209. }
  88210. }
  88211. }
  88212. }
  88213. return true;
  88214. }
  88215. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88216. {
  88217. FLAC__uint32 x;
  88218. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88219. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88220. return false; /* read_callback_ sets the state for us */
  88221. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88222. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88223. return false; /* read_callback_ sets the state for us */
  88224. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88225. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88226. return false;
  88227. }
  88228. if(x > 0) {
  88229. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88230. return false; /* read_callback_ sets the state for us */
  88231. }
  88232. obj->mime_type[x] = '\0';
  88233. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88234. return false; /* read_callback_ sets the state for us */
  88235. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88236. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88237. return false;
  88238. }
  88239. if(x > 0) {
  88240. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88241. return false; /* read_callback_ sets the state for us */
  88242. }
  88243. obj->description[x] = '\0';
  88244. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88245. return false; /* read_callback_ sets the state for us */
  88246. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88247. return false; /* read_callback_ sets the state for us */
  88248. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88249. return false; /* read_callback_ sets the state for us */
  88250. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88251. return false; /* read_callback_ sets the state for us */
  88252. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88253. return false; /* read_callback_ sets the state for us */
  88254. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88255. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88256. return false;
  88257. }
  88258. if(obj->data_length > 0) {
  88259. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88260. return false; /* read_callback_ sets the state for us */
  88261. }
  88262. return true;
  88263. }
  88264. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88265. {
  88266. FLAC__uint32 x;
  88267. unsigned i, skip;
  88268. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88269. return false; /* read_callback_ sets the state for us */
  88270. skip = 0;
  88271. for(i = 0; i < 4; i++) {
  88272. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88273. return false; /* read_callback_ sets the state for us */
  88274. skip <<= 7;
  88275. skip |= (x & 0x7f);
  88276. }
  88277. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88278. return false; /* read_callback_ sets the state for us */
  88279. return true;
  88280. }
  88281. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88282. {
  88283. FLAC__uint32 x;
  88284. FLAC__bool first = true;
  88285. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88286. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88287. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88288. return true;
  88289. }
  88290. }
  88291. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88292. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88293. return false; /* read_callback_ sets the state for us */
  88294. }
  88295. while(1) {
  88296. if(decoder->private_->cached) {
  88297. x = (FLAC__uint32)decoder->private_->lookahead;
  88298. decoder->private_->cached = false;
  88299. }
  88300. else {
  88301. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88302. return false; /* read_callback_ sets the state for us */
  88303. }
  88304. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88305. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88306. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88307. return false; /* read_callback_ sets the state for us */
  88308. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88309. decoder->private_->lookahead = (FLAC__byte)x;
  88310. decoder->private_->cached = true;
  88311. }
  88312. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88313. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88314. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88315. return true;
  88316. }
  88317. }
  88318. if(first) {
  88319. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88320. first = false;
  88321. }
  88322. }
  88323. return true;
  88324. }
  88325. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88326. {
  88327. unsigned channel;
  88328. unsigned i;
  88329. FLAC__int32 mid, side;
  88330. unsigned frame_crc; /* the one we calculate from the input stream */
  88331. FLAC__uint32 x;
  88332. *got_a_frame = false;
  88333. frame_crc = 0;
  88334. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88335. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88336. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88337. if(!read_frame_header_(decoder))
  88338. return false;
  88339. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88340. return true;
  88341. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88342. return false;
  88343. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88344. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88345. switch(decoder->private_->frame.header.channel_assignment) {
  88346. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88347. break;
  88348. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88349. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88350. if(channel == 1)
  88351. bps++;
  88352. break;
  88353. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88354. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88355. if(channel == 0)
  88356. bps++;
  88357. break;
  88358. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88359. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88360. if(channel == 1)
  88361. bps++;
  88362. break;
  88363. default:
  88364. FLAC__ASSERT(0);
  88365. }
  88366. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88367. return false;
  88368. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88369. return true;
  88370. }
  88371. if(!read_zero_padding_(decoder))
  88372. return false;
  88373. 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) */
  88374. return true;
  88375. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88376. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88377. return false; /* read_callback_ sets the state for us */
  88378. if(frame_crc == x) {
  88379. if(do_full_decode) {
  88380. switch(decoder->private_->frame.header.channel_assignment) {
  88381. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88382. break;
  88383. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88384. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88385. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88386. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88387. break;
  88388. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88389. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88390. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88391. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88392. break;
  88393. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88394. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88395. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88396. #if 1
  88397. mid = decoder->private_->output[0][i];
  88398. side = decoder->private_->output[1][i];
  88399. mid <<= 1;
  88400. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88401. decoder->private_->output[0][i] = (mid + side) >> 1;
  88402. decoder->private_->output[1][i] = (mid - side) >> 1;
  88403. #else
  88404. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88405. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88406. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88407. #endif
  88408. }
  88409. break;
  88410. default:
  88411. FLAC__ASSERT(0);
  88412. break;
  88413. }
  88414. }
  88415. }
  88416. else {
  88417. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88418. if(do_full_decode) {
  88419. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88420. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88421. }
  88422. }
  88423. }
  88424. *got_a_frame = true;
  88425. if(decoder->private_->next_fixed_block_size)
  88426. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88427. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88428. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88429. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88430. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88431. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88432. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88433. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88434. if(do_full_decode) {
  88435. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88436. return false;
  88437. }
  88438. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88439. return true;
  88440. }
  88441. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88442. {
  88443. FLAC__uint32 x;
  88444. FLAC__uint64 xx;
  88445. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88446. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88447. unsigned raw_header_len;
  88448. FLAC__bool is_unparseable = false;
  88449. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88450. raw_header[0] = decoder->private_->header_warmup[0];
  88451. raw_header[1] = decoder->private_->header_warmup[1];
  88452. raw_header_len = 2;
  88453. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88454. is_unparseable = true;
  88455. for(i = 0; i < 2; i++) {
  88456. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88457. return false; /* read_callback_ sets the state for us */
  88458. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88459. decoder->private_->lookahead = (FLAC__byte)x;
  88460. decoder->private_->cached = true;
  88461. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88462. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88463. return true;
  88464. }
  88465. raw_header[raw_header_len++] = (FLAC__byte)x;
  88466. }
  88467. switch(x = raw_header[2] >> 4) {
  88468. case 0:
  88469. is_unparseable = true;
  88470. break;
  88471. case 1:
  88472. decoder->private_->frame.header.blocksize = 192;
  88473. break;
  88474. case 2:
  88475. case 3:
  88476. case 4:
  88477. case 5:
  88478. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88479. break;
  88480. case 6:
  88481. case 7:
  88482. blocksize_hint = x;
  88483. break;
  88484. case 8:
  88485. case 9:
  88486. case 10:
  88487. case 11:
  88488. case 12:
  88489. case 13:
  88490. case 14:
  88491. case 15:
  88492. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88493. break;
  88494. default:
  88495. FLAC__ASSERT(0);
  88496. break;
  88497. }
  88498. switch(x = raw_header[2] & 0x0f) {
  88499. case 0:
  88500. if(decoder->private_->has_stream_info)
  88501. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88502. else
  88503. is_unparseable = true;
  88504. break;
  88505. case 1:
  88506. decoder->private_->frame.header.sample_rate = 88200;
  88507. break;
  88508. case 2:
  88509. decoder->private_->frame.header.sample_rate = 176400;
  88510. break;
  88511. case 3:
  88512. decoder->private_->frame.header.sample_rate = 192000;
  88513. break;
  88514. case 4:
  88515. decoder->private_->frame.header.sample_rate = 8000;
  88516. break;
  88517. case 5:
  88518. decoder->private_->frame.header.sample_rate = 16000;
  88519. break;
  88520. case 6:
  88521. decoder->private_->frame.header.sample_rate = 22050;
  88522. break;
  88523. case 7:
  88524. decoder->private_->frame.header.sample_rate = 24000;
  88525. break;
  88526. case 8:
  88527. decoder->private_->frame.header.sample_rate = 32000;
  88528. break;
  88529. case 9:
  88530. decoder->private_->frame.header.sample_rate = 44100;
  88531. break;
  88532. case 10:
  88533. decoder->private_->frame.header.sample_rate = 48000;
  88534. break;
  88535. case 11:
  88536. decoder->private_->frame.header.sample_rate = 96000;
  88537. break;
  88538. case 12:
  88539. case 13:
  88540. case 14:
  88541. sample_rate_hint = x;
  88542. break;
  88543. case 15:
  88544. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88545. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88546. return true;
  88547. default:
  88548. FLAC__ASSERT(0);
  88549. }
  88550. x = (unsigned)(raw_header[3] >> 4);
  88551. if(x & 8) {
  88552. decoder->private_->frame.header.channels = 2;
  88553. switch(x & 7) {
  88554. case 0:
  88555. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88556. break;
  88557. case 1:
  88558. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88559. break;
  88560. case 2:
  88561. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88562. break;
  88563. default:
  88564. is_unparseable = true;
  88565. break;
  88566. }
  88567. }
  88568. else {
  88569. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88570. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88571. }
  88572. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88573. case 0:
  88574. if(decoder->private_->has_stream_info)
  88575. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88576. else
  88577. is_unparseable = true;
  88578. break;
  88579. case 1:
  88580. decoder->private_->frame.header.bits_per_sample = 8;
  88581. break;
  88582. case 2:
  88583. decoder->private_->frame.header.bits_per_sample = 12;
  88584. break;
  88585. case 4:
  88586. decoder->private_->frame.header.bits_per_sample = 16;
  88587. break;
  88588. case 5:
  88589. decoder->private_->frame.header.bits_per_sample = 20;
  88590. break;
  88591. case 6:
  88592. decoder->private_->frame.header.bits_per_sample = 24;
  88593. break;
  88594. case 3:
  88595. case 7:
  88596. is_unparseable = true;
  88597. break;
  88598. default:
  88599. FLAC__ASSERT(0);
  88600. break;
  88601. }
  88602. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88603. is_unparseable = true;
  88604. if(
  88605. raw_header[1] & 0x01 ||
  88606. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88607. ) { /* variable blocksize */
  88608. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88609. return false; /* read_callback_ sets the state for us */
  88610. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88611. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88612. decoder->private_->cached = true;
  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. }
  88617. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88618. decoder->private_->frame.header.number.sample_number = xx;
  88619. }
  88620. else { /* fixed blocksize */
  88621. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88622. return false; /* read_callback_ sets the state for us */
  88623. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88624. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88625. decoder->private_->cached = true;
  88626. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88627. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88628. return true;
  88629. }
  88630. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88631. decoder->private_->frame.header.number.frame_number = x;
  88632. }
  88633. if(blocksize_hint) {
  88634. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88635. return false; /* read_callback_ sets the state for us */
  88636. raw_header[raw_header_len++] = (FLAC__byte)x;
  88637. if(blocksize_hint == 7) {
  88638. FLAC__uint32 _x;
  88639. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88640. return false; /* read_callback_ sets the state for us */
  88641. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88642. x = (x << 8) | _x;
  88643. }
  88644. decoder->private_->frame.header.blocksize = x+1;
  88645. }
  88646. if(sample_rate_hint) {
  88647. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88648. return false; /* read_callback_ sets the state for us */
  88649. raw_header[raw_header_len++] = (FLAC__byte)x;
  88650. if(sample_rate_hint != 12) {
  88651. FLAC__uint32 _x;
  88652. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88653. return false; /* read_callback_ sets the state for us */
  88654. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88655. x = (x << 8) | _x;
  88656. }
  88657. if(sample_rate_hint == 12)
  88658. decoder->private_->frame.header.sample_rate = x*1000;
  88659. else if(sample_rate_hint == 13)
  88660. decoder->private_->frame.header.sample_rate = x;
  88661. else
  88662. decoder->private_->frame.header.sample_rate = x*10;
  88663. }
  88664. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88665. return false; /* read_callback_ sets the state for us */
  88666. crc8 = (FLAC__byte)x;
  88667. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88668. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88669. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88670. return true;
  88671. }
  88672. decoder->private_->next_fixed_block_size = 0;
  88673. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88674. x = decoder->private_->frame.header.number.frame_number;
  88675. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88676. if(decoder->private_->fixed_block_size)
  88677. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88678. else if(decoder->private_->has_stream_info) {
  88679. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88680. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88681. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88682. }
  88683. else
  88684. is_unparseable = true;
  88685. }
  88686. else if(x == 0) {
  88687. decoder->private_->frame.header.number.sample_number = 0;
  88688. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88689. }
  88690. else {
  88691. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88692. }
  88693. }
  88694. if(is_unparseable) {
  88695. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88696. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88697. return true;
  88698. }
  88699. return true;
  88700. }
  88701. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88702. {
  88703. FLAC__uint32 x;
  88704. FLAC__bool wasted_bits;
  88705. unsigned i;
  88706. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88707. return false; /* read_callback_ sets the state for us */
  88708. wasted_bits = (x & 1);
  88709. x &= 0xfe;
  88710. if(wasted_bits) {
  88711. unsigned u;
  88712. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88713. return false; /* read_callback_ sets the state for us */
  88714. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88715. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88716. }
  88717. else
  88718. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88719. if(x & 0x80) {
  88720. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88721. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88722. return true;
  88723. }
  88724. else if(x == 0) {
  88725. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88726. return false;
  88727. }
  88728. else if(x == 2) {
  88729. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88730. return false;
  88731. }
  88732. else if(x < 16) {
  88733. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88734. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88735. return true;
  88736. }
  88737. else if(x <= 24) {
  88738. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88739. return false;
  88740. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88741. return true;
  88742. }
  88743. else if(x < 64) {
  88744. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88745. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88746. return true;
  88747. }
  88748. else {
  88749. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88750. return false;
  88751. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88752. return true;
  88753. }
  88754. if(wasted_bits && do_full_decode) {
  88755. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88756. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88757. decoder->private_->output[channel][i] <<= x;
  88758. }
  88759. return true;
  88760. }
  88761. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88762. {
  88763. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88764. FLAC__int32 x;
  88765. unsigned i;
  88766. FLAC__int32 *output = decoder->private_->output[channel];
  88767. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88768. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88769. return false; /* read_callback_ sets the state for us */
  88770. subframe->value = x;
  88771. if(do_full_decode) {
  88772. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88773. output[i] = x;
  88774. }
  88775. return true;
  88776. }
  88777. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88778. {
  88779. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88780. FLAC__int32 i32;
  88781. FLAC__uint32 u32;
  88782. unsigned u;
  88783. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88784. subframe->residual = decoder->private_->residual[channel];
  88785. subframe->order = order;
  88786. for(u = 0; u < order; u++) {
  88787. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88788. return false; /* read_callback_ sets the state for us */
  88789. subframe->warmup[u] = i32;
  88790. }
  88791. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88792. return false; /* read_callback_ sets the state for us */
  88793. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88794. switch(subframe->entropy_coding_method.type) {
  88795. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88796. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88797. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88798. return false; /* read_callback_ sets the state for us */
  88799. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88800. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88801. break;
  88802. default:
  88803. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88804. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88805. return true;
  88806. }
  88807. switch(subframe->entropy_coding_method.type) {
  88808. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88809. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88810. 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))
  88811. return false;
  88812. break;
  88813. default:
  88814. FLAC__ASSERT(0);
  88815. }
  88816. if(do_full_decode) {
  88817. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88818. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88819. }
  88820. return true;
  88821. }
  88822. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88823. {
  88824. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88825. FLAC__int32 i32;
  88826. FLAC__uint32 u32;
  88827. unsigned u;
  88828. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88829. subframe->residual = decoder->private_->residual[channel];
  88830. subframe->order = order;
  88831. for(u = 0; u < order; u++) {
  88832. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88833. return false; /* read_callback_ sets the state for us */
  88834. subframe->warmup[u] = i32;
  88835. }
  88836. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88837. return false; /* read_callback_ sets the state for us */
  88838. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88839. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88840. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88841. return true;
  88842. }
  88843. subframe->qlp_coeff_precision = u32+1;
  88844. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88845. return false; /* read_callback_ sets the state for us */
  88846. subframe->quantization_level = i32;
  88847. for(u = 0; u < order; u++) {
  88848. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88849. return false; /* read_callback_ sets the state for us */
  88850. subframe->qlp_coeff[u] = i32;
  88851. }
  88852. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88853. return false; /* read_callback_ sets the state for us */
  88854. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88855. switch(subframe->entropy_coding_method.type) {
  88856. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88857. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88858. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88859. return false; /* read_callback_ sets the state for us */
  88860. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88861. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88862. break;
  88863. default:
  88864. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88865. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88866. return true;
  88867. }
  88868. switch(subframe->entropy_coding_method.type) {
  88869. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88870. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88871. 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))
  88872. return false;
  88873. break;
  88874. default:
  88875. FLAC__ASSERT(0);
  88876. }
  88877. if(do_full_decode) {
  88878. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88879. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88880. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88881. if(order <= 8)
  88882. 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);
  88883. else
  88884. 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);
  88885. }
  88886. else
  88887. 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);
  88888. else
  88889. 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);
  88890. }
  88891. return true;
  88892. }
  88893. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88894. {
  88895. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88896. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88897. unsigned i;
  88898. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88899. subframe->data = residual;
  88900. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88901. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88902. return false; /* read_callback_ sets the state for us */
  88903. residual[i] = x;
  88904. }
  88905. if(do_full_decode)
  88906. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88907. return true;
  88908. }
  88909. 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)
  88910. {
  88911. FLAC__uint32 rice_parameter;
  88912. int i;
  88913. unsigned partition, sample, u;
  88914. const unsigned partitions = 1u << partition_order;
  88915. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88916. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88917. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88918. if(partition_order == 0) {
  88919. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88920. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88921. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88922. return true;
  88923. }
  88924. }
  88925. else {
  88926. if(partition_samples < predictor_order) {
  88927. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88928. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88929. return true;
  88930. }
  88931. }
  88932. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  88933. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88934. return false;
  88935. }
  88936. sample = 0;
  88937. for(partition = 0; partition < partitions; partition++) {
  88938. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  88939. return false; /* read_callback_ sets the state for us */
  88940. partitioned_rice_contents->parameters[partition] = rice_parameter;
  88941. if(rice_parameter < pesc) {
  88942. partitioned_rice_contents->raw_bits[partition] = 0;
  88943. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  88944. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  88945. return false; /* read_callback_ sets the state for us */
  88946. sample += u;
  88947. }
  88948. else {
  88949. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  88950. return false; /* read_callback_ sets the state for us */
  88951. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  88952. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  88953. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  88954. return false; /* read_callback_ sets the state for us */
  88955. residual[sample] = i;
  88956. }
  88957. }
  88958. }
  88959. return true;
  88960. }
  88961. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  88962. {
  88963. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88964. FLAC__uint32 zero = 0;
  88965. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88966. return false; /* read_callback_ sets the state for us */
  88967. if(zero != 0) {
  88968. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88969. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88970. }
  88971. }
  88972. return true;
  88973. }
  88974. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  88975. {
  88976. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  88977. if(
  88978. #if FLAC__HAS_OGG
  88979. !decoder->private_->is_ogg &&
  88980. #endif
  88981. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88982. ) {
  88983. *bytes = 0;
  88984. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88985. return false;
  88986. }
  88987. else if(*bytes > 0) {
  88988. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  88989. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88990. return false;
  88991. }
  88992. else {
  88993. const FLAC__StreamDecoderReadStatus status =
  88994. #if FLAC__HAS_OGG
  88995. decoder->private_->is_ogg?
  88996. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  88997. #endif
  88998. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  88999. ;
  89000. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89001. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89002. return false;
  89003. }
  89004. else if(*bytes == 0) {
  89005. if(
  89006. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89007. (
  89008. #if FLAC__HAS_OGG
  89009. !decoder->private_->is_ogg &&
  89010. #endif
  89011. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89012. )
  89013. ) {
  89014. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89015. return false;
  89016. }
  89017. else
  89018. return true;
  89019. }
  89020. else
  89021. return true;
  89022. }
  89023. }
  89024. else {
  89025. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89026. return false;
  89027. }
  89028. }
  89029. #if FLAC__HAS_OGG
  89030. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89031. {
  89032. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89033. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89034. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89035. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89036. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89037. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89038. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89039. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89040. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89041. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89042. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89043. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89044. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89045. default:
  89046. FLAC__ASSERT(0);
  89047. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89048. }
  89049. }
  89050. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89051. {
  89052. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89053. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89054. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89055. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89056. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89057. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89058. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89059. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89060. default:
  89061. FLAC__ASSERT(0);
  89062. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89063. }
  89064. }
  89065. #endif
  89066. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89067. {
  89068. if(decoder->private_->is_seeking) {
  89069. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89070. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89071. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89072. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89073. #if FLAC__HAS_OGG
  89074. decoder->private_->got_a_frame = true;
  89075. #endif
  89076. decoder->private_->last_frame = *frame; /* save the frame */
  89077. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89078. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89079. decoder->private_->is_seeking = false;
  89080. if(delta > 0) {
  89081. unsigned channel;
  89082. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89083. for(channel = 0; channel < frame->header.channels; channel++)
  89084. newbuffer[channel] = buffer[channel] + delta;
  89085. decoder->private_->last_frame.header.blocksize -= delta;
  89086. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89087. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89088. }
  89089. else {
  89090. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89091. }
  89092. }
  89093. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89094. }
  89095. if(!decoder->private_->has_stream_info)
  89096. decoder->private_->do_md5_checking = false;
  89097. if(decoder->private_->do_md5_checking) {
  89098. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89099. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89100. }
  89101. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89102. }
  89103. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89104. {
  89105. if(!decoder->private_->is_seeking)
  89106. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89107. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89108. decoder->private_->unparseable_frame_count++;
  89109. }
  89110. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89111. {
  89112. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89113. FLAC__int64 pos = -1;
  89114. int i;
  89115. unsigned approx_bytes_per_frame;
  89116. FLAC__bool first_seek = true;
  89117. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89118. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89119. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89120. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89121. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89122. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89123. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89124. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89125. if(channels == 0)
  89126. channels = decoder->private_->stream_info.data.stream_info.channels;
  89127. if(bps == 0)
  89128. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89129. if(max_framesize > 0)
  89130. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89131. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89132. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89133. }
  89134. else
  89135. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89136. lower_bound = first_frame_offset;
  89137. lower_bound_sample = 0;
  89138. upper_bound = stream_length;
  89139. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89140. if(seek_table) {
  89141. FLAC__uint64 new_lower_bound = lower_bound;
  89142. FLAC__uint64 new_upper_bound = upper_bound;
  89143. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89144. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89145. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89146. if(
  89147. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89148. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89149. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89150. seek_table->points[i].sample_number <= target_sample
  89151. )
  89152. break;
  89153. }
  89154. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89155. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89156. new_lower_bound_sample = seek_table->points[i].sample_number;
  89157. }
  89158. for(i = 0; i < (int)seek_table->num_points; i++) {
  89159. if(
  89160. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89161. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89162. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89163. seek_table->points[i].sample_number > target_sample
  89164. )
  89165. break;
  89166. }
  89167. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89168. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89169. new_upper_bound_sample = seek_table->points[i].sample_number;
  89170. }
  89171. if(new_upper_bound >= new_lower_bound) {
  89172. lower_bound = new_lower_bound;
  89173. upper_bound = new_upper_bound;
  89174. lower_bound_sample = new_lower_bound_sample;
  89175. upper_bound_sample = new_upper_bound_sample;
  89176. }
  89177. }
  89178. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89179. if(upper_bound_sample == lower_bound_sample)
  89180. upper_bound_sample++;
  89181. decoder->private_->target_sample = target_sample;
  89182. while(1) {
  89183. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89184. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89185. return false;
  89186. }
  89187. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89188. #if defined _MSC_VER || defined __MINGW32__
  89189. 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;
  89190. #else
  89191. 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;
  89192. #endif
  89193. #else
  89194. if(upper_bound - lower_bound < 0xffffffff)
  89195. 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;
  89196. else /* @@@ WATCHOUT, ~2TB limit */
  89197. 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;
  89198. #endif
  89199. if(pos >= (FLAC__int64)upper_bound)
  89200. pos = (FLAC__int64)upper_bound - 1;
  89201. if(pos < (FLAC__int64)lower_bound)
  89202. pos = (FLAC__int64)lower_bound;
  89203. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89204. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89205. return false;
  89206. }
  89207. if(!FLAC__stream_decoder_flush(decoder)) {
  89208. return false;
  89209. }
  89210. decoder->private_->unparseable_frame_count = 0;
  89211. if(!FLAC__stream_decoder_process_single(decoder)) {
  89212. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89213. return false;
  89214. }
  89215. #if 0
  89216. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89217. break;
  89218. #endif
  89219. if(!decoder->private_->is_seeking)
  89220. break;
  89221. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89222. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89223. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89224. if (pos == (FLAC__int64)lower_bound) {
  89225. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89226. return false;
  89227. }
  89228. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89229. continue;
  89230. }
  89231. first_seek = false;
  89232. if (this_frame_sample < lower_bound_sample) {
  89233. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89234. return false;
  89235. }
  89236. if(target_sample < this_frame_sample) {
  89237. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89238. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89239. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89240. return false;
  89241. }
  89242. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89243. }
  89244. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89245. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89246. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89247. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89248. return false;
  89249. }
  89250. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89251. }
  89252. }
  89253. return true;
  89254. }
  89255. #if FLAC__HAS_OGG
  89256. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89257. {
  89258. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89259. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89260. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89261. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89262. FLAC__bool did_a_seek;
  89263. unsigned iteration = 0;
  89264. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89265. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89266. if(right_sample == 0) {
  89267. right_sample = (FLAC__uint64)(-1);
  89268. BINARY_SEARCH_AFTER_ITERATION = 0;
  89269. }
  89270. decoder->private_->target_sample = target_sample;
  89271. for( ; ; iteration++) {
  89272. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89273. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89274. pos = (right_pos + left_pos) / 2;
  89275. }
  89276. else {
  89277. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89278. #if defined _MSC_VER || defined __MINGW32__
  89279. 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));
  89280. #else
  89281. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89282. #endif
  89283. #else
  89284. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89285. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89286. else /* @@@ WATCHOUT, ~2TB limit */
  89287. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89288. #endif
  89289. }
  89290. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89291. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89292. return false;
  89293. }
  89294. if(!FLAC__stream_decoder_flush(decoder)) {
  89295. return false;
  89296. }
  89297. did_a_seek = true;
  89298. }
  89299. else
  89300. did_a_seek = false;
  89301. decoder->private_->got_a_frame = false;
  89302. if(!FLAC__stream_decoder_process_single(decoder)) {
  89303. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89304. return false;
  89305. }
  89306. if(!decoder->private_->got_a_frame) {
  89307. if(did_a_seek) {
  89308. right_pos = pos;
  89309. BINARY_SEARCH_AFTER_ITERATION = 0;
  89310. }
  89311. else {
  89312. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89313. return false;
  89314. }
  89315. }
  89316. else if(!decoder->private_->is_seeking) {
  89317. break;
  89318. }
  89319. else {
  89320. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89321. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89322. if (did_a_seek) {
  89323. if (this_frame_sample <= target_sample) {
  89324. FLAC__ASSERT(this_frame_sample != target_sample);
  89325. left_sample = this_frame_sample;
  89326. if (left_pos == pos) {
  89327. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89328. return false;
  89329. }
  89330. left_pos = pos;
  89331. }
  89332. else if(this_frame_sample > target_sample) {
  89333. right_sample = this_frame_sample;
  89334. if (right_pos == pos) {
  89335. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89336. return false;
  89337. }
  89338. right_pos = pos;
  89339. }
  89340. }
  89341. }
  89342. }
  89343. return true;
  89344. }
  89345. #endif
  89346. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89347. {
  89348. (void)client_data;
  89349. if(*bytes > 0) {
  89350. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89351. if(ferror(decoder->private_->file))
  89352. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89353. else if(*bytes == 0)
  89354. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89355. else
  89356. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89357. }
  89358. else
  89359. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89360. }
  89361. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89362. {
  89363. (void)client_data;
  89364. if(decoder->private_->file == stdin)
  89365. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89366. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89367. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89368. else
  89369. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89370. }
  89371. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89372. {
  89373. off_t pos;
  89374. (void)client_data;
  89375. if(decoder->private_->file == stdin)
  89376. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89377. else if((pos = ftello(decoder->private_->file)) < 0)
  89378. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89379. else {
  89380. *absolute_byte_offset = (FLAC__uint64)pos;
  89381. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89382. }
  89383. }
  89384. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89385. {
  89386. struct stat filestats;
  89387. (void)client_data;
  89388. if(decoder->private_->file == stdin)
  89389. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89390. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89391. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89392. else {
  89393. *stream_length = (FLAC__uint64)filestats.st_size;
  89394. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89395. }
  89396. }
  89397. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89398. {
  89399. (void)client_data;
  89400. return feof(decoder->private_->file)? true : false;
  89401. }
  89402. #endif
  89403. /*** End of inlined file: stream_decoder.c ***/
  89404. /*** Start of inlined file: stream_encoder.c ***/
  89405. /*** Start of inlined file: juce_FlacHeader.h ***/
  89406. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89407. // tasks..
  89408. #define VERSION "1.2.1"
  89409. #define FLAC__NO_DLL 1
  89410. #if JUCE_MSVC
  89411. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89412. #endif
  89413. #if JUCE_MAC
  89414. #define FLAC__SYS_DARWIN 1
  89415. #endif
  89416. /*** End of inlined file: juce_FlacHeader.h ***/
  89417. #if JUCE_USE_FLAC
  89418. #if HAVE_CONFIG_H
  89419. # include <config.h>
  89420. #endif
  89421. #if defined _MSC_VER || defined __MINGW32__
  89422. #include <io.h> /* for _setmode() */
  89423. #include <fcntl.h> /* for _O_BINARY */
  89424. #endif
  89425. #if defined __CYGWIN__ || defined __EMX__
  89426. #include <io.h> /* for setmode(), O_BINARY */
  89427. #include <fcntl.h> /* for _O_BINARY */
  89428. #endif
  89429. #include <limits.h>
  89430. #include <stdio.h>
  89431. #include <stdlib.h> /* for malloc() */
  89432. #include <string.h> /* for memcpy() */
  89433. #include <sys/types.h> /* for off_t */
  89434. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89435. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89436. #define fseeko fseek
  89437. #define ftello ftell
  89438. #endif
  89439. #endif
  89440. /*** Start of inlined file: stream_encoder.h ***/
  89441. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89442. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89443. #if FLAC__HAS_OGG
  89444. #include "private/ogg_encoder_aspect.h"
  89445. #endif
  89446. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89447. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89448. typedef enum {
  89449. FLAC__APODIZATION_BARTLETT,
  89450. FLAC__APODIZATION_BARTLETT_HANN,
  89451. FLAC__APODIZATION_BLACKMAN,
  89452. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89453. FLAC__APODIZATION_CONNES,
  89454. FLAC__APODIZATION_FLATTOP,
  89455. FLAC__APODIZATION_GAUSS,
  89456. FLAC__APODIZATION_HAMMING,
  89457. FLAC__APODIZATION_HANN,
  89458. FLAC__APODIZATION_KAISER_BESSEL,
  89459. FLAC__APODIZATION_NUTTALL,
  89460. FLAC__APODIZATION_RECTANGLE,
  89461. FLAC__APODIZATION_TRIANGLE,
  89462. FLAC__APODIZATION_TUKEY,
  89463. FLAC__APODIZATION_WELCH
  89464. } FLAC__ApodizationFunction;
  89465. typedef struct {
  89466. FLAC__ApodizationFunction type;
  89467. union {
  89468. struct {
  89469. FLAC__real stddev;
  89470. } gauss;
  89471. struct {
  89472. FLAC__real p;
  89473. } tukey;
  89474. } parameters;
  89475. } FLAC__ApodizationSpecification;
  89476. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89477. typedef struct FLAC__StreamEncoderProtected {
  89478. FLAC__StreamEncoderState state;
  89479. FLAC__bool verify;
  89480. FLAC__bool streamable_subset;
  89481. FLAC__bool do_md5;
  89482. FLAC__bool do_mid_side_stereo;
  89483. FLAC__bool loose_mid_side_stereo;
  89484. unsigned channels;
  89485. unsigned bits_per_sample;
  89486. unsigned sample_rate;
  89487. unsigned blocksize;
  89488. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89489. unsigned num_apodizations;
  89490. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89491. #endif
  89492. unsigned max_lpc_order;
  89493. unsigned qlp_coeff_precision;
  89494. FLAC__bool do_qlp_coeff_prec_search;
  89495. FLAC__bool do_exhaustive_model_search;
  89496. FLAC__bool do_escape_coding;
  89497. unsigned min_residual_partition_order;
  89498. unsigned max_residual_partition_order;
  89499. unsigned rice_parameter_search_dist;
  89500. FLAC__uint64 total_samples_estimate;
  89501. FLAC__StreamMetadata **metadata;
  89502. unsigned num_metadata_blocks;
  89503. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89504. #if FLAC__HAS_OGG
  89505. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89506. #endif
  89507. } FLAC__StreamEncoderProtected;
  89508. #endif
  89509. /*** End of inlined file: stream_encoder.h ***/
  89510. #if FLAC__HAS_OGG
  89511. #include "include/private/ogg_helper.h"
  89512. #include "include/private/ogg_mapping.h"
  89513. #endif
  89514. /*** Start of inlined file: stream_encoder_framing.h ***/
  89515. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89516. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89517. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89518. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89519. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89520. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89521. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89522. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89523. #endif
  89524. /*** End of inlined file: stream_encoder_framing.h ***/
  89525. /*** Start of inlined file: window.h ***/
  89526. #ifndef FLAC__PRIVATE__WINDOW_H
  89527. #define FLAC__PRIVATE__WINDOW_H
  89528. #ifdef HAVE_CONFIG_H
  89529. #include <config.h>
  89530. #endif
  89531. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89532. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89533. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89534. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89535. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89536. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89537. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89538. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89539. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89540. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89541. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89542. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89543. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89544. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89545. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89546. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89547. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89548. #endif
  89549. /*** End of inlined file: window.h ***/
  89550. #ifndef FLaC__INLINE
  89551. #define FLaC__INLINE
  89552. #endif
  89553. #ifdef min
  89554. #undef min
  89555. #endif
  89556. #define min(x,y) ((x)<(y)?(x):(y))
  89557. #ifdef max
  89558. #undef max
  89559. #endif
  89560. #define max(x,y) ((x)>(y)?(x):(y))
  89561. #undef EXACT_RICE_BITS_CALCULATION
  89562. #undef ENABLE_RICE_PARAMETER_SEARCH
  89563. typedef struct {
  89564. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89565. unsigned size; /* of each data[] in samples */
  89566. unsigned tail;
  89567. } verify_input_fifo;
  89568. typedef struct {
  89569. const FLAC__byte *data;
  89570. unsigned capacity;
  89571. unsigned bytes;
  89572. } verify_output;
  89573. typedef enum {
  89574. ENCODER_IN_MAGIC = 0,
  89575. ENCODER_IN_METADATA = 1,
  89576. ENCODER_IN_AUDIO = 2
  89577. } EncoderStateHint;
  89578. static struct CompressionLevels {
  89579. FLAC__bool do_mid_side_stereo;
  89580. FLAC__bool loose_mid_side_stereo;
  89581. unsigned max_lpc_order;
  89582. unsigned qlp_coeff_precision;
  89583. FLAC__bool do_qlp_coeff_prec_search;
  89584. FLAC__bool do_escape_coding;
  89585. FLAC__bool do_exhaustive_model_search;
  89586. unsigned min_residual_partition_order;
  89587. unsigned max_residual_partition_order;
  89588. unsigned rice_parameter_search_dist;
  89589. } compression_levels_[] = {
  89590. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89591. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89592. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89593. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89594. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89595. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89596. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89597. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89598. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89599. };
  89600. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89601. static void free_(FLAC__StreamEncoder *encoder);
  89602. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89603. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89604. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89605. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89606. #if FLAC__HAS_OGG
  89607. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89608. #endif
  89609. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89610. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89611. static FLAC__bool process_subframe_(
  89612. FLAC__StreamEncoder *encoder,
  89613. unsigned min_partition_order,
  89614. unsigned max_partition_order,
  89615. const FLAC__FrameHeader *frame_header,
  89616. unsigned subframe_bps,
  89617. const FLAC__int32 integer_signal[],
  89618. FLAC__Subframe *subframe[2],
  89619. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89620. FLAC__int32 *residual[2],
  89621. unsigned *best_subframe,
  89622. unsigned *best_bits
  89623. );
  89624. static FLAC__bool add_subframe_(
  89625. FLAC__StreamEncoder *encoder,
  89626. unsigned blocksize,
  89627. unsigned subframe_bps,
  89628. const FLAC__Subframe *subframe,
  89629. FLAC__BitWriter *frame
  89630. );
  89631. static unsigned evaluate_constant_subframe_(
  89632. FLAC__StreamEncoder *encoder,
  89633. const FLAC__int32 signal,
  89634. unsigned blocksize,
  89635. unsigned subframe_bps,
  89636. FLAC__Subframe *subframe
  89637. );
  89638. static unsigned evaluate_fixed_subframe_(
  89639. FLAC__StreamEncoder *encoder,
  89640. const FLAC__int32 signal[],
  89641. FLAC__int32 residual[],
  89642. FLAC__uint64 abs_residual_partition_sums[],
  89643. unsigned raw_bits_per_partition[],
  89644. unsigned blocksize,
  89645. unsigned subframe_bps,
  89646. unsigned order,
  89647. unsigned rice_parameter,
  89648. unsigned rice_parameter_limit,
  89649. unsigned min_partition_order,
  89650. unsigned max_partition_order,
  89651. FLAC__bool do_escape_coding,
  89652. unsigned rice_parameter_search_dist,
  89653. FLAC__Subframe *subframe,
  89654. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89655. );
  89656. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89657. static unsigned evaluate_lpc_subframe_(
  89658. FLAC__StreamEncoder *encoder,
  89659. const FLAC__int32 signal[],
  89660. FLAC__int32 residual[],
  89661. FLAC__uint64 abs_residual_partition_sums[],
  89662. unsigned raw_bits_per_partition[],
  89663. const FLAC__real lp_coeff[],
  89664. unsigned blocksize,
  89665. unsigned subframe_bps,
  89666. unsigned order,
  89667. unsigned qlp_coeff_precision,
  89668. unsigned rice_parameter,
  89669. unsigned rice_parameter_limit,
  89670. unsigned min_partition_order,
  89671. unsigned max_partition_order,
  89672. FLAC__bool do_escape_coding,
  89673. unsigned rice_parameter_search_dist,
  89674. FLAC__Subframe *subframe,
  89675. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89676. );
  89677. #endif
  89678. static unsigned evaluate_verbatim_subframe_(
  89679. FLAC__StreamEncoder *encoder,
  89680. const FLAC__int32 signal[],
  89681. unsigned blocksize,
  89682. unsigned subframe_bps,
  89683. FLAC__Subframe *subframe
  89684. );
  89685. static unsigned find_best_partition_order_(
  89686. struct FLAC__StreamEncoderPrivate *private_,
  89687. const FLAC__int32 residual[],
  89688. FLAC__uint64 abs_residual_partition_sums[],
  89689. unsigned raw_bits_per_partition[],
  89690. unsigned residual_samples,
  89691. unsigned predictor_order,
  89692. unsigned rice_parameter,
  89693. unsigned rice_parameter_limit,
  89694. unsigned min_partition_order,
  89695. unsigned max_partition_order,
  89696. unsigned bps,
  89697. FLAC__bool do_escape_coding,
  89698. unsigned rice_parameter_search_dist,
  89699. FLAC__EntropyCodingMethod *best_ecm
  89700. );
  89701. static void precompute_partition_info_sums_(
  89702. const FLAC__int32 residual[],
  89703. FLAC__uint64 abs_residual_partition_sums[],
  89704. unsigned residual_samples,
  89705. unsigned predictor_order,
  89706. unsigned min_partition_order,
  89707. unsigned max_partition_order,
  89708. unsigned bps
  89709. );
  89710. static void precompute_partition_info_escapes_(
  89711. const FLAC__int32 residual[],
  89712. unsigned raw_bits_per_partition[],
  89713. unsigned residual_samples,
  89714. unsigned predictor_order,
  89715. unsigned min_partition_order,
  89716. unsigned max_partition_order
  89717. );
  89718. static FLAC__bool set_partitioned_rice_(
  89719. #ifdef EXACT_RICE_BITS_CALCULATION
  89720. const FLAC__int32 residual[],
  89721. #endif
  89722. const FLAC__uint64 abs_residual_partition_sums[],
  89723. const unsigned raw_bits_per_partition[],
  89724. const unsigned residual_samples,
  89725. const unsigned predictor_order,
  89726. const unsigned suggested_rice_parameter,
  89727. const unsigned rice_parameter_limit,
  89728. const unsigned rice_parameter_search_dist,
  89729. const unsigned partition_order,
  89730. const FLAC__bool search_for_escapes,
  89731. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89732. unsigned *bits
  89733. );
  89734. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89735. static void append_to_verify_fifo_(
  89736. verify_input_fifo *fifo,
  89737. const FLAC__int32 * const input[],
  89738. unsigned input_offset,
  89739. unsigned channels,
  89740. unsigned wide_samples
  89741. );
  89742. static void append_to_verify_fifo_interleaved_(
  89743. verify_input_fifo *fifo,
  89744. const FLAC__int32 input[],
  89745. unsigned input_offset,
  89746. unsigned channels,
  89747. unsigned wide_samples
  89748. );
  89749. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89750. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89751. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89752. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89753. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89754. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89755. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89756. 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);
  89757. static FILE *get_binary_stdout_(void);
  89758. typedef struct FLAC__StreamEncoderPrivate {
  89759. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89760. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89761. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89762. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89763. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89764. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89765. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89766. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89767. #endif
  89768. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89769. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89770. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89771. FLAC__int32 *residual_workspace_mid_side[2][2];
  89772. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89773. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89774. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89775. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89776. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89777. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89778. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89779. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89780. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89781. unsigned best_subframe_mid_side[2];
  89782. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89783. unsigned best_subframe_bits_mid_side[2];
  89784. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89785. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89786. FLAC__BitWriter *frame; /* the current frame being worked on */
  89787. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89788. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89789. FLAC__ChannelAssignment last_channel_assignment;
  89790. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89791. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89792. unsigned current_sample_number;
  89793. unsigned current_frame_number;
  89794. FLAC__MD5Context md5context;
  89795. FLAC__CPUInfo cpuinfo;
  89796. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89797. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89798. #else
  89799. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89800. #endif
  89801. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89802. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89803. 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[]);
  89804. 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[]);
  89805. 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[]);
  89806. #endif
  89807. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89808. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89809. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89810. FLAC__bool disable_constant_subframes;
  89811. FLAC__bool disable_fixed_subframes;
  89812. FLAC__bool disable_verbatim_subframes;
  89813. #if FLAC__HAS_OGG
  89814. FLAC__bool is_ogg;
  89815. #endif
  89816. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89817. FLAC__StreamEncoderSeekCallback seek_callback;
  89818. FLAC__StreamEncoderTellCallback tell_callback;
  89819. FLAC__StreamEncoderWriteCallback write_callback;
  89820. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89821. FLAC__StreamEncoderProgressCallback progress_callback;
  89822. void *client_data;
  89823. unsigned first_seekpoint_to_check;
  89824. FILE *file; /* only used when encoding to a file */
  89825. FLAC__uint64 bytes_written;
  89826. FLAC__uint64 samples_written;
  89827. unsigned frames_written;
  89828. unsigned total_frames_estimate;
  89829. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89830. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89831. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89832. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89833. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89834. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89835. FLAC__real *windowed_signal_unaligned;
  89836. #endif
  89837. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89838. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89839. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89840. unsigned *raw_bits_per_partition_unaligned;
  89841. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89842. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89843. #endif
  89844. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89845. struct {
  89846. FLAC__StreamDecoder *decoder;
  89847. EncoderStateHint state_hint;
  89848. FLAC__bool needs_magic_hack;
  89849. verify_input_fifo input_fifo;
  89850. verify_output output;
  89851. struct {
  89852. FLAC__uint64 absolute_sample;
  89853. unsigned frame_number;
  89854. unsigned channel;
  89855. unsigned sample;
  89856. FLAC__int32 expected;
  89857. FLAC__int32 got;
  89858. } error_stats;
  89859. } verify;
  89860. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89861. } FLAC__StreamEncoderPrivate;
  89862. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89863. "FLAC__STREAM_ENCODER_OK",
  89864. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89865. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89866. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89867. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89868. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89869. "FLAC__STREAM_ENCODER_IO_ERROR",
  89870. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89871. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89872. };
  89873. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89874. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89875. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89876. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89877. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89878. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89879. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89880. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89881. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89882. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89883. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89884. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89885. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89886. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89887. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89888. };
  89889. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89890. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89891. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89892. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89893. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89894. };
  89895. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89896. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89897. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89898. };
  89899. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89900. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89901. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89902. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89903. };
  89904. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89905. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89906. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89907. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89908. };
  89909. static const unsigned OVERREAD_ = 1;
  89910. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89911. {
  89912. FLAC__StreamEncoder *encoder;
  89913. unsigned i;
  89914. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89915. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89916. if(encoder == 0) {
  89917. return 0;
  89918. }
  89919. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89920. if(encoder->protected_ == 0) {
  89921. free(encoder);
  89922. return 0;
  89923. }
  89924. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89925. if(encoder->private_ == 0) {
  89926. free(encoder->protected_);
  89927. free(encoder);
  89928. return 0;
  89929. }
  89930. encoder->private_->frame = FLAC__bitwriter_new();
  89931. if(encoder->private_->frame == 0) {
  89932. free(encoder->private_);
  89933. free(encoder->protected_);
  89934. free(encoder);
  89935. return 0;
  89936. }
  89937. encoder->private_->file = 0;
  89938. set_defaults_enc(encoder);
  89939. encoder->private_->is_being_deleted = false;
  89940. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89941. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  89942. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  89943. }
  89944. for(i = 0; i < 2; i++) {
  89945. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  89946. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  89947. }
  89948. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89949. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  89950. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  89951. }
  89952. for(i = 0; i < 2; i++) {
  89953. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  89954. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  89955. }
  89956. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89957. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89958. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89959. }
  89960. for(i = 0; i < 2; i++) {
  89961. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89962. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89963. }
  89964. for(i = 0; i < 2; i++)
  89965. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  89966. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  89967. return encoder;
  89968. }
  89969. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  89970. {
  89971. unsigned i;
  89972. FLAC__ASSERT(0 != encoder);
  89973. FLAC__ASSERT(0 != encoder->protected_);
  89974. FLAC__ASSERT(0 != encoder->private_);
  89975. FLAC__ASSERT(0 != encoder->private_->frame);
  89976. encoder->private_->is_being_deleted = true;
  89977. (void)FLAC__stream_encoder_finish(encoder);
  89978. if(0 != encoder->private_->verify.decoder)
  89979. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  89980. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89981. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89982. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89983. }
  89984. for(i = 0; i < 2; i++) {
  89985. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89986. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89987. }
  89988. for(i = 0; i < 2; i++)
  89989. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  89990. FLAC__bitwriter_delete(encoder->private_->frame);
  89991. free(encoder->private_);
  89992. free(encoder->protected_);
  89993. free(encoder);
  89994. }
  89995. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  89996. FLAC__StreamEncoder *encoder,
  89997. FLAC__StreamEncoderReadCallback read_callback,
  89998. FLAC__StreamEncoderWriteCallback write_callback,
  89999. FLAC__StreamEncoderSeekCallback seek_callback,
  90000. FLAC__StreamEncoderTellCallback tell_callback,
  90001. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90002. void *client_data,
  90003. FLAC__bool is_ogg
  90004. )
  90005. {
  90006. unsigned i;
  90007. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90008. FLAC__ASSERT(0 != encoder);
  90009. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90010. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90011. #if !FLAC__HAS_OGG
  90012. if(is_ogg)
  90013. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90014. #endif
  90015. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90016. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90017. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90018. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90019. if(encoder->protected_->channels != 2) {
  90020. encoder->protected_->do_mid_side_stereo = false;
  90021. encoder->protected_->loose_mid_side_stereo = false;
  90022. }
  90023. else if(!encoder->protected_->do_mid_side_stereo)
  90024. encoder->protected_->loose_mid_side_stereo = false;
  90025. if(encoder->protected_->bits_per_sample >= 32)
  90026. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90027. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90028. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90029. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90030. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90031. if(encoder->protected_->blocksize == 0) {
  90032. if(encoder->protected_->max_lpc_order == 0)
  90033. encoder->protected_->blocksize = 1152;
  90034. else
  90035. encoder->protected_->blocksize = 4096;
  90036. }
  90037. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90038. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90039. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90040. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90041. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90042. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90043. if(encoder->protected_->qlp_coeff_precision == 0) {
  90044. if(encoder->protected_->bits_per_sample < 16) {
  90045. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90046. }
  90047. else if(encoder->protected_->bits_per_sample == 16) {
  90048. if(encoder->protected_->blocksize <= 192)
  90049. encoder->protected_->qlp_coeff_precision = 7;
  90050. else if(encoder->protected_->blocksize <= 384)
  90051. encoder->protected_->qlp_coeff_precision = 8;
  90052. else if(encoder->protected_->blocksize <= 576)
  90053. encoder->protected_->qlp_coeff_precision = 9;
  90054. else if(encoder->protected_->blocksize <= 1152)
  90055. encoder->protected_->qlp_coeff_precision = 10;
  90056. else if(encoder->protected_->blocksize <= 2304)
  90057. encoder->protected_->qlp_coeff_precision = 11;
  90058. else if(encoder->protected_->blocksize <= 4608)
  90059. encoder->protected_->qlp_coeff_precision = 12;
  90060. else
  90061. encoder->protected_->qlp_coeff_precision = 13;
  90062. }
  90063. else {
  90064. if(encoder->protected_->blocksize <= 384)
  90065. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90066. else if(encoder->protected_->blocksize <= 1152)
  90067. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90068. else
  90069. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90070. }
  90071. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90072. }
  90073. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90074. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90075. if(encoder->protected_->streamable_subset) {
  90076. if(
  90077. encoder->protected_->blocksize != 192 &&
  90078. encoder->protected_->blocksize != 576 &&
  90079. encoder->protected_->blocksize != 1152 &&
  90080. encoder->protected_->blocksize != 2304 &&
  90081. encoder->protected_->blocksize != 4608 &&
  90082. encoder->protected_->blocksize != 256 &&
  90083. encoder->protected_->blocksize != 512 &&
  90084. encoder->protected_->blocksize != 1024 &&
  90085. encoder->protected_->blocksize != 2048 &&
  90086. encoder->protected_->blocksize != 4096 &&
  90087. encoder->protected_->blocksize != 8192 &&
  90088. encoder->protected_->blocksize != 16384
  90089. )
  90090. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90091. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90092. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90093. if(
  90094. encoder->protected_->bits_per_sample != 8 &&
  90095. encoder->protected_->bits_per_sample != 12 &&
  90096. encoder->protected_->bits_per_sample != 16 &&
  90097. encoder->protected_->bits_per_sample != 20 &&
  90098. encoder->protected_->bits_per_sample != 24
  90099. )
  90100. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90101. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90102. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90103. if(
  90104. encoder->protected_->sample_rate <= 48000 &&
  90105. (
  90106. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90107. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90108. )
  90109. ) {
  90110. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90111. }
  90112. }
  90113. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90114. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90115. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90116. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90117. #if FLAC__HAS_OGG
  90118. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90119. unsigned i;
  90120. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90121. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90122. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90123. for( ; i > 0; i--)
  90124. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90125. encoder->protected_->metadata[0] = vc;
  90126. break;
  90127. }
  90128. }
  90129. }
  90130. #endif
  90131. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90132. unsigned i;
  90133. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90134. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90135. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90136. break; /* take only the first one */
  90137. }
  90138. }
  90139. }
  90140. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90141. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90142. metadata_has_seektable = false;
  90143. metadata_has_vorbis_comment = false;
  90144. metadata_picture_has_type1 = false;
  90145. metadata_picture_has_type2 = false;
  90146. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90147. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90148. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90149. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90150. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90151. if(metadata_has_seektable) /* only one is allowed */
  90152. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90153. metadata_has_seektable = true;
  90154. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90155. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90156. }
  90157. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90158. if(metadata_has_vorbis_comment) /* only one is allowed */
  90159. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90160. metadata_has_vorbis_comment = true;
  90161. }
  90162. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90163. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90164. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90165. }
  90166. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90167. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90168. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90169. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90170. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90171. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90172. metadata_picture_has_type1 = true;
  90173. if(
  90174. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90175. (
  90176. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90177. m->data.picture.width != 32 ||
  90178. m->data.picture.height != 32
  90179. )
  90180. )
  90181. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90182. }
  90183. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90184. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90185. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90186. metadata_picture_has_type2 = true;
  90187. }
  90188. }
  90189. }
  90190. encoder->private_->input_capacity = 0;
  90191. for(i = 0; i < encoder->protected_->channels; i++) {
  90192. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90193. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90194. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90195. #endif
  90196. }
  90197. for(i = 0; i < 2; i++) {
  90198. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90199. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90200. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90201. #endif
  90202. }
  90203. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90204. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90205. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90206. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90207. #endif
  90208. for(i = 0; i < encoder->protected_->channels; i++) {
  90209. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90210. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90211. encoder->private_->best_subframe[i] = 0;
  90212. }
  90213. for(i = 0; i < 2; i++) {
  90214. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90215. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90216. encoder->private_->best_subframe_mid_side[i] = 0;
  90217. }
  90218. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90219. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90220. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90221. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90222. #else
  90223. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90224. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90225. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90226. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90227. 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);
  90228. #endif
  90229. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90230. encoder->private_->loose_mid_side_stereo_frames = 1;
  90231. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90232. encoder->private_->current_sample_number = 0;
  90233. encoder->private_->current_frame_number = 0;
  90234. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90235. 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? */
  90236. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90237. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90238. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90239. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90240. #endif
  90241. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90242. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90243. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90244. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90245. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90246. #endif
  90247. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90248. # ifndef FLAC__NO_ASM
  90249. if(encoder->private_->cpuinfo.use_asm) {
  90250. # ifdef FLAC__CPU_IA32
  90251. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90252. # ifdef FLAC__HAS_NASM
  90253. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90254. if(encoder->protected_->max_lpc_order < 4)
  90255. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90256. else if(encoder->protected_->max_lpc_order < 8)
  90257. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90258. else if(encoder->protected_->max_lpc_order < 12)
  90259. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90260. else
  90261. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90262. }
  90263. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90264. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90265. else
  90266. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90267. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90268. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90269. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90270. }
  90271. else {
  90272. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90273. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90274. }
  90275. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90276. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90277. # endif /* FLAC__HAS_NASM */
  90278. # endif /* FLAC__CPU_IA32 */
  90279. }
  90280. # endif /* !FLAC__NO_ASM */
  90281. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90282. if(encoder->private_->use_wide_by_block) {
  90283. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90284. }
  90285. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90286. #if FLAC__HAS_OGG
  90287. encoder->private_->is_ogg = is_ogg;
  90288. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90289. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90290. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90291. }
  90292. #endif
  90293. encoder->private_->read_callback = read_callback;
  90294. encoder->private_->write_callback = write_callback;
  90295. encoder->private_->seek_callback = seek_callback;
  90296. encoder->private_->tell_callback = tell_callback;
  90297. encoder->private_->metadata_callback = metadata_callback;
  90298. encoder->private_->client_data = client_data;
  90299. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90300. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90301. }
  90302. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90303. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90304. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90305. }
  90306. if(encoder->protected_->verify) {
  90307. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90308. for(i = 0; i < encoder->protected_->channels; i++) {
  90309. 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))) {
  90310. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90311. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90312. }
  90313. }
  90314. encoder->private_->verify.input_fifo.tail = 0;
  90315. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90316. if(0 == encoder->private_->verify.decoder) {
  90317. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90318. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90319. }
  90320. 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) {
  90321. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90322. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90323. }
  90324. }
  90325. encoder->private_->verify.error_stats.absolute_sample = 0;
  90326. encoder->private_->verify.error_stats.frame_number = 0;
  90327. encoder->private_->verify.error_stats.channel = 0;
  90328. encoder->private_->verify.error_stats.sample = 0;
  90329. encoder->private_->verify.error_stats.expected = 0;
  90330. encoder->private_->verify.error_stats.got = 0;
  90331. encoder->private_->first_seekpoint_to_check = 0;
  90332. encoder->private_->samples_written = 0;
  90333. encoder->protected_->streaminfo_offset = 0;
  90334. encoder->protected_->seektable_offset = 0;
  90335. encoder->protected_->audio_offset = 0;
  90336. if(encoder->protected_->verify)
  90337. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90338. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90339. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90340. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90341. }
  90342. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90343. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90344. }
  90345. if(encoder->protected_->verify)
  90346. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90347. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90348. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90349. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90350. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90351. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90352. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90353. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90354. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90355. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90356. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90357. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90358. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90359. if(encoder->protected_->do_md5)
  90360. FLAC__MD5Init(&encoder->private_->md5context);
  90361. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90362. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90363. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90364. }
  90365. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90366. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90367. }
  90368. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90369. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90370. if(!metadata_has_vorbis_comment) {
  90371. FLAC__StreamMetadata vorbis_comment;
  90372. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90373. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90374. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90375. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90376. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90377. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90378. vorbis_comment.data.vorbis_comment.comments = 0;
  90379. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90380. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90381. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90382. }
  90383. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90384. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90385. }
  90386. }
  90387. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90388. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90389. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90390. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90391. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90392. }
  90393. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90394. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90395. }
  90396. }
  90397. 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 */
  90398. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90399. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90400. }
  90401. if(encoder->protected_->verify)
  90402. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90403. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90404. }
  90405. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90406. FLAC__StreamEncoder *encoder,
  90407. FLAC__StreamEncoderWriteCallback write_callback,
  90408. FLAC__StreamEncoderSeekCallback seek_callback,
  90409. FLAC__StreamEncoderTellCallback tell_callback,
  90410. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90411. void *client_data
  90412. )
  90413. {
  90414. return init_stream_internal_enc(
  90415. encoder,
  90416. 0,
  90417. write_callback,
  90418. seek_callback,
  90419. tell_callback,
  90420. metadata_callback,
  90421. client_data,
  90422. false
  90423. );
  90424. }
  90425. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90426. FLAC__StreamEncoder *encoder,
  90427. FLAC__StreamEncoderReadCallback read_callback,
  90428. FLAC__StreamEncoderWriteCallback write_callback,
  90429. FLAC__StreamEncoderSeekCallback seek_callback,
  90430. FLAC__StreamEncoderTellCallback tell_callback,
  90431. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90432. void *client_data
  90433. )
  90434. {
  90435. return init_stream_internal_enc(
  90436. encoder,
  90437. read_callback,
  90438. write_callback,
  90439. seek_callback,
  90440. tell_callback,
  90441. metadata_callback,
  90442. client_data,
  90443. true
  90444. );
  90445. }
  90446. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90447. FLAC__StreamEncoder *encoder,
  90448. FILE *file,
  90449. FLAC__StreamEncoderProgressCallback progress_callback,
  90450. void *client_data,
  90451. FLAC__bool is_ogg
  90452. )
  90453. {
  90454. FLAC__StreamEncoderInitStatus init_status;
  90455. FLAC__ASSERT(0 != encoder);
  90456. FLAC__ASSERT(0 != file);
  90457. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90458. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90459. if(file == 0) {
  90460. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90461. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90462. }
  90463. if(file == stdout)
  90464. file = get_binary_stdout_(); /* just to be safe */
  90465. encoder->private_->file = file;
  90466. encoder->private_->progress_callback = progress_callback;
  90467. encoder->private_->bytes_written = 0;
  90468. encoder->private_->samples_written = 0;
  90469. encoder->private_->frames_written = 0;
  90470. init_status = init_stream_internal_enc(
  90471. encoder,
  90472. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90473. file_write_callback_,
  90474. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90475. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90476. 0,
  90477. client_data,
  90478. is_ogg
  90479. );
  90480. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90481. return init_status;
  90482. }
  90483. {
  90484. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90485. FLAC__ASSERT(blocksize != 0);
  90486. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90487. }
  90488. return init_status;
  90489. }
  90490. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90491. FLAC__StreamEncoder *encoder,
  90492. FILE *file,
  90493. FLAC__StreamEncoderProgressCallback progress_callback,
  90494. void *client_data
  90495. )
  90496. {
  90497. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90498. }
  90499. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90500. FLAC__StreamEncoder *encoder,
  90501. FILE *file,
  90502. FLAC__StreamEncoderProgressCallback progress_callback,
  90503. void *client_data
  90504. )
  90505. {
  90506. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90507. }
  90508. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90509. FLAC__StreamEncoder *encoder,
  90510. const char *filename,
  90511. FLAC__StreamEncoderProgressCallback progress_callback,
  90512. void *client_data,
  90513. FLAC__bool is_ogg
  90514. )
  90515. {
  90516. FILE *file;
  90517. FLAC__ASSERT(0 != encoder);
  90518. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90519. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90520. file = filename? fopen(filename, "w+b") : stdout;
  90521. if(file == 0) {
  90522. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90523. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90524. }
  90525. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90526. }
  90527. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90528. FLAC__StreamEncoder *encoder,
  90529. const char *filename,
  90530. FLAC__StreamEncoderProgressCallback progress_callback,
  90531. void *client_data
  90532. )
  90533. {
  90534. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90535. }
  90536. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90537. FLAC__StreamEncoder *encoder,
  90538. const char *filename,
  90539. FLAC__StreamEncoderProgressCallback progress_callback,
  90540. void *client_data
  90541. )
  90542. {
  90543. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90544. }
  90545. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90546. {
  90547. FLAC__bool error = false;
  90548. FLAC__ASSERT(0 != encoder);
  90549. FLAC__ASSERT(0 != encoder->private_);
  90550. FLAC__ASSERT(0 != encoder->protected_);
  90551. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90552. return true;
  90553. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90554. if(encoder->private_->current_sample_number != 0) {
  90555. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90556. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90557. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90558. error = true;
  90559. }
  90560. }
  90561. if(encoder->protected_->do_md5)
  90562. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90563. if(!encoder->private_->is_being_deleted) {
  90564. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90565. if(encoder->private_->seek_callback) {
  90566. #if FLAC__HAS_OGG
  90567. if(encoder->private_->is_ogg)
  90568. update_ogg_metadata_(encoder);
  90569. else
  90570. #endif
  90571. update_metadata_(encoder);
  90572. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90573. error = true;
  90574. }
  90575. if(encoder->private_->metadata_callback)
  90576. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90577. }
  90578. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90579. if(!error)
  90580. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90581. error = true;
  90582. }
  90583. }
  90584. if(0 != encoder->private_->file) {
  90585. if(encoder->private_->file != stdout)
  90586. fclose(encoder->private_->file);
  90587. encoder->private_->file = 0;
  90588. }
  90589. #if FLAC__HAS_OGG
  90590. if(encoder->private_->is_ogg)
  90591. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90592. #endif
  90593. free_(encoder);
  90594. set_defaults_enc(encoder);
  90595. if(!error)
  90596. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90597. return !error;
  90598. }
  90599. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90600. {
  90601. FLAC__ASSERT(0 != encoder);
  90602. FLAC__ASSERT(0 != encoder->private_);
  90603. FLAC__ASSERT(0 != encoder->protected_);
  90604. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90605. return false;
  90606. #if FLAC__HAS_OGG
  90607. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90608. return true;
  90609. #else
  90610. (void)value;
  90611. return false;
  90612. #endif
  90613. }
  90614. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90615. {
  90616. FLAC__ASSERT(0 != encoder);
  90617. FLAC__ASSERT(0 != encoder->private_);
  90618. FLAC__ASSERT(0 != encoder->protected_);
  90619. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90620. return false;
  90621. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90622. encoder->protected_->verify = value;
  90623. #endif
  90624. return true;
  90625. }
  90626. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90627. {
  90628. FLAC__ASSERT(0 != encoder);
  90629. FLAC__ASSERT(0 != encoder->private_);
  90630. FLAC__ASSERT(0 != encoder->protected_);
  90631. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90632. return false;
  90633. encoder->protected_->streamable_subset = value;
  90634. return true;
  90635. }
  90636. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90637. {
  90638. FLAC__ASSERT(0 != encoder);
  90639. FLAC__ASSERT(0 != encoder->private_);
  90640. FLAC__ASSERT(0 != encoder->protected_);
  90641. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90642. return false;
  90643. encoder->protected_->do_md5 = value;
  90644. return true;
  90645. }
  90646. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90647. {
  90648. FLAC__ASSERT(0 != encoder);
  90649. FLAC__ASSERT(0 != encoder->private_);
  90650. FLAC__ASSERT(0 != encoder->protected_);
  90651. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90652. return false;
  90653. encoder->protected_->channels = value;
  90654. return true;
  90655. }
  90656. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90657. {
  90658. FLAC__ASSERT(0 != encoder);
  90659. FLAC__ASSERT(0 != encoder->private_);
  90660. FLAC__ASSERT(0 != encoder->protected_);
  90661. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90662. return false;
  90663. encoder->protected_->bits_per_sample = value;
  90664. return true;
  90665. }
  90666. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90667. {
  90668. FLAC__ASSERT(0 != encoder);
  90669. FLAC__ASSERT(0 != encoder->private_);
  90670. FLAC__ASSERT(0 != encoder->protected_);
  90671. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90672. return false;
  90673. encoder->protected_->sample_rate = value;
  90674. return true;
  90675. }
  90676. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90677. {
  90678. FLAC__bool ok = true;
  90679. FLAC__ASSERT(0 != encoder);
  90680. FLAC__ASSERT(0 != encoder->private_);
  90681. FLAC__ASSERT(0 != encoder->protected_);
  90682. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90683. return false;
  90684. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90685. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90686. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90687. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90688. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90689. #if 0
  90690. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90691. #else
  90692. encoder->protected_->num_apodizations = 1;
  90693. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90694. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90695. #endif
  90696. #endif
  90697. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90698. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90699. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90700. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90701. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90702. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90703. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90704. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90705. return ok;
  90706. }
  90707. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90708. {
  90709. FLAC__ASSERT(0 != encoder);
  90710. FLAC__ASSERT(0 != encoder->private_);
  90711. FLAC__ASSERT(0 != encoder->protected_);
  90712. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90713. return false;
  90714. encoder->protected_->blocksize = value;
  90715. return true;
  90716. }
  90717. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90718. {
  90719. FLAC__ASSERT(0 != encoder);
  90720. FLAC__ASSERT(0 != encoder->private_);
  90721. FLAC__ASSERT(0 != encoder->protected_);
  90722. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90723. return false;
  90724. encoder->protected_->do_mid_side_stereo = value;
  90725. return true;
  90726. }
  90727. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90728. {
  90729. FLAC__ASSERT(0 != encoder);
  90730. FLAC__ASSERT(0 != encoder->private_);
  90731. FLAC__ASSERT(0 != encoder->protected_);
  90732. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90733. return false;
  90734. encoder->protected_->loose_mid_side_stereo = value;
  90735. return true;
  90736. }
  90737. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90738. {
  90739. FLAC__ASSERT(0 != encoder);
  90740. FLAC__ASSERT(0 != encoder->private_);
  90741. FLAC__ASSERT(0 != encoder->protected_);
  90742. FLAC__ASSERT(0 != specification);
  90743. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90744. return false;
  90745. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90746. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90747. #else
  90748. encoder->protected_->num_apodizations = 0;
  90749. while(1) {
  90750. const char *s = strchr(specification, ';');
  90751. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90752. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90753. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90754. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90755. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90756. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90757. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90758. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90759. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90760. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90761. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90762. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90763. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90764. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90765. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90766. if (stddev > 0.0 && stddev <= 0.5) {
  90767. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90768. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90769. }
  90770. }
  90771. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90772. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90773. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90774. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90775. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90776. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90777. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90778. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90779. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90780. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90781. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90782. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90783. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90784. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90785. if (p >= 0.0 && p <= 1.0) {
  90786. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90787. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90788. }
  90789. }
  90790. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90791. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90792. if (encoder->protected_->num_apodizations == 32)
  90793. break;
  90794. if (s)
  90795. specification = s+1;
  90796. else
  90797. break;
  90798. }
  90799. if(encoder->protected_->num_apodizations == 0) {
  90800. encoder->protected_->num_apodizations = 1;
  90801. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90802. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90803. }
  90804. #endif
  90805. return true;
  90806. }
  90807. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90808. {
  90809. FLAC__ASSERT(0 != encoder);
  90810. FLAC__ASSERT(0 != encoder->private_);
  90811. FLAC__ASSERT(0 != encoder->protected_);
  90812. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90813. return false;
  90814. encoder->protected_->max_lpc_order = value;
  90815. return true;
  90816. }
  90817. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90818. {
  90819. FLAC__ASSERT(0 != encoder);
  90820. FLAC__ASSERT(0 != encoder->private_);
  90821. FLAC__ASSERT(0 != encoder->protected_);
  90822. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90823. return false;
  90824. encoder->protected_->qlp_coeff_precision = value;
  90825. return true;
  90826. }
  90827. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90828. {
  90829. FLAC__ASSERT(0 != encoder);
  90830. FLAC__ASSERT(0 != encoder->private_);
  90831. FLAC__ASSERT(0 != encoder->protected_);
  90832. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90833. return false;
  90834. encoder->protected_->do_qlp_coeff_prec_search = value;
  90835. return true;
  90836. }
  90837. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90838. {
  90839. FLAC__ASSERT(0 != encoder);
  90840. FLAC__ASSERT(0 != encoder->private_);
  90841. FLAC__ASSERT(0 != encoder->protected_);
  90842. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90843. return false;
  90844. #if 0
  90845. encoder->protected_->do_escape_coding = value;
  90846. #else
  90847. (void)value;
  90848. #endif
  90849. return true;
  90850. }
  90851. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90852. {
  90853. FLAC__ASSERT(0 != encoder);
  90854. FLAC__ASSERT(0 != encoder->private_);
  90855. FLAC__ASSERT(0 != encoder->protected_);
  90856. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90857. return false;
  90858. encoder->protected_->do_exhaustive_model_search = value;
  90859. return true;
  90860. }
  90861. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90862. {
  90863. FLAC__ASSERT(0 != encoder);
  90864. FLAC__ASSERT(0 != encoder->private_);
  90865. FLAC__ASSERT(0 != encoder->protected_);
  90866. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90867. return false;
  90868. encoder->protected_->min_residual_partition_order = value;
  90869. return true;
  90870. }
  90871. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90872. {
  90873. FLAC__ASSERT(0 != encoder);
  90874. FLAC__ASSERT(0 != encoder->private_);
  90875. FLAC__ASSERT(0 != encoder->protected_);
  90876. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90877. return false;
  90878. encoder->protected_->max_residual_partition_order = value;
  90879. return true;
  90880. }
  90881. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90882. {
  90883. FLAC__ASSERT(0 != encoder);
  90884. FLAC__ASSERT(0 != encoder->private_);
  90885. FLAC__ASSERT(0 != encoder->protected_);
  90886. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90887. return false;
  90888. #if 0
  90889. encoder->protected_->rice_parameter_search_dist = value;
  90890. #else
  90891. (void)value;
  90892. #endif
  90893. return true;
  90894. }
  90895. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  90896. {
  90897. FLAC__ASSERT(0 != encoder);
  90898. FLAC__ASSERT(0 != encoder->private_);
  90899. FLAC__ASSERT(0 != encoder->protected_);
  90900. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90901. return false;
  90902. encoder->protected_->total_samples_estimate = value;
  90903. return true;
  90904. }
  90905. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  90906. {
  90907. FLAC__ASSERT(0 != encoder);
  90908. FLAC__ASSERT(0 != encoder->private_);
  90909. FLAC__ASSERT(0 != encoder->protected_);
  90910. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90911. return false;
  90912. if(0 == metadata)
  90913. num_blocks = 0;
  90914. if(0 == num_blocks)
  90915. metadata = 0;
  90916. if(encoder->protected_->metadata) {
  90917. free(encoder->protected_->metadata);
  90918. encoder->protected_->metadata = 0;
  90919. encoder->protected_->num_metadata_blocks = 0;
  90920. }
  90921. if(num_blocks) {
  90922. FLAC__StreamMetadata **m;
  90923. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90924. return false;
  90925. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90926. encoder->protected_->metadata = m;
  90927. encoder->protected_->num_metadata_blocks = num_blocks;
  90928. }
  90929. #if FLAC__HAS_OGG
  90930. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  90931. return false;
  90932. #endif
  90933. return true;
  90934. }
  90935. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90936. {
  90937. FLAC__ASSERT(0 != encoder);
  90938. FLAC__ASSERT(0 != encoder->private_);
  90939. FLAC__ASSERT(0 != encoder->protected_);
  90940. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90941. return false;
  90942. encoder->private_->disable_constant_subframes = value;
  90943. return true;
  90944. }
  90945. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90946. {
  90947. FLAC__ASSERT(0 != encoder);
  90948. FLAC__ASSERT(0 != encoder->private_);
  90949. FLAC__ASSERT(0 != encoder->protected_);
  90950. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90951. return false;
  90952. encoder->private_->disable_fixed_subframes = value;
  90953. return true;
  90954. }
  90955. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90956. {
  90957. FLAC__ASSERT(0 != encoder);
  90958. FLAC__ASSERT(0 != encoder->private_);
  90959. FLAC__ASSERT(0 != encoder->protected_);
  90960. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90961. return false;
  90962. encoder->private_->disable_verbatim_subframes = value;
  90963. return true;
  90964. }
  90965. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  90966. {
  90967. FLAC__ASSERT(0 != encoder);
  90968. FLAC__ASSERT(0 != encoder->private_);
  90969. FLAC__ASSERT(0 != encoder->protected_);
  90970. return encoder->protected_->state;
  90971. }
  90972. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  90973. {
  90974. FLAC__ASSERT(0 != encoder);
  90975. FLAC__ASSERT(0 != encoder->private_);
  90976. FLAC__ASSERT(0 != encoder->protected_);
  90977. if(encoder->protected_->verify)
  90978. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  90979. else
  90980. return FLAC__STREAM_DECODER_UNINITIALIZED;
  90981. }
  90982. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  90983. {
  90984. FLAC__ASSERT(0 != encoder);
  90985. FLAC__ASSERT(0 != encoder->private_);
  90986. FLAC__ASSERT(0 != encoder->protected_);
  90987. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  90988. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  90989. else
  90990. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  90991. }
  90992. 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)
  90993. {
  90994. FLAC__ASSERT(0 != encoder);
  90995. FLAC__ASSERT(0 != encoder->private_);
  90996. FLAC__ASSERT(0 != encoder->protected_);
  90997. if(0 != absolute_sample)
  90998. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  90999. if(0 != frame_number)
  91000. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91001. if(0 != channel)
  91002. *channel = encoder->private_->verify.error_stats.channel;
  91003. if(0 != sample)
  91004. *sample = encoder->private_->verify.error_stats.sample;
  91005. if(0 != expected)
  91006. *expected = encoder->private_->verify.error_stats.expected;
  91007. if(0 != got)
  91008. *got = encoder->private_->verify.error_stats.got;
  91009. }
  91010. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91011. {
  91012. FLAC__ASSERT(0 != encoder);
  91013. FLAC__ASSERT(0 != encoder->private_);
  91014. FLAC__ASSERT(0 != encoder->protected_);
  91015. return encoder->protected_->verify;
  91016. }
  91017. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91018. {
  91019. FLAC__ASSERT(0 != encoder);
  91020. FLAC__ASSERT(0 != encoder->private_);
  91021. FLAC__ASSERT(0 != encoder->protected_);
  91022. return encoder->protected_->streamable_subset;
  91023. }
  91024. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91025. {
  91026. FLAC__ASSERT(0 != encoder);
  91027. FLAC__ASSERT(0 != encoder->private_);
  91028. FLAC__ASSERT(0 != encoder->protected_);
  91029. return encoder->protected_->do_md5;
  91030. }
  91031. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91032. {
  91033. FLAC__ASSERT(0 != encoder);
  91034. FLAC__ASSERT(0 != encoder->private_);
  91035. FLAC__ASSERT(0 != encoder->protected_);
  91036. return encoder->protected_->channels;
  91037. }
  91038. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91039. {
  91040. FLAC__ASSERT(0 != encoder);
  91041. FLAC__ASSERT(0 != encoder->private_);
  91042. FLAC__ASSERT(0 != encoder->protected_);
  91043. return encoder->protected_->bits_per_sample;
  91044. }
  91045. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91046. {
  91047. FLAC__ASSERT(0 != encoder);
  91048. FLAC__ASSERT(0 != encoder->private_);
  91049. FLAC__ASSERT(0 != encoder->protected_);
  91050. return encoder->protected_->sample_rate;
  91051. }
  91052. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91053. {
  91054. FLAC__ASSERT(0 != encoder);
  91055. FLAC__ASSERT(0 != encoder->private_);
  91056. FLAC__ASSERT(0 != encoder->protected_);
  91057. return encoder->protected_->blocksize;
  91058. }
  91059. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91060. {
  91061. FLAC__ASSERT(0 != encoder);
  91062. FLAC__ASSERT(0 != encoder->private_);
  91063. FLAC__ASSERT(0 != encoder->protected_);
  91064. return encoder->protected_->do_mid_side_stereo;
  91065. }
  91066. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91067. {
  91068. FLAC__ASSERT(0 != encoder);
  91069. FLAC__ASSERT(0 != encoder->private_);
  91070. FLAC__ASSERT(0 != encoder->protected_);
  91071. return encoder->protected_->loose_mid_side_stereo;
  91072. }
  91073. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91074. {
  91075. FLAC__ASSERT(0 != encoder);
  91076. FLAC__ASSERT(0 != encoder->private_);
  91077. FLAC__ASSERT(0 != encoder->protected_);
  91078. return encoder->protected_->max_lpc_order;
  91079. }
  91080. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91081. {
  91082. FLAC__ASSERT(0 != encoder);
  91083. FLAC__ASSERT(0 != encoder->private_);
  91084. FLAC__ASSERT(0 != encoder->protected_);
  91085. return encoder->protected_->qlp_coeff_precision;
  91086. }
  91087. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91088. {
  91089. FLAC__ASSERT(0 != encoder);
  91090. FLAC__ASSERT(0 != encoder->private_);
  91091. FLAC__ASSERT(0 != encoder->protected_);
  91092. return encoder->protected_->do_qlp_coeff_prec_search;
  91093. }
  91094. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91095. {
  91096. FLAC__ASSERT(0 != encoder);
  91097. FLAC__ASSERT(0 != encoder->private_);
  91098. FLAC__ASSERT(0 != encoder->protected_);
  91099. return encoder->protected_->do_escape_coding;
  91100. }
  91101. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91102. {
  91103. FLAC__ASSERT(0 != encoder);
  91104. FLAC__ASSERT(0 != encoder->private_);
  91105. FLAC__ASSERT(0 != encoder->protected_);
  91106. return encoder->protected_->do_exhaustive_model_search;
  91107. }
  91108. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91109. {
  91110. FLAC__ASSERT(0 != encoder);
  91111. FLAC__ASSERT(0 != encoder->private_);
  91112. FLAC__ASSERT(0 != encoder->protected_);
  91113. return encoder->protected_->min_residual_partition_order;
  91114. }
  91115. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91116. {
  91117. FLAC__ASSERT(0 != encoder);
  91118. FLAC__ASSERT(0 != encoder->private_);
  91119. FLAC__ASSERT(0 != encoder->protected_);
  91120. return encoder->protected_->max_residual_partition_order;
  91121. }
  91122. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91123. {
  91124. FLAC__ASSERT(0 != encoder);
  91125. FLAC__ASSERT(0 != encoder->private_);
  91126. FLAC__ASSERT(0 != encoder->protected_);
  91127. return encoder->protected_->rice_parameter_search_dist;
  91128. }
  91129. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91130. {
  91131. FLAC__ASSERT(0 != encoder);
  91132. FLAC__ASSERT(0 != encoder->private_);
  91133. FLAC__ASSERT(0 != encoder->protected_);
  91134. return encoder->protected_->total_samples_estimate;
  91135. }
  91136. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91137. {
  91138. unsigned i, j = 0, channel;
  91139. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91140. FLAC__ASSERT(0 != encoder);
  91141. FLAC__ASSERT(0 != encoder->private_);
  91142. FLAC__ASSERT(0 != encoder->protected_);
  91143. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91144. do {
  91145. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91146. if(encoder->protected_->verify)
  91147. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91148. for(channel = 0; channel < channels; channel++)
  91149. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91150. if(encoder->protected_->do_mid_side_stereo) {
  91151. FLAC__ASSERT(channels == 2);
  91152. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91153. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91154. 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' ! */
  91155. }
  91156. }
  91157. else
  91158. j += n;
  91159. encoder->private_->current_sample_number += n;
  91160. if(encoder->private_->current_sample_number > blocksize) {
  91161. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91162. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91163. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91164. return false;
  91165. for(channel = 0; channel < channels; channel++)
  91166. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91167. if(encoder->protected_->do_mid_side_stereo) {
  91168. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91169. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91170. }
  91171. encoder->private_->current_sample_number = 1;
  91172. }
  91173. } while(j < samples);
  91174. return true;
  91175. }
  91176. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91177. {
  91178. unsigned i, j, k, channel;
  91179. FLAC__int32 x, mid, side;
  91180. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91181. FLAC__ASSERT(0 != encoder);
  91182. FLAC__ASSERT(0 != encoder->private_);
  91183. FLAC__ASSERT(0 != encoder->protected_);
  91184. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91185. j = k = 0;
  91186. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91187. do {
  91188. if(encoder->protected_->verify)
  91189. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91190. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91191. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91192. x = buffer[k++];
  91193. encoder->private_->integer_signal[1][i] = x;
  91194. mid += x;
  91195. side -= x;
  91196. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91197. encoder->private_->integer_signal_mid_side[1][i] = side;
  91198. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91199. }
  91200. encoder->private_->current_sample_number = i;
  91201. if(i > blocksize) {
  91202. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91203. return false;
  91204. /* move unprocessed overread samples to beginnings of arrays */
  91205. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91206. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91207. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91208. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91209. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91210. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91211. encoder->private_->current_sample_number = 1;
  91212. }
  91213. } while(j < samples);
  91214. }
  91215. else {
  91216. do {
  91217. if(encoder->protected_->verify)
  91218. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91219. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91220. for(channel = 0; channel < channels; channel++)
  91221. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91222. }
  91223. encoder->private_->current_sample_number = i;
  91224. if(i > blocksize) {
  91225. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91226. return false;
  91227. /* move unprocessed overread samples to beginnings of arrays */
  91228. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91229. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91230. for(channel = 0; channel < channels; channel++)
  91231. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91232. encoder->private_->current_sample_number = 1;
  91233. }
  91234. } while(j < samples);
  91235. }
  91236. return true;
  91237. }
  91238. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91239. {
  91240. FLAC__ASSERT(0 != encoder);
  91241. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91242. encoder->protected_->verify = true;
  91243. #else
  91244. encoder->protected_->verify = false;
  91245. #endif
  91246. encoder->protected_->streamable_subset = true;
  91247. encoder->protected_->do_md5 = true;
  91248. encoder->protected_->do_mid_side_stereo = false;
  91249. encoder->protected_->loose_mid_side_stereo = false;
  91250. encoder->protected_->channels = 2;
  91251. encoder->protected_->bits_per_sample = 16;
  91252. encoder->protected_->sample_rate = 44100;
  91253. encoder->protected_->blocksize = 0;
  91254. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91255. encoder->protected_->num_apodizations = 1;
  91256. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91257. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91258. #endif
  91259. encoder->protected_->max_lpc_order = 0;
  91260. encoder->protected_->qlp_coeff_precision = 0;
  91261. encoder->protected_->do_qlp_coeff_prec_search = false;
  91262. encoder->protected_->do_exhaustive_model_search = false;
  91263. encoder->protected_->do_escape_coding = false;
  91264. encoder->protected_->min_residual_partition_order = 0;
  91265. encoder->protected_->max_residual_partition_order = 0;
  91266. encoder->protected_->rice_parameter_search_dist = 0;
  91267. encoder->protected_->total_samples_estimate = 0;
  91268. encoder->protected_->metadata = 0;
  91269. encoder->protected_->num_metadata_blocks = 0;
  91270. encoder->private_->seek_table = 0;
  91271. encoder->private_->disable_constant_subframes = false;
  91272. encoder->private_->disable_fixed_subframes = false;
  91273. encoder->private_->disable_verbatim_subframes = false;
  91274. #if FLAC__HAS_OGG
  91275. encoder->private_->is_ogg = false;
  91276. #endif
  91277. encoder->private_->read_callback = 0;
  91278. encoder->private_->write_callback = 0;
  91279. encoder->private_->seek_callback = 0;
  91280. encoder->private_->tell_callback = 0;
  91281. encoder->private_->metadata_callback = 0;
  91282. encoder->private_->progress_callback = 0;
  91283. encoder->private_->client_data = 0;
  91284. #if FLAC__HAS_OGG
  91285. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91286. #endif
  91287. }
  91288. void free_(FLAC__StreamEncoder *encoder)
  91289. {
  91290. unsigned i, channel;
  91291. FLAC__ASSERT(0 != encoder);
  91292. if(encoder->protected_->metadata) {
  91293. free(encoder->protected_->metadata);
  91294. encoder->protected_->metadata = 0;
  91295. encoder->protected_->num_metadata_blocks = 0;
  91296. }
  91297. for(i = 0; i < encoder->protected_->channels; i++) {
  91298. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91299. free(encoder->private_->integer_signal_unaligned[i]);
  91300. encoder->private_->integer_signal_unaligned[i] = 0;
  91301. }
  91302. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91303. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91304. free(encoder->private_->real_signal_unaligned[i]);
  91305. encoder->private_->real_signal_unaligned[i] = 0;
  91306. }
  91307. #endif
  91308. }
  91309. for(i = 0; i < 2; i++) {
  91310. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91311. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91312. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91313. }
  91314. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91315. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91316. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91317. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91318. }
  91319. #endif
  91320. }
  91321. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91322. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91323. if(0 != encoder->private_->window_unaligned[i]) {
  91324. free(encoder->private_->window_unaligned[i]);
  91325. encoder->private_->window_unaligned[i] = 0;
  91326. }
  91327. }
  91328. if(0 != encoder->private_->windowed_signal_unaligned) {
  91329. free(encoder->private_->windowed_signal_unaligned);
  91330. encoder->private_->windowed_signal_unaligned = 0;
  91331. }
  91332. #endif
  91333. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91334. for(i = 0; i < 2; i++) {
  91335. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91336. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91337. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91338. }
  91339. }
  91340. }
  91341. for(channel = 0; channel < 2; channel++) {
  91342. for(i = 0; i < 2; i++) {
  91343. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91344. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91345. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91346. }
  91347. }
  91348. }
  91349. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91350. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91351. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91352. }
  91353. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91354. free(encoder->private_->raw_bits_per_partition_unaligned);
  91355. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91356. }
  91357. if(encoder->protected_->verify) {
  91358. for(i = 0; i < encoder->protected_->channels; i++) {
  91359. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91360. free(encoder->private_->verify.input_fifo.data[i]);
  91361. encoder->private_->verify.input_fifo.data[i] = 0;
  91362. }
  91363. }
  91364. }
  91365. FLAC__bitwriter_free(encoder->private_->frame);
  91366. }
  91367. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91368. {
  91369. FLAC__bool ok;
  91370. unsigned i, channel;
  91371. FLAC__ASSERT(new_blocksize > 0);
  91372. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91373. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91374. if(new_blocksize <= encoder->private_->input_capacity)
  91375. return true;
  91376. ok = true;
  91377. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91378. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91379. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91380. encoder->private_->integer_signal[i] += 4;
  91381. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91382. #if 0 /* @@@ currently unused */
  91383. if(encoder->protected_->max_lpc_order > 0)
  91384. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91385. #endif
  91386. #endif
  91387. }
  91388. for(i = 0; ok && i < 2; i++) {
  91389. 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]);
  91390. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91391. encoder->private_->integer_signal_mid_side[i] += 4;
  91392. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91393. #if 0 /* @@@ currently unused */
  91394. if(encoder->protected_->max_lpc_order > 0)
  91395. 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]);
  91396. #endif
  91397. #endif
  91398. }
  91399. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91400. if(ok && encoder->protected_->max_lpc_order > 0) {
  91401. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91402. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91403. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91404. }
  91405. #endif
  91406. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91407. for(i = 0; ok && i < 2; i++) {
  91408. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91409. }
  91410. }
  91411. for(channel = 0; ok && channel < 2; channel++) {
  91412. for(i = 0; ok && i < 2; i++) {
  91413. 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]);
  91414. }
  91415. }
  91416. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91417. if(encoder->protected_->do_escape_coding)
  91418. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91419. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91420. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91421. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91422. switch(encoder->protected_->apodizations[i].type) {
  91423. case FLAC__APODIZATION_BARTLETT:
  91424. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91425. break;
  91426. case FLAC__APODIZATION_BARTLETT_HANN:
  91427. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91428. break;
  91429. case FLAC__APODIZATION_BLACKMAN:
  91430. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91431. break;
  91432. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91433. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91434. break;
  91435. case FLAC__APODIZATION_CONNES:
  91436. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91437. break;
  91438. case FLAC__APODIZATION_FLATTOP:
  91439. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91440. break;
  91441. case FLAC__APODIZATION_GAUSS:
  91442. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91443. break;
  91444. case FLAC__APODIZATION_HAMMING:
  91445. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91446. break;
  91447. case FLAC__APODIZATION_HANN:
  91448. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91449. break;
  91450. case FLAC__APODIZATION_KAISER_BESSEL:
  91451. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91452. break;
  91453. case FLAC__APODIZATION_NUTTALL:
  91454. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91455. break;
  91456. case FLAC__APODIZATION_RECTANGLE:
  91457. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91458. break;
  91459. case FLAC__APODIZATION_TRIANGLE:
  91460. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91461. break;
  91462. case FLAC__APODIZATION_TUKEY:
  91463. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91464. break;
  91465. case FLAC__APODIZATION_WELCH:
  91466. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91467. break;
  91468. default:
  91469. FLAC__ASSERT(0);
  91470. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91471. break;
  91472. }
  91473. }
  91474. }
  91475. #endif
  91476. if(ok)
  91477. encoder->private_->input_capacity = new_blocksize;
  91478. else
  91479. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91480. return ok;
  91481. }
  91482. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91483. {
  91484. const FLAC__byte *buffer;
  91485. size_t bytes;
  91486. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91487. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91488. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91489. return false;
  91490. }
  91491. if(encoder->protected_->verify) {
  91492. encoder->private_->verify.output.data = buffer;
  91493. encoder->private_->verify.output.bytes = bytes;
  91494. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91495. encoder->private_->verify.needs_magic_hack = true;
  91496. }
  91497. else {
  91498. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91499. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91500. FLAC__bitwriter_clear(encoder->private_->frame);
  91501. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91502. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91503. return false;
  91504. }
  91505. }
  91506. }
  91507. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91508. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91509. FLAC__bitwriter_clear(encoder->private_->frame);
  91510. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91511. return false;
  91512. }
  91513. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91514. FLAC__bitwriter_clear(encoder->private_->frame);
  91515. if(samples > 0) {
  91516. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91517. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91518. }
  91519. return true;
  91520. }
  91521. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91522. {
  91523. FLAC__StreamEncoderWriteStatus status;
  91524. FLAC__uint64 output_position = 0;
  91525. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91526. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91527. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91528. }
  91529. if(samples == 0) {
  91530. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91531. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91532. encoder->protected_->streaminfo_offset = output_position;
  91533. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91534. encoder->protected_->seektable_offset = output_position;
  91535. }
  91536. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91537. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91538. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91539. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91540. FLAC__uint64 test_sample;
  91541. unsigned i;
  91542. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91543. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91544. if(test_sample > frame_last_sample) {
  91545. break;
  91546. }
  91547. else if(test_sample >= frame_first_sample) {
  91548. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91549. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91550. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91551. encoder->private_->first_seekpoint_to_check++;
  91552. }
  91553. else {
  91554. encoder->private_->first_seekpoint_to_check++;
  91555. }
  91556. }
  91557. }
  91558. #if FLAC__HAS_OGG
  91559. if(encoder->private_->is_ogg) {
  91560. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91561. &encoder->protected_->ogg_encoder_aspect,
  91562. buffer,
  91563. bytes,
  91564. samples,
  91565. encoder->private_->current_frame_number,
  91566. is_last_block,
  91567. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91568. encoder,
  91569. encoder->private_->client_data
  91570. );
  91571. }
  91572. else
  91573. #endif
  91574. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91575. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91576. encoder->private_->bytes_written += bytes;
  91577. encoder->private_->samples_written += samples;
  91578. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91579. }
  91580. else
  91581. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91582. return status;
  91583. }
  91584. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91585. {
  91586. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91587. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91588. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91589. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91590. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91591. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91592. FLAC__StreamEncoderSeekStatus seek_status;
  91593. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91594. {
  91595. const unsigned md5_offset =
  91596. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91597. (
  91598. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91599. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91600. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91601. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91602. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91603. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91604. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91605. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91606. ) / 8;
  91607. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91608. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91609. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91610. return;
  91611. }
  91612. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91613. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91614. return;
  91615. }
  91616. }
  91617. {
  91618. const unsigned total_samples_byte_offset =
  91619. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91620. (
  91621. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91622. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91623. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91624. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91625. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91626. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91627. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91628. - 4
  91629. ) / 8;
  91630. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91631. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91632. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91633. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91634. b[4] = (FLAC__byte)(samples & 0xFF);
  91635. 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) {
  91636. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91637. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91638. return;
  91639. }
  91640. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91641. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91642. return;
  91643. }
  91644. }
  91645. {
  91646. const unsigned min_framesize_offset =
  91647. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91648. (
  91649. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91650. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91651. ) / 8;
  91652. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91653. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91654. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91655. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91656. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91657. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91658. 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) {
  91659. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91660. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91661. return;
  91662. }
  91663. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91664. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91665. return;
  91666. }
  91667. }
  91668. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91669. unsigned i;
  91670. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91671. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91672. 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) {
  91673. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91674. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91675. return;
  91676. }
  91677. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91678. FLAC__uint64 xx;
  91679. unsigned x;
  91680. xx = encoder->private_->seek_table->points[i].sample_number;
  91681. b[7] = (FLAC__byte)xx; xx >>= 8;
  91682. b[6] = (FLAC__byte)xx; xx >>= 8;
  91683. b[5] = (FLAC__byte)xx; xx >>= 8;
  91684. b[4] = (FLAC__byte)xx; xx >>= 8;
  91685. b[3] = (FLAC__byte)xx; xx >>= 8;
  91686. b[2] = (FLAC__byte)xx; xx >>= 8;
  91687. b[1] = (FLAC__byte)xx; xx >>= 8;
  91688. b[0] = (FLAC__byte)xx; xx >>= 8;
  91689. xx = encoder->private_->seek_table->points[i].stream_offset;
  91690. b[15] = (FLAC__byte)xx; xx >>= 8;
  91691. b[14] = (FLAC__byte)xx; xx >>= 8;
  91692. b[13] = (FLAC__byte)xx; xx >>= 8;
  91693. b[12] = (FLAC__byte)xx; xx >>= 8;
  91694. b[11] = (FLAC__byte)xx; xx >>= 8;
  91695. b[10] = (FLAC__byte)xx; xx >>= 8;
  91696. b[9] = (FLAC__byte)xx; xx >>= 8;
  91697. b[8] = (FLAC__byte)xx; xx >>= 8;
  91698. x = encoder->private_->seek_table->points[i].frame_samples;
  91699. b[17] = (FLAC__byte)x; x >>= 8;
  91700. b[16] = (FLAC__byte)x; x >>= 8;
  91701. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91702. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91703. return;
  91704. }
  91705. }
  91706. }
  91707. }
  91708. #if FLAC__HAS_OGG
  91709. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91710. {
  91711. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91712. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91713. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91714. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91715. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91716. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91717. FLAC__STREAM_SYNC_LENGTH
  91718. ;
  91719. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91720. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91721. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91722. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91723. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91724. ogg_page page;
  91725. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91726. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91727. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91728. return;
  91729. simple_ogg_page__init(&page);
  91730. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91731. simple_ogg_page__clear(&page);
  91732. return; /* state already set */
  91733. }
  91734. {
  91735. const unsigned md5_offset =
  91736. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91737. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91738. (
  91739. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91740. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91741. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91742. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91743. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91744. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91745. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91746. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91747. ) / 8;
  91748. if(md5_offset + 16 > (unsigned)page.body_len) {
  91749. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91750. simple_ogg_page__clear(&page);
  91751. return;
  91752. }
  91753. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91754. }
  91755. {
  91756. const unsigned total_samples_byte_offset =
  91757. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91758. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91759. (
  91760. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91761. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91762. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91763. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91764. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91765. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91766. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91767. - 4
  91768. ) / 8;
  91769. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91770. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91771. simple_ogg_page__clear(&page);
  91772. return;
  91773. }
  91774. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91775. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91776. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91777. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91778. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91779. b[4] = (FLAC__byte)(samples & 0xFF);
  91780. memcpy(page.body + total_samples_byte_offset, b, 5);
  91781. }
  91782. {
  91783. const unsigned min_framesize_offset =
  91784. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91785. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91786. (
  91787. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91788. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91789. ) / 8;
  91790. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91791. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91792. simple_ogg_page__clear(&page);
  91793. return;
  91794. }
  91795. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91796. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91797. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91798. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91799. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91800. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91801. memcpy(page.body + min_framesize_offset, b, 6);
  91802. }
  91803. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91804. simple_ogg_page__clear(&page);
  91805. return; /* state already set */
  91806. }
  91807. simple_ogg_page__clear(&page);
  91808. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91809. unsigned i;
  91810. FLAC__byte *p;
  91811. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91812. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91813. simple_ogg_page__init(&page);
  91814. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91815. simple_ogg_page__clear(&page);
  91816. return; /* state already set */
  91817. }
  91818. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91819. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91820. simple_ogg_page__clear(&page);
  91821. return;
  91822. }
  91823. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91824. FLAC__uint64 xx;
  91825. unsigned x;
  91826. xx = encoder->private_->seek_table->points[i].sample_number;
  91827. b[7] = (FLAC__byte)xx; xx >>= 8;
  91828. b[6] = (FLAC__byte)xx; xx >>= 8;
  91829. b[5] = (FLAC__byte)xx; xx >>= 8;
  91830. b[4] = (FLAC__byte)xx; xx >>= 8;
  91831. b[3] = (FLAC__byte)xx; xx >>= 8;
  91832. b[2] = (FLAC__byte)xx; xx >>= 8;
  91833. b[1] = (FLAC__byte)xx; xx >>= 8;
  91834. b[0] = (FLAC__byte)xx; xx >>= 8;
  91835. xx = encoder->private_->seek_table->points[i].stream_offset;
  91836. b[15] = (FLAC__byte)xx; xx >>= 8;
  91837. b[14] = (FLAC__byte)xx; xx >>= 8;
  91838. b[13] = (FLAC__byte)xx; xx >>= 8;
  91839. b[12] = (FLAC__byte)xx; xx >>= 8;
  91840. b[11] = (FLAC__byte)xx; xx >>= 8;
  91841. b[10] = (FLAC__byte)xx; xx >>= 8;
  91842. b[9] = (FLAC__byte)xx; xx >>= 8;
  91843. b[8] = (FLAC__byte)xx; xx >>= 8;
  91844. x = encoder->private_->seek_table->points[i].frame_samples;
  91845. b[17] = (FLAC__byte)x; x >>= 8;
  91846. b[16] = (FLAC__byte)x; x >>= 8;
  91847. memcpy(p, b, 18);
  91848. }
  91849. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91850. simple_ogg_page__clear(&page);
  91851. return; /* state already set */
  91852. }
  91853. simple_ogg_page__clear(&page);
  91854. }
  91855. }
  91856. #endif
  91857. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91858. {
  91859. FLAC__uint16 crc;
  91860. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91861. 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)) {
  91862. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91863. return false;
  91864. }
  91865. if(!process_subframes_(encoder, is_fractional_block)) {
  91866. return false;
  91867. }
  91868. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91869. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91870. return false;
  91871. }
  91872. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91873. if(
  91874. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91875. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91876. ) {
  91877. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91878. return false;
  91879. }
  91880. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91881. return false;
  91882. }
  91883. encoder->private_->current_sample_number = 0;
  91884. encoder->private_->current_frame_number++;
  91885. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91886. return true;
  91887. }
  91888. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91889. {
  91890. FLAC__FrameHeader frame_header;
  91891. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91892. FLAC__bool do_independent, do_mid_side;
  91893. if(is_fractional_block) {
  91894. max_partition_order = 0;
  91895. }
  91896. else {
  91897. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91898. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91899. }
  91900. min_partition_order = min(min_partition_order, max_partition_order);
  91901. frame_header.blocksize = encoder->protected_->blocksize;
  91902. frame_header.sample_rate = encoder->protected_->sample_rate;
  91903. frame_header.channels = encoder->protected_->channels;
  91904. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91905. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91906. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91907. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91908. if(encoder->protected_->do_mid_side_stereo) {
  91909. if(encoder->protected_->loose_mid_side_stereo) {
  91910. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91911. do_independent = true;
  91912. do_mid_side = true;
  91913. }
  91914. else {
  91915. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91916. do_mid_side = !do_independent;
  91917. }
  91918. }
  91919. else {
  91920. do_independent = true;
  91921. do_mid_side = true;
  91922. }
  91923. }
  91924. else {
  91925. do_independent = true;
  91926. do_mid_side = false;
  91927. }
  91928. FLAC__ASSERT(do_independent || do_mid_side);
  91929. if(do_independent) {
  91930. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91931. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  91932. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  91933. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  91934. }
  91935. }
  91936. if(do_mid_side) {
  91937. FLAC__ASSERT(encoder->protected_->channels == 2);
  91938. for(channel = 0; channel < 2; channel++) {
  91939. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  91940. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  91941. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  91942. }
  91943. }
  91944. if(do_independent) {
  91945. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91946. if(!
  91947. process_subframe_(
  91948. encoder,
  91949. min_partition_order,
  91950. max_partition_order,
  91951. &frame_header,
  91952. encoder->private_->subframe_bps[channel],
  91953. encoder->private_->integer_signal[channel],
  91954. encoder->private_->subframe_workspace_ptr[channel],
  91955. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  91956. encoder->private_->residual_workspace[channel],
  91957. encoder->private_->best_subframe+channel,
  91958. encoder->private_->best_subframe_bits+channel
  91959. )
  91960. )
  91961. return false;
  91962. }
  91963. }
  91964. if(do_mid_side) {
  91965. FLAC__ASSERT(encoder->protected_->channels == 2);
  91966. for(channel = 0; channel < 2; channel++) {
  91967. if(!
  91968. process_subframe_(
  91969. encoder,
  91970. min_partition_order,
  91971. max_partition_order,
  91972. &frame_header,
  91973. encoder->private_->subframe_bps_mid_side[channel],
  91974. encoder->private_->integer_signal_mid_side[channel],
  91975. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  91976. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  91977. encoder->private_->residual_workspace_mid_side[channel],
  91978. encoder->private_->best_subframe_mid_side+channel,
  91979. encoder->private_->best_subframe_bits_mid_side+channel
  91980. )
  91981. )
  91982. return false;
  91983. }
  91984. }
  91985. if(do_mid_side) {
  91986. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  91987. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  91988. FLAC__ChannelAssignment channel_assignment;
  91989. FLAC__ASSERT(encoder->protected_->channels == 2);
  91990. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  91991. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  91992. }
  91993. else {
  91994. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  91995. unsigned min_bits;
  91996. int ca;
  91997. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  91998. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  91999. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92000. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92001. FLAC__ASSERT(do_independent && do_mid_side);
  92002. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92003. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92004. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92005. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92006. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92007. min_bits = bits[channel_assignment];
  92008. for(ca = 1; ca <= 3; ca++) {
  92009. if(bits[ca] < min_bits) {
  92010. min_bits = bits[ca];
  92011. channel_assignment = (FLAC__ChannelAssignment)ca;
  92012. }
  92013. }
  92014. }
  92015. frame_header.channel_assignment = channel_assignment;
  92016. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92017. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92018. return false;
  92019. }
  92020. switch(channel_assignment) {
  92021. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92022. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92023. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92024. break;
  92025. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92026. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92027. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92028. break;
  92029. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92030. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92031. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92032. break;
  92033. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92034. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92035. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92036. break;
  92037. default:
  92038. FLAC__ASSERT(0);
  92039. }
  92040. switch(channel_assignment) {
  92041. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92042. left_bps = encoder->private_->subframe_bps [0];
  92043. right_bps = encoder->private_->subframe_bps [1];
  92044. break;
  92045. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92046. left_bps = encoder->private_->subframe_bps [0];
  92047. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92048. break;
  92049. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92050. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92051. right_bps = encoder->private_->subframe_bps [1];
  92052. break;
  92053. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92054. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92055. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92056. break;
  92057. default:
  92058. FLAC__ASSERT(0);
  92059. }
  92060. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92061. return false;
  92062. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92063. return false;
  92064. }
  92065. else {
  92066. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92067. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92068. return false;
  92069. }
  92070. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92071. 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)) {
  92072. return false;
  92073. }
  92074. }
  92075. }
  92076. if(encoder->protected_->loose_mid_side_stereo) {
  92077. encoder->private_->loose_mid_side_stereo_frame_count++;
  92078. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92079. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92080. }
  92081. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92082. return true;
  92083. }
  92084. FLAC__bool process_subframe_(
  92085. FLAC__StreamEncoder *encoder,
  92086. unsigned min_partition_order,
  92087. unsigned max_partition_order,
  92088. const FLAC__FrameHeader *frame_header,
  92089. unsigned subframe_bps,
  92090. const FLAC__int32 integer_signal[],
  92091. FLAC__Subframe *subframe[2],
  92092. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92093. FLAC__int32 *residual[2],
  92094. unsigned *best_subframe,
  92095. unsigned *best_bits
  92096. )
  92097. {
  92098. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92099. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92100. #else
  92101. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92102. #endif
  92103. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92104. FLAC__double lpc_residual_bits_per_sample;
  92105. 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 */
  92106. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92107. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92108. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92109. #endif
  92110. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92111. unsigned rice_parameter;
  92112. unsigned _candidate_bits, _best_bits;
  92113. unsigned _best_subframe;
  92114. 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;
  92115. FLAC__ASSERT(frame_header->blocksize > 0);
  92116. _best_subframe = 0;
  92117. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92118. _best_bits = UINT_MAX;
  92119. else
  92120. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92121. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92122. unsigned signal_is_constant = false;
  92123. 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);
  92124. if(
  92125. !encoder->private_->disable_constant_subframes &&
  92126. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92127. fixed_residual_bits_per_sample[1] == 0.0
  92128. #else
  92129. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92130. #endif
  92131. ) {
  92132. unsigned i;
  92133. signal_is_constant = true;
  92134. for(i = 1; i < frame_header->blocksize; i++) {
  92135. if(integer_signal[0] != integer_signal[i]) {
  92136. signal_is_constant = false;
  92137. break;
  92138. }
  92139. }
  92140. }
  92141. if(signal_is_constant) {
  92142. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92143. if(_candidate_bits < _best_bits) {
  92144. _best_subframe = !_best_subframe;
  92145. _best_bits = _candidate_bits;
  92146. }
  92147. }
  92148. else {
  92149. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92150. if(encoder->protected_->do_exhaustive_model_search) {
  92151. min_fixed_order = 0;
  92152. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92153. }
  92154. else {
  92155. min_fixed_order = max_fixed_order = guess_fixed_order;
  92156. }
  92157. if(max_fixed_order >= frame_header->blocksize)
  92158. max_fixed_order = frame_header->blocksize - 1;
  92159. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92160. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92161. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92162. continue; /* don't even try */
  92163. 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 */
  92164. #else
  92165. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92166. continue; /* don't even try */
  92167. 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 */
  92168. #endif
  92169. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92170. if(rice_parameter >= rice_parameter_limit) {
  92171. #ifdef DEBUG_VERBOSE
  92172. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92173. #endif
  92174. rice_parameter = rice_parameter_limit - 1;
  92175. }
  92176. _candidate_bits =
  92177. evaluate_fixed_subframe_(
  92178. encoder,
  92179. integer_signal,
  92180. residual[!_best_subframe],
  92181. encoder->private_->abs_residual_partition_sums,
  92182. encoder->private_->raw_bits_per_partition,
  92183. frame_header->blocksize,
  92184. subframe_bps,
  92185. fixed_order,
  92186. rice_parameter,
  92187. rice_parameter_limit,
  92188. min_partition_order,
  92189. max_partition_order,
  92190. encoder->protected_->do_escape_coding,
  92191. encoder->protected_->rice_parameter_search_dist,
  92192. subframe[!_best_subframe],
  92193. partitioned_rice_contents[!_best_subframe]
  92194. );
  92195. if(_candidate_bits < _best_bits) {
  92196. _best_subframe = !_best_subframe;
  92197. _best_bits = _candidate_bits;
  92198. }
  92199. }
  92200. }
  92201. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92202. if(encoder->protected_->max_lpc_order > 0) {
  92203. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92204. max_lpc_order = frame_header->blocksize-1;
  92205. else
  92206. max_lpc_order = encoder->protected_->max_lpc_order;
  92207. if(max_lpc_order > 0) {
  92208. unsigned a;
  92209. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92210. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92211. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92212. if(autoc[0] != 0.0) {
  92213. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92214. if(encoder->protected_->do_exhaustive_model_search) {
  92215. min_lpc_order = 1;
  92216. }
  92217. else {
  92218. const unsigned guess_lpc_order =
  92219. FLAC__lpc_compute_best_order(
  92220. lpc_error,
  92221. max_lpc_order,
  92222. frame_header->blocksize,
  92223. subframe_bps + (
  92224. encoder->protected_->do_qlp_coeff_prec_search?
  92225. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92226. encoder->protected_->qlp_coeff_precision
  92227. )
  92228. );
  92229. min_lpc_order = max_lpc_order = guess_lpc_order;
  92230. }
  92231. if(max_lpc_order >= frame_header->blocksize)
  92232. max_lpc_order = frame_header->blocksize - 1;
  92233. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92234. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92235. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92236. continue; /* don't even try */
  92237. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  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) @1\n", rice_parameter, rice_parameter_limit - 1);
  92242. #endif
  92243. rice_parameter = rice_parameter_limit - 1;
  92244. }
  92245. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92246. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92247. if(subframe_bps <= 17) {
  92248. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92249. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92250. }
  92251. else
  92252. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92253. }
  92254. else {
  92255. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92256. }
  92257. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92258. _candidate_bits =
  92259. evaluate_lpc_subframe_(
  92260. encoder,
  92261. integer_signal,
  92262. residual[!_best_subframe],
  92263. encoder->private_->abs_residual_partition_sums,
  92264. encoder->private_->raw_bits_per_partition,
  92265. encoder->private_->lp_coeff[lpc_order-1],
  92266. frame_header->blocksize,
  92267. subframe_bps,
  92268. lpc_order,
  92269. qlp_coeff_precision,
  92270. rice_parameter,
  92271. rice_parameter_limit,
  92272. min_partition_order,
  92273. max_partition_order,
  92274. encoder->protected_->do_escape_coding,
  92275. encoder->protected_->rice_parameter_search_dist,
  92276. subframe[!_best_subframe],
  92277. partitioned_rice_contents[!_best_subframe]
  92278. );
  92279. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92280. if(_candidate_bits < _best_bits) {
  92281. _best_subframe = !_best_subframe;
  92282. _best_bits = _candidate_bits;
  92283. }
  92284. }
  92285. }
  92286. }
  92287. }
  92288. }
  92289. }
  92290. }
  92291. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92292. }
  92293. }
  92294. if(_best_bits == UINT_MAX) {
  92295. FLAC__ASSERT(_best_subframe == 0);
  92296. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92297. }
  92298. *best_subframe = _best_subframe;
  92299. *best_bits = _best_bits;
  92300. return true;
  92301. }
  92302. FLAC__bool add_subframe_(
  92303. FLAC__StreamEncoder *encoder,
  92304. unsigned blocksize,
  92305. unsigned subframe_bps,
  92306. const FLAC__Subframe *subframe,
  92307. FLAC__BitWriter *frame
  92308. )
  92309. {
  92310. switch(subframe->type) {
  92311. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92312. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92313. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92314. return false;
  92315. }
  92316. break;
  92317. case FLAC__SUBFRAME_TYPE_FIXED:
  92318. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92319. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92320. return false;
  92321. }
  92322. break;
  92323. case FLAC__SUBFRAME_TYPE_LPC:
  92324. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92325. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92326. return false;
  92327. }
  92328. break;
  92329. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92330. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92331. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92332. return false;
  92333. }
  92334. break;
  92335. default:
  92336. FLAC__ASSERT(0);
  92337. }
  92338. return true;
  92339. }
  92340. #define SPOTCHECK_ESTIMATE 0
  92341. #if SPOTCHECK_ESTIMATE
  92342. static void spotcheck_subframe_estimate_(
  92343. FLAC__StreamEncoder *encoder,
  92344. unsigned blocksize,
  92345. unsigned subframe_bps,
  92346. const FLAC__Subframe *subframe,
  92347. unsigned estimate
  92348. )
  92349. {
  92350. FLAC__bool ret;
  92351. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92352. if(frame == 0) {
  92353. fprintf(stderr, "EST: can't allocate frame\n");
  92354. return;
  92355. }
  92356. if(!FLAC__bitwriter_init(frame)) {
  92357. fprintf(stderr, "EST: can't init frame\n");
  92358. return;
  92359. }
  92360. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92361. FLAC__ASSERT(ret);
  92362. {
  92363. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92364. if(estimate != actual)
  92365. 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);
  92366. }
  92367. FLAC__bitwriter_delete(frame);
  92368. }
  92369. #endif
  92370. unsigned evaluate_constant_subframe_(
  92371. FLAC__StreamEncoder *encoder,
  92372. const FLAC__int32 signal,
  92373. unsigned blocksize,
  92374. unsigned subframe_bps,
  92375. FLAC__Subframe *subframe
  92376. )
  92377. {
  92378. unsigned estimate;
  92379. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92380. subframe->data.constant.value = signal;
  92381. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92382. #if SPOTCHECK_ESTIMATE
  92383. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92384. #else
  92385. (void)encoder, (void)blocksize;
  92386. #endif
  92387. return estimate;
  92388. }
  92389. unsigned evaluate_fixed_subframe_(
  92390. FLAC__StreamEncoder *encoder,
  92391. const FLAC__int32 signal[],
  92392. FLAC__int32 residual[],
  92393. FLAC__uint64 abs_residual_partition_sums[],
  92394. unsigned raw_bits_per_partition[],
  92395. unsigned blocksize,
  92396. unsigned subframe_bps,
  92397. unsigned order,
  92398. unsigned rice_parameter,
  92399. unsigned rice_parameter_limit,
  92400. unsigned min_partition_order,
  92401. unsigned max_partition_order,
  92402. FLAC__bool do_escape_coding,
  92403. unsigned rice_parameter_search_dist,
  92404. FLAC__Subframe *subframe,
  92405. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92406. )
  92407. {
  92408. unsigned i, residual_bits, estimate;
  92409. const unsigned residual_samples = blocksize - order;
  92410. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92411. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92412. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92413. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92414. subframe->data.fixed.residual = residual;
  92415. residual_bits =
  92416. find_best_partition_order_(
  92417. encoder->private_,
  92418. residual,
  92419. abs_residual_partition_sums,
  92420. raw_bits_per_partition,
  92421. residual_samples,
  92422. order,
  92423. rice_parameter,
  92424. rice_parameter_limit,
  92425. min_partition_order,
  92426. max_partition_order,
  92427. subframe_bps,
  92428. do_escape_coding,
  92429. rice_parameter_search_dist,
  92430. &subframe->data.fixed.entropy_coding_method
  92431. );
  92432. subframe->data.fixed.order = order;
  92433. for(i = 0; i < order; i++)
  92434. subframe->data.fixed.warmup[i] = signal[i];
  92435. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92436. #if SPOTCHECK_ESTIMATE
  92437. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92438. #endif
  92439. return estimate;
  92440. }
  92441. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92442. unsigned evaluate_lpc_subframe_(
  92443. FLAC__StreamEncoder *encoder,
  92444. const FLAC__int32 signal[],
  92445. FLAC__int32 residual[],
  92446. FLAC__uint64 abs_residual_partition_sums[],
  92447. unsigned raw_bits_per_partition[],
  92448. const FLAC__real lp_coeff[],
  92449. unsigned blocksize,
  92450. unsigned subframe_bps,
  92451. unsigned order,
  92452. unsigned qlp_coeff_precision,
  92453. unsigned rice_parameter,
  92454. unsigned rice_parameter_limit,
  92455. unsigned min_partition_order,
  92456. unsigned max_partition_order,
  92457. FLAC__bool do_escape_coding,
  92458. unsigned rice_parameter_search_dist,
  92459. FLAC__Subframe *subframe,
  92460. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92461. )
  92462. {
  92463. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92464. unsigned i, residual_bits, estimate;
  92465. int quantization, ret;
  92466. const unsigned residual_samples = blocksize - order;
  92467. if(subframe_bps <= 16) {
  92468. FLAC__ASSERT(order > 0);
  92469. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92470. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92471. }
  92472. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92473. if(ret != 0)
  92474. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92475. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92476. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92477. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92478. else
  92479. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92480. else
  92481. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92482. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92483. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92484. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92485. subframe->data.lpc.residual = residual;
  92486. residual_bits =
  92487. find_best_partition_order_(
  92488. encoder->private_,
  92489. residual,
  92490. abs_residual_partition_sums,
  92491. raw_bits_per_partition,
  92492. residual_samples,
  92493. order,
  92494. rice_parameter,
  92495. rice_parameter_limit,
  92496. min_partition_order,
  92497. max_partition_order,
  92498. subframe_bps,
  92499. do_escape_coding,
  92500. rice_parameter_search_dist,
  92501. &subframe->data.lpc.entropy_coding_method
  92502. );
  92503. subframe->data.lpc.order = order;
  92504. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92505. subframe->data.lpc.quantization_level = quantization;
  92506. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92507. for(i = 0; i < order; i++)
  92508. subframe->data.lpc.warmup[i] = signal[i];
  92509. 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;
  92510. #if SPOTCHECK_ESTIMATE
  92511. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92512. #endif
  92513. return estimate;
  92514. }
  92515. #endif
  92516. unsigned evaluate_verbatim_subframe_(
  92517. FLAC__StreamEncoder *encoder,
  92518. const FLAC__int32 signal[],
  92519. unsigned blocksize,
  92520. unsigned subframe_bps,
  92521. FLAC__Subframe *subframe
  92522. )
  92523. {
  92524. unsigned estimate;
  92525. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92526. subframe->data.verbatim.data = signal;
  92527. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92528. #if SPOTCHECK_ESTIMATE
  92529. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92530. #else
  92531. (void)encoder;
  92532. #endif
  92533. return estimate;
  92534. }
  92535. unsigned find_best_partition_order_(
  92536. FLAC__StreamEncoderPrivate *private_,
  92537. const FLAC__int32 residual[],
  92538. FLAC__uint64 abs_residual_partition_sums[],
  92539. unsigned raw_bits_per_partition[],
  92540. unsigned residual_samples,
  92541. unsigned predictor_order,
  92542. unsigned rice_parameter,
  92543. unsigned rice_parameter_limit,
  92544. unsigned min_partition_order,
  92545. unsigned max_partition_order,
  92546. unsigned bps,
  92547. FLAC__bool do_escape_coding,
  92548. unsigned rice_parameter_search_dist,
  92549. FLAC__EntropyCodingMethod *best_ecm
  92550. )
  92551. {
  92552. unsigned residual_bits, best_residual_bits = 0;
  92553. unsigned best_parameters_index = 0;
  92554. unsigned best_partition_order = 0;
  92555. const unsigned blocksize = residual_samples + predictor_order;
  92556. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92557. min_partition_order = min(min_partition_order, max_partition_order);
  92558. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92559. if(do_escape_coding)
  92560. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92561. {
  92562. int partition_order;
  92563. unsigned sum;
  92564. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92565. if(!
  92566. set_partitioned_rice_(
  92567. #ifdef EXACT_RICE_BITS_CALCULATION
  92568. residual,
  92569. #endif
  92570. abs_residual_partition_sums+sum,
  92571. raw_bits_per_partition+sum,
  92572. residual_samples,
  92573. predictor_order,
  92574. rice_parameter,
  92575. rice_parameter_limit,
  92576. rice_parameter_search_dist,
  92577. (unsigned)partition_order,
  92578. do_escape_coding,
  92579. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92580. &residual_bits
  92581. )
  92582. )
  92583. {
  92584. FLAC__ASSERT(best_residual_bits != 0);
  92585. break;
  92586. }
  92587. sum += 1u << partition_order;
  92588. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92589. best_residual_bits = residual_bits;
  92590. best_parameters_index = !best_parameters_index;
  92591. best_partition_order = partition_order;
  92592. }
  92593. }
  92594. }
  92595. best_ecm->data.partitioned_rice.order = best_partition_order;
  92596. {
  92597. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92598. unsigned partition;
  92599. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92600. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92601. if(do_escape_coding)
  92602. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92603. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92604. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92605. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92606. break;
  92607. }
  92608. }
  92609. }
  92610. return best_residual_bits;
  92611. }
  92612. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92613. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92614. const FLAC__int32 residual[],
  92615. FLAC__uint64 abs_residual_partition_sums[],
  92616. unsigned blocksize,
  92617. unsigned predictor_order,
  92618. unsigned min_partition_order,
  92619. unsigned max_partition_order
  92620. );
  92621. #endif
  92622. void precompute_partition_info_sums_(
  92623. const FLAC__int32 residual[],
  92624. FLAC__uint64 abs_residual_partition_sums[],
  92625. unsigned residual_samples,
  92626. unsigned predictor_order,
  92627. unsigned min_partition_order,
  92628. unsigned max_partition_order,
  92629. unsigned bps
  92630. )
  92631. {
  92632. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92633. unsigned partitions = 1u << max_partition_order;
  92634. FLAC__ASSERT(default_partition_samples > predictor_order);
  92635. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92636. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92637. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92638. return;
  92639. }
  92640. #endif
  92641. {
  92642. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92643. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92644. FLAC__uint32 abs_residual_partition_sum;
  92645. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92646. end += default_partition_samples;
  92647. abs_residual_partition_sum = 0;
  92648. for( ; residual_sample < end; residual_sample++)
  92649. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92650. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92651. }
  92652. }
  92653. else { /* have to pessimistically use 64 bits for accumulator */
  92654. FLAC__uint64 abs_residual_partition_sum;
  92655. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92656. end += default_partition_samples;
  92657. abs_residual_partition_sum = 0;
  92658. for( ; residual_sample < end; residual_sample++)
  92659. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92660. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92661. }
  92662. }
  92663. }
  92664. {
  92665. unsigned from_partition = 0, to_partition = partitions;
  92666. int partition_order;
  92667. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92668. unsigned i;
  92669. partitions >>= 1;
  92670. for(i = 0; i < partitions; i++) {
  92671. abs_residual_partition_sums[to_partition++] =
  92672. abs_residual_partition_sums[from_partition ] +
  92673. abs_residual_partition_sums[from_partition+1];
  92674. from_partition += 2;
  92675. }
  92676. }
  92677. }
  92678. }
  92679. void precompute_partition_info_escapes_(
  92680. const FLAC__int32 residual[],
  92681. unsigned raw_bits_per_partition[],
  92682. unsigned residual_samples,
  92683. unsigned predictor_order,
  92684. unsigned min_partition_order,
  92685. unsigned max_partition_order
  92686. )
  92687. {
  92688. int partition_order;
  92689. unsigned from_partition, to_partition = 0;
  92690. const unsigned blocksize = residual_samples + predictor_order;
  92691. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92692. FLAC__int32 r;
  92693. FLAC__uint32 rmax;
  92694. unsigned partition, partition_sample, partition_samples, residual_sample;
  92695. const unsigned partitions = 1u << partition_order;
  92696. const unsigned default_partition_samples = blocksize >> partition_order;
  92697. FLAC__ASSERT(default_partition_samples > predictor_order);
  92698. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92699. partition_samples = default_partition_samples;
  92700. if(partition == 0)
  92701. partition_samples -= predictor_order;
  92702. rmax = 0;
  92703. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92704. r = residual[residual_sample++];
  92705. if(r < 0)
  92706. rmax |= ~r;
  92707. else
  92708. rmax |= r;
  92709. }
  92710. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92711. }
  92712. to_partition = partitions;
  92713. break; /*@@@ yuck, should remove the 'for' loop instead */
  92714. }
  92715. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92716. unsigned m;
  92717. unsigned i;
  92718. const unsigned partitions = 1u << partition_order;
  92719. for(i = 0; i < partitions; i++) {
  92720. m = raw_bits_per_partition[from_partition];
  92721. from_partition++;
  92722. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92723. from_partition++;
  92724. to_partition++;
  92725. }
  92726. }
  92727. }
  92728. #ifdef EXACT_RICE_BITS_CALCULATION
  92729. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92730. const unsigned rice_parameter,
  92731. const unsigned partition_samples,
  92732. const FLAC__int32 *residual
  92733. )
  92734. {
  92735. unsigned i, partition_bits =
  92736. 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 */
  92737. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92738. ;
  92739. for(i = 0; i < partition_samples; i++)
  92740. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92741. return partition_bits;
  92742. }
  92743. #else
  92744. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92745. const unsigned rice_parameter,
  92746. const unsigned partition_samples,
  92747. const FLAC__uint64 abs_residual_partition_sum
  92748. )
  92749. {
  92750. return
  92751. 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 */
  92752. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92753. (
  92754. rice_parameter?
  92755. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92756. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92757. )
  92758. - (partition_samples >> 1)
  92759. ;
  92760. }
  92761. #endif
  92762. FLAC__bool set_partitioned_rice_(
  92763. #ifdef EXACT_RICE_BITS_CALCULATION
  92764. const FLAC__int32 residual[],
  92765. #endif
  92766. const FLAC__uint64 abs_residual_partition_sums[],
  92767. const unsigned raw_bits_per_partition[],
  92768. const unsigned residual_samples,
  92769. const unsigned predictor_order,
  92770. const unsigned suggested_rice_parameter,
  92771. const unsigned rice_parameter_limit,
  92772. const unsigned rice_parameter_search_dist,
  92773. const unsigned partition_order,
  92774. const FLAC__bool search_for_escapes,
  92775. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92776. unsigned *bits
  92777. )
  92778. {
  92779. unsigned rice_parameter, partition_bits;
  92780. unsigned best_partition_bits, best_rice_parameter = 0;
  92781. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92782. unsigned *parameters, *raw_bits;
  92783. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92784. unsigned min_rice_parameter, max_rice_parameter;
  92785. #else
  92786. (void)rice_parameter_search_dist;
  92787. #endif
  92788. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92789. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92790. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92791. parameters = partitioned_rice_contents->parameters;
  92792. raw_bits = partitioned_rice_contents->raw_bits;
  92793. if(partition_order == 0) {
  92794. best_partition_bits = (unsigned)(-1);
  92795. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92796. if(rice_parameter_search_dist) {
  92797. if(suggested_rice_parameter < rice_parameter_search_dist)
  92798. min_rice_parameter = 0;
  92799. else
  92800. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92801. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92802. if(max_rice_parameter >= rice_parameter_limit) {
  92803. #ifdef DEBUG_VERBOSE
  92804. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92805. #endif
  92806. max_rice_parameter = rice_parameter_limit - 1;
  92807. }
  92808. }
  92809. else
  92810. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92811. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92812. #else
  92813. rice_parameter = suggested_rice_parameter;
  92814. #endif
  92815. #ifdef EXACT_RICE_BITS_CALCULATION
  92816. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92817. #else
  92818. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92819. #endif
  92820. if(partition_bits < best_partition_bits) {
  92821. best_rice_parameter = rice_parameter;
  92822. best_partition_bits = partition_bits;
  92823. }
  92824. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92825. }
  92826. #endif
  92827. if(search_for_escapes) {
  92828. 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;
  92829. if(partition_bits <= best_partition_bits) {
  92830. raw_bits[0] = raw_bits_per_partition[0];
  92831. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92832. best_partition_bits = partition_bits;
  92833. }
  92834. else
  92835. raw_bits[0] = 0;
  92836. }
  92837. parameters[0] = best_rice_parameter;
  92838. bits_ += best_partition_bits;
  92839. }
  92840. else {
  92841. unsigned partition, residual_sample;
  92842. unsigned partition_samples;
  92843. FLAC__uint64 mean, k;
  92844. const unsigned partitions = 1u << partition_order;
  92845. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92846. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92847. if(partition == 0) {
  92848. if(partition_samples <= predictor_order)
  92849. return false;
  92850. else
  92851. partition_samples -= predictor_order;
  92852. }
  92853. mean = abs_residual_partition_sums[partition];
  92854. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92855. ;
  92856. if(rice_parameter >= rice_parameter_limit) {
  92857. #ifdef DEBUG_VERBOSE
  92858. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92859. #endif
  92860. rice_parameter = rice_parameter_limit - 1;
  92861. }
  92862. best_partition_bits = (unsigned)(-1);
  92863. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92864. if(rice_parameter_search_dist) {
  92865. if(rice_parameter < rice_parameter_search_dist)
  92866. min_rice_parameter = 0;
  92867. else
  92868. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92869. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92870. if(max_rice_parameter >= rice_parameter_limit) {
  92871. #ifdef DEBUG_VERBOSE
  92872. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92873. #endif
  92874. max_rice_parameter = rice_parameter_limit - 1;
  92875. }
  92876. }
  92877. else
  92878. min_rice_parameter = max_rice_parameter = rice_parameter;
  92879. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92880. #endif
  92881. #ifdef EXACT_RICE_BITS_CALCULATION
  92882. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92883. #else
  92884. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92885. #endif
  92886. if(partition_bits < best_partition_bits) {
  92887. best_rice_parameter = rice_parameter;
  92888. best_partition_bits = partition_bits;
  92889. }
  92890. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92891. }
  92892. #endif
  92893. if(search_for_escapes) {
  92894. 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;
  92895. if(partition_bits <= best_partition_bits) {
  92896. raw_bits[partition] = raw_bits_per_partition[partition];
  92897. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92898. best_partition_bits = partition_bits;
  92899. }
  92900. else
  92901. raw_bits[partition] = 0;
  92902. }
  92903. parameters[partition] = best_rice_parameter;
  92904. bits_ += best_partition_bits;
  92905. residual_sample += partition_samples;
  92906. }
  92907. }
  92908. *bits = bits_;
  92909. return true;
  92910. }
  92911. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92912. {
  92913. unsigned i, shift;
  92914. FLAC__int32 x = 0;
  92915. for(i = 0; i < samples && !(x&1); i++)
  92916. x |= signal[i];
  92917. if(x == 0) {
  92918. shift = 0;
  92919. }
  92920. else {
  92921. for(shift = 0; !(x&1); shift++)
  92922. x >>= 1;
  92923. }
  92924. if(shift > 0) {
  92925. for(i = 0; i < samples; i++)
  92926. signal[i] >>= shift;
  92927. }
  92928. return shift;
  92929. }
  92930. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92931. {
  92932. unsigned channel;
  92933. for(channel = 0; channel < channels; channel++)
  92934. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  92935. fifo->tail += wide_samples;
  92936. FLAC__ASSERT(fifo->tail <= fifo->size);
  92937. }
  92938. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92939. {
  92940. unsigned channel;
  92941. unsigned sample, wide_sample;
  92942. unsigned tail = fifo->tail;
  92943. sample = input_offset * channels;
  92944. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  92945. for(channel = 0; channel < channels; channel++)
  92946. fifo->data[channel][tail] = input[sample++];
  92947. tail++;
  92948. }
  92949. fifo->tail = tail;
  92950. FLAC__ASSERT(fifo->tail <= fifo->size);
  92951. }
  92952. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92953. {
  92954. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92955. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  92956. (void)decoder;
  92957. if(encoder->private_->verify.needs_magic_hack) {
  92958. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  92959. *bytes = FLAC__STREAM_SYNC_LENGTH;
  92960. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  92961. encoder->private_->verify.needs_magic_hack = false;
  92962. }
  92963. else {
  92964. if(encoded_bytes == 0) {
  92965. FLAC__ASSERT(0);
  92966. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  92967. }
  92968. else if(encoded_bytes < *bytes)
  92969. *bytes = encoded_bytes;
  92970. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  92971. encoder->private_->verify.output.data += *bytes;
  92972. encoder->private_->verify.output.bytes -= *bytes;
  92973. }
  92974. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  92975. }
  92976. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  92977. {
  92978. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  92979. unsigned channel;
  92980. const unsigned channels = frame->header.channels;
  92981. const unsigned blocksize = frame->header.blocksize;
  92982. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  92983. (void)decoder;
  92984. for(channel = 0; channel < channels; channel++) {
  92985. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  92986. unsigned i, sample = 0;
  92987. FLAC__int32 expect = 0, got = 0;
  92988. for(i = 0; i < blocksize; i++) {
  92989. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  92990. sample = i;
  92991. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  92992. got = (FLAC__int32)buffer[channel][i];
  92993. break;
  92994. }
  92995. }
  92996. FLAC__ASSERT(i < blocksize);
  92997. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  92998. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  92999. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93000. encoder->private_->verify.error_stats.channel = channel;
  93001. encoder->private_->verify.error_stats.sample = sample;
  93002. encoder->private_->verify.error_stats.expected = expect;
  93003. encoder->private_->verify.error_stats.got = got;
  93004. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93005. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93006. }
  93007. }
  93008. encoder->private_->verify.input_fifo.tail -= blocksize;
  93009. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93010. for(channel = 0; channel < channels; channel++)
  93011. 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]));
  93012. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93013. }
  93014. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93015. {
  93016. (void)decoder, (void)metadata, (void)client_data;
  93017. }
  93018. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93019. {
  93020. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93021. (void)decoder, (void)status;
  93022. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93023. }
  93024. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93025. {
  93026. (void)client_data;
  93027. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93028. if (*bytes == 0) {
  93029. if (feof(encoder->private_->file))
  93030. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93031. else if (ferror(encoder->private_->file))
  93032. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93033. }
  93034. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93035. }
  93036. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93037. {
  93038. (void)client_data;
  93039. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93040. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93041. else
  93042. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93043. }
  93044. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93045. {
  93046. off_t offset;
  93047. (void)client_data;
  93048. offset = ftello(encoder->private_->file);
  93049. if(offset < 0) {
  93050. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93051. }
  93052. else {
  93053. *absolute_byte_offset = (FLAC__uint64)offset;
  93054. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93055. }
  93056. }
  93057. #ifdef FLAC__VALGRIND_TESTING
  93058. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93059. {
  93060. size_t ret = fwrite(ptr, size, nmemb, stream);
  93061. if(!ferror(stream))
  93062. fflush(stream);
  93063. return ret;
  93064. }
  93065. #else
  93066. #define local__fwrite fwrite
  93067. #endif
  93068. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93069. {
  93070. (void)client_data, (void)current_frame;
  93071. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93072. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93073. #if FLAC__HAS_OGG
  93074. encoder->private_->is_ogg? true :
  93075. #endif
  93076. samples > 0
  93077. );
  93078. if(call_it) {
  93079. 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);
  93080. }
  93081. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93082. }
  93083. else
  93084. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93085. }
  93086. FILE *get_binary_stdout_(void)
  93087. {
  93088. #if defined _MSC_VER || defined __MINGW32__
  93089. _setmode(_fileno(stdout), _O_BINARY);
  93090. #elif defined __CYGWIN__
  93091. setmode(_fileno(stdout), _O_BINARY);
  93092. #elif defined __EMX__
  93093. setmode(fileno(stdout), O_BINARY);
  93094. #endif
  93095. return stdout;
  93096. }
  93097. #endif
  93098. /*** End of inlined file: stream_encoder.c ***/
  93099. /*** Start of inlined file: stream_encoder_framing.c ***/
  93100. /*** Start of inlined file: juce_FlacHeader.h ***/
  93101. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93102. // tasks..
  93103. #define VERSION "1.2.1"
  93104. #define FLAC__NO_DLL 1
  93105. #if JUCE_MSVC
  93106. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93107. #endif
  93108. #if JUCE_MAC
  93109. #define FLAC__SYS_DARWIN 1
  93110. #endif
  93111. /*** End of inlined file: juce_FlacHeader.h ***/
  93112. #if JUCE_USE_FLAC
  93113. #if HAVE_CONFIG_H
  93114. # include <config.h>
  93115. #endif
  93116. #include <stdio.h>
  93117. #include <string.h> /* for strlen() */
  93118. #ifdef max
  93119. #undef max
  93120. #endif
  93121. #define max(x,y) ((x)>(y)?(x):(y))
  93122. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93123. 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);
  93124. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93125. {
  93126. unsigned i, j;
  93127. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93128. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93129. return false;
  93130. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93131. return false;
  93132. i = metadata->length;
  93133. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93134. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93135. i -= metadata->data.vorbis_comment.vendor_string.length;
  93136. i += vendor_string_length;
  93137. }
  93138. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93139. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93140. return false;
  93141. switch(metadata->type) {
  93142. case FLAC__METADATA_TYPE_STREAMINFO:
  93143. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93144. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93145. return false;
  93146. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93147. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93148. return false;
  93149. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93150. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93151. return false;
  93152. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93153. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93154. return false;
  93155. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93156. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93157. return false;
  93158. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93159. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93160. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93161. return false;
  93162. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93163. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93164. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93165. return false;
  93166. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93167. return false;
  93168. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93169. return false;
  93170. break;
  93171. case FLAC__METADATA_TYPE_PADDING:
  93172. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93173. return false;
  93174. break;
  93175. case FLAC__METADATA_TYPE_APPLICATION:
  93176. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93177. return false;
  93178. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93179. return false;
  93180. break;
  93181. case FLAC__METADATA_TYPE_SEEKTABLE:
  93182. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93183. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93184. return false;
  93185. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93186. return false;
  93187. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93188. return false;
  93189. }
  93190. break;
  93191. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93192. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93193. return false;
  93194. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93195. return false;
  93196. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93197. return false;
  93198. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93199. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93200. return false;
  93201. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93202. return false;
  93203. }
  93204. break;
  93205. case FLAC__METADATA_TYPE_CUESHEET:
  93206. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93207. 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))
  93208. return false;
  93209. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93210. return false;
  93211. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93212. return false;
  93213. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93214. return false;
  93215. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93216. return false;
  93217. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93218. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93219. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93220. return false;
  93221. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93222. return false;
  93223. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93224. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93225. return false;
  93226. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93227. return false;
  93228. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93229. return false;
  93230. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93231. return false;
  93232. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93233. return false;
  93234. for(j = 0; j < track->num_indices; j++) {
  93235. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93236. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93237. return false;
  93238. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93239. return false;
  93240. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93241. return false;
  93242. }
  93243. }
  93244. break;
  93245. case FLAC__METADATA_TYPE_PICTURE:
  93246. {
  93247. size_t len;
  93248. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93249. return false;
  93250. len = strlen(metadata->data.picture.mime_type);
  93251. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93252. return false;
  93253. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93254. return false;
  93255. len = strlen((const char *)metadata->data.picture.description);
  93256. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93257. return false;
  93258. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93259. return false;
  93260. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93261. return false;
  93262. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93263. return false;
  93264. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93265. return false;
  93266. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93267. return false;
  93268. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93269. return false;
  93270. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93271. return false;
  93272. }
  93273. break;
  93274. default:
  93275. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93276. return false;
  93277. break;
  93278. }
  93279. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93280. return true;
  93281. }
  93282. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93283. {
  93284. unsigned u, blocksize_hint, sample_rate_hint;
  93285. FLAC__byte crc;
  93286. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93287. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93288. return false;
  93289. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93290. return false;
  93291. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93292. return false;
  93293. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93294. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93295. blocksize_hint = 0;
  93296. switch(header->blocksize) {
  93297. case 192: u = 1; break;
  93298. case 576: u = 2; break;
  93299. case 1152: u = 3; break;
  93300. case 2304: u = 4; break;
  93301. case 4608: u = 5; break;
  93302. case 256: u = 8; break;
  93303. case 512: u = 9; break;
  93304. case 1024: u = 10; break;
  93305. case 2048: u = 11; break;
  93306. case 4096: u = 12; break;
  93307. case 8192: u = 13; break;
  93308. case 16384: u = 14; break;
  93309. case 32768: u = 15; break;
  93310. default:
  93311. if(header->blocksize <= 0x100)
  93312. blocksize_hint = u = 6;
  93313. else
  93314. blocksize_hint = u = 7;
  93315. break;
  93316. }
  93317. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93318. return false;
  93319. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93320. sample_rate_hint = 0;
  93321. switch(header->sample_rate) {
  93322. case 88200: u = 1; break;
  93323. case 176400: u = 2; break;
  93324. case 192000: u = 3; break;
  93325. case 8000: u = 4; break;
  93326. case 16000: u = 5; break;
  93327. case 22050: u = 6; break;
  93328. case 24000: u = 7; break;
  93329. case 32000: u = 8; break;
  93330. case 44100: u = 9; break;
  93331. case 48000: u = 10; break;
  93332. case 96000: u = 11; break;
  93333. default:
  93334. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93335. sample_rate_hint = u = 12;
  93336. else if(header->sample_rate % 10 == 0)
  93337. sample_rate_hint = u = 14;
  93338. else if(header->sample_rate <= 0xffff)
  93339. sample_rate_hint = u = 13;
  93340. else
  93341. u = 0;
  93342. break;
  93343. }
  93344. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93345. return false;
  93346. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93347. switch(header->channel_assignment) {
  93348. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93349. u = header->channels - 1;
  93350. break;
  93351. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93352. FLAC__ASSERT(header->channels == 2);
  93353. u = 8;
  93354. break;
  93355. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93356. FLAC__ASSERT(header->channels == 2);
  93357. u = 9;
  93358. break;
  93359. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93360. FLAC__ASSERT(header->channels == 2);
  93361. u = 10;
  93362. break;
  93363. default:
  93364. FLAC__ASSERT(0);
  93365. }
  93366. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93367. return false;
  93368. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93369. switch(header->bits_per_sample) {
  93370. case 8 : u = 1; break;
  93371. case 12: u = 2; break;
  93372. case 16: u = 4; break;
  93373. case 20: u = 5; break;
  93374. case 24: u = 6; break;
  93375. default: u = 0; break;
  93376. }
  93377. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93378. return false;
  93379. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93380. return false;
  93381. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93382. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93383. return false;
  93384. }
  93385. else {
  93386. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93387. return false;
  93388. }
  93389. if(blocksize_hint)
  93390. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93391. return false;
  93392. switch(sample_rate_hint) {
  93393. case 12:
  93394. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93395. return false;
  93396. break;
  93397. case 13:
  93398. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93399. return false;
  93400. break;
  93401. case 14:
  93402. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93403. return false;
  93404. break;
  93405. }
  93406. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93407. return false;
  93408. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93409. return false;
  93410. return true;
  93411. }
  93412. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93413. {
  93414. FLAC__bool ok;
  93415. ok =
  93416. 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) &&
  93417. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93418. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93419. ;
  93420. return ok;
  93421. }
  93422. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93423. {
  93424. unsigned i;
  93425. 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))
  93426. return false;
  93427. if(wasted_bits)
  93428. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93429. return false;
  93430. for(i = 0; i < subframe->order; i++)
  93431. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93432. return false;
  93433. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93434. return false;
  93435. switch(subframe->entropy_coding_method.type) {
  93436. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93437. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93438. if(!add_residual_partitioned_rice_(
  93439. bw,
  93440. subframe->residual,
  93441. residual_samples,
  93442. subframe->order,
  93443. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93444. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93445. subframe->entropy_coding_method.data.partitioned_rice.order,
  93446. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93447. ))
  93448. return false;
  93449. break;
  93450. default:
  93451. FLAC__ASSERT(0);
  93452. }
  93453. return true;
  93454. }
  93455. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93456. {
  93457. unsigned i;
  93458. 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))
  93459. return false;
  93460. if(wasted_bits)
  93461. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93462. return false;
  93463. for(i = 0; i < subframe->order; i++)
  93464. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93465. return false;
  93466. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93467. return false;
  93468. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93469. return false;
  93470. for(i = 0; i < subframe->order; i++)
  93471. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93472. return false;
  93473. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93474. return false;
  93475. switch(subframe->entropy_coding_method.type) {
  93476. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93477. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93478. if(!add_residual_partitioned_rice_(
  93479. bw,
  93480. subframe->residual,
  93481. residual_samples,
  93482. subframe->order,
  93483. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93484. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93485. subframe->entropy_coding_method.data.partitioned_rice.order,
  93486. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93487. ))
  93488. return false;
  93489. break;
  93490. default:
  93491. FLAC__ASSERT(0);
  93492. }
  93493. return true;
  93494. }
  93495. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93496. {
  93497. unsigned i;
  93498. const FLAC__int32 *signal = subframe->data;
  93499. 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))
  93500. return false;
  93501. if(wasted_bits)
  93502. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93503. return false;
  93504. for(i = 0; i < samples; i++)
  93505. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93506. return false;
  93507. return true;
  93508. }
  93509. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93510. {
  93511. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93512. return false;
  93513. switch(method->type) {
  93514. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93515. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93516. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93517. return false;
  93518. break;
  93519. default:
  93520. FLAC__ASSERT(0);
  93521. }
  93522. return true;
  93523. }
  93524. 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)
  93525. {
  93526. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93527. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93528. if(partition_order == 0) {
  93529. unsigned i;
  93530. if(raw_bits[0] == 0) {
  93531. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93532. return false;
  93533. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93534. return false;
  93535. }
  93536. else {
  93537. FLAC__ASSERT(rice_parameters[0] == 0);
  93538. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93539. return false;
  93540. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93541. return false;
  93542. for(i = 0; i < residual_samples; i++) {
  93543. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93544. return false;
  93545. }
  93546. }
  93547. return true;
  93548. }
  93549. else {
  93550. unsigned i, j, k = 0, k_last = 0;
  93551. unsigned partition_samples;
  93552. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93553. for(i = 0; i < (1u<<partition_order); i++) {
  93554. partition_samples = default_partition_samples;
  93555. if(i == 0)
  93556. partition_samples -= predictor_order;
  93557. k += partition_samples;
  93558. if(raw_bits[i] == 0) {
  93559. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93560. return false;
  93561. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93562. return false;
  93563. }
  93564. else {
  93565. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93566. return false;
  93567. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93568. return false;
  93569. for(j = k_last; j < k; j++) {
  93570. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93571. return false;
  93572. }
  93573. }
  93574. k_last = k;
  93575. }
  93576. return true;
  93577. }
  93578. }
  93579. #endif
  93580. /*** End of inlined file: stream_encoder_framing.c ***/
  93581. /*** Start of inlined file: window_flac.c ***/
  93582. /*** Start of inlined file: juce_FlacHeader.h ***/
  93583. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93584. // tasks..
  93585. #define VERSION "1.2.1"
  93586. #define FLAC__NO_DLL 1
  93587. #if JUCE_MSVC
  93588. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93589. #endif
  93590. #if JUCE_MAC
  93591. #define FLAC__SYS_DARWIN 1
  93592. #endif
  93593. /*** End of inlined file: juce_FlacHeader.h ***/
  93594. #if JUCE_USE_FLAC
  93595. #if HAVE_CONFIG_H
  93596. # include <config.h>
  93597. #endif
  93598. #include <math.h>
  93599. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93600. #ifndef M_PI
  93601. #define M_PI 3.14159265358979323846
  93602. #endif
  93603. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93604. {
  93605. const FLAC__int32 N = L - 1;
  93606. FLAC__int32 n;
  93607. if (L & 1) {
  93608. for (n = 0; n <= N/2; n++)
  93609. window[n] = 2.0f * n / (float)N;
  93610. for (; n <= N; n++)
  93611. window[n] = 2.0f - 2.0f * n / (float)N;
  93612. }
  93613. else {
  93614. for (n = 0; n <= L/2-1; n++)
  93615. window[n] = 2.0f * n / (float)N;
  93616. for (; n <= N; n++)
  93617. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93618. }
  93619. }
  93620. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93621. {
  93622. const FLAC__int32 N = L - 1;
  93623. FLAC__int32 n;
  93624. for (n = 0; n < L; n++)
  93625. 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)));
  93626. }
  93627. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93628. {
  93629. const FLAC__int32 N = L - 1;
  93630. FLAC__int32 n;
  93631. for (n = 0; n < L; n++)
  93632. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93633. }
  93634. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93635. {
  93636. const FLAC__int32 N = L - 1;
  93637. FLAC__int32 n;
  93638. for (n = 0; n <= N; n++)
  93639. 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));
  93640. }
  93641. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93642. {
  93643. const FLAC__int32 N = L - 1;
  93644. const double N2 = (double)N / 2.;
  93645. FLAC__int32 n;
  93646. for (n = 0; n <= N; n++) {
  93647. double k = ((double)n - N2) / N2;
  93648. k = 1.0f - k * k;
  93649. window[n] = (FLAC__real)(k * k);
  93650. }
  93651. }
  93652. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93653. {
  93654. const FLAC__int32 N = L - 1;
  93655. FLAC__int32 n;
  93656. for (n = 0; n < L; n++)
  93657. 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));
  93658. }
  93659. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93660. {
  93661. const FLAC__int32 N = L - 1;
  93662. const double N2 = (double)N / 2.;
  93663. FLAC__int32 n;
  93664. for (n = 0; n <= N; n++) {
  93665. const double k = ((double)n - N2) / (stddev * N2);
  93666. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93667. }
  93668. }
  93669. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93670. {
  93671. const FLAC__int32 N = L - 1;
  93672. FLAC__int32 n;
  93673. for (n = 0; n < L; n++)
  93674. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93675. }
  93676. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93677. {
  93678. const FLAC__int32 N = L - 1;
  93679. FLAC__int32 n;
  93680. for (n = 0; n < L; n++)
  93681. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93682. }
  93683. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93684. {
  93685. const FLAC__int32 N = L - 1;
  93686. FLAC__int32 n;
  93687. for (n = 0; n < L; n++)
  93688. 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));
  93689. }
  93690. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93691. {
  93692. const FLAC__int32 N = L - 1;
  93693. FLAC__int32 n;
  93694. for (n = 0; n < L; n++)
  93695. 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));
  93696. }
  93697. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93698. {
  93699. FLAC__int32 n;
  93700. for (n = 0; n < L; n++)
  93701. window[n] = 1.0f;
  93702. }
  93703. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93704. {
  93705. FLAC__int32 n;
  93706. if (L & 1) {
  93707. for (n = 1; n <= L+1/2; n++)
  93708. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93709. for (; n <= L; n++)
  93710. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93711. }
  93712. else {
  93713. for (n = 1; n <= L/2; n++)
  93714. window[n-1] = 2.0f * n / (float)L;
  93715. for (; n <= L; n++)
  93716. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93717. }
  93718. }
  93719. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93720. {
  93721. if (p <= 0.0)
  93722. FLAC__window_rectangle(window, L);
  93723. else if (p >= 1.0)
  93724. FLAC__window_hann(window, L);
  93725. else {
  93726. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93727. FLAC__int32 n;
  93728. FLAC__window_rectangle(window, L);
  93729. if (Np > 0) {
  93730. for (n = 0; n <= Np; n++) {
  93731. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93732. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93733. }
  93734. }
  93735. }
  93736. }
  93737. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93738. {
  93739. const FLAC__int32 N = L - 1;
  93740. const double N2 = (double)N / 2.;
  93741. FLAC__int32 n;
  93742. for (n = 0; n <= N; n++) {
  93743. const double k = ((double)n - N2) / N2;
  93744. window[n] = (FLAC__real)(1.0f - k * k);
  93745. }
  93746. }
  93747. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93748. #endif
  93749. /*** End of inlined file: window_flac.c ***/
  93750. #else
  93751. #include <FLAC/all.h>
  93752. #endif
  93753. }
  93754. #undef max
  93755. #undef min
  93756. #ifdef _MSC_VER
  93757. #pragma warning (pop)
  93758. #endif
  93759. BEGIN_JUCE_NAMESPACE
  93760. static const char* const flacFormatName = "FLAC file";
  93761. static const juce_wchar* const flacExtensions[] = { T(".flac"), 0 };
  93762. class FlacReader : public AudioFormatReader
  93763. {
  93764. public:
  93765. FlacReader (InputStream* const in)
  93766. : AudioFormatReader (in, TRANS (flacFormatName)),
  93767. reservoir (2, 0),
  93768. reservoirStart (0),
  93769. samplesInReservoir (0),
  93770. scanningForLength (false)
  93771. {
  93772. using namespace FlacNamespace;
  93773. lengthInSamples = 0;
  93774. decoder = FLAC__stream_decoder_new();
  93775. ok = FLAC__stream_decoder_init_stream (decoder,
  93776. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93777. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93778. this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93779. if (ok)
  93780. {
  93781. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93782. if (lengthInSamples == 0 && sampleRate > 0)
  93783. {
  93784. // the length hasn't been stored in the metadata, so we'll need to
  93785. // work it out the length the hard way, by scanning the whole file..
  93786. scanningForLength = true;
  93787. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93788. scanningForLength = false;
  93789. const int64 tempLength = lengthInSamples;
  93790. FLAC__stream_decoder_reset (decoder);
  93791. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93792. lengthInSamples = tempLength;
  93793. }
  93794. }
  93795. }
  93796. ~FlacReader()
  93797. {
  93798. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93799. }
  93800. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93801. {
  93802. sampleRate = info.sample_rate;
  93803. bitsPerSample = info.bits_per_sample;
  93804. lengthInSamples = (unsigned int) info.total_samples;
  93805. numChannels = info.channels;
  93806. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93807. }
  93808. // returns the number of samples read
  93809. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93810. int64 startSampleInFile, int numSamples)
  93811. {
  93812. using namespace FlacNamespace;
  93813. if (! ok)
  93814. return false;
  93815. while (numSamples > 0)
  93816. {
  93817. if (startSampleInFile >= reservoirStart
  93818. && startSampleInFile < reservoirStart + samplesInReservoir)
  93819. {
  93820. const int num = (int) jmin ((int64) numSamples,
  93821. reservoirStart + samplesInReservoir - startSampleInFile);
  93822. jassert (num > 0);
  93823. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93824. if (destSamples[i] != 0)
  93825. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93826. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93827. sizeof (int) * num);
  93828. startOffsetInDestBuffer += num;
  93829. startSampleInFile += num;
  93830. numSamples -= num;
  93831. }
  93832. else
  93833. {
  93834. if (startSampleInFile >= (int) lengthInSamples)
  93835. {
  93836. samplesInReservoir = 0;
  93837. }
  93838. else if (startSampleInFile < reservoirStart
  93839. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93840. {
  93841. // had some problems with flac crashing if the read pos is aligned more
  93842. // accurately than this. Probably fixed in newer versions of the library, though.
  93843. reservoirStart = (int) (startSampleInFile & ~511);
  93844. samplesInReservoir = 0;
  93845. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93846. }
  93847. else
  93848. {
  93849. reservoirStart += samplesInReservoir;
  93850. samplesInReservoir = 0;
  93851. FLAC__stream_decoder_process_single (decoder);
  93852. }
  93853. if (samplesInReservoir == 0)
  93854. break;
  93855. }
  93856. }
  93857. if (numSamples > 0)
  93858. {
  93859. for (int i = numDestChannels; --i >= 0;)
  93860. if (destSamples[i] != 0)
  93861. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93862. sizeof (int) * numSamples);
  93863. }
  93864. return true;
  93865. }
  93866. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93867. {
  93868. if (scanningForLength)
  93869. {
  93870. lengthInSamples += numSamples;
  93871. }
  93872. else
  93873. {
  93874. if (numSamples > reservoir.getNumSamples())
  93875. reservoir.setSize (numChannels, numSamples, false, false, true);
  93876. const int bitsToShift = 32 - bitsPerSample;
  93877. for (int i = 0; i < (int) numChannels; ++i)
  93878. {
  93879. const FlacNamespace::FLAC__int32* src = buffer[i];
  93880. int n = i;
  93881. while (src == 0 && n > 0)
  93882. src = buffer [--n];
  93883. if (src != 0)
  93884. {
  93885. int* dest = (int*) reservoir.getSampleData(i);
  93886. for (int j = 0; j < numSamples; ++j)
  93887. dest[j] = src[j] << bitsToShift;
  93888. }
  93889. }
  93890. samplesInReservoir = numSamples;
  93891. }
  93892. }
  93893. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93894. {
  93895. using namespace FlacNamespace;
  93896. *bytes = (size_t) static_cast <const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
  93897. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93898. }
  93899. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93900. {
  93901. using namespace FlacNamespace;
  93902. static_cast <const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
  93903. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93904. }
  93905. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93906. {
  93907. using namespace FlacNamespace;
  93908. *absolute_byte_offset = static_cast <const FlacReader*> (client_data)->input->getPosition();
  93909. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93910. }
  93911. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93912. {
  93913. using namespace FlacNamespace;
  93914. *stream_length = static_cast <const FlacReader*> (client_data)->input->getTotalLength();
  93915. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93916. }
  93917. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93918. {
  93919. return static_cast <const FlacReader*> (client_data)->input->isExhausted();
  93920. }
  93921. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93922. const FlacNamespace::FLAC__Frame* frame,
  93923. const FlacNamespace::FLAC__int32* const buffer[],
  93924. void* client_data)
  93925. {
  93926. using namespace FlacNamespace;
  93927. static_cast <FlacReader*> (client_data)->useSamples (buffer, frame->header.blocksize);
  93928. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93929. }
  93930. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93931. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93932. void* client_data)
  93933. {
  93934. static_cast <FlacReader*> (client_data)->useMetadata (metadata->data.stream_info);
  93935. }
  93936. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  93937. {
  93938. }
  93939. juce_UseDebuggingNewOperator
  93940. private:
  93941. FlacNamespace::FLAC__StreamDecoder* decoder;
  93942. AudioSampleBuffer reservoir;
  93943. int reservoirStart, samplesInReservoir;
  93944. bool ok, scanningForLength;
  93945. FlacReader (const FlacReader&);
  93946. FlacReader& operator= (const FlacReader&);
  93947. };
  93948. class FlacWriter : public AudioFormatWriter
  93949. {
  93950. public:
  93951. FlacWriter (OutputStream* const out,
  93952. const double sampleRate_,
  93953. const int numChannels_,
  93954. const int bitsPerSample_)
  93955. : AudioFormatWriter (out, TRANS (flacFormatName),
  93956. sampleRate_,
  93957. numChannels_,
  93958. bitsPerSample_)
  93959. {
  93960. using namespace FlacNamespace;
  93961. encoder = FLAC__stream_encoder_new();
  93962. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  93963. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  93964. FLAC__stream_encoder_set_channels (encoder, numChannels);
  93965. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  93966. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  93967. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  93968. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  93969. ok = FLAC__stream_encoder_init_stream (encoder,
  93970. encodeWriteCallback, encodeSeekCallback,
  93971. encodeTellCallback, encodeMetadataCallback,
  93972. this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  93973. }
  93974. ~FlacWriter()
  93975. {
  93976. if (ok)
  93977. {
  93978. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  93979. output->flush();
  93980. }
  93981. else
  93982. {
  93983. output = 0; // to stop the base class deleting this, as it needs to be returned
  93984. // to the caller of createWriter()
  93985. }
  93986. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  93987. }
  93988. bool write (const int** samplesToWrite, int numSamples)
  93989. {
  93990. using namespace FlacNamespace;
  93991. if (! ok)
  93992. return false;
  93993. int* buf[3];
  93994. const int bitsToShift = 32 - bitsPerSample;
  93995. if (bitsToShift > 0)
  93996. {
  93997. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  93998. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  93999. buf[0] = (int*) temp.getData();
  94000. buf[1] = buf[0] + numSamples;
  94001. buf[2] = 0;
  94002. for (int i = numChannelsToWrite; --i >= 0;)
  94003. {
  94004. if (samplesToWrite[i] != 0)
  94005. {
  94006. for (int j = 0; j < numSamples; ++j)
  94007. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94008. }
  94009. }
  94010. samplesToWrite = (const int**) buf;
  94011. }
  94012. return FLAC__stream_encoder_process (encoder,
  94013. (const FLAC__int32**) samplesToWrite,
  94014. numSamples) != 0;
  94015. }
  94016. bool writeData (const void* const data, const int size) const
  94017. {
  94018. return output->write (data, size);
  94019. }
  94020. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  94021. {
  94022. using namespace FlacNamespace;
  94023. b += bytes;
  94024. for (int i = 0; i < bytes; ++i)
  94025. {
  94026. *(--b) = (FLAC__byte) (val & 0xff);
  94027. val >>= 8;
  94028. }
  94029. }
  94030. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  94031. {
  94032. using namespace FlacNamespace;
  94033. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94034. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94035. const unsigned int channelsMinus1 = info.channels - 1;
  94036. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94037. packUint32 (info.min_blocksize, buffer, 2);
  94038. packUint32 (info.max_blocksize, buffer + 2, 2);
  94039. packUint32 (info.min_framesize, buffer + 4, 3);
  94040. packUint32 (info.max_framesize, buffer + 7, 3);
  94041. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94042. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94043. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94044. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94045. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94046. memcpy (buffer + 18, info.md5sum, 16);
  94047. const bool seekOk = output->setPosition (4);
  94048. (void) seekOk;
  94049. // if this fails, you've given it an output stream that can't seek! It needs
  94050. // to be able to seek back to write the header
  94051. jassert (seekOk);
  94052. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94053. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94054. }
  94055. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  94056. const FlacNamespace::FLAC__byte buffer[],
  94057. size_t bytes,
  94058. unsigned int /*samples*/,
  94059. unsigned int /*current_frame*/,
  94060. void* client_data)
  94061. {
  94062. using namespace FlacNamespace;
  94063. return static_cast <FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
  94064. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94065. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94066. }
  94067. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  94068. {
  94069. using namespace FlacNamespace;
  94070. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94071. }
  94072. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  94073. {
  94074. using namespace FlacNamespace;
  94075. if (client_data == 0)
  94076. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94077. *absolute_byte_offset = (FLAC__uint64) static_cast <FlacWriter*> (client_data)->output->getPosition();
  94078. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94079. }
  94080. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
  94081. {
  94082. static_cast <FlacWriter*> (client_data)->writeMetaData (metadata);
  94083. }
  94084. juce_UseDebuggingNewOperator
  94085. bool ok;
  94086. private:
  94087. FlacNamespace::FLAC__StreamEncoder* encoder;
  94088. MemoryBlock temp;
  94089. FlacWriter (const FlacWriter&);
  94090. FlacWriter& operator= (const FlacWriter&);
  94091. };
  94092. FlacAudioFormat::FlacAudioFormat()
  94093. : AudioFormat (TRANS (flacFormatName), (const juce_wchar**) flacExtensions)
  94094. {
  94095. }
  94096. FlacAudioFormat::~FlacAudioFormat()
  94097. {
  94098. }
  94099. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94100. {
  94101. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94102. return Array <int> (rates);
  94103. }
  94104. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94105. {
  94106. const int depths[] = { 16, 24, 0 };
  94107. return Array <int> (depths);
  94108. }
  94109. bool FlacAudioFormat::canDoStereo()
  94110. {
  94111. return true;
  94112. }
  94113. bool FlacAudioFormat::canDoMono()
  94114. {
  94115. return true;
  94116. }
  94117. bool FlacAudioFormat::isCompressed()
  94118. {
  94119. return true;
  94120. }
  94121. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94122. const bool deleteStreamIfOpeningFails)
  94123. {
  94124. ScopedPointer<FlacReader> r (new FlacReader (in));
  94125. if (r->sampleRate != 0)
  94126. return r.release();
  94127. if (! deleteStreamIfOpeningFails)
  94128. r->input = 0;
  94129. return 0;
  94130. }
  94131. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94132. double sampleRate,
  94133. unsigned int numberOfChannels,
  94134. int bitsPerSample,
  94135. const StringPairArray& /*metadataValues*/,
  94136. int /*qualityOptionIndex*/)
  94137. {
  94138. if (getPossibleBitDepths().contains (bitsPerSample))
  94139. {
  94140. ScopedPointer<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels, bitsPerSample));
  94141. if (w->ok)
  94142. return w.release();
  94143. }
  94144. return 0;
  94145. }
  94146. END_JUCE_NAMESPACE
  94147. #endif
  94148. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94149. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94150. #if JUCE_USE_OGGVORBIS
  94151. #if JUCE_MAC
  94152. #define __MACOSX__ 1
  94153. #endif
  94154. namespace OggVorbisNamespace
  94155. {
  94156. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94157. /*** Start of inlined file: vorbisenc.h ***/
  94158. #ifndef _OV_ENC_H_
  94159. #define _OV_ENC_H_
  94160. #ifdef __cplusplus
  94161. extern "C"
  94162. {
  94163. #endif /* __cplusplus */
  94164. /*** Start of inlined file: codec.h ***/
  94165. #ifndef _vorbis_codec_h_
  94166. #define _vorbis_codec_h_
  94167. #ifdef __cplusplus
  94168. extern "C"
  94169. {
  94170. #endif /* __cplusplus */
  94171. /*** Start of inlined file: ogg.h ***/
  94172. #ifndef _OGG_H
  94173. #define _OGG_H
  94174. #ifdef __cplusplus
  94175. extern "C" {
  94176. #endif
  94177. /*** Start of inlined file: os_types.h ***/
  94178. #ifndef _OS_TYPES_H
  94179. #define _OS_TYPES_H
  94180. #define _ogg_malloc malloc
  94181. #define _ogg_calloc calloc
  94182. #define _ogg_realloc realloc
  94183. #define _ogg_free free
  94184. #if defined(_WIN32)
  94185. # if defined(__CYGWIN__)
  94186. # include <_G_config.h>
  94187. typedef _G_int64_t ogg_int64_t;
  94188. typedef _G_int32_t ogg_int32_t;
  94189. typedef _G_uint32_t ogg_uint32_t;
  94190. typedef _G_int16_t ogg_int16_t;
  94191. typedef _G_uint16_t ogg_uint16_t;
  94192. # elif defined(__MINGW32__)
  94193. typedef short ogg_int16_t;
  94194. typedef unsigned short ogg_uint16_t;
  94195. typedef int ogg_int32_t;
  94196. typedef unsigned int ogg_uint32_t;
  94197. typedef long long ogg_int64_t;
  94198. typedef unsigned long long ogg_uint64_t;
  94199. # elif defined(__MWERKS__)
  94200. typedef long long ogg_int64_t;
  94201. typedef int ogg_int32_t;
  94202. typedef unsigned int ogg_uint32_t;
  94203. typedef short ogg_int16_t;
  94204. typedef unsigned short ogg_uint16_t;
  94205. # else
  94206. typedef __int64 ogg_int64_t;
  94207. typedef __int32 ogg_int32_t;
  94208. typedef unsigned __int32 ogg_uint32_t;
  94209. typedef __int16 ogg_int16_t;
  94210. typedef unsigned __int16 ogg_uint16_t;
  94211. # endif
  94212. #elif defined(__MACOS__)
  94213. # include <sys/types.h>
  94214. typedef SInt16 ogg_int16_t;
  94215. typedef UInt16 ogg_uint16_t;
  94216. typedef SInt32 ogg_int32_t;
  94217. typedef UInt32 ogg_uint32_t;
  94218. typedef SInt64 ogg_int64_t;
  94219. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94220. # include <sys/types.h>
  94221. typedef int16_t ogg_int16_t;
  94222. typedef u_int16_t ogg_uint16_t;
  94223. typedef int32_t ogg_int32_t;
  94224. typedef u_int32_t ogg_uint32_t;
  94225. typedef int64_t ogg_int64_t;
  94226. #elif defined(__BEOS__)
  94227. # include <inttypes.h>
  94228. typedef int16_t ogg_int16_t;
  94229. typedef u_int16_t ogg_uint16_t;
  94230. typedef int32_t ogg_int32_t;
  94231. typedef u_int32_t ogg_uint32_t;
  94232. typedef int64_t ogg_int64_t;
  94233. #elif defined (__EMX__)
  94234. typedef short ogg_int16_t;
  94235. typedef unsigned short ogg_uint16_t;
  94236. typedef int ogg_int32_t;
  94237. typedef unsigned int ogg_uint32_t;
  94238. typedef long long ogg_int64_t;
  94239. #elif defined (DJGPP)
  94240. typedef short ogg_int16_t;
  94241. typedef int ogg_int32_t;
  94242. typedef unsigned int ogg_uint32_t;
  94243. typedef long long ogg_int64_t;
  94244. #elif defined(R5900)
  94245. typedef long ogg_int64_t;
  94246. typedef int ogg_int32_t;
  94247. typedef unsigned ogg_uint32_t;
  94248. typedef short ogg_int16_t;
  94249. #elif defined(__SYMBIAN32__)
  94250. typedef signed short ogg_int16_t;
  94251. typedef unsigned short ogg_uint16_t;
  94252. typedef signed int ogg_int32_t;
  94253. typedef unsigned int ogg_uint32_t;
  94254. typedef long long int ogg_int64_t;
  94255. #else
  94256. # include <sys/types.h>
  94257. /*** Start of inlined file: config_types.h ***/
  94258. #ifndef __CONFIG_TYPES_H__
  94259. #define __CONFIG_TYPES_H__
  94260. typedef int16_t ogg_int16_t;
  94261. typedef unsigned short ogg_uint16_t;
  94262. typedef int32_t ogg_int32_t;
  94263. typedef unsigned int ogg_uint32_t;
  94264. typedef int64_t ogg_int64_t;
  94265. #endif
  94266. /*** End of inlined file: config_types.h ***/
  94267. #endif
  94268. #endif /* _OS_TYPES_H */
  94269. /*** End of inlined file: os_types.h ***/
  94270. typedef struct {
  94271. long endbyte;
  94272. int endbit;
  94273. unsigned char *buffer;
  94274. unsigned char *ptr;
  94275. long storage;
  94276. } oggpack_buffer;
  94277. typedef struct {
  94278. unsigned char *header;
  94279. long header_len;
  94280. unsigned char *body;
  94281. long body_len;
  94282. } ogg_page;
  94283. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94284. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94285. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94286. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94287. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94288. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94289. }
  94290. typedef struct {
  94291. unsigned char *body_data; /* bytes from packet bodies */
  94292. long body_storage; /* storage elements allocated */
  94293. long body_fill; /* elements stored; fill mark */
  94294. long body_returned; /* elements of fill returned */
  94295. int *lacing_vals; /* The values that will go to the segment table */
  94296. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94297. this way, but it is simple coupled to the
  94298. lacing fifo */
  94299. long lacing_storage;
  94300. long lacing_fill;
  94301. long lacing_packet;
  94302. long lacing_returned;
  94303. unsigned char header[282]; /* working space for header encode */
  94304. int header_fill;
  94305. int e_o_s; /* set when we have buffered the last packet in the
  94306. logical bitstream */
  94307. int b_o_s; /* set after we've written the initial page
  94308. of a logical bitstream */
  94309. long serialno;
  94310. long pageno;
  94311. ogg_int64_t packetno; /* sequence number for decode; the framing
  94312. knows where there's a hole in the data,
  94313. but we need coupling so that the codec
  94314. (which is in a seperate abstraction
  94315. layer) also knows about the gap */
  94316. ogg_int64_t granulepos;
  94317. } ogg_stream_state;
  94318. typedef struct {
  94319. unsigned char *packet;
  94320. long bytes;
  94321. long b_o_s;
  94322. long e_o_s;
  94323. ogg_int64_t granulepos;
  94324. ogg_int64_t packetno; /* sequence number for decode; the framing
  94325. knows where there's a hole in the data,
  94326. but we need coupling so that the codec
  94327. (which is in a seperate abstraction
  94328. layer) also knows about the gap */
  94329. } ogg_packet;
  94330. typedef struct {
  94331. unsigned char *data;
  94332. int storage;
  94333. int fill;
  94334. int returned;
  94335. int unsynced;
  94336. int headerbytes;
  94337. int bodybytes;
  94338. } ogg_sync_state;
  94339. extern void oggpack_writeinit(oggpack_buffer *b);
  94340. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94341. extern void oggpack_writealign(oggpack_buffer *b);
  94342. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94343. extern void oggpack_reset(oggpack_buffer *b);
  94344. extern void oggpack_writeclear(oggpack_buffer *b);
  94345. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94346. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94347. extern long oggpack_look(oggpack_buffer *b,int bits);
  94348. extern long oggpack_look1(oggpack_buffer *b);
  94349. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94350. extern void oggpack_adv1(oggpack_buffer *b);
  94351. extern long oggpack_read(oggpack_buffer *b,int bits);
  94352. extern long oggpack_read1(oggpack_buffer *b);
  94353. extern long oggpack_bytes(oggpack_buffer *b);
  94354. extern long oggpack_bits(oggpack_buffer *b);
  94355. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94356. extern void oggpackB_writeinit(oggpack_buffer *b);
  94357. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94358. extern void oggpackB_writealign(oggpack_buffer *b);
  94359. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94360. extern void oggpackB_reset(oggpack_buffer *b);
  94361. extern void oggpackB_writeclear(oggpack_buffer *b);
  94362. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94363. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94364. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94365. extern long oggpackB_look1(oggpack_buffer *b);
  94366. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94367. extern void oggpackB_adv1(oggpack_buffer *b);
  94368. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94369. extern long oggpackB_read1(oggpack_buffer *b);
  94370. extern long oggpackB_bytes(oggpack_buffer *b);
  94371. extern long oggpackB_bits(oggpack_buffer *b);
  94372. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94373. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94374. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94375. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94376. extern int ogg_sync_init(ogg_sync_state *oy);
  94377. extern int ogg_sync_clear(ogg_sync_state *oy);
  94378. extern int ogg_sync_reset(ogg_sync_state *oy);
  94379. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94380. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94381. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94382. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94383. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94384. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94385. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94386. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94387. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94388. extern int ogg_stream_clear(ogg_stream_state *os);
  94389. extern int ogg_stream_reset(ogg_stream_state *os);
  94390. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94391. extern int ogg_stream_destroy(ogg_stream_state *os);
  94392. extern int ogg_stream_eos(ogg_stream_state *os);
  94393. extern void ogg_page_checksum_set(ogg_page *og);
  94394. extern int ogg_page_version(ogg_page *og);
  94395. extern int ogg_page_continued(ogg_page *og);
  94396. extern int ogg_page_bos(ogg_page *og);
  94397. extern int ogg_page_eos(ogg_page *og);
  94398. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94399. extern int ogg_page_serialno(ogg_page *og);
  94400. extern long ogg_page_pageno(ogg_page *og);
  94401. extern int ogg_page_packets(ogg_page *og);
  94402. extern void ogg_packet_clear(ogg_packet *op);
  94403. #ifdef __cplusplus
  94404. }
  94405. #endif
  94406. #endif /* _OGG_H */
  94407. /*** End of inlined file: ogg.h ***/
  94408. typedef struct vorbis_info{
  94409. int version;
  94410. int channels;
  94411. long rate;
  94412. long bitrate_upper;
  94413. long bitrate_nominal;
  94414. long bitrate_lower;
  94415. long bitrate_window;
  94416. void *codec_setup;
  94417. } vorbis_info;
  94418. typedef struct vorbis_dsp_state{
  94419. int analysisp;
  94420. vorbis_info *vi;
  94421. float **pcm;
  94422. float **pcmret;
  94423. int pcm_storage;
  94424. int pcm_current;
  94425. int pcm_returned;
  94426. int preextrapolate;
  94427. int eofflag;
  94428. long lW;
  94429. long W;
  94430. long nW;
  94431. long centerW;
  94432. ogg_int64_t granulepos;
  94433. ogg_int64_t sequence;
  94434. ogg_int64_t glue_bits;
  94435. ogg_int64_t time_bits;
  94436. ogg_int64_t floor_bits;
  94437. ogg_int64_t res_bits;
  94438. void *backend_state;
  94439. } vorbis_dsp_state;
  94440. typedef struct vorbis_block{
  94441. float **pcm; /* this is a pointer into local storage */
  94442. oggpack_buffer opb;
  94443. long lW;
  94444. long W;
  94445. long nW;
  94446. int pcmend;
  94447. int mode;
  94448. int eofflag;
  94449. ogg_int64_t granulepos;
  94450. ogg_int64_t sequence;
  94451. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94452. void *localstore;
  94453. long localtop;
  94454. long localalloc;
  94455. long totaluse;
  94456. struct alloc_chain *reap;
  94457. long glue_bits;
  94458. long time_bits;
  94459. long floor_bits;
  94460. long res_bits;
  94461. void *internal;
  94462. } vorbis_block;
  94463. struct alloc_chain{
  94464. void *ptr;
  94465. struct alloc_chain *next;
  94466. };
  94467. typedef struct vorbis_comment{
  94468. char **user_comments;
  94469. int *comment_lengths;
  94470. int comments;
  94471. char *vendor;
  94472. } vorbis_comment;
  94473. extern void vorbis_info_init(vorbis_info *vi);
  94474. extern void vorbis_info_clear(vorbis_info *vi);
  94475. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94476. extern void vorbis_comment_init(vorbis_comment *vc);
  94477. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94478. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94479. const char *tag, char *contents);
  94480. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94481. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94482. extern void vorbis_comment_clear(vorbis_comment *vc);
  94483. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94484. extern int vorbis_block_clear(vorbis_block *vb);
  94485. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94486. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94487. ogg_int64_t granulepos);
  94488. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94489. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94490. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94491. vorbis_comment *vc,
  94492. ogg_packet *op,
  94493. ogg_packet *op_comm,
  94494. ogg_packet *op_code);
  94495. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94496. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94497. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94498. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94499. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94500. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94501. ogg_packet *op);
  94502. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94503. ogg_packet *op);
  94504. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94505. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94506. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94507. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94508. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94509. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94510. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94511. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94512. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94513. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94514. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94515. #define OV_FALSE -1
  94516. #define OV_EOF -2
  94517. #define OV_HOLE -3
  94518. #define OV_EREAD -128
  94519. #define OV_EFAULT -129
  94520. #define OV_EIMPL -130
  94521. #define OV_EINVAL -131
  94522. #define OV_ENOTVORBIS -132
  94523. #define OV_EBADHEADER -133
  94524. #define OV_EVERSION -134
  94525. #define OV_ENOTAUDIO -135
  94526. #define OV_EBADPACKET -136
  94527. #define OV_EBADLINK -137
  94528. #define OV_ENOSEEK -138
  94529. #ifdef __cplusplus
  94530. }
  94531. #endif /* __cplusplus */
  94532. #endif
  94533. /*** End of inlined file: codec.h ***/
  94534. extern int vorbis_encode_init(vorbis_info *vi,
  94535. long channels,
  94536. long rate,
  94537. long max_bitrate,
  94538. long nominal_bitrate,
  94539. long min_bitrate);
  94540. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94541. long channels,
  94542. long rate,
  94543. long max_bitrate,
  94544. long nominal_bitrate,
  94545. long min_bitrate);
  94546. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94547. long channels,
  94548. long rate,
  94549. float quality /* quality level from 0. (lo) to 1. (hi) */
  94550. );
  94551. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94552. long channels,
  94553. long rate,
  94554. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94555. );
  94556. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94557. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94558. #define OV_ECTL_RATEMANAGE_GET 0x10
  94559. #define OV_ECTL_RATEMANAGE_SET 0x11
  94560. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94561. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94562. struct ovectl_ratemanage_arg {
  94563. int management_active;
  94564. long bitrate_hard_min;
  94565. long bitrate_hard_max;
  94566. double bitrate_hard_window;
  94567. long bitrate_av_lo;
  94568. long bitrate_av_hi;
  94569. double bitrate_av_window;
  94570. double bitrate_av_window_center;
  94571. };
  94572. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94573. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94574. struct ovectl_ratemanage2_arg {
  94575. int management_active;
  94576. long bitrate_limit_min_kbps;
  94577. long bitrate_limit_max_kbps;
  94578. long bitrate_limit_reservoir_bits;
  94579. double bitrate_limit_reservoir_bias;
  94580. long bitrate_average_kbps;
  94581. double bitrate_average_damping;
  94582. };
  94583. #define OV_ECTL_LOWPASS_GET 0x20
  94584. #define OV_ECTL_LOWPASS_SET 0x21
  94585. #define OV_ECTL_IBLOCK_GET 0x30
  94586. #define OV_ECTL_IBLOCK_SET 0x31
  94587. #ifdef __cplusplus
  94588. }
  94589. #endif /* __cplusplus */
  94590. #endif
  94591. /*** End of inlined file: vorbisenc.h ***/
  94592. /*** Start of inlined file: vorbisfile.h ***/
  94593. #ifndef _OV_FILE_H_
  94594. #define _OV_FILE_H_
  94595. #ifdef __cplusplus
  94596. extern "C"
  94597. {
  94598. #endif /* __cplusplus */
  94599. #include <stdio.h>
  94600. typedef struct {
  94601. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94602. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94603. int (*close_func) (void *datasource);
  94604. long (*tell_func) (void *datasource);
  94605. } ov_callbacks;
  94606. #define NOTOPEN 0
  94607. #define PARTOPEN 1
  94608. #define OPENED 2
  94609. #define STREAMSET 3
  94610. #define INITSET 4
  94611. typedef struct OggVorbis_File {
  94612. void *datasource; /* Pointer to a FILE *, etc. */
  94613. int seekable;
  94614. ogg_int64_t offset;
  94615. ogg_int64_t end;
  94616. ogg_sync_state oy;
  94617. int links;
  94618. ogg_int64_t *offsets;
  94619. ogg_int64_t *dataoffsets;
  94620. long *serialnos;
  94621. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94622. compatability; x2 size, stores both
  94623. beginning and end values */
  94624. vorbis_info *vi;
  94625. vorbis_comment *vc;
  94626. ogg_int64_t pcm_offset;
  94627. int ready_state;
  94628. long current_serialno;
  94629. int current_link;
  94630. double bittrack;
  94631. double samptrack;
  94632. ogg_stream_state os; /* take physical pages, weld into a logical
  94633. stream of packets */
  94634. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94635. vorbis_block vb; /* local working space for packet->PCM decode */
  94636. ov_callbacks callbacks;
  94637. } OggVorbis_File;
  94638. extern int ov_clear(OggVorbis_File *vf);
  94639. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94640. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94641. char *initial, long ibytes, ov_callbacks callbacks);
  94642. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94643. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94644. char *initial, long ibytes, ov_callbacks callbacks);
  94645. extern int ov_test_open(OggVorbis_File *vf);
  94646. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94647. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94648. extern long ov_streams(OggVorbis_File *vf);
  94649. extern long ov_seekable(OggVorbis_File *vf);
  94650. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94651. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94652. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94653. extern double ov_time_total(OggVorbis_File *vf,int i);
  94654. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94655. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94656. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94657. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94658. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94659. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94660. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94661. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94662. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94663. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94664. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94665. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94666. extern double ov_time_tell(OggVorbis_File *vf);
  94667. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94668. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94669. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94670. int *bitstream);
  94671. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94672. int bigendianp,int word,int sgned,int *bitstream);
  94673. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94674. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94675. extern int ov_halfrate_p(OggVorbis_File *vf);
  94676. #ifdef __cplusplus
  94677. }
  94678. #endif /* __cplusplus */
  94679. #endif
  94680. /*** End of inlined file: vorbisfile.h ***/
  94681. /*** Start of inlined file: bitwise.c ***/
  94682. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94683. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94684. // tasks..
  94685. #if JUCE_MSVC
  94686. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94687. #endif
  94688. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94689. #if JUCE_USE_OGGVORBIS
  94690. #include <string.h>
  94691. #include <stdlib.h>
  94692. #define BUFFER_INCREMENT 256
  94693. static const unsigned long mask[]=
  94694. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94695. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94696. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94697. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94698. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94699. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94700. 0x3fffffff,0x7fffffff,0xffffffff };
  94701. static const unsigned int mask8B[]=
  94702. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94703. void oggpack_writeinit(oggpack_buffer *b){
  94704. memset(b,0,sizeof(*b));
  94705. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94706. b->buffer[0]='\0';
  94707. b->storage=BUFFER_INCREMENT;
  94708. }
  94709. void oggpackB_writeinit(oggpack_buffer *b){
  94710. oggpack_writeinit(b);
  94711. }
  94712. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94713. long bytes=bits>>3;
  94714. bits-=bytes*8;
  94715. b->ptr=b->buffer+bytes;
  94716. b->endbit=bits;
  94717. b->endbyte=bytes;
  94718. *b->ptr&=mask[bits];
  94719. }
  94720. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94721. long bytes=bits>>3;
  94722. bits-=bytes*8;
  94723. b->ptr=b->buffer+bytes;
  94724. b->endbit=bits;
  94725. b->endbyte=bytes;
  94726. *b->ptr&=mask8B[bits];
  94727. }
  94728. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94729. if(b->endbyte+4>=b->storage){
  94730. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94731. b->storage+=BUFFER_INCREMENT;
  94732. b->ptr=b->buffer+b->endbyte;
  94733. }
  94734. value&=mask[bits];
  94735. bits+=b->endbit;
  94736. b->ptr[0]|=value<<b->endbit;
  94737. if(bits>=8){
  94738. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94739. if(bits>=16){
  94740. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94741. if(bits>=24){
  94742. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94743. if(bits>=32){
  94744. if(b->endbit)
  94745. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94746. else
  94747. b->ptr[4]=0;
  94748. }
  94749. }
  94750. }
  94751. }
  94752. b->endbyte+=bits/8;
  94753. b->ptr+=bits/8;
  94754. b->endbit=bits&7;
  94755. }
  94756. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94757. if(b->endbyte+4>=b->storage){
  94758. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94759. b->storage+=BUFFER_INCREMENT;
  94760. b->ptr=b->buffer+b->endbyte;
  94761. }
  94762. value=(value&mask[bits])<<(32-bits);
  94763. bits+=b->endbit;
  94764. b->ptr[0]|=value>>(24+b->endbit);
  94765. if(bits>=8){
  94766. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94767. if(bits>=16){
  94768. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94769. if(bits>=24){
  94770. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94771. if(bits>=32){
  94772. if(b->endbit)
  94773. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94774. else
  94775. b->ptr[4]=0;
  94776. }
  94777. }
  94778. }
  94779. }
  94780. b->endbyte+=bits/8;
  94781. b->ptr+=bits/8;
  94782. b->endbit=bits&7;
  94783. }
  94784. void oggpack_writealign(oggpack_buffer *b){
  94785. int bits=8-b->endbit;
  94786. if(bits<8)
  94787. oggpack_write(b,0,bits);
  94788. }
  94789. void oggpackB_writealign(oggpack_buffer *b){
  94790. int bits=8-b->endbit;
  94791. if(bits<8)
  94792. oggpackB_write(b,0,bits);
  94793. }
  94794. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94795. void *source,
  94796. long bits,
  94797. void (*w)(oggpack_buffer *,
  94798. unsigned long,
  94799. int),
  94800. int msb){
  94801. unsigned char *ptr=(unsigned char *)source;
  94802. long bytes=bits/8;
  94803. bits-=bytes*8;
  94804. if(b->endbit){
  94805. int i;
  94806. for(i=0;i<bytes;i++)
  94807. w(b,(unsigned long)(ptr[i]),8);
  94808. }else{
  94809. if(b->endbyte+bytes+1>=b->storage){
  94810. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94811. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94812. b->ptr=b->buffer+b->endbyte;
  94813. }
  94814. memmove(b->ptr,source,bytes);
  94815. b->ptr+=bytes;
  94816. b->endbyte+=bytes;
  94817. *b->ptr=0;
  94818. }
  94819. if(bits){
  94820. if(msb)
  94821. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94822. else
  94823. w(b,(unsigned long)(ptr[bytes]),bits);
  94824. }
  94825. }
  94826. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94827. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94828. }
  94829. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94830. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94831. }
  94832. void oggpack_reset(oggpack_buffer *b){
  94833. b->ptr=b->buffer;
  94834. b->buffer[0]=0;
  94835. b->endbit=b->endbyte=0;
  94836. }
  94837. void oggpackB_reset(oggpack_buffer *b){
  94838. oggpack_reset(b);
  94839. }
  94840. void oggpack_writeclear(oggpack_buffer *b){
  94841. _ogg_free(b->buffer);
  94842. memset(b,0,sizeof(*b));
  94843. }
  94844. void oggpackB_writeclear(oggpack_buffer *b){
  94845. oggpack_writeclear(b);
  94846. }
  94847. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94848. memset(b,0,sizeof(*b));
  94849. b->buffer=b->ptr=buf;
  94850. b->storage=bytes;
  94851. }
  94852. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94853. oggpack_readinit(b,buf,bytes);
  94854. }
  94855. long oggpack_look(oggpack_buffer *b,int bits){
  94856. unsigned long ret;
  94857. unsigned long m=mask[bits];
  94858. bits+=b->endbit;
  94859. if(b->endbyte+4>=b->storage){
  94860. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94861. }
  94862. ret=b->ptr[0]>>b->endbit;
  94863. if(bits>8){
  94864. ret|=b->ptr[1]<<(8-b->endbit);
  94865. if(bits>16){
  94866. ret|=b->ptr[2]<<(16-b->endbit);
  94867. if(bits>24){
  94868. ret|=b->ptr[3]<<(24-b->endbit);
  94869. if(bits>32 && b->endbit)
  94870. ret|=b->ptr[4]<<(32-b->endbit);
  94871. }
  94872. }
  94873. }
  94874. return(m&ret);
  94875. }
  94876. long oggpackB_look(oggpack_buffer *b,int bits){
  94877. unsigned long ret;
  94878. int m=32-bits;
  94879. bits+=b->endbit;
  94880. if(b->endbyte+4>=b->storage){
  94881. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94882. }
  94883. ret=b->ptr[0]<<(24+b->endbit);
  94884. if(bits>8){
  94885. ret|=b->ptr[1]<<(16+b->endbit);
  94886. if(bits>16){
  94887. ret|=b->ptr[2]<<(8+b->endbit);
  94888. if(bits>24){
  94889. ret|=b->ptr[3]<<(b->endbit);
  94890. if(bits>32 && b->endbit)
  94891. ret|=b->ptr[4]>>(8-b->endbit);
  94892. }
  94893. }
  94894. }
  94895. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94896. }
  94897. long oggpack_look1(oggpack_buffer *b){
  94898. if(b->endbyte>=b->storage)return(-1);
  94899. return((b->ptr[0]>>b->endbit)&1);
  94900. }
  94901. long oggpackB_look1(oggpack_buffer *b){
  94902. if(b->endbyte>=b->storage)return(-1);
  94903. return((b->ptr[0]>>(7-b->endbit))&1);
  94904. }
  94905. void oggpack_adv(oggpack_buffer *b,int bits){
  94906. bits+=b->endbit;
  94907. b->ptr+=bits/8;
  94908. b->endbyte+=bits/8;
  94909. b->endbit=bits&7;
  94910. }
  94911. void oggpackB_adv(oggpack_buffer *b,int bits){
  94912. oggpack_adv(b,bits);
  94913. }
  94914. void oggpack_adv1(oggpack_buffer *b){
  94915. if(++(b->endbit)>7){
  94916. b->endbit=0;
  94917. b->ptr++;
  94918. b->endbyte++;
  94919. }
  94920. }
  94921. void oggpackB_adv1(oggpack_buffer *b){
  94922. oggpack_adv1(b);
  94923. }
  94924. long oggpack_read(oggpack_buffer *b,int bits){
  94925. long ret;
  94926. unsigned long m=mask[bits];
  94927. bits+=b->endbit;
  94928. if(b->endbyte+4>=b->storage){
  94929. ret=-1L;
  94930. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94931. }
  94932. ret=b->ptr[0]>>b->endbit;
  94933. if(bits>8){
  94934. ret|=b->ptr[1]<<(8-b->endbit);
  94935. if(bits>16){
  94936. ret|=b->ptr[2]<<(16-b->endbit);
  94937. if(bits>24){
  94938. ret|=b->ptr[3]<<(24-b->endbit);
  94939. if(bits>32 && b->endbit){
  94940. ret|=b->ptr[4]<<(32-b->endbit);
  94941. }
  94942. }
  94943. }
  94944. }
  94945. ret&=m;
  94946. overflow:
  94947. b->ptr+=bits/8;
  94948. b->endbyte+=bits/8;
  94949. b->endbit=bits&7;
  94950. return(ret);
  94951. }
  94952. long oggpackB_read(oggpack_buffer *b,int bits){
  94953. long ret;
  94954. long m=32-bits;
  94955. bits+=b->endbit;
  94956. if(b->endbyte+4>=b->storage){
  94957. ret=-1L;
  94958. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94959. }
  94960. ret=b->ptr[0]<<(24+b->endbit);
  94961. if(bits>8){
  94962. ret|=b->ptr[1]<<(16+b->endbit);
  94963. if(bits>16){
  94964. ret|=b->ptr[2]<<(8+b->endbit);
  94965. if(bits>24){
  94966. ret|=b->ptr[3]<<(b->endbit);
  94967. if(bits>32 && b->endbit)
  94968. ret|=b->ptr[4]>>(8-b->endbit);
  94969. }
  94970. }
  94971. }
  94972. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  94973. overflow:
  94974. b->ptr+=bits/8;
  94975. b->endbyte+=bits/8;
  94976. b->endbit=bits&7;
  94977. return(ret);
  94978. }
  94979. long oggpack_read1(oggpack_buffer *b){
  94980. long ret;
  94981. if(b->endbyte>=b->storage){
  94982. ret=-1L;
  94983. goto overflow;
  94984. }
  94985. ret=(b->ptr[0]>>b->endbit)&1;
  94986. overflow:
  94987. b->endbit++;
  94988. if(b->endbit>7){
  94989. b->endbit=0;
  94990. b->ptr++;
  94991. b->endbyte++;
  94992. }
  94993. return(ret);
  94994. }
  94995. long oggpackB_read1(oggpack_buffer *b){
  94996. long ret;
  94997. if(b->endbyte>=b->storage){
  94998. ret=-1L;
  94999. goto overflow;
  95000. }
  95001. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95002. overflow:
  95003. b->endbit++;
  95004. if(b->endbit>7){
  95005. b->endbit=0;
  95006. b->ptr++;
  95007. b->endbyte++;
  95008. }
  95009. return(ret);
  95010. }
  95011. long oggpack_bytes(oggpack_buffer *b){
  95012. return(b->endbyte+(b->endbit+7)/8);
  95013. }
  95014. long oggpack_bits(oggpack_buffer *b){
  95015. return(b->endbyte*8+b->endbit);
  95016. }
  95017. long oggpackB_bytes(oggpack_buffer *b){
  95018. return oggpack_bytes(b);
  95019. }
  95020. long oggpackB_bits(oggpack_buffer *b){
  95021. return oggpack_bits(b);
  95022. }
  95023. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95024. return(b->buffer);
  95025. }
  95026. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95027. return oggpack_get_buffer(b);
  95028. }
  95029. #ifdef _V_SELFTEST
  95030. #include <stdio.h>
  95031. static int ilog(unsigned int v){
  95032. int ret=0;
  95033. while(v){
  95034. ret++;
  95035. v>>=1;
  95036. }
  95037. return(ret);
  95038. }
  95039. oggpack_buffer o;
  95040. oggpack_buffer r;
  95041. void report(char *in){
  95042. fprintf(stderr,"%s",in);
  95043. exit(1);
  95044. }
  95045. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95046. long bytes,i;
  95047. unsigned char *buffer;
  95048. oggpack_reset(&o);
  95049. for(i=0;i<vals;i++)
  95050. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95051. buffer=oggpack_get_buffer(&o);
  95052. bytes=oggpack_bytes(&o);
  95053. if(bytes!=compsize)report("wrong number of bytes!\n");
  95054. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95055. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95056. report("wrote incorrect value!\n");
  95057. }
  95058. oggpack_readinit(&r,buffer,bytes);
  95059. for(i=0;i<vals;i++){
  95060. int tbit=bits?bits:ilog(b[i]);
  95061. if(oggpack_look(&r,tbit)==-1)
  95062. report("out of data!\n");
  95063. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95064. report("looked at incorrect value!\n");
  95065. if(tbit==1)
  95066. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95067. report("looked at single bit incorrect value!\n");
  95068. if(tbit==1){
  95069. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95070. report("read incorrect single bit value!\n");
  95071. }else{
  95072. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95073. report("read incorrect value!\n");
  95074. }
  95075. }
  95076. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95077. }
  95078. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95079. long bytes,i;
  95080. unsigned char *buffer;
  95081. oggpackB_reset(&o);
  95082. for(i=0;i<vals;i++)
  95083. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95084. buffer=oggpackB_get_buffer(&o);
  95085. bytes=oggpackB_bytes(&o);
  95086. if(bytes!=compsize)report("wrong number of bytes!\n");
  95087. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95088. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95089. report("wrote incorrect value!\n");
  95090. }
  95091. oggpackB_readinit(&r,buffer,bytes);
  95092. for(i=0;i<vals;i++){
  95093. int tbit=bits?bits:ilog(b[i]);
  95094. if(oggpackB_look(&r,tbit)==-1)
  95095. report("out of data!\n");
  95096. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95097. report("looked at incorrect value!\n");
  95098. if(tbit==1)
  95099. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95100. report("looked at single bit incorrect value!\n");
  95101. if(tbit==1){
  95102. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95103. report("read incorrect single bit value!\n");
  95104. }else{
  95105. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95106. report("read incorrect value!\n");
  95107. }
  95108. }
  95109. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95110. }
  95111. int main(void){
  95112. unsigned char *buffer;
  95113. long bytes,i;
  95114. static unsigned long testbuffer1[]=
  95115. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95116. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95117. int test1size=43;
  95118. static unsigned long testbuffer2[]=
  95119. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95120. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95121. 85525151,0,12321,1,349528352};
  95122. int test2size=21;
  95123. static unsigned long testbuffer3[]=
  95124. {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,
  95125. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95126. int test3size=56;
  95127. static unsigned long large[]=
  95128. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95129. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95130. 85525151,0,12321,1,2146528352};
  95131. int onesize=33;
  95132. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95133. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95134. 223,4};
  95135. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95136. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95137. 245,251,128};
  95138. int twosize=6;
  95139. static int two[6]={61,255,255,251,231,29};
  95140. static int twoB[6]={247,63,255,253,249,120};
  95141. int threesize=54;
  95142. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95143. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95144. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95145. 100,52,4,14,18,86,77,1};
  95146. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95147. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95148. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95149. 200,20,254,4,58,106,176,144,0};
  95150. int foursize=38;
  95151. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95152. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95153. 28,2,133,0,1};
  95154. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95155. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95156. 129,10,4,32};
  95157. int fivesize=45;
  95158. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95159. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95160. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95161. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95162. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95163. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95164. int sixsize=7;
  95165. static int six[7]={17,177,170,242,169,19,148};
  95166. static int sixB[7]={136,141,85,79,149,200,41};
  95167. oggpack_writeinit(&o);
  95168. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95169. cliptest(testbuffer1,test1size,0,one,onesize);
  95170. fprintf(stderr,"ok.");
  95171. fprintf(stderr,"\nNull bit call (LSb): ");
  95172. cliptest(testbuffer3,test3size,0,two,twosize);
  95173. fprintf(stderr,"ok.");
  95174. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95175. cliptest(testbuffer2,test2size,0,three,threesize);
  95176. fprintf(stderr,"ok.");
  95177. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95178. oggpack_reset(&o);
  95179. for(i=0;i<test2size;i++)
  95180. oggpack_write(&o,large[i],32);
  95181. buffer=oggpack_get_buffer(&o);
  95182. bytes=oggpack_bytes(&o);
  95183. oggpack_readinit(&r,buffer,bytes);
  95184. for(i=0;i<test2size;i++){
  95185. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95186. if(oggpack_look(&r,32)!=large[i]){
  95187. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95188. oggpack_look(&r,32),large[i]);
  95189. report("read incorrect value!\n");
  95190. }
  95191. oggpack_adv(&r,32);
  95192. }
  95193. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95194. fprintf(stderr,"ok.");
  95195. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95196. cliptest(testbuffer1,test1size,7,four,foursize);
  95197. fprintf(stderr,"ok.");
  95198. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95199. cliptest(testbuffer2,test2size,17,five,fivesize);
  95200. fprintf(stderr,"ok.");
  95201. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95202. cliptest(testbuffer3,test3size,1,six,sixsize);
  95203. fprintf(stderr,"ok.");
  95204. fprintf(stderr,"\nTesting read past end (LSb): ");
  95205. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95206. for(i=0;i<64;i++){
  95207. if(oggpack_read(&r,1)!=0){
  95208. fprintf(stderr,"failed; got -1 prematurely.\n");
  95209. exit(1);
  95210. }
  95211. }
  95212. if(oggpack_look(&r,1)!=-1 ||
  95213. oggpack_read(&r,1)!=-1){
  95214. fprintf(stderr,"failed; read past end without -1.\n");
  95215. exit(1);
  95216. }
  95217. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95218. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95219. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95220. exit(1);
  95221. }
  95222. if(oggpack_look(&r,18)!=0 ||
  95223. oggpack_look(&r,18)!=0){
  95224. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95225. exit(1);
  95226. }
  95227. if(oggpack_look(&r,19)!=-1 ||
  95228. oggpack_look(&r,19)!=-1){
  95229. fprintf(stderr,"failed; read past end without -1.\n");
  95230. exit(1);
  95231. }
  95232. if(oggpack_look(&r,32)!=-1 ||
  95233. oggpack_look(&r,32)!=-1){
  95234. fprintf(stderr,"failed; read past end without -1.\n");
  95235. exit(1);
  95236. }
  95237. oggpack_writeclear(&o);
  95238. fprintf(stderr,"ok.\n");
  95239. oggpackB_writeinit(&o);
  95240. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95241. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95242. fprintf(stderr,"ok.");
  95243. fprintf(stderr,"\nNull bit call (MSb): ");
  95244. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95245. fprintf(stderr,"ok.");
  95246. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95247. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95248. fprintf(stderr,"ok.");
  95249. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95250. oggpackB_reset(&o);
  95251. for(i=0;i<test2size;i++)
  95252. oggpackB_write(&o,large[i],32);
  95253. buffer=oggpackB_get_buffer(&o);
  95254. bytes=oggpackB_bytes(&o);
  95255. oggpackB_readinit(&r,buffer,bytes);
  95256. for(i=0;i<test2size;i++){
  95257. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95258. if(oggpackB_look(&r,32)!=large[i]){
  95259. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95260. oggpackB_look(&r,32),large[i]);
  95261. report("read incorrect value!\n");
  95262. }
  95263. oggpackB_adv(&r,32);
  95264. }
  95265. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95266. fprintf(stderr,"ok.");
  95267. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95268. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95269. fprintf(stderr,"ok.");
  95270. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95271. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95272. fprintf(stderr,"ok.");
  95273. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95274. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95275. fprintf(stderr,"ok.");
  95276. fprintf(stderr,"\nTesting read past end (MSb): ");
  95277. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95278. for(i=0;i<64;i++){
  95279. if(oggpackB_read(&r,1)!=0){
  95280. fprintf(stderr,"failed; got -1 prematurely.\n");
  95281. exit(1);
  95282. }
  95283. }
  95284. if(oggpackB_look(&r,1)!=-1 ||
  95285. oggpackB_read(&r,1)!=-1){
  95286. fprintf(stderr,"failed; read past end without -1.\n");
  95287. exit(1);
  95288. }
  95289. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95290. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95291. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95292. exit(1);
  95293. }
  95294. if(oggpackB_look(&r,18)!=0 ||
  95295. oggpackB_look(&r,18)!=0){
  95296. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95297. exit(1);
  95298. }
  95299. if(oggpackB_look(&r,19)!=-1 ||
  95300. oggpackB_look(&r,19)!=-1){
  95301. fprintf(stderr,"failed; read past end without -1.\n");
  95302. exit(1);
  95303. }
  95304. if(oggpackB_look(&r,32)!=-1 ||
  95305. oggpackB_look(&r,32)!=-1){
  95306. fprintf(stderr,"failed; read past end without -1.\n");
  95307. exit(1);
  95308. }
  95309. oggpackB_writeclear(&o);
  95310. fprintf(stderr,"ok.\n\n");
  95311. return(0);
  95312. }
  95313. #endif /* _V_SELFTEST */
  95314. #undef BUFFER_INCREMENT
  95315. #endif
  95316. /*** End of inlined file: bitwise.c ***/
  95317. /*** Start of inlined file: framing.c ***/
  95318. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95319. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95320. // tasks..
  95321. #if JUCE_MSVC
  95322. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95323. #endif
  95324. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95325. #if JUCE_USE_OGGVORBIS
  95326. #include <stdlib.h>
  95327. #include <string.h>
  95328. int ogg_page_version(ogg_page *og){
  95329. return((int)(og->header[4]));
  95330. }
  95331. int ogg_page_continued(ogg_page *og){
  95332. return((int)(og->header[5]&0x01));
  95333. }
  95334. int ogg_page_bos(ogg_page *og){
  95335. return((int)(og->header[5]&0x02));
  95336. }
  95337. int ogg_page_eos(ogg_page *og){
  95338. return((int)(og->header[5]&0x04));
  95339. }
  95340. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95341. unsigned char *page=og->header;
  95342. ogg_int64_t granulepos=page[13]&(0xff);
  95343. granulepos= (granulepos<<8)|(page[12]&0xff);
  95344. granulepos= (granulepos<<8)|(page[11]&0xff);
  95345. granulepos= (granulepos<<8)|(page[10]&0xff);
  95346. granulepos= (granulepos<<8)|(page[9]&0xff);
  95347. granulepos= (granulepos<<8)|(page[8]&0xff);
  95348. granulepos= (granulepos<<8)|(page[7]&0xff);
  95349. granulepos= (granulepos<<8)|(page[6]&0xff);
  95350. return(granulepos);
  95351. }
  95352. int ogg_page_serialno(ogg_page *og){
  95353. return(og->header[14] |
  95354. (og->header[15]<<8) |
  95355. (og->header[16]<<16) |
  95356. (og->header[17]<<24));
  95357. }
  95358. long ogg_page_pageno(ogg_page *og){
  95359. return(og->header[18] |
  95360. (og->header[19]<<8) |
  95361. (og->header[20]<<16) |
  95362. (og->header[21]<<24));
  95363. }
  95364. int ogg_page_packets(ogg_page *og){
  95365. int i,n=og->header[26],count=0;
  95366. for(i=0;i<n;i++)
  95367. if(og->header[27+i]<255)count++;
  95368. return(count);
  95369. }
  95370. #if 0
  95371. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95372. int i;
  95373. unsigned long r;
  95374. r = index << 24;
  95375. for (i=0; i<8; i++)
  95376. if (r & 0x80000000UL)
  95377. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95378. polynomial, although we use an
  95379. unreflected alg and an init/final
  95380. of 0, not 0xffffffff */
  95381. else
  95382. r<<=1;
  95383. return (r & 0xffffffffUL);
  95384. }
  95385. #endif
  95386. static const ogg_uint32_t crc_lookup[256]={
  95387. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95388. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95389. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95390. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95391. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95392. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95393. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95394. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95395. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95396. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95397. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95398. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95399. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95400. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95401. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95402. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95403. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95404. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95405. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95406. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95407. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95408. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95409. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95410. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95411. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95412. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95413. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95414. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95415. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95416. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95417. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95418. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95419. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95420. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95421. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95422. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95423. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95424. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95425. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95426. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95427. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95428. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95429. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95430. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95431. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95432. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95433. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95434. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95435. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95436. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95437. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95438. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95439. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95440. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95441. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95442. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95443. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95444. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95445. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95446. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95447. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95448. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95449. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95450. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95451. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95452. if(os){
  95453. memset(os,0,sizeof(*os));
  95454. os->body_storage=16*1024;
  95455. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95456. os->lacing_storage=1024;
  95457. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95458. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95459. os->serialno=serialno;
  95460. return(0);
  95461. }
  95462. return(-1);
  95463. }
  95464. int ogg_stream_clear(ogg_stream_state *os){
  95465. if(os){
  95466. if(os->body_data)_ogg_free(os->body_data);
  95467. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95468. if(os->granule_vals)_ogg_free(os->granule_vals);
  95469. memset(os,0,sizeof(*os));
  95470. }
  95471. return(0);
  95472. }
  95473. int ogg_stream_destroy(ogg_stream_state *os){
  95474. if(os){
  95475. ogg_stream_clear(os);
  95476. _ogg_free(os);
  95477. }
  95478. return(0);
  95479. }
  95480. static void _os_body_expand(ogg_stream_state *os,int needed){
  95481. if(os->body_storage<=os->body_fill+needed){
  95482. os->body_storage+=(needed+1024);
  95483. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95484. }
  95485. }
  95486. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95487. if(os->lacing_storage<=os->lacing_fill+needed){
  95488. os->lacing_storage+=(needed+32);
  95489. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95490. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95491. }
  95492. }
  95493. void ogg_page_checksum_set(ogg_page *og){
  95494. if(og){
  95495. ogg_uint32_t crc_reg=0;
  95496. int i;
  95497. og->header[22]=0;
  95498. og->header[23]=0;
  95499. og->header[24]=0;
  95500. og->header[25]=0;
  95501. for(i=0;i<og->header_len;i++)
  95502. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95503. for(i=0;i<og->body_len;i++)
  95504. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95505. og->header[22]=(unsigned char)(crc_reg&0xff);
  95506. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95507. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95508. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95509. }
  95510. }
  95511. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95512. int lacing_vals=op->bytes/255+1,i;
  95513. if(os->body_returned){
  95514. os->body_fill-=os->body_returned;
  95515. if(os->body_fill)
  95516. memmove(os->body_data,os->body_data+os->body_returned,
  95517. os->body_fill);
  95518. os->body_returned=0;
  95519. }
  95520. _os_body_expand(os,op->bytes);
  95521. _os_lacing_expand(os,lacing_vals);
  95522. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95523. os->body_fill+=op->bytes;
  95524. for(i=0;i<lacing_vals-1;i++){
  95525. os->lacing_vals[os->lacing_fill+i]=255;
  95526. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95527. }
  95528. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95529. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95530. os->lacing_vals[os->lacing_fill]|= 0x100;
  95531. os->lacing_fill+=lacing_vals;
  95532. os->packetno++;
  95533. if(op->e_o_s)os->e_o_s=1;
  95534. return(0);
  95535. }
  95536. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95537. int i;
  95538. int vals=0;
  95539. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95540. int bytes=0;
  95541. long acc=0;
  95542. ogg_int64_t granule_pos=-1;
  95543. if(maxvals==0)return(0);
  95544. if(os->b_o_s==0){ /* 'initial header page' case */
  95545. granule_pos=0;
  95546. for(vals=0;vals<maxvals;vals++){
  95547. if((os->lacing_vals[vals]&0x0ff)<255){
  95548. vals++;
  95549. break;
  95550. }
  95551. }
  95552. }else{
  95553. for(vals=0;vals<maxvals;vals++){
  95554. if(acc>4096)break;
  95555. acc+=os->lacing_vals[vals]&0x0ff;
  95556. if((os->lacing_vals[vals]&0xff)<255)
  95557. granule_pos=os->granule_vals[vals];
  95558. }
  95559. }
  95560. memcpy(os->header,"OggS",4);
  95561. os->header[4]=0x00;
  95562. os->header[5]=0x00;
  95563. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95564. if(os->b_o_s==0)os->header[5]|=0x02;
  95565. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95566. os->b_o_s=1;
  95567. for(i=6;i<14;i++){
  95568. os->header[i]=(unsigned char)(granule_pos&0xff);
  95569. granule_pos>>=8;
  95570. }
  95571. {
  95572. long serialno=os->serialno;
  95573. for(i=14;i<18;i++){
  95574. os->header[i]=(unsigned char)(serialno&0xff);
  95575. serialno>>=8;
  95576. }
  95577. }
  95578. if(os->pageno==-1)os->pageno=0; /* because someone called
  95579. stream_reset; this would be a
  95580. strange thing to do in an
  95581. encode stream, but it has
  95582. plausible uses */
  95583. {
  95584. long pageno=os->pageno++;
  95585. for(i=18;i<22;i++){
  95586. os->header[i]=(unsigned char)(pageno&0xff);
  95587. pageno>>=8;
  95588. }
  95589. }
  95590. os->header[22]=0;
  95591. os->header[23]=0;
  95592. os->header[24]=0;
  95593. os->header[25]=0;
  95594. os->header[26]=(unsigned char)(vals&0xff);
  95595. for(i=0;i<vals;i++)
  95596. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95597. og->header=os->header;
  95598. og->header_len=os->header_fill=vals+27;
  95599. og->body=os->body_data+os->body_returned;
  95600. og->body_len=bytes;
  95601. os->lacing_fill-=vals;
  95602. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95603. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95604. os->body_returned+=bytes;
  95605. ogg_page_checksum_set(og);
  95606. return(1);
  95607. }
  95608. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95609. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95610. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95611. os->lacing_fill>=255 || /* 'segment table full' case */
  95612. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95613. return(ogg_stream_flush(os,og));
  95614. }
  95615. return(0);
  95616. }
  95617. int ogg_stream_eos(ogg_stream_state *os){
  95618. return os->e_o_s;
  95619. }
  95620. int ogg_sync_init(ogg_sync_state *oy){
  95621. if(oy){
  95622. memset(oy,0,sizeof(*oy));
  95623. }
  95624. return(0);
  95625. }
  95626. int ogg_sync_clear(ogg_sync_state *oy){
  95627. if(oy){
  95628. if(oy->data)_ogg_free(oy->data);
  95629. ogg_sync_init(oy);
  95630. }
  95631. return(0);
  95632. }
  95633. int ogg_sync_destroy(ogg_sync_state *oy){
  95634. if(oy){
  95635. ogg_sync_clear(oy);
  95636. _ogg_free(oy);
  95637. }
  95638. return(0);
  95639. }
  95640. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95641. if(oy->returned){
  95642. oy->fill-=oy->returned;
  95643. if(oy->fill>0)
  95644. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95645. oy->returned=0;
  95646. }
  95647. if(size>oy->storage-oy->fill){
  95648. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95649. if(oy->data)
  95650. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95651. else
  95652. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95653. oy->storage=newsize;
  95654. }
  95655. return((char *)oy->data+oy->fill);
  95656. }
  95657. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95658. if(oy->fill+bytes>oy->storage)return(-1);
  95659. oy->fill+=bytes;
  95660. return(0);
  95661. }
  95662. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95663. unsigned char *page=oy->data+oy->returned;
  95664. unsigned char *next;
  95665. long bytes=oy->fill-oy->returned;
  95666. if(oy->headerbytes==0){
  95667. int headerbytes,i;
  95668. if(bytes<27)return(0); /* not enough for a header */
  95669. if(memcmp(page,"OggS",4))goto sync_fail;
  95670. headerbytes=page[26]+27;
  95671. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95672. for(i=0;i<page[26];i++)
  95673. oy->bodybytes+=page[27+i];
  95674. oy->headerbytes=headerbytes;
  95675. }
  95676. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95677. {
  95678. char chksum[4];
  95679. ogg_page log;
  95680. memcpy(chksum,page+22,4);
  95681. memset(page+22,0,4);
  95682. log.header=page;
  95683. log.header_len=oy->headerbytes;
  95684. log.body=page+oy->headerbytes;
  95685. log.body_len=oy->bodybytes;
  95686. ogg_page_checksum_set(&log);
  95687. if(memcmp(chksum,page+22,4)){
  95688. memcpy(page+22,chksum,4);
  95689. goto sync_fail;
  95690. }
  95691. }
  95692. {
  95693. unsigned char *page=oy->data+oy->returned;
  95694. long bytes;
  95695. if(og){
  95696. og->header=page;
  95697. og->header_len=oy->headerbytes;
  95698. og->body=page+oy->headerbytes;
  95699. og->body_len=oy->bodybytes;
  95700. }
  95701. oy->unsynced=0;
  95702. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95703. oy->headerbytes=0;
  95704. oy->bodybytes=0;
  95705. return(bytes);
  95706. }
  95707. sync_fail:
  95708. oy->headerbytes=0;
  95709. oy->bodybytes=0;
  95710. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95711. if(!next)
  95712. next=oy->data+oy->fill;
  95713. oy->returned=next-oy->data;
  95714. return(-(next-page));
  95715. }
  95716. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95717. for(;;){
  95718. long ret=ogg_sync_pageseek(oy,og);
  95719. if(ret>0){
  95720. return(1);
  95721. }
  95722. if(ret==0){
  95723. return(0);
  95724. }
  95725. if(!oy->unsynced){
  95726. oy->unsynced=1;
  95727. return(-1);
  95728. }
  95729. }
  95730. }
  95731. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95732. unsigned char *header=og->header;
  95733. unsigned char *body=og->body;
  95734. long bodysize=og->body_len;
  95735. int segptr=0;
  95736. int version=ogg_page_version(og);
  95737. int continued=ogg_page_continued(og);
  95738. int bos=ogg_page_bos(og);
  95739. int eos=ogg_page_eos(og);
  95740. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95741. int serialno=ogg_page_serialno(og);
  95742. long pageno=ogg_page_pageno(og);
  95743. int segments=header[26];
  95744. {
  95745. long lr=os->lacing_returned;
  95746. long br=os->body_returned;
  95747. if(br){
  95748. os->body_fill-=br;
  95749. if(os->body_fill)
  95750. memmove(os->body_data,os->body_data+br,os->body_fill);
  95751. os->body_returned=0;
  95752. }
  95753. if(lr){
  95754. if(os->lacing_fill-lr){
  95755. memmove(os->lacing_vals,os->lacing_vals+lr,
  95756. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95757. memmove(os->granule_vals,os->granule_vals+lr,
  95758. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95759. }
  95760. os->lacing_fill-=lr;
  95761. os->lacing_packet-=lr;
  95762. os->lacing_returned=0;
  95763. }
  95764. }
  95765. if(serialno!=os->serialno)return(-1);
  95766. if(version>0)return(-1);
  95767. _os_lacing_expand(os,segments+1);
  95768. if(pageno!=os->pageno){
  95769. int i;
  95770. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95771. os->body_fill-=os->lacing_vals[i]&0xff;
  95772. os->lacing_fill=os->lacing_packet;
  95773. if(os->pageno!=-1){
  95774. os->lacing_vals[os->lacing_fill++]=0x400;
  95775. os->lacing_packet++;
  95776. }
  95777. }
  95778. if(continued){
  95779. if(os->lacing_fill<1 ||
  95780. os->lacing_vals[os->lacing_fill-1]==0x400){
  95781. bos=0;
  95782. for(;segptr<segments;segptr++){
  95783. int val=header[27+segptr];
  95784. body+=val;
  95785. bodysize-=val;
  95786. if(val<255){
  95787. segptr++;
  95788. break;
  95789. }
  95790. }
  95791. }
  95792. }
  95793. if(bodysize){
  95794. _os_body_expand(os,bodysize);
  95795. memcpy(os->body_data+os->body_fill,body,bodysize);
  95796. os->body_fill+=bodysize;
  95797. }
  95798. {
  95799. int saved=-1;
  95800. while(segptr<segments){
  95801. int val=header[27+segptr];
  95802. os->lacing_vals[os->lacing_fill]=val;
  95803. os->granule_vals[os->lacing_fill]=-1;
  95804. if(bos){
  95805. os->lacing_vals[os->lacing_fill]|=0x100;
  95806. bos=0;
  95807. }
  95808. if(val<255)saved=os->lacing_fill;
  95809. os->lacing_fill++;
  95810. segptr++;
  95811. if(val<255)os->lacing_packet=os->lacing_fill;
  95812. }
  95813. if(saved!=-1){
  95814. os->granule_vals[saved]=granulepos;
  95815. }
  95816. }
  95817. if(eos){
  95818. os->e_o_s=1;
  95819. if(os->lacing_fill>0)
  95820. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95821. }
  95822. os->pageno=pageno+1;
  95823. return(0);
  95824. }
  95825. int ogg_sync_reset(ogg_sync_state *oy){
  95826. oy->fill=0;
  95827. oy->returned=0;
  95828. oy->unsynced=0;
  95829. oy->headerbytes=0;
  95830. oy->bodybytes=0;
  95831. return(0);
  95832. }
  95833. int ogg_stream_reset(ogg_stream_state *os){
  95834. os->body_fill=0;
  95835. os->body_returned=0;
  95836. os->lacing_fill=0;
  95837. os->lacing_packet=0;
  95838. os->lacing_returned=0;
  95839. os->header_fill=0;
  95840. os->e_o_s=0;
  95841. os->b_o_s=0;
  95842. os->pageno=-1;
  95843. os->packetno=0;
  95844. os->granulepos=0;
  95845. return(0);
  95846. }
  95847. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95848. ogg_stream_reset(os);
  95849. os->serialno=serialno;
  95850. return(0);
  95851. }
  95852. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95853. int ptr=os->lacing_returned;
  95854. if(os->lacing_packet<=ptr)return(0);
  95855. if(os->lacing_vals[ptr]&0x400){
  95856. os->lacing_returned++;
  95857. os->packetno++;
  95858. return(-1);
  95859. }
  95860. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95861. to ask if there's a whole packet
  95862. waiting */
  95863. {
  95864. int size=os->lacing_vals[ptr]&0xff;
  95865. int bytes=size;
  95866. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95867. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95868. while(size==255){
  95869. int val=os->lacing_vals[++ptr];
  95870. size=val&0xff;
  95871. if(val&0x200)eos=0x200;
  95872. bytes+=size;
  95873. }
  95874. if(op){
  95875. op->e_o_s=eos;
  95876. op->b_o_s=bos;
  95877. op->packet=os->body_data+os->body_returned;
  95878. op->packetno=os->packetno;
  95879. op->granulepos=os->granule_vals[ptr];
  95880. op->bytes=bytes;
  95881. }
  95882. if(adv){
  95883. os->body_returned+=bytes;
  95884. os->lacing_returned=ptr+1;
  95885. os->packetno++;
  95886. }
  95887. }
  95888. return(1);
  95889. }
  95890. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95891. return _packetout(os,op,1);
  95892. }
  95893. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95894. return _packetout(os,op,0);
  95895. }
  95896. void ogg_packet_clear(ogg_packet *op) {
  95897. _ogg_free(op->packet);
  95898. memset(op, 0, sizeof(*op));
  95899. }
  95900. #ifdef _V_SELFTEST
  95901. #include <stdio.h>
  95902. ogg_stream_state os_en, os_de;
  95903. ogg_sync_state oy;
  95904. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95905. long j;
  95906. static int sequence=0;
  95907. static int lastno=0;
  95908. if(op->bytes!=len){
  95909. fprintf(stderr,"incorrect packet length!\n");
  95910. exit(1);
  95911. }
  95912. if(op->granulepos!=pos){
  95913. fprintf(stderr,"incorrect packet position!\n");
  95914. exit(1);
  95915. }
  95916. if(no==0){
  95917. sequence=0;
  95918. }else{
  95919. sequence++;
  95920. if(no>lastno+1)
  95921. sequence++;
  95922. }
  95923. lastno=no;
  95924. if(op->packetno!=sequence){
  95925. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95926. (long)(op->packetno),sequence);
  95927. exit(1);
  95928. }
  95929. for(j=0;j<op->bytes;j++)
  95930. if(op->packet[j]!=((j+no)&0xff)){
  95931. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  95932. j,op->packet[j],(j+no)&0xff);
  95933. exit(1);
  95934. }
  95935. }
  95936. void check_page(unsigned char *data,const int *header,ogg_page *og){
  95937. long j;
  95938. for(j=0;j<og->body_len;j++)
  95939. if(og->body[j]!=data[j]){
  95940. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  95941. j,data[j],og->body[j]);
  95942. exit(1);
  95943. }
  95944. for(j=0;j<og->header_len;j++){
  95945. if(og->header[j]!=header[j]){
  95946. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  95947. for(j=0;j<header[26]+27;j++)
  95948. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  95949. fprintf(stderr,"\n");
  95950. exit(1);
  95951. }
  95952. }
  95953. if(og->header_len!=header[26]+27){
  95954. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  95955. og->header_len,header[26]+27);
  95956. exit(1);
  95957. }
  95958. }
  95959. void print_header(ogg_page *og){
  95960. int j;
  95961. fprintf(stderr,"\nHEADER:\n");
  95962. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  95963. og->header[0],og->header[1],og->header[2],og->header[3],
  95964. (int)og->header[4],(int)og->header[5]);
  95965. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  95966. (og->header[9]<<24)|(og->header[8]<<16)|
  95967. (og->header[7]<<8)|og->header[6],
  95968. (og->header[17]<<24)|(og->header[16]<<16)|
  95969. (og->header[15]<<8)|og->header[14],
  95970. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  95971. (og->header[19]<<8)|og->header[18]);
  95972. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  95973. (int)og->header[22],(int)og->header[23],
  95974. (int)og->header[24],(int)og->header[25],
  95975. (int)og->header[26]);
  95976. for(j=27;j<og->header_len;j++)
  95977. fprintf(stderr,"%d ",(int)og->header[j]);
  95978. fprintf(stderr,")\n\n");
  95979. }
  95980. void copy_page(ogg_page *og){
  95981. unsigned char *temp=_ogg_malloc(og->header_len);
  95982. memcpy(temp,og->header,og->header_len);
  95983. og->header=temp;
  95984. temp=_ogg_malloc(og->body_len);
  95985. memcpy(temp,og->body,og->body_len);
  95986. og->body=temp;
  95987. }
  95988. void free_page(ogg_page *og){
  95989. _ogg_free (og->header);
  95990. _ogg_free (og->body);
  95991. }
  95992. void error(void){
  95993. fprintf(stderr,"error!\n");
  95994. exit(1);
  95995. }
  95996. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  95997. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95998. 0x01,0x02,0x03,0x04,0,0,0,0,
  95999. 0x15,0xed,0xec,0x91,
  96000. 1,
  96001. 17};
  96002. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96003. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96004. 0x01,0x02,0x03,0x04,0,0,0,0,
  96005. 0x59,0x10,0x6c,0x2c,
  96006. 1,
  96007. 17};
  96008. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96009. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96010. 0x01,0x02,0x03,0x04,1,0,0,0,
  96011. 0x89,0x33,0x85,0xce,
  96012. 13,
  96013. 254,255,0,255,1,255,245,255,255,0,
  96014. 255,255,90};
  96015. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96016. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96017. 0x01,0x02,0x03,0x04,0,0,0,0,
  96018. 0xff,0x7b,0x23,0x17,
  96019. 1,
  96020. 0};
  96021. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96022. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96023. 0x01,0x02,0x03,0x04,1,0,0,0,
  96024. 0x5c,0x3f,0x66,0xcb,
  96025. 17,
  96026. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96027. 255,255,90,0};
  96028. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96029. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96030. 0x01,0x02,0x03,0x04,0,0,0,0,
  96031. 0x01,0x27,0x31,0xaa,
  96032. 18,
  96033. 255,255,255,255,255,255,255,255,
  96034. 255,255,255,255,255,255,255,255,255,10};
  96035. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96036. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96037. 0x01,0x02,0x03,0x04,1,0,0,0,
  96038. 0x7f,0x4e,0x8a,0xd2,
  96039. 4,
  96040. 255,4,255,0};
  96041. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96042. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96043. 0x01,0x02,0x03,0x04,0,0,0,0,
  96044. 0xff,0x7b,0x23,0x17,
  96045. 1,
  96046. 0};
  96047. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96048. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96049. 0x01,0x02,0x03,0x04,1,0,0,0,
  96050. 0x54,0x05,0x51,0xc8,
  96051. 17,
  96052. 255,255,255,255,255,255,255,255,
  96053. 255,255,255,255,255,255,255,255,255};
  96054. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96055. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96056. 0x01,0x02,0x03,0x04,2,0,0,0,
  96057. 0xc8,0xc3,0xcb,0xed,
  96058. 5,
  96059. 10,255,4,255,0};
  96060. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96061. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96062. 0x01,0x02,0x03,0x04,0,0,0,0,
  96063. 0xff,0x7b,0x23,0x17,
  96064. 1,
  96065. 0};
  96066. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96067. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96068. 0x01,0x02,0x03,0x04,1,0,0,0,
  96069. 0xed,0x2a,0x2e,0xa7,
  96070. 255,
  96071. 10,10,10,10,10,10,10,10,
  96072. 10,10,10,10,10,10,10,10,
  96073. 10,10,10,10,10,10,10,10,
  96074. 10,10,10,10,10,10,10,10,
  96075. 10,10,10,10,10,10,10,10,
  96076. 10,10,10,10,10,10,10,10,
  96077. 10,10,10,10,10,10,10,10,
  96078. 10,10,10,10,10,10,10,10,
  96079. 10,10,10,10,10,10,10,10,
  96080. 10,10,10,10,10,10,10,10,
  96081. 10,10,10,10,10,10,10,10,
  96082. 10,10,10,10,10,10,10,10,
  96083. 10,10,10,10,10,10,10,10,
  96084. 10,10,10,10,10,10,10,10,
  96085. 10,10,10,10,10,10,10,10,
  96086. 10,10,10,10,10,10,10,10,
  96087. 10,10,10,10,10,10,10,10,
  96088. 10,10,10,10,10,10,10,10,
  96089. 10,10,10,10,10,10,10,10,
  96090. 10,10,10,10,10,10,10,10,
  96091. 10,10,10,10,10,10,10,10,
  96092. 10,10,10,10,10,10,10,10,
  96093. 10,10,10,10,10,10,10,10,
  96094. 10,10,10,10,10,10,10,10,
  96095. 10,10,10,10,10,10,10,10,
  96096. 10,10,10,10,10,10,10,10,
  96097. 10,10,10,10,10,10,10,10,
  96098. 10,10,10,10,10,10,10,10,
  96099. 10,10,10,10,10,10,10,10,
  96100. 10,10,10,10,10,10,10,10,
  96101. 10,10,10,10,10,10,10,10,
  96102. 10,10,10,10,10,10,10};
  96103. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96104. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96105. 0x01,0x02,0x03,0x04,2,0,0,0,
  96106. 0x6c,0x3b,0x82,0x3d,
  96107. 1,
  96108. 50};
  96109. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96110. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96111. 0x01,0x02,0x03,0x04,0,0,0,0,
  96112. 0xff,0x7b,0x23,0x17,
  96113. 1,
  96114. 0};
  96115. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96116. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96117. 0x01,0x02,0x03,0x04,1,0,0,0,
  96118. 0x3c,0xd9,0x4d,0x3f,
  96119. 17,
  96120. 100,255,255,255,255,255,255,255,255,
  96121. 255,255,255,255,255,255,255,255};
  96122. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96123. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96124. 0x01,0x02,0x03,0x04,2,0,0,0,
  96125. 0x01,0xd2,0xe5,0xe5,
  96126. 17,
  96127. 255,255,255,255,255,255,255,255,
  96128. 255,255,255,255,255,255,255,255,255};
  96129. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96130. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96131. 0x01,0x02,0x03,0x04,3,0,0,0,
  96132. 0xef,0xdd,0x88,0xde,
  96133. 7,
  96134. 255,255,75,255,4,255,0};
  96135. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96136. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96137. 0x01,0x02,0x03,0x04,0,0,0,0,
  96138. 0xff,0x7b,0x23,0x17,
  96139. 1,
  96140. 0};
  96141. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96142. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96143. 0x01,0x02,0x03,0x04,1,0,0,0,
  96144. 0x3c,0xd9,0x4d,0x3f,
  96145. 17,
  96146. 100,255,255,255,255,255,255,255,255,
  96147. 255,255,255,255,255,255,255,255};
  96148. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96149. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96150. 0x01,0x02,0x03,0x04,2,0,0,0,
  96151. 0xd4,0xe0,0x60,0xe5,
  96152. 1,0};
  96153. void test_pack(const int *pl, const int **headers, int byteskip,
  96154. int pageskip, int packetskip){
  96155. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96156. long inptr=0;
  96157. long outptr=0;
  96158. long deptr=0;
  96159. long depacket=0;
  96160. long granule_pos=7,pageno=0;
  96161. int i,j,packets,pageout=pageskip;
  96162. int eosflag=0;
  96163. int bosflag=0;
  96164. int byteskipcount=0;
  96165. ogg_stream_reset(&os_en);
  96166. ogg_stream_reset(&os_de);
  96167. ogg_sync_reset(&oy);
  96168. for(packets=0;packets<packetskip;packets++)
  96169. depacket+=pl[packets];
  96170. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96171. for(i=0;i<packets;i++){
  96172. ogg_packet op;
  96173. int len=pl[i];
  96174. op.packet=data+inptr;
  96175. op.bytes=len;
  96176. op.e_o_s=(pl[i+1]<0?1:0);
  96177. op.granulepos=granule_pos;
  96178. granule_pos+=1024;
  96179. for(j=0;j<len;j++)data[inptr++]=i+j;
  96180. ogg_stream_packetin(&os_en,&op);
  96181. {
  96182. ogg_page og;
  96183. while(ogg_stream_pageout(&os_en,&og)){
  96184. fprintf(stderr,"%ld, ",pageno);
  96185. if(headers[pageno]==NULL){
  96186. fprintf(stderr,"coded too many pages!\n");
  96187. exit(1);
  96188. }
  96189. check_page(data+outptr,headers[pageno],&og);
  96190. outptr+=og.body_len;
  96191. pageno++;
  96192. if(pageskip){
  96193. bosflag=1;
  96194. pageskip--;
  96195. deptr+=og.body_len;
  96196. }
  96197. {
  96198. ogg_page og_de;
  96199. ogg_packet op_de,op_de2;
  96200. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96201. char *next=buf;
  96202. byteskipcount+=og.header_len;
  96203. if(byteskipcount>byteskip){
  96204. memcpy(next,og.header,byteskipcount-byteskip);
  96205. next+=byteskipcount-byteskip;
  96206. byteskipcount=byteskip;
  96207. }
  96208. byteskipcount+=og.body_len;
  96209. if(byteskipcount>byteskip){
  96210. memcpy(next,og.body,byteskipcount-byteskip);
  96211. next+=byteskipcount-byteskip;
  96212. byteskipcount=byteskip;
  96213. }
  96214. ogg_sync_wrote(&oy,next-buf);
  96215. while(1){
  96216. int ret=ogg_sync_pageout(&oy,&og_de);
  96217. if(ret==0)break;
  96218. if(ret<0)continue;
  96219. fprintf(stderr,"(%ld), ",pageout);
  96220. check_page(data+deptr,headers[pageout],&og_de);
  96221. deptr+=og_de.body_len;
  96222. pageout++;
  96223. ogg_stream_pagein(&os_de,&og_de);
  96224. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96225. ogg_stream_packetpeek(&os_de,NULL);
  96226. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96227. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96228. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96229. depacket);
  96230. exit(1);
  96231. }
  96232. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96233. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96234. depacket);
  96235. exit(1);
  96236. }
  96237. if(bosflag==0 && op_de.b_o_s==0){
  96238. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96239. exit(1);
  96240. }
  96241. if(bosflag && op_de.b_o_s){
  96242. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96243. exit(1);
  96244. }
  96245. bosflag=1;
  96246. depacket+=op_de.bytes;
  96247. if(eosflag){
  96248. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96249. exit(1);
  96250. }
  96251. if(op_de.e_o_s)eosflag=1;
  96252. if(op_de.granulepos!=-1){
  96253. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96254. }
  96255. }
  96256. }
  96257. }
  96258. }
  96259. }
  96260. }
  96261. _ogg_free(data);
  96262. if(headers[pageno]!=NULL){
  96263. fprintf(stderr,"did not write last page!\n");
  96264. exit(1);
  96265. }
  96266. if(headers[pageout]!=NULL){
  96267. fprintf(stderr,"did not decode last page!\n");
  96268. exit(1);
  96269. }
  96270. if(inptr!=outptr){
  96271. fprintf(stderr,"encoded page data incomplete!\n");
  96272. exit(1);
  96273. }
  96274. if(inptr!=deptr){
  96275. fprintf(stderr,"decoded page data incomplete!\n");
  96276. exit(1);
  96277. }
  96278. if(inptr!=depacket){
  96279. fprintf(stderr,"decoded packet data incomplete!\n");
  96280. exit(1);
  96281. }
  96282. if(!eosflag){
  96283. fprintf(stderr,"Never got a packet with EOS set!\n");
  96284. exit(1);
  96285. }
  96286. fprintf(stderr,"ok.\n");
  96287. }
  96288. int main(void){
  96289. ogg_stream_init(&os_en,0x04030201);
  96290. ogg_stream_init(&os_de,0x04030201);
  96291. ogg_sync_init(&oy);
  96292. {
  96293. const int packets[]={17, -1};
  96294. const int *headret[]={head1_0,NULL};
  96295. fprintf(stderr,"testing single page encoding... ");
  96296. test_pack(packets,headret,0,0,0);
  96297. }
  96298. {
  96299. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96300. const int *headret[]={head1_1,head2_1,NULL};
  96301. fprintf(stderr,"testing basic page encoding... ");
  96302. test_pack(packets,headret,0,0,0);
  96303. }
  96304. {
  96305. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96306. const int *headret[]={head1_2,head2_2,NULL};
  96307. fprintf(stderr,"testing basic nil packets... ");
  96308. test_pack(packets,headret,0,0,0);
  96309. }
  96310. {
  96311. const int packets[]={4345,259,255,-1};
  96312. const int *headret[]={head1_3,head2_3,NULL};
  96313. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96314. test_pack(packets,headret,0,0,0);
  96315. }
  96316. {
  96317. const int packets[]={0,4345,259,255,-1};
  96318. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96319. fprintf(stderr,"testing single packet page span... ");
  96320. test_pack(packets,headret,0,0,0);
  96321. }
  96322. {
  96323. const int packets[]={0,10,10,10,10,10,10,10,10,
  96324. 10,10,10,10,10,10,10,10,
  96325. 10,10,10,10,10,10,10,10,
  96326. 10,10,10,10,10,10,10,10,
  96327. 10,10,10,10,10,10,10,10,
  96328. 10,10,10,10,10,10,10,10,
  96329. 10,10,10,10,10,10,10,10,
  96330. 10,10,10,10,10,10,10,10,
  96331. 10,10,10,10,10,10,10,10,
  96332. 10,10,10,10,10,10,10,10,
  96333. 10,10,10,10,10,10,10,10,
  96334. 10,10,10,10,10,10,10,10,
  96335. 10,10,10,10,10,10,10,10,
  96336. 10,10,10,10,10,10,10,10,
  96337. 10,10,10,10,10,10,10,10,
  96338. 10,10,10,10,10,10,10,10,
  96339. 10,10,10,10,10,10,10,10,
  96340. 10,10,10,10,10,10,10,10,
  96341. 10,10,10,10,10,10,10,10,
  96342. 10,10,10,10,10,10,10,10,
  96343. 10,10,10,10,10,10,10,10,
  96344. 10,10,10,10,10,10,10,10,
  96345. 10,10,10,10,10,10,10,10,
  96346. 10,10,10,10,10,10,10,10,
  96347. 10,10,10,10,10,10,10,10,
  96348. 10,10,10,10,10,10,10,10,
  96349. 10,10,10,10,10,10,10,10,
  96350. 10,10,10,10,10,10,10,10,
  96351. 10,10,10,10,10,10,10,10,
  96352. 10,10,10,10,10,10,10,10,
  96353. 10,10,10,10,10,10,10,10,
  96354. 10,10,10,10,10,10,10,50,-1};
  96355. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96356. fprintf(stderr,"testing max packet segments... ");
  96357. test_pack(packets,headret,0,0,0);
  96358. }
  96359. {
  96360. const int packets[]={0,100,9000,259,255,-1};
  96361. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96362. fprintf(stderr,"testing very large packets... ");
  96363. test_pack(packets,headret,0,0,0);
  96364. }
  96365. {
  96366. const int packets[]={0,100,9000,259,255,-1};
  96367. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96368. fprintf(stderr,"testing continuation resync in very large packets... ");
  96369. test_pack(packets,headret,100,2,3);
  96370. }
  96371. {
  96372. const int packets[]={0,100,4080,-1};
  96373. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96374. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96375. test_pack(packets,headret,0,0,0);
  96376. }
  96377. {
  96378. unsigned char *data=_ogg_malloc(1024*1024);
  96379. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96380. int inptr=0,i,j;
  96381. ogg_page og[5];
  96382. ogg_stream_reset(&os_en);
  96383. for(i=0;pl[i]!=-1;i++){
  96384. ogg_packet op;
  96385. int len=pl[i];
  96386. op.packet=data+inptr;
  96387. op.bytes=len;
  96388. op.e_o_s=(pl[i+1]<0?1:0);
  96389. op.granulepos=(i+1)*1000;
  96390. for(j=0;j<len;j++)data[inptr++]=i+j;
  96391. ogg_stream_packetin(&os_en,&op);
  96392. }
  96393. _ogg_free(data);
  96394. for(i=0;i<5;i++){
  96395. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96396. fprintf(stderr,"Too few pages output building sync tests!\n");
  96397. exit(1);
  96398. }
  96399. copy_page(&og[i]);
  96400. }
  96401. {
  96402. ogg_page temp;
  96403. ogg_packet test;
  96404. fprintf(stderr,"Testing loss of pages... ");
  96405. ogg_sync_reset(&oy);
  96406. ogg_stream_reset(&os_de);
  96407. for(i=0;i<5;i++){
  96408. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96409. og[i].header_len);
  96410. ogg_sync_wrote(&oy,og[i].header_len);
  96411. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96412. ogg_sync_wrote(&oy,og[i].body_len);
  96413. }
  96414. ogg_sync_pageout(&oy,&temp);
  96415. ogg_stream_pagein(&os_de,&temp);
  96416. ogg_sync_pageout(&oy,&temp);
  96417. ogg_stream_pagein(&os_de,&temp);
  96418. ogg_sync_pageout(&oy,&temp);
  96419. ogg_sync_pageout(&oy,&temp);
  96420. ogg_stream_pagein(&os_de,&temp);
  96421. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96422. checkpacket(&test,0,0,0);
  96423. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96424. checkpacket(&test,100,1,-1);
  96425. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96426. checkpacket(&test,4079,2,3000);
  96427. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96428. fprintf(stderr,"Error: loss of page did not return error\n");
  96429. exit(1);
  96430. }
  96431. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96432. checkpacket(&test,76,5,-1);
  96433. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96434. checkpacket(&test,34,6,-1);
  96435. fprintf(stderr,"ok.\n");
  96436. }
  96437. {
  96438. ogg_page temp;
  96439. ogg_packet test;
  96440. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96441. ogg_sync_reset(&oy);
  96442. ogg_stream_reset(&os_de);
  96443. for(i=0;i<5;i++){
  96444. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96445. og[i].header_len);
  96446. ogg_sync_wrote(&oy,og[i].header_len);
  96447. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96448. ogg_sync_wrote(&oy,og[i].body_len);
  96449. }
  96450. ogg_sync_pageout(&oy,&temp);
  96451. ogg_stream_pagein(&os_de,&temp);
  96452. ogg_sync_pageout(&oy,&temp);
  96453. ogg_stream_pagein(&os_de,&temp);
  96454. ogg_sync_pageout(&oy,&temp);
  96455. ogg_stream_pagein(&os_de,&temp);
  96456. ogg_sync_pageout(&oy,&temp);
  96457. ogg_sync_pageout(&oy,&temp);
  96458. ogg_stream_pagein(&os_de,&temp);
  96459. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96460. checkpacket(&test,0,0,0);
  96461. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96462. checkpacket(&test,100,1,-1);
  96463. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96464. checkpacket(&test,4079,2,3000);
  96465. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96466. checkpacket(&test,2956,3,4000);
  96467. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96468. fprintf(stderr,"Error: loss of page did not return error\n");
  96469. exit(1);
  96470. }
  96471. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96472. checkpacket(&test,300,13,14000);
  96473. fprintf(stderr,"ok.\n");
  96474. }
  96475. {
  96476. ogg_page og_de;
  96477. fprintf(stderr,"Testing sync on partial inputs... ");
  96478. ogg_sync_reset(&oy);
  96479. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96480. 3);
  96481. ogg_sync_wrote(&oy,3);
  96482. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96483. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96484. 20);
  96485. ogg_sync_wrote(&oy,20);
  96486. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96487. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96488. 5);
  96489. ogg_sync_wrote(&oy,5);
  96490. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96491. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96492. og[1].header_len-28);
  96493. ogg_sync_wrote(&oy,og[1].header_len-28);
  96494. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96495. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96496. ogg_sync_wrote(&oy,1000);
  96497. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96498. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96499. og[1].body_len-1000);
  96500. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96501. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96502. fprintf(stderr,"ok.\n");
  96503. }
  96504. {
  96505. ogg_page og_de;
  96506. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96507. ogg_sync_reset(&oy);
  96508. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96509. og[1].header_len);
  96510. ogg_sync_wrote(&oy,og[1].header_len);
  96511. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96512. og[1].body_len);
  96513. ogg_sync_wrote(&oy,og[1].body_len);
  96514. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96515. 20);
  96516. ogg_sync_wrote(&oy,20);
  96517. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96518. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96519. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96520. og[1].header_len-20);
  96521. ogg_sync_wrote(&oy,og[1].header_len-20);
  96522. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96523. og[1].body_len);
  96524. ogg_sync_wrote(&oy,og[1].body_len);
  96525. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96526. fprintf(stderr,"ok.\n");
  96527. }
  96528. {
  96529. ogg_page og_de;
  96530. fprintf(stderr,"Testing search for capture... ");
  96531. ogg_sync_reset(&oy);
  96532. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96533. og[1].body_len);
  96534. ogg_sync_wrote(&oy,og[1].body_len);
  96535. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96536. og[1].header_len);
  96537. ogg_sync_wrote(&oy,og[1].header_len);
  96538. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96539. og[1].body_len);
  96540. ogg_sync_wrote(&oy,og[1].body_len);
  96541. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96542. 20);
  96543. ogg_sync_wrote(&oy,20);
  96544. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96545. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96546. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96547. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96548. og[2].header_len-20);
  96549. ogg_sync_wrote(&oy,og[2].header_len-20);
  96550. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96551. og[2].body_len);
  96552. ogg_sync_wrote(&oy,og[2].body_len);
  96553. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96554. fprintf(stderr,"ok.\n");
  96555. }
  96556. {
  96557. ogg_page og_de;
  96558. fprintf(stderr,"Testing recapture... ");
  96559. ogg_sync_reset(&oy);
  96560. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96561. og[1].header_len);
  96562. ogg_sync_wrote(&oy,og[1].header_len);
  96563. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96564. og[1].body_len);
  96565. ogg_sync_wrote(&oy,og[1].body_len);
  96566. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96567. og[2].header_len);
  96568. ogg_sync_wrote(&oy,og[2].header_len);
  96569. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96570. og[2].header_len);
  96571. ogg_sync_wrote(&oy,og[2].header_len);
  96572. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96573. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96574. og[2].body_len-5);
  96575. ogg_sync_wrote(&oy,og[2].body_len-5);
  96576. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96577. og[3].header_len);
  96578. ogg_sync_wrote(&oy,og[3].header_len);
  96579. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96580. og[3].body_len);
  96581. ogg_sync_wrote(&oy,og[3].body_len);
  96582. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96583. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96584. fprintf(stderr,"ok.\n");
  96585. }
  96586. {
  96587. for(i=0;i<5;i++){
  96588. free_page(&og[i]);
  96589. }
  96590. }
  96591. }
  96592. return(0);
  96593. }
  96594. #endif
  96595. #endif
  96596. /*** End of inlined file: framing.c ***/
  96597. /*** Start of inlined file: analysis.c ***/
  96598. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96599. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96600. // tasks..
  96601. #if JUCE_MSVC
  96602. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96603. #endif
  96604. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96605. #if JUCE_USE_OGGVORBIS
  96606. #include <stdio.h>
  96607. #include <string.h>
  96608. #include <math.h>
  96609. /*** Start of inlined file: codec_internal.h ***/
  96610. #ifndef _V_CODECI_H_
  96611. #define _V_CODECI_H_
  96612. /*** Start of inlined file: envelope.h ***/
  96613. #ifndef _V_ENVELOPE_
  96614. #define _V_ENVELOPE_
  96615. /*** Start of inlined file: mdct.h ***/
  96616. #ifndef _OGG_mdct_H_
  96617. #define _OGG_mdct_H_
  96618. #ifdef MDCT_INTEGERIZED
  96619. #define DATA_TYPE int
  96620. #define REG_TYPE register int
  96621. #define TRIGBITS 14
  96622. #define cPI3_8 6270
  96623. #define cPI2_8 11585
  96624. #define cPI1_8 15137
  96625. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96626. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96627. #define HALVE(x) ((x)>>1)
  96628. #else
  96629. #define DATA_TYPE float
  96630. #define REG_TYPE float
  96631. #define cPI3_8 .38268343236508977175F
  96632. #define cPI2_8 .70710678118654752441F
  96633. #define cPI1_8 .92387953251128675613F
  96634. #define FLOAT_CONV(x) (x)
  96635. #define MULT_NORM(x) (x)
  96636. #define HALVE(x) ((x)*.5f)
  96637. #endif
  96638. typedef struct {
  96639. int n;
  96640. int log2n;
  96641. DATA_TYPE *trig;
  96642. int *bitrev;
  96643. DATA_TYPE scale;
  96644. } mdct_lookup;
  96645. extern void mdct_init(mdct_lookup *lookup,int n);
  96646. extern void mdct_clear(mdct_lookup *l);
  96647. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96648. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96649. #endif
  96650. /*** End of inlined file: mdct.h ***/
  96651. #define VE_PRE 16
  96652. #define VE_WIN 4
  96653. #define VE_POST 2
  96654. #define VE_AMP (VE_PRE+VE_POST-1)
  96655. #define VE_BANDS 7
  96656. #define VE_NEARDC 15
  96657. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96658. #define VE_MAXSTRETCH 12 /* one-third full block */
  96659. typedef struct {
  96660. float ampbuf[VE_AMP];
  96661. int ampptr;
  96662. float nearDC[VE_NEARDC];
  96663. float nearDC_acc;
  96664. float nearDC_partialacc;
  96665. int nearptr;
  96666. } envelope_filter_state;
  96667. typedef struct {
  96668. int begin;
  96669. int end;
  96670. float *window;
  96671. float total;
  96672. } envelope_band;
  96673. typedef struct {
  96674. int ch;
  96675. int winlength;
  96676. int searchstep;
  96677. float minenergy;
  96678. mdct_lookup mdct;
  96679. float *mdct_win;
  96680. envelope_band band[VE_BANDS];
  96681. envelope_filter_state *filter;
  96682. int stretch;
  96683. int *mark;
  96684. long storage;
  96685. long current;
  96686. long curmark;
  96687. long cursor;
  96688. } envelope_lookup;
  96689. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96690. extern void _ve_envelope_clear(envelope_lookup *e);
  96691. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96692. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96693. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96694. #endif
  96695. /*** End of inlined file: envelope.h ***/
  96696. /*** Start of inlined file: codebook.h ***/
  96697. #ifndef _V_CODEBOOK_H_
  96698. #define _V_CODEBOOK_H_
  96699. typedef struct static_codebook{
  96700. long dim; /* codebook dimensions (elements per vector) */
  96701. long entries; /* codebook entries */
  96702. long *lengthlist; /* codeword lengths in bits */
  96703. int maptype; /* 0=none
  96704. 1=implicitly populated values from map column
  96705. 2=listed arbitrary values */
  96706. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96707. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96708. int q_quant; /* bits: 0 < quant <= 16 */
  96709. int q_sequencep; /* bitflag */
  96710. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96711. map == 2: list of dim*entries quantized entry vals
  96712. */
  96713. struct encode_aux_nearestmatch *nearest_tree;
  96714. struct encode_aux_threshmatch *thresh_tree;
  96715. struct encode_aux_pigeonhole *pigeon_tree;
  96716. int allocedp;
  96717. } static_codebook;
  96718. typedef struct encode_aux_nearestmatch{
  96719. long *ptr0;
  96720. long *ptr1;
  96721. long *p; /* decision points (each is an entry) */
  96722. long *q; /* decision points (each is an entry) */
  96723. long aux; /* number of tree entries */
  96724. long alloc;
  96725. } encode_aux_nearestmatch;
  96726. typedef struct encode_aux_threshmatch{
  96727. float *quantthresh;
  96728. long *quantmap;
  96729. int quantvals;
  96730. int threshvals;
  96731. } encode_aux_threshmatch;
  96732. typedef struct encode_aux_pigeonhole{
  96733. float min;
  96734. float del;
  96735. int mapentries;
  96736. int quantvals;
  96737. long *pigeonmap;
  96738. long fittotal;
  96739. long *fitlist;
  96740. long *fitmap;
  96741. long *fitlength;
  96742. } encode_aux_pigeonhole;
  96743. typedef struct codebook{
  96744. long dim; /* codebook dimensions (elements per vector) */
  96745. long entries; /* codebook entries */
  96746. long used_entries; /* populated codebook entries */
  96747. const static_codebook *c;
  96748. float *valuelist; /* list of dim*entries actual entry values */
  96749. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96750. int *dec_index; /* only used if sparseness collapsed */
  96751. char *dec_codelengths;
  96752. ogg_uint32_t *dec_firsttable;
  96753. int dec_firsttablen;
  96754. int dec_maxlength;
  96755. } codebook;
  96756. extern void vorbis_staticbook_clear(static_codebook *b);
  96757. extern void vorbis_staticbook_destroy(static_codebook *b);
  96758. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96759. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96760. extern void vorbis_book_clear(codebook *b);
  96761. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96762. extern float *_book_logdist(const static_codebook *b,float *vals);
  96763. extern float _float32_unpack(long val);
  96764. extern long _float32_pack(float val);
  96765. extern int _best(codebook *book, float *a, int step);
  96766. extern int _ilog(unsigned int v);
  96767. extern long _book_maptype1_quantvals(const static_codebook *b);
  96768. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96769. extern long vorbis_book_codeword(codebook *book,int entry);
  96770. extern long vorbis_book_codelen(codebook *book,int entry);
  96771. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96772. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96773. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96774. extern int vorbis_book_errorv(codebook *book, float *a);
  96775. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96776. oggpack_buffer *b);
  96777. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96778. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96779. oggpack_buffer *b,int n);
  96780. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96781. oggpack_buffer *b,int n);
  96782. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96783. oggpack_buffer *b,int n);
  96784. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96785. long off,int ch,
  96786. oggpack_buffer *b,int n);
  96787. #endif
  96788. /*** End of inlined file: codebook.h ***/
  96789. #define BLOCKTYPE_IMPULSE 0
  96790. #define BLOCKTYPE_PADDING 1
  96791. #define BLOCKTYPE_TRANSITION 0
  96792. #define BLOCKTYPE_LONG 1
  96793. #define PACKETBLOBS 15
  96794. typedef struct vorbis_block_internal{
  96795. float **pcmdelay; /* this is a pointer into local storage */
  96796. float ampmax;
  96797. int blocktype;
  96798. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96799. blob [PACKETBLOBS/2] points to
  96800. the oggpack_buffer in the
  96801. main vorbis_block */
  96802. } vorbis_block_internal;
  96803. typedef void vorbis_look_floor;
  96804. typedef void vorbis_look_residue;
  96805. typedef void vorbis_look_transform;
  96806. typedef struct {
  96807. int blockflag;
  96808. int windowtype;
  96809. int transformtype;
  96810. int mapping;
  96811. } vorbis_info_mode;
  96812. typedef void vorbis_info_floor;
  96813. typedef void vorbis_info_residue;
  96814. typedef void vorbis_info_mapping;
  96815. /*** Start of inlined file: psy.h ***/
  96816. #ifndef _V_PSY_H_
  96817. #define _V_PSY_H_
  96818. /*** Start of inlined file: smallft.h ***/
  96819. #ifndef _V_SMFT_H_
  96820. #define _V_SMFT_H_
  96821. typedef struct {
  96822. int n;
  96823. float *trigcache;
  96824. int *splitcache;
  96825. } drft_lookup;
  96826. extern void drft_forward(drft_lookup *l,float *data);
  96827. extern void drft_backward(drft_lookup *l,float *data);
  96828. extern void drft_init(drft_lookup *l,int n);
  96829. extern void drft_clear(drft_lookup *l);
  96830. #endif
  96831. /*** End of inlined file: smallft.h ***/
  96832. /*** Start of inlined file: backends.h ***/
  96833. #ifndef _vorbis_backend_h_
  96834. #define _vorbis_backend_h_
  96835. typedef struct{
  96836. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96837. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96838. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96839. void (*free_info) (vorbis_info_floor *);
  96840. void (*free_look) (vorbis_look_floor *);
  96841. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96842. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96843. void *buffer,float *);
  96844. } vorbis_func_floor;
  96845. typedef struct{
  96846. int order;
  96847. long rate;
  96848. long barkmap;
  96849. int ampbits;
  96850. int ampdB;
  96851. int numbooks; /* <= 16 */
  96852. int books[16];
  96853. float lessthan; /* encode-only config setting hacks for libvorbis */
  96854. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96855. } vorbis_info_floor0;
  96856. #define VIF_POSIT 63
  96857. #define VIF_CLASS 16
  96858. #define VIF_PARTS 31
  96859. typedef struct{
  96860. int partitions; /* 0 to 31 */
  96861. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96862. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96863. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96864. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96865. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96866. int mult; /* 1 2 3 or 4 */
  96867. int postlist[VIF_POSIT+2]; /* first two implicit */
  96868. float maxover;
  96869. float maxunder;
  96870. float maxerr;
  96871. float twofitweight;
  96872. float twofitatten;
  96873. int n;
  96874. } vorbis_info_floor1;
  96875. typedef struct{
  96876. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96877. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96878. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96879. vorbis_info_residue *);
  96880. void (*free_info) (vorbis_info_residue *);
  96881. void (*free_look) (vorbis_look_residue *);
  96882. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96883. float **,int *,int);
  96884. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96885. vorbis_look_residue *,
  96886. float **,float **,int *,int,long **);
  96887. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96888. float **,int *,int);
  96889. } vorbis_func_residue;
  96890. typedef struct vorbis_info_residue0{
  96891. long begin;
  96892. long end;
  96893. int grouping; /* group n vectors per partition */
  96894. int partitions; /* possible codebooks for a partition */
  96895. int groupbook; /* huffbook for partitioning */
  96896. int secondstages[64]; /* expanded out to pointers in lookup */
  96897. int booklist[256]; /* list of second stage books */
  96898. float classmetric1[64];
  96899. float classmetric2[64];
  96900. } vorbis_info_residue0;
  96901. typedef struct{
  96902. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96903. oggpack_buffer *);
  96904. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96905. void (*free_info) (vorbis_info_mapping *);
  96906. int (*forward) (struct vorbis_block *vb);
  96907. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96908. } vorbis_func_mapping;
  96909. typedef struct vorbis_info_mapping0{
  96910. int submaps; /* <= 16 */
  96911. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96912. int floorsubmap[16]; /* [mux] submap to floors */
  96913. int residuesubmap[16]; /* [mux] submap to residue */
  96914. int coupling_steps;
  96915. int coupling_mag[256];
  96916. int coupling_ang[256];
  96917. } vorbis_info_mapping0;
  96918. #endif
  96919. /*** End of inlined file: backends.h ***/
  96920. #ifndef EHMER_MAX
  96921. #define EHMER_MAX 56
  96922. #endif
  96923. #define P_BANDS 17 /* 62Hz to 16kHz */
  96924. #define P_LEVELS 8 /* 30dB to 100dB */
  96925. #define P_LEVEL_0 30. /* 30 dB */
  96926. #define P_NOISECURVES 3
  96927. #define NOISE_COMPAND_LEVELS 40
  96928. typedef struct vorbis_info_psy{
  96929. int blockflag;
  96930. float ath_adjatt;
  96931. float ath_maxatt;
  96932. float tone_masteratt[P_NOISECURVES];
  96933. float tone_centerboost;
  96934. float tone_decay;
  96935. float tone_abs_limit;
  96936. float toneatt[P_BANDS];
  96937. int noisemaskp;
  96938. float noisemaxsupp;
  96939. float noisewindowlo;
  96940. float noisewindowhi;
  96941. int noisewindowlomin;
  96942. int noisewindowhimin;
  96943. int noisewindowfixed;
  96944. float noiseoff[P_NOISECURVES][P_BANDS];
  96945. float noisecompand[NOISE_COMPAND_LEVELS];
  96946. float max_curve_dB;
  96947. int normal_channel_p;
  96948. int normal_point_p;
  96949. int normal_start;
  96950. int normal_partition;
  96951. double normal_thresh;
  96952. } vorbis_info_psy;
  96953. typedef struct{
  96954. int eighth_octave_lines;
  96955. float preecho_thresh[VE_BANDS];
  96956. float postecho_thresh[VE_BANDS];
  96957. float stretch_penalty;
  96958. float preecho_minenergy;
  96959. float ampmax_att_per_sec;
  96960. int coupling_pkHz[PACKETBLOBS];
  96961. int coupling_pointlimit[2][PACKETBLOBS];
  96962. int coupling_prepointamp[PACKETBLOBS];
  96963. int coupling_postpointamp[PACKETBLOBS];
  96964. int sliding_lowpass[2][PACKETBLOBS];
  96965. } vorbis_info_psy_global;
  96966. typedef struct {
  96967. float ampmax;
  96968. int channels;
  96969. vorbis_info_psy_global *gi;
  96970. int coupling_pointlimit[2][P_NOISECURVES];
  96971. } vorbis_look_psy_global;
  96972. typedef struct {
  96973. int n;
  96974. struct vorbis_info_psy *vi;
  96975. float ***tonecurves;
  96976. float **noiseoffset;
  96977. float *ath;
  96978. long *octave; /* in n.ocshift format */
  96979. long *bark;
  96980. long firstoc;
  96981. long shiftoc;
  96982. int eighth_octave_lines; /* power of two, please */
  96983. int total_octave_lines;
  96984. long rate; /* cache it */
  96985. float m_val; /* Masking compensation value */
  96986. } vorbis_look_psy;
  96987. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  96988. vorbis_info_psy_global *gi,int n,long rate);
  96989. extern void _vp_psy_clear(vorbis_look_psy *p);
  96990. extern void *_vi_psy_dup(void *source);
  96991. extern void _vi_psy_free(vorbis_info_psy *i);
  96992. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  96993. extern void _vp_remove_floor(vorbis_look_psy *p,
  96994. float *mdct,
  96995. int *icodedflr,
  96996. float *residue,
  96997. int sliding_lowpass);
  96998. extern void _vp_noisemask(vorbis_look_psy *p,
  96999. float *logmdct,
  97000. float *logmask);
  97001. extern void _vp_tonemask(vorbis_look_psy *p,
  97002. float *logfft,
  97003. float *logmask,
  97004. float global_specmax,
  97005. float local_specmax);
  97006. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97007. float *noise,
  97008. float *tone,
  97009. int offset_select,
  97010. float *logmask,
  97011. float *mdct,
  97012. float *logmdct);
  97013. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97014. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97015. vorbis_info_psy_global *g,
  97016. vorbis_look_psy *p,
  97017. vorbis_info_mapping0 *vi,
  97018. float **mdct);
  97019. extern void _vp_couple(int blobno,
  97020. vorbis_info_psy_global *g,
  97021. vorbis_look_psy *p,
  97022. vorbis_info_mapping0 *vi,
  97023. float **res,
  97024. float **mag_memo,
  97025. int **mag_sort,
  97026. int **ifloor,
  97027. int *nonzero,
  97028. int sliding_lowpass);
  97029. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97030. float *in,float *out,int *sortedindex);
  97031. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97032. float *magnitudes,int *sortedindex);
  97033. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97034. vorbis_look_psy *p,
  97035. vorbis_info_mapping0 *vi,
  97036. float **mags);
  97037. extern void hf_reduction(vorbis_info_psy_global *g,
  97038. vorbis_look_psy *p,
  97039. vorbis_info_mapping0 *vi,
  97040. float **mdct);
  97041. #endif
  97042. /*** End of inlined file: psy.h ***/
  97043. /*** Start of inlined file: bitrate.h ***/
  97044. #ifndef _V_BITRATE_H_
  97045. #define _V_BITRATE_H_
  97046. /*** Start of inlined file: os.h ***/
  97047. #ifndef _OS_H
  97048. #define _OS_H
  97049. #ifdef HAVE_CONFIG_H
  97050. #include "config.h"
  97051. #endif
  97052. #include <math.h>
  97053. /*** Start of inlined file: misc.h ***/
  97054. #ifndef _V_RANDOM_H_
  97055. #define _V_RANDOM_H_
  97056. extern int analysis_noisy;
  97057. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97058. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97059. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97060. ogg_int64_t off);
  97061. #ifdef DEBUG_MALLOC
  97062. #define _VDBG_GRAPHFILE "malloc.m"
  97063. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97064. extern void _VDBG_free(void *ptr,char *file,long line);
  97065. #ifndef MISC_C
  97066. #undef _ogg_malloc
  97067. #undef _ogg_calloc
  97068. #undef _ogg_realloc
  97069. #undef _ogg_free
  97070. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97071. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97072. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97073. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97074. #endif
  97075. #endif
  97076. #endif
  97077. /*** End of inlined file: misc.h ***/
  97078. #ifndef _V_IFDEFJAIL_H_
  97079. # define _V_IFDEFJAIL_H_
  97080. # ifdef __GNUC__
  97081. # define STIN static __inline__
  97082. # elif _WIN32
  97083. # define STIN static __inline
  97084. # else
  97085. # define STIN static
  97086. # endif
  97087. #ifdef DJGPP
  97088. # define rint(x) (floor((x)+0.5f))
  97089. #endif
  97090. #ifndef M_PI
  97091. # define M_PI (3.1415926536f)
  97092. #endif
  97093. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97094. # include <malloc.h>
  97095. # define rint(x) (floor((x)+0.5f))
  97096. # define NO_FLOAT_MATH_LIB
  97097. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97098. #endif
  97099. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97100. void *_alloca(size_t size);
  97101. # define alloca _alloca
  97102. #endif
  97103. #ifndef FAST_HYPOT
  97104. # define FAST_HYPOT hypot
  97105. #endif
  97106. #endif
  97107. #ifdef HAVE_ALLOCA_H
  97108. # include <alloca.h>
  97109. #endif
  97110. #ifdef USE_MEMORY_H
  97111. # include <memory.h>
  97112. #endif
  97113. #ifndef min
  97114. # define min(x,y) ((x)>(y)?(y):(x))
  97115. #endif
  97116. #ifndef max
  97117. # define max(x,y) ((x)<(y)?(y):(x))
  97118. #endif
  97119. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97120. # define VORBIS_FPU_CONTROL
  97121. typedef ogg_int16_t vorbis_fpu_control;
  97122. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97123. ogg_int16_t ret;
  97124. ogg_int16_t temp;
  97125. __asm__ __volatile__("fnstcw %0\n\t"
  97126. "movw %0,%%dx\n\t"
  97127. "orw $62463,%%dx\n\t"
  97128. "movw %%dx,%1\n\t"
  97129. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97130. *fpu=ret;
  97131. }
  97132. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97133. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97134. }
  97135. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97136. we get extra fst/fld to
  97137. truncate precision */
  97138. int i;
  97139. __asm__("fistl %0": "=m"(i) : "t"(f));
  97140. return(i);
  97141. }
  97142. #endif
  97143. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97144. # define VORBIS_FPU_CONTROL
  97145. typedef ogg_int16_t vorbis_fpu_control;
  97146. static __inline int vorbis_ftoi(double f){
  97147. int i;
  97148. __asm{
  97149. fld f
  97150. fistp i
  97151. }
  97152. return i;
  97153. }
  97154. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97155. }
  97156. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97157. }
  97158. #endif
  97159. #ifndef VORBIS_FPU_CONTROL
  97160. typedef int vorbis_fpu_control;
  97161. static int vorbis_ftoi(double f){
  97162. return (int)(f+.5);
  97163. }
  97164. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97165. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97166. #endif
  97167. #endif /* _OS_H */
  97168. /*** End of inlined file: os.h ***/
  97169. typedef struct bitrate_manager_state {
  97170. int managed;
  97171. long avg_reservoir;
  97172. long minmax_reservoir;
  97173. long avg_bitsper;
  97174. long min_bitsper;
  97175. long max_bitsper;
  97176. long short_per_long;
  97177. double avgfloat;
  97178. vorbis_block *vb;
  97179. int choice;
  97180. } bitrate_manager_state;
  97181. typedef struct bitrate_manager_info{
  97182. long avg_rate;
  97183. long min_rate;
  97184. long max_rate;
  97185. long reservoir_bits;
  97186. double reservoir_bias;
  97187. double slew_damp;
  97188. } bitrate_manager_info;
  97189. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97190. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97191. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97192. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97193. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97194. #endif
  97195. /*** End of inlined file: bitrate.h ***/
  97196. static int ilog(unsigned int v){
  97197. int ret=0;
  97198. while(v){
  97199. ret++;
  97200. v>>=1;
  97201. }
  97202. return(ret);
  97203. }
  97204. static int ilog2(unsigned int v){
  97205. int ret=0;
  97206. if(v)--v;
  97207. while(v){
  97208. ret++;
  97209. v>>=1;
  97210. }
  97211. return(ret);
  97212. }
  97213. typedef struct private_state {
  97214. envelope_lookup *ve; /* envelope lookup */
  97215. int window[2];
  97216. vorbis_look_transform **transform[2]; /* block, type */
  97217. drft_lookup fft_look[2];
  97218. int modebits;
  97219. vorbis_look_floor **flr;
  97220. vorbis_look_residue **residue;
  97221. vorbis_look_psy *psy;
  97222. vorbis_look_psy_global *psy_g_look;
  97223. unsigned char *header;
  97224. unsigned char *header1;
  97225. unsigned char *header2;
  97226. bitrate_manager_state bms;
  97227. ogg_int64_t sample_count;
  97228. } private_state;
  97229. /*** Start of inlined file: highlevel.h ***/
  97230. typedef struct highlevel_byblocktype {
  97231. double tone_mask_setting;
  97232. double tone_peaklimit_setting;
  97233. double noise_bias_setting;
  97234. double noise_compand_setting;
  97235. } highlevel_byblocktype;
  97236. typedef struct highlevel_encode_setup {
  97237. void *setup;
  97238. int set_in_stone;
  97239. double base_setting;
  97240. double long_setting;
  97241. double short_setting;
  97242. double impulse_noisetune;
  97243. int managed;
  97244. long bitrate_min;
  97245. long bitrate_av;
  97246. double bitrate_av_damp;
  97247. long bitrate_max;
  97248. long bitrate_reservoir;
  97249. double bitrate_reservoir_bias;
  97250. int impulse_block_p;
  97251. int noise_normalize_p;
  97252. double stereo_point_setting;
  97253. double lowpass_kHz;
  97254. double ath_floating_dB;
  97255. double ath_absolute_dB;
  97256. double amplitude_track_dBpersec;
  97257. double trigger_setting;
  97258. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97259. } highlevel_encode_setup;
  97260. /*** End of inlined file: highlevel.h ***/
  97261. typedef struct codec_setup_info {
  97262. long blocksizes[2];
  97263. int modes;
  97264. int maps;
  97265. int floors;
  97266. int residues;
  97267. int books;
  97268. int psys; /* encode only */
  97269. vorbis_info_mode *mode_param[64];
  97270. int map_type[64];
  97271. vorbis_info_mapping *map_param[64];
  97272. int floor_type[64];
  97273. vorbis_info_floor *floor_param[64];
  97274. int residue_type[64];
  97275. vorbis_info_residue *residue_param[64];
  97276. static_codebook *book_param[256];
  97277. codebook *fullbooks;
  97278. vorbis_info_psy *psy_param[4]; /* encode only */
  97279. vorbis_info_psy_global psy_g_param;
  97280. bitrate_manager_info bi;
  97281. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97282. highly redundant structure, but
  97283. improves clarity of program flow. */
  97284. int halfrate_flag; /* painless downsample for decode */
  97285. } codec_setup_info;
  97286. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97287. extern void _vp_global_free(vorbis_look_psy_global *look);
  97288. #endif
  97289. /*** End of inlined file: codec_internal.h ***/
  97290. /*** Start of inlined file: registry.h ***/
  97291. #ifndef _V_REG_H_
  97292. #define _V_REG_H_
  97293. #define VI_TRANSFORMB 1
  97294. #define VI_WINDOWB 1
  97295. #define VI_TIMEB 1
  97296. #define VI_FLOORB 2
  97297. #define VI_RESB 3
  97298. #define VI_MAPB 1
  97299. extern vorbis_func_floor *_floor_P[];
  97300. extern vorbis_func_residue *_residue_P[];
  97301. extern vorbis_func_mapping *_mapping_P[];
  97302. #endif
  97303. /*** End of inlined file: registry.h ***/
  97304. /*** Start of inlined file: scales.h ***/
  97305. #ifndef _V_SCALES_H_
  97306. #define _V_SCALES_H_
  97307. #include <math.h>
  97308. #define VORBIS_IEEE_FLOAT32 1
  97309. #ifdef VORBIS_IEEE_FLOAT32
  97310. static float unitnorm(float x){
  97311. union {
  97312. ogg_uint32_t i;
  97313. float f;
  97314. } ix;
  97315. ix.f = x;
  97316. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97317. return ix.f;
  97318. }
  97319. static float todB(const float *x){
  97320. union {
  97321. ogg_uint32_t i;
  97322. float f;
  97323. } ix;
  97324. ix.f = *x;
  97325. ix.i = ix.i&0x7fffffff;
  97326. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97327. }
  97328. #define todB_nn(x) todB(x)
  97329. #else
  97330. static float unitnorm(float x){
  97331. if(x<0)return(-1.f);
  97332. return(1.f);
  97333. }
  97334. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97335. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97336. #endif
  97337. #define fromdB(x) (exp((x)*.11512925f))
  97338. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97339. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97340. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97341. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97342. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97343. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97344. #endif
  97345. /*** End of inlined file: scales.h ***/
  97346. int analysis_noisy=1;
  97347. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97348. int ret,i;
  97349. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97350. vb->glue_bits=0;
  97351. vb->time_bits=0;
  97352. vb->floor_bits=0;
  97353. vb->res_bits=0;
  97354. for(i=0;i<PACKETBLOBS;i++)
  97355. oggpack_reset(vbi->packetblob[i]);
  97356. if((ret=_mapping_P[0]->forward(vb)))
  97357. return(ret);
  97358. if(op){
  97359. if(vorbis_bitrate_managed(vb))
  97360. return(OV_EINVAL);
  97361. op->packet=oggpack_get_buffer(&vb->opb);
  97362. op->bytes=oggpack_bytes(&vb->opb);
  97363. op->b_o_s=0;
  97364. op->e_o_s=vb->eofflag;
  97365. op->granulepos=vb->granulepos;
  97366. op->packetno=vb->sequence; /* for sake of completeness */
  97367. }
  97368. return(0);
  97369. }
  97370. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97371. int j;
  97372. FILE *of;
  97373. char buffer[80];
  97374. sprintf(buffer,"%s_%d.m",base,i);
  97375. of=fopen(buffer,"w");
  97376. if(!of)perror("failed to open data dump file");
  97377. for(j=0;j<n;j++){
  97378. if(bark){
  97379. float b=toBARK((4000.f*j/n)+.25);
  97380. fprintf(of,"%f ",b);
  97381. }else
  97382. if(off!=0)
  97383. fprintf(of,"%f ",(double)(j+off)/8000.);
  97384. else
  97385. fprintf(of,"%f ",(double)j);
  97386. if(dB){
  97387. float val;
  97388. if(v[j]==0.)
  97389. val=-140.;
  97390. else
  97391. val=todB(v+j);
  97392. fprintf(of,"%f\n",val);
  97393. }else{
  97394. fprintf(of,"%f\n",v[j]);
  97395. }
  97396. }
  97397. fclose(of);
  97398. }
  97399. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97400. ogg_int64_t off){
  97401. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97402. }
  97403. #endif
  97404. /*** End of inlined file: analysis.c ***/
  97405. /*** Start of inlined file: bitrate.c ***/
  97406. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97407. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97408. // tasks..
  97409. #if JUCE_MSVC
  97410. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97411. #endif
  97412. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97413. #if JUCE_USE_OGGVORBIS
  97414. #include <stdlib.h>
  97415. #include <string.h>
  97416. #include <math.h>
  97417. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97418. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97419. bitrate_manager_info *bi=&ci->bi;
  97420. memset(bm,0,sizeof(*bm));
  97421. if(bi && (bi->reservoir_bits>0)){
  97422. long ratesamples=vi->rate;
  97423. int halfsamples=ci->blocksizes[0]>>1;
  97424. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97425. bm->managed=1;
  97426. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97427. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97428. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97429. bm->avgfloat=PACKETBLOBS/2;
  97430. {
  97431. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97432. bm->minmax_reservoir=desired_fill;
  97433. bm->avg_reservoir=desired_fill;
  97434. }
  97435. }
  97436. }
  97437. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97438. memset(bm,0,sizeof(*bm));
  97439. return;
  97440. }
  97441. int vorbis_bitrate_managed(vorbis_block *vb){
  97442. vorbis_dsp_state *vd=vb->vd;
  97443. private_state *b=(private_state*)vd->backend_state;
  97444. bitrate_manager_state *bm=&b->bms;
  97445. if(bm && bm->managed)return(1);
  97446. return(0);
  97447. }
  97448. int vorbis_bitrate_addblock(vorbis_block *vb){
  97449. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97450. vorbis_dsp_state *vd=vb->vd;
  97451. private_state *b=(private_state*)vd->backend_state;
  97452. bitrate_manager_state *bm=&b->bms;
  97453. vorbis_info *vi=vd->vi;
  97454. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97455. bitrate_manager_info *bi=&ci->bi;
  97456. int choice=rint(bm->avgfloat);
  97457. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97458. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97459. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97460. int samples=ci->blocksizes[vb->W]>>1;
  97461. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97462. if(!bm->managed){
  97463. if(bm->vb)return(-1); /* one has been submitted without
  97464. being claimed */
  97465. bm->vb=vb;
  97466. return(0);
  97467. }
  97468. bm->vb=vb;
  97469. if(bm->avg_bitsper>0){
  97470. double slew=0.;
  97471. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97472. double slewlimit= 15./bi->slew_damp;
  97473. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97474. while(choice>0 && this_bits>avg_target_bits &&
  97475. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97476. choice--;
  97477. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97478. }
  97479. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97480. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97481. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97482. choice++;
  97483. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97484. }
  97485. }
  97486. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97487. if(slew<-slewlimit)slew=-slewlimit;
  97488. if(slew>slewlimit)slew=slewlimit;
  97489. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97490. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97491. }
  97492. if(bm->min_bitsper>0){
  97493. if(this_bits<min_target_bits){
  97494. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97495. choice++;
  97496. if(choice>=PACKETBLOBS)break;
  97497. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97498. }
  97499. }
  97500. }
  97501. if(bm->max_bitsper>0){
  97502. if(this_bits>max_target_bits){
  97503. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97504. choice--;
  97505. if(choice<0)break;
  97506. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97507. }
  97508. }
  97509. }
  97510. if(choice<0){
  97511. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97512. bm->choice=choice=0;
  97513. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97514. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97515. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97516. }
  97517. }else{
  97518. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97519. if(choice>=PACKETBLOBS)
  97520. choice=PACKETBLOBS-1;
  97521. bm->choice=choice;
  97522. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97523. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97524. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97525. }
  97526. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97527. if(max_target_bits>0 && this_bits>max_target_bits){
  97528. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97529. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97530. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97531. }else{
  97532. if(bm->minmax_reservoir>desired_fill){
  97533. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97534. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97535. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97536. }else{
  97537. bm->minmax_reservoir=desired_fill;
  97538. }
  97539. }else{
  97540. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97541. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97542. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97543. }else{
  97544. bm->minmax_reservoir=desired_fill;
  97545. }
  97546. }
  97547. }
  97548. }
  97549. if(bm->avg_bitsper>0){
  97550. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97551. bm->avg_reservoir+=this_bits-avg_target_bits;
  97552. }
  97553. return(0);
  97554. }
  97555. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97556. private_state *b=(private_state*)vd->backend_state;
  97557. bitrate_manager_state *bm=&b->bms;
  97558. vorbis_block *vb=bm->vb;
  97559. int choice=PACKETBLOBS/2;
  97560. if(!vb)return 0;
  97561. if(op){
  97562. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97563. if(vorbis_bitrate_managed(vb))
  97564. choice=bm->choice;
  97565. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97566. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97567. op->b_o_s=0;
  97568. op->e_o_s=vb->eofflag;
  97569. op->granulepos=vb->granulepos;
  97570. op->packetno=vb->sequence; /* for sake of completeness */
  97571. }
  97572. bm->vb=0;
  97573. return(1);
  97574. }
  97575. #endif
  97576. /*** End of inlined file: bitrate.c ***/
  97577. /*** Start of inlined file: block.c ***/
  97578. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97579. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97580. // tasks..
  97581. #if JUCE_MSVC
  97582. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97583. #endif
  97584. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97585. #if JUCE_USE_OGGVORBIS
  97586. #include <stdio.h>
  97587. #include <stdlib.h>
  97588. #include <string.h>
  97589. /*** Start of inlined file: window.h ***/
  97590. #ifndef _V_WINDOW_
  97591. #define _V_WINDOW_
  97592. extern float *_vorbis_window_get(int n);
  97593. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97594. int lW,int W,int nW);
  97595. #endif
  97596. /*** End of inlined file: window.h ***/
  97597. /*** Start of inlined file: lpc.h ***/
  97598. #ifndef _V_LPC_H_
  97599. #define _V_LPC_H_
  97600. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97601. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97602. float *data,long n);
  97603. #endif
  97604. /*** End of inlined file: lpc.h ***/
  97605. #ifndef WORD_ALIGN
  97606. #define WORD_ALIGN 8
  97607. #endif
  97608. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97609. int i;
  97610. memset(vb,0,sizeof(*vb));
  97611. vb->vd=v;
  97612. vb->localalloc=0;
  97613. vb->localstore=NULL;
  97614. if(v->analysisp){
  97615. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97616. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97617. vbi->ampmax=-9999;
  97618. for(i=0;i<PACKETBLOBS;i++){
  97619. if(i==PACKETBLOBS/2){
  97620. vbi->packetblob[i]=&vb->opb;
  97621. }else{
  97622. vbi->packetblob[i]=
  97623. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97624. }
  97625. oggpack_writeinit(vbi->packetblob[i]);
  97626. }
  97627. }
  97628. return(0);
  97629. }
  97630. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97631. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97632. if(bytes+vb->localtop>vb->localalloc){
  97633. if(vb->localstore){
  97634. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97635. vb->totaluse+=vb->localtop;
  97636. link->next=vb->reap;
  97637. link->ptr=vb->localstore;
  97638. vb->reap=link;
  97639. }
  97640. vb->localalloc=bytes;
  97641. vb->localstore=_ogg_malloc(vb->localalloc);
  97642. vb->localtop=0;
  97643. }
  97644. {
  97645. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97646. vb->localtop+=bytes;
  97647. return ret;
  97648. }
  97649. }
  97650. void _vorbis_block_ripcord(vorbis_block *vb){
  97651. struct alloc_chain *reap=vb->reap;
  97652. while(reap){
  97653. struct alloc_chain *next=reap->next;
  97654. _ogg_free(reap->ptr);
  97655. memset(reap,0,sizeof(*reap));
  97656. _ogg_free(reap);
  97657. reap=next;
  97658. }
  97659. if(vb->totaluse){
  97660. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97661. vb->localalloc+=vb->totaluse;
  97662. vb->totaluse=0;
  97663. }
  97664. vb->localtop=0;
  97665. vb->reap=NULL;
  97666. }
  97667. int vorbis_block_clear(vorbis_block *vb){
  97668. int i;
  97669. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97670. _vorbis_block_ripcord(vb);
  97671. if(vb->localstore)_ogg_free(vb->localstore);
  97672. if(vbi){
  97673. for(i=0;i<PACKETBLOBS;i++){
  97674. oggpack_writeclear(vbi->packetblob[i]);
  97675. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97676. }
  97677. _ogg_free(vbi);
  97678. }
  97679. memset(vb,0,sizeof(*vb));
  97680. return(0);
  97681. }
  97682. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97683. int i;
  97684. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97685. private_state *b=NULL;
  97686. int hs;
  97687. if(ci==NULL) return 1;
  97688. hs=ci->halfrate_flag;
  97689. memset(v,0,sizeof(*v));
  97690. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97691. v->vi=vi;
  97692. b->modebits=ilog2(ci->modes);
  97693. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97694. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97695. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97696. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97697. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97698. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97699. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97700. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97701. if(encp){ /* encode/decode differ here */
  97702. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97703. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97704. if(!ci->fullbooks){
  97705. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97706. for(i=0;i<ci->books;i++)
  97707. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97708. }
  97709. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97710. for(i=0;i<ci->psys;i++){
  97711. _vp_psy_init(b->psy+i,
  97712. ci->psy_param[i],
  97713. &ci->psy_g_param,
  97714. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97715. vi->rate);
  97716. }
  97717. v->analysisp=1;
  97718. }else{
  97719. if(!ci->fullbooks){
  97720. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97721. for(i=0;i<ci->books;i++){
  97722. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97723. vorbis_staticbook_destroy(ci->book_param[i]);
  97724. ci->book_param[i]=NULL;
  97725. }
  97726. }
  97727. }
  97728. v->pcm_storage=ci->blocksizes[1];
  97729. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97730. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97731. {
  97732. int i;
  97733. for(i=0;i<vi->channels;i++)
  97734. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97735. }
  97736. v->lW=0; /* previous window size */
  97737. v->W=0; /* current window size */
  97738. v->centerW=ci->blocksizes[1]/2;
  97739. v->pcm_current=v->centerW;
  97740. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97741. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97742. for(i=0;i<ci->floors;i++)
  97743. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97744. look(v,ci->floor_param[i]);
  97745. for(i=0;i<ci->residues;i++)
  97746. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97747. look(v,ci->residue_param[i]);
  97748. return 0;
  97749. }
  97750. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97751. private_state *b=NULL;
  97752. if(_vds_shared_init(v,vi,1))return 1;
  97753. b=(private_state*)v->backend_state;
  97754. b->psy_g_look=_vp_global_look(vi);
  97755. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97756. _ve_envelope_init(b->ve,vi);
  97757. vorbis_bitrate_init(vi,&b->bms);
  97758. v->sequence=3;
  97759. return(0);
  97760. }
  97761. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97762. int i;
  97763. if(v){
  97764. vorbis_info *vi=v->vi;
  97765. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97766. private_state *b=(private_state*)v->backend_state;
  97767. if(b){
  97768. if(b->ve){
  97769. _ve_envelope_clear(b->ve);
  97770. _ogg_free(b->ve);
  97771. }
  97772. if(b->transform[0]){
  97773. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97774. _ogg_free(b->transform[0][0]);
  97775. _ogg_free(b->transform[0]);
  97776. }
  97777. if(b->transform[1]){
  97778. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97779. _ogg_free(b->transform[1][0]);
  97780. _ogg_free(b->transform[1]);
  97781. }
  97782. if(b->flr){
  97783. for(i=0;i<ci->floors;i++)
  97784. _floor_P[ci->floor_type[i]]->
  97785. free_look(b->flr[i]);
  97786. _ogg_free(b->flr);
  97787. }
  97788. if(b->residue){
  97789. for(i=0;i<ci->residues;i++)
  97790. _residue_P[ci->residue_type[i]]->
  97791. free_look(b->residue[i]);
  97792. _ogg_free(b->residue);
  97793. }
  97794. if(b->psy){
  97795. for(i=0;i<ci->psys;i++)
  97796. _vp_psy_clear(b->psy+i);
  97797. _ogg_free(b->psy);
  97798. }
  97799. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97800. vorbis_bitrate_clear(&b->bms);
  97801. drft_clear(&b->fft_look[0]);
  97802. drft_clear(&b->fft_look[1]);
  97803. }
  97804. if(v->pcm){
  97805. for(i=0;i<vi->channels;i++)
  97806. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97807. _ogg_free(v->pcm);
  97808. if(v->pcmret)_ogg_free(v->pcmret);
  97809. }
  97810. if(b){
  97811. if(b->header)_ogg_free(b->header);
  97812. if(b->header1)_ogg_free(b->header1);
  97813. if(b->header2)_ogg_free(b->header2);
  97814. _ogg_free(b);
  97815. }
  97816. memset(v,0,sizeof(*v));
  97817. }
  97818. }
  97819. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97820. int i;
  97821. vorbis_info *vi=v->vi;
  97822. private_state *b=(private_state*)v->backend_state;
  97823. if(b->header)_ogg_free(b->header);b->header=NULL;
  97824. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97825. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97826. if(v->pcm_current+vals>=v->pcm_storage){
  97827. v->pcm_storage=v->pcm_current+vals*2;
  97828. for(i=0;i<vi->channels;i++){
  97829. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97830. }
  97831. }
  97832. for(i=0;i<vi->channels;i++)
  97833. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97834. return(v->pcmret);
  97835. }
  97836. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97837. int i;
  97838. int order=32;
  97839. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97840. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97841. long j;
  97842. v->preextrapolate=1;
  97843. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97844. for(i=0;i<v->vi->channels;i++){
  97845. for(j=0;j<v->pcm_current;j++)
  97846. work[j]=v->pcm[i][v->pcm_current-j-1];
  97847. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97848. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97849. order,
  97850. work+v->pcm_current-v->centerW,
  97851. v->centerW);
  97852. for(j=0;j<v->pcm_current;j++)
  97853. v->pcm[i][v->pcm_current-j-1]=work[j];
  97854. }
  97855. }
  97856. }
  97857. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97858. vorbis_info *vi=v->vi;
  97859. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97860. if(vals<=0){
  97861. int order=32;
  97862. int i;
  97863. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97864. if(!v->preextrapolate)
  97865. _preextrapolate_helper(v);
  97866. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97867. v->eofflag=v->pcm_current;
  97868. v->pcm_current+=ci->blocksizes[1]*3;
  97869. for(i=0;i<vi->channels;i++){
  97870. if(v->eofflag>order*2){
  97871. long n;
  97872. n=v->eofflag;
  97873. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97874. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97875. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97876. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97877. }else{
  97878. memset(v->pcm[i]+v->eofflag,0,
  97879. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97880. }
  97881. }
  97882. }else{
  97883. if(v->pcm_current+vals>v->pcm_storage)
  97884. return(OV_EINVAL);
  97885. v->pcm_current+=vals;
  97886. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97887. _preextrapolate_helper(v);
  97888. }
  97889. return(0);
  97890. }
  97891. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97892. int i;
  97893. vorbis_info *vi=v->vi;
  97894. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97895. private_state *b=(private_state*)v->backend_state;
  97896. vorbis_look_psy_global *g=b->psy_g_look;
  97897. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97898. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97899. if(!v->preextrapolate)return(0);
  97900. if(v->eofflag==-1)return(0);
  97901. {
  97902. long bp=_ve_envelope_search(v);
  97903. if(bp==-1){
  97904. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97905. full long block */
  97906. v->nW=0;
  97907. }else{
  97908. if(ci->blocksizes[0]==ci->blocksizes[1])
  97909. v->nW=0;
  97910. else
  97911. v->nW=bp;
  97912. }
  97913. }
  97914. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97915. {
  97916. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97917. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97918. although this check is
  97919. less strict that the
  97920. _ve_envelope_search,
  97921. the search is not run
  97922. if we only use one
  97923. block size */
  97924. }
  97925. _vorbis_block_ripcord(vb);
  97926. vb->lW=v->lW;
  97927. vb->W=v->W;
  97928. vb->nW=v->nW;
  97929. if(v->W){
  97930. if(!v->lW || !v->nW){
  97931. vbi->blocktype=BLOCKTYPE_TRANSITION;
  97932. }else{
  97933. vbi->blocktype=BLOCKTYPE_LONG;
  97934. }
  97935. }else{
  97936. if(_ve_envelope_mark(v)){
  97937. vbi->blocktype=BLOCKTYPE_IMPULSE;
  97938. }else{
  97939. vbi->blocktype=BLOCKTYPE_PADDING;
  97940. }
  97941. }
  97942. vb->vd=v;
  97943. vb->sequence=v->sequence++;
  97944. vb->granulepos=v->granulepos;
  97945. vb->pcmend=ci->blocksizes[v->W];
  97946. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  97947. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  97948. vbi->ampmax=g->ampmax;
  97949. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  97950. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  97951. for(i=0;i<vi->channels;i++){
  97952. vbi->pcmdelay[i]=
  97953. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97954. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97955. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  97956. }
  97957. if(v->eofflag){
  97958. if(v->centerW>=v->eofflag){
  97959. v->eofflag=-1;
  97960. vb->eofflag=1;
  97961. return(1);
  97962. }
  97963. }
  97964. {
  97965. int new_centerNext=ci->blocksizes[1]/2;
  97966. int movementW=centerNext-new_centerNext;
  97967. if(movementW>0){
  97968. _ve_envelope_shift(b->ve,movementW);
  97969. v->pcm_current-=movementW;
  97970. for(i=0;i<vi->channels;i++)
  97971. memmove(v->pcm[i],v->pcm[i]+movementW,
  97972. v->pcm_current*sizeof(*v->pcm[i]));
  97973. v->lW=v->W;
  97974. v->W=v->nW;
  97975. v->centerW=new_centerNext;
  97976. if(v->eofflag){
  97977. v->eofflag-=movementW;
  97978. if(v->eofflag<=0)v->eofflag=-1;
  97979. if(v->centerW>=v->eofflag){
  97980. v->granulepos+=movementW-(v->centerW-v->eofflag);
  97981. }else{
  97982. v->granulepos+=movementW;
  97983. }
  97984. }else{
  97985. v->granulepos+=movementW;
  97986. }
  97987. }
  97988. }
  97989. return(1);
  97990. }
  97991. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  97992. vorbis_info *vi=v->vi;
  97993. codec_setup_info *ci;
  97994. int hs;
  97995. if(!v->backend_state)return -1;
  97996. if(!vi)return -1;
  97997. ci=(codec_setup_info*) vi->codec_setup;
  97998. if(!ci)return -1;
  97999. hs=ci->halfrate_flag;
  98000. v->centerW=ci->blocksizes[1]>>(hs+1);
  98001. v->pcm_current=v->centerW>>hs;
  98002. v->pcm_returned=-1;
  98003. v->granulepos=-1;
  98004. v->sequence=-1;
  98005. v->eofflag=0;
  98006. ((private_state *)(v->backend_state))->sample_count=-1;
  98007. return(0);
  98008. }
  98009. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98010. if(_vds_shared_init(v,vi,0)) return 1;
  98011. vorbis_synthesis_restart(v);
  98012. return 0;
  98013. }
  98014. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98015. vorbis_info *vi=v->vi;
  98016. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98017. private_state *b=(private_state*)v->backend_state;
  98018. int hs=ci->halfrate_flag;
  98019. int i,j;
  98020. if(!vb)return(OV_EINVAL);
  98021. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98022. v->lW=v->W;
  98023. v->W=vb->W;
  98024. v->nW=-1;
  98025. if((v->sequence==-1)||
  98026. (v->sequence+1 != vb->sequence)){
  98027. v->granulepos=-1; /* out of sequence; lose count */
  98028. b->sample_count=-1;
  98029. }
  98030. v->sequence=vb->sequence;
  98031. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98032. was called on block */
  98033. int n=ci->blocksizes[v->W]>>(hs+1);
  98034. int n0=ci->blocksizes[0]>>(hs+1);
  98035. int n1=ci->blocksizes[1]>>(hs+1);
  98036. int thisCenter;
  98037. int prevCenter;
  98038. v->glue_bits+=vb->glue_bits;
  98039. v->time_bits+=vb->time_bits;
  98040. v->floor_bits+=vb->floor_bits;
  98041. v->res_bits+=vb->res_bits;
  98042. if(v->centerW){
  98043. thisCenter=n1;
  98044. prevCenter=0;
  98045. }else{
  98046. thisCenter=0;
  98047. prevCenter=n1;
  98048. }
  98049. for(j=0;j<vi->channels;j++){
  98050. if(v->lW){
  98051. if(v->W){
  98052. float *w=_vorbis_window_get(b->window[1]-hs);
  98053. float *pcm=v->pcm[j]+prevCenter;
  98054. float *p=vb->pcm[j];
  98055. for(i=0;i<n1;i++)
  98056. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98057. }else{
  98058. float *w=_vorbis_window_get(b->window[0]-hs);
  98059. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98060. float *p=vb->pcm[j];
  98061. for(i=0;i<n0;i++)
  98062. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98063. }
  98064. }else{
  98065. if(v->W){
  98066. float *w=_vorbis_window_get(b->window[0]-hs);
  98067. float *pcm=v->pcm[j]+prevCenter;
  98068. float *p=vb->pcm[j]+n1/2-n0/2;
  98069. for(i=0;i<n0;i++)
  98070. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98071. for(;i<n1/2+n0/2;i++)
  98072. pcm[i]=p[i];
  98073. }else{
  98074. float *w=_vorbis_window_get(b->window[0]-hs);
  98075. float *pcm=v->pcm[j]+prevCenter;
  98076. float *p=vb->pcm[j];
  98077. for(i=0;i<n0;i++)
  98078. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98079. }
  98080. }
  98081. {
  98082. float *pcm=v->pcm[j]+thisCenter;
  98083. float *p=vb->pcm[j]+n;
  98084. for(i=0;i<n;i++)
  98085. pcm[i]=p[i];
  98086. }
  98087. }
  98088. if(v->centerW)
  98089. v->centerW=0;
  98090. else
  98091. v->centerW=n1;
  98092. if(v->pcm_returned==-1){
  98093. v->pcm_returned=thisCenter;
  98094. v->pcm_current=thisCenter;
  98095. }else{
  98096. v->pcm_returned=prevCenter;
  98097. v->pcm_current=prevCenter+
  98098. ((ci->blocksizes[v->lW]/4+
  98099. ci->blocksizes[v->W]/4)>>hs);
  98100. }
  98101. }
  98102. if(b->sample_count==-1){
  98103. b->sample_count=0;
  98104. }else{
  98105. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98106. }
  98107. if(v->granulepos==-1){
  98108. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98109. v->granulepos=vb->granulepos;
  98110. if(b->sample_count>v->granulepos){
  98111. if(vb->eofflag){
  98112. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98113. }else{
  98114. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98115. if(v->pcm_returned>v->pcm_current)
  98116. v->pcm_returned=v->pcm_current;
  98117. }
  98118. }
  98119. }
  98120. }else{
  98121. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98122. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98123. if(v->granulepos>vb->granulepos){
  98124. long extra=v->granulepos-vb->granulepos;
  98125. if(extra)
  98126. if(vb->eofflag){
  98127. v->pcm_current-=extra>>hs;
  98128. } /* else {Shouldn't happen *unless* the bitstream is out of
  98129. spec. Either way, believe the bitstream } */
  98130. } /* else {Shouldn't happen *unless* the bitstream is out of
  98131. spec. Either way, believe the bitstream } */
  98132. v->granulepos=vb->granulepos;
  98133. }
  98134. }
  98135. if(vb->eofflag)v->eofflag=1;
  98136. return(0);
  98137. }
  98138. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98139. vorbis_info *vi=v->vi;
  98140. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98141. if(pcm){
  98142. int i;
  98143. for(i=0;i<vi->channels;i++)
  98144. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98145. *pcm=v->pcmret;
  98146. }
  98147. return(v->pcm_current-v->pcm_returned);
  98148. }
  98149. return(0);
  98150. }
  98151. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98152. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98153. v->pcm_returned+=n;
  98154. return(0);
  98155. }
  98156. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98157. vorbis_info *vi=v->vi;
  98158. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98159. int hs=ci->halfrate_flag;
  98160. int n=ci->blocksizes[v->W]>>(hs+1);
  98161. int n0=ci->blocksizes[0]>>(hs+1);
  98162. int n1=ci->blocksizes[1]>>(hs+1);
  98163. int i,j;
  98164. if(v->pcm_returned<0)return 0;
  98165. if(v->centerW==n1){
  98166. for(j=0;j<vi->channels;j++){
  98167. float *p=v->pcm[j];
  98168. for(i=0;i<n1;i++){
  98169. float temp=p[i];
  98170. p[i]=p[i+n1];
  98171. p[i+n1]=temp;
  98172. }
  98173. }
  98174. v->pcm_current-=n1;
  98175. v->pcm_returned-=n1;
  98176. v->centerW=0;
  98177. }
  98178. if((v->lW^v->W)==1){
  98179. for(j=0;j<vi->channels;j++){
  98180. float *s=v->pcm[j];
  98181. float *d=v->pcm[j]+(n1-n0)/2;
  98182. for(i=(n1+n0)/2-1;i>=0;--i)
  98183. d[i]=s[i];
  98184. }
  98185. v->pcm_returned+=(n1-n0)/2;
  98186. v->pcm_current+=(n1-n0)/2;
  98187. }else{
  98188. if(v->lW==0){
  98189. for(j=0;j<vi->channels;j++){
  98190. float *s=v->pcm[j];
  98191. float *d=v->pcm[j]+n1-n0;
  98192. for(i=n0-1;i>=0;--i)
  98193. d[i]=s[i];
  98194. }
  98195. v->pcm_returned+=n1-n0;
  98196. v->pcm_current+=n1-n0;
  98197. }
  98198. }
  98199. if(pcm){
  98200. int i;
  98201. for(i=0;i<vi->channels;i++)
  98202. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98203. *pcm=v->pcmret;
  98204. }
  98205. return(n1+n-v->pcm_returned);
  98206. }
  98207. float *vorbis_window(vorbis_dsp_state *v,int W){
  98208. vorbis_info *vi=v->vi;
  98209. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98210. int hs=ci->halfrate_flag;
  98211. private_state *b=(private_state*)v->backend_state;
  98212. if(b->window[W]-1<0)return NULL;
  98213. return _vorbis_window_get(b->window[W]-hs);
  98214. }
  98215. #endif
  98216. /*** End of inlined file: block.c ***/
  98217. /*** Start of inlined file: codebook.c ***/
  98218. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98219. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98220. // tasks..
  98221. #if JUCE_MSVC
  98222. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98223. #endif
  98224. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98225. #if JUCE_USE_OGGVORBIS
  98226. #include <stdlib.h>
  98227. #include <string.h>
  98228. #include <math.h>
  98229. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98230. long i,j;
  98231. int ordered=0;
  98232. oggpack_write(opb,0x564342,24);
  98233. oggpack_write(opb,c->dim,16);
  98234. oggpack_write(opb,c->entries,24);
  98235. for(i=1;i<c->entries;i++)
  98236. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98237. if(i==c->entries)ordered=1;
  98238. if(ordered){
  98239. long count=0;
  98240. oggpack_write(opb,1,1); /* ordered */
  98241. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98242. for(i=1;i<c->entries;i++){
  98243. long thisx=c->lengthlist[i];
  98244. long last=c->lengthlist[i-1];
  98245. if(thisx>last){
  98246. for(j=last;j<thisx;j++){
  98247. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98248. count=i;
  98249. }
  98250. }
  98251. }
  98252. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98253. }else{
  98254. oggpack_write(opb,0,1); /* unordered */
  98255. for(i=0;i<c->entries;i++)
  98256. if(c->lengthlist[i]==0)break;
  98257. if(i==c->entries){
  98258. oggpack_write(opb,0,1); /* no unused entries */
  98259. for(i=0;i<c->entries;i++)
  98260. oggpack_write(opb,c->lengthlist[i]-1,5);
  98261. }else{
  98262. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98263. for(i=0;i<c->entries;i++){
  98264. if(c->lengthlist[i]==0){
  98265. oggpack_write(opb,0,1);
  98266. }else{
  98267. oggpack_write(opb,1,1);
  98268. oggpack_write(opb,c->lengthlist[i]-1,5);
  98269. }
  98270. }
  98271. }
  98272. }
  98273. oggpack_write(opb,c->maptype,4);
  98274. switch(c->maptype){
  98275. case 0:
  98276. break;
  98277. case 1:case 2:
  98278. if(!c->quantlist){
  98279. return(-1);
  98280. }
  98281. oggpack_write(opb,c->q_min,32);
  98282. oggpack_write(opb,c->q_delta,32);
  98283. oggpack_write(opb,c->q_quant-1,4);
  98284. oggpack_write(opb,c->q_sequencep,1);
  98285. {
  98286. int quantvals;
  98287. switch(c->maptype){
  98288. case 1:
  98289. quantvals=_book_maptype1_quantvals(c);
  98290. break;
  98291. case 2:
  98292. quantvals=c->entries*c->dim;
  98293. break;
  98294. default: /* NOT_REACHABLE */
  98295. quantvals=-1;
  98296. }
  98297. for(i=0;i<quantvals;i++)
  98298. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98299. }
  98300. break;
  98301. default:
  98302. return(-1);
  98303. }
  98304. return(0);
  98305. }
  98306. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98307. long i,j;
  98308. memset(s,0,sizeof(*s));
  98309. s->allocedp=1;
  98310. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98311. s->dim=oggpack_read(opb,16);
  98312. s->entries=oggpack_read(opb,24);
  98313. if(s->entries==-1)goto _eofout;
  98314. switch((int)oggpack_read(opb,1)){
  98315. case 0:
  98316. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98317. if(oggpack_read(opb,1)){
  98318. for(i=0;i<s->entries;i++){
  98319. if(oggpack_read(opb,1)){
  98320. long num=oggpack_read(opb,5);
  98321. if(num==-1)goto _eofout;
  98322. s->lengthlist[i]=num+1;
  98323. }else
  98324. s->lengthlist[i]=0;
  98325. }
  98326. }else{
  98327. for(i=0;i<s->entries;i++){
  98328. long num=oggpack_read(opb,5);
  98329. if(num==-1)goto _eofout;
  98330. s->lengthlist[i]=num+1;
  98331. }
  98332. }
  98333. break;
  98334. case 1:
  98335. {
  98336. long length=oggpack_read(opb,5)+1;
  98337. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98338. for(i=0;i<s->entries;){
  98339. long num=oggpack_read(opb,_ilog(s->entries-i));
  98340. if(num==-1)goto _eofout;
  98341. for(j=0;j<num && i<s->entries;j++,i++)
  98342. s->lengthlist[i]=length;
  98343. length++;
  98344. }
  98345. }
  98346. break;
  98347. default:
  98348. return(-1);
  98349. }
  98350. switch((s->maptype=oggpack_read(opb,4))){
  98351. case 0:
  98352. break;
  98353. case 1: case 2:
  98354. s->q_min=oggpack_read(opb,32);
  98355. s->q_delta=oggpack_read(opb,32);
  98356. s->q_quant=oggpack_read(opb,4)+1;
  98357. s->q_sequencep=oggpack_read(opb,1);
  98358. {
  98359. int quantvals=0;
  98360. switch(s->maptype){
  98361. case 1:
  98362. quantvals=_book_maptype1_quantvals(s);
  98363. break;
  98364. case 2:
  98365. quantvals=s->entries*s->dim;
  98366. break;
  98367. }
  98368. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98369. for(i=0;i<quantvals;i++)
  98370. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98371. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98372. }
  98373. break;
  98374. default:
  98375. goto _errout;
  98376. }
  98377. return(0);
  98378. _errout:
  98379. _eofout:
  98380. vorbis_staticbook_clear(s);
  98381. return(-1);
  98382. }
  98383. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98384. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98385. return(book->c->lengthlist[a]);
  98386. }
  98387. int vorbis_book_errorv(codebook *book,float *a){
  98388. int dim=book->dim,k;
  98389. int best=_best(book,a,1);
  98390. for(k=0;k<dim;k++)
  98391. a[k]=(book->valuelist+best*dim)[k];
  98392. return(best);
  98393. }
  98394. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98395. int k,dim=book->dim;
  98396. for(k=0;k<dim;k++)
  98397. a[k]=(book->valuelist+best*dim)[k];
  98398. return(vorbis_book_encode(book,best,b));
  98399. }
  98400. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98401. int read=book->dec_maxlength;
  98402. long lo,hi;
  98403. long lok = oggpack_look(b,book->dec_firsttablen);
  98404. if (lok >= 0) {
  98405. long entry = book->dec_firsttable[lok];
  98406. if(entry&0x80000000UL){
  98407. lo=(entry>>15)&0x7fff;
  98408. hi=book->used_entries-(entry&0x7fff);
  98409. }else{
  98410. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98411. return(entry-1);
  98412. }
  98413. }else{
  98414. lo=0;
  98415. hi=book->used_entries;
  98416. }
  98417. lok = oggpack_look(b, read);
  98418. while(lok<0 && read>1)
  98419. lok = oggpack_look(b, --read);
  98420. if(lok<0)return -1;
  98421. {
  98422. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98423. while(hi-lo>1){
  98424. long p=(hi-lo)>>1;
  98425. long test=book->codelist[lo+p]>testword;
  98426. lo+=p&(test-1);
  98427. hi-=p&(-test);
  98428. }
  98429. if(book->dec_codelengths[lo]<=read){
  98430. oggpack_adv(b, book->dec_codelengths[lo]);
  98431. return(lo);
  98432. }
  98433. }
  98434. oggpack_adv(b, read);
  98435. return(-1);
  98436. }
  98437. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98438. long packed_entry=decode_packed_entry_number(book,b);
  98439. if(packed_entry>=0)
  98440. return(book->dec_index[packed_entry]);
  98441. return(packed_entry);
  98442. }
  98443. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98444. int step=n/book->dim;
  98445. long *entry = (long*)alloca(sizeof(*entry)*step);
  98446. float **t = (float**)alloca(sizeof(*t)*step);
  98447. int i,j,o;
  98448. for (i = 0; i < step; i++) {
  98449. entry[i]=decode_packed_entry_number(book,b);
  98450. if(entry[i]==-1)return(-1);
  98451. t[i] = book->valuelist+entry[i]*book->dim;
  98452. }
  98453. for(i=0,o=0;i<book->dim;i++,o+=step)
  98454. for (j=0;j<step;j++)
  98455. a[o+j]+=t[j][i];
  98456. return(0);
  98457. }
  98458. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98459. int i,j,entry;
  98460. float *t;
  98461. if(book->dim>8){
  98462. for(i=0;i<n;){
  98463. entry = decode_packed_entry_number(book,b);
  98464. if(entry==-1)return(-1);
  98465. t = book->valuelist+entry*book->dim;
  98466. for (j=0;j<book->dim;)
  98467. a[i++]+=t[j++];
  98468. }
  98469. }else{
  98470. for(i=0;i<n;){
  98471. entry = decode_packed_entry_number(book,b);
  98472. if(entry==-1)return(-1);
  98473. t = book->valuelist+entry*book->dim;
  98474. j=0;
  98475. switch((int)book->dim){
  98476. case 8:
  98477. a[i++]+=t[j++];
  98478. case 7:
  98479. a[i++]+=t[j++];
  98480. case 6:
  98481. a[i++]+=t[j++];
  98482. case 5:
  98483. a[i++]+=t[j++];
  98484. case 4:
  98485. a[i++]+=t[j++];
  98486. case 3:
  98487. a[i++]+=t[j++];
  98488. case 2:
  98489. a[i++]+=t[j++];
  98490. case 1:
  98491. a[i++]+=t[j++];
  98492. case 0:
  98493. break;
  98494. }
  98495. }
  98496. }
  98497. return(0);
  98498. }
  98499. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98500. int i,j,entry;
  98501. float *t;
  98502. for(i=0;i<n;){
  98503. entry = decode_packed_entry_number(book,b);
  98504. if(entry==-1)return(-1);
  98505. t = book->valuelist+entry*book->dim;
  98506. for (j=0;j<book->dim;)
  98507. a[i++]=t[j++];
  98508. }
  98509. return(0);
  98510. }
  98511. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98512. oggpack_buffer *b,int n){
  98513. long i,j,entry;
  98514. int chptr=0;
  98515. for(i=offset/ch;i<(offset+n)/ch;){
  98516. entry = decode_packed_entry_number(book,b);
  98517. if(entry==-1)return(-1);
  98518. {
  98519. const float *t = book->valuelist+entry*book->dim;
  98520. for (j=0;j<book->dim;j++){
  98521. a[chptr++][i]+=t[j];
  98522. if(chptr==ch){
  98523. chptr=0;
  98524. i++;
  98525. }
  98526. }
  98527. }
  98528. }
  98529. return(0);
  98530. }
  98531. #ifdef _V_SELFTEST
  98532. #include <stdio.h>
  98533. #include "vorbis/book/lsp20_0.vqh"
  98534. #include "vorbis/book/res0a_13.vqh"
  98535. #define TESTSIZE 40
  98536. float test1[TESTSIZE]={
  98537. 0.105939f,
  98538. 0.215373f,
  98539. 0.429117f,
  98540. 0.587974f,
  98541. 0.181173f,
  98542. 0.296583f,
  98543. 0.515707f,
  98544. 0.715261f,
  98545. 0.162327f,
  98546. 0.263834f,
  98547. 0.342876f,
  98548. 0.406025f,
  98549. 0.103571f,
  98550. 0.223561f,
  98551. 0.368513f,
  98552. 0.540313f,
  98553. 0.136672f,
  98554. 0.395882f,
  98555. 0.587183f,
  98556. 0.652476f,
  98557. 0.114338f,
  98558. 0.417300f,
  98559. 0.525486f,
  98560. 0.698679f,
  98561. 0.147492f,
  98562. 0.324481f,
  98563. 0.643089f,
  98564. 0.757582f,
  98565. 0.139556f,
  98566. 0.215795f,
  98567. 0.324559f,
  98568. 0.399387f,
  98569. 0.120236f,
  98570. 0.267420f,
  98571. 0.446940f,
  98572. 0.608760f,
  98573. 0.115587f,
  98574. 0.287234f,
  98575. 0.571081f,
  98576. 0.708603f,
  98577. };
  98578. float test3[TESTSIZE]={
  98579. 0,1,-2,3,4,-5,6,7,8,9,
  98580. 8,-2,7,-1,4,6,8,3,1,-9,
  98581. 10,11,12,13,14,15,26,17,18,19,
  98582. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98583. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98584. &_vq_book_res0a_13,NULL};
  98585. float *testvec[]={test1,test3};
  98586. int main(){
  98587. oggpack_buffer write;
  98588. oggpack_buffer read;
  98589. long ptr=0,i;
  98590. oggpack_writeinit(&write);
  98591. fprintf(stderr,"Testing codebook abstraction...:\n");
  98592. while(testlist[ptr]){
  98593. codebook c;
  98594. static_codebook s;
  98595. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98596. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98597. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98598. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98599. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98600. oggpack_reset(&write);
  98601. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98602. we can write */
  98603. vorbis_staticbook_pack(testlist[ptr],&write);
  98604. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98605. for(i=0;i<TESTSIZE;i+=c.dim){
  98606. int best=_best(&c,qv+i,1);
  98607. vorbis_book_encodev(&c,best,qv+i,&write);
  98608. }
  98609. vorbis_book_clear(&c);
  98610. fprintf(stderr,"OK.\n");
  98611. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98612. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98613. if(vorbis_staticbook_unpack(&read,&s)){
  98614. fprintf(stderr,"Error unpacking codebook.\n");
  98615. exit(1);
  98616. }
  98617. if(vorbis_book_init_decode(&c,&s)){
  98618. fprintf(stderr,"Error initializing codebook.\n");
  98619. exit(1);
  98620. }
  98621. for(i=0;i<TESTSIZE;i+=c.dim)
  98622. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98623. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98624. exit(1);
  98625. }
  98626. for(i=0;i<TESTSIZE;i++)
  98627. if(fabs(qv[i]-iv[i])>.000001){
  98628. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98629. iv[i],qv[i],i);
  98630. exit(1);
  98631. }
  98632. fprintf(stderr,"OK\n");
  98633. ptr++;
  98634. }
  98635. exit(0);
  98636. }
  98637. #endif
  98638. #endif
  98639. /*** End of inlined file: codebook.c ***/
  98640. /*** Start of inlined file: envelope.c ***/
  98641. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98642. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98643. // tasks..
  98644. #if JUCE_MSVC
  98645. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98646. #endif
  98647. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98648. #if JUCE_USE_OGGVORBIS
  98649. #include <stdlib.h>
  98650. #include <string.h>
  98651. #include <stdio.h>
  98652. #include <math.h>
  98653. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98654. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98655. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98656. int ch=vi->channels;
  98657. int i,j;
  98658. int n=e->winlength=128;
  98659. e->searchstep=64; /* not random */
  98660. e->minenergy=gi->preecho_minenergy;
  98661. e->ch=ch;
  98662. e->storage=128;
  98663. e->cursor=ci->blocksizes[1]/2;
  98664. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98665. mdct_init(&e->mdct,n);
  98666. for(i=0;i<n;i++){
  98667. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98668. e->mdct_win[i]*=e->mdct_win[i];
  98669. }
  98670. e->band[0].begin=2; e->band[0].end=4;
  98671. e->band[1].begin=4; e->band[1].end=5;
  98672. e->band[2].begin=6; e->band[2].end=6;
  98673. e->band[3].begin=9; e->band[3].end=8;
  98674. e->band[4].begin=13; e->band[4].end=8;
  98675. e->band[5].begin=17; e->band[5].end=8;
  98676. e->band[6].begin=22; e->band[6].end=8;
  98677. for(j=0;j<VE_BANDS;j++){
  98678. n=e->band[j].end;
  98679. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98680. for(i=0;i<n;i++){
  98681. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98682. e->band[j].total+=e->band[j].window[i];
  98683. }
  98684. e->band[j].total=1./e->band[j].total;
  98685. }
  98686. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98687. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98688. }
  98689. void _ve_envelope_clear(envelope_lookup *e){
  98690. int i;
  98691. mdct_clear(&e->mdct);
  98692. for(i=0;i<VE_BANDS;i++)
  98693. _ogg_free(e->band[i].window);
  98694. _ogg_free(e->mdct_win);
  98695. _ogg_free(e->filter);
  98696. _ogg_free(e->mark);
  98697. memset(e,0,sizeof(*e));
  98698. }
  98699. static int _ve_amp(envelope_lookup *ve,
  98700. vorbis_info_psy_global *gi,
  98701. float *data,
  98702. envelope_band *bands,
  98703. envelope_filter_state *filters,
  98704. long pos){
  98705. long n=ve->winlength;
  98706. int ret=0;
  98707. long i,j;
  98708. float decay;
  98709. float minV=ve->minenergy;
  98710. float *vec=(float*) alloca(n*sizeof(*vec));
  98711. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98712. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98713. if(penalty<0.f)penalty=0.f;
  98714. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98715. for(i=0;i<n;i++)
  98716. vec[i]=data[i]*ve->mdct_win[i];
  98717. mdct_forward(&ve->mdct,vec,vec);
  98718. {
  98719. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98720. int ptr=filters->nearptr;
  98721. if(ptr==0){
  98722. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98723. filters->nearDC_partialacc=temp;
  98724. }else{
  98725. decay=filters->nearDC_acc+=temp;
  98726. filters->nearDC_partialacc+=temp;
  98727. }
  98728. filters->nearDC_acc-=filters->nearDC[ptr];
  98729. filters->nearDC[ptr]=temp;
  98730. decay*=(1./(VE_NEARDC+1));
  98731. filters->nearptr++;
  98732. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98733. decay=todB(&decay)*.5-15.f;
  98734. }
  98735. for(i=0;i<n/2;i+=2){
  98736. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98737. val=todB(&val)*.5f;
  98738. if(val<decay)val=decay;
  98739. if(val<minV)val=minV;
  98740. vec[i>>1]=val;
  98741. decay-=8.;
  98742. }
  98743. for(j=0;j<VE_BANDS;j++){
  98744. float acc=0.;
  98745. float valmax,valmin;
  98746. for(i=0;i<bands[j].end;i++)
  98747. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98748. acc*=bands[j].total;
  98749. {
  98750. int p,thisx=filters[j].ampptr;
  98751. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98752. p=thisx;
  98753. p--;
  98754. if(p<0)p+=VE_AMP;
  98755. postmax=max(acc,filters[j].ampbuf[p]);
  98756. postmin=min(acc,filters[j].ampbuf[p]);
  98757. for(i=0;i<stretch;i++){
  98758. p--;
  98759. if(p<0)p+=VE_AMP;
  98760. premax=max(premax,filters[j].ampbuf[p]);
  98761. premin=min(premin,filters[j].ampbuf[p]);
  98762. }
  98763. valmin=postmin-premin;
  98764. valmax=postmax-premax;
  98765. filters[j].ampbuf[thisx]=acc;
  98766. filters[j].ampptr++;
  98767. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98768. }
  98769. if(valmax>gi->preecho_thresh[j]+penalty){
  98770. ret|=1;
  98771. ret|=4;
  98772. }
  98773. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98774. }
  98775. return(ret);
  98776. }
  98777. #if 0
  98778. static int seq=0;
  98779. static ogg_int64_t totalshift=-1024;
  98780. #endif
  98781. long _ve_envelope_search(vorbis_dsp_state *v){
  98782. vorbis_info *vi=v->vi;
  98783. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98784. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98785. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98786. long i,j;
  98787. int first=ve->current/ve->searchstep;
  98788. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98789. if(first<0)first=0;
  98790. if(last+VE_WIN+VE_POST>ve->storage){
  98791. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98792. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98793. }
  98794. for(j=first;j<last;j++){
  98795. int ret=0;
  98796. ve->stretch++;
  98797. if(ve->stretch>VE_MAXSTRETCH*2)
  98798. ve->stretch=VE_MAXSTRETCH*2;
  98799. for(i=0;i<ve->ch;i++){
  98800. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98801. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98802. }
  98803. ve->mark[j+VE_POST]=0;
  98804. if(ret&1){
  98805. ve->mark[j]=1;
  98806. ve->mark[j+1]=1;
  98807. }
  98808. if(ret&2){
  98809. ve->mark[j]=1;
  98810. if(j>0)ve->mark[j-1]=1;
  98811. }
  98812. if(ret&4)ve->stretch=-1;
  98813. }
  98814. ve->current=last*ve->searchstep;
  98815. {
  98816. long centerW=v->centerW;
  98817. long testW=
  98818. centerW+
  98819. ci->blocksizes[v->W]/4+
  98820. ci->blocksizes[1]/2+
  98821. ci->blocksizes[0]/4;
  98822. j=ve->cursor;
  98823. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98824. working back one window */
  98825. if(j>=testW)return(1);
  98826. ve->cursor=j;
  98827. if(ve->mark[j/ve->searchstep]){
  98828. if(j>centerW){
  98829. #if 0
  98830. if(j>ve->curmark){
  98831. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98832. int l,m;
  98833. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98834. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98835. seq,
  98836. (totalshift+ve->cursor)/44100.,
  98837. (totalshift+j)/44100.);
  98838. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98839. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98840. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98841. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98842. for(m=0;m<VE_BANDS;m++){
  98843. char buf[80];
  98844. sprintf(buf,"delL%d",m);
  98845. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98846. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98847. }
  98848. for(m=0;m<VE_BANDS;m++){
  98849. char buf[80];
  98850. sprintf(buf,"delR%d",m);
  98851. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98852. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98853. }
  98854. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98855. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98856. seq++;
  98857. }
  98858. #endif
  98859. ve->curmark=j;
  98860. if(j>=testW)return(1);
  98861. return(0);
  98862. }
  98863. }
  98864. j+=ve->searchstep;
  98865. }
  98866. }
  98867. return(-1);
  98868. }
  98869. int _ve_envelope_mark(vorbis_dsp_state *v){
  98870. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98871. vorbis_info *vi=v->vi;
  98872. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98873. long centerW=v->centerW;
  98874. long beginW=centerW-ci->blocksizes[v->W]/4;
  98875. long endW=centerW+ci->blocksizes[v->W]/4;
  98876. if(v->W){
  98877. beginW-=ci->blocksizes[v->lW]/4;
  98878. endW+=ci->blocksizes[v->nW]/4;
  98879. }else{
  98880. beginW-=ci->blocksizes[0]/4;
  98881. endW+=ci->blocksizes[0]/4;
  98882. }
  98883. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98884. {
  98885. long first=beginW/ve->searchstep;
  98886. long last=endW/ve->searchstep;
  98887. long i;
  98888. for(i=first;i<last;i++)
  98889. if(ve->mark[i])return(1);
  98890. }
  98891. return(0);
  98892. }
  98893. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98894. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98895. ahead of ve->current */
  98896. int smallshift=shift/e->searchstep;
  98897. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98898. #if 0
  98899. for(i=0;i<VE_BANDS*e->ch;i++)
  98900. memmove(e->filter[i].markers,
  98901. e->filter[i].markers+smallshift,
  98902. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98903. totalshift+=shift;
  98904. #endif
  98905. e->current-=shift;
  98906. if(e->curmark>=0)
  98907. e->curmark-=shift;
  98908. e->cursor-=shift;
  98909. }
  98910. #endif
  98911. /*** End of inlined file: envelope.c ***/
  98912. /*** Start of inlined file: floor0.c ***/
  98913. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98914. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98915. // tasks..
  98916. #if JUCE_MSVC
  98917. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98918. #endif
  98919. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98920. #if JUCE_USE_OGGVORBIS
  98921. #include <stdlib.h>
  98922. #include <string.h>
  98923. #include <math.h>
  98924. /*** Start of inlined file: lsp.h ***/
  98925. #ifndef _V_LSP_H_
  98926. #define _V_LSP_H_
  98927. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  98928. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  98929. float *lsp,int m,
  98930. float amp,float ampoffset);
  98931. #endif
  98932. /*** End of inlined file: lsp.h ***/
  98933. #include <stdio.h>
  98934. typedef struct {
  98935. int ln;
  98936. int m;
  98937. int **linearmap;
  98938. int n[2];
  98939. vorbis_info_floor0 *vi;
  98940. long bits;
  98941. long frames;
  98942. } vorbis_look_floor0;
  98943. static void floor0_free_info(vorbis_info_floor *i){
  98944. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  98945. if(info){
  98946. memset(info,0,sizeof(*info));
  98947. _ogg_free(info);
  98948. }
  98949. }
  98950. static void floor0_free_look(vorbis_look_floor *i){
  98951. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98952. if(look){
  98953. if(look->linearmap){
  98954. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  98955. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  98956. _ogg_free(look->linearmap);
  98957. }
  98958. memset(look,0,sizeof(*look));
  98959. _ogg_free(look);
  98960. }
  98961. }
  98962. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98963. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98964. int j;
  98965. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  98966. info->order=oggpack_read(opb,8);
  98967. info->rate=oggpack_read(opb,16);
  98968. info->barkmap=oggpack_read(opb,16);
  98969. info->ampbits=oggpack_read(opb,6);
  98970. info->ampdB=oggpack_read(opb,8);
  98971. info->numbooks=oggpack_read(opb,4)+1;
  98972. if(info->order<1)goto err_out;
  98973. if(info->rate<1)goto err_out;
  98974. if(info->barkmap<1)goto err_out;
  98975. if(info->numbooks<1)goto err_out;
  98976. for(j=0;j<info->numbooks;j++){
  98977. info->books[j]=oggpack_read(opb,8);
  98978. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  98979. }
  98980. return(info);
  98981. err_out:
  98982. floor0_free_info(info);
  98983. return(NULL);
  98984. }
  98985. static void floor0_map_lazy_init(vorbis_block *vb,
  98986. vorbis_info_floor *infoX,
  98987. vorbis_look_floor0 *look){
  98988. if(!look->linearmap[vb->W]){
  98989. vorbis_dsp_state *vd=vb->vd;
  98990. vorbis_info *vi=vd->vi;
  98991. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98992. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  98993. int W=vb->W;
  98994. int n=ci->blocksizes[W]/2,j;
  98995. float scale=look->ln/toBARK(info->rate/2.f);
  98996. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  98997. for(j=0;j<n;j++){
  98998. int val=floor( toBARK((info->rate/2.f)/n*j)
  98999. *scale); /* bark numbers represent band edges */
  99000. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99001. look->linearmap[W][j]=val;
  99002. }
  99003. look->linearmap[W][j]=-1;
  99004. look->n[W]=n;
  99005. }
  99006. }
  99007. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99008. vorbis_info_floor *i){
  99009. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99010. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99011. look->m=info->order;
  99012. look->ln=info->barkmap;
  99013. look->vi=info;
  99014. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99015. return look;
  99016. }
  99017. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99018. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99019. vorbis_info_floor0 *info=look->vi;
  99020. int j,k;
  99021. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99022. if(ampraw>0){ /* also handles the -1 out of data case */
  99023. long maxval=(1<<info->ampbits)-1;
  99024. float amp=(float)ampraw/maxval*info->ampdB;
  99025. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99026. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99027. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99028. codebook *b=ci->fullbooks+info->books[booknum];
  99029. float last=0.f;
  99030. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99031. for(j=0;j<look->m;j+=b->dim)
  99032. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99033. for(j=0;j<look->m;){
  99034. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99035. last=lsp[j-1];
  99036. }
  99037. lsp[look->m]=amp;
  99038. return(lsp);
  99039. }
  99040. }
  99041. eop:
  99042. return(NULL);
  99043. }
  99044. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99045. void *memo,float *out){
  99046. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99047. vorbis_info_floor0 *info=look->vi;
  99048. floor0_map_lazy_init(vb,info,look);
  99049. if(memo){
  99050. float *lsp=(float *)memo;
  99051. float amp=lsp[look->m];
  99052. vorbis_lsp_to_curve(out,
  99053. look->linearmap[vb->W],
  99054. look->n[vb->W],
  99055. look->ln,
  99056. lsp,look->m,amp,(float)info->ampdB);
  99057. return(1);
  99058. }
  99059. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99060. return(0);
  99061. }
  99062. vorbis_func_floor floor0_exportbundle={
  99063. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99064. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99065. };
  99066. #endif
  99067. /*** End of inlined file: floor0.c ***/
  99068. /*** Start of inlined file: floor1.c ***/
  99069. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99070. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99071. // tasks..
  99072. #if JUCE_MSVC
  99073. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99074. #endif
  99075. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99076. #if JUCE_USE_OGGVORBIS
  99077. #include <stdlib.h>
  99078. #include <string.h>
  99079. #include <math.h>
  99080. #include <stdio.h>
  99081. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99082. typedef struct {
  99083. int sorted_index[VIF_POSIT+2];
  99084. int forward_index[VIF_POSIT+2];
  99085. int reverse_index[VIF_POSIT+2];
  99086. int hineighbor[VIF_POSIT];
  99087. int loneighbor[VIF_POSIT];
  99088. int posts;
  99089. int n;
  99090. int quant_q;
  99091. vorbis_info_floor1 *vi;
  99092. long phrasebits;
  99093. long postbits;
  99094. long frames;
  99095. } vorbis_look_floor1;
  99096. typedef struct lsfit_acc{
  99097. long x0;
  99098. long x1;
  99099. long xa;
  99100. long ya;
  99101. long x2a;
  99102. long y2a;
  99103. long xya;
  99104. long an;
  99105. } lsfit_acc;
  99106. static void floor1_free_info(vorbis_info_floor *i){
  99107. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99108. if(info){
  99109. memset(info,0,sizeof(*info));
  99110. _ogg_free(info);
  99111. }
  99112. }
  99113. static void floor1_free_look(vorbis_look_floor *i){
  99114. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99115. if(look){
  99116. memset(look,0,sizeof(*look));
  99117. _ogg_free(look);
  99118. }
  99119. }
  99120. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99121. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99122. int j,k;
  99123. int count=0;
  99124. int rangebits;
  99125. int maxposit=info->postlist[1];
  99126. int maxclass=-1;
  99127. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99128. for(j=0;j<info->partitions;j++){
  99129. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99130. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99131. }
  99132. for(j=0;j<maxclass+1;j++){
  99133. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99134. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99135. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99136. for(k=0;k<(1<<info->class_subs[j]);k++)
  99137. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99138. }
  99139. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99140. oggpack_write(opb,ilog2(maxposit),4);
  99141. rangebits=ilog2(maxposit);
  99142. for(j=0,k=0;j<info->partitions;j++){
  99143. count+=info->class_dim[info->partitionclass[j]];
  99144. for(;k<count;k++)
  99145. oggpack_write(opb,info->postlist[k+2],rangebits);
  99146. }
  99147. }
  99148. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99149. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99150. int j,k,count=0,maxclass=-1,rangebits;
  99151. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99152. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99153. for(j=0;j<info->partitions;j++){
  99154. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99155. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99156. }
  99157. for(j=0;j<maxclass+1;j++){
  99158. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99159. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99160. if(info->class_subs[j]<0)
  99161. goto err_out;
  99162. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99163. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99164. goto err_out;
  99165. for(k=0;k<(1<<info->class_subs[j]);k++){
  99166. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99167. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99168. goto err_out;
  99169. }
  99170. }
  99171. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99172. rangebits=oggpack_read(opb,4);
  99173. for(j=0,k=0;j<info->partitions;j++){
  99174. count+=info->class_dim[info->partitionclass[j]];
  99175. for(;k<count;k++){
  99176. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99177. if(t<0 || t>=(1<<rangebits))
  99178. goto err_out;
  99179. }
  99180. }
  99181. info->postlist[0]=0;
  99182. info->postlist[1]=1<<rangebits;
  99183. return(info);
  99184. err_out:
  99185. floor1_free_info(info);
  99186. return(NULL);
  99187. }
  99188. static int icomp(const void *a,const void *b){
  99189. return(**(int **)a-**(int **)b);
  99190. }
  99191. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99192. vorbis_info_floor *in){
  99193. int *sortpointer[VIF_POSIT+2];
  99194. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99195. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99196. int i,j,n=0;
  99197. look->vi=info;
  99198. look->n=info->postlist[1];
  99199. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99200. n+=2;
  99201. look->posts=n;
  99202. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99203. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99204. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99205. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99206. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99207. switch(info->mult){
  99208. case 1: /* 1024 -> 256 */
  99209. look->quant_q=256;
  99210. break;
  99211. case 2: /* 1024 -> 128 */
  99212. look->quant_q=128;
  99213. break;
  99214. case 3: /* 1024 -> 86 */
  99215. look->quant_q=86;
  99216. break;
  99217. case 4: /* 1024 -> 64 */
  99218. look->quant_q=64;
  99219. break;
  99220. }
  99221. for(i=0;i<n-2;i++){
  99222. int lo=0;
  99223. int hi=1;
  99224. int lx=0;
  99225. int hx=look->n;
  99226. int currentx=info->postlist[i+2];
  99227. for(j=0;j<i+2;j++){
  99228. int x=info->postlist[j];
  99229. if(x>lx && x<currentx){
  99230. lo=j;
  99231. lx=x;
  99232. }
  99233. if(x<hx && x>currentx){
  99234. hi=j;
  99235. hx=x;
  99236. }
  99237. }
  99238. look->loneighbor[i]=lo;
  99239. look->hineighbor[i]=hi;
  99240. }
  99241. return(look);
  99242. }
  99243. static int render_point(int x0,int x1,int y0,int y1,int x){
  99244. y0&=0x7fff; /* mask off flag */
  99245. y1&=0x7fff;
  99246. {
  99247. int dy=y1-y0;
  99248. int adx=x1-x0;
  99249. int ady=abs(dy);
  99250. int err=ady*(x-x0);
  99251. int off=err/adx;
  99252. if(dy<0)return(y0-off);
  99253. return(y0+off);
  99254. }
  99255. }
  99256. static int vorbis_dBquant(const float *x){
  99257. int i= *x*7.3142857f+1023.5f;
  99258. if(i>1023)return(1023);
  99259. if(i<0)return(0);
  99260. return i;
  99261. }
  99262. static float FLOOR1_fromdB_LOOKUP[256]={
  99263. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99264. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99265. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99266. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99267. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99268. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99269. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99270. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99271. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99272. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99273. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99274. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99275. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99276. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99277. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99278. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99279. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99280. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99281. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99282. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99283. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99284. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99285. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99286. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99287. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99288. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99289. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99290. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99291. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99292. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99293. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99294. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99295. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99296. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99297. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99298. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99299. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99300. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99301. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99302. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99303. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99304. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99305. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99306. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99307. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99308. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99309. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99310. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99311. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99312. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99313. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99314. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99315. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99316. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99317. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99318. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99319. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99320. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99321. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99322. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99323. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99324. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99325. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99326. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99327. };
  99328. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99329. int dy=y1-y0;
  99330. int adx=x1-x0;
  99331. int ady=abs(dy);
  99332. int base=dy/adx;
  99333. int sy=(dy<0?base-1:base+1);
  99334. int x=x0;
  99335. int y=y0;
  99336. int err=0;
  99337. ady-=abs(base*adx);
  99338. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99339. while(++x<x1){
  99340. err=err+ady;
  99341. if(err>=adx){
  99342. err-=adx;
  99343. y+=sy;
  99344. }else{
  99345. y+=base;
  99346. }
  99347. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99348. }
  99349. }
  99350. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99351. int dy=y1-y0;
  99352. int adx=x1-x0;
  99353. int ady=abs(dy);
  99354. int base=dy/adx;
  99355. int sy=(dy<0?base-1:base+1);
  99356. int x=x0;
  99357. int y=y0;
  99358. int err=0;
  99359. ady-=abs(base*adx);
  99360. d[x]=y;
  99361. while(++x<x1){
  99362. err=err+ady;
  99363. if(err>=adx){
  99364. err-=adx;
  99365. y+=sy;
  99366. }else{
  99367. y+=base;
  99368. }
  99369. d[x]=y;
  99370. }
  99371. }
  99372. static int accumulate_fit(const float *flr,const float *mdct,
  99373. int x0, int x1,lsfit_acc *a,
  99374. int n,vorbis_info_floor1 *info){
  99375. long i;
  99376. 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;
  99377. memset(a,0,sizeof(*a));
  99378. a->x0=x0;
  99379. a->x1=x1;
  99380. if(x1>=n)x1=n-1;
  99381. for(i=x0;i<=x1;i++){
  99382. int quantized=vorbis_dBquant(flr+i);
  99383. if(quantized){
  99384. if(mdct[i]+info->twofitatten>=flr[i]){
  99385. xa += i;
  99386. ya += quantized;
  99387. x2a += i*i;
  99388. y2a += quantized*quantized;
  99389. xya += i*quantized;
  99390. na++;
  99391. }else{
  99392. xb += i;
  99393. yb += quantized;
  99394. x2b += i*i;
  99395. y2b += quantized*quantized;
  99396. xyb += i*quantized;
  99397. nb++;
  99398. }
  99399. }
  99400. }
  99401. xb+=xa;
  99402. yb+=ya;
  99403. x2b+=x2a;
  99404. y2b+=y2a;
  99405. xyb+=xya;
  99406. nb+=na;
  99407. {
  99408. int weight=nb*info->twofitweight/(na+1);
  99409. a->xa=xa*weight+xb;
  99410. a->ya=ya*weight+yb;
  99411. a->x2a=x2a*weight+x2b;
  99412. a->y2a=y2a*weight+y2b;
  99413. a->xya=xya*weight+xyb;
  99414. a->an=na*weight+nb;
  99415. }
  99416. return(na);
  99417. }
  99418. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99419. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99420. long x0=a[0].x0;
  99421. long x1=a[fits-1].x1;
  99422. for(i=0;i<fits;i++){
  99423. x+=a[i].xa;
  99424. y+=a[i].ya;
  99425. x2+=a[i].x2a;
  99426. y2+=a[i].y2a;
  99427. xy+=a[i].xya;
  99428. an+=a[i].an;
  99429. }
  99430. if(*y0>=0){
  99431. x+= x0;
  99432. y+= *y0;
  99433. x2+= x0 * x0;
  99434. y2+= *y0 * *y0;
  99435. xy+= *y0 * x0;
  99436. an++;
  99437. }
  99438. if(*y1>=0){
  99439. x+= x1;
  99440. y+= *y1;
  99441. x2+= x1 * x1;
  99442. y2+= *y1 * *y1;
  99443. xy+= *y1 * x1;
  99444. an++;
  99445. }
  99446. if(an){
  99447. double fx=x;
  99448. double fy=y;
  99449. double fx2=x2;
  99450. double fxy=xy;
  99451. double denom=1./(an*fx2-fx*fx);
  99452. double a=(fy*fx2-fxy*fx)*denom;
  99453. double b=(an*fxy-fx*fy)*denom;
  99454. *y0=rint(a+b*x0);
  99455. *y1=rint(a+b*x1);
  99456. if(*y0>1023)*y0=1023;
  99457. if(*y1>1023)*y1=1023;
  99458. if(*y0<0)*y0=0;
  99459. if(*y1<0)*y1=0;
  99460. }else{
  99461. *y0=0;
  99462. *y1=0;
  99463. }
  99464. }
  99465. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99466. const float *mdct,
  99467. vorbis_info_floor1 *info){
  99468. int dy=y1-y0;
  99469. int adx=x1-x0;
  99470. int ady=abs(dy);
  99471. int base=dy/adx;
  99472. int sy=(dy<0?base-1:base+1);
  99473. int x=x0;
  99474. int y=y0;
  99475. int err=0;
  99476. int val=vorbis_dBquant(mask+x);
  99477. int mse=0;
  99478. int n=0;
  99479. ady-=abs(base*adx);
  99480. mse=(y-val);
  99481. mse*=mse;
  99482. n++;
  99483. if(mdct[x]+info->twofitatten>=mask[x]){
  99484. if(y+info->maxover<val)return(1);
  99485. if(y-info->maxunder>val)return(1);
  99486. }
  99487. while(++x<x1){
  99488. err=err+ady;
  99489. if(err>=adx){
  99490. err-=adx;
  99491. y+=sy;
  99492. }else{
  99493. y+=base;
  99494. }
  99495. val=vorbis_dBquant(mask+x);
  99496. mse+=((y-val)*(y-val));
  99497. n++;
  99498. if(mdct[x]+info->twofitatten>=mask[x]){
  99499. if(val){
  99500. if(y+info->maxover<val)return(1);
  99501. if(y-info->maxunder>val)return(1);
  99502. }
  99503. }
  99504. }
  99505. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99506. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99507. if(mse/n>info->maxerr)return(1);
  99508. return(0);
  99509. }
  99510. static int post_Y(int *A,int *B,int pos){
  99511. if(A[pos]<0)
  99512. return B[pos];
  99513. if(B[pos]<0)
  99514. return A[pos];
  99515. return (A[pos]+B[pos])>>1;
  99516. }
  99517. int *floor1_fit(vorbis_block *vb,void *look_,
  99518. const float *logmdct, /* in */
  99519. const float *logmask){
  99520. long i,j;
  99521. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99522. vorbis_info_floor1 *info=look->vi;
  99523. long n=look->n;
  99524. long posts=look->posts;
  99525. long nonzero=0;
  99526. lsfit_acc fits[VIF_POSIT+1];
  99527. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99528. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99529. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99530. int hineighbor[VIF_POSIT+2];
  99531. int *output=NULL;
  99532. int memo[VIF_POSIT+2];
  99533. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99534. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99535. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99536. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99537. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99538. if(posts==0){
  99539. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99540. }else{
  99541. for(i=0;i<posts-1;i++)
  99542. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99543. look->sorted_index[i+1],fits+i,
  99544. n,info);
  99545. }
  99546. if(nonzero){
  99547. int y0=-200;
  99548. int y1=-200;
  99549. fit_line(fits,posts-1,&y0,&y1);
  99550. fit_valueA[0]=y0;
  99551. fit_valueB[0]=y0;
  99552. fit_valueB[1]=y1;
  99553. fit_valueA[1]=y1;
  99554. for(i=2;i<posts;i++){
  99555. int sortpos=look->reverse_index[i];
  99556. int ln=loneighbor[sortpos];
  99557. int hn=hineighbor[sortpos];
  99558. if(memo[ln]!=hn){
  99559. int lsortpos=look->reverse_index[ln];
  99560. int hsortpos=look->reverse_index[hn];
  99561. memo[ln]=hn;
  99562. {
  99563. int lx=info->postlist[ln];
  99564. int hx=info->postlist[hn];
  99565. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99566. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99567. if(ly==-1 || hy==-1){
  99568. exit(1);
  99569. }
  99570. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99571. int ly0=-200;
  99572. int ly1=-200;
  99573. int hy0=-200;
  99574. int hy1=-200;
  99575. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99576. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99577. fit_valueB[ln]=ly0;
  99578. if(ln==0)fit_valueA[ln]=ly0;
  99579. fit_valueA[i]=ly1;
  99580. fit_valueB[i]=hy0;
  99581. fit_valueA[hn]=hy1;
  99582. if(hn==1)fit_valueB[hn]=hy1;
  99583. if(ly1>=0 || hy0>=0){
  99584. for(j=sortpos-1;j>=0;j--)
  99585. if(hineighbor[j]==hn)
  99586. hineighbor[j]=i;
  99587. else
  99588. break;
  99589. for(j=sortpos+1;j<posts;j++)
  99590. if(loneighbor[j]==ln)
  99591. loneighbor[j]=i;
  99592. else
  99593. break;
  99594. }
  99595. }else{
  99596. fit_valueA[i]=-200;
  99597. fit_valueB[i]=-200;
  99598. }
  99599. }
  99600. }
  99601. }
  99602. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99603. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99604. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99605. for(i=2;i<posts;i++){
  99606. int ln=look->loneighbor[i-2];
  99607. int hn=look->hineighbor[i-2];
  99608. int x0=info->postlist[ln];
  99609. int x1=info->postlist[hn];
  99610. int y0=output[ln];
  99611. int y1=output[hn];
  99612. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99613. int vx=post_Y(fit_valueA,fit_valueB,i);
  99614. if(vx>=0 && predicted!=vx){
  99615. output[i]=vx;
  99616. }else{
  99617. output[i]= predicted|0x8000;
  99618. }
  99619. }
  99620. }
  99621. return(output);
  99622. }
  99623. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99624. int *A,int *B,
  99625. int del){
  99626. long i;
  99627. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99628. long posts=look->posts;
  99629. int *output=NULL;
  99630. if(A && B){
  99631. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99632. for(i=0;i<posts;i++){
  99633. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99634. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99635. }
  99636. }
  99637. return(output);
  99638. }
  99639. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99640. void*look_,
  99641. int *post,int *ilogmask){
  99642. long i,j;
  99643. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99644. vorbis_info_floor1 *info=look->vi;
  99645. long posts=look->posts;
  99646. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99647. int out[VIF_POSIT+2];
  99648. static_codebook **sbooks=ci->book_param;
  99649. codebook *books=ci->fullbooks;
  99650. static long seq=0;
  99651. if(post){
  99652. for(i=0;i<posts;i++){
  99653. int val=post[i]&0x7fff;
  99654. switch(info->mult){
  99655. case 1: /* 1024 -> 256 */
  99656. val>>=2;
  99657. break;
  99658. case 2: /* 1024 -> 128 */
  99659. val>>=3;
  99660. break;
  99661. case 3: /* 1024 -> 86 */
  99662. val/=12;
  99663. break;
  99664. case 4: /* 1024 -> 64 */
  99665. val>>=4;
  99666. break;
  99667. }
  99668. post[i]=val | (post[i]&0x8000);
  99669. }
  99670. out[0]=post[0];
  99671. out[1]=post[1];
  99672. for(i=2;i<posts;i++){
  99673. int ln=look->loneighbor[i-2];
  99674. int hn=look->hineighbor[i-2];
  99675. int x0=info->postlist[ln];
  99676. int x1=info->postlist[hn];
  99677. int y0=post[ln];
  99678. int y1=post[hn];
  99679. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99680. if((post[i]&0x8000) || (predicted==post[i])){
  99681. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99682. in interpolation */
  99683. out[i]=0;
  99684. }else{
  99685. int headroom=(look->quant_q-predicted<predicted?
  99686. look->quant_q-predicted:predicted);
  99687. int val=post[i]-predicted;
  99688. if(val<0)
  99689. if(val<-headroom)
  99690. val=headroom-val-1;
  99691. else
  99692. val=-1-(val<<1);
  99693. else
  99694. if(val>=headroom)
  99695. val= val+headroom;
  99696. else
  99697. val<<=1;
  99698. out[i]=val;
  99699. post[ln]&=0x7fff;
  99700. post[hn]&=0x7fff;
  99701. }
  99702. }
  99703. oggpack_write(opb,1,1);
  99704. look->frames++;
  99705. look->postbits+=ilog(look->quant_q-1)*2;
  99706. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99707. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99708. for(i=0,j=2;i<info->partitions;i++){
  99709. int classx=info->partitionclass[i];
  99710. int cdim=info->class_dim[classx];
  99711. int csubbits=info->class_subs[classx];
  99712. int csub=1<<csubbits;
  99713. int bookas[8]={0,0,0,0,0,0,0,0};
  99714. int cval=0;
  99715. int cshift=0;
  99716. int k,l;
  99717. if(csubbits){
  99718. int maxval[8];
  99719. for(k=0;k<csub;k++){
  99720. int booknum=info->class_subbook[classx][k];
  99721. if(booknum<0){
  99722. maxval[k]=1;
  99723. }else{
  99724. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99725. }
  99726. }
  99727. for(k=0;k<cdim;k++){
  99728. for(l=0;l<csub;l++){
  99729. int val=out[j+k];
  99730. if(val<maxval[l]){
  99731. bookas[k]=l;
  99732. break;
  99733. }
  99734. }
  99735. cval|= bookas[k]<<cshift;
  99736. cshift+=csubbits;
  99737. }
  99738. look->phrasebits+=
  99739. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99740. #ifdef TRAIN_FLOOR1
  99741. {
  99742. FILE *of;
  99743. char buffer[80];
  99744. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99745. vb->pcmend/2,posts-2,class);
  99746. of=fopen(buffer,"a");
  99747. fprintf(of,"%d\n",cval);
  99748. fclose(of);
  99749. }
  99750. #endif
  99751. }
  99752. for(k=0;k<cdim;k++){
  99753. int book=info->class_subbook[classx][bookas[k]];
  99754. if(book>=0){
  99755. if(out[j+k]<(books+book)->entries)
  99756. look->postbits+=vorbis_book_encode(books+book,
  99757. out[j+k],opb);
  99758. #ifdef TRAIN_FLOOR1
  99759. {
  99760. FILE *of;
  99761. char buffer[80];
  99762. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99763. vb->pcmend/2,posts-2,class,bookas[k]);
  99764. of=fopen(buffer,"a");
  99765. fprintf(of,"%d\n",out[j+k]);
  99766. fclose(of);
  99767. }
  99768. #endif
  99769. }
  99770. }
  99771. j+=cdim;
  99772. }
  99773. {
  99774. int hx=0;
  99775. int lx=0;
  99776. int ly=post[0]*info->mult;
  99777. for(j=1;j<look->posts;j++){
  99778. int current=look->forward_index[j];
  99779. int hy=post[current]&0x7fff;
  99780. if(hy==post[current]){
  99781. hy*=info->mult;
  99782. hx=info->postlist[current];
  99783. render_line0(lx,hx,ly,hy,ilogmask);
  99784. lx=hx;
  99785. ly=hy;
  99786. }
  99787. }
  99788. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99789. seq++;
  99790. return(1);
  99791. }
  99792. }else{
  99793. oggpack_write(opb,0,1);
  99794. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99795. seq++;
  99796. return(0);
  99797. }
  99798. }
  99799. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99800. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99801. vorbis_info_floor1 *info=look->vi;
  99802. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99803. int i,j,k;
  99804. codebook *books=ci->fullbooks;
  99805. if(oggpack_read(&vb->opb,1)==1){
  99806. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99807. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99808. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99809. for(i=0,j=2;i<info->partitions;i++){
  99810. int classx=info->partitionclass[i];
  99811. int cdim=info->class_dim[classx];
  99812. int csubbits=info->class_subs[classx];
  99813. int csub=1<<csubbits;
  99814. int cval=0;
  99815. if(csubbits){
  99816. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99817. if(cval==-1)goto eop;
  99818. }
  99819. for(k=0;k<cdim;k++){
  99820. int book=info->class_subbook[classx][cval&(csub-1)];
  99821. cval>>=csubbits;
  99822. if(book>=0){
  99823. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99824. goto eop;
  99825. }else{
  99826. fit_value[j+k]=0;
  99827. }
  99828. }
  99829. j+=cdim;
  99830. }
  99831. for(i=2;i<look->posts;i++){
  99832. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99833. info->postlist[look->hineighbor[i-2]],
  99834. fit_value[look->loneighbor[i-2]],
  99835. fit_value[look->hineighbor[i-2]],
  99836. info->postlist[i]);
  99837. int hiroom=look->quant_q-predicted;
  99838. int loroom=predicted;
  99839. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99840. int val=fit_value[i];
  99841. if(val){
  99842. if(val>=room){
  99843. if(hiroom>loroom){
  99844. val = val-loroom;
  99845. }else{
  99846. val = -1-(val-hiroom);
  99847. }
  99848. }else{
  99849. if(val&1){
  99850. val= -((val+1)>>1);
  99851. }else{
  99852. val>>=1;
  99853. }
  99854. }
  99855. fit_value[i]=val+predicted;
  99856. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99857. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99858. }else{
  99859. fit_value[i]=predicted|0x8000;
  99860. }
  99861. }
  99862. return(fit_value);
  99863. }
  99864. eop:
  99865. return(NULL);
  99866. }
  99867. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99868. float *out){
  99869. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99870. vorbis_info_floor1 *info=look->vi;
  99871. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99872. int n=ci->blocksizes[vb->W]/2;
  99873. int j;
  99874. if(memo){
  99875. int *fit_value=(int *)memo;
  99876. int hx=0;
  99877. int lx=0;
  99878. int ly=fit_value[0]*info->mult;
  99879. for(j=1;j<look->posts;j++){
  99880. int current=look->forward_index[j];
  99881. int hy=fit_value[current]&0x7fff;
  99882. if(hy==fit_value[current]){
  99883. hy*=info->mult;
  99884. hx=info->postlist[current];
  99885. render_line(lx,hx,ly,hy,out);
  99886. lx=hx;
  99887. ly=hy;
  99888. }
  99889. }
  99890. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99891. return(1);
  99892. }
  99893. memset(out,0,sizeof(*out)*n);
  99894. return(0);
  99895. }
  99896. vorbis_func_floor floor1_exportbundle={
  99897. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99898. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99899. };
  99900. #endif
  99901. /*** End of inlined file: floor1.c ***/
  99902. /*** Start of inlined file: info.c ***/
  99903. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99904. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99905. // tasks..
  99906. #if JUCE_MSVC
  99907. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99908. #endif
  99909. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99910. #if JUCE_USE_OGGVORBIS
  99911. #include <stdlib.h>
  99912. #include <string.h>
  99913. #include <ctype.h>
  99914. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99915. while(bytes--){
  99916. oggpack_write(o,*s++,8);
  99917. }
  99918. }
  99919. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99920. while(bytes--){
  99921. *buf++=oggpack_read(o,8);
  99922. }
  99923. }
  99924. void vorbis_comment_init(vorbis_comment *vc){
  99925. memset(vc,0,sizeof(*vc));
  99926. }
  99927. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  99928. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  99929. (vc->comments+2)*sizeof(*vc->user_comments));
  99930. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  99931. (vc->comments+2)*sizeof(*vc->comment_lengths));
  99932. vc->comment_lengths[vc->comments]=strlen(comment);
  99933. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  99934. strcpy(vc->user_comments[vc->comments], comment);
  99935. vc->comments++;
  99936. vc->user_comments[vc->comments]=NULL;
  99937. }
  99938. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  99939. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  99940. strcpy(comment, tag);
  99941. strcat(comment, "=");
  99942. strcat(comment, contents);
  99943. vorbis_comment_add(vc, comment);
  99944. }
  99945. static int tagcompare(const char *s1, const char *s2, int n){
  99946. int c=0;
  99947. while(c < n){
  99948. if(toupper(s1[c]) != toupper(s2[c]))
  99949. return !0;
  99950. c++;
  99951. }
  99952. return 0;
  99953. }
  99954. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  99955. long i;
  99956. int found = 0;
  99957. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99958. char *fulltag = (char*)alloca(taglen+ 1);
  99959. strcpy(fulltag, tag);
  99960. strcat(fulltag, "=");
  99961. for(i=0;i<vc->comments;i++){
  99962. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  99963. if(count == found)
  99964. return vc->user_comments[i] + taglen;
  99965. else
  99966. found++;
  99967. }
  99968. }
  99969. return NULL; /* didn't find anything */
  99970. }
  99971. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  99972. int i,count=0;
  99973. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99974. char *fulltag = (char*)alloca(taglen+1);
  99975. strcpy(fulltag,tag);
  99976. strcat(fulltag, "=");
  99977. for(i=0;i<vc->comments;i++){
  99978. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  99979. count++;
  99980. }
  99981. return count;
  99982. }
  99983. void vorbis_comment_clear(vorbis_comment *vc){
  99984. if(vc){
  99985. long i;
  99986. for(i=0;i<vc->comments;i++)
  99987. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  99988. if(vc->user_comments)_ogg_free(vc->user_comments);
  99989. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  99990. if(vc->vendor)_ogg_free(vc->vendor);
  99991. }
  99992. memset(vc,0,sizeof(*vc));
  99993. }
  99994. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  99995. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  99996. return ci ? ci->blocksizes[zo] : -1;
  99997. }
  99998. void vorbis_info_init(vorbis_info *vi){
  99999. memset(vi,0,sizeof(*vi));
  100000. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100001. }
  100002. void vorbis_info_clear(vorbis_info *vi){
  100003. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100004. int i;
  100005. if(ci){
  100006. for(i=0;i<ci->modes;i++)
  100007. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100008. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100009. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100010. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100011. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100012. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100013. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100014. for(i=0;i<ci->books;i++){
  100015. if(ci->book_param[i]){
  100016. vorbis_staticbook_destroy(ci->book_param[i]);
  100017. }
  100018. if(ci->fullbooks)
  100019. vorbis_book_clear(ci->fullbooks+i);
  100020. }
  100021. if(ci->fullbooks)
  100022. _ogg_free(ci->fullbooks);
  100023. for(i=0;i<ci->psys;i++)
  100024. _vi_psy_free(ci->psy_param[i]);
  100025. _ogg_free(ci);
  100026. }
  100027. memset(vi,0,sizeof(*vi));
  100028. }
  100029. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100030. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100031. if(!ci)return(OV_EFAULT);
  100032. vi->version=oggpack_read(opb,32);
  100033. if(vi->version!=0)return(OV_EVERSION);
  100034. vi->channels=oggpack_read(opb,8);
  100035. vi->rate=oggpack_read(opb,32);
  100036. vi->bitrate_upper=oggpack_read(opb,32);
  100037. vi->bitrate_nominal=oggpack_read(opb,32);
  100038. vi->bitrate_lower=oggpack_read(opb,32);
  100039. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100040. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100041. if(vi->rate<1)goto err_out;
  100042. if(vi->channels<1)goto err_out;
  100043. if(ci->blocksizes[0]<8)goto err_out;
  100044. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100045. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100046. return(0);
  100047. err_out:
  100048. vorbis_info_clear(vi);
  100049. return(OV_EBADHEADER);
  100050. }
  100051. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100052. int i;
  100053. int vendorlen=oggpack_read(opb,32);
  100054. if(vendorlen<0)goto err_out;
  100055. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100056. _v_readstring(opb,vc->vendor,vendorlen);
  100057. vc->comments=oggpack_read(opb,32);
  100058. if(vc->comments<0)goto err_out;
  100059. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100060. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100061. for(i=0;i<vc->comments;i++){
  100062. int len=oggpack_read(opb,32);
  100063. if(len<0)goto err_out;
  100064. vc->comment_lengths[i]=len;
  100065. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100066. _v_readstring(opb,vc->user_comments[i],len);
  100067. }
  100068. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100069. return(0);
  100070. err_out:
  100071. vorbis_comment_clear(vc);
  100072. return(OV_EBADHEADER);
  100073. }
  100074. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100075. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100076. int i;
  100077. if(!ci)return(OV_EFAULT);
  100078. ci->books=oggpack_read(opb,8)+1;
  100079. for(i=0;i<ci->books;i++){
  100080. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100081. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100082. }
  100083. {
  100084. int times=oggpack_read(opb,6)+1;
  100085. for(i=0;i<times;i++){
  100086. int test=oggpack_read(opb,16);
  100087. if(test<0 || test>=VI_TIMEB)goto err_out;
  100088. }
  100089. }
  100090. ci->floors=oggpack_read(opb,6)+1;
  100091. for(i=0;i<ci->floors;i++){
  100092. ci->floor_type[i]=oggpack_read(opb,16);
  100093. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100094. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100095. if(!ci->floor_param[i])goto err_out;
  100096. }
  100097. ci->residues=oggpack_read(opb,6)+1;
  100098. for(i=0;i<ci->residues;i++){
  100099. ci->residue_type[i]=oggpack_read(opb,16);
  100100. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100101. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100102. if(!ci->residue_param[i])goto err_out;
  100103. }
  100104. ci->maps=oggpack_read(opb,6)+1;
  100105. for(i=0;i<ci->maps;i++){
  100106. ci->map_type[i]=oggpack_read(opb,16);
  100107. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100108. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100109. if(!ci->map_param[i])goto err_out;
  100110. }
  100111. ci->modes=oggpack_read(opb,6)+1;
  100112. for(i=0;i<ci->modes;i++){
  100113. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100114. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100115. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100116. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100117. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100118. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100119. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100120. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100121. }
  100122. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100123. return(0);
  100124. err_out:
  100125. vorbis_info_clear(vi);
  100126. return(OV_EBADHEADER);
  100127. }
  100128. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100129. oggpack_buffer opb;
  100130. if(op){
  100131. oggpack_readinit(&opb,op->packet,op->bytes);
  100132. {
  100133. char buffer[6];
  100134. int packtype=oggpack_read(&opb,8);
  100135. memset(buffer,0,6);
  100136. _v_readstring(&opb,buffer,6);
  100137. if(memcmp(buffer,"vorbis",6)){
  100138. return(OV_ENOTVORBIS);
  100139. }
  100140. switch(packtype){
  100141. case 0x01: /* least significant *bit* is read first */
  100142. if(!op->b_o_s){
  100143. return(OV_EBADHEADER);
  100144. }
  100145. if(vi->rate!=0){
  100146. return(OV_EBADHEADER);
  100147. }
  100148. return(_vorbis_unpack_info(vi,&opb));
  100149. case 0x03: /* least significant *bit* is read first */
  100150. if(vi->rate==0){
  100151. return(OV_EBADHEADER);
  100152. }
  100153. return(_vorbis_unpack_comment(vc,&opb));
  100154. case 0x05: /* least significant *bit* is read first */
  100155. if(vi->rate==0 || vc->vendor==NULL){
  100156. return(OV_EBADHEADER);
  100157. }
  100158. return(_vorbis_unpack_books(vi,&opb));
  100159. default:
  100160. return(OV_EBADHEADER);
  100161. break;
  100162. }
  100163. }
  100164. }
  100165. return(OV_EBADHEADER);
  100166. }
  100167. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100168. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100169. if(!ci)return(OV_EFAULT);
  100170. oggpack_write(opb,0x01,8);
  100171. _v_writestring(opb,"vorbis", 6);
  100172. oggpack_write(opb,0x00,32);
  100173. oggpack_write(opb,vi->channels,8);
  100174. oggpack_write(opb,vi->rate,32);
  100175. oggpack_write(opb,vi->bitrate_upper,32);
  100176. oggpack_write(opb,vi->bitrate_nominal,32);
  100177. oggpack_write(opb,vi->bitrate_lower,32);
  100178. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100179. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100180. oggpack_write(opb,1,1);
  100181. return(0);
  100182. }
  100183. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100184. char temp[]="Xiph.Org libVorbis I 20050304";
  100185. int bytes = strlen(temp);
  100186. oggpack_write(opb,0x03,8);
  100187. _v_writestring(opb,"vorbis", 6);
  100188. oggpack_write(opb,bytes,32);
  100189. _v_writestring(opb,temp, bytes);
  100190. oggpack_write(opb,vc->comments,32);
  100191. if(vc->comments){
  100192. int i;
  100193. for(i=0;i<vc->comments;i++){
  100194. if(vc->user_comments[i]){
  100195. oggpack_write(opb,vc->comment_lengths[i],32);
  100196. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100197. }else{
  100198. oggpack_write(opb,0,32);
  100199. }
  100200. }
  100201. }
  100202. oggpack_write(opb,1,1);
  100203. return(0);
  100204. }
  100205. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100206. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100207. int i;
  100208. if(!ci)return(OV_EFAULT);
  100209. oggpack_write(opb,0x05,8);
  100210. _v_writestring(opb,"vorbis", 6);
  100211. oggpack_write(opb,ci->books-1,8);
  100212. for(i=0;i<ci->books;i++)
  100213. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100214. oggpack_write(opb,0,6);
  100215. oggpack_write(opb,0,16);
  100216. oggpack_write(opb,ci->floors-1,6);
  100217. for(i=0;i<ci->floors;i++){
  100218. oggpack_write(opb,ci->floor_type[i],16);
  100219. if(_floor_P[ci->floor_type[i]]->pack)
  100220. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100221. else
  100222. goto err_out;
  100223. }
  100224. oggpack_write(opb,ci->residues-1,6);
  100225. for(i=0;i<ci->residues;i++){
  100226. oggpack_write(opb,ci->residue_type[i],16);
  100227. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100228. }
  100229. oggpack_write(opb,ci->maps-1,6);
  100230. for(i=0;i<ci->maps;i++){
  100231. oggpack_write(opb,ci->map_type[i],16);
  100232. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100233. }
  100234. oggpack_write(opb,ci->modes-1,6);
  100235. for(i=0;i<ci->modes;i++){
  100236. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100237. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100238. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100239. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100240. }
  100241. oggpack_write(opb,1,1);
  100242. return(0);
  100243. err_out:
  100244. return(-1);
  100245. }
  100246. int vorbis_commentheader_out(vorbis_comment *vc,
  100247. ogg_packet *op){
  100248. oggpack_buffer opb;
  100249. oggpack_writeinit(&opb);
  100250. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100251. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100252. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100253. op->bytes=oggpack_bytes(&opb);
  100254. op->b_o_s=0;
  100255. op->e_o_s=0;
  100256. op->granulepos=0;
  100257. op->packetno=1;
  100258. return 0;
  100259. }
  100260. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100261. vorbis_comment *vc,
  100262. ogg_packet *op,
  100263. ogg_packet *op_comm,
  100264. ogg_packet *op_code){
  100265. int ret=OV_EIMPL;
  100266. vorbis_info *vi=v->vi;
  100267. oggpack_buffer opb;
  100268. private_state *b=(private_state*)v->backend_state;
  100269. if(!b){
  100270. ret=OV_EFAULT;
  100271. goto err_out;
  100272. }
  100273. oggpack_writeinit(&opb);
  100274. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100275. if(b->header)_ogg_free(b->header);
  100276. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100277. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100278. op->packet=b->header;
  100279. op->bytes=oggpack_bytes(&opb);
  100280. op->b_o_s=1;
  100281. op->e_o_s=0;
  100282. op->granulepos=0;
  100283. op->packetno=0;
  100284. oggpack_reset(&opb);
  100285. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100286. if(b->header1)_ogg_free(b->header1);
  100287. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100288. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100289. op_comm->packet=b->header1;
  100290. op_comm->bytes=oggpack_bytes(&opb);
  100291. op_comm->b_o_s=0;
  100292. op_comm->e_o_s=0;
  100293. op_comm->granulepos=0;
  100294. op_comm->packetno=1;
  100295. oggpack_reset(&opb);
  100296. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100297. if(b->header2)_ogg_free(b->header2);
  100298. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100299. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100300. op_code->packet=b->header2;
  100301. op_code->bytes=oggpack_bytes(&opb);
  100302. op_code->b_o_s=0;
  100303. op_code->e_o_s=0;
  100304. op_code->granulepos=0;
  100305. op_code->packetno=2;
  100306. oggpack_writeclear(&opb);
  100307. return(0);
  100308. err_out:
  100309. oggpack_writeclear(&opb);
  100310. memset(op,0,sizeof(*op));
  100311. memset(op_comm,0,sizeof(*op_comm));
  100312. memset(op_code,0,sizeof(*op_code));
  100313. if(b->header)_ogg_free(b->header);
  100314. if(b->header1)_ogg_free(b->header1);
  100315. if(b->header2)_ogg_free(b->header2);
  100316. b->header=NULL;
  100317. b->header1=NULL;
  100318. b->header2=NULL;
  100319. return(ret);
  100320. }
  100321. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100322. if(granulepos>=0)
  100323. return((double)granulepos/v->vi->rate);
  100324. return(-1);
  100325. }
  100326. #endif
  100327. /*** End of inlined file: info.c ***/
  100328. /*** Start of inlined file: lpc.c ***/
  100329. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100330. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100331. // tasks..
  100332. #if JUCE_MSVC
  100333. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100334. #endif
  100335. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100336. #if JUCE_USE_OGGVORBIS
  100337. #include <stdlib.h>
  100338. #include <string.h>
  100339. #include <math.h>
  100340. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100341. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100342. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100343. double error;
  100344. int i,j;
  100345. j=m+1;
  100346. while(j--){
  100347. double d=0; /* double needed for accumulator depth */
  100348. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100349. aut[j]=d;
  100350. }
  100351. error=aut[0];
  100352. for(i=0;i<m;i++){
  100353. double r= -aut[i+1];
  100354. if(error==0){
  100355. memset(lpci,0,m*sizeof(*lpci));
  100356. return 0;
  100357. }
  100358. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100359. r/=error;
  100360. lpc[i]=r;
  100361. for(j=0;j<i/2;j++){
  100362. double tmp=lpc[j];
  100363. lpc[j]+=r*lpc[i-1-j];
  100364. lpc[i-1-j]+=r*tmp;
  100365. }
  100366. if(i%2)lpc[j]+=lpc[j]*r;
  100367. error*=1.f-r*r;
  100368. }
  100369. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100370. return error;
  100371. }
  100372. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100373. float *data,long n){
  100374. long i,j,o,p;
  100375. float y;
  100376. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100377. if(!prime)
  100378. for(i=0;i<m;i++)
  100379. work[i]=0.f;
  100380. else
  100381. for(i=0;i<m;i++)
  100382. work[i]=prime[i];
  100383. for(i=0;i<n;i++){
  100384. y=0;
  100385. o=i;
  100386. p=m;
  100387. for(j=0;j<m;j++)
  100388. y-=work[o++]*coeff[--p];
  100389. data[i]=work[o]=y;
  100390. }
  100391. }
  100392. #endif
  100393. /*** End of inlined file: lpc.c ***/
  100394. /*** Start of inlined file: lsp.c ***/
  100395. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100396. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100397. // tasks..
  100398. #if JUCE_MSVC
  100399. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100400. #endif
  100401. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100402. #if JUCE_USE_OGGVORBIS
  100403. #include <math.h>
  100404. #include <string.h>
  100405. #include <stdlib.h>
  100406. /*** Start of inlined file: lookup.h ***/
  100407. #ifndef _V_LOOKUP_H_
  100408. #ifdef FLOAT_LOOKUP
  100409. extern float vorbis_coslook(float a);
  100410. extern float vorbis_invsqlook(float a);
  100411. extern float vorbis_invsq2explook(int a);
  100412. extern float vorbis_fromdBlook(float a);
  100413. #endif
  100414. #ifdef INT_LOOKUP
  100415. extern long vorbis_invsqlook_i(long a,long e);
  100416. extern long vorbis_coslook_i(long a);
  100417. extern float vorbis_fromdBlook_i(long a);
  100418. #endif
  100419. #endif
  100420. /*** End of inlined file: lookup.h ***/
  100421. #define FLOAT_LOOKUP
  100422. #undef INT_LOOKUP
  100423. #ifdef FLOAT_LOOKUP
  100424. /*** Start of inlined file: lookup.c ***/
  100425. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100426. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100427. // tasks..
  100428. #if JUCE_MSVC
  100429. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100430. #endif
  100431. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100432. #if JUCE_USE_OGGVORBIS
  100433. #include <math.h>
  100434. /*** Start of inlined file: lookup.h ***/
  100435. #ifndef _V_LOOKUP_H_
  100436. #ifdef FLOAT_LOOKUP
  100437. extern float vorbis_coslook(float a);
  100438. extern float vorbis_invsqlook(float a);
  100439. extern float vorbis_invsq2explook(int a);
  100440. extern float vorbis_fromdBlook(float a);
  100441. #endif
  100442. #ifdef INT_LOOKUP
  100443. extern long vorbis_invsqlook_i(long a,long e);
  100444. extern long vorbis_coslook_i(long a);
  100445. extern float vorbis_fromdBlook_i(long a);
  100446. #endif
  100447. #endif
  100448. /*** End of inlined file: lookup.h ***/
  100449. /*** Start of inlined file: lookup_data.h ***/
  100450. #ifndef _V_LOOKUP_DATA_H_
  100451. #ifdef FLOAT_LOOKUP
  100452. #define COS_LOOKUP_SZ 128
  100453. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100454. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100455. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100456. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100457. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100458. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100459. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100460. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100461. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100462. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100463. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100464. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100465. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100466. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100467. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100468. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100469. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100470. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100471. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100472. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100473. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100474. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100475. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100476. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100477. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100478. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100479. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100480. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100481. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100482. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100483. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100484. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100485. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100486. -1.0000000000000f,
  100487. };
  100488. #define INVSQ_LOOKUP_SZ 32
  100489. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100490. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100491. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100492. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100493. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100494. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100495. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100496. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100497. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100498. 1.000000000000f,
  100499. };
  100500. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100501. #define INVSQ2EXP_LOOKUP_MAX 32
  100502. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100503. INVSQ2EXP_LOOKUP_MIN+1]={
  100504. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100505. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100506. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100507. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100508. 256.f, 181.019336f, 128.f, 90.50966799f,
  100509. 64.f, 45.254834f, 32.f, 22.627417f,
  100510. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100511. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100512. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100513. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100514. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100515. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100516. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100517. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100518. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100519. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100520. 1.525878906e-05f,
  100521. };
  100522. #endif
  100523. #define FROMdB_LOOKUP_SZ 35
  100524. #define FROMdB2_LOOKUP_SZ 32
  100525. #define FROMdB_SHIFT 5
  100526. #define FROMdB2_SHIFT 3
  100527. #define FROMdB2_MASK 31
  100528. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100529. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100530. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100531. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100532. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100533. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100534. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100535. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100536. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100537. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100538. };
  100539. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100540. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100541. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100542. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100543. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100544. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100545. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100546. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100547. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100548. };
  100549. #ifdef INT_LOOKUP
  100550. #define INVSQ_LOOKUP_I_SHIFT 10
  100551. #define INVSQ_LOOKUP_I_MASK 1023
  100552. static long INVSQ_LOOKUP_I[64+1]={
  100553. 92682l, 91966l, 91267l, 90583l,
  100554. 89915l, 89261l, 88621l, 87995l,
  100555. 87381l, 86781l, 86192l, 85616l,
  100556. 85051l, 84497l, 83953l, 83420l,
  100557. 82897l, 82384l, 81880l, 81385l,
  100558. 80899l, 80422l, 79953l, 79492l,
  100559. 79039l, 78594l, 78156l, 77726l,
  100560. 77302l, 76885l, 76475l, 76072l,
  100561. 75674l, 75283l, 74898l, 74519l,
  100562. 74146l, 73778l, 73415l, 73058l,
  100563. 72706l, 72359l, 72016l, 71679l,
  100564. 71347l, 71019l, 70695l, 70376l,
  100565. 70061l, 69750l, 69444l, 69141l,
  100566. 68842l, 68548l, 68256l, 67969l,
  100567. 67685l, 67405l, 67128l, 66855l,
  100568. 66585l, 66318l, 66054l, 65794l,
  100569. 65536l,
  100570. };
  100571. #define COS_LOOKUP_I_SHIFT 9
  100572. #define COS_LOOKUP_I_MASK 511
  100573. #define COS_LOOKUP_I_SZ 128
  100574. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100575. 16384l, 16379l, 16364l, 16340l,
  100576. 16305l, 16261l, 16207l, 16143l,
  100577. 16069l, 15986l, 15893l, 15791l,
  100578. 15679l, 15557l, 15426l, 15286l,
  100579. 15137l, 14978l, 14811l, 14635l,
  100580. 14449l, 14256l, 14053l, 13842l,
  100581. 13623l, 13395l, 13160l, 12916l,
  100582. 12665l, 12406l, 12140l, 11866l,
  100583. 11585l, 11297l, 11003l, 10702l,
  100584. 10394l, 10080l, 9760l, 9434l,
  100585. 9102l, 8765l, 8423l, 8076l,
  100586. 7723l, 7366l, 7005l, 6639l,
  100587. 6270l, 5897l, 5520l, 5139l,
  100588. 4756l, 4370l, 3981l, 3590l,
  100589. 3196l, 2801l, 2404l, 2006l,
  100590. 1606l, 1205l, 804l, 402l,
  100591. 0l, -401l, -803l, -1204l,
  100592. -1605l, -2005l, -2403l, -2800l,
  100593. -3195l, -3589l, -3980l, -4369l,
  100594. -4755l, -5138l, -5519l, -5896l,
  100595. -6269l, -6638l, -7004l, -7365l,
  100596. -7722l, -8075l, -8422l, -8764l,
  100597. -9101l, -9433l, -9759l, -10079l,
  100598. -10393l, -10701l, -11002l, -11296l,
  100599. -11584l, -11865l, -12139l, -12405l,
  100600. -12664l, -12915l, -13159l, -13394l,
  100601. -13622l, -13841l, -14052l, -14255l,
  100602. -14448l, -14634l, -14810l, -14977l,
  100603. -15136l, -15285l, -15425l, -15556l,
  100604. -15678l, -15790l, -15892l, -15985l,
  100605. -16068l, -16142l, -16206l, -16260l,
  100606. -16304l, -16339l, -16363l, -16378l,
  100607. -16383l,
  100608. };
  100609. #endif
  100610. #endif
  100611. /*** End of inlined file: lookup_data.h ***/
  100612. #ifdef FLOAT_LOOKUP
  100613. float vorbis_coslook(float a){
  100614. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100615. int i=vorbis_ftoi(d-.5);
  100616. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100617. }
  100618. float vorbis_invsqlook(float a){
  100619. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100620. int i=vorbis_ftoi(d-.5f);
  100621. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100622. }
  100623. float vorbis_invsq2explook(int a){
  100624. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100625. }
  100626. #include <stdio.h>
  100627. float vorbis_fromdBlook(float a){
  100628. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100629. return (i<0)?1.f:
  100630. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100631. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100632. }
  100633. #endif
  100634. #ifdef INT_LOOKUP
  100635. long vorbis_invsqlook_i(long a,long e){
  100636. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100637. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100638. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100639. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100640. d)>>16); /* result 1.16 */
  100641. e+=32;
  100642. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100643. e=(e>>1)-8;
  100644. return(val>>e);
  100645. }
  100646. float vorbis_fromdBlook_i(long a){
  100647. int i=(-a)>>(12-FROMdB2_SHIFT);
  100648. return (i<0)?1.f:
  100649. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100650. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100651. }
  100652. long vorbis_coslook_i(long a){
  100653. int i=a>>COS_LOOKUP_I_SHIFT;
  100654. int d=a&COS_LOOKUP_I_MASK;
  100655. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100656. COS_LOOKUP_I_SHIFT);
  100657. }
  100658. #endif
  100659. #endif
  100660. /*** End of inlined file: lookup.c ***/
  100661. /* catch this in the build system; we #include for
  100662. compilers (like gcc) that can't inline across
  100663. modules */
  100664. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100665. float amp,float ampoffset){
  100666. int i;
  100667. float wdel=M_PI/ln;
  100668. vorbis_fpu_control fpu;
  100669. (void) fpu; // to avoid an unused variable warning
  100670. vorbis_fpu_setround(&fpu);
  100671. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100672. i=0;
  100673. while(i<n){
  100674. int k=map[i];
  100675. int qexp;
  100676. float p=.7071067812f;
  100677. float q=.7071067812f;
  100678. float w=vorbis_coslook(wdel*k);
  100679. float *ftmp=lsp;
  100680. int c=m>>1;
  100681. do{
  100682. q*=ftmp[0]-w;
  100683. p*=ftmp[1]-w;
  100684. ftmp+=2;
  100685. }while(--c);
  100686. if(m&1){
  100687. q*=ftmp[0]-w;
  100688. q*=q;
  100689. p*=p*(1.f-w*w);
  100690. }else{
  100691. q*=q*(1.f+w);
  100692. p*=p*(1.f-w);
  100693. }
  100694. q=frexp(p+q,&qexp);
  100695. q=vorbis_fromdBlook(amp*
  100696. vorbis_invsqlook(q)*
  100697. vorbis_invsq2explook(qexp+m)-
  100698. ampoffset);
  100699. do{
  100700. curve[i++]*=q;
  100701. }while(map[i]==k);
  100702. }
  100703. vorbis_fpu_restore(fpu);
  100704. }
  100705. #else
  100706. #ifdef INT_LOOKUP
  100707. /*** Start of inlined file: lookup.c ***/
  100708. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100709. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100710. // tasks..
  100711. #if JUCE_MSVC
  100712. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100713. #endif
  100714. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100715. #if JUCE_USE_OGGVORBIS
  100716. #include <math.h>
  100717. /*** Start of inlined file: lookup.h ***/
  100718. #ifndef _V_LOOKUP_H_
  100719. #ifdef FLOAT_LOOKUP
  100720. extern float vorbis_coslook(float a);
  100721. extern float vorbis_invsqlook(float a);
  100722. extern float vorbis_invsq2explook(int a);
  100723. extern float vorbis_fromdBlook(float a);
  100724. #endif
  100725. #ifdef INT_LOOKUP
  100726. extern long vorbis_invsqlook_i(long a,long e);
  100727. extern long vorbis_coslook_i(long a);
  100728. extern float vorbis_fromdBlook_i(long a);
  100729. #endif
  100730. #endif
  100731. /*** End of inlined file: lookup.h ***/
  100732. /*** Start of inlined file: lookup_data.h ***/
  100733. #ifndef _V_LOOKUP_DATA_H_
  100734. #ifdef FLOAT_LOOKUP
  100735. #define COS_LOOKUP_SZ 128
  100736. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100737. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100738. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100739. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100740. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100741. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100742. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100743. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100744. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100745. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100746. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100747. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100748. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100749. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100750. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100751. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100752. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100753. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100754. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100755. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100756. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100757. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100758. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100759. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100760. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100761. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100762. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100763. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100764. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100765. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100766. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100767. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100768. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100769. -1.0000000000000f,
  100770. };
  100771. #define INVSQ_LOOKUP_SZ 32
  100772. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100773. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100774. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100775. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100776. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100777. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100778. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100779. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100780. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100781. 1.000000000000f,
  100782. };
  100783. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100784. #define INVSQ2EXP_LOOKUP_MAX 32
  100785. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100786. INVSQ2EXP_LOOKUP_MIN+1]={
  100787. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100788. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100789. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100790. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100791. 256.f, 181.019336f, 128.f, 90.50966799f,
  100792. 64.f, 45.254834f, 32.f, 22.627417f,
  100793. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100794. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100795. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100796. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100797. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100798. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100799. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100800. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100801. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100802. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100803. 1.525878906e-05f,
  100804. };
  100805. #endif
  100806. #define FROMdB_LOOKUP_SZ 35
  100807. #define FROMdB2_LOOKUP_SZ 32
  100808. #define FROMdB_SHIFT 5
  100809. #define FROMdB2_SHIFT 3
  100810. #define FROMdB2_MASK 31
  100811. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100812. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100813. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100814. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100815. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100816. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100817. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100818. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100819. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100820. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100821. };
  100822. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100823. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100824. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100825. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100826. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100827. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100828. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100829. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100830. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100831. };
  100832. #ifdef INT_LOOKUP
  100833. #define INVSQ_LOOKUP_I_SHIFT 10
  100834. #define INVSQ_LOOKUP_I_MASK 1023
  100835. static long INVSQ_LOOKUP_I[64+1]={
  100836. 92682l, 91966l, 91267l, 90583l,
  100837. 89915l, 89261l, 88621l, 87995l,
  100838. 87381l, 86781l, 86192l, 85616l,
  100839. 85051l, 84497l, 83953l, 83420l,
  100840. 82897l, 82384l, 81880l, 81385l,
  100841. 80899l, 80422l, 79953l, 79492l,
  100842. 79039l, 78594l, 78156l, 77726l,
  100843. 77302l, 76885l, 76475l, 76072l,
  100844. 75674l, 75283l, 74898l, 74519l,
  100845. 74146l, 73778l, 73415l, 73058l,
  100846. 72706l, 72359l, 72016l, 71679l,
  100847. 71347l, 71019l, 70695l, 70376l,
  100848. 70061l, 69750l, 69444l, 69141l,
  100849. 68842l, 68548l, 68256l, 67969l,
  100850. 67685l, 67405l, 67128l, 66855l,
  100851. 66585l, 66318l, 66054l, 65794l,
  100852. 65536l,
  100853. };
  100854. #define COS_LOOKUP_I_SHIFT 9
  100855. #define COS_LOOKUP_I_MASK 511
  100856. #define COS_LOOKUP_I_SZ 128
  100857. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100858. 16384l, 16379l, 16364l, 16340l,
  100859. 16305l, 16261l, 16207l, 16143l,
  100860. 16069l, 15986l, 15893l, 15791l,
  100861. 15679l, 15557l, 15426l, 15286l,
  100862. 15137l, 14978l, 14811l, 14635l,
  100863. 14449l, 14256l, 14053l, 13842l,
  100864. 13623l, 13395l, 13160l, 12916l,
  100865. 12665l, 12406l, 12140l, 11866l,
  100866. 11585l, 11297l, 11003l, 10702l,
  100867. 10394l, 10080l, 9760l, 9434l,
  100868. 9102l, 8765l, 8423l, 8076l,
  100869. 7723l, 7366l, 7005l, 6639l,
  100870. 6270l, 5897l, 5520l, 5139l,
  100871. 4756l, 4370l, 3981l, 3590l,
  100872. 3196l, 2801l, 2404l, 2006l,
  100873. 1606l, 1205l, 804l, 402l,
  100874. 0l, -401l, -803l, -1204l,
  100875. -1605l, -2005l, -2403l, -2800l,
  100876. -3195l, -3589l, -3980l, -4369l,
  100877. -4755l, -5138l, -5519l, -5896l,
  100878. -6269l, -6638l, -7004l, -7365l,
  100879. -7722l, -8075l, -8422l, -8764l,
  100880. -9101l, -9433l, -9759l, -10079l,
  100881. -10393l, -10701l, -11002l, -11296l,
  100882. -11584l, -11865l, -12139l, -12405l,
  100883. -12664l, -12915l, -13159l, -13394l,
  100884. -13622l, -13841l, -14052l, -14255l,
  100885. -14448l, -14634l, -14810l, -14977l,
  100886. -15136l, -15285l, -15425l, -15556l,
  100887. -15678l, -15790l, -15892l, -15985l,
  100888. -16068l, -16142l, -16206l, -16260l,
  100889. -16304l, -16339l, -16363l, -16378l,
  100890. -16383l,
  100891. };
  100892. #endif
  100893. #endif
  100894. /*** End of inlined file: lookup_data.h ***/
  100895. #ifdef FLOAT_LOOKUP
  100896. float vorbis_coslook(float a){
  100897. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100898. int i=vorbis_ftoi(d-.5);
  100899. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100900. }
  100901. float vorbis_invsqlook(float a){
  100902. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100903. int i=vorbis_ftoi(d-.5f);
  100904. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100905. }
  100906. float vorbis_invsq2explook(int a){
  100907. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100908. }
  100909. #include <stdio.h>
  100910. float vorbis_fromdBlook(float a){
  100911. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100912. return (i<0)?1.f:
  100913. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100914. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100915. }
  100916. #endif
  100917. #ifdef INT_LOOKUP
  100918. long vorbis_invsqlook_i(long a,long e){
  100919. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100920. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100921. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100922. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100923. d)>>16); /* result 1.16 */
  100924. e+=32;
  100925. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100926. e=(e>>1)-8;
  100927. return(val>>e);
  100928. }
  100929. float vorbis_fromdBlook_i(long a){
  100930. int i=(-a)>>(12-FROMdB2_SHIFT);
  100931. return (i<0)?1.f:
  100932. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100933. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100934. }
  100935. long vorbis_coslook_i(long a){
  100936. int i=a>>COS_LOOKUP_I_SHIFT;
  100937. int d=a&COS_LOOKUP_I_MASK;
  100938. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100939. COS_LOOKUP_I_SHIFT);
  100940. }
  100941. #endif
  100942. #endif
  100943. /*** End of inlined file: lookup.c ***/
  100944. /* catch this in the build system; we #include for
  100945. compilers (like gcc) that can't inline across
  100946. modules */
  100947. static int MLOOP_1[64]={
  100948. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  100949. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  100950. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100951. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100952. };
  100953. static int MLOOP_2[64]={
  100954. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  100955. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  100956. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100957. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100958. };
  100959. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  100960. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100961. float amp,float ampoffset){
  100962. int i;
  100963. int ampoffseti=rint(ampoffset*4096.f);
  100964. int ampi=rint(amp*16.f);
  100965. long *ilsp=alloca(m*sizeof(*ilsp));
  100966. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  100967. i=0;
  100968. while(i<n){
  100969. int j,k=map[i];
  100970. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  100971. unsigned long qi=46341;
  100972. int qexp=0,shift;
  100973. long wi=vorbis_coslook_i(k*65536/ln);
  100974. qi*=labs(ilsp[0]-wi);
  100975. pi*=labs(ilsp[1]-wi);
  100976. for(j=3;j<m;j+=2){
  100977. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100978. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100979. shift=MLOOP_3[(pi|qi)>>16];
  100980. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100981. pi=(pi>>shift)*labs(ilsp[j]-wi);
  100982. qexp+=shift;
  100983. }
  100984. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100985. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100986. shift=MLOOP_3[(pi|qi)>>16];
  100987. if(m&1){
  100988. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100989. pi=(pi>>shift)<<14;
  100990. qexp+=shift;
  100991. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100992. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100993. shift=MLOOP_3[(pi|qi)>>16];
  100994. pi>>=shift;
  100995. qi>>=shift;
  100996. qexp+=shift-14*((m+1)>>1);
  100997. pi=((pi*pi)>>16);
  100998. qi=((qi*qi)>>16);
  100999. qexp=qexp*2+m;
  101000. pi*=(1<<14)-((wi*wi)>>14);
  101001. qi+=pi>>14;
  101002. }else{
  101003. pi>>=shift;
  101004. qi>>=shift;
  101005. qexp+=shift-7*m;
  101006. pi=((pi*pi)>>16);
  101007. qi=((qi*qi)>>16);
  101008. qexp=qexp*2+m;
  101009. pi*=(1<<14)-wi;
  101010. qi*=(1<<14)+wi;
  101011. qi=(qi+pi)>>14;
  101012. }
  101013. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101014. qi>>=1; qexp++;
  101015. }else
  101016. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101017. qi<<=1; qexp--;
  101018. }
  101019. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101020. vorbis_invsqlook_i(qi,qexp)-
  101021. ampoffseti); /* 8.12[0] */
  101022. curve[i]*=amp;
  101023. while(map[++i]==k)curve[i]*=amp;
  101024. }
  101025. }
  101026. #else
  101027. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101028. float amp,float ampoffset){
  101029. int i;
  101030. float wdel=M_PI/ln;
  101031. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101032. i=0;
  101033. while(i<n){
  101034. int j,k=map[i];
  101035. float p=.5f;
  101036. float q=.5f;
  101037. float w=2.f*cos(wdel*k);
  101038. for(j=1;j<m;j+=2){
  101039. q *= w-lsp[j-1];
  101040. p *= w-lsp[j];
  101041. }
  101042. if(j==m){
  101043. q*=w-lsp[j-1];
  101044. p*=p*(4.f-w*w);
  101045. q*=q;
  101046. }else{
  101047. p*=p*(2.f-w);
  101048. q*=q*(2.f+w);
  101049. }
  101050. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101051. curve[i]*=q;
  101052. while(map[++i]==k)curve[i]*=q;
  101053. }
  101054. }
  101055. #endif
  101056. #endif
  101057. static void cheby(float *g, int ord) {
  101058. int i, j;
  101059. g[0] *= .5f;
  101060. for(i=2; i<= ord; i++) {
  101061. for(j=ord; j >= i; j--) {
  101062. g[j-2] -= g[j];
  101063. g[j] += g[j];
  101064. }
  101065. }
  101066. }
  101067. static int comp(const void *a,const void *b){
  101068. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101069. }
  101070. #define EPSILON 10e-7
  101071. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101072. int i,m;
  101073. double lastdelta=0.f;
  101074. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101075. for(i=0;i<=ord;i++)defl[i]=a[i];
  101076. for(m=ord;m>0;m--){
  101077. double newx=0.f,delta;
  101078. while(1){
  101079. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101080. for(i=m;i>0;i--){
  101081. ppp = newx*ppp + pp;
  101082. pp = newx*pp + p;
  101083. p = newx*p + defl[i-1];
  101084. }
  101085. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101086. if(denom<0)
  101087. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101088. if(pp>0){
  101089. denom = pp + sqrt(denom);
  101090. if(denom<EPSILON)denom=EPSILON;
  101091. }else{
  101092. denom = pp - sqrt(denom);
  101093. if(denom>-(EPSILON))denom=-(EPSILON);
  101094. }
  101095. delta = m*p/denom;
  101096. newx -= delta;
  101097. if(delta<0.f)delta*=-1;
  101098. if(fabs(delta/newx)<10e-12)break;
  101099. lastdelta=delta;
  101100. }
  101101. r[m-1]=newx;
  101102. for(i=m;i>0;i--)
  101103. defl[i-1]+=newx*defl[i];
  101104. defl++;
  101105. }
  101106. return(0);
  101107. }
  101108. static int Newton_Raphson(float *a,int ord,float *r){
  101109. int i, k, count=0;
  101110. double error=1.f;
  101111. double *root=(double*)alloca(ord*sizeof(*root));
  101112. for(i=0; i<ord;i++) root[i] = r[i];
  101113. while(error>1e-20){
  101114. error=0;
  101115. for(i=0; i<ord; i++) { /* Update each point. */
  101116. double pp=0.,delta;
  101117. double rooti=root[i];
  101118. double p=a[ord];
  101119. for(k=ord-1; k>= 0; k--) {
  101120. pp= pp* rooti + p;
  101121. p = p * rooti + a[k];
  101122. }
  101123. delta = p/pp;
  101124. root[i] -= delta;
  101125. error+= delta*delta;
  101126. }
  101127. if(count>40)return(-1);
  101128. count++;
  101129. }
  101130. for(i=0; i<ord;i++) r[i] = root[i];
  101131. return(0);
  101132. }
  101133. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101134. int order2=(m+1)>>1;
  101135. int g1_order,g2_order;
  101136. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101137. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101138. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101139. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101140. int i;
  101141. g1_order=(m+1)>>1;
  101142. g2_order=(m) >>1;
  101143. g1[g1_order] = 1.f;
  101144. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101145. g2[g2_order] = 1.f;
  101146. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101147. if(g1_order>g2_order){
  101148. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101149. }else{
  101150. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101151. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101152. }
  101153. cheby(g1,g1_order);
  101154. cheby(g2,g2_order);
  101155. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101156. Laguerre_With_Deflation(g2,g2_order,g2r))
  101157. return(-1);
  101158. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101159. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101160. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101161. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101162. for(i=0;i<g1_order;i++)
  101163. lsp[i*2] = acos(g1r[i]);
  101164. for(i=0;i<g2_order;i++)
  101165. lsp[i*2+1] = acos(g2r[i]);
  101166. return(0);
  101167. }
  101168. #endif
  101169. /*** End of inlined file: lsp.c ***/
  101170. /*** Start of inlined file: mapping0.c ***/
  101171. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101172. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101173. // tasks..
  101174. #if JUCE_MSVC
  101175. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101176. #endif
  101177. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101178. #if JUCE_USE_OGGVORBIS
  101179. #include <stdlib.h>
  101180. #include <stdio.h>
  101181. #include <string.h>
  101182. #include <math.h>
  101183. static void mapping0_free_info(vorbis_info_mapping *i){
  101184. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101185. if(info){
  101186. memset(info,0,sizeof(*info));
  101187. _ogg_free(info);
  101188. }
  101189. }
  101190. static int ilog3(unsigned int v){
  101191. int ret=0;
  101192. if(v)--v;
  101193. while(v){
  101194. ret++;
  101195. v>>=1;
  101196. }
  101197. return(ret);
  101198. }
  101199. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101200. oggpack_buffer *opb){
  101201. int i;
  101202. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101203. if(info->submaps>1){
  101204. oggpack_write(opb,1,1);
  101205. oggpack_write(opb,info->submaps-1,4);
  101206. }else
  101207. oggpack_write(opb,0,1);
  101208. if(info->coupling_steps>0){
  101209. oggpack_write(opb,1,1);
  101210. oggpack_write(opb,info->coupling_steps-1,8);
  101211. for(i=0;i<info->coupling_steps;i++){
  101212. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101213. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101214. }
  101215. }else
  101216. oggpack_write(opb,0,1);
  101217. oggpack_write(opb,0,2); /* 2,3:reserved */
  101218. if(info->submaps>1){
  101219. for(i=0;i<vi->channels;i++)
  101220. oggpack_write(opb,info->chmuxlist[i],4);
  101221. }
  101222. for(i=0;i<info->submaps;i++){
  101223. oggpack_write(opb,0,8); /* time submap unused */
  101224. oggpack_write(opb,info->floorsubmap[i],8);
  101225. oggpack_write(opb,info->residuesubmap[i],8);
  101226. }
  101227. }
  101228. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101229. int i;
  101230. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101231. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101232. memset(info,0,sizeof(*info));
  101233. if(oggpack_read(opb,1))
  101234. info->submaps=oggpack_read(opb,4)+1;
  101235. else
  101236. info->submaps=1;
  101237. if(oggpack_read(opb,1)){
  101238. info->coupling_steps=oggpack_read(opb,8)+1;
  101239. for(i=0;i<info->coupling_steps;i++){
  101240. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101241. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101242. if(testM<0 ||
  101243. testA<0 ||
  101244. testM==testA ||
  101245. testM>=vi->channels ||
  101246. testA>=vi->channels) goto err_out;
  101247. }
  101248. }
  101249. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101250. if(info->submaps>1){
  101251. for(i=0;i<vi->channels;i++){
  101252. info->chmuxlist[i]=oggpack_read(opb,4);
  101253. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101254. }
  101255. }
  101256. for(i=0;i<info->submaps;i++){
  101257. oggpack_read(opb,8); /* time submap unused */
  101258. info->floorsubmap[i]=oggpack_read(opb,8);
  101259. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101260. info->residuesubmap[i]=oggpack_read(opb,8);
  101261. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101262. }
  101263. return info;
  101264. err_out:
  101265. mapping0_free_info(info);
  101266. return(NULL);
  101267. }
  101268. #if 0
  101269. static long seq=0;
  101270. static ogg_int64_t total=0;
  101271. static float FLOOR1_fromdB_LOOKUP[256]={
  101272. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101273. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101274. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101275. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101276. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101277. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101278. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101279. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101280. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101281. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101282. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101283. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101284. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101285. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101286. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101287. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101288. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101289. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101290. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101291. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101292. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101293. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101294. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101295. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101296. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101297. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101298. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101299. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101300. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101301. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101302. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101303. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101304. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101305. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101306. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101307. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101308. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101309. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101310. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101311. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101312. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101313. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101314. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101315. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101316. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101317. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101318. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101319. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101320. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101321. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101322. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101323. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101324. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101325. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101326. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101327. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101328. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101329. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101330. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101331. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101332. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101333. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101334. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101335. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101336. };
  101337. #endif
  101338. extern int *floor1_fit(vorbis_block *vb,void *look,
  101339. const float *logmdct, /* in */
  101340. const float *logmask);
  101341. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101342. int *A,int *B,
  101343. int del);
  101344. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101345. void*look,
  101346. int *post,int *ilogmask);
  101347. static int mapping0_forward(vorbis_block *vb){
  101348. vorbis_dsp_state *vd=vb->vd;
  101349. vorbis_info *vi=vd->vi;
  101350. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101351. private_state *b=(private_state*)vb->vd->backend_state;
  101352. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101353. int n=vb->pcmend;
  101354. int i,j,k;
  101355. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101356. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101357. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101358. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101359. float global_ampmax=vbi->ampmax;
  101360. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101361. int blocktype=vbi->blocktype;
  101362. int modenumber=vb->W;
  101363. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101364. vorbis_look_psy *psy_look=
  101365. b->psy+blocktype+(vb->W?2:0);
  101366. vb->mode=modenumber;
  101367. for(i=0;i<vi->channels;i++){
  101368. float scale=4.f/n;
  101369. float scale_dB;
  101370. float *pcm =vb->pcm[i];
  101371. float *logfft =pcm;
  101372. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101373. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101374. todB estimation used on IEEE 754
  101375. compliant machines had a bug that
  101376. returned dB values about a third
  101377. of a decibel too high. The bug
  101378. was harmless because tunings
  101379. implicitly took that into
  101380. account. However, fixing the bug
  101381. in the estimator requires
  101382. changing all the tunings as well.
  101383. For now, it's easier to sync
  101384. things back up here, and
  101385. recalibrate the tunings in the
  101386. next major model upgrade. */
  101387. #if 0
  101388. if(vi->channels==2)
  101389. if(i==0)
  101390. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101391. else
  101392. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101393. #endif
  101394. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101395. #if 0
  101396. if(vi->channels==2)
  101397. if(i==0)
  101398. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101399. else
  101400. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101401. #endif
  101402. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101403. drft_forward(&b->fft_look[vb->W],pcm);
  101404. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101405. original todB estimation used on
  101406. IEEE 754 compliant machines had a
  101407. bug that returned dB values about
  101408. a third of a decibel too high.
  101409. The bug was harmless because
  101410. tunings implicitly took that into
  101411. account. However, fixing the bug
  101412. in the estimator requires
  101413. changing all the tunings as well.
  101414. For now, it's easier to sync
  101415. things back up here, and
  101416. recalibrate the tunings in the
  101417. next major model upgrade. */
  101418. local_ampmax[i]=logfft[0];
  101419. for(j=1;j<n-1;j+=2){
  101420. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101421. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101422. .345 is a hack; the original todB
  101423. estimation used on IEEE 754
  101424. compliant machines had a bug that
  101425. returned dB values about a third
  101426. of a decibel too high. The bug
  101427. was harmless because tunings
  101428. implicitly took that into
  101429. account. However, fixing the bug
  101430. in the estimator requires
  101431. changing all the tunings as well.
  101432. For now, it's easier to sync
  101433. things back up here, and
  101434. recalibrate the tunings in the
  101435. next major model upgrade. */
  101436. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101437. }
  101438. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101439. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101440. #if 0
  101441. if(vi->channels==2){
  101442. if(i==0){
  101443. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101444. }else{
  101445. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101446. }
  101447. }
  101448. #endif
  101449. }
  101450. {
  101451. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101452. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101453. for(i=0;i<vi->channels;i++){
  101454. int submap=info->chmuxlist[i];
  101455. float *mdct =gmdct[i];
  101456. float *logfft =vb->pcm[i];
  101457. float *logmdct =logfft+n/2;
  101458. float *logmask =logfft;
  101459. vb->mode=modenumber;
  101460. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101461. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101462. for(j=0;j<n/2;j++)
  101463. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101464. todB estimation used on IEEE 754
  101465. compliant machines had a bug that
  101466. returned dB values about a third
  101467. of a decibel too high. The bug
  101468. was harmless because tunings
  101469. implicitly took that into
  101470. account. However, fixing the bug
  101471. in the estimator requires
  101472. changing all the tunings as well.
  101473. For now, it's easier to sync
  101474. things back up here, and
  101475. recalibrate the tunings in the
  101476. next major model upgrade. */
  101477. #if 0
  101478. if(vi->channels==2){
  101479. if(i==0)
  101480. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101481. else
  101482. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101483. }else{
  101484. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101485. }
  101486. #endif
  101487. _vp_noisemask(psy_look,
  101488. logmdct,
  101489. noise); /* noise does not have by-frequency offset
  101490. bias applied yet */
  101491. #if 0
  101492. if(vi->channels==2){
  101493. if(i==0)
  101494. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101495. else
  101496. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101497. }
  101498. #endif
  101499. _vp_tonemask(psy_look,
  101500. logfft,
  101501. tone,
  101502. global_ampmax,
  101503. local_ampmax[i]);
  101504. #if 0
  101505. if(vi->channels==2){
  101506. if(i==0)
  101507. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101508. else
  101509. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101510. }
  101511. #endif
  101512. #if 0
  101513. {
  101514. float aotuv[psy_look->n];
  101515. #endif
  101516. _vp_offset_and_mix(psy_look,
  101517. noise,
  101518. tone,
  101519. 1,
  101520. logmask,
  101521. mdct,
  101522. logmdct);
  101523. #if 0
  101524. if(vi->channels==2){
  101525. if(i==0)
  101526. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101527. else
  101528. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101529. }
  101530. }
  101531. #endif
  101532. #if 0
  101533. if(vi->channels==2){
  101534. if(i==0)
  101535. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101536. else
  101537. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101538. }
  101539. #endif
  101540. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101541. floor_posts[i][PACKETBLOBS/2]=
  101542. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101543. logmdct,
  101544. logmask);
  101545. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101546. _vp_offset_and_mix(psy_look,
  101547. noise,
  101548. tone,
  101549. 2,
  101550. logmask,
  101551. mdct,
  101552. logmdct);
  101553. #if 0
  101554. if(vi->channels==2){
  101555. if(i==0)
  101556. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101557. else
  101558. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101559. }
  101560. #endif
  101561. floor_posts[i][PACKETBLOBS-1]=
  101562. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101563. logmdct,
  101564. logmask);
  101565. _vp_offset_and_mix(psy_look,
  101566. noise,
  101567. tone,
  101568. 0,
  101569. logmask,
  101570. mdct,
  101571. logmdct);
  101572. #if 0
  101573. if(vi->channels==2)
  101574. if(i==0)
  101575. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101576. else
  101577. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101578. #endif
  101579. floor_posts[i][0]=
  101580. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101581. logmdct,
  101582. logmask);
  101583. for(k=1;k<PACKETBLOBS/2;k++)
  101584. floor_posts[i][k]=
  101585. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101586. floor_posts[i][0],
  101587. floor_posts[i][PACKETBLOBS/2],
  101588. k*65536/(PACKETBLOBS/2));
  101589. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101590. floor_posts[i][k]=
  101591. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101592. floor_posts[i][PACKETBLOBS/2],
  101593. floor_posts[i][PACKETBLOBS-1],
  101594. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101595. }
  101596. }
  101597. }
  101598. vbi->ampmax=global_ampmax;
  101599. {
  101600. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101601. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101602. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101603. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101604. float **mag_memo;
  101605. int **mag_sort;
  101606. if(info->coupling_steps){
  101607. mag_memo=_vp_quantize_couple_memo(vb,
  101608. &ci->psy_g_param,
  101609. psy_look,
  101610. info,
  101611. gmdct);
  101612. mag_sort=_vp_quantize_couple_sort(vb,
  101613. psy_look,
  101614. info,
  101615. mag_memo);
  101616. hf_reduction(&ci->psy_g_param,
  101617. psy_look,
  101618. info,
  101619. mag_memo);
  101620. }
  101621. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101622. if(psy_look->vi->normal_channel_p){
  101623. for(i=0;i<vi->channels;i++){
  101624. float *mdct =gmdct[i];
  101625. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101626. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101627. }
  101628. }
  101629. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101630. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101631. k++){
  101632. oggpack_buffer *opb=vbi->packetblob[k];
  101633. oggpack_write(opb,0,1);
  101634. oggpack_write(opb,modenumber,b->modebits);
  101635. if(vb->W){
  101636. oggpack_write(opb,vb->lW,1);
  101637. oggpack_write(opb,vb->nW,1);
  101638. }
  101639. for(i=0;i<vi->channels;i++){
  101640. int submap=info->chmuxlist[i];
  101641. float *mdct =gmdct[i];
  101642. float *res =vb->pcm[i];
  101643. int *ilogmask=ilogmaskch[i]=
  101644. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101645. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101646. floor_posts[i][k],
  101647. ilogmask);
  101648. #if 0
  101649. {
  101650. char buf[80];
  101651. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101652. float work[n/2];
  101653. for(j=0;j<n/2;j++)
  101654. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101655. _analysis_output(buf,seq,work,n/2,1,1,0);
  101656. }
  101657. #endif
  101658. _vp_remove_floor(psy_look,
  101659. mdct,
  101660. ilogmask,
  101661. res,
  101662. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101663. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101664. #if 0
  101665. {
  101666. char buf[80];
  101667. float work[n/2];
  101668. for(j=0;j<n/2;j++)
  101669. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101670. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101671. _analysis_output(buf,seq,work,n/2,1,1,0);
  101672. }
  101673. #endif
  101674. }
  101675. if(info->coupling_steps){
  101676. _vp_couple(k,
  101677. &ci->psy_g_param,
  101678. psy_look,
  101679. info,
  101680. vb->pcm,
  101681. mag_memo,
  101682. mag_sort,
  101683. ilogmaskch,
  101684. nonzero,
  101685. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101686. }
  101687. for(i=0;i<info->submaps;i++){
  101688. int ch_in_bundle=0;
  101689. long **classifications;
  101690. int resnum=info->residuesubmap[i];
  101691. for(j=0;j<vi->channels;j++){
  101692. if(info->chmuxlist[j]==i){
  101693. zerobundle[ch_in_bundle]=0;
  101694. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101695. res_bundle[ch_in_bundle]=vb->pcm[j];
  101696. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101697. }
  101698. }
  101699. classifications=_residue_P[ci->residue_type[resnum]]->
  101700. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101701. _residue_P[ci->residue_type[resnum]]->
  101702. forward(opb,vb,b->residue[resnum],
  101703. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101704. }
  101705. }
  101706. }
  101707. #if 0
  101708. seq++;
  101709. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101710. #endif
  101711. return(0);
  101712. }
  101713. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101714. vorbis_dsp_state *vd=vb->vd;
  101715. vorbis_info *vi=vd->vi;
  101716. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101717. private_state *b=(private_state*)vd->backend_state;
  101718. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101719. int i,j;
  101720. long n=vb->pcmend=ci->blocksizes[vb->W];
  101721. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101722. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101723. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101724. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101725. for(i=0;i<vi->channels;i++){
  101726. int submap=info->chmuxlist[i];
  101727. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101728. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101729. if(floormemo[i])
  101730. nonzero[i]=1;
  101731. else
  101732. nonzero[i]=0;
  101733. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101734. }
  101735. for(i=0;i<info->coupling_steps;i++){
  101736. if(nonzero[info->coupling_mag[i]] ||
  101737. nonzero[info->coupling_ang[i]]){
  101738. nonzero[info->coupling_mag[i]]=1;
  101739. nonzero[info->coupling_ang[i]]=1;
  101740. }
  101741. }
  101742. for(i=0;i<info->submaps;i++){
  101743. int ch_in_bundle=0;
  101744. for(j=0;j<vi->channels;j++){
  101745. if(info->chmuxlist[j]==i){
  101746. if(nonzero[j])
  101747. zerobundle[ch_in_bundle]=1;
  101748. else
  101749. zerobundle[ch_in_bundle]=0;
  101750. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101751. }
  101752. }
  101753. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101754. inverse(vb,b->residue[info->residuesubmap[i]],
  101755. pcmbundle,zerobundle,ch_in_bundle);
  101756. }
  101757. for(i=info->coupling_steps-1;i>=0;i--){
  101758. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101759. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101760. for(j=0;j<n/2;j++){
  101761. float mag=pcmM[j];
  101762. float ang=pcmA[j];
  101763. if(mag>0)
  101764. if(ang>0){
  101765. pcmM[j]=mag;
  101766. pcmA[j]=mag-ang;
  101767. }else{
  101768. pcmA[j]=mag;
  101769. pcmM[j]=mag+ang;
  101770. }
  101771. else
  101772. if(ang>0){
  101773. pcmM[j]=mag;
  101774. pcmA[j]=mag+ang;
  101775. }else{
  101776. pcmA[j]=mag;
  101777. pcmM[j]=mag-ang;
  101778. }
  101779. }
  101780. }
  101781. for(i=0;i<vi->channels;i++){
  101782. float *pcm=vb->pcm[i];
  101783. int submap=info->chmuxlist[i];
  101784. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101785. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101786. floormemo[i],pcm);
  101787. }
  101788. for(i=0;i<vi->channels;i++){
  101789. float *pcm=vb->pcm[i];
  101790. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101791. }
  101792. return(0);
  101793. }
  101794. vorbis_func_mapping mapping0_exportbundle={
  101795. &mapping0_pack,
  101796. &mapping0_unpack,
  101797. &mapping0_free_info,
  101798. &mapping0_forward,
  101799. &mapping0_inverse
  101800. };
  101801. #endif
  101802. /*** End of inlined file: mapping0.c ***/
  101803. /*** Start of inlined file: mdct.c ***/
  101804. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101805. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101806. // tasks..
  101807. #if JUCE_MSVC
  101808. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101809. #endif
  101810. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101811. #if JUCE_USE_OGGVORBIS
  101812. #include <stdio.h>
  101813. #include <stdlib.h>
  101814. #include <string.h>
  101815. #include <math.h>
  101816. void mdct_init(mdct_lookup *lookup,int n){
  101817. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101818. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101819. int i;
  101820. int n2=n>>1;
  101821. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101822. lookup->n=n;
  101823. lookup->trig=T;
  101824. lookup->bitrev=bitrev;
  101825. for(i=0;i<n/4;i++){
  101826. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101827. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101828. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101829. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101830. }
  101831. for(i=0;i<n/8;i++){
  101832. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101833. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101834. }
  101835. {
  101836. int mask=(1<<(log2n-1))-1,i,j;
  101837. int msb=1<<(log2n-2);
  101838. for(i=0;i<n/8;i++){
  101839. int acc=0;
  101840. for(j=0;msb>>j;j++)
  101841. if((msb>>j)&i)acc|=1<<j;
  101842. bitrev[i*2]=((~acc)&mask)-1;
  101843. bitrev[i*2+1]=acc;
  101844. }
  101845. }
  101846. lookup->scale=FLOAT_CONV(4.f/n);
  101847. }
  101848. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101849. REG_TYPE r0 = x[6] + x[2];
  101850. REG_TYPE r1 = x[6] - x[2];
  101851. REG_TYPE r2 = x[4] + x[0];
  101852. REG_TYPE r3 = x[4] - x[0];
  101853. x[6] = r0 + r2;
  101854. x[4] = r0 - r2;
  101855. r0 = x[5] - x[1];
  101856. r2 = x[7] - x[3];
  101857. x[0] = r1 + r0;
  101858. x[2] = r1 - r0;
  101859. r0 = x[5] + x[1];
  101860. r1 = x[7] + x[3];
  101861. x[3] = r2 + r3;
  101862. x[1] = r2 - r3;
  101863. x[7] = r1 + r0;
  101864. x[5] = r1 - r0;
  101865. }
  101866. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101867. REG_TYPE r0 = x[1] - x[9];
  101868. REG_TYPE r1 = x[0] - x[8];
  101869. x[8] += x[0];
  101870. x[9] += x[1];
  101871. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101872. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101873. r0 = x[3] - x[11];
  101874. r1 = x[10] - x[2];
  101875. x[10] += x[2];
  101876. x[11] += x[3];
  101877. x[2] = r0;
  101878. x[3] = r1;
  101879. r0 = x[12] - x[4];
  101880. r1 = x[13] - x[5];
  101881. x[12] += x[4];
  101882. x[13] += x[5];
  101883. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101884. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101885. r0 = x[14] - x[6];
  101886. r1 = x[15] - x[7];
  101887. x[14] += x[6];
  101888. x[15] += x[7];
  101889. x[6] = r0;
  101890. x[7] = r1;
  101891. mdct_butterfly_8(x);
  101892. mdct_butterfly_8(x+8);
  101893. }
  101894. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101895. REG_TYPE r0 = x[30] - x[14];
  101896. REG_TYPE r1 = x[31] - x[15];
  101897. x[30] += x[14];
  101898. x[31] += x[15];
  101899. x[14] = r0;
  101900. x[15] = r1;
  101901. r0 = x[28] - x[12];
  101902. r1 = x[29] - x[13];
  101903. x[28] += x[12];
  101904. x[29] += x[13];
  101905. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101906. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101907. r0 = x[26] - x[10];
  101908. r1 = x[27] - x[11];
  101909. x[26] += x[10];
  101910. x[27] += x[11];
  101911. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101912. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101913. r0 = x[24] - x[8];
  101914. r1 = x[25] - x[9];
  101915. x[24] += x[8];
  101916. x[25] += x[9];
  101917. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101918. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101919. r0 = x[22] - x[6];
  101920. r1 = x[7] - x[23];
  101921. x[22] += x[6];
  101922. x[23] += x[7];
  101923. x[6] = r1;
  101924. x[7] = r0;
  101925. r0 = x[4] - x[20];
  101926. r1 = x[5] - x[21];
  101927. x[20] += x[4];
  101928. x[21] += x[5];
  101929. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  101930. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  101931. r0 = x[2] - x[18];
  101932. r1 = x[3] - x[19];
  101933. x[18] += x[2];
  101934. x[19] += x[3];
  101935. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  101936. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  101937. r0 = x[0] - x[16];
  101938. r1 = x[1] - x[17];
  101939. x[16] += x[0];
  101940. x[17] += x[1];
  101941. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101942. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  101943. mdct_butterfly_16(x);
  101944. mdct_butterfly_16(x+16);
  101945. }
  101946. STIN void mdct_butterfly_first(DATA_TYPE *T,
  101947. DATA_TYPE *x,
  101948. int points){
  101949. DATA_TYPE *x1 = x + points - 8;
  101950. DATA_TYPE *x2 = x + (points>>1) - 8;
  101951. REG_TYPE r0;
  101952. REG_TYPE r1;
  101953. do{
  101954. r0 = x1[6] - x2[6];
  101955. r1 = x1[7] - x2[7];
  101956. x1[6] += x2[6];
  101957. x1[7] += x2[7];
  101958. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101959. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101960. r0 = x1[4] - x2[4];
  101961. r1 = x1[5] - x2[5];
  101962. x1[4] += x2[4];
  101963. x1[5] += x2[5];
  101964. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  101965. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  101966. r0 = x1[2] - x2[2];
  101967. r1 = x1[3] - x2[3];
  101968. x1[2] += x2[2];
  101969. x1[3] += x2[3];
  101970. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  101971. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  101972. r0 = x1[0] - x2[0];
  101973. r1 = x1[1] - x2[1];
  101974. x1[0] += x2[0];
  101975. x1[1] += x2[1];
  101976. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  101977. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  101978. x1-=8;
  101979. x2-=8;
  101980. T+=16;
  101981. }while(x2>=x);
  101982. }
  101983. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  101984. DATA_TYPE *x,
  101985. int points,
  101986. int trigint){
  101987. DATA_TYPE *x1 = x + points - 8;
  101988. DATA_TYPE *x2 = x + (points>>1) - 8;
  101989. REG_TYPE r0;
  101990. REG_TYPE r1;
  101991. do{
  101992. r0 = x1[6] - x2[6];
  101993. r1 = x1[7] - x2[7];
  101994. x1[6] += x2[6];
  101995. x1[7] += x2[7];
  101996. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101997. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101998. T+=trigint;
  101999. r0 = x1[4] - x2[4];
  102000. r1 = x1[5] - x2[5];
  102001. x1[4] += x2[4];
  102002. x1[5] += x2[5];
  102003. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102004. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102005. T+=trigint;
  102006. r0 = x1[2] - x2[2];
  102007. r1 = x1[3] - x2[3];
  102008. x1[2] += x2[2];
  102009. x1[3] += x2[3];
  102010. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102011. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102012. T+=trigint;
  102013. r0 = x1[0] - x2[0];
  102014. r1 = x1[1] - x2[1];
  102015. x1[0] += x2[0];
  102016. x1[1] += x2[1];
  102017. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102018. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102019. T+=trigint;
  102020. x1-=8;
  102021. x2-=8;
  102022. }while(x2>=x);
  102023. }
  102024. STIN void mdct_butterflies(mdct_lookup *init,
  102025. DATA_TYPE *x,
  102026. int points){
  102027. DATA_TYPE *T=init->trig;
  102028. int stages=init->log2n-5;
  102029. int i,j;
  102030. if(--stages>0){
  102031. mdct_butterfly_first(T,x,points);
  102032. }
  102033. for(i=1;--stages>0;i++){
  102034. for(j=0;j<(1<<i);j++)
  102035. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102036. }
  102037. for(j=0;j<points;j+=32)
  102038. mdct_butterfly_32(x+j);
  102039. }
  102040. void mdct_clear(mdct_lookup *l){
  102041. if(l){
  102042. if(l->trig)_ogg_free(l->trig);
  102043. if(l->bitrev)_ogg_free(l->bitrev);
  102044. memset(l,0,sizeof(*l));
  102045. }
  102046. }
  102047. STIN void mdct_bitreverse(mdct_lookup *init,
  102048. DATA_TYPE *x){
  102049. int n = init->n;
  102050. int *bit = init->bitrev;
  102051. DATA_TYPE *w0 = x;
  102052. DATA_TYPE *w1 = x = w0+(n>>1);
  102053. DATA_TYPE *T = init->trig+n;
  102054. do{
  102055. DATA_TYPE *x0 = x+bit[0];
  102056. DATA_TYPE *x1 = x+bit[1];
  102057. REG_TYPE r0 = x0[1] - x1[1];
  102058. REG_TYPE r1 = x0[0] + x1[0];
  102059. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102060. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102061. w1 -= 4;
  102062. r0 = HALVE(x0[1] + x1[1]);
  102063. r1 = HALVE(x0[0] - x1[0]);
  102064. w0[0] = r0 + r2;
  102065. w1[2] = r0 - r2;
  102066. w0[1] = r1 + r3;
  102067. w1[3] = r3 - r1;
  102068. x0 = x+bit[2];
  102069. x1 = x+bit[3];
  102070. r0 = x0[1] - x1[1];
  102071. r1 = x0[0] + x1[0];
  102072. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102073. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102074. r0 = HALVE(x0[1] + x1[1]);
  102075. r1 = HALVE(x0[0] - x1[0]);
  102076. w0[2] = r0 + r2;
  102077. w1[0] = r0 - r2;
  102078. w0[3] = r1 + r3;
  102079. w1[1] = r3 - r1;
  102080. T += 4;
  102081. bit += 4;
  102082. w0 += 4;
  102083. }while(w0<w1);
  102084. }
  102085. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102086. int n=init->n;
  102087. int n2=n>>1;
  102088. int n4=n>>2;
  102089. DATA_TYPE *iX = in+n2-7;
  102090. DATA_TYPE *oX = out+n2+n4;
  102091. DATA_TYPE *T = init->trig+n4;
  102092. do{
  102093. oX -= 4;
  102094. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102095. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102096. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102097. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102098. iX -= 8;
  102099. T += 4;
  102100. }while(iX>=in);
  102101. iX = in+n2-8;
  102102. oX = out+n2+n4;
  102103. T = init->trig+n4;
  102104. do{
  102105. T -= 4;
  102106. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102107. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102108. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102109. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102110. iX -= 8;
  102111. oX += 4;
  102112. }while(iX>=in);
  102113. mdct_butterflies(init,out+n2,n2);
  102114. mdct_bitreverse(init,out);
  102115. {
  102116. DATA_TYPE *oX1=out+n2+n4;
  102117. DATA_TYPE *oX2=out+n2+n4;
  102118. DATA_TYPE *iX =out;
  102119. T =init->trig+n2;
  102120. do{
  102121. oX1-=4;
  102122. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102123. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102124. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102125. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102126. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102127. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102128. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102129. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102130. oX2+=4;
  102131. iX += 8;
  102132. T += 8;
  102133. }while(iX<oX1);
  102134. iX=out+n2+n4;
  102135. oX1=out+n4;
  102136. oX2=oX1;
  102137. do{
  102138. oX1-=4;
  102139. iX-=4;
  102140. oX2[0] = -(oX1[3] = iX[3]);
  102141. oX2[1] = -(oX1[2] = iX[2]);
  102142. oX2[2] = -(oX1[1] = iX[1]);
  102143. oX2[3] = -(oX1[0] = iX[0]);
  102144. oX2+=4;
  102145. }while(oX2<iX);
  102146. iX=out+n2+n4;
  102147. oX1=out+n2+n4;
  102148. oX2=out+n2;
  102149. do{
  102150. oX1-=4;
  102151. oX1[0]= iX[3];
  102152. oX1[1]= iX[2];
  102153. oX1[2]= iX[1];
  102154. oX1[3]= iX[0];
  102155. iX+=4;
  102156. }while(oX1>oX2);
  102157. }
  102158. }
  102159. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102160. int n=init->n;
  102161. int n2=n>>1;
  102162. int n4=n>>2;
  102163. int n8=n>>3;
  102164. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102165. DATA_TYPE *w2=w+n2;
  102166. REG_TYPE r0;
  102167. REG_TYPE r1;
  102168. DATA_TYPE *x0=in+n2+n4;
  102169. DATA_TYPE *x1=x0+1;
  102170. DATA_TYPE *T=init->trig+n2;
  102171. int i=0;
  102172. for(i=0;i<n8;i+=2){
  102173. x0 -=4;
  102174. T-=2;
  102175. r0= x0[2] + x1[0];
  102176. r1= x0[0] + x1[2];
  102177. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102178. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102179. x1 +=4;
  102180. }
  102181. x1=in+1;
  102182. for(;i<n2-n8;i+=2){
  102183. T-=2;
  102184. x0 -=4;
  102185. r0= x0[2] - x1[0];
  102186. r1= x0[0] - x1[2];
  102187. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102188. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102189. x1 +=4;
  102190. }
  102191. x0=in+n;
  102192. for(;i<n2;i+=2){
  102193. T-=2;
  102194. x0 -=4;
  102195. r0= -x0[2] - x1[0];
  102196. r1= -x0[0] - x1[2];
  102197. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102198. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102199. x1 +=4;
  102200. }
  102201. mdct_butterflies(init,w+n2,n2);
  102202. mdct_bitreverse(init,w);
  102203. T=init->trig+n2;
  102204. x0=out+n2;
  102205. for(i=0;i<n4;i++){
  102206. x0--;
  102207. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102208. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102209. w+=2;
  102210. T+=2;
  102211. }
  102212. }
  102213. #endif
  102214. /*** End of inlined file: mdct.c ***/
  102215. /*** Start of inlined file: psy.c ***/
  102216. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102217. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102218. // tasks..
  102219. #if JUCE_MSVC
  102220. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102221. #endif
  102222. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102223. #if JUCE_USE_OGGVORBIS
  102224. #include <stdlib.h>
  102225. #include <math.h>
  102226. #include <string.h>
  102227. /*** Start of inlined file: masking.h ***/
  102228. #ifndef _V_MASKING_H_
  102229. #define _V_MASKING_H_
  102230. #define MAX_ATH 88
  102231. static float ATH[]={
  102232. -51, -52, -53, -54, -55, -56, -57, -58,
  102233. -59, -60, -61, -62, -63, -64, -65, -66,
  102234. -67, -68, -69, -70, -71, -72, -73, -74,
  102235. -75, -76, -77, -78, -80, -81, -82, -83,
  102236. -84, -85, -86, -87, -88, -88, -89, -89,
  102237. -90, -91, -91, -92, -93, -94, -95, -96,
  102238. -96, -97, -98, -98, -99, -99,-100,-100,
  102239. -101,-102,-103,-104,-106,-107,-107,-107,
  102240. -107,-105,-103,-102,-101, -99, -98, -96,
  102241. -95, -95, -96, -97, -96, -95, -93, -90,
  102242. -80, -70, -50, -40, -30, -30, -30, -30
  102243. };
  102244. #define EHMER_OFFSET 16
  102245. #define EHMER_MAX 56
  102246. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102247. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102248. -60, -60, -60, -60, -62, -62, -65, -73,
  102249. -69, -68, -68, -67, -70, -70, -72, -74,
  102250. -75, -79, -79, -80, -83, -88, -93, -100,
  102251. -110, -999, -999, -999, -999, -999, -999, -999,
  102252. -999, -999, -999, -999, -999, -999, -999, -999,
  102253. -999, -999, -999, -999, -999, -999, -999, -999},
  102254. { -48, -48, -48, -48, -48, -48, -48, -48,
  102255. -48, -48, -48, -48, -48, -53, -61, -66,
  102256. -66, -68, -67, -70, -76, -76, -72, -73,
  102257. -75, -76, -78, -79, -83, -88, -93, -100,
  102258. -110, -999, -999, -999, -999, -999, -999, -999,
  102259. -999, -999, -999, -999, -999, -999, -999, -999,
  102260. -999, -999, -999, -999, -999, -999, -999, -999},
  102261. { -37, -37, -37, -37, -37, -37, -37, -37,
  102262. -38, -40, -42, -46, -48, -53, -55, -62,
  102263. -65, -58, -56, -56, -61, -60, -65, -67,
  102264. -69, -71, -77, -77, -78, -80, -82, -84,
  102265. -88, -93, -98, -106, -112, -999, -999, -999,
  102266. -999, -999, -999, -999, -999, -999, -999, -999,
  102267. -999, -999, -999, -999, -999, -999, -999, -999},
  102268. { -25, -25, -25, -25, -25, -25, -25, -25,
  102269. -25, -26, -27, -29, -32, -38, -48, -52,
  102270. -52, -50, -48, -48, -51, -52, -54, -60,
  102271. -67, -67, -66, -68, -69, -73, -73, -76,
  102272. -80, -81, -81, -85, -85, -86, -88, -93,
  102273. -100, -110, -999, -999, -999, -999, -999, -999,
  102274. -999, -999, -999, -999, -999, -999, -999, -999},
  102275. { -16, -16, -16, -16, -16, -16, -16, -16,
  102276. -17, -19, -20, -22, -26, -28, -31, -40,
  102277. -47, -39, -39, -40, -42, -43, -47, -51,
  102278. -57, -52, -55, -55, -60, -58, -62, -63,
  102279. -70, -67, -69, -72, -73, -77, -80, -82,
  102280. -83, -87, -90, -94, -98, -104, -115, -999,
  102281. -999, -999, -999, -999, -999, -999, -999, -999},
  102282. { -8, -8, -8, -8, -8, -8, -8, -8,
  102283. -8, -8, -10, -11, -15, -19, -25, -30,
  102284. -34, -31, -30, -31, -29, -32, -35, -42,
  102285. -48, -42, -44, -46, -50, -50, -51, -52,
  102286. -59, -54, -55, -55, -58, -62, -63, -66,
  102287. -72, -73, -76, -75, -78, -80, -80, -81,
  102288. -84, -88, -90, -94, -98, -101, -106, -110}},
  102289. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102290. -66, -66, -66, -66, -66, -67, -67, -67,
  102291. -76, -72, -71, -74, -76, -76, -75, -78,
  102292. -79, -79, -81, -83, -86, -89, -93, -97,
  102293. -100, -105, -110, -999, -999, -999, -999, -999,
  102294. -999, -999, -999, -999, -999, -999, -999, -999,
  102295. -999, -999, -999, -999, -999, -999, -999, -999},
  102296. { -47, -47, -47, -47, -47, -47, -47, -47,
  102297. -47, -47, -47, -48, -51, -55, -59, -66,
  102298. -66, -66, -67, -66, -68, -69, -70, -74,
  102299. -79, -77, -77, -78, -80, -81, -82, -84,
  102300. -86, -88, -91, -95, -100, -108, -116, -999,
  102301. -999, -999, -999, -999, -999, -999, -999, -999,
  102302. -999, -999, -999, -999, -999, -999, -999, -999},
  102303. { -36, -36, -36, -36, -36, -36, -36, -36,
  102304. -36, -37, -37, -41, -44, -48, -51, -58,
  102305. -62, -60, -57, -59, -59, -60, -63, -65,
  102306. -72, -71, -70, -72, -74, -77, -76, -78,
  102307. -81, -81, -80, -83, -86, -91, -96, -100,
  102308. -105, -110, -999, -999, -999, -999, -999, -999,
  102309. -999, -999, -999, -999, -999, -999, -999, -999},
  102310. { -28, -28, -28, -28, -28, -28, -28, -28,
  102311. -28, -30, -32, -32, -33, -35, -41, -49,
  102312. -50, -49, -47, -48, -48, -52, -51, -57,
  102313. -65, -61, -59, -61, -64, -69, -70, -74,
  102314. -77, -77, -78, -81, -84, -85, -87, -90,
  102315. -92, -96, -100, -107, -112, -999, -999, -999,
  102316. -999, -999, -999, -999, -999, -999, -999, -999},
  102317. { -19, -19, -19, -19, -19, -19, -19, -19,
  102318. -20, -21, -23, -27, -30, -35, -36, -41,
  102319. -46, -44, -42, -40, -41, -41, -43, -48,
  102320. -55, -53, -52, -53, -56, -59, -58, -60,
  102321. -67, -66, -69, -71, -72, -75, -79, -81,
  102322. -84, -87, -90, -93, -97, -101, -107, -114,
  102323. -999, -999, -999, -999, -999, -999, -999, -999},
  102324. { -9, -9, -9, -9, -9, -9, -9, -9,
  102325. -11, -12, -12, -15, -16, -20, -23, -30,
  102326. -37, -34, -33, -34, -31, -32, -32, -38,
  102327. -47, -44, -41, -40, -47, -49, -46, -46,
  102328. -58, -50, -50, -54, -58, -62, -64, -67,
  102329. -67, -70, -72, -76, -79, -83, -87, -91,
  102330. -96, -100, -104, -110, -999, -999, -999, -999}},
  102331. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102332. -62, -62, -63, -64, -66, -67, -66, -68,
  102333. -75, -72, -76, -75, -76, -78, -79, -82,
  102334. -84, -85, -90, -94, -101, -110, -999, -999,
  102335. -999, -999, -999, -999, -999, -999, -999, -999,
  102336. -999, -999, -999, -999, -999, -999, -999, -999,
  102337. -999, -999, -999, -999, -999, -999, -999, -999},
  102338. { -59, -59, -59, -59, -59, -59, -59, -59,
  102339. -59, -59, -59, -60, -60, -61, -63, -66,
  102340. -71, -68, -70, -70, -71, -72, -72, -75,
  102341. -81, -78, -79, -82, -83, -86, -90, -97,
  102342. -103, -113, -999, -999, -999, -999, -999, -999,
  102343. -999, -999, -999, -999, -999, -999, -999, -999,
  102344. -999, -999, -999, -999, -999, -999, -999, -999},
  102345. { -53, -53, -53, -53, -53, -53, -53, -53,
  102346. -53, -54, -55, -57, -56, -57, -55, -61,
  102347. -65, -60, -60, -62, -63, -63, -66, -68,
  102348. -74, -73, -75, -75, -78, -80, -80, -82,
  102349. -85, -90, -96, -101, -108, -999, -999, -999,
  102350. -999, -999, -999, -999, -999, -999, -999, -999,
  102351. -999, -999, -999, -999, -999, -999, -999, -999},
  102352. { -46, -46, -46, -46, -46, -46, -46, -46,
  102353. -46, -46, -47, -47, -47, -47, -48, -51,
  102354. -57, -51, -49, -50, -51, -53, -54, -59,
  102355. -66, -60, -62, -67, -67, -70, -72, -75,
  102356. -76, -78, -81, -85, -88, -94, -97, -104,
  102357. -112, -999, -999, -999, -999, -999, -999, -999,
  102358. -999, -999, -999, -999, -999, -999, -999, -999},
  102359. { -36, -36, -36, -36, -36, -36, -36, -36,
  102360. -39, -41, -42, -42, -39, -38, -41, -43,
  102361. -52, -44, -40, -39, -37, -37, -40, -47,
  102362. -54, -50, -48, -50, -55, -61, -59, -62,
  102363. -66, -66, -66, -69, -69, -73, -74, -74,
  102364. -75, -77, -79, -82, -87, -91, -95, -100,
  102365. -108, -115, -999, -999, -999, -999, -999, -999},
  102366. { -28, -26, -24, -22, -20, -20, -23, -29,
  102367. -30, -31, -28, -27, -28, -28, -28, -35,
  102368. -40, -33, -32, -29, -30, -30, -30, -37,
  102369. -45, -41, -37, -38, -45, -47, -47, -48,
  102370. -53, -49, -48, -50, -49, -49, -51, -52,
  102371. -58, -56, -57, -56, -60, -61, -62, -70,
  102372. -72, -74, -78, -83, -88, -93, -100, -106}},
  102373. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102374. -999, -110, -105, -100, -95, -91, -87, -83,
  102375. -80, -78, -76, -78, -78, -81, -83, -85,
  102376. -86, -85, -86, -87, -90, -97, -107, -999,
  102377. -999, -999, -999, -999, -999, -999, -999, -999,
  102378. -999, -999, -999, -999, -999, -999, -999, -999,
  102379. -999, -999, -999, -999, -999, -999, -999, -999},
  102380. {-999, -999, -999, -110, -105, -100, -95, -90,
  102381. -85, -81, -77, -73, -70, -67, -67, -68,
  102382. -75, -73, -70, -69, -70, -72, -75, -79,
  102383. -84, -83, -84, -86, -88, -89, -89, -93,
  102384. -98, -105, -112, -999, -999, -999, -999, -999,
  102385. -999, -999, -999, -999, -999, -999, -999, -999,
  102386. -999, -999, -999, -999, -999, -999, -999, -999},
  102387. {-105, -100, -95, -90, -85, -80, -76, -71,
  102388. -68, -68, -65, -63, -63, -62, -62, -64,
  102389. -65, -64, -61, -62, -63, -64, -66, -68,
  102390. -73, -73, -74, -75, -76, -81, -83, -85,
  102391. -88, -89, -92, -95, -100, -108, -999, -999,
  102392. -999, -999, -999, -999, -999, -999, -999, -999,
  102393. -999, -999, -999, -999, -999, -999, -999, -999},
  102394. { -80, -75, -71, -68, -65, -63, -62, -61,
  102395. -61, -61, -61, -59, -56, -57, -53, -50,
  102396. -58, -52, -50, -50, -52, -53, -54, -58,
  102397. -67, -63, -67, -68, -72, -75, -78, -80,
  102398. -81, -81, -82, -85, -89, -90, -93, -97,
  102399. -101, -107, -114, -999, -999, -999, -999, -999,
  102400. -999, -999, -999, -999, -999, -999, -999, -999},
  102401. { -65, -61, -59, -57, -56, -55, -55, -56,
  102402. -56, -57, -55, -53, -52, -47, -44, -44,
  102403. -50, -44, -41, -39, -39, -42, -40, -46,
  102404. -51, -49, -50, -53, -54, -63, -60, -61,
  102405. -62, -66, -66, -66, -70, -73, -74, -75,
  102406. -76, -75, -79, -85, -89, -91, -96, -102,
  102407. -110, -999, -999, -999, -999, -999, -999, -999},
  102408. { -52, -50, -49, -49, -48, -48, -48, -49,
  102409. -50, -50, -49, -46, -43, -39, -35, -33,
  102410. -38, -36, -32, -29, -32, -32, -32, -35,
  102411. -44, -39, -38, -38, -46, -50, -45, -46,
  102412. -53, -50, -50, -50, -54, -54, -53, -53,
  102413. -56, -57, -59, -66, -70, -72, -74, -79,
  102414. -83, -85, -90, -97, -114, -999, -999, -999}},
  102415. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102416. -100, -95, -90, -86, -80, -75, -75, -79,
  102417. -80, -79, -80, -81, -82, -88, -95, -103,
  102418. -110, -999, -999, -999, -999, -999, -999, -999,
  102419. -999, -999, -999, -999, -999, -999, -999, -999,
  102420. -999, -999, -999, -999, -999, -999, -999, -999,
  102421. -999, -999, -999, -999, -999, -999, -999, -999},
  102422. {-999, -999, -999, -999, -108, -103, -98, -93,
  102423. -88, -83, -79, -78, -75, -71, -67, -68,
  102424. -73, -73, -72, -73, -75, -77, -80, -82,
  102425. -88, -93, -100, -107, -114, -999, -999, -999,
  102426. -999, -999, -999, -999, -999, -999, -999, -999,
  102427. -999, -999, -999, -999, -999, -999, -999, -999,
  102428. -999, -999, -999, -999, -999, -999, -999, -999},
  102429. {-999, -999, -999, -110, -105, -101, -96, -90,
  102430. -86, -81, -77, -73, -69, -66, -61, -62,
  102431. -66, -64, -62, -65, -66, -70, -72, -76,
  102432. -81, -80, -84, -90, -95, -102, -110, -999,
  102433. -999, -999, -999, -999, -999, -999, -999, -999,
  102434. -999, -999, -999, -999, -999, -999, -999, -999,
  102435. -999, -999, -999, -999, -999, -999, -999, -999},
  102436. {-999, -999, -999, -107, -103, -97, -92, -88,
  102437. -83, -79, -74, -70, -66, -59, -53, -58,
  102438. -62, -55, -54, -54, -54, -58, -61, -62,
  102439. -72, -70, -72, -75, -78, -80, -81, -80,
  102440. -83, -83, -88, -93, -100, -107, -115, -999,
  102441. -999, -999, -999, -999, -999, -999, -999, -999,
  102442. -999, -999, -999, -999, -999, -999, -999, -999},
  102443. {-999, -999, -999, -105, -100, -95, -90, -85,
  102444. -80, -75, -70, -66, -62, -56, -48, -44,
  102445. -48, -46, -46, -43, -46, -48, -48, -51,
  102446. -58, -58, -59, -60, -62, -62, -61, -61,
  102447. -65, -64, -65, -68, -70, -74, -75, -78,
  102448. -81, -86, -95, -110, -999, -999, -999, -999,
  102449. -999, -999, -999, -999, -999, -999, -999, -999},
  102450. {-999, -999, -105, -100, -95, -90, -85, -80,
  102451. -75, -70, -65, -61, -55, -49, -39, -33,
  102452. -40, -35, -32, -38, -40, -33, -35, -37,
  102453. -46, -41, -45, -44, -46, -42, -45, -46,
  102454. -52, -50, -50, -50, -54, -54, -55, -57,
  102455. -62, -64, -66, -68, -70, -76, -81, -90,
  102456. -100, -110, -999, -999, -999, -999, -999, -999}},
  102457. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102458. -105, -98, -90, -85, -82, -83, -80, -78,
  102459. -84, -79, -80, -83, -87, -89, -91, -93,
  102460. -99, -106, -117, -999, -999, -999, -999, -999,
  102461. -999, -999, -999, -999, -999, -999, -999, -999,
  102462. -999, -999, -999, -999, -999, -999, -999, -999,
  102463. -999, -999, -999, -999, -999, -999, -999, -999},
  102464. {-999, -999, -999, -999, -999, -999, -999, -999,
  102465. -105, -98, -90, -85, -80, -75, -70, -68,
  102466. -74, -72, -74, -77, -80, -82, -85, -87,
  102467. -92, -89, -91, -95, -100, -106, -112, -999,
  102468. -999, -999, -999, -999, -999, -999, -999, -999,
  102469. -999, -999, -999, -999, -999, -999, -999, -999,
  102470. -999, -999, -999, -999, -999, -999, -999, -999},
  102471. {-999, -999, -999, -999, -999, -999, -999, -999,
  102472. -105, -98, -90, -83, -75, -71, -63, -64,
  102473. -67, -62, -64, -67, -70, -73, -77, -81,
  102474. -84, -83, -85, -89, -90, -93, -98, -104,
  102475. -109, -114, -999, -999, -999, -999, -999, -999,
  102476. -999, -999, -999, -999, -999, -999, -999, -999,
  102477. -999, -999, -999, -999, -999, -999, -999, -999},
  102478. {-999, -999, -999, -999, -999, -999, -999, -999,
  102479. -103, -96, -88, -81, -75, -68, -58, -54,
  102480. -56, -54, -56, -56, -58, -60, -63, -66,
  102481. -74, -69, -72, -72, -75, -74, -77, -81,
  102482. -81, -82, -84, -87, -93, -96, -99, -104,
  102483. -110, -999, -999, -999, -999, -999, -999, -999,
  102484. -999, -999, -999, -999, -999, -999, -999, -999},
  102485. {-999, -999, -999, -999, -999, -108, -102, -96,
  102486. -91, -85, -80, -74, -68, -60, -51, -46,
  102487. -48, -46, -43, -45, -47, -47, -49, -48,
  102488. -56, -53, -55, -58, -57, -63, -58, -60,
  102489. -66, -64, -67, -70, -70, -74, -77, -84,
  102490. -86, -89, -91, -93, -94, -101, -109, -118,
  102491. -999, -999, -999, -999, -999, -999, -999, -999},
  102492. {-999, -999, -999, -108, -103, -98, -93, -88,
  102493. -83, -78, -73, -68, -60, -53, -44, -35,
  102494. -38, -38, -34, -34, -36, -40, -41, -44,
  102495. -51, -45, -46, -47, -46, -54, -50, -49,
  102496. -50, -50, -50, -51, -54, -57, -58, -60,
  102497. -66, -66, -66, -64, -65, -68, -77, -82,
  102498. -87, -95, -110, -999, -999, -999, -999, -999}},
  102499. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102500. -107, -102, -97, -92, -87, -83, -78, -75,
  102501. -82, -79, -83, -85, -89, -92, -95, -98,
  102502. -101, -105, -109, -113, -999, -999, -999, -999,
  102503. -999, -999, -999, -999, -999, -999, -999, -999,
  102504. -999, -999, -999, -999, -999, -999, -999, -999,
  102505. -999, -999, -999, -999, -999, -999, -999, -999},
  102506. {-999, -999, -999, -999, -999, -999, -999, -106,
  102507. -100, -95, -90, -86, -81, -78, -74, -69,
  102508. -74, -74, -76, -79, -83, -84, -86, -89,
  102509. -92, -97, -93, -100, -103, -107, -110, -999,
  102510. -999, -999, -999, -999, -999, -999, -999, -999,
  102511. -999, -999, -999, -999, -999, -999, -999, -999,
  102512. -999, -999, -999, -999, -999, -999, -999, -999},
  102513. {-999, -999, -999, -999, -999, -999, -106, -100,
  102514. -95, -90, -87, -83, -80, -75, -69, -60,
  102515. -66, -66, -68, -70, -74, -78, -79, -81,
  102516. -81, -83, -84, -87, -93, -96, -99, -103,
  102517. -107, -110, -999, -999, -999, -999, -999, -999,
  102518. -999, -999, -999, -999, -999, -999, -999, -999,
  102519. -999, -999, -999, -999, -999, -999, -999, -999},
  102520. {-999, -999, -999, -999, -999, -108, -103, -98,
  102521. -93, -89, -85, -82, -78, -71, -62, -55,
  102522. -58, -58, -54, -54, -55, -59, -61, -62,
  102523. -70, -66, -66, -67, -70, -72, -75, -78,
  102524. -84, -84, -84, -88, -91, -90, -95, -98,
  102525. -102, -103, -106, -110, -999, -999, -999, -999,
  102526. -999, -999, -999, -999, -999, -999, -999, -999},
  102527. {-999, -999, -999, -999, -108, -103, -98, -94,
  102528. -90, -87, -82, -79, -73, -67, -58, -47,
  102529. -50, -45, -41, -45, -48, -44, -44, -49,
  102530. -54, -51, -48, -47, -49, -50, -51, -57,
  102531. -58, -60, -63, -69, -70, -69, -71, -74,
  102532. -78, -82, -90, -95, -101, -105, -110, -999,
  102533. -999, -999, -999, -999, -999, -999, -999, -999},
  102534. {-999, -999, -999, -105, -101, -97, -93, -90,
  102535. -85, -80, -77, -72, -65, -56, -48, -37,
  102536. -40, -36, -34, -40, -50, -47, -38, -41,
  102537. -47, -38, -35, -39, -38, -43, -40, -45,
  102538. -50, -45, -44, -47, -50, -55, -48, -48,
  102539. -52, -66, -70, -76, -82, -90, -97, -105,
  102540. -110, -999, -999, -999, -999, -999, -999, -999}},
  102541. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102542. -999, -108, -103, -98, -93, -86, -79, -76,
  102543. -83, -81, -85, -87, -89, -93, -98, -102,
  102544. -107, -112, -999, -999, -999, -999, -999, -999,
  102545. -999, -999, -999, -999, -999, -999, -999, -999,
  102546. -999, -999, -999, -999, -999, -999, -999, -999,
  102547. -999, -999, -999, -999, -999, -999, -999, -999},
  102548. {-999, -999, -999, -999, -999, -999, -999, -999,
  102549. -999, -108, -103, -98, -93, -86, -79, -71,
  102550. -77, -74, -77, -79, -81, -84, -85, -90,
  102551. -92, -93, -92, -98, -101, -108, -112, -999,
  102552. -999, -999, -999, -999, -999, -999, -999, -999,
  102553. -999, -999, -999, -999, -999, -999, -999, -999,
  102554. -999, -999, -999, -999, -999, -999, -999, -999},
  102555. {-999, -999, -999, -999, -999, -999, -999, -999,
  102556. -108, -103, -98, -93, -87, -78, -68, -65,
  102557. -66, -62, -65, -67, -70, -73, -75, -78,
  102558. -82, -82, -83, -84, -91, -93, -98, -102,
  102559. -106, -110, -999, -999, -999, -999, -999, -999,
  102560. -999, -999, -999, -999, -999, -999, -999, -999,
  102561. -999, -999, -999, -999, -999, -999, -999, -999},
  102562. {-999, -999, -999, -999, -999, -999, -999, -999,
  102563. -105, -100, -95, -90, -82, -74, -62, -57,
  102564. -58, -56, -51, -52, -52, -54, -54, -58,
  102565. -66, -59, -60, -63, -66, -69, -73, -79,
  102566. -83, -84, -80, -81, -81, -82, -88, -92,
  102567. -98, -105, -113, -999, -999, -999, -999, -999,
  102568. -999, -999, -999, -999, -999, -999, -999, -999},
  102569. {-999, -999, -999, -999, -999, -999, -999, -107,
  102570. -102, -97, -92, -84, -79, -69, -57, -47,
  102571. -52, -47, -44, -45, -50, -52, -42, -42,
  102572. -53, -43, -43, -48, -51, -56, -55, -52,
  102573. -57, -59, -61, -62, -67, -71, -78, -83,
  102574. -86, -94, -98, -103, -110, -999, -999, -999,
  102575. -999, -999, -999, -999, -999, -999, -999, -999},
  102576. {-999, -999, -999, -999, -999, -999, -105, -100,
  102577. -95, -90, -84, -78, -70, -61, -51, -41,
  102578. -40, -38, -40, -46, -52, -51, -41, -40,
  102579. -46, -40, -38, -38, -41, -46, -41, -46,
  102580. -47, -43, -43, -45, -41, -45, -56, -67,
  102581. -68, -83, -87, -90, -95, -102, -107, -113,
  102582. -999, -999, -999, -999, -999, -999, -999, -999}},
  102583. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102584. -999, -109, -105, -101, -96, -91, -84, -77,
  102585. -82, -82, -85, -89, -94, -100, -106, -110,
  102586. -999, -999, -999, -999, -999, -999, -999, -999,
  102587. -999, -999, -999, -999, -999, -999, -999, -999,
  102588. -999, -999, -999, -999, -999, -999, -999, -999,
  102589. -999, -999, -999, -999, -999, -999, -999, -999},
  102590. {-999, -999, -999, -999, -999, -999, -999, -999,
  102591. -999, -106, -103, -98, -92, -85, -80, -71,
  102592. -75, -72, -76, -80, -84, -86, -89, -93,
  102593. -100, -107, -113, -999, -999, -999, -999, -999,
  102594. -999, -999, -999, -999, -999, -999, -999, -999,
  102595. -999, -999, -999, -999, -999, -999, -999, -999,
  102596. -999, -999, -999, -999, -999, -999, -999, -999},
  102597. {-999, -999, -999, -999, -999, -999, -999, -107,
  102598. -104, -101, -97, -92, -88, -84, -80, -64,
  102599. -66, -63, -64, -66, -69, -73, -77, -83,
  102600. -83, -86, -91, -98, -104, -111, -999, -999,
  102601. -999, -999, -999, -999, -999, -999, -999, -999,
  102602. -999, -999, -999, -999, -999, -999, -999, -999,
  102603. -999, -999, -999, -999, -999, -999, -999, -999},
  102604. {-999, -999, -999, -999, -999, -999, -999, -107,
  102605. -104, -101, -97, -92, -90, -84, -74, -57,
  102606. -58, -52, -55, -54, -50, -52, -50, -52,
  102607. -63, -62, -69, -76, -77, -78, -78, -79,
  102608. -82, -88, -94, -100, -106, -111, -999, -999,
  102609. -999, -999, -999, -999, -999, -999, -999, -999,
  102610. -999, -999, -999, -999, -999, -999, -999, -999},
  102611. {-999, -999, -999, -999, -999, -999, -106, -102,
  102612. -98, -95, -90, -85, -83, -78, -70, -50,
  102613. -50, -41, -44, -49, -47, -50, -50, -44,
  102614. -55, -46, -47, -48, -48, -54, -49, -49,
  102615. -58, -62, -71, -81, -87, -92, -97, -102,
  102616. -108, -114, -999, -999, -999, -999, -999, -999,
  102617. -999, -999, -999, -999, -999, -999, -999, -999},
  102618. {-999, -999, -999, -999, -999, -999, -106, -102,
  102619. -98, -95, -90, -85, -83, -78, -70, -45,
  102620. -43, -41, -47, -50, -51, -50, -49, -45,
  102621. -47, -41, -44, -41, -39, -43, -38, -37,
  102622. -40, -41, -44, -50, -58, -65, -73, -79,
  102623. -85, -92, -97, -101, -105, -109, -113, -999,
  102624. -999, -999, -999, -999, -999, -999, -999, -999}},
  102625. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102626. -999, -999, -999, -107, -100, -95, -87, -81,
  102627. -85, -83, -88, -93, -100, -107, -114, -999,
  102628. -999, -999, -999, -999, -999, -999, -999, -999,
  102629. -999, -999, -999, -999, -999, -999, -999, -999,
  102630. -999, -999, -999, -999, -999, -999, -999, -999,
  102631. -999, -999, -999, -999, -999, -999, -999, -999},
  102632. {-999, -999, -999, -999, -999, -999, -999, -999,
  102633. -999, -999, -107, -101, -95, -88, -83, -76,
  102634. -73, -72, -79, -84, -90, -95, -100, -105,
  102635. -110, -115, -999, -999, -999, -999, -999, -999,
  102636. -999, -999, -999, -999, -999, -999, -999, -999,
  102637. -999, -999, -999, -999, -999, -999, -999, -999,
  102638. -999, -999, -999, -999, -999, -999, -999, -999},
  102639. {-999, -999, -999, -999, -999, -999, -999, -999,
  102640. -999, -999, -104, -98, -92, -87, -81, -70,
  102641. -65, -62, -67, -71, -74, -80, -85, -91,
  102642. -95, -99, -103, -108, -111, -114, -999, -999,
  102643. -999, -999, -999, -999, -999, -999, -999, -999,
  102644. -999, -999, -999, -999, -999, -999, -999, -999,
  102645. -999, -999, -999, -999, -999, -999, -999, -999},
  102646. {-999, -999, -999, -999, -999, -999, -999, -999,
  102647. -999, -999, -103, -97, -90, -85, -76, -60,
  102648. -56, -54, -60, -62, -61, -56, -63, -65,
  102649. -73, -74, -77, -75, -78, -81, -86, -87,
  102650. -88, -91, -94, -98, -103, -110, -999, -999,
  102651. -999, -999, -999, -999, -999, -999, -999, -999,
  102652. -999, -999, -999, -999, -999, -999, -999, -999},
  102653. {-999, -999, -999, -999, -999, -999, -999, -105,
  102654. -100, -97, -92, -86, -81, -79, -70, -57,
  102655. -51, -47, -51, -58, -60, -56, -53, -50,
  102656. -58, -52, -50, -50, -53, -55, -64, -69,
  102657. -71, -85, -82, -78, -81, -85, -95, -102,
  102658. -112, -999, -999, -999, -999, -999, -999, -999,
  102659. -999, -999, -999, -999, -999, -999, -999, -999},
  102660. {-999, -999, -999, -999, -999, -999, -999, -105,
  102661. -100, -97, -92, -85, -83, -79, -72, -49,
  102662. -40, -43, -43, -54, -56, -51, -50, -40,
  102663. -43, -38, -36, -35, -37, -38, -37, -44,
  102664. -54, -60, -57, -60, -70, -75, -84, -92,
  102665. -103, -112, -999, -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, -110, -102, -95, -89, -82,
  102669. -83, -84, -90, -92, -99, -107, -113, -999,
  102670. -999, -999, -999, -999, -999, -999, -999, -999,
  102671. -999, -999, -999, -999, -999, -999, -999, -999,
  102672. -999, -999, -999, -999, -999, -999, -999, -999,
  102673. -999, -999, -999, -999, -999, -999, -999, -999},
  102674. {-999, -999, -999, -999, -999, -999, -999, -999,
  102675. -999, -999, -107, -101, -95, -89, -83, -72,
  102676. -74, -78, -85, -88, -88, -90, -92, -98,
  102677. -105, -111, -999, -999, -999, -999, -999, -999,
  102678. -999, -999, -999, -999, -999, -999, -999, -999,
  102679. -999, -999, -999, -999, -999, -999, -999, -999,
  102680. -999, -999, -999, -999, -999, -999, -999, -999},
  102681. {-999, -999, -999, -999, -999, -999, -999, -999,
  102682. -999, -109, -103, -97, -93, -87, -81, -70,
  102683. -70, -67, -75, -73, -76, -79, -81, -83,
  102684. -88, -89, -97, -103, -110, -999, -999, -999,
  102685. -999, -999, -999, -999, -999, -999, -999, -999,
  102686. -999, -999, -999, -999, -999, -999, -999, -999,
  102687. -999, -999, -999, -999, -999, -999, -999, -999},
  102688. {-999, -999, -999, -999, -999, -999, -999, -999,
  102689. -999, -107, -100, -94, -88, -83, -75, -63,
  102690. -59, -59, -63, -66, -60, -62, -67, -67,
  102691. -77, -76, -81, -88, -86, -92, -96, -102,
  102692. -109, -116, -999, -999, -999, -999, -999, -999,
  102693. -999, -999, -999, -999, -999, -999, -999, -999,
  102694. -999, -999, -999, -999, -999, -999, -999, -999},
  102695. {-999, -999, -999, -999, -999, -999, -999, -999,
  102696. -999, -105, -98, -92, -86, -81, -73, -56,
  102697. -52, -47, -55, -60, -58, -52, -51, -45,
  102698. -49, -50, -53, -54, -61, -71, -70, -69,
  102699. -78, -79, -87, -90, -96, -104, -112, -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, -103, -96, -90, -86, -78, -70, -51,
  102704. -42, -47, -48, -55, -54, -54, -53, -42,
  102705. -35, -28, -33, -38, -37, -44, -47, -49,
  102706. -54, -63, -68, -78, -82, -89, -94, -99,
  102707. -104, -109, -114, -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, -110, -100, -90, -79,
  102711. -85, -81, -82, -82, -89, -94, -99, -103,
  102712. -109, -115, -999, -999, -999, -999, -999, -999,
  102713. -999, -999, -999, -999, -999, -999, -999, -999,
  102714. -999, -999, -999, -999, -999, -999, -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, -105, -97, -85, -72,
  102718. -74, -70, -70, -70, -76, -85, -91, -93,
  102719. -97, -103, -109, -115, -999, -999, -999, -999,
  102720. -999, -999, -999, -999, -999, -999, -999, -999,
  102721. -999, -999, -999, -999, -999, -999, -999, -999,
  102722. -999, -999, -999, -999, -999, -999, -999, -999},
  102723. {-999, -999, -999, -999, -999, -999, -999, -999,
  102724. -999, -999, -999, -999, -112, -93, -81, -68,
  102725. -62, -60, -60, -57, -63, -70, -77, -82,
  102726. -90, -93, -98, -104, -109, -113, -999, -999,
  102727. -999, -999, -999, -999, -999, -999, -999, -999,
  102728. -999, -999, -999, -999, -999, -999, -999, -999,
  102729. -999, -999, -999, -999, -999, -999, -999, -999},
  102730. {-999, -999, -999, -999, -999, -999, -999, -999,
  102731. -999, -999, -999, -113, -100, -93, -84, -63,
  102732. -58, -48, -53, -54, -52, -52, -57, -64,
  102733. -66, -76, -83, -81, -85, -85, -90, -95,
  102734. -98, -101, -103, -106, -108, -111, -999, -999,
  102735. -999, -999, -999, -999, -999, -999, -999, -999,
  102736. -999, -999, -999, -999, -999, -999, -999, -999},
  102737. {-999, -999, -999, -999, -999, -999, -999, -999,
  102738. -999, -999, -999, -105, -95, -86, -74, -53,
  102739. -50, -38, -43, -49, -43, -42, -39, -39,
  102740. -46, -52, -57, -56, -72, -69, -74, -81,
  102741. -87, -92, -94, -97, -99, -102, -105, -108,
  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, -108, -99, -90, -76, -66, -45,
  102746. -43, -41, -44, -47, -43, -47, -40, -30,
  102747. -31, -31, -39, -33, -40, -41, -43, -53,
  102748. -59, -70, -73, -77, -79, -82, -84, -87,
  102749. -999, -999, -999, -999, -999, -999, -999, -999,
  102750. -999, -999, -999, -999, -999, -999, -999, -999}},
  102751. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102752. -999, -999, -999, -999, -999, -110, -91, -76,
  102753. -75, -85, -93, -98, -104, -110, -999, -999,
  102754. -999, -999, -999, -999, -999, -999, -999, -999,
  102755. -999, -999, -999, -999, -999, -999, -999, -999,
  102756. -999, -999, -999, -999, -999, -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, -110, -91, -70,
  102760. -70, -75, -86, -89, -94, -98, -101, -106,
  102761. -110, -999, -999, -999, -999, -999, -999, -999,
  102762. -999, -999, -999, -999, -999, -999, -999, -999,
  102763. -999, -999, -999, -999, -999, -999, -999, -999,
  102764. -999, -999, -999, -999, -999, -999, -999, -999},
  102765. {-999, -999, -999, -999, -999, -999, -999, -999,
  102766. -999, -999, -999, -999, -110, -95, -80, -60,
  102767. -65, -64, -74, -83, -88, -91, -95, -99,
  102768. -103, -107, -110, -999, -999, -999, -999, -999,
  102769. -999, -999, -999, -999, -999, -999, -999, -999,
  102770. -999, -999, -999, -999, -999, -999, -999, -999,
  102771. -999, -999, -999, -999, -999, -999, -999, -999},
  102772. {-999, -999, -999, -999, -999, -999, -999, -999,
  102773. -999, -999, -999, -999, -110, -95, -80, -58,
  102774. -55, -49, -66, -68, -71, -78, -78, -80,
  102775. -88, -85, -89, -97, -100, -105, -110, -999,
  102776. -999, -999, -999, -999, -999, -999, -999, -999,
  102777. -999, -999, -999, -999, -999, -999, -999, -999,
  102778. -999, -999, -999, -999, -999, -999, -999, -999},
  102779. {-999, -999, -999, -999, -999, -999, -999, -999,
  102780. -999, -999, -999, -999, -110, -95, -80, -53,
  102781. -52, -41, -59, -59, -49, -58, -56, -63,
  102782. -86, -79, -90, -93, -98, -103, -107, -112,
  102783. -999, -999, -999, -999, -999, -999, -999, -999,
  102784. -999, -999, -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, -110, -97, -91, -73, -45,
  102788. -40, -33, -53, -61, -49, -54, -50, -50,
  102789. -60, -52, -67, -74, -81, -92, -96, -100,
  102790. -105, -110, -999, -999, -999, -999, -999, -999,
  102791. -999, -999, -999, -999, -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, -113, -106, -99, -92, -77,
  102795. -80, -88, -97, -106, -115, -999, -999, -999,
  102796. -999, -999, -999, -999, -999, -999, -999, -999,
  102797. -999, -999, -999, -999, -999, -999, -999, -999,
  102798. -999, -999, -999, -999, -999, -999, -999, -999,
  102799. -999, -999, -999, -999, -999, -999, -999, -999},
  102800. {-999, -999, -999, -999, -999, -999, -999, -999,
  102801. -999, -999, -116, -109, -102, -95, -89, -74,
  102802. -72, -88, -87, -95, -102, -109, -116, -999,
  102803. -999, -999, -999, -999, -999, -999, -999, -999,
  102804. -999, -999, -999, -999, -999, -999, -999, -999,
  102805. -999, -999, -999, -999, -999, -999, -999, -999,
  102806. -999, -999, -999, -999, -999, -999, -999, -999},
  102807. {-999, -999, -999, -999, -999, -999, -999, -999,
  102808. -999, -999, -116, -109, -102, -95, -89, -75,
  102809. -66, -74, -77, -78, -86, -87, -90, -96,
  102810. -105, -115, -999, -999, -999, -999, -999, -999,
  102811. -999, -999, -999, -999, -999, -999, -999, -999,
  102812. -999, -999, -999, -999, -999, -999, -999, -999,
  102813. -999, -999, -999, -999, -999, -999, -999, -999},
  102814. {-999, -999, -999, -999, -999, -999, -999, -999,
  102815. -999, -999, -115, -108, -101, -94, -88, -66,
  102816. -56, -61, -70, -65, -78, -72, -83, -84,
  102817. -93, -98, -105, -110, -999, -999, -999, -999,
  102818. -999, -999, -999, -999, -999, -999, -999, -999,
  102819. -999, -999, -999, -999, -999, -999, -999, -999,
  102820. -999, -999, -999, -999, -999, -999, -999, -999},
  102821. {-999, -999, -999, -999, -999, -999, -999, -999,
  102822. -999, -999, -110, -105, -95, -89, -82, -57,
  102823. -52, -52, -59, -56, -59, -58, -69, -67,
  102824. -88, -82, -82, -89, -94, -100, -108, -999,
  102825. -999, -999, -999, -999, -999, -999, -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, -110, -101, -96, -90, -83, -77, -54,
  102830. -43, -38, -50, -48, -52, -48, -42, -42,
  102831. -51, -52, -53, -59, -65, -71, -78, -85,
  102832. -95, -999, -999, -999, -999, -999, -999, -999,
  102833. -999, -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, -120, -105, -86, -68,
  102837. -78, -79, -90, -100, -110, -999, -999, -999,
  102838. -999, -999, -999, -999, -999, -999, -999, -999,
  102839. -999, -999, -999, -999, -999, -999, -999, -999,
  102840. -999, -999, -999, -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, -120, -105, -86, -66,
  102844. -73, -77, -88, -96, -105, -115, -999, -999,
  102845. -999, -999, -999, -999, -999, -999, -999, -999,
  102846. -999, -999, -999, -999, -999, -999, -999, -999,
  102847. -999, -999, -999, -999, -999, -999, -999, -999,
  102848. -999, -999, -999, -999, -999, -999, -999, -999},
  102849. {-999, -999, -999, -999, -999, -999, -999, -999,
  102850. -999, -999, -999, -120, -105, -92, -80, -61,
  102851. -64, -68, -80, -87, -92, -100, -110, -999,
  102852. -999, -999, -999, -999, -999, -999, -999, -999,
  102853. -999, -999, -999, -999, -999, -999, -999, -999,
  102854. -999, -999, -999, -999, -999, -999, -999, -999,
  102855. -999, -999, -999, -999, -999, -999, -999, -999},
  102856. {-999, -999, -999, -999, -999, -999, -999, -999,
  102857. -999, -999, -999, -120, -104, -91, -79, -52,
  102858. -60, -54, -64, -69, -77, -80, -82, -84,
  102859. -85, -87, -88, -90, -999, -999, -999, -999,
  102860. -999, -999, -999, -999, -999, -999, -999, -999,
  102861. -999, -999, -999, -999, -999, -999, -999, -999,
  102862. -999, -999, -999, -999, -999, -999, -999, -999},
  102863. {-999, -999, -999, -999, -999, -999, -999, -999,
  102864. -999, -999, -999, -118, -100, -87, -77, -49,
  102865. -50, -44, -58, -61, -61, -67, -65, -62,
  102866. -62, -62, -65, -68, -999, -999, -999, -999,
  102867. -999, -999, -999, -999, -999, -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, -115, -98, -84, -62, -49,
  102872. -44, -38, -46, -49, -49, -46, -39, -37,
  102873. -39, -40, -42, -43, -999, -999, -999, -999,
  102874. -999, -999, -999, -999, -999, -999, -999, -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, -110, -88, -74,
  102879. -77, -82, -82, -85, -90, -94, -99, -104,
  102880. -999, -999, -999, -999, -999, -999, -999, -999,
  102881. -999, -999, -999, -999, -999, -999, -999, -999,
  102882. -999, -999, -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, -110, -88, -66,
  102886. -70, -81, -80, -81, -84, -88, -91, -93,
  102887. -999, -999, -999, -999, -999, -999, -999, -999,
  102888. -999, -999, -999, -999, -999, -999, -999, -999,
  102889. -999, -999, -999, -999, -999, -999, -999, -999,
  102890. -999, -999, -999, -999, -999, -999, -999, -999},
  102891. {-999, -999, -999, -999, -999, -999, -999, -999,
  102892. -999, -999, -999, -999, -999, -110, -88, -61,
  102893. -63, -70, -71, -74, -77, -80, -83, -85,
  102894. -999, -999, -999, -999, -999, -999, -999, -999,
  102895. -999, -999, -999, -999, -999, -999, -999, -999,
  102896. -999, -999, -999, -999, -999, -999, -999, -999,
  102897. -999, -999, -999, -999, -999, -999, -999, -999},
  102898. {-999, -999, -999, -999, -999, -999, -999, -999,
  102899. -999, -999, -999, -999, -999, -110, -86, -62,
  102900. -63, -62, -62, -58, -52, -50, -50, -52,
  102901. -54, -999, -999, -999, -999, -999, -999, -999,
  102902. -999, -999, -999, -999, -999, -999, -999, -999,
  102903. -999, -999, -999, -999, -999, -999, -999, -999,
  102904. -999, -999, -999, -999, -999, -999, -999, -999},
  102905. {-999, -999, -999, -999, -999, -999, -999, -999,
  102906. -999, -999, -999, -999, -118, -108, -84, -53,
  102907. -50, -50, -50, -55, -47, -45, -40, -40,
  102908. -40, -999, -999, -999, -999, -999, -999, -999,
  102909. -999, -999, -999, -999, -999, -999, -999, -999,
  102910. -999, -999, -999, -999, -999, -999, -999, -999,
  102911. -999, -999, -999, -999, -999, -999, -999, -999},
  102912. {-999, -999, -999, -999, -999, -999, -999, -999,
  102913. -999, -999, -999, -999, -118, -100, -73, -43,
  102914. -37, -42, -43, -53, -38, -37, -35, -35,
  102915. -38, -999, -999, -999, -999, -999, -999, -999,
  102916. -999, -999, -999, -999, -999, -999, -999, -999,
  102917. -999, -999, -999, -999, -999, -999, -999, -999,
  102918. -999, -999, -999, -999, -999, -999, -999, -999}},
  102919. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102920. -999, -999, -999, -110, -100, -91, -84, -74,
  102921. -80, -80, -80, -80, -80, -999, -999, -999,
  102922. -999, -999, -999, -999, -999, -999, -999, -999,
  102923. -999, -999, -999, -999, -999, -999, -999, -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, -110, -100, -91, -84, -74,
  102928. -68, -68, -68, -68, -68, -999, -999, -999,
  102929. -999, -999, -999, -999, -999, -999, -999, -999,
  102930. -999, -999, -999, -999, -999, -999, -999, -999,
  102931. -999, -999, -999, -999, -999, -999, -999, -999,
  102932. -999, -999, -999, -999, -999, -999, -999, -999},
  102933. {-999, -999, -999, -999, -999, -999, -999, -999,
  102934. -999, -999, -999, -110, -100, -86, -78, -70,
  102935. -60, -45, -30, -21, -999, -999, -999, -999,
  102936. -999, -999, -999, -999, -999, -999, -999, -999,
  102937. -999, -999, -999, -999, -999, -999, -999, -999,
  102938. -999, -999, -999, -999, -999, -999, -999, -999,
  102939. -999, -999, -999, -999, -999, -999, -999, -999},
  102940. {-999, -999, -999, -999, -999, -999, -999, -999,
  102941. -999, -999, -999, -110, -100, -87, -78, -67,
  102942. -48, -38, -29, -21, -999, -999, -999, -999,
  102943. -999, -999, -999, -999, -999, -999, -999, -999,
  102944. -999, -999, -999, -999, -999, -999, -999, -999,
  102945. -999, -999, -999, -999, -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, -110, -100, -86, -69, -56,
  102949. -45, -35, -33, -29, -999, -999, -999, -999,
  102950. -999, -999, -999, -999, -999, -999, -999, -999,
  102951. -999, -999, -999, -999, -999, -999, -999, -999,
  102952. -999, -999, -999, -999, -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, -110, -100, -83, -71, -48,
  102956. -27, -38, -37, -34, -999, -999, -999, -999,
  102957. -999, -999, -999, -999, -999, -999, -999, -999,
  102958. -999, -999, -999, -999, -999, -999, -999, -999,
  102959. -999, -999, -999, -999, -999, -999, -999, -999,
  102960. -999, -999, -999, -999, -999, -999, -999, -999}}
  102961. };
  102962. #endif
  102963. /*** End of inlined file: masking.h ***/
  102964. #define NEGINF -9999.f
  102965. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  102966. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  102967. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  102968. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102969. vorbis_info_psy_global *gi=&ci->psy_g_param;
  102970. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  102971. look->channels=vi->channels;
  102972. look->ampmax=-9999.;
  102973. look->gi=gi;
  102974. return(look);
  102975. }
  102976. void _vp_global_free(vorbis_look_psy_global *look){
  102977. if(look){
  102978. memset(look,0,sizeof(*look));
  102979. _ogg_free(look);
  102980. }
  102981. }
  102982. void _vi_gpsy_free(vorbis_info_psy_global *i){
  102983. if(i){
  102984. memset(i,0,sizeof(*i));
  102985. _ogg_free(i);
  102986. }
  102987. }
  102988. void _vi_psy_free(vorbis_info_psy *i){
  102989. if(i){
  102990. memset(i,0,sizeof(*i));
  102991. _ogg_free(i);
  102992. }
  102993. }
  102994. static void min_curve(float *c,
  102995. float *c2){
  102996. int i;
  102997. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  102998. }
  102999. static void max_curve(float *c,
  103000. float *c2){
  103001. int i;
  103002. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103003. }
  103004. static void attenuate_curve(float *c,float att){
  103005. int i;
  103006. for(i=0;i<EHMER_MAX;i++)
  103007. c[i]+=att;
  103008. }
  103009. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103010. float center_boost, float center_decay_rate){
  103011. int i,j,k,m;
  103012. float ath[EHMER_MAX];
  103013. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103014. float athc[P_LEVELS][EHMER_MAX];
  103015. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103016. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103017. memset(workc,0,sizeof(workc));
  103018. for(i=0;i<P_BANDS;i++){
  103019. int ath_offset=i*4;
  103020. for(j=0;j<EHMER_MAX;j++){
  103021. float min=999.;
  103022. for(k=0;k<4;k++)
  103023. if(j+k+ath_offset<MAX_ATH){
  103024. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103025. }else{
  103026. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103027. }
  103028. ath[j]=min;
  103029. }
  103030. for(j=0;j<6;j++)
  103031. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103032. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103033. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103034. for(j=0;j<P_LEVELS;j++){
  103035. for(k=0;k<EHMER_MAX;k++){
  103036. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103037. if(adj<0. && center_boost>0)adj=0.;
  103038. if(adj>0. && center_boost<0)adj=0.;
  103039. workc[i][j][k]+=adj;
  103040. }
  103041. }
  103042. for(j=0;j<P_LEVELS;j++){
  103043. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103044. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103045. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103046. max_curve(athc[j],workc[i][j]);
  103047. }
  103048. for(j=1;j<P_LEVELS;j++){
  103049. min_curve(athc[j],athc[j-1]);
  103050. min_curve(workc[i][j],athc[j]);
  103051. }
  103052. }
  103053. for(i=0;i<P_BANDS;i++){
  103054. int hi_curve,lo_curve,bin;
  103055. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103056. bin=floor(fromOC(i*.5)/binHz);
  103057. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103058. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103059. if(lo_curve>i)lo_curve=i;
  103060. if(lo_curve<0)lo_curve=0;
  103061. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103062. for(m=0;m<P_LEVELS;m++){
  103063. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103064. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103065. for(k=lo_curve;k<=hi_curve;k++){
  103066. int l=0;
  103067. for(j=0;j<EHMER_MAX;j++){
  103068. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103069. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103070. if(lo_bin<0)lo_bin=0;
  103071. if(lo_bin>n)lo_bin=n;
  103072. if(lo_bin<l)l=lo_bin;
  103073. if(hi_bin<0)hi_bin=0;
  103074. if(hi_bin>n)hi_bin=n;
  103075. for(;l<hi_bin && l<n;l++)
  103076. if(brute_buffer[l]>workc[k][m][j])
  103077. brute_buffer[l]=workc[k][m][j];
  103078. }
  103079. for(;l<n;l++)
  103080. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103081. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103082. }
  103083. if(i+1<P_BANDS){
  103084. int l=0;
  103085. k=i+1;
  103086. for(j=0;j<EHMER_MAX;j++){
  103087. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103088. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103089. if(lo_bin<0)lo_bin=0;
  103090. if(lo_bin>n)lo_bin=n;
  103091. if(lo_bin<l)l=lo_bin;
  103092. if(hi_bin<0)hi_bin=0;
  103093. if(hi_bin>n)hi_bin=n;
  103094. for(;l<hi_bin && l<n;l++)
  103095. if(brute_buffer[l]>workc[k][m][j])
  103096. brute_buffer[l]=workc[k][m][j];
  103097. }
  103098. for(;l<n;l++)
  103099. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103100. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103101. }
  103102. for(j=0;j<EHMER_MAX;j++){
  103103. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103104. if(bin<0){
  103105. ret[i][m][j+2]=-999.;
  103106. }else{
  103107. if(bin>=n){
  103108. ret[i][m][j+2]=-999.;
  103109. }else{
  103110. ret[i][m][j+2]=brute_buffer[bin];
  103111. }
  103112. }
  103113. }
  103114. for(j=0;j<EHMER_OFFSET;j++)
  103115. if(ret[i][m][j+2]>-200.f)break;
  103116. ret[i][m][0]=j;
  103117. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103118. if(ret[i][m][j+2]>-200.f)
  103119. break;
  103120. ret[i][m][1]=j;
  103121. }
  103122. }
  103123. return(ret);
  103124. }
  103125. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103126. vorbis_info_psy_global *gi,int n,long rate){
  103127. long i,j,lo=-99,hi=1;
  103128. long maxoc;
  103129. memset(p,0,sizeof(*p));
  103130. p->eighth_octave_lines=gi->eighth_octave_lines;
  103131. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103132. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103133. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103134. p->total_octave_lines=maxoc-p->firstoc+1;
  103135. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103136. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103137. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103138. p->vi=vi;
  103139. p->n=n;
  103140. p->rate=rate;
  103141. p->m_val = 1.;
  103142. if(rate < 26000) p->m_val = 0;
  103143. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103144. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103145. for(i=0,j=0;i<MAX_ATH-1;i++){
  103146. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103147. float base=ATH[i];
  103148. if(j<endpos){
  103149. float delta=(ATH[i+1]-base)/(endpos-j);
  103150. for(;j<endpos && j<n;j++){
  103151. p->ath[j]=base+100.;
  103152. base+=delta;
  103153. }
  103154. }
  103155. }
  103156. for(i=0;i<n;i++){
  103157. float bark=toBARK(rate/(2*n)*i);
  103158. for(;lo+vi->noisewindowlomin<i &&
  103159. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103160. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103161. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103162. p->bark[i]=((lo-1)<<16)+(hi-1);
  103163. }
  103164. for(i=0;i<n;i++)
  103165. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103166. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103167. vi->tone_centerboost,vi->tone_decay);
  103168. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103169. for(i=0;i<P_NOISECURVES;i++)
  103170. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103171. for(i=0;i<n;i++){
  103172. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103173. int inthalfoc;
  103174. float del;
  103175. if(halfoc<0)halfoc=0;
  103176. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103177. inthalfoc=(int)halfoc;
  103178. del=halfoc-inthalfoc;
  103179. for(j=0;j<P_NOISECURVES;j++)
  103180. p->noiseoffset[j][i]=
  103181. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103182. p->vi->noiseoff[j][inthalfoc+1]*del;
  103183. }
  103184. #if 0
  103185. {
  103186. static int ls=0;
  103187. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103188. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103189. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103190. }
  103191. #endif
  103192. }
  103193. void _vp_psy_clear(vorbis_look_psy *p){
  103194. int i,j;
  103195. if(p){
  103196. if(p->ath)_ogg_free(p->ath);
  103197. if(p->octave)_ogg_free(p->octave);
  103198. if(p->bark)_ogg_free(p->bark);
  103199. if(p->tonecurves){
  103200. for(i=0;i<P_BANDS;i++){
  103201. for(j=0;j<P_LEVELS;j++){
  103202. _ogg_free(p->tonecurves[i][j]);
  103203. }
  103204. _ogg_free(p->tonecurves[i]);
  103205. }
  103206. _ogg_free(p->tonecurves);
  103207. }
  103208. if(p->noiseoffset){
  103209. for(i=0;i<P_NOISECURVES;i++){
  103210. _ogg_free(p->noiseoffset[i]);
  103211. }
  103212. _ogg_free(p->noiseoffset);
  103213. }
  103214. memset(p,0,sizeof(*p));
  103215. }
  103216. }
  103217. static void seed_curve(float *seed,
  103218. const float **curves,
  103219. float amp,
  103220. int oc, int n,
  103221. int linesper,float dBoffset){
  103222. int i,post1;
  103223. int seedptr;
  103224. const float *posts,*curve;
  103225. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103226. choice=max(choice,0);
  103227. choice=min(choice,P_LEVELS-1);
  103228. posts=curves[choice];
  103229. curve=posts+2;
  103230. post1=(int)posts[1];
  103231. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103232. for(i=posts[0];i<post1;i++){
  103233. if(seedptr>0){
  103234. float lin=amp+curve[i];
  103235. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103236. }
  103237. seedptr+=linesper;
  103238. if(seedptr>=n)break;
  103239. }
  103240. }
  103241. static void seed_loop(vorbis_look_psy *p,
  103242. const float ***curves,
  103243. const float *f,
  103244. const float *flr,
  103245. float *seed,
  103246. float specmax){
  103247. vorbis_info_psy *vi=p->vi;
  103248. long n=p->n,i;
  103249. float dBoffset=vi->max_curve_dB-specmax;
  103250. for(i=0;i<n;i++){
  103251. float max=f[i];
  103252. long oc=p->octave[i];
  103253. while(i+1<n && p->octave[i+1]==oc){
  103254. i++;
  103255. if(f[i]>max)max=f[i];
  103256. }
  103257. if(max+6.f>flr[i]){
  103258. oc=oc>>p->shiftoc;
  103259. if(oc>=P_BANDS)oc=P_BANDS-1;
  103260. if(oc<0)oc=0;
  103261. seed_curve(seed,
  103262. curves[oc],
  103263. max,
  103264. p->octave[i]-p->firstoc,
  103265. p->total_octave_lines,
  103266. p->eighth_octave_lines,
  103267. dBoffset);
  103268. }
  103269. }
  103270. }
  103271. static void seed_chase(float *seeds, int linesper, long n){
  103272. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103273. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103274. long stack=0;
  103275. long pos=0;
  103276. long i;
  103277. for(i=0;i<n;i++){
  103278. if(stack<2){
  103279. posstack[stack]=i;
  103280. ampstack[stack++]=seeds[i];
  103281. }else{
  103282. while(1){
  103283. if(seeds[i]<ampstack[stack-1]){
  103284. posstack[stack]=i;
  103285. ampstack[stack++]=seeds[i];
  103286. break;
  103287. }else{
  103288. if(i<posstack[stack-1]+linesper){
  103289. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103290. i<posstack[stack-2]+linesper){
  103291. stack--;
  103292. continue;
  103293. }
  103294. }
  103295. posstack[stack]=i;
  103296. ampstack[stack++]=seeds[i];
  103297. break;
  103298. }
  103299. }
  103300. }
  103301. }
  103302. for(i=0;i<stack;i++){
  103303. long endpos;
  103304. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103305. endpos=posstack[i+1];
  103306. }else{
  103307. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103308. discarded in short frames */
  103309. }
  103310. if(endpos>n)endpos=n;
  103311. for(;pos<endpos;pos++)
  103312. seeds[pos]=ampstack[i];
  103313. }
  103314. }
  103315. #include<stdio.h>
  103316. static void max_seeds(vorbis_look_psy *p,
  103317. float *seed,
  103318. float *flr){
  103319. long n=p->total_octave_lines;
  103320. int linesper=p->eighth_octave_lines;
  103321. long linpos=0;
  103322. long pos;
  103323. seed_chase(seed,linesper,n); /* for masking */
  103324. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103325. while(linpos+1<p->n){
  103326. float minV=seed[pos];
  103327. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103328. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103329. while(pos+1<=end){
  103330. pos++;
  103331. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103332. minV=seed[pos];
  103333. }
  103334. end=pos+p->firstoc;
  103335. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103336. if(flr[linpos]<minV)flr[linpos]=minV;
  103337. }
  103338. {
  103339. float minV=seed[p->total_octave_lines-1];
  103340. for(;linpos<p->n;linpos++)
  103341. if(flr[linpos]<minV)flr[linpos]=minV;
  103342. }
  103343. }
  103344. static void bark_noise_hybridmp(int n,const long *b,
  103345. const float *f,
  103346. float *noise,
  103347. const float offset,
  103348. const int fixed){
  103349. float *N=(float*) alloca(n*sizeof(*N));
  103350. float *X=(float*) alloca(n*sizeof(*N));
  103351. float *XX=(float*) alloca(n*sizeof(*N));
  103352. float *Y=(float*) alloca(n*sizeof(*N));
  103353. float *XY=(float*) alloca(n*sizeof(*N));
  103354. float tN, tX, tXX, tY, tXY;
  103355. int i;
  103356. int lo, hi;
  103357. float R, A, B, D;
  103358. float w, x, y;
  103359. tN = tX = tXX = tY = tXY = 0.f;
  103360. y = f[0] + offset;
  103361. if (y < 1.f) y = 1.f;
  103362. w = y * y * .5;
  103363. tN += w;
  103364. tX += w;
  103365. tY += w * y;
  103366. N[0] = tN;
  103367. X[0] = tX;
  103368. XX[0] = tXX;
  103369. Y[0] = tY;
  103370. XY[0] = tXY;
  103371. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103372. y = f[i] + offset;
  103373. if (y < 1.f) y = 1.f;
  103374. w = y * y;
  103375. tN += w;
  103376. tX += w * x;
  103377. tXX += w * x * x;
  103378. tY += w * y;
  103379. tXY += w * x * y;
  103380. N[i] = tN;
  103381. X[i] = tX;
  103382. XX[i] = tXX;
  103383. Y[i] = tY;
  103384. XY[i] = tXY;
  103385. }
  103386. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103387. lo = b[i] >> 16;
  103388. if( lo>=0 ) break;
  103389. hi = b[i] & 0xffff;
  103390. tN = N[hi] + N[-lo];
  103391. tX = X[hi] - X[-lo];
  103392. tXX = XX[hi] + XX[-lo];
  103393. tY = Y[hi] + Y[-lo];
  103394. tXY = XY[hi] - XY[-lo];
  103395. A = tY * tXX - tX * tXY;
  103396. B = tN * tXY - tX * tY;
  103397. D = tN * tXX - tX * tX;
  103398. R = (A + x * B) / D;
  103399. if (R < 0.f)
  103400. R = 0.f;
  103401. noise[i] = R - offset;
  103402. }
  103403. for ( ;; i++, x += 1.f) {
  103404. lo = b[i] >> 16;
  103405. hi = b[i] & 0xffff;
  103406. if(hi>=n)break;
  103407. tN = N[hi] - N[lo];
  103408. tX = X[hi] - X[lo];
  103409. tXX = XX[hi] - XX[lo];
  103410. tY = Y[hi] - Y[lo];
  103411. tXY = XY[hi] - XY[lo];
  103412. A = tY * tXX - tX * tXY;
  103413. B = tN * tXY - tX * tY;
  103414. D = tN * tXX - tX * tX;
  103415. R = (A + x * B) / D;
  103416. if (R < 0.f) R = 0.f;
  103417. noise[i] = R - offset;
  103418. }
  103419. for ( ; i < n; i++, x += 1.f) {
  103420. R = (A + x * B) / D;
  103421. if (R < 0.f) R = 0.f;
  103422. noise[i] = R - offset;
  103423. }
  103424. if (fixed <= 0) return;
  103425. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103426. hi = i + fixed / 2;
  103427. lo = hi - fixed;
  103428. if(lo>=0)break;
  103429. tN = N[hi] + N[-lo];
  103430. tX = X[hi] - X[-lo];
  103431. tXX = XX[hi] + XX[-lo];
  103432. tY = Y[hi] + Y[-lo];
  103433. tXY = XY[hi] - XY[-lo];
  103434. A = tY * tXX - tX * tXY;
  103435. B = tN * tXY - tX * tY;
  103436. D = tN * tXX - tX * tX;
  103437. R = (A + x * B) / D;
  103438. if (R - offset < noise[i]) noise[i] = R - offset;
  103439. }
  103440. for ( ;; i++, x += 1.f) {
  103441. hi = i + fixed / 2;
  103442. lo = hi - fixed;
  103443. if(hi>=n)break;
  103444. tN = N[hi] - N[lo];
  103445. tX = X[hi] - X[lo];
  103446. tXX = XX[hi] - XX[lo];
  103447. tY = Y[hi] - Y[lo];
  103448. tXY = XY[hi] - XY[lo];
  103449. A = tY * tXX - tX * tXY;
  103450. B = tN * tXY - tX * tY;
  103451. D = tN * tXX - tX * tX;
  103452. R = (A + x * B) / D;
  103453. if (R - offset < noise[i]) noise[i] = R - offset;
  103454. }
  103455. for ( ; i < n; i++, x += 1.f) {
  103456. R = (A + x * B) / D;
  103457. if (R - offset < noise[i]) noise[i] = R - offset;
  103458. }
  103459. }
  103460. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103461. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103462. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103463. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103464. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103465. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103466. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103467. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103468. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103469. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103470. 973377.F, 913981.F, 858210.F, 805842.F,
  103471. 756669.F, 710497.F, 667142.F, 626433.F,
  103472. 588208.F, 552316.F, 518613.F, 486967.F,
  103473. 457252.F, 429351.F, 403152.F, 378551.F,
  103474. 355452.F, 333762.F, 313396.F, 294273.F,
  103475. 276316.F, 259455.F, 243623.F, 228757.F,
  103476. 214798.F, 201691.F, 189384.F, 177828.F,
  103477. 166977.F, 156788.F, 147221.F, 138237.F,
  103478. 129802.F, 121881.F, 114444.F, 107461.F,
  103479. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103480. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103481. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103482. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103483. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103484. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103485. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103486. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103487. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103488. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103489. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103490. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103491. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103492. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103493. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103494. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103495. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103496. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103497. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103498. 842.910F, 791.475F, 743.179F, 697.830F,
  103499. 655.249F, 615.265F, 577.722F, 542.469F,
  103500. 509.367F, 478.286F, 449.101F, 421.696F,
  103501. 395.964F, 371.803F, 349.115F, 327.812F,
  103502. 307.809F, 289.026F, 271.390F, 254.830F,
  103503. 239.280F, 224.679F, 210.969F, 198.096F,
  103504. 186.008F, 174.658F, 164.000F, 153.993F,
  103505. 144.596F, 135.773F, 127.488F, 119.708F,
  103506. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103507. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103508. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103509. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103510. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103511. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103512. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103513. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103514. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103515. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103516. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103517. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103518. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103519. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103520. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103521. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103522. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103523. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103524. 1.20790F, 1.13419F, 1.06499F, 1.F
  103525. };
  103526. void _vp_remove_floor(vorbis_look_psy *p,
  103527. float *mdct,
  103528. int *codedflr,
  103529. float *residue,
  103530. int sliding_lowpass){
  103531. int i,n=p->n;
  103532. if(sliding_lowpass>n)sliding_lowpass=n;
  103533. for(i=0;i<sliding_lowpass;i++){
  103534. residue[i]=
  103535. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103536. }
  103537. for(;i<n;i++)
  103538. residue[i]=0.;
  103539. }
  103540. void _vp_noisemask(vorbis_look_psy *p,
  103541. float *logmdct,
  103542. float *logmask){
  103543. int i,n=p->n;
  103544. float *work=(float*) alloca(n*sizeof(*work));
  103545. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103546. 140.,-1);
  103547. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103548. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103549. p->vi->noisewindowfixed);
  103550. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103551. #if 0
  103552. {
  103553. static int seq=0;
  103554. float work2[n];
  103555. for(i=0;i<n;i++){
  103556. work2[i]=logmask[i]+work[i];
  103557. }
  103558. if(seq&1)
  103559. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103560. else
  103561. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103562. if(seq&1)
  103563. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103564. else
  103565. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103566. seq++;
  103567. }
  103568. #endif
  103569. for(i=0;i<n;i++){
  103570. int dB=logmask[i]+.5;
  103571. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103572. if(dB<0)dB=0;
  103573. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103574. }
  103575. }
  103576. void _vp_tonemask(vorbis_look_psy *p,
  103577. float *logfft,
  103578. float *logmask,
  103579. float global_specmax,
  103580. float local_specmax){
  103581. int i,n=p->n;
  103582. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103583. float att=local_specmax+p->vi->ath_adjatt;
  103584. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103585. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103586. for(i=0;i<n;i++)
  103587. logmask[i]=p->ath[i]+att;
  103588. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103589. max_seeds(p,seed,logmask);
  103590. }
  103591. void _vp_offset_and_mix(vorbis_look_psy *p,
  103592. float *noise,
  103593. float *tone,
  103594. int offset_select,
  103595. float *logmask,
  103596. float *mdct,
  103597. float *logmdct){
  103598. int i,n=p->n;
  103599. float de, coeffi, cx;/* AoTuV */
  103600. float toneatt=p->vi->tone_masteratt[offset_select];
  103601. cx = p->m_val;
  103602. for(i=0;i<n;i++){
  103603. float val= noise[i]+p->noiseoffset[offset_select][i];
  103604. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103605. logmask[i]=max(val,tone[i]+toneatt);
  103606. if(offset_select == 1) {
  103607. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103608. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103609. if(val > coeffi){
  103610. de = 1.0-((val-coeffi)*0.005*cx);
  103611. if(de < 0) de = 0.0001;
  103612. }else
  103613. de = 1.0-((val-coeffi)*0.0003*cx);
  103614. mdct[i] *= de;
  103615. }
  103616. }
  103617. }
  103618. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103619. vorbis_info *vi=vd->vi;
  103620. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103621. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103622. int n=ci->blocksizes[vd->W]/2;
  103623. float secs=(float)n/vi->rate;
  103624. amp+=secs*gi->ampmax_att_per_sec;
  103625. if(amp<-9999)amp=-9999;
  103626. return(amp);
  103627. }
  103628. static void couple_lossless(float A, float B,
  103629. float *qA, float *qB){
  103630. int test1=fabs(*qA)>fabs(*qB);
  103631. test1-= fabs(*qA)<fabs(*qB);
  103632. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103633. if(test1==1){
  103634. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103635. }else{
  103636. float temp=*qB;
  103637. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103638. *qA=temp;
  103639. }
  103640. if(*qB>fabs(*qA)*1.9999f){
  103641. *qB= -fabs(*qA)*2.f;
  103642. *qA= -*qA;
  103643. }
  103644. }
  103645. static float hypot_lookup[32]={
  103646. -0.009935, -0.011245, -0.012726, -0.014397,
  103647. -0.016282, -0.018407, -0.020800, -0.023494,
  103648. -0.026522, -0.029923, -0.033737, -0.038010,
  103649. -0.042787, -0.048121, -0.054064, -0.060671,
  103650. -0.068000, -0.076109, -0.085054, -0.094892,
  103651. -0.105675, -0.117451, -0.130260, -0.144134,
  103652. -0.159093, -0.175146, -0.192286, -0.210490,
  103653. -0.229718, -0.249913, -0.271001, -0.292893};
  103654. static void precomputed_couple_point(float premag,
  103655. int floorA,int floorB,
  103656. float *mag, float *ang){
  103657. int test=(floorA>floorB)-1;
  103658. int offset=31-abs(floorA-floorB);
  103659. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103660. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103661. *mag=premag*floormag;
  103662. *ang=0.f;
  103663. }
  103664. static float dipole_hypot(float a, float b){
  103665. if(a>0.){
  103666. if(b>0.)return sqrt(a*a+b*b);
  103667. if(a>-b)return sqrt(a*a-b*b);
  103668. return -sqrt(b*b-a*a);
  103669. }
  103670. if(b<0.)return -sqrt(a*a+b*b);
  103671. if(-a>b)return -sqrt(a*a-b*b);
  103672. return sqrt(b*b-a*a);
  103673. }
  103674. static float round_hypot(float a, float b){
  103675. if(a>0.){
  103676. if(b>0.)return sqrt(a*a+b*b);
  103677. if(a>-b)return sqrt(a*a+b*b);
  103678. return -sqrt(b*b+a*a);
  103679. }
  103680. if(b<0.)return -sqrt(a*a+b*b);
  103681. if(-a>b)return -sqrt(a*a+b*b);
  103682. return sqrt(b*b+a*a);
  103683. }
  103684. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103685. vorbis_info_psy_global *g,
  103686. vorbis_look_psy *p,
  103687. vorbis_info_mapping0 *vi,
  103688. float **mdct){
  103689. int i,j,n=p->n;
  103690. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103691. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103692. for(i=0;i<vi->coupling_steps;i++){
  103693. float *mdctM=mdct[vi->coupling_mag[i]];
  103694. float *mdctA=mdct[vi->coupling_ang[i]];
  103695. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103696. for(j=0;j<limit;j++)
  103697. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103698. for(;j<n;j++)
  103699. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103700. }
  103701. return(ret);
  103702. }
  103703. static int apsort(const void *a, const void *b){
  103704. float f1=fabs(**(float**)a);
  103705. float f2=fabs(**(float**)b);
  103706. return (f1<f2)-(f1>f2);
  103707. }
  103708. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103709. vorbis_look_psy *p,
  103710. vorbis_info_mapping0 *vi,
  103711. float **mags){
  103712. if(p->vi->normal_point_p){
  103713. int i,j,k,n=p->n;
  103714. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103715. int partition=p->vi->normal_partition;
  103716. float **work=(float**) alloca(sizeof(*work)*partition);
  103717. for(i=0;i<vi->coupling_steps;i++){
  103718. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103719. for(j=0;j<n;j+=partition){
  103720. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103721. qsort(work,partition,sizeof(*work),apsort);
  103722. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103723. }
  103724. }
  103725. return(ret);
  103726. }
  103727. return(NULL);
  103728. }
  103729. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103730. float *magnitudes,int *sortedindex){
  103731. int i,j,n=p->n;
  103732. vorbis_info_psy *vi=p->vi;
  103733. int partition=vi->normal_partition;
  103734. float **work=(float**) alloca(sizeof(*work)*partition);
  103735. int start=vi->normal_start;
  103736. for(j=start;j<n;j+=partition){
  103737. if(j+partition>n)partition=n-j;
  103738. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103739. qsort(work,partition,sizeof(*work),apsort);
  103740. for(i=0;i<partition;i++){
  103741. sortedindex[i+j-start]=work[i]-magnitudes;
  103742. }
  103743. }
  103744. }
  103745. void _vp_noise_normalize(vorbis_look_psy *p,
  103746. float *in,float *out,int *sortedindex){
  103747. int flag=0,i,j=0,n=p->n;
  103748. vorbis_info_psy *vi=p->vi;
  103749. int partition=vi->normal_partition;
  103750. int start=vi->normal_start;
  103751. if(start>n)start=n;
  103752. if(vi->normal_channel_p){
  103753. for(;j<start;j++)
  103754. out[j]=rint(in[j]);
  103755. for(;j+partition<=n;j+=partition){
  103756. float acc=0.;
  103757. int k;
  103758. for(i=j;i<j+partition;i++)
  103759. acc+=in[i]*in[i];
  103760. for(i=0;i<partition;i++){
  103761. k=sortedindex[i+j-start];
  103762. if(in[k]*in[k]>=.25f){
  103763. out[k]=rint(in[k]);
  103764. acc-=in[k]*in[k];
  103765. flag=1;
  103766. }else{
  103767. if(acc<vi->normal_thresh)break;
  103768. out[k]=unitnorm(in[k]);
  103769. acc-=1.;
  103770. }
  103771. }
  103772. for(;i<partition;i++){
  103773. k=sortedindex[i+j-start];
  103774. out[k]=0.;
  103775. }
  103776. }
  103777. }
  103778. for(;j<n;j++)
  103779. out[j]=rint(in[j]);
  103780. }
  103781. void _vp_couple(int blobno,
  103782. vorbis_info_psy_global *g,
  103783. vorbis_look_psy *p,
  103784. vorbis_info_mapping0 *vi,
  103785. float **res,
  103786. float **mag_memo,
  103787. int **mag_sort,
  103788. int **ifloor,
  103789. int *nonzero,
  103790. int sliding_lowpass){
  103791. int i,j,k,n=p->n;
  103792. for(i=0;i<vi->coupling_steps;i++){
  103793. if(nonzero[vi->coupling_mag[i]] ||
  103794. nonzero[vi->coupling_ang[i]]){
  103795. float *rM=res[vi->coupling_mag[i]];
  103796. float *rA=res[vi->coupling_ang[i]];
  103797. float *qM=rM+n;
  103798. float *qA=rA+n;
  103799. int *floorM=ifloor[vi->coupling_mag[i]];
  103800. int *floorA=ifloor[vi->coupling_ang[i]];
  103801. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103802. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103803. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103804. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103805. int pointlimit=limit;
  103806. nonzero[vi->coupling_mag[i]]=1;
  103807. nonzero[vi->coupling_ang[i]]=1;
  103808. if(n > 1000)
  103809. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103810. for(j=0;j<p->n;j+=partition){
  103811. float acc=0.f;
  103812. for(k=0;k<partition;k++){
  103813. int l=k+j;
  103814. if(l<sliding_lowpass){
  103815. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103816. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103817. precomputed_couple_point(mag_memo[i][l],
  103818. floorM[l],floorA[l],
  103819. qM+l,qA+l);
  103820. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103821. }else{
  103822. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103823. }
  103824. }else{
  103825. qM[l]=0.;
  103826. qA[l]=0.;
  103827. }
  103828. }
  103829. if(p->vi->normal_point_p){
  103830. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103831. int l=mag_sort[i][j+k];
  103832. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103833. qM[l]=unitnorm(qM[l]);
  103834. acc-=1.f;
  103835. }
  103836. }
  103837. }
  103838. }
  103839. }
  103840. }
  103841. }
  103842. void hf_reduction(vorbis_info_psy_global *g,
  103843. vorbis_look_psy *p,
  103844. vorbis_info_mapping0 *vi,
  103845. float **mdct){
  103846. int i,j,n=p->n, de=0.3*p->m_val;
  103847. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103848. for(i=0; i<vi->coupling_steps; i++){
  103849. for(j=limit; j<n; j++)
  103850. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103851. }
  103852. }
  103853. #endif
  103854. /*** End of inlined file: psy.c ***/
  103855. /*** Start of inlined file: registry.c ***/
  103856. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103857. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103858. // tasks..
  103859. #if JUCE_MSVC
  103860. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103861. #endif
  103862. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103863. #if JUCE_USE_OGGVORBIS
  103864. extern vorbis_func_floor floor0_exportbundle;
  103865. extern vorbis_func_floor floor1_exportbundle;
  103866. extern vorbis_func_residue residue0_exportbundle;
  103867. extern vorbis_func_residue residue1_exportbundle;
  103868. extern vorbis_func_residue residue2_exportbundle;
  103869. extern vorbis_func_mapping mapping0_exportbundle;
  103870. vorbis_func_floor *_floor_P[]={
  103871. &floor0_exportbundle,
  103872. &floor1_exportbundle,
  103873. };
  103874. vorbis_func_residue *_residue_P[]={
  103875. &residue0_exportbundle,
  103876. &residue1_exportbundle,
  103877. &residue2_exportbundle,
  103878. };
  103879. vorbis_func_mapping *_mapping_P[]={
  103880. &mapping0_exportbundle,
  103881. };
  103882. #endif
  103883. /*** End of inlined file: registry.c ***/
  103884. /*** Start of inlined file: res0.c ***/
  103885. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103886. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103887. // tasks..
  103888. #if JUCE_MSVC
  103889. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103890. #endif
  103891. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103892. #if JUCE_USE_OGGVORBIS
  103893. #include <stdlib.h>
  103894. #include <string.h>
  103895. #include <math.h>
  103896. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103897. #include <stdio.h>
  103898. #endif
  103899. typedef struct {
  103900. vorbis_info_residue0 *info;
  103901. int parts;
  103902. int stages;
  103903. codebook *fullbooks;
  103904. codebook *phrasebook;
  103905. codebook ***partbooks;
  103906. int partvals;
  103907. int **decodemap;
  103908. long postbits;
  103909. long phrasebits;
  103910. long frames;
  103911. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103912. int train_seq;
  103913. long *training_data[8][64];
  103914. float training_max[8][64];
  103915. float training_min[8][64];
  103916. float tmin;
  103917. float tmax;
  103918. #endif
  103919. } vorbis_look_residue0;
  103920. void res0_free_info(vorbis_info_residue *i){
  103921. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103922. if(info){
  103923. memset(info,0,sizeof(*info));
  103924. _ogg_free(info);
  103925. }
  103926. }
  103927. void res0_free_look(vorbis_look_residue *i){
  103928. int j;
  103929. if(i){
  103930. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  103931. #ifdef TRAIN_RES
  103932. {
  103933. int j,k,l;
  103934. for(j=0;j<look->parts;j++){
  103935. for(k=0;k<8;k++)
  103936. if(look->training_data[k][j]){
  103937. char buffer[80];
  103938. FILE *of;
  103939. codebook *statebook=look->partbooks[j][k];
  103940. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  103941. of=fopen(buffer,"a");
  103942. for(l=0;l<statebook->entries;l++)
  103943. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  103944. fclose(of);
  103945. _ogg_free(look->training_data[k][j]);
  103946. look->training_data[k][j]=NULL;
  103947. }
  103948. }
  103949. }
  103950. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  103951. #endif
  103952. for(j=0;j<look->parts;j++)
  103953. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  103954. _ogg_free(look->partbooks);
  103955. for(j=0;j<look->partvals;j++)
  103956. _ogg_free(look->decodemap[j]);
  103957. _ogg_free(look->decodemap);
  103958. memset(look,0,sizeof(*look));
  103959. _ogg_free(look);
  103960. }
  103961. }
  103962. static int icount(unsigned int v){
  103963. int ret=0;
  103964. while(v){
  103965. ret+=v&1;
  103966. v>>=1;
  103967. }
  103968. return(ret);
  103969. }
  103970. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  103971. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103972. int j,acc=0;
  103973. oggpack_write(opb,info->begin,24);
  103974. oggpack_write(opb,info->end,24);
  103975. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  103976. code with a partitioned book */
  103977. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  103978. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  103979. for(j=0;j<info->partitions;j++){
  103980. if(ilog(info->secondstages[j])>3){
  103981. oggpack_write(opb,info->secondstages[j],3);
  103982. oggpack_write(opb,1,1);
  103983. oggpack_write(opb,info->secondstages[j]>>3,5);
  103984. }else
  103985. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  103986. acc+=icount(info->secondstages[j]);
  103987. }
  103988. for(j=0;j<acc;j++)
  103989. oggpack_write(opb,info->booklist[j],8);
  103990. }
  103991. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  103992. int j,acc=0;
  103993. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  103994. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  103995. info->begin=oggpack_read(opb,24);
  103996. info->end=oggpack_read(opb,24);
  103997. info->grouping=oggpack_read(opb,24)+1;
  103998. info->partitions=oggpack_read(opb,6)+1;
  103999. info->groupbook=oggpack_read(opb,8);
  104000. for(j=0;j<info->partitions;j++){
  104001. int cascade=oggpack_read(opb,3);
  104002. if(oggpack_read(opb,1))
  104003. cascade|=(oggpack_read(opb,5)<<3);
  104004. info->secondstages[j]=cascade;
  104005. acc+=icount(cascade);
  104006. }
  104007. for(j=0;j<acc;j++)
  104008. info->booklist[j]=oggpack_read(opb,8);
  104009. if(info->groupbook>=ci->books)goto errout;
  104010. for(j=0;j<acc;j++)
  104011. if(info->booklist[j]>=ci->books)goto errout;
  104012. return(info);
  104013. errout:
  104014. res0_free_info(info);
  104015. return(NULL);
  104016. }
  104017. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104018. vorbis_info_residue *vr){
  104019. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104020. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104021. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104022. int j,k,acc=0;
  104023. int dim;
  104024. int maxstage=0;
  104025. look->info=info;
  104026. look->parts=info->partitions;
  104027. look->fullbooks=ci->fullbooks;
  104028. look->phrasebook=ci->fullbooks+info->groupbook;
  104029. dim=look->phrasebook->dim;
  104030. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104031. for(j=0;j<look->parts;j++){
  104032. int stages=ilog(info->secondstages[j]);
  104033. if(stages){
  104034. if(stages>maxstage)maxstage=stages;
  104035. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104036. for(k=0;k<stages;k++)
  104037. if(info->secondstages[j]&(1<<k)){
  104038. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104039. #ifdef TRAIN_RES
  104040. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104041. sizeof(***look->training_data));
  104042. #endif
  104043. }
  104044. }
  104045. }
  104046. look->partvals=rint(pow((float)look->parts,(float)dim));
  104047. look->stages=maxstage;
  104048. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104049. for(j=0;j<look->partvals;j++){
  104050. long val=j;
  104051. long mult=look->partvals/look->parts;
  104052. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104053. for(k=0;k<dim;k++){
  104054. long deco=val/mult;
  104055. val-=deco*mult;
  104056. mult/=look->parts;
  104057. look->decodemap[j][k]=deco;
  104058. }
  104059. }
  104060. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104061. {
  104062. static int train_seq=0;
  104063. look->train_seq=train_seq++;
  104064. }
  104065. #endif
  104066. return(look);
  104067. }
  104068. static int local_book_besterror(codebook *book,float *a){
  104069. int dim=book->dim,i,k,o;
  104070. int best=0;
  104071. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104072. for(k=0,o=dim;k<dim;++k){
  104073. float val=a[--o];
  104074. i=tt->threshvals>>1;
  104075. if(val<tt->quantthresh[i]){
  104076. if(val<tt->quantthresh[i-1]){
  104077. for(--i;i>0;--i)
  104078. if(val>=tt->quantthresh[i-1])
  104079. break;
  104080. }
  104081. }else{
  104082. for(++i;i<tt->threshvals-1;++i)
  104083. if(val<tt->quantthresh[i])break;
  104084. }
  104085. best=(best*tt->quantvals)+tt->quantmap[i];
  104086. }
  104087. if(book->c->lengthlist[best]<=0){
  104088. const static_codebook *c=book->c;
  104089. int i,j;
  104090. float bestf=0.f;
  104091. float *e=book->valuelist;
  104092. best=-1;
  104093. for(i=0;i<book->entries;i++){
  104094. if(c->lengthlist[i]>0){
  104095. float thisx=0.f;
  104096. for(j=0;j<dim;j++){
  104097. float val=(e[j]-a[j]);
  104098. thisx+=val*val;
  104099. }
  104100. if(best==-1 || thisx<bestf){
  104101. bestf=thisx;
  104102. best=i;
  104103. }
  104104. }
  104105. e+=dim;
  104106. }
  104107. }
  104108. {
  104109. float *ptr=book->valuelist+best*dim;
  104110. for(i=0;i<dim;i++)
  104111. *a++ -= *ptr++;
  104112. }
  104113. return(best);
  104114. }
  104115. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104116. codebook *book,long *acc){
  104117. int i,bits=0;
  104118. int dim=book->dim;
  104119. int step=n/dim;
  104120. for(i=0;i<step;i++){
  104121. int entry=local_book_besterror(book,vec+i*dim);
  104122. #ifdef TRAIN_RES
  104123. acc[entry]++;
  104124. #endif
  104125. bits+=vorbis_book_encode(book,entry,opb);
  104126. }
  104127. return(bits);
  104128. }
  104129. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104130. float **in,int ch){
  104131. long i,j,k;
  104132. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104133. vorbis_info_residue0 *info=look->info;
  104134. int samples_per_partition=info->grouping;
  104135. int possible_partitions=info->partitions;
  104136. int n=info->end-info->begin;
  104137. int partvals=n/samples_per_partition;
  104138. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104139. float scale=100./samples_per_partition;
  104140. for(i=0;i<ch;i++){
  104141. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104142. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104143. }
  104144. for(i=0;i<partvals;i++){
  104145. int offset=i*samples_per_partition+info->begin;
  104146. for(j=0;j<ch;j++){
  104147. float max=0.;
  104148. float ent=0.;
  104149. for(k=0;k<samples_per_partition;k++){
  104150. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104151. ent+=fabs(rint(in[j][offset+k]));
  104152. }
  104153. ent*=scale;
  104154. for(k=0;k<possible_partitions-1;k++)
  104155. if(max<=info->classmetric1[k] &&
  104156. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104157. break;
  104158. partword[j][i]=k;
  104159. }
  104160. }
  104161. #ifdef TRAIN_RESAUX
  104162. {
  104163. FILE *of;
  104164. char buffer[80];
  104165. for(i=0;i<ch;i++){
  104166. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104167. of=fopen(buffer,"a");
  104168. for(j=0;j<partvals;j++)
  104169. fprintf(of,"%ld, ",partword[i][j]);
  104170. fprintf(of,"\n");
  104171. fclose(of);
  104172. }
  104173. }
  104174. #endif
  104175. look->frames++;
  104176. return(partword);
  104177. }
  104178. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104179. int ch){
  104180. long i,j,k,l;
  104181. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104182. vorbis_info_residue0 *info=look->info;
  104183. int samples_per_partition=info->grouping;
  104184. int possible_partitions=info->partitions;
  104185. int n=info->end-info->begin;
  104186. int partvals=n/samples_per_partition;
  104187. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104188. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104189. FILE *of;
  104190. char buffer[80];
  104191. #endif
  104192. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104193. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104194. for(i=0,l=info->begin/ch;i<partvals;i++){
  104195. float magmax=0.f;
  104196. float angmax=0.f;
  104197. for(j=0;j<samples_per_partition;j+=ch){
  104198. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104199. for(k=1;k<ch;k++)
  104200. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104201. l++;
  104202. }
  104203. for(j=0;j<possible_partitions-1;j++)
  104204. if(magmax<=info->classmetric1[j] &&
  104205. angmax<=info->classmetric2[j])
  104206. break;
  104207. partword[0][i]=j;
  104208. }
  104209. #ifdef TRAIN_RESAUX
  104210. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104211. of=fopen(buffer,"a");
  104212. for(i=0;i<partvals;i++)
  104213. fprintf(of,"%ld, ",partword[0][i]);
  104214. fprintf(of,"\n");
  104215. fclose(of);
  104216. #endif
  104217. look->frames++;
  104218. return(partword);
  104219. }
  104220. static int _01forward(oggpack_buffer *opb,
  104221. vorbis_block *vb,vorbis_look_residue *vl,
  104222. float **in,int ch,
  104223. long **partword,
  104224. int (*encode)(oggpack_buffer *,float *,int,
  104225. codebook *,long *)){
  104226. long i,j,k,s;
  104227. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104228. vorbis_info_residue0 *info=look->info;
  104229. int samples_per_partition=info->grouping;
  104230. int possible_partitions=info->partitions;
  104231. int partitions_per_word=look->phrasebook->dim;
  104232. int n=info->end-info->begin;
  104233. int partvals=n/samples_per_partition;
  104234. long resbits[128];
  104235. long resvals[128];
  104236. #ifdef TRAIN_RES
  104237. for(i=0;i<ch;i++)
  104238. for(j=info->begin;j<info->end;j++){
  104239. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104240. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104241. }
  104242. #endif
  104243. memset(resbits,0,sizeof(resbits));
  104244. memset(resvals,0,sizeof(resvals));
  104245. for(s=0;s<look->stages;s++){
  104246. for(i=0;i<partvals;){
  104247. if(s==0){
  104248. for(j=0;j<ch;j++){
  104249. long val=partword[j][i];
  104250. for(k=1;k<partitions_per_word;k++){
  104251. val*=possible_partitions;
  104252. if(i+k<partvals)
  104253. val+=partword[j][i+k];
  104254. }
  104255. if(val<look->phrasebook->entries)
  104256. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104257. #if 0 /*def TRAIN_RES*/
  104258. else
  104259. fprintf(stderr,"!");
  104260. #endif
  104261. }
  104262. }
  104263. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104264. long offset=i*samples_per_partition+info->begin;
  104265. for(j=0;j<ch;j++){
  104266. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104267. if(info->secondstages[partword[j][i]]&(1<<s)){
  104268. codebook *statebook=look->partbooks[partword[j][i]][s];
  104269. if(statebook){
  104270. int ret;
  104271. long *accumulator=NULL;
  104272. #ifdef TRAIN_RES
  104273. accumulator=look->training_data[s][partword[j][i]];
  104274. {
  104275. int l;
  104276. float *samples=in[j]+offset;
  104277. for(l=0;l<samples_per_partition;l++){
  104278. if(samples[l]<look->training_min[s][partword[j][i]])
  104279. look->training_min[s][partword[j][i]]=samples[l];
  104280. if(samples[l]>look->training_max[s][partword[j][i]])
  104281. look->training_max[s][partword[j][i]]=samples[l];
  104282. }
  104283. }
  104284. #endif
  104285. ret=encode(opb,in[j]+offset,samples_per_partition,
  104286. statebook,accumulator);
  104287. look->postbits+=ret;
  104288. resbits[partword[j][i]]+=ret;
  104289. }
  104290. }
  104291. }
  104292. }
  104293. }
  104294. }
  104295. return(0);
  104296. }
  104297. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104298. float **in,int ch,
  104299. long (*decodepart)(codebook *, float *,
  104300. oggpack_buffer *,int)){
  104301. long i,j,k,l,s;
  104302. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104303. vorbis_info_residue0 *info=look->info;
  104304. int samples_per_partition=info->grouping;
  104305. int partitions_per_word=look->phrasebook->dim;
  104306. int n=info->end-info->begin;
  104307. int partvals=n/samples_per_partition;
  104308. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104309. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104310. for(j=0;j<ch;j++)
  104311. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104312. for(s=0;s<look->stages;s++){
  104313. for(i=0,l=0;i<partvals;l++){
  104314. if(s==0){
  104315. for(j=0;j<ch;j++){
  104316. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104317. if(temp==-1)goto eopbreak;
  104318. partword[j][l]=look->decodemap[temp];
  104319. if(partword[j][l]==NULL)goto errout;
  104320. }
  104321. }
  104322. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104323. for(j=0;j<ch;j++){
  104324. long offset=info->begin+i*samples_per_partition;
  104325. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104326. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104327. if(stagebook){
  104328. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104329. samples_per_partition)==-1)goto eopbreak;
  104330. }
  104331. }
  104332. }
  104333. }
  104334. }
  104335. errout:
  104336. eopbreak:
  104337. return(0);
  104338. }
  104339. #if 0
  104340. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104341. float **in,int *nonzero,int ch){
  104342. int i,used=0;
  104343. for(i=0;i<ch;i++)
  104344. if(nonzero[i])
  104345. in[used++]=in[i];
  104346. if(used)
  104347. return(_01class(vb,vl,in,used));
  104348. else
  104349. return(0);
  104350. }
  104351. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104352. float **in,float **out,int *nonzero,int ch,
  104353. long **partword){
  104354. int i,j,used=0,n=vb->pcmend/2;
  104355. for(i=0;i<ch;i++)
  104356. if(nonzero[i]){
  104357. if(out)
  104358. for(j=0;j<n;j++)
  104359. out[i][j]+=in[i][j];
  104360. in[used++]=in[i];
  104361. }
  104362. if(used){
  104363. int ret=_01forward(vb,vl,in,used,partword,
  104364. _interleaved_encodepart);
  104365. if(out){
  104366. used=0;
  104367. for(i=0;i<ch;i++)
  104368. if(nonzero[i]){
  104369. for(j=0;j<n;j++)
  104370. out[i][j]-=in[used][j];
  104371. used++;
  104372. }
  104373. }
  104374. return(ret);
  104375. }else{
  104376. return(0);
  104377. }
  104378. }
  104379. #endif
  104380. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104381. float **in,int *nonzero,int ch){
  104382. int i,used=0;
  104383. for(i=0;i<ch;i++)
  104384. if(nonzero[i])
  104385. in[used++]=in[i];
  104386. if(used)
  104387. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104388. else
  104389. return(0);
  104390. }
  104391. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104392. float **in,float **out,int *nonzero,int ch,
  104393. long **partword){
  104394. int i,j,used=0,n=vb->pcmend/2;
  104395. for(i=0;i<ch;i++)
  104396. if(nonzero[i]){
  104397. if(out)
  104398. for(j=0;j<n;j++)
  104399. out[i][j]+=in[i][j];
  104400. in[used++]=in[i];
  104401. }
  104402. if(used){
  104403. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104404. if(out){
  104405. used=0;
  104406. for(i=0;i<ch;i++)
  104407. if(nonzero[i]){
  104408. for(j=0;j<n;j++)
  104409. out[i][j]-=in[used][j];
  104410. used++;
  104411. }
  104412. }
  104413. return(ret);
  104414. }else{
  104415. return(0);
  104416. }
  104417. }
  104418. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104419. float **in,int *nonzero,int ch){
  104420. int i,used=0;
  104421. for(i=0;i<ch;i++)
  104422. if(nonzero[i])
  104423. in[used++]=in[i];
  104424. if(used)
  104425. return(_01class(vb,vl,in,used));
  104426. else
  104427. return(0);
  104428. }
  104429. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104430. float **in,int *nonzero,int ch){
  104431. int i,used=0;
  104432. for(i=0;i<ch;i++)
  104433. if(nonzero[i])
  104434. in[used++]=in[i];
  104435. if(used)
  104436. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104437. else
  104438. return(0);
  104439. }
  104440. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104441. float **in,int *nonzero,int ch){
  104442. int i,used=0;
  104443. for(i=0;i<ch;i++)
  104444. if(nonzero[i])used++;
  104445. if(used)
  104446. return(_2class(vb,vl,in,ch));
  104447. else
  104448. return(0);
  104449. }
  104450. int res2_forward(oggpack_buffer *opb,
  104451. vorbis_block *vb,vorbis_look_residue *vl,
  104452. float **in,float **out,int *nonzero,int ch,
  104453. long **partword){
  104454. long i,j,k,n=vb->pcmend/2,used=0;
  104455. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104456. for(i=0;i<ch;i++){
  104457. float *pcm=in[i];
  104458. if(nonzero[i])used++;
  104459. for(j=0,k=i;j<n;j++,k+=ch)
  104460. work[k]=pcm[j];
  104461. }
  104462. if(used){
  104463. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104464. if(out){
  104465. for(i=0;i<ch;i++){
  104466. float *pcm=in[i];
  104467. float *sofar=out[i];
  104468. for(j=0,k=i;j<n;j++,k+=ch)
  104469. sofar[j]+=pcm[j]-work[k];
  104470. }
  104471. }
  104472. return(ret);
  104473. }else{
  104474. return(0);
  104475. }
  104476. }
  104477. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104478. float **in,int *nonzero,int ch){
  104479. long i,k,l,s;
  104480. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104481. vorbis_info_residue0 *info=look->info;
  104482. int samples_per_partition=info->grouping;
  104483. int partitions_per_word=look->phrasebook->dim;
  104484. int n=info->end-info->begin;
  104485. int partvals=n/samples_per_partition;
  104486. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104487. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104488. for(i=0;i<ch;i++)if(nonzero[i])break;
  104489. if(i==ch)return(0); /* no nonzero vectors */
  104490. for(s=0;s<look->stages;s++){
  104491. for(i=0,l=0;i<partvals;l++){
  104492. if(s==0){
  104493. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104494. if(temp==-1)goto eopbreak;
  104495. partword[l]=look->decodemap[temp];
  104496. if(partword[l]==NULL)goto errout;
  104497. }
  104498. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104499. if(info->secondstages[partword[l][k]]&(1<<s)){
  104500. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104501. if(stagebook){
  104502. if(vorbis_book_decodevv_add(stagebook,in,
  104503. i*samples_per_partition+info->begin,ch,
  104504. &vb->opb,samples_per_partition)==-1)
  104505. goto eopbreak;
  104506. }
  104507. }
  104508. }
  104509. }
  104510. errout:
  104511. eopbreak:
  104512. return(0);
  104513. }
  104514. vorbis_func_residue residue0_exportbundle={
  104515. NULL,
  104516. &res0_unpack,
  104517. &res0_look,
  104518. &res0_free_info,
  104519. &res0_free_look,
  104520. NULL,
  104521. NULL,
  104522. &res0_inverse
  104523. };
  104524. vorbis_func_residue residue1_exportbundle={
  104525. &res0_pack,
  104526. &res0_unpack,
  104527. &res0_look,
  104528. &res0_free_info,
  104529. &res0_free_look,
  104530. &res1_class,
  104531. &res1_forward,
  104532. &res1_inverse
  104533. };
  104534. vorbis_func_residue residue2_exportbundle={
  104535. &res0_pack,
  104536. &res0_unpack,
  104537. &res0_look,
  104538. &res0_free_info,
  104539. &res0_free_look,
  104540. &res2_class,
  104541. &res2_forward,
  104542. &res2_inverse
  104543. };
  104544. #endif
  104545. /*** End of inlined file: res0.c ***/
  104546. /*** Start of inlined file: sharedbook.c ***/
  104547. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104548. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104549. // tasks..
  104550. #if JUCE_MSVC
  104551. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104552. #endif
  104553. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104554. #if JUCE_USE_OGGVORBIS
  104555. #include <stdlib.h>
  104556. #include <math.h>
  104557. #include <string.h>
  104558. int _ilog(unsigned int v){
  104559. int ret=0;
  104560. while(v){
  104561. ret++;
  104562. v>>=1;
  104563. }
  104564. return(ret);
  104565. }
  104566. #define VQ_FEXP 10
  104567. #define VQ_FMAN 21
  104568. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104569. long _float32_pack(float val){
  104570. int sign=0;
  104571. long exp;
  104572. long mant;
  104573. if(val<0){
  104574. sign=0x80000000;
  104575. val= -val;
  104576. }
  104577. exp= floor(log(val)/log(2.f));
  104578. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104579. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104580. return(sign|exp|mant);
  104581. }
  104582. float _float32_unpack(long val){
  104583. double mant=val&0x1fffff;
  104584. int sign=val&0x80000000;
  104585. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104586. if(sign)mant= -mant;
  104587. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104588. }
  104589. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104590. long i,j,count=0;
  104591. ogg_uint32_t marker[33];
  104592. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104593. memset(marker,0,sizeof(marker));
  104594. for(i=0;i<n;i++){
  104595. long length=l[i];
  104596. if(length>0){
  104597. ogg_uint32_t entry=marker[length];
  104598. if(length<32 && (entry>>length)){
  104599. _ogg_free(r);
  104600. return(NULL);
  104601. }
  104602. r[count++]=entry;
  104603. {
  104604. for(j=length;j>0;j--){
  104605. if(marker[j]&1){
  104606. if(j==1)
  104607. marker[1]++;
  104608. else
  104609. marker[j]=marker[j-1]<<1;
  104610. break; /* invariant says next upper marker would already
  104611. have been moved if it was on the same path */
  104612. }
  104613. marker[j]++;
  104614. }
  104615. }
  104616. for(j=length+1;j<33;j++)
  104617. if((marker[j]>>1) == entry){
  104618. entry=marker[j];
  104619. marker[j]=marker[j-1]<<1;
  104620. }else
  104621. break;
  104622. }else
  104623. if(sparsecount==0)count++;
  104624. }
  104625. for(i=0,count=0;i<n;i++){
  104626. ogg_uint32_t temp=0;
  104627. for(j=0;j<l[i];j++){
  104628. temp<<=1;
  104629. temp|=(r[count]>>j)&1;
  104630. }
  104631. if(sparsecount){
  104632. if(l[i])
  104633. r[count++]=temp;
  104634. }else
  104635. r[count++]=temp;
  104636. }
  104637. return(r);
  104638. }
  104639. long _book_maptype1_quantvals(const static_codebook *b){
  104640. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104641. while(1){
  104642. long acc=1;
  104643. long acc1=1;
  104644. int i;
  104645. for(i=0;i<b->dim;i++){
  104646. acc*=vals;
  104647. acc1*=vals+1;
  104648. }
  104649. if(acc<=b->entries && acc1>b->entries){
  104650. return(vals);
  104651. }else{
  104652. if(acc>b->entries){
  104653. vals--;
  104654. }else{
  104655. vals++;
  104656. }
  104657. }
  104658. }
  104659. }
  104660. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104661. long j,k,count=0;
  104662. if(b->maptype==1 || b->maptype==2){
  104663. int quantvals;
  104664. float mindel=_float32_unpack(b->q_min);
  104665. float delta=_float32_unpack(b->q_delta);
  104666. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104667. switch(b->maptype){
  104668. case 1:
  104669. quantvals=_book_maptype1_quantvals(b);
  104670. for(j=0;j<b->entries;j++){
  104671. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104672. float last=0.f;
  104673. int indexdiv=1;
  104674. for(k=0;k<b->dim;k++){
  104675. int index= (j/indexdiv)%quantvals;
  104676. float val=b->quantlist[index];
  104677. val=fabs(val)*delta+mindel+last;
  104678. if(b->q_sequencep)last=val;
  104679. if(sparsemap)
  104680. r[sparsemap[count]*b->dim+k]=val;
  104681. else
  104682. r[count*b->dim+k]=val;
  104683. indexdiv*=quantvals;
  104684. }
  104685. count++;
  104686. }
  104687. }
  104688. break;
  104689. case 2:
  104690. for(j=0;j<b->entries;j++){
  104691. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104692. float last=0.f;
  104693. for(k=0;k<b->dim;k++){
  104694. float val=b->quantlist[j*b->dim+k];
  104695. val=fabs(val)*delta+mindel+last;
  104696. if(b->q_sequencep)last=val;
  104697. if(sparsemap)
  104698. r[sparsemap[count]*b->dim+k]=val;
  104699. else
  104700. r[count*b->dim+k]=val;
  104701. }
  104702. count++;
  104703. }
  104704. }
  104705. break;
  104706. }
  104707. return(r);
  104708. }
  104709. return(NULL);
  104710. }
  104711. void vorbis_staticbook_clear(static_codebook *b){
  104712. if(b->allocedp){
  104713. if(b->quantlist)_ogg_free(b->quantlist);
  104714. if(b->lengthlist)_ogg_free(b->lengthlist);
  104715. if(b->nearest_tree){
  104716. _ogg_free(b->nearest_tree->ptr0);
  104717. _ogg_free(b->nearest_tree->ptr1);
  104718. _ogg_free(b->nearest_tree->p);
  104719. _ogg_free(b->nearest_tree->q);
  104720. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104721. _ogg_free(b->nearest_tree);
  104722. }
  104723. if(b->thresh_tree){
  104724. _ogg_free(b->thresh_tree->quantthresh);
  104725. _ogg_free(b->thresh_tree->quantmap);
  104726. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104727. _ogg_free(b->thresh_tree);
  104728. }
  104729. memset(b,0,sizeof(*b));
  104730. }
  104731. }
  104732. void vorbis_staticbook_destroy(static_codebook *b){
  104733. if(b->allocedp){
  104734. vorbis_staticbook_clear(b);
  104735. _ogg_free(b);
  104736. }
  104737. }
  104738. void vorbis_book_clear(codebook *b){
  104739. if(b->valuelist)_ogg_free(b->valuelist);
  104740. if(b->codelist)_ogg_free(b->codelist);
  104741. if(b->dec_index)_ogg_free(b->dec_index);
  104742. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104743. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104744. memset(b,0,sizeof(*b));
  104745. }
  104746. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104747. memset(c,0,sizeof(*c));
  104748. c->c=s;
  104749. c->entries=s->entries;
  104750. c->used_entries=s->entries;
  104751. c->dim=s->dim;
  104752. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104753. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104754. return(0);
  104755. }
  104756. static int sort32a(const void *a,const void *b){
  104757. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104758. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104759. }
  104760. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104761. int i,j,n=0,tabn;
  104762. int *sortindex;
  104763. memset(c,0,sizeof(*c));
  104764. for(i=0;i<s->entries;i++)
  104765. if(s->lengthlist[i]>0)
  104766. n++;
  104767. c->entries=s->entries;
  104768. c->used_entries=n;
  104769. c->dim=s->dim;
  104770. {
  104771. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104772. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104773. if(codes==NULL)goto err_out;
  104774. for(i=0;i<n;i++){
  104775. codes[i]=ogg_bitreverse(codes[i]);
  104776. codep[i]=codes+i;
  104777. }
  104778. qsort(codep,n,sizeof(*codep),sort32a);
  104779. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104780. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104781. for(i=0;i<n;i++){
  104782. int position=codep[i]-codes;
  104783. sortindex[position]=i;
  104784. }
  104785. for(i=0;i<n;i++)
  104786. c->codelist[sortindex[i]]=codes[i];
  104787. _ogg_free(codes);
  104788. }
  104789. c->valuelist=_book_unquantize(s,n,sortindex);
  104790. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104791. for(n=0,i=0;i<s->entries;i++)
  104792. if(s->lengthlist[i]>0)
  104793. c->dec_index[sortindex[n++]]=i;
  104794. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104795. for(n=0,i=0;i<s->entries;i++)
  104796. if(s->lengthlist[i]>0)
  104797. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104798. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104799. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104800. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104801. tabn=1<<c->dec_firsttablen;
  104802. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104803. c->dec_maxlength=0;
  104804. for(i=0;i<n;i++){
  104805. if(c->dec_maxlength<c->dec_codelengths[i])
  104806. c->dec_maxlength=c->dec_codelengths[i];
  104807. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104808. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104809. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104810. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104811. }
  104812. }
  104813. {
  104814. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104815. long lo=0,hi=0;
  104816. for(i=0;i<tabn;i++){
  104817. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104818. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104819. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104820. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104821. {
  104822. unsigned long loval=lo;
  104823. unsigned long hival=n-hi;
  104824. if(loval>0x7fff)loval=0x7fff;
  104825. if(hival>0x7fff)hival=0x7fff;
  104826. c->dec_firsttable[ogg_bitreverse(word)]=
  104827. 0x80000000UL | (loval<<15) | hival;
  104828. }
  104829. }
  104830. }
  104831. }
  104832. return(0);
  104833. err_out:
  104834. vorbis_book_clear(c);
  104835. return(-1);
  104836. }
  104837. static float _dist(int el,float *ref, float *b,int step){
  104838. int i;
  104839. float acc=0.f;
  104840. for(i=0;i<el;i++){
  104841. float val=(ref[i]-b[i*step]);
  104842. acc+=val*val;
  104843. }
  104844. return(acc);
  104845. }
  104846. int _best(codebook *book, float *a, int step){
  104847. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104848. #if 0
  104849. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104850. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104851. #endif
  104852. int dim=book->dim;
  104853. int k,o;
  104854. if(tt){
  104855. int index=0,i;
  104856. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104857. i=tt->threshvals>>1;
  104858. if(a[o]<tt->quantthresh[i]){
  104859. for(;i>0;i--)
  104860. if(a[o]>=tt->quantthresh[i-1])
  104861. break;
  104862. }else{
  104863. for(i++;i<tt->threshvals-1;i++)
  104864. if(a[o]<tt->quantthresh[i])break;
  104865. }
  104866. index=(index*tt->quantvals)+tt->quantmap[i];
  104867. }
  104868. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104869. use a decision tree after all
  104870. and fall through*/
  104871. return(index);
  104872. }
  104873. #if 0
  104874. if(pt){
  104875. const static_codebook *c=book->c;
  104876. int i,besti=-1;
  104877. float best=0.f;
  104878. int entry=0;
  104879. if(c->q_sequencep){
  104880. int pv;
  104881. long mul=1;
  104882. float qlast=0;
  104883. for(k=0,o=0;k<dim;k++,o+=step){
  104884. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104885. if(pv<0 || pv>=pt->mapentries)break;
  104886. entry+=pt->pigeonmap[pv]*mul;
  104887. mul*=pt->quantvals;
  104888. qlast+=pv*pt->del+pt->min;
  104889. }
  104890. }else{
  104891. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104892. int pv=(int)((a[o]-pt->min)/pt->del);
  104893. if(pv<0 || pv>=pt->mapentries)break;
  104894. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104895. }
  104896. }
  104897. if(k==dim && pt->fitlength[entry]){
  104898. long *list=pt->fitlist+pt->fitmap[entry];
  104899. for(i=0;i<pt->fitlength[entry];i++){
  104900. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104901. if(besti==-1 || this<best){
  104902. best=this;
  104903. besti=list[i];
  104904. }
  104905. }
  104906. return(besti);
  104907. }
  104908. }
  104909. if(nt){
  104910. while(1){
  104911. float c=0.f;
  104912. float *p=book->valuelist+nt->p[ptr];
  104913. float *q=book->valuelist+nt->q[ptr];
  104914. for(k=0,o=0;k<dim;k++,o+=step)
  104915. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104916. if(c>0.f) /* in A */
  104917. ptr= -nt->ptr0[ptr];
  104918. else /* in B */
  104919. ptr= -nt->ptr1[ptr];
  104920. if(ptr<=0)break;
  104921. }
  104922. return(-ptr);
  104923. }
  104924. #endif
  104925. {
  104926. const static_codebook *c=book->c;
  104927. int i,besti=-1;
  104928. float best=0.f;
  104929. float *e=book->valuelist;
  104930. for(i=0;i<book->entries;i++){
  104931. if(c->lengthlist[i]>0){
  104932. float thisx=_dist(dim,e,a,step);
  104933. if(besti==-1 || thisx<best){
  104934. best=thisx;
  104935. besti=i;
  104936. }
  104937. }
  104938. e+=dim;
  104939. }
  104940. return(besti);
  104941. }
  104942. }
  104943. long vorbis_book_codeword(codebook *book,int entry){
  104944. if(book->c) /* only use with encode; decode optimizations are
  104945. allowed to break this */
  104946. return book->codelist[entry];
  104947. return -1;
  104948. }
  104949. long vorbis_book_codelen(codebook *book,int entry){
  104950. if(book->c) /* only use with encode; decode optimizations are
  104951. allowed to break this */
  104952. return book->c->lengthlist[entry];
  104953. return -1;
  104954. }
  104955. #ifdef _V_SELFTEST
  104956. #include <stdio.h>
  104957. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  104958. static long partial_quantlist1[]={0,7,2};
  104959. static_codebook test1={
  104960. 4,16,
  104961. NULL,
  104962. 0,
  104963. 0,0,0,0,
  104964. NULL,
  104965. NULL,NULL
  104966. };
  104967. static float *test1_result=NULL;
  104968. static_codebook test2={
  104969. 4,3,
  104970. NULL,
  104971. 2,
  104972. -533200896,1611661312,4,0,
  104973. full_quantlist1,
  104974. NULL,NULL
  104975. };
  104976. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  104977. static_codebook test3={
  104978. 4,3,
  104979. NULL,
  104980. 2,
  104981. -533200896,1611661312,4,1,
  104982. full_quantlist1,
  104983. NULL,NULL
  104984. };
  104985. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  104986. static_codebook test4={
  104987. 3,27,
  104988. NULL,
  104989. 1,
  104990. -533200896,1611661312,4,0,
  104991. partial_quantlist1,
  104992. NULL,NULL
  104993. };
  104994. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  104995. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  104996. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  104997. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  104998. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  104999. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105000. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105001. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105002. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105003. static_codebook test5={
  105004. 3,27,
  105005. NULL,
  105006. 1,
  105007. -533200896,1611661312,4,1,
  105008. partial_quantlist1,
  105009. NULL,NULL
  105010. };
  105011. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105012. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105013. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105014. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105015. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105016. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105017. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105018. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105019. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105020. void run_test(static_codebook *b,float *comp){
  105021. float *out=_book_unquantize(b,b->entries,NULL);
  105022. int i;
  105023. if(comp){
  105024. if(!out){
  105025. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105026. exit(1);
  105027. }
  105028. for(i=0;i<b->entries*b->dim;i++)
  105029. if(fabs(out[i]-comp[i])>.0001){
  105030. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105031. "position %d, %g != %g\n",i,out[i],comp[i]);
  105032. exit(1);
  105033. }
  105034. }else{
  105035. if(out){
  105036. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105037. " correct result should have been NULL\n");
  105038. exit(1);
  105039. }
  105040. }
  105041. }
  105042. int main(){
  105043. fprintf(stderr,"Dequant test 1... ");
  105044. run_test(&test1,test1_result);
  105045. fprintf(stderr,"OK\nDequant test 2... ");
  105046. run_test(&test2,test2_result);
  105047. fprintf(stderr,"OK\nDequant test 3... ");
  105048. run_test(&test3,test3_result);
  105049. fprintf(stderr,"OK\nDequant test 4... ");
  105050. run_test(&test4,test4_result);
  105051. fprintf(stderr,"OK\nDequant test 5... ");
  105052. run_test(&test5,test5_result);
  105053. fprintf(stderr,"OK\n\n");
  105054. return(0);
  105055. }
  105056. #endif
  105057. #endif
  105058. /*** End of inlined file: sharedbook.c ***/
  105059. /*** Start of inlined file: smallft.c ***/
  105060. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105061. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105062. // tasks..
  105063. #if JUCE_MSVC
  105064. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105065. #endif
  105066. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105067. #if JUCE_USE_OGGVORBIS
  105068. #include <stdlib.h>
  105069. #include <string.h>
  105070. #include <math.h>
  105071. static void drfti1(int n, float *wa, int *ifac){
  105072. static int ntryh[4] = { 4,2,3,5 };
  105073. static float tpi = 6.28318530717958648f;
  105074. float arg,argh,argld,fi;
  105075. int ntry=0,i,j=-1;
  105076. int k1, l1, l2, ib;
  105077. int ld, ii, ip, is, nq, nr;
  105078. int ido, ipm, nfm1;
  105079. int nl=n;
  105080. int nf=0;
  105081. L101:
  105082. j++;
  105083. if (j < 4)
  105084. ntry=ntryh[j];
  105085. else
  105086. ntry+=2;
  105087. L104:
  105088. nq=nl/ntry;
  105089. nr=nl-ntry*nq;
  105090. if (nr!=0) goto L101;
  105091. nf++;
  105092. ifac[nf+1]=ntry;
  105093. nl=nq;
  105094. if(ntry!=2)goto L107;
  105095. if(nf==1)goto L107;
  105096. for (i=1;i<nf;i++){
  105097. ib=nf-i+1;
  105098. ifac[ib+1]=ifac[ib];
  105099. }
  105100. ifac[2] = 2;
  105101. L107:
  105102. if(nl!=1)goto L104;
  105103. ifac[0]=n;
  105104. ifac[1]=nf;
  105105. argh=tpi/n;
  105106. is=0;
  105107. nfm1=nf-1;
  105108. l1=1;
  105109. if(nfm1==0)return;
  105110. for (k1=0;k1<nfm1;k1++){
  105111. ip=ifac[k1+2];
  105112. ld=0;
  105113. l2=l1*ip;
  105114. ido=n/l2;
  105115. ipm=ip-1;
  105116. for (j=0;j<ipm;j++){
  105117. ld+=l1;
  105118. i=is;
  105119. argld=(float)ld*argh;
  105120. fi=0.f;
  105121. for (ii=2;ii<ido;ii+=2){
  105122. fi+=1.f;
  105123. arg=fi*argld;
  105124. wa[i++]=cos(arg);
  105125. wa[i++]=sin(arg);
  105126. }
  105127. is+=ido;
  105128. }
  105129. l1=l2;
  105130. }
  105131. }
  105132. static void fdrffti(int n, float *wsave, int *ifac){
  105133. if (n == 1) return;
  105134. drfti1(n, wsave+n, ifac);
  105135. }
  105136. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105137. int i,k;
  105138. float ti2,tr2;
  105139. int t0,t1,t2,t3,t4,t5,t6;
  105140. t1=0;
  105141. t0=(t2=l1*ido);
  105142. t3=ido<<1;
  105143. for(k=0;k<l1;k++){
  105144. ch[t1<<1]=cc[t1]+cc[t2];
  105145. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105146. t1+=ido;
  105147. t2+=ido;
  105148. }
  105149. if(ido<2)return;
  105150. if(ido==2)goto L105;
  105151. t1=0;
  105152. t2=t0;
  105153. for(k=0;k<l1;k++){
  105154. t3=t2;
  105155. t4=(t1<<1)+(ido<<1);
  105156. t5=t1;
  105157. t6=t1+t1;
  105158. for(i=2;i<ido;i+=2){
  105159. t3+=2;
  105160. t4-=2;
  105161. t5+=2;
  105162. t6+=2;
  105163. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105164. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105165. ch[t6]=cc[t5]+ti2;
  105166. ch[t4]=ti2-cc[t5];
  105167. ch[t6-1]=cc[t5-1]+tr2;
  105168. ch[t4-1]=cc[t5-1]-tr2;
  105169. }
  105170. t1+=ido;
  105171. t2+=ido;
  105172. }
  105173. if(ido%2==1)return;
  105174. L105:
  105175. t3=(t2=(t1=ido)-1);
  105176. t2+=t0;
  105177. for(k=0;k<l1;k++){
  105178. ch[t1]=-cc[t2];
  105179. ch[t1-1]=cc[t3];
  105180. t1+=ido<<1;
  105181. t2+=ido;
  105182. t3+=ido;
  105183. }
  105184. }
  105185. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105186. float *wa2,float *wa3){
  105187. static float hsqt2 = .70710678118654752f;
  105188. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105189. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105190. t0=l1*ido;
  105191. t1=t0;
  105192. t4=t1<<1;
  105193. t2=t1+(t1<<1);
  105194. t3=0;
  105195. for(k=0;k<l1;k++){
  105196. tr1=cc[t1]+cc[t2];
  105197. tr2=cc[t3]+cc[t4];
  105198. ch[t5=t3<<2]=tr1+tr2;
  105199. ch[(ido<<2)+t5-1]=tr2-tr1;
  105200. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105201. ch[t5]=cc[t2]-cc[t1];
  105202. t1+=ido;
  105203. t2+=ido;
  105204. t3+=ido;
  105205. t4+=ido;
  105206. }
  105207. if(ido<2)return;
  105208. if(ido==2)goto L105;
  105209. t1=0;
  105210. for(k=0;k<l1;k++){
  105211. t2=t1;
  105212. t4=t1<<2;
  105213. t5=(t6=ido<<1)+t4;
  105214. for(i=2;i<ido;i+=2){
  105215. t3=(t2+=2);
  105216. t4+=2;
  105217. t5-=2;
  105218. t3+=t0;
  105219. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105220. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105221. t3+=t0;
  105222. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105223. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105224. t3+=t0;
  105225. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105226. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105227. tr1=cr2+cr4;
  105228. tr4=cr4-cr2;
  105229. ti1=ci2+ci4;
  105230. ti4=ci2-ci4;
  105231. ti2=cc[t2]+ci3;
  105232. ti3=cc[t2]-ci3;
  105233. tr2=cc[t2-1]+cr3;
  105234. tr3=cc[t2-1]-cr3;
  105235. ch[t4-1]=tr1+tr2;
  105236. ch[t4]=ti1+ti2;
  105237. ch[t5-1]=tr3-ti4;
  105238. ch[t5]=tr4-ti3;
  105239. ch[t4+t6-1]=ti4+tr3;
  105240. ch[t4+t6]=tr4+ti3;
  105241. ch[t5+t6-1]=tr2-tr1;
  105242. ch[t5+t6]=ti1-ti2;
  105243. }
  105244. t1+=ido;
  105245. }
  105246. if(ido&1)return;
  105247. L105:
  105248. t2=(t1=t0+ido-1)+(t0<<1);
  105249. t3=ido<<2;
  105250. t4=ido;
  105251. t5=ido<<1;
  105252. t6=ido;
  105253. for(k=0;k<l1;k++){
  105254. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105255. tr1=hsqt2*(cc[t1]-cc[t2]);
  105256. ch[t4-1]=tr1+cc[t6-1];
  105257. ch[t4+t5-1]=cc[t6-1]-tr1;
  105258. ch[t4]=ti1-cc[t1+t0];
  105259. ch[t4+t5]=ti1+cc[t1+t0];
  105260. t1+=ido;
  105261. t2+=ido;
  105262. t4+=t3;
  105263. t6+=ido;
  105264. }
  105265. }
  105266. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105267. float *c2,float *ch,float *ch2,float *wa){
  105268. static float tpi=6.283185307179586f;
  105269. int idij,ipph,i,j,k,l,ic,ik,is;
  105270. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105271. float dc2,ai1,ai2,ar1,ar2,ds2;
  105272. int nbd;
  105273. float dcp,arg,dsp,ar1h,ar2h;
  105274. int idp2,ipp2;
  105275. arg=tpi/(float)ip;
  105276. dcp=cos(arg);
  105277. dsp=sin(arg);
  105278. ipph=(ip+1)>>1;
  105279. ipp2=ip;
  105280. idp2=ido;
  105281. nbd=(ido-1)>>1;
  105282. t0=l1*ido;
  105283. t10=ip*ido;
  105284. if(ido==1)goto L119;
  105285. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105286. t1=0;
  105287. for(j=1;j<ip;j++){
  105288. t1+=t0;
  105289. t2=t1;
  105290. for(k=0;k<l1;k++){
  105291. ch[t2]=c1[t2];
  105292. t2+=ido;
  105293. }
  105294. }
  105295. is=-ido;
  105296. t1=0;
  105297. if(nbd>l1){
  105298. for(j=1;j<ip;j++){
  105299. t1+=t0;
  105300. is+=ido;
  105301. t2= -ido+t1;
  105302. for(k=0;k<l1;k++){
  105303. idij=is-1;
  105304. t2+=ido;
  105305. t3=t2;
  105306. for(i=2;i<ido;i+=2){
  105307. idij+=2;
  105308. t3+=2;
  105309. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105310. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105311. }
  105312. }
  105313. }
  105314. }else{
  105315. for(j=1;j<ip;j++){
  105316. is+=ido;
  105317. idij=is-1;
  105318. t1+=t0;
  105319. t2=t1;
  105320. for(i=2;i<ido;i+=2){
  105321. idij+=2;
  105322. t2+=2;
  105323. t3=t2;
  105324. for(k=0;k<l1;k++){
  105325. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105326. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105327. t3+=ido;
  105328. }
  105329. }
  105330. }
  105331. }
  105332. t1=0;
  105333. t2=ipp2*t0;
  105334. if(nbd<l1){
  105335. for(j=1;j<ipph;j++){
  105336. t1+=t0;
  105337. t2-=t0;
  105338. t3=t1;
  105339. t4=t2;
  105340. for(i=2;i<ido;i+=2){
  105341. t3+=2;
  105342. t4+=2;
  105343. t5=t3-ido;
  105344. t6=t4-ido;
  105345. for(k=0;k<l1;k++){
  105346. t5+=ido;
  105347. t6+=ido;
  105348. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105349. c1[t6-1]=ch[t5]-ch[t6];
  105350. c1[t5]=ch[t5]+ch[t6];
  105351. c1[t6]=ch[t6-1]-ch[t5-1];
  105352. }
  105353. }
  105354. }
  105355. }else{
  105356. for(j=1;j<ipph;j++){
  105357. t1+=t0;
  105358. t2-=t0;
  105359. t3=t1;
  105360. t4=t2;
  105361. for(k=0;k<l1;k++){
  105362. t5=t3;
  105363. t6=t4;
  105364. for(i=2;i<ido;i+=2){
  105365. t5+=2;
  105366. t6+=2;
  105367. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105368. c1[t6-1]=ch[t5]-ch[t6];
  105369. c1[t5]=ch[t5]+ch[t6];
  105370. c1[t6]=ch[t6-1]-ch[t5-1];
  105371. }
  105372. t3+=ido;
  105373. t4+=ido;
  105374. }
  105375. }
  105376. }
  105377. L119:
  105378. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105379. t1=0;
  105380. t2=ipp2*idl1;
  105381. for(j=1;j<ipph;j++){
  105382. t1+=t0;
  105383. t2-=t0;
  105384. t3=t1-ido;
  105385. t4=t2-ido;
  105386. for(k=0;k<l1;k++){
  105387. t3+=ido;
  105388. t4+=ido;
  105389. c1[t3]=ch[t3]+ch[t4];
  105390. c1[t4]=ch[t4]-ch[t3];
  105391. }
  105392. }
  105393. ar1=1.f;
  105394. ai1=0.f;
  105395. t1=0;
  105396. t2=ipp2*idl1;
  105397. t3=(ip-1)*idl1;
  105398. for(l=1;l<ipph;l++){
  105399. t1+=idl1;
  105400. t2-=idl1;
  105401. ar1h=dcp*ar1-dsp*ai1;
  105402. ai1=dcp*ai1+dsp*ar1;
  105403. ar1=ar1h;
  105404. t4=t1;
  105405. t5=t2;
  105406. t6=t3;
  105407. t7=idl1;
  105408. for(ik=0;ik<idl1;ik++){
  105409. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105410. ch2[t5++]=ai1*c2[t6++];
  105411. }
  105412. dc2=ar1;
  105413. ds2=ai1;
  105414. ar2=ar1;
  105415. ai2=ai1;
  105416. t4=idl1;
  105417. t5=(ipp2-1)*idl1;
  105418. for(j=2;j<ipph;j++){
  105419. t4+=idl1;
  105420. t5-=idl1;
  105421. ar2h=dc2*ar2-ds2*ai2;
  105422. ai2=dc2*ai2+ds2*ar2;
  105423. ar2=ar2h;
  105424. t6=t1;
  105425. t7=t2;
  105426. t8=t4;
  105427. t9=t5;
  105428. for(ik=0;ik<idl1;ik++){
  105429. ch2[t6++]+=ar2*c2[t8++];
  105430. ch2[t7++]+=ai2*c2[t9++];
  105431. }
  105432. }
  105433. }
  105434. t1=0;
  105435. for(j=1;j<ipph;j++){
  105436. t1+=idl1;
  105437. t2=t1;
  105438. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105439. }
  105440. if(ido<l1)goto L132;
  105441. t1=0;
  105442. t2=0;
  105443. for(k=0;k<l1;k++){
  105444. t3=t1;
  105445. t4=t2;
  105446. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105447. t1+=ido;
  105448. t2+=t10;
  105449. }
  105450. goto L135;
  105451. L132:
  105452. for(i=0;i<ido;i++){
  105453. t1=i;
  105454. t2=i;
  105455. for(k=0;k<l1;k++){
  105456. cc[t2]=ch[t1];
  105457. t1+=ido;
  105458. t2+=t10;
  105459. }
  105460. }
  105461. L135:
  105462. t1=0;
  105463. t2=ido<<1;
  105464. t3=0;
  105465. t4=ipp2*t0;
  105466. for(j=1;j<ipph;j++){
  105467. t1+=t2;
  105468. t3+=t0;
  105469. t4-=t0;
  105470. t5=t1;
  105471. t6=t3;
  105472. t7=t4;
  105473. for(k=0;k<l1;k++){
  105474. cc[t5-1]=ch[t6];
  105475. cc[t5]=ch[t7];
  105476. t5+=t10;
  105477. t6+=ido;
  105478. t7+=ido;
  105479. }
  105480. }
  105481. if(ido==1)return;
  105482. if(nbd<l1)goto L141;
  105483. t1=-ido;
  105484. t3=0;
  105485. t4=0;
  105486. t5=ipp2*t0;
  105487. for(j=1;j<ipph;j++){
  105488. t1+=t2;
  105489. t3+=t2;
  105490. t4+=t0;
  105491. t5-=t0;
  105492. t6=t1;
  105493. t7=t3;
  105494. t8=t4;
  105495. t9=t5;
  105496. for(k=0;k<l1;k++){
  105497. for(i=2;i<ido;i+=2){
  105498. ic=idp2-i;
  105499. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105500. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105501. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105502. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105503. }
  105504. t6+=t10;
  105505. t7+=t10;
  105506. t8+=ido;
  105507. t9+=ido;
  105508. }
  105509. }
  105510. return;
  105511. L141:
  105512. t1=-ido;
  105513. t3=0;
  105514. t4=0;
  105515. t5=ipp2*t0;
  105516. for(j=1;j<ipph;j++){
  105517. t1+=t2;
  105518. t3+=t2;
  105519. t4+=t0;
  105520. t5-=t0;
  105521. for(i=2;i<ido;i+=2){
  105522. t6=idp2+t1-i;
  105523. t7=i+t3;
  105524. t8=i+t4;
  105525. t9=i+t5;
  105526. for(k=0;k<l1;k++){
  105527. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105528. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105529. cc[t7]=ch[t8]+ch[t9];
  105530. cc[t6]=ch[t9]-ch[t8];
  105531. t6+=t10;
  105532. t7+=t10;
  105533. t8+=ido;
  105534. t9+=ido;
  105535. }
  105536. }
  105537. }
  105538. }
  105539. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105540. int i,k1,l1,l2;
  105541. int na,kh,nf;
  105542. int ip,iw,ido,idl1,ix2,ix3;
  105543. nf=ifac[1];
  105544. na=1;
  105545. l2=n;
  105546. iw=n;
  105547. for(k1=0;k1<nf;k1++){
  105548. kh=nf-k1;
  105549. ip=ifac[kh+1];
  105550. l1=l2/ip;
  105551. ido=n/l2;
  105552. idl1=ido*l1;
  105553. iw-=(ip-1)*ido;
  105554. na=1-na;
  105555. if(ip!=4)goto L102;
  105556. ix2=iw+ido;
  105557. ix3=ix2+ido;
  105558. if(na!=0)
  105559. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105560. else
  105561. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105562. goto L110;
  105563. L102:
  105564. if(ip!=2)goto L104;
  105565. if(na!=0)goto L103;
  105566. dradf2(ido,l1,c,ch,wa+iw-1);
  105567. goto L110;
  105568. L103:
  105569. dradf2(ido,l1,ch,c,wa+iw-1);
  105570. goto L110;
  105571. L104:
  105572. if(ido==1)na=1-na;
  105573. if(na!=0)goto L109;
  105574. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105575. na=1;
  105576. goto L110;
  105577. L109:
  105578. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105579. na=0;
  105580. L110:
  105581. l2=l1;
  105582. }
  105583. if(na==1)return;
  105584. for(i=0;i<n;i++)c[i]=ch[i];
  105585. }
  105586. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105587. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105588. float ti2,tr2;
  105589. t0=l1*ido;
  105590. t1=0;
  105591. t2=0;
  105592. t3=(ido<<1)-1;
  105593. for(k=0;k<l1;k++){
  105594. ch[t1]=cc[t2]+cc[t3+t2];
  105595. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105596. t2=(t1+=ido)<<1;
  105597. }
  105598. if(ido<2)return;
  105599. if(ido==2)goto L105;
  105600. t1=0;
  105601. t2=0;
  105602. for(k=0;k<l1;k++){
  105603. t3=t1;
  105604. t5=(t4=t2)+(ido<<1);
  105605. t6=t0+t1;
  105606. for(i=2;i<ido;i+=2){
  105607. t3+=2;
  105608. t4+=2;
  105609. t5-=2;
  105610. t6+=2;
  105611. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105612. tr2=cc[t4-1]-cc[t5-1];
  105613. ch[t3]=cc[t4]-cc[t5];
  105614. ti2=cc[t4]+cc[t5];
  105615. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105616. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105617. }
  105618. t2=(t1+=ido)<<1;
  105619. }
  105620. if(ido%2==1)return;
  105621. L105:
  105622. t1=ido-1;
  105623. t2=ido-1;
  105624. for(k=0;k<l1;k++){
  105625. ch[t1]=cc[t2]+cc[t2];
  105626. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105627. t1+=ido;
  105628. t2+=ido<<1;
  105629. }
  105630. }
  105631. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105632. float *wa2){
  105633. static float taur = -.5f;
  105634. static float taui = .8660254037844386f;
  105635. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105636. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105637. t0=l1*ido;
  105638. t1=0;
  105639. t2=t0<<1;
  105640. t3=ido<<1;
  105641. t4=ido+(ido<<1);
  105642. t5=0;
  105643. for(k=0;k<l1;k++){
  105644. tr2=cc[t3-1]+cc[t3-1];
  105645. cr2=cc[t5]+(taur*tr2);
  105646. ch[t1]=cc[t5]+tr2;
  105647. ci3=taui*(cc[t3]+cc[t3]);
  105648. ch[t1+t0]=cr2-ci3;
  105649. ch[t1+t2]=cr2+ci3;
  105650. t1+=ido;
  105651. t3+=t4;
  105652. t5+=t4;
  105653. }
  105654. if(ido==1)return;
  105655. t1=0;
  105656. t3=ido<<1;
  105657. for(k=0;k<l1;k++){
  105658. t7=t1+(t1<<1);
  105659. t6=(t5=t7+t3);
  105660. t8=t1;
  105661. t10=(t9=t1+t0)+t0;
  105662. for(i=2;i<ido;i+=2){
  105663. t5+=2;
  105664. t6-=2;
  105665. t7+=2;
  105666. t8+=2;
  105667. t9+=2;
  105668. t10+=2;
  105669. tr2=cc[t5-1]+cc[t6-1];
  105670. cr2=cc[t7-1]+(taur*tr2);
  105671. ch[t8-1]=cc[t7-1]+tr2;
  105672. ti2=cc[t5]-cc[t6];
  105673. ci2=cc[t7]+(taur*ti2);
  105674. ch[t8]=cc[t7]+ti2;
  105675. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105676. ci3=taui*(cc[t5]+cc[t6]);
  105677. dr2=cr2-ci3;
  105678. dr3=cr2+ci3;
  105679. di2=ci2+cr3;
  105680. di3=ci2-cr3;
  105681. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105682. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105683. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105684. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105685. }
  105686. t1+=ido;
  105687. }
  105688. }
  105689. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105690. float *wa2,float *wa3){
  105691. static float sqrt2=1.414213562373095f;
  105692. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105693. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105694. t0=l1*ido;
  105695. t1=0;
  105696. t2=ido<<2;
  105697. t3=0;
  105698. t6=ido<<1;
  105699. for(k=0;k<l1;k++){
  105700. t4=t3+t6;
  105701. t5=t1;
  105702. tr3=cc[t4-1]+cc[t4-1];
  105703. tr4=cc[t4]+cc[t4];
  105704. tr1=cc[t3]-cc[(t4+=t6)-1];
  105705. tr2=cc[t3]+cc[t4-1];
  105706. ch[t5]=tr2+tr3;
  105707. ch[t5+=t0]=tr1-tr4;
  105708. ch[t5+=t0]=tr2-tr3;
  105709. ch[t5+=t0]=tr1+tr4;
  105710. t1+=ido;
  105711. t3+=t2;
  105712. }
  105713. if(ido<2)return;
  105714. if(ido==2)goto L105;
  105715. t1=0;
  105716. for(k=0;k<l1;k++){
  105717. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105718. t7=t1;
  105719. for(i=2;i<ido;i+=2){
  105720. t2+=2;
  105721. t3+=2;
  105722. t4-=2;
  105723. t5-=2;
  105724. t7+=2;
  105725. ti1=cc[t2]+cc[t5];
  105726. ti2=cc[t2]-cc[t5];
  105727. ti3=cc[t3]-cc[t4];
  105728. tr4=cc[t3]+cc[t4];
  105729. tr1=cc[t2-1]-cc[t5-1];
  105730. tr2=cc[t2-1]+cc[t5-1];
  105731. ti4=cc[t3-1]-cc[t4-1];
  105732. tr3=cc[t3-1]+cc[t4-1];
  105733. ch[t7-1]=tr2+tr3;
  105734. cr3=tr2-tr3;
  105735. ch[t7]=ti2+ti3;
  105736. ci3=ti2-ti3;
  105737. cr2=tr1-tr4;
  105738. cr4=tr1+tr4;
  105739. ci2=ti1+ti4;
  105740. ci4=ti1-ti4;
  105741. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105742. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105743. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105744. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105745. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105746. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105747. }
  105748. t1+=ido;
  105749. }
  105750. if(ido%2 == 1)return;
  105751. L105:
  105752. t1=ido;
  105753. t2=ido<<2;
  105754. t3=ido-1;
  105755. t4=ido+(ido<<1);
  105756. for(k=0;k<l1;k++){
  105757. t5=t3;
  105758. ti1=cc[t1]+cc[t4];
  105759. ti2=cc[t4]-cc[t1];
  105760. tr1=cc[t1-1]-cc[t4-1];
  105761. tr2=cc[t1-1]+cc[t4-1];
  105762. ch[t5]=tr2+tr2;
  105763. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105764. ch[t5+=t0]=ti2+ti2;
  105765. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105766. t3+=ido;
  105767. t1+=t2;
  105768. t4+=t2;
  105769. }
  105770. }
  105771. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105772. float *c2,float *ch,float *ch2,float *wa){
  105773. static float tpi=6.283185307179586f;
  105774. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105775. t11,t12;
  105776. float dc2,ai1,ai2,ar1,ar2,ds2;
  105777. int nbd;
  105778. float dcp,arg,dsp,ar1h,ar2h;
  105779. int ipp2;
  105780. t10=ip*ido;
  105781. t0=l1*ido;
  105782. arg=tpi/(float)ip;
  105783. dcp=cos(arg);
  105784. dsp=sin(arg);
  105785. nbd=(ido-1)>>1;
  105786. ipp2=ip;
  105787. ipph=(ip+1)>>1;
  105788. if(ido<l1)goto L103;
  105789. t1=0;
  105790. t2=0;
  105791. for(k=0;k<l1;k++){
  105792. t3=t1;
  105793. t4=t2;
  105794. for(i=0;i<ido;i++){
  105795. ch[t3]=cc[t4];
  105796. t3++;
  105797. t4++;
  105798. }
  105799. t1+=ido;
  105800. t2+=t10;
  105801. }
  105802. goto L106;
  105803. L103:
  105804. t1=0;
  105805. for(i=0;i<ido;i++){
  105806. t2=t1;
  105807. t3=t1;
  105808. for(k=0;k<l1;k++){
  105809. ch[t2]=cc[t3];
  105810. t2+=ido;
  105811. t3+=t10;
  105812. }
  105813. t1++;
  105814. }
  105815. L106:
  105816. t1=0;
  105817. t2=ipp2*t0;
  105818. t7=(t5=ido<<1);
  105819. for(j=1;j<ipph;j++){
  105820. t1+=t0;
  105821. t2-=t0;
  105822. t3=t1;
  105823. t4=t2;
  105824. t6=t5;
  105825. for(k=0;k<l1;k++){
  105826. ch[t3]=cc[t6-1]+cc[t6-1];
  105827. ch[t4]=cc[t6]+cc[t6];
  105828. t3+=ido;
  105829. t4+=ido;
  105830. t6+=t10;
  105831. }
  105832. t5+=t7;
  105833. }
  105834. if (ido == 1)goto L116;
  105835. if(nbd<l1)goto L112;
  105836. t1=0;
  105837. t2=ipp2*t0;
  105838. t7=0;
  105839. for(j=1;j<ipph;j++){
  105840. t1+=t0;
  105841. t2-=t0;
  105842. t3=t1;
  105843. t4=t2;
  105844. t7+=(ido<<1);
  105845. t8=t7;
  105846. for(k=0;k<l1;k++){
  105847. t5=t3;
  105848. t6=t4;
  105849. t9=t8;
  105850. t11=t8;
  105851. for(i=2;i<ido;i+=2){
  105852. t5+=2;
  105853. t6+=2;
  105854. t9+=2;
  105855. t11-=2;
  105856. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105857. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105858. ch[t5]=cc[t9]-cc[t11];
  105859. ch[t6]=cc[t9]+cc[t11];
  105860. }
  105861. t3+=ido;
  105862. t4+=ido;
  105863. t8+=t10;
  105864. }
  105865. }
  105866. goto L116;
  105867. L112:
  105868. t1=0;
  105869. t2=ipp2*t0;
  105870. t7=0;
  105871. for(j=1;j<ipph;j++){
  105872. t1+=t0;
  105873. t2-=t0;
  105874. t3=t1;
  105875. t4=t2;
  105876. t7+=(ido<<1);
  105877. t8=t7;
  105878. t9=t7;
  105879. for(i=2;i<ido;i+=2){
  105880. t3+=2;
  105881. t4+=2;
  105882. t8+=2;
  105883. t9-=2;
  105884. t5=t3;
  105885. t6=t4;
  105886. t11=t8;
  105887. t12=t9;
  105888. for(k=0;k<l1;k++){
  105889. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105890. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105891. ch[t5]=cc[t11]-cc[t12];
  105892. ch[t6]=cc[t11]+cc[t12];
  105893. t5+=ido;
  105894. t6+=ido;
  105895. t11+=t10;
  105896. t12+=t10;
  105897. }
  105898. }
  105899. }
  105900. L116:
  105901. ar1=1.f;
  105902. ai1=0.f;
  105903. t1=0;
  105904. t9=(t2=ipp2*idl1);
  105905. t3=(ip-1)*idl1;
  105906. for(l=1;l<ipph;l++){
  105907. t1+=idl1;
  105908. t2-=idl1;
  105909. ar1h=dcp*ar1-dsp*ai1;
  105910. ai1=dcp*ai1+dsp*ar1;
  105911. ar1=ar1h;
  105912. t4=t1;
  105913. t5=t2;
  105914. t6=0;
  105915. t7=idl1;
  105916. t8=t3;
  105917. for(ik=0;ik<idl1;ik++){
  105918. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105919. c2[t5++]=ai1*ch2[t8++];
  105920. }
  105921. dc2=ar1;
  105922. ds2=ai1;
  105923. ar2=ar1;
  105924. ai2=ai1;
  105925. t6=idl1;
  105926. t7=t9-idl1;
  105927. for(j=2;j<ipph;j++){
  105928. t6+=idl1;
  105929. t7-=idl1;
  105930. ar2h=dc2*ar2-ds2*ai2;
  105931. ai2=dc2*ai2+ds2*ar2;
  105932. ar2=ar2h;
  105933. t4=t1;
  105934. t5=t2;
  105935. t11=t6;
  105936. t12=t7;
  105937. for(ik=0;ik<idl1;ik++){
  105938. c2[t4++]+=ar2*ch2[t11++];
  105939. c2[t5++]+=ai2*ch2[t12++];
  105940. }
  105941. }
  105942. }
  105943. t1=0;
  105944. for(j=1;j<ipph;j++){
  105945. t1+=idl1;
  105946. t2=t1;
  105947. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  105948. }
  105949. t1=0;
  105950. t2=ipp2*t0;
  105951. for(j=1;j<ipph;j++){
  105952. t1+=t0;
  105953. t2-=t0;
  105954. t3=t1;
  105955. t4=t2;
  105956. for(k=0;k<l1;k++){
  105957. ch[t3]=c1[t3]-c1[t4];
  105958. ch[t4]=c1[t3]+c1[t4];
  105959. t3+=ido;
  105960. t4+=ido;
  105961. }
  105962. }
  105963. if(ido==1)goto L132;
  105964. if(nbd<l1)goto L128;
  105965. t1=0;
  105966. t2=ipp2*t0;
  105967. for(j=1;j<ipph;j++){
  105968. t1+=t0;
  105969. t2-=t0;
  105970. t3=t1;
  105971. t4=t2;
  105972. for(k=0;k<l1;k++){
  105973. t5=t3;
  105974. t6=t4;
  105975. for(i=2;i<ido;i+=2){
  105976. t5+=2;
  105977. t6+=2;
  105978. ch[t5-1]=c1[t5-1]-c1[t6];
  105979. ch[t6-1]=c1[t5-1]+c1[t6];
  105980. ch[t5]=c1[t5]+c1[t6-1];
  105981. ch[t6]=c1[t5]-c1[t6-1];
  105982. }
  105983. t3+=ido;
  105984. t4+=ido;
  105985. }
  105986. }
  105987. goto L132;
  105988. L128:
  105989. t1=0;
  105990. t2=ipp2*t0;
  105991. for(j=1;j<ipph;j++){
  105992. t1+=t0;
  105993. t2-=t0;
  105994. t3=t1;
  105995. t4=t2;
  105996. for(i=2;i<ido;i+=2){
  105997. t3+=2;
  105998. t4+=2;
  105999. t5=t3;
  106000. t6=t4;
  106001. for(k=0;k<l1;k++){
  106002. ch[t5-1]=c1[t5-1]-c1[t6];
  106003. ch[t6-1]=c1[t5-1]+c1[t6];
  106004. ch[t5]=c1[t5]+c1[t6-1];
  106005. ch[t6]=c1[t5]-c1[t6-1];
  106006. t5+=ido;
  106007. t6+=ido;
  106008. }
  106009. }
  106010. }
  106011. L132:
  106012. if(ido==1)return;
  106013. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106014. t1=0;
  106015. for(j=1;j<ip;j++){
  106016. t2=(t1+=t0);
  106017. for(k=0;k<l1;k++){
  106018. c1[t2]=ch[t2];
  106019. t2+=ido;
  106020. }
  106021. }
  106022. if(nbd>l1)goto L139;
  106023. is= -ido-1;
  106024. t1=0;
  106025. for(j=1;j<ip;j++){
  106026. is+=ido;
  106027. t1+=t0;
  106028. idij=is;
  106029. t2=t1;
  106030. for(i=2;i<ido;i+=2){
  106031. t2+=2;
  106032. idij+=2;
  106033. t3=t2;
  106034. for(k=0;k<l1;k++){
  106035. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106036. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106037. t3+=ido;
  106038. }
  106039. }
  106040. }
  106041. return;
  106042. L139:
  106043. is= -ido-1;
  106044. t1=0;
  106045. for(j=1;j<ip;j++){
  106046. is+=ido;
  106047. t1+=t0;
  106048. t2=t1;
  106049. for(k=0;k<l1;k++){
  106050. idij=is;
  106051. t3=t2;
  106052. for(i=2;i<ido;i+=2){
  106053. idij+=2;
  106054. t3+=2;
  106055. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106056. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106057. }
  106058. t2+=ido;
  106059. }
  106060. }
  106061. }
  106062. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106063. int i,k1,l1,l2;
  106064. int na;
  106065. int nf,ip,iw,ix2,ix3,ido,idl1;
  106066. nf=ifac[1];
  106067. na=0;
  106068. l1=1;
  106069. iw=1;
  106070. for(k1=0;k1<nf;k1++){
  106071. ip=ifac[k1 + 2];
  106072. l2=ip*l1;
  106073. ido=n/l2;
  106074. idl1=ido*l1;
  106075. if(ip!=4)goto L103;
  106076. ix2=iw+ido;
  106077. ix3=ix2+ido;
  106078. if(na!=0)
  106079. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106080. else
  106081. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106082. na=1-na;
  106083. goto L115;
  106084. L103:
  106085. if(ip!=2)goto L106;
  106086. if(na!=0)
  106087. dradb2(ido,l1,ch,c,wa+iw-1);
  106088. else
  106089. dradb2(ido,l1,c,ch,wa+iw-1);
  106090. na=1-na;
  106091. goto L115;
  106092. L106:
  106093. if(ip!=3)goto L109;
  106094. ix2=iw+ido;
  106095. if(na!=0)
  106096. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106097. else
  106098. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106099. na=1-na;
  106100. goto L115;
  106101. L109:
  106102. if(na!=0)
  106103. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106104. else
  106105. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106106. if(ido==1)na=1-na;
  106107. L115:
  106108. l1=l2;
  106109. iw+=(ip-1)*ido;
  106110. }
  106111. if(na==0)return;
  106112. for(i=0;i<n;i++)c[i]=ch[i];
  106113. }
  106114. void drft_forward(drft_lookup *l,float *data){
  106115. if(l->n==1)return;
  106116. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106117. }
  106118. void drft_backward(drft_lookup *l,float *data){
  106119. if (l->n==1)return;
  106120. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106121. }
  106122. void drft_init(drft_lookup *l,int n){
  106123. l->n=n;
  106124. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106125. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106126. fdrffti(n, l->trigcache, l->splitcache);
  106127. }
  106128. void drft_clear(drft_lookup *l){
  106129. if(l){
  106130. if(l->trigcache)_ogg_free(l->trigcache);
  106131. if(l->splitcache)_ogg_free(l->splitcache);
  106132. memset(l,0,sizeof(*l));
  106133. }
  106134. }
  106135. #endif
  106136. /*** End of inlined file: smallft.c ***/
  106137. /*** Start of inlined file: synthesis.c ***/
  106138. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106139. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106140. // tasks..
  106141. #if JUCE_MSVC
  106142. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106143. #endif
  106144. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106145. #if JUCE_USE_OGGVORBIS
  106146. #include <stdio.h>
  106147. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106148. vorbis_dsp_state *vd=vb->vd;
  106149. private_state *b=(private_state*)vd->backend_state;
  106150. vorbis_info *vi=vd->vi;
  106151. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106152. oggpack_buffer *opb=&vb->opb;
  106153. int type,mode,i;
  106154. _vorbis_block_ripcord(vb);
  106155. oggpack_readinit(opb,op->packet,op->bytes);
  106156. if(oggpack_read(opb,1)!=0){
  106157. return(OV_ENOTAUDIO);
  106158. }
  106159. mode=oggpack_read(opb,b->modebits);
  106160. if(mode==-1)return(OV_EBADPACKET);
  106161. vb->mode=mode;
  106162. vb->W=ci->mode_param[mode]->blockflag;
  106163. if(vb->W){
  106164. vb->lW=oggpack_read(opb,1);
  106165. vb->nW=oggpack_read(opb,1);
  106166. if(vb->nW==-1) return(OV_EBADPACKET);
  106167. }else{
  106168. vb->lW=0;
  106169. vb->nW=0;
  106170. }
  106171. vb->granulepos=op->granulepos;
  106172. vb->sequence=op->packetno;
  106173. vb->eofflag=op->e_o_s;
  106174. vb->pcmend=ci->blocksizes[vb->W];
  106175. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106176. for(i=0;i<vi->channels;i++)
  106177. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106178. type=ci->map_type[ci->mode_param[mode]->mapping];
  106179. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106180. mapping]));
  106181. }
  106182. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106183. vorbis_dsp_state *vd=vb->vd;
  106184. private_state *b=(private_state*)vd->backend_state;
  106185. vorbis_info *vi=vd->vi;
  106186. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106187. oggpack_buffer *opb=&vb->opb;
  106188. int mode;
  106189. _vorbis_block_ripcord(vb);
  106190. oggpack_readinit(opb,op->packet,op->bytes);
  106191. if(oggpack_read(opb,1)!=0){
  106192. return(OV_ENOTAUDIO);
  106193. }
  106194. mode=oggpack_read(opb,b->modebits);
  106195. if(mode==-1)return(OV_EBADPACKET);
  106196. vb->mode=mode;
  106197. vb->W=ci->mode_param[mode]->blockflag;
  106198. if(vb->W){
  106199. vb->lW=oggpack_read(opb,1);
  106200. vb->nW=oggpack_read(opb,1);
  106201. if(vb->nW==-1) return(OV_EBADPACKET);
  106202. }else{
  106203. vb->lW=0;
  106204. vb->nW=0;
  106205. }
  106206. vb->granulepos=op->granulepos;
  106207. vb->sequence=op->packetno;
  106208. vb->eofflag=op->e_o_s;
  106209. vb->pcmend=0;
  106210. vb->pcm=NULL;
  106211. return(0);
  106212. }
  106213. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106214. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106215. oggpack_buffer opb;
  106216. int mode;
  106217. oggpack_readinit(&opb,op->packet,op->bytes);
  106218. if(oggpack_read(&opb,1)!=0){
  106219. return(OV_ENOTAUDIO);
  106220. }
  106221. {
  106222. int modebits=0;
  106223. int v=ci->modes;
  106224. while(v>1){
  106225. modebits++;
  106226. v>>=1;
  106227. }
  106228. mode=oggpack_read(&opb,modebits);
  106229. }
  106230. if(mode==-1)return(OV_EBADPACKET);
  106231. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106232. }
  106233. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106234. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106235. if(ci->blocksizes[0]<=64 && flag)return -1;
  106236. ci->halfrate_flag=(flag?1:0);
  106237. return 0;
  106238. }
  106239. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106240. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106241. return ci->halfrate_flag;
  106242. }
  106243. #endif
  106244. /*** End of inlined file: synthesis.c ***/
  106245. /*** Start of inlined file: vorbisenc.c ***/
  106246. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106247. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106248. // tasks..
  106249. #if JUCE_MSVC
  106250. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106251. #endif
  106252. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106253. #if JUCE_USE_OGGVORBIS
  106254. #include <stdlib.h>
  106255. #include <string.h>
  106256. #include <math.h>
  106257. typedef struct {
  106258. static_codebook *books[12][3];
  106259. } static_bookblock;
  106260. typedef struct {
  106261. int res_type;
  106262. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106263. vorbis_info_residue0 *res;
  106264. static_codebook *book_aux;
  106265. static_codebook *book_aux_managed;
  106266. static_bookblock *books_base;
  106267. static_bookblock *books_base_managed;
  106268. } vorbis_residue_template;
  106269. typedef struct {
  106270. vorbis_info_mapping0 *map;
  106271. vorbis_residue_template *res;
  106272. } vorbis_mapping_template;
  106273. typedef struct vp_adjblock{
  106274. int block[P_BANDS];
  106275. } vp_adjblock;
  106276. typedef struct {
  106277. int data[NOISE_COMPAND_LEVELS];
  106278. } compandblock;
  106279. typedef struct {
  106280. int att[P_NOISECURVES];
  106281. float boost;
  106282. float decay;
  106283. } att3;
  106284. typedef struct { int data[P_NOISECURVES]; } adj3;
  106285. typedef struct {
  106286. int pre[PACKETBLOBS];
  106287. int post[PACKETBLOBS];
  106288. float kHz[PACKETBLOBS];
  106289. float lowpasskHz[PACKETBLOBS];
  106290. } adj_stereo;
  106291. typedef struct {
  106292. int lo;
  106293. int hi;
  106294. int fixed;
  106295. } noiseguard;
  106296. typedef struct {
  106297. int data[P_NOISECURVES][17];
  106298. } noise3;
  106299. typedef struct {
  106300. int mappings;
  106301. double *rate_mapping;
  106302. double *quality_mapping;
  106303. int coupling_restriction;
  106304. long samplerate_min_restriction;
  106305. long samplerate_max_restriction;
  106306. int *blocksize_short;
  106307. int *blocksize_long;
  106308. att3 *psy_tone_masteratt;
  106309. int *psy_tone_0dB;
  106310. int *psy_tone_dBsuppress;
  106311. vp_adjblock *psy_tone_adj_impulse;
  106312. vp_adjblock *psy_tone_adj_long;
  106313. vp_adjblock *psy_tone_adj_other;
  106314. noiseguard *psy_noiseguards;
  106315. noise3 *psy_noise_bias_impulse;
  106316. noise3 *psy_noise_bias_padding;
  106317. noise3 *psy_noise_bias_trans;
  106318. noise3 *psy_noise_bias_long;
  106319. int *psy_noise_dBsuppress;
  106320. compandblock *psy_noise_compand;
  106321. double *psy_noise_compand_short_mapping;
  106322. double *psy_noise_compand_long_mapping;
  106323. int *psy_noise_normal_start[2];
  106324. int *psy_noise_normal_partition[2];
  106325. double *psy_noise_normal_thresh;
  106326. int *psy_ath_float;
  106327. int *psy_ath_abs;
  106328. double *psy_lowpass;
  106329. vorbis_info_psy_global *global_params;
  106330. double *global_mapping;
  106331. adj_stereo *stereo_modes;
  106332. static_codebook ***floor_books;
  106333. vorbis_info_floor1 *floor_params;
  106334. int *floor_short_mapping;
  106335. int *floor_long_mapping;
  106336. vorbis_mapping_template *maps;
  106337. } ve_setup_data_template;
  106338. static vorbis_info_mode _mode_template[2]={
  106339. {0,0,0,0},
  106340. {1,0,0,1}
  106341. };
  106342. static vorbis_info_mapping0 _map_nominal[2]={
  106343. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106344. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106345. };
  106346. /*** Start of inlined file: setup_44.h ***/
  106347. /*** Start of inlined file: floor_all.h ***/
  106348. /*** Start of inlined file: floor_books.h ***/
  106349. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106350. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106351. };
  106352. static static_codebook _huff_book_line_256x7_0sub1 = {
  106353. 1, 9,
  106354. _huff_lengthlist_line_256x7_0sub1,
  106355. 0, 0, 0, 0, 0,
  106356. NULL,
  106357. NULL,
  106358. NULL,
  106359. NULL,
  106360. 0
  106361. };
  106362. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106364. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106365. };
  106366. static static_codebook _huff_book_line_256x7_0sub2 = {
  106367. 1, 25,
  106368. _huff_lengthlist_line_256x7_0sub2,
  106369. 0, 0, 0, 0, 0,
  106370. NULL,
  106371. NULL,
  106372. NULL,
  106373. NULL,
  106374. 0
  106375. };
  106376. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106379. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106380. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106381. };
  106382. static static_codebook _huff_book_line_256x7_0sub3 = {
  106383. 1, 64,
  106384. _huff_lengthlist_line_256x7_0sub3,
  106385. 0, 0, 0, 0, 0,
  106386. NULL,
  106387. NULL,
  106388. NULL,
  106389. NULL,
  106390. 0
  106391. };
  106392. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106393. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106394. };
  106395. static static_codebook _huff_book_line_256x7_1sub1 = {
  106396. 1, 9,
  106397. _huff_lengthlist_line_256x7_1sub1,
  106398. 0, 0, 0, 0, 0,
  106399. NULL,
  106400. NULL,
  106401. NULL,
  106402. NULL,
  106403. 0
  106404. };
  106405. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106407. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106408. };
  106409. static static_codebook _huff_book_line_256x7_1sub2 = {
  106410. 1, 25,
  106411. _huff_lengthlist_line_256x7_1sub2,
  106412. 0, 0, 0, 0, 0,
  106413. NULL,
  106414. NULL,
  106415. NULL,
  106416. NULL,
  106417. 0
  106418. };
  106419. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106422. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106423. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106424. };
  106425. static static_codebook _huff_book_line_256x7_1sub3 = {
  106426. 1, 64,
  106427. _huff_lengthlist_line_256x7_1sub3,
  106428. 0, 0, 0, 0, 0,
  106429. NULL,
  106430. NULL,
  106431. NULL,
  106432. NULL,
  106433. 0
  106434. };
  106435. static long _huff_lengthlist_line_256x7_class0[] = {
  106436. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106437. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106438. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106439. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106440. };
  106441. static static_codebook _huff_book_line_256x7_class0 = {
  106442. 1, 64,
  106443. _huff_lengthlist_line_256x7_class0,
  106444. 0, 0, 0, 0, 0,
  106445. NULL,
  106446. NULL,
  106447. NULL,
  106448. NULL,
  106449. 0
  106450. };
  106451. static long _huff_lengthlist_line_256x7_class1[] = {
  106452. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106453. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106454. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106455. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106456. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106457. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106458. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106459. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106460. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106461. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106462. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106463. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106464. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106465. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106466. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106467. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106468. };
  106469. static static_codebook _huff_book_line_256x7_class1 = {
  106470. 1, 256,
  106471. _huff_lengthlist_line_256x7_class1,
  106472. 0, 0, 0, 0, 0,
  106473. NULL,
  106474. NULL,
  106475. NULL,
  106476. NULL,
  106477. 0
  106478. };
  106479. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106480. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106481. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106482. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106483. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106484. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106485. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106486. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106487. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106488. };
  106489. static static_codebook _huff_book_line_512x17_0sub0 = {
  106490. 1, 128,
  106491. _huff_lengthlist_line_512x17_0sub0,
  106492. 0, 0, 0, 0, 0,
  106493. NULL,
  106494. NULL,
  106495. NULL,
  106496. NULL,
  106497. 0
  106498. };
  106499. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106500. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106501. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106502. };
  106503. static static_codebook _huff_book_line_512x17_1sub0 = {
  106504. 1, 32,
  106505. _huff_lengthlist_line_512x17_1sub0,
  106506. 0, 0, 0, 0, 0,
  106507. NULL,
  106508. NULL,
  106509. NULL,
  106510. NULL,
  106511. 0
  106512. };
  106513. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106516. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106517. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106518. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106519. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106520. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106521. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106522. };
  106523. static static_codebook _huff_book_line_512x17_1sub1 = {
  106524. 1, 128,
  106525. _huff_lengthlist_line_512x17_1sub1,
  106526. 0, 0, 0, 0, 0,
  106527. NULL,
  106528. NULL,
  106529. NULL,
  106530. NULL,
  106531. 0
  106532. };
  106533. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106534. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106535. 5, 3,
  106536. };
  106537. static static_codebook _huff_book_line_512x17_2sub1 = {
  106538. 1, 18,
  106539. _huff_lengthlist_line_512x17_2sub1,
  106540. 0, 0, 0, 0, 0,
  106541. NULL,
  106542. NULL,
  106543. NULL,
  106544. NULL,
  106545. 0
  106546. };
  106547. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106549. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106550. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106551. 9, 8,
  106552. };
  106553. static static_codebook _huff_book_line_512x17_2sub2 = {
  106554. 1, 50,
  106555. _huff_lengthlist_line_512x17_2sub2,
  106556. 0, 0, 0, 0, 0,
  106557. NULL,
  106558. NULL,
  106559. NULL,
  106560. NULL,
  106561. 0
  106562. };
  106563. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106567. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106568. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106569. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106570. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106571. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106572. };
  106573. static static_codebook _huff_book_line_512x17_2sub3 = {
  106574. 1, 128,
  106575. _huff_lengthlist_line_512x17_2sub3,
  106576. 0, 0, 0, 0, 0,
  106577. NULL,
  106578. NULL,
  106579. NULL,
  106580. NULL,
  106581. 0
  106582. };
  106583. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106584. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106585. 5, 5,
  106586. };
  106587. static static_codebook _huff_book_line_512x17_3sub1 = {
  106588. 1, 18,
  106589. _huff_lengthlist_line_512x17_3sub1,
  106590. 0, 0, 0, 0, 0,
  106591. NULL,
  106592. NULL,
  106593. NULL,
  106594. NULL,
  106595. 0
  106596. };
  106597. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106599. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106600. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106601. 11,14,
  106602. };
  106603. static static_codebook _huff_book_line_512x17_3sub2 = {
  106604. 1, 50,
  106605. _huff_lengthlist_line_512x17_3sub2,
  106606. 0, 0, 0, 0, 0,
  106607. NULL,
  106608. NULL,
  106609. NULL,
  106610. NULL,
  106611. 0
  106612. };
  106613. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106617. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106618. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106619. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106620. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106621. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106622. };
  106623. static static_codebook _huff_book_line_512x17_3sub3 = {
  106624. 1, 128,
  106625. _huff_lengthlist_line_512x17_3sub3,
  106626. 0, 0, 0, 0, 0,
  106627. NULL,
  106628. NULL,
  106629. NULL,
  106630. NULL,
  106631. 0
  106632. };
  106633. static long _huff_lengthlist_line_512x17_class1[] = {
  106634. 1, 2, 3, 6, 5, 4, 7, 7,
  106635. };
  106636. static static_codebook _huff_book_line_512x17_class1 = {
  106637. 1, 8,
  106638. _huff_lengthlist_line_512x17_class1,
  106639. 0, 0, 0, 0, 0,
  106640. NULL,
  106641. NULL,
  106642. NULL,
  106643. NULL,
  106644. 0
  106645. };
  106646. static long _huff_lengthlist_line_512x17_class2[] = {
  106647. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106648. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106649. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106650. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106651. };
  106652. static static_codebook _huff_book_line_512x17_class2 = {
  106653. 1, 64,
  106654. _huff_lengthlist_line_512x17_class2,
  106655. 0, 0, 0, 0, 0,
  106656. NULL,
  106657. NULL,
  106658. NULL,
  106659. NULL,
  106660. 0
  106661. };
  106662. static long _huff_lengthlist_line_512x17_class3[] = {
  106663. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106664. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106665. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106666. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106667. };
  106668. static static_codebook _huff_book_line_512x17_class3 = {
  106669. 1, 64,
  106670. _huff_lengthlist_line_512x17_class3,
  106671. 0, 0, 0, 0, 0,
  106672. NULL,
  106673. NULL,
  106674. NULL,
  106675. NULL,
  106676. 0
  106677. };
  106678. static long _huff_lengthlist_line_128x4_class0[] = {
  106679. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106680. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106681. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106682. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106683. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106684. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106685. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106686. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106687. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106688. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106689. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106690. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106691. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106692. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106693. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106694. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106695. };
  106696. static static_codebook _huff_book_line_128x4_class0 = {
  106697. 1, 256,
  106698. _huff_lengthlist_line_128x4_class0,
  106699. 0, 0, 0, 0, 0,
  106700. NULL,
  106701. NULL,
  106702. NULL,
  106703. NULL,
  106704. 0
  106705. };
  106706. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106707. 2, 2, 2, 2,
  106708. };
  106709. static static_codebook _huff_book_line_128x4_0sub0 = {
  106710. 1, 4,
  106711. _huff_lengthlist_line_128x4_0sub0,
  106712. 0, 0, 0, 0, 0,
  106713. NULL,
  106714. NULL,
  106715. NULL,
  106716. NULL,
  106717. 0
  106718. };
  106719. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106720. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106721. };
  106722. static static_codebook _huff_book_line_128x4_0sub1 = {
  106723. 1, 10,
  106724. _huff_lengthlist_line_128x4_0sub1,
  106725. 0, 0, 0, 0, 0,
  106726. NULL,
  106727. NULL,
  106728. NULL,
  106729. NULL,
  106730. 0
  106731. };
  106732. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106734. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106735. };
  106736. static static_codebook _huff_book_line_128x4_0sub2 = {
  106737. 1, 25,
  106738. _huff_lengthlist_line_128x4_0sub2,
  106739. 0, 0, 0, 0, 0,
  106740. NULL,
  106741. NULL,
  106742. NULL,
  106743. NULL,
  106744. 0
  106745. };
  106746. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106749. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106750. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106751. };
  106752. static static_codebook _huff_book_line_128x4_0sub3 = {
  106753. 1, 64,
  106754. _huff_lengthlist_line_128x4_0sub3,
  106755. 0, 0, 0, 0, 0,
  106756. NULL,
  106757. NULL,
  106758. NULL,
  106759. NULL,
  106760. 0
  106761. };
  106762. static long _huff_lengthlist_line_256x4_class0[] = {
  106763. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106764. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106765. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106766. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106767. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106768. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106769. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106770. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106771. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106772. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106773. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106774. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106775. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106776. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106777. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106778. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106779. };
  106780. static static_codebook _huff_book_line_256x4_class0 = {
  106781. 1, 256,
  106782. _huff_lengthlist_line_256x4_class0,
  106783. 0, 0, 0, 0, 0,
  106784. NULL,
  106785. NULL,
  106786. NULL,
  106787. NULL,
  106788. 0
  106789. };
  106790. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106791. 2, 2, 2, 2,
  106792. };
  106793. static static_codebook _huff_book_line_256x4_0sub0 = {
  106794. 1, 4,
  106795. _huff_lengthlist_line_256x4_0sub0,
  106796. 0, 0, 0, 0, 0,
  106797. NULL,
  106798. NULL,
  106799. NULL,
  106800. NULL,
  106801. 0
  106802. };
  106803. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106804. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106805. };
  106806. static static_codebook _huff_book_line_256x4_0sub1 = {
  106807. 1, 10,
  106808. _huff_lengthlist_line_256x4_0sub1,
  106809. 0, 0, 0, 0, 0,
  106810. NULL,
  106811. NULL,
  106812. NULL,
  106813. NULL,
  106814. 0
  106815. };
  106816. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106818. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106819. };
  106820. static static_codebook _huff_book_line_256x4_0sub2 = {
  106821. 1, 25,
  106822. _huff_lengthlist_line_256x4_0sub2,
  106823. 0, 0, 0, 0, 0,
  106824. NULL,
  106825. NULL,
  106826. NULL,
  106827. NULL,
  106828. 0
  106829. };
  106830. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106833. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106834. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106835. };
  106836. static static_codebook _huff_book_line_256x4_0sub3 = {
  106837. 1, 64,
  106838. _huff_lengthlist_line_256x4_0sub3,
  106839. 0, 0, 0, 0, 0,
  106840. NULL,
  106841. NULL,
  106842. NULL,
  106843. NULL,
  106844. 0
  106845. };
  106846. static long _huff_lengthlist_line_128x7_class0[] = {
  106847. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106848. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106849. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106850. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106851. };
  106852. static static_codebook _huff_book_line_128x7_class0 = {
  106853. 1, 64,
  106854. _huff_lengthlist_line_128x7_class0,
  106855. 0, 0, 0, 0, 0,
  106856. NULL,
  106857. NULL,
  106858. NULL,
  106859. NULL,
  106860. 0
  106861. };
  106862. static long _huff_lengthlist_line_128x7_class1[] = {
  106863. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106864. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106865. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106866. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106867. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106868. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106869. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106870. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106871. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106872. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106873. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106874. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106875. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106876. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106877. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106878. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106879. };
  106880. static static_codebook _huff_book_line_128x7_class1 = {
  106881. 1, 256,
  106882. _huff_lengthlist_line_128x7_class1,
  106883. 0, 0, 0, 0, 0,
  106884. NULL,
  106885. NULL,
  106886. NULL,
  106887. NULL,
  106888. 0
  106889. };
  106890. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106891. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106892. };
  106893. static static_codebook _huff_book_line_128x7_0sub1 = {
  106894. 1, 9,
  106895. _huff_lengthlist_line_128x7_0sub1,
  106896. 0, 0, 0, 0, 0,
  106897. NULL,
  106898. NULL,
  106899. NULL,
  106900. NULL,
  106901. 0
  106902. };
  106903. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106905. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106906. };
  106907. static static_codebook _huff_book_line_128x7_0sub2 = {
  106908. 1, 25,
  106909. _huff_lengthlist_line_128x7_0sub2,
  106910. 0, 0, 0, 0, 0,
  106911. NULL,
  106912. NULL,
  106913. NULL,
  106914. NULL,
  106915. 0
  106916. };
  106917. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106920. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106921. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106922. };
  106923. static static_codebook _huff_book_line_128x7_0sub3 = {
  106924. 1, 64,
  106925. _huff_lengthlist_line_128x7_0sub3,
  106926. 0, 0, 0, 0, 0,
  106927. NULL,
  106928. NULL,
  106929. NULL,
  106930. NULL,
  106931. 0
  106932. };
  106933. static long _huff_lengthlist_line_128x7_1sub1[] = {
  106934. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  106935. };
  106936. static static_codebook _huff_book_line_128x7_1sub1 = {
  106937. 1, 9,
  106938. _huff_lengthlist_line_128x7_1sub1,
  106939. 0, 0, 0, 0, 0,
  106940. NULL,
  106941. NULL,
  106942. NULL,
  106943. NULL,
  106944. 0
  106945. };
  106946. static long _huff_lengthlist_line_128x7_1sub2[] = {
  106947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  106948. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  106949. };
  106950. static static_codebook _huff_book_line_128x7_1sub2 = {
  106951. 1, 25,
  106952. _huff_lengthlist_line_128x7_1sub2,
  106953. 0, 0, 0, 0, 0,
  106954. NULL,
  106955. NULL,
  106956. NULL,
  106957. NULL,
  106958. 0
  106959. };
  106960. static long _huff_lengthlist_line_128x7_1sub3[] = {
  106961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  106963. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  106964. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  106965. };
  106966. static static_codebook _huff_book_line_128x7_1sub3 = {
  106967. 1, 64,
  106968. _huff_lengthlist_line_128x7_1sub3,
  106969. 0, 0, 0, 0, 0,
  106970. NULL,
  106971. NULL,
  106972. NULL,
  106973. NULL,
  106974. 0
  106975. };
  106976. static long _huff_lengthlist_line_128x11_class1[] = {
  106977. 1, 6, 3, 7, 2, 4, 5, 7,
  106978. };
  106979. static static_codebook _huff_book_line_128x11_class1 = {
  106980. 1, 8,
  106981. _huff_lengthlist_line_128x11_class1,
  106982. 0, 0, 0, 0, 0,
  106983. NULL,
  106984. NULL,
  106985. NULL,
  106986. NULL,
  106987. 0
  106988. };
  106989. static long _huff_lengthlist_line_128x11_class2[] = {
  106990. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  106991. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  106992. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  106993. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  106994. };
  106995. static static_codebook _huff_book_line_128x11_class2 = {
  106996. 1, 64,
  106997. _huff_lengthlist_line_128x11_class2,
  106998. 0, 0, 0, 0, 0,
  106999. NULL,
  107000. NULL,
  107001. NULL,
  107002. NULL,
  107003. 0
  107004. };
  107005. static long _huff_lengthlist_line_128x11_class3[] = {
  107006. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107007. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107008. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107009. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107010. };
  107011. static static_codebook _huff_book_line_128x11_class3 = {
  107012. 1, 64,
  107013. _huff_lengthlist_line_128x11_class3,
  107014. 0, 0, 0, 0, 0,
  107015. NULL,
  107016. NULL,
  107017. NULL,
  107018. NULL,
  107019. 0
  107020. };
  107021. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107022. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107023. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107024. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107025. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107026. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107027. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107028. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107029. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107030. };
  107031. static static_codebook _huff_book_line_128x11_0sub0 = {
  107032. 1, 128,
  107033. _huff_lengthlist_line_128x11_0sub0,
  107034. 0, 0, 0, 0, 0,
  107035. NULL,
  107036. NULL,
  107037. NULL,
  107038. NULL,
  107039. 0
  107040. };
  107041. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107042. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107043. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107044. };
  107045. static static_codebook _huff_book_line_128x11_1sub0 = {
  107046. 1, 32,
  107047. _huff_lengthlist_line_128x11_1sub0,
  107048. 0, 0, 0, 0, 0,
  107049. NULL,
  107050. NULL,
  107051. NULL,
  107052. NULL,
  107053. 0
  107054. };
  107055. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107058. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107059. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107060. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107061. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107062. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107063. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107064. };
  107065. static static_codebook _huff_book_line_128x11_1sub1 = {
  107066. 1, 128,
  107067. _huff_lengthlist_line_128x11_1sub1,
  107068. 0, 0, 0, 0, 0,
  107069. NULL,
  107070. NULL,
  107071. NULL,
  107072. NULL,
  107073. 0
  107074. };
  107075. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107076. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107077. 5, 5,
  107078. };
  107079. static static_codebook _huff_book_line_128x11_2sub1 = {
  107080. 1, 18,
  107081. _huff_lengthlist_line_128x11_2sub1,
  107082. 0, 0, 0, 0, 0,
  107083. NULL,
  107084. NULL,
  107085. NULL,
  107086. NULL,
  107087. 0
  107088. };
  107089. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107091. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107092. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107093. 8,11,
  107094. };
  107095. static static_codebook _huff_book_line_128x11_2sub2 = {
  107096. 1, 50,
  107097. _huff_lengthlist_line_128x11_2sub2,
  107098. 0, 0, 0, 0, 0,
  107099. NULL,
  107100. NULL,
  107101. NULL,
  107102. NULL,
  107103. 0
  107104. };
  107105. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107109. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107110. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107111. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107112. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107113. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107114. };
  107115. static static_codebook _huff_book_line_128x11_2sub3 = {
  107116. 1, 128,
  107117. _huff_lengthlist_line_128x11_2sub3,
  107118. 0, 0, 0, 0, 0,
  107119. NULL,
  107120. NULL,
  107121. NULL,
  107122. NULL,
  107123. 0
  107124. };
  107125. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107126. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107127. 5, 4,
  107128. };
  107129. static static_codebook _huff_book_line_128x11_3sub1 = {
  107130. 1, 18,
  107131. _huff_lengthlist_line_128x11_3sub1,
  107132. 0, 0, 0, 0, 0,
  107133. NULL,
  107134. NULL,
  107135. NULL,
  107136. NULL,
  107137. 0
  107138. };
  107139. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107141. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107142. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107143. 12, 6,
  107144. };
  107145. static static_codebook _huff_book_line_128x11_3sub2 = {
  107146. 1, 50,
  107147. _huff_lengthlist_line_128x11_3sub2,
  107148. 0, 0, 0, 0, 0,
  107149. NULL,
  107150. NULL,
  107151. NULL,
  107152. NULL,
  107153. 0
  107154. };
  107155. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107159. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107160. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107161. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107162. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107163. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107164. };
  107165. static static_codebook _huff_book_line_128x11_3sub3 = {
  107166. 1, 128,
  107167. _huff_lengthlist_line_128x11_3sub3,
  107168. 0, 0, 0, 0, 0,
  107169. NULL,
  107170. NULL,
  107171. NULL,
  107172. NULL,
  107173. 0
  107174. };
  107175. static long _huff_lengthlist_line_128x17_class1[] = {
  107176. 1, 3, 4, 7, 2, 5, 6, 7,
  107177. };
  107178. static static_codebook _huff_book_line_128x17_class1 = {
  107179. 1, 8,
  107180. _huff_lengthlist_line_128x17_class1,
  107181. 0, 0, 0, 0, 0,
  107182. NULL,
  107183. NULL,
  107184. NULL,
  107185. NULL,
  107186. 0
  107187. };
  107188. static long _huff_lengthlist_line_128x17_class2[] = {
  107189. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107190. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107191. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107192. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107193. };
  107194. static static_codebook _huff_book_line_128x17_class2 = {
  107195. 1, 64,
  107196. _huff_lengthlist_line_128x17_class2,
  107197. 0, 0, 0, 0, 0,
  107198. NULL,
  107199. NULL,
  107200. NULL,
  107201. NULL,
  107202. 0
  107203. };
  107204. static long _huff_lengthlist_line_128x17_class3[] = {
  107205. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107206. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107207. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107208. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107209. };
  107210. static static_codebook _huff_book_line_128x17_class3 = {
  107211. 1, 64,
  107212. _huff_lengthlist_line_128x17_class3,
  107213. 0, 0, 0, 0, 0,
  107214. NULL,
  107215. NULL,
  107216. NULL,
  107217. NULL,
  107218. 0
  107219. };
  107220. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107221. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107222. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107223. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107224. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107225. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107226. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107227. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107228. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107229. };
  107230. static static_codebook _huff_book_line_128x17_0sub0 = {
  107231. 1, 128,
  107232. _huff_lengthlist_line_128x17_0sub0,
  107233. 0, 0, 0, 0, 0,
  107234. NULL,
  107235. NULL,
  107236. NULL,
  107237. NULL,
  107238. 0
  107239. };
  107240. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107241. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107242. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107243. };
  107244. static static_codebook _huff_book_line_128x17_1sub0 = {
  107245. 1, 32,
  107246. _huff_lengthlist_line_128x17_1sub0,
  107247. 0, 0, 0, 0, 0,
  107248. NULL,
  107249. NULL,
  107250. NULL,
  107251. NULL,
  107252. 0
  107253. };
  107254. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107257. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107258. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107259. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107260. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107261. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107262. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107263. };
  107264. static static_codebook _huff_book_line_128x17_1sub1 = {
  107265. 1, 128,
  107266. _huff_lengthlist_line_128x17_1sub1,
  107267. 0, 0, 0, 0, 0,
  107268. NULL,
  107269. NULL,
  107270. NULL,
  107271. NULL,
  107272. 0
  107273. };
  107274. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107275. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107276. 9, 4,
  107277. };
  107278. static static_codebook _huff_book_line_128x17_2sub1 = {
  107279. 1, 18,
  107280. _huff_lengthlist_line_128x17_2sub1,
  107281. 0, 0, 0, 0, 0,
  107282. NULL,
  107283. NULL,
  107284. NULL,
  107285. NULL,
  107286. 0
  107287. };
  107288. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107290. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107291. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107292. 13,13,
  107293. };
  107294. static static_codebook _huff_book_line_128x17_2sub2 = {
  107295. 1, 50,
  107296. _huff_lengthlist_line_128x17_2sub2,
  107297. 0, 0, 0, 0, 0,
  107298. NULL,
  107299. NULL,
  107300. NULL,
  107301. NULL,
  107302. 0
  107303. };
  107304. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107308. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107309. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107310. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107311. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107312. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107313. };
  107314. static static_codebook _huff_book_line_128x17_2sub3 = {
  107315. 1, 128,
  107316. _huff_lengthlist_line_128x17_2sub3,
  107317. 0, 0, 0, 0, 0,
  107318. NULL,
  107319. NULL,
  107320. NULL,
  107321. NULL,
  107322. 0
  107323. };
  107324. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107325. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107326. 6, 4,
  107327. };
  107328. static static_codebook _huff_book_line_128x17_3sub1 = {
  107329. 1, 18,
  107330. _huff_lengthlist_line_128x17_3sub1,
  107331. 0, 0, 0, 0, 0,
  107332. NULL,
  107333. NULL,
  107334. NULL,
  107335. NULL,
  107336. 0
  107337. };
  107338. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107340. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107341. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107342. 10, 8,
  107343. };
  107344. static static_codebook _huff_book_line_128x17_3sub2 = {
  107345. 1, 50,
  107346. _huff_lengthlist_line_128x17_3sub2,
  107347. 0, 0, 0, 0, 0,
  107348. NULL,
  107349. NULL,
  107350. NULL,
  107351. NULL,
  107352. 0
  107353. };
  107354. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107358. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107359. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107360. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107361. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107362. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107363. };
  107364. static static_codebook _huff_book_line_128x17_3sub3 = {
  107365. 1, 128,
  107366. _huff_lengthlist_line_128x17_3sub3,
  107367. 0, 0, 0, 0, 0,
  107368. NULL,
  107369. NULL,
  107370. NULL,
  107371. NULL,
  107372. 0
  107373. };
  107374. static long _huff_lengthlist_line_1024x27_class1[] = {
  107375. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107376. };
  107377. static static_codebook _huff_book_line_1024x27_class1 = {
  107378. 1, 16,
  107379. _huff_lengthlist_line_1024x27_class1,
  107380. 0, 0, 0, 0, 0,
  107381. NULL,
  107382. NULL,
  107383. NULL,
  107384. NULL,
  107385. 0
  107386. };
  107387. static long _huff_lengthlist_line_1024x27_class2[] = {
  107388. 1, 4, 2, 6, 3, 7, 5, 7,
  107389. };
  107390. static static_codebook _huff_book_line_1024x27_class2 = {
  107391. 1, 8,
  107392. _huff_lengthlist_line_1024x27_class2,
  107393. 0, 0, 0, 0, 0,
  107394. NULL,
  107395. NULL,
  107396. NULL,
  107397. NULL,
  107398. 0
  107399. };
  107400. static long _huff_lengthlist_line_1024x27_class3[] = {
  107401. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107402. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107403. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107404. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107405. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107406. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107407. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107408. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107409. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107410. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107411. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107412. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107413. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107414. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107415. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107416. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107417. };
  107418. static static_codebook _huff_book_line_1024x27_class3 = {
  107419. 1, 256,
  107420. _huff_lengthlist_line_1024x27_class3,
  107421. 0, 0, 0, 0, 0,
  107422. NULL,
  107423. NULL,
  107424. NULL,
  107425. NULL,
  107426. 0
  107427. };
  107428. static long _huff_lengthlist_line_1024x27_class4[] = {
  107429. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107430. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107431. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107432. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107433. };
  107434. static static_codebook _huff_book_line_1024x27_class4 = {
  107435. 1, 64,
  107436. _huff_lengthlist_line_1024x27_class4,
  107437. 0, 0, 0, 0, 0,
  107438. NULL,
  107439. NULL,
  107440. NULL,
  107441. NULL,
  107442. 0
  107443. };
  107444. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107445. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107446. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107447. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107448. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107449. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107450. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107451. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107452. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107453. };
  107454. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107455. 1, 128,
  107456. _huff_lengthlist_line_1024x27_0sub0,
  107457. 0, 0, 0, 0, 0,
  107458. NULL,
  107459. NULL,
  107460. NULL,
  107461. NULL,
  107462. 0
  107463. };
  107464. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107465. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107466. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107467. };
  107468. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107469. 1, 32,
  107470. _huff_lengthlist_line_1024x27_1sub0,
  107471. 0, 0, 0, 0, 0,
  107472. NULL,
  107473. NULL,
  107474. NULL,
  107475. NULL,
  107476. 0
  107477. };
  107478. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107481. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107482. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107483. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107484. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107485. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107486. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107487. };
  107488. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107489. 1, 128,
  107490. _huff_lengthlist_line_1024x27_1sub1,
  107491. 0, 0, 0, 0, 0,
  107492. NULL,
  107493. NULL,
  107494. NULL,
  107495. NULL,
  107496. 0
  107497. };
  107498. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107499. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107500. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107501. };
  107502. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107503. 1, 32,
  107504. _huff_lengthlist_line_1024x27_2sub0,
  107505. 0, 0, 0, 0, 0,
  107506. NULL,
  107507. NULL,
  107508. NULL,
  107509. NULL,
  107510. 0
  107511. };
  107512. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107515. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107516. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107517. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107518. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107519. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107520. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107521. };
  107522. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107523. 1, 128,
  107524. _huff_lengthlist_line_1024x27_2sub1,
  107525. 0, 0, 0, 0, 0,
  107526. NULL,
  107527. NULL,
  107528. NULL,
  107529. NULL,
  107530. 0
  107531. };
  107532. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107533. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107534. 5, 5,
  107535. };
  107536. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107537. 1, 18,
  107538. _huff_lengthlist_line_1024x27_3sub1,
  107539. 0, 0, 0, 0, 0,
  107540. NULL,
  107541. NULL,
  107542. NULL,
  107543. NULL,
  107544. 0
  107545. };
  107546. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107548. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107549. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107550. 9,11,
  107551. };
  107552. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107553. 1, 50,
  107554. _huff_lengthlist_line_1024x27_3sub2,
  107555. 0, 0, 0, 0, 0,
  107556. NULL,
  107557. NULL,
  107558. NULL,
  107559. NULL,
  107560. 0
  107561. };
  107562. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107566. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107567. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107568. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107569. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107570. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107571. };
  107572. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107573. 1, 128,
  107574. _huff_lengthlist_line_1024x27_3sub3,
  107575. 0, 0, 0, 0, 0,
  107576. NULL,
  107577. NULL,
  107578. NULL,
  107579. NULL,
  107580. 0
  107581. };
  107582. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107583. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107584. 5, 4,
  107585. };
  107586. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107587. 1, 18,
  107588. _huff_lengthlist_line_1024x27_4sub1,
  107589. 0, 0, 0, 0, 0,
  107590. NULL,
  107591. NULL,
  107592. NULL,
  107593. NULL,
  107594. 0
  107595. };
  107596. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107598. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107599. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107600. 9,12,
  107601. };
  107602. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107603. 1, 50,
  107604. _huff_lengthlist_line_1024x27_4sub2,
  107605. 0, 0, 0, 0, 0,
  107606. NULL,
  107607. NULL,
  107608. NULL,
  107609. NULL,
  107610. 0
  107611. };
  107612. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107616. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107617. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107618. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107619. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107620. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107621. };
  107622. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107623. 1, 128,
  107624. _huff_lengthlist_line_1024x27_4sub3,
  107625. 0, 0, 0, 0, 0,
  107626. NULL,
  107627. NULL,
  107628. NULL,
  107629. NULL,
  107630. 0
  107631. };
  107632. static long _huff_lengthlist_line_2048x27_class1[] = {
  107633. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107634. };
  107635. static static_codebook _huff_book_line_2048x27_class1 = {
  107636. 1, 16,
  107637. _huff_lengthlist_line_2048x27_class1,
  107638. 0, 0, 0, 0, 0,
  107639. NULL,
  107640. NULL,
  107641. NULL,
  107642. NULL,
  107643. 0
  107644. };
  107645. static long _huff_lengthlist_line_2048x27_class2[] = {
  107646. 1, 2, 3, 6, 4, 7, 5, 7,
  107647. };
  107648. static static_codebook _huff_book_line_2048x27_class2 = {
  107649. 1, 8,
  107650. _huff_lengthlist_line_2048x27_class2,
  107651. 0, 0, 0, 0, 0,
  107652. NULL,
  107653. NULL,
  107654. NULL,
  107655. NULL,
  107656. 0
  107657. };
  107658. static long _huff_lengthlist_line_2048x27_class3[] = {
  107659. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107660. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107661. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107662. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107663. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107664. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107665. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107666. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107667. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107668. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107669. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107670. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107671. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107672. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107673. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107674. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107675. };
  107676. static static_codebook _huff_book_line_2048x27_class3 = {
  107677. 1, 256,
  107678. _huff_lengthlist_line_2048x27_class3,
  107679. 0, 0, 0, 0, 0,
  107680. NULL,
  107681. NULL,
  107682. NULL,
  107683. NULL,
  107684. 0
  107685. };
  107686. static long _huff_lengthlist_line_2048x27_class4[] = {
  107687. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107688. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107689. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107690. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107691. };
  107692. static static_codebook _huff_book_line_2048x27_class4 = {
  107693. 1, 64,
  107694. _huff_lengthlist_line_2048x27_class4,
  107695. 0, 0, 0, 0, 0,
  107696. NULL,
  107697. NULL,
  107698. NULL,
  107699. NULL,
  107700. 0
  107701. };
  107702. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107703. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107704. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107705. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107706. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107707. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107708. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107709. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107710. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107711. };
  107712. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107713. 1, 128,
  107714. _huff_lengthlist_line_2048x27_0sub0,
  107715. 0, 0, 0, 0, 0,
  107716. NULL,
  107717. NULL,
  107718. NULL,
  107719. NULL,
  107720. 0
  107721. };
  107722. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107723. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107724. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107725. };
  107726. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107727. 1, 32,
  107728. _huff_lengthlist_line_2048x27_1sub0,
  107729. 0, 0, 0, 0, 0,
  107730. NULL,
  107731. NULL,
  107732. NULL,
  107733. NULL,
  107734. 0
  107735. };
  107736. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107739. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107740. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107741. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107742. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107743. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107744. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107745. };
  107746. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107747. 1, 128,
  107748. _huff_lengthlist_line_2048x27_1sub1,
  107749. 0, 0, 0, 0, 0,
  107750. NULL,
  107751. NULL,
  107752. NULL,
  107753. NULL,
  107754. 0
  107755. };
  107756. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107757. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107758. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107759. };
  107760. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107761. 1, 32,
  107762. _huff_lengthlist_line_2048x27_2sub0,
  107763. 0, 0, 0, 0, 0,
  107764. NULL,
  107765. NULL,
  107766. NULL,
  107767. NULL,
  107768. 0
  107769. };
  107770. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107773. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107774. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107775. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107776. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107777. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107778. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107779. };
  107780. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107781. 1, 128,
  107782. _huff_lengthlist_line_2048x27_2sub1,
  107783. 0, 0, 0, 0, 0,
  107784. NULL,
  107785. NULL,
  107786. NULL,
  107787. NULL,
  107788. 0
  107789. };
  107790. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107791. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107792. 5, 5,
  107793. };
  107794. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107795. 1, 18,
  107796. _huff_lengthlist_line_2048x27_3sub1,
  107797. 0, 0, 0, 0, 0,
  107798. NULL,
  107799. NULL,
  107800. NULL,
  107801. NULL,
  107802. 0
  107803. };
  107804. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107806. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107807. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107808. 10,12,
  107809. };
  107810. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107811. 1, 50,
  107812. _huff_lengthlist_line_2048x27_3sub2,
  107813. 0, 0, 0, 0, 0,
  107814. NULL,
  107815. NULL,
  107816. NULL,
  107817. NULL,
  107818. 0
  107819. };
  107820. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107824. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107825. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107826. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107827. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107828. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107829. };
  107830. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107831. 1, 128,
  107832. _huff_lengthlist_line_2048x27_3sub3,
  107833. 0, 0, 0, 0, 0,
  107834. NULL,
  107835. NULL,
  107836. NULL,
  107837. NULL,
  107838. 0
  107839. };
  107840. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107841. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107842. 4, 5,
  107843. };
  107844. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107845. 1, 18,
  107846. _huff_lengthlist_line_2048x27_4sub1,
  107847. 0, 0, 0, 0, 0,
  107848. NULL,
  107849. NULL,
  107850. NULL,
  107851. NULL,
  107852. 0
  107853. };
  107854. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107856. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107857. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107858. 10,10,
  107859. };
  107860. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107861. 1, 50,
  107862. _huff_lengthlist_line_2048x27_4sub2,
  107863. 0, 0, 0, 0, 0,
  107864. NULL,
  107865. NULL,
  107866. NULL,
  107867. NULL,
  107868. 0
  107869. };
  107870. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107874. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107875. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107876. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107877. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107878. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107879. };
  107880. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107881. 1, 128,
  107882. _huff_lengthlist_line_2048x27_4sub3,
  107883. 0, 0, 0, 0, 0,
  107884. NULL,
  107885. NULL,
  107886. NULL,
  107887. NULL,
  107888. 0
  107889. };
  107890. static long _huff_lengthlist_line_256x4low_class0[] = {
  107891. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107892. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107893. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107894. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107895. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107896. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107897. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107898. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107899. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107900. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107901. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107902. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107903. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107904. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107905. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107906. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107907. };
  107908. static static_codebook _huff_book_line_256x4low_class0 = {
  107909. 1, 256,
  107910. _huff_lengthlist_line_256x4low_class0,
  107911. 0, 0, 0, 0, 0,
  107912. NULL,
  107913. NULL,
  107914. NULL,
  107915. NULL,
  107916. 0
  107917. };
  107918. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107919. 1, 3, 2, 3,
  107920. };
  107921. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107922. 1, 4,
  107923. _huff_lengthlist_line_256x4low_0sub0,
  107924. 0, 0, 0, 0, 0,
  107925. NULL,
  107926. NULL,
  107927. NULL,
  107928. NULL,
  107929. 0
  107930. };
  107931. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  107932. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  107933. };
  107934. static static_codebook _huff_book_line_256x4low_0sub1 = {
  107935. 1, 10,
  107936. _huff_lengthlist_line_256x4low_0sub1,
  107937. 0, 0, 0, 0, 0,
  107938. NULL,
  107939. NULL,
  107940. NULL,
  107941. NULL,
  107942. 0
  107943. };
  107944. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  107945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  107946. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  107947. };
  107948. static static_codebook _huff_book_line_256x4low_0sub2 = {
  107949. 1, 25,
  107950. _huff_lengthlist_line_256x4low_0sub2,
  107951. 0, 0, 0, 0, 0,
  107952. NULL,
  107953. NULL,
  107954. NULL,
  107955. NULL,
  107956. 0
  107957. };
  107958. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  107959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  107961. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  107962. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  107963. };
  107964. static static_codebook _huff_book_line_256x4low_0sub3 = {
  107965. 1, 64,
  107966. _huff_lengthlist_line_256x4low_0sub3,
  107967. 0, 0, 0, 0, 0,
  107968. NULL,
  107969. NULL,
  107970. NULL,
  107971. NULL,
  107972. 0
  107973. };
  107974. /*** End of inlined file: floor_books.h ***/
  107975. static static_codebook *_floor_128x4_books[]={
  107976. &_huff_book_line_128x4_class0,
  107977. &_huff_book_line_128x4_0sub0,
  107978. &_huff_book_line_128x4_0sub1,
  107979. &_huff_book_line_128x4_0sub2,
  107980. &_huff_book_line_128x4_0sub3,
  107981. };
  107982. static static_codebook *_floor_256x4_books[]={
  107983. &_huff_book_line_256x4_class0,
  107984. &_huff_book_line_256x4_0sub0,
  107985. &_huff_book_line_256x4_0sub1,
  107986. &_huff_book_line_256x4_0sub2,
  107987. &_huff_book_line_256x4_0sub3,
  107988. };
  107989. static static_codebook *_floor_128x7_books[]={
  107990. &_huff_book_line_128x7_class0,
  107991. &_huff_book_line_128x7_class1,
  107992. &_huff_book_line_128x7_0sub1,
  107993. &_huff_book_line_128x7_0sub2,
  107994. &_huff_book_line_128x7_0sub3,
  107995. &_huff_book_line_128x7_1sub1,
  107996. &_huff_book_line_128x7_1sub2,
  107997. &_huff_book_line_128x7_1sub3,
  107998. };
  107999. static static_codebook *_floor_256x7_books[]={
  108000. &_huff_book_line_256x7_class0,
  108001. &_huff_book_line_256x7_class1,
  108002. &_huff_book_line_256x7_0sub1,
  108003. &_huff_book_line_256x7_0sub2,
  108004. &_huff_book_line_256x7_0sub3,
  108005. &_huff_book_line_256x7_1sub1,
  108006. &_huff_book_line_256x7_1sub2,
  108007. &_huff_book_line_256x7_1sub3,
  108008. };
  108009. static static_codebook *_floor_128x11_books[]={
  108010. &_huff_book_line_128x11_class1,
  108011. &_huff_book_line_128x11_class2,
  108012. &_huff_book_line_128x11_class3,
  108013. &_huff_book_line_128x11_0sub0,
  108014. &_huff_book_line_128x11_1sub0,
  108015. &_huff_book_line_128x11_1sub1,
  108016. &_huff_book_line_128x11_2sub1,
  108017. &_huff_book_line_128x11_2sub2,
  108018. &_huff_book_line_128x11_2sub3,
  108019. &_huff_book_line_128x11_3sub1,
  108020. &_huff_book_line_128x11_3sub2,
  108021. &_huff_book_line_128x11_3sub3,
  108022. };
  108023. static static_codebook *_floor_128x17_books[]={
  108024. &_huff_book_line_128x17_class1,
  108025. &_huff_book_line_128x17_class2,
  108026. &_huff_book_line_128x17_class3,
  108027. &_huff_book_line_128x17_0sub0,
  108028. &_huff_book_line_128x17_1sub0,
  108029. &_huff_book_line_128x17_1sub1,
  108030. &_huff_book_line_128x17_2sub1,
  108031. &_huff_book_line_128x17_2sub2,
  108032. &_huff_book_line_128x17_2sub3,
  108033. &_huff_book_line_128x17_3sub1,
  108034. &_huff_book_line_128x17_3sub2,
  108035. &_huff_book_line_128x17_3sub3,
  108036. };
  108037. static static_codebook *_floor_256x4low_books[]={
  108038. &_huff_book_line_256x4low_class0,
  108039. &_huff_book_line_256x4low_0sub0,
  108040. &_huff_book_line_256x4low_0sub1,
  108041. &_huff_book_line_256x4low_0sub2,
  108042. &_huff_book_line_256x4low_0sub3,
  108043. };
  108044. static static_codebook *_floor_1024x27_books[]={
  108045. &_huff_book_line_1024x27_class1,
  108046. &_huff_book_line_1024x27_class2,
  108047. &_huff_book_line_1024x27_class3,
  108048. &_huff_book_line_1024x27_class4,
  108049. &_huff_book_line_1024x27_0sub0,
  108050. &_huff_book_line_1024x27_1sub0,
  108051. &_huff_book_line_1024x27_1sub1,
  108052. &_huff_book_line_1024x27_2sub0,
  108053. &_huff_book_line_1024x27_2sub1,
  108054. &_huff_book_line_1024x27_3sub1,
  108055. &_huff_book_line_1024x27_3sub2,
  108056. &_huff_book_line_1024x27_3sub3,
  108057. &_huff_book_line_1024x27_4sub1,
  108058. &_huff_book_line_1024x27_4sub2,
  108059. &_huff_book_line_1024x27_4sub3,
  108060. };
  108061. static static_codebook *_floor_2048x27_books[]={
  108062. &_huff_book_line_2048x27_class1,
  108063. &_huff_book_line_2048x27_class2,
  108064. &_huff_book_line_2048x27_class3,
  108065. &_huff_book_line_2048x27_class4,
  108066. &_huff_book_line_2048x27_0sub0,
  108067. &_huff_book_line_2048x27_1sub0,
  108068. &_huff_book_line_2048x27_1sub1,
  108069. &_huff_book_line_2048x27_2sub0,
  108070. &_huff_book_line_2048x27_2sub1,
  108071. &_huff_book_line_2048x27_3sub1,
  108072. &_huff_book_line_2048x27_3sub2,
  108073. &_huff_book_line_2048x27_3sub3,
  108074. &_huff_book_line_2048x27_4sub1,
  108075. &_huff_book_line_2048x27_4sub2,
  108076. &_huff_book_line_2048x27_4sub3,
  108077. };
  108078. static static_codebook *_floor_512x17_books[]={
  108079. &_huff_book_line_512x17_class1,
  108080. &_huff_book_line_512x17_class2,
  108081. &_huff_book_line_512x17_class3,
  108082. &_huff_book_line_512x17_0sub0,
  108083. &_huff_book_line_512x17_1sub0,
  108084. &_huff_book_line_512x17_1sub1,
  108085. &_huff_book_line_512x17_2sub1,
  108086. &_huff_book_line_512x17_2sub2,
  108087. &_huff_book_line_512x17_2sub3,
  108088. &_huff_book_line_512x17_3sub1,
  108089. &_huff_book_line_512x17_3sub2,
  108090. &_huff_book_line_512x17_3sub3,
  108091. };
  108092. static static_codebook **_floor_books[10]={
  108093. _floor_128x4_books,
  108094. _floor_256x4_books,
  108095. _floor_128x7_books,
  108096. _floor_256x7_books,
  108097. _floor_128x11_books,
  108098. _floor_128x17_books,
  108099. _floor_256x4low_books,
  108100. _floor_1024x27_books,
  108101. _floor_2048x27_books,
  108102. _floor_512x17_books,
  108103. };
  108104. static vorbis_info_floor1 _floor[10]={
  108105. {
  108106. 1,{0},{4},{2},{0},
  108107. {{1,2,3,4}},
  108108. 4,{0,128, 33,8,16,70},
  108109. 60,30,500, 1.,18., -1
  108110. },
  108111. {
  108112. 1,{0},{4},{2},{0},
  108113. {{1,2,3,4}},
  108114. 4,{0,256, 66,16,32,140},
  108115. 60,30,500, 1.,18., -1
  108116. },
  108117. {
  108118. 2,{0,1},{3,4},{2,2},{0,1},
  108119. {{-1,2,3,4},{-1,5,6,7}},
  108120. 4,{0,128, 14,4,58, 2,8,28,90},
  108121. 60,30,500, 1.,18., -1
  108122. },
  108123. {
  108124. 2,{0,1},{3,4},{2,2},{0,1},
  108125. {{-1,2,3,4},{-1,5,6,7}},
  108126. 4,{0,256, 28,8,116, 4,16,56,180},
  108127. 60,30,500, 1.,18., -1
  108128. },
  108129. {
  108130. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108131. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108132. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108133. 60,30,500, 1,18., -1
  108134. },
  108135. {
  108136. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108137. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108138. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108139. 60,30,500, 1,18., -1
  108140. },
  108141. {
  108142. 1,{0},{4},{2},{0},
  108143. {{1,2,3,4}},
  108144. 4,{0,256, 66,16,32,140},
  108145. 60,30,500, 1.,18., -1
  108146. },
  108147. {
  108148. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108149. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108150. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108151. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108152. 60,30,500, 3,18., -1 /* lowpass */
  108153. },
  108154. {
  108155. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108156. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108157. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108158. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108159. 60,30,500, 3,18., -1 /* lowpass */
  108160. },
  108161. {
  108162. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108163. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108164. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108165. 7,23,39, 55,79,110, 156,232,360},
  108166. 60,30,500, 1,18., -1 /* lowpass! */
  108167. },
  108168. };
  108169. /*** End of inlined file: floor_all.h ***/
  108170. /*** Start of inlined file: residue_44.h ***/
  108171. /*** Start of inlined file: res_books_stereo.h ***/
  108172. static long _vq_quantlist__16c0_s_p1_0[] = {
  108173. 1,
  108174. 0,
  108175. 2,
  108176. };
  108177. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108178. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108179. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108183. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108184. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108188. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108189. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108224. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108229. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108234. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108251. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108256. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108261. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108270. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108275. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108280. 0, 0, 0, 0, 0, 0, 9,12, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  108296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108297. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  108301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  108589. };
  108590. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108591. -0.5, 0.5,
  108592. };
  108593. static long _vq_quantmap__16c0_s_p1_0[] = {
  108594. 1, 0, 2,
  108595. };
  108596. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108597. _vq_quantthresh__16c0_s_p1_0,
  108598. _vq_quantmap__16c0_s_p1_0,
  108599. 3,
  108600. 3
  108601. };
  108602. static static_codebook _16c0_s_p1_0 = {
  108603. 8, 6561,
  108604. _vq_lengthlist__16c0_s_p1_0,
  108605. 1, -535822336, 1611661312, 2, 0,
  108606. _vq_quantlist__16c0_s_p1_0,
  108607. NULL,
  108608. &_vq_auxt__16c0_s_p1_0,
  108609. NULL,
  108610. 0
  108611. };
  108612. static long _vq_quantlist__16c0_s_p2_0[] = {
  108613. 2,
  108614. 1,
  108615. 3,
  108616. 0,
  108617. 4,
  108618. };
  108619. static long _vq_lengthlist__16c0_s_p2_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,
  108660. };
  108661. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108662. -1.5, -0.5, 0.5, 1.5,
  108663. };
  108664. static long _vq_quantmap__16c0_s_p2_0[] = {
  108665. 3, 1, 0, 2, 4,
  108666. };
  108667. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108668. _vq_quantthresh__16c0_s_p2_0,
  108669. _vq_quantmap__16c0_s_p2_0,
  108670. 5,
  108671. 5
  108672. };
  108673. static static_codebook _16c0_s_p2_0 = {
  108674. 4, 625,
  108675. _vq_lengthlist__16c0_s_p2_0,
  108676. 1, -533725184, 1611661312, 3, 0,
  108677. _vq_quantlist__16c0_s_p2_0,
  108678. NULL,
  108679. &_vq_auxt__16c0_s_p2_0,
  108680. NULL,
  108681. 0
  108682. };
  108683. static long _vq_quantlist__16c0_s_p3_0[] = {
  108684. 2,
  108685. 1,
  108686. 3,
  108687. 0,
  108688. 4,
  108689. };
  108690. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108691. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108694. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108697. 0, 0, 0, 0, 6, 6, 6, 9, 9, 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,
  108731. };
  108732. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108733. -1.5, -0.5, 0.5, 1.5,
  108734. };
  108735. static long _vq_quantmap__16c0_s_p3_0[] = {
  108736. 3, 1, 0, 2, 4,
  108737. };
  108738. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108739. _vq_quantthresh__16c0_s_p3_0,
  108740. _vq_quantmap__16c0_s_p3_0,
  108741. 5,
  108742. 5
  108743. };
  108744. static static_codebook _16c0_s_p3_0 = {
  108745. 4, 625,
  108746. _vq_lengthlist__16c0_s_p3_0,
  108747. 1, -533725184, 1611661312, 3, 0,
  108748. _vq_quantlist__16c0_s_p3_0,
  108749. NULL,
  108750. &_vq_auxt__16c0_s_p3_0,
  108751. NULL,
  108752. 0
  108753. };
  108754. static long _vq_quantlist__16c0_s_p4_0[] = {
  108755. 4,
  108756. 3,
  108757. 5,
  108758. 2,
  108759. 6,
  108760. 1,
  108761. 7,
  108762. 0,
  108763. 8,
  108764. };
  108765. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108766. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108767. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108768. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108769. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108770. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108771. 0,
  108772. };
  108773. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108774. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108775. };
  108776. static long _vq_quantmap__16c0_s_p4_0[] = {
  108777. 7, 5, 3, 1, 0, 2, 4, 6,
  108778. 8,
  108779. };
  108780. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108781. _vq_quantthresh__16c0_s_p4_0,
  108782. _vq_quantmap__16c0_s_p4_0,
  108783. 9,
  108784. 9
  108785. };
  108786. static static_codebook _16c0_s_p4_0 = {
  108787. 2, 81,
  108788. _vq_lengthlist__16c0_s_p4_0,
  108789. 1, -531628032, 1611661312, 4, 0,
  108790. _vq_quantlist__16c0_s_p4_0,
  108791. NULL,
  108792. &_vq_auxt__16c0_s_p4_0,
  108793. NULL,
  108794. 0
  108795. };
  108796. static long _vq_quantlist__16c0_s_p5_0[] = {
  108797. 4,
  108798. 3,
  108799. 5,
  108800. 2,
  108801. 6,
  108802. 1,
  108803. 7,
  108804. 0,
  108805. 8,
  108806. };
  108807. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108808. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108809. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108810. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108811. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108812. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108813. 10,
  108814. };
  108815. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108816. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108817. };
  108818. static long _vq_quantmap__16c0_s_p5_0[] = {
  108819. 7, 5, 3, 1, 0, 2, 4, 6,
  108820. 8,
  108821. };
  108822. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108823. _vq_quantthresh__16c0_s_p5_0,
  108824. _vq_quantmap__16c0_s_p5_0,
  108825. 9,
  108826. 9
  108827. };
  108828. static static_codebook _16c0_s_p5_0 = {
  108829. 2, 81,
  108830. _vq_lengthlist__16c0_s_p5_0,
  108831. 1, -531628032, 1611661312, 4, 0,
  108832. _vq_quantlist__16c0_s_p5_0,
  108833. NULL,
  108834. &_vq_auxt__16c0_s_p5_0,
  108835. NULL,
  108836. 0
  108837. };
  108838. static long _vq_quantlist__16c0_s_p6_0[] = {
  108839. 8,
  108840. 7,
  108841. 9,
  108842. 6,
  108843. 10,
  108844. 5,
  108845. 11,
  108846. 4,
  108847. 12,
  108848. 3,
  108849. 13,
  108850. 2,
  108851. 14,
  108852. 1,
  108853. 15,
  108854. 0,
  108855. 16,
  108856. };
  108857. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108858. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108859. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108860. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108861. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108862. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108863. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108864. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108865. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108866. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108867. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108868. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108869. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108870. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108871. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108872. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108873. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108874. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108875. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108876. 14,
  108877. };
  108878. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108879. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108880. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108881. };
  108882. static long _vq_quantmap__16c0_s_p6_0[] = {
  108883. 15, 13, 11, 9, 7, 5, 3, 1,
  108884. 0, 2, 4, 6, 8, 10, 12, 14,
  108885. 16,
  108886. };
  108887. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108888. _vq_quantthresh__16c0_s_p6_0,
  108889. _vq_quantmap__16c0_s_p6_0,
  108890. 17,
  108891. 17
  108892. };
  108893. static static_codebook _16c0_s_p6_0 = {
  108894. 2, 289,
  108895. _vq_lengthlist__16c0_s_p6_0,
  108896. 1, -529530880, 1611661312, 5, 0,
  108897. _vq_quantlist__16c0_s_p6_0,
  108898. NULL,
  108899. &_vq_auxt__16c0_s_p6_0,
  108900. NULL,
  108901. 0
  108902. };
  108903. static long _vq_quantlist__16c0_s_p7_0[] = {
  108904. 1,
  108905. 0,
  108906. 2,
  108907. };
  108908. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108909. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108910. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108911. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108912. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108913. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108914. 13,
  108915. };
  108916. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108917. -5.5, 5.5,
  108918. };
  108919. static long _vq_quantmap__16c0_s_p7_0[] = {
  108920. 1, 0, 2,
  108921. };
  108922. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108923. _vq_quantthresh__16c0_s_p7_0,
  108924. _vq_quantmap__16c0_s_p7_0,
  108925. 3,
  108926. 3
  108927. };
  108928. static static_codebook _16c0_s_p7_0 = {
  108929. 4, 81,
  108930. _vq_lengthlist__16c0_s_p7_0,
  108931. 1, -529137664, 1618345984, 2, 0,
  108932. _vq_quantlist__16c0_s_p7_0,
  108933. NULL,
  108934. &_vq_auxt__16c0_s_p7_0,
  108935. NULL,
  108936. 0
  108937. };
  108938. static long _vq_quantlist__16c0_s_p7_1[] = {
  108939. 5,
  108940. 4,
  108941. 6,
  108942. 3,
  108943. 7,
  108944. 2,
  108945. 8,
  108946. 1,
  108947. 9,
  108948. 0,
  108949. 10,
  108950. };
  108951. static long _vq_lengthlist__16c0_s_p7_1[] = {
  108952. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  108953. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  108954. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  108955. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  108956. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  108957. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  108958. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  108959. 11,11,11, 9, 9, 9, 9,10,10,
  108960. };
  108961. static float _vq_quantthresh__16c0_s_p7_1[] = {
  108962. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  108963. 3.5, 4.5,
  108964. };
  108965. static long _vq_quantmap__16c0_s_p7_1[] = {
  108966. 9, 7, 5, 3, 1, 0, 2, 4,
  108967. 6, 8, 10,
  108968. };
  108969. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  108970. _vq_quantthresh__16c0_s_p7_1,
  108971. _vq_quantmap__16c0_s_p7_1,
  108972. 11,
  108973. 11
  108974. };
  108975. static static_codebook _16c0_s_p7_1 = {
  108976. 2, 121,
  108977. _vq_lengthlist__16c0_s_p7_1,
  108978. 1, -531365888, 1611661312, 4, 0,
  108979. _vq_quantlist__16c0_s_p7_1,
  108980. NULL,
  108981. &_vq_auxt__16c0_s_p7_1,
  108982. NULL,
  108983. 0
  108984. };
  108985. static long _vq_quantlist__16c0_s_p8_0[] = {
  108986. 6,
  108987. 5,
  108988. 7,
  108989. 4,
  108990. 8,
  108991. 3,
  108992. 9,
  108993. 2,
  108994. 10,
  108995. 1,
  108996. 11,
  108997. 0,
  108998. 12,
  108999. };
  109000. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109001. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109002. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109003. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109004. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109005. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109006. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109007. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109008. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109009. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109010. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109011. 0,12,13,13,12,13,14,14,14,
  109012. };
  109013. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109014. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109015. 12.5, 17.5, 22.5, 27.5,
  109016. };
  109017. static long _vq_quantmap__16c0_s_p8_0[] = {
  109018. 11, 9, 7, 5, 3, 1, 0, 2,
  109019. 4, 6, 8, 10, 12,
  109020. };
  109021. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109022. _vq_quantthresh__16c0_s_p8_0,
  109023. _vq_quantmap__16c0_s_p8_0,
  109024. 13,
  109025. 13
  109026. };
  109027. static static_codebook _16c0_s_p8_0 = {
  109028. 2, 169,
  109029. _vq_lengthlist__16c0_s_p8_0,
  109030. 1, -526516224, 1616117760, 4, 0,
  109031. _vq_quantlist__16c0_s_p8_0,
  109032. NULL,
  109033. &_vq_auxt__16c0_s_p8_0,
  109034. NULL,
  109035. 0
  109036. };
  109037. static long _vq_quantlist__16c0_s_p8_1[] = {
  109038. 2,
  109039. 1,
  109040. 3,
  109041. 0,
  109042. 4,
  109043. };
  109044. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109045. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109046. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109047. };
  109048. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109049. -1.5, -0.5, 0.5, 1.5,
  109050. };
  109051. static long _vq_quantmap__16c0_s_p8_1[] = {
  109052. 3, 1, 0, 2, 4,
  109053. };
  109054. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109055. _vq_quantthresh__16c0_s_p8_1,
  109056. _vq_quantmap__16c0_s_p8_1,
  109057. 5,
  109058. 5
  109059. };
  109060. static static_codebook _16c0_s_p8_1 = {
  109061. 2, 25,
  109062. _vq_lengthlist__16c0_s_p8_1,
  109063. 1, -533725184, 1611661312, 3, 0,
  109064. _vq_quantlist__16c0_s_p8_1,
  109065. NULL,
  109066. &_vq_auxt__16c0_s_p8_1,
  109067. NULL,
  109068. 0
  109069. };
  109070. static long _vq_quantlist__16c0_s_p9_0[] = {
  109071. 1,
  109072. 0,
  109073. 2,
  109074. };
  109075. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109076. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109077. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109078. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109079. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109080. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109081. 7,
  109082. };
  109083. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109084. -157.5, 157.5,
  109085. };
  109086. static long _vq_quantmap__16c0_s_p9_0[] = {
  109087. 1, 0, 2,
  109088. };
  109089. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109090. _vq_quantthresh__16c0_s_p9_0,
  109091. _vq_quantmap__16c0_s_p9_0,
  109092. 3,
  109093. 3
  109094. };
  109095. static static_codebook _16c0_s_p9_0 = {
  109096. 4, 81,
  109097. _vq_lengthlist__16c0_s_p9_0,
  109098. 1, -518803456, 1628680192, 2, 0,
  109099. _vq_quantlist__16c0_s_p9_0,
  109100. NULL,
  109101. &_vq_auxt__16c0_s_p9_0,
  109102. NULL,
  109103. 0
  109104. };
  109105. static long _vq_quantlist__16c0_s_p9_1[] = {
  109106. 7,
  109107. 6,
  109108. 8,
  109109. 5,
  109110. 9,
  109111. 4,
  109112. 10,
  109113. 3,
  109114. 11,
  109115. 2,
  109116. 12,
  109117. 1,
  109118. 13,
  109119. 0,
  109120. 14,
  109121. };
  109122. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109123. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109124. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109125. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109126. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109127. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109128. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109129. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109130. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109131. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109132. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109133. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109134. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109135. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109136. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109137. 10,
  109138. };
  109139. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109140. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109141. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109142. };
  109143. static long _vq_quantmap__16c0_s_p9_1[] = {
  109144. 13, 11, 9, 7, 5, 3, 1, 0,
  109145. 2, 4, 6, 8, 10, 12, 14,
  109146. };
  109147. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109148. _vq_quantthresh__16c0_s_p9_1,
  109149. _vq_quantmap__16c0_s_p9_1,
  109150. 15,
  109151. 15
  109152. };
  109153. static static_codebook _16c0_s_p9_1 = {
  109154. 2, 225,
  109155. _vq_lengthlist__16c0_s_p9_1,
  109156. 1, -520986624, 1620377600, 4, 0,
  109157. _vq_quantlist__16c0_s_p9_1,
  109158. NULL,
  109159. &_vq_auxt__16c0_s_p9_1,
  109160. NULL,
  109161. 0
  109162. };
  109163. static long _vq_quantlist__16c0_s_p9_2[] = {
  109164. 10,
  109165. 9,
  109166. 11,
  109167. 8,
  109168. 12,
  109169. 7,
  109170. 13,
  109171. 6,
  109172. 14,
  109173. 5,
  109174. 15,
  109175. 4,
  109176. 16,
  109177. 3,
  109178. 17,
  109179. 2,
  109180. 18,
  109181. 1,
  109182. 19,
  109183. 0,
  109184. 20,
  109185. };
  109186. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109187. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109188. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109189. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109190. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109191. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109192. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109193. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109194. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109195. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109196. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109197. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109198. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109199. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109200. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109201. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109202. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109203. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109204. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109205. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109206. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109207. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109208. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109209. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109210. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109211. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109212. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109213. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109214. 10,11,10,10,11, 9,10,10,10,
  109215. };
  109216. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109217. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109218. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109219. 6.5, 7.5, 8.5, 9.5,
  109220. };
  109221. static long _vq_quantmap__16c0_s_p9_2[] = {
  109222. 19, 17, 15, 13, 11, 9, 7, 5,
  109223. 3, 1, 0, 2, 4, 6, 8, 10,
  109224. 12, 14, 16, 18, 20,
  109225. };
  109226. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109227. _vq_quantthresh__16c0_s_p9_2,
  109228. _vq_quantmap__16c0_s_p9_2,
  109229. 21,
  109230. 21
  109231. };
  109232. static static_codebook _16c0_s_p9_2 = {
  109233. 2, 441,
  109234. _vq_lengthlist__16c0_s_p9_2,
  109235. 1, -529268736, 1611661312, 5, 0,
  109236. _vq_quantlist__16c0_s_p9_2,
  109237. NULL,
  109238. &_vq_auxt__16c0_s_p9_2,
  109239. NULL,
  109240. 0
  109241. };
  109242. static long _huff_lengthlist__16c0_s_single[] = {
  109243. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109244. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109245. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109246. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109247. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109248. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109249. 16,16,18,18,
  109250. };
  109251. static static_codebook _huff_book__16c0_s_single = {
  109252. 2, 100,
  109253. _huff_lengthlist__16c0_s_single,
  109254. 0, 0, 0, 0, 0,
  109255. NULL,
  109256. NULL,
  109257. NULL,
  109258. NULL,
  109259. 0
  109260. };
  109261. static long _huff_lengthlist__16c1_s_long[] = {
  109262. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109263. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109264. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109265. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109266. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109267. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109268. 12,11,11,13,
  109269. };
  109270. static static_codebook _huff_book__16c1_s_long = {
  109271. 2, 100,
  109272. _huff_lengthlist__16c1_s_long,
  109273. 0, 0, 0, 0, 0,
  109274. NULL,
  109275. NULL,
  109276. NULL,
  109277. NULL,
  109278. 0
  109279. };
  109280. static long _vq_quantlist__16c1_s_p1_0[] = {
  109281. 1,
  109282. 0,
  109283. 2,
  109284. };
  109285. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109286. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109287. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109291. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109292. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109296. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109297. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109332. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109337. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109342. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109359. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109364. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109369. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109378. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109383. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109388. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  109404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109405. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  109409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  109697. };
  109698. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109699. -0.5, 0.5,
  109700. };
  109701. static long _vq_quantmap__16c1_s_p1_0[] = {
  109702. 1, 0, 2,
  109703. };
  109704. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109705. _vq_quantthresh__16c1_s_p1_0,
  109706. _vq_quantmap__16c1_s_p1_0,
  109707. 3,
  109708. 3
  109709. };
  109710. static static_codebook _16c1_s_p1_0 = {
  109711. 8, 6561,
  109712. _vq_lengthlist__16c1_s_p1_0,
  109713. 1, -535822336, 1611661312, 2, 0,
  109714. _vq_quantlist__16c1_s_p1_0,
  109715. NULL,
  109716. &_vq_auxt__16c1_s_p1_0,
  109717. NULL,
  109718. 0
  109719. };
  109720. static long _vq_quantlist__16c1_s_p2_0[] = {
  109721. 2,
  109722. 1,
  109723. 3,
  109724. 0,
  109725. 4,
  109726. };
  109727. static long _vq_lengthlist__16c1_s_p2_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,
  109768. };
  109769. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109770. -1.5, -0.5, 0.5, 1.5,
  109771. };
  109772. static long _vq_quantmap__16c1_s_p2_0[] = {
  109773. 3, 1, 0, 2, 4,
  109774. };
  109775. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109776. _vq_quantthresh__16c1_s_p2_0,
  109777. _vq_quantmap__16c1_s_p2_0,
  109778. 5,
  109779. 5
  109780. };
  109781. static static_codebook _16c1_s_p2_0 = {
  109782. 4, 625,
  109783. _vq_lengthlist__16c1_s_p2_0,
  109784. 1, -533725184, 1611661312, 3, 0,
  109785. _vq_quantlist__16c1_s_p2_0,
  109786. NULL,
  109787. &_vq_auxt__16c1_s_p2_0,
  109788. NULL,
  109789. 0
  109790. };
  109791. static long _vq_quantlist__16c1_s_p3_0[] = {
  109792. 2,
  109793. 1,
  109794. 3,
  109795. 0,
  109796. 4,
  109797. };
  109798. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109799. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109802. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109805. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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,
  109839. };
  109840. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109841. -1.5, -0.5, 0.5, 1.5,
  109842. };
  109843. static long _vq_quantmap__16c1_s_p3_0[] = {
  109844. 3, 1, 0, 2, 4,
  109845. };
  109846. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109847. _vq_quantthresh__16c1_s_p3_0,
  109848. _vq_quantmap__16c1_s_p3_0,
  109849. 5,
  109850. 5
  109851. };
  109852. static static_codebook _16c1_s_p3_0 = {
  109853. 4, 625,
  109854. _vq_lengthlist__16c1_s_p3_0,
  109855. 1, -533725184, 1611661312, 3, 0,
  109856. _vq_quantlist__16c1_s_p3_0,
  109857. NULL,
  109858. &_vq_auxt__16c1_s_p3_0,
  109859. NULL,
  109860. 0
  109861. };
  109862. static long _vq_quantlist__16c1_s_p4_0[] = {
  109863. 4,
  109864. 3,
  109865. 5,
  109866. 2,
  109867. 6,
  109868. 1,
  109869. 7,
  109870. 0,
  109871. 8,
  109872. };
  109873. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109874. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109875. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109876. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109877. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109878. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109879. 0,
  109880. };
  109881. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109882. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109883. };
  109884. static long _vq_quantmap__16c1_s_p4_0[] = {
  109885. 7, 5, 3, 1, 0, 2, 4, 6,
  109886. 8,
  109887. };
  109888. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109889. _vq_quantthresh__16c1_s_p4_0,
  109890. _vq_quantmap__16c1_s_p4_0,
  109891. 9,
  109892. 9
  109893. };
  109894. static static_codebook _16c1_s_p4_0 = {
  109895. 2, 81,
  109896. _vq_lengthlist__16c1_s_p4_0,
  109897. 1, -531628032, 1611661312, 4, 0,
  109898. _vq_quantlist__16c1_s_p4_0,
  109899. NULL,
  109900. &_vq_auxt__16c1_s_p4_0,
  109901. NULL,
  109902. 0
  109903. };
  109904. static long _vq_quantlist__16c1_s_p5_0[] = {
  109905. 4,
  109906. 3,
  109907. 5,
  109908. 2,
  109909. 6,
  109910. 1,
  109911. 7,
  109912. 0,
  109913. 8,
  109914. };
  109915. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109916. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109917. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109918. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109919. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109920. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109921. 10,
  109922. };
  109923. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109924. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109925. };
  109926. static long _vq_quantmap__16c1_s_p5_0[] = {
  109927. 7, 5, 3, 1, 0, 2, 4, 6,
  109928. 8,
  109929. };
  109930. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  109931. _vq_quantthresh__16c1_s_p5_0,
  109932. _vq_quantmap__16c1_s_p5_0,
  109933. 9,
  109934. 9
  109935. };
  109936. static static_codebook _16c1_s_p5_0 = {
  109937. 2, 81,
  109938. _vq_lengthlist__16c1_s_p5_0,
  109939. 1, -531628032, 1611661312, 4, 0,
  109940. _vq_quantlist__16c1_s_p5_0,
  109941. NULL,
  109942. &_vq_auxt__16c1_s_p5_0,
  109943. NULL,
  109944. 0
  109945. };
  109946. static long _vq_quantlist__16c1_s_p6_0[] = {
  109947. 8,
  109948. 7,
  109949. 9,
  109950. 6,
  109951. 10,
  109952. 5,
  109953. 11,
  109954. 4,
  109955. 12,
  109956. 3,
  109957. 13,
  109958. 2,
  109959. 14,
  109960. 1,
  109961. 15,
  109962. 0,
  109963. 16,
  109964. };
  109965. static long _vq_lengthlist__16c1_s_p6_0[] = {
  109966. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  109967. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  109968. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  109969. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  109970. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  109971. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109972. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109973. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109974. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  109975. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109976. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  109977. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  109978. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  109979. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  109980. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  109981. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  109982. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  109983. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  109984. 14,
  109985. };
  109986. static float _vq_quantthresh__16c1_s_p6_0[] = {
  109987. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109988. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109989. };
  109990. static long _vq_quantmap__16c1_s_p6_0[] = {
  109991. 15, 13, 11, 9, 7, 5, 3, 1,
  109992. 0, 2, 4, 6, 8, 10, 12, 14,
  109993. 16,
  109994. };
  109995. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  109996. _vq_quantthresh__16c1_s_p6_0,
  109997. _vq_quantmap__16c1_s_p6_0,
  109998. 17,
  109999. 17
  110000. };
  110001. static static_codebook _16c1_s_p6_0 = {
  110002. 2, 289,
  110003. _vq_lengthlist__16c1_s_p6_0,
  110004. 1, -529530880, 1611661312, 5, 0,
  110005. _vq_quantlist__16c1_s_p6_0,
  110006. NULL,
  110007. &_vq_auxt__16c1_s_p6_0,
  110008. NULL,
  110009. 0
  110010. };
  110011. static long _vq_quantlist__16c1_s_p7_0[] = {
  110012. 1,
  110013. 0,
  110014. 2,
  110015. };
  110016. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110017. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110018. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110019. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110020. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110021. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110022. 11,
  110023. };
  110024. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110025. -5.5, 5.5,
  110026. };
  110027. static long _vq_quantmap__16c1_s_p7_0[] = {
  110028. 1, 0, 2,
  110029. };
  110030. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110031. _vq_quantthresh__16c1_s_p7_0,
  110032. _vq_quantmap__16c1_s_p7_0,
  110033. 3,
  110034. 3
  110035. };
  110036. static static_codebook _16c1_s_p7_0 = {
  110037. 4, 81,
  110038. _vq_lengthlist__16c1_s_p7_0,
  110039. 1, -529137664, 1618345984, 2, 0,
  110040. _vq_quantlist__16c1_s_p7_0,
  110041. NULL,
  110042. &_vq_auxt__16c1_s_p7_0,
  110043. NULL,
  110044. 0
  110045. };
  110046. static long _vq_quantlist__16c1_s_p7_1[] = {
  110047. 5,
  110048. 4,
  110049. 6,
  110050. 3,
  110051. 7,
  110052. 2,
  110053. 8,
  110054. 1,
  110055. 9,
  110056. 0,
  110057. 10,
  110058. };
  110059. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110060. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110061. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110062. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110063. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110064. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110065. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110066. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110067. 10,10,10, 8, 8, 8, 8, 9, 9,
  110068. };
  110069. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110070. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110071. 3.5, 4.5,
  110072. };
  110073. static long _vq_quantmap__16c1_s_p7_1[] = {
  110074. 9, 7, 5, 3, 1, 0, 2, 4,
  110075. 6, 8, 10,
  110076. };
  110077. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110078. _vq_quantthresh__16c1_s_p7_1,
  110079. _vq_quantmap__16c1_s_p7_1,
  110080. 11,
  110081. 11
  110082. };
  110083. static static_codebook _16c1_s_p7_1 = {
  110084. 2, 121,
  110085. _vq_lengthlist__16c1_s_p7_1,
  110086. 1, -531365888, 1611661312, 4, 0,
  110087. _vq_quantlist__16c1_s_p7_1,
  110088. NULL,
  110089. &_vq_auxt__16c1_s_p7_1,
  110090. NULL,
  110091. 0
  110092. };
  110093. static long _vq_quantlist__16c1_s_p8_0[] = {
  110094. 6,
  110095. 5,
  110096. 7,
  110097. 4,
  110098. 8,
  110099. 3,
  110100. 9,
  110101. 2,
  110102. 10,
  110103. 1,
  110104. 11,
  110105. 0,
  110106. 12,
  110107. };
  110108. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110109. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110110. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110111. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110112. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110113. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110114. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110115. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110116. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110117. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110118. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110119. 0,12,12,12,12,13,13,14,15,
  110120. };
  110121. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110122. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110123. 12.5, 17.5, 22.5, 27.5,
  110124. };
  110125. static long _vq_quantmap__16c1_s_p8_0[] = {
  110126. 11, 9, 7, 5, 3, 1, 0, 2,
  110127. 4, 6, 8, 10, 12,
  110128. };
  110129. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110130. _vq_quantthresh__16c1_s_p8_0,
  110131. _vq_quantmap__16c1_s_p8_0,
  110132. 13,
  110133. 13
  110134. };
  110135. static static_codebook _16c1_s_p8_0 = {
  110136. 2, 169,
  110137. _vq_lengthlist__16c1_s_p8_0,
  110138. 1, -526516224, 1616117760, 4, 0,
  110139. _vq_quantlist__16c1_s_p8_0,
  110140. NULL,
  110141. &_vq_auxt__16c1_s_p8_0,
  110142. NULL,
  110143. 0
  110144. };
  110145. static long _vq_quantlist__16c1_s_p8_1[] = {
  110146. 2,
  110147. 1,
  110148. 3,
  110149. 0,
  110150. 4,
  110151. };
  110152. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110153. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110154. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110155. };
  110156. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110157. -1.5, -0.5, 0.5, 1.5,
  110158. };
  110159. static long _vq_quantmap__16c1_s_p8_1[] = {
  110160. 3, 1, 0, 2, 4,
  110161. };
  110162. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110163. _vq_quantthresh__16c1_s_p8_1,
  110164. _vq_quantmap__16c1_s_p8_1,
  110165. 5,
  110166. 5
  110167. };
  110168. static static_codebook _16c1_s_p8_1 = {
  110169. 2, 25,
  110170. _vq_lengthlist__16c1_s_p8_1,
  110171. 1, -533725184, 1611661312, 3, 0,
  110172. _vq_quantlist__16c1_s_p8_1,
  110173. NULL,
  110174. &_vq_auxt__16c1_s_p8_1,
  110175. NULL,
  110176. 0
  110177. };
  110178. static long _vq_quantlist__16c1_s_p9_0[] = {
  110179. 6,
  110180. 5,
  110181. 7,
  110182. 4,
  110183. 8,
  110184. 3,
  110185. 9,
  110186. 2,
  110187. 10,
  110188. 1,
  110189. 11,
  110190. 0,
  110191. 12,
  110192. };
  110193. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110194. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110195. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110196. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110197. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110198. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110199. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110200. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110201. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110202. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110203. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110204. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110205. };
  110206. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110207. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110208. 787.5, 1102.5, 1417.5, 1732.5,
  110209. };
  110210. static long _vq_quantmap__16c1_s_p9_0[] = {
  110211. 11, 9, 7, 5, 3, 1, 0, 2,
  110212. 4, 6, 8, 10, 12,
  110213. };
  110214. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110215. _vq_quantthresh__16c1_s_p9_0,
  110216. _vq_quantmap__16c1_s_p9_0,
  110217. 13,
  110218. 13
  110219. };
  110220. static static_codebook _16c1_s_p9_0 = {
  110221. 2, 169,
  110222. _vq_lengthlist__16c1_s_p9_0,
  110223. 1, -513964032, 1628680192, 4, 0,
  110224. _vq_quantlist__16c1_s_p9_0,
  110225. NULL,
  110226. &_vq_auxt__16c1_s_p9_0,
  110227. NULL,
  110228. 0
  110229. };
  110230. static long _vq_quantlist__16c1_s_p9_1[] = {
  110231. 7,
  110232. 6,
  110233. 8,
  110234. 5,
  110235. 9,
  110236. 4,
  110237. 10,
  110238. 3,
  110239. 11,
  110240. 2,
  110241. 12,
  110242. 1,
  110243. 13,
  110244. 0,
  110245. 14,
  110246. };
  110247. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110248. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110249. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110250. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110251. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110252. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110253. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110254. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110255. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110256. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110257. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110258. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110259. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110260. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110261. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110262. 13,
  110263. };
  110264. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110265. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110266. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110267. };
  110268. static long _vq_quantmap__16c1_s_p9_1[] = {
  110269. 13, 11, 9, 7, 5, 3, 1, 0,
  110270. 2, 4, 6, 8, 10, 12, 14,
  110271. };
  110272. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110273. _vq_quantthresh__16c1_s_p9_1,
  110274. _vq_quantmap__16c1_s_p9_1,
  110275. 15,
  110276. 15
  110277. };
  110278. static static_codebook _16c1_s_p9_1 = {
  110279. 2, 225,
  110280. _vq_lengthlist__16c1_s_p9_1,
  110281. 1, -520986624, 1620377600, 4, 0,
  110282. _vq_quantlist__16c1_s_p9_1,
  110283. NULL,
  110284. &_vq_auxt__16c1_s_p9_1,
  110285. NULL,
  110286. 0
  110287. };
  110288. static long _vq_quantlist__16c1_s_p9_2[] = {
  110289. 10,
  110290. 9,
  110291. 11,
  110292. 8,
  110293. 12,
  110294. 7,
  110295. 13,
  110296. 6,
  110297. 14,
  110298. 5,
  110299. 15,
  110300. 4,
  110301. 16,
  110302. 3,
  110303. 17,
  110304. 2,
  110305. 18,
  110306. 1,
  110307. 19,
  110308. 0,
  110309. 20,
  110310. };
  110311. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110312. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110313. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110314. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110315. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110316. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110317. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110318. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110319. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110320. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110321. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110322. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110323. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110324. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110325. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110326. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110327. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110328. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110329. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110330. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110331. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110332. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110333. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110334. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110335. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110336. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110337. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110338. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110339. 11,11,11,11,12,11,11,12,11,
  110340. };
  110341. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110342. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110343. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110344. 6.5, 7.5, 8.5, 9.5,
  110345. };
  110346. static long _vq_quantmap__16c1_s_p9_2[] = {
  110347. 19, 17, 15, 13, 11, 9, 7, 5,
  110348. 3, 1, 0, 2, 4, 6, 8, 10,
  110349. 12, 14, 16, 18, 20,
  110350. };
  110351. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110352. _vq_quantthresh__16c1_s_p9_2,
  110353. _vq_quantmap__16c1_s_p9_2,
  110354. 21,
  110355. 21
  110356. };
  110357. static static_codebook _16c1_s_p9_2 = {
  110358. 2, 441,
  110359. _vq_lengthlist__16c1_s_p9_2,
  110360. 1, -529268736, 1611661312, 5, 0,
  110361. _vq_quantlist__16c1_s_p9_2,
  110362. NULL,
  110363. &_vq_auxt__16c1_s_p9_2,
  110364. NULL,
  110365. 0
  110366. };
  110367. static long _huff_lengthlist__16c1_s_short[] = {
  110368. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110369. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110370. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110371. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110372. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110373. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110374. 9, 9,10,13,
  110375. };
  110376. static static_codebook _huff_book__16c1_s_short = {
  110377. 2, 100,
  110378. _huff_lengthlist__16c1_s_short,
  110379. 0, 0, 0, 0, 0,
  110380. NULL,
  110381. NULL,
  110382. NULL,
  110383. NULL,
  110384. 0
  110385. };
  110386. static long _huff_lengthlist__16c2_s_long[] = {
  110387. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110388. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110389. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110390. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110391. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110392. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110393. 14,14,16,18,
  110394. };
  110395. static static_codebook _huff_book__16c2_s_long = {
  110396. 2, 100,
  110397. _huff_lengthlist__16c2_s_long,
  110398. 0, 0, 0, 0, 0,
  110399. NULL,
  110400. NULL,
  110401. NULL,
  110402. NULL,
  110403. 0
  110404. };
  110405. static long _vq_quantlist__16c2_s_p1_0[] = {
  110406. 1,
  110407. 0,
  110408. 2,
  110409. };
  110410. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110411. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110412. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110416. 0,
  110417. };
  110418. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110419. -0.5, 0.5,
  110420. };
  110421. static long _vq_quantmap__16c2_s_p1_0[] = {
  110422. 1, 0, 2,
  110423. };
  110424. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110425. _vq_quantthresh__16c2_s_p1_0,
  110426. _vq_quantmap__16c2_s_p1_0,
  110427. 3,
  110428. 3
  110429. };
  110430. static static_codebook _16c2_s_p1_0 = {
  110431. 4, 81,
  110432. _vq_lengthlist__16c2_s_p1_0,
  110433. 1, -535822336, 1611661312, 2, 0,
  110434. _vq_quantlist__16c2_s_p1_0,
  110435. NULL,
  110436. &_vq_auxt__16c2_s_p1_0,
  110437. NULL,
  110438. 0
  110439. };
  110440. static long _vq_quantlist__16c2_s_p2_0[] = {
  110441. 2,
  110442. 1,
  110443. 3,
  110444. 0,
  110445. 4,
  110446. };
  110447. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110448. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110449. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110450. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110451. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110452. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110453. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110454. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110455. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110460. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110461. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110462. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110463. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110468. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110469. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110470. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110471. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110476. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110477. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110478. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110479. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110484. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110485. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110486. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110487. 13,
  110488. };
  110489. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110490. -1.5, -0.5, 0.5, 1.5,
  110491. };
  110492. static long _vq_quantmap__16c2_s_p2_0[] = {
  110493. 3, 1, 0, 2, 4,
  110494. };
  110495. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110496. _vq_quantthresh__16c2_s_p2_0,
  110497. _vq_quantmap__16c2_s_p2_0,
  110498. 5,
  110499. 5
  110500. };
  110501. static static_codebook _16c2_s_p2_0 = {
  110502. 4, 625,
  110503. _vq_lengthlist__16c2_s_p2_0,
  110504. 1, -533725184, 1611661312, 3, 0,
  110505. _vq_quantlist__16c2_s_p2_0,
  110506. NULL,
  110507. &_vq_auxt__16c2_s_p2_0,
  110508. NULL,
  110509. 0
  110510. };
  110511. static long _vq_quantlist__16c2_s_p3_0[] = {
  110512. 4,
  110513. 3,
  110514. 5,
  110515. 2,
  110516. 6,
  110517. 1,
  110518. 7,
  110519. 0,
  110520. 8,
  110521. };
  110522. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110523. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110524. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110525. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110526. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110528. 0,
  110529. };
  110530. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110531. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110532. };
  110533. static long _vq_quantmap__16c2_s_p3_0[] = {
  110534. 7, 5, 3, 1, 0, 2, 4, 6,
  110535. 8,
  110536. };
  110537. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110538. _vq_quantthresh__16c2_s_p3_0,
  110539. _vq_quantmap__16c2_s_p3_0,
  110540. 9,
  110541. 9
  110542. };
  110543. static static_codebook _16c2_s_p3_0 = {
  110544. 2, 81,
  110545. _vq_lengthlist__16c2_s_p3_0,
  110546. 1, -531628032, 1611661312, 4, 0,
  110547. _vq_quantlist__16c2_s_p3_0,
  110548. NULL,
  110549. &_vq_auxt__16c2_s_p3_0,
  110550. NULL,
  110551. 0
  110552. };
  110553. static long _vq_quantlist__16c2_s_p4_0[] = {
  110554. 8,
  110555. 7,
  110556. 9,
  110557. 6,
  110558. 10,
  110559. 5,
  110560. 11,
  110561. 4,
  110562. 12,
  110563. 3,
  110564. 13,
  110565. 2,
  110566. 14,
  110567. 1,
  110568. 15,
  110569. 0,
  110570. 16,
  110571. };
  110572. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110573. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110574. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110575. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110576. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110577. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110578. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110579. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110580. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110581. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110582. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110591. 0,
  110592. };
  110593. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110594. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110595. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110596. };
  110597. static long _vq_quantmap__16c2_s_p4_0[] = {
  110598. 15, 13, 11, 9, 7, 5, 3, 1,
  110599. 0, 2, 4, 6, 8, 10, 12, 14,
  110600. 16,
  110601. };
  110602. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110603. _vq_quantthresh__16c2_s_p4_0,
  110604. _vq_quantmap__16c2_s_p4_0,
  110605. 17,
  110606. 17
  110607. };
  110608. static static_codebook _16c2_s_p4_0 = {
  110609. 2, 289,
  110610. _vq_lengthlist__16c2_s_p4_0,
  110611. 1, -529530880, 1611661312, 5, 0,
  110612. _vq_quantlist__16c2_s_p4_0,
  110613. NULL,
  110614. &_vq_auxt__16c2_s_p4_0,
  110615. NULL,
  110616. 0
  110617. };
  110618. static long _vq_quantlist__16c2_s_p5_0[] = {
  110619. 1,
  110620. 0,
  110621. 2,
  110622. };
  110623. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110624. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110625. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110626. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110627. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110628. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110629. 12,
  110630. };
  110631. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110632. -5.5, 5.5,
  110633. };
  110634. static long _vq_quantmap__16c2_s_p5_0[] = {
  110635. 1, 0, 2,
  110636. };
  110637. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110638. _vq_quantthresh__16c2_s_p5_0,
  110639. _vq_quantmap__16c2_s_p5_0,
  110640. 3,
  110641. 3
  110642. };
  110643. static static_codebook _16c2_s_p5_0 = {
  110644. 4, 81,
  110645. _vq_lengthlist__16c2_s_p5_0,
  110646. 1, -529137664, 1618345984, 2, 0,
  110647. _vq_quantlist__16c2_s_p5_0,
  110648. NULL,
  110649. &_vq_auxt__16c2_s_p5_0,
  110650. NULL,
  110651. 0
  110652. };
  110653. static long _vq_quantlist__16c2_s_p5_1[] = {
  110654. 5,
  110655. 4,
  110656. 6,
  110657. 3,
  110658. 7,
  110659. 2,
  110660. 8,
  110661. 1,
  110662. 9,
  110663. 0,
  110664. 10,
  110665. };
  110666. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110667. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110668. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110669. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110670. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110671. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110672. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110673. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110674. 11,11,11, 7, 7, 8, 8, 8, 8,
  110675. };
  110676. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110677. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110678. 3.5, 4.5,
  110679. };
  110680. static long _vq_quantmap__16c2_s_p5_1[] = {
  110681. 9, 7, 5, 3, 1, 0, 2, 4,
  110682. 6, 8, 10,
  110683. };
  110684. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110685. _vq_quantthresh__16c2_s_p5_1,
  110686. _vq_quantmap__16c2_s_p5_1,
  110687. 11,
  110688. 11
  110689. };
  110690. static static_codebook _16c2_s_p5_1 = {
  110691. 2, 121,
  110692. _vq_lengthlist__16c2_s_p5_1,
  110693. 1, -531365888, 1611661312, 4, 0,
  110694. _vq_quantlist__16c2_s_p5_1,
  110695. NULL,
  110696. &_vq_auxt__16c2_s_p5_1,
  110697. NULL,
  110698. 0
  110699. };
  110700. static long _vq_quantlist__16c2_s_p6_0[] = {
  110701. 6,
  110702. 5,
  110703. 7,
  110704. 4,
  110705. 8,
  110706. 3,
  110707. 9,
  110708. 2,
  110709. 10,
  110710. 1,
  110711. 11,
  110712. 0,
  110713. 12,
  110714. };
  110715. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110716. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110717. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110718. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110719. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110720. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110721. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110726. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110727. };
  110728. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110729. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110730. 12.5, 17.5, 22.5, 27.5,
  110731. };
  110732. static long _vq_quantmap__16c2_s_p6_0[] = {
  110733. 11, 9, 7, 5, 3, 1, 0, 2,
  110734. 4, 6, 8, 10, 12,
  110735. };
  110736. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110737. _vq_quantthresh__16c2_s_p6_0,
  110738. _vq_quantmap__16c2_s_p6_0,
  110739. 13,
  110740. 13
  110741. };
  110742. static static_codebook _16c2_s_p6_0 = {
  110743. 2, 169,
  110744. _vq_lengthlist__16c2_s_p6_0,
  110745. 1, -526516224, 1616117760, 4, 0,
  110746. _vq_quantlist__16c2_s_p6_0,
  110747. NULL,
  110748. &_vq_auxt__16c2_s_p6_0,
  110749. NULL,
  110750. 0
  110751. };
  110752. static long _vq_quantlist__16c2_s_p6_1[] = {
  110753. 2,
  110754. 1,
  110755. 3,
  110756. 0,
  110757. 4,
  110758. };
  110759. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110760. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110761. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110762. };
  110763. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110764. -1.5, -0.5, 0.5, 1.5,
  110765. };
  110766. static long _vq_quantmap__16c2_s_p6_1[] = {
  110767. 3, 1, 0, 2, 4,
  110768. };
  110769. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110770. _vq_quantthresh__16c2_s_p6_1,
  110771. _vq_quantmap__16c2_s_p6_1,
  110772. 5,
  110773. 5
  110774. };
  110775. static static_codebook _16c2_s_p6_1 = {
  110776. 2, 25,
  110777. _vq_lengthlist__16c2_s_p6_1,
  110778. 1, -533725184, 1611661312, 3, 0,
  110779. _vq_quantlist__16c2_s_p6_1,
  110780. NULL,
  110781. &_vq_auxt__16c2_s_p6_1,
  110782. NULL,
  110783. 0
  110784. };
  110785. static long _vq_quantlist__16c2_s_p7_0[] = {
  110786. 6,
  110787. 5,
  110788. 7,
  110789. 4,
  110790. 8,
  110791. 3,
  110792. 9,
  110793. 2,
  110794. 10,
  110795. 1,
  110796. 11,
  110797. 0,
  110798. 12,
  110799. };
  110800. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110801. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110802. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110803. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110804. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110805. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110806. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110807. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110808. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110809. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110810. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110811. 18,13,14,13,13,14,13,15,14,
  110812. };
  110813. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110814. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110815. 27.5, 38.5, 49.5, 60.5,
  110816. };
  110817. static long _vq_quantmap__16c2_s_p7_0[] = {
  110818. 11, 9, 7, 5, 3, 1, 0, 2,
  110819. 4, 6, 8, 10, 12,
  110820. };
  110821. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110822. _vq_quantthresh__16c2_s_p7_0,
  110823. _vq_quantmap__16c2_s_p7_0,
  110824. 13,
  110825. 13
  110826. };
  110827. static static_codebook _16c2_s_p7_0 = {
  110828. 2, 169,
  110829. _vq_lengthlist__16c2_s_p7_0,
  110830. 1, -523206656, 1618345984, 4, 0,
  110831. _vq_quantlist__16c2_s_p7_0,
  110832. NULL,
  110833. &_vq_auxt__16c2_s_p7_0,
  110834. NULL,
  110835. 0
  110836. };
  110837. static long _vq_quantlist__16c2_s_p7_1[] = {
  110838. 5,
  110839. 4,
  110840. 6,
  110841. 3,
  110842. 7,
  110843. 2,
  110844. 8,
  110845. 1,
  110846. 9,
  110847. 0,
  110848. 10,
  110849. };
  110850. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110851. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110852. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110853. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110854. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110855. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110856. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110857. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110858. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110859. };
  110860. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110861. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110862. 3.5, 4.5,
  110863. };
  110864. static long _vq_quantmap__16c2_s_p7_1[] = {
  110865. 9, 7, 5, 3, 1, 0, 2, 4,
  110866. 6, 8, 10,
  110867. };
  110868. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110869. _vq_quantthresh__16c2_s_p7_1,
  110870. _vq_quantmap__16c2_s_p7_1,
  110871. 11,
  110872. 11
  110873. };
  110874. static static_codebook _16c2_s_p7_1 = {
  110875. 2, 121,
  110876. _vq_lengthlist__16c2_s_p7_1,
  110877. 1, -531365888, 1611661312, 4, 0,
  110878. _vq_quantlist__16c2_s_p7_1,
  110879. NULL,
  110880. &_vq_auxt__16c2_s_p7_1,
  110881. NULL,
  110882. 0
  110883. };
  110884. static long _vq_quantlist__16c2_s_p8_0[] = {
  110885. 7,
  110886. 6,
  110887. 8,
  110888. 5,
  110889. 9,
  110890. 4,
  110891. 10,
  110892. 3,
  110893. 11,
  110894. 2,
  110895. 12,
  110896. 1,
  110897. 13,
  110898. 0,
  110899. 14,
  110900. };
  110901. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110902. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110903. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110904. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110905. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110906. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110907. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110908. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110909. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110910. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110911. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110912. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110913. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110914. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110915. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110916. 13,
  110917. };
  110918. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110919. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110920. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110921. };
  110922. static long _vq_quantmap__16c2_s_p8_0[] = {
  110923. 13, 11, 9, 7, 5, 3, 1, 0,
  110924. 2, 4, 6, 8, 10, 12, 14,
  110925. };
  110926. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110927. _vq_quantthresh__16c2_s_p8_0,
  110928. _vq_quantmap__16c2_s_p8_0,
  110929. 15,
  110930. 15
  110931. };
  110932. static static_codebook _16c2_s_p8_0 = {
  110933. 2, 225,
  110934. _vq_lengthlist__16c2_s_p8_0,
  110935. 1, -520986624, 1620377600, 4, 0,
  110936. _vq_quantlist__16c2_s_p8_0,
  110937. NULL,
  110938. &_vq_auxt__16c2_s_p8_0,
  110939. NULL,
  110940. 0
  110941. };
  110942. static long _vq_quantlist__16c2_s_p8_1[] = {
  110943. 10,
  110944. 9,
  110945. 11,
  110946. 8,
  110947. 12,
  110948. 7,
  110949. 13,
  110950. 6,
  110951. 14,
  110952. 5,
  110953. 15,
  110954. 4,
  110955. 16,
  110956. 3,
  110957. 17,
  110958. 2,
  110959. 18,
  110960. 1,
  110961. 19,
  110962. 0,
  110963. 20,
  110964. };
  110965. static long _vq_lengthlist__16c2_s_p8_1[] = {
  110966. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  110967. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  110968. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  110969. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  110970. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  110971. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  110972. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  110973. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  110974. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  110975. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  110976. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  110977. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  110978. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  110979. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  110980. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  110981. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  110982. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  110983. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  110984. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  110985. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  110986. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  110987. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  110988. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  110989. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  110990. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  110991. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  110992. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  110993. 10,11,10,10,10,10,10,10,10,
  110994. };
  110995. static float _vq_quantthresh__16c2_s_p8_1[] = {
  110996. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110997. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110998. 6.5, 7.5, 8.5, 9.5,
  110999. };
  111000. static long _vq_quantmap__16c2_s_p8_1[] = {
  111001. 19, 17, 15, 13, 11, 9, 7, 5,
  111002. 3, 1, 0, 2, 4, 6, 8, 10,
  111003. 12, 14, 16, 18, 20,
  111004. };
  111005. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111006. _vq_quantthresh__16c2_s_p8_1,
  111007. _vq_quantmap__16c2_s_p8_1,
  111008. 21,
  111009. 21
  111010. };
  111011. static static_codebook _16c2_s_p8_1 = {
  111012. 2, 441,
  111013. _vq_lengthlist__16c2_s_p8_1,
  111014. 1, -529268736, 1611661312, 5, 0,
  111015. _vq_quantlist__16c2_s_p8_1,
  111016. NULL,
  111017. &_vq_auxt__16c2_s_p8_1,
  111018. NULL,
  111019. 0
  111020. };
  111021. static long _vq_quantlist__16c2_s_p9_0[] = {
  111022. 6,
  111023. 5,
  111024. 7,
  111025. 4,
  111026. 8,
  111027. 3,
  111028. 9,
  111029. 2,
  111030. 10,
  111031. 1,
  111032. 11,
  111033. 0,
  111034. 12,
  111035. };
  111036. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111037. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111038. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111039. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111040. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111041. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111042. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111043. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111044. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111045. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111046. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111047. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111048. };
  111049. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111050. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111051. 2327.5, 3258.5, 4189.5, 5120.5,
  111052. };
  111053. static long _vq_quantmap__16c2_s_p9_0[] = {
  111054. 11, 9, 7, 5, 3, 1, 0, 2,
  111055. 4, 6, 8, 10, 12,
  111056. };
  111057. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111058. _vq_quantthresh__16c2_s_p9_0,
  111059. _vq_quantmap__16c2_s_p9_0,
  111060. 13,
  111061. 13
  111062. };
  111063. static static_codebook _16c2_s_p9_0 = {
  111064. 2, 169,
  111065. _vq_lengthlist__16c2_s_p9_0,
  111066. 1, -510275072, 1631393792, 4, 0,
  111067. _vq_quantlist__16c2_s_p9_0,
  111068. NULL,
  111069. &_vq_auxt__16c2_s_p9_0,
  111070. NULL,
  111071. 0
  111072. };
  111073. static long _vq_quantlist__16c2_s_p9_1[] = {
  111074. 8,
  111075. 7,
  111076. 9,
  111077. 6,
  111078. 10,
  111079. 5,
  111080. 11,
  111081. 4,
  111082. 12,
  111083. 3,
  111084. 13,
  111085. 2,
  111086. 14,
  111087. 1,
  111088. 15,
  111089. 0,
  111090. 16,
  111091. };
  111092. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111093. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111094. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111095. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111096. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111097. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111098. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111099. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111100. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111101. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111102. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111103. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111104. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111105. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111106. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111107. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111108. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111109. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111110. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111111. 10,
  111112. };
  111113. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111114. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111115. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111116. };
  111117. static long _vq_quantmap__16c2_s_p9_1[] = {
  111118. 15, 13, 11, 9, 7, 5, 3, 1,
  111119. 0, 2, 4, 6, 8, 10, 12, 14,
  111120. 16,
  111121. };
  111122. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111123. _vq_quantthresh__16c2_s_p9_1,
  111124. _vq_quantmap__16c2_s_p9_1,
  111125. 17,
  111126. 17
  111127. };
  111128. static static_codebook _16c2_s_p9_1 = {
  111129. 2, 289,
  111130. _vq_lengthlist__16c2_s_p9_1,
  111131. 1, -518488064, 1622704128, 5, 0,
  111132. _vq_quantlist__16c2_s_p9_1,
  111133. NULL,
  111134. &_vq_auxt__16c2_s_p9_1,
  111135. NULL,
  111136. 0
  111137. };
  111138. static long _vq_quantlist__16c2_s_p9_2[] = {
  111139. 13,
  111140. 12,
  111141. 14,
  111142. 11,
  111143. 15,
  111144. 10,
  111145. 16,
  111146. 9,
  111147. 17,
  111148. 8,
  111149. 18,
  111150. 7,
  111151. 19,
  111152. 6,
  111153. 20,
  111154. 5,
  111155. 21,
  111156. 4,
  111157. 22,
  111158. 3,
  111159. 23,
  111160. 2,
  111161. 24,
  111162. 1,
  111163. 25,
  111164. 0,
  111165. 26,
  111166. };
  111167. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111168. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111169. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111170. };
  111171. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111172. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111173. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111174. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111175. 11.5, 12.5,
  111176. };
  111177. static long _vq_quantmap__16c2_s_p9_2[] = {
  111178. 25, 23, 21, 19, 17, 15, 13, 11,
  111179. 9, 7, 5, 3, 1, 0, 2, 4,
  111180. 6, 8, 10, 12, 14, 16, 18, 20,
  111181. 22, 24, 26,
  111182. };
  111183. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111184. _vq_quantthresh__16c2_s_p9_2,
  111185. _vq_quantmap__16c2_s_p9_2,
  111186. 27,
  111187. 27
  111188. };
  111189. static static_codebook _16c2_s_p9_2 = {
  111190. 1, 27,
  111191. _vq_lengthlist__16c2_s_p9_2,
  111192. 1, -528875520, 1611661312, 5, 0,
  111193. _vq_quantlist__16c2_s_p9_2,
  111194. NULL,
  111195. &_vq_auxt__16c2_s_p9_2,
  111196. NULL,
  111197. 0
  111198. };
  111199. static long _huff_lengthlist__16c2_s_short[] = {
  111200. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111201. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111202. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111203. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111204. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111205. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111206. 15,12,14,14,
  111207. };
  111208. static static_codebook _huff_book__16c2_s_short = {
  111209. 2, 100,
  111210. _huff_lengthlist__16c2_s_short,
  111211. 0, 0, 0, 0, 0,
  111212. NULL,
  111213. NULL,
  111214. NULL,
  111215. NULL,
  111216. 0
  111217. };
  111218. static long _vq_quantlist__8c0_s_p1_0[] = {
  111219. 1,
  111220. 0,
  111221. 2,
  111222. };
  111223. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111224. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111225. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111229. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111230. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111234. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111235. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111270. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111275. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111280. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111297. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111302. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111307. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111316. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111321. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111326. 0, 0, 0, 0, 0, 0, 8,11, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  111342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111343. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  111347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  111635. };
  111636. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111637. -0.5, 0.5,
  111638. };
  111639. static long _vq_quantmap__8c0_s_p1_0[] = {
  111640. 1, 0, 2,
  111641. };
  111642. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111643. _vq_quantthresh__8c0_s_p1_0,
  111644. _vq_quantmap__8c0_s_p1_0,
  111645. 3,
  111646. 3
  111647. };
  111648. static static_codebook _8c0_s_p1_0 = {
  111649. 8, 6561,
  111650. _vq_lengthlist__8c0_s_p1_0,
  111651. 1, -535822336, 1611661312, 2, 0,
  111652. _vq_quantlist__8c0_s_p1_0,
  111653. NULL,
  111654. &_vq_auxt__8c0_s_p1_0,
  111655. NULL,
  111656. 0
  111657. };
  111658. static long _vq_quantlist__8c0_s_p2_0[] = {
  111659. 2,
  111660. 1,
  111661. 3,
  111662. 0,
  111663. 4,
  111664. };
  111665. static long _vq_lengthlist__8c0_s_p2_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,
  111706. };
  111707. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111708. -1.5, -0.5, 0.5, 1.5,
  111709. };
  111710. static long _vq_quantmap__8c0_s_p2_0[] = {
  111711. 3, 1, 0, 2, 4,
  111712. };
  111713. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111714. _vq_quantthresh__8c0_s_p2_0,
  111715. _vq_quantmap__8c0_s_p2_0,
  111716. 5,
  111717. 5
  111718. };
  111719. static static_codebook _8c0_s_p2_0 = {
  111720. 4, 625,
  111721. _vq_lengthlist__8c0_s_p2_0,
  111722. 1, -533725184, 1611661312, 3, 0,
  111723. _vq_quantlist__8c0_s_p2_0,
  111724. NULL,
  111725. &_vq_auxt__8c0_s_p2_0,
  111726. NULL,
  111727. 0
  111728. };
  111729. static long _vq_quantlist__8c0_s_p3_0[] = {
  111730. 2,
  111731. 1,
  111732. 3,
  111733. 0,
  111734. 4,
  111735. };
  111736. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111737. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111740. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111743. 0, 0, 0, 0, 6, 7, 7, 8, 8, 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,
  111777. };
  111778. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111779. -1.5, -0.5, 0.5, 1.5,
  111780. };
  111781. static long _vq_quantmap__8c0_s_p3_0[] = {
  111782. 3, 1, 0, 2, 4,
  111783. };
  111784. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111785. _vq_quantthresh__8c0_s_p3_0,
  111786. _vq_quantmap__8c0_s_p3_0,
  111787. 5,
  111788. 5
  111789. };
  111790. static static_codebook _8c0_s_p3_0 = {
  111791. 4, 625,
  111792. _vq_lengthlist__8c0_s_p3_0,
  111793. 1, -533725184, 1611661312, 3, 0,
  111794. _vq_quantlist__8c0_s_p3_0,
  111795. NULL,
  111796. &_vq_auxt__8c0_s_p3_0,
  111797. NULL,
  111798. 0
  111799. };
  111800. static long _vq_quantlist__8c0_s_p4_0[] = {
  111801. 4,
  111802. 3,
  111803. 5,
  111804. 2,
  111805. 6,
  111806. 1,
  111807. 7,
  111808. 0,
  111809. 8,
  111810. };
  111811. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111812. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111813. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111814. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111815. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111816. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111817. 0,
  111818. };
  111819. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111820. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111821. };
  111822. static long _vq_quantmap__8c0_s_p4_0[] = {
  111823. 7, 5, 3, 1, 0, 2, 4, 6,
  111824. 8,
  111825. };
  111826. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111827. _vq_quantthresh__8c0_s_p4_0,
  111828. _vq_quantmap__8c0_s_p4_0,
  111829. 9,
  111830. 9
  111831. };
  111832. static static_codebook _8c0_s_p4_0 = {
  111833. 2, 81,
  111834. _vq_lengthlist__8c0_s_p4_0,
  111835. 1, -531628032, 1611661312, 4, 0,
  111836. _vq_quantlist__8c0_s_p4_0,
  111837. NULL,
  111838. &_vq_auxt__8c0_s_p4_0,
  111839. NULL,
  111840. 0
  111841. };
  111842. static long _vq_quantlist__8c0_s_p5_0[] = {
  111843. 4,
  111844. 3,
  111845. 5,
  111846. 2,
  111847. 6,
  111848. 1,
  111849. 7,
  111850. 0,
  111851. 8,
  111852. };
  111853. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111854. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111855. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111856. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111857. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111858. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111859. 10,
  111860. };
  111861. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111862. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111863. };
  111864. static long _vq_quantmap__8c0_s_p5_0[] = {
  111865. 7, 5, 3, 1, 0, 2, 4, 6,
  111866. 8,
  111867. };
  111868. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111869. _vq_quantthresh__8c0_s_p5_0,
  111870. _vq_quantmap__8c0_s_p5_0,
  111871. 9,
  111872. 9
  111873. };
  111874. static static_codebook _8c0_s_p5_0 = {
  111875. 2, 81,
  111876. _vq_lengthlist__8c0_s_p5_0,
  111877. 1, -531628032, 1611661312, 4, 0,
  111878. _vq_quantlist__8c0_s_p5_0,
  111879. NULL,
  111880. &_vq_auxt__8c0_s_p5_0,
  111881. NULL,
  111882. 0
  111883. };
  111884. static long _vq_quantlist__8c0_s_p6_0[] = {
  111885. 8,
  111886. 7,
  111887. 9,
  111888. 6,
  111889. 10,
  111890. 5,
  111891. 11,
  111892. 4,
  111893. 12,
  111894. 3,
  111895. 13,
  111896. 2,
  111897. 14,
  111898. 1,
  111899. 15,
  111900. 0,
  111901. 16,
  111902. };
  111903. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111904. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111905. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111906. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111907. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111908. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111909. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111910. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111911. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111912. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111913. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111914. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111915. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111916. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111917. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111918. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111919. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111920. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111921. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111922. 14,
  111923. };
  111924. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111925. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111926. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111927. };
  111928. static long _vq_quantmap__8c0_s_p6_0[] = {
  111929. 15, 13, 11, 9, 7, 5, 3, 1,
  111930. 0, 2, 4, 6, 8, 10, 12, 14,
  111931. 16,
  111932. };
  111933. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  111934. _vq_quantthresh__8c0_s_p6_0,
  111935. _vq_quantmap__8c0_s_p6_0,
  111936. 17,
  111937. 17
  111938. };
  111939. static static_codebook _8c0_s_p6_0 = {
  111940. 2, 289,
  111941. _vq_lengthlist__8c0_s_p6_0,
  111942. 1, -529530880, 1611661312, 5, 0,
  111943. _vq_quantlist__8c0_s_p6_0,
  111944. NULL,
  111945. &_vq_auxt__8c0_s_p6_0,
  111946. NULL,
  111947. 0
  111948. };
  111949. static long _vq_quantlist__8c0_s_p7_0[] = {
  111950. 1,
  111951. 0,
  111952. 2,
  111953. };
  111954. static long _vq_lengthlist__8c0_s_p7_0[] = {
  111955. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  111956. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  111957. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  111958. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  111959. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  111960. 10,
  111961. };
  111962. static float _vq_quantthresh__8c0_s_p7_0[] = {
  111963. -5.5, 5.5,
  111964. };
  111965. static long _vq_quantmap__8c0_s_p7_0[] = {
  111966. 1, 0, 2,
  111967. };
  111968. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  111969. _vq_quantthresh__8c0_s_p7_0,
  111970. _vq_quantmap__8c0_s_p7_0,
  111971. 3,
  111972. 3
  111973. };
  111974. static static_codebook _8c0_s_p7_0 = {
  111975. 4, 81,
  111976. _vq_lengthlist__8c0_s_p7_0,
  111977. 1, -529137664, 1618345984, 2, 0,
  111978. _vq_quantlist__8c0_s_p7_0,
  111979. NULL,
  111980. &_vq_auxt__8c0_s_p7_0,
  111981. NULL,
  111982. 0
  111983. };
  111984. static long _vq_quantlist__8c0_s_p7_1[] = {
  111985. 5,
  111986. 4,
  111987. 6,
  111988. 3,
  111989. 7,
  111990. 2,
  111991. 8,
  111992. 1,
  111993. 9,
  111994. 0,
  111995. 10,
  111996. };
  111997. static long _vq_lengthlist__8c0_s_p7_1[] = {
  111998. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  111999. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112000. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112001. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112002. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112003. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112004. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112005. 10,10,10, 9, 9, 9,10,10,10,
  112006. };
  112007. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112008. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112009. 3.5, 4.5,
  112010. };
  112011. static long _vq_quantmap__8c0_s_p7_1[] = {
  112012. 9, 7, 5, 3, 1, 0, 2, 4,
  112013. 6, 8, 10,
  112014. };
  112015. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112016. _vq_quantthresh__8c0_s_p7_1,
  112017. _vq_quantmap__8c0_s_p7_1,
  112018. 11,
  112019. 11
  112020. };
  112021. static static_codebook _8c0_s_p7_1 = {
  112022. 2, 121,
  112023. _vq_lengthlist__8c0_s_p7_1,
  112024. 1, -531365888, 1611661312, 4, 0,
  112025. _vq_quantlist__8c0_s_p7_1,
  112026. NULL,
  112027. &_vq_auxt__8c0_s_p7_1,
  112028. NULL,
  112029. 0
  112030. };
  112031. static long _vq_quantlist__8c0_s_p8_0[] = {
  112032. 6,
  112033. 5,
  112034. 7,
  112035. 4,
  112036. 8,
  112037. 3,
  112038. 9,
  112039. 2,
  112040. 10,
  112041. 1,
  112042. 11,
  112043. 0,
  112044. 12,
  112045. };
  112046. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112047. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112048. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112049. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112050. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112051. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112052. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112053. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112054. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112055. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112056. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112057. 0, 0,13,13,11,13,13,11,12,
  112058. };
  112059. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112060. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112061. 12.5, 17.5, 22.5, 27.5,
  112062. };
  112063. static long _vq_quantmap__8c0_s_p8_0[] = {
  112064. 11, 9, 7, 5, 3, 1, 0, 2,
  112065. 4, 6, 8, 10, 12,
  112066. };
  112067. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112068. _vq_quantthresh__8c0_s_p8_0,
  112069. _vq_quantmap__8c0_s_p8_0,
  112070. 13,
  112071. 13
  112072. };
  112073. static static_codebook _8c0_s_p8_0 = {
  112074. 2, 169,
  112075. _vq_lengthlist__8c0_s_p8_0,
  112076. 1, -526516224, 1616117760, 4, 0,
  112077. _vq_quantlist__8c0_s_p8_0,
  112078. NULL,
  112079. &_vq_auxt__8c0_s_p8_0,
  112080. NULL,
  112081. 0
  112082. };
  112083. static long _vq_quantlist__8c0_s_p8_1[] = {
  112084. 2,
  112085. 1,
  112086. 3,
  112087. 0,
  112088. 4,
  112089. };
  112090. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112091. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112092. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112093. };
  112094. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112095. -1.5, -0.5, 0.5, 1.5,
  112096. };
  112097. static long _vq_quantmap__8c0_s_p8_1[] = {
  112098. 3, 1, 0, 2, 4,
  112099. };
  112100. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112101. _vq_quantthresh__8c0_s_p8_1,
  112102. _vq_quantmap__8c0_s_p8_1,
  112103. 5,
  112104. 5
  112105. };
  112106. static static_codebook _8c0_s_p8_1 = {
  112107. 2, 25,
  112108. _vq_lengthlist__8c0_s_p8_1,
  112109. 1, -533725184, 1611661312, 3, 0,
  112110. _vq_quantlist__8c0_s_p8_1,
  112111. NULL,
  112112. &_vq_auxt__8c0_s_p8_1,
  112113. NULL,
  112114. 0
  112115. };
  112116. static long _vq_quantlist__8c0_s_p9_0[] = {
  112117. 1,
  112118. 0,
  112119. 2,
  112120. };
  112121. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112122. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112123. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112124. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112125. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112126. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112127. 7,
  112128. };
  112129. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112130. -157.5, 157.5,
  112131. };
  112132. static long _vq_quantmap__8c0_s_p9_0[] = {
  112133. 1, 0, 2,
  112134. };
  112135. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112136. _vq_quantthresh__8c0_s_p9_0,
  112137. _vq_quantmap__8c0_s_p9_0,
  112138. 3,
  112139. 3
  112140. };
  112141. static static_codebook _8c0_s_p9_0 = {
  112142. 4, 81,
  112143. _vq_lengthlist__8c0_s_p9_0,
  112144. 1, -518803456, 1628680192, 2, 0,
  112145. _vq_quantlist__8c0_s_p9_0,
  112146. NULL,
  112147. &_vq_auxt__8c0_s_p9_0,
  112148. NULL,
  112149. 0
  112150. };
  112151. static long _vq_quantlist__8c0_s_p9_1[] = {
  112152. 7,
  112153. 6,
  112154. 8,
  112155. 5,
  112156. 9,
  112157. 4,
  112158. 10,
  112159. 3,
  112160. 11,
  112161. 2,
  112162. 12,
  112163. 1,
  112164. 13,
  112165. 0,
  112166. 14,
  112167. };
  112168. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112169. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112170. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112171. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112172. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112173. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112174. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112175. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112177. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112178. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112179. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112180. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112181. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112182. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112183. 11,
  112184. };
  112185. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112186. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112187. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112188. };
  112189. static long _vq_quantmap__8c0_s_p9_1[] = {
  112190. 13, 11, 9, 7, 5, 3, 1, 0,
  112191. 2, 4, 6, 8, 10, 12, 14,
  112192. };
  112193. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112194. _vq_quantthresh__8c0_s_p9_1,
  112195. _vq_quantmap__8c0_s_p9_1,
  112196. 15,
  112197. 15
  112198. };
  112199. static static_codebook _8c0_s_p9_1 = {
  112200. 2, 225,
  112201. _vq_lengthlist__8c0_s_p9_1,
  112202. 1, -520986624, 1620377600, 4, 0,
  112203. _vq_quantlist__8c0_s_p9_1,
  112204. NULL,
  112205. &_vq_auxt__8c0_s_p9_1,
  112206. NULL,
  112207. 0
  112208. };
  112209. static long _vq_quantlist__8c0_s_p9_2[] = {
  112210. 10,
  112211. 9,
  112212. 11,
  112213. 8,
  112214. 12,
  112215. 7,
  112216. 13,
  112217. 6,
  112218. 14,
  112219. 5,
  112220. 15,
  112221. 4,
  112222. 16,
  112223. 3,
  112224. 17,
  112225. 2,
  112226. 18,
  112227. 1,
  112228. 19,
  112229. 0,
  112230. 20,
  112231. };
  112232. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112233. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112234. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112235. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112236. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112237. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112238. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112239. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112240. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112241. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112242. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112243. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112244. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112245. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112246. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112247. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112248. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112249. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112250. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112251. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112252. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112253. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112254. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112255. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112256. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112257. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112258. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112259. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112260. 10,11, 9,11,10, 9,10, 9,10,
  112261. };
  112262. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112263. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112264. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112265. 6.5, 7.5, 8.5, 9.5,
  112266. };
  112267. static long _vq_quantmap__8c0_s_p9_2[] = {
  112268. 19, 17, 15, 13, 11, 9, 7, 5,
  112269. 3, 1, 0, 2, 4, 6, 8, 10,
  112270. 12, 14, 16, 18, 20,
  112271. };
  112272. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112273. _vq_quantthresh__8c0_s_p9_2,
  112274. _vq_quantmap__8c0_s_p9_2,
  112275. 21,
  112276. 21
  112277. };
  112278. static static_codebook _8c0_s_p9_2 = {
  112279. 2, 441,
  112280. _vq_lengthlist__8c0_s_p9_2,
  112281. 1, -529268736, 1611661312, 5, 0,
  112282. _vq_quantlist__8c0_s_p9_2,
  112283. NULL,
  112284. &_vq_auxt__8c0_s_p9_2,
  112285. NULL,
  112286. 0
  112287. };
  112288. static long _huff_lengthlist__8c0_s_single[] = {
  112289. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112290. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112291. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112292. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112293. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112294. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112295. 17,16,17,17,
  112296. };
  112297. static static_codebook _huff_book__8c0_s_single = {
  112298. 2, 100,
  112299. _huff_lengthlist__8c0_s_single,
  112300. 0, 0, 0, 0, 0,
  112301. NULL,
  112302. NULL,
  112303. NULL,
  112304. NULL,
  112305. 0
  112306. };
  112307. static long _vq_quantlist__8c1_s_p1_0[] = {
  112308. 1,
  112309. 0,
  112310. 2,
  112311. };
  112312. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112313. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112314. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112318. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112319. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112323. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112324. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112359. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112364. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112369. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112386. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112391. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112396. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112405. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112410. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112415. 0, 0, 0, 0, 0, 0, 8,10, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  112431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112432. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  112436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  112724. };
  112725. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112726. -0.5, 0.5,
  112727. };
  112728. static long _vq_quantmap__8c1_s_p1_0[] = {
  112729. 1, 0, 2,
  112730. };
  112731. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112732. _vq_quantthresh__8c1_s_p1_0,
  112733. _vq_quantmap__8c1_s_p1_0,
  112734. 3,
  112735. 3
  112736. };
  112737. static static_codebook _8c1_s_p1_0 = {
  112738. 8, 6561,
  112739. _vq_lengthlist__8c1_s_p1_0,
  112740. 1, -535822336, 1611661312, 2, 0,
  112741. _vq_quantlist__8c1_s_p1_0,
  112742. NULL,
  112743. &_vq_auxt__8c1_s_p1_0,
  112744. NULL,
  112745. 0
  112746. };
  112747. static long _vq_quantlist__8c1_s_p2_0[] = {
  112748. 2,
  112749. 1,
  112750. 3,
  112751. 0,
  112752. 4,
  112753. };
  112754. static long _vq_lengthlist__8c1_s_p2_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,
  112795. };
  112796. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112797. -1.5, -0.5, 0.5, 1.5,
  112798. };
  112799. static long _vq_quantmap__8c1_s_p2_0[] = {
  112800. 3, 1, 0, 2, 4,
  112801. };
  112802. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112803. _vq_quantthresh__8c1_s_p2_0,
  112804. _vq_quantmap__8c1_s_p2_0,
  112805. 5,
  112806. 5
  112807. };
  112808. static static_codebook _8c1_s_p2_0 = {
  112809. 4, 625,
  112810. _vq_lengthlist__8c1_s_p2_0,
  112811. 1, -533725184, 1611661312, 3, 0,
  112812. _vq_quantlist__8c1_s_p2_0,
  112813. NULL,
  112814. &_vq_auxt__8c1_s_p2_0,
  112815. NULL,
  112816. 0
  112817. };
  112818. static long _vq_quantlist__8c1_s_p3_0[] = {
  112819. 2,
  112820. 1,
  112821. 3,
  112822. 0,
  112823. 4,
  112824. };
  112825. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112826. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112829. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112832. 0, 0, 0, 0, 6, 6, 6, 7, 7, 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,
  112866. };
  112867. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112868. -1.5, -0.5, 0.5, 1.5,
  112869. };
  112870. static long _vq_quantmap__8c1_s_p3_0[] = {
  112871. 3, 1, 0, 2, 4,
  112872. };
  112873. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112874. _vq_quantthresh__8c1_s_p3_0,
  112875. _vq_quantmap__8c1_s_p3_0,
  112876. 5,
  112877. 5
  112878. };
  112879. static static_codebook _8c1_s_p3_0 = {
  112880. 4, 625,
  112881. _vq_lengthlist__8c1_s_p3_0,
  112882. 1, -533725184, 1611661312, 3, 0,
  112883. _vq_quantlist__8c1_s_p3_0,
  112884. NULL,
  112885. &_vq_auxt__8c1_s_p3_0,
  112886. NULL,
  112887. 0
  112888. };
  112889. static long _vq_quantlist__8c1_s_p4_0[] = {
  112890. 4,
  112891. 3,
  112892. 5,
  112893. 2,
  112894. 6,
  112895. 1,
  112896. 7,
  112897. 0,
  112898. 8,
  112899. };
  112900. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112901. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112902. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112903. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112904. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112905. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112906. 0,
  112907. };
  112908. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112909. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112910. };
  112911. static long _vq_quantmap__8c1_s_p4_0[] = {
  112912. 7, 5, 3, 1, 0, 2, 4, 6,
  112913. 8,
  112914. };
  112915. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112916. _vq_quantthresh__8c1_s_p4_0,
  112917. _vq_quantmap__8c1_s_p4_0,
  112918. 9,
  112919. 9
  112920. };
  112921. static static_codebook _8c1_s_p4_0 = {
  112922. 2, 81,
  112923. _vq_lengthlist__8c1_s_p4_0,
  112924. 1, -531628032, 1611661312, 4, 0,
  112925. _vq_quantlist__8c1_s_p4_0,
  112926. NULL,
  112927. &_vq_auxt__8c1_s_p4_0,
  112928. NULL,
  112929. 0
  112930. };
  112931. static long _vq_quantlist__8c1_s_p5_0[] = {
  112932. 4,
  112933. 3,
  112934. 5,
  112935. 2,
  112936. 6,
  112937. 1,
  112938. 7,
  112939. 0,
  112940. 8,
  112941. };
  112942. static long _vq_lengthlist__8c1_s_p5_0[] = {
  112943. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  112944. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  112945. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  112946. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  112947. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112948. 10,
  112949. };
  112950. static float _vq_quantthresh__8c1_s_p5_0[] = {
  112951. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112952. };
  112953. static long _vq_quantmap__8c1_s_p5_0[] = {
  112954. 7, 5, 3, 1, 0, 2, 4, 6,
  112955. 8,
  112956. };
  112957. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  112958. _vq_quantthresh__8c1_s_p5_0,
  112959. _vq_quantmap__8c1_s_p5_0,
  112960. 9,
  112961. 9
  112962. };
  112963. static static_codebook _8c1_s_p5_0 = {
  112964. 2, 81,
  112965. _vq_lengthlist__8c1_s_p5_0,
  112966. 1, -531628032, 1611661312, 4, 0,
  112967. _vq_quantlist__8c1_s_p5_0,
  112968. NULL,
  112969. &_vq_auxt__8c1_s_p5_0,
  112970. NULL,
  112971. 0
  112972. };
  112973. static long _vq_quantlist__8c1_s_p6_0[] = {
  112974. 8,
  112975. 7,
  112976. 9,
  112977. 6,
  112978. 10,
  112979. 5,
  112980. 11,
  112981. 4,
  112982. 12,
  112983. 3,
  112984. 13,
  112985. 2,
  112986. 14,
  112987. 1,
  112988. 15,
  112989. 0,
  112990. 16,
  112991. };
  112992. static long _vq_lengthlist__8c1_s_p6_0[] = {
  112993. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  112994. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112995. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  112996. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  112997. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  112998. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  112999. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113000. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113001. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113002. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113003. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113004. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113005. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113006. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113007. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113008. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113009. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113010. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113011. 14,
  113012. };
  113013. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113014. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113015. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113016. };
  113017. static long _vq_quantmap__8c1_s_p6_0[] = {
  113018. 15, 13, 11, 9, 7, 5, 3, 1,
  113019. 0, 2, 4, 6, 8, 10, 12, 14,
  113020. 16,
  113021. };
  113022. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113023. _vq_quantthresh__8c1_s_p6_0,
  113024. _vq_quantmap__8c1_s_p6_0,
  113025. 17,
  113026. 17
  113027. };
  113028. static static_codebook _8c1_s_p6_0 = {
  113029. 2, 289,
  113030. _vq_lengthlist__8c1_s_p6_0,
  113031. 1, -529530880, 1611661312, 5, 0,
  113032. _vq_quantlist__8c1_s_p6_0,
  113033. NULL,
  113034. &_vq_auxt__8c1_s_p6_0,
  113035. NULL,
  113036. 0
  113037. };
  113038. static long _vq_quantlist__8c1_s_p7_0[] = {
  113039. 1,
  113040. 0,
  113041. 2,
  113042. };
  113043. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113044. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113045. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113046. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113047. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113048. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113049. 9,
  113050. };
  113051. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113052. -5.5, 5.5,
  113053. };
  113054. static long _vq_quantmap__8c1_s_p7_0[] = {
  113055. 1, 0, 2,
  113056. };
  113057. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113058. _vq_quantthresh__8c1_s_p7_0,
  113059. _vq_quantmap__8c1_s_p7_0,
  113060. 3,
  113061. 3
  113062. };
  113063. static static_codebook _8c1_s_p7_0 = {
  113064. 4, 81,
  113065. _vq_lengthlist__8c1_s_p7_0,
  113066. 1, -529137664, 1618345984, 2, 0,
  113067. _vq_quantlist__8c1_s_p7_0,
  113068. NULL,
  113069. &_vq_auxt__8c1_s_p7_0,
  113070. NULL,
  113071. 0
  113072. };
  113073. static long _vq_quantlist__8c1_s_p7_1[] = {
  113074. 5,
  113075. 4,
  113076. 6,
  113077. 3,
  113078. 7,
  113079. 2,
  113080. 8,
  113081. 1,
  113082. 9,
  113083. 0,
  113084. 10,
  113085. };
  113086. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113087. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113088. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113089. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113090. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113091. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113092. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113093. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113094. 10,10,10, 8, 8, 8, 8, 8, 8,
  113095. };
  113096. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113097. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113098. 3.5, 4.5,
  113099. };
  113100. static long _vq_quantmap__8c1_s_p7_1[] = {
  113101. 9, 7, 5, 3, 1, 0, 2, 4,
  113102. 6, 8, 10,
  113103. };
  113104. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113105. _vq_quantthresh__8c1_s_p7_1,
  113106. _vq_quantmap__8c1_s_p7_1,
  113107. 11,
  113108. 11
  113109. };
  113110. static static_codebook _8c1_s_p7_1 = {
  113111. 2, 121,
  113112. _vq_lengthlist__8c1_s_p7_1,
  113113. 1, -531365888, 1611661312, 4, 0,
  113114. _vq_quantlist__8c1_s_p7_1,
  113115. NULL,
  113116. &_vq_auxt__8c1_s_p7_1,
  113117. NULL,
  113118. 0
  113119. };
  113120. static long _vq_quantlist__8c1_s_p8_0[] = {
  113121. 6,
  113122. 5,
  113123. 7,
  113124. 4,
  113125. 8,
  113126. 3,
  113127. 9,
  113128. 2,
  113129. 10,
  113130. 1,
  113131. 11,
  113132. 0,
  113133. 12,
  113134. };
  113135. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113136. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113137. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113138. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113139. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113140. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113141. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113142. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113143. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113144. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113145. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113146. 0,12,12,11,10,12,11,13,12,
  113147. };
  113148. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113149. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113150. 12.5, 17.5, 22.5, 27.5,
  113151. };
  113152. static long _vq_quantmap__8c1_s_p8_0[] = {
  113153. 11, 9, 7, 5, 3, 1, 0, 2,
  113154. 4, 6, 8, 10, 12,
  113155. };
  113156. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113157. _vq_quantthresh__8c1_s_p8_0,
  113158. _vq_quantmap__8c1_s_p8_0,
  113159. 13,
  113160. 13
  113161. };
  113162. static static_codebook _8c1_s_p8_0 = {
  113163. 2, 169,
  113164. _vq_lengthlist__8c1_s_p8_0,
  113165. 1, -526516224, 1616117760, 4, 0,
  113166. _vq_quantlist__8c1_s_p8_0,
  113167. NULL,
  113168. &_vq_auxt__8c1_s_p8_0,
  113169. NULL,
  113170. 0
  113171. };
  113172. static long _vq_quantlist__8c1_s_p8_1[] = {
  113173. 2,
  113174. 1,
  113175. 3,
  113176. 0,
  113177. 4,
  113178. };
  113179. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113180. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113181. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113182. };
  113183. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113184. -1.5, -0.5, 0.5, 1.5,
  113185. };
  113186. static long _vq_quantmap__8c1_s_p8_1[] = {
  113187. 3, 1, 0, 2, 4,
  113188. };
  113189. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113190. _vq_quantthresh__8c1_s_p8_1,
  113191. _vq_quantmap__8c1_s_p8_1,
  113192. 5,
  113193. 5
  113194. };
  113195. static static_codebook _8c1_s_p8_1 = {
  113196. 2, 25,
  113197. _vq_lengthlist__8c1_s_p8_1,
  113198. 1, -533725184, 1611661312, 3, 0,
  113199. _vq_quantlist__8c1_s_p8_1,
  113200. NULL,
  113201. &_vq_auxt__8c1_s_p8_1,
  113202. NULL,
  113203. 0
  113204. };
  113205. static long _vq_quantlist__8c1_s_p9_0[] = {
  113206. 6,
  113207. 5,
  113208. 7,
  113209. 4,
  113210. 8,
  113211. 3,
  113212. 9,
  113213. 2,
  113214. 10,
  113215. 1,
  113216. 11,
  113217. 0,
  113218. 12,
  113219. };
  113220. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113221. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113222. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113223. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113224. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113225. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113226. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113227. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113228. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113229. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113230. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113231. 10,10,10,10,10, 9, 9, 9, 9,
  113232. };
  113233. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113234. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113235. 787.5, 1102.5, 1417.5, 1732.5,
  113236. };
  113237. static long _vq_quantmap__8c1_s_p9_0[] = {
  113238. 11, 9, 7, 5, 3, 1, 0, 2,
  113239. 4, 6, 8, 10, 12,
  113240. };
  113241. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113242. _vq_quantthresh__8c1_s_p9_0,
  113243. _vq_quantmap__8c1_s_p9_0,
  113244. 13,
  113245. 13
  113246. };
  113247. static static_codebook _8c1_s_p9_0 = {
  113248. 2, 169,
  113249. _vq_lengthlist__8c1_s_p9_0,
  113250. 1, -513964032, 1628680192, 4, 0,
  113251. _vq_quantlist__8c1_s_p9_0,
  113252. NULL,
  113253. &_vq_auxt__8c1_s_p9_0,
  113254. NULL,
  113255. 0
  113256. };
  113257. static long _vq_quantlist__8c1_s_p9_1[] = {
  113258. 7,
  113259. 6,
  113260. 8,
  113261. 5,
  113262. 9,
  113263. 4,
  113264. 10,
  113265. 3,
  113266. 11,
  113267. 2,
  113268. 12,
  113269. 1,
  113270. 13,
  113271. 0,
  113272. 14,
  113273. };
  113274. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113275. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113276. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113277. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113278. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113279. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113280. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113281. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113282. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113283. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113284. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113285. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113286. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113287. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113288. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113289. 15,
  113290. };
  113291. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113292. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113293. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113294. };
  113295. static long _vq_quantmap__8c1_s_p9_1[] = {
  113296. 13, 11, 9, 7, 5, 3, 1, 0,
  113297. 2, 4, 6, 8, 10, 12, 14,
  113298. };
  113299. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113300. _vq_quantthresh__8c1_s_p9_1,
  113301. _vq_quantmap__8c1_s_p9_1,
  113302. 15,
  113303. 15
  113304. };
  113305. static static_codebook _8c1_s_p9_1 = {
  113306. 2, 225,
  113307. _vq_lengthlist__8c1_s_p9_1,
  113308. 1, -520986624, 1620377600, 4, 0,
  113309. _vq_quantlist__8c1_s_p9_1,
  113310. NULL,
  113311. &_vq_auxt__8c1_s_p9_1,
  113312. NULL,
  113313. 0
  113314. };
  113315. static long _vq_quantlist__8c1_s_p9_2[] = {
  113316. 10,
  113317. 9,
  113318. 11,
  113319. 8,
  113320. 12,
  113321. 7,
  113322. 13,
  113323. 6,
  113324. 14,
  113325. 5,
  113326. 15,
  113327. 4,
  113328. 16,
  113329. 3,
  113330. 17,
  113331. 2,
  113332. 18,
  113333. 1,
  113334. 19,
  113335. 0,
  113336. 20,
  113337. };
  113338. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113339. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113340. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113341. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113342. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113343. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113344. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113345. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113346. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113347. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113348. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113349. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113350. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113351. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113352. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113353. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113354. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113355. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113356. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113357. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113358. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113359. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113360. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113361. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113362. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113363. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113364. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113365. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113366. 10,10,10,10,10,10,10,10,10,
  113367. };
  113368. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113369. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113370. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113371. 6.5, 7.5, 8.5, 9.5,
  113372. };
  113373. static long _vq_quantmap__8c1_s_p9_2[] = {
  113374. 19, 17, 15, 13, 11, 9, 7, 5,
  113375. 3, 1, 0, 2, 4, 6, 8, 10,
  113376. 12, 14, 16, 18, 20,
  113377. };
  113378. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113379. _vq_quantthresh__8c1_s_p9_2,
  113380. _vq_quantmap__8c1_s_p9_2,
  113381. 21,
  113382. 21
  113383. };
  113384. static static_codebook _8c1_s_p9_2 = {
  113385. 2, 441,
  113386. _vq_lengthlist__8c1_s_p9_2,
  113387. 1, -529268736, 1611661312, 5, 0,
  113388. _vq_quantlist__8c1_s_p9_2,
  113389. NULL,
  113390. &_vq_auxt__8c1_s_p9_2,
  113391. NULL,
  113392. 0
  113393. };
  113394. static long _huff_lengthlist__8c1_s_single[] = {
  113395. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113396. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113397. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113398. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113399. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113400. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113401. 9, 7, 7, 8,
  113402. };
  113403. static static_codebook _huff_book__8c1_s_single = {
  113404. 2, 100,
  113405. _huff_lengthlist__8c1_s_single,
  113406. 0, 0, 0, 0, 0,
  113407. NULL,
  113408. NULL,
  113409. NULL,
  113410. NULL,
  113411. 0
  113412. };
  113413. static long _huff_lengthlist__44c2_s_long[] = {
  113414. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113415. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113416. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113417. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113418. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113419. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113420. 10, 8, 8, 9,
  113421. };
  113422. static static_codebook _huff_book__44c2_s_long = {
  113423. 2, 100,
  113424. _huff_lengthlist__44c2_s_long,
  113425. 0, 0, 0, 0, 0,
  113426. NULL,
  113427. NULL,
  113428. NULL,
  113429. NULL,
  113430. 0
  113431. };
  113432. static long _vq_quantlist__44c2_s_p1_0[] = {
  113433. 1,
  113434. 0,
  113435. 2,
  113436. };
  113437. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113438. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113439. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113443. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113444. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113448. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113449. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113484. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113489. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113494. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113511. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113516. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113521. 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113530. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113535. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113540. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  113556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113557. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  113561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  113849. };
  113850. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113851. -0.5, 0.5,
  113852. };
  113853. static long _vq_quantmap__44c2_s_p1_0[] = {
  113854. 1, 0, 2,
  113855. };
  113856. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113857. _vq_quantthresh__44c2_s_p1_0,
  113858. _vq_quantmap__44c2_s_p1_0,
  113859. 3,
  113860. 3
  113861. };
  113862. static static_codebook _44c2_s_p1_0 = {
  113863. 8, 6561,
  113864. _vq_lengthlist__44c2_s_p1_0,
  113865. 1, -535822336, 1611661312, 2, 0,
  113866. _vq_quantlist__44c2_s_p1_0,
  113867. NULL,
  113868. &_vq_auxt__44c2_s_p1_0,
  113869. NULL,
  113870. 0
  113871. };
  113872. static long _vq_quantlist__44c2_s_p2_0[] = {
  113873. 2,
  113874. 1,
  113875. 3,
  113876. 0,
  113877. 4,
  113878. };
  113879. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113880. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113881. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113882. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113883. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113884. 0, 0, 9, 9, 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, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113890. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113891. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113892. 12, 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, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113898. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113899. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 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. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113906. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113907. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 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,
  113920. };
  113921. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113922. -1.5, -0.5, 0.5, 1.5,
  113923. };
  113924. static long _vq_quantmap__44c2_s_p2_0[] = {
  113925. 3, 1, 0, 2, 4,
  113926. };
  113927. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  113928. _vq_quantthresh__44c2_s_p2_0,
  113929. _vq_quantmap__44c2_s_p2_0,
  113930. 5,
  113931. 5
  113932. };
  113933. static static_codebook _44c2_s_p2_0 = {
  113934. 4, 625,
  113935. _vq_lengthlist__44c2_s_p2_0,
  113936. 1, -533725184, 1611661312, 3, 0,
  113937. _vq_quantlist__44c2_s_p2_0,
  113938. NULL,
  113939. &_vq_auxt__44c2_s_p2_0,
  113940. NULL,
  113941. 0
  113942. };
  113943. static long _vq_quantlist__44c2_s_p3_0[] = {
  113944. 2,
  113945. 1,
  113946. 3,
  113947. 0,
  113948. 4,
  113949. };
  113950. static long _vq_lengthlist__44c2_s_p3_0[] = {
  113951. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113954. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  113956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113957. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113982. 0, 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,
  113991. };
  113992. static float _vq_quantthresh__44c2_s_p3_0[] = {
  113993. -1.5, -0.5, 0.5, 1.5,
  113994. };
  113995. static long _vq_quantmap__44c2_s_p3_0[] = {
  113996. 3, 1, 0, 2, 4,
  113997. };
  113998. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  113999. _vq_quantthresh__44c2_s_p3_0,
  114000. _vq_quantmap__44c2_s_p3_0,
  114001. 5,
  114002. 5
  114003. };
  114004. static static_codebook _44c2_s_p3_0 = {
  114005. 4, 625,
  114006. _vq_lengthlist__44c2_s_p3_0,
  114007. 1, -533725184, 1611661312, 3, 0,
  114008. _vq_quantlist__44c2_s_p3_0,
  114009. NULL,
  114010. &_vq_auxt__44c2_s_p3_0,
  114011. NULL,
  114012. 0
  114013. };
  114014. static long _vq_quantlist__44c2_s_p4_0[] = {
  114015. 4,
  114016. 3,
  114017. 5,
  114018. 2,
  114019. 6,
  114020. 1,
  114021. 7,
  114022. 0,
  114023. 8,
  114024. };
  114025. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114026. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114027. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114028. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114029. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114030. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114031. 0,
  114032. };
  114033. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114034. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114035. };
  114036. static long _vq_quantmap__44c2_s_p4_0[] = {
  114037. 7, 5, 3, 1, 0, 2, 4, 6,
  114038. 8,
  114039. };
  114040. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114041. _vq_quantthresh__44c2_s_p4_0,
  114042. _vq_quantmap__44c2_s_p4_0,
  114043. 9,
  114044. 9
  114045. };
  114046. static static_codebook _44c2_s_p4_0 = {
  114047. 2, 81,
  114048. _vq_lengthlist__44c2_s_p4_0,
  114049. 1, -531628032, 1611661312, 4, 0,
  114050. _vq_quantlist__44c2_s_p4_0,
  114051. NULL,
  114052. &_vq_auxt__44c2_s_p4_0,
  114053. NULL,
  114054. 0
  114055. };
  114056. static long _vq_quantlist__44c2_s_p5_0[] = {
  114057. 4,
  114058. 3,
  114059. 5,
  114060. 2,
  114061. 6,
  114062. 1,
  114063. 7,
  114064. 0,
  114065. 8,
  114066. };
  114067. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114068. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114069. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114070. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114071. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114072. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114073. 11,
  114074. };
  114075. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114076. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114077. };
  114078. static long _vq_quantmap__44c2_s_p5_0[] = {
  114079. 7, 5, 3, 1, 0, 2, 4, 6,
  114080. 8,
  114081. };
  114082. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114083. _vq_quantthresh__44c2_s_p5_0,
  114084. _vq_quantmap__44c2_s_p5_0,
  114085. 9,
  114086. 9
  114087. };
  114088. static static_codebook _44c2_s_p5_0 = {
  114089. 2, 81,
  114090. _vq_lengthlist__44c2_s_p5_0,
  114091. 1, -531628032, 1611661312, 4, 0,
  114092. _vq_quantlist__44c2_s_p5_0,
  114093. NULL,
  114094. &_vq_auxt__44c2_s_p5_0,
  114095. NULL,
  114096. 0
  114097. };
  114098. static long _vq_quantlist__44c2_s_p6_0[] = {
  114099. 8,
  114100. 7,
  114101. 9,
  114102. 6,
  114103. 10,
  114104. 5,
  114105. 11,
  114106. 4,
  114107. 12,
  114108. 3,
  114109. 13,
  114110. 2,
  114111. 14,
  114112. 1,
  114113. 15,
  114114. 0,
  114115. 16,
  114116. };
  114117. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114118. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114119. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114120. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114121. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114122. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114123. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114124. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114125. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114126. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114127. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114128. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114129. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114130. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114131. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114132. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114133. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114134. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114135. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114136. 14,
  114137. };
  114138. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114139. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114140. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114141. };
  114142. static long _vq_quantmap__44c2_s_p6_0[] = {
  114143. 15, 13, 11, 9, 7, 5, 3, 1,
  114144. 0, 2, 4, 6, 8, 10, 12, 14,
  114145. 16,
  114146. };
  114147. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114148. _vq_quantthresh__44c2_s_p6_0,
  114149. _vq_quantmap__44c2_s_p6_0,
  114150. 17,
  114151. 17
  114152. };
  114153. static static_codebook _44c2_s_p6_0 = {
  114154. 2, 289,
  114155. _vq_lengthlist__44c2_s_p6_0,
  114156. 1, -529530880, 1611661312, 5, 0,
  114157. _vq_quantlist__44c2_s_p6_0,
  114158. NULL,
  114159. &_vq_auxt__44c2_s_p6_0,
  114160. NULL,
  114161. 0
  114162. };
  114163. static long _vq_quantlist__44c2_s_p7_0[] = {
  114164. 1,
  114165. 0,
  114166. 2,
  114167. };
  114168. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114169. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114170. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114171. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114172. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114173. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114174. 11,
  114175. };
  114176. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114177. -5.5, 5.5,
  114178. };
  114179. static long _vq_quantmap__44c2_s_p7_0[] = {
  114180. 1, 0, 2,
  114181. };
  114182. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114183. _vq_quantthresh__44c2_s_p7_0,
  114184. _vq_quantmap__44c2_s_p7_0,
  114185. 3,
  114186. 3
  114187. };
  114188. static static_codebook _44c2_s_p7_0 = {
  114189. 4, 81,
  114190. _vq_lengthlist__44c2_s_p7_0,
  114191. 1, -529137664, 1618345984, 2, 0,
  114192. _vq_quantlist__44c2_s_p7_0,
  114193. NULL,
  114194. &_vq_auxt__44c2_s_p7_0,
  114195. NULL,
  114196. 0
  114197. };
  114198. static long _vq_quantlist__44c2_s_p7_1[] = {
  114199. 5,
  114200. 4,
  114201. 6,
  114202. 3,
  114203. 7,
  114204. 2,
  114205. 8,
  114206. 1,
  114207. 9,
  114208. 0,
  114209. 10,
  114210. };
  114211. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114212. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114213. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114214. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114215. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114216. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114217. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114218. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114219. 10,10,10, 8, 8, 8, 8, 8, 8,
  114220. };
  114221. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114222. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114223. 3.5, 4.5,
  114224. };
  114225. static long _vq_quantmap__44c2_s_p7_1[] = {
  114226. 9, 7, 5, 3, 1, 0, 2, 4,
  114227. 6, 8, 10,
  114228. };
  114229. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114230. _vq_quantthresh__44c2_s_p7_1,
  114231. _vq_quantmap__44c2_s_p7_1,
  114232. 11,
  114233. 11
  114234. };
  114235. static static_codebook _44c2_s_p7_1 = {
  114236. 2, 121,
  114237. _vq_lengthlist__44c2_s_p7_1,
  114238. 1, -531365888, 1611661312, 4, 0,
  114239. _vq_quantlist__44c2_s_p7_1,
  114240. NULL,
  114241. &_vq_auxt__44c2_s_p7_1,
  114242. NULL,
  114243. 0
  114244. };
  114245. static long _vq_quantlist__44c2_s_p8_0[] = {
  114246. 6,
  114247. 5,
  114248. 7,
  114249. 4,
  114250. 8,
  114251. 3,
  114252. 9,
  114253. 2,
  114254. 10,
  114255. 1,
  114256. 11,
  114257. 0,
  114258. 12,
  114259. };
  114260. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114261. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114262. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114263. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114264. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114265. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114266. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114267. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114268. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114269. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114270. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114271. 0,12,12,12,12,13,12,14,14,
  114272. };
  114273. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114274. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114275. 12.5, 17.5, 22.5, 27.5,
  114276. };
  114277. static long _vq_quantmap__44c2_s_p8_0[] = {
  114278. 11, 9, 7, 5, 3, 1, 0, 2,
  114279. 4, 6, 8, 10, 12,
  114280. };
  114281. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114282. _vq_quantthresh__44c2_s_p8_0,
  114283. _vq_quantmap__44c2_s_p8_0,
  114284. 13,
  114285. 13
  114286. };
  114287. static static_codebook _44c2_s_p8_0 = {
  114288. 2, 169,
  114289. _vq_lengthlist__44c2_s_p8_0,
  114290. 1, -526516224, 1616117760, 4, 0,
  114291. _vq_quantlist__44c2_s_p8_0,
  114292. NULL,
  114293. &_vq_auxt__44c2_s_p8_0,
  114294. NULL,
  114295. 0
  114296. };
  114297. static long _vq_quantlist__44c2_s_p8_1[] = {
  114298. 2,
  114299. 1,
  114300. 3,
  114301. 0,
  114302. 4,
  114303. };
  114304. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114305. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114306. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114307. };
  114308. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114309. -1.5, -0.5, 0.5, 1.5,
  114310. };
  114311. static long _vq_quantmap__44c2_s_p8_1[] = {
  114312. 3, 1, 0, 2, 4,
  114313. };
  114314. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114315. _vq_quantthresh__44c2_s_p8_1,
  114316. _vq_quantmap__44c2_s_p8_1,
  114317. 5,
  114318. 5
  114319. };
  114320. static static_codebook _44c2_s_p8_1 = {
  114321. 2, 25,
  114322. _vq_lengthlist__44c2_s_p8_1,
  114323. 1, -533725184, 1611661312, 3, 0,
  114324. _vq_quantlist__44c2_s_p8_1,
  114325. NULL,
  114326. &_vq_auxt__44c2_s_p8_1,
  114327. NULL,
  114328. 0
  114329. };
  114330. static long _vq_quantlist__44c2_s_p9_0[] = {
  114331. 6,
  114332. 5,
  114333. 7,
  114334. 4,
  114335. 8,
  114336. 3,
  114337. 9,
  114338. 2,
  114339. 10,
  114340. 1,
  114341. 11,
  114342. 0,
  114343. 12,
  114344. };
  114345. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114346. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114347. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114348. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114349. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114350. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114351. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114352. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114353. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114354. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114355. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114356. 11,11,11,11,11,11,11,11,11,
  114357. };
  114358. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114359. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114360. 552.5, 773.5, 994.5, 1215.5,
  114361. };
  114362. static long _vq_quantmap__44c2_s_p9_0[] = {
  114363. 11, 9, 7, 5, 3, 1, 0, 2,
  114364. 4, 6, 8, 10, 12,
  114365. };
  114366. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114367. _vq_quantthresh__44c2_s_p9_0,
  114368. _vq_quantmap__44c2_s_p9_0,
  114369. 13,
  114370. 13
  114371. };
  114372. static static_codebook _44c2_s_p9_0 = {
  114373. 2, 169,
  114374. _vq_lengthlist__44c2_s_p9_0,
  114375. 1, -514541568, 1627103232, 4, 0,
  114376. _vq_quantlist__44c2_s_p9_0,
  114377. NULL,
  114378. &_vq_auxt__44c2_s_p9_0,
  114379. NULL,
  114380. 0
  114381. };
  114382. static long _vq_quantlist__44c2_s_p9_1[] = {
  114383. 6,
  114384. 5,
  114385. 7,
  114386. 4,
  114387. 8,
  114388. 3,
  114389. 9,
  114390. 2,
  114391. 10,
  114392. 1,
  114393. 11,
  114394. 0,
  114395. 12,
  114396. };
  114397. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114398. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114399. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114400. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114401. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114402. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114403. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114404. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114405. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114406. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114407. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114408. 17,13,12,12,10,13,11,14,14,
  114409. };
  114410. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114411. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114412. 42.5, 59.5, 76.5, 93.5,
  114413. };
  114414. static long _vq_quantmap__44c2_s_p9_1[] = {
  114415. 11, 9, 7, 5, 3, 1, 0, 2,
  114416. 4, 6, 8, 10, 12,
  114417. };
  114418. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114419. _vq_quantthresh__44c2_s_p9_1,
  114420. _vq_quantmap__44c2_s_p9_1,
  114421. 13,
  114422. 13
  114423. };
  114424. static static_codebook _44c2_s_p9_1 = {
  114425. 2, 169,
  114426. _vq_lengthlist__44c2_s_p9_1,
  114427. 1, -522616832, 1620115456, 4, 0,
  114428. _vq_quantlist__44c2_s_p9_1,
  114429. NULL,
  114430. &_vq_auxt__44c2_s_p9_1,
  114431. NULL,
  114432. 0
  114433. };
  114434. static long _vq_quantlist__44c2_s_p9_2[] = {
  114435. 8,
  114436. 7,
  114437. 9,
  114438. 6,
  114439. 10,
  114440. 5,
  114441. 11,
  114442. 4,
  114443. 12,
  114444. 3,
  114445. 13,
  114446. 2,
  114447. 14,
  114448. 1,
  114449. 15,
  114450. 0,
  114451. 16,
  114452. };
  114453. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114454. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114455. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114456. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114457. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114458. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114459. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114460. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114461. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114462. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114463. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114464. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114465. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114466. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114467. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114468. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114469. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114470. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114471. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114472. 10,
  114473. };
  114474. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114475. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114476. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114477. };
  114478. static long _vq_quantmap__44c2_s_p9_2[] = {
  114479. 15, 13, 11, 9, 7, 5, 3, 1,
  114480. 0, 2, 4, 6, 8, 10, 12, 14,
  114481. 16,
  114482. };
  114483. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114484. _vq_quantthresh__44c2_s_p9_2,
  114485. _vq_quantmap__44c2_s_p9_2,
  114486. 17,
  114487. 17
  114488. };
  114489. static static_codebook _44c2_s_p9_2 = {
  114490. 2, 289,
  114491. _vq_lengthlist__44c2_s_p9_2,
  114492. 1, -529530880, 1611661312, 5, 0,
  114493. _vq_quantlist__44c2_s_p9_2,
  114494. NULL,
  114495. &_vq_auxt__44c2_s_p9_2,
  114496. NULL,
  114497. 0
  114498. };
  114499. static long _huff_lengthlist__44c2_s_short[] = {
  114500. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114501. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114502. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114503. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114504. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114505. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114506. 6, 8, 9,12,
  114507. };
  114508. static static_codebook _huff_book__44c2_s_short = {
  114509. 2, 100,
  114510. _huff_lengthlist__44c2_s_short,
  114511. 0, 0, 0, 0, 0,
  114512. NULL,
  114513. NULL,
  114514. NULL,
  114515. NULL,
  114516. 0
  114517. };
  114518. static long _huff_lengthlist__44c3_s_long[] = {
  114519. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114520. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114521. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114522. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114523. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114524. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114525. 9, 8, 8, 8,
  114526. };
  114527. static static_codebook _huff_book__44c3_s_long = {
  114528. 2, 100,
  114529. _huff_lengthlist__44c3_s_long,
  114530. 0, 0, 0, 0, 0,
  114531. NULL,
  114532. NULL,
  114533. NULL,
  114534. NULL,
  114535. 0
  114536. };
  114537. static long _vq_quantlist__44c3_s_p1_0[] = {
  114538. 1,
  114539. 0,
  114540. 2,
  114541. };
  114542. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114543. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114544. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114548. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114549. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114553. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114554. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114589. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114594. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  114599. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114616. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114621. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114626. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114635. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114640. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114645. 0, 0, 0, 0, 0, 0, 8, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  114661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114662. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  114666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  114954. };
  114955. static float _vq_quantthresh__44c3_s_p1_0[] = {
  114956. -0.5, 0.5,
  114957. };
  114958. static long _vq_quantmap__44c3_s_p1_0[] = {
  114959. 1, 0, 2,
  114960. };
  114961. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  114962. _vq_quantthresh__44c3_s_p1_0,
  114963. _vq_quantmap__44c3_s_p1_0,
  114964. 3,
  114965. 3
  114966. };
  114967. static static_codebook _44c3_s_p1_0 = {
  114968. 8, 6561,
  114969. _vq_lengthlist__44c3_s_p1_0,
  114970. 1, -535822336, 1611661312, 2, 0,
  114971. _vq_quantlist__44c3_s_p1_0,
  114972. NULL,
  114973. &_vq_auxt__44c3_s_p1_0,
  114974. NULL,
  114975. 0
  114976. };
  114977. static long _vq_quantlist__44c3_s_p2_0[] = {
  114978. 2,
  114979. 1,
  114980. 3,
  114981. 0,
  114982. 4,
  114983. };
  114984. static long _vq_lengthlist__44c3_s_p2_0[] = {
  114985. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  114986. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  114987. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114988. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  114989. 0, 0,10,10, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  114995. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  114996. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  114997. 9, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115003. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115004. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115011. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115012. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 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,
  115025. };
  115026. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115027. -1.5, -0.5, 0.5, 1.5,
  115028. };
  115029. static long _vq_quantmap__44c3_s_p2_0[] = {
  115030. 3, 1, 0, 2, 4,
  115031. };
  115032. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115033. _vq_quantthresh__44c3_s_p2_0,
  115034. _vq_quantmap__44c3_s_p2_0,
  115035. 5,
  115036. 5
  115037. };
  115038. static static_codebook _44c3_s_p2_0 = {
  115039. 4, 625,
  115040. _vq_lengthlist__44c3_s_p2_0,
  115041. 1, -533725184, 1611661312, 3, 0,
  115042. _vq_quantlist__44c3_s_p2_0,
  115043. NULL,
  115044. &_vq_auxt__44c3_s_p2_0,
  115045. NULL,
  115046. 0
  115047. };
  115048. static long _vq_quantlist__44c3_s_p3_0[] = {
  115049. 2,
  115050. 1,
  115051. 3,
  115052. 0,
  115053. 4,
  115054. };
  115055. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115056. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115059. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115062. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115087. 0, 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,
  115096. };
  115097. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115098. -1.5, -0.5, 0.5, 1.5,
  115099. };
  115100. static long _vq_quantmap__44c3_s_p3_0[] = {
  115101. 3, 1, 0, 2, 4,
  115102. };
  115103. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115104. _vq_quantthresh__44c3_s_p3_0,
  115105. _vq_quantmap__44c3_s_p3_0,
  115106. 5,
  115107. 5
  115108. };
  115109. static static_codebook _44c3_s_p3_0 = {
  115110. 4, 625,
  115111. _vq_lengthlist__44c3_s_p3_0,
  115112. 1, -533725184, 1611661312, 3, 0,
  115113. _vq_quantlist__44c3_s_p3_0,
  115114. NULL,
  115115. &_vq_auxt__44c3_s_p3_0,
  115116. NULL,
  115117. 0
  115118. };
  115119. static long _vq_quantlist__44c3_s_p4_0[] = {
  115120. 4,
  115121. 3,
  115122. 5,
  115123. 2,
  115124. 6,
  115125. 1,
  115126. 7,
  115127. 0,
  115128. 8,
  115129. };
  115130. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115131. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115132. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115133. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115134. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115135. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115136. 0,
  115137. };
  115138. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115139. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115140. };
  115141. static long _vq_quantmap__44c3_s_p4_0[] = {
  115142. 7, 5, 3, 1, 0, 2, 4, 6,
  115143. 8,
  115144. };
  115145. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115146. _vq_quantthresh__44c3_s_p4_0,
  115147. _vq_quantmap__44c3_s_p4_0,
  115148. 9,
  115149. 9
  115150. };
  115151. static static_codebook _44c3_s_p4_0 = {
  115152. 2, 81,
  115153. _vq_lengthlist__44c3_s_p4_0,
  115154. 1, -531628032, 1611661312, 4, 0,
  115155. _vq_quantlist__44c3_s_p4_0,
  115156. NULL,
  115157. &_vq_auxt__44c3_s_p4_0,
  115158. NULL,
  115159. 0
  115160. };
  115161. static long _vq_quantlist__44c3_s_p5_0[] = {
  115162. 4,
  115163. 3,
  115164. 5,
  115165. 2,
  115166. 6,
  115167. 1,
  115168. 7,
  115169. 0,
  115170. 8,
  115171. };
  115172. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115173. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115174. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115175. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115176. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115177. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115178. 11,
  115179. };
  115180. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115181. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115182. };
  115183. static long _vq_quantmap__44c3_s_p5_0[] = {
  115184. 7, 5, 3, 1, 0, 2, 4, 6,
  115185. 8,
  115186. };
  115187. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115188. _vq_quantthresh__44c3_s_p5_0,
  115189. _vq_quantmap__44c3_s_p5_0,
  115190. 9,
  115191. 9
  115192. };
  115193. static static_codebook _44c3_s_p5_0 = {
  115194. 2, 81,
  115195. _vq_lengthlist__44c3_s_p5_0,
  115196. 1, -531628032, 1611661312, 4, 0,
  115197. _vq_quantlist__44c3_s_p5_0,
  115198. NULL,
  115199. &_vq_auxt__44c3_s_p5_0,
  115200. NULL,
  115201. 0
  115202. };
  115203. static long _vq_quantlist__44c3_s_p6_0[] = {
  115204. 8,
  115205. 7,
  115206. 9,
  115207. 6,
  115208. 10,
  115209. 5,
  115210. 11,
  115211. 4,
  115212. 12,
  115213. 3,
  115214. 13,
  115215. 2,
  115216. 14,
  115217. 1,
  115218. 15,
  115219. 0,
  115220. 16,
  115221. };
  115222. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115223. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115224. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115225. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115226. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115227. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115228. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115229. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115230. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115231. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115232. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115233. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115234. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115235. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115236. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115237. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115238. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115239. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115240. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115241. 13,
  115242. };
  115243. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115244. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115245. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115246. };
  115247. static long _vq_quantmap__44c3_s_p6_0[] = {
  115248. 15, 13, 11, 9, 7, 5, 3, 1,
  115249. 0, 2, 4, 6, 8, 10, 12, 14,
  115250. 16,
  115251. };
  115252. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115253. _vq_quantthresh__44c3_s_p6_0,
  115254. _vq_quantmap__44c3_s_p6_0,
  115255. 17,
  115256. 17
  115257. };
  115258. static static_codebook _44c3_s_p6_0 = {
  115259. 2, 289,
  115260. _vq_lengthlist__44c3_s_p6_0,
  115261. 1, -529530880, 1611661312, 5, 0,
  115262. _vq_quantlist__44c3_s_p6_0,
  115263. NULL,
  115264. &_vq_auxt__44c3_s_p6_0,
  115265. NULL,
  115266. 0
  115267. };
  115268. static long _vq_quantlist__44c3_s_p7_0[] = {
  115269. 1,
  115270. 0,
  115271. 2,
  115272. };
  115273. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115274. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115275. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115276. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115277. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115278. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115279. 10,
  115280. };
  115281. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115282. -5.5, 5.5,
  115283. };
  115284. static long _vq_quantmap__44c3_s_p7_0[] = {
  115285. 1, 0, 2,
  115286. };
  115287. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115288. _vq_quantthresh__44c3_s_p7_0,
  115289. _vq_quantmap__44c3_s_p7_0,
  115290. 3,
  115291. 3
  115292. };
  115293. static static_codebook _44c3_s_p7_0 = {
  115294. 4, 81,
  115295. _vq_lengthlist__44c3_s_p7_0,
  115296. 1, -529137664, 1618345984, 2, 0,
  115297. _vq_quantlist__44c3_s_p7_0,
  115298. NULL,
  115299. &_vq_auxt__44c3_s_p7_0,
  115300. NULL,
  115301. 0
  115302. };
  115303. static long _vq_quantlist__44c3_s_p7_1[] = {
  115304. 5,
  115305. 4,
  115306. 6,
  115307. 3,
  115308. 7,
  115309. 2,
  115310. 8,
  115311. 1,
  115312. 9,
  115313. 0,
  115314. 10,
  115315. };
  115316. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115317. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115318. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115319. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115320. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115321. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115322. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115323. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115324. 10,10,10, 8, 8, 8, 8, 8, 8,
  115325. };
  115326. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115327. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115328. 3.5, 4.5,
  115329. };
  115330. static long _vq_quantmap__44c3_s_p7_1[] = {
  115331. 9, 7, 5, 3, 1, 0, 2, 4,
  115332. 6, 8, 10,
  115333. };
  115334. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115335. _vq_quantthresh__44c3_s_p7_1,
  115336. _vq_quantmap__44c3_s_p7_1,
  115337. 11,
  115338. 11
  115339. };
  115340. static static_codebook _44c3_s_p7_1 = {
  115341. 2, 121,
  115342. _vq_lengthlist__44c3_s_p7_1,
  115343. 1, -531365888, 1611661312, 4, 0,
  115344. _vq_quantlist__44c3_s_p7_1,
  115345. NULL,
  115346. &_vq_auxt__44c3_s_p7_1,
  115347. NULL,
  115348. 0
  115349. };
  115350. static long _vq_quantlist__44c3_s_p8_0[] = {
  115351. 6,
  115352. 5,
  115353. 7,
  115354. 4,
  115355. 8,
  115356. 3,
  115357. 9,
  115358. 2,
  115359. 10,
  115360. 1,
  115361. 11,
  115362. 0,
  115363. 12,
  115364. };
  115365. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115366. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115367. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115368. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115369. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115370. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115371. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115372. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115373. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115374. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115375. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115376. 0,13,13,12,12,13,12,14,13,
  115377. };
  115378. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115379. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115380. 12.5, 17.5, 22.5, 27.5,
  115381. };
  115382. static long _vq_quantmap__44c3_s_p8_0[] = {
  115383. 11, 9, 7, 5, 3, 1, 0, 2,
  115384. 4, 6, 8, 10, 12,
  115385. };
  115386. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115387. _vq_quantthresh__44c3_s_p8_0,
  115388. _vq_quantmap__44c3_s_p8_0,
  115389. 13,
  115390. 13
  115391. };
  115392. static static_codebook _44c3_s_p8_0 = {
  115393. 2, 169,
  115394. _vq_lengthlist__44c3_s_p8_0,
  115395. 1, -526516224, 1616117760, 4, 0,
  115396. _vq_quantlist__44c3_s_p8_0,
  115397. NULL,
  115398. &_vq_auxt__44c3_s_p8_0,
  115399. NULL,
  115400. 0
  115401. };
  115402. static long _vq_quantlist__44c3_s_p8_1[] = {
  115403. 2,
  115404. 1,
  115405. 3,
  115406. 0,
  115407. 4,
  115408. };
  115409. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115410. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115411. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115412. };
  115413. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115414. -1.5, -0.5, 0.5, 1.5,
  115415. };
  115416. static long _vq_quantmap__44c3_s_p8_1[] = {
  115417. 3, 1, 0, 2, 4,
  115418. };
  115419. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115420. _vq_quantthresh__44c3_s_p8_1,
  115421. _vq_quantmap__44c3_s_p8_1,
  115422. 5,
  115423. 5
  115424. };
  115425. static static_codebook _44c3_s_p8_1 = {
  115426. 2, 25,
  115427. _vq_lengthlist__44c3_s_p8_1,
  115428. 1, -533725184, 1611661312, 3, 0,
  115429. _vq_quantlist__44c3_s_p8_1,
  115430. NULL,
  115431. &_vq_auxt__44c3_s_p8_1,
  115432. NULL,
  115433. 0
  115434. };
  115435. static long _vq_quantlist__44c3_s_p9_0[] = {
  115436. 6,
  115437. 5,
  115438. 7,
  115439. 4,
  115440. 8,
  115441. 3,
  115442. 9,
  115443. 2,
  115444. 10,
  115445. 1,
  115446. 11,
  115447. 0,
  115448. 12,
  115449. };
  115450. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115451. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115452. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115453. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115454. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115455. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115456. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115457. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115458. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115459. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115460. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115461. 11,11,11,11,11,11,11,11,11,
  115462. };
  115463. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115464. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115465. 637.5, 892.5, 1147.5, 1402.5,
  115466. };
  115467. static long _vq_quantmap__44c3_s_p9_0[] = {
  115468. 11, 9, 7, 5, 3, 1, 0, 2,
  115469. 4, 6, 8, 10, 12,
  115470. };
  115471. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115472. _vq_quantthresh__44c3_s_p9_0,
  115473. _vq_quantmap__44c3_s_p9_0,
  115474. 13,
  115475. 13
  115476. };
  115477. static static_codebook _44c3_s_p9_0 = {
  115478. 2, 169,
  115479. _vq_lengthlist__44c3_s_p9_0,
  115480. 1, -514332672, 1627381760, 4, 0,
  115481. _vq_quantlist__44c3_s_p9_0,
  115482. NULL,
  115483. &_vq_auxt__44c3_s_p9_0,
  115484. NULL,
  115485. 0
  115486. };
  115487. static long _vq_quantlist__44c3_s_p9_1[] = {
  115488. 7,
  115489. 6,
  115490. 8,
  115491. 5,
  115492. 9,
  115493. 4,
  115494. 10,
  115495. 3,
  115496. 11,
  115497. 2,
  115498. 12,
  115499. 1,
  115500. 13,
  115501. 0,
  115502. 14,
  115503. };
  115504. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115505. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115506. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115507. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115508. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115509. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115510. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115511. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115512. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115513. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115514. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115515. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115516. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115517. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115518. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115519. 15,
  115520. };
  115521. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115522. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115523. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115524. };
  115525. static long _vq_quantmap__44c3_s_p9_1[] = {
  115526. 13, 11, 9, 7, 5, 3, 1, 0,
  115527. 2, 4, 6, 8, 10, 12, 14,
  115528. };
  115529. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115530. _vq_quantthresh__44c3_s_p9_1,
  115531. _vq_quantmap__44c3_s_p9_1,
  115532. 15,
  115533. 15
  115534. };
  115535. static static_codebook _44c3_s_p9_1 = {
  115536. 2, 225,
  115537. _vq_lengthlist__44c3_s_p9_1,
  115538. 1, -522338304, 1620115456, 4, 0,
  115539. _vq_quantlist__44c3_s_p9_1,
  115540. NULL,
  115541. &_vq_auxt__44c3_s_p9_1,
  115542. NULL,
  115543. 0
  115544. };
  115545. static long _vq_quantlist__44c3_s_p9_2[] = {
  115546. 8,
  115547. 7,
  115548. 9,
  115549. 6,
  115550. 10,
  115551. 5,
  115552. 11,
  115553. 4,
  115554. 12,
  115555. 3,
  115556. 13,
  115557. 2,
  115558. 14,
  115559. 1,
  115560. 15,
  115561. 0,
  115562. 16,
  115563. };
  115564. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115565. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115566. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115567. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115568. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115569. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115570. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115571. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115572. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115573. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115574. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115575. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115576. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115577. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115578. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115579. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115580. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115581. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115582. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115583. 10,
  115584. };
  115585. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115586. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115587. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115588. };
  115589. static long _vq_quantmap__44c3_s_p9_2[] = {
  115590. 15, 13, 11, 9, 7, 5, 3, 1,
  115591. 0, 2, 4, 6, 8, 10, 12, 14,
  115592. 16,
  115593. };
  115594. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115595. _vq_quantthresh__44c3_s_p9_2,
  115596. _vq_quantmap__44c3_s_p9_2,
  115597. 17,
  115598. 17
  115599. };
  115600. static static_codebook _44c3_s_p9_2 = {
  115601. 2, 289,
  115602. _vq_lengthlist__44c3_s_p9_2,
  115603. 1, -529530880, 1611661312, 5, 0,
  115604. _vq_quantlist__44c3_s_p9_2,
  115605. NULL,
  115606. &_vq_auxt__44c3_s_p9_2,
  115607. NULL,
  115608. 0
  115609. };
  115610. static long _huff_lengthlist__44c3_s_short[] = {
  115611. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115612. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115613. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115614. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115615. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115616. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115617. 6, 8, 9,11,
  115618. };
  115619. static static_codebook _huff_book__44c3_s_short = {
  115620. 2, 100,
  115621. _huff_lengthlist__44c3_s_short,
  115622. 0, 0, 0, 0, 0,
  115623. NULL,
  115624. NULL,
  115625. NULL,
  115626. NULL,
  115627. 0
  115628. };
  115629. static long _huff_lengthlist__44c4_s_long[] = {
  115630. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115631. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115632. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115633. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115634. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115635. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115636. 9, 8, 7, 7,
  115637. };
  115638. static static_codebook _huff_book__44c4_s_long = {
  115639. 2, 100,
  115640. _huff_lengthlist__44c4_s_long,
  115641. 0, 0, 0, 0, 0,
  115642. NULL,
  115643. NULL,
  115644. NULL,
  115645. NULL,
  115646. 0
  115647. };
  115648. static long _vq_quantlist__44c4_s_p1_0[] = {
  115649. 1,
  115650. 0,
  115651. 2,
  115652. };
  115653. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115654. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115655. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115659. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115660. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115664. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115665. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115700. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115705. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115710. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115727. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115732. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115737. 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115746. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115751. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115756. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  115772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115773. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  115777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  116065. };
  116066. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116067. -0.5, 0.5,
  116068. };
  116069. static long _vq_quantmap__44c4_s_p1_0[] = {
  116070. 1, 0, 2,
  116071. };
  116072. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116073. _vq_quantthresh__44c4_s_p1_0,
  116074. _vq_quantmap__44c4_s_p1_0,
  116075. 3,
  116076. 3
  116077. };
  116078. static static_codebook _44c4_s_p1_0 = {
  116079. 8, 6561,
  116080. _vq_lengthlist__44c4_s_p1_0,
  116081. 1, -535822336, 1611661312, 2, 0,
  116082. _vq_quantlist__44c4_s_p1_0,
  116083. NULL,
  116084. &_vq_auxt__44c4_s_p1_0,
  116085. NULL,
  116086. 0
  116087. };
  116088. static long _vq_quantlist__44c4_s_p2_0[] = {
  116089. 2,
  116090. 1,
  116091. 3,
  116092. 0,
  116093. 4,
  116094. };
  116095. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116096. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116097. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116098. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116099. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116100. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116106. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116107. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116108. 9, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116114. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116115. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116122. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116123. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 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,
  116136. };
  116137. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116138. -1.5, -0.5, 0.5, 1.5,
  116139. };
  116140. static long _vq_quantmap__44c4_s_p2_0[] = {
  116141. 3, 1, 0, 2, 4,
  116142. };
  116143. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116144. _vq_quantthresh__44c4_s_p2_0,
  116145. _vq_quantmap__44c4_s_p2_0,
  116146. 5,
  116147. 5
  116148. };
  116149. static static_codebook _44c4_s_p2_0 = {
  116150. 4, 625,
  116151. _vq_lengthlist__44c4_s_p2_0,
  116152. 1, -533725184, 1611661312, 3, 0,
  116153. _vq_quantlist__44c4_s_p2_0,
  116154. NULL,
  116155. &_vq_auxt__44c4_s_p2_0,
  116156. NULL,
  116157. 0
  116158. };
  116159. static long _vq_quantlist__44c4_s_p3_0[] = {
  116160. 2,
  116161. 1,
  116162. 3,
  116163. 0,
  116164. 4,
  116165. };
  116166. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116167. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116170. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116173. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116198. 0, 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,
  116207. };
  116208. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116209. -1.5, -0.5, 0.5, 1.5,
  116210. };
  116211. static long _vq_quantmap__44c4_s_p3_0[] = {
  116212. 3, 1, 0, 2, 4,
  116213. };
  116214. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116215. _vq_quantthresh__44c4_s_p3_0,
  116216. _vq_quantmap__44c4_s_p3_0,
  116217. 5,
  116218. 5
  116219. };
  116220. static static_codebook _44c4_s_p3_0 = {
  116221. 4, 625,
  116222. _vq_lengthlist__44c4_s_p3_0,
  116223. 1, -533725184, 1611661312, 3, 0,
  116224. _vq_quantlist__44c4_s_p3_0,
  116225. NULL,
  116226. &_vq_auxt__44c4_s_p3_0,
  116227. NULL,
  116228. 0
  116229. };
  116230. static long _vq_quantlist__44c4_s_p4_0[] = {
  116231. 4,
  116232. 3,
  116233. 5,
  116234. 2,
  116235. 6,
  116236. 1,
  116237. 7,
  116238. 0,
  116239. 8,
  116240. };
  116241. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116242. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116243. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116244. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116245. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116246. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116247. 0,
  116248. };
  116249. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116250. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116251. };
  116252. static long _vq_quantmap__44c4_s_p4_0[] = {
  116253. 7, 5, 3, 1, 0, 2, 4, 6,
  116254. 8,
  116255. };
  116256. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116257. _vq_quantthresh__44c4_s_p4_0,
  116258. _vq_quantmap__44c4_s_p4_0,
  116259. 9,
  116260. 9
  116261. };
  116262. static static_codebook _44c4_s_p4_0 = {
  116263. 2, 81,
  116264. _vq_lengthlist__44c4_s_p4_0,
  116265. 1, -531628032, 1611661312, 4, 0,
  116266. _vq_quantlist__44c4_s_p4_0,
  116267. NULL,
  116268. &_vq_auxt__44c4_s_p4_0,
  116269. NULL,
  116270. 0
  116271. };
  116272. static long _vq_quantlist__44c4_s_p5_0[] = {
  116273. 4,
  116274. 3,
  116275. 5,
  116276. 2,
  116277. 6,
  116278. 1,
  116279. 7,
  116280. 0,
  116281. 8,
  116282. };
  116283. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116284. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116285. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116286. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116287. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116288. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116289. 10,
  116290. };
  116291. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116292. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116293. };
  116294. static long _vq_quantmap__44c4_s_p5_0[] = {
  116295. 7, 5, 3, 1, 0, 2, 4, 6,
  116296. 8,
  116297. };
  116298. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116299. _vq_quantthresh__44c4_s_p5_0,
  116300. _vq_quantmap__44c4_s_p5_0,
  116301. 9,
  116302. 9
  116303. };
  116304. static static_codebook _44c4_s_p5_0 = {
  116305. 2, 81,
  116306. _vq_lengthlist__44c4_s_p5_0,
  116307. 1, -531628032, 1611661312, 4, 0,
  116308. _vq_quantlist__44c4_s_p5_0,
  116309. NULL,
  116310. &_vq_auxt__44c4_s_p5_0,
  116311. NULL,
  116312. 0
  116313. };
  116314. static long _vq_quantlist__44c4_s_p6_0[] = {
  116315. 8,
  116316. 7,
  116317. 9,
  116318. 6,
  116319. 10,
  116320. 5,
  116321. 11,
  116322. 4,
  116323. 12,
  116324. 3,
  116325. 13,
  116326. 2,
  116327. 14,
  116328. 1,
  116329. 15,
  116330. 0,
  116331. 16,
  116332. };
  116333. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116334. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116335. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116336. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116337. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116338. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116339. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116340. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116341. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116342. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116343. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116344. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116345. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116346. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116347. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116348. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116349. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116350. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116351. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116352. 13,
  116353. };
  116354. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116355. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116356. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116357. };
  116358. static long _vq_quantmap__44c4_s_p6_0[] = {
  116359. 15, 13, 11, 9, 7, 5, 3, 1,
  116360. 0, 2, 4, 6, 8, 10, 12, 14,
  116361. 16,
  116362. };
  116363. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116364. _vq_quantthresh__44c4_s_p6_0,
  116365. _vq_quantmap__44c4_s_p6_0,
  116366. 17,
  116367. 17
  116368. };
  116369. static static_codebook _44c4_s_p6_0 = {
  116370. 2, 289,
  116371. _vq_lengthlist__44c4_s_p6_0,
  116372. 1, -529530880, 1611661312, 5, 0,
  116373. _vq_quantlist__44c4_s_p6_0,
  116374. NULL,
  116375. &_vq_auxt__44c4_s_p6_0,
  116376. NULL,
  116377. 0
  116378. };
  116379. static long _vq_quantlist__44c4_s_p7_0[] = {
  116380. 1,
  116381. 0,
  116382. 2,
  116383. };
  116384. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116385. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116386. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116387. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116388. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116389. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116390. 10,
  116391. };
  116392. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116393. -5.5, 5.5,
  116394. };
  116395. static long _vq_quantmap__44c4_s_p7_0[] = {
  116396. 1, 0, 2,
  116397. };
  116398. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116399. _vq_quantthresh__44c4_s_p7_0,
  116400. _vq_quantmap__44c4_s_p7_0,
  116401. 3,
  116402. 3
  116403. };
  116404. static static_codebook _44c4_s_p7_0 = {
  116405. 4, 81,
  116406. _vq_lengthlist__44c4_s_p7_0,
  116407. 1, -529137664, 1618345984, 2, 0,
  116408. _vq_quantlist__44c4_s_p7_0,
  116409. NULL,
  116410. &_vq_auxt__44c4_s_p7_0,
  116411. NULL,
  116412. 0
  116413. };
  116414. static long _vq_quantlist__44c4_s_p7_1[] = {
  116415. 5,
  116416. 4,
  116417. 6,
  116418. 3,
  116419. 7,
  116420. 2,
  116421. 8,
  116422. 1,
  116423. 9,
  116424. 0,
  116425. 10,
  116426. };
  116427. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116428. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116429. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116430. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116431. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116432. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116433. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116434. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116435. 10,10,10, 8, 8, 8, 8, 9, 9,
  116436. };
  116437. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116438. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116439. 3.5, 4.5,
  116440. };
  116441. static long _vq_quantmap__44c4_s_p7_1[] = {
  116442. 9, 7, 5, 3, 1, 0, 2, 4,
  116443. 6, 8, 10,
  116444. };
  116445. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116446. _vq_quantthresh__44c4_s_p7_1,
  116447. _vq_quantmap__44c4_s_p7_1,
  116448. 11,
  116449. 11
  116450. };
  116451. static static_codebook _44c4_s_p7_1 = {
  116452. 2, 121,
  116453. _vq_lengthlist__44c4_s_p7_1,
  116454. 1, -531365888, 1611661312, 4, 0,
  116455. _vq_quantlist__44c4_s_p7_1,
  116456. NULL,
  116457. &_vq_auxt__44c4_s_p7_1,
  116458. NULL,
  116459. 0
  116460. };
  116461. static long _vq_quantlist__44c4_s_p8_0[] = {
  116462. 6,
  116463. 5,
  116464. 7,
  116465. 4,
  116466. 8,
  116467. 3,
  116468. 9,
  116469. 2,
  116470. 10,
  116471. 1,
  116472. 11,
  116473. 0,
  116474. 12,
  116475. };
  116476. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116477. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116478. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116479. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116480. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116481. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116482. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116483. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116484. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116485. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116486. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116487. 0,13,12,12,12,12,12,13,13,
  116488. };
  116489. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116490. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116491. 12.5, 17.5, 22.5, 27.5,
  116492. };
  116493. static long _vq_quantmap__44c4_s_p8_0[] = {
  116494. 11, 9, 7, 5, 3, 1, 0, 2,
  116495. 4, 6, 8, 10, 12,
  116496. };
  116497. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116498. _vq_quantthresh__44c4_s_p8_0,
  116499. _vq_quantmap__44c4_s_p8_0,
  116500. 13,
  116501. 13
  116502. };
  116503. static static_codebook _44c4_s_p8_0 = {
  116504. 2, 169,
  116505. _vq_lengthlist__44c4_s_p8_0,
  116506. 1, -526516224, 1616117760, 4, 0,
  116507. _vq_quantlist__44c4_s_p8_0,
  116508. NULL,
  116509. &_vq_auxt__44c4_s_p8_0,
  116510. NULL,
  116511. 0
  116512. };
  116513. static long _vq_quantlist__44c4_s_p8_1[] = {
  116514. 2,
  116515. 1,
  116516. 3,
  116517. 0,
  116518. 4,
  116519. };
  116520. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116521. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116522. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116523. };
  116524. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116525. -1.5, -0.5, 0.5, 1.5,
  116526. };
  116527. static long _vq_quantmap__44c4_s_p8_1[] = {
  116528. 3, 1, 0, 2, 4,
  116529. };
  116530. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116531. _vq_quantthresh__44c4_s_p8_1,
  116532. _vq_quantmap__44c4_s_p8_1,
  116533. 5,
  116534. 5
  116535. };
  116536. static static_codebook _44c4_s_p8_1 = {
  116537. 2, 25,
  116538. _vq_lengthlist__44c4_s_p8_1,
  116539. 1, -533725184, 1611661312, 3, 0,
  116540. _vq_quantlist__44c4_s_p8_1,
  116541. NULL,
  116542. &_vq_auxt__44c4_s_p8_1,
  116543. NULL,
  116544. 0
  116545. };
  116546. static long _vq_quantlist__44c4_s_p9_0[] = {
  116547. 6,
  116548. 5,
  116549. 7,
  116550. 4,
  116551. 8,
  116552. 3,
  116553. 9,
  116554. 2,
  116555. 10,
  116556. 1,
  116557. 11,
  116558. 0,
  116559. 12,
  116560. };
  116561. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116562. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116563. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116564. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116565. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116566. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116567. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116568. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116569. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116570. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116571. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116572. 12,12,12,12,12,12,12,12,12,
  116573. };
  116574. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116575. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116576. 787.5, 1102.5, 1417.5, 1732.5,
  116577. };
  116578. static long _vq_quantmap__44c4_s_p9_0[] = {
  116579. 11, 9, 7, 5, 3, 1, 0, 2,
  116580. 4, 6, 8, 10, 12,
  116581. };
  116582. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116583. _vq_quantthresh__44c4_s_p9_0,
  116584. _vq_quantmap__44c4_s_p9_0,
  116585. 13,
  116586. 13
  116587. };
  116588. static static_codebook _44c4_s_p9_0 = {
  116589. 2, 169,
  116590. _vq_lengthlist__44c4_s_p9_0,
  116591. 1, -513964032, 1628680192, 4, 0,
  116592. _vq_quantlist__44c4_s_p9_0,
  116593. NULL,
  116594. &_vq_auxt__44c4_s_p9_0,
  116595. NULL,
  116596. 0
  116597. };
  116598. static long _vq_quantlist__44c4_s_p9_1[] = {
  116599. 7,
  116600. 6,
  116601. 8,
  116602. 5,
  116603. 9,
  116604. 4,
  116605. 10,
  116606. 3,
  116607. 11,
  116608. 2,
  116609. 12,
  116610. 1,
  116611. 13,
  116612. 0,
  116613. 14,
  116614. };
  116615. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116616. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116617. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116618. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116619. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116620. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116621. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116622. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116623. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116624. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116625. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116626. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116627. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116628. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116629. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116630. 15,
  116631. };
  116632. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116633. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116634. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116635. };
  116636. static long _vq_quantmap__44c4_s_p9_1[] = {
  116637. 13, 11, 9, 7, 5, 3, 1, 0,
  116638. 2, 4, 6, 8, 10, 12, 14,
  116639. };
  116640. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116641. _vq_quantthresh__44c4_s_p9_1,
  116642. _vq_quantmap__44c4_s_p9_1,
  116643. 15,
  116644. 15
  116645. };
  116646. static static_codebook _44c4_s_p9_1 = {
  116647. 2, 225,
  116648. _vq_lengthlist__44c4_s_p9_1,
  116649. 1, -520986624, 1620377600, 4, 0,
  116650. _vq_quantlist__44c4_s_p9_1,
  116651. NULL,
  116652. &_vq_auxt__44c4_s_p9_1,
  116653. NULL,
  116654. 0
  116655. };
  116656. static long _vq_quantlist__44c4_s_p9_2[] = {
  116657. 10,
  116658. 9,
  116659. 11,
  116660. 8,
  116661. 12,
  116662. 7,
  116663. 13,
  116664. 6,
  116665. 14,
  116666. 5,
  116667. 15,
  116668. 4,
  116669. 16,
  116670. 3,
  116671. 17,
  116672. 2,
  116673. 18,
  116674. 1,
  116675. 19,
  116676. 0,
  116677. 20,
  116678. };
  116679. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116680. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116681. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116682. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116683. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116684. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116685. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116686. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116687. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116688. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116689. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116690. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116691. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116692. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116693. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116694. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116695. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116696. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116697. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116698. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116699. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116700. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116701. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116702. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116703. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116704. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116705. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116706. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116707. 10,10,10,10,10,10,10,10,10,
  116708. };
  116709. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116710. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116711. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116712. 6.5, 7.5, 8.5, 9.5,
  116713. };
  116714. static long _vq_quantmap__44c4_s_p9_2[] = {
  116715. 19, 17, 15, 13, 11, 9, 7, 5,
  116716. 3, 1, 0, 2, 4, 6, 8, 10,
  116717. 12, 14, 16, 18, 20,
  116718. };
  116719. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116720. _vq_quantthresh__44c4_s_p9_2,
  116721. _vq_quantmap__44c4_s_p9_2,
  116722. 21,
  116723. 21
  116724. };
  116725. static static_codebook _44c4_s_p9_2 = {
  116726. 2, 441,
  116727. _vq_lengthlist__44c4_s_p9_2,
  116728. 1, -529268736, 1611661312, 5, 0,
  116729. _vq_quantlist__44c4_s_p9_2,
  116730. NULL,
  116731. &_vq_auxt__44c4_s_p9_2,
  116732. NULL,
  116733. 0
  116734. };
  116735. static long _huff_lengthlist__44c4_s_short[] = {
  116736. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116737. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116738. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116739. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116740. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116741. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116742. 7, 9,12,17,
  116743. };
  116744. static static_codebook _huff_book__44c4_s_short = {
  116745. 2, 100,
  116746. _huff_lengthlist__44c4_s_short,
  116747. 0, 0, 0, 0, 0,
  116748. NULL,
  116749. NULL,
  116750. NULL,
  116751. NULL,
  116752. 0
  116753. };
  116754. static long _huff_lengthlist__44c5_s_long[] = {
  116755. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116756. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116757. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116758. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116759. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116760. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116761. 9, 8, 7, 7,
  116762. };
  116763. static static_codebook _huff_book__44c5_s_long = {
  116764. 2, 100,
  116765. _huff_lengthlist__44c5_s_long,
  116766. 0, 0, 0, 0, 0,
  116767. NULL,
  116768. NULL,
  116769. NULL,
  116770. NULL,
  116771. 0
  116772. };
  116773. static long _vq_quantlist__44c5_s_p1_0[] = {
  116774. 1,
  116775. 0,
  116776. 2,
  116777. };
  116778. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116779. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116780. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116784. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116785. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116789. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116790. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116825. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116830. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  116831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116835. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  116836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116852. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116857. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116862. 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116871. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116876. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116881. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0,
  116897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116898. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  116902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  117190. };
  117191. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117192. -0.5, 0.5,
  117193. };
  117194. static long _vq_quantmap__44c5_s_p1_0[] = {
  117195. 1, 0, 2,
  117196. };
  117197. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117198. _vq_quantthresh__44c5_s_p1_0,
  117199. _vq_quantmap__44c5_s_p1_0,
  117200. 3,
  117201. 3
  117202. };
  117203. static static_codebook _44c5_s_p1_0 = {
  117204. 8, 6561,
  117205. _vq_lengthlist__44c5_s_p1_0,
  117206. 1, -535822336, 1611661312, 2, 0,
  117207. _vq_quantlist__44c5_s_p1_0,
  117208. NULL,
  117209. &_vq_auxt__44c5_s_p1_0,
  117210. NULL,
  117211. 0
  117212. };
  117213. static long _vq_quantlist__44c5_s_p2_0[] = {
  117214. 2,
  117215. 1,
  117216. 3,
  117217. 0,
  117218. 4,
  117219. };
  117220. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117221. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117222. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117223. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117224. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117225. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117231. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117232. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117233. 10, 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, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117239. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117240. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 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. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117247. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117248. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 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,
  117261. };
  117262. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117263. -1.5, -0.5, 0.5, 1.5,
  117264. };
  117265. static long _vq_quantmap__44c5_s_p2_0[] = {
  117266. 3, 1, 0, 2, 4,
  117267. };
  117268. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117269. _vq_quantthresh__44c5_s_p2_0,
  117270. _vq_quantmap__44c5_s_p2_0,
  117271. 5,
  117272. 5
  117273. };
  117274. static static_codebook _44c5_s_p2_0 = {
  117275. 4, 625,
  117276. _vq_lengthlist__44c5_s_p2_0,
  117277. 1, -533725184, 1611661312, 3, 0,
  117278. _vq_quantlist__44c5_s_p2_0,
  117279. NULL,
  117280. &_vq_auxt__44c5_s_p2_0,
  117281. NULL,
  117282. 0
  117283. };
  117284. static long _vq_quantlist__44c5_s_p3_0[] = {
  117285. 2,
  117286. 1,
  117287. 3,
  117288. 0,
  117289. 4,
  117290. };
  117291. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117292. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117295. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117298. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117323. 0, 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,
  117332. };
  117333. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117334. -1.5, -0.5, 0.5, 1.5,
  117335. };
  117336. static long _vq_quantmap__44c5_s_p3_0[] = {
  117337. 3, 1, 0, 2, 4,
  117338. };
  117339. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117340. _vq_quantthresh__44c5_s_p3_0,
  117341. _vq_quantmap__44c5_s_p3_0,
  117342. 5,
  117343. 5
  117344. };
  117345. static static_codebook _44c5_s_p3_0 = {
  117346. 4, 625,
  117347. _vq_lengthlist__44c5_s_p3_0,
  117348. 1, -533725184, 1611661312, 3, 0,
  117349. _vq_quantlist__44c5_s_p3_0,
  117350. NULL,
  117351. &_vq_auxt__44c5_s_p3_0,
  117352. NULL,
  117353. 0
  117354. };
  117355. static long _vq_quantlist__44c5_s_p4_0[] = {
  117356. 4,
  117357. 3,
  117358. 5,
  117359. 2,
  117360. 6,
  117361. 1,
  117362. 7,
  117363. 0,
  117364. 8,
  117365. };
  117366. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117367. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117368. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117369. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117370. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117371. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117372. 0,
  117373. };
  117374. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117375. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117376. };
  117377. static long _vq_quantmap__44c5_s_p4_0[] = {
  117378. 7, 5, 3, 1, 0, 2, 4, 6,
  117379. 8,
  117380. };
  117381. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117382. _vq_quantthresh__44c5_s_p4_0,
  117383. _vq_quantmap__44c5_s_p4_0,
  117384. 9,
  117385. 9
  117386. };
  117387. static static_codebook _44c5_s_p4_0 = {
  117388. 2, 81,
  117389. _vq_lengthlist__44c5_s_p4_0,
  117390. 1, -531628032, 1611661312, 4, 0,
  117391. _vq_quantlist__44c5_s_p4_0,
  117392. NULL,
  117393. &_vq_auxt__44c5_s_p4_0,
  117394. NULL,
  117395. 0
  117396. };
  117397. static long _vq_quantlist__44c5_s_p5_0[] = {
  117398. 4,
  117399. 3,
  117400. 5,
  117401. 2,
  117402. 6,
  117403. 1,
  117404. 7,
  117405. 0,
  117406. 8,
  117407. };
  117408. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117409. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117410. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117411. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117412. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117413. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117414. 10,
  117415. };
  117416. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117417. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117418. };
  117419. static long _vq_quantmap__44c5_s_p5_0[] = {
  117420. 7, 5, 3, 1, 0, 2, 4, 6,
  117421. 8,
  117422. };
  117423. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117424. _vq_quantthresh__44c5_s_p5_0,
  117425. _vq_quantmap__44c5_s_p5_0,
  117426. 9,
  117427. 9
  117428. };
  117429. static static_codebook _44c5_s_p5_0 = {
  117430. 2, 81,
  117431. _vq_lengthlist__44c5_s_p5_0,
  117432. 1, -531628032, 1611661312, 4, 0,
  117433. _vq_quantlist__44c5_s_p5_0,
  117434. NULL,
  117435. &_vq_auxt__44c5_s_p5_0,
  117436. NULL,
  117437. 0
  117438. };
  117439. static long _vq_quantlist__44c5_s_p6_0[] = {
  117440. 8,
  117441. 7,
  117442. 9,
  117443. 6,
  117444. 10,
  117445. 5,
  117446. 11,
  117447. 4,
  117448. 12,
  117449. 3,
  117450. 13,
  117451. 2,
  117452. 14,
  117453. 1,
  117454. 15,
  117455. 0,
  117456. 16,
  117457. };
  117458. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117459. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117460. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117461. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117462. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117463. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117464. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117465. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117466. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117467. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117468. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117469. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117470. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117471. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117472. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117473. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117474. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117475. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117476. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117477. 13,
  117478. };
  117479. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117480. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117481. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117482. };
  117483. static long _vq_quantmap__44c5_s_p6_0[] = {
  117484. 15, 13, 11, 9, 7, 5, 3, 1,
  117485. 0, 2, 4, 6, 8, 10, 12, 14,
  117486. 16,
  117487. };
  117488. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117489. _vq_quantthresh__44c5_s_p6_0,
  117490. _vq_quantmap__44c5_s_p6_0,
  117491. 17,
  117492. 17
  117493. };
  117494. static static_codebook _44c5_s_p6_0 = {
  117495. 2, 289,
  117496. _vq_lengthlist__44c5_s_p6_0,
  117497. 1, -529530880, 1611661312, 5, 0,
  117498. _vq_quantlist__44c5_s_p6_0,
  117499. NULL,
  117500. &_vq_auxt__44c5_s_p6_0,
  117501. NULL,
  117502. 0
  117503. };
  117504. static long _vq_quantlist__44c5_s_p7_0[] = {
  117505. 1,
  117506. 0,
  117507. 2,
  117508. };
  117509. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117510. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117511. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117512. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117513. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117514. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117515. 10,
  117516. };
  117517. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117518. -5.5, 5.5,
  117519. };
  117520. static long _vq_quantmap__44c5_s_p7_0[] = {
  117521. 1, 0, 2,
  117522. };
  117523. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117524. _vq_quantthresh__44c5_s_p7_0,
  117525. _vq_quantmap__44c5_s_p7_0,
  117526. 3,
  117527. 3
  117528. };
  117529. static static_codebook _44c5_s_p7_0 = {
  117530. 4, 81,
  117531. _vq_lengthlist__44c5_s_p7_0,
  117532. 1, -529137664, 1618345984, 2, 0,
  117533. _vq_quantlist__44c5_s_p7_0,
  117534. NULL,
  117535. &_vq_auxt__44c5_s_p7_0,
  117536. NULL,
  117537. 0
  117538. };
  117539. static long _vq_quantlist__44c5_s_p7_1[] = {
  117540. 5,
  117541. 4,
  117542. 6,
  117543. 3,
  117544. 7,
  117545. 2,
  117546. 8,
  117547. 1,
  117548. 9,
  117549. 0,
  117550. 10,
  117551. };
  117552. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117553. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117554. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117555. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117556. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117557. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117558. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117559. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117560. 10,10,10, 8, 8, 8, 8, 8, 8,
  117561. };
  117562. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117563. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117564. 3.5, 4.5,
  117565. };
  117566. static long _vq_quantmap__44c5_s_p7_1[] = {
  117567. 9, 7, 5, 3, 1, 0, 2, 4,
  117568. 6, 8, 10,
  117569. };
  117570. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117571. _vq_quantthresh__44c5_s_p7_1,
  117572. _vq_quantmap__44c5_s_p7_1,
  117573. 11,
  117574. 11
  117575. };
  117576. static static_codebook _44c5_s_p7_1 = {
  117577. 2, 121,
  117578. _vq_lengthlist__44c5_s_p7_1,
  117579. 1, -531365888, 1611661312, 4, 0,
  117580. _vq_quantlist__44c5_s_p7_1,
  117581. NULL,
  117582. &_vq_auxt__44c5_s_p7_1,
  117583. NULL,
  117584. 0
  117585. };
  117586. static long _vq_quantlist__44c5_s_p8_0[] = {
  117587. 6,
  117588. 5,
  117589. 7,
  117590. 4,
  117591. 8,
  117592. 3,
  117593. 9,
  117594. 2,
  117595. 10,
  117596. 1,
  117597. 11,
  117598. 0,
  117599. 12,
  117600. };
  117601. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117602. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117603. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117604. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117605. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117606. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117607. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117608. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117609. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117610. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117611. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117612. 0,12,12,12,12,12,12,13,13,
  117613. };
  117614. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117615. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117616. 12.5, 17.5, 22.5, 27.5,
  117617. };
  117618. static long _vq_quantmap__44c5_s_p8_0[] = {
  117619. 11, 9, 7, 5, 3, 1, 0, 2,
  117620. 4, 6, 8, 10, 12,
  117621. };
  117622. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117623. _vq_quantthresh__44c5_s_p8_0,
  117624. _vq_quantmap__44c5_s_p8_0,
  117625. 13,
  117626. 13
  117627. };
  117628. static static_codebook _44c5_s_p8_0 = {
  117629. 2, 169,
  117630. _vq_lengthlist__44c5_s_p8_0,
  117631. 1, -526516224, 1616117760, 4, 0,
  117632. _vq_quantlist__44c5_s_p8_0,
  117633. NULL,
  117634. &_vq_auxt__44c5_s_p8_0,
  117635. NULL,
  117636. 0
  117637. };
  117638. static long _vq_quantlist__44c5_s_p8_1[] = {
  117639. 2,
  117640. 1,
  117641. 3,
  117642. 0,
  117643. 4,
  117644. };
  117645. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117646. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117647. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117648. };
  117649. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117650. -1.5, -0.5, 0.5, 1.5,
  117651. };
  117652. static long _vq_quantmap__44c5_s_p8_1[] = {
  117653. 3, 1, 0, 2, 4,
  117654. };
  117655. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117656. _vq_quantthresh__44c5_s_p8_1,
  117657. _vq_quantmap__44c5_s_p8_1,
  117658. 5,
  117659. 5
  117660. };
  117661. static static_codebook _44c5_s_p8_1 = {
  117662. 2, 25,
  117663. _vq_lengthlist__44c5_s_p8_1,
  117664. 1, -533725184, 1611661312, 3, 0,
  117665. _vq_quantlist__44c5_s_p8_1,
  117666. NULL,
  117667. &_vq_auxt__44c5_s_p8_1,
  117668. NULL,
  117669. 0
  117670. };
  117671. static long _vq_quantlist__44c5_s_p9_0[] = {
  117672. 7,
  117673. 6,
  117674. 8,
  117675. 5,
  117676. 9,
  117677. 4,
  117678. 10,
  117679. 3,
  117680. 11,
  117681. 2,
  117682. 12,
  117683. 1,
  117684. 13,
  117685. 0,
  117686. 14,
  117687. };
  117688. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117689. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117690. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117691. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117692. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117693. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117694. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117695. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117696. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117697. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117698. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117699. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117700. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117701. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117702. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117703. 12,
  117704. };
  117705. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117706. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117707. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117708. };
  117709. static long _vq_quantmap__44c5_s_p9_0[] = {
  117710. 13, 11, 9, 7, 5, 3, 1, 0,
  117711. 2, 4, 6, 8, 10, 12, 14,
  117712. };
  117713. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117714. _vq_quantthresh__44c5_s_p9_0,
  117715. _vq_quantmap__44c5_s_p9_0,
  117716. 15,
  117717. 15
  117718. };
  117719. static static_codebook _44c5_s_p9_0 = {
  117720. 2, 225,
  117721. _vq_lengthlist__44c5_s_p9_0,
  117722. 1, -512522752, 1628852224, 4, 0,
  117723. _vq_quantlist__44c5_s_p9_0,
  117724. NULL,
  117725. &_vq_auxt__44c5_s_p9_0,
  117726. NULL,
  117727. 0
  117728. };
  117729. static long _vq_quantlist__44c5_s_p9_1[] = {
  117730. 8,
  117731. 7,
  117732. 9,
  117733. 6,
  117734. 10,
  117735. 5,
  117736. 11,
  117737. 4,
  117738. 12,
  117739. 3,
  117740. 13,
  117741. 2,
  117742. 14,
  117743. 1,
  117744. 15,
  117745. 0,
  117746. 16,
  117747. };
  117748. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117749. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117750. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117751. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117752. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117753. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117754. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117755. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117756. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117757. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117758. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117759. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117760. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117761. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117762. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117763. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117764. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117765. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117766. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117767. 15,
  117768. };
  117769. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117770. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117771. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117772. };
  117773. static long _vq_quantmap__44c5_s_p9_1[] = {
  117774. 15, 13, 11, 9, 7, 5, 3, 1,
  117775. 0, 2, 4, 6, 8, 10, 12, 14,
  117776. 16,
  117777. };
  117778. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117779. _vq_quantthresh__44c5_s_p9_1,
  117780. _vq_quantmap__44c5_s_p9_1,
  117781. 17,
  117782. 17
  117783. };
  117784. static static_codebook _44c5_s_p9_1 = {
  117785. 2, 289,
  117786. _vq_lengthlist__44c5_s_p9_1,
  117787. 1, -520814592, 1620377600, 5, 0,
  117788. _vq_quantlist__44c5_s_p9_1,
  117789. NULL,
  117790. &_vq_auxt__44c5_s_p9_1,
  117791. NULL,
  117792. 0
  117793. };
  117794. static long _vq_quantlist__44c5_s_p9_2[] = {
  117795. 10,
  117796. 9,
  117797. 11,
  117798. 8,
  117799. 12,
  117800. 7,
  117801. 13,
  117802. 6,
  117803. 14,
  117804. 5,
  117805. 15,
  117806. 4,
  117807. 16,
  117808. 3,
  117809. 17,
  117810. 2,
  117811. 18,
  117812. 1,
  117813. 19,
  117814. 0,
  117815. 20,
  117816. };
  117817. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117818. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117819. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117820. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117821. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117822. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117823. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117824. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117825. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117826. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117827. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117828. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117829. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117830. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117831. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117832. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117833. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117834. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117835. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117836. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117837. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117838. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117839. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117840. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117841. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117842. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117843. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117844. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117845. 10,10,10,10,10,10,10,10,10,
  117846. };
  117847. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117848. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117849. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117850. 6.5, 7.5, 8.5, 9.5,
  117851. };
  117852. static long _vq_quantmap__44c5_s_p9_2[] = {
  117853. 19, 17, 15, 13, 11, 9, 7, 5,
  117854. 3, 1, 0, 2, 4, 6, 8, 10,
  117855. 12, 14, 16, 18, 20,
  117856. };
  117857. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117858. _vq_quantthresh__44c5_s_p9_2,
  117859. _vq_quantmap__44c5_s_p9_2,
  117860. 21,
  117861. 21
  117862. };
  117863. static static_codebook _44c5_s_p9_2 = {
  117864. 2, 441,
  117865. _vq_lengthlist__44c5_s_p9_2,
  117866. 1, -529268736, 1611661312, 5, 0,
  117867. _vq_quantlist__44c5_s_p9_2,
  117868. NULL,
  117869. &_vq_auxt__44c5_s_p9_2,
  117870. NULL,
  117871. 0
  117872. };
  117873. static long _huff_lengthlist__44c5_s_short[] = {
  117874. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117875. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117876. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117877. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117878. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117879. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117880. 6, 8,11,16,
  117881. };
  117882. static static_codebook _huff_book__44c5_s_short = {
  117883. 2, 100,
  117884. _huff_lengthlist__44c5_s_short,
  117885. 0, 0, 0, 0, 0,
  117886. NULL,
  117887. NULL,
  117888. NULL,
  117889. NULL,
  117890. 0
  117891. };
  117892. static long _huff_lengthlist__44c6_s_long[] = {
  117893. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117894. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117895. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117896. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117897. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117898. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117899. 11,10,10,12,
  117900. };
  117901. static static_codebook _huff_book__44c6_s_long = {
  117902. 2, 100,
  117903. _huff_lengthlist__44c6_s_long,
  117904. 0, 0, 0, 0, 0,
  117905. NULL,
  117906. NULL,
  117907. NULL,
  117908. NULL,
  117909. 0
  117910. };
  117911. static long _vq_quantlist__44c6_s_p1_0[] = {
  117912. 1,
  117913. 0,
  117914. 2,
  117915. };
  117916. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117917. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117918. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117919. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117920. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117921. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117922. 8,
  117923. };
  117924. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117925. -0.5, 0.5,
  117926. };
  117927. static long _vq_quantmap__44c6_s_p1_0[] = {
  117928. 1, 0, 2,
  117929. };
  117930. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  117931. _vq_quantthresh__44c6_s_p1_0,
  117932. _vq_quantmap__44c6_s_p1_0,
  117933. 3,
  117934. 3
  117935. };
  117936. static static_codebook _44c6_s_p1_0 = {
  117937. 4, 81,
  117938. _vq_lengthlist__44c6_s_p1_0,
  117939. 1, -535822336, 1611661312, 2, 0,
  117940. _vq_quantlist__44c6_s_p1_0,
  117941. NULL,
  117942. &_vq_auxt__44c6_s_p1_0,
  117943. NULL,
  117944. 0
  117945. };
  117946. static long _vq_quantlist__44c6_s_p2_0[] = {
  117947. 2,
  117948. 1,
  117949. 3,
  117950. 0,
  117951. 4,
  117952. };
  117953. static long _vq_lengthlist__44c6_s_p2_0[] = {
  117954. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  117955. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  117956. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  117957. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  117958. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  117959. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  117960. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  117961. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  117962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117963. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  117964. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  117965. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  117966. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  117967. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  117968. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  117969. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  117970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117971. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  117972. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  117973. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  117974. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  117975. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  117976. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  117977. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117979. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  117980. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  117981. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  117982. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  117983. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  117984. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  117985. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  117990. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  117991. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  117992. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  117993. 13,
  117994. };
  117995. static float _vq_quantthresh__44c6_s_p2_0[] = {
  117996. -1.5, -0.5, 0.5, 1.5,
  117997. };
  117998. static long _vq_quantmap__44c6_s_p2_0[] = {
  117999. 3, 1, 0, 2, 4,
  118000. };
  118001. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118002. _vq_quantthresh__44c6_s_p2_0,
  118003. _vq_quantmap__44c6_s_p2_0,
  118004. 5,
  118005. 5
  118006. };
  118007. static static_codebook _44c6_s_p2_0 = {
  118008. 4, 625,
  118009. _vq_lengthlist__44c6_s_p2_0,
  118010. 1, -533725184, 1611661312, 3, 0,
  118011. _vq_quantlist__44c6_s_p2_0,
  118012. NULL,
  118013. &_vq_auxt__44c6_s_p2_0,
  118014. NULL,
  118015. 0
  118016. };
  118017. static long _vq_quantlist__44c6_s_p3_0[] = {
  118018. 4,
  118019. 3,
  118020. 5,
  118021. 2,
  118022. 6,
  118023. 1,
  118024. 7,
  118025. 0,
  118026. 8,
  118027. };
  118028. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118029. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118030. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118031. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118032. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118034. 0,
  118035. };
  118036. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118037. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118038. };
  118039. static long _vq_quantmap__44c6_s_p3_0[] = {
  118040. 7, 5, 3, 1, 0, 2, 4, 6,
  118041. 8,
  118042. };
  118043. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118044. _vq_quantthresh__44c6_s_p3_0,
  118045. _vq_quantmap__44c6_s_p3_0,
  118046. 9,
  118047. 9
  118048. };
  118049. static static_codebook _44c6_s_p3_0 = {
  118050. 2, 81,
  118051. _vq_lengthlist__44c6_s_p3_0,
  118052. 1, -531628032, 1611661312, 4, 0,
  118053. _vq_quantlist__44c6_s_p3_0,
  118054. NULL,
  118055. &_vq_auxt__44c6_s_p3_0,
  118056. NULL,
  118057. 0
  118058. };
  118059. static long _vq_quantlist__44c6_s_p4_0[] = {
  118060. 8,
  118061. 7,
  118062. 9,
  118063. 6,
  118064. 10,
  118065. 5,
  118066. 11,
  118067. 4,
  118068. 12,
  118069. 3,
  118070. 13,
  118071. 2,
  118072. 14,
  118073. 1,
  118074. 15,
  118075. 0,
  118076. 16,
  118077. };
  118078. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118079. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118080. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118081. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118082. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118083. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118084. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118085. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118086. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118087. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118088. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118097. 0,
  118098. };
  118099. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118100. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118101. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118102. };
  118103. static long _vq_quantmap__44c6_s_p4_0[] = {
  118104. 15, 13, 11, 9, 7, 5, 3, 1,
  118105. 0, 2, 4, 6, 8, 10, 12, 14,
  118106. 16,
  118107. };
  118108. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118109. _vq_quantthresh__44c6_s_p4_0,
  118110. _vq_quantmap__44c6_s_p4_0,
  118111. 17,
  118112. 17
  118113. };
  118114. static static_codebook _44c6_s_p4_0 = {
  118115. 2, 289,
  118116. _vq_lengthlist__44c6_s_p4_0,
  118117. 1, -529530880, 1611661312, 5, 0,
  118118. _vq_quantlist__44c6_s_p4_0,
  118119. NULL,
  118120. &_vq_auxt__44c6_s_p4_0,
  118121. NULL,
  118122. 0
  118123. };
  118124. static long _vq_quantlist__44c6_s_p5_0[] = {
  118125. 1,
  118126. 0,
  118127. 2,
  118128. };
  118129. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118130. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118131. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118132. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118133. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118134. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118135. 12,
  118136. };
  118137. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118138. -5.5, 5.5,
  118139. };
  118140. static long _vq_quantmap__44c6_s_p5_0[] = {
  118141. 1, 0, 2,
  118142. };
  118143. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118144. _vq_quantthresh__44c6_s_p5_0,
  118145. _vq_quantmap__44c6_s_p5_0,
  118146. 3,
  118147. 3
  118148. };
  118149. static static_codebook _44c6_s_p5_0 = {
  118150. 4, 81,
  118151. _vq_lengthlist__44c6_s_p5_0,
  118152. 1, -529137664, 1618345984, 2, 0,
  118153. _vq_quantlist__44c6_s_p5_0,
  118154. NULL,
  118155. &_vq_auxt__44c6_s_p5_0,
  118156. NULL,
  118157. 0
  118158. };
  118159. static long _vq_quantlist__44c6_s_p5_1[] = {
  118160. 5,
  118161. 4,
  118162. 6,
  118163. 3,
  118164. 7,
  118165. 2,
  118166. 8,
  118167. 1,
  118168. 9,
  118169. 0,
  118170. 10,
  118171. };
  118172. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118173. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118174. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118175. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118176. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118177. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118178. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118179. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118180. 11,10,10, 7, 7, 8, 8, 8, 8,
  118181. };
  118182. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118183. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118184. 3.5, 4.5,
  118185. };
  118186. static long _vq_quantmap__44c6_s_p5_1[] = {
  118187. 9, 7, 5, 3, 1, 0, 2, 4,
  118188. 6, 8, 10,
  118189. };
  118190. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118191. _vq_quantthresh__44c6_s_p5_1,
  118192. _vq_quantmap__44c6_s_p5_1,
  118193. 11,
  118194. 11
  118195. };
  118196. static static_codebook _44c6_s_p5_1 = {
  118197. 2, 121,
  118198. _vq_lengthlist__44c6_s_p5_1,
  118199. 1, -531365888, 1611661312, 4, 0,
  118200. _vq_quantlist__44c6_s_p5_1,
  118201. NULL,
  118202. &_vq_auxt__44c6_s_p5_1,
  118203. NULL,
  118204. 0
  118205. };
  118206. static long _vq_quantlist__44c6_s_p6_0[] = {
  118207. 6,
  118208. 5,
  118209. 7,
  118210. 4,
  118211. 8,
  118212. 3,
  118213. 9,
  118214. 2,
  118215. 10,
  118216. 1,
  118217. 11,
  118218. 0,
  118219. 12,
  118220. };
  118221. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118222. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118223. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118224. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118225. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118226. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118227. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118232. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118233. };
  118234. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118235. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118236. 12.5, 17.5, 22.5, 27.5,
  118237. };
  118238. static long _vq_quantmap__44c6_s_p6_0[] = {
  118239. 11, 9, 7, 5, 3, 1, 0, 2,
  118240. 4, 6, 8, 10, 12,
  118241. };
  118242. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118243. _vq_quantthresh__44c6_s_p6_0,
  118244. _vq_quantmap__44c6_s_p6_0,
  118245. 13,
  118246. 13
  118247. };
  118248. static static_codebook _44c6_s_p6_0 = {
  118249. 2, 169,
  118250. _vq_lengthlist__44c6_s_p6_0,
  118251. 1, -526516224, 1616117760, 4, 0,
  118252. _vq_quantlist__44c6_s_p6_0,
  118253. NULL,
  118254. &_vq_auxt__44c6_s_p6_0,
  118255. NULL,
  118256. 0
  118257. };
  118258. static long _vq_quantlist__44c6_s_p6_1[] = {
  118259. 2,
  118260. 1,
  118261. 3,
  118262. 0,
  118263. 4,
  118264. };
  118265. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118266. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118267. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118268. };
  118269. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118270. -1.5, -0.5, 0.5, 1.5,
  118271. };
  118272. static long _vq_quantmap__44c6_s_p6_1[] = {
  118273. 3, 1, 0, 2, 4,
  118274. };
  118275. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118276. _vq_quantthresh__44c6_s_p6_1,
  118277. _vq_quantmap__44c6_s_p6_1,
  118278. 5,
  118279. 5
  118280. };
  118281. static static_codebook _44c6_s_p6_1 = {
  118282. 2, 25,
  118283. _vq_lengthlist__44c6_s_p6_1,
  118284. 1, -533725184, 1611661312, 3, 0,
  118285. _vq_quantlist__44c6_s_p6_1,
  118286. NULL,
  118287. &_vq_auxt__44c6_s_p6_1,
  118288. NULL,
  118289. 0
  118290. };
  118291. static long _vq_quantlist__44c6_s_p7_0[] = {
  118292. 6,
  118293. 5,
  118294. 7,
  118295. 4,
  118296. 8,
  118297. 3,
  118298. 9,
  118299. 2,
  118300. 10,
  118301. 1,
  118302. 11,
  118303. 0,
  118304. 12,
  118305. };
  118306. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118307. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118308. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118309. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118310. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118311. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118312. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118313. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118314. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118315. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118316. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118317. 20,13,13,13,13,13,13,14,14,
  118318. };
  118319. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118320. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118321. 27.5, 38.5, 49.5, 60.5,
  118322. };
  118323. static long _vq_quantmap__44c6_s_p7_0[] = {
  118324. 11, 9, 7, 5, 3, 1, 0, 2,
  118325. 4, 6, 8, 10, 12,
  118326. };
  118327. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118328. _vq_quantthresh__44c6_s_p7_0,
  118329. _vq_quantmap__44c6_s_p7_0,
  118330. 13,
  118331. 13
  118332. };
  118333. static static_codebook _44c6_s_p7_0 = {
  118334. 2, 169,
  118335. _vq_lengthlist__44c6_s_p7_0,
  118336. 1, -523206656, 1618345984, 4, 0,
  118337. _vq_quantlist__44c6_s_p7_0,
  118338. NULL,
  118339. &_vq_auxt__44c6_s_p7_0,
  118340. NULL,
  118341. 0
  118342. };
  118343. static long _vq_quantlist__44c6_s_p7_1[] = {
  118344. 5,
  118345. 4,
  118346. 6,
  118347. 3,
  118348. 7,
  118349. 2,
  118350. 8,
  118351. 1,
  118352. 9,
  118353. 0,
  118354. 10,
  118355. };
  118356. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118357. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118358. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118359. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118360. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118361. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118362. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118363. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118364. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118365. };
  118366. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118367. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118368. 3.5, 4.5,
  118369. };
  118370. static long _vq_quantmap__44c6_s_p7_1[] = {
  118371. 9, 7, 5, 3, 1, 0, 2, 4,
  118372. 6, 8, 10,
  118373. };
  118374. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118375. _vq_quantthresh__44c6_s_p7_1,
  118376. _vq_quantmap__44c6_s_p7_1,
  118377. 11,
  118378. 11
  118379. };
  118380. static static_codebook _44c6_s_p7_1 = {
  118381. 2, 121,
  118382. _vq_lengthlist__44c6_s_p7_1,
  118383. 1, -531365888, 1611661312, 4, 0,
  118384. _vq_quantlist__44c6_s_p7_1,
  118385. NULL,
  118386. &_vq_auxt__44c6_s_p7_1,
  118387. NULL,
  118388. 0
  118389. };
  118390. static long _vq_quantlist__44c6_s_p8_0[] = {
  118391. 7,
  118392. 6,
  118393. 8,
  118394. 5,
  118395. 9,
  118396. 4,
  118397. 10,
  118398. 3,
  118399. 11,
  118400. 2,
  118401. 12,
  118402. 1,
  118403. 13,
  118404. 0,
  118405. 14,
  118406. };
  118407. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118408. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118409. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118410. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118411. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118412. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118413. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118414. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118415. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118416. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118417. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118418. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118419. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118420. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118421. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118422. 14,
  118423. };
  118424. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118425. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118426. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118427. };
  118428. static long _vq_quantmap__44c6_s_p8_0[] = {
  118429. 13, 11, 9, 7, 5, 3, 1, 0,
  118430. 2, 4, 6, 8, 10, 12, 14,
  118431. };
  118432. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118433. _vq_quantthresh__44c6_s_p8_0,
  118434. _vq_quantmap__44c6_s_p8_0,
  118435. 15,
  118436. 15
  118437. };
  118438. static static_codebook _44c6_s_p8_0 = {
  118439. 2, 225,
  118440. _vq_lengthlist__44c6_s_p8_0,
  118441. 1, -520986624, 1620377600, 4, 0,
  118442. _vq_quantlist__44c6_s_p8_0,
  118443. NULL,
  118444. &_vq_auxt__44c6_s_p8_0,
  118445. NULL,
  118446. 0
  118447. };
  118448. static long _vq_quantlist__44c6_s_p8_1[] = {
  118449. 10,
  118450. 9,
  118451. 11,
  118452. 8,
  118453. 12,
  118454. 7,
  118455. 13,
  118456. 6,
  118457. 14,
  118458. 5,
  118459. 15,
  118460. 4,
  118461. 16,
  118462. 3,
  118463. 17,
  118464. 2,
  118465. 18,
  118466. 1,
  118467. 19,
  118468. 0,
  118469. 20,
  118470. };
  118471. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118472. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118473. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118474. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118475. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118476. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118477. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118478. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118479. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118480. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118481. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118482. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118483. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118484. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118485. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118486. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118487. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118488. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118489. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118490. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118491. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118492. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118493. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118494. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118495. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118496. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118497. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118498. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118499. 10,10,10,10,10,10,10,10,10,
  118500. };
  118501. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118502. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118503. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118504. 6.5, 7.5, 8.5, 9.5,
  118505. };
  118506. static long _vq_quantmap__44c6_s_p8_1[] = {
  118507. 19, 17, 15, 13, 11, 9, 7, 5,
  118508. 3, 1, 0, 2, 4, 6, 8, 10,
  118509. 12, 14, 16, 18, 20,
  118510. };
  118511. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118512. _vq_quantthresh__44c6_s_p8_1,
  118513. _vq_quantmap__44c6_s_p8_1,
  118514. 21,
  118515. 21
  118516. };
  118517. static static_codebook _44c6_s_p8_1 = {
  118518. 2, 441,
  118519. _vq_lengthlist__44c6_s_p8_1,
  118520. 1, -529268736, 1611661312, 5, 0,
  118521. _vq_quantlist__44c6_s_p8_1,
  118522. NULL,
  118523. &_vq_auxt__44c6_s_p8_1,
  118524. NULL,
  118525. 0
  118526. };
  118527. static long _vq_quantlist__44c6_s_p9_0[] = {
  118528. 6,
  118529. 5,
  118530. 7,
  118531. 4,
  118532. 8,
  118533. 3,
  118534. 9,
  118535. 2,
  118536. 10,
  118537. 1,
  118538. 11,
  118539. 0,
  118540. 12,
  118541. };
  118542. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118543. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118544. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118545. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118546. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118547. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118548. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118549. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118550. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118551. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118552. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118553. 10,10,10,10,10,10,10,10,10,
  118554. };
  118555. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118556. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118557. 1592.5, 2229.5, 2866.5, 3503.5,
  118558. };
  118559. static long _vq_quantmap__44c6_s_p9_0[] = {
  118560. 11, 9, 7, 5, 3, 1, 0, 2,
  118561. 4, 6, 8, 10, 12,
  118562. };
  118563. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118564. _vq_quantthresh__44c6_s_p9_0,
  118565. _vq_quantmap__44c6_s_p9_0,
  118566. 13,
  118567. 13
  118568. };
  118569. static static_codebook _44c6_s_p9_0 = {
  118570. 2, 169,
  118571. _vq_lengthlist__44c6_s_p9_0,
  118572. 1, -511845376, 1630791680, 4, 0,
  118573. _vq_quantlist__44c6_s_p9_0,
  118574. NULL,
  118575. &_vq_auxt__44c6_s_p9_0,
  118576. NULL,
  118577. 0
  118578. };
  118579. static long _vq_quantlist__44c6_s_p9_1[] = {
  118580. 6,
  118581. 5,
  118582. 7,
  118583. 4,
  118584. 8,
  118585. 3,
  118586. 9,
  118587. 2,
  118588. 10,
  118589. 1,
  118590. 11,
  118591. 0,
  118592. 12,
  118593. };
  118594. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118595. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118596. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118597. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118598. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118599. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118600. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118601. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118602. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118603. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118604. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118605. 15,12,10,11,11,13,11,12,13,
  118606. };
  118607. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118608. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118609. 122.5, 171.5, 220.5, 269.5,
  118610. };
  118611. static long _vq_quantmap__44c6_s_p9_1[] = {
  118612. 11, 9, 7, 5, 3, 1, 0, 2,
  118613. 4, 6, 8, 10, 12,
  118614. };
  118615. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118616. _vq_quantthresh__44c6_s_p9_1,
  118617. _vq_quantmap__44c6_s_p9_1,
  118618. 13,
  118619. 13
  118620. };
  118621. static static_codebook _44c6_s_p9_1 = {
  118622. 2, 169,
  118623. _vq_lengthlist__44c6_s_p9_1,
  118624. 1, -518889472, 1622704128, 4, 0,
  118625. _vq_quantlist__44c6_s_p9_1,
  118626. NULL,
  118627. &_vq_auxt__44c6_s_p9_1,
  118628. NULL,
  118629. 0
  118630. };
  118631. static long _vq_quantlist__44c6_s_p9_2[] = {
  118632. 24,
  118633. 23,
  118634. 25,
  118635. 22,
  118636. 26,
  118637. 21,
  118638. 27,
  118639. 20,
  118640. 28,
  118641. 19,
  118642. 29,
  118643. 18,
  118644. 30,
  118645. 17,
  118646. 31,
  118647. 16,
  118648. 32,
  118649. 15,
  118650. 33,
  118651. 14,
  118652. 34,
  118653. 13,
  118654. 35,
  118655. 12,
  118656. 36,
  118657. 11,
  118658. 37,
  118659. 10,
  118660. 38,
  118661. 9,
  118662. 39,
  118663. 8,
  118664. 40,
  118665. 7,
  118666. 41,
  118667. 6,
  118668. 42,
  118669. 5,
  118670. 43,
  118671. 4,
  118672. 44,
  118673. 3,
  118674. 45,
  118675. 2,
  118676. 46,
  118677. 1,
  118678. 47,
  118679. 0,
  118680. 48,
  118681. };
  118682. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118683. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118684. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118685. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118686. 7,
  118687. };
  118688. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118689. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118690. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118691. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118692. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118693. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118694. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118695. };
  118696. static long _vq_quantmap__44c6_s_p9_2[] = {
  118697. 47, 45, 43, 41, 39, 37, 35, 33,
  118698. 31, 29, 27, 25, 23, 21, 19, 17,
  118699. 15, 13, 11, 9, 7, 5, 3, 1,
  118700. 0, 2, 4, 6, 8, 10, 12, 14,
  118701. 16, 18, 20, 22, 24, 26, 28, 30,
  118702. 32, 34, 36, 38, 40, 42, 44, 46,
  118703. 48,
  118704. };
  118705. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118706. _vq_quantthresh__44c6_s_p9_2,
  118707. _vq_quantmap__44c6_s_p9_2,
  118708. 49,
  118709. 49
  118710. };
  118711. static static_codebook _44c6_s_p9_2 = {
  118712. 1, 49,
  118713. _vq_lengthlist__44c6_s_p9_2,
  118714. 1, -526909440, 1611661312, 6, 0,
  118715. _vq_quantlist__44c6_s_p9_2,
  118716. NULL,
  118717. &_vq_auxt__44c6_s_p9_2,
  118718. NULL,
  118719. 0
  118720. };
  118721. static long _huff_lengthlist__44c6_s_short[] = {
  118722. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118723. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118724. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118725. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118726. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118727. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118728. 9,10,17,18,
  118729. };
  118730. static static_codebook _huff_book__44c6_s_short = {
  118731. 2, 100,
  118732. _huff_lengthlist__44c6_s_short,
  118733. 0, 0, 0, 0, 0,
  118734. NULL,
  118735. NULL,
  118736. NULL,
  118737. NULL,
  118738. 0
  118739. };
  118740. static long _huff_lengthlist__44c7_s_long[] = {
  118741. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118742. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118743. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118744. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118745. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118746. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118747. 11,10,10,12,
  118748. };
  118749. static static_codebook _huff_book__44c7_s_long = {
  118750. 2, 100,
  118751. _huff_lengthlist__44c7_s_long,
  118752. 0, 0, 0, 0, 0,
  118753. NULL,
  118754. NULL,
  118755. NULL,
  118756. NULL,
  118757. 0
  118758. };
  118759. static long _vq_quantlist__44c7_s_p1_0[] = {
  118760. 1,
  118761. 0,
  118762. 2,
  118763. };
  118764. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118765. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118766. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118767. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118768. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118769. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118770. 8,
  118771. };
  118772. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118773. -0.5, 0.5,
  118774. };
  118775. static long _vq_quantmap__44c7_s_p1_0[] = {
  118776. 1, 0, 2,
  118777. };
  118778. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118779. _vq_quantthresh__44c7_s_p1_0,
  118780. _vq_quantmap__44c7_s_p1_0,
  118781. 3,
  118782. 3
  118783. };
  118784. static static_codebook _44c7_s_p1_0 = {
  118785. 4, 81,
  118786. _vq_lengthlist__44c7_s_p1_0,
  118787. 1, -535822336, 1611661312, 2, 0,
  118788. _vq_quantlist__44c7_s_p1_0,
  118789. NULL,
  118790. &_vq_auxt__44c7_s_p1_0,
  118791. NULL,
  118792. 0
  118793. };
  118794. static long _vq_quantlist__44c7_s_p2_0[] = {
  118795. 2,
  118796. 1,
  118797. 3,
  118798. 0,
  118799. 4,
  118800. };
  118801. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118802. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118803. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118804. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118805. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118806. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118807. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118808. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118809. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118811. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118812. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118813. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118814. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118815. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118816. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118817. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118819. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118820. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118821. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118822. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118823. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118824. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118825. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118827. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118828. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118829. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118830. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118831. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118832. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118833. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118838. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118839. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118840. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118841. 13,
  118842. };
  118843. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118844. -1.5, -0.5, 0.5, 1.5,
  118845. };
  118846. static long _vq_quantmap__44c7_s_p2_0[] = {
  118847. 3, 1, 0, 2, 4,
  118848. };
  118849. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118850. _vq_quantthresh__44c7_s_p2_0,
  118851. _vq_quantmap__44c7_s_p2_0,
  118852. 5,
  118853. 5
  118854. };
  118855. static static_codebook _44c7_s_p2_0 = {
  118856. 4, 625,
  118857. _vq_lengthlist__44c7_s_p2_0,
  118858. 1, -533725184, 1611661312, 3, 0,
  118859. _vq_quantlist__44c7_s_p2_0,
  118860. NULL,
  118861. &_vq_auxt__44c7_s_p2_0,
  118862. NULL,
  118863. 0
  118864. };
  118865. static long _vq_quantlist__44c7_s_p3_0[] = {
  118866. 4,
  118867. 3,
  118868. 5,
  118869. 2,
  118870. 6,
  118871. 1,
  118872. 7,
  118873. 0,
  118874. 8,
  118875. };
  118876. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118877. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118878. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118879. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118880. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118882. 0,
  118883. };
  118884. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118885. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118886. };
  118887. static long _vq_quantmap__44c7_s_p3_0[] = {
  118888. 7, 5, 3, 1, 0, 2, 4, 6,
  118889. 8,
  118890. };
  118891. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118892. _vq_quantthresh__44c7_s_p3_0,
  118893. _vq_quantmap__44c7_s_p3_0,
  118894. 9,
  118895. 9
  118896. };
  118897. static static_codebook _44c7_s_p3_0 = {
  118898. 2, 81,
  118899. _vq_lengthlist__44c7_s_p3_0,
  118900. 1, -531628032, 1611661312, 4, 0,
  118901. _vq_quantlist__44c7_s_p3_0,
  118902. NULL,
  118903. &_vq_auxt__44c7_s_p3_0,
  118904. NULL,
  118905. 0
  118906. };
  118907. static long _vq_quantlist__44c7_s_p4_0[] = {
  118908. 8,
  118909. 7,
  118910. 9,
  118911. 6,
  118912. 10,
  118913. 5,
  118914. 11,
  118915. 4,
  118916. 12,
  118917. 3,
  118918. 13,
  118919. 2,
  118920. 14,
  118921. 1,
  118922. 15,
  118923. 0,
  118924. 16,
  118925. };
  118926. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118927. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  118928. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  118929. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  118930. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  118931. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  118932. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  118933. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  118934. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118935. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  118936. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  118937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118945. 0,
  118946. };
  118947. static float _vq_quantthresh__44c7_s_p4_0[] = {
  118948. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118949. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118950. };
  118951. static long _vq_quantmap__44c7_s_p4_0[] = {
  118952. 15, 13, 11, 9, 7, 5, 3, 1,
  118953. 0, 2, 4, 6, 8, 10, 12, 14,
  118954. 16,
  118955. };
  118956. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  118957. _vq_quantthresh__44c7_s_p4_0,
  118958. _vq_quantmap__44c7_s_p4_0,
  118959. 17,
  118960. 17
  118961. };
  118962. static static_codebook _44c7_s_p4_0 = {
  118963. 2, 289,
  118964. _vq_lengthlist__44c7_s_p4_0,
  118965. 1, -529530880, 1611661312, 5, 0,
  118966. _vq_quantlist__44c7_s_p4_0,
  118967. NULL,
  118968. &_vq_auxt__44c7_s_p4_0,
  118969. NULL,
  118970. 0
  118971. };
  118972. static long _vq_quantlist__44c7_s_p5_0[] = {
  118973. 1,
  118974. 0,
  118975. 2,
  118976. };
  118977. static long _vq_lengthlist__44c7_s_p5_0[] = {
  118978. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  118979. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  118980. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  118981. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118982. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  118983. 12,
  118984. };
  118985. static float _vq_quantthresh__44c7_s_p5_0[] = {
  118986. -5.5, 5.5,
  118987. };
  118988. static long _vq_quantmap__44c7_s_p5_0[] = {
  118989. 1, 0, 2,
  118990. };
  118991. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  118992. _vq_quantthresh__44c7_s_p5_0,
  118993. _vq_quantmap__44c7_s_p5_0,
  118994. 3,
  118995. 3
  118996. };
  118997. static static_codebook _44c7_s_p5_0 = {
  118998. 4, 81,
  118999. _vq_lengthlist__44c7_s_p5_0,
  119000. 1, -529137664, 1618345984, 2, 0,
  119001. _vq_quantlist__44c7_s_p5_0,
  119002. NULL,
  119003. &_vq_auxt__44c7_s_p5_0,
  119004. NULL,
  119005. 0
  119006. };
  119007. static long _vq_quantlist__44c7_s_p5_1[] = {
  119008. 5,
  119009. 4,
  119010. 6,
  119011. 3,
  119012. 7,
  119013. 2,
  119014. 8,
  119015. 1,
  119016. 9,
  119017. 0,
  119018. 10,
  119019. };
  119020. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119021. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119022. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119023. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119024. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119025. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119026. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119027. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119028. 11,11,11, 7, 7, 8, 8, 8, 8,
  119029. };
  119030. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119031. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119032. 3.5, 4.5,
  119033. };
  119034. static long _vq_quantmap__44c7_s_p5_1[] = {
  119035. 9, 7, 5, 3, 1, 0, 2, 4,
  119036. 6, 8, 10,
  119037. };
  119038. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119039. _vq_quantthresh__44c7_s_p5_1,
  119040. _vq_quantmap__44c7_s_p5_1,
  119041. 11,
  119042. 11
  119043. };
  119044. static static_codebook _44c7_s_p5_1 = {
  119045. 2, 121,
  119046. _vq_lengthlist__44c7_s_p5_1,
  119047. 1, -531365888, 1611661312, 4, 0,
  119048. _vq_quantlist__44c7_s_p5_1,
  119049. NULL,
  119050. &_vq_auxt__44c7_s_p5_1,
  119051. NULL,
  119052. 0
  119053. };
  119054. static long _vq_quantlist__44c7_s_p6_0[] = {
  119055. 6,
  119056. 5,
  119057. 7,
  119058. 4,
  119059. 8,
  119060. 3,
  119061. 9,
  119062. 2,
  119063. 10,
  119064. 1,
  119065. 11,
  119066. 0,
  119067. 12,
  119068. };
  119069. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119070. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119071. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119072. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119073. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119074. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119075. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119080. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119081. };
  119082. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119083. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119084. 12.5, 17.5, 22.5, 27.5,
  119085. };
  119086. static long _vq_quantmap__44c7_s_p6_0[] = {
  119087. 11, 9, 7, 5, 3, 1, 0, 2,
  119088. 4, 6, 8, 10, 12,
  119089. };
  119090. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119091. _vq_quantthresh__44c7_s_p6_0,
  119092. _vq_quantmap__44c7_s_p6_0,
  119093. 13,
  119094. 13
  119095. };
  119096. static static_codebook _44c7_s_p6_0 = {
  119097. 2, 169,
  119098. _vq_lengthlist__44c7_s_p6_0,
  119099. 1, -526516224, 1616117760, 4, 0,
  119100. _vq_quantlist__44c7_s_p6_0,
  119101. NULL,
  119102. &_vq_auxt__44c7_s_p6_0,
  119103. NULL,
  119104. 0
  119105. };
  119106. static long _vq_quantlist__44c7_s_p6_1[] = {
  119107. 2,
  119108. 1,
  119109. 3,
  119110. 0,
  119111. 4,
  119112. };
  119113. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119114. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119115. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119116. };
  119117. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119118. -1.5, -0.5, 0.5, 1.5,
  119119. };
  119120. static long _vq_quantmap__44c7_s_p6_1[] = {
  119121. 3, 1, 0, 2, 4,
  119122. };
  119123. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119124. _vq_quantthresh__44c7_s_p6_1,
  119125. _vq_quantmap__44c7_s_p6_1,
  119126. 5,
  119127. 5
  119128. };
  119129. static static_codebook _44c7_s_p6_1 = {
  119130. 2, 25,
  119131. _vq_lengthlist__44c7_s_p6_1,
  119132. 1, -533725184, 1611661312, 3, 0,
  119133. _vq_quantlist__44c7_s_p6_1,
  119134. NULL,
  119135. &_vq_auxt__44c7_s_p6_1,
  119136. NULL,
  119137. 0
  119138. };
  119139. static long _vq_quantlist__44c7_s_p7_0[] = {
  119140. 6,
  119141. 5,
  119142. 7,
  119143. 4,
  119144. 8,
  119145. 3,
  119146. 9,
  119147. 2,
  119148. 10,
  119149. 1,
  119150. 11,
  119151. 0,
  119152. 12,
  119153. };
  119154. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119155. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119156. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119157. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119158. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119159. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119160. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119161. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119162. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119163. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119164. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119165. 19,13,13,13,13,14,14,15,15,
  119166. };
  119167. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119168. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119169. 27.5, 38.5, 49.5, 60.5,
  119170. };
  119171. static long _vq_quantmap__44c7_s_p7_0[] = {
  119172. 11, 9, 7, 5, 3, 1, 0, 2,
  119173. 4, 6, 8, 10, 12,
  119174. };
  119175. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119176. _vq_quantthresh__44c7_s_p7_0,
  119177. _vq_quantmap__44c7_s_p7_0,
  119178. 13,
  119179. 13
  119180. };
  119181. static static_codebook _44c7_s_p7_0 = {
  119182. 2, 169,
  119183. _vq_lengthlist__44c7_s_p7_0,
  119184. 1, -523206656, 1618345984, 4, 0,
  119185. _vq_quantlist__44c7_s_p7_0,
  119186. NULL,
  119187. &_vq_auxt__44c7_s_p7_0,
  119188. NULL,
  119189. 0
  119190. };
  119191. static long _vq_quantlist__44c7_s_p7_1[] = {
  119192. 5,
  119193. 4,
  119194. 6,
  119195. 3,
  119196. 7,
  119197. 2,
  119198. 8,
  119199. 1,
  119200. 9,
  119201. 0,
  119202. 10,
  119203. };
  119204. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119205. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119206. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119207. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119208. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119209. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119210. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119211. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119212. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119213. };
  119214. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119215. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119216. 3.5, 4.5,
  119217. };
  119218. static long _vq_quantmap__44c7_s_p7_1[] = {
  119219. 9, 7, 5, 3, 1, 0, 2, 4,
  119220. 6, 8, 10,
  119221. };
  119222. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119223. _vq_quantthresh__44c7_s_p7_1,
  119224. _vq_quantmap__44c7_s_p7_1,
  119225. 11,
  119226. 11
  119227. };
  119228. static static_codebook _44c7_s_p7_1 = {
  119229. 2, 121,
  119230. _vq_lengthlist__44c7_s_p7_1,
  119231. 1, -531365888, 1611661312, 4, 0,
  119232. _vq_quantlist__44c7_s_p7_1,
  119233. NULL,
  119234. &_vq_auxt__44c7_s_p7_1,
  119235. NULL,
  119236. 0
  119237. };
  119238. static long _vq_quantlist__44c7_s_p8_0[] = {
  119239. 7,
  119240. 6,
  119241. 8,
  119242. 5,
  119243. 9,
  119244. 4,
  119245. 10,
  119246. 3,
  119247. 11,
  119248. 2,
  119249. 12,
  119250. 1,
  119251. 13,
  119252. 0,
  119253. 14,
  119254. };
  119255. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119256. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119257. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119258. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119259. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119260. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119261. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119262. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119263. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119264. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119265. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119266. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119267. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119268. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119269. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119270. 14,
  119271. };
  119272. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119273. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119274. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119275. };
  119276. static long _vq_quantmap__44c7_s_p8_0[] = {
  119277. 13, 11, 9, 7, 5, 3, 1, 0,
  119278. 2, 4, 6, 8, 10, 12, 14,
  119279. };
  119280. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119281. _vq_quantthresh__44c7_s_p8_0,
  119282. _vq_quantmap__44c7_s_p8_0,
  119283. 15,
  119284. 15
  119285. };
  119286. static static_codebook _44c7_s_p8_0 = {
  119287. 2, 225,
  119288. _vq_lengthlist__44c7_s_p8_0,
  119289. 1, -520986624, 1620377600, 4, 0,
  119290. _vq_quantlist__44c7_s_p8_0,
  119291. NULL,
  119292. &_vq_auxt__44c7_s_p8_0,
  119293. NULL,
  119294. 0
  119295. };
  119296. static long _vq_quantlist__44c7_s_p8_1[] = {
  119297. 10,
  119298. 9,
  119299. 11,
  119300. 8,
  119301. 12,
  119302. 7,
  119303. 13,
  119304. 6,
  119305. 14,
  119306. 5,
  119307. 15,
  119308. 4,
  119309. 16,
  119310. 3,
  119311. 17,
  119312. 2,
  119313. 18,
  119314. 1,
  119315. 19,
  119316. 0,
  119317. 20,
  119318. };
  119319. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119320. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119321. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119322. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119323. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119324. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119325. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119326. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119327. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119328. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119329. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119330. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119331. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119332. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119333. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119334. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119335. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119336. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119337. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119338. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119339. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119340. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119341. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119342. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119343. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119344. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119345. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119346. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119347. 10,10,10,10,10,10,10,10,10,
  119348. };
  119349. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119350. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119351. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119352. 6.5, 7.5, 8.5, 9.5,
  119353. };
  119354. static long _vq_quantmap__44c7_s_p8_1[] = {
  119355. 19, 17, 15, 13, 11, 9, 7, 5,
  119356. 3, 1, 0, 2, 4, 6, 8, 10,
  119357. 12, 14, 16, 18, 20,
  119358. };
  119359. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119360. _vq_quantthresh__44c7_s_p8_1,
  119361. _vq_quantmap__44c7_s_p8_1,
  119362. 21,
  119363. 21
  119364. };
  119365. static static_codebook _44c7_s_p8_1 = {
  119366. 2, 441,
  119367. _vq_lengthlist__44c7_s_p8_1,
  119368. 1, -529268736, 1611661312, 5, 0,
  119369. _vq_quantlist__44c7_s_p8_1,
  119370. NULL,
  119371. &_vq_auxt__44c7_s_p8_1,
  119372. NULL,
  119373. 0
  119374. };
  119375. static long _vq_quantlist__44c7_s_p9_0[] = {
  119376. 6,
  119377. 5,
  119378. 7,
  119379. 4,
  119380. 8,
  119381. 3,
  119382. 9,
  119383. 2,
  119384. 10,
  119385. 1,
  119386. 11,
  119387. 0,
  119388. 12,
  119389. };
  119390. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119391. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119392. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119393. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119394. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119395. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119396. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119397. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119398. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119399. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119400. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119401. 11,11,11,11,11,11,11,11,11,
  119402. };
  119403. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119404. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119405. 1592.5, 2229.5, 2866.5, 3503.5,
  119406. };
  119407. static long _vq_quantmap__44c7_s_p9_0[] = {
  119408. 11, 9, 7, 5, 3, 1, 0, 2,
  119409. 4, 6, 8, 10, 12,
  119410. };
  119411. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119412. _vq_quantthresh__44c7_s_p9_0,
  119413. _vq_quantmap__44c7_s_p9_0,
  119414. 13,
  119415. 13
  119416. };
  119417. static static_codebook _44c7_s_p9_0 = {
  119418. 2, 169,
  119419. _vq_lengthlist__44c7_s_p9_0,
  119420. 1, -511845376, 1630791680, 4, 0,
  119421. _vq_quantlist__44c7_s_p9_0,
  119422. NULL,
  119423. &_vq_auxt__44c7_s_p9_0,
  119424. NULL,
  119425. 0
  119426. };
  119427. static long _vq_quantlist__44c7_s_p9_1[] = {
  119428. 6,
  119429. 5,
  119430. 7,
  119431. 4,
  119432. 8,
  119433. 3,
  119434. 9,
  119435. 2,
  119436. 10,
  119437. 1,
  119438. 11,
  119439. 0,
  119440. 12,
  119441. };
  119442. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119443. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119444. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119445. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119446. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119447. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119448. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119449. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119450. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119451. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119452. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119453. 15,11,11,10,10,12,12,12,12,
  119454. };
  119455. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119456. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119457. 122.5, 171.5, 220.5, 269.5,
  119458. };
  119459. static long _vq_quantmap__44c7_s_p9_1[] = {
  119460. 11, 9, 7, 5, 3, 1, 0, 2,
  119461. 4, 6, 8, 10, 12,
  119462. };
  119463. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119464. _vq_quantthresh__44c7_s_p9_1,
  119465. _vq_quantmap__44c7_s_p9_1,
  119466. 13,
  119467. 13
  119468. };
  119469. static static_codebook _44c7_s_p9_1 = {
  119470. 2, 169,
  119471. _vq_lengthlist__44c7_s_p9_1,
  119472. 1, -518889472, 1622704128, 4, 0,
  119473. _vq_quantlist__44c7_s_p9_1,
  119474. NULL,
  119475. &_vq_auxt__44c7_s_p9_1,
  119476. NULL,
  119477. 0
  119478. };
  119479. static long _vq_quantlist__44c7_s_p9_2[] = {
  119480. 24,
  119481. 23,
  119482. 25,
  119483. 22,
  119484. 26,
  119485. 21,
  119486. 27,
  119487. 20,
  119488. 28,
  119489. 19,
  119490. 29,
  119491. 18,
  119492. 30,
  119493. 17,
  119494. 31,
  119495. 16,
  119496. 32,
  119497. 15,
  119498. 33,
  119499. 14,
  119500. 34,
  119501. 13,
  119502. 35,
  119503. 12,
  119504. 36,
  119505. 11,
  119506. 37,
  119507. 10,
  119508. 38,
  119509. 9,
  119510. 39,
  119511. 8,
  119512. 40,
  119513. 7,
  119514. 41,
  119515. 6,
  119516. 42,
  119517. 5,
  119518. 43,
  119519. 4,
  119520. 44,
  119521. 3,
  119522. 45,
  119523. 2,
  119524. 46,
  119525. 1,
  119526. 47,
  119527. 0,
  119528. 48,
  119529. };
  119530. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119531. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119532. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119533. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119534. 7,
  119535. };
  119536. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119537. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119538. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119539. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119540. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119541. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119542. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119543. };
  119544. static long _vq_quantmap__44c7_s_p9_2[] = {
  119545. 47, 45, 43, 41, 39, 37, 35, 33,
  119546. 31, 29, 27, 25, 23, 21, 19, 17,
  119547. 15, 13, 11, 9, 7, 5, 3, 1,
  119548. 0, 2, 4, 6, 8, 10, 12, 14,
  119549. 16, 18, 20, 22, 24, 26, 28, 30,
  119550. 32, 34, 36, 38, 40, 42, 44, 46,
  119551. 48,
  119552. };
  119553. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119554. _vq_quantthresh__44c7_s_p9_2,
  119555. _vq_quantmap__44c7_s_p9_2,
  119556. 49,
  119557. 49
  119558. };
  119559. static static_codebook _44c7_s_p9_2 = {
  119560. 1, 49,
  119561. _vq_lengthlist__44c7_s_p9_2,
  119562. 1, -526909440, 1611661312, 6, 0,
  119563. _vq_quantlist__44c7_s_p9_2,
  119564. NULL,
  119565. &_vq_auxt__44c7_s_p9_2,
  119566. NULL,
  119567. 0
  119568. };
  119569. static long _huff_lengthlist__44c7_s_short[] = {
  119570. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119571. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119572. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119573. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119574. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119575. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119576. 10, 9,11,14,
  119577. };
  119578. static static_codebook _huff_book__44c7_s_short = {
  119579. 2, 100,
  119580. _huff_lengthlist__44c7_s_short,
  119581. 0, 0, 0, 0, 0,
  119582. NULL,
  119583. NULL,
  119584. NULL,
  119585. NULL,
  119586. 0
  119587. };
  119588. static long _huff_lengthlist__44c8_s_long[] = {
  119589. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119590. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119591. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119592. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119593. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119594. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119595. 11, 9, 9,10,
  119596. };
  119597. static static_codebook _huff_book__44c8_s_long = {
  119598. 2, 100,
  119599. _huff_lengthlist__44c8_s_long,
  119600. 0, 0, 0, 0, 0,
  119601. NULL,
  119602. NULL,
  119603. NULL,
  119604. NULL,
  119605. 0
  119606. };
  119607. static long _vq_quantlist__44c8_s_p1_0[] = {
  119608. 1,
  119609. 0,
  119610. 2,
  119611. };
  119612. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119613. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119614. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119615. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119616. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119617. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119618. 8,
  119619. };
  119620. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119621. -0.5, 0.5,
  119622. };
  119623. static long _vq_quantmap__44c8_s_p1_0[] = {
  119624. 1, 0, 2,
  119625. };
  119626. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119627. _vq_quantthresh__44c8_s_p1_0,
  119628. _vq_quantmap__44c8_s_p1_0,
  119629. 3,
  119630. 3
  119631. };
  119632. static static_codebook _44c8_s_p1_0 = {
  119633. 4, 81,
  119634. _vq_lengthlist__44c8_s_p1_0,
  119635. 1, -535822336, 1611661312, 2, 0,
  119636. _vq_quantlist__44c8_s_p1_0,
  119637. NULL,
  119638. &_vq_auxt__44c8_s_p1_0,
  119639. NULL,
  119640. 0
  119641. };
  119642. static long _vq_quantlist__44c8_s_p2_0[] = {
  119643. 2,
  119644. 1,
  119645. 3,
  119646. 0,
  119647. 4,
  119648. };
  119649. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119650. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119651. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119652. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119653. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119654. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119655. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119656. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119657. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119659. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119660. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119661. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119662. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119663. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119664. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119665. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119667. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119668. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119669. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119670. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119671. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119672. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119673. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119675. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119676. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119677. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119678. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119679. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119680. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119681. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119686. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119687. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119688. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119689. 13,
  119690. };
  119691. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119692. -1.5, -0.5, 0.5, 1.5,
  119693. };
  119694. static long _vq_quantmap__44c8_s_p2_0[] = {
  119695. 3, 1, 0, 2, 4,
  119696. };
  119697. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119698. _vq_quantthresh__44c8_s_p2_0,
  119699. _vq_quantmap__44c8_s_p2_0,
  119700. 5,
  119701. 5
  119702. };
  119703. static static_codebook _44c8_s_p2_0 = {
  119704. 4, 625,
  119705. _vq_lengthlist__44c8_s_p2_0,
  119706. 1, -533725184, 1611661312, 3, 0,
  119707. _vq_quantlist__44c8_s_p2_0,
  119708. NULL,
  119709. &_vq_auxt__44c8_s_p2_0,
  119710. NULL,
  119711. 0
  119712. };
  119713. static long _vq_quantlist__44c8_s_p3_0[] = {
  119714. 4,
  119715. 3,
  119716. 5,
  119717. 2,
  119718. 6,
  119719. 1,
  119720. 7,
  119721. 0,
  119722. 8,
  119723. };
  119724. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119725. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119726. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119727. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119728. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119730. 0,
  119731. };
  119732. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119733. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119734. };
  119735. static long _vq_quantmap__44c8_s_p3_0[] = {
  119736. 7, 5, 3, 1, 0, 2, 4, 6,
  119737. 8,
  119738. };
  119739. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119740. _vq_quantthresh__44c8_s_p3_0,
  119741. _vq_quantmap__44c8_s_p3_0,
  119742. 9,
  119743. 9
  119744. };
  119745. static static_codebook _44c8_s_p3_0 = {
  119746. 2, 81,
  119747. _vq_lengthlist__44c8_s_p3_0,
  119748. 1, -531628032, 1611661312, 4, 0,
  119749. _vq_quantlist__44c8_s_p3_0,
  119750. NULL,
  119751. &_vq_auxt__44c8_s_p3_0,
  119752. NULL,
  119753. 0
  119754. };
  119755. static long _vq_quantlist__44c8_s_p4_0[] = {
  119756. 8,
  119757. 7,
  119758. 9,
  119759. 6,
  119760. 10,
  119761. 5,
  119762. 11,
  119763. 4,
  119764. 12,
  119765. 3,
  119766. 13,
  119767. 2,
  119768. 14,
  119769. 1,
  119770. 15,
  119771. 0,
  119772. 16,
  119773. };
  119774. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119775. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119776. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119777. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119778. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119779. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119780. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119781. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119782. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119783. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119784. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119793. 0,
  119794. };
  119795. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119796. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119797. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119798. };
  119799. static long _vq_quantmap__44c8_s_p4_0[] = {
  119800. 15, 13, 11, 9, 7, 5, 3, 1,
  119801. 0, 2, 4, 6, 8, 10, 12, 14,
  119802. 16,
  119803. };
  119804. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119805. _vq_quantthresh__44c8_s_p4_0,
  119806. _vq_quantmap__44c8_s_p4_0,
  119807. 17,
  119808. 17
  119809. };
  119810. static static_codebook _44c8_s_p4_0 = {
  119811. 2, 289,
  119812. _vq_lengthlist__44c8_s_p4_0,
  119813. 1, -529530880, 1611661312, 5, 0,
  119814. _vq_quantlist__44c8_s_p4_0,
  119815. NULL,
  119816. &_vq_auxt__44c8_s_p4_0,
  119817. NULL,
  119818. 0
  119819. };
  119820. static long _vq_quantlist__44c8_s_p5_0[] = {
  119821. 1,
  119822. 0,
  119823. 2,
  119824. };
  119825. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119826. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119827. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119828. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119829. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119830. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119831. 12,
  119832. };
  119833. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119834. -5.5, 5.5,
  119835. };
  119836. static long _vq_quantmap__44c8_s_p5_0[] = {
  119837. 1, 0, 2,
  119838. };
  119839. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119840. _vq_quantthresh__44c8_s_p5_0,
  119841. _vq_quantmap__44c8_s_p5_0,
  119842. 3,
  119843. 3
  119844. };
  119845. static static_codebook _44c8_s_p5_0 = {
  119846. 4, 81,
  119847. _vq_lengthlist__44c8_s_p5_0,
  119848. 1, -529137664, 1618345984, 2, 0,
  119849. _vq_quantlist__44c8_s_p5_0,
  119850. NULL,
  119851. &_vq_auxt__44c8_s_p5_0,
  119852. NULL,
  119853. 0
  119854. };
  119855. static long _vq_quantlist__44c8_s_p5_1[] = {
  119856. 5,
  119857. 4,
  119858. 6,
  119859. 3,
  119860. 7,
  119861. 2,
  119862. 8,
  119863. 1,
  119864. 9,
  119865. 0,
  119866. 10,
  119867. };
  119868. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119869. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119870. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119871. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119872. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119873. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119874. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119875. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119876. 11,11,11, 7, 7, 7, 7, 8, 8,
  119877. };
  119878. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119879. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119880. 3.5, 4.5,
  119881. };
  119882. static long _vq_quantmap__44c8_s_p5_1[] = {
  119883. 9, 7, 5, 3, 1, 0, 2, 4,
  119884. 6, 8, 10,
  119885. };
  119886. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119887. _vq_quantthresh__44c8_s_p5_1,
  119888. _vq_quantmap__44c8_s_p5_1,
  119889. 11,
  119890. 11
  119891. };
  119892. static static_codebook _44c8_s_p5_1 = {
  119893. 2, 121,
  119894. _vq_lengthlist__44c8_s_p5_1,
  119895. 1, -531365888, 1611661312, 4, 0,
  119896. _vq_quantlist__44c8_s_p5_1,
  119897. NULL,
  119898. &_vq_auxt__44c8_s_p5_1,
  119899. NULL,
  119900. 0
  119901. };
  119902. static long _vq_quantlist__44c8_s_p6_0[] = {
  119903. 6,
  119904. 5,
  119905. 7,
  119906. 4,
  119907. 8,
  119908. 3,
  119909. 9,
  119910. 2,
  119911. 10,
  119912. 1,
  119913. 11,
  119914. 0,
  119915. 12,
  119916. };
  119917. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119918. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119919. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119920. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119921. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119922. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119923. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119928. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119929. };
  119930. static float _vq_quantthresh__44c8_s_p6_0[] = {
  119931. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119932. 12.5, 17.5, 22.5, 27.5,
  119933. };
  119934. static long _vq_quantmap__44c8_s_p6_0[] = {
  119935. 11, 9, 7, 5, 3, 1, 0, 2,
  119936. 4, 6, 8, 10, 12,
  119937. };
  119938. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  119939. _vq_quantthresh__44c8_s_p6_0,
  119940. _vq_quantmap__44c8_s_p6_0,
  119941. 13,
  119942. 13
  119943. };
  119944. static static_codebook _44c8_s_p6_0 = {
  119945. 2, 169,
  119946. _vq_lengthlist__44c8_s_p6_0,
  119947. 1, -526516224, 1616117760, 4, 0,
  119948. _vq_quantlist__44c8_s_p6_0,
  119949. NULL,
  119950. &_vq_auxt__44c8_s_p6_0,
  119951. NULL,
  119952. 0
  119953. };
  119954. static long _vq_quantlist__44c8_s_p6_1[] = {
  119955. 2,
  119956. 1,
  119957. 3,
  119958. 0,
  119959. 4,
  119960. };
  119961. static long _vq_lengthlist__44c8_s_p6_1[] = {
  119962. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119963. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119964. };
  119965. static float _vq_quantthresh__44c8_s_p6_1[] = {
  119966. -1.5, -0.5, 0.5, 1.5,
  119967. };
  119968. static long _vq_quantmap__44c8_s_p6_1[] = {
  119969. 3, 1, 0, 2, 4,
  119970. };
  119971. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  119972. _vq_quantthresh__44c8_s_p6_1,
  119973. _vq_quantmap__44c8_s_p6_1,
  119974. 5,
  119975. 5
  119976. };
  119977. static static_codebook _44c8_s_p6_1 = {
  119978. 2, 25,
  119979. _vq_lengthlist__44c8_s_p6_1,
  119980. 1, -533725184, 1611661312, 3, 0,
  119981. _vq_quantlist__44c8_s_p6_1,
  119982. NULL,
  119983. &_vq_auxt__44c8_s_p6_1,
  119984. NULL,
  119985. 0
  119986. };
  119987. static long _vq_quantlist__44c8_s_p7_0[] = {
  119988. 6,
  119989. 5,
  119990. 7,
  119991. 4,
  119992. 8,
  119993. 3,
  119994. 9,
  119995. 2,
  119996. 10,
  119997. 1,
  119998. 11,
  119999. 0,
  120000. 12,
  120001. };
  120002. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120003. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120004. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120005. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120006. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120007. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120008. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120009. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120010. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120011. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120012. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120013. 20,13,13,13,13,14,13,15,15,
  120014. };
  120015. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120016. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120017. 27.5, 38.5, 49.5, 60.5,
  120018. };
  120019. static long _vq_quantmap__44c8_s_p7_0[] = {
  120020. 11, 9, 7, 5, 3, 1, 0, 2,
  120021. 4, 6, 8, 10, 12,
  120022. };
  120023. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120024. _vq_quantthresh__44c8_s_p7_0,
  120025. _vq_quantmap__44c8_s_p7_0,
  120026. 13,
  120027. 13
  120028. };
  120029. static static_codebook _44c8_s_p7_0 = {
  120030. 2, 169,
  120031. _vq_lengthlist__44c8_s_p7_0,
  120032. 1, -523206656, 1618345984, 4, 0,
  120033. _vq_quantlist__44c8_s_p7_0,
  120034. NULL,
  120035. &_vq_auxt__44c8_s_p7_0,
  120036. NULL,
  120037. 0
  120038. };
  120039. static long _vq_quantlist__44c8_s_p7_1[] = {
  120040. 5,
  120041. 4,
  120042. 6,
  120043. 3,
  120044. 7,
  120045. 2,
  120046. 8,
  120047. 1,
  120048. 9,
  120049. 0,
  120050. 10,
  120051. };
  120052. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120053. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120054. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120055. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120056. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120057. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120058. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120059. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120060. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120061. };
  120062. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120063. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120064. 3.5, 4.5,
  120065. };
  120066. static long _vq_quantmap__44c8_s_p7_1[] = {
  120067. 9, 7, 5, 3, 1, 0, 2, 4,
  120068. 6, 8, 10,
  120069. };
  120070. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120071. _vq_quantthresh__44c8_s_p7_1,
  120072. _vq_quantmap__44c8_s_p7_1,
  120073. 11,
  120074. 11
  120075. };
  120076. static static_codebook _44c8_s_p7_1 = {
  120077. 2, 121,
  120078. _vq_lengthlist__44c8_s_p7_1,
  120079. 1, -531365888, 1611661312, 4, 0,
  120080. _vq_quantlist__44c8_s_p7_1,
  120081. NULL,
  120082. &_vq_auxt__44c8_s_p7_1,
  120083. NULL,
  120084. 0
  120085. };
  120086. static long _vq_quantlist__44c8_s_p8_0[] = {
  120087. 7,
  120088. 6,
  120089. 8,
  120090. 5,
  120091. 9,
  120092. 4,
  120093. 10,
  120094. 3,
  120095. 11,
  120096. 2,
  120097. 12,
  120098. 1,
  120099. 13,
  120100. 0,
  120101. 14,
  120102. };
  120103. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120104. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120105. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120106. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120107. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120108. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120109. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120110. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120111. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120112. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120113. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120114. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120115. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120116. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120117. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120118. 15,
  120119. };
  120120. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120121. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120122. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120123. };
  120124. static long _vq_quantmap__44c8_s_p8_0[] = {
  120125. 13, 11, 9, 7, 5, 3, 1, 0,
  120126. 2, 4, 6, 8, 10, 12, 14,
  120127. };
  120128. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120129. _vq_quantthresh__44c8_s_p8_0,
  120130. _vq_quantmap__44c8_s_p8_0,
  120131. 15,
  120132. 15
  120133. };
  120134. static static_codebook _44c8_s_p8_0 = {
  120135. 2, 225,
  120136. _vq_lengthlist__44c8_s_p8_0,
  120137. 1, -520986624, 1620377600, 4, 0,
  120138. _vq_quantlist__44c8_s_p8_0,
  120139. NULL,
  120140. &_vq_auxt__44c8_s_p8_0,
  120141. NULL,
  120142. 0
  120143. };
  120144. static long _vq_quantlist__44c8_s_p8_1[] = {
  120145. 10,
  120146. 9,
  120147. 11,
  120148. 8,
  120149. 12,
  120150. 7,
  120151. 13,
  120152. 6,
  120153. 14,
  120154. 5,
  120155. 15,
  120156. 4,
  120157. 16,
  120158. 3,
  120159. 17,
  120160. 2,
  120161. 18,
  120162. 1,
  120163. 19,
  120164. 0,
  120165. 20,
  120166. };
  120167. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120168. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120169. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120170. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120171. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120172. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120173. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120174. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120175. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120176. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120177. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120178. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120179. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120180. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120181. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120182. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120183. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120184. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120185. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120186. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120187. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120188. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120189. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120190. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120191. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120192. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120193. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120194. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120195. 10, 9, 9,10,10, 9,10, 9, 9,
  120196. };
  120197. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120198. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120199. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120200. 6.5, 7.5, 8.5, 9.5,
  120201. };
  120202. static long _vq_quantmap__44c8_s_p8_1[] = {
  120203. 19, 17, 15, 13, 11, 9, 7, 5,
  120204. 3, 1, 0, 2, 4, 6, 8, 10,
  120205. 12, 14, 16, 18, 20,
  120206. };
  120207. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120208. _vq_quantthresh__44c8_s_p8_1,
  120209. _vq_quantmap__44c8_s_p8_1,
  120210. 21,
  120211. 21
  120212. };
  120213. static static_codebook _44c8_s_p8_1 = {
  120214. 2, 441,
  120215. _vq_lengthlist__44c8_s_p8_1,
  120216. 1, -529268736, 1611661312, 5, 0,
  120217. _vq_quantlist__44c8_s_p8_1,
  120218. NULL,
  120219. &_vq_auxt__44c8_s_p8_1,
  120220. NULL,
  120221. 0
  120222. };
  120223. static long _vq_quantlist__44c8_s_p9_0[] = {
  120224. 8,
  120225. 7,
  120226. 9,
  120227. 6,
  120228. 10,
  120229. 5,
  120230. 11,
  120231. 4,
  120232. 12,
  120233. 3,
  120234. 13,
  120235. 2,
  120236. 14,
  120237. 1,
  120238. 15,
  120239. 0,
  120240. 16,
  120241. };
  120242. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120243. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120244. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120245. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120246. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120248. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120249. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120250. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120251. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120252. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120253. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120254. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120255. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120256. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120257. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120258. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120259. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120260. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120261. 10,
  120262. };
  120263. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120264. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120265. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120266. };
  120267. static long _vq_quantmap__44c8_s_p9_0[] = {
  120268. 15, 13, 11, 9, 7, 5, 3, 1,
  120269. 0, 2, 4, 6, 8, 10, 12, 14,
  120270. 16,
  120271. };
  120272. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120273. _vq_quantthresh__44c8_s_p9_0,
  120274. _vq_quantmap__44c8_s_p9_0,
  120275. 17,
  120276. 17
  120277. };
  120278. static static_codebook _44c8_s_p9_0 = {
  120279. 2, 289,
  120280. _vq_lengthlist__44c8_s_p9_0,
  120281. 1, -509798400, 1631393792, 5, 0,
  120282. _vq_quantlist__44c8_s_p9_0,
  120283. NULL,
  120284. &_vq_auxt__44c8_s_p9_0,
  120285. NULL,
  120286. 0
  120287. };
  120288. static long _vq_quantlist__44c8_s_p9_1[] = {
  120289. 9,
  120290. 8,
  120291. 10,
  120292. 7,
  120293. 11,
  120294. 6,
  120295. 12,
  120296. 5,
  120297. 13,
  120298. 4,
  120299. 14,
  120300. 3,
  120301. 15,
  120302. 2,
  120303. 16,
  120304. 1,
  120305. 17,
  120306. 0,
  120307. 18,
  120308. };
  120309. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120310. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120311. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120312. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120313. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120314. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120315. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120316. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120317. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120318. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120319. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120320. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120321. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120322. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120323. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120324. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120325. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120326. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120327. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120328. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120329. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120330. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120331. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120332. 14,13,13,14,14,15,14,15,14,
  120333. };
  120334. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120335. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120336. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120337. 367.5, 416.5,
  120338. };
  120339. static long _vq_quantmap__44c8_s_p9_1[] = {
  120340. 17, 15, 13, 11, 9, 7, 5, 3,
  120341. 1, 0, 2, 4, 6, 8, 10, 12,
  120342. 14, 16, 18,
  120343. };
  120344. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120345. _vq_quantthresh__44c8_s_p9_1,
  120346. _vq_quantmap__44c8_s_p9_1,
  120347. 19,
  120348. 19
  120349. };
  120350. static static_codebook _44c8_s_p9_1 = {
  120351. 2, 361,
  120352. _vq_lengthlist__44c8_s_p9_1,
  120353. 1, -518287360, 1622704128, 5, 0,
  120354. _vq_quantlist__44c8_s_p9_1,
  120355. NULL,
  120356. &_vq_auxt__44c8_s_p9_1,
  120357. NULL,
  120358. 0
  120359. };
  120360. static long _vq_quantlist__44c8_s_p9_2[] = {
  120361. 24,
  120362. 23,
  120363. 25,
  120364. 22,
  120365. 26,
  120366. 21,
  120367. 27,
  120368. 20,
  120369. 28,
  120370. 19,
  120371. 29,
  120372. 18,
  120373. 30,
  120374. 17,
  120375. 31,
  120376. 16,
  120377. 32,
  120378. 15,
  120379. 33,
  120380. 14,
  120381. 34,
  120382. 13,
  120383. 35,
  120384. 12,
  120385. 36,
  120386. 11,
  120387. 37,
  120388. 10,
  120389. 38,
  120390. 9,
  120391. 39,
  120392. 8,
  120393. 40,
  120394. 7,
  120395. 41,
  120396. 6,
  120397. 42,
  120398. 5,
  120399. 43,
  120400. 4,
  120401. 44,
  120402. 3,
  120403. 45,
  120404. 2,
  120405. 46,
  120406. 1,
  120407. 47,
  120408. 0,
  120409. 48,
  120410. };
  120411. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120412. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120413. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120414. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120415. 7,
  120416. };
  120417. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120418. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120419. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120420. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120421. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120422. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120423. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120424. };
  120425. static long _vq_quantmap__44c8_s_p9_2[] = {
  120426. 47, 45, 43, 41, 39, 37, 35, 33,
  120427. 31, 29, 27, 25, 23, 21, 19, 17,
  120428. 15, 13, 11, 9, 7, 5, 3, 1,
  120429. 0, 2, 4, 6, 8, 10, 12, 14,
  120430. 16, 18, 20, 22, 24, 26, 28, 30,
  120431. 32, 34, 36, 38, 40, 42, 44, 46,
  120432. 48,
  120433. };
  120434. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120435. _vq_quantthresh__44c8_s_p9_2,
  120436. _vq_quantmap__44c8_s_p9_2,
  120437. 49,
  120438. 49
  120439. };
  120440. static static_codebook _44c8_s_p9_2 = {
  120441. 1, 49,
  120442. _vq_lengthlist__44c8_s_p9_2,
  120443. 1, -526909440, 1611661312, 6, 0,
  120444. _vq_quantlist__44c8_s_p9_2,
  120445. NULL,
  120446. &_vq_auxt__44c8_s_p9_2,
  120447. NULL,
  120448. 0
  120449. };
  120450. static long _huff_lengthlist__44c8_s_short[] = {
  120451. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120452. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120453. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120454. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120455. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120456. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120457. 10, 9,11,14,
  120458. };
  120459. static static_codebook _huff_book__44c8_s_short = {
  120460. 2, 100,
  120461. _huff_lengthlist__44c8_s_short,
  120462. 0, 0, 0, 0, 0,
  120463. NULL,
  120464. NULL,
  120465. NULL,
  120466. NULL,
  120467. 0
  120468. };
  120469. static long _huff_lengthlist__44c9_s_long[] = {
  120470. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120471. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120472. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120473. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120474. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120475. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120476. 10, 9, 8, 9,
  120477. };
  120478. static static_codebook _huff_book__44c9_s_long = {
  120479. 2, 100,
  120480. _huff_lengthlist__44c9_s_long,
  120481. 0, 0, 0, 0, 0,
  120482. NULL,
  120483. NULL,
  120484. NULL,
  120485. NULL,
  120486. 0
  120487. };
  120488. static long _vq_quantlist__44c9_s_p1_0[] = {
  120489. 1,
  120490. 0,
  120491. 2,
  120492. };
  120493. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120494. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120495. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120496. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120497. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120498. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120499. 7,
  120500. };
  120501. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120502. -0.5, 0.5,
  120503. };
  120504. static long _vq_quantmap__44c9_s_p1_0[] = {
  120505. 1, 0, 2,
  120506. };
  120507. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120508. _vq_quantthresh__44c9_s_p1_0,
  120509. _vq_quantmap__44c9_s_p1_0,
  120510. 3,
  120511. 3
  120512. };
  120513. static static_codebook _44c9_s_p1_0 = {
  120514. 4, 81,
  120515. _vq_lengthlist__44c9_s_p1_0,
  120516. 1, -535822336, 1611661312, 2, 0,
  120517. _vq_quantlist__44c9_s_p1_0,
  120518. NULL,
  120519. &_vq_auxt__44c9_s_p1_0,
  120520. NULL,
  120521. 0
  120522. };
  120523. static long _vq_quantlist__44c9_s_p2_0[] = {
  120524. 2,
  120525. 1,
  120526. 3,
  120527. 0,
  120528. 4,
  120529. };
  120530. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120531. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120532. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120533. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120534. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120535. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120536. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120537. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120538. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120540. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120541. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120542. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120543. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120544. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120545. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120546. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120548. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120549. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120550. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120551. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120552. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120553. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120554. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120556. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120557. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120558. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120559. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120560. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120561. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120562. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120567. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120568. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120569. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120570. 12,
  120571. };
  120572. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120573. -1.5, -0.5, 0.5, 1.5,
  120574. };
  120575. static long _vq_quantmap__44c9_s_p2_0[] = {
  120576. 3, 1, 0, 2, 4,
  120577. };
  120578. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120579. _vq_quantthresh__44c9_s_p2_0,
  120580. _vq_quantmap__44c9_s_p2_0,
  120581. 5,
  120582. 5
  120583. };
  120584. static static_codebook _44c9_s_p2_0 = {
  120585. 4, 625,
  120586. _vq_lengthlist__44c9_s_p2_0,
  120587. 1, -533725184, 1611661312, 3, 0,
  120588. _vq_quantlist__44c9_s_p2_0,
  120589. NULL,
  120590. &_vq_auxt__44c9_s_p2_0,
  120591. NULL,
  120592. 0
  120593. };
  120594. static long _vq_quantlist__44c9_s_p3_0[] = {
  120595. 4,
  120596. 3,
  120597. 5,
  120598. 2,
  120599. 6,
  120600. 1,
  120601. 7,
  120602. 0,
  120603. 8,
  120604. };
  120605. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120606. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120607. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120608. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120609. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120611. 0,
  120612. };
  120613. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120614. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120615. };
  120616. static long _vq_quantmap__44c9_s_p3_0[] = {
  120617. 7, 5, 3, 1, 0, 2, 4, 6,
  120618. 8,
  120619. };
  120620. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120621. _vq_quantthresh__44c9_s_p3_0,
  120622. _vq_quantmap__44c9_s_p3_0,
  120623. 9,
  120624. 9
  120625. };
  120626. static static_codebook _44c9_s_p3_0 = {
  120627. 2, 81,
  120628. _vq_lengthlist__44c9_s_p3_0,
  120629. 1, -531628032, 1611661312, 4, 0,
  120630. _vq_quantlist__44c9_s_p3_0,
  120631. NULL,
  120632. &_vq_auxt__44c9_s_p3_0,
  120633. NULL,
  120634. 0
  120635. };
  120636. static long _vq_quantlist__44c9_s_p4_0[] = {
  120637. 8,
  120638. 7,
  120639. 9,
  120640. 6,
  120641. 10,
  120642. 5,
  120643. 11,
  120644. 4,
  120645. 12,
  120646. 3,
  120647. 13,
  120648. 2,
  120649. 14,
  120650. 1,
  120651. 15,
  120652. 0,
  120653. 16,
  120654. };
  120655. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120656. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120657. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120658. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120659. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120660. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120661. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120662. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120663. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120664. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120665. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120674. 0,
  120675. };
  120676. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120677. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120678. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120679. };
  120680. static long _vq_quantmap__44c9_s_p4_0[] = {
  120681. 15, 13, 11, 9, 7, 5, 3, 1,
  120682. 0, 2, 4, 6, 8, 10, 12, 14,
  120683. 16,
  120684. };
  120685. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120686. _vq_quantthresh__44c9_s_p4_0,
  120687. _vq_quantmap__44c9_s_p4_0,
  120688. 17,
  120689. 17
  120690. };
  120691. static static_codebook _44c9_s_p4_0 = {
  120692. 2, 289,
  120693. _vq_lengthlist__44c9_s_p4_0,
  120694. 1, -529530880, 1611661312, 5, 0,
  120695. _vq_quantlist__44c9_s_p4_0,
  120696. NULL,
  120697. &_vq_auxt__44c9_s_p4_0,
  120698. NULL,
  120699. 0
  120700. };
  120701. static long _vq_quantlist__44c9_s_p5_0[] = {
  120702. 1,
  120703. 0,
  120704. 2,
  120705. };
  120706. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120707. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120708. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120709. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120710. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120711. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120712. 12,
  120713. };
  120714. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120715. -5.5, 5.5,
  120716. };
  120717. static long _vq_quantmap__44c9_s_p5_0[] = {
  120718. 1, 0, 2,
  120719. };
  120720. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120721. _vq_quantthresh__44c9_s_p5_0,
  120722. _vq_quantmap__44c9_s_p5_0,
  120723. 3,
  120724. 3
  120725. };
  120726. static static_codebook _44c9_s_p5_0 = {
  120727. 4, 81,
  120728. _vq_lengthlist__44c9_s_p5_0,
  120729. 1, -529137664, 1618345984, 2, 0,
  120730. _vq_quantlist__44c9_s_p5_0,
  120731. NULL,
  120732. &_vq_auxt__44c9_s_p5_0,
  120733. NULL,
  120734. 0
  120735. };
  120736. static long _vq_quantlist__44c9_s_p5_1[] = {
  120737. 5,
  120738. 4,
  120739. 6,
  120740. 3,
  120741. 7,
  120742. 2,
  120743. 8,
  120744. 1,
  120745. 9,
  120746. 0,
  120747. 10,
  120748. };
  120749. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120750. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120751. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120752. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120753. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120754. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120755. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120756. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120757. 11,11,11, 7, 7, 7, 7, 7, 7,
  120758. };
  120759. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120760. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120761. 3.5, 4.5,
  120762. };
  120763. static long _vq_quantmap__44c9_s_p5_1[] = {
  120764. 9, 7, 5, 3, 1, 0, 2, 4,
  120765. 6, 8, 10,
  120766. };
  120767. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120768. _vq_quantthresh__44c9_s_p5_1,
  120769. _vq_quantmap__44c9_s_p5_1,
  120770. 11,
  120771. 11
  120772. };
  120773. static static_codebook _44c9_s_p5_1 = {
  120774. 2, 121,
  120775. _vq_lengthlist__44c9_s_p5_1,
  120776. 1, -531365888, 1611661312, 4, 0,
  120777. _vq_quantlist__44c9_s_p5_1,
  120778. NULL,
  120779. &_vq_auxt__44c9_s_p5_1,
  120780. NULL,
  120781. 0
  120782. };
  120783. static long _vq_quantlist__44c9_s_p6_0[] = {
  120784. 6,
  120785. 5,
  120786. 7,
  120787. 4,
  120788. 8,
  120789. 3,
  120790. 9,
  120791. 2,
  120792. 10,
  120793. 1,
  120794. 11,
  120795. 0,
  120796. 12,
  120797. };
  120798. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120799. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120800. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120801. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120802. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120803. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120804. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120809. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120810. };
  120811. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120812. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120813. 12.5, 17.5, 22.5, 27.5,
  120814. };
  120815. static long _vq_quantmap__44c9_s_p6_0[] = {
  120816. 11, 9, 7, 5, 3, 1, 0, 2,
  120817. 4, 6, 8, 10, 12,
  120818. };
  120819. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120820. _vq_quantthresh__44c9_s_p6_0,
  120821. _vq_quantmap__44c9_s_p6_0,
  120822. 13,
  120823. 13
  120824. };
  120825. static static_codebook _44c9_s_p6_0 = {
  120826. 2, 169,
  120827. _vq_lengthlist__44c9_s_p6_0,
  120828. 1, -526516224, 1616117760, 4, 0,
  120829. _vq_quantlist__44c9_s_p6_0,
  120830. NULL,
  120831. &_vq_auxt__44c9_s_p6_0,
  120832. NULL,
  120833. 0
  120834. };
  120835. static long _vq_quantlist__44c9_s_p6_1[] = {
  120836. 2,
  120837. 1,
  120838. 3,
  120839. 0,
  120840. 4,
  120841. };
  120842. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120843. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120844. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120845. };
  120846. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120847. -1.5, -0.5, 0.5, 1.5,
  120848. };
  120849. static long _vq_quantmap__44c9_s_p6_1[] = {
  120850. 3, 1, 0, 2, 4,
  120851. };
  120852. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120853. _vq_quantthresh__44c9_s_p6_1,
  120854. _vq_quantmap__44c9_s_p6_1,
  120855. 5,
  120856. 5
  120857. };
  120858. static static_codebook _44c9_s_p6_1 = {
  120859. 2, 25,
  120860. _vq_lengthlist__44c9_s_p6_1,
  120861. 1, -533725184, 1611661312, 3, 0,
  120862. _vq_quantlist__44c9_s_p6_1,
  120863. NULL,
  120864. &_vq_auxt__44c9_s_p6_1,
  120865. NULL,
  120866. 0
  120867. };
  120868. static long _vq_quantlist__44c9_s_p7_0[] = {
  120869. 6,
  120870. 5,
  120871. 7,
  120872. 4,
  120873. 8,
  120874. 3,
  120875. 9,
  120876. 2,
  120877. 10,
  120878. 1,
  120879. 11,
  120880. 0,
  120881. 12,
  120882. };
  120883. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120884. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120885. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120886. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120887. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120888. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120889. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120890. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120891. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120892. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120893. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120894. 19,12,12,12,12,13,13,14,14,
  120895. };
  120896. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120897. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120898. 27.5, 38.5, 49.5, 60.5,
  120899. };
  120900. static long _vq_quantmap__44c9_s_p7_0[] = {
  120901. 11, 9, 7, 5, 3, 1, 0, 2,
  120902. 4, 6, 8, 10, 12,
  120903. };
  120904. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120905. _vq_quantthresh__44c9_s_p7_0,
  120906. _vq_quantmap__44c9_s_p7_0,
  120907. 13,
  120908. 13
  120909. };
  120910. static static_codebook _44c9_s_p7_0 = {
  120911. 2, 169,
  120912. _vq_lengthlist__44c9_s_p7_0,
  120913. 1, -523206656, 1618345984, 4, 0,
  120914. _vq_quantlist__44c9_s_p7_0,
  120915. NULL,
  120916. &_vq_auxt__44c9_s_p7_0,
  120917. NULL,
  120918. 0
  120919. };
  120920. static long _vq_quantlist__44c9_s_p7_1[] = {
  120921. 5,
  120922. 4,
  120923. 6,
  120924. 3,
  120925. 7,
  120926. 2,
  120927. 8,
  120928. 1,
  120929. 9,
  120930. 0,
  120931. 10,
  120932. };
  120933. static long _vq_lengthlist__44c9_s_p7_1[] = {
  120934. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  120935. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120936. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  120937. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120938. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120939. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120940. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120941. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120942. };
  120943. static float _vq_quantthresh__44c9_s_p7_1[] = {
  120944. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120945. 3.5, 4.5,
  120946. };
  120947. static long _vq_quantmap__44c9_s_p7_1[] = {
  120948. 9, 7, 5, 3, 1, 0, 2, 4,
  120949. 6, 8, 10,
  120950. };
  120951. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  120952. _vq_quantthresh__44c9_s_p7_1,
  120953. _vq_quantmap__44c9_s_p7_1,
  120954. 11,
  120955. 11
  120956. };
  120957. static static_codebook _44c9_s_p7_1 = {
  120958. 2, 121,
  120959. _vq_lengthlist__44c9_s_p7_1,
  120960. 1, -531365888, 1611661312, 4, 0,
  120961. _vq_quantlist__44c9_s_p7_1,
  120962. NULL,
  120963. &_vq_auxt__44c9_s_p7_1,
  120964. NULL,
  120965. 0
  120966. };
  120967. static long _vq_quantlist__44c9_s_p8_0[] = {
  120968. 7,
  120969. 6,
  120970. 8,
  120971. 5,
  120972. 9,
  120973. 4,
  120974. 10,
  120975. 3,
  120976. 11,
  120977. 2,
  120978. 12,
  120979. 1,
  120980. 13,
  120981. 0,
  120982. 14,
  120983. };
  120984. static long _vq_lengthlist__44c9_s_p8_0[] = {
  120985. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  120986. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  120987. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  120988. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  120989. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  120990. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  120991. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  120992. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  120993. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  120994. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  120995. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  120996. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  120997. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  120998. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  120999. 14,
  121000. };
  121001. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121002. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121003. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121004. };
  121005. static long _vq_quantmap__44c9_s_p8_0[] = {
  121006. 13, 11, 9, 7, 5, 3, 1, 0,
  121007. 2, 4, 6, 8, 10, 12, 14,
  121008. };
  121009. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121010. _vq_quantthresh__44c9_s_p8_0,
  121011. _vq_quantmap__44c9_s_p8_0,
  121012. 15,
  121013. 15
  121014. };
  121015. static static_codebook _44c9_s_p8_0 = {
  121016. 2, 225,
  121017. _vq_lengthlist__44c9_s_p8_0,
  121018. 1, -520986624, 1620377600, 4, 0,
  121019. _vq_quantlist__44c9_s_p8_0,
  121020. NULL,
  121021. &_vq_auxt__44c9_s_p8_0,
  121022. NULL,
  121023. 0
  121024. };
  121025. static long _vq_quantlist__44c9_s_p8_1[] = {
  121026. 10,
  121027. 9,
  121028. 11,
  121029. 8,
  121030. 12,
  121031. 7,
  121032. 13,
  121033. 6,
  121034. 14,
  121035. 5,
  121036. 15,
  121037. 4,
  121038. 16,
  121039. 3,
  121040. 17,
  121041. 2,
  121042. 18,
  121043. 1,
  121044. 19,
  121045. 0,
  121046. 20,
  121047. };
  121048. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121049. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121050. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121051. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121052. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121053. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121054. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121055. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121056. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121057. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121058. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121059. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121060. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121061. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121062. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121063. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121064. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121065. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121066. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121067. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121068. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121069. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121070. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121071. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121072. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121073. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121074. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121075. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121076. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121077. };
  121078. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121079. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121080. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121081. 6.5, 7.5, 8.5, 9.5,
  121082. };
  121083. static long _vq_quantmap__44c9_s_p8_1[] = {
  121084. 19, 17, 15, 13, 11, 9, 7, 5,
  121085. 3, 1, 0, 2, 4, 6, 8, 10,
  121086. 12, 14, 16, 18, 20,
  121087. };
  121088. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121089. _vq_quantthresh__44c9_s_p8_1,
  121090. _vq_quantmap__44c9_s_p8_1,
  121091. 21,
  121092. 21
  121093. };
  121094. static static_codebook _44c9_s_p8_1 = {
  121095. 2, 441,
  121096. _vq_lengthlist__44c9_s_p8_1,
  121097. 1, -529268736, 1611661312, 5, 0,
  121098. _vq_quantlist__44c9_s_p8_1,
  121099. NULL,
  121100. &_vq_auxt__44c9_s_p8_1,
  121101. NULL,
  121102. 0
  121103. };
  121104. static long _vq_quantlist__44c9_s_p9_0[] = {
  121105. 9,
  121106. 8,
  121107. 10,
  121108. 7,
  121109. 11,
  121110. 6,
  121111. 12,
  121112. 5,
  121113. 13,
  121114. 4,
  121115. 14,
  121116. 3,
  121117. 15,
  121118. 2,
  121119. 16,
  121120. 1,
  121121. 17,
  121122. 0,
  121123. 18,
  121124. };
  121125. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121126. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121127. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121128. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121129. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121130. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121131. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121132. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121133. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121134. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121135. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121136. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121137. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121138. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121139. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121140. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121141. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121142. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121143. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121144. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121145. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121146. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121147. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121148. 11,11,11,11,11,11,11,11,11,
  121149. };
  121150. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121151. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121152. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121153. 6982.5, 7913.5,
  121154. };
  121155. static long _vq_quantmap__44c9_s_p9_0[] = {
  121156. 17, 15, 13, 11, 9, 7, 5, 3,
  121157. 1, 0, 2, 4, 6, 8, 10, 12,
  121158. 14, 16, 18,
  121159. };
  121160. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121161. _vq_quantthresh__44c9_s_p9_0,
  121162. _vq_quantmap__44c9_s_p9_0,
  121163. 19,
  121164. 19
  121165. };
  121166. static static_codebook _44c9_s_p9_0 = {
  121167. 2, 361,
  121168. _vq_lengthlist__44c9_s_p9_0,
  121169. 1, -508535424, 1631393792, 5, 0,
  121170. _vq_quantlist__44c9_s_p9_0,
  121171. NULL,
  121172. &_vq_auxt__44c9_s_p9_0,
  121173. NULL,
  121174. 0
  121175. };
  121176. static long _vq_quantlist__44c9_s_p9_1[] = {
  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_1[] = {
  121198. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121199. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121200. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121201. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121202. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121203. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121204. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121205. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121206. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121207. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121208. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121209. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121210. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121211. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121212. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121213. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121214. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121215. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121216. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121217. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121218. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121219. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121220. 13,13,13,14,13,14,15,15,15,
  121221. };
  121222. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121223. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121224. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121225. 367.5, 416.5,
  121226. };
  121227. static long _vq_quantmap__44c9_s_p9_1[] = {
  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_1 = {
  121233. _vq_quantthresh__44c9_s_p9_1,
  121234. _vq_quantmap__44c9_s_p9_1,
  121235. 19,
  121236. 19
  121237. };
  121238. static static_codebook _44c9_s_p9_1 = {
  121239. 2, 361,
  121240. _vq_lengthlist__44c9_s_p9_1,
  121241. 1, -518287360, 1622704128, 5, 0,
  121242. _vq_quantlist__44c9_s_p9_1,
  121243. NULL,
  121244. &_vq_auxt__44c9_s_p9_1,
  121245. NULL,
  121246. 0
  121247. };
  121248. static long _vq_quantlist__44c9_s_p9_2[] = {
  121249. 24,
  121250. 23,
  121251. 25,
  121252. 22,
  121253. 26,
  121254. 21,
  121255. 27,
  121256. 20,
  121257. 28,
  121258. 19,
  121259. 29,
  121260. 18,
  121261. 30,
  121262. 17,
  121263. 31,
  121264. 16,
  121265. 32,
  121266. 15,
  121267. 33,
  121268. 14,
  121269. 34,
  121270. 13,
  121271. 35,
  121272. 12,
  121273. 36,
  121274. 11,
  121275. 37,
  121276. 10,
  121277. 38,
  121278. 9,
  121279. 39,
  121280. 8,
  121281. 40,
  121282. 7,
  121283. 41,
  121284. 6,
  121285. 42,
  121286. 5,
  121287. 43,
  121288. 4,
  121289. 44,
  121290. 3,
  121291. 45,
  121292. 2,
  121293. 46,
  121294. 1,
  121295. 47,
  121296. 0,
  121297. 48,
  121298. };
  121299. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121300. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121301. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121302. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121303. 7,
  121304. };
  121305. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121306. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121307. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121308. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121309. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121310. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121311. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121312. };
  121313. static long _vq_quantmap__44c9_s_p9_2[] = {
  121314. 47, 45, 43, 41, 39, 37, 35, 33,
  121315. 31, 29, 27, 25, 23, 21, 19, 17,
  121316. 15, 13, 11, 9, 7, 5, 3, 1,
  121317. 0, 2, 4, 6, 8, 10, 12, 14,
  121318. 16, 18, 20, 22, 24, 26, 28, 30,
  121319. 32, 34, 36, 38, 40, 42, 44, 46,
  121320. 48,
  121321. };
  121322. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121323. _vq_quantthresh__44c9_s_p9_2,
  121324. _vq_quantmap__44c9_s_p9_2,
  121325. 49,
  121326. 49
  121327. };
  121328. static static_codebook _44c9_s_p9_2 = {
  121329. 1, 49,
  121330. _vq_lengthlist__44c9_s_p9_2,
  121331. 1, -526909440, 1611661312, 6, 0,
  121332. _vq_quantlist__44c9_s_p9_2,
  121333. NULL,
  121334. &_vq_auxt__44c9_s_p9_2,
  121335. NULL,
  121336. 0
  121337. };
  121338. static long _huff_lengthlist__44c9_s_short[] = {
  121339. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121340. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121341. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121342. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121343. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121344. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121345. 9, 8,10,13,
  121346. };
  121347. static static_codebook _huff_book__44c9_s_short = {
  121348. 2, 100,
  121349. _huff_lengthlist__44c9_s_short,
  121350. 0, 0, 0, 0, 0,
  121351. NULL,
  121352. NULL,
  121353. NULL,
  121354. NULL,
  121355. 0
  121356. };
  121357. static long _huff_lengthlist__44c0_s_long[] = {
  121358. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121359. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121360. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121361. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121362. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121363. 12,
  121364. };
  121365. static static_codebook _huff_book__44c0_s_long = {
  121366. 2, 81,
  121367. _huff_lengthlist__44c0_s_long,
  121368. 0, 0, 0, 0, 0,
  121369. NULL,
  121370. NULL,
  121371. NULL,
  121372. NULL,
  121373. 0
  121374. };
  121375. static long _vq_quantlist__44c0_s_p1_0[] = {
  121376. 1,
  121377. 0,
  121378. 2,
  121379. };
  121380. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121381. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121382. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121386. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121387. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121391. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121392. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121427. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121432. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121437. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121454. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121459. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121464. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121473. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121478. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121483. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0,
  121499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121500. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  121504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  121792. };
  121793. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121794. -0.5, 0.5,
  121795. };
  121796. static long _vq_quantmap__44c0_s_p1_0[] = {
  121797. 1, 0, 2,
  121798. };
  121799. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121800. _vq_quantthresh__44c0_s_p1_0,
  121801. _vq_quantmap__44c0_s_p1_0,
  121802. 3,
  121803. 3
  121804. };
  121805. static static_codebook _44c0_s_p1_0 = {
  121806. 8, 6561,
  121807. _vq_lengthlist__44c0_s_p1_0,
  121808. 1, -535822336, 1611661312, 2, 0,
  121809. _vq_quantlist__44c0_s_p1_0,
  121810. NULL,
  121811. &_vq_auxt__44c0_s_p1_0,
  121812. NULL,
  121813. 0
  121814. };
  121815. static long _vq_quantlist__44c0_s_p2_0[] = {
  121816. 2,
  121817. 1,
  121818. 3,
  121819. 0,
  121820. 4,
  121821. };
  121822. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121823. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121826. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121829. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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,
  121863. };
  121864. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121865. -1.5, -0.5, 0.5, 1.5,
  121866. };
  121867. static long _vq_quantmap__44c0_s_p2_0[] = {
  121868. 3, 1, 0, 2, 4,
  121869. };
  121870. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121871. _vq_quantthresh__44c0_s_p2_0,
  121872. _vq_quantmap__44c0_s_p2_0,
  121873. 5,
  121874. 5
  121875. };
  121876. static static_codebook _44c0_s_p2_0 = {
  121877. 4, 625,
  121878. _vq_lengthlist__44c0_s_p2_0,
  121879. 1, -533725184, 1611661312, 3, 0,
  121880. _vq_quantlist__44c0_s_p2_0,
  121881. NULL,
  121882. &_vq_auxt__44c0_s_p2_0,
  121883. NULL,
  121884. 0
  121885. };
  121886. static long _vq_quantlist__44c0_s_p3_0[] = {
  121887. 4,
  121888. 3,
  121889. 5,
  121890. 2,
  121891. 6,
  121892. 1,
  121893. 7,
  121894. 0,
  121895. 8,
  121896. };
  121897. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121898. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121899. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121900. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121901. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121902. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121903. 0,
  121904. };
  121905. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121906. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121907. };
  121908. static long _vq_quantmap__44c0_s_p3_0[] = {
  121909. 7, 5, 3, 1, 0, 2, 4, 6,
  121910. 8,
  121911. };
  121912. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121913. _vq_quantthresh__44c0_s_p3_0,
  121914. _vq_quantmap__44c0_s_p3_0,
  121915. 9,
  121916. 9
  121917. };
  121918. static static_codebook _44c0_s_p3_0 = {
  121919. 2, 81,
  121920. _vq_lengthlist__44c0_s_p3_0,
  121921. 1, -531628032, 1611661312, 4, 0,
  121922. _vq_quantlist__44c0_s_p3_0,
  121923. NULL,
  121924. &_vq_auxt__44c0_s_p3_0,
  121925. NULL,
  121926. 0
  121927. };
  121928. static long _vq_quantlist__44c0_s_p4_0[] = {
  121929. 4,
  121930. 3,
  121931. 5,
  121932. 2,
  121933. 6,
  121934. 1,
  121935. 7,
  121936. 0,
  121937. 8,
  121938. };
  121939. static long _vq_lengthlist__44c0_s_p4_0[] = {
  121940. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  121941. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  121942. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  121943. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  121944. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  121945. 10,
  121946. };
  121947. static float _vq_quantthresh__44c0_s_p4_0[] = {
  121948. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121949. };
  121950. static long _vq_quantmap__44c0_s_p4_0[] = {
  121951. 7, 5, 3, 1, 0, 2, 4, 6,
  121952. 8,
  121953. };
  121954. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  121955. _vq_quantthresh__44c0_s_p4_0,
  121956. _vq_quantmap__44c0_s_p4_0,
  121957. 9,
  121958. 9
  121959. };
  121960. static static_codebook _44c0_s_p4_0 = {
  121961. 2, 81,
  121962. _vq_lengthlist__44c0_s_p4_0,
  121963. 1, -531628032, 1611661312, 4, 0,
  121964. _vq_quantlist__44c0_s_p4_0,
  121965. NULL,
  121966. &_vq_auxt__44c0_s_p4_0,
  121967. NULL,
  121968. 0
  121969. };
  121970. static long _vq_quantlist__44c0_s_p5_0[] = {
  121971. 8,
  121972. 7,
  121973. 9,
  121974. 6,
  121975. 10,
  121976. 5,
  121977. 11,
  121978. 4,
  121979. 12,
  121980. 3,
  121981. 13,
  121982. 2,
  121983. 14,
  121984. 1,
  121985. 15,
  121986. 0,
  121987. 16,
  121988. };
  121989. static long _vq_lengthlist__44c0_s_p5_0[] = {
  121990. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  121991. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  121992. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  121993. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  121994. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  121995. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  121996. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  121997. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  121998. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  121999. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122000. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122001. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122002. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122003. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122004. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122005. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122006. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122007. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122008. 14,
  122009. };
  122010. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122011. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122012. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122013. };
  122014. static long _vq_quantmap__44c0_s_p5_0[] = {
  122015. 15, 13, 11, 9, 7, 5, 3, 1,
  122016. 0, 2, 4, 6, 8, 10, 12, 14,
  122017. 16,
  122018. };
  122019. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122020. _vq_quantthresh__44c0_s_p5_0,
  122021. _vq_quantmap__44c0_s_p5_0,
  122022. 17,
  122023. 17
  122024. };
  122025. static static_codebook _44c0_s_p5_0 = {
  122026. 2, 289,
  122027. _vq_lengthlist__44c0_s_p5_0,
  122028. 1, -529530880, 1611661312, 5, 0,
  122029. _vq_quantlist__44c0_s_p5_0,
  122030. NULL,
  122031. &_vq_auxt__44c0_s_p5_0,
  122032. NULL,
  122033. 0
  122034. };
  122035. static long _vq_quantlist__44c0_s_p6_0[] = {
  122036. 1,
  122037. 0,
  122038. 2,
  122039. };
  122040. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122041. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122042. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122043. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122044. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122045. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122046. 10,
  122047. };
  122048. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122049. -5.5, 5.5,
  122050. };
  122051. static long _vq_quantmap__44c0_s_p6_0[] = {
  122052. 1, 0, 2,
  122053. };
  122054. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122055. _vq_quantthresh__44c0_s_p6_0,
  122056. _vq_quantmap__44c0_s_p6_0,
  122057. 3,
  122058. 3
  122059. };
  122060. static static_codebook _44c0_s_p6_0 = {
  122061. 4, 81,
  122062. _vq_lengthlist__44c0_s_p6_0,
  122063. 1, -529137664, 1618345984, 2, 0,
  122064. _vq_quantlist__44c0_s_p6_0,
  122065. NULL,
  122066. &_vq_auxt__44c0_s_p6_0,
  122067. NULL,
  122068. 0
  122069. };
  122070. static long _vq_quantlist__44c0_s_p6_1[] = {
  122071. 5,
  122072. 4,
  122073. 6,
  122074. 3,
  122075. 7,
  122076. 2,
  122077. 8,
  122078. 1,
  122079. 9,
  122080. 0,
  122081. 10,
  122082. };
  122083. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122084. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122085. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122086. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122087. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122088. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122089. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122090. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122091. 10,10,10, 8, 8, 8, 8, 8, 8,
  122092. };
  122093. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122094. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122095. 3.5, 4.5,
  122096. };
  122097. static long _vq_quantmap__44c0_s_p6_1[] = {
  122098. 9, 7, 5, 3, 1, 0, 2, 4,
  122099. 6, 8, 10,
  122100. };
  122101. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122102. _vq_quantthresh__44c0_s_p6_1,
  122103. _vq_quantmap__44c0_s_p6_1,
  122104. 11,
  122105. 11
  122106. };
  122107. static static_codebook _44c0_s_p6_1 = {
  122108. 2, 121,
  122109. _vq_lengthlist__44c0_s_p6_1,
  122110. 1, -531365888, 1611661312, 4, 0,
  122111. _vq_quantlist__44c0_s_p6_1,
  122112. NULL,
  122113. &_vq_auxt__44c0_s_p6_1,
  122114. NULL,
  122115. 0
  122116. };
  122117. static long _vq_quantlist__44c0_s_p7_0[] = {
  122118. 6,
  122119. 5,
  122120. 7,
  122121. 4,
  122122. 8,
  122123. 3,
  122124. 9,
  122125. 2,
  122126. 10,
  122127. 1,
  122128. 11,
  122129. 0,
  122130. 12,
  122131. };
  122132. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122133. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122134. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122135. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122136. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122137. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122138. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122139. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122140. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122141. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122142. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122143. 0,12,12,11,11,12,12,13,13,
  122144. };
  122145. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122146. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122147. 12.5, 17.5, 22.5, 27.5,
  122148. };
  122149. static long _vq_quantmap__44c0_s_p7_0[] = {
  122150. 11, 9, 7, 5, 3, 1, 0, 2,
  122151. 4, 6, 8, 10, 12,
  122152. };
  122153. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122154. _vq_quantthresh__44c0_s_p7_0,
  122155. _vq_quantmap__44c0_s_p7_0,
  122156. 13,
  122157. 13
  122158. };
  122159. static static_codebook _44c0_s_p7_0 = {
  122160. 2, 169,
  122161. _vq_lengthlist__44c0_s_p7_0,
  122162. 1, -526516224, 1616117760, 4, 0,
  122163. _vq_quantlist__44c0_s_p7_0,
  122164. NULL,
  122165. &_vq_auxt__44c0_s_p7_0,
  122166. NULL,
  122167. 0
  122168. };
  122169. static long _vq_quantlist__44c0_s_p7_1[] = {
  122170. 2,
  122171. 1,
  122172. 3,
  122173. 0,
  122174. 4,
  122175. };
  122176. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122177. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122178. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122179. };
  122180. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122181. -1.5, -0.5, 0.5, 1.5,
  122182. };
  122183. static long _vq_quantmap__44c0_s_p7_1[] = {
  122184. 3, 1, 0, 2, 4,
  122185. };
  122186. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122187. _vq_quantthresh__44c0_s_p7_1,
  122188. _vq_quantmap__44c0_s_p7_1,
  122189. 5,
  122190. 5
  122191. };
  122192. static static_codebook _44c0_s_p7_1 = {
  122193. 2, 25,
  122194. _vq_lengthlist__44c0_s_p7_1,
  122195. 1, -533725184, 1611661312, 3, 0,
  122196. _vq_quantlist__44c0_s_p7_1,
  122197. NULL,
  122198. &_vq_auxt__44c0_s_p7_1,
  122199. NULL,
  122200. 0
  122201. };
  122202. static long _vq_quantlist__44c0_s_p8_0[] = {
  122203. 2,
  122204. 1,
  122205. 3,
  122206. 0,
  122207. 4,
  122208. };
  122209. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122210. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122211. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122212. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122213. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122214. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122215. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122216. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122217. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122218. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122219. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122220. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122221. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122222. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122223. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122224. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122225. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122226. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122227. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122228. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122229. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122230. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122231. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122232. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122233. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122234. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122235. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122236. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122237. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122238. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122239. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122240. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122241. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122242. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122243. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122244. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122245. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122246. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122248. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122249. 11,
  122250. };
  122251. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122252. -331.5, -110.5, 110.5, 331.5,
  122253. };
  122254. static long _vq_quantmap__44c0_s_p8_0[] = {
  122255. 3, 1, 0, 2, 4,
  122256. };
  122257. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122258. _vq_quantthresh__44c0_s_p8_0,
  122259. _vq_quantmap__44c0_s_p8_0,
  122260. 5,
  122261. 5
  122262. };
  122263. static static_codebook _44c0_s_p8_0 = {
  122264. 4, 625,
  122265. _vq_lengthlist__44c0_s_p8_0,
  122266. 1, -518283264, 1627103232, 3, 0,
  122267. _vq_quantlist__44c0_s_p8_0,
  122268. NULL,
  122269. &_vq_auxt__44c0_s_p8_0,
  122270. NULL,
  122271. 0
  122272. };
  122273. static long _vq_quantlist__44c0_s_p8_1[] = {
  122274. 6,
  122275. 5,
  122276. 7,
  122277. 4,
  122278. 8,
  122279. 3,
  122280. 9,
  122281. 2,
  122282. 10,
  122283. 1,
  122284. 11,
  122285. 0,
  122286. 12,
  122287. };
  122288. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122289. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122290. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122291. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122292. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122293. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122294. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122295. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122296. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122297. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122298. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122299. 16,13,13,12,12,14,14,15,13,
  122300. };
  122301. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122302. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122303. 42.5, 59.5, 76.5, 93.5,
  122304. };
  122305. static long _vq_quantmap__44c0_s_p8_1[] = {
  122306. 11, 9, 7, 5, 3, 1, 0, 2,
  122307. 4, 6, 8, 10, 12,
  122308. };
  122309. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122310. _vq_quantthresh__44c0_s_p8_1,
  122311. _vq_quantmap__44c0_s_p8_1,
  122312. 13,
  122313. 13
  122314. };
  122315. static static_codebook _44c0_s_p8_1 = {
  122316. 2, 169,
  122317. _vq_lengthlist__44c0_s_p8_1,
  122318. 1, -522616832, 1620115456, 4, 0,
  122319. _vq_quantlist__44c0_s_p8_1,
  122320. NULL,
  122321. &_vq_auxt__44c0_s_p8_1,
  122322. NULL,
  122323. 0
  122324. };
  122325. static long _vq_quantlist__44c0_s_p8_2[] = {
  122326. 8,
  122327. 7,
  122328. 9,
  122329. 6,
  122330. 10,
  122331. 5,
  122332. 11,
  122333. 4,
  122334. 12,
  122335. 3,
  122336. 13,
  122337. 2,
  122338. 14,
  122339. 1,
  122340. 15,
  122341. 0,
  122342. 16,
  122343. };
  122344. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122345. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122346. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122347. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122348. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122349. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122350. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122351. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122352. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122353. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122354. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122355. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122356. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122357. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122358. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122359. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122360. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122361. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122362. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122363. 10,
  122364. };
  122365. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122366. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122367. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122368. };
  122369. static long _vq_quantmap__44c0_s_p8_2[] = {
  122370. 15, 13, 11, 9, 7, 5, 3, 1,
  122371. 0, 2, 4, 6, 8, 10, 12, 14,
  122372. 16,
  122373. };
  122374. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122375. _vq_quantthresh__44c0_s_p8_2,
  122376. _vq_quantmap__44c0_s_p8_2,
  122377. 17,
  122378. 17
  122379. };
  122380. static static_codebook _44c0_s_p8_2 = {
  122381. 2, 289,
  122382. _vq_lengthlist__44c0_s_p8_2,
  122383. 1, -529530880, 1611661312, 5, 0,
  122384. _vq_quantlist__44c0_s_p8_2,
  122385. NULL,
  122386. &_vq_auxt__44c0_s_p8_2,
  122387. NULL,
  122388. 0
  122389. };
  122390. static long _huff_lengthlist__44c0_s_short[] = {
  122391. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122392. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122393. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122394. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122395. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122396. 12,
  122397. };
  122398. static static_codebook _huff_book__44c0_s_short = {
  122399. 2, 81,
  122400. _huff_lengthlist__44c0_s_short,
  122401. 0, 0, 0, 0, 0,
  122402. NULL,
  122403. NULL,
  122404. NULL,
  122405. NULL,
  122406. 0
  122407. };
  122408. static long _huff_lengthlist__44c0_sm_long[] = {
  122409. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122410. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122411. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122412. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122413. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122414. 13,
  122415. };
  122416. static static_codebook _huff_book__44c0_sm_long = {
  122417. 2, 81,
  122418. _huff_lengthlist__44c0_sm_long,
  122419. 0, 0, 0, 0, 0,
  122420. NULL,
  122421. NULL,
  122422. NULL,
  122423. NULL,
  122424. 0
  122425. };
  122426. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122427. 1,
  122428. 0,
  122429. 2,
  122430. };
  122431. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122432. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122433. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122437. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122438. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122442. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122443. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122478. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122483. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122488. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122505. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122510. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122515. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122524. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122529. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122534. 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 0, 0, 0, 0, 0,
  122550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122551. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  122555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  122843. };
  122844. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122845. -0.5, 0.5,
  122846. };
  122847. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122848. 1, 0, 2,
  122849. };
  122850. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122851. _vq_quantthresh__44c0_sm_p1_0,
  122852. _vq_quantmap__44c0_sm_p1_0,
  122853. 3,
  122854. 3
  122855. };
  122856. static static_codebook _44c0_sm_p1_0 = {
  122857. 8, 6561,
  122858. _vq_lengthlist__44c0_sm_p1_0,
  122859. 1, -535822336, 1611661312, 2, 0,
  122860. _vq_quantlist__44c0_sm_p1_0,
  122861. NULL,
  122862. &_vq_auxt__44c0_sm_p1_0,
  122863. NULL,
  122864. 0
  122865. };
  122866. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122867. 2,
  122868. 1,
  122869. 3,
  122870. 0,
  122871. 4,
  122872. };
  122873. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122874. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122877. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122880. 0, 0, 0, 0, 7, 7, 7, 9, 9, 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,
  122914. };
  122915. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122916. -1.5, -0.5, 0.5, 1.5,
  122917. };
  122918. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122919. 3, 1, 0, 2, 4,
  122920. };
  122921. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122922. _vq_quantthresh__44c0_sm_p2_0,
  122923. _vq_quantmap__44c0_sm_p2_0,
  122924. 5,
  122925. 5
  122926. };
  122927. static static_codebook _44c0_sm_p2_0 = {
  122928. 4, 625,
  122929. _vq_lengthlist__44c0_sm_p2_0,
  122930. 1, -533725184, 1611661312, 3, 0,
  122931. _vq_quantlist__44c0_sm_p2_0,
  122932. NULL,
  122933. &_vq_auxt__44c0_sm_p2_0,
  122934. NULL,
  122935. 0
  122936. };
  122937. static long _vq_quantlist__44c0_sm_p3_0[] = {
  122938. 4,
  122939. 3,
  122940. 5,
  122941. 2,
  122942. 6,
  122943. 1,
  122944. 7,
  122945. 0,
  122946. 8,
  122947. };
  122948. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  122949. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  122950. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  122951. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  122952. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  122953. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122954. 0,
  122955. };
  122956. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  122957. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122958. };
  122959. static long _vq_quantmap__44c0_sm_p3_0[] = {
  122960. 7, 5, 3, 1, 0, 2, 4, 6,
  122961. 8,
  122962. };
  122963. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  122964. _vq_quantthresh__44c0_sm_p3_0,
  122965. _vq_quantmap__44c0_sm_p3_0,
  122966. 9,
  122967. 9
  122968. };
  122969. static static_codebook _44c0_sm_p3_0 = {
  122970. 2, 81,
  122971. _vq_lengthlist__44c0_sm_p3_0,
  122972. 1, -531628032, 1611661312, 4, 0,
  122973. _vq_quantlist__44c0_sm_p3_0,
  122974. NULL,
  122975. &_vq_auxt__44c0_sm_p3_0,
  122976. NULL,
  122977. 0
  122978. };
  122979. static long _vq_quantlist__44c0_sm_p4_0[] = {
  122980. 4,
  122981. 3,
  122982. 5,
  122983. 2,
  122984. 6,
  122985. 1,
  122986. 7,
  122987. 0,
  122988. 8,
  122989. };
  122990. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  122991. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  122992. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  122993. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  122994. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  122995. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  122996. 11,
  122997. };
  122998. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  122999. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123000. };
  123001. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123002. 7, 5, 3, 1, 0, 2, 4, 6,
  123003. 8,
  123004. };
  123005. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123006. _vq_quantthresh__44c0_sm_p4_0,
  123007. _vq_quantmap__44c0_sm_p4_0,
  123008. 9,
  123009. 9
  123010. };
  123011. static static_codebook _44c0_sm_p4_0 = {
  123012. 2, 81,
  123013. _vq_lengthlist__44c0_sm_p4_0,
  123014. 1, -531628032, 1611661312, 4, 0,
  123015. _vq_quantlist__44c0_sm_p4_0,
  123016. NULL,
  123017. &_vq_auxt__44c0_sm_p4_0,
  123018. NULL,
  123019. 0
  123020. };
  123021. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123022. 8,
  123023. 7,
  123024. 9,
  123025. 6,
  123026. 10,
  123027. 5,
  123028. 11,
  123029. 4,
  123030. 12,
  123031. 3,
  123032. 13,
  123033. 2,
  123034. 14,
  123035. 1,
  123036. 15,
  123037. 0,
  123038. 16,
  123039. };
  123040. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123041. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123042. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123043. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123044. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123045. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123046. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123047. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123048. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123049. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123050. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123051. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123052. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123053. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123054. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123055. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123056. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123057. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123058. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123059. 14,
  123060. };
  123061. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123062. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123063. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123064. };
  123065. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123066. 15, 13, 11, 9, 7, 5, 3, 1,
  123067. 0, 2, 4, 6, 8, 10, 12, 14,
  123068. 16,
  123069. };
  123070. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123071. _vq_quantthresh__44c0_sm_p5_0,
  123072. _vq_quantmap__44c0_sm_p5_0,
  123073. 17,
  123074. 17
  123075. };
  123076. static static_codebook _44c0_sm_p5_0 = {
  123077. 2, 289,
  123078. _vq_lengthlist__44c0_sm_p5_0,
  123079. 1, -529530880, 1611661312, 5, 0,
  123080. _vq_quantlist__44c0_sm_p5_0,
  123081. NULL,
  123082. &_vq_auxt__44c0_sm_p5_0,
  123083. NULL,
  123084. 0
  123085. };
  123086. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123087. 1,
  123088. 0,
  123089. 2,
  123090. };
  123091. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123092. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123093. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123094. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123095. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123096. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123097. 11,
  123098. };
  123099. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123100. -5.5, 5.5,
  123101. };
  123102. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123103. 1, 0, 2,
  123104. };
  123105. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123106. _vq_quantthresh__44c0_sm_p6_0,
  123107. _vq_quantmap__44c0_sm_p6_0,
  123108. 3,
  123109. 3
  123110. };
  123111. static static_codebook _44c0_sm_p6_0 = {
  123112. 4, 81,
  123113. _vq_lengthlist__44c0_sm_p6_0,
  123114. 1, -529137664, 1618345984, 2, 0,
  123115. _vq_quantlist__44c0_sm_p6_0,
  123116. NULL,
  123117. &_vq_auxt__44c0_sm_p6_0,
  123118. NULL,
  123119. 0
  123120. };
  123121. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123122. 5,
  123123. 4,
  123124. 6,
  123125. 3,
  123126. 7,
  123127. 2,
  123128. 8,
  123129. 1,
  123130. 9,
  123131. 0,
  123132. 10,
  123133. };
  123134. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123135. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123136. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123137. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123138. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123139. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123140. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123141. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123142. 10,10,10, 8, 8, 8, 8, 8, 8,
  123143. };
  123144. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123145. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123146. 3.5, 4.5,
  123147. };
  123148. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123149. 9, 7, 5, 3, 1, 0, 2, 4,
  123150. 6, 8, 10,
  123151. };
  123152. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123153. _vq_quantthresh__44c0_sm_p6_1,
  123154. _vq_quantmap__44c0_sm_p6_1,
  123155. 11,
  123156. 11
  123157. };
  123158. static static_codebook _44c0_sm_p6_1 = {
  123159. 2, 121,
  123160. _vq_lengthlist__44c0_sm_p6_1,
  123161. 1, -531365888, 1611661312, 4, 0,
  123162. _vq_quantlist__44c0_sm_p6_1,
  123163. NULL,
  123164. &_vq_auxt__44c0_sm_p6_1,
  123165. NULL,
  123166. 0
  123167. };
  123168. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123169. 6,
  123170. 5,
  123171. 7,
  123172. 4,
  123173. 8,
  123174. 3,
  123175. 9,
  123176. 2,
  123177. 10,
  123178. 1,
  123179. 11,
  123180. 0,
  123181. 12,
  123182. };
  123183. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123184. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123185. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123186. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123187. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123188. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123189. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123190. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123191. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123192. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123193. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123194. 0,12,12,11,11,13,12,14,14,
  123195. };
  123196. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123197. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123198. 12.5, 17.5, 22.5, 27.5,
  123199. };
  123200. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123201. 11, 9, 7, 5, 3, 1, 0, 2,
  123202. 4, 6, 8, 10, 12,
  123203. };
  123204. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123205. _vq_quantthresh__44c0_sm_p7_0,
  123206. _vq_quantmap__44c0_sm_p7_0,
  123207. 13,
  123208. 13
  123209. };
  123210. static static_codebook _44c0_sm_p7_0 = {
  123211. 2, 169,
  123212. _vq_lengthlist__44c0_sm_p7_0,
  123213. 1, -526516224, 1616117760, 4, 0,
  123214. _vq_quantlist__44c0_sm_p7_0,
  123215. NULL,
  123216. &_vq_auxt__44c0_sm_p7_0,
  123217. NULL,
  123218. 0
  123219. };
  123220. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123221. 2,
  123222. 1,
  123223. 3,
  123224. 0,
  123225. 4,
  123226. };
  123227. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123228. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123229. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123230. };
  123231. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123232. -1.5, -0.5, 0.5, 1.5,
  123233. };
  123234. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123235. 3, 1, 0, 2, 4,
  123236. };
  123237. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123238. _vq_quantthresh__44c0_sm_p7_1,
  123239. _vq_quantmap__44c0_sm_p7_1,
  123240. 5,
  123241. 5
  123242. };
  123243. static static_codebook _44c0_sm_p7_1 = {
  123244. 2, 25,
  123245. _vq_lengthlist__44c0_sm_p7_1,
  123246. 1, -533725184, 1611661312, 3, 0,
  123247. _vq_quantlist__44c0_sm_p7_1,
  123248. NULL,
  123249. &_vq_auxt__44c0_sm_p7_1,
  123250. NULL,
  123251. 0
  123252. };
  123253. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123254. 4,
  123255. 3,
  123256. 5,
  123257. 2,
  123258. 6,
  123259. 1,
  123260. 7,
  123261. 0,
  123262. 8,
  123263. };
  123264. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123265. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123266. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123267. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123268. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123269. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123270. 12,
  123271. };
  123272. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123273. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123274. };
  123275. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123276. 7, 5, 3, 1, 0, 2, 4, 6,
  123277. 8,
  123278. };
  123279. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123280. _vq_quantthresh__44c0_sm_p8_0,
  123281. _vq_quantmap__44c0_sm_p8_0,
  123282. 9,
  123283. 9
  123284. };
  123285. static static_codebook _44c0_sm_p8_0 = {
  123286. 2, 81,
  123287. _vq_lengthlist__44c0_sm_p8_0,
  123288. 1, -516186112, 1627103232, 4, 0,
  123289. _vq_quantlist__44c0_sm_p8_0,
  123290. NULL,
  123291. &_vq_auxt__44c0_sm_p8_0,
  123292. NULL,
  123293. 0
  123294. };
  123295. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123296. 6,
  123297. 5,
  123298. 7,
  123299. 4,
  123300. 8,
  123301. 3,
  123302. 9,
  123303. 2,
  123304. 10,
  123305. 1,
  123306. 11,
  123307. 0,
  123308. 12,
  123309. };
  123310. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123311. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123312. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123313. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123314. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123315. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123316. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123317. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123318. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123319. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123320. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123321. 20,13,13,12,12,16,13,15,13,
  123322. };
  123323. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123324. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123325. 42.5, 59.5, 76.5, 93.5,
  123326. };
  123327. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123328. 11, 9, 7, 5, 3, 1, 0, 2,
  123329. 4, 6, 8, 10, 12,
  123330. };
  123331. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123332. _vq_quantthresh__44c0_sm_p8_1,
  123333. _vq_quantmap__44c0_sm_p8_1,
  123334. 13,
  123335. 13
  123336. };
  123337. static static_codebook _44c0_sm_p8_1 = {
  123338. 2, 169,
  123339. _vq_lengthlist__44c0_sm_p8_1,
  123340. 1, -522616832, 1620115456, 4, 0,
  123341. _vq_quantlist__44c0_sm_p8_1,
  123342. NULL,
  123343. &_vq_auxt__44c0_sm_p8_1,
  123344. NULL,
  123345. 0
  123346. };
  123347. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123348. 8,
  123349. 7,
  123350. 9,
  123351. 6,
  123352. 10,
  123353. 5,
  123354. 11,
  123355. 4,
  123356. 12,
  123357. 3,
  123358. 13,
  123359. 2,
  123360. 14,
  123361. 1,
  123362. 15,
  123363. 0,
  123364. 16,
  123365. };
  123366. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123367. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123368. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123369. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123370. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123371. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123372. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123373. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123374. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123375. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123376. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123377. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123378. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123379. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123380. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123381. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123382. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123383. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123384. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123385. 9,
  123386. };
  123387. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123388. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123389. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123390. };
  123391. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123392. 15, 13, 11, 9, 7, 5, 3, 1,
  123393. 0, 2, 4, 6, 8, 10, 12, 14,
  123394. 16,
  123395. };
  123396. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123397. _vq_quantthresh__44c0_sm_p8_2,
  123398. _vq_quantmap__44c0_sm_p8_2,
  123399. 17,
  123400. 17
  123401. };
  123402. static static_codebook _44c0_sm_p8_2 = {
  123403. 2, 289,
  123404. _vq_lengthlist__44c0_sm_p8_2,
  123405. 1, -529530880, 1611661312, 5, 0,
  123406. _vq_quantlist__44c0_sm_p8_2,
  123407. NULL,
  123408. &_vq_auxt__44c0_sm_p8_2,
  123409. NULL,
  123410. 0
  123411. };
  123412. static long _huff_lengthlist__44c0_sm_short[] = {
  123413. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123414. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123415. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123416. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123417. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123418. 12,
  123419. };
  123420. static static_codebook _huff_book__44c0_sm_short = {
  123421. 2, 81,
  123422. _huff_lengthlist__44c0_sm_short,
  123423. 0, 0, 0, 0, 0,
  123424. NULL,
  123425. NULL,
  123426. NULL,
  123427. NULL,
  123428. 0
  123429. };
  123430. static long _huff_lengthlist__44c1_s_long[] = {
  123431. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123432. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123433. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123434. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123435. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123436. 11,
  123437. };
  123438. static static_codebook _huff_book__44c1_s_long = {
  123439. 2, 81,
  123440. _huff_lengthlist__44c1_s_long,
  123441. 0, 0, 0, 0, 0,
  123442. NULL,
  123443. NULL,
  123444. NULL,
  123445. NULL,
  123446. 0
  123447. };
  123448. static long _vq_quantlist__44c1_s_p1_0[] = {
  123449. 1,
  123450. 0,
  123451. 2,
  123452. };
  123453. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123454. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123455. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123459. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123460. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123464. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123465. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123500. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123505. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  123510. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123527. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123532. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123537. 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123546. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123551. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123556. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  123572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123573. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  123577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  123865. };
  123866. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123867. -0.5, 0.5,
  123868. };
  123869. static long _vq_quantmap__44c1_s_p1_0[] = {
  123870. 1, 0, 2,
  123871. };
  123872. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123873. _vq_quantthresh__44c1_s_p1_0,
  123874. _vq_quantmap__44c1_s_p1_0,
  123875. 3,
  123876. 3
  123877. };
  123878. static static_codebook _44c1_s_p1_0 = {
  123879. 8, 6561,
  123880. _vq_lengthlist__44c1_s_p1_0,
  123881. 1, -535822336, 1611661312, 2, 0,
  123882. _vq_quantlist__44c1_s_p1_0,
  123883. NULL,
  123884. &_vq_auxt__44c1_s_p1_0,
  123885. NULL,
  123886. 0
  123887. };
  123888. static long _vq_quantlist__44c1_s_p2_0[] = {
  123889. 2,
  123890. 1,
  123891. 3,
  123892. 0,
  123893. 4,
  123894. };
  123895. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123896. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123899. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123902. 0, 0, 0, 0, 6, 6, 6, 8, 8, 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,
  123936. };
  123937. static float _vq_quantthresh__44c1_s_p2_0[] = {
  123938. -1.5, -0.5, 0.5, 1.5,
  123939. };
  123940. static long _vq_quantmap__44c1_s_p2_0[] = {
  123941. 3, 1, 0, 2, 4,
  123942. };
  123943. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  123944. _vq_quantthresh__44c1_s_p2_0,
  123945. _vq_quantmap__44c1_s_p2_0,
  123946. 5,
  123947. 5
  123948. };
  123949. static static_codebook _44c1_s_p2_0 = {
  123950. 4, 625,
  123951. _vq_lengthlist__44c1_s_p2_0,
  123952. 1, -533725184, 1611661312, 3, 0,
  123953. _vq_quantlist__44c1_s_p2_0,
  123954. NULL,
  123955. &_vq_auxt__44c1_s_p2_0,
  123956. NULL,
  123957. 0
  123958. };
  123959. static long _vq_quantlist__44c1_s_p3_0[] = {
  123960. 4,
  123961. 3,
  123962. 5,
  123963. 2,
  123964. 6,
  123965. 1,
  123966. 7,
  123967. 0,
  123968. 8,
  123969. };
  123970. static long _vq_lengthlist__44c1_s_p3_0[] = {
  123971. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  123972. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  123973. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  123974. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  123975. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123976. 0,
  123977. };
  123978. static float _vq_quantthresh__44c1_s_p3_0[] = {
  123979. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123980. };
  123981. static long _vq_quantmap__44c1_s_p3_0[] = {
  123982. 7, 5, 3, 1, 0, 2, 4, 6,
  123983. 8,
  123984. };
  123985. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  123986. _vq_quantthresh__44c1_s_p3_0,
  123987. _vq_quantmap__44c1_s_p3_0,
  123988. 9,
  123989. 9
  123990. };
  123991. static static_codebook _44c1_s_p3_0 = {
  123992. 2, 81,
  123993. _vq_lengthlist__44c1_s_p3_0,
  123994. 1, -531628032, 1611661312, 4, 0,
  123995. _vq_quantlist__44c1_s_p3_0,
  123996. NULL,
  123997. &_vq_auxt__44c1_s_p3_0,
  123998. NULL,
  123999. 0
  124000. };
  124001. static long _vq_quantlist__44c1_s_p4_0[] = {
  124002. 4,
  124003. 3,
  124004. 5,
  124005. 2,
  124006. 6,
  124007. 1,
  124008. 7,
  124009. 0,
  124010. 8,
  124011. };
  124012. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124013. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124014. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124015. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124016. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124017. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124018. 11,
  124019. };
  124020. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124021. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124022. };
  124023. static long _vq_quantmap__44c1_s_p4_0[] = {
  124024. 7, 5, 3, 1, 0, 2, 4, 6,
  124025. 8,
  124026. };
  124027. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124028. _vq_quantthresh__44c1_s_p4_0,
  124029. _vq_quantmap__44c1_s_p4_0,
  124030. 9,
  124031. 9
  124032. };
  124033. static static_codebook _44c1_s_p4_0 = {
  124034. 2, 81,
  124035. _vq_lengthlist__44c1_s_p4_0,
  124036. 1, -531628032, 1611661312, 4, 0,
  124037. _vq_quantlist__44c1_s_p4_0,
  124038. NULL,
  124039. &_vq_auxt__44c1_s_p4_0,
  124040. NULL,
  124041. 0
  124042. };
  124043. static long _vq_quantlist__44c1_s_p5_0[] = {
  124044. 8,
  124045. 7,
  124046. 9,
  124047. 6,
  124048. 10,
  124049. 5,
  124050. 11,
  124051. 4,
  124052. 12,
  124053. 3,
  124054. 13,
  124055. 2,
  124056. 14,
  124057. 1,
  124058. 15,
  124059. 0,
  124060. 16,
  124061. };
  124062. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124063. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124064. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124065. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124066. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124067. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124068. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124069. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124070. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124071. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124072. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124073. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124074. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124075. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124076. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124077. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124078. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124079. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124080. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124081. 14,
  124082. };
  124083. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124084. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124085. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124086. };
  124087. static long _vq_quantmap__44c1_s_p5_0[] = {
  124088. 15, 13, 11, 9, 7, 5, 3, 1,
  124089. 0, 2, 4, 6, 8, 10, 12, 14,
  124090. 16,
  124091. };
  124092. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124093. _vq_quantthresh__44c1_s_p5_0,
  124094. _vq_quantmap__44c1_s_p5_0,
  124095. 17,
  124096. 17
  124097. };
  124098. static static_codebook _44c1_s_p5_0 = {
  124099. 2, 289,
  124100. _vq_lengthlist__44c1_s_p5_0,
  124101. 1, -529530880, 1611661312, 5, 0,
  124102. _vq_quantlist__44c1_s_p5_0,
  124103. NULL,
  124104. &_vq_auxt__44c1_s_p5_0,
  124105. NULL,
  124106. 0
  124107. };
  124108. static long _vq_quantlist__44c1_s_p6_0[] = {
  124109. 1,
  124110. 0,
  124111. 2,
  124112. };
  124113. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124114. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124115. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124116. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124117. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124118. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124119. 11,
  124120. };
  124121. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124122. -5.5, 5.5,
  124123. };
  124124. static long _vq_quantmap__44c1_s_p6_0[] = {
  124125. 1, 0, 2,
  124126. };
  124127. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124128. _vq_quantthresh__44c1_s_p6_0,
  124129. _vq_quantmap__44c1_s_p6_0,
  124130. 3,
  124131. 3
  124132. };
  124133. static static_codebook _44c1_s_p6_0 = {
  124134. 4, 81,
  124135. _vq_lengthlist__44c1_s_p6_0,
  124136. 1, -529137664, 1618345984, 2, 0,
  124137. _vq_quantlist__44c1_s_p6_0,
  124138. NULL,
  124139. &_vq_auxt__44c1_s_p6_0,
  124140. NULL,
  124141. 0
  124142. };
  124143. static long _vq_quantlist__44c1_s_p6_1[] = {
  124144. 5,
  124145. 4,
  124146. 6,
  124147. 3,
  124148. 7,
  124149. 2,
  124150. 8,
  124151. 1,
  124152. 9,
  124153. 0,
  124154. 10,
  124155. };
  124156. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124157. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124158. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124159. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124160. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124161. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124162. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124163. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124164. 10,10,10, 8, 8, 8, 8, 8, 8,
  124165. };
  124166. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124167. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124168. 3.5, 4.5,
  124169. };
  124170. static long _vq_quantmap__44c1_s_p6_1[] = {
  124171. 9, 7, 5, 3, 1, 0, 2, 4,
  124172. 6, 8, 10,
  124173. };
  124174. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124175. _vq_quantthresh__44c1_s_p6_1,
  124176. _vq_quantmap__44c1_s_p6_1,
  124177. 11,
  124178. 11
  124179. };
  124180. static static_codebook _44c1_s_p6_1 = {
  124181. 2, 121,
  124182. _vq_lengthlist__44c1_s_p6_1,
  124183. 1, -531365888, 1611661312, 4, 0,
  124184. _vq_quantlist__44c1_s_p6_1,
  124185. NULL,
  124186. &_vq_auxt__44c1_s_p6_1,
  124187. NULL,
  124188. 0
  124189. };
  124190. static long _vq_quantlist__44c1_s_p7_0[] = {
  124191. 6,
  124192. 5,
  124193. 7,
  124194. 4,
  124195. 8,
  124196. 3,
  124197. 9,
  124198. 2,
  124199. 10,
  124200. 1,
  124201. 11,
  124202. 0,
  124203. 12,
  124204. };
  124205. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124206. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124207. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124208. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124209. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124210. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124211. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124212. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124213. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124214. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124215. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124216. 0,12,11,11,11,13,10,14,13,
  124217. };
  124218. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124219. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124220. 12.5, 17.5, 22.5, 27.5,
  124221. };
  124222. static long _vq_quantmap__44c1_s_p7_0[] = {
  124223. 11, 9, 7, 5, 3, 1, 0, 2,
  124224. 4, 6, 8, 10, 12,
  124225. };
  124226. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124227. _vq_quantthresh__44c1_s_p7_0,
  124228. _vq_quantmap__44c1_s_p7_0,
  124229. 13,
  124230. 13
  124231. };
  124232. static static_codebook _44c1_s_p7_0 = {
  124233. 2, 169,
  124234. _vq_lengthlist__44c1_s_p7_0,
  124235. 1, -526516224, 1616117760, 4, 0,
  124236. _vq_quantlist__44c1_s_p7_0,
  124237. NULL,
  124238. &_vq_auxt__44c1_s_p7_0,
  124239. NULL,
  124240. 0
  124241. };
  124242. static long _vq_quantlist__44c1_s_p7_1[] = {
  124243. 2,
  124244. 1,
  124245. 3,
  124246. 0,
  124247. 4,
  124248. };
  124249. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124250. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124251. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124252. };
  124253. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124254. -1.5, -0.5, 0.5, 1.5,
  124255. };
  124256. static long _vq_quantmap__44c1_s_p7_1[] = {
  124257. 3, 1, 0, 2, 4,
  124258. };
  124259. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124260. _vq_quantthresh__44c1_s_p7_1,
  124261. _vq_quantmap__44c1_s_p7_1,
  124262. 5,
  124263. 5
  124264. };
  124265. static static_codebook _44c1_s_p7_1 = {
  124266. 2, 25,
  124267. _vq_lengthlist__44c1_s_p7_1,
  124268. 1, -533725184, 1611661312, 3, 0,
  124269. _vq_quantlist__44c1_s_p7_1,
  124270. NULL,
  124271. &_vq_auxt__44c1_s_p7_1,
  124272. NULL,
  124273. 0
  124274. };
  124275. static long _vq_quantlist__44c1_s_p8_0[] = {
  124276. 6,
  124277. 5,
  124278. 7,
  124279. 4,
  124280. 8,
  124281. 3,
  124282. 9,
  124283. 2,
  124284. 10,
  124285. 1,
  124286. 11,
  124287. 0,
  124288. 12,
  124289. };
  124290. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124291. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124292. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124293. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124294. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124295. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124296. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124297. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124298. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124299. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124300. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124301. 10,10,10,10,10,10,10,10,10,
  124302. };
  124303. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124304. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124305. 552.5, 773.5, 994.5, 1215.5,
  124306. };
  124307. static long _vq_quantmap__44c1_s_p8_0[] = {
  124308. 11, 9, 7, 5, 3, 1, 0, 2,
  124309. 4, 6, 8, 10, 12,
  124310. };
  124311. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124312. _vq_quantthresh__44c1_s_p8_0,
  124313. _vq_quantmap__44c1_s_p8_0,
  124314. 13,
  124315. 13
  124316. };
  124317. static static_codebook _44c1_s_p8_0 = {
  124318. 2, 169,
  124319. _vq_lengthlist__44c1_s_p8_0,
  124320. 1, -514541568, 1627103232, 4, 0,
  124321. _vq_quantlist__44c1_s_p8_0,
  124322. NULL,
  124323. &_vq_auxt__44c1_s_p8_0,
  124324. NULL,
  124325. 0
  124326. };
  124327. static long _vq_quantlist__44c1_s_p8_1[] = {
  124328. 6,
  124329. 5,
  124330. 7,
  124331. 4,
  124332. 8,
  124333. 3,
  124334. 9,
  124335. 2,
  124336. 10,
  124337. 1,
  124338. 11,
  124339. 0,
  124340. 12,
  124341. };
  124342. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124343. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124344. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124345. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124346. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124347. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124348. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124349. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124350. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124351. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124352. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124353. 16,13,12,12,11,14,12,15,13,
  124354. };
  124355. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124356. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124357. 42.5, 59.5, 76.5, 93.5,
  124358. };
  124359. static long _vq_quantmap__44c1_s_p8_1[] = {
  124360. 11, 9, 7, 5, 3, 1, 0, 2,
  124361. 4, 6, 8, 10, 12,
  124362. };
  124363. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124364. _vq_quantthresh__44c1_s_p8_1,
  124365. _vq_quantmap__44c1_s_p8_1,
  124366. 13,
  124367. 13
  124368. };
  124369. static static_codebook _44c1_s_p8_1 = {
  124370. 2, 169,
  124371. _vq_lengthlist__44c1_s_p8_1,
  124372. 1, -522616832, 1620115456, 4, 0,
  124373. _vq_quantlist__44c1_s_p8_1,
  124374. NULL,
  124375. &_vq_auxt__44c1_s_p8_1,
  124376. NULL,
  124377. 0
  124378. };
  124379. static long _vq_quantlist__44c1_s_p8_2[] = {
  124380. 8,
  124381. 7,
  124382. 9,
  124383. 6,
  124384. 10,
  124385. 5,
  124386. 11,
  124387. 4,
  124388. 12,
  124389. 3,
  124390. 13,
  124391. 2,
  124392. 14,
  124393. 1,
  124394. 15,
  124395. 0,
  124396. 16,
  124397. };
  124398. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124399. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124400. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124401. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124402. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124403. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124404. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124405. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124406. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124407. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124408. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124409. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124410. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124411. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124412. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124413. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124414. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124415. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124416. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124417. 9,
  124418. };
  124419. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124420. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124421. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124422. };
  124423. static long _vq_quantmap__44c1_s_p8_2[] = {
  124424. 15, 13, 11, 9, 7, 5, 3, 1,
  124425. 0, 2, 4, 6, 8, 10, 12, 14,
  124426. 16,
  124427. };
  124428. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124429. _vq_quantthresh__44c1_s_p8_2,
  124430. _vq_quantmap__44c1_s_p8_2,
  124431. 17,
  124432. 17
  124433. };
  124434. static static_codebook _44c1_s_p8_2 = {
  124435. 2, 289,
  124436. _vq_lengthlist__44c1_s_p8_2,
  124437. 1, -529530880, 1611661312, 5, 0,
  124438. _vq_quantlist__44c1_s_p8_2,
  124439. NULL,
  124440. &_vq_auxt__44c1_s_p8_2,
  124441. NULL,
  124442. 0
  124443. };
  124444. static long _huff_lengthlist__44c1_s_short[] = {
  124445. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124446. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124447. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124448. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124449. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124450. 11,
  124451. };
  124452. static static_codebook _huff_book__44c1_s_short = {
  124453. 2, 81,
  124454. _huff_lengthlist__44c1_s_short,
  124455. 0, 0, 0, 0, 0,
  124456. NULL,
  124457. NULL,
  124458. NULL,
  124459. NULL,
  124460. 0
  124461. };
  124462. static long _huff_lengthlist__44c1_sm_long[] = {
  124463. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124464. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124465. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124466. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124467. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124468. 11,
  124469. };
  124470. static static_codebook _huff_book__44c1_sm_long = {
  124471. 2, 81,
  124472. _huff_lengthlist__44c1_sm_long,
  124473. 0, 0, 0, 0, 0,
  124474. NULL,
  124475. NULL,
  124476. NULL,
  124477. NULL,
  124478. 0
  124479. };
  124480. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124481. 1,
  124482. 0,
  124483. 2,
  124484. };
  124485. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124486. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124487. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124491. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124492. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124496. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124497. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124532. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124537. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  124542. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124559. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124564. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124569. 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124578. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124583. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124588. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  124604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124605. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  124609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  124897. };
  124898. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124899. -0.5, 0.5,
  124900. };
  124901. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124902. 1, 0, 2,
  124903. };
  124904. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124905. _vq_quantthresh__44c1_sm_p1_0,
  124906. _vq_quantmap__44c1_sm_p1_0,
  124907. 3,
  124908. 3
  124909. };
  124910. static static_codebook _44c1_sm_p1_0 = {
  124911. 8, 6561,
  124912. _vq_lengthlist__44c1_sm_p1_0,
  124913. 1, -535822336, 1611661312, 2, 0,
  124914. _vq_quantlist__44c1_sm_p1_0,
  124915. NULL,
  124916. &_vq_auxt__44c1_sm_p1_0,
  124917. NULL,
  124918. 0
  124919. };
  124920. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124921. 2,
  124922. 1,
  124923. 3,
  124924. 0,
  124925. 4,
  124926. };
  124927. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  124928. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124931. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  124933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124934. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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,
  124968. };
  124969. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  124970. -1.5, -0.5, 0.5, 1.5,
  124971. };
  124972. static long _vq_quantmap__44c1_sm_p2_0[] = {
  124973. 3, 1, 0, 2, 4,
  124974. };
  124975. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  124976. _vq_quantthresh__44c1_sm_p2_0,
  124977. _vq_quantmap__44c1_sm_p2_0,
  124978. 5,
  124979. 5
  124980. };
  124981. static static_codebook _44c1_sm_p2_0 = {
  124982. 4, 625,
  124983. _vq_lengthlist__44c1_sm_p2_0,
  124984. 1, -533725184, 1611661312, 3, 0,
  124985. _vq_quantlist__44c1_sm_p2_0,
  124986. NULL,
  124987. &_vq_auxt__44c1_sm_p2_0,
  124988. NULL,
  124989. 0
  124990. };
  124991. static long _vq_quantlist__44c1_sm_p3_0[] = {
  124992. 4,
  124993. 3,
  124994. 5,
  124995. 2,
  124996. 6,
  124997. 1,
  124998. 7,
  124999. 0,
  125000. 8,
  125001. };
  125002. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125003. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125004. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125005. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125006. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125007. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125008. 0,
  125009. };
  125010. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125011. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125012. };
  125013. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125014. 7, 5, 3, 1, 0, 2, 4, 6,
  125015. 8,
  125016. };
  125017. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125018. _vq_quantthresh__44c1_sm_p3_0,
  125019. _vq_quantmap__44c1_sm_p3_0,
  125020. 9,
  125021. 9
  125022. };
  125023. static static_codebook _44c1_sm_p3_0 = {
  125024. 2, 81,
  125025. _vq_lengthlist__44c1_sm_p3_0,
  125026. 1, -531628032, 1611661312, 4, 0,
  125027. _vq_quantlist__44c1_sm_p3_0,
  125028. NULL,
  125029. &_vq_auxt__44c1_sm_p3_0,
  125030. NULL,
  125031. 0
  125032. };
  125033. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125034. 4,
  125035. 3,
  125036. 5,
  125037. 2,
  125038. 6,
  125039. 1,
  125040. 7,
  125041. 0,
  125042. 8,
  125043. };
  125044. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125045. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125046. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125047. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125048. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125049. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125050. 11,
  125051. };
  125052. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125053. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125054. };
  125055. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125056. 7, 5, 3, 1, 0, 2, 4, 6,
  125057. 8,
  125058. };
  125059. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125060. _vq_quantthresh__44c1_sm_p4_0,
  125061. _vq_quantmap__44c1_sm_p4_0,
  125062. 9,
  125063. 9
  125064. };
  125065. static static_codebook _44c1_sm_p4_0 = {
  125066. 2, 81,
  125067. _vq_lengthlist__44c1_sm_p4_0,
  125068. 1, -531628032, 1611661312, 4, 0,
  125069. _vq_quantlist__44c1_sm_p4_0,
  125070. NULL,
  125071. &_vq_auxt__44c1_sm_p4_0,
  125072. NULL,
  125073. 0
  125074. };
  125075. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125076. 8,
  125077. 7,
  125078. 9,
  125079. 6,
  125080. 10,
  125081. 5,
  125082. 11,
  125083. 4,
  125084. 12,
  125085. 3,
  125086. 13,
  125087. 2,
  125088. 14,
  125089. 1,
  125090. 15,
  125091. 0,
  125092. 16,
  125093. };
  125094. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125095. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125096. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125097. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125098. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125099. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125100. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125101. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125102. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125103. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125104. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125105. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125106. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125107. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125108. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125109. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125110. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125111. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125112. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125113. 14,
  125114. };
  125115. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125116. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125117. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125118. };
  125119. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125120. 15, 13, 11, 9, 7, 5, 3, 1,
  125121. 0, 2, 4, 6, 8, 10, 12, 14,
  125122. 16,
  125123. };
  125124. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125125. _vq_quantthresh__44c1_sm_p5_0,
  125126. _vq_quantmap__44c1_sm_p5_0,
  125127. 17,
  125128. 17
  125129. };
  125130. static static_codebook _44c1_sm_p5_0 = {
  125131. 2, 289,
  125132. _vq_lengthlist__44c1_sm_p5_0,
  125133. 1, -529530880, 1611661312, 5, 0,
  125134. _vq_quantlist__44c1_sm_p5_0,
  125135. NULL,
  125136. &_vq_auxt__44c1_sm_p5_0,
  125137. NULL,
  125138. 0
  125139. };
  125140. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125141. 1,
  125142. 0,
  125143. 2,
  125144. };
  125145. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125146. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125147. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125148. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125149. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125150. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125151. 11,
  125152. };
  125153. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125154. -5.5, 5.5,
  125155. };
  125156. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125157. 1, 0, 2,
  125158. };
  125159. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125160. _vq_quantthresh__44c1_sm_p6_0,
  125161. _vq_quantmap__44c1_sm_p6_0,
  125162. 3,
  125163. 3
  125164. };
  125165. static static_codebook _44c1_sm_p6_0 = {
  125166. 4, 81,
  125167. _vq_lengthlist__44c1_sm_p6_0,
  125168. 1, -529137664, 1618345984, 2, 0,
  125169. _vq_quantlist__44c1_sm_p6_0,
  125170. NULL,
  125171. &_vq_auxt__44c1_sm_p6_0,
  125172. NULL,
  125173. 0
  125174. };
  125175. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125176. 5,
  125177. 4,
  125178. 6,
  125179. 3,
  125180. 7,
  125181. 2,
  125182. 8,
  125183. 1,
  125184. 9,
  125185. 0,
  125186. 10,
  125187. };
  125188. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125189. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125190. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125191. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125192. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125193. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125194. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125195. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125196. 10,10,10, 8, 8, 8, 8, 8, 8,
  125197. };
  125198. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125199. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125200. 3.5, 4.5,
  125201. };
  125202. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125203. 9, 7, 5, 3, 1, 0, 2, 4,
  125204. 6, 8, 10,
  125205. };
  125206. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125207. _vq_quantthresh__44c1_sm_p6_1,
  125208. _vq_quantmap__44c1_sm_p6_1,
  125209. 11,
  125210. 11
  125211. };
  125212. static static_codebook _44c1_sm_p6_1 = {
  125213. 2, 121,
  125214. _vq_lengthlist__44c1_sm_p6_1,
  125215. 1, -531365888, 1611661312, 4, 0,
  125216. _vq_quantlist__44c1_sm_p6_1,
  125217. NULL,
  125218. &_vq_auxt__44c1_sm_p6_1,
  125219. NULL,
  125220. 0
  125221. };
  125222. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125223. 6,
  125224. 5,
  125225. 7,
  125226. 4,
  125227. 8,
  125228. 3,
  125229. 9,
  125230. 2,
  125231. 10,
  125232. 1,
  125233. 11,
  125234. 0,
  125235. 12,
  125236. };
  125237. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125238. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125239. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125240. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125241. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125242. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125243. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125244. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125245. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125246. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125247. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125248. 0,12,12,11,11,13,12,14,13,
  125249. };
  125250. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125251. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125252. 12.5, 17.5, 22.5, 27.5,
  125253. };
  125254. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125255. 11, 9, 7, 5, 3, 1, 0, 2,
  125256. 4, 6, 8, 10, 12,
  125257. };
  125258. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125259. _vq_quantthresh__44c1_sm_p7_0,
  125260. _vq_quantmap__44c1_sm_p7_0,
  125261. 13,
  125262. 13
  125263. };
  125264. static static_codebook _44c1_sm_p7_0 = {
  125265. 2, 169,
  125266. _vq_lengthlist__44c1_sm_p7_0,
  125267. 1, -526516224, 1616117760, 4, 0,
  125268. _vq_quantlist__44c1_sm_p7_0,
  125269. NULL,
  125270. &_vq_auxt__44c1_sm_p7_0,
  125271. NULL,
  125272. 0
  125273. };
  125274. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125275. 2,
  125276. 1,
  125277. 3,
  125278. 0,
  125279. 4,
  125280. };
  125281. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125282. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125283. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125284. };
  125285. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125286. -1.5, -0.5, 0.5, 1.5,
  125287. };
  125288. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125289. 3, 1, 0, 2, 4,
  125290. };
  125291. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125292. _vq_quantthresh__44c1_sm_p7_1,
  125293. _vq_quantmap__44c1_sm_p7_1,
  125294. 5,
  125295. 5
  125296. };
  125297. static static_codebook _44c1_sm_p7_1 = {
  125298. 2, 25,
  125299. _vq_lengthlist__44c1_sm_p7_1,
  125300. 1, -533725184, 1611661312, 3, 0,
  125301. _vq_quantlist__44c1_sm_p7_1,
  125302. NULL,
  125303. &_vq_auxt__44c1_sm_p7_1,
  125304. NULL,
  125305. 0
  125306. };
  125307. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125308. 6,
  125309. 5,
  125310. 7,
  125311. 4,
  125312. 8,
  125313. 3,
  125314. 9,
  125315. 2,
  125316. 10,
  125317. 1,
  125318. 11,
  125319. 0,
  125320. 12,
  125321. };
  125322. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125323. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125324. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125325. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125326. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125327. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125328. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125329. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125330. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125331. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125332. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125333. 13,13,13,13,13,13,13,13,13,
  125334. };
  125335. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125336. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125337. 552.5, 773.5, 994.5, 1215.5,
  125338. };
  125339. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125340. 11, 9, 7, 5, 3, 1, 0, 2,
  125341. 4, 6, 8, 10, 12,
  125342. };
  125343. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125344. _vq_quantthresh__44c1_sm_p8_0,
  125345. _vq_quantmap__44c1_sm_p8_0,
  125346. 13,
  125347. 13
  125348. };
  125349. static static_codebook _44c1_sm_p8_0 = {
  125350. 2, 169,
  125351. _vq_lengthlist__44c1_sm_p8_0,
  125352. 1, -514541568, 1627103232, 4, 0,
  125353. _vq_quantlist__44c1_sm_p8_0,
  125354. NULL,
  125355. &_vq_auxt__44c1_sm_p8_0,
  125356. NULL,
  125357. 0
  125358. };
  125359. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125360. 6,
  125361. 5,
  125362. 7,
  125363. 4,
  125364. 8,
  125365. 3,
  125366. 9,
  125367. 2,
  125368. 10,
  125369. 1,
  125370. 11,
  125371. 0,
  125372. 12,
  125373. };
  125374. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125375. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125376. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125377. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125378. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125379. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125380. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125381. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125382. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125383. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125384. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125385. 20,13,12,12,12,14,12,14,13,
  125386. };
  125387. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125388. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125389. 42.5, 59.5, 76.5, 93.5,
  125390. };
  125391. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125392. 11, 9, 7, 5, 3, 1, 0, 2,
  125393. 4, 6, 8, 10, 12,
  125394. };
  125395. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125396. _vq_quantthresh__44c1_sm_p8_1,
  125397. _vq_quantmap__44c1_sm_p8_1,
  125398. 13,
  125399. 13
  125400. };
  125401. static static_codebook _44c1_sm_p8_1 = {
  125402. 2, 169,
  125403. _vq_lengthlist__44c1_sm_p8_1,
  125404. 1, -522616832, 1620115456, 4, 0,
  125405. _vq_quantlist__44c1_sm_p8_1,
  125406. NULL,
  125407. &_vq_auxt__44c1_sm_p8_1,
  125408. NULL,
  125409. 0
  125410. };
  125411. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125412. 8,
  125413. 7,
  125414. 9,
  125415. 6,
  125416. 10,
  125417. 5,
  125418. 11,
  125419. 4,
  125420. 12,
  125421. 3,
  125422. 13,
  125423. 2,
  125424. 14,
  125425. 1,
  125426. 15,
  125427. 0,
  125428. 16,
  125429. };
  125430. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125431. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125432. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125433. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125434. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125435. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125436. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125437. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125438. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125439. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125440. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125441. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125442. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125443. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125444. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125445. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125446. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125447. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125448. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125449. 9,
  125450. };
  125451. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125452. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125453. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125454. };
  125455. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125456. 15, 13, 11, 9, 7, 5, 3, 1,
  125457. 0, 2, 4, 6, 8, 10, 12, 14,
  125458. 16,
  125459. };
  125460. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125461. _vq_quantthresh__44c1_sm_p8_2,
  125462. _vq_quantmap__44c1_sm_p8_2,
  125463. 17,
  125464. 17
  125465. };
  125466. static static_codebook _44c1_sm_p8_2 = {
  125467. 2, 289,
  125468. _vq_lengthlist__44c1_sm_p8_2,
  125469. 1, -529530880, 1611661312, 5, 0,
  125470. _vq_quantlist__44c1_sm_p8_2,
  125471. NULL,
  125472. &_vq_auxt__44c1_sm_p8_2,
  125473. NULL,
  125474. 0
  125475. };
  125476. static long _huff_lengthlist__44c1_sm_short[] = {
  125477. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125478. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125479. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125480. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125481. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125482. 11,
  125483. };
  125484. static static_codebook _huff_book__44c1_sm_short = {
  125485. 2, 81,
  125486. _huff_lengthlist__44c1_sm_short,
  125487. 0, 0, 0, 0, 0,
  125488. NULL,
  125489. NULL,
  125490. NULL,
  125491. NULL,
  125492. 0
  125493. };
  125494. static long _huff_lengthlist__44cn1_s_long[] = {
  125495. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125496. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125497. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125498. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125499. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125500. 20,
  125501. };
  125502. static static_codebook _huff_book__44cn1_s_long = {
  125503. 2, 81,
  125504. _huff_lengthlist__44cn1_s_long,
  125505. 0, 0, 0, 0, 0,
  125506. NULL,
  125507. NULL,
  125508. NULL,
  125509. NULL,
  125510. 0
  125511. };
  125512. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125513. 1,
  125514. 0,
  125515. 2,
  125516. };
  125517. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125518. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125519. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125523. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125524. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125528. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125529. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125564. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  125565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  125569. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  125574. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125591. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125596. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125601. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125610. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125615. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125620. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  125636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125637. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  125641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  125929. };
  125930. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  125931. -0.5, 0.5,
  125932. };
  125933. static long _vq_quantmap__44cn1_s_p1_0[] = {
  125934. 1, 0, 2,
  125935. };
  125936. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  125937. _vq_quantthresh__44cn1_s_p1_0,
  125938. _vq_quantmap__44cn1_s_p1_0,
  125939. 3,
  125940. 3
  125941. };
  125942. static static_codebook _44cn1_s_p1_0 = {
  125943. 8, 6561,
  125944. _vq_lengthlist__44cn1_s_p1_0,
  125945. 1, -535822336, 1611661312, 2, 0,
  125946. _vq_quantlist__44cn1_s_p1_0,
  125947. NULL,
  125948. &_vq_auxt__44cn1_s_p1_0,
  125949. NULL,
  125950. 0
  125951. };
  125952. static long _vq_quantlist__44cn1_s_p2_0[] = {
  125953. 2,
  125954. 1,
  125955. 3,
  125956. 0,
  125957. 4,
  125958. };
  125959. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  125960. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  125962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125963. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  125965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125966. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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,
  126000. };
  126001. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126002. -1.5, -0.5, 0.5, 1.5,
  126003. };
  126004. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126005. 3, 1, 0, 2, 4,
  126006. };
  126007. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126008. _vq_quantthresh__44cn1_s_p2_0,
  126009. _vq_quantmap__44cn1_s_p2_0,
  126010. 5,
  126011. 5
  126012. };
  126013. static static_codebook _44cn1_s_p2_0 = {
  126014. 4, 625,
  126015. _vq_lengthlist__44cn1_s_p2_0,
  126016. 1, -533725184, 1611661312, 3, 0,
  126017. _vq_quantlist__44cn1_s_p2_0,
  126018. NULL,
  126019. &_vq_auxt__44cn1_s_p2_0,
  126020. NULL,
  126021. 0
  126022. };
  126023. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126024. 4,
  126025. 3,
  126026. 5,
  126027. 2,
  126028. 6,
  126029. 1,
  126030. 7,
  126031. 0,
  126032. 8,
  126033. };
  126034. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126035. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126036. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126037. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126038. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126039. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126040. 0,
  126041. };
  126042. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126043. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126044. };
  126045. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126046. 7, 5, 3, 1, 0, 2, 4, 6,
  126047. 8,
  126048. };
  126049. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126050. _vq_quantthresh__44cn1_s_p3_0,
  126051. _vq_quantmap__44cn1_s_p3_0,
  126052. 9,
  126053. 9
  126054. };
  126055. static static_codebook _44cn1_s_p3_0 = {
  126056. 2, 81,
  126057. _vq_lengthlist__44cn1_s_p3_0,
  126058. 1, -531628032, 1611661312, 4, 0,
  126059. _vq_quantlist__44cn1_s_p3_0,
  126060. NULL,
  126061. &_vq_auxt__44cn1_s_p3_0,
  126062. NULL,
  126063. 0
  126064. };
  126065. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126066. 4,
  126067. 3,
  126068. 5,
  126069. 2,
  126070. 6,
  126071. 1,
  126072. 7,
  126073. 0,
  126074. 8,
  126075. };
  126076. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126077. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126078. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126079. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126080. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126081. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126082. 11,
  126083. };
  126084. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126085. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126086. };
  126087. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126088. 7, 5, 3, 1, 0, 2, 4, 6,
  126089. 8,
  126090. };
  126091. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126092. _vq_quantthresh__44cn1_s_p4_0,
  126093. _vq_quantmap__44cn1_s_p4_0,
  126094. 9,
  126095. 9
  126096. };
  126097. static static_codebook _44cn1_s_p4_0 = {
  126098. 2, 81,
  126099. _vq_lengthlist__44cn1_s_p4_0,
  126100. 1, -531628032, 1611661312, 4, 0,
  126101. _vq_quantlist__44cn1_s_p4_0,
  126102. NULL,
  126103. &_vq_auxt__44cn1_s_p4_0,
  126104. NULL,
  126105. 0
  126106. };
  126107. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126108. 8,
  126109. 7,
  126110. 9,
  126111. 6,
  126112. 10,
  126113. 5,
  126114. 11,
  126115. 4,
  126116. 12,
  126117. 3,
  126118. 13,
  126119. 2,
  126120. 14,
  126121. 1,
  126122. 15,
  126123. 0,
  126124. 16,
  126125. };
  126126. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126127. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126128. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126129. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126130. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126131. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126132. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126133. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126134. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126135. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126136. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126137. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126138. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126139. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126140. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126141. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126142. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126143. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126144. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126145. 14,
  126146. };
  126147. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126148. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126149. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126150. };
  126151. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126152. 15, 13, 11, 9, 7, 5, 3, 1,
  126153. 0, 2, 4, 6, 8, 10, 12, 14,
  126154. 16,
  126155. };
  126156. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126157. _vq_quantthresh__44cn1_s_p5_0,
  126158. _vq_quantmap__44cn1_s_p5_0,
  126159. 17,
  126160. 17
  126161. };
  126162. static static_codebook _44cn1_s_p5_0 = {
  126163. 2, 289,
  126164. _vq_lengthlist__44cn1_s_p5_0,
  126165. 1, -529530880, 1611661312, 5, 0,
  126166. _vq_quantlist__44cn1_s_p5_0,
  126167. NULL,
  126168. &_vq_auxt__44cn1_s_p5_0,
  126169. NULL,
  126170. 0
  126171. };
  126172. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126173. 1,
  126174. 0,
  126175. 2,
  126176. };
  126177. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126178. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126179. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126180. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126181. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126182. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126183. 10,
  126184. };
  126185. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126186. -5.5, 5.5,
  126187. };
  126188. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126189. 1, 0, 2,
  126190. };
  126191. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126192. _vq_quantthresh__44cn1_s_p6_0,
  126193. _vq_quantmap__44cn1_s_p6_0,
  126194. 3,
  126195. 3
  126196. };
  126197. static static_codebook _44cn1_s_p6_0 = {
  126198. 4, 81,
  126199. _vq_lengthlist__44cn1_s_p6_0,
  126200. 1, -529137664, 1618345984, 2, 0,
  126201. _vq_quantlist__44cn1_s_p6_0,
  126202. NULL,
  126203. &_vq_auxt__44cn1_s_p6_0,
  126204. NULL,
  126205. 0
  126206. };
  126207. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126208. 5,
  126209. 4,
  126210. 6,
  126211. 3,
  126212. 7,
  126213. 2,
  126214. 8,
  126215. 1,
  126216. 9,
  126217. 0,
  126218. 10,
  126219. };
  126220. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126221. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126222. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126223. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126224. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126225. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126226. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126227. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126228. 10,10,10, 9, 9, 9, 9, 9, 9,
  126229. };
  126230. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126231. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126232. 3.5, 4.5,
  126233. };
  126234. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126235. 9, 7, 5, 3, 1, 0, 2, 4,
  126236. 6, 8, 10,
  126237. };
  126238. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126239. _vq_quantthresh__44cn1_s_p6_1,
  126240. _vq_quantmap__44cn1_s_p6_1,
  126241. 11,
  126242. 11
  126243. };
  126244. static static_codebook _44cn1_s_p6_1 = {
  126245. 2, 121,
  126246. _vq_lengthlist__44cn1_s_p6_1,
  126247. 1, -531365888, 1611661312, 4, 0,
  126248. _vq_quantlist__44cn1_s_p6_1,
  126249. NULL,
  126250. &_vq_auxt__44cn1_s_p6_1,
  126251. NULL,
  126252. 0
  126253. };
  126254. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126255. 6,
  126256. 5,
  126257. 7,
  126258. 4,
  126259. 8,
  126260. 3,
  126261. 9,
  126262. 2,
  126263. 10,
  126264. 1,
  126265. 11,
  126266. 0,
  126267. 12,
  126268. };
  126269. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126270. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126271. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126272. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126273. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126274. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126275. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126276. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126277. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126278. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126279. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126280. 0,13,13,12,12,13,13,13,14,
  126281. };
  126282. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126283. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126284. 12.5, 17.5, 22.5, 27.5,
  126285. };
  126286. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126287. 11, 9, 7, 5, 3, 1, 0, 2,
  126288. 4, 6, 8, 10, 12,
  126289. };
  126290. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126291. _vq_quantthresh__44cn1_s_p7_0,
  126292. _vq_quantmap__44cn1_s_p7_0,
  126293. 13,
  126294. 13
  126295. };
  126296. static static_codebook _44cn1_s_p7_0 = {
  126297. 2, 169,
  126298. _vq_lengthlist__44cn1_s_p7_0,
  126299. 1, -526516224, 1616117760, 4, 0,
  126300. _vq_quantlist__44cn1_s_p7_0,
  126301. NULL,
  126302. &_vq_auxt__44cn1_s_p7_0,
  126303. NULL,
  126304. 0
  126305. };
  126306. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126307. 2,
  126308. 1,
  126309. 3,
  126310. 0,
  126311. 4,
  126312. };
  126313. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126314. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126315. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126316. };
  126317. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126318. -1.5, -0.5, 0.5, 1.5,
  126319. };
  126320. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126321. 3, 1, 0, 2, 4,
  126322. };
  126323. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126324. _vq_quantthresh__44cn1_s_p7_1,
  126325. _vq_quantmap__44cn1_s_p7_1,
  126326. 5,
  126327. 5
  126328. };
  126329. static static_codebook _44cn1_s_p7_1 = {
  126330. 2, 25,
  126331. _vq_lengthlist__44cn1_s_p7_1,
  126332. 1, -533725184, 1611661312, 3, 0,
  126333. _vq_quantlist__44cn1_s_p7_1,
  126334. NULL,
  126335. &_vq_auxt__44cn1_s_p7_1,
  126336. NULL,
  126337. 0
  126338. };
  126339. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126340. 2,
  126341. 1,
  126342. 3,
  126343. 0,
  126344. 4,
  126345. };
  126346. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126347. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126348. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126349. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126350. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126351. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126352. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126353. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126354. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126355. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126356. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126357. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126358. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126359. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126360. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126361. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126362. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126363. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126364. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126365. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126366. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126367. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126368. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126369. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126370. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126371. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126372. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126373. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126374. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126375. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126376. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126377. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126378. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126379. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126380. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126381. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126382. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126383. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126384. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126385. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126386. 12,
  126387. };
  126388. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126389. -331.5, -110.5, 110.5, 331.5,
  126390. };
  126391. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126392. 3, 1, 0, 2, 4,
  126393. };
  126394. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126395. _vq_quantthresh__44cn1_s_p8_0,
  126396. _vq_quantmap__44cn1_s_p8_0,
  126397. 5,
  126398. 5
  126399. };
  126400. static static_codebook _44cn1_s_p8_0 = {
  126401. 4, 625,
  126402. _vq_lengthlist__44cn1_s_p8_0,
  126403. 1, -518283264, 1627103232, 3, 0,
  126404. _vq_quantlist__44cn1_s_p8_0,
  126405. NULL,
  126406. &_vq_auxt__44cn1_s_p8_0,
  126407. NULL,
  126408. 0
  126409. };
  126410. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126411. 6,
  126412. 5,
  126413. 7,
  126414. 4,
  126415. 8,
  126416. 3,
  126417. 9,
  126418. 2,
  126419. 10,
  126420. 1,
  126421. 11,
  126422. 0,
  126423. 12,
  126424. };
  126425. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126426. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126427. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126428. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126429. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126430. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126431. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126432. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126433. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126434. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126435. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126436. 15,12,12,11,11,14,12,13,14,
  126437. };
  126438. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126439. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126440. 42.5, 59.5, 76.5, 93.5,
  126441. };
  126442. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126443. 11, 9, 7, 5, 3, 1, 0, 2,
  126444. 4, 6, 8, 10, 12,
  126445. };
  126446. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126447. _vq_quantthresh__44cn1_s_p8_1,
  126448. _vq_quantmap__44cn1_s_p8_1,
  126449. 13,
  126450. 13
  126451. };
  126452. static static_codebook _44cn1_s_p8_1 = {
  126453. 2, 169,
  126454. _vq_lengthlist__44cn1_s_p8_1,
  126455. 1, -522616832, 1620115456, 4, 0,
  126456. _vq_quantlist__44cn1_s_p8_1,
  126457. NULL,
  126458. &_vq_auxt__44cn1_s_p8_1,
  126459. NULL,
  126460. 0
  126461. };
  126462. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126463. 8,
  126464. 7,
  126465. 9,
  126466. 6,
  126467. 10,
  126468. 5,
  126469. 11,
  126470. 4,
  126471. 12,
  126472. 3,
  126473. 13,
  126474. 2,
  126475. 14,
  126476. 1,
  126477. 15,
  126478. 0,
  126479. 16,
  126480. };
  126481. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126482. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126483. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126484. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126485. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126486. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126487. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126488. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126489. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126490. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126491. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126492. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126493. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126494. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126495. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126496. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126497. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126498. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126499. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126500. 9,
  126501. };
  126502. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126503. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126504. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126505. };
  126506. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126507. 15, 13, 11, 9, 7, 5, 3, 1,
  126508. 0, 2, 4, 6, 8, 10, 12, 14,
  126509. 16,
  126510. };
  126511. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126512. _vq_quantthresh__44cn1_s_p8_2,
  126513. _vq_quantmap__44cn1_s_p8_2,
  126514. 17,
  126515. 17
  126516. };
  126517. static static_codebook _44cn1_s_p8_2 = {
  126518. 2, 289,
  126519. _vq_lengthlist__44cn1_s_p8_2,
  126520. 1, -529530880, 1611661312, 5, 0,
  126521. _vq_quantlist__44cn1_s_p8_2,
  126522. NULL,
  126523. &_vq_auxt__44cn1_s_p8_2,
  126524. NULL,
  126525. 0
  126526. };
  126527. static long _huff_lengthlist__44cn1_s_short[] = {
  126528. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126529. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126530. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126531. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126532. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126533. 10,
  126534. };
  126535. static static_codebook _huff_book__44cn1_s_short = {
  126536. 2, 81,
  126537. _huff_lengthlist__44cn1_s_short,
  126538. 0, 0, 0, 0, 0,
  126539. NULL,
  126540. NULL,
  126541. NULL,
  126542. NULL,
  126543. 0
  126544. };
  126545. static long _huff_lengthlist__44cn1_sm_long[] = {
  126546. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126547. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126548. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126549. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126550. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126551. 17,
  126552. };
  126553. static static_codebook _huff_book__44cn1_sm_long = {
  126554. 2, 81,
  126555. _huff_lengthlist__44cn1_sm_long,
  126556. 0, 0, 0, 0, 0,
  126557. NULL,
  126558. NULL,
  126559. NULL,
  126560. NULL,
  126561. 0
  126562. };
  126563. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126564. 1,
  126565. 0,
  126566. 2,
  126567. };
  126568. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126569. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126570. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126574. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126575. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126579. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126580. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126615. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  126620. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  126625. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  126626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126642. 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126647. 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126652. 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126661. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126666. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126671. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  126687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126688. 0, 0, 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, 0, 0, 0, 0, 0, 0,
  126692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  126980. };
  126981. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  126982. -0.5, 0.5,
  126983. };
  126984. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  126985. 1, 0, 2,
  126986. };
  126987. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  126988. _vq_quantthresh__44cn1_sm_p1_0,
  126989. _vq_quantmap__44cn1_sm_p1_0,
  126990. 3,
  126991. 3
  126992. };
  126993. static static_codebook _44cn1_sm_p1_0 = {
  126994. 8, 6561,
  126995. _vq_lengthlist__44cn1_sm_p1_0,
  126996. 1, -535822336, 1611661312, 2, 0,
  126997. _vq_quantlist__44cn1_sm_p1_0,
  126998. NULL,
  126999. &_vq_auxt__44cn1_sm_p1_0,
  127000. NULL,
  127001. 0
  127002. };
  127003. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127004. 2,
  127005. 1,
  127006. 3,
  127007. 0,
  127008. 4,
  127009. };
  127010. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127011. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127014. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127017. 0, 0, 0, 0, 7, 7, 7, 9, 9, 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,
  127051. };
  127052. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127053. -1.5, -0.5, 0.5, 1.5,
  127054. };
  127055. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127056. 3, 1, 0, 2, 4,
  127057. };
  127058. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127059. _vq_quantthresh__44cn1_sm_p2_0,
  127060. _vq_quantmap__44cn1_sm_p2_0,
  127061. 5,
  127062. 5
  127063. };
  127064. static static_codebook _44cn1_sm_p2_0 = {
  127065. 4, 625,
  127066. _vq_lengthlist__44cn1_sm_p2_0,
  127067. 1, -533725184, 1611661312, 3, 0,
  127068. _vq_quantlist__44cn1_sm_p2_0,
  127069. NULL,
  127070. &_vq_auxt__44cn1_sm_p2_0,
  127071. NULL,
  127072. 0
  127073. };
  127074. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127075. 4,
  127076. 3,
  127077. 5,
  127078. 2,
  127079. 6,
  127080. 1,
  127081. 7,
  127082. 0,
  127083. 8,
  127084. };
  127085. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127086. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127087. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127088. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127089. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127090. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127091. 0,
  127092. };
  127093. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127094. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127095. };
  127096. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127097. 7, 5, 3, 1, 0, 2, 4, 6,
  127098. 8,
  127099. };
  127100. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127101. _vq_quantthresh__44cn1_sm_p3_0,
  127102. _vq_quantmap__44cn1_sm_p3_0,
  127103. 9,
  127104. 9
  127105. };
  127106. static static_codebook _44cn1_sm_p3_0 = {
  127107. 2, 81,
  127108. _vq_lengthlist__44cn1_sm_p3_0,
  127109. 1, -531628032, 1611661312, 4, 0,
  127110. _vq_quantlist__44cn1_sm_p3_0,
  127111. NULL,
  127112. &_vq_auxt__44cn1_sm_p3_0,
  127113. NULL,
  127114. 0
  127115. };
  127116. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127117. 4,
  127118. 3,
  127119. 5,
  127120. 2,
  127121. 6,
  127122. 1,
  127123. 7,
  127124. 0,
  127125. 8,
  127126. };
  127127. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127128. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127129. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127130. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127131. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127132. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127133. 11,
  127134. };
  127135. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127136. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127137. };
  127138. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127139. 7, 5, 3, 1, 0, 2, 4, 6,
  127140. 8,
  127141. };
  127142. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127143. _vq_quantthresh__44cn1_sm_p4_0,
  127144. _vq_quantmap__44cn1_sm_p4_0,
  127145. 9,
  127146. 9
  127147. };
  127148. static static_codebook _44cn1_sm_p4_0 = {
  127149. 2, 81,
  127150. _vq_lengthlist__44cn1_sm_p4_0,
  127151. 1, -531628032, 1611661312, 4, 0,
  127152. _vq_quantlist__44cn1_sm_p4_0,
  127153. NULL,
  127154. &_vq_auxt__44cn1_sm_p4_0,
  127155. NULL,
  127156. 0
  127157. };
  127158. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127159. 8,
  127160. 7,
  127161. 9,
  127162. 6,
  127163. 10,
  127164. 5,
  127165. 11,
  127166. 4,
  127167. 12,
  127168. 3,
  127169. 13,
  127170. 2,
  127171. 14,
  127172. 1,
  127173. 15,
  127174. 0,
  127175. 16,
  127176. };
  127177. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127178. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127179. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127180. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127181. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127182. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127183. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127184. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127185. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127186. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127187. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127188. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127189. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127190. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127191. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127192. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127193. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127194. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127195. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127196. 14,
  127197. };
  127198. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127199. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127200. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127201. };
  127202. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127203. 15, 13, 11, 9, 7, 5, 3, 1,
  127204. 0, 2, 4, 6, 8, 10, 12, 14,
  127205. 16,
  127206. };
  127207. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127208. _vq_quantthresh__44cn1_sm_p5_0,
  127209. _vq_quantmap__44cn1_sm_p5_0,
  127210. 17,
  127211. 17
  127212. };
  127213. static static_codebook _44cn1_sm_p5_0 = {
  127214. 2, 289,
  127215. _vq_lengthlist__44cn1_sm_p5_0,
  127216. 1, -529530880, 1611661312, 5, 0,
  127217. _vq_quantlist__44cn1_sm_p5_0,
  127218. NULL,
  127219. &_vq_auxt__44cn1_sm_p5_0,
  127220. NULL,
  127221. 0
  127222. };
  127223. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127224. 1,
  127225. 0,
  127226. 2,
  127227. };
  127228. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127229. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127230. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127231. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127232. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127233. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127234. 10,
  127235. };
  127236. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127237. -5.5, 5.5,
  127238. };
  127239. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127240. 1, 0, 2,
  127241. };
  127242. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127243. _vq_quantthresh__44cn1_sm_p6_0,
  127244. _vq_quantmap__44cn1_sm_p6_0,
  127245. 3,
  127246. 3
  127247. };
  127248. static static_codebook _44cn1_sm_p6_0 = {
  127249. 4, 81,
  127250. _vq_lengthlist__44cn1_sm_p6_0,
  127251. 1, -529137664, 1618345984, 2, 0,
  127252. _vq_quantlist__44cn1_sm_p6_0,
  127253. NULL,
  127254. &_vq_auxt__44cn1_sm_p6_0,
  127255. NULL,
  127256. 0
  127257. };
  127258. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127259. 5,
  127260. 4,
  127261. 6,
  127262. 3,
  127263. 7,
  127264. 2,
  127265. 8,
  127266. 1,
  127267. 9,
  127268. 0,
  127269. 10,
  127270. };
  127271. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127272. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127273. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127274. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127275. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127276. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127277. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127278. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127279. 10,10,10, 8, 9, 8, 8, 9, 8,
  127280. };
  127281. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127282. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127283. 3.5, 4.5,
  127284. };
  127285. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127286. 9, 7, 5, 3, 1, 0, 2, 4,
  127287. 6, 8, 10,
  127288. };
  127289. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127290. _vq_quantthresh__44cn1_sm_p6_1,
  127291. _vq_quantmap__44cn1_sm_p6_1,
  127292. 11,
  127293. 11
  127294. };
  127295. static static_codebook _44cn1_sm_p6_1 = {
  127296. 2, 121,
  127297. _vq_lengthlist__44cn1_sm_p6_1,
  127298. 1, -531365888, 1611661312, 4, 0,
  127299. _vq_quantlist__44cn1_sm_p6_1,
  127300. NULL,
  127301. &_vq_auxt__44cn1_sm_p6_1,
  127302. NULL,
  127303. 0
  127304. };
  127305. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127306. 6,
  127307. 5,
  127308. 7,
  127309. 4,
  127310. 8,
  127311. 3,
  127312. 9,
  127313. 2,
  127314. 10,
  127315. 1,
  127316. 11,
  127317. 0,
  127318. 12,
  127319. };
  127320. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127321. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127322. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127323. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127324. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127325. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127326. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127327. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127328. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127329. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127330. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127331. 0,13,12,12,12,13,13,13,14,
  127332. };
  127333. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127334. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127335. 12.5, 17.5, 22.5, 27.5,
  127336. };
  127337. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127338. 11, 9, 7, 5, 3, 1, 0, 2,
  127339. 4, 6, 8, 10, 12,
  127340. };
  127341. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127342. _vq_quantthresh__44cn1_sm_p7_0,
  127343. _vq_quantmap__44cn1_sm_p7_0,
  127344. 13,
  127345. 13
  127346. };
  127347. static static_codebook _44cn1_sm_p7_0 = {
  127348. 2, 169,
  127349. _vq_lengthlist__44cn1_sm_p7_0,
  127350. 1, -526516224, 1616117760, 4, 0,
  127351. _vq_quantlist__44cn1_sm_p7_0,
  127352. NULL,
  127353. &_vq_auxt__44cn1_sm_p7_0,
  127354. NULL,
  127355. 0
  127356. };
  127357. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127358. 2,
  127359. 1,
  127360. 3,
  127361. 0,
  127362. 4,
  127363. };
  127364. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127365. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127366. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127367. };
  127368. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127369. -1.5, -0.5, 0.5, 1.5,
  127370. };
  127371. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127372. 3, 1, 0, 2, 4,
  127373. };
  127374. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127375. _vq_quantthresh__44cn1_sm_p7_1,
  127376. _vq_quantmap__44cn1_sm_p7_1,
  127377. 5,
  127378. 5
  127379. };
  127380. static static_codebook _44cn1_sm_p7_1 = {
  127381. 2, 25,
  127382. _vq_lengthlist__44cn1_sm_p7_1,
  127383. 1, -533725184, 1611661312, 3, 0,
  127384. _vq_quantlist__44cn1_sm_p7_1,
  127385. NULL,
  127386. &_vq_auxt__44cn1_sm_p7_1,
  127387. NULL,
  127388. 0
  127389. };
  127390. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127391. 4,
  127392. 3,
  127393. 5,
  127394. 2,
  127395. 6,
  127396. 1,
  127397. 7,
  127398. 0,
  127399. 8,
  127400. };
  127401. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127402. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127403. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127404. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127405. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127406. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127407. 14,
  127408. };
  127409. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127410. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127411. };
  127412. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127413. 7, 5, 3, 1, 0, 2, 4, 6,
  127414. 8,
  127415. };
  127416. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127417. _vq_quantthresh__44cn1_sm_p8_0,
  127418. _vq_quantmap__44cn1_sm_p8_0,
  127419. 9,
  127420. 9
  127421. };
  127422. static static_codebook _44cn1_sm_p8_0 = {
  127423. 2, 81,
  127424. _vq_lengthlist__44cn1_sm_p8_0,
  127425. 1, -516186112, 1627103232, 4, 0,
  127426. _vq_quantlist__44cn1_sm_p8_0,
  127427. NULL,
  127428. &_vq_auxt__44cn1_sm_p8_0,
  127429. NULL,
  127430. 0
  127431. };
  127432. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127433. 6,
  127434. 5,
  127435. 7,
  127436. 4,
  127437. 8,
  127438. 3,
  127439. 9,
  127440. 2,
  127441. 10,
  127442. 1,
  127443. 11,
  127444. 0,
  127445. 12,
  127446. };
  127447. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127448. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127449. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127450. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127451. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127452. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127453. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127454. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127455. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127456. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127457. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127458. 17,12,12,11,10,13,11,13,13,
  127459. };
  127460. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127461. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127462. 42.5, 59.5, 76.5, 93.5,
  127463. };
  127464. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127465. 11, 9, 7, 5, 3, 1, 0, 2,
  127466. 4, 6, 8, 10, 12,
  127467. };
  127468. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127469. _vq_quantthresh__44cn1_sm_p8_1,
  127470. _vq_quantmap__44cn1_sm_p8_1,
  127471. 13,
  127472. 13
  127473. };
  127474. static static_codebook _44cn1_sm_p8_1 = {
  127475. 2, 169,
  127476. _vq_lengthlist__44cn1_sm_p8_1,
  127477. 1, -522616832, 1620115456, 4, 0,
  127478. _vq_quantlist__44cn1_sm_p8_1,
  127479. NULL,
  127480. &_vq_auxt__44cn1_sm_p8_1,
  127481. NULL,
  127482. 0
  127483. };
  127484. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127485. 8,
  127486. 7,
  127487. 9,
  127488. 6,
  127489. 10,
  127490. 5,
  127491. 11,
  127492. 4,
  127493. 12,
  127494. 3,
  127495. 13,
  127496. 2,
  127497. 14,
  127498. 1,
  127499. 15,
  127500. 0,
  127501. 16,
  127502. };
  127503. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127504. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127505. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127506. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127507. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127508. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127509. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127510. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127511. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127512. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127513. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127514. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127515. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127516. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127517. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127518. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127519. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127520. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127521. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127522. 9,
  127523. };
  127524. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127525. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127526. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127527. };
  127528. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127529. 15, 13, 11, 9, 7, 5, 3, 1,
  127530. 0, 2, 4, 6, 8, 10, 12, 14,
  127531. 16,
  127532. };
  127533. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127534. _vq_quantthresh__44cn1_sm_p8_2,
  127535. _vq_quantmap__44cn1_sm_p8_2,
  127536. 17,
  127537. 17
  127538. };
  127539. static static_codebook _44cn1_sm_p8_2 = {
  127540. 2, 289,
  127541. _vq_lengthlist__44cn1_sm_p8_2,
  127542. 1, -529530880, 1611661312, 5, 0,
  127543. _vq_quantlist__44cn1_sm_p8_2,
  127544. NULL,
  127545. &_vq_auxt__44cn1_sm_p8_2,
  127546. NULL,
  127547. 0
  127548. };
  127549. static long _huff_lengthlist__44cn1_sm_short[] = {
  127550. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127551. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127552. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127553. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127554. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127555. 9,
  127556. };
  127557. static static_codebook _huff_book__44cn1_sm_short = {
  127558. 2, 81,
  127559. _huff_lengthlist__44cn1_sm_short,
  127560. 0, 0, 0, 0, 0,
  127561. NULL,
  127562. NULL,
  127563. NULL,
  127564. NULL,
  127565. 0
  127566. };
  127567. /*** End of inlined file: res_books_stereo.h ***/
  127568. static vorbis_info_residue0 _residue_44_low={
  127569. 0,-1, -1, 9,-1,
  127570. {0},
  127571. {-1},
  127572. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127573. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127574. };
  127575. static vorbis_info_residue0 _residue_44_mid={
  127576. 0,-1, -1, 10,-1,
  127577. {0},
  127578. {-1},
  127579. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127580. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127581. };
  127582. static vorbis_info_residue0 _residue_44_high={
  127583. 0,-1, -1, 10,-1,
  127584. {0},
  127585. {-1},
  127586. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127587. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127588. };
  127589. static static_bookblock _resbook_44s_n1={
  127590. {
  127591. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127592. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127593. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127594. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127595. }
  127596. };
  127597. static static_bookblock _resbook_44sm_n1={
  127598. {
  127599. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127600. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127601. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127602. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127603. }
  127604. };
  127605. static static_bookblock _resbook_44s_0={
  127606. {
  127607. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127608. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127609. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127610. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127611. }
  127612. };
  127613. static static_bookblock _resbook_44sm_0={
  127614. {
  127615. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127616. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127617. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127618. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127619. }
  127620. };
  127621. static static_bookblock _resbook_44s_1={
  127622. {
  127623. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127624. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127625. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127626. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127627. }
  127628. };
  127629. static static_bookblock _resbook_44sm_1={
  127630. {
  127631. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127632. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127633. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127634. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127635. }
  127636. };
  127637. static static_bookblock _resbook_44s_2={
  127638. {
  127639. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127640. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127641. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127642. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127643. }
  127644. };
  127645. static static_bookblock _resbook_44s_3={
  127646. {
  127647. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127648. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127649. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127650. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127651. }
  127652. };
  127653. static static_bookblock _resbook_44s_4={
  127654. {
  127655. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127656. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127657. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127658. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127659. }
  127660. };
  127661. static static_bookblock _resbook_44s_5={
  127662. {
  127663. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127664. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127665. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127666. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127667. }
  127668. };
  127669. static static_bookblock _resbook_44s_6={
  127670. {
  127671. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127672. {0,0,&_44c6_s_p4_0},
  127673. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127674. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127675. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127676. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127677. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127678. }
  127679. };
  127680. static static_bookblock _resbook_44s_7={
  127681. {
  127682. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127683. {0,0,&_44c7_s_p4_0},
  127684. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127685. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127686. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127687. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127688. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127689. }
  127690. };
  127691. static static_bookblock _resbook_44s_8={
  127692. {
  127693. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127694. {0,0,&_44c8_s_p4_0},
  127695. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127696. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127697. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127698. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127699. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127700. }
  127701. };
  127702. static static_bookblock _resbook_44s_9={
  127703. {
  127704. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127705. {0,0,&_44c9_s_p4_0},
  127706. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127707. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127708. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127709. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127710. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127711. }
  127712. };
  127713. static vorbis_residue_template _res_44s_n1[]={
  127714. {2,0, &_residue_44_low,
  127715. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127716. &_resbook_44s_n1,&_resbook_44sm_n1},
  127717. {2,0, &_residue_44_low,
  127718. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127719. &_resbook_44s_n1,&_resbook_44sm_n1}
  127720. };
  127721. static vorbis_residue_template _res_44s_0[]={
  127722. {2,0, &_residue_44_low,
  127723. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127724. &_resbook_44s_0,&_resbook_44sm_0},
  127725. {2,0, &_residue_44_low,
  127726. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127727. &_resbook_44s_0,&_resbook_44sm_0}
  127728. };
  127729. static vorbis_residue_template _res_44s_1[]={
  127730. {2,0, &_residue_44_low,
  127731. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127732. &_resbook_44s_1,&_resbook_44sm_1},
  127733. {2,0, &_residue_44_low,
  127734. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127735. &_resbook_44s_1,&_resbook_44sm_1}
  127736. };
  127737. static vorbis_residue_template _res_44s_2[]={
  127738. {2,0, &_residue_44_mid,
  127739. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127740. &_resbook_44s_2,&_resbook_44s_2},
  127741. {2,0, &_residue_44_mid,
  127742. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127743. &_resbook_44s_2,&_resbook_44s_2}
  127744. };
  127745. static vorbis_residue_template _res_44s_3[]={
  127746. {2,0, &_residue_44_mid,
  127747. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127748. &_resbook_44s_3,&_resbook_44s_3},
  127749. {2,0, &_residue_44_mid,
  127750. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127751. &_resbook_44s_3,&_resbook_44s_3}
  127752. };
  127753. static vorbis_residue_template _res_44s_4[]={
  127754. {2,0, &_residue_44_mid,
  127755. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127756. &_resbook_44s_4,&_resbook_44s_4},
  127757. {2,0, &_residue_44_mid,
  127758. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127759. &_resbook_44s_4,&_resbook_44s_4}
  127760. };
  127761. static vorbis_residue_template _res_44s_5[]={
  127762. {2,0, &_residue_44_mid,
  127763. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127764. &_resbook_44s_5,&_resbook_44s_5},
  127765. {2,0, &_residue_44_mid,
  127766. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127767. &_resbook_44s_5,&_resbook_44s_5}
  127768. };
  127769. static vorbis_residue_template _res_44s_6[]={
  127770. {2,0, &_residue_44_high,
  127771. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127772. &_resbook_44s_6,&_resbook_44s_6},
  127773. {2,0, &_residue_44_high,
  127774. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127775. &_resbook_44s_6,&_resbook_44s_6}
  127776. };
  127777. static vorbis_residue_template _res_44s_7[]={
  127778. {2,0, &_residue_44_high,
  127779. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127780. &_resbook_44s_7,&_resbook_44s_7},
  127781. {2,0, &_residue_44_high,
  127782. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127783. &_resbook_44s_7,&_resbook_44s_7}
  127784. };
  127785. static vorbis_residue_template _res_44s_8[]={
  127786. {2,0, &_residue_44_high,
  127787. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127788. &_resbook_44s_8,&_resbook_44s_8},
  127789. {2,0, &_residue_44_high,
  127790. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127791. &_resbook_44s_8,&_resbook_44s_8}
  127792. };
  127793. static vorbis_residue_template _res_44s_9[]={
  127794. {2,0, &_residue_44_high,
  127795. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127796. &_resbook_44s_9,&_resbook_44s_9},
  127797. {2,0, &_residue_44_high,
  127798. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127799. &_resbook_44s_9,&_resbook_44s_9}
  127800. };
  127801. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127802. { _map_nominal, _res_44s_n1 }, /* -1 */
  127803. { _map_nominal, _res_44s_0 }, /* 0 */
  127804. { _map_nominal, _res_44s_1 }, /* 1 */
  127805. { _map_nominal, _res_44s_2 }, /* 2 */
  127806. { _map_nominal, _res_44s_3 }, /* 3 */
  127807. { _map_nominal, _res_44s_4 }, /* 4 */
  127808. { _map_nominal, _res_44s_5 }, /* 5 */
  127809. { _map_nominal, _res_44s_6 }, /* 6 */
  127810. { _map_nominal, _res_44s_7 }, /* 7 */
  127811. { _map_nominal, _res_44s_8 }, /* 8 */
  127812. { _map_nominal, _res_44s_9 }, /* 9 */
  127813. };
  127814. /*** End of inlined file: residue_44.h ***/
  127815. /*** Start of inlined file: psych_44.h ***/
  127816. static vorbis_info_psy_global _psy_global_44[5]={
  127817. {8, /* lines per eighth octave */
  127818. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127819. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127820. -6.f,
  127821. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127822. },
  127823. {8, /* lines per eighth octave */
  127824. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127825. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127826. -6.f,
  127827. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127828. },
  127829. {8, /* lines per eighth octave */
  127830. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127831. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127832. -6.f,
  127833. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127834. },
  127835. {8, /* lines per eighth octave */
  127836. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127837. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127838. -6.f,
  127839. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127840. },
  127841. {8, /* lines per eighth octave */
  127842. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127843. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127844. -6.f,
  127845. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127846. },
  127847. };
  127848. static compandblock _psy_compand_44[6]={
  127849. {{
  127850. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127851. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127852. 16,17,18,19,20,21,22, 23, /* 23dB */
  127853. 24,25,26,27,28,29,30, 31, /* 31dB */
  127854. 32,33,34,35,36,37,38, 39, /* 39dB */
  127855. }},
  127856. {{
  127857. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127858. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127859. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127860. 15,16,17,17,17,18,18, 19, /* 31dB */
  127861. 19,19,20,21,22,23,24, 25, /* 39dB */
  127862. }},
  127863. {{
  127864. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127865. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127866. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127867. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127868. 11,12,13,14,15,16,17, 18, /* 39dB */
  127869. }},
  127870. {{
  127871. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127872. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127873. 16,17,18,19,20,21,22, 23, /* 23dB */
  127874. 24,25,26,27,28,29,30, 31, /* 31dB */
  127875. 32,33,34,35,36,37,38, 39, /* 39dB */
  127876. }},
  127877. {{
  127878. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127879. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127880. 13,14,14,14,15,15,15, 15, /* 23dB */
  127881. 16,16,17,17,17,18,18, 19, /* 31dB */
  127882. 19,19,20,21,22,23,24, 25, /* 39dB */
  127883. }},
  127884. {{
  127885. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127886. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127887. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127888. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127889. 11,12,13,14,15,16,17, 18, /* 39dB */
  127890. }}
  127891. };
  127892. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127893. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127894. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127895. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127896. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127897. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127898. /* 4 */
  127899. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127900. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127901. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127902. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127903. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127904. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127905. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127906. };
  127907. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127908. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127909. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127910. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127911. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127912. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127913. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127914. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127915. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127916. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127917. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127918. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127919. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127920. };
  127921. static noise3 _psy_noisebias_trans[12]={
  127922. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127923. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127924. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127925. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127926. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127927. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127928. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127929. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127930. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127931. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127932. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127933. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  127934. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127935. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127936. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127937. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127938. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127939. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127940. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127941. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127942. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  127943. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127944. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127945. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127946. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127947. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  127948. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127949. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  127950. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  127951. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127952. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127953. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  127954. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  127955. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  127956. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  127957. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127958. };
  127959. static noise3 _psy_noisebias_long[12]={
  127960. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  127961. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  127962. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127963. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  127964. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  127965. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127966. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127967. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127968. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127969. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127970. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127971. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127972. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127973. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127974. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  127975. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127976. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127977. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  127978. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127979. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127980. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  127981. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127982. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127983. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  127984. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127985. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  127986. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127987. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  127988. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  127989. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127990. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127991. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  127992. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127993. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  127994. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  127995. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127996. };
  127997. static noise3 _psy_noisebias_impulse[12]={
  127998. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127999. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128000. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128001. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128002. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128003. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128004. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128005. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128006. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128007. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128008. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128009. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128010. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128011. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128012. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128013. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128014. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128015. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128016. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128017. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128018. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128019. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128020. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128021. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128022. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128023. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128024. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128025. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128026. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128027. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128028. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128029. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128030. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128031. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128032. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128033. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128034. };
  128035. static noise3 _psy_noisebias_padding[12]={
  128036. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128037. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128038. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128039. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128040. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128041. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128042. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128043. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128044. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128045. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128046. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128047. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128048. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128049. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128050. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128051. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128052. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128053. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128054. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128055. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128056. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128057. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128058. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128059. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128060. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128061. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128062. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128063. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128064. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128065. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128066. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128067. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128068. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128069. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128070. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128071. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128072. };
  128073. static noiseguard _psy_noiseguards_44[4]={
  128074. {3,3,15},
  128075. {3,3,15},
  128076. {10,10,100},
  128077. {10,10,100},
  128078. };
  128079. static int _psy_tone_suppress[12]={
  128080. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128081. };
  128082. static int _psy_tone_0dB[12]={
  128083. 90,90,95,95,95,95,105,105,105,105,105,105,
  128084. };
  128085. static int _psy_noise_suppress[12]={
  128086. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128087. };
  128088. static vorbis_info_psy _psy_info_template={
  128089. -1,
  128090. -140.,-140.,
  128091. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128092. 1, -0.f, .5f, .5f, 0,0,0,
  128093. {{-1},{-1},{-1}},{-1},105.f,
  128094. 0,0,-1,-1,0.,
  128095. };
  128096. static int _psy_ath_floater[12]={
  128097. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128098. };
  128099. static int _psy_ath_abs[12]={
  128100. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128101. };
  128102. static adj_stereo _psy_stereo_modes_44[12]={
  128103. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128104. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128105. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128106. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128107. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128108. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128109. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128110. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128111. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128112. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128113. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128114. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128115. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128116. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128117. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128118. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128119. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128120. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128121. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128122. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128123. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128124. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128125. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128126. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128127. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128128. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128129. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128130. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128131. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128132. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128133. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128134. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128135. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128136. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128137. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128138. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128139. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128140. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128141. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128142. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128143. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128144. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128145. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128146. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128147. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128148. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128149. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128150. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128151. };
  128152. static att3 _psy_tone_masteratt_44[12]={
  128153. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128154. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128155. /* 1 */
  128156. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128157. /* 2 */
  128158. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128159. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128160. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128161. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128162. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128163. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128164. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128165. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128166. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128167. };
  128168. static double _psy_lowpass_44[12]={
  128169. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128170. };
  128171. static int _noise_start_short_44[11]={
  128172. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128173. };
  128174. static int _noise_start_long_44[11]={
  128175. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128176. };
  128177. static int _noise_part_short_44[11]={
  128178. 8,8,8,8,8,8,8,8,8,8,8
  128179. };
  128180. static int _noise_part_long_44[11]={
  128181. 32,32,32,32,32,32,32,32,32,32,32
  128182. };
  128183. static double _noise_thresh_44[11]={
  128184. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128185. };
  128186. static double _noise_thresh_5only[2]={
  128187. .5,.5,
  128188. };
  128189. /*** End of inlined file: psych_44.h ***/
  128190. static double rate_mapping_44_stereo[12]={
  128191. 22500.,32000.,40000.,48000.,56000.,64000.,
  128192. 80000.,96000.,112000.,128000.,160000.,250001.
  128193. };
  128194. static double quality_mapping_44[12]={
  128195. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128196. };
  128197. static int blocksize_short_44[11]={
  128198. 512,256,256,256,256,256,256,256,256,256,256
  128199. };
  128200. static int blocksize_long_44[11]={
  128201. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128202. };
  128203. static double _psy_compand_short_mapping[12]={
  128204. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128205. };
  128206. static double _psy_compand_long_mapping[12]={
  128207. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128208. };
  128209. static double _global_mapping_44[12]={
  128210. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128211. };
  128212. static int _floor_short_mapping_44[11]={
  128213. 1,0,0,2,2,4,5,5,5,5,5
  128214. };
  128215. static int _floor_long_mapping_44[11]={
  128216. 8,7,7,7,7,7,7,7,7,7,7
  128217. };
  128218. ve_setup_data_template ve_setup_44_stereo={
  128219. 11,
  128220. rate_mapping_44_stereo,
  128221. quality_mapping_44,
  128222. 2,
  128223. 40000,
  128224. 50000,
  128225. blocksize_short_44,
  128226. blocksize_long_44,
  128227. _psy_tone_masteratt_44,
  128228. _psy_tone_0dB,
  128229. _psy_tone_suppress,
  128230. _vp_tonemask_adj_otherblock,
  128231. _vp_tonemask_adj_longblock,
  128232. _vp_tonemask_adj_otherblock,
  128233. _psy_noiseguards_44,
  128234. _psy_noisebias_impulse,
  128235. _psy_noisebias_padding,
  128236. _psy_noisebias_trans,
  128237. _psy_noisebias_long,
  128238. _psy_noise_suppress,
  128239. _psy_compand_44,
  128240. _psy_compand_short_mapping,
  128241. _psy_compand_long_mapping,
  128242. {_noise_start_short_44,_noise_start_long_44},
  128243. {_noise_part_short_44,_noise_part_long_44},
  128244. _noise_thresh_44,
  128245. _psy_ath_floater,
  128246. _psy_ath_abs,
  128247. _psy_lowpass_44,
  128248. _psy_global_44,
  128249. _global_mapping_44,
  128250. _psy_stereo_modes_44,
  128251. _floor_books,
  128252. _floor,
  128253. _floor_short_mapping_44,
  128254. _floor_long_mapping_44,
  128255. _mapres_template_44_stereo
  128256. };
  128257. /*** End of inlined file: setup_44.h ***/
  128258. /*** Start of inlined file: setup_44u.h ***/
  128259. /*** Start of inlined file: residue_44u.h ***/
  128260. /*** Start of inlined file: res_books_uncoupled.h ***/
  128261. static long _vq_quantlist__16u0__p1_0[] = {
  128262. 1,
  128263. 0,
  128264. 2,
  128265. };
  128266. static long _vq_lengthlist__16u0__p1_0[] = {
  128267. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128268. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128269. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128270. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128271. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128272. 12,
  128273. };
  128274. static float _vq_quantthresh__16u0__p1_0[] = {
  128275. -0.5, 0.5,
  128276. };
  128277. static long _vq_quantmap__16u0__p1_0[] = {
  128278. 1, 0, 2,
  128279. };
  128280. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128281. _vq_quantthresh__16u0__p1_0,
  128282. _vq_quantmap__16u0__p1_0,
  128283. 3,
  128284. 3
  128285. };
  128286. static static_codebook _16u0__p1_0 = {
  128287. 4, 81,
  128288. _vq_lengthlist__16u0__p1_0,
  128289. 1, -535822336, 1611661312, 2, 0,
  128290. _vq_quantlist__16u0__p1_0,
  128291. NULL,
  128292. &_vq_auxt__16u0__p1_0,
  128293. NULL,
  128294. 0
  128295. };
  128296. static long _vq_quantlist__16u0__p2_0[] = {
  128297. 1,
  128298. 0,
  128299. 2,
  128300. };
  128301. static long _vq_lengthlist__16u0__p2_0[] = {
  128302. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128303. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128304. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128305. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128306. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128307. 8,
  128308. };
  128309. static float _vq_quantthresh__16u0__p2_0[] = {
  128310. -0.5, 0.5,
  128311. };
  128312. static long _vq_quantmap__16u0__p2_0[] = {
  128313. 1, 0, 2,
  128314. };
  128315. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128316. _vq_quantthresh__16u0__p2_0,
  128317. _vq_quantmap__16u0__p2_0,
  128318. 3,
  128319. 3
  128320. };
  128321. static static_codebook _16u0__p2_0 = {
  128322. 4, 81,
  128323. _vq_lengthlist__16u0__p2_0,
  128324. 1, -535822336, 1611661312, 2, 0,
  128325. _vq_quantlist__16u0__p2_0,
  128326. NULL,
  128327. &_vq_auxt__16u0__p2_0,
  128328. NULL,
  128329. 0
  128330. };
  128331. static long _vq_quantlist__16u0__p3_0[] = {
  128332. 2,
  128333. 1,
  128334. 3,
  128335. 0,
  128336. 4,
  128337. };
  128338. static long _vq_lengthlist__16u0__p3_0[] = {
  128339. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128340. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128341. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128342. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128343. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128344. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128345. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128346. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128347. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128348. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128349. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128350. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128351. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128352. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128353. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128354. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128355. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128356. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128357. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128358. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128359. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128360. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128361. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128362. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128363. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128364. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128365. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128366. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128367. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128368. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128369. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128370. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128371. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128372. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128373. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128374. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128375. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128376. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128377. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128378. 18,
  128379. };
  128380. static float _vq_quantthresh__16u0__p3_0[] = {
  128381. -1.5, -0.5, 0.5, 1.5,
  128382. };
  128383. static long _vq_quantmap__16u0__p3_0[] = {
  128384. 3, 1, 0, 2, 4,
  128385. };
  128386. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128387. _vq_quantthresh__16u0__p3_0,
  128388. _vq_quantmap__16u0__p3_0,
  128389. 5,
  128390. 5
  128391. };
  128392. static static_codebook _16u0__p3_0 = {
  128393. 4, 625,
  128394. _vq_lengthlist__16u0__p3_0,
  128395. 1, -533725184, 1611661312, 3, 0,
  128396. _vq_quantlist__16u0__p3_0,
  128397. NULL,
  128398. &_vq_auxt__16u0__p3_0,
  128399. NULL,
  128400. 0
  128401. };
  128402. static long _vq_quantlist__16u0__p4_0[] = {
  128403. 2,
  128404. 1,
  128405. 3,
  128406. 0,
  128407. 4,
  128408. };
  128409. static long _vq_lengthlist__16u0__p4_0[] = {
  128410. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128411. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128412. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128413. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128414. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128415. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128416. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128417. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128418. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128419. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128420. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128421. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128422. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128423. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128424. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128425. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128426. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128427. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128428. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128429. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128430. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128431. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128432. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128433. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128434. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128435. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128436. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128437. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128438. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128439. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128440. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128441. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128442. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128443. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128444. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128445. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128446. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128447. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128448. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128449. 11,
  128450. };
  128451. static float _vq_quantthresh__16u0__p4_0[] = {
  128452. -1.5, -0.5, 0.5, 1.5,
  128453. };
  128454. static long _vq_quantmap__16u0__p4_0[] = {
  128455. 3, 1, 0, 2, 4,
  128456. };
  128457. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128458. _vq_quantthresh__16u0__p4_0,
  128459. _vq_quantmap__16u0__p4_0,
  128460. 5,
  128461. 5
  128462. };
  128463. static static_codebook _16u0__p4_0 = {
  128464. 4, 625,
  128465. _vq_lengthlist__16u0__p4_0,
  128466. 1, -533725184, 1611661312, 3, 0,
  128467. _vq_quantlist__16u0__p4_0,
  128468. NULL,
  128469. &_vq_auxt__16u0__p4_0,
  128470. NULL,
  128471. 0
  128472. };
  128473. static long _vq_quantlist__16u0__p5_0[] = {
  128474. 4,
  128475. 3,
  128476. 5,
  128477. 2,
  128478. 6,
  128479. 1,
  128480. 7,
  128481. 0,
  128482. 8,
  128483. };
  128484. static long _vq_lengthlist__16u0__p5_0[] = {
  128485. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128486. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128487. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128488. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128489. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128490. 12,
  128491. };
  128492. static float _vq_quantthresh__16u0__p5_0[] = {
  128493. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128494. };
  128495. static long _vq_quantmap__16u0__p5_0[] = {
  128496. 7, 5, 3, 1, 0, 2, 4, 6,
  128497. 8,
  128498. };
  128499. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128500. _vq_quantthresh__16u0__p5_0,
  128501. _vq_quantmap__16u0__p5_0,
  128502. 9,
  128503. 9
  128504. };
  128505. static static_codebook _16u0__p5_0 = {
  128506. 2, 81,
  128507. _vq_lengthlist__16u0__p5_0,
  128508. 1, -531628032, 1611661312, 4, 0,
  128509. _vq_quantlist__16u0__p5_0,
  128510. NULL,
  128511. &_vq_auxt__16u0__p5_0,
  128512. NULL,
  128513. 0
  128514. };
  128515. static long _vq_quantlist__16u0__p6_0[] = {
  128516. 6,
  128517. 5,
  128518. 7,
  128519. 4,
  128520. 8,
  128521. 3,
  128522. 9,
  128523. 2,
  128524. 10,
  128525. 1,
  128526. 11,
  128527. 0,
  128528. 12,
  128529. };
  128530. static long _vq_lengthlist__16u0__p6_0[] = {
  128531. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128532. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128533. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128534. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128535. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128536. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128537. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128538. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128539. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128540. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128541. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128542. };
  128543. static float _vq_quantthresh__16u0__p6_0[] = {
  128544. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128545. 12.5, 17.5, 22.5, 27.5,
  128546. };
  128547. static long _vq_quantmap__16u0__p6_0[] = {
  128548. 11, 9, 7, 5, 3, 1, 0, 2,
  128549. 4, 6, 8, 10, 12,
  128550. };
  128551. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128552. _vq_quantthresh__16u0__p6_0,
  128553. _vq_quantmap__16u0__p6_0,
  128554. 13,
  128555. 13
  128556. };
  128557. static static_codebook _16u0__p6_0 = {
  128558. 2, 169,
  128559. _vq_lengthlist__16u0__p6_0,
  128560. 1, -526516224, 1616117760, 4, 0,
  128561. _vq_quantlist__16u0__p6_0,
  128562. NULL,
  128563. &_vq_auxt__16u0__p6_0,
  128564. NULL,
  128565. 0
  128566. };
  128567. static long _vq_quantlist__16u0__p6_1[] = {
  128568. 2,
  128569. 1,
  128570. 3,
  128571. 0,
  128572. 4,
  128573. };
  128574. static long _vq_lengthlist__16u0__p6_1[] = {
  128575. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128576. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128577. };
  128578. static float _vq_quantthresh__16u0__p6_1[] = {
  128579. -1.5, -0.5, 0.5, 1.5,
  128580. };
  128581. static long _vq_quantmap__16u0__p6_1[] = {
  128582. 3, 1, 0, 2, 4,
  128583. };
  128584. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128585. _vq_quantthresh__16u0__p6_1,
  128586. _vq_quantmap__16u0__p6_1,
  128587. 5,
  128588. 5
  128589. };
  128590. static static_codebook _16u0__p6_1 = {
  128591. 2, 25,
  128592. _vq_lengthlist__16u0__p6_1,
  128593. 1, -533725184, 1611661312, 3, 0,
  128594. _vq_quantlist__16u0__p6_1,
  128595. NULL,
  128596. &_vq_auxt__16u0__p6_1,
  128597. NULL,
  128598. 0
  128599. };
  128600. static long _vq_quantlist__16u0__p7_0[] = {
  128601. 1,
  128602. 0,
  128603. 2,
  128604. };
  128605. static long _vq_lengthlist__16u0__p7_0[] = {
  128606. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128607. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128608. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128609. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128610. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128611. 7,
  128612. };
  128613. static float _vq_quantthresh__16u0__p7_0[] = {
  128614. -157.5, 157.5,
  128615. };
  128616. static long _vq_quantmap__16u0__p7_0[] = {
  128617. 1, 0, 2,
  128618. };
  128619. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128620. _vq_quantthresh__16u0__p7_0,
  128621. _vq_quantmap__16u0__p7_0,
  128622. 3,
  128623. 3
  128624. };
  128625. static static_codebook _16u0__p7_0 = {
  128626. 4, 81,
  128627. _vq_lengthlist__16u0__p7_0,
  128628. 1, -518803456, 1628680192, 2, 0,
  128629. _vq_quantlist__16u0__p7_0,
  128630. NULL,
  128631. &_vq_auxt__16u0__p7_0,
  128632. NULL,
  128633. 0
  128634. };
  128635. static long _vq_quantlist__16u0__p7_1[] = {
  128636. 7,
  128637. 6,
  128638. 8,
  128639. 5,
  128640. 9,
  128641. 4,
  128642. 10,
  128643. 3,
  128644. 11,
  128645. 2,
  128646. 12,
  128647. 1,
  128648. 13,
  128649. 0,
  128650. 14,
  128651. };
  128652. static long _vq_lengthlist__16u0__p7_1[] = {
  128653. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128654. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128655. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128656. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128657. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128658. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128659. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128660. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128661. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128662. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128663. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128664. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128665. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128666. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128667. 10,
  128668. };
  128669. static float _vq_quantthresh__16u0__p7_1[] = {
  128670. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128671. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128672. };
  128673. static long _vq_quantmap__16u0__p7_1[] = {
  128674. 13, 11, 9, 7, 5, 3, 1, 0,
  128675. 2, 4, 6, 8, 10, 12, 14,
  128676. };
  128677. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128678. _vq_quantthresh__16u0__p7_1,
  128679. _vq_quantmap__16u0__p7_1,
  128680. 15,
  128681. 15
  128682. };
  128683. static static_codebook _16u0__p7_1 = {
  128684. 2, 225,
  128685. _vq_lengthlist__16u0__p7_1,
  128686. 1, -520986624, 1620377600, 4, 0,
  128687. _vq_quantlist__16u0__p7_1,
  128688. NULL,
  128689. &_vq_auxt__16u0__p7_1,
  128690. NULL,
  128691. 0
  128692. };
  128693. static long _vq_quantlist__16u0__p7_2[] = {
  128694. 10,
  128695. 9,
  128696. 11,
  128697. 8,
  128698. 12,
  128699. 7,
  128700. 13,
  128701. 6,
  128702. 14,
  128703. 5,
  128704. 15,
  128705. 4,
  128706. 16,
  128707. 3,
  128708. 17,
  128709. 2,
  128710. 18,
  128711. 1,
  128712. 19,
  128713. 0,
  128714. 20,
  128715. };
  128716. static long _vq_lengthlist__16u0__p7_2[] = {
  128717. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128718. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128719. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128720. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128721. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128722. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128723. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128724. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128725. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128726. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128727. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128728. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128729. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128730. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128731. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128732. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128733. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128734. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128735. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128736. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128737. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128738. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128739. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128740. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128741. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128742. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128743. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128744. 10,10,12,11,10,11,11,11,10,
  128745. };
  128746. static float _vq_quantthresh__16u0__p7_2[] = {
  128747. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128748. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128749. 6.5, 7.5, 8.5, 9.5,
  128750. };
  128751. static long _vq_quantmap__16u0__p7_2[] = {
  128752. 19, 17, 15, 13, 11, 9, 7, 5,
  128753. 3, 1, 0, 2, 4, 6, 8, 10,
  128754. 12, 14, 16, 18, 20,
  128755. };
  128756. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128757. _vq_quantthresh__16u0__p7_2,
  128758. _vq_quantmap__16u0__p7_2,
  128759. 21,
  128760. 21
  128761. };
  128762. static static_codebook _16u0__p7_2 = {
  128763. 2, 441,
  128764. _vq_lengthlist__16u0__p7_2,
  128765. 1, -529268736, 1611661312, 5, 0,
  128766. _vq_quantlist__16u0__p7_2,
  128767. NULL,
  128768. &_vq_auxt__16u0__p7_2,
  128769. NULL,
  128770. 0
  128771. };
  128772. static long _huff_lengthlist__16u0__single[] = {
  128773. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128774. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128775. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128776. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128777. };
  128778. static static_codebook _huff_book__16u0__single = {
  128779. 2, 64,
  128780. _huff_lengthlist__16u0__single,
  128781. 0, 0, 0, 0, 0,
  128782. NULL,
  128783. NULL,
  128784. NULL,
  128785. NULL,
  128786. 0
  128787. };
  128788. static long _huff_lengthlist__16u1__long[] = {
  128789. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128790. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128791. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128792. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128793. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128794. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128795. 16,13,16,18,
  128796. };
  128797. static static_codebook _huff_book__16u1__long = {
  128798. 2, 100,
  128799. _huff_lengthlist__16u1__long,
  128800. 0, 0, 0, 0, 0,
  128801. NULL,
  128802. NULL,
  128803. NULL,
  128804. NULL,
  128805. 0
  128806. };
  128807. static long _vq_quantlist__16u1__p1_0[] = {
  128808. 1,
  128809. 0,
  128810. 2,
  128811. };
  128812. static long _vq_lengthlist__16u1__p1_0[] = {
  128813. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128814. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128815. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128816. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128817. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128818. 11,
  128819. };
  128820. static float _vq_quantthresh__16u1__p1_0[] = {
  128821. -0.5, 0.5,
  128822. };
  128823. static long _vq_quantmap__16u1__p1_0[] = {
  128824. 1, 0, 2,
  128825. };
  128826. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128827. _vq_quantthresh__16u1__p1_0,
  128828. _vq_quantmap__16u1__p1_0,
  128829. 3,
  128830. 3
  128831. };
  128832. static static_codebook _16u1__p1_0 = {
  128833. 4, 81,
  128834. _vq_lengthlist__16u1__p1_0,
  128835. 1, -535822336, 1611661312, 2, 0,
  128836. _vq_quantlist__16u1__p1_0,
  128837. NULL,
  128838. &_vq_auxt__16u1__p1_0,
  128839. NULL,
  128840. 0
  128841. };
  128842. static long _vq_quantlist__16u1__p2_0[] = {
  128843. 1,
  128844. 0,
  128845. 2,
  128846. };
  128847. static long _vq_lengthlist__16u1__p2_0[] = {
  128848. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128849. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128850. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128851. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128852. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128853. 8,
  128854. };
  128855. static float _vq_quantthresh__16u1__p2_0[] = {
  128856. -0.5, 0.5,
  128857. };
  128858. static long _vq_quantmap__16u1__p2_0[] = {
  128859. 1, 0, 2,
  128860. };
  128861. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128862. _vq_quantthresh__16u1__p2_0,
  128863. _vq_quantmap__16u1__p2_0,
  128864. 3,
  128865. 3
  128866. };
  128867. static static_codebook _16u1__p2_0 = {
  128868. 4, 81,
  128869. _vq_lengthlist__16u1__p2_0,
  128870. 1, -535822336, 1611661312, 2, 0,
  128871. _vq_quantlist__16u1__p2_0,
  128872. NULL,
  128873. &_vq_auxt__16u1__p2_0,
  128874. NULL,
  128875. 0
  128876. };
  128877. static long _vq_quantlist__16u1__p3_0[] = {
  128878. 2,
  128879. 1,
  128880. 3,
  128881. 0,
  128882. 4,
  128883. };
  128884. static long _vq_lengthlist__16u1__p3_0[] = {
  128885. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128886. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128887. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128888. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128889. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128890. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128891. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128892. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128893. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128894. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128895. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128896. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128897. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128898. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128899. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128900. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128901. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128902. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128903. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128904. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128905. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128906. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128907. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128908. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128909. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128910. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128911. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128912. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128913. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128914. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128915. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128916. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128917. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128918. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128919. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128920. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128921. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128922. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128923. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128924. 16,
  128925. };
  128926. static float _vq_quantthresh__16u1__p3_0[] = {
  128927. -1.5, -0.5, 0.5, 1.5,
  128928. };
  128929. static long _vq_quantmap__16u1__p3_0[] = {
  128930. 3, 1, 0, 2, 4,
  128931. };
  128932. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  128933. _vq_quantthresh__16u1__p3_0,
  128934. _vq_quantmap__16u1__p3_0,
  128935. 5,
  128936. 5
  128937. };
  128938. static static_codebook _16u1__p3_0 = {
  128939. 4, 625,
  128940. _vq_lengthlist__16u1__p3_0,
  128941. 1, -533725184, 1611661312, 3, 0,
  128942. _vq_quantlist__16u1__p3_0,
  128943. NULL,
  128944. &_vq_auxt__16u1__p3_0,
  128945. NULL,
  128946. 0
  128947. };
  128948. static long _vq_quantlist__16u1__p4_0[] = {
  128949. 2,
  128950. 1,
  128951. 3,
  128952. 0,
  128953. 4,
  128954. };
  128955. static long _vq_lengthlist__16u1__p4_0[] = {
  128956. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  128957. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  128958. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  128959. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  128960. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  128961. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  128962. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  128963. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  128964. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  128965. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  128966. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  128967. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  128968. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  128969. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  128970. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  128971. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  128972. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  128973. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  128974. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  128975. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  128976. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  128977. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  128978. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  128979. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  128980. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  128981. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  128982. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  128983. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  128984. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  128985. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  128986. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  128987. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  128988. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  128989. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  128990. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  128991. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  128992. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  128993. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  128994. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  128995. 11,
  128996. };
  128997. static float _vq_quantthresh__16u1__p4_0[] = {
  128998. -1.5, -0.5, 0.5, 1.5,
  128999. };
  129000. static long _vq_quantmap__16u1__p4_0[] = {
  129001. 3, 1, 0, 2, 4,
  129002. };
  129003. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129004. _vq_quantthresh__16u1__p4_0,
  129005. _vq_quantmap__16u1__p4_0,
  129006. 5,
  129007. 5
  129008. };
  129009. static static_codebook _16u1__p4_0 = {
  129010. 4, 625,
  129011. _vq_lengthlist__16u1__p4_0,
  129012. 1, -533725184, 1611661312, 3, 0,
  129013. _vq_quantlist__16u1__p4_0,
  129014. NULL,
  129015. &_vq_auxt__16u1__p4_0,
  129016. NULL,
  129017. 0
  129018. };
  129019. static long _vq_quantlist__16u1__p5_0[] = {
  129020. 4,
  129021. 3,
  129022. 5,
  129023. 2,
  129024. 6,
  129025. 1,
  129026. 7,
  129027. 0,
  129028. 8,
  129029. };
  129030. static long _vq_lengthlist__16u1__p5_0[] = {
  129031. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129032. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129033. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129034. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129035. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129036. 13,
  129037. };
  129038. static float _vq_quantthresh__16u1__p5_0[] = {
  129039. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129040. };
  129041. static long _vq_quantmap__16u1__p5_0[] = {
  129042. 7, 5, 3, 1, 0, 2, 4, 6,
  129043. 8,
  129044. };
  129045. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129046. _vq_quantthresh__16u1__p5_0,
  129047. _vq_quantmap__16u1__p5_0,
  129048. 9,
  129049. 9
  129050. };
  129051. static static_codebook _16u1__p5_0 = {
  129052. 2, 81,
  129053. _vq_lengthlist__16u1__p5_0,
  129054. 1, -531628032, 1611661312, 4, 0,
  129055. _vq_quantlist__16u1__p5_0,
  129056. NULL,
  129057. &_vq_auxt__16u1__p5_0,
  129058. NULL,
  129059. 0
  129060. };
  129061. static long _vq_quantlist__16u1__p6_0[] = {
  129062. 4,
  129063. 3,
  129064. 5,
  129065. 2,
  129066. 6,
  129067. 1,
  129068. 7,
  129069. 0,
  129070. 8,
  129071. };
  129072. static long _vq_lengthlist__16u1__p6_0[] = {
  129073. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129074. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129075. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129076. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129077. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129078. 11,
  129079. };
  129080. static float _vq_quantthresh__16u1__p6_0[] = {
  129081. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129082. };
  129083. static long _vq_quantmap__16u1__p6_0[] = {
  129084. 7, 5, 3, 1, 0, 2, 4, 6,
  129085. 8,
  129086. };
  129087. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129088. _vq_quantthresh__16u1__p6_0,
  129089. _vq_quantmap__16u1__p6_0,
  129090. 9,
  129091. 9
  129092. };
  129093. static static_codebook _16u1__p6_0 = {
  129094. 2, 81,
  129095. _vq_lengthlist__16u1__p6_0,
  129096. 1, -531628032, 1611661312, 4, 0,
  129097. _vq_quantlist__16u1__p6_0,
  129098. NULL,
  129099. &_vq_auxt__16u1__p6_0,
  129100. NULL,
  129101. 0
  129102. };
  129103. static long _vq_quantlist__16u1__p7_0[] = {
  129104. 1,
  129105. 0,
  129106. 2,
  129107. };
  129108. static long _vq_lengthlist__16u1__p7_0[] = {
  129109. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129110. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129111. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129112. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129113. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129114. 13,
  129115. };
  129116. static float _vq_quantthresh__16u1__p7_0[] = {
  129117. -5.5, 5.5,
  129118. };
  129119. static long _vq_quantmap__16u1__p7_0[] = {
  129120. 1, 0, 2,
  129121. };
  129122. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129123. _vq_quantthresh__16u1__p7_0,
  129124. _vq_quantmap__16u1__p7_0,
  129125. 3,
  129126. 3
  129127. };
  129128. static static_codebook _16u1__p7_0 = {
  129129. 4, 81,
  129130. _vq_lengthlist__16u1__p7_0,
  129131. 1, -529137664, 1618345984, 2, 0,
  129132. _vq_quantlist__16u1__p7_0,
  129133. NULL,
  129134. &_vq_auxt__16u1__p7_0,
  129135. NULL,
  129136. 0
  129137. };
  129138. static long _vq_quantlist__16u1__p7_1[] = {
  129139. 5,
  129140. 4,
  129141. 6,
  129142. 3,
  129143. 7,
  129144. 2,
  129145. 8,
  129146. 1,
  129147. 9,
  129148. 0,
  129149. 10,
  129150. };
  129151. static long _vq_lengthlist__16u1__p7_1[] = {
  129152. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129153. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129154. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129155. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129156. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129157. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129158. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129159. 8, 9, 9,10,10,10,10,10,10,
  129160. };
  129161. static float _vq_quantthresh__16u1__p7_1[] = {
  129162. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129163. 3.5, 4.5,
  129164. };
  129165. static long _vq_quantmap__16u1__p7_1[] = {
  129166. 9, 7, 5, 3, 1, 0, 2, 4,
  129167. 6, 8, 10,
  129168. };
  129169. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129170. _vq_quantthresh__16u1__p7_1,
  129171. _vq_quantmap__16u1__p7_1,
  129172. 11,
  129173. 11
  129174. };
  129175. static static_codebook _16u1__p7_1 = {
  129176. 2, 121,
  129177. _vq_lengthlist__16u1__p7_1,
  129178. 1, -531365888, 1611661312, 4, 0,
  129179. _vq_quantlist__16u1__p7_1,
  129180. NULL,
  129181. &_vq_auxt__16u1__p7_1,
  129182. NULL,
  129183. 0
  129184. };
  129185. static long _vq_quantlist__16u1__p8_0[] = {
  129186. 5,
  129187. 4,
  129188. 6,
  129189. 3,
  129190. 7,
  129191. 2,
  129192. 8,
  129193. 1,
  129194. 9,
  129195. 0,
  129196. 10,
  129197. };
  129198. static long _vq_lengthlist__16u1__p8_0[] = {
  129199. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129200. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129201. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129202. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129203. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129204. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129205. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129206. 13,14,14,15,15,16,16,15,16,
  129207. };
  129208. static float _vq_quantthresh__16u1__p8_0[] = {
  129209. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129210. 38.5, 49.5,
  129211. };
  129212. static long _vq_quantmap__16u1__p8_0[] = {
  129213. 9, 7, 5, 3, 1, 0, 2, 4,
  129214. 6, 8, 10,
  129215. };
  129216. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129217. _vq_quantthresh__16u1__p8_0,
  129218. _vq_quantmap__16u1__p8_0,
  129219. 11,
  129220. 11
  129221. };
  129222. static static_codebook _16u1__p8_0 = {
  129223. 2, 121,
  129224. _vq_lengthlist__16u1__p8_0,
  129225. 1, -524582912, 1618345984, 4, 0,
  129226. _vq_quantlist__16u1__p8_0,
  129227. NULL,
  129228. &_vq_auxt__16u1__p8_0,
  129229. NULL,
  129230. 0
  129231. };
  129232. static long _vq_quantlist__16u1__p8_1[] = {
  129233. 5,
  129234. 4,
  129235. 6,
  129236. 3,
  129237. 7,
  129238. 2,
  129239. 8,
  129240. 1,
  129241. 9,
  129242. 0,
  129243. 10,
  129244. };
  129245. static long _vq_lengthlist__16u1__p8_1[] = {
  129246. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129247. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129248. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129249. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129250. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129251. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129252. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129253. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129254. };
  129255. static float _vq_quantthresh__16u1__p8_1[] = {
  129256. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129257. 3.5, 4.5,
  129258. };
  129259. static long _vq_quantmap__16u1__p8_1[] = {
  129260. 9, 7, 5, 3, 1, 0, 2, 4,
  129261. 6, 8, 10,
  129262. };
  129263. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129264. _vq_quantthresh__16u1__p8_1,
  129265. _vq_quantmap__16u1__p8_1,
  129266. 11,
  129267. 11
  129268. };
  129269. static static_codebook _16u1__p8_1 = {
  129270. 2, 121,
  129271. _vq_lengthlist__16u1__p8_1,
  129272. 1, -531365888, 1611661312, 4, 0,
  129273. _vq_quantlist__16u1__p8_1,
  129274. NULL,
  129275. &_vq_auxt__16u1__p8_1,
  129276. NULL,
  129277. 0
  129278. };
  129279. static long _vq_quantlist__16u1__p9_0[] = {
  129280. 7,
  129281. 6,
  129282. 8,
  129283. 5,
  129284. 9,
  129285. 4,
  129286. 10,
  129287. 3,
  129288. 11,
  129289. 2,
  129290. 12,
  129291. 1,
  129292. 13,
  129293. 0,
  129294. 14,
  129295. };
  129296. static long _vq_lengthlist__16u1__p9_0[] = {
  129297. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129298. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129299. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129300. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129301. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129302. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129303. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129304. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129305. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129306. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129307. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129308. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129309. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129310. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129311. 8,
  129312. };
  129313. static float _vq_quantthresh__16u1__p9_0[] = {
  129314. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129315. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129316. };
  129317. static long _vq_quantmap__16u1__p9_0[] = {
  129318. 13, 11, 9, 7, 5, 3, 1, 0,
  129319. 2, 4, 6, 8, 10, 12, 14,
  129320. };
  129321. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129322. _vq_quantthresh__16u1__p9_0,
  129323. _vq_quantmap__16u1__p9_0,
  129324. 15,
  129325. 15
  129326. };
  129327. static static_codebook _16u1__p9_0 = {
  129328. 2, 225,
  129329. _vq_lengthlist__16u1__p9_0,
  129330. 1, -514071552, 1627381760, 4, 0,
  129331. _vq_quantlist__16u1__p9_0,
  129332. NULL,
  129333. &_vq_auxt__16u1__p9_0,
  129334. NULL,
  129335. 0
  129336. };
  129337. static long _vq_quantlist__16u1__p9_1[] = {
  129338. 7,
  129339. 6,
  129340. 8,
  129341. 5,
  129342. 9,
  129343. 4,
  129344. 10,
  129345. 3,
  129346. 11,
  129347. 2,
  129348. 12,
  129349. 1,
  129350. 13,
  129351. 0,
  129352. 14,
  129353. };
  129354. static long _vq_lengthlist__16u1__p9_1[] = {
  129355. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129356. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129357. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129358. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129359. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129360. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129361. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129362. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129363. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129364. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129365. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129366. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129367. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129368. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129369. 9,
  129370. };
  129371. static float _vq_quantthresh__16u1__p9_1[] = {
  129372. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129373. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129374. };
  129375. static long _vq_quantmap__16u1__p9_1[] = {
  129376. 13, 11, 9, 7, 5, 3, 1, 0,
  129377. 2, 4, 6, 8, 10, 12, 14,
  129378. };
  129379. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129380. _vq_quantthresh__16u1__p9_1,
  129381. _vq_quantmap__16u1__p9_1,
  129382. 15,
  129383. 15
  129384. };
  129385. static static_codebook _16u1__p9_1 = {
  129386. 2, 225,
  129387. _vq_lengthlist__16u1__p9_1,
  129388. 1, -522338304, 1620115456, 4, 0,
  129389. _vq_quantlist__16u1__p9_1,
  129390. NULL,
  129391. &_vq_auxt__16u1__p9_1,
  129392. NULL,
  129393. 0
  129394. };
  129395. static long _vq_quantlist__16u1__p9_2[] = {
  129396. 8,
  129397. 7,
  129398. 9,
  129399. 6,
  129400. 10,
  129401. 5,
  129402. 11,
  129403. 4,
  129404. 12,
  129405. 3,
  129406. 13,
  129407. 2,
  129408. 14,
  129409. 1,
  129410. 15,
  129411. 0,
  129412. 16,
  129413. };
  129414. static long _vq_lengthlist__16u1__p9_2[] = {
  129415. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129416. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129417. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129418. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129419. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129420. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129421. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129422. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129423. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129424. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129425. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129426. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129427. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129428. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129429. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129430. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129431. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129432. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129433. 10,
  129434. };
  129435. static float _vq_quantthresh__16u1__p9_2[] = {
  129436. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129437. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129438. };
  129439. static long _vq_quantmap__16u1__p9_2[] = {
  129440. 15, 13, 11, 9, 7, 5, 3, 1,
  129441. 0, 2, 4, 6, 8, 10, 12, 14,
  129442. 16,
  129443. };
  129444. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129445. _vq_quantthresh__16u1__p9_2,
  129446. _vq_quantmap__16u1__p9_2,
  129447. 17,
  129448. 17
  129449. };
  129450. static static_codebook _16u1__p9_2 = {
  129451. 2, 289,
  129452. _vq_lengthlist__16u1__p9_2,
  129453. 1, -529530880, 1611661312, 5, 0,
  129454. _vq_quantlist__16u1__p9_2,
  129455. NULL,
  129456. &_vq_auxt__16u1__p9_2,
  129457. NULL,
  129458. 0
  129459. };
  129460. static long _huff_lengthlist__16u1__short[] = {
  129461. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129462. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129463. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129464. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129465. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129466. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129467. 16,16,16,16,
  129468. };
  129469. static static_codebook _huff_book__16u1__short = {
  129470. 2, 100,
  129471. _huff_lengthlist__16u1__short,
  129472. 0, 0, 0, 0, 0,
  129473. NULL,
  129474. NULL,
  129475. NULL,
  129476. NULL,
  129477. 0
  129478. };
  129479. static long _huff_lengthlist__16u2__long[] = {
  129480. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129481. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129482. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129483. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129484. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129485. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129486. 13,14,18,18,
  129487. };
  129488. static static_codebook _huff_book__16u2__long = {
  129489. 2, 100,
  129490. _huff_lengthlist__16u2__long,
  129491. 0, 0, 0, 0, 0,
  129492. NULL,
  129493. NULL,
  129494. NULL,
  129495. NULL,
  129496. 0
  129497. };
  129498. static long _huff_lengthlist__16u2__short[] = {
  129499. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129500. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129501. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129502. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129503. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129504. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129505. 16,16,16,16,
  129506. };
  129507. static static_codebook _huff_book__16u2__short = {
  129508. 2, 100,
  129509. _huff_lengthlist__16u2__short,
  129510. 0, 0, 0, 0, 0,
  129511. NULL,
  129512. NULL,
  129513. NULL,
  129514. NULL,
  129515. 0
  129516. };
  129517. static long _vq_quantlist__16u2_p1_0[] = {
  129518. 1,
  129519. 0,
  129520. 2,
  129521. };
  129522. static long _vq_lengthlist__16u2_p1_0[] = {
  129523. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129524. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129525. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129526. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129527. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129528. 10,
  129529. };
  129530. static float _vq_quantthresh__16u2_p1_0[] = {
  129531. -0.5, 0.5,
  129532. };
  129533. static long _vq_quantmap__16u2_p1_0[] = {
  129534. 1, 0, 2,
  129535. };
  129536. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129537. _vq_quantthresh__16u2_p1_0,
  129538. _vq_quantmap__16u2_p1_0,
  129539. 3,
  129540. 3
  129541. };
  129542. static static_codebook _16u2_p1_0 = {
  129543. 4, 81,
  129544. _vq_lengthlist__16u2_p1_0,
  129545. 1, -535822336, 1611661312, 2, 0,
  129546. _vq_quantlist__16u2_p1_0,
  129547. NULL,
  129548. &_vq_auxt__16u2_p1_0,
  129549. NULL,
  129550. 0
  129551. };
  129552. static long _vq_quantlist__16u2_p2_0[] = {
  129553. 2,
  129554. 1,
  129555. 3,
  129556. 0,
  129557. 4,
  129558. };
  129559. static long _vq_lengthlist__16u2_p2_0[] = {
  129560. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129561. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129562. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129563. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129564. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129565. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129566. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129567. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129568. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129569. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129570. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129571. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129572. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129573. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129574. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129575. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129576. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129577. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129578. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129579. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129580. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129581. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129582. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129583. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129584. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129585. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129586. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129587. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129588. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129589. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129590. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129591. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129592. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129593. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129594. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129595. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129596. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129597. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129598. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129599. 13,
  129600. };
  129601. static float _vq_quantthresh__16u2_p2_0[] = {
  129602. -1.5, -0.5, 0.5, 1.5,
  129603. };
  129604. static long _vq_quantmap__16u2_p2_0[] = {
  129605. 3, 1, 0, 2, 4,
  129606. };
  129607. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129608. _vq_quantthresh__16u2_p2_0,
  129609. _vq_quantmap__16u2_p2_0,
  129610. 5,
  129611. 5
  129612. };
  129613. static static_codebook _16u2_p2_0 = {
  129614. 4, 625,
  129615. _vq_lengthlist__16u2_p2_0,
  129616. 1, -533725184, 1611661312, 3, 0,
  129617. _vq_quantlist__16u2_p2_0,
  129618. NULL,
  129619. &_vq_auxt__16u2_p2_0,
  129620. NULL,
  129621. 0
  129622. };
  129623. static long _vq_quantlist__16u2_p3_0[] = {
  129624. 4,
  129625. 3,
  129626. 5,
  129627. 2,
  129628. 6,
  129629. 1,
  129630. 7,
  129631. 0,
  129632. 8,
  129633. };
  129634. static long _vq_lengthlist__16u2_p3_0[] = {
  129635. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129636. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129637. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129638. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129639. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129640. 11,
  129641. };
  129642. static float _vq_quantthresh__16u2_p3_0[] = {
  129643. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129644. };
  129645. static long _vq_quantmap__16u2_p3_0[] = {
  129646. 7, 5, 3, 1, 0, 2, 4, 6,
  129647. 8,
  129648. };
  129649. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129650. _vq_quantthresh__16u2_p3_0,
  129651. _vq_quantmap__16u2_p3_0,
  129652. 9,
  129653. 9
  129654. };
  129655. static static_codebook _16u2_p3_0 = {
  129656. 2, 81,
  129657. _vq_lengthlist__16u2_p3_0,
  129658. 1, -531628032, 1611661312, 4, 0,
  129659. _vq_quantlist__16u2_p3_0,
  129660. NULL,
  129661. &_vq_auxt__16u2_p3_0,
  129662. NULL,
  129663. 0
  129664. };
  129665. static long _vq_quantlist__16u2_p4_0[] = {
  129666. 8,
  129667. 7,
  129668. 9,
  129669. 6,
  129670. 10,
  129671. 5,
  129672. 11,
  129673. 4,
  129674. 12,
  129675. 3,
  129676. 13,
  129677. 2,
  129678. 14,
  129679. 1,
  129680. 15,
  129681. 0,
  129682. 16,
  129683. };
  129684. static long _vq_lengthlist__16u2_p4_0[] = {
  129685. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129686. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129687. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129688. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129689. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129690. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129691. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129692. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129693. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129694. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129695. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129696. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129697. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129698. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129699. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129700. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129701. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129702. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129703. 14,
  129704. };
  129705. static float _vq_quantthresh__16u2_p4_0[] = {
  129706. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129707. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129708. };
  129709. static long _vq_quantmap__16u2_p4_0[] = {
  129710. 15, 13, 11, 9, 7, 5, 3, 1,
  129711. 0, 2, 4, 6, 8, 10, 12, 14,
  129712. 16,
  129713. };
  129714. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129715. _vq_quantthresh__16u2_p4_0,
  129716. _vq_quantmap__16u2_p4_0,
  129717. 17,
  129718. 17
  129719. };
  129720. static static_codebook _16u2_p4_0 = {
  129721. 2, 289,
  129722. _vq_lengthlist__16u2_p4_0,
  129723. 1, -529530880, 1611661312, 5, 0,
  129724. _vq_quantlist__16u2_p4_0,
  129725. NULL,
  129726. &_vq_auxt__16u2_p4_0,
  129727. NULL,
  129728. 0
  129729. };
  129730. static long _vq_quantlist__16u2_p5_0[] = {
  129731. 1,
  129732. 0,
  129733. 2,
  129734. };
  129735. static long _vq_lengthlist__16u2_p5_0[] = {
  129736. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129737. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129738. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129739. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129740. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129741. 10,
  129742. };
  129743. static float _vq_quantthresh__16u2_p5_0[] = {
  129744. -5.5, 5.5,
  129745. };
  129746. static long _vq_quantmap__16u2_p5_0[] = {
  129747. 1, 0, 2,
  129748. };
  129749. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129750. _vq_quantthresh__16u2_p5_0,
  129751. _vq_quantmap__16u2_p5_0,
  129752. 3,
  129753. 3
  129754. };
  129755. static static_codebook _16u2_p5_0 = {
  129756. 4, 81,
  129757. _vq_lengthlist__16u2_p5_0,
  129758. 1, -529137664, 1618345984, 2, 0,
  129759. _vq_quantlist__16u2_p5_0,
  129760. NULL,
  129761. &_vq_auxt__16u2_p5_0,
  129762. NULL,
  129763. 0
  129764. };
  129765. static long _vq_quantlist__16u2_p5_1[] = {
  129766. 5,
  129767. 4,
  129768. 6,
  129769. 3,
  129770. 7,
  129771. 2,
  129772. 8,
  129773. 1,
  129774. 9,
  129775. 0,
  129776. 10,
  129777. };
  129778. static long _vq_lengthlist__16u2_p5_1[] = {
  129779. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129780. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129781. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129782. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129783. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129784. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129785. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129786. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129787. };
  129788. static float _vq_quantthresh__16u2_p5_1[] = {
  129789. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129790. 3.5, 4.5,
  129791. };
  129792. static long _vq_quantmap__16u2_p5_1[] = {
  129793. 9, 7, 5, 3, 1, 0, 2, 4,
  129794. 6, 8, 10,
  129795. };
  129796. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129797. _vq_quantthresh__16u2_p5_1,
  129798. _vq_quantmap__16u2_p5_1,
  129799. 11,
  129800. 11
  129801. };
  129802. static static_codebook _16u2_p5_1 = {
  129803. 2, 121,
  129804. _vq_lengthlist__16u2_p5_1,
  129805. 1, -531365888, 1611661312, 4, 0,
  129806. _vq_quantlist__16u2_p5_1,
  129807. NULL,
  129808. &_vq_auxt__16u2_p5_1,
  129809. NULL,
  129810. 0
  129811. };
  129812. static long _vq_quantlist__16u2_p6_0[] = {
  129813. 6,
  129814. 5,
  129815. 7,
  129816. 4,
  129817. 8,
  129818. 3,
  129819. 9,
  129820. 2,
  129821. 10,
  129822. 1,
  129823. 11,
  129824. 0,
  129825. 12,
  129826. };
  129827. static long _vq_lengthlist__16u2_p6_0[] = {
  129828. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129829. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129830. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129831. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129832. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129833. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129834. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129835. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129836. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129837. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129838. 12,13,13,14,14,14,14,15,15,
  129839. };
  129840. static float _vq_quantthresh__16u2_p6_0[] = {
  129841. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129842. 12.5, 17.5, 22.5, 27.5,
  129843. };
  129844. static long _vq_quantmap__16u2_p6_0[] = {
  129845. 11, 9, 7, 5, 3, 1, 0, 2,
  129846. 4, 6, 8, 10, 12,
  129847. };
  129848. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129849. _vq_quantthresh__16u2_p6_0,
  129850. _vq_quantmap__16u2_p6_0,
  129851. 13,
  129852. 13
  129853. };
  129854. static static_codebook _16u2_p6_0 = {
  129855. 2, 169,
  129856. _vq_lengthlist__16u2_p6_0,
  129857. 1, -526516224, 1616117760, 4, 0,
  129858. _vq_quantlist__16u2_p6_0,
  129859. NULL,
  129860. &_vq_auxt__16u2_p6_0,
  129861. NULL,
  129862. 0
  129863. };
  129864. static long _vq_quantlist__16u2_p6_1[] = {
  129865. 2,
  129866. 1,
  129867. 3,
  129868. 0,
  129869. 4,
  129870. };
  129871. static long _vq_lengthlist__16u2_p6_1[] = {
  129872. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129873. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129874. };
  129875. static float _vq_quantthresh__16u2_p6_1[] = {
  129876. -1.5, -0.5, 0.5, 1.5,
  129877. };
  129878. static long _vq_quantmap__16u2_p6_1[] = {
  129879. 3, 1, 0, 2, 4,
  129880. };
  129881. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129882. _vq_quantthresh__16u2_p6_1,
  129883. _vq_quantmap__16u2_p6_1,
  129884. 5,
  129885. 5
  129886. };
  129887. static static_codebook _16u2_p6_1 = {
  129888. 2, 25,
  129889. _vq_lengthlist__16u2_p6_1,
  129890. 1, -533725184, 1611661312, 3, 0,
  129891. _vq_quantlist__16u2_p6_1,
  129892. NULL,
  129893. &_vq_auxt__16u2_p6_1,
  129894. NULL,
  129895. 0
  129896. };
  129897. static long _vq_quantlist__16u2_p7_0[] = {
  129898. 6,
  129899. 5,
  129900. 7,
  129901. 4,
  129902. 8,
  129903. 3,
  129904. 9,
  129905. 2,
  129906. 10,
  129907. 1,
  129908. 11,
  129909. 0,
  129910. 12,
  129911. };
  129912. static long _vq_lengthlist__16u2_p7_0[] = {
  129913. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129914. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129915. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129916. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129917. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129918. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129919. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129920. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129921. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129922. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129923. 12,13,13,13,14,14,14,15,14,
  129924. };
  129925. static float _vq_quantthresh__16u2_p7_0[] = {
  129926. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129927. 27.5, 38.5, 49.5, 60.5,
  129928. };
  129929. static long _vq_quantmap__16u2_p7_0[] = {
  129930. 11, 9, 7, 5, 3, 1, 0, 2,
  129931. 4, 6, 8, 10, 12,
  129932. };
  129933. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  129934. _vq_quantthresh__16u2_p7_0,
  129935. _vq_quantmap__16u2_p7_0,
  129936. 13,
  129937. 13
  129938. };
  129939. static static_codebook _16u2_p7_0 = {
  129940. 2, 169,
  129941. _vq_lengthlist__16u2_p7_0,
  129942. 1, -523206656, 1618345984, 4, 0,
  129943. _vq_quantlist__16u2_p7_0,
  129944. NULL,
  129945. &_vq_auxt__16u2_p7_0,
  129946. NULL,
  129947. 0
  129948. };
  129949. static long _vq_quantlist__16u2_p7_1[] = {
  129950. 5,
  129951. 4,
  129952. 6,
  129953. 3,
  129954. 7,
  129955. 2,
  129956. 8,
  129957. 1,
  129958. 9,
  129959. 0,
  129960. 10,
  129961. };
  129962. static long _vq_lengthlist__16u2_p7_1[] = {
  129963. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  129964. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  129965. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  129966. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  129967. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  129968. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  129969. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  129970. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129971. };
  129972. static float _vq_quantthresh__16u2_p7_1[] = {
  129973. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129974. 3.5, 4.5,
  129975. };
  129976. static long _vq_quantmap__16u2_p7_1[] = {
  129977. 9, 7, 5, 3, 1, 0, 2, 4,
  129978. 6, 8, 10,
  129979. };
  129980. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  129981. _vq_quantthresh__16u2_p7_1,
  129982. _vq_quantmap__16u2_p7_1,
  129983. 11,
  129984. 11
  129985. };
  129986. static static_codebook _16u2_p7_1 = {
  129987. 2, 121,
  129988. _vq_lengthlist__16u2_p7_1,
  129989. 1, -531365888, 1611661312, 4, 0,
  129990. _vq_quantlist__16u2_p7_1,
  129991. NULL,
  129992. &_vq_auxt__16u2_p7_1,
  129993. NULL,
  129994. 0
  129995. };
  129996. static long _vq_quantlist__16u2_p8_0[] = {
  129997. 7,
  129998. 6,
  129999. 8,
  130000. 5,
  130001. 9,
  130002. 4,
  130003. 10,
  130004. 3,
  130005. 11,
  130006. 2,
  130007. 12,
  130008. 1,
  130009. 13,
  130010. 0,
  130011. 14,
  130012. };
  130013. static long _vq_lengthlist__16u2_p8_0[] = {
  130014. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130015. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130016. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130017. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130018. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130019. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130020. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130021. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130022. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130023. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130024. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130025. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130026. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130027. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130028. 14,
  130029. };
  130030. static float _vq_quantthresh__16u2_p8_0[] = {
  130031. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130032. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130033. };
  130034. static long _vq_quantmap__16u2_p8_0[] = {
  130035. 13, 11, 9, 7, 5, 3, 1, 0,
  130036. 2, 4, 6, 8, 10, 12, 14,
  130037. };
  130038. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130039. _vq_quantthresh__16u2_p8_0,
  130040. _vq_quantmap__16u2_p8_0,
  130041. 15,
  130042. 15
  130043. };
  130044. static static_codebook _16u2_p8_0 = {
  130045. 2, 225,
  130046. _vq_lengthlist__16u2_p8_0,
  130047. 1, -520986624, 1620377600, 4, 0,
  130048. _vq_quantlist__16u2_p8_0,
  130049. NULL,
  130050. &_vq_auxt__16u2_p8_0,
  130051. NULL,
  130052. 0
  130053. };
  130054. static long _vq_quantlist__16u2_p8_1[] = {
  130055. 10,
  130056. 9,
  130057. 11,
  130058. 8,
  130059. 12,
  130060. 7,
  130061. 13,
  130062. 6,
  130063. 14,
  130064. 5,
  130065. 15,
  130066. 4,
  130067. 16,
  130068. 3,
  130069. 17,
  130070. 2,
  130071. 18,
  130072. 1,
  130073. 19,
  130074. 0,
  130075. 20,
  130076. };
  130077. static long _vq_lengthlist__16u2_p8_1[] = {
  130078. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130079. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130080. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130081. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130082. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130083. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130084. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130085. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130086. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130087. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130088. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130089. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130090. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130091. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130092. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130093. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130094. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130095. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130096. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130097. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130098. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130099. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130100. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130101. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130102. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130103. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130104. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130105. 11,11,10,11,11,11,10,11,11,
  130106. };
  130107. static float _vq_quantthresh__16u2_p8_1[] = {
  130108. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130109. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130110. 6.5, 7.5, 8.5, 9.5,
  130111. };
  130112. static long _vq_quantmap__16u2_p8_1[] = {
  130113. 19, 17, 15, 13, 11, 9, 7, 5,
  130114. 3, 1, 0, 2, 4, 6, 8, 10,
  130115. 12, 14, 16, 18, 20,
  130116. };
  130117. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130118. _vq_quantthresh__16u2_p8_1,
  130119. _vq_quantmap__16u2_p8_1,
  130120. 21,
  130121. 21
  130122. };
  130123. static static_codebook _16u2_p8_1 = {
  130124. 2, 441,
  130125. _vq_lengthlist__16u2_p8_1,
  130126. 1, -529268736, 1611661312, 5, 0,
  130127. _vq_quantlist__16u2_p8_1,
  130128. NULL,
  130129. &_vq_auxt__16u2_p8_1,
  130130. NULL,
  130131. 0
  130132. };
  130133. static long _vq_quantlist__16u2_p9_0[] = {
  130134. 5586,
  130135. 4655,
  130136. 6517,
  130137. 3724,
  130138. 7448,
  130139. 2793,
  130140. 8379,
  130141. 1862,
  130142. 9310,
  130143. 931,
  130144. 10241,
  130145. 0,
  130146. 11172,
  130147. 5521,
  130148. 5651,
  130149. };
  130150. static long _vq_lengthlist__16u2_p9_0[] = {
  130151. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130152. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130153. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130154. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130155. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130156. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130157. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130158. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130159. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130160. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130161. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130162. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130163. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130164. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130165. 5,
  130166. };
  130167. static float _vq_quantthresh__16u2_p9_0[] = {
  130168. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130169. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130170. };
  130171. static long _vq_quantmap__16u2_p9_0[] = {
  130172. 11, 9, 7, 5, 3, 1, 13, 0,
  130173. 14, 2, 4, 6, 8, 10, 12,
  130174. };
  130175. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130176. _vq_quantthresh__16u2_p9_0,
  130177. _vq_quantmap__16u2_p9_0,
  130178. 15,
  130179. 15
  130180. };
  130181. static static_codebook _16u2_p9_0 = {
  130182. 2, 225,
  130183. _vq_lengthlist__16u2_p9_0,
  130184. 1, -510275072, 1611661312, 14, 0,
  130185. _vq_quantlist__16u2_p9_0,
  130186. NULL,
  130187. &_vq_auxt__16u2_p9_0,
  130188. NULL,
  130189. 0
  130190. };
  130191. static long _vq_quantlist__16u2_p9_1[] = {
  130192. 392,
  130193. 343,
  130194. 441,
  130195. 294,
  130196. 490,
  130197. 245,
  130198. 539,
  130199. 196,
  130200. 588,
  130201. 147,
  130202. 637,
  130203. 98,
  130204. 686,
  130205. 49,
  130206. 735,
  130207. 0,
  130208. 784,
  130209. 388,
  130210. 396,
  130211. };
  130212. static long _vq_lengthlist__16u2_p9_1[] = {
  130213. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130214. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130215. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130216. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130217. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130218. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130219. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130220. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130221. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130222. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130223. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130224. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130225. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130226. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130227. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130228. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130229. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130230. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130231. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130232. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130233. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130234. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130235. 11,11,11,11,11,11,11, 5, 4,
  130236. };
  130237. static float _vq_quantthresh__16u2_p9_1[] = {
  130238. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130239. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130240. 318.5, 367.5,
  130241. };
  130242. static long _vq_quantmap__16u2_p9_1[] = {
  130243. 15, 13, 11, 9, 7, 5, 3, 1,
  130244. 17, 0, 18, 2, 4, 6, 8, 10,
  130245. 12, 14, 16,
  130246. };
  130247. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130248. _vq_quantthresh__16u2_p9_1,
  130249. _vq_quantmap__16u2_p9_1,
  130250. 19,
  130251. 19
  130252. };
  130253. static static_codebook _16u2_p9_1 = {
  130254. 2, 361,
  130255. _vq_lengthlist__16u2_p9_1,
  130256. 1, -518488064, 1611661312, 10, 0,
  130257. _vq_quantlist__16u2_p9_1,
  130258. NULL,
  130259. &_vq_auxt__16u2_p9_1,
  130260. NULL,
  130261. 0
  130262. };
  130263. static long _vq_quantlist__16u2_p9_2[] = {
  130264. 24,
  130265. 23,
  130266. 25,
  130267. 22,
  130268. 26,
  130269. 21,
  130270. 27,
  130271. 20,
  130272. 28,
  130273. 19,
  130274. 29,
  130275. 18,
  130276. 30,
  130277. 17,
  130278. 31,
  130279. 16,
  130280. 32,
  130281. 15,
  130282. 33,
  130283. 14,
  130284. 34,
  130285. 13,
  130286. 35,
  130287. 12,
  130288. 36,
  130289. 11,
  130290. 37,
  130291. 10,
  130292. 38,
  130293. 9,
  130294. 39,
  130295. 8,
  130296. 40,
  130297. 7,
  130298. 41,
  130299. 6,
  130300. 42,
  130301. 5,
  130302. 43,
  130303. 4,
  130304. 44,
  130305. 3,
  130306. 45,
  130307. 2,
  130308. 46,
  130309. 1,
  130310. 47,
  130311. 0,
  130312. 48,
  130313. };
  130314. static long _vq_lengthlist__16u2_p9_2[] = {
  130315. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130316. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130317. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130318. 11,
  130319. };
  130320. static float _vq_quantthresh__16u2_p9_2[] = {
  130321. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130322. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130323. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130324. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130325. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130326. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130327. };
  130328. static long _vq_quantmap__16u2_p9_2[] = {
  130329. 47, 45, 43, 41, 39, 37, 35, 33,
  130330. 31, 29, 27, 25, 23, 21, 19, 17,
  130331. 15, 13, 11, 9, 7, 5, 3, 1,
  130332. 0, 2, 4, 6, 8, 10, 12, 14,
  130333. 16, 18, 20, 22, 24, 26, 28, 30,
  130334. 32, 34, 36, 38, 40, 42, 44, 46,
  130335. 48,
  130336. };
  130337. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130338. _vq_quantthresh__16u2_p9_2,
  130339. _vq_quantmap__16u2_p9_2,
  130340. 49,
  130341. 49
  130342. };
  130343. static static_codebook _16u2_p9_2 = {
  130344. 1, 49,
  130345. _vq_lengthlist__16u2_p9_2,
  130346. 1, -526909440, 1611661312, 6, 0,
  130347. _vq_quantlist__16u2_p9_2,
  130348. NULL,
  130349. &_vq_auxt__16u2_p9_2,
  130350. NULL,
  130351. 0
  130352. };
  130353. static long _vq_quantlist__8u0__p1_0[] = {
  130354. 1,
  130355. 0,
  130356. 2,
  130357. };
  130358. static long _vq_lengthlist__8u0__p1_0[] = {
  130359. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130360. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130361. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130362. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130363. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130364. 11,
  130365. };
  130366. static float _vq_quantthresh__8u0__p1_0[] = {
  130367. -0.5, 0.5,
  130368. };
  130369. static long _vq_quantmap__8u0__p1_0[] = {
  130370. 1, 0, 2,
  130371. };
  130372. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130373. _vq_quantthresh__8u0__p1_0,
  130374. _vq_quantmap__8u0__p1_0,
  130375. 3,
  130376. 3
  130377. };
  130378. static static_codebook _8u0__p1_0 = {
  130379. 4, 81,
  130380. _vq_lengthlist__8u0__p1_0,
  130381. 1, -535822336, 1611661312, 2, 0,
  130382. _vq_quantlist__8u0__p1_0,
  130383. NULL,
  130384. &_vq_auxt__8u0__p1_0,
  130385. NULL,
  130386. 0
  130387. };
  130388. static long _vq_quantlist__8u0__p2_0[] = {
  130389. 1,
  130390. 0,
  130391. 2,
  130392. };
  130393. static long _vq_lengthlist__8u0__p2_0[] = {
  130394. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130395. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130396. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130397. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130398. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130399. 8,
  130400. };
  130401. static float _vq_quantthresh__8u0__p2_0[] = {
  130402. -0.5, 0.5,
  130403. };
  130404. static long _vq_quantmap__8u0__p2_0[] = {
  130405. 1, 0, 2,
  130406. };
  130407. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130408. _vq_quantthresh__8u0__p2_0,
  130409. _vq_quantmap__8u0__p2_0,
  130410. 3,
  130411. 3
  130412. };
  130413. static static_codebook _8u0__p2_0 = {
  130414. 4, 81,
  130415. _vq_lengthlist__8u0__p2_0,
  130416. 1, -535822336, 1611661312, 2, 0,
  130417. _vq_quantlist__8u0__p2_0,
  130418. NULL,
  130419. &_vq_auxt__8u0__p2_0,
  130420. NULL,
  130421. 0
  130422. };
  130423. static long _vq_quantlist__8u0__p3_0[] = {
  130424. 2,
  130425. 1,
  130426. 3,
  130427. 0,
  130428. 4,
  130429. };
  130430. static long _vq_lengthlist__8u0__p3_0[] = {
  130431. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130432. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130433. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130434. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130435. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130436. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130437. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130438. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130439. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130440. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130441. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130442. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130443. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130444. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130445. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130446. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130447. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130448. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130449. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130450. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130451. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130452. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130453. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130454. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130455. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130456. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130457. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130458. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130459. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130460. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130461. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130462. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130463. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130464. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130465. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130466. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130467. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130468. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130469. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130470. 16,
  130471. };
  130472. static float _vq_quantthresh__8u0__p3_0[] = {
  130473. -1.5, -0.5, 0.5, 1.5,
  130474. };
  130475. static long _vq_quantmap__8u0__p3_0[] = {
  130476. 3, 1, 0, 2, 4,
  130477. };
  130478. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130479. _vq_quantthresh__8u0__p3_0,
  130480. _vq_quantmap__8u0__p3_0,
  130481. 5,
  130482. 5
  130483. };
  130484. static static_codebook _8u0__p3_0 = {
  130485. 4, 625,
  130486. _vq_lengthlist__8u0__p3_0,
  130487. 1, -533725184, 1611661312, 3, 0,
  130488. _vq_quantlist__8u0__p3_0,
  130489. NULL,
  130490. &_vq_auxt__8u0__p3_0,
  130491. NULL,
  130492. 0
  130493. };
  130494. static long _vq_quantlist__8u0__p4_0[] = {
  130495. 2,
  130496. 1,
  130497. 3,
  130498. 0,
  130499. 4,
  130500. };
  130501. static long _vq_lengthlist__8u0__p4_0[] = {
  130502. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130503. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130504. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130505. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130506. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130507. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130508. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130509. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130510. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130511. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130512. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130513. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130514. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130515. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130516. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130517. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130518. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130519. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130520. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130521. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130522. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130523. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130524. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130525. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130526. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130527. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130528. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130529. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130530. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130531. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130532. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130533. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130534. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130535. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130536. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130537. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130538. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130539. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130540. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130541. 12,
  130542. };
  130543. static float _vq_quantthresh__8u0__p4_0[] = {
  130544. -1.5, -0.5, 0.5, 1.5,
  130545. };
  130546. static long _vq_quantmap__8u0__p4_0[] = {
  130547. 3, 1, 0, 2, 4,
  130548. };
  130549. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130550. _vq_quantthresh__8u0__p4_0,
  130551. _vq_quantmap__8u0__p4_0,
  130552. 5,
  130553. 5
  130554. };
  130555. static static_codebook _8u0__p4_0 = {
  130556. 4, 625,
  130557. _vq_lengthlist__8u0__p4_0,
  130558. 1, -533725184, 1611661312, 3, 0,
  130559. _vq_quantlist__8u0__p4_0,
  130560. NULL,
  130561. &_vq_auxt__8u0__p4_0,
  130562. NULL,
  130563. 0
  130564. };
  130565. static long _vq_quantlist__8u0__p5_0[] = {
  130566. 4,
  130567. 3,
  130568. 5,
  130569. 2,
  130570. 6,
  130571. 1,
  130572. 7,
  130573. 0,
  130574. 8,
  130575. };
  130576. static long _vq_lengthlist__8u0__p5_0[] = {
  130577. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130578. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130579. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130580. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130581. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130582. 12,
  130583. };
  130584. static float _vq_quantthresh__8u0__p5_0[] = {
  130585. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130586. };
  130587. static long _vq_quantmap__8u0__p5_0[] = {
  130588. 7, 5, 3, 1, 0, 2, 4, 6,
  130589. 8,
  130590. };
  130591. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130592. _vq_quantthresh__8u0__p5_0,
  130593. _vq_quantmap__8u0__p5_0,
  130594. 9,
  130595. 9
  130596. };
  130597. static static_codebook _8u0__p5_0 = {
  130598. 2, 81,
  130599. _vq_lengthlist__8u0__p5_0,
  130600. 1, -531628032, 1611661312, 4, 0,
  130601. _vq_quantlist__8u0__p5_0,
  130602. NULL,
  130603. &_vq_auxt__8u0__p5_0,
  130604. NULL,
  130605. 0
  130606. };
  130607. static long _vq_quantlist__8u0__p6_0[] = {
  130608. 6,
  130609. 5,
  130610. 7,
  130611. 4,
  130612. 8,
  130613. 3,
  130614. 9,
  130615. 2,
  130616. 10,
  130617. 1,
  130618. 11,
  130619. 0,
  130620. 12,
  130621. };
  130622. static long _vq_lengthlist__8u0__p6_0[] = {
  130623. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130624. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130625. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130626. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130627. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130628. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130629. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130630. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130631. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130632. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130633. 16, 0,15, 0,17, 0, 0, 0, 0,
  130634. };
  130635. static float _vq_quantthresh__8u0__p6_0[] = {
  130636. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130637. 12.5, 17.5, 22.5, 27.5,
  130638. };
  130639. static long _vq_quantmap__8u0__p6_0[] = {
  130640. 11, 9, 7, 5, 3, 1, 0, 2,
  130641. 4, 6, 8, 10, 12,
  130642. };
  130643. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130644. _vq_quantthresh__8u0__p6_0,
  130645. _vq_quantmap__8u0__p6_0,
  130646. 13,
  130647. 13
  130648. };
  130649. static static_codebook _8u0__p6_0 = {
  130650. 2, 169,
  130651. _vq_lengthlist__8u0__p6_0,
  130652. 1, -526516224, 1616117760, 4, 0,
  130653. _vq_quantlist__8u0__p6_0,
  130654. NULL,
  130655. &_vq_auxt__8u0__p6_0,
  130656. NULL,
  130657. 0
  130658. };
  130659. static long _vq_quantlist__8u0__p6_1[] = {
  130660. 2,
  130661. 1,
  130662. 3,
  130663. 0,
  130664. 4,
  130665. };
  130666. static long _vq_lengthlist__8u0__p6_1[] = {
  130667. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130668. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130669. };
  130670. static float _vq_quantthresh__8u0__p6_1[] = {
  130671. -1.5, -0.5, 0.5, 1.5,
  130672. };
  130673. static long _vq_quantmap__8u0__p6_1[] = {
  130674. 3, 1, 0, 2, 4,
  130675. };
  130676. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130677. _vq_quantthresh__8u0__p6_1,
  130678. _vq_quantmap__8u0__p6_1,
  130679. 5,
  130680. 5
  130681. };
  130682. static static_codebook _8u0__p6_1 = {
  130683. 2, 25,
  130684. _vq_lengthlist__8u0__p6_1,
  130685. 1, -533725184, 1611661312, 3, 0,
  130686. _vq_quantlist__8u0__p6_1,
  130687. NULL,
  130688. &_vq_auxt__8u0__p6_1,
  130689. NULL,
  130690. 0
  130691. };
  130692. static long _vq_quantlist__8u0__p7_0[] = {
  130693. 1,
  130694. 0,
  130695. 2,
  130696. };
  130697. static long _vq_lengthlist__8u0__p7_0[] = {
  130698. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130699. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130700. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130701. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130702. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130703. 7,
  130704. };
  130705. static float _vq_quantthresh__8u0__p7_0[] = {
  130706. -157.5, 157.5,
  130707. };
  130708. static long _vq_quantmap__8u0__p7_0[] = {
  130709. 1, 0, 2,
  130710. };
  130711. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130712. _vq_quantthresh__8u0__p7_0,
  130713. _vq_quantmap__8u0__p7_0,
  130714. 3,
  130715. 3
  130716. };
  130717. static static_codebook _8u0__p7_0 = {
  130718. 4, 81,
  130719. _vq_lengthlist__8u0__p7_0,
  130720. 1, -518803456, 1628680192, 2, 0,
  130721. _vq_quantlist__8u0__p7_0,
  130722. NULL,
  130723. &_vq_auxt__8u0__p7_0,
  130724. NULL,
  130725. 0
  130726. };
  130727. static long _vq_quantlist__8u0__p7_1[] = {
  130728. 7,
  130729. 6,
  130730. 8,
  130731. 5,
  130732. 9,
  130733. 4,
  130734. 10,
  130735. 3,
  130736. 11,
  130737. 2,
  130738. 12,
  130739. 1,
  130740. 13,
  130741. 0,
  130742. 14,
  130743. };
  130744. static long _vq_lengthlist__8u0__p7_1[] = {
  130745. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130746. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130747. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130748. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130749. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130750. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130751. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130757. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130758. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130759. 10,
  130760. };
  130761. static float _vq_quantthresh__8u0__p7_1[] = {
  130762. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130763. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130764. };
  130765. static long _vq_quantmap__8u0__p7_1[] = {
  130766. 13, 11, 9, 7, 5, 3, 1, 0,
  130767. 2, 4, 6, 8, 10, 12, 14,
  130768. };
  130769. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130770. _vq_quantthresh__8u0__p7_1,
  130771. _vq_quantmap__8u0__p7_1,
  130772. 15,
  130773. 15
  130774. };
  130775. static static_codebook _8u0__p7_1 = {
  130776. 2, 225,
  130777. _vq_lengthlist__8u0__p7_1,
  130778. 1, -520986624, 1620377600, 4, 0,
  130779. _vq_quantlist__8u0__p7_1,
  130780. NULL,
  130781. &_vq_auxt__8u0__p7_1,
  130782. NULL,
  130783. 0
  130784. };
  130785. static long _vq_quantlist__8u0__p7_2[] = {
  130786. 10,
  130787. 9,
  130788. 11,
  130789. 8,
  130790. 12,
  130791. 7,
  130792. 13,
  130793. 6,
  130794. 14,
  130795. 5,
  130796. 15,
  130797. 4,
  130798. 16,
  130799. 3,
  130800. 17,
  130801. 2,
  130802. 18,
  130803. 1,
  130804. 19,
  130805. 0,
  130806. 20,
  130807. };
  130808. static long _vq_lengthlist__8u0__p7_2[] = {
  130809. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130810. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130811. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130812. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130813. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130814. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130815. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130816. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130817. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130818. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130819. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130820. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130821. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130822. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130823. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130824. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130825. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130826. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130827. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130828. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130829. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130830. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130831. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130832. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130833. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130834. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130835. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130836. 11,12,11,11,11,10,10,11,11,
  130837. };
  130838. static float _vq_quantthresh__8u0__p7_2[] = {
  130839. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130840. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130841. 6.5, 7.5, 8.5, 9.5,
  130842. };
  130843. static long _vq_quantmap__8u0__p7_2[] = {
  130844. 19, 17, 15, 13, 11, 9, 7, 5,
  130845. 3, 1, 0, 2, 4, 6, 8, 10,
  130846. 12, 14, 16, 18, 20,
  130847. };
  130848. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130849. _vq_quantthresh__8u0__p7_2,
  130850. _vq_quantmap__8u0__p7_2,
  130851. 21,
  130852. 21
  130853. };
  130854. static static_codebook _8u0__p7_2 = {
  130855. 2, 441,
  130856. _vq_lengthlist__8u0__p7_2,
  130857. 1, -529268736, 1611661312, 5, 0,
  130858. _vq_quantlist__8u0__p7_2,
  130859. NULL,
  130860. &_vq_auxt__8u0__p7_2,
  130861. NULL,
  130862. 0
  130863. };
  130864. static long _huff_lengthlist__8u0__single[] = {
  130865. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130866. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130867. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130868. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130869. };
  130870. static static_codebook _huff_book__8u0__single = {
  130871. 2, 64,
  130872. _huff_lengthlist__8u0__single,
  130873. 0, 0, 0, 0, 0,
  130874. NULL,
  130875. NULL,
  130876. NULL,
  130877. NULL,
  130878. 0
  130879. };
  130880. static long _vq_quantlist__8u1__p1_0[] = {
  130881. 1,
  130882. 0,
  130883. 2,
  130884. };
  130885. static long _vq_lengthlist__8u1__p1_0[] = {
  130886. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130887. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130888. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130889. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130890. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130891. 10,
  130892. };
  130893. static float _vq_quantthresh__8u1__p1_0[] = {
  130894. -0.5, 0.5,
  130895. };
  130896. static long _vq_quantmap__8u1__p1_0[] = {
  130897. 1, 0, 2,
  130898. };
  130899. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130900. _vq_quantthresh__8u1__p1_0,
  130901. _vq_quantmap__8u1__p1_0,
  130902. 3,
  130903. 3
  130904. };
  130905. static static_codebook _8u1__p1_0 = {
  130906. 4, 81,
  130907. _vq_lengthlist__8u1__p1_0,
  130908. 1, -535822336, 1611661312, 2, 0,
  130909. _vq_quantlist__8u1__p1_0,
  130910. NULL,
  130911. &_vq_auxt__8u1__p1_0,
  130912. NULL,
  130913. 0
  130914. };
  130915. static long _vq_quantlist__8u1__p2_0[] = {
  130916. 1,
  130917. 0,
  130918. 2,
  130919. };
  130920. static long _vq_lengthlist__8u1__p2_0[] = {
  130921. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130922. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130923. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130924. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130925. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130926. 7,
  130927. };
  130928. static float _vq_quantthresh__8u1__p2_0[] = {
  130929. -0.5, 0.5,
  130930. };
  130931. static long _vq_quantmap__8u1__p2_0[] = {
  130932. 1, 0, 2,
  130933. };
  130934. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  130935. _vq_quantthresh__8u1__p2_0,
  130936. _vq_quantmap__8u1__p2_0,
  130937. 3,
  130938. 3
  130939. };
  130940. static static_codebook _8u1__p2_0 = {
  130941. 4, 81,
  130942. _vq_lengthlist__8u1__p2_0,
  130943. 1, -535822336, 1611661312, 2, 0,
  130944. _vq_quantlist__8u1__p2_0,
  130945. NULL,
  130946. &_vq_auxt__8u1__p2_0,
  130947. NULL,
  130948. 0
  130949. };
  130950. static long _vq_quantlist__8u1__p3_0[] = {
  130951. 2,
  130952. 1,
  130953. 3,
  130954. 0,
  130955. 4,
  130956. };
  130957. static long _vq_lengthlist__8u1__p3_0[] = {
  130958. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130959. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130960. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  130961. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  130962. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  130963. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  130964. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  130965. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  130966. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  130967. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  130968. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  130969. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  130970. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  130971. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  130972. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  130973. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  130974. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  130975. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  130976. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  130977. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  130978. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  130979. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  130980. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  130981. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  130982. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  130983. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  130984. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  130985. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  130986. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  130987. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  130988. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  130989. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  130990. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  130991. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  130992. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  130993. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  130994. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  130995. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  130996. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  130997. 16,
  130998. };
  130999. static float _vq_quantthresh__8u1__p3_0[] = {
  131000. -1.5, -0.5, 0.5, 1.5,
  131001. };
  131002. static long _vq_quantmap__8u1__p3_0[] = {
  131003. 3, 1, 0, 2, 4,
  131004. };
  131005. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131006. _vq_quantthresh__8u1__p3_0,
  131007. _vq_quantmap__8u1__p3_0,
  131008. 5,
  131009. 5
  131010. };
  131011. static static_codebook _8u1__p3_0 = {
  131012. 4, 625,
  131013. _vq_lengthlist__8u1__p3_0,
  131014. 1, -533725184, 1611661312, 3, 0,
  131015. _vq_quantlist__8u1__p3_0,
  131016. NULL,
  131017. &_vq_auxt__8u1__p3_0,
  131018. NULL,
  131019. 0
  131020. };
  131021. static long _vq_quantlist__8u1__p4_0[] = {
  131022. 2,
  131023. 1,
  131024. 3,
  131025. 0,
  131026. 4,
  131027. };
  131028. static long _vq_lengthlist__8u1__p4_0[] = {
  131029. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131030. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131031. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131032. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131033. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131034. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131035. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131036. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131037. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131038. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131039. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131040. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131041. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131042. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131043. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131044. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131045. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131046. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131047. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131048. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131049. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131050. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131051. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131052. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131053. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131054. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131055. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131056. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131057. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131058. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131059. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131060. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131061. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131062. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131063. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131064. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131065. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131066. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131067. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131068. 10,
  131069. };
  131070. static float _vq_quantthresh__8u1__p4_0[] = {
  131071. -1.5, -0.5, 0.5, 1.5,
  131072. };
  131073. static long _vq_quantmap__8u1__p4_0[] = {
  131074. 3, 1, 0, 2, 4,
  131075. };
  131076. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131077. _vq_quantthresh__8u1__p4_0,
  131078. _vq_quantmap__8u1__p4_0,
  131079. 5,
  131080. 5
  131081. };
  131082. static static_codebook _8u1__p4_0 = {
  131083. 4, 625,
  131084. _vq_lengthlist__8u1__p4_0,
  131085. 1, -533725184, 1611661312, 3, 0,
  131086. _vq_quantlist__8u1__p4_0,
  131087. NULL,
  131088. &_vq_auxt__8u1__p4_0,
  131089. NULL,
  131090. 0
  131091. };
  131092. static long _vq_quantlist__8u1__p5_0[] = {
  131093. 4,
  131094. 3,
  131095. 5,
  131096. 2,
  131097. 6,
  131098. 1,
  131099. 7,
  131100. 0,
  131101. 8,
  131102. };
  131103. static long _vq_lengthlist__8u1__p5_0[] = {
  131104. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131105. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131106. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131107. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131108. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131109. 13,
  131110. };
  131111. static float _vq_quantthresh__8u1__p5_0[] = {
  131112. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131113. };
  131114. static long _vq_quantmap__8u1__p5_0[] = {
  131115. 7, 5, 3, 1, 0, 2, 4, 6,
  131116. 8,
  131117. };
  131118. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131119. _vq_quantthresh__8u1__p5_0,
  131120. _vq_quantmap__8u1__p5_0,
  131121. 9,
  131122. 9
  131123. };
  131124. static static_codebook _8u1__p5_0 = {
  131125. 2, 81,
  131126. _vq_lengthlist__8u1__p5_0,
  131127. 1, -531628032, 1611661312, 4, 0,
  131128. _vq_quantlist__8u1__p5_0,
  131129. NULL,
  131130. &_vq_auxt__8u1__p5_0,
  131131. NULL,
  131132. 0
  131133. };
  131134. static long _vq_quantlist__8u1__p6_0[] = {
  131135. 4,
  131136. 3,
  131137. 5,
  131138. 2,
  131139. 6,
  131140. 1,
  131141. 7,
  131142. 0,
  131143. 8,
  131144. };
  131145. static long _vq_lengthlist__8u1__p6_0[] = {
  131146. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131147. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131148. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131149. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131150. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131151. 10,
  131152. };
  131153. static float _vq_quantthresh__8u1__p6_0[] = {
  131154. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131155. };
  131156. static long _vq_quantmap__8u1__p6_0[] = {
  131157. 7, 5, 3, 1, 0, 2, 4, 6,
  131158. 8,
  131159. };
  131160. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131161. _vq_quantthresh__8u1__p6_0,
  131162. _vq_quantmap__8u1__p6_0,
  131163. 9,
  131164. 9
  131165. };
  131166. static static_codebook _8u1__p6_0 = {
  131167. 2, 81,
  131168. _vq_lengthlist__8u1__p6_0,
  131169. 1, -531628032, 1611661312, 4, 0,
  131170. _vq_quantlist__8u1__p6_0,
  131171. NULL,
  131172. &_vq_auxt__8u1__p6_0,
  131173. NULL,
  131174. 0
  131175. };
  131176. static long _vq_quantlist__8u1__p7_0[] = {
  131177. 1,
  131178. 0,
  131179. 2,
  131180. };
  131181. static long _vq_lengthlist__8u1__p7_0[] = {
  131182. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131183. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131184. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131185. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131186. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131187. 11,
  131188. };
  131189. static float _vq_quantthresh__8u1__p7_0[] = {
  131190. -5.5, 5.5,
  131191. };
  131192. static long _vq_quantmap__8u1__p7_0[] = {
  131193. 1, 0, 2,
  131194. };
  131195. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131196. _vq_quantthresh__8u1__p7_0,
  131197. _vq_quantmap__8u1__p7_0,
  131198. 3,
  131199. 3
  131200. };
  131201. static static_codebook _8u1__p7_0 = {
  131202. 4, 81,
  131203. _vq_lengthlist__8u1__p7_0,
  131204. 1, -529137664, 1618345984, 2, 0,
  131205. _vq_quantlist__8u1__p7_0,
  131206. NULL,
  131207. &_vq_auxt__8u1__p7_0,
  131208. NULL,
  131209. 0
  131210. };
  131211. static long _vq_quantlist__8u1__p7_1[] = {
  131212. 5,
  131213. 4,
  131214. 6,
  131215. 3,
  131216. 7,
  131217. 2,
  131218. 8,
  131219. 1,
  131220. 9,
  131221. 0,
  131222. 10,
  131223. };
  131224. static long _vq_lengthlist__8u1__p7_1[] = {
  131225. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131226. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131227. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131228. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131229. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131230. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131231. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131232. 9, 9, 9, 9, 9,10,10,10,10,
  131233. };
  131234. static float _vq_quantthresh__8u1__p7_1[] = {
  131235. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131236. 3.5, 4.5,
  131237. };
  131238. static long _vq_quantmap__8u1__p7_1[] = {
  131239. 9, 7, 5, 3, 1, 0, 2, 4,
  131240. 6, 8, 10,
  131241. };
  131242. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131243. _vq_quantthresh__8u1__p7_1,
  131244. _vq_quantmap__8u1__p7_1,
  131245. 11,
  131246. 11
  131247. };
  131248. static static_codebook _8u1__p7_1 = {
  131249. 2, 121,
  131250. _vq_lengthlist__8u1__p7_1,
  131251. 1, -531365888, 1611661312, 4, 0,
  131252. _vq_quantlist__8u1__p7_1,
  131253. NULL,
  131254. &_vq_auxt__8u1__p7_1,
  131255. NULL,
  131256. 0
  131257. };
  131258. static long _vq_quantlist__8u1__p8_0[] = {
  131259. 5,
  131260. 4,
  131261. 6,
  131262. 3,
  131263. 7,
  131264. 2,
  131265. 8,
  131266. 1,
  131267. 9,
  131268. 0,
  131269. 10,
  131270. };
  131271. static long _vq_lengthlist__8u1__p8_0[] = {
  131272. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131273. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131274. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131275. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131276. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131277. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131278. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131279. 12,13,13,14,14,15,15,15,15,
  131280. };
  131281. static float _vq_quantthresh__8u1__p8_0[] = {
  131282. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131283. 38.5, 49.5,
  131284. };
  131285. static long _vq_quantmap__8u1__p8_0[] = {
  131286. 9, 7, 5, 3, 1, 0, 2, 4,
  131287. 6, 8, 10,
  131288. };
  131289. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131290. _vq_quantthresh__8u1__p8_0,
  131291. _vq_quantmap__8u1__p8_0,
  131292. 11,
  131293. 11
  131294. };
  131295. static static_codebook _8u1__p8_0 = {
  131296. 2, 121,
  131297. _vq_lengthlist__8u1__p8_0,
  131298. 1, -524582912, 1618345984, 4, 0,
  131299. _vq_quantlist__8u1__p8_0,
  131300. NULL,
  131301. &_vq_auxt__8u1__p8_0,
  131302. NULL,
  131303. 0
  131304. };
  131305. static long _vq_quantlist__8u1__p8_1[] = {
  131306. 5,
  131307. 4,
  131308. 6,
  131309. 3,
  131310. 7,
  131311. 2,
  131312. 8,
  131313. 1,
  131314. 9,
  131315. 0,
  131316. 10,
  131317. };
  131318. static long _vq_lengthlist__8u1__p8_1[] = {
  131319. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131320. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131321. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131322. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131323. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131324. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131325. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131326. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131327. };
  131328. static float _vq_quantthresh__8u1__p8_1[] = {
  131329. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131330. 3.5, 4.5,
  131331. };
  131332. static long _vq_quantmap__8u1__p8_1[] = {
  131333. 9, 7, 5, 3, 1, 0, 2, 4,
  131334. 6, 8, 10,
  131335. };
  131336. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131337. _vq_quantthresh__8u1__p8_1,
  131338. _vq_quantmap__8u1__p8_1,
  131339. 11,
  131340. 11
  131341. };
  131342. static static_codebook _8u1__p8_1 = {
  131343. 2, 121,
  131344. _vq_lengthlist__8u1__p8_1,
  131345. 1, -531365888, 1611661312, 4, 0,
  131346. _vq_quantlist__8u1__p8_1,
  131347. NULL,
  131348. &_vq_auxt__8u1__p8_1,
  131349. NULL,
  131350. 0
  131351. };
  131352. static long _vq_quantlist__8u1__p9_0[] = {
  131353. 7,
  131354. 6,
  131355. 8,
  131356. 5,
  131357. 9,
  131358. 4,
  131359. 10,
  131360. 3,
  131361. 11,
  131362. 2,
  131363. 12,
  131364. 1,
  131365. 13,
  131366. 0,
  131367. 14,
  131368. };
  131369. static long _vq_lengthlist__8u1__p9_0[] = {
  131370. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131371. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131372. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131373. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131374. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131375. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131376. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131377. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131378. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131379. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131380. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131381. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131382. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131383. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131384. 10,
  131385. };
  131386. static float _vq_quantthresh__8u1__p9_0[] = {
  131387. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131388. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131389. };
  131390. static long _vq_quantmap__8u1__p9_0[] = {
  131391. 13, 11, 9, 7, 5, 3, 1, 0,
  131392. 2, 4, 6, 8, 10, 12, 14,
  131393. };
  131394. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131395. _vq_quantthresh__8u1__p9_0,
  131396. _vq_quantmap__8u1__p9_0,
  131397. 15,
  131398. 15
  131399. };
  131400. static static_codebook _8u1__p9_0 = {
  131401. 2, 225,
  131402. _vq_lengthlist__8u1__p9_0,
  131403. 1, -514071552, 1627381760, 4, 0,
  131404. _vq_quantlist__8u1__p9_0,
  131405. NULL,
  131406. &_vq_auxt__8u1__p9_0,
  131407. NULL,
  131408. 0
  131409. };
  131410. static long _vq_quantlist__8u1__p9_1[] = {
  131411. 7,
  131412. 6,
  131413. 8,
  131414. 5,
  131415. 9,
  131416. 4,
  131417. 10,
  131418. 3,
  131419. 11,
  131420. 2,
  131421. 12,
  131422. 1,
  131423. 13,
  131424. 0,
  131425. 14,
  131426. };
  131427. static long _vq_lengthlist__8u1__p9_1[] = {
  131428. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131429. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131430. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131431. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131432. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131433. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131434. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131435. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131436. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131437. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131438. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131439. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131440. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131441. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131442. 13,
  131443. };
  131444. static float _vq_quantthresh__8u1__p9_1[] = {
  131445. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131446. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131447. };
  131448. static long _vq_quantmap__8u1__p9_1[] = {
  131449. 13, 11, 9, 7, 5, 3, 1, 0,
  131450. 2, 4, 6, 8, 10, 12, 14,
  131451. };
  131452. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131453. _vq_quantthresh__8u1__p9_1,
  131454. _vq_quantmap__8u1__p9_1,
  131455. 15,
  131456. 15
  131457. };
  131458. static static_codebook _8u1__p9_1 = {
  131459. 2, 225,
  131460. _vq_lengthlist__8u1__p9_1,
  131461. 1, -522338304, 1620115456, 4, 0,
  131462. _vq_quantlist__8u1__p9_1,
  131463. NULL,
  131464. &_vq_auxt__8u1__p9_1,
  131465. NULL,
  131466. 0
  131467. };
  131468. static long _vq_quantlist__8u1__p9_2[] = {
  131469. 8,
  131470. 7,
  131471. 9,
  131472. 6,
  131473. 10,
  131474. 5,
  131475. 11,
  131476. 4,
  131477. 12,
  131478. 3,
  131479. 13,
  131480. 2,
  131481. 14,
  131482. 1,
  131483. 15,
  131484. 0,
  131485. 16,
  131486. };
  131487. static long _vq_lengthlist__8u1__p9_2[] = {
  131488. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131489. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131490. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131491. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131492. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131493. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131494. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131495. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131496. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131497. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131498. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131499. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131500. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131501. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131502. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131503. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131504. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131505. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131506. 10,
  131507. };
  131508. static float _vq_quantthresh__8u1__p9_2[] = {
  131509. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131510. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131511. };
  131512. static long _vq_quantmap__8u1__p9_2[] = {
  131513. 15, 13, 11, 9, 7, 5, 3, 1,
  131514. 0, 2, 4, 6, 8, 10, 12, 14,
  131515. 16,
  131516. };
  131517. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131518. _vq_quantthresh__8u1__p9_2,
  131519. _vq_quantmap__8u1__p9_2,
  131520. 17,
  131521. 17
  131522. };
  131523. static static_codebook _8u1__p9_2 = {
  131524. 2, 289,
  131525. _vq_lengthlist__8u1__p9_2,
  131526. 1, -529530880, 1611661312, 5, 0,
  131527. _vq_quantlist__8u1__p9_2,
  131528. NULL,
  131529. &_vq_auxt__8u1__p9_2,
  131530. NULL,
  131531. 0
  131532. };
  131533. static long _huff_lengthlist__8u1__single[] = {
  131534. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131535. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131536. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131537. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131538. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131539. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131540. 13, 8, 8,15,
  131541. };
  131542. static static_codebook _huff_book__8u1__single = {
  131543. 2, 100,
  131544. _huff_lengthlist__8u1__single,
  131545. 0, 0, 0, 0, 0,
  131546. NULL,
  131547. NULL,
  131548. NULL,
  131549. NULL,
  131550. 0
  131551. };
  131552. static long _huff_lengthlist__44u0__long[] = {
  131553. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131554. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131555. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131556. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131557. };
  131558. static static_codebook _huff_book__44u0__long = {
  131559. 2, 64,
  131560. _huff_lengthlist__44u0__long,
  131561. 0, 0, 0, 0, 0,
  131562. NULL,
  131563. NULL,
  131564. NULL,
  131565. NULL,
  131566. 0
  131567. };
  131568. static long _vq_quantlist__44u0__p1_0[] = {
  131569. 1,
  131570. 0,
  131571. 2,
  131572. };
  131573. static long _vq_lengthlist__44u0__p1_0[] = {
  131574. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131575. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131576. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131577. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131578. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131579. 13,
  131580. };
  131581. static float _vq_quantthresh__44u0__p1_0[] = {
  131582. -0.5, 0.5,
  131583. };
  131584. static long _vq_quantmap__44u0__p1_0[] = {
  131585. 1, 0, 2,
  131586. };
  131587. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131588. _vq_quantthresh__44u0__p1_0,
  131589. _vq_quantmap__44u0__p1_0,
  131590. 3,
  131591. 3
  131592. };
  131593. static static_codebook _44u0__p1_0 = {
  131594. 4, 81,
  131595. _vq_lengthlist__44u0__p1_0,
  131596. 1, -535822336, 1611661312, 2, 0,
  131597. _vq_quantlist__44u0__p1_0,
  131598. NULL,
  131599. &_vq_auxt__44u0__p1_0,
  131600. NULL,
  131601. 0
  131602. };
  131603. static long _vq_quantlist__44u0__p2_0[] = {
  131604. 1,
  131605. 0,
  131606. 2,
  131607. };
  131608. static long _vq_lengthlist__44u0__p2_0[] = {
  131609. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131610. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131611. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131612. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131613. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131614. 9,
  131615. };
  131616. static float _vq_quantthresh__44u0__p2_0[] = {
  131617. -0.5, 0.5,
  131618. };
  131619. static long _vq_quantmap__44u0__p2_0[] = {
  131620. 1, 0, 2,
  131621. };
  131622. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131623. _vq_quantthresh__44u0__p2_0,
  131624. _vq_quantmap__44u0__p2_0,
  131625. 3,
  131626. 3
  131627. };
  131628. static static_codebook _44u0__p2_0 = {
  131629. 4, 81,
  131630. _vq_lengthlist__44u0__p2_0,
  131631. 1, -535822336, 1611661312, 2, 0,
  131632. _vq_quantlist__44u0__p2_0,
  131633. NULL,
  131634. &_vq_auxt__44u0__p2_0,
  131635. NULL,
  131636. 0
  131637. };
  131638. static long _vq_quantlist__44u0__p3_0[] = {
  131639. 2,
  131640. 1,
  131641. 3,
  131642. 0,
  131643. 4,
  131644. };
  131645. static long _vq_lengthlist__44u0__p3_0[] = {
  131646. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131647. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131648. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131649. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131650. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131651. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131652. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131653. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131654. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131655. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131656. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131657. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131658. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131659. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131660. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131661. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131662. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131663. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131664. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131665. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131666. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131667. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131668. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131669. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131670. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131671. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131672. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131673. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131674. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131675. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131676. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131677. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131678. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131679. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131680. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131681. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131682. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131683. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131684. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131685. 19,
  131686. };
  131687. static float _vq_quantthresh__44u0__p3_0[] = {
  131688. -1.5, -0.5, 0.5, 1.5,
  131689. };
  131690. static long _vq_quantmap__44u0__p3_0[] = {
  131691. 3, 1, 0, 2, 4,
  131692. };
  131693. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131694. _vq_quantthresh__44u0__p3_0,
  131695. _vq_quantmap__44u0__p3_0,
  131696. 5,
  131697. 5
  131698. };
  131699. static static_codebook _44u0__p3_0 = {
  131700. 4, 625,
  131701. _vq_lengthlist__44u0__p3_0,
  131702. 1, -533725184, 1611661312, 3, 0,
  131703. _vq_quantlist__44u0__p3_0,
  131704. NULL,
  131705. &_vq_auxt__44u0__p3_0,
  131706. NULL,
  131707. 0
  131708. };
  131709. static long _vq_quantlist__44u0__p4_0[] = {
  131710. 2,
  131711. 1,
  131712. 3,
  131713. 0,
  131714. 4,
  131715. };
  131716. static long _vq_lengthlist__44u0__p4_0[] = {
  131717. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131718. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131719. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131720. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131721. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131722. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131723. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131724. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131725. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131726. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131727. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131728. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131729. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131730. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131731. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131732. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131733. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131734. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131735. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131736. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131737. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131738. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131739. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131740. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131741. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131742. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131743. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131744. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131745. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131746. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131747. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131748. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131749. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131750. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131751. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131752. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131753. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131754. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131755. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131756. 12,
  131757. };
  131758. static float _vq_quantthresh__44u0__p4_0[] = {
  131759. -1.5, -0.5, 0.5, 1.5,
  131760. };
  131761. static long _vq_quantmap__44u0__p4_0[] = {
  131762. 3, 1, 0, 2, 4,
  131763. };
  131764. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131765. _vq_quantthresh__44u0__p4_0,
  131766. _vq_quantmap__44u0__p4_0,
  131767. 5,
  131768. 5
  131769. };
  131770. static static_codebook _44u0__p4_0 = {
  131771. 4, 625,
  131772. _vq_lengthlist__44u0__p4_0,
  131773. 1, -533725184, 1611661312, 3, 0,
  131774. _vq_quantlist__44u0__p4_0,
  131775. NULL,
  131776. &_vq_auxt__44u0__p4_0,
  131777. NULL,
  131778. 0
  131779. };
  131780. static long _vq_quantlist__44u0__p5_0[] = {
  131781. 4,
  131782. 3,
  131783. 5,
  131784. 2,
  131785. 6,
  131786. 1,
  131787. 7,
  131788. 0,
  131789. 8,
  131790. };
  131791. static long _vq_lengthlist__44u0__p5_0[] = {
  131792. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131793. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131794. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131795. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131796. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131797. 12,
  131798. };
  131799. static float _vq_quantthresh__44u0__p5_0[] = {
  131800. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131801. };
  131802. static long _vq_quantmap__44u0__p5_0[] = {
  131803. 7, 5, 3, 1, 0, 2, 4, 6,
  131804. 8,
  131805. };
  131806. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131807. _vq_quantthresh__44u0__p5_0,
  131808. _vq_quantmap__44u0__p5_0,
  131809. 9,
  131810. 9
  131811. };
  131812. static static_codebook _44u0__p5_0 = {
  131813. 2, 81,
  131814. _vq_lengthlist__44u0__p5_0,
  131815. 1, -531628032, 1611661312, 4, 0,
  131816. _vq_quantlist__44u0__p5_0,
  131817. NULL,
  131818. &_vq_auxt__44u0__p5_0,
  131819. NULL,
  131820. 0
  131821. };
  131822. static long _vq_quantlist__44u0__p6_0[] = {
  131823. 6,
  131824. 5,
  131825. 7,
  131826. 4,
  131827. 8,
  131828. 3,
  131829. 9,
  131830. 2,
  131831. 10,
  131832. 1,
  131833. 11,
  131834. 0,
  131835. 12,
  131836. };
  131837. static long _vq_lengthlist__44u0__p6_0[] = {
  131838. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131839. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131840. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131841. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131842. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131843. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131844. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131845. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131846. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131847. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131848. 15,17,16,17,18,17,17,18, 0,
  131849. };
  131850. static float _vq_quantthresh__44u0__p6_0[] = {
  131851. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131852. 12.5, 17.5, 22.5, 27.5,
  131853. };
  131854. static long _vq_quantmap__44u0__p6_0[] = {
  131855. 11, 9, 7, 5, 3, 1, 0, 2,
  131856. 4, 6, 8, 10, 12,
  131857. };
  131858. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131859. _vq_quantthresh__44u0__p6_0,
  131860. _vq_quantmap__44u0__p6_0,
  131861. 13,
  131862. 13
  131863. };
  131864. static static_codebook _44u0__p6_0 = {
  131865. 2, 169,
  131866. _vq_lengthlist__44u0__p6_0,
  131867. 1, -526516224, 1616117760, 4, 0,
  131868. _vq_quantlist__44u0__p6_0,
  131869. NULL,
  131870. &_vq_auxt__44u0__p6_0,
  131871. NULL,
  131872. 0
  131873. };
  131874. static long _vq_quantlist__44u0__p6_1[] = {
  131875. 2,
  131876. 1,
  131877. 3,
  131878. 0,
  131879. 4,
  131880. };
  131881. static long _vq_lengthlist__44u0__p6_1[] = {
  131882. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131883. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131884. };
  131885. static float _vq_quantthresh__44u0__p6_1[] = {
  131886. -1.5, -0.5, 0.5, 1.5,
  131887. };
  131888. static long _vq_quantmap__44u0__p6_1[] = {
  131889. 3, 1, 0, 2, 4,
  131890. };
  131891. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131892. _vq_quantthresh__44u0__p6_1,
  131893. _vq_quantmap__44u0__p6_1,
  131894. 5,
  131895. 5
  131896. };
  131897. static static_codebook _44u0__p6_1 = {
  131898. 2, 25,
  131899. _vq_lengthlist__44u0__p6_1,
  131900. 1, -533725184, 1611661312, 3, 0,
  131901. _vq_quantlist__44u0__p6_1,
  131902. NULL,
  131903. &_vq_auxt__44u0__p6_1,
  131904. NULL,
  131905. 0
  131906. };
  131907. static long _vq_quantlist__44u0__p7_0[] = {
  131908. 2,
  131909. 1,
  131910. 3,
  131911. 0,
  131912. 4,
  131913. };
  131914. static long _vq_lengthlist__44u0__p7_0[] = {
  131915. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131916. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131917. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131918. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131919. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131920. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131921. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131922. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131923. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131924. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131925. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131926. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131927. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131928. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131929. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131930. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131931. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131932. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131933. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131934. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131935. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131936. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131937. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131938. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131939. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131940. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131941. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131942. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131943. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131944. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131945. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  131946. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131947. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131948. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131949. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131950. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131951. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131952. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131953. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131954. 10,
  131955. };
  131956. static float _vq_quantthresh__44u0__p7_0[] = {
  131957. -253.5, -84.5, 84.5, 253.5,
  131958. };
  131959. static long _vq_quantmap__44u0__p7_0[] = {
  131960. 3, 1, 0, 2, 4,
  131961. };
  131962. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  131963. _vq_quantthresh__44u0__p7_0,
  131964. _vq_quantmap__44u0__p7_0,
  131965. 5,
  131966. 5
  131967. };
  131968. static static_codebook _44u0__p7_0 = {
  131969. 4, 625,
  131970. _vq_lengthlist__44u0__p7_0,
  131971. 1, -518709248, 1626677248, 3, 0,
  131972. _vq_quantlist__44u0__p7_0,
  131973. NULL,
  131974. &_vq_auxt__44u0__p7_0,
  131975. NULL,
  131976. 0
  131977. };
  131978. static long _vq_quantlist__44u0__p7_1[] = {
  131979. 6,
  131980. 5,
  131981. 7,
  131982. 4,
  131983. 8,
  131984. 3,
  131985. 9,
  131986. 2,
  131987. 10,
  131988. 1,
  131989. 11,
  131990. 0,
  131991. 12,
  131992. };
  131993. static long _vq_lengthlist__44u0__p7_1[] = {
  131994. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  131995. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  131996. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  131997. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  131998. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  131999. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132000. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132001. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132002. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132003. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132004. 15,15,15,15,15,15,15,15,15,
  132005. };
  132006. static float _vq_quantthresh__44u0__p7_1[] = {
  132007. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132008. 32.5, 45.5, 58.5, 71.5,
  132009. };
  132010. static long _vq_quantmap__44u0__p7_1[] = {
  132011. 11, 9, 7, 5, 3, 1, 0, 2,
  132012. 4, 6, 8, 10, 12,
  132013. };
  132014. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132015. _vq_quantthresh__44u0__p7_1,
  132016. _vq_quantmap__44u0__p7_1,
  132017. 13,
  132018. 13
  132019. };
  132020. static static_codebook _44u0__p7_1 = {
  132021. 2, 169,
  132022. _vq_lengthlist__44u0__p7_1,
  132023. 1, -523010048, 1618608128, 4, 0,
  132024. _vq_quantlist__44u0__p7_1,
  132025. NULL,
  132026. &_vq_auxt__44u0__p7_1,
  132027. NULL,
  132028. 0
  132029. };
  132030. static long _vq_quantlist__44u0__p7_2[] = {
  132031. 6,
  132032. 5,
  132033. 7,
  132034. 4,
  132035. 8,
  132036. 3,
  132037. 9,
  132038. 2,
  132039. 10,
  132040. 1,
  132041. 11,
  132042. 0,
  132043. 12,
  132044. };
  132045. static long _vq_lengthlist__44u0__p7_2[] = {
  132046. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132047. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132048. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132049. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132050. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132051. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132052. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132053. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132054. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132055. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132056. 9, 9, 9,10, 9, 9,10,10, 9,
  132057. };
  132058. static float _vq_quantthresh__44u0__p7_2[] = {
  132059. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132060. 2.5, 3.5, 4.5, 5.5,
  132061. };
  132062. static long _vq_quantmap__44u0__p7_2[] = {
  132063. 11, 9, 7, 5, 3, 1, 0, 2,
  132064. 4, 6, 8, 10, 12,
  132065. };
  132066. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132067. _vq_quantthresh__44u0__p7_2,
  132068. _vq_quantmap__44u0__p7_2,
  132069. 13,
  132070. 13
  132071. };
  132072. static static_codebook _44u0__p7_2 = {
  132073. 2, 169,
  132074. _vq_lengthlist__44u0__p7_2,
  132075. 1, -531103744, 1611661312, 4, 0,
  132076. _vq_quantlist__44u0__p7_2,
  132077. NULL,
  132078. &_vq_auxt__44u0__p7_2,
  132079. NULL,
  132080. 0
  132081. };
  132082. static long _huff_lengthlist__44u0__short[] = {
  132083. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132084. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132085. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132086. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132087. };
  132088. static static_codebook _huff_book__44u0__short = {
  132089. 2, 64,
  132090. _huff_lengthlist__44u0__short,
  132091. 0, 0, 0, 0, 0,
  132092. NULL,
  132093. NULL,
  132094. NULL,
  132095. NULL,
  132096. 0
  132097. };
  132098. static long _huff_lengthlist__44u1__long[] = {
  132099. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132100. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132101. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132102. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132103. };
  132104. static static_codebook _huff_book__44u1__long = {
  132105. 2, 64,
  132106. _huff_lengthlist__44u1__long,
  132107. 0, 0, 0, 0, 0,
  132108. NULL,
  132109. NULL,
  132110. NULL,
  132111. NULL,
  132112. 0
  132113. };
  132114. static long _vq_quantlist__44u1__p1_0[] = {
  132115. 1,
  132116. 0,
  132117. 2,
  132118. };
  132119. static long _vq_lengthlist__44u1__p1_0[] = {
  132120. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132121. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132122. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132123. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132124. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132125. 13,
  132126. };
  132127. static float _vq_quantthresh__44u1__p1_0[] = {
  132128. -0.5, 0.5,
  132129. };
  132130. static long _vq_quantmap__44u1__p1_0[] = {
  132131. 1, 0, 2,
  132132. };
  132133. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132134. _vq_quantthresh__44u1__p1_0,
  132135. _vq_quantmap__44u1__p1_0,
  132136. 3,
  132137. 3
  132138. };
  132139. static static_codebook _44u1__p1_0 = {
  132140. 4, 81,
  132141. _vq_lengthlist__44u1__p1_0,
  132142. 1, -535822336, 1611661312, 2, 0,
  132143. _vq_quantlist__44u1__p1_0,
  132144. NULL,
  132145. &_vq_auxt__44u1__p1_0,
  132146. NULL,
  132147. 0
  132148. };
  132149. static long _vq_quantlist__44u1__p2_0[] = {
  132150. 1,
  132151. 0,
  132152. 2,
  132153. };
  132154. static long _vq_lengthlist__44u1__p2_0[] = {
  132155. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132156. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132157. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132158. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132159. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132160. 9,
  132161. };
  132162. static float _vq_quantthresh__44u1__p2_0[] = {
  132163. -0.5, 0.5,
  132164. };
  132165. static long _vq_quantmap__44u1__p2_0[] = {
  132166. 1, 0, 2,
  132167. };
  132168. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132169. _vq_quantthresh__44u1__p2_0,
  132170. _vq_quantmap__44u1__p2_0,
  132171. 3,
  132172. 3
  132173. };
  132174. static static_codebook _44u1__p2_0 = {
  132175. 4, 81,
  132176. _vq_lengthlist__44u1__p2_0,
  132177. 1, -535822336, 1611661312, 2, 0,
  132178. _vq_quantlist__44u1__p2_0,
  132179. NULL,
  132180. &_vq_auxt__44u1__p2_0,
  132181. NULL,
  132182. 0
  132183. };
  132184. static long _vq_quantlist__44u1__p3_0[] = {
  132185. 2,
  132186. 1,
  132187. 3,
  132188. 0,
  132189. 4,
  132190. };
  132191. static long _vq_lengthlist__44u1__p3_0[] = {
  132192. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132193. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132194. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132195. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132196. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132197. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132198. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132199. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132200. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132201. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132202. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132203. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132204. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132205. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132206. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132207. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132208. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132209. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132210. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132211. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132212. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132213. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132214. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132215. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132216. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132217. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132218. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132219. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132220. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132221. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132222. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132223. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132224. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132225. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132226. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132227. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132228. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132229. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132230. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132231. 19,
  132232. };
  132233. static float _vq_quantthresh__44u1__p3_0[] = {
  132234. -1.5, -0.5, 0.5, 1.5,
  132235. };
  132236. static long _vq_quantmap__44u1__p3_0[] = {
  132237. 3, 1, 0, 2, 4,
  132238. };
  132239. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132240. _vq_quantthresh__44u1__p3_0,
  132241. _vq_quantmap__44u1__p3_0,
  132242. 5,
  132243. 5
  132244. };
  132245. static static_codebook _44u1__p3_0 = {
  132246. 4, 625,
  132247. _vq_lengthlist__44u1__p3_0,
  132248. 1, -533725184, 1611661312, 3, 0,
  132249. _vq_quantlist__44u1__p3_0,
  132250. NULL,
  132251. &_vq_auxt__44u1__p3_0,
  132252. NULL,
  132253. 0
  132254. };
  132255. static long _vq_quantlist__44u1__p4_0[] = {
  132256. 2,
  132257. 1,
  132258. 3,
  132259. 0,
  132260. 4,
  132261. };
  132262. static long _vq_lengthlist__44u1__p4_0[] = {
  132263. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132264. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132265. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132266. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132267. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132268. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132269. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132270. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132271. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132272. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132273. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132274. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132275. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132276. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132277. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132278. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132279. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132280. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132281. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132282. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132283. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132284. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132285. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132286. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132287. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132288. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132289. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132290. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132291. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132292. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132293. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132294. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132295. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132296. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132297. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132298. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132299. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132300. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132301. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132302. 12,
  132303. };
  132304. static float _vq_quantthresh__44u1__p4_0[] = {
  132305. -1.5, -0.5, 0.5, 1.5,
  132306. };
  132307. static long _vq_quantmap__44u1__p4_0[] = {
  132308. 3, 1, 0, 2, 4,
  132309. };
  132310. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132311. _vq_quantthresh__44u1__p4_0,
  132312. _vq_quantmap__44u1__p4_0,
  132313. 5,
  132314. 5
  132315. };
  132316. static static_codebook _44u1__p4_0 = {
  132317. 4, 625,
  132318. _vq_lengthlist__44u1__p4_0,
  132319. 1, -533725184, 1611661312, 3, 0,
  132320. _vq_quantlist__44u1__p4_0,
  132321. NULL,
  132322. &_vq_auxt__44u1__p4_0,
  132323. NULL,
  132324. 0
  132325. };
  132326. static long _vq_quantlist__44u1__p5_0[] = {
  132327. 4,
  132328. 3,
  132329. 5,
  132330. 2,
  132331. 6,
  132332. 1,
  132333. 7,
  132334. 0,
  132335. 8,
  132336. };
  132337. static long _vq_lengthlist__44u1__p5_0[] = {
  132338. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132339. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132340. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132341. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132342. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132343. 12,
  132344. };
  132345. static float _vq_quantthresh__44u1__p5_0[] = {
  132346. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132347. };
  132348. static long _vq_quantmap__44u1__p5_0[] = {
  132349. 7, 5, 3, 1, 0, 2, 4, 6,
  132350. 8,
  132351. };
  132352. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132353. _vq_quantthresh__44u1__p5_0,
  132354. _vq_quantmap__44u1__p5_0,
  132355. 9,
  132356. 9
  132357. };
  132358. static static_codebook _44u1__p5_0 = {
  132359. 2, 81,
  132360. _vq_lengthlist__44u1__p5_0,
  132361. 1, -531628032, 1611661312, 4, 0,
  132362. _vq_quantlist__44u1__p5_0,
  132363. NULL,
  132364. &_vq_auxt__44u1__p5_0,
  132365. NULL,
  132366. 0
  132367. };
  132368. static long _vq_quantlist__44u1__p6_0[] = {
  132369. 6,
  132370. 5,
  132371. 7,
  132372. 4,
  132373. 8,
  132374. 3,
  132375. 9,
  132376. 2,
  132377. 10,
  132378. 1,
  132379. 11,
  132380. 0,
  132381. 12,
  132382. };
  132383. static long _vq_lengthlist__44u1__p6_0[] = {
  132384. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132385. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132386. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132387. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132388. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132389. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132390. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132391. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132392. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132393. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132394. 15,17,16,17,18,17,17,18, 0,
  132395. };
  132396. static float _vq_quantthresh__44u1__p6_0[] = {
  132397. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132398. 12.5, 17.5, 22.5, 27.5,
  132399. };
  132400. static long _vq_quantmap__44u1__p6_0[] = {
  132401. 11, 9, 7, 5, 3, 1, 0, 2,
  132402. 4, 6, 8, 10, 12,
  132403. };
  132404. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132405. _vq_quantthresh__44u1__p6_0,
  132406. _vq_quantmap__44u1__p6_0,
  132407. 13,
  132408. 13
  132409. };
  132410. static static_codebook _44u1__p6_0 = {
  132411. 2, 169,
  132412. _vq_lengthlist__44u1__p6_0,
  132413. 1, -526516224, 1616117760, 4, 0,
  132414. _vq_quantlist__44u1__p6_0,
  132415. NULL,
  132416. &_vq_auxt__44u1__p6_0,
  132417. NULL,
  132418. 0
  132419. };
  132420. static long _vq_quantlist__44u1__p6_1[] = {
  132421. 2,
  132422. 1,
  132423. 3,
  132424. 0,
  132425. 4,
  132426. };
  132427. static long _vq_lengthlist__44u1__p6_1[] = {
  132428. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132429. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132430. };
  132431. static float _vq_quantthresh__44u1__p6_1[] = {
  132432. -1.5, -0.5, 0.5, 1.5,
  132433. };
  132434. static long _vq_quantmap__44u1__p6_1[] = {
  132435. 3, 1, 0, 2, 4,
  132436. };
  132437. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132438. _vq_quantthresh__44u1__p6_1,
  132439. _vq_quantmap__44u1__p6_1,
  132440. 5,
  132441. 5
  132442. };
  132443. static static_codebook _44u1__p6_1 = {
  132444. 2, 25,
  132445. _vq_lengthlist__44u1__p6_1,
  132446. 1, -533725184, 1611661312, 3, 0,
  132447. _vq_quantlist__44u1__p6_1,
  132448. NULL,
  132449. &_vq_auxt__44u1__p6_1,
  132450. NULL,
  132451. 0
  132452. };
  132453. static long _vq_quantlist__44u1__p7_0[] = {
  132454. 3,
  132455. 2,
  132456. 4,
  132457. 1,
  132458. 5,
  132459. 0,
  132460. 6,
  132461. };
  132462. static long _vq_lengthlist__44u1__p7_0[] = {
  132463. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132464. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132465. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132466. 8,
  132467. };
  132468. static float _vq_quantthresh__44u1__p7_0[] = {
  132469. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132470. };
  132471. static long _vq_quantmap__44u1__p7_0[] = {
  132472. 5, 3, 1, 0, 2, 4, 6,
  132473. };
  132474. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132475. _vq_quantthresh__44u1__p7_0,
  132476. _vq_quantmap__44u1__p7_0,
  132477. 7,
  132478. 7
  132479. };
  132480. static static_codebook _44u1__p7_0 = {
  132481. 2, 49,
  132482. _vq_lengthlist__44u1__p7_0,
  132483. 1, -518017024, 1626677248, 3, 0,
  132484. _vq_quantlist__44u1__p7_0,
  132485. NULL,
  132486. &_vq_auxt__44u1__p7_0,
  132487. NULL,
  132488. 0
  132489. };
  132490. static long _vq_quantlist__44u1__p7_1[] = {
  132491. 6,
  132492. 5,
  132493. 7,
  132494. 4,
  132495. 8,
  132496. 3,
  132497. 9,
  132498. 2,
  132499. 10,
  132500. 1,
  132501. 11,
  132502. 0,
  132503. 12,
  132504. };
  132505. static long _vq_lengthlist__44u1__p7_1[] = {
  132506. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132507. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132508. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132509. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132510. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132511. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132512. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132513. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132514. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132515. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132516. 15,15,15,15,15,15,15,15,15,
  132517. };
  132518. static float _vq_quantthresh__44u1__p7_1[] = {
  132519. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132520. 32.5, 45.5, 58.5, 71.5,
  132521. };
  132522. static long _vq_quantmap__44u1__p7_1[] = {
  132523. 11, 9, 7, 5, 3, 1, 0, 2,
  132524. 4, 6, 8, 10, 12,
  132525. };
  132526. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132527. _vq_quantthresh__44u1__p7_1,
  132528. _vq_quantmap__44u1__p7_1,
  132529. 13,
  132530. 13
  132531. };
  132532. static static_codebook _44u1__p7_1 = {
  132533. 2, 169,
  132534. _vq_lengthlist__44u1__p7_1,
  132535. 1, -523010048, 1618608128, 4, 0,
  132536. _vq_quantlist__44u1__p7_1,
  132537. NULL,
  132538. &_vq_auxt__44u1__p7_1,
  132539. NULL,
  132540. 0
  132541. };
  132542. static long _vq_quantlist__44u1__p7_2[] = {
  132543. 6,
  132544. 5,
  132545. 7,
  132546. 4,
  132547. 8,
  132548. 3,
  132549. 9,
  132550. 2,
  132551. 10,
  132552. 1,
  132553. 11,
  132554. 0,
  132555. 12,
  132556. };
  132557. static long _vq_lengthlist__44u1__p7_2[] = {
  132558. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132559. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132560. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132561. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132562. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132563. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132564. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132565. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132566. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132567. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132568. 9, 9, 9,10, 9, 9,10,10, 9,
  132569. };
  132570. static float _vq_quantthresh__44u1__p7_2[] = {
  132571. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132572. 2.5, 3.5, 4.5, 5.5,
  132573. };
  132574. static long _vq_quantmap__44u1__p7_2[] = {
  132575. 11, 9, 7, 5, 3, 1, 0, 2,
  132576. 4, 6, 8, 10, 12,
  132577. };
  132578. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132579. _vq_quantthresh__44u1__p7_2,
  132580. _vq_quantmap__44u1__p7_2,
  132581. 13,
  132582. 13
  132583. };
  132584. static static_codebook _44u1__p7_2 = {
  132585. 2, 169,
  132586. _vq_lengthlist__44u1__p7_2,
  132587. 1, -531103744, 1611661312, 4, 0,
  132588. _vq_quantlist__44u1__p7_2,
  132589. NULL,
  132590. &_vq_auxt__44u1__p7_2,
  132591. NULL,
  132592. 0
  132593. };
  132594. static long _huff_lengthlist__44u1__short[] = {
  132595. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132596. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132597. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132598. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132599. };
  132600. static static_codebook _huff_book__44u1__short = {
  132601. 2, 64,
  132602. _huff_lengthlist__44u1__short,
  132603. 0, 0, 0, 0, 0,
  132604. NULL,
  132605. NULL,
  132606. NULL,
  132607. NULL,
  132608. 0
  132609. };
  132610. static long _huff_lengthlist__44u2__long[] = {
  132611. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132612. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132613. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132614. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132615. };
  132616. static static_codebook _huff_book__44u2__long = {
  132617. 2, 64,
  132618. _huff_lengthlist__44u2__long,
  132619. 0, 0, 0, 0, 0,
  132620. NULL,
  132621. NULL,
  132622. NULL,
  132623. NULL,
  132624. 0
  132625. };
  132626. static long _vq_quantlist__44u2__p1_0[] = {
  132627. 1,
  132628. 0,
  132629. 2,
  132630. };
  132631. static long _vq_lengthlist__44u2__p1_0[] = {
  132632. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132633. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132634. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132635. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132636. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132637. 13,
  132638. };
  132639. static float _vq_quantthresh__44u2__p1_0[] = {
  132640. -0.5, 0.5,
  132641. };
  132642. static long _vq_quantmap__44u2__p1_0[] = {
  132643. 1, 0, 2,
  132644. };
  132645. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132646. _vq_quantthresh__44u2__p1_0,
  132647. _vq_quantmap__44u2__p1_0,
  132648. 3,
  132649. 3
  132650. };
  132651. static static_codebook _44u2__p1_0 = {
  132652. 4, 81,
  132653. _vq_lengthlist__44u2__p1_0,
  132654. 1, -535822336, 1611661312, 2, 0,
  132655. _vq_quantlist__44u2__p1_0,
  132656. NULL,
  132657. &_vq_auxt__44u2__p1_0,
  132658. NULL,
  132659. 0
  132660. };
  132661. static long _vq_quantlist__44u2__p2_0[] = {
  132662. 1,
  132663. 0,
  132664. 2,
  132665. };
  132666. static long _vq_lengthlist__44u2__p2_0[] = {
  132667. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132668. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132669. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132670. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132671. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132672. 9,
  132673. };
  132674. static float _vq_quantthresh__44u2__p2_0[] = {
  132675. -0.5, 0.5,
  132676. };
  132677. static long _vq_quantmap__44u2__p2_0[] = {
  132678. 1, 0, 2,
  132679. };
  132680. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132681. _vq_quantthresh__44u2__p2_0,
  132682. _vq_quantmap__44u2__p2_0,
  132683. 3,
  132684. 3
  132685. };
  132686. static static_codebook _44u2__p2_0 = {
  132687. 4, 81,
  132688. _vq_lengthlist__44u2__p2_0,
  132689. 1, -535822336, 1611661312, 2, 0,
  132690. _vq_quantlist__44u2__p2_0,
  132691. NULL,
  132692. &_vq_auxt__44u2__p2_0,
  132693. NULL,
  132694. 0
  132695. };
  132696. static long _vq_quantlist__44u2__p3_0[] = {
  132697. 2,
  132698. 1,
  132699. 3,
  132700. 0,
  132701. 4,
  132702. };
  132703. static long _vq_lengthlist__44u2__p3_0[] = {
  132704. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132705. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132706. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132707. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132708. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132709. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132710. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132711. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132712. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132713. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132714. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132715. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132716. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132717. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132718. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132719. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132720. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132721. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132722. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132723. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132724. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132725. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132726. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132727. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132728. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132729. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132730. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132731. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132732. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132733. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132734. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132735. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132736. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132737. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132738. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132739. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132740. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132741. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132742. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132743. 0,
  132744. };
  132745. static float _vq_quantthresh__44u2__p3_0[] = {
  132746. -1.5, -0.5, 0.5, 1.5,
  132747. };
  132748. static long _vq_quantmap__44u2__p3_0[] = {
  132749. 3, 1, 0, 2, 4,
  132750. };
  132751. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132752. _vq_quantthresh__44u2__p3_0,
  132753. _vq_quantmap__44u2__p3_0,
  132754. 5,
  132755. 5
  132756. };
  132757. static static_codebook _44u2__p3_0 = {
  132758. 4, 625,
  132759. _vq_lengthlist__44u2__p3_0,
  132760. 1, -533725184, 1611661312, 3, 0,
  132761. _vq_quantlist__44u2__p3_0,
  132762. NULL,
  132763. &_vq_auxt__44u2__p3_0,
  132764. NULL,
  132765. 0
  132766. };
  132767. static long _vq_quantlist__44u2__p4_0[] = {
  132768. 2,
  132769. 1,
  132770. 3,
  132771. 0,
  132772. 4,
  132773. };
  132774. static long _vq_lengthlist__44u2__p4_0[] = {
  132775. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132776. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132777. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132778. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132779. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132780. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132781. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132782. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132783. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132784. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132785. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132786. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132787. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132788. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132789. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132790. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132791. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132792. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132793. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132794. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132795. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132796. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132797. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132798. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132799. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132800. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132801. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132802. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132803. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132804. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132805. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132806. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132807. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132808. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132809. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132810. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132811. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132812. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132813. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132814. 13,
  132815. };
  132816. static float _vq_quantthresh__44u2__p4_0[] = {
  132817. -1.5, -0.5, 0.5, 1.5,
  132818. };
  132819. static long _vq_quantmap__44u2__p4_0[] = {
  132820. 3, 1, 0, 2, 4,
  132821. };
  132822. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132823. _vq_quantthresh__44u2__p4_0,
  132824. _vq_quantmap__44u2__p4_0,
  132825. 5,
  132826. 5
  132827. };
  132828. static static_codebook _44u2__p4_0 = {
  132829. 4, 625,
  132830. _vq_lengthlist__44u2__p4_0,
  132831. 1, -533725184, 1611661312, 3, 0,
  132832. _vq_quantlist__44u2__p4_0,
  132833. NULL,
  132834. &_vq_auxt__44u2__p4_0,
  132835. NULL,
  132836. 0
  132837. };
  132838. static long _vq_quantlist__44u2__p5_0[] = {
  132839. 4,
  132840. 3,
  132841. 5,
  132842. 2,
  132843. 6,
  132844. 1,
  132845. 7,
  132846. 0,
  132847. 8,
  132848. };
  132849. static long _vq_lengthlist__44u2__p5_0[] = {
  132850. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132851. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132852. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132853. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132854. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132855. 13,
  132856. };
  132857. static float _vq_quantthresh__44u2__p5_0[] = {
  132858. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132859. };
  132860. static long _vq_quantmap__44u2__p5_0[] = {
  132861. 7, 5, 3, 1, 0, 2, 4, 6,
  132862. 8,
  132863. };
  132864. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132865. _vq_quantthresh__44u2__p5_0,
  132866. _vq_quantmap__44u2__p5_0,
  132867. 9,
  132868. 9
  132869. };
  132870. static static_codebook _44u2__p5_0 = {
  132871. 2, 81,
  132872. _vq_lengthlist__44u2__p5_0,
  132873. 1, -531628032, 1611661312, 4, 0,
  132874. _vq_quantlist__44u2__p5_0,
  132875. NULL,
  132876. &_vq_auxt__44u2__p5_0,
  132877. NULL,
  132878. 0
  132879. };
  132880. static long _vq_quantlist__44u2__p6_0[] = {
  132881. 6,
  132882. 5,
  132883. 7,
  132884. 4,
  132885. 8,
  132886. 3,
  132887. 9,
  132888. 2,
  132889. 10,
  132890. 1,
  132891. 11,
  132892. 0,
  132893. 12,
  132894. };
  132895. static long _vq_lengthlist__44u2__p6_0[] = {
  132896. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132897. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132898. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132899. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132900. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132901. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132902. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132903. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132904. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132905. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132906. 15,17,17,16,18,17,18, 0, 0,
  132907. };
  132908. static float _vq_quantthresh__44u2__p6_0[] = {
  132909. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132910. 12.5, 17.5, 22.5, 27.5,
  132911. };
  132912. static long _vq_quantmap__44u2__p6_0[] = {
  132913. 11, 9, 7, 5, 3, 1, 0, 2,
  132914. 4, 6, 8, 10, 12,
  132915. };
  132916. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132917. _vq_quantthresh__44u2__p6_0,
  132918. _vq_quantmap__44u2__p6_0,
  132919. 13,
  132920. 13
  132921. };
  132922. static static_codebook _44u2__p6_0 = {
  132923. 2, 169,
  132924. _vq_lengthlist__44u2__p6_0,
  132925. 1, -526516224, 1616117760, 4, 0,
  132926. _vq_quantlist__44u2__p6_0,
  132927. NULL,
  132928. &_vq_auxt__44u2__p6_0,
  132929. NULL,
  132930. 0
  132931. };
  132932. static long _vq_quantlist__44u2__p6_1[] = {
  132933. 2,
  132934. 1,
  132935. 3,
  132936. 0,
  132937. 4,
  132938. };
  132939. static long _vq_lengthlist__44u2__p6_1[] = {
  132940. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  132941. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  132942. };
  132943. static float _vq_quantthresh__44u2__p6_1[] = {
  132944. -1.5, -0.5, 0.5, 1.5,
  132945. };
  132946. static long _vq_quantmap__44u2__p6_1[] = {
  132947. 3, 1, 0, 2, 4,
  132948. };
  132949. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  132950. _vq_quantthresh__44u2__p6_1,
  132951. _vq_quantmap__44u2__p6_1,
  132952. 5,
  132953. 5
  132954. };
  132955. static static_codebook _44u2__p6_1 = {
  132956. 2, 25,
  132957. _vq_lengthlist__44u2__p6_1,
  132958. 1, -533725184, 1611661312, 3, 0,
  132959. _vq_quantlist__44u2__p6_1,
  132960. NULL,
  132961. &_vq_auxt__44u2__p6_1,
  132962. NULL,
  132963. 0
  132964. };
  132965. static long _vq_quantlist__44u2__p7_0[] = {
  132966. 4,
  132967. 3,
  132968. 5,
  132969. 2,
  132970. 6,
  132971. 1,
  132972. 7,
  132973. 0,
  132974. 8,
  132975. };
  132976. static long _vq_lengthlist__44u2__p7_0[] = {
  132977. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  132978. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  132979. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132980. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132981. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132982. 11,
  132983. };
  132984. static float _vq_quantthresh__44u2__p7_0[] = {
  132985. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  132986. };
  132987. static long _vq_quantmap__44u2__p7_0[] = {
  132988. 7, 5, 3, 1, 0, 2, 4, 6,
  132989. 8,
  132990. };
  132991. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  132992. _vq_quantthresh__44u2__p7_0,
  132993. _vq_quantmap__44u2__p7_0,
  132994. 9,
  132995. 9
  132996. };
  132997. static static_codebook _44u2__p7_0 = {
  132998. 2, 81,
  132999. _vq_lengthlist__44u2__p7_0,
  133000. 1, -516612096, 1626677248, 4, 0,
  133001. _vq_quantlist__44u2__p7_0,
  133002. NULL,
  133003. &_vq_auxt__44u2__p7_0,
  133004. NULL,
  133005. 0
  133006. };
  133007. static long _vq_quantlist__44u2__p7_1[] = {
  133008. 6,
  133009. 5,
  133010. 7,
  133011. 4,
  133012. 8,
  133013. 3,
  133014. 9,
  133015. 2,
  133016. 10,
  133017. 1,
  133018. 11,
  133019. 0,
  133020. 12,
  133021. };
  133022. static long _vq_lengthlist__44u2__p7_1[] = {
  133023. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133024. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133025. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133026. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133027. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133028. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133029. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133030. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133031. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133032. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133033. 14,14,14,17,15,17,17,17,17,
  133034. };
  133035. static float _vq_quantthresh__44u2__p7_1[] = {
  133036. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133037. 32.5, 45.5, 58.5, 71.5,
  133038. };
  133039. static long _vq_quantmap__44u2__p7_1[] = {
  133040. 11, 9, 7, 5, 3, 1, 0, 2,
  133041. 4, 6, 8, 10, 12,
  133042. };
  133043. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133044. _vq_quantthresh__44u2__p7_1,
  133045. _vq_quantmap__44u2__p7_1,
  133046. 13,
  133047. 13
  133048. };
  133049. static static_codebook _44u2__p7_1 = {
  133050. 2, 169,
  133051. _vq_lengthlist__44u2__p7_1,
  133052. 1, -523010048, 1618608128, 4, 0,
  133053. _vq_quantlist__44u2__p7_1,
  133054. NULL,
  133055. &_vq_auxt__44u2__p7_1,
  133056. NULL,
  133057. 0
  133058. };
  133059. static long _vq_quantlist__44u2__p7_2[] = {
  133060. 6,
  133061. 5,
  133062. 7,
  133063. 4,
  133064. 8,
  133065. 3,
  133066. 9,
  133067. 2,
  133068. 10,
  133069. 1,
  133070. 11,
  133071. 0,
  133072. 12,
  133073. };
  133074. static long _vq_lengthlist__44u2__p7_2[] = {
  133075. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133076. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133077. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133078. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133079. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133080. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133081. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133082. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133083. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133084. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133085. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133086. };
  133087. static float _vq_quantthresh__44u2__p7_2[] = {
  133088. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133089. 2.5, 3.5, 4.5, 5.5,
  133090. };
  133091. static long _vq_quantmap__44u2__p7_2[] = {
  133092. 11, 9, 7, 5, 3, 1, 0, 2,
  133093. 4, 6, 8, 10, 12,
  133094. };
  133095. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133096. _vq_quantthresh__44u2__p7_2,
  133097. _vq_quantmap__44u2__p7_2,
  133098. 13,
  133099. 13
  133100. };
  133101. static static_codebook _44u2__p7_2 = {
  133102. 2, 169,
  133103. _vq_lengthlist__44u2__p7_2,
  133104. 1, -531103744, 1611661312, 4, 0,
  133105. _vq_quantlist__44u2__p7_2,
  133106. NULL,
  133107. &_vq_auxt__44u2__p7_2,
  133108. NULL,
  133109. 0
  133110. };
  133111. static long _huff_lengthlist__44u2__short[] = {
  133112. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133113. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133114. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133115. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133116. };
  133117. static static_codebook _huff_book__44u2__short = {
  133118. 2, 64,
  133119. _huff_lengthlist__44u2__short,
  133120. 0, 0, 0, 0, 0,
  133121. NULL,
  133122. NULL,
  133123. NULL,
  133124. NULL,
  133125. 0
  133126. };
  133127. static long _huff_lengthlist__44u3__long[] = {
  133128. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133129. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133130. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133131. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133132. };
  133133. static static_codebook _huff_book__44u3__long = {
  133134. 2, 64,
  133135. _huff_lengthlist__44u3__long,
  133136. 0, 0, 0, 0, 0,
  133137. NULL,
  133138. NULL,
  133139. NULL,
  133140. NULL,
  133141. 0
  133142. };
  133143. static long _vq_quantlist__44u3__p1_0[] = {
  133144. 1,
  133145. 0,
  133146. 2,
  133147. };
  133148. static long _vq_lengthlist__44u3__p1_0[] = {
  133149. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133150. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133151. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133152. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133153. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133154. 13,
  133155. };
  133156. static float _vq_quantthresh__44u3__p1_0[] = {
  133157. -0.5, 0.5,
  133158. };
  133159. static long _vq_quantmap__44u3__p1_0[] = {
  133160. 1, 0, 2,
  133161. };
  133162. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133163. _vq_quantthresh__44u3__p1_0,
  133164. _vq_quantmap__44u3__p1_0,
  133165. 3,
  133166. 3
  133167. };
  133168. static static_codebook _44u3__p1_0 = {
  133169. 4, 81,
  133170. _vq_lengthlist__44u3__p1_0,
  133171. 1, -535822336, 1611661312, 2, 0,
  133172. _vq_quantlist__44u3__p1_0,
  133173. NULL,
  133174. &_vq_auxt__44u3__p1_0,
  133175. NULL,
  133176. 0
  133177. };
  133178. static long _vq_quantlist__44u3__p2_0[] = {
  133179. 1,
  133180. 0,
  133181. 2,
  133182. };
  133183. static long _vq_lengthlist__44u3__p2_0[] = {
  133184. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133185. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133186. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133187. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133188. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133189. 9,
  133190. };
  133191. static float _vq_quantthresh__44u3__p2_0[] = {
  133192. -0.5, 0.5,
  133193. };
  133194. static long _vq_quantmap__44u3__p2_0[] = {
  133195. 1, 0, 2,
  133196. };
  133197. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133198. _vq_quantthresh__44u3__p2_0,
  133199. _vq_quantmap__44u3__p2_0,
  133200. 3,
  133201. 3
  133202. };
  133203. static static_codebook _44u3__p2_0 = {
  133204. 4, 81,
  133205. _vq_lengthlist__44u3__p2_0,
  133206. 1, -535822336, 1611661312, 2, 0,
  133207. _vq_quantlist__44u3__p2_0,
  133208. NULL,
  133209. &_vq_auxt__44u3__p2_0,
  133210. NULL,
  133211. 0
  133212. };
  133213. static long _vq_quantlist__44u3__p3_0[] = {
  133214. 2,
  133215. 1,
  133216. 3,
  133217. 0,
  133218. 4,
  133219. };
  133220. static long _vq_lengthlist__44u3__p3_0[] = {
  133221. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133222. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133223. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133224. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133225. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133226. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133227. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133228. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133229. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133230. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133231. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133232. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133233. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133234. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133235. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133236. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133237. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133238. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133239. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133240. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133241. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133242. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133243. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133244. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133245. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133246. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133247. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133248. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133249. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133250. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133251. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133252. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133253. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133254. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133255. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133256. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133257. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133258. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133259. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133260. 0,
  133261. };
  133262. static float _vq_quantthresh__44u3__p3_0[] = {
  133263. -1.5, -0.5, 0.5, 1.5,
  133264. };
  133265. static long _vq_quantmap__44u3__p3_0[] = {
  133266. 3, 1, 0, 2, 4,
  133267. };
  133268. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133269. _vq_quantthresh__44u3__p3_0,
  133270. _vq_quantmap__44u3__p3_0,
  133271. 5,
  133272. 5
  133273. };
  133274. static static_codebook _44u3__p3_0 = {
  133275. 4, 625,
  133276. _vq_lengthlist__44u3__p3_0,
  133277. 1, -533725184, 1611661312, 3, 0,
  133278. _vq_quantlist__44u3__p3_0,
  133279. NULL,
  133280. &_vq_auxt__44u3__p3_0,
  133281. NULL,
  133282. 0
  133283. };
  133284. static long _vq_quantlist__44u3__p4_0[] = {
  133285. 2,
  133286. 1,
  133287. 3,
  133288. 0,
  133289. 4,
  133290. };
  133291. static long _vq_lengthlist__44u3__p4_0[] = {
  133292. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133293. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133294. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133295. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133296. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133297. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133298. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133299. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133300. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133301. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133302. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133303. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133304. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133305. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133306. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133307. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133308. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133309. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133310. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133311. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133312. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133313. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133314. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133315. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133316. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133317. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133318. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133319. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133320. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133321. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133322. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133323. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133324. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133325. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133326. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133327. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133328. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133329. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133330. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133331. 13,
  133332. };
  133333. static float _vq_quantthresh__44u3__p4_0[] = {
  133334. -1.5, -0.5, 0.5, 1.5,
  133335. };
  133336. static long _vq_quantmap__44u3__p4_0[] = {
  133337. 3, 1, 0, 2, 4,
  133338. };
  133339. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133340. _vq_quantthresh__44u3__p4_0,
  133341. _vq_quantmap__44u3__p4_0,
  133342. 5,
  133343. 5
  133344. };
  133345. static static_codebook _44u3__p4_0 = {
  133346. 4, 625,
  133347. _vq_lengthlist__44u3__p4_0,
  133348. 1, -533725184, 1611661312, 3, 0,
  133349. _vq_quantlist__44u3__p4_0,
  133350. NULL,
  133351. &_vq_auxt__44u3__p4_0,
  133352. NULL,
  133353. 0
  133354. };
  133355. static long _vq_quantlist__44u3__p5_0[] = {
  133356. 4,
  133357. 3,
  133358. 5,
  133359. 2,
  133360. 6,
  133361. 1,
  133362. 7,
  133363. 0,
  133364. 8,
  133365. };
  133366. static long _vq_lengthlist__44u3__p5_0[] = {
  133367. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133368. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133369. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133370. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133371. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133372. 12,
  133373. };
  133374. static float _vq_quantthresh__44u3__p5_0[] = {
  133375. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133376. };
  133377. static long _vq_quantmap__44u3__p5_0[] = {
  133378. 7, 5, 3, 1, 0, 2, 4, 6,
  133379. 8,
  133380. };
  133381. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133382. _vq_quantthresh__44u3__p5_0,
  133383. _vq_quantmap__44u3__p5_0,
  133384. 9,
  133385. 9
  133386. };
  133387. static static_codebook _44u3__p5_0 = {
  133388. 2, 81,
  133389. _vq_lengthlist__44u3__p5_0,
  133390. 1, -531628032, 1611661312, 4, 0,
  133391. _vq_quantlist__44u3__p5_0,
  133392. NULL,
  133393. &_vq_auxt__44u3__p5_0,
  133394. NULL,
  133395. 0
  133396. };
  133397. static long _vq_quantlist__44u3__p6_0[] = {
  133398. 6,
  133399. 5,
  133400. 7,
  133401. 4,
  133402. 8,
  133403. 3,
  133404. 9,
  133405. 2,
  133406. 10,
  133407. 1,
  133408. 11,
  133409. 0,
  133410. 12,
  133411. };
  133412. static long _vq_lengthlist__44u3__p6_0[] = {
  133413. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133414. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133415. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133416. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133417. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133418. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133419. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133420. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133421. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133422. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133423. 15,16,16,16,17,18,16,20,18,
  133424. };
  133425. static float _vq_quantthresh__44u3__p6_0[] = {
  133426. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133427. 12.5, 17.5, 22.5, 27.5,
  133428. };
  133429. static long _vq_quantmap__44u3__p6_0[] = {
  133430. 11, 9, 7, 5, 3, 1, 0, 2,
  133431. 4, 6, 8, 10, 12,
  133432. };
  133433. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133434. _vq_quantthresh__44u3__p6_0,
  133435. _vq_quantmap__44u3__p6_0,
  133436. 13,
  133437. 13
  133438. };
  133439. static static_codebook _44u3__p6_0 = {
  133440. 2, 169,
  133441. _vq_lengthlist__44u3__p6_0,
  133442. 1, -526516224, 1616117760, 4, 0,
  133443. _vq_quantlist__44u3__p6_0,
  133444. NULL,
  133445. &_vq_auxt__44u3__p6_0,
  133446. NULL,
  133447. 0
  133448. };
  133449. static long _vq_quantlist__44u3__p6_1[] = {
  133450. 2,
  133451. 1,
  133452. 3,
  133453. 0,
  133454. 4,
  133455. };
  133456. static long _vq_lengthlist__44u3__p6_1[] = {
  133457. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133458. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133459. };
  133460. static float _vq_quantthresh__44u3__p6_1[] = {
  133461. -1.5, -0.5, 0.5, 1.5,
  133462. };
  133463. static long _vq_quantmap__44u3__p6_1[] = {
  133464. 3, 1, 0, 2, 4,
  133465. };
  133466. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133467. _vq_quantthresh__44u3__p6_1,
  133468. _vq_quantmap__44u3__p6_1,
  133469. 5,
  133470. 5
  133471. };
  133472. static static_codebook _44u3__p6_1 = {
  133473. 2, 25,
  133474. _vq_lengthlist__44u3__p6_1,
  133475. 1, -533725184, 1611661312, 3, 0,
  133476. _vq_quantlist__44u3__p6_1,
  133477. NULL,
  133478. &_vq_auxt__44u3__p6_1,
  133479. NULL,
  133480. 0
  133481. };
  133482. static long _vq_quantlist__44u3__p7_0[] = {
  133483. 4,
  133484. 3,
  133485. 5,
  133486. 2,
  133487. 6,
  133488. 1,
  133489. 7,
  133490. 0,
  133491. 8,
  133492. };
  133493. static long _vq_lengthlist__44u3__p7_0[] = {
  133494. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133495. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133496. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133497. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133498. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133499. 9,
  133500. };
  133501. static float _vq_quantthresh__44u3__p7_0[] = {
  133502. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133503. };
  133504. static long _vq_quantmap__44u3__p7_0[] = {
  133505. 7, 5, 3, 1, 0, 2, 4, 6,
  133506. 8,
  133507. };
  133508. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133509. _vq_quantthresh__44u3__p7_0,
  133510. _vq_quantmap__44u3__p7_0,
  133511. 9,
  133512. 9
  133513. };
  133514. static static_codebook _44u3__p7_0 = {
  133515. 2, 81,
  133516. _vq_lengthlist__44u3__p7_0,
  133517. 1, -515907584, 1627381760, 4, 0,
  133518. _vq_quantlist__44u3__p7_0,
  133519. NULL,
  133520. &_vq_auxt__44u3__p7_0,
  133521. NULL,
  133522. 0
  133523. };
  133524. static long _vq_quantlist__44u3__p7_1[] = {
  133525. 7,
  133526. 6,
  133527. 8,
  133528. 5,
  133529. 9,
  133530. 4,
  133531. 10,
  133532. 3,
  133533. 11,
  133534. 2,
  133535. 12,
  133536. 1,
  133537. 13,
  133538. 0,
  133539. 14,
  133540. };
  133541. static long _vq_lengthlist__44u3__p7_1[] = {
  133542. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133543. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133544. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133545. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133546. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133547. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133548. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133549. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133550. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133551. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133552. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133553. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133554. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133555. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133556. 17,
  133557. };
  133558. static float _vq_quantthresh__44u3__p7_1[] = {
  133559. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133560. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133561. };
  133562. static long _vq_quantmap__44u3__p7_1[] = {
  133563. 13, 11, 9, 7, 5, 3, 1, 0,
  133564. 2, 4, 6, 8, 10, 12, 14,
  133565. };
  133566. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133567. _vq_quantthresh__44u3__p7_1,
  133568. _vq_quantmap__44u3__p7_1,
  133569. 15,
  133570. 15
  133571. };
  133572. static static_codebook _44u3__p7_1 = {
  133573. 2, 225,
  133574. _vq_lengthlist__44u3__p7_1,
  133575. 1, -522338304, 1620115456, 4, 0,
  133576. _vq_quantlist__44u3__p7_1,
  133577. NULL,
  133578. &_vq_auxt__44u3__p7_1,
  133579. NULL,
  133580. 0
  133581. };
  133582. static long _vq_quantlist__44u3__p7_2[] = {
  133583. 8,
  133584. 7,
  133585. 9,
  133586. 6,
  133587. 10,
  133588. 5,
  133589. 11,
  133590. 4,
  133591. 12,
  133592. 3,
  133593. 13,
  133594. 2,
  133595. 14,
  133596. 1,
  133597. 15,
  133598. 0,
  133599. 16,
  133600. };
  133601. static long _vq_lengthlist__44u3__p7_2[] = {
  133602. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133603. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133604. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133605. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133606. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133607. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133608. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133609. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133610. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133611. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133612. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133613. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133614. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133615. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133616. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133617. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133618. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133619. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133620. 11,
  133621. };
  133622. static float _vq_quantthresh__44u3__p7_2[] = {
  133623. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133624. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133625. };
  133626. static long _vq_quantmap__44u3__p7_2[] = {
  133627. 15, 13, 11, 9, 7, 5, 3, 1,
  133628. 0, 2, 4, 6, 8, 10, 12, 14,
  133629. 16,
  133630. };
  133631. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133632. _vq_quantthresh__44u3__p7_2,
  133633. _vq_quantmap__44u3__p7_2,
  133634. 17,
  133635. 17
  133636. };
  133637. static static_codebook _44u3__p7_2 = {
  133638. 2, 289,
  133639. _vq_lengthlist__44u3__p7_2,
  133640. 1, -529530880, 1611661312, 5, 0,
  133641. _vq_quantlist__44u3__p7_2,
  133642. NULL,
  133643. &_vq_auxt__44u3__p7_2,
  133644. NULL,
  133645. 0
  133646. };
  133647. static long _huff_lengthlist__44u3__short[] = {
  133648. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133649. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133650. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133651. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133652. };
  133653. static static_codebook _huff_book__44u3__short = {
  133654. 2, 64,
  133655. _huff_lengthlist__44u3__short,
  133656. 0, 0, 0, 0, 0,
  133657. NULL,
  133658. NULL,
  133659. NULL,
  133660. NULL,
  133661. 0
  133662. };
  133663. static long _huff_lengthlist__44u4__long[] = {
  133664. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133665. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133666. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133667. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133668. };
  133669. static static_codebook _huff_book__44u4__long = {
  133670. 2, 64,
  133671. _huff_lengthlist__44u4__long,
  133672. 0, 0, 0, 0, 0,
  133673. NULL,
  133674. NULL,
  133675. NULL,
  133676. NULL,
  133677. 0
  133678. };
  133679. static long _vq_quantlist__44u4__p1_0[] = {
  133680. 1,
  133681. 0,
  133682. 2,
  133683. };
  133684. static long _vq_lengthlist__44u4__p1_0[] = {
  133685. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133686. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133687. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133688. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133689. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133690. 13,
  133691. };
  133692. static float _vq_quantthresh__44u4__p1_0[] = {
  133693. -0.5, 0.5,
  133694. };
  133695. static long _vq_quantmap__44u4__p1_0[] = {
  133696. 1, 0, 2,
  133697. };
  133698. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133699. _vq_quantthresh__44u4__p1_0,
  133700. _vq_quantmap__44u4__p1_0,
  133701. 3,
  133702. 3
  133703. };
  133704. static static_codebook _44u4__p1_0 = {
  133705. 4, 81,
  133706. _vq_lengthlist__44u4__p1_0,
  133707. 1, -535822336, 1611661312, 2, 0,
  133708. _vq_quantlist__44u4__p1_0,
  133709. NULL,
  133710. &_vq_auxt__44u4__p1_0,
  133711. NULL,
  133712. 0
  133713. };
  133714. static long _vq_quantlist__44u4__p2_0[] = {
  133715. 1,
  133716. 0,
  133717. 2,
  133718. };
  133719. static long _vq_lengthlist__44u4__p2_0[] = {
  133720. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133721. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133722. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133723. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133724. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133725. 9,
  133726. };
  133727. static float _vq_quantthresh__44u4__p2_0[] = {
  133728. -0.5, 0.5,
  133729. };
  133730. static long _vq_quantmap__44u4__p2_0[] = {
  133731. 1, 0, 2,
  133732. };
  133733. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133734. _vq_quantthresh__44u4__p2_0,
  133735. _vq_quantmap__44u4__p2_0,
  133736. 3,
  133737. 3
  133738. };
  133739. static static_codebook _44u4__p2_0 = {
  133740. 4, 81,
  133741. _vq_lengthlist__44u4__p2_0,
  133742. 1, -535822336, 1611661312, 2, 0,
  133743. _vq_quantlist__44u4__p2_0,
  133744. NULL,
  133745. &_vq_auxt__44u4__p2_0,
  133746. NULL,
  133747. 0
  133748. };
  133749. static long _vq_quantlist__44u4__p3_0[] = {
  133750. 2,
  133751. 1,
  133752. 3,
  133753. 0,
  133754. 4,
  133755. };
  133756. static long _vq_lengthlist__44u4__p3_0[] = {
  133757. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133758. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133759. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133760. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133761. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133762. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133763. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133764. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133765. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133766. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133767. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133768. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133769. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133770. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133771. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133772. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133773. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133774. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133775. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133776. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133777. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133778. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133779. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133780. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133781. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133782. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133783. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133784. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133785. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133786. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133787. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133788. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133789. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133790. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133791. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133792. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133793. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133794. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133795. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133796. 0,
  133797. };
  133798. static float _vq_quantthresh__44u4__p3_0[] = {
  133799. -1.5, -0.5, 0.5, 1.5,
  133800. };
  133801. static long _vq_quantmap__44u4__p3_0[] = {
  133802. 3, 1, 0, 2, 4,
  133803. };
  133804. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133805. _vq_quantthresh__44u4__p3_0,
  133806. _vq_quantmap__44u4__p3_0,
  133807. 5,
  133808. 5
  133809. };
  133810. static static_codebook _44u4__p3_0 = {
  133811. 4, 625,
  133812. _vq_lengthlist__44u4__p3_0,
  133813. 1, -533725184, 1611661312, 3, 0,
  133814. _vq_quantlist__44u4__p3_0,
  133815. NULL,
  133816. &_vq_auxt__44u4__p3_0,
  133817. NULL,
  133818. 0
  133819. };
  133820. static long _vq_quantlist__44u4__p4_0[] = {
  133821. 2,
  133822. 1,
  133823. 3,
  133824. 0,
  133825. 4,
  133826. };
  133827. static long _vq_lengthlist__44u4__p4_0[] = {
  133828. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133829. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133830. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133831. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133832. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133833. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133834. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133835. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133836. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133837. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133838. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133839. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133840. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133841. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133842. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133843. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133844. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133845. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133846. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133847. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133848. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133849. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133850. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133851. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133852. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133853. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133854. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133855. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133856. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133857. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133858. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133859. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133860. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133861. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133862. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133863. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133864. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133865. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133866. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133867. 13,
  133868. };
  133869. static float _vq_quantthresh__44u4__p4_0[] = {
  133870. -1.5, -0.5, 0.5, 1.5,
  133871. };
  133872. static long _vq_quantmap__44u4__p4_0[] = {
  133873. 3, 1, 0, 2, 4,
  133874. };
  133875. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133876. _vq_quantthresh__44u4__p4_0,
  133877. _vq_quantmap__44u4__p4_0,
  133878. 5,
  133879. 5
  133880. };
  133881. static static_codebook _44u4__p4_0 = {
  133882. 4, 625,
  133883. _vq_lengthlist__44u4__p4_0,
  133884. 1, -533725184, 1611661312, 3, 0,
  133885. _vq_quantlist__44u4__p4_0,
  133886. NULL,
  133887. &_vq_auxt__44u4__p4_0,
  133888. NULL,
  133889. 0
  133890. };
  133891. static long _vq_quantlist__44u4__p5_0[] = {
  133892. 4,
  133893. 3,
  133894. 5,
  133895. 2,
  133896. 6,
  133897. 1,
  133898. 7,
  133899. 0,
  133900. 8,
  133901. };
  133902. static long _vq_lengthlist__44u4__p5_0[] = {
  133903. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133904. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133905. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133906. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133907. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133908. 12,
  133909. };
  133910. static float _vq_quantthresh__44u4__p5_0[] = {
  133911. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133912. };
  133913. static long _vq_quantmap__44u4__p5_0[] = {
  133914. 7, 5, 3, 1, 0, 2, 4, 6,
  133915. 8,
  133916. };
  133917. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133918. _vq_quantthresh__44u4__p5_0,
  133919. _vq_quantmap__44u4__p5_0,
  133920. 9,
  133921. 9
  133922. };
  133923. static static_codebook _44u4__p5_0 = {
  133924. 2, 81,
  133925. _vq_lengthlist__44u4__p5_0,
  133926. 1, -531628032, 1611661312, 4, 0,
  133927. _vq_quantlist__44u4__p5_0,
  133928. NULL,
  133929. &_vq_auxt__44u4__p5_0,
  133930. NULL,
  133931. 0
  133932. };
  133933. static long _vq_quantlist__44u4__p6_0[] = {
  133934. 6,
  133935. 5,
  133936. 7,
  133937. 4,
  133938. 8,
  133939. 3,
  133940. 9,
  133941. 2,
  133942. 10,
  133943. 1,
  133944. 11,
  133945. 0,
  133946. 12,
  133947. };
  133948. static long _vq_lengthlist__44u4__p6_0[] = {
  133949. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  133950. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133951. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133952. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133953. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  133954. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  133955. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  133956. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  133957. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  133958. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  133959. 16,16,16,17,17,18,17,20,21,
  133960. };
  133961. static float _vq_quantthresh__44u4__p6_0[] = {
  133962. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133963. 12.5, 17.5, 22.5, 27.5,
  133964. };
  133965. static long _vq_quantmap__44u4__p6_0[] = {
  133966. 11, 9, 7, 5, 3, 1, 0, 2,
  133967. 4, 6, 8, 10, 12,
  133968. };
  133969. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  133970. _vq_quantthresh__44u4__p6_0,
  133971. _vq_quantmap__44u4__p6_0,
  133972. 13,
  133973. 13
  133974. };
  133975. static static_codebook _44u4__p6_0 = {
  133976. 2, 169,
  133977. _vq_lengthlist__44u4__p6_0,
  133978. 1, -526516224, 1616117760, 4, 0,
  133979. _vq_quantlist__44u4__p6_0,
  133980. NULL,
  133981. &_vq_auxt__44u4__p6_0,
  133982. NULL,
  133983. 0
  133984. };
  133985. static long _vq_quantlist__44u4__p6_1[] = {
  133986. 2,
  133987. 1,
  133988. 3,
  133989. 0,
  133990. 4,
  133991. };
  133992. static long _vq_lengthlist__44u4__p6_1[] = {
  133993. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133994. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133995. };
  133996. static float _vq_quantthresh__44u4__p6_1[] = {
  133997. -1.5, -0.5, 0.5, 1.5,
  133998. };
  133999. static long _vq_quantmap__44u4__p6_1[] = {
  134000. 3, 1, 0, 2, 4,
  134001. };
  134002. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134003. _vq_quantthresh__44u4__p6_1,
  134004. _vq_quantmap__44u4__p6_1,
  134005. 5,
  134006. 5
  134007. };
  134008. static static_codebook _44u4__p6_1 = {
  134009. 2, 25,
  134010. _vq_lengthlist__44u4__p6_1,
  134011. 1, -533725184, 1611661312, 3, 0,
  134012. _vq_quantlist__44u4__p6_1,
  134013. NULL,
  134014. &_vq_auxt__44u4__p6_1,
  134015. NULL,
  134016. 0
  134017. };
  134018. static long _vq_quantlist__44u4__p7_0[] = {
  134019. 6,
  134020. 5,
  134021. 7,
  134022. 4,
  134023. 8,
  134024. 3,
  134025. 9,
  134026. 2,
  134027. 10,
  134028. 1,
  134029. 11,
  134030. 0,
  134031. 12,
  134032. };
  134033. static long _vq_lengthlist__44u4__p7_0[] = {
  134034. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134035. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134036. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134037. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134038. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134039. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134040. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134041. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134042. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134043. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134044. 11,11,11,11,11,11,11,11,11,
  134045. };
  134046. static float _vq_quantthresh__44u4__p7_0[] = {
  134047. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134048. 637.5, 892.5, 1147.5, 1402.5,
  134049. };
  134050. static long _vq_quantmap__44u4__p7_0[] = {
  134051. 11, 9, 7, 5, 3, 1, 0, 2,
  134052. 4, 6, 8, 10, 12,
  134053. };
  134054. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134055. _vq_quantthresh__44u4__p7_0,
  134056. _vq_quantmap__44u4__p7_0,
  134057. 13,
  134058. 13
  134059. };
  134060. static static_codebook _44u4__p7_0 = {
  134061. 2, 169,
  134062. _vq_lengthlist__44u4__p7_0,
  134063. 1, -514332672, 1627381760, 4, 0,
  134064. _vq_quantlist__44u4__p7_0,
  134065. NULL,
  134066. &_vq_auxt__44u4__p7_0,
  134067. NULL,
  134068. 0
  134069. };
  134070. static long _vq_quantlist__44u4__p7_1[] = {
  134071. 7,
  134072. 6,
  134073. 8,
  134074. 5,
  134075. 9,
  134076. 4,
  134077. 10,
  134078. 3,
  134079. 11,
  134080. 2,
  134081. 12,
  134082. 1,
  134083. 13,
  134084. 0,
  134085. 14,
  134086. };
  134087. static long _vq_lengthlist__44u4__p7_1[] = {
  134088. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134089. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134090. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134091. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134092. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134093. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134094. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134095. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134096. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134097. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134098. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134099. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134100. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134101. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134102. 16,
  134103. };
  134104. static float _vq_quantthresh__44u4__p7_1[] = {
  134105. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134106. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134107. };
  134108. static long _vq_quantmap__44u4__p7_1[] = {
  134109. 13, 11, 9, 7, 5, 3, 1, 0,
  134110. 2, 4, 6, 8, 10, 12, 14,
  134111. };
  134112. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134113. _vq_quantthresh__44u4__p7_1,
  134114. _vq_quantmap__44u4__p7_1,
  134115. 15,
  134116. 15
  134117. };
  134118. static static_codebook _44u4__p7_1 = {
  134119. 2, 225,
  134120. _vq_lengthlist__44u4__p7_1,
  134121. 1, -522338304, 1620115456, 4, 0,
  134122. _vq_quantlist__44u4__p7_1,
  134123. NULL,
  134124. &_vq_auxt__44u4__p7_1,
  134125. NULL,
  134126. 0
  134127. };
  134128. static long _vq_quantlist__44u4__p7_2[] = {
  134129. 8,
  134130. 7,
  134131. 9,
  134132. 6,
  134133. 10,
  134134. 5,
  134135. 11,
  134136. 4,
  134137. 12,
  134138. 3,
  134139. 13,
  134140. 2,
  134141. 14,
  134142. 1,
  134143. 15,
  134144. 0,
  134145. 16,
  134146. };
  134147. static long _vq_lengthlist__44u4__p7_2[] = {
  134148. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134149. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134150. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134151. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134152. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134153. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134154. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134155. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134156. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134157. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134158. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134159. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134160. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134161. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134162. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134163. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134164. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134165. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134166. 10,
  134167. };
  134168. static float _vq_quantthresh__44u4__p7_2[] = {
  134169. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134170. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134171. };
  134172. static long _vq_quantmap__44u4__p7_2[] = {
  134173. 15, 13, 11, 9, 7, 5, 3, 1,
  134174. 0, 2, 4, 6, 8, 10, 12, 14,
  134175. 16,
  134176. };
  134177. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134178. _vq_quantthresh__44u4__p7_2,
  134179. _vq_quantmap__44u4__p7_2,
  134180. 17,
  134181. 17
  134182. };
  134183. static static_codebook _44u4__p7_2 = {
  134184. 2, 289,
  134185. _vq_lengthlist__44u4__p7_2,
  134186. 1, -529530880, 1611661312, 5, 0,
  134187. _vq_quantlist__44u4__p7_2,
  134188. NULL,
  134189. &_vq_auxt__44u4__p7_2,
  134190. NULL,
  134191. 0
  134192. };
  134193. static long _huff_lengthlist__44u4__short[] = {
  134194. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134195. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134196. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134197. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134198. };
  134199. static static_codebook _huff_book__44u4__short = {
  134200. 2, 64,
  134201. _huff_lengthlist__44u4__short,
  134202. 0, 0, 0, 0, 0,
  134203. NULL,
  134204. NULL,
  134205. NULL,
  134206. NULL,
  134207. 0
  134208. };
  134209. static long _huff_lengthlist__44u5__long[] = {
  134210. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134211. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134212. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134213. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134214. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134215. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134216. 14, 8, 7, 8,
  134217. };
  134218. static static_codebook _huff_book__44u5__long = {
  134219. 2, 100,
  134220. _huff_lengthlist__44u5__long,
  134221. 0, 0, 0, 0, 0,
  134222. NULL,
  134223. NULL,
  134224. NULL,
  134225. NULL,
  134226. 0
  134227. };
  134228. static long _vq_quantlist__44u5__p1_0[] = {
  134229. 1,
  134230. 0,
  134231. 2,
  134232. };
  134233. static long _vq_lengthlist__44u5__p1_0[] = {
  134234. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134235. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134236. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134237. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134238. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134239. 12,
  134240. };
  134241. static float _vq_quantthresh__44u5__p1_0[] = {
  134242. -0.5, 0.5,
  134243. };
  134244. static long _vq_quantmap__44u5__p1_0[] = {
  134245. 1, 0, 2,
  134246. };
  134247. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134248. _vq_quantthresh__44u5__p1_0,
  134249. _vq_quantmap__44u5__p1_0,
  134250. 3,
  134251. 3
  134252. };
  134253. static static_codebook _44u5__p1_0 = {
  134254. 4, 81,
  134255. _vq_lengthlist__44u5__p1_0,
  134256. 1, -535822336, 1611661312, 2, 0,
  134257. _vq_quantlist__44u5__p1_0,
  134258. NULL,
  134259. &_vq_auxt__44u5__p1_0,
  134260. NULL,
  134261. 0
  134262. };
  134263. static long _vq_quantlist__44u5__p2_0[] = {
  134264. 1,
  134265. 0,
  134266. 2,
  134267. };
  134268. static long _vq_lengthlist__44u5__p2_0[] = {
  134269. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134270. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134271. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134272. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134273. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134274. 9,
  134275. };
  134276. static float _vq_quantthresh__44u5__p2_0[] = {
  134277. -0.5, 0.5,
  134278. };
  134279. static long _vq_quantmap__44u5__p2_0[] = {
  134280. 1, 0, 2,
  134281. };
  134282. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134283. _vq_quantthresh__44u5__p2_0,
  134284. _vq_quantmap__44u5__p2_0,
  134285. 3,
  134286. 3
  134287. };
  134288. static static_codebook _44u5__p2_0 = {
  134289. 4, 81,
  134290. _vq_lengthlist__44u5__p2_0,
  134291. 1, -535822336, 1611661312, 2, 0,
  134292. _vq_quantlist__44u5__p2_0,
  134293. NULL,
  134294. &_vq_auxt__44u5__p2_0,
  134295. NULL,
  134296. 0
  134297. };
  134298. static long _vq_quantlist__44u5__p3_0[] = {
  134299. 2,
  134300. 1,
  134301. 3,
  134302. 0,
  134303. 4,
  134304. };
  134305. static long _vq_lengthlist__44u5__p3_0[] = {
  134306. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134307. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134308. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134309. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134310. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134311. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134312. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134313. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134314. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134315. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134316. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134317. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134318. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134319. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134320. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134321. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134322. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134323. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134324. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134325. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134326. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134327. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134328. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134329. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134330. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134331. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134332. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134333. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134334. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134335. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134336. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134337. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134338. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134339. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134340. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134341. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134342. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134343. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134344. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134345. 0,
  134346. };
  134347. static float _vq_quantthresh__44u5__p3_0[] = {
  134348. -1.5, -0.5, 0.5, 1.5,
  134349. };
  134350. static long _vq_quantmap__44u5__p3_0[] = {
  134351. 3, 1, 0, 2, 4,
  134352. };
  134353. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134354. _vq_quantthresh__44u5__p3_0,
  134355. _vq_quantmap__44u5__p3_0,
  134356. 5,
  134357. 5
  134358. };
  134359. static static_codebook _44u5__p3_0 = {
  134360. 4, 625,
  134361. _vq_lengthlist__44u5__p3_0,
  134362. 1, -533725184, 1611661312, 3, 0,
  134363. _vq_quantlist__44u5__p3_0,
  134364. NULL,
  134365. &_vq_auxt__44u5__p3_0,
  134366. NULL,
  134367. 0
  134368. };
  134369. static long _vq_quantlist__44u5__p4_0[] = {
  134370. 2,
  134371. 1,
  134372. 3,
  134373. 0,
  134374. 4,
  134375. };
  134376. static long _vq_lengthlist__44u5__p4_0[] = {
  134377. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134378. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134379. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134380. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134381. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134382. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134383. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134384. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134385. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134386. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134387. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134388. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134389. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134390. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134391. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134392. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134393. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134394. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134395. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134396. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134397. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134398. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134399. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134400. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134401. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134402. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134403. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134404. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134405. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134406. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134407. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134408. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134409. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134410. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134411. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134412. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134413. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134414. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134415. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134416. 12,
  134417. };
  134418. static float _vq_quantthresh__44u5__p4_0[] = {
  134419. -1.5, -0.5, 0.5, 1.5,
  134420. };
  134421. static long _vq_quantmap__44u5__p4_0[] = {
  134422. 3, 1, 0, 2, 4,
  134423. };
  134424. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134425. _vq_quantthresh__44u5__p4_0,
  134426. _vq_quantmap__44u5__p4_0,
  134427. 5,
  134428. 5
  134429. };
  134430. static static_codebook _44u5__p4_0 = {
  134431. 4, 625,
  134432. _vq_lengthlist__44u5__p4_0,
  134433. 1, -533725184, 1611661312, 3, 0,
  134434. _vq_quantlist__44u5__p4_0,
  134435. NULL,
  134436. &_vq_auxt__44u5__p4_0,
  134437. NULL,
  134438. 0
  134439. };
  134440. static long _vq_quantlist__44u5__p5_0[] = {
  134441. 4,
  134442. 3,
  134443. 5,
  134444. 2,
  134445. 6,
  134446. 1,
  134447. 7,
  134448. 0,
  134449. 8,
  134450. };
  134451. static long _vq_lengthlist__44u5__p5_0[] = {
  134452. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134453. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134454. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134455. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134456. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134457. 14,
  134458. };
  134459. static float _vq_quantthresh__44u5__p5_0[] = {
  134460. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134461. };
  134462. static long _vq_quantmap__44u5__p5_0[] = {
  134463. 7, 5, 3, 1, 0, 2, 4, 6,
  134464. 8,
  134465. };
  134466. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134467. _vq_quantthresh__44u5__p5_0,
  134468. _vq_quantmap__44u5__p5_0,
  134469. 9,
  134470. 9
  134471. };
  134472. static static_codebook _44u5__p5_0 = {
  134473. 2, 81,
  134474. _vq_lengthlist__44u5__p5_0,
  134475. 1, -531628032, 1611661312, 4, 0,
  134476. _vq_quantlist__44u5__p5_0,
  134477. NULL,
  134478. &_vq_auxt__44u5__p5_0,
  134479. NULL,
  134480. 0
  134481. };
  134482. static long _vq_quantlist__44u5__p6_0[] = {
  134483. 4,
  134484. 3,
  134485. 5,
  134486. 2,
  134487. 6,
  134488. 1,
  134489. 7,
  134490. 0,
  134491. 8,
  134492. };
  134493. static long _vq_lengthlist__44u5__p6_0[] = {
  134494. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134495. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134496. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134497. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134498. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134499. 11,
  134500. };
  134501. static float _vq_quantthresh__44u5__p6_0[] = {
  134502. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134503. };
  134504. static long _vq_quantmap__44u5__p6_0[] = {
  134505. 7, 5, 3, 1, 0, 2, 4, 6,
  134506. 8,
  134507. };
  134508. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134509. _vq_quantthresh__44u5__p6_0,
  134510. _vq_quantmap__44u5__p6_0,
  134511. 9,
  134512. 9
  134513. };
  134514. static static_codebook _44u5__p6_0 = {
  134515. 2, 81,
  134516. _vq_lengthlist__44u5__p6_0,
  134517. 1, -531628032, 1611661312, 4, 0,
  134518. _vq_quantlist__44u5__p6_0,
  134519. NULL,
  134520. &_vq_auxt__44u5__p6_0,
  134521. NULL,
  134522. 0
  134523. };
  134524. static long _vq_quantlist__44u5__p7_0[] = {
  134525. 1,
  134526. 0,
  134527. 2,
  134528. };
  134529. static long _vq_lengthlist__44u5__p7_0[] = {
  134530. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134531. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134532. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134533. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134534. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134535. 12,
  134536. };
  134537. static float _vq_quantthresh__44u5__p7_0[] = {
  134538. -5.5, 5.5,
  134539. };
  134540. static long _vq_quantmap__44u5__p7_0[] = {
  134541. 1, 0, 2,
  134542. };
  134543. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134544. _vq_quantthresh__44u5__p7_0,
  134545. _vq_quantmap__44u5__p7_0,
  134546. 3,
  134547. 3
  134548. };
  134549. static static_codebook _44u5__p7_0 = {
  134550. 4, 81,
  134551. _vq_lengthlist__44u5__p7_0,
  134552. 1, -529137664, 1618345984, 2, 0,
  134553. _vq_quantlist__44u5__p7_0,
  134554. NULL,
  134555. &_vq_auxt__44u5__p7_0,
  134556. NULL,
  134557. 0
  134558. };
  134559. static long _vq_quantlist__44u5__p7_1[] = {
  134560. 5,
  134561. 4,
  134562. 6,
  134563. 3,
  134564. 7,
  134565. 2,
  134566. 8,
  134567. 1,
  134568. 9,
  134569. 0,
  134570. 10,
  134571. };
  134572. static long _vq_lengthlist__44u5__p7_1[] = {
  134573. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134574. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134575. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134576. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134577. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134578. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134579. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134580. 9, 9, 9, 9, 9,10,10,10,10,
  134581. };
  134582. static float _vq_quantthresh__44u5__p7_1[] = {
  134583. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134584. 3.5, 4.5,
  134585. };
  134586. static long _vq_quantmap__44u5__p7_1[] = {
  134587. 9, 7, 5, 3, 1, 0, 2, 4,
  134588. 6, 8, 10,
  134589. };
  134590. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134591. _vq_quantthresh__44u5__p7_1,
  134592. _vq_quantmap__44u5__p7_1,
  134593. 11,
  134594. 11
  134595. };
  134596. static static_codebook _44u5__p7_1 = {
  134597. 2, 121,
  134598. _vq_lengthlist__44u5__p7_1,
  134599. 1, -531365888, 1611661312, 4, 0,
  134600. _vq_quantlist__44u5__p7_1,
  134601. NULL,
  134602. &_vq_auxt__44u5__p7_1,
  134603. NULL,
  134604. 0
  134605. };
  134606. static long _vq_quantlist__44u5__p8_0[] = {
  134607. 5,
  134608. 4,
  134609. 6,
  134610. 3,
  134611. 7,
  134612. 2,
  134613. 8,
  134614. 1,
  134615. 9,
  134616. 0,
  134617. 10,
  134618. };
  134619. static long _vq_lengthlist__44u5__p8_0[] = {
  134620. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134621. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134622. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134623. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134624. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134625. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134626. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134627. 12,13,13,14,14,14,14,15,15,
  134628. };
  134629. static float _vq_quantthresh__44u5__p8_0[] = {
  134630. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134631. 38.5, 49.5,
  134632. };
  134633. static long _vq_quantmap__44u5__p8_0[] = {
  134634. 9, 7, 5, 3, 1, 0, 2, 4,
  134635. 6, 8, 10,
  134636. };
  134637. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134638. _vq_quantthresh__44u5__p8_0,
  134639. _vq_quantmap__44u5__p8_0,
  134640. 11,
  134641. 11
  134642. };
  134643. static static_codebook _44u5__p8_0 = {
  134644. 2, 121,
  134645. _vq_lengthlist__44u5__p8_0,
  134646. 1, -524582912, 1618345984, 4, 0,
  134647. _vq_quantlist__44u5__p8_0,
  134648. NULL,
  134649. &_vq_auxt__44u5__p8_0,
  134650. NULL,
  134651. 0
  134652. };
  134653. static long _vq_quantlist__44u5__p8_1[] = {
  134654. 5,
  134655. 4,
  134656. 6,
  134657. 3,
  134658. 7,
  134659. 2,
  134660. 8,
  134661. 1,
  134662. 9,
  134663. 0,
  134664. 10,
  134665. };
  134666. static long _vq_lengthlist__44u5__p8_1[] = {
  134667. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134668. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134669. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134670. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134671. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134672. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134673. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134674. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134675. };
  134676. static float _vq_quantthresh__44u5__p8_1[] = {
  134677. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134678. 3.5, 4.5,
  134679. };
  134680. static long _vq_quantmap__44u5__p8_1[] = {
  134681. 9, 7, 5, 3, 1, 0, 2, 4,
  134682. 6, 8, 10,
  134683. };
  134684. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134685. _vq_quantthresh__44u5__p8_1,
  134686. _vq_quantmap__44u5__p8_1,
  134687. 11,
  134688. 11
  134689. };
  134690. static static_codebook _44u5__p8_1 = {
  134691. 2, 121,
  134692. _vq_lengthlist__44u5__p8_1,
  134693. 1, -531365888, 1611661312, 4, 0,
  134694. _vq_quantlist__44u5__p8_1,
  134695. NULL,
  134696. &_vq_auxt__44u5__p8_1,
  134697. NULL,
  134698. 0
  134699. };
  134700. static long _vq_quantlist__44u5__p9_0[] = {
  134701. 6,
  134702. 5,
  134703. 7,
  134704. 4,
  134705. 8,
  134706. 3,
  134707. 9,
  134708. 2,
  134709. 10,
  134710. 1,
  134711. 11,
  134712. 0,
  134713. 12,
  134714. };
  134715. static long _vq_lengthlist__44u5__p9_0[] = {
  134716. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134717. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134718. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134719. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134720. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134721. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134722. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134723. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134724. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134725. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134726. 12,12,12,12,12,12,12,12,12,
  134727. };
  134728. static float _vq_quantthresh__44u5__p9_0[] = {
  134729. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134730. 637.5, 892.5, 1147.5, 1402.5,
  134731. };
  134732. static long _vq_quantmap__44u5__p9_0[] = {
  134733. 11, 9, 7, 5, 3, 1, 0, 2,
  134734. 4, 6, 8, 10, 12,
  134735. };
  134736. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134737. _vq_quantthresh__44u5__p9_0,
  134738. _vq_quantmap__44u5__p9_0,
  134739. 13,
  134740. 13
  134741. };
  134742. static static_codebook _44u5__p9_0 = {
  134743. 2, 169,
  134744. _vq_lengthlist__44u5__p9_0,
  134745. 1, -514332672, 1627381760, 4, 0,
  134746. _vq_quantlist__44u5__p9_0,
  134747. NULL,
  134748. &_vq_auxt__44u5__p9_0,
  134749. NULL,
  134750. 0
  134751. };
  134752. static long _vq_quantlist__44u5__p9_1[] = {
  134753. 7,
  134754. 6,
  134755. 8,
  134756. 5,
  134757. 9,
  134758. 4,
  134759. 10,
  134760. 3,
  134761. 11,
  134762. 2,
  134763. 12,
  134764. 1,
  134765. 13,
  134766. 0,
  134767. 14,
  134768. };
  134769. static long _vq_lengthlist__44u5__p9_1[] = {
  134770. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134771. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134772. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134773. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134774. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134775. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134776. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134777. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134778. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134779. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134780. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134781. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134782. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134783. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134784. 14,
  134785. };
  134786. static float _vq_quantthresh__44u5__p9_1[] = {
  134787. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134788. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134789. };
  134790. static long _vq_quantmap__44u5__p9_1[] = {
  134791. 13, 11, 9, 7, 5, 3, 1, 0,
  134792. 2, 4, 6, 8, 10, 12, 14,
  134793. };
  134794. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134795. _vq_quantthresh__44u5__p9_1,
  134796. _vq_quantmap__44u5__p9_1,
  134797. 15,
  134798. 15
  134799. };
  134800. static static_codebook _44u5__p9_1 = {
  134801. 2, 225,
  134802. _vq_lengthlist__44u5__p9_1,
  134803. 1, -522338304, 1620115456, 4, 0,
  134804. _vq_quantlist__44u5__p9_1,
  134805. NULL,
  134806. &_vq_auxt__44u5__p9_1,
  134807. NULL,
  134808. 0
  134809. };
  134810. static long _vq_quantlist__44u5__p9_2[] = {
  134811. 8,
  134812. 7,
  134813. 9,
  134814. 6,
  134815. 10,
  134816. 5,
  134817. 11,
  134818. 4,
  134819. 12,
  134820. 3,
  134821. 13,
  134822. 2,
  134823. 14,
  134824. 1,
  134825. 15,
  134826. 0,
  134827. 16,
  134828. };
  134829. static long _vq_lengthlist__44u5__p9_2[] = {
  134830. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134831. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134832. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134833. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134834. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134835. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134836. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134837. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134838. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134839. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134840. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134841. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134842. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134843. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134844. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134845. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134846. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134847. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134848. 10,
  134849. };
  134850. static float _vq_quantthresh__44u5__p9_2[] = {
  134851. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134852. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134853. };
  134854. static long _vq_quantmap__44u5__p9_2[] = {
  134855. 15, 13, 11, 9, 7, 5, 3, 1,
  134856. 0, 2, 4, 6, 8, 10, 12, 14,
  134857. 16,
  134858. };
  134859. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134860. _vq_quantthresh__44u5__p9_2,
  134861. _vq_quantmap__44u5__p9_2,
  134862. 17,
  134863. 17
  134864. };
  134865. static static_codebook _44u5__p9_2 = {
  134866. 2, 289,
  134867. _vq_lengthlist__44u5__p9_2,
  134868. 1, -529530880, 1611661312, 5, 0,
  134869. _vq_quantlist__44u5__p9_2,
  134870. NULL,
  134871. &_vq_auxt__44u5__p9_2,
  134872. NULL,
  134873. 0
  134874. };
  134875. static long _huff_lengthlist__44u5__short[] = {
  134876. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134877. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134878. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134879. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134880. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134881. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134882. 6, 8,15,17,
  134883. };
  134884. static static_codebook _huff_book__44u5__short = {
  134885. 2, 100,
  134886. _huff_lengthlist__44u5__short,
  134887. 0, 0, 0, 0, 0,
  134888. NULL,
  134889. NULL,
  134890. NULL,
  134891. NULL,
  134892. 0
  134893. };
  134894. static long _huff_lengthlist__44u6__long[] = {
  134895. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134896. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134897. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134898. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134899. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134900. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134901. 13, 8, 7, 7,
  134902. };
  134903. static static_codebook _huff_book__44u6__long = {
  134904. 2, 100,
  134905. _huff_lengthlist__44u6__long,
  134906. 0, 0, 0, 0, 0,
  134907. NULL,
  134908. NULL,
  134909. NULL,
  134910. NULL,
  134911. 0
  134912. };
  134913. static long _vq_quantlist__44u6__p1_0[] = {
  134914. 1,
  134915. 0,
  134916. 2,
  134917. };
  134918. static long _vq_lengthlist__44u6__p1_0[] = {
  134919. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134920. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134921. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134922. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134923. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134924. 12,
  134925. };
  134926. static float _vq_quantthresh__44u6__p1_0[] = {
  134927. -0.5, 0.5,
  134928. };
  134929. static long _vq_quantmap__44u6__p1_0[] = {
  134930. 1, 0, 2,
  134931. };
  134932. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  134933. _vq_quantthresh__44u6__p1_0,
  134934. _vq_quantmap__44u6__p1_0,
  134935. 3,
  134936. 3
  134937. };
  134938. static static_codebook _44u6__p1_0 = {
  134939. 4, 81,
  134940. _vq_lengthlist__44u6__p1_0,
  134941. 1, -535822336, 1611661312, 2, 0,
  134942. _vq_quantlist__44u6__p1_0,
  134943. NULL,
  134944. &_vq_auxt__44u6__p1_0,
  134945. NULL,
  134946. 0
  134947. };
  134948. static long _vq_quantlist__44u6__p2_0[] = {
  134949. 1,
  134950. 0,
  134951. 2,
  134952. };
  134953. static long _vq_lengthlist__44u6__p2_0[] = {
  134954. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134955. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134956. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  134957. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134958. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134959. 9,
  134960. };
  134961. static float _vq_quantthresh__44u6__p2_0[] = {
  134962. -0.5, 0.5,
  134963. };
  134964. static long _vq_quantmap__44u6__p2_0[] = {
  134965. 1, 0, 2,
  134966. };
  134967. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  134968. _vq_quantthresh__44u6__p2_0,
  134969. _vq_quantmap__44u6__p2_0,
  134970. 3,
  134971. 3
  134972. };
  134973. static static_codebook _44u6__p2_0 = {
  134974. 4, 81,
  134975. _vq_lengthlist__44u6__p2_0,
  134976. 1, -535822336, 1611661312, 2, 0,
  134977. _vq_quantlist__44u6__p2_0,
  134978. NULL,
  134979. &_vq_auxt__44u6__p2_0,
  134980. NULL,
  134981. 0
  134982. };
  134983. static long _vq_quantlist__44u6__p3_0[] = {
  134984. 2,
  134985. 1,
  134986. 3,
  134987. 0,
  134988. 4,
  134989. };
  134990. static long _vq_lengthlist__44u6__p3_0[] = {
  134991. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134992. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  134993. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134994. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  134995. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  134996. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  134997. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  134998. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  134999. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135000. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135001. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135002. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135003. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135004. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135005. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135006. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135007. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135008. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135009. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135010. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135011. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135012. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135013. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135014. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135015. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135016. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135017. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135018. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135019. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135020. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135021. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135022. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135023. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135024. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135025. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135026. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135027. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135028. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135029. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135030. 19,
  135031. };
  135032. static float _vq_quantthresh__44u6__p3_0[] = {
  135033. -1.5, -0.5, 0.5, 1.5,
  135034. };
  135035. static long _vq_quantmap__44u6__p3_0[] = {
  135036. 3, 1, 0, 2, 4,
  135037. };
  135038. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135039. _vq_quantthresh__44u6__p3_0,
  135040. _vq_quantmap__44u6__p3_0,
  135041. 5,
  135042. 5
  135043. };
  135044. static static_codebook _44u6__p3_0 = {
  135045. 4, 625,
  135046. _vq_lengthlist__44u6__p3_0,
  135047. 1, -533725184, 1611661312, 3, 0,
  135048. _vq_quantlist__44u6__p3_0,
  135049. NULL,
  135050. &_vq_auxt__44u6__p3_0,
  135051. NULL,
  135052. 0
  135053. };
  135054. static long _vq_quantlist__44u6__p4_0[] = {
  135055. 2,
  135056. 1,
  135057. 3,
  135058. 0,
  135059. 4,
  135060. };
  135061. static long _vq_lengthlist__44u6__p4_0[] = {
  135062. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135063. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135064. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135065. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135066. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135067. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135068. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135069. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135070. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135071. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135072. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135073. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135074. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135075. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135076. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135077. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135078. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135079. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135080. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135081. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135082. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135083. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135084. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135085. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135086. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135087. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135088. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135089. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135090. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135091. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135092. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135093. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135094. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135095. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135096. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135097. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135098. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135099. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135100. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135101. 13,
  135102. };
  135103. static float _vq_quantthresh__44u6__p4_0[] = {
  135104. -1.5, -0.5, 0.5, 1.5,
  135105. };
  135106. static long _vq_quantmap__44u6__p4_0[] = {
  135107. 3, 1, 0, 2, 4,
  135108. };
  135109. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135110. _vq_quantthresh__44u6__p4_0,
  135111. _vq_quantmap__44u6__p4_0,
  135112. 5,
  135113. 5
  135114. };
  135115. static static_codebook _44u6__p4_0 = {
  135116. 4, 625,
  135117. _vq_lengthlist__44u6__p4_0,
  135118. 1, -533725184, 1611661312, 3, 0,
  135119. _vq_quantlist__44u6__p4_0,
  135120. NULL,
  135121. &_vq_auxt__44u6__p4_0,
  135122. NULL,
  135123. 0
  135124. };
  135125. static long _vq_quantlist__44u6__p5_0[] = {
  135126. 4,
  135127. 3,
  135128. 5,
  135129. 2,
  135130. 6,
  135131. 1,
  135132. 7,
  135133. 0,
  135134. 8,
  135135. };
  135136. static long _vq_lengthlist__44u6__p5_0[] = {
  135137. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135138. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135139. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135140. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135141. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135142. 14,
  135143. };
  135144. static float _vq_quantthresh__44u6__p5_0[] = {
  135145. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135146. };
  135147. static long _vq_quantmap__44u6__p5_0[] = {
  135148. 7, 5, 3, 1, 0, 2, 4, 6,
  135149. 8,
  135150. };
  135151. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135152. _vq_quantthresh__44u6__p5_0,
  135153. _vq_quantmap__44u6__p5_0,
  135154. 9,
  135155. 9
  135156. };
  135157. static static_codebook _44u6__p5_0 = {
  135158. 2, 81,
  135159. _vq_lengthlist__44u6__p5_0,
  135160. 1, -531628032, 1611661312, 4, 0,
  135161. _vq_quantlist__44u6__p5_0,
  135162. NULL,
  135163. &_vq_auxt__44u6__p5_0,
  135164. NULL,
  135165. 0
  135166. };
  135167. static long _vq_quantlist__44u6__p6_0[] = {
  135168. 4,
  135169. 3,
  135170. 5,
  135171. 2,
  135172. 6,
  135173. 1,
  135174. 7,
  135175. 0,
  135176. 8,
  135177. };
  135178. static long _vq_lengthlist__44u6__p6_0[] = {
  135179. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135180. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135181. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135182. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135183. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135184. 12,
  135185. };
  135186. static float _vq_quantthresh__44u6__p6_0[] = {
  135187. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135188. };
  135189. static long _vq_quantmap__44u6__p6_0[] = {
  135190. 7, 5, 3, 1, 0, 2, 4, 6,
  135191. 8,
  135192. };
  135193. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135194. _vq_quantthresh__44u6__p6_0,
  135195. _vq_quantmap__44u6__p6_0,
  135196. 9,
  135197. 9
  135198. };
  135199. static static_codebook _44u6__p6_0 = {
  135200. 2, 81,
  135201. _vq_lengthlist__44u6__p6_0,
  135202. 1, -531628032, 1611661312, 4, 0,
  135203. _vq_quantlist__44u6__p6_0,
  135204. NULL,
  135205. &_vq_auxt__44u6__p6_0,
  135206. NULL,
  135207. 0
  135208. };
  135209. static long _vq_quantlist__44u6__p7_0[] = {
  135210. 1,
  135211. 0,
  135212. 2,
  135213. };
  135214. static long _vq_lengthlist__44u6__p7_0[] = {
  135215. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135216. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135217. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135218. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135219. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135220. 10,
  135221. };
  135222. static float _vq_quantthresh__44u6__p7_0[] = {
  135223. -5.5, 5.5,
  135224. };
  135225. static long _vq_quantmap__44u6__p7_0[] = {
  135226. 1, 0, 2,
  135227. };
  135228. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135229. _vq_quantthresh__44u6__p7_0,
  135230. _vq_quantmap__44u6__p7_0,
  135231. 3,
  135232. 3
  135233. };
  135234. static static_codebook _44u6__p7_0 = {
  135235. 4, 81,
  135236. _vq_lengthlist__44u6__p7_0,
  135237. 1, -529137664, 1618345984, 2, 0,
  135238. _vq_quantlist__44u6__p7_0,
  135239. NULL,
  135240. &_vq_auxt__44u6__p7_0,
  135241. NULL,
  135242. 0
  135243. };
  135244. static long _vq_quantlist__44u6__p7_1[] = {
  135245. 5,
  135246. 4,
  135247. 6,
  135248. 3,
  135249. 7,
  135250. 2,
  135251. 8,
  135252. 1,
  135253. 9,
  135254. 0,
  135255. 10,
  135256. };
  135257. static long _vq_lengthlist__44u6__p7_1[] = {
  135258. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135259. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135260. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135261. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135262. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135263. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135264. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135265. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135266. };
  135267. static float _vq_quantthresh__44u6__p7_1[] = {
  135268. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135269. 3.5, 4.5,
  135270. };
  135271. static long _vq_quantmap__44u6__p7_1[] = {
  135272. 9, 7, 5, 3, 1, 0, 2, 4,
  135273. 6, 8, 10,
  135274. };
  135275. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135276. _vq_quantthresh__44u6__p7_1,
  135277. _vq_quantmap__44u6__p7_1,
  135278. 11,
  135279. 11
  135280. };
  135281. static static_codebook _44u6__p7_1 = {
  135282. 2, 121,
  135283. _vq_lengthlist__44u6__p7_1,
  135284. 1, -531365888, 1611661312, 4, 0,
  135285. _vq_quantlist__44u6__p7_1,
  135286. NULL,
  135287. &_vq_auxt__44u6__p7_1,
  135288. NULL,
  135289. 0
  135290. };
  135291. static long _vq_quantlist__44u6__p8_0[] = {
  135292. 5,
  135293. 4,
  135294. 6,
  135295. 3,
  135296. 7,
  135297. 2,
  135298. 8,
  135299. 1,
  135300. 9,
  135301. 0,
  135302. 10,
  135303. };
  135304. static long _vq_lengthlist__44u6__p8_0[] = {
  135305. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135306. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135307. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135308. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135309. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135310. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135311. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135312. 12,13,13,14,14,14,15,15,15,
  135313. };
  135314. static float _vq_quantthresh__44u6__p8_0[] = {
  135315. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135316. 38.5, 49.5,
  135317. };
  135318. static long _vq_quantmap__44u6__p8_0[] = {
  135319. 9, 7, 5, 3, 1, 0, 2, 4,
  135320. 6, 8, 10,
  135321. };
  135322. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135323. _vq_quantthresh__44u6__p8_0,
  135324. _vq_quantmap__44u6__p8_0,
  135325. 11,
  135326. 11
  135327. };
  135328. static static_codebook _44u6__p8_0 = {
  135329. 2, 121,
  135330. _vq_lengthlist__44u6__p8_0,
  135331. 1, -524582912, 1618345984, 4, 0,
  135332. _vq_quantlist__44u6__p8_0,
  135333. NULL,
  135334. &_vq_auxt__44u6__p8_0,
  135335. NULL,
  135336. 0
  135337. };
  135338. static long _vq_quantlist__44u6__p8_1[] = {
  135339. 5,
  135340. 4,
  135341. 6,
  135342. 3,
  135343. 7,
  135344. 2,
  135345. 8,
  135346. 1,
  135347. 9,
  135348. 0,
  135349. 10,
  135350. };
  135351. static long _vq_lengthlist__44u6__p8_1[] = {
  135352. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135353. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135354. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135355. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135356. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135357. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135358. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135359. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135360. };
  135361. static float _vq_quantthresh__44u6__p8_1[] = {
  135362. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135363. 3.5, 4.5,
  135364. };
  135365. static long _vq_quantmap__44u6__p8_1[] = {
  135366. 9, 7, 5, 3, 1, 0, 2, 4,
  135367. 6, 8, 10,
  135368. };
  135369. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135370. _vq_quantthresh__44u6__p8_1,
  135371. _vq_quantmap__44u6__p8_1,
  135372. 11,
  135373. 11
  135374. };
  135375. static static_codebook _44u6__p8_1 = {
  135376. 2, 121,
  135377. _vq_lengthlist__44u6__p8_1,
  135378. 1, -531365888, 1611661312, 4, 0,
  135379. _vq_quantlist__44u6__p8_1,
  135380. NULL,
  135381. &_vq_auxt__44u6__p8_1,
  135382. NULL,
  135383. 0
  135384. };
  135385. static long _vq_quantlist__44u6__p9_0[] = {
  135386. 7,
  135387. 6,
  135388. 8,
  135389. 5,
  135390. 9,
  135391. 4,
  135392. 10,
  135393. 3,
  135394. 11,
  135395. 2,
  135396. 12,
  135397. 1,
  135398. 13,
  135399. 0,
  135400. 14,
  135401. };
  135402. static long _vq_lengthlist__44u6__p9_0[] = {
  135403. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135404. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135405. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135406. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135407. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135408. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135409. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135410. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135411. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135412. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135413. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135414. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135415. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135416. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135417. 14,
  135418. };
  135419. static float _vq_quantthresh__44u6__p9_0[] = {
  135420. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135421. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135422. };
  135423. static long _vq_quantmap__44u6__p9_0[] = {
  135424. 13, 11, 9, 7, 5, 3, 1, 0,
  135425. 2, 4, 6, 8, 10, 12, 14,
  135426. };
  135427. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135428. _vq_quantthresh__44u6__p9_0,
  135429. _vq_quantmap__44u6__p9_0,
  135430. 15,
  135431. 15
  135432. };
  135433. static static_codebook _44u6__p9_0 = {
  135434. 2, 225,
  135435. _vq_lengthlist__44u6__p9_0,
  135436. 1, -514071552, 1627381760, 4, 0,
  135437. _vq_quantlist__44u6__p9_0,
  135438. NULL,
  135439. &_vq_auxt__44u6__p9_0,
  135440. NULL,
  135441. 0
  135442. };
  135443. static long _vq_quantlist__44u6__p9_1[] = {
  135444. 7,
  135445. 6,
  135446. 8,
  135447. 5,
  135448. 9,
  135449. 4,
  135450. 10,
  135451. 3,
  135452. 11,
  135453. 2,
  135454. 12,
  135455. 1,
  135456. 13,
  135457. 0,
  135458. 14,
  135459. };
  135460. static long _vq_lengthlist__44u6__p9_1[] = {
  135461. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135462. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135463. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135464. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135465. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135466. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135467. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135468. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135469. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135470. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135471. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135472. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135473. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135474. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135475. 13,
  135476. };
  135477. static float _vq_quantthresh__44u6__p9_1[] = {
  135478. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135479. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135480. };
  135481. static long _vq_quantmap__44u6__p9_1[] = {
  135482. 13, 11, 9, 7, 5, 3, 1, 0,
  135483. 2, 4, 6, 8, 10, 12, 14,
  135484. };
  135485. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135486. _vq_quantthresh__44u6__p9_1,
  135487. _vq_quantmap__44u6__p9_1,
  135488. 15,
  135489. 15
  135490. };
  135491. static static_codebook _44u6__p9_1 = {
  135492. 2, 225,
  135493. _vq_lengthlist__44u6__p9_1,
  135494. 1, -522338304, 1620115456, 4, 0,
  135495. _vq_quantlist__44u6__p9_1,
  135496. NULL,
  135497. &_vq_auxt__44u6__p9_1,
  135498. NULL,
  135499. 0
  135500. };
  135501. static long _vq_quantlist__44u6__p9_2[] = {
  135502. 8,
  135503. 7,
  135504. 9,
  135505. 6,
  135506. 10,
  135507. 5,
  135508. 11,
  135509. 4,
  135510. 12,
  135511. 3,
  135512. 13,
  135513. 2,
  135514. 14,
  135515. 1,
  135516. 15,
  135517. 0,
  135518. 16,
  135519. };
  135520. static long _vq_lengthlist__44u6__p9_2[] = {
  135521. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135522. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135523. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135524. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135525. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135526. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135527. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135528. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135529. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135530. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135531. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135532. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135533. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135534. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135535. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135536. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135537. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135538. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135539. 10,
  135540. };
  135541. static float _vq_quantthresh__44u6__p9_2[] = {
  135542. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135543. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135544. };
  135545. static long _vq_quantmap__44u6__p9_2[] = {
  135546. 15, 13, 11, 9, 7, 5, 3, 1,
  135547. 0, 2, 4, 6, 8, 10, 12, 14,
  135548. 16,
  135549. };
  135550. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135551. _vq_quantthresh__44u6__p9_2,
  135552. _vq_quantmap__44u6__p9_2,
  135553. 17,
  135554. 17
  135555. };
  135556. static static_codebook _44u6__p9_2 = {
  135557. 2, 289,
  135558. _vq_lengthlist__44u6__p9_2,
  135559. 1, -529530880, 1611661312, 5, 0,
  135560. _vq_quantlist__44u6__p9_2,
  135561. NULL,
  135562. &_vq_auxt__44u6__p9_2,
  135563. NULL,
  135564. 0
  135565. };
  135566. static long _huff_lengthlist__44u6__short[] = {
  135567. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135568. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135569. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135570. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135571. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135572. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135573. 7, 6, 9,16,
  135574. };
  135575. static static_codebook _huff_book__44u6__short = {
  135576. 2, 100,
  135577. _huff_lengthlist__44u6__short,
  135578. 0, 0, 0, 0, 0,
  135579. NULL,
  135580. NULL,
  135581. NULL,
  135582. NULL,
  135583. 0
  135584. };
  135585. static long _huff_lengthlist__44u7__long[] = {
  135586. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135587. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135588. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135589. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135590. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135591. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135592. 12, 8, 6, 7,
  135593. };
  135594. static static_codebook _huff_book__44u7__long = {
  135595. 2, 100,
  135596. _huff_lengthlist__44u7__long,
  135597. 0, 0, 0, 0, 0,
  135598. NULL,
  135599. NULL,
  135600. NULL,
  135601. NULL,
  135602. 0
  135603. };
  135604. static long _vq_quantlist__44u7__p1_0[] = {
  135605. 1,
  135606. 0,
  135607. 2,
  135608. };
  135609. static long _vq_lengthlist__44u7__p1_0[] = {
  135610. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135611. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135612. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135613. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135614. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135615. 12,
  135616. };
  135617. static float _vq_quantthresh__44u7__p1_0[] = {
  135618. -0.5, 0.5,
  135619. };
  135620. static long _vq_quantmap__44u7__p1_0[] = {
  135621. 1, 0, 2,
  135622. };
  135623. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135624. _vq_quantthresh__44u7__p1_0,
  135625. _vq_quantmap__44u7__p1_0,
  135626. 3,
  135627. 3
  135628. };
  135629. static static_codebook _44u7__p1_0 = {
  135630. 4, 81,
  135631. _vq_lengthlist__44u7__p1_0,
  135632. 1, -535822336, 1611661312, 2, 0,
  135633. _vq_quantlist__44u7__p1_0,
  135634. NULL,
  135635. &_vq_auxt__44u7__p1_0,
  135636. NULL,
  135637. 0
  135638. };
  135639. static long _vq_quantlist__44u7__p2_0[] = {
  135640. 1,
  135641. 0,
  135642. 2,
  135643. };
  135644. static long _vq_lengthlist__44u7__p2_0[] = {
  135645. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135646. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135647. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135648. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135649. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135650. 9,
  135651. };
  135652. static float _vq_quantthresh__44u7__p2_0[] = {
  135653. -0.5, 0.5,
  135654. };
  135655. static long _vq_quantmap__44u7__p2_0[] = {
  135656. 1, 0, 2,
  135657. };
  135658. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135659. _vq_quantthresh__44u7__p2_0,
  135660. _vq_quantmap__44u7__p2_0,
  135661. 3,
  135662. 3
  135663. };
  135664. static static_codebook _44u7__p2_0 = {
  135665. 4, 81,
  135666. _vq_lengthlist__44u7__p2_0,
  135667. 1, -535822336, 1611661312, 2, 0,
  135668. _vq_quantlist__44u7__p2_0,
  135669. NULL,
  135670. &_vq_auxt__44u7__p2_0,
  135671. NULL,
  135672. 0
  135673. };
  135674. static long _vq_quantlist__44u7__p3_0[] = {
  135675. 2,
  135676. 1,
  135677. 3,
  135678. 0,
  135679. 4,
  135680. };
  135681. static long _vq_lengthlist__44u7__p3_0[] = {
  135682. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135683. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135684. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135685. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135686. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135687. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135688. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135689. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135690. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135691. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135692. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135693. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135694. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135695. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135696. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135697. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135698. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135699. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135700. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135701. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135702. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135703. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135704. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135705. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135706. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135707. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135708. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135709. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135710. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135711. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135712. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135713. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135714. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135715. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135716. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135717. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135718. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135719. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135720. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135721. 0,
  135722. };
  135723. static float _vq_quantthresh__44u7__p3_0[] = {
  135724. -1.5, -0.5, 0.5, 1.5,
  135725. };
  135726. static long _vq_quantmap__44u7__p3_0[] = {
  135727. 3, 1, 0, 2, 4,
  135728. };
  135729. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135730. _vq_quantthresh__44u7__p3_0,
  135731. _vq_quantmap__44u7__p3_0,
  135732. 5,
  135733. 5
  135734. };
  135735. static static_codebook _44u7__p3_0 = {
  135736. 4, 625,
  135737. _vq_lengthlist__44u7__p3_0,
  135738. 1, -533725184, 1611661312, 3, 0,
  135739. _vq_quantlist__44u7__p3_0,
  135740. NULL,
  135741. &_vq_auxt__44u7__p3_0,
  135742. NULL,
  135743. 0
  135744. };
  135745. static long _vq_quantlist__44u7__p4_0[] = {
  135746. 2,
  135747. 1,
  135748. 3,
  135749. 0,
  135750. 4,
  135751. };
  135752. static long _vq_lengthlist__44u7__p4_0[] = {
  135753. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135754. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135755. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135756. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135757. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135758. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135759. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135760. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135761. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135762. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135763. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135764. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135765. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135766. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135767. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135768. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135769. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135770. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135771. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135772. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135773. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135774. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135775. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135776. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135777. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135778. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135779. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135780. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135781. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135782. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135783. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135784. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135785. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135786. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135787. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135788. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135789. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135790. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135791. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135792. 14,
  135793. };
  135794. static float _vq_quantthresh__44u7__p4_0[] = {
  135795. -1.5, -0.5, 0.5, 1.5,
  135796. };
  135797. static long _vq_quantmap__44u7__p4_0[] = {
  135798. 3, 1, 0, 2, 4,
  135799. };
  135800. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135801. _vq_quantthresh__44u7__p4_0,
  135802. _vq_quantmap__44u7__p4_0,
  135803. 5,
  135804. 5
  135805. };
  135806. static static_codebook _44u7__p4_0 = {
  135807. 4, 625,
  135808. _vq_lengthlist__44u7__p4_0,
  135809. 1, -533725184, 1611661312, 3, 0,
  135810. _vq_quantlist__44u7__p4_0,
  135811. NULL,
  135812. &_vq_auxt__44u7__p4_0,
  135813. NULL,
  135814. 0
  135815. };
  135816. static long _vq_quantlist__44u7__p5_0[] = {
  135817. 4,
  135818. 3,
  135819. 5,
  135820. 2,
  135821. 6,
  135822. 1,
  135823. 7,
  135824. 0,
  135825. 8,
  135826. };
  135827. static long _vq_lengthlist__44u7__p5_0[] = {
  135828. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135829. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135830. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135831. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135832. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135833. 14,
  135834. };
  135835. static float _vq_quantthresh__44u7__p5_0[] = {
  135836. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135837. };
  135838. static long _vq_quantmap__44u7__p5_0[] = {
  135839. 7, 5, 3, 1, 0, 2, 4, 6,
  135840. 8,
  135841. };
  135842. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135843. _vq_quantthresh__44u7__p5_0,
  135844. _vq_quantmap__44u7__p5_0,
  135845. 9,
  135846. 9
  135847. };
  135848. static static_codebook _44u7__p5_0 = {
  135849. 2, 81,
  135850. _vq_lengthlist__44u7__p5_0,
  135851. 1, -531628032, 1611661312, 4, 0,
  135852. _vq_quantlist__44u7__p5_0,
  135853. NULL,
  135854. &_vq_auxt__44u7__p5_0,
  135855. NULL,
  135856. 0
  135857. };
  135858. static long _vq_quantlist__44u7__p6_0[] = {
  135859. 4,
  135860. 3,
  135861. 5,
  135862. 2,
  135863. 6,
  135864. 1,
  135865. 7,
  135866. 0,
  135867. 8,
  135868. };
  135869. static long _vq_lengthlist__44u7__p6_0[] = {
  135870. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135871. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135872. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135873. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135874. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135875. 12,
  135876. };
  135877. static float _vq_quantthresh__44u7__p6_0[] = {
  135878. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135879. };
  135880. static long _vq_quantmap__44u7__p6_0[] = {
  135881. 7, 5, 3, 1, 0, 2, 4, 6,
  135882. 8,
  135883. };
  135884. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135885. _vq_quantthresh__44u7__p6_0,
  135886. _vq_quantmap__44u7__p6_0,
  135887. 9,
  135888. 9
  135889. };
  135890. static static_codebook _44u7__p6_0 = {
  135891. 2, 81,
  135892. _vq_lengthlist__44u7__p6_0,
  135893. 1, -531628032, 1611661312, 4, 0,
  135894. _vq_quantlist__44u7__p6_0,
  135895. NULL,
  135896. &_vq_auxt__44u7__p6_0,
  135897. NULL,
  135898. 0
  135899. };
  135900. static long _vq_quantlist__44u7__p7_0[] = {
  135901. 1,
  135902. 0,
  135903. 2,
  135904. };
  135905. static long _vq_lengthlist__44u7__p7_0[] = {
  135906. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135907. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135908. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135909. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135910. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135911. 10,
  135912. };
  135913. static float _vq_quantthresh__44u7__p7_0[] = {
  135914. -5.5, 5.5,
  135915. };
  135916. static long _vq_quantmap__44u7__p7_0[] = {
  135917. 1, 0, 2,
  135918. };
  135919. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135920. _vq_quantthresh__44u7__p7_0,
  135921. _vq_quantmap__44u7__p7_0,
  135922. 3,
  135923. 3
  135924. };
  135925. static static_codebook _44u7__p7_0 = {
  135926. 4, 81,
  135927. _vq_lengthlist__44u7__p7_0,
  135928. 1, -529137664, 1618345984, 2, 0,
  135929. _vq_quantlist__44u7__p7_0,
  135930. NULL,
  135931. &_vq_auxt__44u7__p7_0,
  135932. NULL,
  135933. 0
  135934. };
  135935. static long _vq_quantlist__44u7__p7_1[] = {
  135936. 5,
  135937. 4,
  135938. 6,
  135939. 3,
  135940. 7,
  135941. 2,
  135942. 8,
  135943. 1,
  135944. 9,
  135945. 0,
  135946. 10,
  135947. };
  135948. static long _vq_lengthlist__44u7__p7_1[] = {
  135949. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  135950. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  135951. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  135952. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  135953. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  135954. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135955. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  135956. 8, 9, 9, 9, 9, 9,10,10,10,
  135957. };
  135958. static float _vq_quantthresh__44u7__p7_1[] = {
  135959. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135960. 3.5, 4.5,
  135961. };
  135962. static long _vq_quantmap__44u7__p7_1[] = {
  135963. 9, 7, 5, 3, 1, 0, 2, 4,
  135964. 6, 8, 10,
  135965. };
  135966. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  135967. _vq_quantthresh__44u7__p7_1,
  135968. _vq_quantmap__44u7__p7_1,
  135969. 11,
  135970. 11
  135971. };
  135972. static static_codebook _44u7__p7_1 = {
  135973. 2, 121,
  135974. _vq_lengthlist__44u7__p7_1,
  135975. 1, -531365888, 1611661312, 4, 0,
  135976. _vq_quantlist__44u7__p7_1,
  135977. NULL,
  135978. &_vq_auxt__44u7__p7_1,
  135979. NULL,
  135980. 0
  135981. };
  135982. static long _vq_quantlist__44u7__p8_0[] = {
  135983. 5,
  135984. 4,
  135985. 6,
  135986. 3,
  135987. 7,
  135988. 2,
  135989. 8,
  135990. 1,
  135991. 9,
  135992. 0,
  135993. 10,
  135994. };
  135995. static long _vq_lengthlist__44u7__p8_0[] = {
  135996. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  135997. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  135998. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  135999. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136000. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136001. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136002. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136003. 12,13,13,14,14,15,15,15,16,
  136004. };
  136005. static float _vq_quantthresh__44u7__p8_0[] = {
  136006. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136007. 38.5, 49.5,
  136008. };
  136009. static long _vq_quantmap__44u7__p8_0[] = {
  136010. 9, 7, 5, 3, 1, 0, 2, 4,
  136011. 6, 8, 10,
  136012. };
  136013. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136014. _vq_quantthresh__44u7__p8_0,
  136015. _vq_quantmap__44u7__p8_0,
  136016. 11,
  136017. 11
  136018. };
  136019. static static_codebook _44u7__p8_0 = {
  136020. 2, 121,
  136021. _vq_lengthlist__44u7__p8_0,
  136022. 1, -524582912, 1618345984, 4, 0,
  136023. _vq_quantlist__44u7__p8_0,
  136024. NULL,
  136025. &_vq_auxt__44u7__p8_0,
  136026. NULL,
  136027. 0
  136028. };
  136029. static long _vq_quantlist__44u7__p8_1[] = {
  136030. 5,
  136031. 4,
  136032. 6,
  136033. 3,
  136034. 7,
  136035. 2,
  136036. 8,
  136037. 1,
  136038. 9,
  136039. 0,
  136040. 10,
  136041. };
  136042. static long _vq_lengthlist__44u7__p8_1[] = {
  136043. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136044. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136045. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136046. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136047. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136048. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136049. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136050. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136051. };
  136052. static float _vq_quantthresh__44u7__p8_1[] = {
  136053. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136054. 3.5, 4.5,
  136055. };
  136056. static long _vq_quantmap__44u7__p8_1[] = {
  136057. 9, 7, 5, 3, 1, 0, 2, 4,
  136058. 6, 8, 10,
  136059. };
  136060. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136061. _vq_quantthresh__44u7__p8_1,
  136062. _vq_quantmap__44u7__p8_1,
  136063. 11,
  136064. 11
  136065. };
  136066. static static_codebook _44u7__p8_1 = {
  136067. 2, 121,
  136068. _vq_lengthlist__44u7__p8_1,
  136069. 1, -531365888, 1611661312, 4, 0,
  136070. _vq_quantlist__44u7__p8_1,
  136071. NULL,
  136072. &_vq_auxt__44u7__p8_1,
  136073. NULL,
  136074. 0
  136075. };
  136076. static long _vq_quantlist__44u7__p9_0[] = {
  136077. 5,
  136078. 4,
  136079. 6,
  136080. 3,
  136081. 7,
  136082. 2,
  136083. 8,
  136084. 1,
  136085. 9,
  136086. 0,
  136087. 10,
  136088. };
  136089. static long _vq_lengthlist__44u7__p9_0[] = {
  136090. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136091. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136092. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136093. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136094. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136095. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136096. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136097. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136098. };
  136099. static float _vq_quantthresh__44u7__p9_0[] = {
  136100. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136101. 2229.5, 2866.5,
  136102. };
  136103. static long _vq_quantmap__44u7__p9_0[] = {
  136104. 9, 7, 5, 3, 1, 0, 2, 4,
  136105. 6, 8, 10,
  136106. };
  136107. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136108. _vq_quantthresh__44u7__p9_0,
  136109. _vq_quantmap__44u7__p9_0,
  136110. 11,
  136111. 11
  136112. };
  136113. static static_codebook _44u7__p9_0 = {
  136114. 2, 121,
  136115. _vq_lengthlist__44u7__p9_0,
  136116. 1, -512171520, 1630791680, 4, 0,
  136117. _vq_quantlist__44u7__p9_0,
  136118. NULL,
  136119. &_vq_auxt__44u7__p9_0,
  136120. NULL,
  136121. 0
  136122. };
  136123. static long _vq_quantlist__44u7__p9_1[] = {
  136124. 6,
  136125. 5,
  136126. 7,
  136127. 4,
  136128. 8,
  136129. 3,
  136130. 9,
  136131. 2,
  136132. 10,
  136133. 1,
  136134. 11,
  136135. 0,
  136136. 12,
  136137. };
  136138. static long _vq_lengthlist__44u7__p9_1[] = {
  136139. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136140. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136141. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136142. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136143. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136144. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136145. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136146. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136147. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136148. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136149. 15,15,15,15,17,17,16,17,16,
  136150. };
  136151. static float _vq_quantthresh__44u7__p9_1[] = {
  136152. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136153. 122.5, 171.5, 220.5, 269.5,
  136154. };
  136155. static long _vq_quantmap__44u7__p9_1[] = {
  136156. 11, 9, 7, 5, 3, 1, 0, 2,
  136157. 4, 6, 8, 10, 12,
  136158. };
  136159. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136160. _vq_quantthresh__44u7__p9_1,
  136161. _vq_quantmap__44u7__p9_1,
  136162. 13,
  136163. 13
  136164. };
  136165. static static_codebook _44u7__p9_1 = {
  136166. 2, 169,
  136167. _vq_lengthlist__44u7__p9_1,
  136168. 1, -518889472, 1622704128, 4, 0,
  136169. _vq_quantlist__44u7__p9_1,
  136170. NULL,
  136171. &_vq_auxt__44u7__p9_1,
  136172. NULL,
  136173. 0
  136174. };
  136175. static long _vq_quantlist__44u7__p9_2[] = {
  136176. 24,
  136177. 23,
  136178. 25,
  136179. 22,
  136180. 26,
  136181. 21,
  136182. 27,
  136183. 20,
  136184. 28,
  136185. 19,
  136186. 29,
  136187. 18,
  136188. 30,
  136189. 17,
  136190. 31,
  136191. 16,
  136192. 32,
  136193. 15,
  136194. 33,
  136195. 14,
  136196. 34,
  136197. 13,
  136198. 35,
  136199. 12,
  136200. 36,
  136201. 11,
  136202. 37,
  136203. 10,
  136204. 38,
  136205. 9,
  136206. 39,
  136207. 8,
  136208. 40,
  136209. 7,
  136210. 41,
  136211. 6,
  136212. 42,
  136213. 5,
  136214. 43,
  136215. 4,
  136216. 44,
  136217. 3,
  136218. 45,
  136219. 2,
  136220. 46,
  136221. 1,
  136222. 47,
  136223. 0,
  136224. 48,
  136225. };
  136226. static long _vq_lengthlist__44u7__p9_2[] = {
  136227. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136228. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136229. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136230. 8,
  136231. };
  136232. static float _vq_quantthresh__44u7__p9_2[] = {
  136233. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136234. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136235. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136236. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136237. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136238. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136239. };
  136240. static long _vq_quantmap__44u7__p9_2[] = {
  136241. 47, 45, 43, 41, 39, 37, 35, 33,
  136242. 31, 29, 27, 25, 23, 21, 19, 17,
  136243. 15, 13, 11, 9, 7, 5, 3, 1,
  136244. 0, 2, 4, 6, 8, 10, 12, 14,
  136245. 16, 18, 20, 22, 24, 26, 28, 30,
  136246. 32, 34, 36, 38, 40, 42, 44, 46,
  136247. 48,
  136248. };
  136249. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136250. _vq_quantthresh__44u7__p9_2,
  136251. _vq_quantmap__44u7__p9_2,
  136252. 49,
  136253. 49
  136254. };
  136255. static static_codebook _44u7__p9_2 = {
  136256. 1, 49,
  136257. _vq_lengthlist__44u7__p9_2,
  136258. 1, -526909440, 1611661312, 6, 0,
  136259. _vq_quantlist__44u7__p9_2,
  136260. NULL,
  136261. &_vq_auxt__44u7__p9_2,
  136262. NULL,
  136263. 0
  136264. };
  136265. static long _huff_lengthlist__44u7__short[] = {
  136266. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136267. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136268. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136269. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136270. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136271. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136272. 6, 8, 5, 9,
  136273. };
  136274. static static_codebook _huff_book__44u7__short = {
  136275. 2, 100,
  136276. _huff_lengthlist__44u7__short,
  136277. 0, 0, 0, 0, 0,
  136278. NULL,
  136279. NULL,
  136280. NULL,
  136281. NULL,
  136282. 0
  136283. };
  136284. static long _huff_lengthlist__44u8__long[] = {
  136285. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136286. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136287. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136288. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136289. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136290. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136291. 10, 8, 8, 9,
  136292. };
  136293. static static_codebook _huff_book__44u8__long = {
  136294. 2, 100,
  136295. _huff_lengthlist__44u8__long,
  136296. 0, 0, 0, 0, 0,
  136297. NULL,
  136298. NULL,
  136299. NULL,
  136300. NULL,
  136301. 0
  136302. };
  136303. static long _huff_lengthlist__44u8__short[] = {
  136304. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136305. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136306. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136307. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136308. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136309. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136310. 10,10,15,17,
  136311. };
  136312. static static_codebook _huff_book__44u8__short = {
  136313. 2, 100,
  136314. _huff_lengthlist__44u8__short,
  136315. 0, 0, 0, 0, 0,
  136316. NULL,
  136317. NULL,
  136318. NULL,
  136319. NULL,
  136320. 0
  136321. };
  136322. static long _vq_quantlist__44u8_p1_0[] = {
  136323. 1,
  136324. 0,
  136325. 2,
  136326. };
  136327. static long _vq_lengthlist__44u8_p1_0[] = {
  136328. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136329. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136330. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136331. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136332. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136333. 10,
  136334. };
  136335. static float _vq_quantthresh__44u8_p1_0[] = {
  136336. -0.5, 0.5,
  136337. };
  136338. static long _vq_quantmap__44u8_p1_0[] = {
  136339. 1, 0, 2,
  136340. };
  136341. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136342. _vq_quantthresh__44u8_p1_0,
  136343. _vq_quantmap__44u8_p1_0,
  136344. 3,
  136345. 3
  136346. };
  136347. static static_codebook _44u8_p1_0 = {
  136348. 4, 81,
  136349. _vq_lengthlist__44u8_p1_0,
  136350. 1, -535822336, 1611661312, 2, 0,
  136351. _vq_quantlist__44u8_p1_0,
  136352. NULL,
  136353. &_vq_auxt__44u8_p1_0,
  136354. NULL,
  136355. 0
  136356. };
  136357. static long _vq_quantlist__44u8_p2_0[] = {
  136358. 2,
  136359. 1,
  136360. 3,
  136361. 0,
  136362. 4,
  136363. };
  136364. static long _vq_lengthlist__44u8_p2_0[] = {
  136365. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136366. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136367. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136368. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136369. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136370. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136371. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136372. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136373. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136374. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136375. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136376. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136377. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136378. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136379. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136380. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136381. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136382. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136383. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136384. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136385. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136386. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136387. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136388. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136389. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136390. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136391. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136392. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136393. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136394. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136395. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136396. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136397. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136398. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136399. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136400. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136401. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136402. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136403. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136404. 14,
  136405. };
  136406. static float _vq_quantthresh__44u8_p2_0[] = {
  136407. -1.5, -0.5, 0.5, 1.5,
  136408. };
  136409. static long _vq_quantmap__44u8_p2_0[] = {
  136410. 3, 1, 0, 2, 4,
  136411. };
  136412. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136413. _vq_quantthresh__44u8_p2_0,
  136414. _vq_quantmap__44u8_p2_0,
  136415. 5,
  136416. 5
  136417. };
  136418. static static_codebook _44u8_p2_0 = {
  136419. 4, 625,
  136420. _vq_lengthlist__44u8_p2_0,
  136421. 1, -533725184, 1611661312, 3, 0,
  136422. _vq_quantlist__44u8_p2_0,
  136423. NULL,
  136424. &_vq_auxt__44u8_p2_0,
  136425. NULL,
  136426. 0
  136427. };
  136428. static long _vq_quantlist__44u8_p3_0[] = {
  136429. 4,
  136430. 3,
  136431. 5,
  136432. 2,
  136433. 6,
  136434. 1,
  136435. 7,
  136436. 0,
  136437. 8,
  136438. };
  136439. static long _vq_lengthlist__44u8_p3_0[] = {
  136440. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136441. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136442. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136443. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136444. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136445. 12,
  136446. };
  136447. static float _vq_quantthresh__44u8_p3_0[] = {
  136448. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136449. };
  136450. static long _vq_quantmap__44u8_p3_0[] = {
  136451. 7, 5, 3, 1, 0, 2, 4, 6,
  136452. 8,
  136453. };
  136454. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136455. _vq_quantthresh__44u8_p3_0,
  136456. _vq_quantmap__44u8_p3_0,
  136457. 9,
  136458. 9
  136459. };
  136460. static static_codebook _44u8_p3_0 = {
  136461. 2, 81,
  136462. _vq_lengthlist__44u8_p3_0,
  136463. 1, -531628032, 1611661312, 4, 0,
  136464. _vq_quantlist__44u8_p3_0,
  136465. NULL,
  136466. &_vq_auxt__44u8_p3_0,
  136467. NULL,
  136468. 0
  136469. };
  136470. static long _vq_quantlist__44u8_p4_0[] = {
  136471. 8,
  136472. 7,
  136473. 9,
  136474. 6,
  136475. 10,
  136476. 5,
  136477. 11,
  136478. 4,
  136479. 12,
  136480. 3,
  136481. 13,
  136482. 2,
  136483. 14,
  136484. 1,
  136485. 15,
  136486. 0,
  136487. 16,
  136488. };
  136489. static long _vq_lengthlist__44u8_p4_0[] = {
  136490. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136491. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136492. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136493. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136494. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136495. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136496. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136497. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136498. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136499. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136500. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136501. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136502. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136503. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136504. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136505. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136506. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136507. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136508. 14,
  136509. };
  136510. static float _vq_quantthresh__44u8_p4_0[] = {
  136511. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136512. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136513. };
  136514. static long _vq_quantmap__44u8_p4_0[] = {
  136515. 15, 13, 11, 9, 7, 5, 3, 1,
  136516. 0, 2, 4, 6, 8, 10, 12, 14,
  136517. 16,
  136518. };
  136519. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136520. _vq_quantthresh__44u8_p4_0,
  136521. _vq_quantmap__44u8_p4_0,
  136522. 17,
  136523. 17
  136524. };
  136525. static static_codebook _44u8_p4_0 = {
  136526. 2, 289,
  136527. _vq_lengthlist__44u8_p4_0,
  136528. 1, -529530880, 1611661312, 5, 0,
  136529. _vq_quantlist__44u8_p4_0,
  136530. NULL,
  136531. &_vq_auxt__44u8_p4_0,
  136532. NULL,
  136533. 0
  136534. };
  136535. static long _vq_quantlist__44u8_p5_0[] = {
  136536. 1,
  136537. 0,
  136538. 2,
  136539. };
  136540. static long _vq_lengthlist__44u8_p5_0[] = {
  136541. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136542. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136543. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136544. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136545. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136546. 10,
  136547. };
  136548. static float _vq_quantthresh__44u8_p5_0[] = {
  136549. -5.5, 5.5,
  136550. };
  136551. static long _vq_quantmap__44u8_p5_0[] = {
  136552. 1, 0, 2,
  136553. };
  136554. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136555. _vq_quantthresh__44u8_p5_0,
  136556. _vq_quantmap__44u8_p5_0,
  136557. 3,
  136558. 3
  136559. };
  136560. static static_codebook _44u8_p5_0 = {
  136561. 4, 81,
  136562. _vq_lengthlist__44u8_p5_0,
  136563. 1, -529137664, 1618345984, 2, 0,
  136564. _vq_quantlist__44u8_p5_0,
  136565. NULL,
  136566. &_vq_auxt__44u8_p5_0,
  136567. NULL,
  136568. 0
  136569. };
  136570. static long _vq_quantlist__44u8_p5_1[] = {
  136571. 5,
  136572. 4,
  136573. 6,
  136574. 3,
  136575. 7,
  136576. 2,
  136577. 8,
  136578. 1,
  136579. 9,
  136580. 0,
  136581. 10,
  136582. };
  136583. static long _vq_lengthlist__44u8_p5_1[] = {
  136584. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136585. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136586. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136587. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136588. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136589. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136590. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136591. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136592. };
  136593. static float _vq_quantthresh__44u8_p5_1[] = {
  136594. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136595. 3.5, 4.5,
  136596. };
  136597. static long _vq_quantmap__44u8_p5_1[] = {
  136598. 9, 7, 5, 3, 1, 0, 2, 4,
  136599. 6, 8, 10,
  136600. };
  136601. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136602. _vq_quantthresh__44u8_p5_1,
  136603. _vq_quantmap__44u8_p5_1,
  136604. 11,
  136605. 11
  136606. };
  136607. static static_codebook _44u8_p5_1 = {
  136608. 2, 121,
  136609. _vq_lengthlist__44u8_p5_1,
  136610. 1, -531365888, 1611661312, 4, 0,
  136611. _vq_quantlist__44u8_p5_1,
  136612. NULL,
  136613. &_vq_auxt__44u8_p5_1,
  136614. NULL,
  136615. 0
  136616. };
  136617. static long _vq_quantlist__44u8_p6_0[] = {
  136618. 6,
  136619. 5,
  136620. 7,
  136621. 4,
  136622. 8,
  136623. 3,
  136624. 9,
  136625. 2,
  136626. 10,
  136627. 1,
  136628. 11,
  136629. 0,
  136630. 12,
  136631. };
  136632. static long _vq_lengthlist__44u8_p6_0[] = {
  136633. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136634. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136635. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136636. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136637. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136638. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136639. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136640. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136641. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136642. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136643. 11,11,11,11,11,12,11,12,12,
  136644. };
  136645. static float _vq_quantthresh__44u8_p6_0[] = {
  136646. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136647. 12.5, 17.5, 22.5, 27.5,
  136648. };
  136649. static long _vq_quantmap__44u8_p6_0[] = {
  136650. 11, 9, 7, 5, 3, 1, 0, 2,
  136651. 4, 6, 8, 10, 12,
  136652. };
  136653. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136654. _vq_quantthresh__44u8_p6_0,
  136655. _vq_quantmap__44u8_p6_0,
  136656. 13,
  136657. 13
  136658. };
  136659. static static_codebook _44u8_p6_0 = {
  136660. 2, 169,
  136661. _vq_lengthlist__44u8_p6_0,
  136662. 1, -526516224, 1616117760, 4, 0,
  136663. _vq_quantlist__44u8_p6_0,
  136664. NULL,
  136665. &_vq_auxt__44u8_p6_0,
  136666. NULL,
  136667. 0
  136668. };
  136669. static long _vq_quantlist__44u8_p6_1[] = {
  136670. 2,
  136671. 1,
  136672. 3,
  136673. 0,
  136674. 4,
  136675. };
  136676. static long _vq_lengthlist__44u8_p6_1[] = {
  136677. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136678. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136679. };
  136680. static float _vq_quantthresh__44u8_p6_1[] = {
  136681. -1.5, -0.5, 0.5, 1.5,
  136682. };
  136683. static long _vq_quantmap__44u8_p6_1[] = {
  136684. 3, 1, 0, 2, 4,
  136685. };
  136686. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136687. _vq_quantthresh__44u8_p6_1,
  136688. _vq_quantmap__44u8_p6_1,
  136689. 5,
  136690. 5
  136691. };
  136692. static static_codebook _44u8_p6_1 = {
  136693. 2, 25,
  136694. _vq_lengthlist__44u8_p6_1,
  136695. 1, -533725184, 1611661312, 3, 0,
  136696. _vq_quantlist__44u8_p6_1,
  136697. NULL,
  136698. &_vq_auxt__44u8_p6_1,
  136699. NULL,
  136700. 0
  136701. };
  136702. static long _vq_quantlist__44u8_p7_0[] = {
  136703. 6,
  136704. 5,
  136705. 7,
  136706. 4,
  136707. 8,
  136708. 3,
  136709. 9,
  136710. 2,
  136711. 10,
  136712. 1,
  136713. 11,
  136714. 0,
  136715. 12,
  136716. };
  136717. static long _vq_lengthlist__44u8_p7_0[] = {
  136718. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136719. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136720. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136721. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136722. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136723. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136724. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136725. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136726. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136727. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136728. 13,13,14,14,14,15,15,15,16,
  136729. };
  136730. static float _vq_quantthresh__44u8_p7_0[] = {
  136731. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136732. 27.5, 38.5, 49.5, 60.5,
  136733. };
  136734. static long _vq_quantmap__44u8_p7_0[] = {
  136735. 11, 9, 7, 5, 3, 1, 0, 2,
  136736. 4, 6, 8, 10, 12,
  136737. };
  136738. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136739. _vq_quantthresh__44u8_p7_0,
  136740. _vq_quantmap__44u8_p7_0,
  136741. 13,
  136742. 13
  136743. };
  136744. static static_codebook _44u8_p7_0 = {
  136745. 2, 169,
  136746. _vq_lengthlist__44u8_p7_0,
  136747. 1, -523206656, 1618345984, 4, 0,
  136748. _vq_quantlist__44u8_p7_0,
  136749. NULL,
  136750. &_vq_auxt__44u8_p7_0,
  136751. NULL,
  136752. 0
  136753. };
  136754. static long _vq_quantlist__44u8_p7_1[] = {
  136755. 5,
  136756. 4,
  136757. 6,
  136758. 3,
  136759. 7,
  136760. 2,
  136761. 8,
  136762. 1,
  136763. 9,
  136764. 0,
  136765. 10,
  136766. };
  136767. static long _vq_lengthlist__44u8_p7_1[] = {
  136768. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136769. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136770. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136771. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136772. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136773. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136774. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136775. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136776. };
  136777. static float _vq_quantthresh__44u8_p7_1[] = {
  136778. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136779. 3.5, 4.5,
  136780. };
  136781. static long _vq_quantmap__44u8_p7_1[] = {
  136782. 9, 7, 5, 3, 1, 0, 2, 4,
  136783. 6, 8, 10,
  136784. };
  136785. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136786. _vq_quantthresh__44u8_p7_1,
  136787. _vq_quantmap__44u8_p7_1,
  136788. 11,
  136789. 11
  136790. };
  136791. static static_codebook _44u8_p7_1 = {
  136792. 2, 121,
  136793. _vq_lengthlist__44u8_p7_1,
  136794. 1, -531365888, 1611661312, 4, 0,
  136795. _vq_quantlist__44u8_p7_1,
  136796. NULL,
  136797. &_vq_auxt__44u8_p7_1,
  136798. NULL,
  136799. 0
  136800. };
  136801. static long _vq_quantlist__44u8_p8_0[] = {
  136802. 7,
  136803. 6,
  136804. 8,
  136805. 5,
  136806. 9,
  136807. 4,
  136808. 10,
  136809. 3,
  136810. 11,
  136811. 2,
  136812. 12,
  136813. 1,
  136814. 13,
  136815. 0,
  136816. 14,
  136817. };
  136818. static long _vq_lengthlist__44u8_p8_0[] = {
  136819. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136820. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136821. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136822. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136823. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136824. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136825. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136826. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136827. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136828. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136829. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136830. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136831. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136832. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136833. 17,
  136834. };
  136835. static float _vq_quantthresh__44u8_p8_0[] = {
  136836. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136837. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136838. };
  136839. static long _vq_quantmap__44u8_p8_0[] = {
  136840. 13, 11, 9, 7, 5, 3, 1, 0,
  136841. 2, 4, 6, 8, 10, 12, 14,
  136842. };
  136843. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136844. _vq_quantthresh__44u8_p8_0,
  136845. _vq_quantmap__44u8_p8_0,
  136846. 15,
  136847. 15
  136848. };
  136849. static static_codebook _44u8_p8_0 = {
  136850. 2, 225,
  136851. _vq_lengthlist__44u8_p8_0,
  136852. 1, -520986624, 1620377600, 4, 0,
  136853. _vq_quantlist__44u8_p8_0,
  136854. NULL,
  136855. &_vq_auxt__44u8_p8_0,
  136856. NULL,
  136857. 0
  136858. };
  136859. static long _vq_quantlist__44u8_p8_1[] = {
  136860. 10,
  136861. 9,
  136862. 11,
  136863. 8,
  136864. 12,
  136865. 7,
  136866. 13,
  136867. 6,
  136868. 14,
  136869. 5,
  136870. 15,
  136871. 4,
  136872. 16,
  136873. 3,
  136874. 17,
  136875. 2,
  136876. 18,
  136877. 1,
  136878. 19,
  136879. 0,
  136880. 20,
  136881. };
  136882. static long _vq_lengthlist__44u8_p8_1[] = {
  136883. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136884. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136885. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136886. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136887. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136888. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136889. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136890. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136891. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136892. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136893. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136894. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136895. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136896. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136897. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136898. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136899. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136900. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136901. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136902. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136903. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136904. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136905. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136906. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136907. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136908. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136909. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136910. 10,10,10,10,10,10,10,10,10,
  136911. };
  136912. static float _vq_quantthresh__44u8_p8_1[] = {
  136913. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136914. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136915. 6.5, 7.5, 8.5, 9.5,
  136916. };
  136917. static long _vq_quantmap__44u8_p8_1[] = {
  136918. 19, 17, 15, 13, 11, 9, 7, 5,
  136919. 3, 1, 0, 2, 4, 6, 8, 10,
  136920. 12, 14, 16, 18, 20,
  136921. };
  136922. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136923. _vq_quantthresh__44u8_p8_1,
  136924. _vq_quantmap__44u8_p8_1,
  136925. 21,
  136926. 21
  136927. };
  136928. static static_codebook _44u8_p8_1 = {
  136929. 2, 441,
  136930. _vq_lengthlist__44u8_p8_1,
  136931. 1, -529268736, 1611661312, 5, 0,
  136932. _vq_quantlist__44u8_p8_1,
  136933. NULL,
  136934. &_vq_auxt__44u8_p8_1,
  136935. NULL,
  136936. 0
  136937. };
  136938. static long _vq_quantlist__44u8_p9_0[] = {
  136939. 4,
  136940. 3,
  136941. 5,
  136942. 2,
  136943. 6,
  136944. 1,
  136945. 7,
  136946. 0,
  136947. 8,
  136948. };
  136949. static long _vq_lengthlist__44u8_p9_0[] = {
  136950. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  136951. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136952. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136953. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136954. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136955. 8,
  136956. };
  136957. static float _vq_quantthresh__44u8_p9_0[] = {
  136958. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  136959. };
  136960. static long _vq_quantmap__44u8_p9_0[] = {
  136961. 7, 5, 3, 1, 0, 2, 4, 6,
  136962. 8,
  136963. };
  136964. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  136965. _vq_quantthresh__44u8_p9_0,
  136966. _vq_quantmap__44u8_p9_0,
  136967. 9,
  136968. 9
  136969. };
  136970. static static_codebook _44u8_p9_0 = {
  136971. 2, 81,
  136972. _vq_lengthlist__44u8_p9_0,
  136973. 1, -511895552, 1631393792, 4, 0,
  136974. _vq_quantlist__44u8_p9_0,
  136975. NULL,
  136976. &_vq_auxt__44u8_p9_0,
  136977. NULL,
  136978. 0
  136979. };
  136980. static long _vq_quantlist__44u8_p9_1[] = {
  136981. 9,
  136982. 8,
  136983. 10,
  136984. 7,
  136985. 11,
  136986. 6,
  136987. 12,
  136988. 5,
  136989. 13,
  136990. 4,
  136991. 14,
  136992. 3,
  136993. 15,
  136994. 2,
  136995. 16,
  136996. 1,
  136997. 17,
  136998. 0,
  136999. 18,
  137000. };
  137001. static long _vq_lengthlist__44u8_p9_1[] = {
  137002. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137003. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137004. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137005. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137006. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137007. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137008. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137009. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137010. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137011. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137012. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137013. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137014. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137015. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137016. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137017. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137018. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137019. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137020. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137021. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137022. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137023. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137024. 16,15,16,16,16,16,16,16,16,
  137025. };
  137026. static float _vq_quantthresh__44u8_p9_1[] = {
  137027. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137028. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137029. 367.5, 416.5,
  137030. };
  137031. static long _vq_quantmap__44u8_p9_1[] = {
  137032. 17, 15, 13, 11, 9, 7, 5, 3,
  137033. 1, 0, 2, 4, 6, 8, 10, 12,
  137034. 14, 16, 18,
  137035. };
  137036. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137037. _vq_quantthresh__44u8_p9_1,
  137038. _vq_quantmap__44u8_p9_1,
  137039. 19,
  137040. 19
  137041. };
  137042. static static_codebook _44u8_p9_1 = {
  137043. 2, 361,
  137044. _vq_lengthlist__44u8_p9_1,
  137045. 1, -518287360, 1622704128, 5, 0,
  137046. _vq_quantlist__44u8_p9_1,
  137047. NULL,
  137048. &_vq_auxt__44u8_p9_1,
  137049. NULL,
  137050. 0
  137051. };
  137052. static long _vq_quantlist__44u8_p9_2[] = {
  137053. 24,
  137054. 23,
  137055. 25,
  137056. 22,
  137057. 26,
  137058. 21,
  137059. 27,
  137060. 20,
  137061. 28,
  137062. 19,
  137063. 29,
  137064. 18,
  137065. 30,
  137066. 17,
  137067. 31,
  137068. 16,
  137069. 32,
  137070. 15,
  137071. 33,
  137072. 14,
  137073. 34,
  137074. 13,
  137075. 35,
  137076. 12,
  137077. 36,
  137078. 11,
  137079. 37,
  137080. 10,
  137081. 38,
  137082. 9,
  137083. 39,
  137084. 8,
  137085. 40,
  137086. 7,
  137087. 41,
  137088. 6,
  137089. 42,
  137090. 5,
  137091. 43,
  137092. 4,
  137093. 44,
  137094. 3,
  137095. 45,
  137096. 2,
  137097. 46,
  137098. 1,
  137099. 47,
  137100. 0,
  137101. 48,
  137102. };
  137103. static long _vq_lengthlist__44u8_p9_2[] = {
  137104. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137105. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137106. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137107. 7,
  137108. };
  137109. static float _vq_quantthresh__44u8_p9_2[] = {
  137110. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137111. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137112. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137113. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137114. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137115. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137116. };
  137117. static long _vq_quantmap__44u8_p9_2[] = {
  137118. 47, 45, 43, 41, 39, 37, 35, 33,
  137119. 31, 29, 27, 25, 23, 21, 19, 17,
  137120. 15, 13, 11, 9, 7, 5, 3, 1,
  137121. 0, 2, 4, 6, 8, 10, 12, 14,
  137122. 16, 18, 20, 22, 24, 26, 28, 30,
  137123. 32, 34, 36, 38, 40, 42, 44, 46,
  137124. 48,
  137125. };
  137126. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137127. _vq_quantthresh__44u8_p9_2,
  137128. _vq_quantmap__44u8_p9_2,
  137129. 49,
  137130. 49
  137131. };
  137132. static static_codebook _44u8_p9_2 = {
  137133. 1, 49,
  137134. _vq_lengthlist__44u8_p9_2,
  137135. 1, -526909440, 1611661312, 6, 0,
  137136. _vq_quantlist__44u8_p9_2,
  137137. NULL,
  137138. &_vq_auxt__44u8_p9_2,
  137139. NULL,
  137140. 0
  137141. };
  137142. static long _huff_lengthlist__44u9__long[] = {
  137143. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137144. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137145. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137146. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137147. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137148. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137149. 10, 8, 8, 9,
  137150. };
  137151. static static_codebook _huff_book__44u9__long = {
  137152. 2, 100,
  137153. _huff_lengthlist__44u9__long,
  137154. 0, 0, 0, 0, 0,
  137155. NULL,
  137156. NULL,
  137157. NULL,
  137158. NULL,
  137159. 0
  137160. };
  137161. static long _huff_lengthlist__44u9__short[] = {
  137162. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137163. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137164. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137165. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137166. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137167. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137168. 9, 9,12,15,
  137169. };
  137170. static static_codebook _huff_book__44u9__short = {
  137171. 2, 100,
  137172. _huff_lengthlist__44u9__short,
  137173. 0, 0, 0, 0, 0,
  137174. NULL,
  137175. NULL,
  137176. NULL,
  137177. NULL,
  137178. 0
  137179. };
  137180. static long _vq_quantlist__44u9_p1_0[] = {
  137181. 1,
  137182. 0,
  137183. 2,
  137184. };
  137185. static long _vq_lengthlist__44u9_p1_0[] = {
  137186. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137187. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137188. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137189. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137190. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137191. 10,
  137192. };
  137193. static float _vq_quantthresh__44u9_p1_0[] = {
  137194. -0.5, 0.5,
  137195. };
  137196. static long _vq_quantmap__44u9_p1_0[] = {
  137197. 1, 0, 2,
  137198. };
  137199. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137200. _vq_quantthresh__44u9_p1_0,
  137201. _vq_quantmap__44u9_p1_0,
  137202. 3,
  137203. 3
  137204. };
  137205. static static_codebook _44u9_p1_0 = {
  137206. 4, 81,
  137207. _vq_lengthlist__44u9_p1_0,
  137208. 1, -535822336, 1611661312, 2, 0,
  137209. _vq_quantlist__44u9_p1_0,
  137210. NULL,
  137211. &_vq_auxt__44u9_p1_0,
  137212. NULL,
  137213. 0
  137214. };
  137215. static long _vq_quantlist__44u9_p2_0[] = {
  137216. 2,
  137217. 1,
  137218. 3,
  137219. 0,
  137220. 4,
  137221. };
  137222. static long _vq_lengthlist__44u9_p2_0[] = {
  137223. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137224. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137225. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137226. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137227. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137228. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137229. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137230. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137231. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137232. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137233. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137234. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137235. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137236. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137237. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137238. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137239. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137240. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137241. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137242. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137243. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137244. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137245. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137246. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137247. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137248. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137249. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137250. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137251. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137252. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137253. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137254. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137255. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137256. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137257. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137258. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137259. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137260. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137261. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137262. 14,
  137263. };
  137264. static float _vq_quantthresh__44u9_p2_0[] = {
  137265. -1.5, -0.5, 0.5, 1.5,
  137266. };
  137267. static long _vq_quantmap__44u9_p2_0[] = {
  137268. 3, 1, 0, 2, 4,
  137269. };
  137270. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137271. _vq_quantthresh__44u9_p2_0,
  137272. _vq_quantmap__44u9_p2_0,
  137273. 5,
  137274. 5
  137275. };
  137276. static static_codebook _44u9_p2_0 = {
  137277. 4, 625,
  137278. _vq_lengthlist__44u9_p2_0,
  137279. 1, -533725184, 1611661312, 3, 0,
  137280. _vq_quantlist__44u9_p2_0,
  137281. NULL,
  137282. &_vq_auxt__44u9_p2_0,
  137283. NULL,
  137284. 0
  137285. };
  137286. static long _vq_quantlist__44u9_p3_0[] = {
  137287. 4,
  137288. 3,
  137289. 5,
  137290. 2,
  137291. 6,
  137292. 1,
  137293. 7,
  137294. 0,
  137295. 8,
  137296. };
  137297. static long _vq_lengthlist__44u9_p3_0[] = {
  137298. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137299. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137300. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137301. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137302. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137303. 11,
  137304. };
  137305. static float _vq_quantthresh__44u9_p3_0[] = {
  137306. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137307. };
  137308. static long _vq_quantmap__44u9_p3_0[] = {
  137309. 7, 5, 3, 1, 0, 2, 4, 6,
  137310. 8,
  137311. };
  137312. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137313. _vq_quantthresh__44u9_p3_0,
  137314. _vq_quantmap__44u9_p3_0,
  137315. 9,
  137316. 9
  137317. };
  137318. static static_codebook _44u9_p3_0 = {
  137319. 2, 81,
  137320. _vq_lengthlist__44u9_p3_0,
  137321. 1, -531628032, 1611661312, 4, 0,
  137322. _vq_quantlist__44u9_p3_0,
  137323. NULL,
  137324. &_vq_auxt__44u9_p3_0,
  137325. NULL,
  137326. 0
  137327. };
  137328. static long _vq_quantlist__44u9_p4_0[] = {
  137329. 8,
  137330. 7,
  137331. 9,
  137332. 6,
  137333. 10,
  137334. 5,
  137335. 11,
  137336. 4,
  137337. 12,
  137338. 3,
  137339. 13,
  137340. 2,
  137341. 14,
  137342. 1,
  137343. 15,
  137344. 0,
  137345. 16,
  137346. };
  137347. static long _vq_lengthlist__44u9_p4_0[] = {
  137348. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137349. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137350. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137351. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137352. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137353. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137354. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137355. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137356. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137357. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137358. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137359. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137360. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137361. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137362. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137363. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137364. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137365. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137366. 14,
  137367. };
  137368. static float _vq_quantthresh__44u9_p4_0[] = {
  137369. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137370. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137371. };
  137372. static long _vq_quantmap__44u9_p4_0[] = {
  137373. 15, 13, 11, 9, 7, 5, 3, 1,
  137374. 0, 2, 4, 6, 8, 10, 12, 14,
  137375. 16,
  137376. };
  137377. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137378. _vq_quantthresh__44u9_p4_0,
  137379. _vq_quantmap__44u9_p4_0,
  137380. 17,
  137381. 17
  137382. };
  137383. static static_codebook _44u9_p4_0 = {
  137384. 2, 289,
  137385. _vq_lengthlist__44u9_p4_0,
  137386. 1, -529530880, 1611661312, 5, 0,
  137387. _vq_quantlist__44u9_p4_0,
  137388. NULL,
  137389. &_vq_auxt__44u9_p4_0,
  137390. NULL,
  137391. 0
  137392. };
  137393. static long _vq_quantlist__44u9_p5_0[] = {
  137394. 1,
  137395. 0,
  137396. 2,
  137397. };
  137398. static long _vq_lengthlist__44u9_p5_0[] = {
  137399. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137400. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137401. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137402. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137403. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137404. 10,
  137405. };
  137406. static float _vq_quantthresh__44u9_p5_0[] = {
  137407. -5.5, 5.5,
  137408. };
  137409. static long _vq_quantmap__44u9_p5_0[] = {
  137410. 1, 0, 2,
  137411. };
  137412. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137413. _vq_quantthresh__44u9_p5_0,
  137414. _vq_quantmap__44u9_p5_0,
  137415. 3,
  137416. 3
  137417. };
  137418. static static_codebook _44u9_p5_0 = {
  137419. 4, 81,
  137420. _vq_lengthlist__44u9_p5_0,
  137421. 1, -529137664, 1618345984, 2, 0,
  137422. _vq_quantlist__44u9_p5_0,
  137423. NULL,
  137424. &_vq_auxt__44u9_p5_0,
  137425. NULL,
  137426. 0
  137427. };
  137428. static long _vq_quantlist__44u9_p5_1[] = {
  137429. 5,
  137430. 4,
  137431. 6,
  137432. 3,
  137433. 7,
  137434. 2,
  137435. 8,
  137436. 1,
  137437. 9,
  137438. 0,
  137439. 10,
  137440. };
  137441. static long _vq_lengthlist__44u9_p5_1[] = {
  137442. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137443. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137444. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137445. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137446. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137447. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137448. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137449. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137450. };
  137451. static float _vq_quantthresh__44u9_p5_1[] = {
  137452. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137453. 3.5, 4.5,
  137454. };
  137455. static long _vq_quantmap__44u9_p5_1[] = {
  137456. 9, 7, 5, 3, 1, 0, 2, 4,
  137457. 6, 8, 10,
  137458. };
  137459. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137460. _vq_quantthresh__44u9_p5_1,
  137461. _vq_quantmap__44u9_p5_1,
  137462. 11,
  137463. 11
  137464. };
  137465. static static_codebook _44u9_p5_1 = {
  137466. 2, 121,
  137467. _vq_lengthlist__44u9_p5_1,
  137468. 1, -531365888, 1611661312, 4, 0,
  137469. _vq_quantlist__44u9_p5_1,
  137470. NULL,
  137471. &_vq_auxt__44u9_p5_1,
  137472. NULL,
  137473. 0
  137474. };
  137475. static long _vq_quantlist__44u9_p6_0[] = {
  137476. 6,
  137477. 5,
  137478. 7,
  137479. 4,
  137480. 8,
  137481. 3,
  137482. 9,
  137483. 2,
  137484. 10,
  137485. 1,
  137486. 11,
  137487. 0,
  137488. 12,
  137489. };
  137490. static long _vq_lengthlist__44u9_p6_0[] = {
  137491. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137492. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137493. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137494. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137495. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137496. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137497. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137498. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137499. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137500. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137501. 10,11,11,11,11,12,11,12,12,
  137502. };
  137503. static float _vq_quantthresh__44u9_p6_0[] = {
  137504. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137505. 12.5, 17.5, 22.5, 27.5,
  137506. };
  137507. static long _vq_quantmap__44u9_p6_0[] = {
  137508. 11, 9, 7, 5, 3, 1, 0, 2,
  137509. 4, 6, 8, 10, 12,
  137510. };
  137511. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137512. _vq_quantthresh__44u9_p6_0,
  137513. _vq_quantmap__44u9_p6_0,
  137514. 13,
  137515. 13
  137516. };
  137517. static static_codebook _44u9_p6_0 = {
  137518. 2, 169,
  137519. _vq_lengthlist__44u9_p6_0,
  137520. 1, -526516224, 1616117760, 4, 0,
  137521. _vq_quantlist__44u9_p6_0,
  137522. NULL,
  137523. &_vq_auxt__44u9_p6_0,
  137524. NULL,
  137525. 0
  137526. };
  137527. static long _vq_quantlist__44u9_p6_1[] = {
  137528. 2,
  137529. 1,
  137530. 3,
  137531. 0,
  137532. 4,
  137533. };
  137534. static long _vq_lengthlist__44u9_p6_1[] = {
  137535. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137536. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137537. };
  137538. static float _vq_quantthresh__44u9_p6_1[] = {
  137539. -1.5, -0.5, 0.5, 1.5,
  137540. };
  137541. static long _vq_quantmap__44u9_p6_1[] = {
  137542. 3, 1, 0, 2, 4,
  137543. };
  137544. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137545. _vq_quantthresh__44u9_p6_1,
  137546. _vq_quantmap__44u9_p6_1,
  137547. 5,
  137548. 5
  137549. };
  137550. static static_codebook _44u9_p6_1 = {
  137551. 2, 25,
  137552. _vq_lengthlist__44u9_p6_1,
  137553. 1, -533725184, 1611661312, 3, 0,
  137554. _vq_quantlist__44u9_p6_1,
  137555. NULL,
  137556. &_vq_auxt__44u9_p6_1,
  137557. NULL,
  137558. 0
  137559. };
  137560. static long _vq_quantlist__44u9_p7_0[] = {
  137561. 6,
  137562. 5,
  137563. 7,
  137564. 4,
  137565. 8,
  137566. 3,
  137567. 9,
  137568. 2,
  137569. 10,
  137570. 1,
  137571. 11,
  137572. 0,
  137573. 12,
  137574. };
  137575. static long _vq_lengthlist__44u9_p7_0[] = {
  137576. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137577. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137578. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137579. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137580. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137581. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137582. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137583. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137584. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137585. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137586. 12,13,13,14,14,14,15,15,15,
  137587. };
  137588. static float _vq_quantthresh__44u9_p7_0[] = {
  137589. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137590. 27.5, 38.5, 49.5, 60.5,
  137591. };
  137592. static long _vq_quantmap__44u9_p7_0[] = {
  137593. 11, 9, 7, 5, 3, 1, 0, 2,
  137594. 4, 6, 8, 10, 12,
  137595. };
  137596. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137597. _vq_quantthresh__44u9_p7_0,
  137598. _vq_quantmap__44u9_p7_0,
  137599. 13,
  137600. 13
  137601. };
  137602. static static_codebook _44u9_p7_0 = {
  137603. 2, 169,
  137604. _vq_lengthlist__44u9_p7_0,
  137605. 1, -523206656, 1618345984, 4, 0,
  137606. _vq_quantlist__44u9_p7_0,
  137607. NULL,
  137608. &_vq_auxt__44u9_p7_0,
  137609. NULL,
  137610. 0
  137611. };
  137612. static long _vq_quantlist__44u9_p7_1[] = {
  137613. 5,
  137614. 4,
  137615. 6,
  137616. 3,
  137617. 7,
  137618. 2,
  137619. 8,
  137620. 1,
  137621. 9,
  137622. 0,
  137623. 10,
  137624. };
  137625. static long _vq_lengthlist__44u9_p7_1[] = {
  137626. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137627. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137628. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137629. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137630. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137631. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137632. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137633. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137634. };
  137635. static float _vq_quantthresh__44u9_p7_1[] = {
  137636. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137637. 3.5, 4.5,
  137638. };
  137639. static long _vq_quantmap__44u9_p7_1[] = {
  137640. 9, 7, 5, 3, 1, 0, 2, 4,
  137641. 6, 8, 10,
  137642. };
  137643. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137644. _vq_quantthresh__44u9_p7_1,
  137645. _vq_quantmap__44u9_p7_1,
  137646. 11,
  137647. 11
  137648. };
  137649. static static_codebook _44u9_p7_1 = {
  137650. 2, 121,
  137651. _vq_lengthlist__44u9_p7_1,
  137652. 1, -531365888, 1611661312, 4, 0,
  137653. _vq_quantlist__44u9_p7_1,
  137654. NULL,
  137655. &_vq_auxt__44u9_p7_1,
  137656. NULL,
  137657. 0
  137658. };
  137659. static long _vq_quantlist__44u9_p8_0[] = {
  137660. 7,
  137661. 6,
  137662. 8,
  137663. 5,
  137664. 9,
  137665. 4,
  137666. 10,
  137667. 3,
  137668. 11,
  137669. 2,
  137670. 12,
  137671. 1,
  137672. 13,
  137673. 0,
  137674. 14,
  137675. };
  137676. static long _vq_lengthlist__44u9_p8_0[] = {
  137677. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137678. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137679. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137680. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137681. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137682. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137683. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137684. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137685. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137686. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137687. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137688. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137689. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137690. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137691. 15,
  137692. };
  137693. static float _vq_quantthresh__44u9_p8_0[] = {
  137694. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137695. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137696. };
  137697. static long _vq_quantmap__44u9_p8_0[] = {
  137698. 13, 11, 9, 7, 5, 3, 1, 0,
  137699. 2, 4, 6, 8, 10, 12, 14,
  137700. };
  137701. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137702. _vq_quantthresh__44u9_p8_0,
  137703. _vq_quantmap__44u9_p8_0,
  137704. 15,
  137705. 15
  137706. };
  137707. static static_codebook _44u9_p8_0 = {
  137708. 2, 225,
  137709. _vq_lengthlist__44u9_p8_0,
  137710. 1, -520986624, 1620377600, 4, 0,
  137711. _vq_quantlist__44u9_p8_0,
  137712. NULL,
  137713. &_vq_auxt__44u9_p8_0,
  137714. NULL,
  137715. 0
  137716. };
  137717. static long _vq_quantlist__44u9_p8_1[] = {
  137718. 10,
  137719. 9,
  137720. 11,
  137721. 8,
  137722. 12,
  137723. 7,
  137724. 13,
  137725. 6,
  137726. 14,
  137727. 5,
  137728. 15,
  137729. 4,
  137730. 16,
  137731. 3,
  137732. 17,
  137733. 2,
  137734. 18,
  137735. 1,
  137736. 19,
  137737. 0,
  137738. 20,
  137739. };
  137740. static long _vq_lengthlist__44u9_p8_1[] = {
  137741. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137742. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137743. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137744. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137745. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137746. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137747. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137748. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137749. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137750. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137751. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137752. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137753. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137754. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137755. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137756. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137757. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137758. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137759. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137760. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137761. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137762. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137763. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137764. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137765. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137766. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137767. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137768. 10,10,10,10,10,10,10,10,10,
  137769. };
  137770. static float _vq_quantthresh__44u9_p8_1[] = {
  137771. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137772. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137773. 6.5, 7.5, 8.5, 9.5,
  137774. };
  137775. static long _vq_quantmap__44u9_p8_1[] = {
  137776. 19, 17, 15, 13, 11, 9, 7, 5,
  137777. 3, 1, 0, 2, 4, 6, 8, 10,
  137778. 12, 14, 16, 18, 20,
  137779. };
  137780. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137781. _vq_quantthresh__44u9_p8_1,
  137782. _vq_quantmap__44u9_p8_1,
  137783. 21,
  137784. 21
  137785. };
  137786. static static_codebook _44u9_p8_1 = {
  137787. 2, 441,
  137788. _vq_lengthlist__44u9_p8_1,
  137789. 1, -529268736, 1611661312, 5, 0,
  137790. _vq_quantlist__44u9_p8_1,
  137791. NULL,
  137792. &_vq_auxt__44u9_p8_1,
  137793. NULL,
  137794. 0
  137795. };
  137796. static long _vq_quantlist__44u9_p9_0[] = {
  137797. 7,
  137798. 6,
  137799. 8,
  137800. 5,
  137801. 9,
  137802. 4,
  137803. 10,
  137804. 3,
  137805. 11,
  137806. 2,
  137807. 12,
  137808. 1,
  137809. 13,
  137810. 0,
  137811. 14,
  137812. };
  137813. static long _vq_lengthlist__44u9_p9_0[] = {
  137814. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137815. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137816. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137817. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137818. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137819. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137820. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137821. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137822. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137823. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137824. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137825. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137826. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137827. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137828. 10,
  137829. };
  137830. static float _vq_quantthresh__44u9_p9_0[] = {
  137831. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137832. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137833. };
  137834. static long _vq_quantmap__44u9_p9_0[] = {
  137835. 13, 11, 9, 7, 5, 3, 1, 0,
  137836. 2, 4, 6, 8, 10, 12, 14,
  137837. };
  137838. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137839. _vq_quantthresh__44u9_p9_0,
  137840. _vq_quantmap__44u9_p9_0,
  137841. 15,
  137842. 15
  137843. };
  137844. static static_codebook _44u9_p9_0 = {
  137845. 2, 225,
  137846. _vq_lengthlist__44u9_p9_0,
  137847. 1, -510036736, 1631393792, 4, 0,
  137848. _vq_quantlist__44u9_p9_0,
  137849. NULL,
  137850. &_vq_auxt__44u9_p9_0,
  137851. NULL,
  137852. 0
  137853. };
  137854. static long _vq_quantlist__44u9_p9_1[] = {
  137855. 9,
  137856. 8,
  137857. 10,
  137858. 7,
  137859. 11,
  137860. 6,
  137861. 12,
  137862. 5,
  137863. 13,
  137864. 4,
  137865. 14,
  137866. 3,
  137867. 15,
  137868. 2,
  137869. 16,
  137870. 1,
  137871. 17,
  137872. 0,
  137873. 18,
  137874. };
  137875. static long _vq_lengthlist__44u9_p9_1[] = {
  137876. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137877. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137878. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137879. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137880. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137881. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137882. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137883. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137884. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137885. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137886. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137887. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137888. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137889. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137890. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137891. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137892. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137893. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137894. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137895. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137896. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137897. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137898. 17,17,15,17,15,17,16,16,17,
  137899. };
  137900. static float _vq_quantthresh__44u9_p9_1[] = {
  137901. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137902. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137903. 367.5, 416.5,
  137904. };
  137905. static long _vq_quantmap__44u9_p9_1[] = {
  137906. 17, 15, 13, 11, 9, 7, 5, 3,
  137907. 1, 0, 2, 4, 6, 8, 10, 12,
  137908. 14, 16, 18,
  137909. };
  137910. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137911. _vq_quantthresh__44u9_p9_1,
  137912. _vq_quantmap__44u9_p9_1,
  137913. 19,
  137914. 19
  137915. };
  137916. static static_codebook _44u9_p9_1 = {
  137917. 2, 361,
  137918. _vq_lengthlist__44u9_p9_1,
  137919. 1, -518287360, 1622704128, 5, 0,
  137920. _vq_quantlist__44u9_p9_1,
  137921. NULL,
  137922. &_vq_auxt__44u9_p9_1,
  137923. NULL,
  137924. 0
  137925. };
  137926. static long _vq_quantlist__44u9_p9_2[] = {
  137927. 24,
  137928. 23,
  137929. 25,
  137930. 22,
  137931. 26,
  137932. 21,
  137933. 27,
  137934. 20,
  137935. 28,
  137936. 19,
  137937. 29,
  137938. 18,
  137939. 30,
  137940. 17,
  137941. 31,
  137942. 16,
  137943. 32,
  137944. 15,
  137945. 33,
  137946. 14,
  137947. 34,
  137948. 13,
  137949. 35,
  137950. 12,
  137951. 36,
  137952. 11,
  137953. 37,
  137954. 10,
  137955. 38,
  137956. 9,
  137957. 39,
  137958. 8,
  137959. 40,
  137960. 7,
  137961. 41,
  137962. 6,
  137963. 42,
  137964. 5,
  137965. 43,
  137966. 4,
  137967. 44,
  137968. 3,
  137969. 45,
  137970. 2,
  137971. 46,
  137972. 1,
  137973. 47,
  137974. 0,
  137975. 48,
  137976. };
  137977. static long _vq_lengthlist__44u9_p9_2[] = {
  137978. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  137979. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137980. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137981. 7,
  137982. };
  137983. static float _vq_quantthresh__44u9_p9_2[] = {
  137984. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137985. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137986. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137987. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137988. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137989. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137990. };
  137991. static long _vq_quantmap__44u9_p9_2[] = {
  137992. 47, 45, 43, 41, 39, 37, 35, 33,
  137993. 31, 29, 27, 25, 23, 21, 19, 17,
  137994. 15, 13, 11, 9, 7, 5, 3, 1,
  137995. 0, 2, 4, 6, 8, 10, 12, 14,
  137996. 16, 18, 20, 22, 24, 26, 28, 30,
  137997. 32, 34, 36, 38, 40, 42, 44, 46,
  137998. 48,
  137999. };
  138000. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138001. _vq_quantthresh__44u9_p9_2,
  138002. _vq_quantmap__44u9_p9_2,
  138003. 49,
  138004. 49
  138005. };
  138006. static static_codebook _44u9_p9_2 = {
  138007. 1, 49,
  138008. _vq_lengthlist__44u9_p9_2,
  138009. 1, -526909440, 1611661312, 6, 0,
  138010. _vq_quantlist__44u9_p9_2,
  138011. NULL,
  138012. &_vq_auxt__44u9_p9_2,
  138013. NULL,
  138014. 0
  138015. };
  138016. static long _huff_lengthlist__44un1__long[] = {
  138017. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138018. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138019. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138020. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138021. };
  138022. static static_codebook _huff_book__44un1__long = {
  138023. 2, 64,
  138024. _huff_lengthlist__44un1__long,
  138025. 0, 0, 0, 0, 0,
  138026. NULL,
  138027. NULL,
  138028. NULL,
  138029. NULL,
  138030. 0
  138031. };
  138032. static long _vq_quantlist__44un1__p1_0[] = {
  138033. 1,
  138034. 0,
  138035. 2,
  138036. };
  138037. static long _vq_lengthlist__44un1__p1_0[] = {
  138038. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138039. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138040. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138041. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138042. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138043. 12,
  138044. };
  138045. static float _vq_quantthresh__44un1__p1_0[] = {
  138046. -0.5, 0.5,
  138047. };
  138048. static long _vq_quantmap__44un1__p1_0[] = {
  138049. 1, 0, 2,
  138050. };
  138051. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138052. _vq_quantthresh__44un1__p1_0,
  138053. _vq_quantmap__44un1__p1_0,
  138054. 3,
  138055. 3
  138056. };
  138057. static static_codebook _44un1__p1_0 = {
  138058. 4, 81,
  138059. _vq_lengthlist__44un1__p1_0,
  138060. 1, -535822336, 1611661312, 2, 0,
  138061. _vq_quantlist__44un1__p1_0,
  138062. NULL,
  138063. &_vq_auxt__44un1__p1_0,
  138064. NULL,
  138065. 0
  138066. };
  138067. static long _vq_quantlist__44un1__p2_0[] = {
  138068. 1,
  138069. 0,
  138070. 2,
  138071. };
  138072. static long _vq_lengthlist__44un1__p2_0[] = {
  138073. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138074. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138075. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138076. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138077. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138078. 8,
  138079. };
  138080. static float _vq_quantthresh__44un1__p2_0[] = {
  138081. -0.5, 0.5,
  138082. };
  138083. static long _vq_quantmap__44un1__p2_0[] = {
  138084. 1, 0, 2,
  138085. };
  138086. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138087. _vq_quantthresh__44un1__p2_0,
  138088. _vq_quantmap__44un1__p2_0,
  138089. 3,
  138090. 3
  138091. };
  138092. static static_codebook _44un1__p2_0 = {
  138093. 4, 81,
  138094. _vq_lengthlist__44un1__p2_0,
  138095. 1, -535822336, 1611661312, 2, 0,
  138096. _vq_quantlist__44un1__p2_0,
  138097. NULL,
  138098. &_vq_auxt__44un1__p2_0,
  138099. NULL,
  138100. 0
  138101. };
  138102. static long _vq_quantlist__44un1__p3_0[] = {
  138103. 2,
  138104. 1,
  138105. 3,
  138106. 0,
  138107. 4,
  138108. };
  138109. static long _vq_lengthlist__44un1__p3_0[] = {
  138110. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138111. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138112. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138113. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138114. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138115. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138116. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138117. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138118. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138119. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138120. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138121. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138122. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138123. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138124. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138125. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138126. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138127. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138128. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138129. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138130. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138131. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138132. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138133. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138134. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138135. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138136. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138137. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138138. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138139. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138140. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138141. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138142. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138143. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138144. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138145. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138146. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138147. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138148. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138149. 17,
  138150. };
  138151. static float _vq_quantthresh__44un1__p3_0[] = {
  138152. -1.5, -0.5, 0.5, 1.5,
  138153. };
  138154. static long _vq_quantmap__44un1__p3_0[] = {
  138155. 3, 1, 0, 2, 4,
  138156. };
  138157. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138158. _vq_quantthresh__44un1__p3_0,
  138159. _vq_quantmap__44un1__p3_0,
  138160. 5,
  138161. 5
  138162. };
  138163. static static_codebook _44un1__p3_0 = {
  138164. 4, 625,
  138165. _vq_lengthlist__44un1__p3_0,
  138166. 1, -533725184, 1611661312, 3, 0,
  138167. _vq_quantlist__44un1__p3_0,
  138168. NULL,
  138169. &_vq_auxt__44un1__p3_0,
  138170. NULL,
  138171. 0
  138172. };
  138173. static long _vq_quantlist__44un1__p4_0[] = {
  138174. 2,
  138175. 1,
  138176. 3,
  138177. 0,
  138178. 4,
  138179. };
  138180. static long _vq_lengthlist__44un1__p4_0[] = {
  138181. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138182. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138183. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138184. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138185. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138186. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138187. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138188. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138189. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138190. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138191. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138192. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138193. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138194. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138195. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138196. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138197. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138198. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138199. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138200. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138201. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138202. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138203. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138204. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138205. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138206. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138207. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138208. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138209. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138210. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138211. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138212. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138213. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138214. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138215. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138216. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138217. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138218. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138219. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138220. 12,
  138221. };
  138222. static float _vq_quantthresh__44un1__p4_0[] = {
  138223. -1.5, -0.5, 0.5, 1.5,
  138224. };
  138225. static long _vq_quantmap__44un1__p4_0[] = {
  138226. 3, 1, 0, 2, 4,
  138227. };
  138228. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138229. _vq_quantthresh__44un1__p4_0,
  138230. _vq_quantmap__44un1__p4_0,
  138231. 5,
  138232. 5
  138233. };
  138234. static static_codebook _44un1__p4_0 = {
  138235. 4, 625,
  138236. _vq_lengthlist__44un1__p4_0,
  138237. 1, -533725184, 1611661312, 3, 0,
  138238. _vq_quantlist__44un1__p4_0,
  138239. NULL,
  138240. &_vq_auxt__44un1__p4_0,
  138241. NULL,
  138242. 0
  138243. };
  138244. static long _vq_quantlist__44un1__p5_0[] = {
  138245. 4,
  138246. 3,
  138247. 5,
  138248. 2,
  138249. 6,
  138250. 1,
  138251. 7,
  138252. 0,
  138253. 8,
  138254. };
  138255. static long _vq_lengthlist__44un1__p5_0[] = {
  138256. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138257. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138258. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138259. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138260. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138261. 12,
  138262. };
  138263. static float _vq_quantthresh__44un1__p5_0[] = {
  138264. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138265. };
  138266. static long _vq_quantmap__44un1__p5_0[] = {
  138267. 7, 5, 3, 1, 0, 2, 4, 6,
  138268. 8,
  138269. };
  138270. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138271. _vq_quantthresh__44un1__p5_0,
  138272. _vq_quantmap__44un1__p5_0,
  138273. 9,
  138274. 9
  138275. };
  138276. static static_codebook _44un1__p5_0 = {
  138277. 2, 81,
  138278. _vq_lengthlist__44un1__p5_0,
  138279. 1, -531628032, 1611661312, 4, 0,
  138280. _vq_quantlist__44un1__p5_0,
  138281. NULL,
  138282. &_vq_auxt__44un1__p5_0,
  138283. NULL,
  138284. 0
  138285. };
  138286. static long _vq_quantlist__44un1__p6_0[] = {
  138287. 6,
  138288. 5,
  138289. 7,
  138290. 4,
  138291. 8,
  138292. 3,
  138293. 9,
  138294. 2,
  138295. 10,
  138296. 1,
  138297. 11,
  138298. 0,
  138299. 12,
  138300. };
  138301. static long _vq_lengthlist__44un1__p6_0[] = {
  138302. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138303. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138304. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138305. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138306. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138307. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138308. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138309. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138310. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138311. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138312. 16, 0,15,18,18, 0,16, 0, 0,
  138313. };
  138314. static float _vq_quantthresh__44un1__p6_0[] = {
  138315. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138316. 12.5, 17.5, 22.5, 27.5,
  138317. };
  138318. static long _vq_quantmap__44un1__p6_0[] = {
  138319. 11, 9, 7, 5, 3, 1, 0, 2,
  138320. 4, 6, 8, 10, 12,
  138321. };
  138322. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138323. _vq_quantthresh__44un1__p6_0,
  138324. _vq_quantmap__44un1__p6_0,
  138325. 13,
  138326. 13
  138327. };
  138328. static static_codebook _44un1__p6_0 = {
  138329. 2, 169,
  138330. _vq_lengthlist__44un1__p6_0,
  138331. 1, -526516224, 1616117760, 4, 0,
  138332. _vq_quantlist__44un1__p6_0,
  138333. NULL,
  138334. &_vq_auxt__44un1__p6_0,
  138335. NULL,
  138336. 0
  138337. };
  138338. static long _vq_quantlist__44un1__p6_1[] = {
  138339. 2,
  138340. 1,
  138341. 3,
  138342. 0,
  138343. 4,
  138344. };
  138345. static long _vq_lengthlist__44un1__p6_1[] = {
  138346. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138347. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138348. };
  138349. static float _vq_quantthresh__44un1__p6_1[] = {
  138350. -1.5, -0.5, 0.5, 1.5,
  138351. };
  138352. static long _vq_quantmap__44un1__p6_1[] = {
  138353. 3, 1, 0, 2, 4,
  138354. };
  138355. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138356. _vq_quantthresh__44un1__p6_1,
  138357. _vq_quantmap__44un1__p6_1,
  138358. 5,
  138359. 5
  138360. };
  138361. static static_codebook _44un1__p6_1 = {
  138362. 2, 25,
  138363. _vq_lengthlist__44un1__p6_1,
  138364. 1, -533725184, 1611661312, 3, 0,
  138365. _vq_quantlist__44un1__p6_1,
  138366. NULL,
  138367. &_vq_auxt__44un1__p6_1,
  138368. NULL,
  138369. 0
  138370. };
  138371. static long _vq_quantlist__44un1__p7_0[] = {
  138372. 2,
  138373. 1,
  138374. 3,
  138375. 0,
  138376. 4,
  138377. };
  138378. static long _vq_lengthlist__44un1__p7_0[] = {
  138379. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138380. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138381. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138382. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138383. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138384. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138385. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138386. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138387. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138388. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138389. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138390. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138391. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138392. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138393. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138394. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138395. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138396. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138397. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138398. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138399. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138400. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138401. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138402. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138403. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138404. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138405. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138406. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138407. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138408. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138409. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138410. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138411. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138412. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138413. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138414. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138415. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138416. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138417. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138418. 10,
  138419. };
  138420. static float _vq_quantthresh__44un1__p7_0[] = {
  138421. -253.5, -84.5, 84.5, 253.5,
  138422. };
  138423. static long _vq_quantmap__44un1__p7_0[] = {
  138424. 3, 1, 0, 2, 4,
  138425. };
  138426. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138427. _vq_quantthresh__44un1__p7_0,
  138428. _vq_quantmap__44un1__p7_0,
  138429. 5,
  138430. 5
  138431. };
  138432. static static_codebook _44un1__p7_0 = {
  138433. 4, 625,
  138434. _vq_lengthlist__44un1__p7_0,
  138435. 1, -518709248, 1626677248, 3, 0,
  138436. _vq_quantlist__44un1__p7_0,
  138437. NULL,
  138438. &_vq_auxt__44un1__p7_0,
  138439. NULL,
  138440. 0
  138441. };
  138442. static long _vq_quantlist__44un1__p7_1[] = {
  138443. 6,
  138444. 5,
  138445. 7,
  138446. 4,
  138447. 8,
  138448. 3,
  138449. 9,
  138450. 2,
  138451. 10,
  138452. 1,
  138453. 11,
  138454. 0,
  138455. 12,
  138456. };
  138457. static long _vq_lengthlist__44un1__p7_1[] = {
  138458. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138459. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138460. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138461. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138462. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138463. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138464. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138465. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138466. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138467. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138468. 12,13,13,12,13,13,14,14,14,
  138469. };
  138470. static float _vq_quantthresh__44un1__p7_1[] = {
  138471. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138472. 32.5, 45.5, 58.5, 71.5,
  138473. };
  138474. static long _vq_quantmap__44un1__p7_1[] = {
  138475. 11, 9, 7, 5, 3, 1, 0, 2,
  138476. 4, 6, 8, 10, 12,
  138477. };
  138478. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138479. _vq_quantthresh__44un1__p7_1,
  138480. _vq_quantmap__44un1__p7_1,
  138481. 13,
  138482. 13
  138483. };
  138484. static static_codebook _44un1__p7_1 = {
  138485. 2, 169,
  138486. _vq_lengthlist__44un1__p7_1,
  138487. 1, -523010048, 1618608128, 4, 0,
  138488. _vq_quantlist__44un1__p7_1,
  138489. NULL,
  138490. &_vq_auxt__44un1__p7_1,
  138491. NULL,
  138492. 0
  138493. };
  138494. static long _vq_quantlist__44un1__p7_2[] = {
  138495. 6,
  138496. 5,
  138497. 7,
  138498. 4,
  138499. 8,
  138500. 3,
  138501. 9,
  138502. 2,
  138503. 10,
  138504. 1,
  138505. 11,
  138506. 0,
  138507. 12,
  138508. };
  138509. static long _vq_lengthlist__44un1__p7_2[] = {
  138510. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138511. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138512. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138513. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138514. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138515. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138516. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138517. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138518. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138519. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138520. 9, 9, 9,10,10,10,10,10,10,
  138521. };
  138522. static float _vq_quantthresh__44un1__p7_2[] = {
  138523. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138524. 2.5, 3.5, 4.5, 5.5,
  138525. };
  138526. static long _vq_quantmap__44un1__p7_2[] = {
  138527. 11, 9, 7, 5, 3, 1, 0, 2,
  138528. 4, 6, 8, 10, 12,
  138529. };
  138530. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138531. _vq_quantthresh__44un1__p7_2,
  138532. _vq_quantmap__44un1__p7_2,
  138533. 13,
  138534. 13
  138535. };
  138536. static static_codebook _44un1__p7_2 = {
  138537. 2, 169,
  138538. _vq_lengthlist__44un1__p7_2,
  138539. 1, -531103744, 1611661312, 4, 0,
  138540. _vq_quantlist__44un1__p7_2,
  138541. NULL,
  138542. &_vq_auxt__44un1__p7_2,
  138543. NULL,
  138544. 0
  138545. };
  138546. static long _huff_lengthlist__44un1__short[] = {
  138547. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138548. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138549. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138550. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138551. };
  138552. static static_codebook _huff_book__44un1__short = {
  138553. 2, 64,
  138554. _huff_lengthlist__44un1__short,
  138555. 0, 0, 0, 0, 0,
  138556. NULL,
  138557. NULL,
  138558. NULL,
  138559. NULL,
  138560. 0
  138561. };
  138562. /*** End of inlined file: res_books_uncoupled.h ***/
  138563. static vorbis_info_residue0 _residue_44_low_un={
  138564. 0,-1, -1, 8,-1,
  138565. {0},
  138566. {-1},
  138567. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138568. { -1, 25, -1, 45, -1, -1, -1}
  138569. };
  138570. static vorbis_info_residue0 _residue_44_mid_un={
  138571. 0,-1, -1, 10,-1,
  138572. {0},
  138573. {-1},
  138574. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138575. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138576. };
  138577. static vorbis_info_residue0 _residue_44_hi_un={
  138578. 0,-1, -1, 10,-1,
  138579. {0},
  138580. {-1},
  138581. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138582. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138583. };
  138584. static vorbis_info_mapping0 _map_nominal_u[2]={
  138585. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138586. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138587. };
  138588. static static_bookblock _resbook_44u_n1={
  138589. {
  138590. {0},
  138591. {0,0,&_44un1__p1_0},
  138592. {0,0,&_44un1__p2_0},
  138593. {0,0,&_44un1__p3_0},
  138594. {0,0,&_44un1__p4_0},
  138595. {0,0,&_44un1__p5_0},
  138596. {&_44un1__p6_0,&_44un1__p6_1},
  138597. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138598. }
  138599. };
  138600. static static_bookblock _resbook_44u_0={
  138601. {
  138602. {0},
  138603. {0,0,&_44u0__p1_0},
  138604. {0,0,&_44u0__p2_0},
  138605. {0,0,&_44u0__p3_0},
  138606. {0,0,&_44u0__p4_0},
  138607. {0,0,&_44u0__p5_0},
  138608. {&_44u0__p6_0,&_44u0__p6_1},
  138609. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138610. }
  138611. };
  138612. static static_bookblock _resbook_44u_1={
  138613. {
  138614. {0},
  138615. {0,0,&_44u1__p1_0},
  138616. {0,0,&_44u1__p2_0},
  138617. {0,0,&_44u1__p3_0},
  138618. {0,0,&_44u1__p4_0},
  138619. {0,0,&_44u1__p5_0},
  138620. {&_44u1__p6_0,&_44u1__p6_1},
  138621. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138622. }
  138623. };
  138624. static static_bookblock _resbook_44u_2={
  138625. {
  138626. {0},
  138627. {0,0,&_44u2__p1_0},
  138628. {0,0,&_44u2__p2_0},
  138629. {0,0,&_44u2__p3_0},
  138630. {0,0,&_44u2__p4_0},
  138631. {0,0,&_44u2__p5_0},
  138632. {&_44u2__p6_0,&_44u2__p6_1},
  138633. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138634. }
  138635. };
  138636. static static_bookblock _resbook_44u_3={
  138637. {
  138638. {0},
  138639. {0,0,&_44u3__p1_0},
  138640. {0,0,&_44u3__p2_0},
  138641. {0,0,&_44u3__p3_0},
  138642. {0,0,&_44u3__p4_0},
  138643. {0,0,&_44u3__p5_0},
  138644. {&_44u3__p6_0,&_44u3__p6_1},
  138645. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138646. }
  138647. };
  138648. static static_bookblock _resbook_44u_4={
  138649. {
  138650. {0},
  138651. {0,0,&_44u4__p1_0},
  138652. {0,0,&_44u4__p2_0},
  138653. {0,0,&_44u4__p3_0},
  138654. {0,0,&_44u4__p4_0},
  138655. {0,0,&_44u4__p5_0},
  138656. {&_44u4__p6_0,&_44u4__p6_1},
  138657. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138658. }
  138659. };
  138660. static static_bookblock _resbook_44u_5={
  138661. {
  138662. {0},
  138663. {0,0,&_44u5__p1_0},
  138664. {0,0,&_44u5__p2_0},
  138665. {0,0,&_44u5__p3_0},
  138666. {0,0,&_44u5__p4_0},
  138667. {0,0,&_44u5__p5_0},
  138668. {0,0,&_44u5__p6_0},
  138669. {&_44u5__p7_0,&_44u5__p7_1},
  138670. {&_44u5__p8_0,&_44u5__p8_1},
  138671. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138672. }
  138673. };
  138674. static static_bookblock _resbook_44u_6={
  138675. {
  138676. {0},
  138677. {0,0,&_44u6__p1_0},
  138678. {0,0,&_44u6__p2_0},
  138679. {0,0,&_44u6__p3_0},
  138680. {0,0,&_44u6__p4_0},
  138681. {0,0,&_44u6__p5_0},
  138682. {0,0,&_44u6__p6_0},
  138683. {&_44u6__p7_0,&_44u6__p7_1},
  138684. {&_44u6__p8_0,&_44u6__p8_1},
  138685. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138686. }
  138687. };
  138688. static static_bookblock _resbook_44u_7={
  138689. {
  138690. {0},
  138691. {0,0,&_44u7__p1_0},
  138692. {0,0,&_44u7__p2_0},
  138693. {0,0,&_44u7__p3_0},
  138694. {0,0,&_44u7__p4_0},
  138695. {0,0,&_44u7__p5_0},
  138696. {0,0,&_44u7__p6_0},
  138697. {&_44u7__p7_0,&_44u7__p7_1},
  138698. {&_44u7__p8_0,&_44u7__p8_1},
  138699. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138700. }
  138701. };
  138702. static static_bookblock _resbook_44u_8={
  138703. {
  138704. {0},
  138705. {0,0,&_44u8_p1_0},
  138706. {0,0,&_44u8_p2_0},
  138707. {0,0,&_44u8_p3_0},
  138708. {0,0,&_44u8_p4_0},
  138709. {&_44u8_p5_0,&_44u8_p5_1},
  138710. {&_44u8_p6_0,&_44u8_p6_1},
  138711. {&_44u8_p7_0,&_44u8_p7_1},
  138712. {&_44u8_p8_0,&_44u8_p8_1},
  138713. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138714. }
  138715. };
  138716. static static_bookblock _resbook_44u_9={
  138717. {
  138718. {0},
  138719. {0,0,&_44u9_p1_0},
  138720. {0,0,&_44u9_p2_0},
  138721. {0,0,&_44u9_p3_0},
  138722. {0,0,&_44u9_p4_0},
  138723. {&_44u9_p5_0,&_44u9_p5_1},
  138724. {&_44u9_p6_0,&_44u9_p6_1},
  138725. {&_44u9_p7_0,&_44u9_p7_1},
  138726. {&_44u9_p8_0,&_44u9_p8_1},
  138727. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138728. }
  138729. };
  138730. static vorbis_residue_template _res_44u_n1[]={
  138731. {1,0, &_residue_44_low_un,
  138732. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138733. &_resbook_44u_n1,&_resbook_44u_n1},
  138734. {1,0, &_residue_44_low_un,
  138735. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138736. &_resbook_44u_n1,&_resbook_44u_n1}
  138737. };
  138738. static vorbis_residue_template _res_44u_0[]={
  138739. {1,0, &_residue_44_low_un,
  138740. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138741. &_resbook_44u_0,&_resbook_44u_0},
  138742. {1,0, &_residue_44_low_un,
  138743. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138744. &_resbook_44u_0,&_resbook_44u_0}
  138745. };
  138746. static vorbis_residue_template _res_44u_1[]={
  138747. {1,0, &_residue_44_low_un,
  138748. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138749. &_resbook_44u_1,&_resbook_44u_1},
  138750. {1,0, &_residue_44_low_un,
  138751. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138752. &_resbook_44u_1,&_resbook_44u_1}
  138753. };
  138754. static vorbis_residue_template _res_44u_2[]={
  138755. {1,0, &_residue_44_low_un,
  138756. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138757. &_resbook_44u_2,&_resbook_44u_2},
  138758. {1,0, &_residue_44_low_un,
  138759. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138760. &_resbook_44u_2,&_resbook_44u_2}
  138761. };
  138762. static vorbis_residue_template _res_44u_3[]={
  138763. {1,0, &_residue_44_low_un,
  138764. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138765. &_resbook_44u_3,&_resbook_44u_3},
  138766. {1,0, &_residue_44_low_un,
  138767. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138768. &_resbook_44u_3,&_resbook_44u_3}
  138769. };
  138770. static vorbis_residue_template _res_44u_4[]={
  138771. {1,0, &_residue_44_low_un,
  138772. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138773. &_resbook_44u_4,&_resbook_44u_4},
  138774. {1,0, &_residue_44_low_un,
  138775. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138776. &_resbook_44u_4,&_resbook_44u_4}
  138777. };
  138778. static vorbis_residue_template _res_44u_5[]={
  138779. {1,0, &_residue_44_mid_un,
  138780. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138781. &_resbook_44u_5,&_resbook_44u_5},
  138782. {1,0, &_residue_44_mid_un,
  138783. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138784. &_resbook_44u_5,&_resbook_44u_5}
  138785. };
  138786. static vorbis_residue_template _res_44u_6[]={
  138787. {1,0, &_residue_44_mid_un,
  138788. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138789. &_resbook_44u_6,&_resbook_44u_6},
  138790. {1,0, &_residue_44_mid_un,
  138791. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138792. &_resbook_44u_6,&_resbook_44u_6}
  138793. };
  138794. static vorbis_residue_template _res_44u_7[]={
  138795. {1,0, &_residue_44_mid_un,
  138796. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138797. &_resbook_44u_7,&_resbook_44u_7},
  138798. {1,0, &_residue_44_mid_un,
  138799. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138800. &_resbook_44u_7,&_resbook_44u_7}
  138801. };
  138802. static vorbis_residue_template _res_44u_8[]={
  138803. {1,0, &_residue_44_hi_un,
  138804. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138805. &_resbook_44u_8,&_resbook_44u_8},
  138806. {1,0, &_residue_44_hi_un,
  138807. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138808. &_resbook_44u_8,&_resbook_44u_8}
  138809. };
  138810. static vorbis_residue_template _res_44u_9[]={
  138811. {1,0, &_residue_44_hi_un,
  138812. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138813. &_resbook_44u_9,&_resbook_44u_9},
  138814. {1,0, &_residue_44_hi_un,
  138815. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138816. &_resbook_44u_9,&_resbook_44u_9}
  138817. };
  138818. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138819. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138820. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138821. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138822. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138823. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138824. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138825. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138826. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138827. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138828. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138829. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138830. };
  138831. /*** End of inlined file: residue_44u.h ***/
  138832. static double rate_mapping_44_un[12]={
  138833. 32000.,48000.,60000.,70000.,80000.,86000.,
  138834. 96000.,110000.,120000.,140000.,160000.,240001.
  138835. };
  138836. ve_setup_data_template ve_setup_44_uncoupled={
  138837. 11,
  138838. rate_mapping_44_un,
  138839. quality_mapping_44,
  138840. -1,
  138841. 40000,
  138842. 50000,
  138843. blocksize_short_44,
  138844. blocksize_long_44,
  138845. _psy_tone_masteratt_44,
  138846. _psy_tone_0dB,
  138847. _psy_tone_suppress,
  138848. _vp_tonemask_adj_otherblock,
  138849. _vp_tonemask_adj_longblock,
  138850. _vp_tonemask_adj_otherblock,
  138851. _psy_noiseguards_44,
  138852. _psy_noisebias_impulse,
  138853. _psy_noisebias_padding,
  138854. _psy_noisebias_trans,
  138855. _psy_noisebias_long,
  138856. _psy_noise_suppress,
  138857. _psy_compand_44,
  138858. _psy_compand_short_mapping,
  138859. _psy_compand_long_mapping,
  138860. {_noise_start_short_44,_noise_start_long_44},
  138861. {_noise_part_short_44,_noise_part_long_44},
  138862. _noise_thresh_44,
  138863. _psy_ath_floater,
  138864. _psy_ath_abs,
  138865. _psy_lowpass_44,
  138866. _psy_global_44,
  138867. _global_mapping_44,
  138868. NULL,
  138869. _floor_books,
  138870. _floor,
  138871. _floor_short_mapping_44,
  138872. _floor_long_mapping_44,
  138873. _mapres_template_44_uncoupled
  138874. };
  138875. /*** End of inlined file: setup_44u.h ***/
  138876. /*** Start of inlined file: setup_32.h ***/
  138877. static double rate_mapping_32[12]={
  138878. 18000.,28000.,35000.,45000.,56000.,60000.,
  138879. 75000.,90000.,100000.,115000.,150000.,190000.,
  138880. };
  138881. static double rate_mapping_32_un[12]={
  138882. 30000.,42000.,52000.,64000.,72000.,78000.,
  138883. 86000.,92000.,110000.,120000.,140000.,190000.,
  138884. };
  138885. static double _psy_lowpass_32[12]={
  138886. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138887. };
  138888. ve_setup_data_template ve_setup_32_stereo={
  138889. 11,
  138890. rate_mapping_32,
  138891. quality_mapping_44,
  138892. 2,
  138893. 26000,
  138894. 40000,
  138895. blocksize_short_44,
  138896. blocksize_long_44,
  138897. _psy_tone_masteratt_44,
  138898. _psy_tone_0dB,
  138899. _psy_tone_suppress,
  138900. _vp_tonemask_adj_otherblock,
  138901. _vp_tonemask_adj_longblock,
  138902. _vp_tonemask_adj_otherblock,
  138903. _psy_noiseguards_44,
  138904. _psy_noisebias_impulse,
  138905. _psy_noisebias_padding,
  138906. _psy_noisebias_trans,
  138907. _psy_noisebias_long,
  138908. _psy_noise_suppress,
  138909. _psy_compand_44,
  138910. _psy_compand_short_mapping,
  138911. _psy_compand_long_mapping,
  138912. {_noise_start_short_44,_noise_start_long_44},
  138913. {_noise_part_short_44,_noise_part_long_44},
  138914. _noise_thresh_44,
  138915. _psy_ath_floater,
  138916. _psy_ath_abs,
  138917. _psy_lowpass_32,
  138918. _psy_global_44,
  138919. _global_mapping_44,
  138920. _psy_stereo_modes_44,
  138921. _floor_books,
  138922. _floor,
  138923. _floor_short_mapping_44,
  138924. _floor_long_mapping_44,
  138925. _mapres_template_44_stereo
  138926. };
  138927. ve_setup_data_template ve_setup_32_uncoupled={
  138928. 11,
  138929. rate_mapping_32_un,
  138930. quality_mapping_44,
  138931. -1,
  138932. 26000,
  138933. 40000,
  138934. blocksize_short_44,
  138935. blocksize_long_44,
  138936. _psy_tone_masteratt_44,
  138937. _psy_tone_0dB,
  138938. _psy_tone_suppress,
  138939. _vp_tonemask_adj_otherblock,
  138940. _vp_tonemask_adj_longblock,
  138941. _vp_tonemask_adj_otherblock,
  138942. _psy_noiseguards_44,
  138943. _psy_noisebias_impulse,
  138944. _psy_noisebias_padding,
  138945. _psy_noisebias_trans,
  138946. _psy_noisebias_long,
  138947. _psy_noise_suppress,
  138948. _psy_compand_44,
  138949. _psy_compand_short_mapping,
  138950. _psy_compand_long_mapping,
  138951. {_noise_start_short_44,_noise_start_long_44},
  138952. {_noise_part_short_44,_noise_part_long_44},
  138953. _noise_thresh_44,
  138954. _psy_ath_floater,
  138955. _psy_ath_abs,
  138956. _psy_lowpass_32,
  138957. _psy_global_44,
  138958. _global_mapping_44,
  138959. NULL,
  138960. _floor_books,
  138961. _floor,
  138962. _floor_short_mapping_44,
  138963. _floor_long_mapping_44,
  138964. _mapres_template_44_uncoupled
  138965. };
  138966. /*** End of inlined file: setup_32.h ***/
  138967. /*** Start of inlined file: setup_8.h ***/
  138968. /*** Start of inlined file: psych_8.h ***/
  138969. static att3 _psy_tone_masteratt_8[3]={
  138970. {{ 32, 25, 12}, 0, 0}, /* 0 */
  138971. {{ 30, 25, 12}, 0, 0}, /* 0 */
  138972. {{ 20, 0, -14}, 0, 0}, /* 0 */
  138973. };
  138974. static vp_adjblock _vp_tonemask_adj_8[3]={
  138975. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138976. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138977. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  138978. };
  138979. static noise3 _psy_noisebias_8[3]={
  138980. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138981. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  138982. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138983. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138984. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  138985. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138986. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  138987. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  138988. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  138989. };
  138990. static adj_stereo _psy_stereo_modes_8[3]={
  138991. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138992. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138993. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138994. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138995. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138996. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138997. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138998. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138999. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139000. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139001. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139002. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139003. };
  139004. static noiseguard _psy_noiseguards_8[2]={
  139005. {10,10,-1},
  139006. {10,10,-1},
  139007. };
  139008. static compandblock _psy_compand_8[2]={
  139009. {{
  139010. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139011. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139012. 12,12,13,13,14,14,15, 15, /* 23dB */
  139013. 16,16,17,17,17,18,18, 19, /* 31dB */
  139014. 19,19,20,21,22,23,24, 25, /* 39dB */
  139015. }},
  139016. {{
  139017. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139018. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139019. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139020. 9,10,11,12,13,14,15, 16, /* 31dB */
  139021. 17,18,19,20,21,22,23, 24, /* 39dB */
  139022. }},
  139023. };
  139024. static double _psy_lowpass_8[3]={3.,4.,4.};
  139025. static int _noise_start_8[2]={
  139026. 64,64,
  139027. };
  139028. static int _noise_part_8[2]={
  139029. 8,8,
  139030. };
  139031. static int _psy_ath_floater_8[3]={
  139032. -100,-100,-105,
  139033. };
  139034. static int _psy_ath_abs_8[3]={
  139035. -130,-130,-140,
  139036. };
  139037. /*** End of inlined file: psych_8.h ***/
  139038. /*** Start of inlined file: residue_8.h ***/
  139039. static static_bookblock _resbook_8s_0={
  139040. {
  139041. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139042. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139043. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139044. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139045. }
  139046. };
  139047. static static_bookblock _resbook_8s_1={
  139048. {
  139049. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139050. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139051. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139052. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139053. }
  139054. };
  139055. static vorbis_residue_template _res_8s_0[]={
  139056. {2,0, &_residue_44_mid,
  139057. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139058. &_resbook_8s_0,&_resbook_8s_0},
  139059. };
  139060. static vorbis_residue_template _res_8s_1[]={
  139061. {2,0, &_residue_44_mid,
  139062. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139063. &_resbook_8s_1,&_resbook_8s_1},
  139064. };
  139065. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139066. { _map_nominal, _res_8s_0 }, /* 0 */
  139067. { _map_nominal, _res_8s_1 }, /* 1 */
  139068. };
  139069. static static_bookblock _resbook_8u_0={
  139070. {
  139071. {0},
  139072. {0,0,&_8u0__p1_0},
  139073. {0,0,&_8u0__p2_0},
  139074. {0,0,&_8u0__p3_0},
  139075. {0,0,&_8u0__p4_0},
  139076. {0,0,&_8u0__p5_0},
  139077. {&_8u0__p6_0,&_8u0__p6_1},
  139078. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139079. }
  139080. };
  139081. static static_bookblock _resbook_8u_1={
  139082. {
  139083. {0},
  139084. {0,0,&_8u1__p1_0},
  139085. {0,0,&_8u1__p2_0},
  139086. {0,0,&_8u1__p3_0},
  139087. {0,0,&_8u1__p4_0},
  139088. {0,0,&_8u1__p5_0},
  139089. {0,0,&_8u1__p6_0},
  139090. {&_8u1__p7_0,&_8u1__p7_1},
  139091. {&_8u1__p8_0,&_8u1__p8_1},
  139092. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139093. }
  139094. };
  139095. static vorbis_residue_template _res_8u_0[]={
  139096. {1,0, &_residue_44_low_un,
  139097. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139098. &_resbook_8u_0,&_resbook_8u_0},
  139099. };
  139100. static vorbis_residue_template _res_8u_1[]={
  139101. {1,0, &_residue_44_mid_un,
  139102. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139103. &_resbook_8u_1,&_resbook_8u_1},
  139104. };
  139105. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139106. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139107. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139108. };
  139109. /*** End of inlined file: residue_8.h ***/
  139110. static int blocksize_8[2]={
  139111. 512,512
  139112. };
  139113. static int _floor_mapping_8[2]={
  139114. 6,6,
  139115. };
  139116. static double rate_mapping_8[3]={
  139117. 6000.,9000.,32000.,
  139118. };
  139119. static double rate_mapping_8_uncoupled[3]={
  139120. 8000.,14000.,42000.,
  139121. };
  139122. static double quality_mapping_8[3]={
  139123. -.1,.0,1.
  139124. };
  139125. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139126. static double _global_mapping_8[3]={ 1., 2., 3. };
  139127. ve_setup_data_template ve_setup_8_stereo={
  139128. 2,
  139129. rate_mapping_8,
  139130. quality_mapping_8,
  139131. 2,
  139132. 8000,
  139133. 9000,
  139134. blocksize_8,
  139135. blocksize_8,
  139136. _psy_tone_masteratt_8,
  139137. _psy_tone_0dB,
  139138. _psy_tone_suppress,
  139139. _vp_tonemask_adj_8,
  139140. NULL,
  139141. _vp_tonemask_adj_8,
  139142. _psy_noiseguards_8,
  139143. _psy_noisebias_8,
  139144. _psy_noisebias_8,
  139145. NULL,
  139146. NULL,
  139147. _psy_noise_suppress,
  139148. _psy_compand_8,
  139149. _psy_compand_8_mapping,
  139150. NULL,
  139151. {_noise_start_8,_noise_start_8},
  139152. {_noise_part_8,_noise_part_8},
  139153. _noise_thresh_5only,
  139154. _psy_ath_floater_8,
  139155. _psy_ath_abs_8,
  139156. _psy_lowpass_8,
  139157. _psy_global_44,
  139158. _global_mapping_8,
  139159. _psy_stereo_modes_8,
  139160. _floor_books,
  139161. _floor,
  139162. _floor_mapping_8,
  139163. NULL,
  139164. _mapres_template_8_stereo
  139165. };
  139166. ve_setup_data_template ve_setup_8_uncoupled={
  139167. 2,
  139168. rate_mapping_8_uncoupled,
  139169. quality_mapping_8,
  139170. -1,
  139171. 8000,
  139172. 9000,
  139173. blocksize_8,
  139174. blocksize_8,
  139175. _psy_tone_masteratt_8,
  139176. _psy_tone_0dB,
  139177. _psy_tone_suppress,
  139178. _vp_tonemask_adj_8,
  139179. NULL,
  139180. _vp_tonemask_adj_8,
  139181. _psy_noiseguards_8,
  139182. _psy_noisebias_8,
  139183. _psy_noisebias_8,
  139184. NULL,
  139185. NULL,
  139186. _psy_noise_suppress,
  139187. _psy_compand_8,
  139188. _psy_compand_8_mapping,
  139189. NULL,
  139190. {_noise_start_8,_noise_start_8},
  139191. {_noise_part_8,_noise_part_8},
  139192. _noise_thresh_5only,
  139193. _psy_ath_floater_8,
  139194. _psy_ath_abs_8,
  139195. _psy_lowpass_8,
  139196. _psy_global_44,
  139197. _global_mapping_8,
  139198. _psy_stereo_modes_8,
  139199. _floor_books,
  139200. _floor,
  139201. _floor_mapping_8,
  139202. NULL,
  139203. _mapres_template_8_uncoupled
  139204. };
  139205. /*** End of inlined file: setup_8.h ***/
  139206. /*** Start of inlined file: setup_11.h ***/
  139207. /*** Start of inlined file: psych_11.h ***/
  139208. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139209. static att3 _psy_tone_masteratt_11[3]={
  139210. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139211. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139212. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139213. };
  139214. static vp_adjblock _vp_tonemask_adj_11[3]={
  139215. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139216. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139217. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139218. };
  139219. static noise3 _psy_noisebias_11[3]={
  139220. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139221. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139222. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139223. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139224. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139225. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139226. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139227. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139228. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139229. };
  139230. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139231. /*** End of inlined file: psych_11.h ***/
  139232. static int blocksize_11[2]={
  139233. 512,512
  139234. };
  139235. static int _floor_mapping_11[2]={
  139236. 6,6,
  139237. };
  139238. static double rate_mapping_11[3]={
  139239. 8000.,13000.,44000.,
  139240. };
  139241. static double rate_mapping_11_uncoupled[3]={
  139242. 12000.,20000.,50000.,
  139243. };
  139244. static double quality_mapping_11[3]={
  139245. -.1,.0,1.
  139246. };
  139247. ve_setup_data_template ve_setup_11_stereo={
  139248. 2,
  139249. rate_mapping_11,
  139250. quality_mapping_11,
  139251. 2,
  139252. 9000,
  139253. 15000,
  139254. blocksize_11,
  139255. blocksize_11,
  139256. _psy_tone_masteratt_11,
  139257. _psy_tone_0dB,
  139258. _psy_tone_suppress,
  139259. _vp_tonemask_adj_11,
  139260. NULL,
  139261. _vp_tonemask_adj_11,
  139262. _psy_noiseguards_8,
  139263. _psy_noisebias_11,
  139264. _psy_noisebias_11,
  139265. NULL,
  139266. NULL,
  139267. _psy_noise_suppress,
  139268. _psy_compand_8,
  139269. _psy_compand_8_mapping,
  139270. NULL,
  139271. {_noise_start_8,_noise_start_8},
  139272. {_noise_part_8,_noise_part_8},
  139273. _noise_thresh_11,
  139274. _psy_ath_floater_8,
  139275. _psy_ath_abs_8,
  139276. _psy_lowpass_11,
  139277. _psy_global_44,
  139278. _global_mapping_8,
  139279. _psy_stereo_modes_8,
  139280. _floor_books,
  139281. _floor,
  139282. _floor_mapping_11,
  139283. NULL,
  139284. _mapres_template_8_stereo
  139285. };
  139286. ve_setup_data_template ve_setup_11_uncoupled={
  139287. 2,
  139288. rate_mapping_11_uncoupled,
  139289. quality_mapping_11,
  139290. -1,
  139291. 9000,
  139292. 15000,
  139293. blocksize_11,
  139294. blocksize_11,
  139295. _psy_tone_masteratt_11,
  139296. _psy_tone_0dB,
  139297. _psy_tone_suppress,
  139298. _vp_tonemask_adj_11,
  139299. NULL,
  139300. _vp_tonemask_adj_11,
  139301. _psy_noiseguards_8,
  139302. _psy_noisebias_11,
  139303. _psy_noisebias_11,
  139304. NULL,
  139305. NULL,
  139306. _psy_noise_suppress,
  139307. _psy_compand_8,
  139308. _psy_compand_8_mapping,
  139309. NULL,
  139310. {_noise_start_8,_noise_start_8},
  139311. {_noise_part_8,_noise_part_8},
  139312. _noise_thresh_11,
  139313. _psy_ath_floater_8,
  139314. _psy_ath_abs_8,
  139315. _psy_lowpass_11,
  139316. _psy_global_44,
  139317. _global_mapping_8,
  139318. _psy_stereo_modes_8,
  139319. _floor_books,
  139320. _floor,
  139321. _floor_mapping_11,
  139322. NULL,
  139323. _mapres_template_8_uncoupled
  139324. };
  139325. /*** End of inlined file: setup_11.h ***/
  139326. /*** Start of inlined file: setup_16.h ***/
  139327. /*** Start of inlined file: psych_16.h ***/
  139328. static adj_stereo _psy_stereo_modes_16[4]={
  139329. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139330. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139331. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139332. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139333. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139334. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139335. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139336. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139337. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139338. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139339. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139340. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139341. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139342. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139343. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139344. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139345. };
  139346. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139347. static att3 _psy_tone_masteratt_16[4]={
  139348. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139349. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139350. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139351. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139352. };
  139353. static vp_adjblock _vp_tonemask_adj_16[4]={
  139354. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139355. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139356. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139357. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139358. };
  139359. static noise3 _psy_noisebias_16_short[4]={
  139360. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139361. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139362. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139363. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139364. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139365. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139366. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139367. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139368. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139369. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139370. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139371. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139372. };
  139373. static noise3 _psy_noisebias_16_impulse[4]={
  139374. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139375. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139376. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139377. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139378. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139379. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139380. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139381. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139382. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139383. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139384. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139385. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139386. };
  139387. static noise3 _psy_noisebias_16[4]={
  139388. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139389. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139390. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139391. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139392. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139393. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139394. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139395. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139396. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139397. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139398. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139399. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139400. };
  139401. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139402. static int _noise_start_16[3]={ 256,256,9999 };
  139403. static int _noise_part_16[4]={ 8,8,8,8 };
  139404. static int _psy_ath_floater_16[4]={
  139405. -100,-100,-100,-105,
  139406. };
  139407. static int _psy_ath_abs_16[4]={
  139408. -130,-130,-130,-140,
  139409. };
  139410. /*** End of inlined file: psych_16.h ***/
  139411. /*** Start of inlined file: residue_16.h ***/
  139412. static static_bookblock _resbook_16s_0={
  139413. {
  139414. {0},
  139415. {0,0,&_16c0_s_p1_0},
  139416. {0,0,&_16c0_s_p2_0},
  139417. {0,0,&_16c0_s_p3_0},
  139418. {0,0,&_16c0_s_p4_0},
  139419. {0,0,&_16c0_s_p5_0},
  139420. {0,0,&_16c0_s_p6_0},
  139421. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139422. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139423. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139424. }
  139425. };
  139426. static static_bookblock _resbook_16s_1={
  139427. {
  139428. {0},
  139429. {0,0,&_16c1_s_p1_0},
  139430. {0,0,&_16c1_s_p2_0},
  139431. {0,0,&_16c1_s_p3_0},
  139432. {0,0,&_16c1_s_p4_0},
  139433. {0,0,&_16c1_s_p5_0},
  139434. {0,0,&_16c1_s_p6_0},
  139435. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139436. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139437. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139438. }
  139439. };
  139440. static static_bookblock _resbook_16s_2={
  139441. {
  139442. {0},
  139443. {0,0,&_16c2_s_p1_0},
  139444. {0,0,&_16c2_s_p2_0},
  139445. {0,0,&_16c2_s_p3_0},
  139446. {0,0,&_16c2_s_p4_0},
  139447. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139448. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139449. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139450. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139451. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139452. }
  139453. };
  139454. static vorbis_residue_template _res_16s_0[]={
  139455. {2,0, &_residue_44_mid,
  139456. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139457. &_resbook_16s_0,&_resbook_16s_0},
  139458. };
  139459. static vorbis_residue_template _res_16s_1[]={
  139460. {2,0, &_residue_44_mid,
  139461. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139462. &_resbook_16s_1,&_resbook_16s_1},
  139463. {2,0, &_residue_44_mid,
  139464. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139465. &_resbook_16s_1,&_resbook_16s_1}
  139466. };
  139467. static vorbis_residue_template _res_16s_2[]={
  139468. {2,0, &_residue_44_high,
  139469. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139470. &_resbook_16s_2,&_resbook_16s_2},
  139471. {2,0, &_residue_44_high,
  139472. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139473. &_resbook_16s_2,&_resbook_16s_2}
  139474. };
  139475. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139476. { _map_nominal, _res_16s_0 }, /* 0 */
  139477. { _map_nominal, _res_16s_1 }, /* 1 */
  139478. { _map_nominal, _res_16s_2 }, /* 2 */
  139479. };
  139480. static static_bookblock _resbook_16u_0={
  139481. {
  139482. {0},
  139483. {0,0,&_16u0__p1_0},
  139484. {0,0,&_16u0__p2_0},
  139485. {0,0,&_16u0__p3_0},
  139486. {0,0,&_16u0__p4_0},
  139487. {0,0,&_16u0__p5_0},
  139488. {&_16u0__p6_0,&_16u0__p6_1},
  139489. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139490. }
  139491. };
  139492. static static_bookblock _resbook_16u_1={
  139493. {
  139494. {0},
  139495. {0,0,&_16u1__p1_0},
  139496. {0,0,&_16u1__p2_0},
  139497. {0,0,&_16u1__p3_0},
  139498. {0,0,&_16u1__p4_0},
  139499. {0,0,&_16u1__p5_0},
  139500. {0,0,&_16u1__p6_0},
  139501. {&_16u1__p7_0,&_16u1__p7_1},
  139502. {&_16u1__p8_0,&_16u1__p8_1},
  139503. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139504. }
  139505. };
  139506. static static_bookblock _resbook_16u_2={
  139507. {
  139508. {0},
  139509. {0,0,&_16u2_p1_0},
  139510. {0,0,&_16u2_p2_0},
  139511. {0,0,&_16u2_p3_0},
  139512. {0,0,&_16u2_p4_0},
  139513. {&_16u2_p5_0,&_16u2_p5_1},
  139514. {&_16u2_p6_0,&_16u2_p6_1},
  139515. {&_16u2_p7_0,&_16u2_p7_1},
  139516. {&_16u2_p8_0,&_16u2_p8_1},
  139517. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139518. }
  139519. };
  139520. static vorbis_residue_template _res_16u_0[]={
  139521. {1,0, &_residue_44_low_un,
  139522. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139523. &_resbook_16u_0,&_resbook_16u_0},
  139524. };
  139525. static vorbis_residue_template _res_16u_1[]={
  139526. {1,0, &_residue_44_mid_un,
  139527. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139528. &_resbook_16u_1,&_resbook_16u_1},
  139529. {1,0, &_residue_44_mid_un,
  139530. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139531. &_resbook_16u_1,&_resbook_16u_1}
  139532. };
  139533. static vorbis_residue_template _res_16u_2[]={
  139534. {1,0, &_residue_44_hi_un,
  139535. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139536. &_resbook_16u_2,&_resbook_16u_2},
  139537. {1,0, &_residue_44_hi_un,
  139538. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139539. &_resbook_16u_2,&_resbook_16u_2}
  139540. };
  139541. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139542. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139543. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139544. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139545. };
  139546. /*** End of inlined file: residue_16.h ***/
  139547. static int blocksize_16_short[3]={
  139548. 1024,512,512
  139549. };
  139550. static int blocksize_16_long[3]={
  139551. 1024,1024,1024
  139552. };
  139553. static int _floor_mapping_16_short[3]={
  139554. 9,3,3
  139555. };
  139556. static int _floor_mapping_16[3]={
  139557. 9,9,9
  139558. };
  139559. static double rate_mapping_16[4]={
  139560. 12000.,20000.,44000.,86000.
  139561. };
  139562. static double rate_mapping_16_uncoupled[4]={
  139563. 16000.,28000.,64000.,100000.
  139564. };
  139565. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139566. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139567. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139568. ve_setup_data_template ve_setup_16_stereo={
  139569. 3,
  139570. rate_mapping_16,
  139571. quality_mapping_16,
  139572. 2,
  139573. 15000,
  139574. 19000,
  139575. blocksize_16_short,
  139576. blocksize_16_long,
  139577. _psy_tone_masteratt_16,
  139578. _psy_tone_0dB,
  139579. _psy_tone_suppress,
  139580. _vp_tonemask_adj_16,
  139581. _vp_tonemask_adj_16,
  139582. _vp_tonemask_adj_16,
  139583. _psy_noiseguards_8,
  139584. _psy_noisebias_16_impulse,
  139585. _psy_noisebias_16_short,
  139586. _psy_noisebias_16_short,
  139587. _psy_noisebias_16,
  139588. _psy_noise_suppress,
  139589. _psy_compand_8,
  139590. _psy_compand_16_mapping,
  139591. _psy_compand_16_mapping,
  139592. {_noise_start_16,_noise_start_16},
  139593. { _noise_part_16, _noise_part_16},
  139594. _noise_thresh_16,
  139595. _psy_ath_floater_16,
  139596. _psy_ath_abs_16,
  139597. _psy_lowpass_16,
  139598. _psy_global_44,
  139599. _global_mapping_16,
  139600. _psy_stereo_modes_16,
  139601. _floor_books,
  139602. _floor,
  139603. _floor_mapping_16_short,
  139604. _floor_mapping_16,
  139605. _mapres_template_16_stereo
  139606. };
  139607. ve_setup_data_template ve_setup_16_uncoupled={
  139608. 3,
  139609. rate_mapping_16_uncoupled,
  139610. quality_mapping_16,
  139611. -1,
  139612. 15000,
  139613. 19000,
  139614. blocksize_16_short,
  139615. blocksize_16_long,
  139616. _psy_tone_masteratt_16,
  139617. _psy_tone_0dB,
  139618. _psy_tone_suppress,
  139619. _vp_tonemask_adj_16,
  139620. _vp_tonemask_adj_16,
  139621. _vp_tonemask_adj_16,
  139622. _psy_noiseguards_8,
  139623. _psy_noisebias_16_impulse,
  139624. _psy_noisebias_16_short,
  139625. _psy_noisebias_16_short,
  139626. _psy_noisebias_16,
  139627. _psy_noise_suppress,
  139628. _psy_compand_8,
  139629. _psy_compand_16_mapping,
  139630. _psy_compand_16_mapping,
  139631. {_noise_start_16,_noise_start_16},
  139632. { _noise_part_16, _noise_part_16},
  139633. _noise_thresh_16,
  139634. _psy_ath_floater_16,
  139635. _psy_ath_abs_16,
  139636. _psy_lowpass_16,
  139637. _psy_global_44,
  139638. _global_mapping_16,
  139639. _psy_stereo_modes_16,
  139640. _floor_books,
  139641. _floor,
  139642. _floor_mapping_16_short,
  139643. _floor_mapping_16,
  139644. _mapres_template_16_uncoupled
  139645. };
  139646. /*** End of inlined file: setup_16.h ***/
  139647. /*** Start of inlined file: setup_22.h ***/
  139648. static double rate_mapping_22[4]={
  139649. 15000.,20000.,44000.,86000.
  139650. };
  139651. static double rate_mapping_22_uncoupled[4]={
  139652. 16000.,28000.,50000.,90000.
  139653. };
  139654. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139655. ve_setup_data_template ve_setup_22_stereo={
  139656. 3,
  139657. rate_mapping_22,
  139658. quality_mapping_16,
  139659. 2,
  139660. 19000,
  139661. 26000,
  139662. blocksize_16_short,
  139663. blocksize_16_long,
  139664. _psy_tone_masteratt_16,
  139665. _psy_tone_0dB,
  139666. _psy_tone_suppress,
  139667. _vp_tonemask_adj_16,
  139668. _vp_tonemask_adj_16,
  139669. _vp_tonemask_adj_16,
  139670. _psy_noiseguards_8,
  139671. _psy_noisebias_16_impulse,
  139672. _psy_noisebias_16_short,
  139673. _psy_noisebias_16_short,
  139674. _psy_noisebias_16,
  139675. _psy_noise_suppress,
  139676. _psy_compand_8,
  139677. _psy_compand_8_mapping,
  139678. _psy_compand_8_mapping,
  139679. {_noise_start_16,_noise_start_16},
  139680. { _noise_part_16, _noise_part_16},
  139681. _noise_thresh_16,
  139682. _psy_ath_floater_16,
  139683. _psy_ath_abs_16,
  139684. _psy_lowpass_22,
  139685. _psy_global_44,
  139686. _global_mapping_16,
  139687. _psy_stereo_modes_16,
  139688. _floor_books,
  139689. _floor,
  139690. _floor_mapping_16_short,
  139691. _floor_mapping_16,
  139692. _mapres_template_16_stereo
  139693. };
  139694. ve_setup_data_template ve_setup_22_uncoupled={
  139695. 3,
  139696. rate_mapping_22_uncoupled,
  139697. quality_mapping_16,
  139698. -1,
  139699. 19000,
  139700. 26000,
  139701. blocksize_16_short,
  139702. blocksize_16_long,
  139703. _psy_tone_masteratt_16,
  139704. _psy_tone_0dB,
  139705. _psy_tone_suppress,
  139706. _vp_tonemask_adj_16,
  139707. _vp_tonemask_adj_16,
  139708. _vp_tonemask_adj_16,
  139709. _psy_noiseguards_8,
  139710. _psy_noisebias_16_impulse,
  139711. _psy_noisebias_16_short,
  139712. _psy_noisebias_16_short,
  139713. _psy_noisebias_16,
  139714. _psy_noise_suppress,
  139715. _psy_compand_8,
  139716. _psy_compand_8_mapping,
  139717. _psy_compand_8_mapping,
  139718. {_noise_start_16,_noise_start_16},
  139719. { _noise_part_16, _noise_part_16},
  139720. _noise_thresh_16,
  139721. _psy_ath_floater_16,
  139722. _psy_ath_abs_16,
  139723. _psy_lowpass_22,
  139724. _psy_global_44,
  139725. _global_mapping_16,
  139726. _psy_stereo_modes_16,
  139727. _floor_books,
  139728. _floor,
  139729. _floor_mapping_16_short,
  139730. _floor_mapping_16,
  139731. _mapres_template_16_uncoupled
  139732. };
  139733. /*** End of inlined file: setup_22.h ***/
  139734. /*** Start of inlined file: setup_X.h ***/
  139735. static double rate_mapping_X[12]={
  139736. -1.,-1.,-1.,-1.,-1.,-1.,
  139737. -1.,-1.,-1.,-1.,-1.,-1.
  139738. };
  139739. ve_setup_data_template ve_setup_X_stereo={
  139740. 11,
  139741. rate_mapping_X,
  139742. quality_mapping_44,
  139743. 2,
  139744. 50000,
  139745. 200000,
  139746. blocksize_short_44,
  139747. blocksize_long_44,
  139748. _psy_tone_masteratt_44,
  139749. _psy_tone_0dB,
  139750. _psy_tone_suppress,
  139751. _vp_tonemask_adj_otherblock,
  139752. _vp_tonemask_adj_longblock,
  139753. _vp_tonemask_adj_otherblock,
  139754. _psy_noiseguards_44,
  139755. _psy_noisebias_impulse,
  139756. _psy_noisebias_padding,
  139757. _psy_noisebias_trans,
  139758. _psy_noisebias_long,
  139759. _psy_noise_suppress,
  139760. _psy_compand_44,
  139761. _psy_compand_short_mapping,
  139762. _psy_compand_long_mapping,
  139763. {_noise_start_short_44,_noise_start_long_44},
  139764. {_noise_part_short_44,_noise_part_long_44},
  139765. _noise_thresh_44,
  139766. _psy_ath_floater,
  139767. _psy_ath_abs,
  139768. _psy_lowpass_44,
  139769. _psy_global_44,
  139770. _global_mapping_44,
  139771. _psy_stereo_modes_44,
  139772. _floor_books,
  139773. _floor,
  139774. _floor_short_mapping_44,
  139775. _floor_long_mapping_44,
  139776. _mapres_template_44_stereo
  139777. };
  139778. ve_setup_data_template ve_setup_X_uncoupled={
  139779. 11,
  139780. rate_mapping_X,
  139781. quality_mapping_44,
  139782. -1,
  139783. 50000,
  139784. 200000,
  139785. blocksize_short_44,
  139786. blocksize_long_44,
  139787. _psy_tone_masteratt_44,
  139788. _psy_tone_0dB,
  139789. _psy_tone_suppress,
  139790. _vp_tonemask_adj_otherblock,
  139791. _vp_tonemask_adj_longblock,
  139792. _vp_tonemask_adj_otherblock,
  139793. _psy_noiseguards_44,
  139794. _psy_noisebias_impulse,
  139795. _psy_noisebias_padding,
  139796. _psy_noisebias_trans,
  139797. _psy_noisebias_long,
  139798. _psy_noise_suppress,
  139799. _psy_compand_44,
  139800. _psy_compand_short_mapping,
  139801. _psy_compand_long_mapping,
  139802. {_noise_start_short_44,_noise_start_long_44},
  139803. {_noise_part_short_44,_noise_part_long_44},
  139804. _noise_thresh_44,
  139805. _psy_ath_floater,
  139806. _psy_ath_abs,
  139807. _psy_lowpass_44,
  139808. _psy_global_44,
  139809. _global_mapping_44,
  139810. NULL,
  139811. _floor_books,
  139812. _floor,
  139813. _floor_short_mapping_44,
  139814. _floor_long_mapping_44,
  139815. _mapres_template_44_uncoupled
  139816. };
  139817. ve_setup_data_template ve_setup_XX_stereo={
  139818. 2,
  139819. rate_mapping_X,
  139820. quality_mapping_8,
  139821. 2,
  139822. 0,
  139823. 8000,
  139824. blocksize_8,
  139825. blocksize_8,
  139826. _psy_tone_masteratt_8,
  139827. _psy_tone_0dB,
  139828. _psy_tone_suppress,
  139829. _vp_tonemask_adj_8,
  139830. NULL,
  139831. _vp_tonemask_adj_8,
  139832. _psy_noiseguards_8,
  139833. _psy_noisebias_8,
  139834. _psy_noisebias_8,
  139835. NULL,
  139836. NULL,
  139837. _psy_noise_suppress,
  139838. _psy_compand_8,
  139839. _psy_compand_8_mapping,
  139840. NULL,
  139841. {_noise_start_8,_noise_start_8},
  139842. {_noise_part_8,_noise_part_8},
  139843. _noise_thresh_5only,
  139844. _psy_ath_floater_8,
  139845. _psy_ath_abs_8,
  139846. _psy_lowpass_8,
  139847. _psy_global_44,
  139848. _global_mapping_8,
  139849. _psy_stereo_modes_8,
  139850. _floor_books,
  139851. _floor,
  139852. _floor_mapping_8,
  139853. NULL,
  139854. _mapres_template_8_stereo
  139855. };
  139856. ve_setup_data_template ve_setup_XX_uncoupled={
  139857. 2,
  139858. rate_mapping_X,
  139859. quality_mapping_8,
  139860. -1,
  139861. 0,
  139862. 8000,
  139863. blocksize_8,
  139864. blocksize_8,
  139865. _psy_tone_masteratt_8,
  139866. _psy_tone_0dB,
  139867. _psy_tone_suppress,
  139868. _vp_tonemask_adj_8,
  139869. NULL,
  139870. _vp_tonemask_adj_8,
  139871. _psy_noiseguards_8,
  139872. _psy_noisebias_8,
  139873. _psy_noisebias_8,
  139874. NULL,
  139875. NULL,
  139876. _psy_noise_suppress,
  139877. _psy_compand_8,
  139878. _psy_compand_8_mapping,
  139879. NULL,
  139880. {_noise_start_8,_noise_start_8},
  139881. {_noise_part_8,_noise_part_8},
  139882. _noise_thresh_5only,
  139883. _psy_ath_floater_8,
  139884. _psy_ath_abs_8,
  139885. _psy_lowpass_8,
  139886. _psy_global_44,
  139887. _global_mapping_8,
  139888. _psy_stereo_modes_8,
  139889. _floor_books,
  139890. _floor,
  139891. _floor_mapping_8,
  139892. NULL,
  139893. _mapres_template_8_uncoupled
  139894. };
  139895. /*** End of inlined file: setup_X.h ***/
  139896. static ve_setup_data_template *setup_list[]={
  139897. &ve_setup_44_stereo,
  139898. &ve_setup_44_uncoupled,
  139899. &ve_setup_32_stereo,
  139900. &ve_setup_32_uncoupled,
  139901. &ve_setup_22_stereo,
  139902. &ve_setup_22_uncoupled,
  139903. &ve_setup_16_stereo,
  139904. &ve_setup_16_uncoupled,
  139905. &ve_setup_11_stereo,
  139906. &ve_setup_11_uncoupled,
  139907. &ve_setup_8_stereo,
  139908. &ve_setup_8_uncoupled,
  139909. &ve_setup_X_stereo,
  139910. &ve_setup_X_uncoupled,
  139911. &ve_setup_XX_stereo,
  139912. &ve_setup_XX_uncoupled,
  139913. 0
  139914. };
  139915. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139916. if(vi && vi->codec_setup){
  139917. vi->version=0;
  139918. vi->channels=ch;
  139919. vi->rate=rate;
  139920. return(0);
  139921. }
  139922. return(OV_EINVAL);
  139923. }
  139924. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139925. static_codebook ***books,
  139926. vorbis_info_floor1 *in,
  139927. int *x){
  139928. int i,k,is=s;
  139929. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  139930. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139931. memcpy(f,in+x[is],sizeof(*f));
  139932. f->n=ci->blocksizes[block]>>1;
  139933. {
  139934. int partitions=f->partitions;
  139935. int maxclass=-1;
  139936. int maxbook=-1;
  139937. for(i=0;i<partitions;i++)
  139938. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  139939. for(i=0;i<=maxclass;i++){
  139940. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  139941. f->class_book[i]+=ci->books;
  139942. for(k=0;k<(1<<f->class_subs[i]);k++){
  139943. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  139944. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  139945. }
  139946. }
  139947. for(i=0;i<=maxbook;i++)
  139948. ci->book_param[ci->books++]=books[x[is]][i];
  139949. }
  139950. ci->floor_type[ci->floors]=1;
  139951. ci->floor_param[ci->floors]=f;
  139952. ci->floors++;
  139953. return;
  139954. }
  139955. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  139956. vorbis_info_psy_global *in,
  139957. double *x){
  139958. int i,is=s;
  139959. double ds=s-is;
  139960. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139961. vorbis_info_psy_global *g=&ci->psy_g_param;
  139962. memcpy(g,in+(int)x[is],sizeof(*g));
  139963. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139964. is=(int)ds;
  139965. ds-=is;
  139966. if(ds==0 && is>0){
  139967. is--;
  139968. ds=1.;
  139969. }
  139970. for(i=0;i<4;i++){
  139971. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  139972. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  139973. }
  139974. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  139975. return;
  139976. }
  139977. static void vorbis_encode_global_stereo(vorbis_info *vi,
  139978. highlevel_encode_setup *hi,
  139979. adj_stereo *p){
  139980. float s=hi->stereo_point_setting;
  139981. int i,is=s;
  139982. double ds=s-is;
  139983. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139984. vorbis_info_psy_global *g=&ci->psy_g_param;
  139985. if(p){
  139986. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  139987. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  139988. if(hi->managed){
  139989. for(i=0;i<PACKETBLOBS;i++){
  139990. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  139991. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139992. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139993. g->coupling_pkHz[i]=kHz;
  139994. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  139995. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139996. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139997. }
  139998. }else{
  139999. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140000. for(i=0;i<PACKETBLOBS;i++){
  140001. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140002. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140003. g->coupling_pkHz[i]=kHz;
  140004. }
  140005. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140006. for(i=0;i<PACKETBLOBS;i++){
  140007. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140008. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140009. }
  140010. }
  140011. }else{
  140012. for(i=0;i<PACKETBLOBS;i++){
  140013. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140014. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140015. }
  140016. }
  140017. return;
  140018. }
  140019. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140020. int *nn_start,
  140021. int *nn_partition,
  140022. double *nn_thresh,
  140023. int block){
  140024. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140025. vorbis_info_psy *p=ci->psy_param[block];
  140026. highlevel_encode_setup *hi=&ci->hi;
  140027. int is=s;
  140028. if(block>=ci->psys)
  140029. ci->psys=block+1;
  140030. if(!p){
  140031. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140032. ci->psy_param[block]=p;
  140033. }
  140034. memcpy(p,&_psy_info_template,sizeof(*p));
  140035. p->blockflag=block>>1;
  140036. if(hi->noise_normalize_p){
  140037. p->normal_channel_p=1;
  140038. p->normal_point_p=1;
  140039. p->normal_start=nn_start[is];
  140040. p->normal_partition=nn_partition[is];
  140041. p->normal_thresh=nn_thresh[is];
  140042. }
  140043. return;
  140044. }
  140045. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140046. att3 *att,
  140047. int *max,
  140048. vp_adjblock *in){
  140049. int i,is=s;
  140050. double ds=s-is;
  140051. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140052. vorbis_info_psy *p=ci->psy_param[block];
  140053. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140054. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140055. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140056. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140057. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140058. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140059. for(i=0;i<P_BANDS;i++)
  140060. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140061. return;
  140062. }
  140063. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140064. compandblock *in, double *x){
  140065. int i,is=s;
  140066. double ds=s-is;
  140067. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140068. vorbis_info_psy *p=ci->psy_param[block];
  140069. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140070. is=(int)ds;
  140071. ds-=is;
  140072. if(ds==0 && is>0){
  140073. is--;
  140074. ds=1.;
  140075. }
  140076. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140077. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140078. return;
  140079. }
  140080. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140081. int *suppress){
  140082. int is=s;
  140083. double ds=s-is;
  140084. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140085. vorbis_info_psy *p=ci->psy_param[block];
  140086. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140087. return;
  140088. }
  140089. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140090. int *suppress,
  140091. noise3 *in,
  140092. noiseguard *guard,
  140093. double userbias){
  140094. int i,is=s,j;
  140095. double ds=s-is;
  140096. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140097. vorbis_info_psy *p=ci->psy_param[block];
  140098. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140099. p->noisewindowlomin=guard[block].lo;
  140100. p->noisewindowhimin=guard[block].hi;
  140101. p->noisewindowfixed=guard[block].fixed;
  140102. for(j=0;j<P_NOISECURVES;j++)
  140103. for(i=0;i<P_BANDS;i++)
  140104. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140105. for(j=0;j<P_NOISECURVES;j++){
  140106. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140107. for(i=0;i<P_BANDS;i++){
  140108. p->noiseoff[j][i]+=userbias;
  140109. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140110. }
  140111. }
  140112. return;
  140113. }
  140114. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140115. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140116. vorbis_info_psy *p=ci->psy_param[block];
  140117. p->ath_adjatt=ci->hi.ath_floating_dB;
  140118. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140119. return;
  140120. }
  140121. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140122. int i;
  140123. for(i=0;i<ci->books;i++)
  140124. if(ci->book_param[i]==book)return(i);
  140125. return(ci->books++);
  140126. }
  140127. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140128. int *shortb,int *longb){
  140129. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140130. int is=s;
  140131. int blockshort=shortb[is];
  140132. int blocklong=longb[is];
  140133. ci->blocksizes[0]=blockshort;
  140134. ci->blocksizes[1]=blocklong;
  140135. }
  140136. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140137. int number, int block,
  140138. vorbis_residue_template *res){
  140139. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140140. int i,n;
  140141. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140142. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140143. memcpy(r,res->res,sizeof(*r));
  140144. if(ci->residues<=number)ci->residues=number+1;
  140145. switch(ci->blocksizes[block]){
  140146. case 64:case 128:case 256:
  140147. r->grouping=16;
  140148. break;
  140149. default:
  140150. r->grouping=32;
  140151. break;
  140152. }
  140153. ci->residue_type[number]=res->res_type;
  140154. n=r->end=ci->blocksizes[block]>>1;
  140155. if(res->res_type==2)
  140156. n=r->end*=vi->channels;
  140157. {
  140158. int booklist=0,k;
  140159. if(ci->hi.managed){
  140160. for(i=0;i<r->partitions;i++)
  140161. for(k=0;k<3;k++)
  140162. if(res->books_base_managed->books[i][k])
  140163. r->secondstages[i]|=(1<<k);
  140164. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140165. ci->book_param[r->groupbook]=res->book_aux_managed;
  140166. for(i=0;i<r->partitions;i++){
  140167. for(k=0;k<3;k++){
  140168. if(res->books_base_managed->books[i][k]){
  140169. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140170. r->booklist[booklist++]=bookid;
  140171. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140172. }
  140173. }
  140174. }
  140175. }else{
  140176. for(i=0;i<r->partitions;i++)
  140177. for(k=0;k<3;k++)
  140178. if(res->books_base->books[i][k])
  140179. r->secondstages[i]|=(1<<k);
  140180. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140181. ci->book_param[r->groupbook]=res->book_aux;
  140182. for(i=0;i<r->partitions;i++){
  140183. for(k=0;k<3;k++){
  140184. if(res->books_base->books[i][k]){
  140185. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140186. r->booklist[booklist++]=bookid;
  140187. ci->book_param[bookid]=res->books_base->books[i][k];
  140188. }
  140189. }
  140190. }
  140191. }
  140192. }
  140193. {
  140194. double freq=ci->hi.lowpass_kHz*1000.;
  140195. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140196. double nyq=vi->rate/2.;
  140197. long blocksize=ci->blocksizes[block]>>1;
  140198. if(freq>nyq)freq=nyq;
  140199. f->n=freq/nyq*blocksize;
  140200. if(res->limit_type){
  140201. if(ci->hi.managed)
  140202. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140203. else
  140204. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140205. if(freq>nyq)freq=nyq;
  140206. }
  140207. if(ci->residue_type[block]==2)
  140208. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140209. r->grouping;
  140210. else
  140211. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140212. r->grouping;
  140213. }
  140214. }
  140215. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140216. vorbis_mapping_template *maps){
  140217. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140218. int i,j,is=s,modes=2;
  140219. vorbis_info_mapping0 *map=maps[is].map;
  140220. vorbis_info_mode *mode=_mode_template;
  140221. vorbis_residue_template *res=maps[is].res;
  140222. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140223. for(i=0;i<modes;i++){
  140224. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140225. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140226. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140227. if(i>=ci->modes)ci->modes=i+1;
  140228. ci->map_type[i]=0;
  140229. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140230. if(i>=ci->maps)ci->maps=i+1;
  140231. for(j=0;j<map[i].submaps;j++)
  140232. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140233. ,res+map[i].residuesubmap[j]);
  140234. }
  140235. }
  140236. static double setting_to_approx_bitrate(vorbis_info *vi){
  140237. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140238. highlevel_encode_setup *hi=&ci->hi;
  140239. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140240. int is=hi->base_setting;
  140241. double ds=hi->base_setting-is;
  140242. int ch=vi->channels;
  140243. double *r=setup->rate_mapping;
  140244. if(r==NULL)
  140245. return(-1);
  140246. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140247. }
  140248. static void get_setup_template(vorbis_info *vi,
  140249. long ch,long srate,
  140250. double req,int q_or_bitrate){
  140251. int i=0,j;
  140252. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140253. highlevel_encode_setup *hi=&ci->hi;
  140254. if(q_or_bitrate)req/=ch;
  140255. while(setup_list[i]){
  140256. if(setup_list[i]->coupling_restriction==-1 ||
  140257. setup_list[i]->coupling_restriction==ch){
  140258. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140259. srate<=setup_list[i]->samplerate_max_restriction){
  140260. int mappings=setup_list[i]->mappings;
  140261. double *map=(q_or_bitrate?
  140262. setup_list[i]->rate_mapping:
  140263. setup_list[i]->quality_mapping);
  140264. if(req<map[0]){++i;continue;}
  140265. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140266. for(j=0;j<mappings;j++)
  140267. if(req>=map[j] && req<map[j+1])break;
  140268. hi->setup=setup_list[i];
  140269. if(j==mappings)
  140270. hi->base_setting=j-.001;
  140271. else{
  140272. float low=map[j];
  140273. float high=map[j+1];
  140274. float del=(req-low)/(high-low);
  140275. hi->base_setting=j+del;
  140276. }
  140277. return;
  140278. }
  140279. }
  140280. i++;
  140281. }
  140282. hi->setup=NULL;
  140283. }
  140284. int vorbis_encode_setup_init(vorbis_info *vi){
  140285. int i0=0,singleblock=0;
  140286. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140287. ve_setup_data_template *setup=NULL;
  140288. highlevel_encode_setup *hi=&ci->hi;
  140289. if(ci==NULL)return(OV_EINVAL);
  140290. if(!hi->impulse_block_p)i0=1;
  140291. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140292. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140293. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140294. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140295. setup=(ve_setup_data_template *)hi->setup;
  140296. if(setup==NULL)return(OV_EINVAL);
  140297. hi->set_in_stone=1;
  140298. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140299. setup->blocksize_short,
  140300. setup->blocksize_long);
  140301. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140302. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140303. setup->floor_books,
  140304. setup->floor_params,
  140305. setup->floor_short_mapping);
  140306. if(!singleblock)
  140307. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140308. setup->floor_books,
  140309. setup->floor_params,
  140310. setup->floor_long_mapping);
  140311. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140312. setup->global_params,
  140313. setup->global_mapping);
  140314. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140315. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140316. setup->psy_noise_normal_start[0],
  140317. setup->psy_noise_normal_partition[0],
  140318. setup->psy_noise_normal_thresh,
  140319. 0);
  140320. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140321. setup->psy_noise_normal_start[0],
  140322. setup->psy_noise_normal_partition[0],
  140323. setup->psy_noise_normal_thresh,
  140324. 1);
  140325. if(!singleblock){
  140326. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140327. setup->psy_noise_normal_start[1],
  140328. setup->psy_noise_normal_partition[1],
  140329. setup->psy_noise_normal_thresh,
  140330. 2);
  140331. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140332. setup->psy_noise_normal_start[1],
  140333. setup->psy_noise_normal_partition[1],
  140334. setup->psy_noise_normal_thresh,
  140335. 3);
  140336. }
  140337. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140338. setup->psy_tone_masteratt,
  140339. setup->psy_tone_0dB,
  140340. setup->psy_tone_adj_impulse);
  140341. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140342. setup->psy_tone_masteratt,
  140343. setup->psy_tone_0dB,
  140344. setup->psy_tone_adj_other);
  140345. if(!singleblock){
  140346. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140347. setup->psy_tone_masteratt,
  140348. setup->psy_tone_0dB,
  140349. setup->psy_tone_adj_other);
  140350. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140351. setup->psy_tone_masteratt,
  140352. setup->psy_tone_0dB,
  140353. setup->psy_tone_adj_long);
  140354. }
  140355. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140356. setup->psy_noise_compand,
  140357. setup->psy_noise_compand_short_mapping);
  140358. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140359. setup->psy_noise_compand,
  140360. setup->psy_noise_compand_short_mapping);
  140361. if(!singleblock){
  140362. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140363. setup->psy_noise_compand,
  140364. setup->psy_noise_compand_long_mapping);
  140365. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140366. setup->psy_noise_compand,
  140367. setup->psy_noise_compand_long_mapping);
  140368. }
  140369. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140370. setup->psy_tone_dBsuppress);
  140371. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140372. setup->psy_tone_dBsuppress);
  140373. if(!singleblock){
  140374. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140375. setup->psy_tone_dBsuppress);
  140376. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140377. setup->psy_tone_dBsuppress);
  140378. }
  140379. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140380. setup->psy_noise_dBsuppress,
  140381. setup->psy_noise_bias_impulse,
  140382. setup->psy_noiseguards,
  140383. (i0==0?hi->impulse_noisetune:0.));
  140384. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140385. setup->psy_noise_dBsuppress,
  140386. setup->psy_noise_bias_padding,
  140387. setup->psy_noiseguards,0.);
  140388. if(!singleblock){
  140389. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140390. setup->psy_noise_dBsuppress,
  140391. setup->psy_noise_bias_trans,
  140392. setup->psy_noiseguards,0.);
  140393. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140394. setup->psy_noise_dBsuppress,
  140395. setup->psy_noise_bias_long,
  140396. setup->psy_noiseguards,0.);
  140397. }
  140398. vorbis_encode_ath_setup(vi,0);
  140399. vorbis_encode_ath_setup(vi,1);
  140400. if(!singleblock){
  140401. vorbis_encode_ath_setup(vi,2);
  140402. vorbis_encode_ath_setup(vi,3);
  140403. }
  140404. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140405. if(hi->bitrate_av>0)
  140406. vi->bitrate_nominal=hi->bitrate_av;
  140407. else{
  140408. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140409. }
  140410. vi->bitrate_lower=hi->bitrate_min;
  140411. vi->bitrate_upper=hi->bitrate_max;
  140412. if(hi->bitrate_av)
  140413. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140414. else
  140415. vi->bitrate_window=0.;
  140416. if(hi->managed){
  140417. ci->bi.avg_rate=hi->bitrate_av;
  140418. ci->bi.min_rate=hi->bitrate_min;
  140419. ci->bi.max_rate=hi->bitrate_max;
  140420. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140421. ci->bi.reservoir_bias=
  140422. hi->bitrate_reservoir_bias;
  140423. ci->bi.slew_damp=hi->bitrate_av_damp;
  140424. }
  140425. return(0);
  140426. }
  140427. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140428. long channels,
  140429. long rate){
  140430. int ret=0,i,is;
  140431. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140432. highlevel_encode_setup *hi=&ci->hi;
  140433. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140434. double ds;
  140435. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140436. if(ret)return(ret);
  140437. is=hi->base_setting;
  140438. ds=hi->base_setting-is;
  140439. hi->short_setting=hi->base_setting;
  140440. hi->long_setting=hi->base_setting;
  140441. hi->managed=0;
  140442. hi->impulse_block_p=1;
  140443. hi->noise_normalize_p=1;
  140444. hi->stereo_point_setting=hi->base_setting;
  140445. hi->lowpass_kHz=
  140446. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140447. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140448. setup->psy_ath_float[is+1]*ds;
  140449. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140450. setup->psy_ath_abs[is+1]*ds;
  140451. hi->amplitude_track_dBpersec=-6.;
  140452. hi->trigger_setting=hi->base_setting;
  140453. for(i=0;i<4;i++){
  140454. hi->block[i].tone_mask_setting=hi->base_setting;
  140455. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140456. hi->block[i].noise_bias_setting=hi->base_setting;
  140457. hi->block[i].noise_compand_setting=hi->base_setting;
  140458. }
  140459. return(ret);
  140460. }
  140461. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140462. long channels,
  140463. long rate,
  140464. float quality){
  140465. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140466. highlevel_encode_setup *hi=&ci->hi;
  140467. quality+=.0000001;
  140468. if(quality>=1.)quality=.9999;
  140469. get_setup_template(vi,channels,rate,quality,0);
  140470. if(!hi->setup)return OV_EIMPL;
  140471. return vorbis_encode_setup_setting(vi,channels,rate);
  140472. }
  140473. int vorbis_encode_init_vbr(vorbis_info *vi,
  140474. long channels,
  140475. long rate,
  140476. float base_quality /* 0. to 1. */
  140477. ){
  140478. int ret=0;
  140479. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140480. if(ret){
  140481. vorbis_info_clear(vi);
  140482. return ret;
  140483. }
  140484. ret=vorbis_encode_setup_init(vi);
  140485. if(ret)
  140486. vorbis_info_clear(vi);
  140487. return(ret);
  140488. }
  140489. int vorbis_encode_setup_managed(vorbis_info *vi,
  140490. long channels,
  140491. long rate,
  140492. long max_bitrate,
  140493. long nominal_bitrate,
  140494. long min_bitrate){
  140495. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140496. highlevel_encode_setup *hi=&ci->hi;
  140497. double tnominal=nominal_bitrate;
  140498. int ret=0;
  140499. if(nominal_bitrate<=0.){
  140500. if(max_bitrate>0.){
  140501. if(min_bitrate>0.)
  140502. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140503. else
  140504. nominal_bitrate=max_bitrate*.875;
  140505. }else{
  140506. if(min_bitrate>0.){
  140507. nominal_bitrate=min_bitrate;
  140508. }else{
  140509. return(OV_EINVAL);
  140510. }
  140511. }
  140512. }
  140513. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140514. if(!hi->setup)return OV_EIMPL;
  140515. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140516. if(ret){
  140517. vorbis_info_clear(vi);
  140518. return ret;
  140519. }
  140520. hi->managed=1;
  140521. hi->bitrate_min=min_bitrate;
  140522. hi->bitrate_max=max_bitrate;
  140523. hi->bitrate_av=tnominal;
  140524. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140525. hi->bitrate_reservoir=nominal_bitrate*2;
  140526. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140527. return(ret);
  140528. }
  140529. int vorbis_encode_init(vorbis_info *vi,
  140530. long channels,
  140531. long rate,
  140532. long max_bitrate,
  140533. long nominal_bitrate,
  140534. long min_bitrate){
  140535. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140536. max_bitrate,
  140537. nominal_bitrate,
  140538. min_bitrate);
  140539. if(ret){
  140540. vorbis_info_clear(vi);
  140541. return(ret);
  140542. }
  140543. ret=vorbis_encode_setup_init(vi);
  140544. if(ret)
  140545. vorbis_info_clear(vi);
  140546. return(ret);
  140547. }
  140548. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140549. if(vi){
  140550. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140551. highlevel_encode_setup *hi=&ci->hi;
  140552. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140553. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140554. switch(number){
  140555. case OV_ECTL_RATEMANAGE_GET:
  140556. {
  140557. struct ovectl_ratemanage_arg *ai=
  140558. (struct ovectl_ratemanage_arg *)arg;
  140559. ai->management_active=hi->managed;
  140560. ai->bitrate_hard_window=ai->bitrate_av_window=
  140561. (double)hi->bitrate_reservoir/vi->rate;
  140562. ai->bitrate_av_window_center=1.;
  140563. ai->bitrate_hard_min=hi->bitrate_min;
  140564. ai->bitrate_hard_max=hi->bitrate_max;
  140565. ai->bitrate_av_lo=hi->bitrate_av;
  140566. ai->bitrate_av_hi=hi->bitrate_av;
  140567. }
  140568. return(0);
  140569. case OV_ECTL_RATEMANAGE_SET:
  140570. {
  140571. struct ovectl_ratemanage_arg *ai=
  140572. (struct ovectl_ratemanage_arg *)arg;
  140573. if(ai==NULL){
  140574. hi->managed=0;
  140575. }else{
  140576. hi->managed=ai->management_active;
  140577. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140578. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140579. }
  140580. }
  140581. return 0;
  140582. case OV_ECTL_RATEMANAGE_AVG:
  140583. {
  140584. struct ovectl_ratemanage_arg *ai=
  140585. (struct ovectl_ratemanage_arg *)arg;
  140586. if(ai==NULL){
  140587. hi->bitrate_av=0;
  140588. }else{
  140589. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140590. }
  140591. }
  140592. return(0);
  140593. case OV_ECTL_RATEMANAGE_HARD:
  140594. {
  140595. struct ovectl_ratemanage_arg *ai=
  140596. (struct ovectl_ratemanage_arg *)arg;
  140597. if(ai==NULL){
  140598. hi->bitrate_min=0;
  140599. hi->bitrate_max=0;
  140600. }else{
  140601. hi->bitrate_min=ai->bitrate_hard_min;
  140602. hi->bitrate_max=ai->bitrate_hard_max;
  140603. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140604. (hi->bitrate_max+hi->bitrate_min)*.5;
  140605. }
  140606. if(hi->bitrate_reservoir<128.)
  140607. hi->bitrate_reservoir=128.;
  140608. }
  140609. return(0);
  140610. case OV_ECTL_RATEMANAGE2_GET:
  140611. {
  140612. struct ovectl_ratemanage2_arg *ai=
  140613. (struct ovectl_ratemanage2_arg *)arg;
  140614. if(ai==NULL)return OV_EINVAL;
  140615. ai->management_active=hi->managed;
  140616. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140617. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140618. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140619. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140620. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140621. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140622. }
  140623. return (0);
  140624. case OV_ECTL_RATEMANAGE2_SET:
  140625. {
  140626. struct ovectl_ratemanage2_arg *ai=
  140627. (struct ovectl_ratemanage2_arg *)arg;
  140628. if(ai==NULL){
  140629. hi->managed=0;
  140630. }else{
  140631. if(ai->bitrate_limit_min_kbps>0 &&
  140632. ai->bitrate_average_kbps>0 &&
  140633. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140634. return OV_EINVAL;
  140635. if(ai->bitrate_limit_max_kbps>0 &&
  140636. ai->bitrate_average_kbps>0 &&
  140637. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140638. return OV_EINVAL;
  140639. if(ai->bitrate_limit_min_kbps>0 &&
  140640. ai->bitrate_limit_max_kbps>0 &&
  140641. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140642. return OV_EINVAL;
  140643. if(ai->bitrate_average_damping <= 0.)
  140644. return OV_EINVAL;
  140645. if(ai->bitrate_limit_reservoir_bits < 0)
  140646. return OV_EINVAL;
  140647. if(ai->bitrate_limit_reservoir_bias < 0.)
  140648. return OV_EINVAL;
  140649. if(ai->bitrate_limit_reservoir_bias > 1.)
  140650. return OV_EINVAL;
  140651. hi->managed=ai->management_active;
  140652. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140653. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140654. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140655. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140656. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140657. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140658. }
  140659. }
  140660. return 0;
  140661. case OV_ECTL_LOWPASS_GET:
  140662. {
  140663. double *farg=(double *)arg;
  140664. *farg=hi->lowpass_kHz;
  140665. }
  140666. return(0);
  140667. case OV_ECTL_LOWPASS_SET:
  140668. {
  140669. double *farg=(double *)arg;
  140670. hi->lowpass_kHz=*farg;
  140671. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140672. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140673. }
  140674. return(0);
  140675. case OV_ECTL_IBLOCK_GET:
  140676. {
  140677. double *farg=(double *)arg;
  140678. *farg=hi->impulse_noisetune;
  140679. }
  140680. return(0);
  140681. case OV_ECTL_IBLOCK_SET:
  140682. {
  140683. double *farg=(double *)arg;
  140684. hi->impulse_noisetune=*farg;
  140685. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140686. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140687. }
  140688. return(0);
  140689. }
  140690. return(OV_EIMPL);
  140691. }
  140692. return(OV_EINVAL);
  140693. }
  140694. #endif
  140695. /*** End of inlined file: vorbisenc.c ***/
  140696. /*** Start of inlined file: vorbisfile.c ***/
  140697. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140698. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140699. // tasks..
  140700. #if JUCE_MSVC
  140701. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140702. #endif
  140703. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140704. #if JUCE_USE_OGGVORBIS
  140705. #include <stdlib.h>
  140706. #include <stdio.h>
  140707. #include <errno.h>
  140708. #include <string.h>
  140709. #include <math.h>
  140710. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140711. over 8k gets what they deserve */
  140712. static long _get_data(OggVorbis_File *vf){
  140713. errno=0;
  140714. if(vf->datasource){
  140715. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140716. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140717. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140718. if(bytes==0 && errno)return(-1);
  140719. return(bytes);
  140720. }else
  140721. return(0);
  140722. }
  140723. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140724. if(vf->datasource){
  140725. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140726. vf->offset=offset;
  140727. ogg_sync_reset(&vf->oy);
  140728. }else{
  140729. return;
  140730. }
  140731. }
  140732. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140733. ogg_int64_t boundary){
  140734. if(boundary>0)boundary+=vf->offset;
  140735. while(1){
  140736. long more;
  140737. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140738. more=ogg_sync_pageseek(&vf->oy,og);
  140739. if(more<0){
  140740. vf->offset-=more;
  140741. }else{
  140742. if(more==0){
  140743. if(!boundary)return(OV_FALSE);
  140744. {
  140745. long ret=_get_data(vf);
  140746. if(ret==0)return(OV_EOF);
  140747. if(ret<0)return(OV_EREAD);
  140748. }
  140749. }else{
  140750. ogg_int64_t ret=vf->offset;
  140751. vf->offset+=more;
  140752. return(ret);
  140753. }
  140754. }
  140755. }
  140756. }
  140757. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140758. ogg_int64_t begin=vf->offset;
  140759. ogg_int64_t end=begin;
  140760. ogg_int64_t ret;
  140761. ogg_int64_t offset=-1;
  140762. while(offset==-1){
  140763. begin-=CHUNKSIZE;
  140764. if(begin<0)
  140765. begin=0;
  140766. _seek_helper(vf,begin);
  140767. while(vf->offset<end){
  140768. ret=_get_next_page(vf,og,end-vf->offset);
  140769. if(ret==OV_EREAD)return(OV_EREAD);
  140770. if(ret<0){
  140771. break;
  140772. }else{
  140773. offset=ret;
  140774. }
  140775. }
  140776. }
  140777. _seek_helper(vf,offset);
  140778. ret=_get_next_page(vf,og,CHUNKSIZE);
  140779. if(ret<0)
  140780. return(OV_EFAULT);
  140781. return(offset);
  140782. }
  140783. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140784. ogg_int64_t begin,
  140785. ogg_int64_t searched,
  140786. ogg_int64_t end,
  140787. long currentno,
  140788. long m){
  140789. ogg_int64_t endsearched=end;
  140790. ogg_int64_t next=end;
  140791. ogg_page og;
  140792. ogg_int64_t ret;
  140793. while(searched<endsearched){
  140794. ogg_int64_t bisect;
  140795. if(endsearched-searched<CHUNKSIZE){
  140796. bisect=searched;
  140797. }else{
  140798. bisect=(searched+endsearched)/2;
  140799. }
  140800. _seek_helper(vf,bisect);
  140801. ret=_get_next_page(vf,&og,-1);
  140802. if(ret==OV_EREAD)return(OV_EREAD);
  140803. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140804. endsearched=bisect;
  140805. if(ret>=0)next=ret;
  140806. }else{
  140807. searched=ret+og.header_len+og.body_len;
  140808. }
  140809. }
  140810. _seek_helper(vf,next);
  140811. ret=_get_next_page(vf,&og,-1);
  140812. if(ret==OV_EREAD)return(OV_EREAD);
  140813. if(searched>=end || ret<0){
  140814. vf->links=m+1;
  140815. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140816. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140817. vf->offsets[m+1]=searched;
  140818. }else{
  140819. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140820. end,ogg_page_serialno(&og),m+1);
  140821. if(ret==OV_EREAD)return(OV_EREAD);
  140822. }
  140823. vf->offsets[m]=begin;
  140824. vf->serialnos[m]=currentno;
  140825. return(0);
  140826. }
  140827. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140828. long *serialno,ogg_page *og_ptr){
  140829. ogg_page og;
  140830. ogg_packet op;
  140831. int i,ret;
  140832. if(!og_ptr){
  140833. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140834. if(llret==OV_EREAD)return(OV_EREAD);
  140835. if(llret<0)return OV_ENOTVORBIS;
  140836. og_ptr=&og;
  140837. }
  140838. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140839. if(serialno)*serialno=vf->os.serialno;
  140840. vf->ready_state=STREAMSET;
  140841. vorbis_info_init(vi);
  140842. vorbis_comment_init(vc);
  140843. i=0;
  140844. while(i<3){
  140845. ogg_stream_pagein(&vf->os,og_ptr);
  140846. while(i<3){
  140847. int result=ogg_stream_packetout(&vf->os,&op);
  140848. if(result==0)break;
  140849. if(result==-1){
  140850. ret=OV_EBADHEADER;
  140851. goto bail_header;
  140852. }
  140853. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140854. goto bail_header;
  140855. }
  140856. i++;
  140857. }
  140858. if(i<3)
  140859. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140860. ret=OV_EBADHEADER;
  140861. goto bail_header;
  140862. }
  140863. }
  140864. return 0;
  140865. bail_header:
  140866. vorbis_info_clear(vi);
  140867. vorbis_comment_clear(vc);
  140868. vf->ready_state=OPENED;
  140869. return ret;
  140870. }
  140871. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140872. ogg_page og;
  140873. int i;
  140874. ogg_int64_t ret;
  140875. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140876. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140877. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140878. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140879. for(i=0;i<vf->links;i++){
  140880. if(i==0){
  140881. vf->dataoffsets[i]=dataoffset;
  140882. _seek_helper(vf,dataoffset);
  140883. }else{
  140884. _seek_helper(vf,vf->offsets[i]);
  140885. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140886. vf->dataoffsets[i]=-1;
  140887. }else{
  140888. vf->dataoffsets[i]=vf->offset;
  140889. }
  140890. }
  140891. if(vf->dataoffsets[i]!=-1){
  140892. ogg_int64_t accumulated=0;
  140893. long lastblock=-1;
  140894. int result;
  140895. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140896. while(1){
  140897. ogg_packet op;
  140898. ret=_get_next_page(vf,&og,-1);
  140899. if(ret<0)
  140900. break;
  140901. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140902. break;
  140903. ogg_stream_pagein(&vf->os,&og);
  140904. while((result=ogg_stream_packetout(&vf->os,&op))){
  140905. if(result>0){ /* ignore holes */
  140906. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140907. if(lastblock!=-1)
  140908. accumulated+=(lastblock+thisblock)>>2;
  140909. lastblock=thisblock;
  140910. }
  140911. }
  140912. if(ogg_page_granulepos(&og)!=-1){
  140913. accumulated= ogg_page_granulepos(&og)-accumulated;
  140914. break;
  140915. }
  140916. }
  140917. if(accumulated<0)accumulated=0;
  140918. vf->pcmlengths[i*2]=accumulated;
  140919. }
  140920. {
  140921. ogg_int64_t end=vf->offsets[i+1];
  140922. _seek_helper(vf,end);
  140923. while(1){
  140924. ret=_get_prev_page(vf,&og);
  140925. if(ret<0){
  140926. vorbis_info_clear(vf->vi+i);
  140927. vorbis_comment_clear(vf->vc+i);
  140928. break;
  140929. }
  140930. if(ogg_page_granulepos(&og)!=-1){
  140931. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  140932. break;
  140933. }
  140934. vf->offset=ret;
  140935. }
  140936. }
  140937. }
  140938. }
  140939. static int _make_decode_ready(OggVorbis_File *vf){
  140940. if(vf->ready_state>STREAMSET)return 0;
  140941. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  140942. if(vf->seekable){
  140943. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  140944. return OV_EBADLINK;
  140945. }else{
  140946. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  140947. return OV_EBADLINK;
  140948. }
  140949. vorbis_block_init(&vf->vd,&vf->vb);
  140950. vf->ready_state=INITSET;
  140951. vf->bittrack=0.f;
  140952. vf->samptrack=0.f;
  140953. return 0;
  140954. }
  140955. static int _open_seekable2(OggVorbis_File *vf){
  140956. long serialno=vf->current_serialno;
  140957. ogg_int64_t dataoffset=vf->offset, end;
  140958. ogg_page og;
  140959. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  140960. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  140961. end=_get_prev_page(vf,&og);
  140962. if(end<0)return(end);
  140963. if(ogg_page_serialno(&og)!=serialno){
  140964. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  140965. }else{
  140966. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  140967. }
  140968. _prefetch_all_headers(vf,dataoffset);
  140969. return(ov_raw_seek(vf,0));
  140970. }
  140971. static void _decode_clear(OggVorbis_File *vf){
  140972. vorbis_dsp_clear(&vf->vd);
  140973. vorbis_block_clear(&vf->vb);
  140974. vf->ready_state=OPENED;
  140975. }
  140976. static int _fetch_and_process_packet(OggVorbis_File *vf,
  140977. ogg_packet *op_in,
  140978. int readp,
  140979. int spanp){
  140980. ogg_page og;
  140981. while(1){
  140982. if(vf->ready_state==INITSET){
  140983. while(1) {
  140984. ogg_packet op;
  140985. ogg_packet *op_ptr=(op_in?op_in:&op);
  140986. int result=ogg_stream_packetout(&vf->os,op_ptr);
  140987. ogg_int64_t granulepos;
  140988. op_in=NULL;
  140989. if(result==-1)return(OV_HOLE); /* hole in the data. */
  140990. if(result>0){
  140991. granulepos=op_ptr->granulepos;
  140992. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  140993. header handling. The
  140994. header packets aren't
  140995. audio, so if/when we
  140996. submit them,
  140997. vorbis_synthesis will
  140998. reject them */
  140999. {
  141000. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141001. if(oldsamples)return(OV_EFAULT);
  141002. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141003. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141004. vf->bittrack+=op_ptr->bytes*8;
  141005. }
  141006. if(granulepos!=-1 && !op_ptr->e_o_s){
  141007. int link=(vf->seekable?vf->current_link:0);
  141008. int i,samples;
  141009. if(vf->seekable && link>0)
  141010. granulepos-=vf->pcmlengths[link*2];
  141011. if(granulepos<0)granulepos=0; /* actually, this
  141012. shouldn't be possible
  141013. here unless the stream
  141014. is very broken */
  141015. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141016. granulepos-=samples;
  141017. for(i=0;i<link;i++)
  141018. granulepos+=vf->pcmlengths[i*2+1];
  141019. vf->pcm_offset=granulepos;
  141020. }
  141021. return(1);
  141022. }
  141023. }
  141024. else
  141025. break;
  141026. }
  141027. }
  141028. if(vf->ready_state>=OPENED){
  141029. ogg_int64_t ret;
  141030. if(!readp)return(0);
  141031. if((ret=_get_next_page(vf,&og,-1))<0){
  141032. return(OV_EOF); /* eof.
  141033. leave unitialized */
  141034. }
  141035. vf->bittrack+=og.header_len*8;
  141036. if(vf->ready_state==INITSET){
  141037. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141038. if(!spanp)
  141039. return(OV_EOF);
  141040. _decode_clear(vf);
  141041. if(!vf->seekable){
  141042. vorbis_info_clear(vf->vi);
  141043. vorbis_comment_clear(vf->vc);
  141044. }
  141045. }
  141046. }
  141047. }
  141048. if(vf->ready_state!=INITSET){
  141049. int link;
  141050. if(vf->ready_state<STREAMSET){
  141051. if(vf->seekable){
  141052. vf->current_serialno=ogg_page_serialno(&og);
  141053. for(link=0;link<vf->links;link++)
  141054. if(vf->serialnos[link]==vf->current_serialno)break;
  141055. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141056. stream. error out,
  141057. leave machine
  141058. uninitialized */
  141059. vf->current_link=link;
  141060. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141061. vf->ready_state=STREAMSET;
  141062. }else{
  141063. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141064. if(ret)return(ret);
  141065. vf->current_link++;
  141066. link=0;
  141067. }
  141068. }
  141069. {
  141070. int ret=_make_decode_ready(vf);
  141071. if(ret<0)return ret;
  141072. }
  141073. }
  141074. ogg_stream_pagein(&vf->os,&og);
  141075. }
  141076. }
  141077. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141078. if(f==NULL)return(-1);
  141079. return fseek(f,off,whence);
  141080. }
  141081. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141082. long ibytes, ov_callbacks callbacks){
  141083. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141084. int ret;
  141085. memset(vf,0,sizeof(*vf));
  141086. vf->datasource=f;
  141087. vf->callbacks = callbacks;
  141088. ogg_sync_init(&vf->oy);
  141089. if(initial){
  141090. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141091. memcpy(buffer,initial,ibytes);
  141092. ogg_sync_wrote(&vf->oy,ibytes);
  141093. }
  141094. if(offsettest!=-1)vf->seekable=1;
  141095. vf->links=1;
  141096. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141097. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141098. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141099. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141100. vf->datasource=NULL;
  141101. ov_clear(vf);
  141102. }else
  141103. vf->ready_state=PARTOPEN;
  141104. return(ret);
  141105. }
  141106. static int _ov_open2(OggVorbis_File *vf){
  141107. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141108. vf->ready_state=OPENED;
  141109. if(vf->seekable){
  141110. int ret=_open_seekable2(vf);
  141111. if(ret){
  141112. vf->datasource=NULL;
  141113. ov_clear(vf);
  141114. }
  141115. return(ret);
  141116. }else
  141117. vf->ready_state=STREAMSET;
  141118. return 0;
  141119. }
  141120. int ov_clear(OggVorbis_File *vf){
  141121. if(vf){
  141122. vorbis_block_clear(&vf->vb);
  141123. vorbis_dsp_clear(&vf->vd);
  141124. ogg_stream_clear(&vf->os);
  141125. if(vf->vi && vf->links){
  141126. int i;
  141127. for(i=0;i<vf->links;i++){
  141128. vorbis_info_clear(vf->vi+i);
  141129. vorbis_comment_clear(vf->vc+i);
  141130. }
  141131. _ogg_free(vf->vi);
  141132. _ogg_free(vf->vc);
  141133. }
  141134. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141135. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141136. if(vf->serialnos)_ogg_free(vf->serialnos);
  141137. if(vf->offsets)_ogg_free(vf->offsets);
  141138. ogg_sync_clear(&vf->oy);
  141139. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141140. memset(vf,0,sizeof(*vf));
  141141. }
  141142. #ifdef DEBUG_LEAKS
  141143. _VDBG_dump();
  141144. #endif
  141145. return(0);
  141146. }
  141147. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141148. ov_callbacks callbacks){
  141149. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141150. if(ret)return ret;
  141151. return _ov_open2(vf);
  141152. }
  141153. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141154. ov_callbacks callbacks = {
  141155. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141156. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141157. (int (*)(void *)) fclose,
  141158. (long (*)(void *)) ftell
  141159. };
  141160. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141161. }
  141162. int ov_halfrate(OggVorbis_File *vf,int flag){
  141163. int i;
  141164. if(vf->vi==NULL)return OV_EINVAL;
  141165. if(!vf->seekable)return OV_EINVAL;
  141166. if(vf->ready_state>=STREAMSET)
  141167. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141168. will be able to swap this on the fly, but
  141169. for now dumping the decode machine is needed
  141170. to reinit the MDCT lookups. 1.1 libvorbis
  141171. is planned to be able to switch on the fly */
  141172. for(i=0;i<vf->links;i++){
  141173. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141174. ov_halfrate(vf,0);
  141175. return OV_EINVAL;
  141176. }
  141177. }
  141178. return 0;
  141179. }
  141180. int ov_halfrate_p(OggVorbis_File *vf){
  141181. if(vf->vi==NULL)return OV_EINVAL;
  141182. return vorbis_synthesis_halfrate_p(vf->vi);
  141183. }
  141184. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141185. ov_callbacks callbacks)
  141186. {
  141187. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141188. }
  141189. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141190. ov_callbacks callbacks = {
  141191. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141192. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141193. (int (*)(void *)) fclose,
  141194. (long (*)(void *)) ftell
  141195. };
  141196. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141197. }
  141198. int ov_test_open(OggVorbis_File *vf){
  141199. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141200. return _ov_open2(vf);
  141201. }
  141202. long ov_streams(OggVorbis_File *vf){
  141203. return vf->links;
  141204. }
  141205. long ov_seekable(OggVorbis_File *vf){
  141206. return vf->seekable;
  141207. }
  141208. long ov_bitrate(OggVorbis_File *vf,int i){
  141209. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141210. if(i>=vf->links)return(OV_EINVAL);
  141211. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141212. if(i<0){
  141213. ogg_int64_t bits=0;
  141214. int i;
  141215. float br;
  141216. for(i=0;i<vf->links;i++)
  141217. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141218. br = bits/ov_time_total(vf,-1);
  141219. return(rint(br));
  141220. }else{
  141221. if(vf->seekable){
  141222. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141223. }else{
  141224. if(vf->vi[i].bitrate_nominal>0){
  141225. return vf->vi[i].bitrate_nominal;
  141226. }else{
  141227. if(vf->vi[i].bitrate_upper>0){
  141228. if(vf->vi[i].bitrate_lower>0){
  141229. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141230. }else{
  141231. return vf->vi[i].bitrate_upper;
  141232. }
  141233. }
  141234. return(OV_FALSE);
  141235. }
  141236. }
  141237. }
  141238. }
  141239. long ov_bitrate_instant(OggVorbis_File *vf){
  141240. int link=(vf->seekable?vf->current_link:0);
  141241. long ret;
  141242. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141243. if(vf->samptrack==0)return(OV_FALSE);
  141244. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141245. vf->bittrack=0.f;
  141246. vf->samptrack=0.f;
  141247. return(ret);
  141248. }
  141249. long ov_serialnumber(OggVorbis_File *vf,int i){
  141250. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141251. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141252. if(i<0){
  141253. return(vf->current_serialno);
  141254. }else{
  141255. return(vf->serialnos[i]);
  141256. }
  141257. }
  141258. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141259. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141260. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141261. if(i<0){
  141262. ogg_int64_t acc=0;
  141263. int i;
  141264. for(i=0;i<vf->links;i++)
  141265. acc+=ov_raw_total(vf,i);
  141266. return(acc);
  141267. }else{
  141268. return(vf->offsets[i+1]-vf->offsets[i]);
  141269. }
  141270. }
  141271. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141272. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141273. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141274. if(i<0){
  141275. ogg_int64_t acc=0;
  141276. int i;
  141277. for(i=0;i<vf->links;i++)
  141278. acc+=ov_pcm_total(vf,i);
  141279. return(acc);
  141280. }else{
  141281. return(vf->pcmlengths[i*2+1]);
  141282. }
  141283. }
  141284. double ov_time_total(OggVorbis_File *vf,int i){
  141285. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141286. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141287. if(i<0){
  141288. double acc=0;
  141289. int i;
  141290. for(i=0;i<vf->links;i++)
  141291. acc+=ov_time_total(vf,i);
  141292. return(acc);
  141293. }else{
  141294. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141295. }
  141296. }
  141297. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141298. ogg_stream_state work_os;
  141299. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141300. if(!vf->seekable)
  141301. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141302. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141303. vf->pcm_offset=-1;
  141304. ogg_stream_reset_serialno(&vf->os,
  141305. vf->current_serialno); /* must set serialno */
  141306. vorbis_synthesis_restart(&vf->vd);
  141307. _seek_helper(vf,pos);
  141308. {
  141309. ogg_page og;
  141310. ogg_packet op;
  141311. int lastblock=0;
  141312. int accblock=0;
  141313. int thisblock;
  141314. int eosflag;
  141315. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141316. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141317. return from not necessarily
  141318. starting from the beginning */
  141319. while(1){
  141320. if(vf->ready_state>=STREAMSET){
  141321. int result=ogg_stream_packetout(&work_os,&op);
  141322. if(result>0){
  141323. if(vf->vi[vf->current_link].codec_setup){
  141324. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141325. if(thisblock<0){
  141326. ogg_stream_packetout(&vf->os,NULL);
  141327. thisblock=0;
  141328. }else{
  141329. if(eosflag)
  141330. ogg_stream_packetout(&vf->os,NULL);
  141331. else
  141332. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141333. }
  141334. if(op.granulepos!=-1){
  141335. int i,link=vf->current_link;
  141336. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141337. if(granulepos<0)granulepos=0;
  141338. for(i=0;i<link;i++)
  141339. granulepos+=vf->pcmlengths[i*2+1];
  141340. vf->pcm_offset=granulepos-accblock;
  141341. break;
  141342. }
  141343. lastblock=thisblock;
  141344. continue;
  141345. }else
  141346. ogg_stream_packetout(&vf->os,NULL);
  141347. }
  141348. }
  141349. if(!lastblock){
  141350. if(_get_next_page(vf,&og,-1)<0){
  141351. vf->pcm_offset=ov_pcm_total(vf,-1);
  141352. break;
  141353. }
  141354. }else{
  141355. vf->pcm_offset=-1;
  141356. break;
  141357. }
  141358. if(vf->ready_state>=STREAMSET)
  141359. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141360. _decode_clear(vf); /* clear out stream state */
  141361. ogg_stream_clear(&work_os);
  141362. }
  141363. if(vf->ready_state<STREAMSET){
  141364. int link;
  141365. vf->current_serialno=ogg_page_serialno(&og);
  141366. for(link=0;link<vf->links;link++)
  141367. if(vf->serialnos[link]==vf->current_serialno)break;
  141368. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141369. error out, leave
  141370. machine uninitialized */
  141371. vf->current_link=link;
  141372. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141373. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141374. vf->ready_state=STREAMSET;
  141375. }
  141376. ogg_stream_pagein(&vf->os,&og);
  141377. ogg_stream_pagein(&work_os,&og);
  141378. eosflag=ogg_page_eos(&og);
  141379. }
  141380. }
  141381. ogg_stream_clear(&work_os);
  141382. vf->bittrack=0.f;
  141383. vf->samptrack=0.f;
  141384. return(0);
  141385. seek_error:
  141386. vf->pcm_offset=-1;
  141387. ogg_stream_clear(&work_os);
  141388. _decode_clear(vf);
  141389. return OV_EBADLINK;
  141390. }
  141391. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141392. int link=-1;
  141393. ogg_int64_t result=0;
  141394. ogg_int64_t total=ov_pcm_total(vf,-1);
  141395. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141396. if(!vf->seekable)return(OV_ENOSEEK);
  141397. if(pos<0 || pos>total)return(OV_EINVAL);
  141398. for(link=vf->links-1;link>=0;link--){
  141399. total-=vf->pcmlengths[link*2+1];
  141400. if(pos>=total)break;
  141401. }
  141402. {
  141403. ogg_int64_t end=vf->offsets[link+1];
  141404. ogg_int64_t begin=vf->offsets[link];
  141405. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141406. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141407. ogg_int64_t target=pos-total+begintime;
  141408. ogg_int64_t best=begin;
  141409. ogg_page og;
  141410. while(begin<end){
  141411. ogg_int64_t bisect;
  141412. if(end-begin<CHUNKSIZE){
  141413. bisect=begin;
  141414. }else{
  141415. bisect=begin +
  141416. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141417. if(bisect<=begin)
  141418. bisect=begin+1;
  141419. }
  141420. _seek_helper(vf,bisect);
  141421. while(begin<end){
  141422. result=_get_next_page(vf,&og,end-vf->offset);
  141423. if(result==OV_EREAD) goto seek_error;
  141424. if(result<0){
  141425. if(bisect<=begin+1)
  141426. end=begin; /* found it */
  141427. else{
  141428. if(bisect==0) goto seek_error;
  141429. bisect-=CHUNKSIZE;
  141430. if(bisect<=begin)bisect=begin+1;
  141431. _seek_helper(vf,bisect);
  141432. }
  141433. }else{
  141434. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141435. if(granulepos==-1)continue;
  141436. if(granulepos<target){
  141437. best=result; /* raw offset of packet with granulepos */
  141438. begin=vf->offset; /* raw offset of next page */
  141439. begintime=granulepos;
  141440. if(target-begintime>44100)break;
  141441. bisect=begin; /* *not* begin + 1 */
  141442. }else{
  141443. if(bisect<=begin+1)
  141444. end=begin; /* found it */
  141445. else{
  141446. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141447. end=result;
  141448. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141449. if(bisect<=begin)bisect=begin+1;
  141450. _seek_helper(vf,bisect);
  141451. }else{
  141452. end=result;
  141453. endtime=granulepos;
  141454. break;
  141455. }
  141456. }
  141457. }
  141458. }
  141459. }
  141460. }
  141461. {
  141462. ogg_page og;
  141463. ogg_packet op;
  141464. _seek_helper(vf,best);
  141465. vf->pcm_offset=-1;
  141466. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141467. if(link!=vf->current_link){
  141468. _decode_clear(vf);
  141469. vf->current_link=link;
  141470. vf->current_serialno=ogg_page_serialno(&og);
  141471. vf->ready_state=STREAMSET;
  141472. }else{
  141473. vorbis_synthesis_restart(&vf->vd);
  141474. }
  141475. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141476. ogg_stream_pagein(&vf->os,&og);
  141477. while(1){
  141478. result=ogg_stream_packetpeek(&vf->os,&op);
  141479. if(result==0){
  141480. _seek_helper(vf,best);
  141481. while(1){
  141482. result=_get_prev_page(vf,&og);
  141483. if(result<0) goto seek_error;
  141484. if(ogg_page_granulepos(&og)>-1 ||
  141485. !ogg_page_continued(&og)){
  141486. return ov_raw_seek(vf,result);
  141487. }
  141488. vf->offset=result;
  141489. }
  141490. }
  141491. if(result<0){
  141492. result = OV_EBADPACKET;
  141493. goto seek_error;
  141494. }
  141495. if(op.granulepos!=-1){
  141496. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141497. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141498. vf->pcm_offset+=total;
  141499. break;
  141500. }else
  141501. result=ogg_stream_packetout(&vf->os,NULL);
  141502. }
  141503. }
  141504. }
  141505. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141506. result=OV_EFAULT;
  141507. goto seek_error;
  141508. }
  141509. vf->bittrack=0.f;
  141510. vf->samptrack=0.f;
  141511. return(0);
  141512. seek_error:
  141513. vf->pcm_offset=-1;
  141514. _decode_clear(vf);
  141515. return (int)result;
  141516. }
  141517. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141518. int thisblock,lastblock=0;
  141519. int ret=ov_pcm_seek_page(vf,pos);
  141520. if(ret<0)return(ret);
  141521. if((ret=_make_decode_ready(vf)))return ret;
  141522. while(1){
  141523. ogg_packet op;
  141524. ogg_page og;
  141525. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141526. if(ret>0){
  141527. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141528. if(thisblock<0){
  141529. ogg_stream_packetout(&vf->os,NULL);
  141530. continue; /* non audio packet */
  141531. }
  141532. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141533. if(vf->pcm_offset+((thisblock+
  141534. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141535. ogg_stream_packetout(&vf->os,NULL);
  141536. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141537. only tracking, no
  141538. pcm_decode */
  141539. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141540. if(op.granulepos>-1){
  141541. int i;
  141542. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141543. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141544. for(i=0;i<vf->current_link;i++)
  141545. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141546. }
  141547. lastblock=thisblock;
  141548. }else{
  141549. if(ret<0 && ret!=OV_HOLE)break;
  141550. if(_get_next_page(vf,&og,-1)<0)break;
  141551. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141552. if(vf->ready_state<STREAMSET){
  141553. int link;
  141554. vf->current_serialno=ogg_page_serialno(&og);
  141555. for(link=0;link<vf->links;link++)
  141556. if(vf->serialnos[link]==vf->current_serialno)break;
  141557. if(link==vf->links)return(OV_EBADLINK);
  141558. vf->current_link=link;
  141559. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141560. vf->ready_state=STREAMSET;
  141561. ret=_make_decode_ready(vf);
  141562. if(ret)return ret;
  141563. lastblock=0;
  141564. }
  141565. ogg_stream_pagein(&vf->os,&og);
  141566. }
  141567. }
  141568. vf->bittrack=0.f;
  141569. vf->samptrack=0.f;
  141570. while(vf->pcm_offset<pos){
  141571. ogg_int64_t target=pos-vf->pcm_offset;
  141572. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141573. if(samples>target)samples=target;
  141574. vorbis_synthesis_read(&vf->vd,samples);
  141575. vf->pcm_offset+=samples;
  141576. if(samples<target)
  141577. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141578. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141579. }
  141580. return 0;
  141581. }
  141582. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141583. int link=-1;
  141584. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141585. double time_total=ov_time_total(vf,-1);
  141586. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141587. if(!vf->seekable)return(OV_ENOSEEK);
  141588. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141589. for(link=vf->links-1;link>=0;link--){
  141590. pcm_total-=vf->pcmlengths[link*2+1];
  141591. time_total-=ov_time_total(vf,link);
  141592. if(seconds>=time_total)break;
  141593. }
  141594. {
  141595. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141596. return(ov_pcm_seek(vf,target));
  141597. }
  141598. }
  141599. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141600. int link=-1;
  141601. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141602. double time_total=ov_time_total(vf,-1);
  141603. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141604. if(!vf->seekable)return(OV_ENOSEEK);
  141605. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141606. for(link=vf->links-1;link>=0;link--){
  141607. pcm_total-=vf->pcmlengths[link*2+1];
  141608. time_total-=ov_time_total(vf,link);
  141609. if(seconds>=time_total)break;
  141610. }
  141611. {
  141612. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141613. return(ov_pcm_seek_page(vf,target));
  141614. }
  141615. }
  141616. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141617. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141618. return(vf->offset);
  141619. }
  141620. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141621. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141622. return(vf->pcm_offset);
  141623. }
  141624. double ov_time_tell(OggVorbis_File *vf){
  141625. int link=0;
  141626. ogg_int64_t pcm_total=0;
  141627. double time_total=0.f;
  141628. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141629. if(vf->seekable){
  141630. pcm_total=ov_pcm_total(vf,-1);
  141631. time_total=ov_time_total(vf,-1);
  141632. for(link=vf->links-1;link>=0;link--){
  141633. pcm_total-=vf->pcmlengths[link*2+1];
  141634. time_total-=ov_time_total(vf,link);
  141635. if(vf->pcm_offset>=pcm_total)break;
  141636. }
  141637. }
  141638. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141639. }
  141640. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141641. if(vf->seekable){
  141642. if(link<0)
  141643. if(vf->ready_state>=STREAMSET)
  141644. return vf->vi+vf->current_link;
  141645. else
  141646. return vf->vi;
  141647. else
  141648. if(link>=vf->links)
  141649. return NULL;
  141650. else
  141651. return vf->vi+link;
  141652. }else{
  141653. return vf->vi;
  141654. }
  141655. }
  141656. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141657. if(vf->seekable){
  141658. if(link<0)
  141659. if(vf->ready_state>=STREAMSET)
  141660. return vf->vc+vf->current_link;
  141661. else
  141662. return vf->vc;
  141663. else
  141664. if(link>=vf->links)
  141665. return NULL;
  141666. else
  141667. return vf->vc+link;
  141668. }else{
  141669. return vf->vc;
  141670. }
  141671. }
  141672. static int host_is_big_endian() {
  141673. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141674. unsigned char *bytewise = (unsigned char *)&pattern;
  141675. if (bytewise[0] == 0xfe) return 1;
  141676. return 0;
  141677. }
  141678. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141679. int bigendianp,int word,int sgned,int *bitstream){
  141680. int i,j;
  141681. int host_endian = host_is_big_endian();
  141682. float **pcm;
  141683. long samples;
  141684. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141685. while(1){
  141686. if(vf->ready_state==INITSET){
  141687. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141688. if(samples)break;
  141689. }
  141690. {
  141691. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141692. if(ret==OV_EOF)
  141693. return(0);
  141694. if(ret<=0)
  141695. return(ret);
  141696. }
  141697. }
  141698. if(samples>0){
  141699. long channels=ov_info(vf,-1)->channels;
  141700. long bytespersample=word * channels;
  141701. vorbis_fpu_control fpu;
  141702. (void) fpu; // (to avoid a warning about it being unused)
  141703. if(samples>length/bytespersample)samples=length/bytespersample;
  141704. if(samples <= 0)
  141705. return OV_EINVAL;
  141706. {
  141707. int val;
  141708. if(word==1){
  141709. int off=(sgned?0:128);
  141710. vorbis_fpu_setround(&fpu);
  141711. for(j=0;j<samples;j++)
  141712. for(i=0;i<channels;i++){
  141713. val=vorbis_ftoi(pcm[i][j]*128.f);
  141714. if(val>127)val=127;
  141715. else if(val<-128)val=-128;
  141716. *buffer++=val+off;
  141717. }
  141718. vorbis_fpu_restore(fpu);
  141719. }else{
  141720. int off=(sgned?0:32768);
  141721. if(host_endian==bigendianp){
  141722. if(sgned){
  141723. vorbis_fpu_setround(&fpu);
  141724. for(i=0;i<channels;i++) { /* It's faster in this order */
  141725. float *src=pcm[i];
  141726. short *dest=((short *)buffer)+i;
  141727. for(j=0;j<samples;j++) {
  141728. val=vorbis_ftoi(src[j]*32768.f);
  141729. if(val>32767)val=32767;
  141730. else if(val<-32768)val=-32768;
  141731. *dest=val;
  141732. dest+=channels;
  141733. }
  141734. }
  141735. vorbis_fpu_restore(fpu);
  141736. }else{
  141737. vorbis_fpu_setround(&fpu);
  141738. for(i=0;i<channels;i++) {
  141739. float *src=pcm[i];
  141740. short *dest=((short *)buffer)+i;
  141741. for(j=0;j<samples;j++) {
  141742. val=vorbis_ftoi(src[j]*32768.f);
  141743. if(val>32767)val=32767;
  141744. else if(val<-32768)val=-32768;
  141745. *dest=val+off;
  141746. dest+=channels;
  141747. }
  141748. }
  141749. vorbis_fpu_restore(fpu);
  141750. }
  141751. }else if(bigendianp){
  141752. vorbis_fpu_setround(&fpu);
  141753. for(j=0;j<samples;j++)
  141754. for(i=0;i<channels;i++){
  141755. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141756. if(val>32767)val=32767;
  141757. else if(val<-32768)val=-32768;
  141758. val+=off;
  141759. *buffer++=(val>>8);
  141760. *buffer++=(val&0xff);
  141761. }
  141762. vorbis_fpu_restore(fpu);
  141763. }else{
  141764. int val;
  141765. vorbis_fpu_setround(&fpu);
  141766. for(j=0;j<samples;j++)
  141767. for(i=0;i<channels;i++){
  141768. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141769. if(val>32767)val=32767;
  141770. else if(val<-32768)val=-32768;
  141771. val+=off;
  141772. *buffer++=(val&0xff);
  141773. *buffer++=(val>>8);
  141774. }
  141775. vorbis_fpu_restore(fpu);
  141776. }
  141777. }
  141778. }
  141779. vorbis_synthesis_read(&vf->vd,samples);
  141780. vf->pcm_offset+=samples;
  141781. if(bitstream)*bitstream=vf->current_link;
  141782. return(samples*bytespersample);
  141783. }else{
  141784. return(samples);
  141785. }
  141786. }
  141787. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141788. int *bitstream){
  141789. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141790. while(1){
  141791. if(vf->ready_state==INITSET){
  141792. float **pcm;
  141793. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141794. if(samples){
  141795. if(pcm_channels)*pcm_channels=pcm;
  141796. if(samples>length)samples=length;
  141797. vorbis_synthesis_read(&vf->vd,samples);
  141798. vf->pcm_offset+=samples;
  141799. if(bitstream)*bitstream=vf->current_link;
  141800. return samples;
  141801. }
  141802. }
  141803. {
  141804. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141805. if(ret==OV_EOF)return(0);
  141806. if(ret<=0)return(ret);
  141807. }
  141808. }
  141809. }
  141810. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141811. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141812. ogg_int64_t off);
  141813. static void _ov_splice(float **pcm,float **lappcm,
  141814. int n1, int n2,
  141815. int ch1, int ch2,
  141816. float *w1, float *w2){
  141817. int i,j;
  141818. float *w=w1;
  141819. int n=n1;
  141820. if(n1>n2){
  141821. n=n2;
  141822. w=w2;
  141823. }
  141824. for(j=0;j<ch1 && j<ch2;j++){
  141825. float *s=lappcm[j];
  141826. float *d=pcm[j];
  141827. for(i=0;i<n;i++){
  141828. float wd=w[i]*w[i];
  141829. float ws=1.-wd;
  141830. d[i]=d[i]*wd + s[i]*ws;
  141831. }
  141832. }
  141833. for(;j<ch2;j++){
  141834. float *d=pcm[j];
  141835. for(i=0;i<n;i++){
  141836. float wd=w[i]*w[i];
  141837. d[i]=d[i]*wd;
  141838. }
  141839. }
  141840. }
  141841. static int _ov_initset(OggVorbis_File *vf){
  141842. while(1){
  141843. if(vf->ready_state==INITSET)break;
  141844. {
  141845. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141846. if(ret<0 && ret!=OV_HOLE)return(ret);
  141847. }
  141848. }
  141849. return 0;
  141850. }
  141851. static int _ov_initprime(OggVorbis_File *vf){
  141852. vorbis_dsp_state *vd=&vf->vd;
  141853. while(1){
  141854. if(vf->ready_state==INITSET)
  141855. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141856. {
  141857. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141858. if(ret<0 && ret!=OV_HOLE)return(ret);
  141859. }
  141860. }
  141861. return 0;
  141862. }
  141863. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141864. float **lappcm,int lapsize){
  141865. int lapcount=0,i;
  141866. float **pcm;
  141867. while(lapcount<lapsize){
  141868. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141869. if(samples){
  141870. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141871. for(i=0;i<vi->channels;i++)
  141872. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141873. lapcount+=samples;
  141874. vorbis_synthesis_read(vd,samples);
  141875. }else{
  141876. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141877. if(ret==OV_EOF)break;
  141878. }
  141879. }
  141880. if(lapcount<lapsize){
  141881. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141882. if(samples==0){
  141883. for(i=0;i<vi->channels;i++)
  141884. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141885. lapcount=lapsize;
  141886. }else{
  141887. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141888. for(i=0;i<vi->channels;i++)
  141889. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141890. lapcount+=samples;
  141891. }
  141892. }
  141893. }
  141894. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141895. vorbis_info *vi1,*vi2;
  141896. float **lappcm;
  141897. float **pcm;
  141898. float *w1,*w2;
  141899. int n1,n2,i,ret,hs1,hs2;
  141900. if(vf1==vf2)return(0); /* degenerate case */
  141901. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141902. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141903. ret=_ov_initset(vf1);
  141904. if(ret)return(ret);
  141905. ret=_ov_initprime(vf2);
  141906. if(ret)return(ret);
  141907. vi1=ov_info(vf1,-1);
  141908. vi2=ov_info(vf2,-1);
  141909. hs1=ov_halfrate_p(vf1);
  141910. hs2=ov_halfrate_p(vf2);
  141911. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141912. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141913. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141914. w1=vorbis_window(&vf1->vd,0);
  141915. w2=vorbis_window(&vf2->vd,0);
  141916. for(i=0;i<vi1->channels;i++)
  141917. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141918. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141919. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141920. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141921. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141922. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141923. return(0);
  141924. }
  141925. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141926. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141927. vorbis_info *vi;
  141928. float **lappcm;
  141929. float **pcm;
  141930. float *w1,*w2;
  141931. int n1,n2,ch1,ch2,hs;
  141932. int i,ret;
  141933. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141934. ret=_ov_initset(vf);
  141935. if(ret)return(ret);
  141936. vi=ov_info(vf,-1);
  141937. hs=ov_halfrate_p(vf);
  141938. ch1=vi->channels;
  141939. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141940. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141941. persistent; even if the decode state
  141942. from this link gets dumped, this
  141943. window array continues to exist */
  141944. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141945. for(i=0;i<ch1;i++)
  141946. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141947. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141948. ret=localseek(vf,pos);
  141949. if(ret)return ret;
  141950. ret=_ov_initprime(vf);
  141951. if(ret)return(ret);
  141952. vi=ov_info(vf,-1);
  141953. ch2=vi->channels;
  141954. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141955. w2=vorbis_window(&vf->vd,0);
  141956. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141957. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141958. return(0);
  141959. }
  141960. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141961. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  141962. }
  141963. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141964. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  141965. }
  141966. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141967. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  141968. }
  141969. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  141970. int (*localseek)(OggVorbis_File *,double)){
  141971. vorbis_info *vi;
  141972. float **lappcm;
  141973. float **pcm;
  141974. float *w1,*w2;
  141975. int n1,n2,ch1,ch2,hs;
  141976. int i,ret;
  141977. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141978. ret=_ov_initset(vf);
  141979. if(ret)return(ret);
  141980. vi=ov_info(vf,-1);
  141981. hs=ov_halfrate_p(vf);
  141982. ch1=vi->channels;
  141983. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141984. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141985. persistent; even if the decode state
  141986. from this link gets dumped, this
  141987. window array continues to exist */
  141988. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141989. for(i=0;i<ch1;i++)
  141990. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141991. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141992. ret=localseek(vf,pos);
  141993. if(ret)return ret;
  141994. ret=_ov_initprime(vf);
  141995. if(ret)return(ret);
  141996. vi=ov_info(vf,-1);
  141997. ch2=vi->channels;
  141998. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141999. w2=vorbis_window(&vf->vd,0);
  142000. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142001. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142002. return(0);
  142003. }
  142004. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142005. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142006. }
  142007. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142008. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142009. }
  142010. #endif
  142011. /*** End of inlined file: vorbisfile.c ***/
  142012. /*** Start of inlined file: window.c ***/
  142013. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142014. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142015. // tasks..
  142016. #if JUCE_MSVC
  142017. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142018. #endif
  142019. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142020. #if JUCE_USE_OGGVORBIS
  142021. #include <stdlib.h>
  142022. #include <math.h>
  142023. static float vwin64[32] = {
  142024. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142025. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142026. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142027. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142028. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142029. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142030. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142031. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142032. };
  142033. static float vwin128[64] = {
  142034. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142035. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142036. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142037. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142038. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142039. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142040. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142041. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142042. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142043. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142044. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142045. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142046. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142047. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142048. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142049. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142050. };
  142051. static float vwin256[128] = {
  142052. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142053. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142054. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142055. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142056. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142057. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142058. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142059. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142060. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142061. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142062. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142063. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142064. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142065. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142066. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142067. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142068. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142069. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142070. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142071. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142072. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142073. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142074. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142075. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142076. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142077. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142078. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142079. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142080. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142081. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142082. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142083. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142084. };
  142085. static float vwin512[256] = {
  142086. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142087. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142088. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142089. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142090. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142091. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142092. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142093. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142094. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142095. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142096. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142097. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142098. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142099. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142100. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142101. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142102. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142103. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142104. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142105. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142106. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142107. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142108. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142109. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142110. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142111. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142112. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142113. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142114. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142115. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142116. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142117. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142118. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142119. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142120. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142121. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142122. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142123. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142124. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142125. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142126. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142127. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142128. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142129. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142130. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142131. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142132. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142133. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142134. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142135. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142136. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142137. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142138. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142139. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142140. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142141. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142142. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142143. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142144. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142145. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142146. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142147. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142148. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142149. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142150. };
  142151. static float vwin1024[512] = {
  142152. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142153. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142154. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142155. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142156. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142157. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142158. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142159. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142160. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142161. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142162. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142163. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142164. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142165. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142166. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142167. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142168. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142169. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142170. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142171. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142172. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142173. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142174. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142175. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142176. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142177. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142178. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142179. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142180. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142181. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142182. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142183. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142184. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142185. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142186. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142187. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142188. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142189. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142190. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142191. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142192. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142193. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142194. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142195. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142196. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142197. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142198. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142199. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142200. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142201. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142202. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142203. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142204. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142205. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142206. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142207. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142208. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142209. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142210. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142211. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142212. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142213. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142214. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142215. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142216. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142217. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142218. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142219. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142220. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142221. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142222. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142223. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142224. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142225. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142226. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142227. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142228. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142229. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142230. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142231. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142232. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142233. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142234. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142235. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142236. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142237. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142238. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142239. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142240. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142241. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142242. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142243. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142244. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142245. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142246. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142247. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142248. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142249. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142250. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142251. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142252. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142253. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142254. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142255. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142256. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142257. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142258. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142259. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142260. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142261. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142262. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142263. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142264. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142265. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142266. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142267. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142268. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142269. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142270. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142271. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142272. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142273. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142274. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142275. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142276. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142277. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142278. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142279. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142280. };
  142281. static float vwin2048[1024] = {
  142282. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142283. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142284. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142285. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142286. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142287. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142288. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142289. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142290. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142291. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142292. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142293. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142294. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142295. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142296. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142297. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142298. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142299. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142300. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142301. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142302. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142303. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142304. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142305. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142306. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142307. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142308. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142309. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142310. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142311. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142312. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142313. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142314. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142315. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142316. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142317. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142318. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142319. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142320. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142321. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142322. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142323. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142324. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142325. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142326. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142327. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142328. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142329. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142330. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142331. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142332. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142333. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142334. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142335. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142336. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142337. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142338. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142339. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142340. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142341. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142342. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142343. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142344. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142345. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142346. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142347. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142348. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142349. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142350. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142351. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142352. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142353. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142354. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142355. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142356. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142357. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142358. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142359. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142360. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142361. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142362. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142363. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142364. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142365. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142366. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142367. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142368. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142369. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142370. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142371. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142372. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142373. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142374. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142375. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142376. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142377. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142378. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142379. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142380. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142381. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142382. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142383. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142384. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142385. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142386. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142387. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142388. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142389. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142390. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142391. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142392. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142393. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142394. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142395. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142396. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142397. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142398. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142399. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142400. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142401. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142402. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142403. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142404. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142405. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142406. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142407. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142408. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142409. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142410. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142411. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142412. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142413. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142414. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142415. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142416. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142417. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142418. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142419. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142420. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142421. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142422. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142423. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142424. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142425. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142426. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142427. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142428. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142429. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142430. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142431. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142432. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142433. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142434. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142435. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142436. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142437. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142438. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142439. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142440. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142441. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142442. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142443. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142444. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142445. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142446. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142447. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142448. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142449. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142450. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142451. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142452. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142453. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142454. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142455. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142456. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142457. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142458. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142459. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142460. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142461. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142462. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142463. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142464. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142465. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142466. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142467. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142468. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142469. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142470. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142471. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142472. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142473. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142474. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142475. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142476. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142477. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142478. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142479. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142480. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142481. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142482. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142483. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142484. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142485. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142486. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142487. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142488. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142489. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142490. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142491. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142492. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142493. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142494. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142495. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142496. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142497. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142498. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142499. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142500. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142501. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142502. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142503. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142504. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142505. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142506. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142507. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142508. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142509. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142510. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142511. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142512. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142513. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142514. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142515. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142516. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142517. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142518. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142519. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142520. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142521. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142522. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142523. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142524. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142525. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142526. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142527. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142528. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142529. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142530. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142531. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142532. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142533. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142534. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142535. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142536. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142537. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142538. };
  142539. static float vwin4096[2048] = {
  142540. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142541. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142542. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142543. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142544. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142545. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142546. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142547. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142548. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142549. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142550. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142551. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142552. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142553. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142554. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142555. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142556. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142557. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142558. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142559. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142560. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142561. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142562. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142563. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142564. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142565. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142566. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142567. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142568. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142569. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142570. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142571. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142572. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142573. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142574. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142575. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142576. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142577. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142578. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142579. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142580. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142581. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142582. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142583. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142584. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142585. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142586. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142587. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142588. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142589. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142590. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142591. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142592. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142593. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142594. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142595. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142596. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142597. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142598. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142599. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142600. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142601. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142602. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142603. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142604. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142605. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142606. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142607. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142608. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142609. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142610. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142611. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142612. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142613. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142614. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142615. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142616. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142617. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142618. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142619. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142620. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142621. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142622. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142623. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142624. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142625. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142626. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142627. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142628. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142629. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142630. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142631. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142632. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142633. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142634. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142635. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142636. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142637. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142638. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142639. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142640. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142641. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142642. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142643. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142644. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142645. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142646. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142647. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142648. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142649. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142650. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142651. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142652. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142653. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142654. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142655. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142656. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142657. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142658. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142659. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142660. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142661. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142662. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142663. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142664. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142665. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142666. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142667. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142668. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142669. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142670. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142671. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142672. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142673. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142674. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142675. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142676. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142677. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142678. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142679. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142680. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142681. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142682. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142683. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142684. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142685. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142686. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142687. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142688. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142689. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142690. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142691. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142692. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142693. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142694. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142695. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142696. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142697. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142698. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142699. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142700. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142701. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142702. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142703. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142704. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142705. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142706. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142707. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142708. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142709. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142710. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142711. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142712. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142713. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142714. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142715. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142716. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142717. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142718. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142719. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142720. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142721. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142722. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142723. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142724. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142725. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142726. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142727. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142728. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142729. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142730. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142731. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142732. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142733. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142734. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142735. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142736. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142737. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142738. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142739. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142740. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142741. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142742. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142743. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142744. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142745. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142746. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142747. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142748. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142749. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142750. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142751. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142752. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142753. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142754. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142755. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142756. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142757. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142758. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142759. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142760. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142761. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142762. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142763. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142764. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142765. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142766. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142767. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142768. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142769. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142770. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142771. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142772. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142773. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142774. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142775. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142776. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142777. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142778. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142779. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142780. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142781. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142782. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142783. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142784. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142785. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142786. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142787. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142788. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142789. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142790. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142791. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142792. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142793. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142794. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142795. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142796. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142797. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142798. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142799. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142800. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142801. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142802. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142803. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142804. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142805. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142806. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142807. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142808. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142809. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142810. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142811. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142812. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142813. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142814. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142815. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142816. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142817. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142818. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142819. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142820. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142821. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142822. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142823. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142824. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142825. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142826. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142827. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142828. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142829. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142830. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142831. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142832. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142833. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142834. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142835. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142836. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142837. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142838. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142839. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142840. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142841. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142842. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142843. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142844. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142845. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142846. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142847. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142848. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142849. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142850. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142851. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142852. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142853. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142854. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142855. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142856. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142857. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142858. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142859. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142860. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142861. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142862. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142863. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142864. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142865. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142866. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142867. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142868. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142869. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142870. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142871. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142872. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142873. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142874. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142875. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142876. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142877. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142878. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142879. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142880. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142881. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142882. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142883. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142884. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142885. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142886. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142887. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142888. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142889. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142890. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142891. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142892. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142893. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142894. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142895. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142896. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142897. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142898. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142899. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142900. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142901. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142902. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142903. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142904. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142905. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142906. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142907. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142908. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142909. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142910. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142911. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142912. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142913. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142914. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142915. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142916. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142917. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142918. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142919. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142920. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142921. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142922. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142923. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142924. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142925. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142926. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142927. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  142928. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  142929. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  142930. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  142931. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  142932. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  142933. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  142934. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  142935. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  142936. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  142937. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  142938. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  142939. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  142940. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  142941. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  142942. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  142943. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  142944. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  142945. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  142946. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  142947. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  142948. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  142949. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  142950. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  142951. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  142952. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  142953. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  142954. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  142955. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  142956. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  142957. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  142958. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  142959. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  142960. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  142961. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  142962. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  142963. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  142964. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  142965. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  142966. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  142967. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  142968. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  142969. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  142970. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  142971. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  142972. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  142973. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  142974. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  142975. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  142976. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  142977. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  142978. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  142979. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  142980. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  142981. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  142982. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  142983. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  142984. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  142985. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  142986. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  142987. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  142988. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  142989. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  142990. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  142991. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  142992. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  142993. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  142994. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  142995. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  142996. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  142997. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  142998. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  142999. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143000. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143001. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143002. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143003. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143004. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143005. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143006. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143007. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143008. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143009. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143010. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143011. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143012. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143013. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143014. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143015. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143016. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143017. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143018. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143019. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143020. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143021. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143022. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143023. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143024. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143025. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143026. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143027. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143028. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143029. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143030. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143031. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143032. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143033. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143034. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143035. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143036. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143037. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143038. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143039. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143040. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143041. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143042. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143043. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143044. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143045. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143046. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143047. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143048. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143049. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143050. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143051. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143052. };
  143053. static float vwin8192[4096] = {
  143054. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143055. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143056. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143057. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143058. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143059. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143060. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143061. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143062. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143063. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143064. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143065. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143066. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143067. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143068. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143069. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143070. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143071. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143072. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143073. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143074. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143075. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143076. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143077. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143078. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143079. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143080. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143081. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143082. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143083. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143084. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143085. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143086. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143087. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143088. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143089. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143090. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143091. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143092. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143093. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143094. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143095. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143096. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143097. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143098. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143099. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143100. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143101. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143102. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143103. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143104. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143105. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143106. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143107. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143108. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143109. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143110. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143111. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143112. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143113. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143114. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143115. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143116. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143117. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143118. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143119. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143120. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143121. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143122. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143123. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143124. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143125. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143126. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143127. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143128. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143129. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143130. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143131. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143132. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143133. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143134. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143135. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143136. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143137. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143138. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143139. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143140. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143141. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143142. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143143. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143144. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143145. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143146. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143147. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143148. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143149. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143150. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143151. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143152. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143153. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143154. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143155. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143156. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143157. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143158. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143159. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143160. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143161. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143162. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143163. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143164. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143165. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143166. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143167. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143168. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143169. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143170. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143171. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143172. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143173. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143174. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143175. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143176. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143177. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143178. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143179. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143180. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143181. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143182. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143183. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143184. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143185. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143186. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143187. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143188. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143189. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143190. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143191. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143192. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143193. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143194. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143195. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143196. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143197. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143198. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143199. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143200. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143201. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143202. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143203. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143204. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143205. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143206. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143207. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143208. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143209. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143210. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143211. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143212. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143213. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143214. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143215. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143216. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143217. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143218. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143219. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143220. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143221. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143222. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143223. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143224. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143225. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143226. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143227. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143228. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143229. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143230. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143231. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143232. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143233. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143234. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143235. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143236. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143237. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143238. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143239. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143240. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143241. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143242. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143243. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143244. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143245. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143246. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143247. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143248. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143249. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143250. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143251. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143252. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143253. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143254. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143255. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143256. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143257. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143258. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143259. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143260. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143261. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143262. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143263. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143264. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143265. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143266. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143267. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143268. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143269. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143270. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143271. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143272. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143273. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143274. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143275. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143276. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143277. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143278. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143279. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143280. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143281. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143282. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143283. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143284. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143285. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143286. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143287. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143288. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143289. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143290. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143291. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143292. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143293. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143294. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143295. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143296. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143297. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143298. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143299. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143300. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143301. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143302. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143303. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143304. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143305. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143306. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143307. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143308. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143309. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143310. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143311. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143312. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143313. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143314. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143315. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143316. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143317. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143318. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143319. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143320. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143321. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143322. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143323. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143324. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143325. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143326. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143327. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143328. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143329. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143330. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143331. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143332. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143333. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143334. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143335. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143336. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143337. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143338. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143339. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143340. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143341. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143342. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143343. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143344. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143345. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143346. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143347. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143348. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143349. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143350. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143351. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143352. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143353. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143354. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143355. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143356. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143357. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143358. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143359. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143360. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143361. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143362. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143363. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143364. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143365. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143366. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143367. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143368. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143369. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143370. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143371. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143372. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143373. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143374. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143375. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143376. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143377. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143378. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143379. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143380. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143381. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143382. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143383. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143384. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143385. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143386. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143387. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143388. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143389. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143390. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143391. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143392. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143393. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143394. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143395. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143396. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143397. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143398. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143399. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143400. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143401. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143402. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143403. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143404. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143405. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143406. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143407. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143408. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143409. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143410. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143411. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143412. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143413. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143414. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143415. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143416. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143417. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143418. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143419. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143420. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143421. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143422. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143423. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143424. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143425. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143426. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143427. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143428. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143429. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143430. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143431. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143432. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143433. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143434. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143435. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143436. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143437. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143438. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143439. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143440. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143441. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143442. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143443. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143444. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143445. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143446. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143447. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143448. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143449. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143450. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143451. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143452. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143453. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143454. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143455. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143456. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143457. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143458. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143459. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143460. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143461. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143462. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143463. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143464. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143465. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143466. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143467. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143468. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143469. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143470. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143471. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143472. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143473. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143474. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143475. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143476. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143477. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143478. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143479. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143480. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143481. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143482. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143483. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143484. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143485. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143486. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143487. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143488. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143489. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143490. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143491. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143492. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143493. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143494. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143495. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143496. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143497. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143498. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143499. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143500. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143501. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143502. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143503. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143504. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143505. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143506. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143507. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143508. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143509. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143510. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143511. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143512. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143513. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143514. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143515. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143516. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143517. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143518. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143519. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143520. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143521. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143522. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143523. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143524. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143525. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143526. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143527. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143528. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143529. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143530. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143531. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143532. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143533. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143534. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143535. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143536. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143537. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143538. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143539. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143540. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143541. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143542. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143543. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143544. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143545. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143546. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143547. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143548. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143549. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143550. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143551. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143552. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143553. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143554. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143555. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143556. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143557. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143558. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143559. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143560. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143561. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143562. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143563. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143564. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143565. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143566. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143567. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143568. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143569. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143570. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143571. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143572. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143573. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143574. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143575. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143576. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143577. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143578. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143579. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143580. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143581. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143582. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143583. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143584. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143585. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143586. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143587. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143588. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143589. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143590. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143591. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143592. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143593. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143594. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143595. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143596. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143597. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143598. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143599. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143600. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143601. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143602. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143603. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143604. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143605. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143606. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143607. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143608. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143609. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143610. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143611. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143612. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143613. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143614. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143615. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143616. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143617. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143618. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143619. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143620. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143621. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143622. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143623. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143624. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143625. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143626. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143627. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143628. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143629. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143630. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143631. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143632. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143633. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143634. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143635. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143636. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143637. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143638. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143639. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143640. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143641. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143642. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143643. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143644. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143645. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143646. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143647. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143648. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143649. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143650. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143651. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143652. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143653. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143654. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143655. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143656. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143657. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143658. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143659. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143660. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143661. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143662. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143663. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143664. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143665. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143666. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143667. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143668. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143669. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143670. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143671. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143672. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143673. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143674. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143675. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143676. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143677. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143678. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143679. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143680. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143681. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143682. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143683. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143684. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143685. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143686. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143687. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143688. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143689. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143690. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143691. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143692. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143693. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143694. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143695. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143696. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143697. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143698. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143699. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143700. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143701. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143702. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143703. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143704. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143705. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143706. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143707. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143708. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143709. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143710. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143711. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143712. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143713. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143714. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143715. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143716. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143717. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143718. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143719. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143720. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143721. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143722. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143723. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143724. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143725. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143726. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143727. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143728. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143729. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143730. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143731. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143732. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143733. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143734. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143735. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143736. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143737. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143738. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143739. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143740. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143741. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143742. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143743. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143744. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143745. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143746. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143747. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143748. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143749. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143750. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143751. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143752. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143753. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143754. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143755. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143756. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143757. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143758. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143759. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143760. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143761. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143762. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143763. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143764. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143765. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143766. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143767. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143768. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143769. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143770. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143771. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143772. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143773. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143774. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143775. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143776. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143777. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143778. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143779. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143780. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143781. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143782. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143783. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143784. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143785. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143786. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143787. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143788. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143789. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143790. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143791. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143792. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143793. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143794. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143795. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143796. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143797. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143798. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143799. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143800. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143801. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143802. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143803. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143804. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143805. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143806. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143807. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143808. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143809. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143810. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143811. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143812. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143813. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143814. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143815. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143816. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143817. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143818. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143819. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143820. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143821. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143822. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143823. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143824. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143825. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143826. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143827. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143828. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143829. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143830. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143831. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143832. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143833. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143834. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143835. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143836. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143837. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143838. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143839. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143840. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143841. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143842. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143843. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143844. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143845. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143846. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143847. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143848. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143849. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143850. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143851. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143852. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143853. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143854. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143855. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143856. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143857. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143858. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143859. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143860. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143861. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143862. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143863. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143864. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143865. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143866. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143867. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143868. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143869. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143870. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143871. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143872. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143873. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143874. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143875. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143876. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143877. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143878. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143879. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143880. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143881. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143882. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143883. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143884. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143885. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143886. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143887. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143888. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143889. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143890. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143891. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143892. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143893. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143894. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143895. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143896. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143897. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143898. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143899. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143900. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143901. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143902. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143903. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143904. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143905. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143906. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143907. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143908. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143909. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143910. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143911. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143912. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143913. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143914. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143915. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143916. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143917. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143918. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143919. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143920. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143921. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143922. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143923. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143924. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143925. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143926. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143927. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  143928. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  143929. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  143930. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  143931. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  143932. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  143933. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  143934. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  143935. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  143936. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  143937. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  143938. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  143939. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  143940. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  143941. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  143942. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  143943. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  143944. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  143945. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  143946. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  143947. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  143948. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  143949. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  143950. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  143951. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  143952. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  143953. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  143954. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  143955. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  143956. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  143957. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  143958. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  143959. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  143960. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  143961. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  143962. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  143963. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  143964. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  143965. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  143966. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  143967. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  143968. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  143969. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  143970. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  143971. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  143972. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  143973. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  143974. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  143975. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  143976. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  143977. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  143978. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  143979. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  143980. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  143981. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  143982. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  143983. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  143984. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  143985. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  143986. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  143987. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  143988. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  143989. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  143990. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  143991. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  143992. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  143993. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  143994. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  143995. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  143996. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  143997. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  143998. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  143999. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144000. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144001. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144002. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144003. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144004. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144005. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144006. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144007. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144008. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144009. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144010. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144011. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144012. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144013. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144014. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144015. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144016. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144017. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144018. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144019. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144020. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144021. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144022. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144023. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144024. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144025. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144026. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144027. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144028. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144029. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144030. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144031. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144032. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144033. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144034. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144035. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144036. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144037. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144038. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144039. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144040. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144041. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144042. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144043. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144044. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144045. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144046. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144047. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144048. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144049. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144050. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144051. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144052. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144053. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144054. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144055. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144056. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144057. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144058. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144059. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144060. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144061. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144062. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144063. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144064. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144065. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144066. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144067. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144068. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144069. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144070. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144071. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144072. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144073. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144074. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144075. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144076. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144077. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144078. };
  144079. static float *vwin[8] = {
  144080. vwin64,
  144081. vwin128,
  144082. vwin256,
  144083. vwin512,
  144084. vwin1024,
  144085. vwin2048,
  144086. vwin4096,
  144087. vwin8192,
  144088. };
  144089. float *_vorbis_window_get(int n){
  144090. return vwin[n];
  144091. }
  144092. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144093. int lW,int W,int nW){
  144094. lW=(W?lW:0);
  144095. nW=(W?nW:0);
  144096. {
  144097. float *windowLW=vwin[winno[lW]];
  144098. float *windowNW=vwin[winno[nW]];
  144099. long n=blocksizes[W];
  144100. long ln=blocksizes[lW];
  144101. long rn=blocksizes[nW];
  144102. long leftbegin=n/4-ln/4;
  144103. long leftend=leftbegin+ln/2;
  144104. long rightbegin=n/2+n/4-rn/4;
  144105. long rightend=rightbegin+rn/2;
  144106. int i,p;
  144107. for(i=0;i<leftbegin;i++)
  144108. d[i]=0.f;
  144109. for(p=0;i<leftend;i++,p++)
  144110. d[i]*=windowLW[p];
  144111. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144112. d[i]*=windowNW[p];
  144113. for(;i<n;i++)
  144114. d[i]=0.f;
  144115. }
  144116. }
  144117. #endif
  144118. /*** End of inlined file: window.c ***/
  144119. #else
  144120. #include <vorbis/vorbisenc.h>
  144121. #include <vorbis/codec.h>
  144122. #include <vorbis/vorbisfile.h>
  144123. #endif
  144124. }
  144125. #undef max
  144126. #undef min
  144127. BEGIN_JUCE_NAMESPACE
  144128. static const char* const oggFormatName = "Ogg-Vorbis file";
  144129. static const juce_wchar* const oggExtensions[] = { T(".ogg"), 0 };
  144130. class OggReader : public AudioFormatReader
  144131. {
  144132. OggVorbisNamespace::OggVorbis_File ovFile;
  144133. OggVorbisNamespace::ov_callbacks callbacks;
  144134. AudioSampleBuffer reservoir;
  144135. int reservoirStart, samplesInReservoir;
  144136. public:
  144137. OggReader (InputStream* const inp)
  144138. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144139. reservoir (2, 4096),
  144140. reservoirStart (0),
  144141. samplesInReservoir (0)
  144142. {
  144143. using namespace OggVorbisNamespace;
  144144. sampleRate = 0;
  144145. usesFloatingPointData = true;
  144146. callbacks.read_func = &oggReadCallback;
  144147. callbacks.seek_func = &oggSeekCallback;
  144148. callbacks.close_func = &oggCloseCallback;
  144149. callbacks.tell_func = &oggTellCallback;
  144150. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144151. if (err == 0)
  144152. {
  144153. vorbis_info* info = ov_info (&ovFile, -1);
  144154. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144155. numChannels = info->channels;
  144156. bitsPerSample = 16;
  144157. sampleRate = info->rate;
  144158. reservoir.setSize (numChannels,
  144159. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144160. }
  144161. }
  144162. ~OggReader()
  144163. {
  144164. OggVorbisNamespace::ov_clear (&ovFile);
  144165. }
  144166. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144167. int64 startSampleInFile, int numSamples)
  144168. {
  144169. while (numSamples > 0)
  144170. {
  144171. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144172. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144173. {
  144174. // got a few samples overlapping, so use them before seeking..
  144175. const int numToUse = jmin (numSamples, numAvailable);
  144176. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144177. if (destSamples[i] != 0)
  144178. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144179. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144180. sizeof (float) * numToUse);
  144181. startSampleInFile += numToUse;
  144182. numSamples -= numToUse;
  144183. startOffsetInDestBuffer += numToUse;
  144184. if (numSamples == 0)
  144185. break;
  144186. }
  144187. if (startSampleInFile < reservoirStart
  144188. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144189. {
  144190. // buffer miss, so refill the reservoir
  144191. int bitStream = 0;
  144192. reservoirStart = jmax (0, (int) startSampleInFile);
  144193. samplesInReservoir = reservoir.getNumSamples();
  144194. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  144195. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  144196. int offset = 0;
  144197. int numToRead = samplesInReservoir;
  144198. while (numToRead > 0)
  144199. {
  144200. float** dataIn = 0;
  144201. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144202. if (samps <= 0)
  144203. break;
  144204. jassert (samps <= numToRead);
  144205. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144206. {
  144207. memcpy (reservoir.getSampleData (i, offset),
  144208. dataIn[i],
  144209. sizeof (float) * samps);
  144210. }
  144211. numToRead -= samps;
  144212. offset += samps;
  144213. }
  144214. if (numToRead > 0)
  144215. reservoir.clear (offset, numToRead);
  144216. }
  144217. }
  144218. if (numSamples > 0)
  144219. {
  144220. for (int i = numDestChannels; --i >= 0;)
  144221. if (destSamples[i] != 0)
  144222. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144223. sizeof (int) * numSamples);
  144224. }
  144225. return true;
  144226. }
  144227. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144228. {
  144229. return (size_t) (static_cast <InputStream*> (datasource)->read (ptr, (int) (size * nmemb)) / size);
  144230. }
  144231. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144232. {
  144233. InputStream* const in = static_cast <InputStream*> (datasource);
  144234. if (whence == SEEK_CUR)
  144235. offset += in->getPosition();
  144236. else if (whence == SEEK_END)
  144237. offset += in->getTotalLength();
  144238. in->setPosition (offset);
  144239. return 0;
  144240. }
  144241. static int oggCloseCallback (void*)
  144242. {
  144243. return 0;
  144244. }
  144245. static long oggTellCallback (void* datasource)
  144246. {
  144247. return (long) static_cast <InputStream*> (datasource)->getPosition();
  144248. }
  144249. juce_UseDebuggingNewOperator
  144250. };
  144251. class OggWriter : public AudioFormatWriter
  144252. {
  144253. OggVorbisNamespace::ogg_stream_state os;
  144254. OggVorbisNamespace::ogg_page og;
  144255. OggVorbisNamespace::ogg_packet op;
  144256. OggVorbisNamespace::vorbis_info vi;
  144257. OggVorbisNamespace::vorbis_comment vc;
  144258. OggVorbisNamespace::vorbis_dsp_state vd;
  144259. OggVorbisNamespace::vorbis_block vb;
  144260. public:
  144261. bool ok;
  144262. OggWriter (OutputStream* const out,
  144263. const double sampleRate,
  144264. const int numChannels,
  144265. const int bitsPerSample,
  144266. const int qualityIndex)
  144267. : AudioFormatWriter (out, TRANS (oggFormatName),
  144268. sampleRate,
  144269. numChannels,
  144270. bitsPerSample)
  144271. {
  144272. using namespace OggVorbisNamespace;
  144273. ok = false;
  144274. vorbis_info_init (&vi);
  144275. if (vorbis_encode_init_vbr (&vi,
  144276. numChannels,
  144277. (int) sampleRate,
  144278. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144279. {
  144280. vorbis_comment_init (&vc);
  144281. if (JUCEApplication::getInstance() != 0)
  144282. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144283. vorbis_analysis_init (&vd, &vi);
  144284. vorbis_block_init (&vd, &vb);
  144285. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144286. ogg_packet header;
  144287. ogg_packet header_comm;
  144288. ogg_packet header_code;
  144289. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144290. ogg_stream_packetin (&os, &header);
  144291. ogg_stream_packetin (&os, &header_comm);
  144292. ogg_stream_packetin (&os, &header_code);
  144293. for (;;)
  144294. {
  144295. if (ogg_stream_flush (&os, &og) == 0)
  144296. break;
  144297. output->write (og.header, og.header_len);
  144298. output->write (og.body, og.body_len);
  144299. }
  144300. ok = true;
  144301. }
  144302. }
  144303. ~OggWriter()
  144304. {
  144305. using namespace OggVorbisNamespace;
  144306. if (ok)
  144307. {
  144308. // write a zero-length packet to show ogg that we're finished..
  144309. write (0, 0);
  144310. ogg_stream_clear (&os);
  144311. vorbis_block_clear (&vb);
  144312. vorbis_dsp_clear (&vd);
  144313. vorbis_comment_clear (&vc);
  144314. vorbis_info_clear (&vi);
  144315. output->flush();
  144316. }
  144317. else
  144318. {
  144319. vorbis_info_clear (&vi);
  144320. output = 0; // to stop the base class deleting this, as it needs to be returned
  144321. // to the caller of createWriter()
  144322. }
  144323. }
  144324. bool write (const int** samplesToWrite, int numSamples)
  144325. {
  144326. using namespace OggVorbisNamespace;
  144327. if (! ok)
  144328. return false;
  144329. if (numSamples > 0)
  144330. {
  144331. const double gain = 1.0 / 0x80000000u;
  144332. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144333. for (int i = numChannels; --i >= 0;)
  144334. {
  144335. float* const dst = vorbisBuffer[i];
  144336. const int* const src = samplesToWrite [i];
  144337. if (src != 0 && dst != 0)
  144338. {
  144339. for (int j = 0; j < numSamples; ++j)
  144340. dst[j] = (float) (src[j] * gain);
  144341. }
  144342. }
  144343. }
  144344. vorbis_analysis_wrote (&vd, numSamples);
  144345. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144346. {
  144347. vorbis_analysis (&vb, 0);
  144348. vorbis_bitrate_addblock (&vb);
  144349. while (vorbis_bitrate_flushpacket (&vd, &op))
  144350. {
  144351. ogg_stream_packetin (&os, &op);
  144352. for (;;)
  144353. {
  144354. if (ogg_stream_pageout (&os, &og) == 0)
  144355. break;
  144356. output->write (og.header, og.header_len);
  144357. output->write (og.body, og.body_len);
  144358. if (ogg_page_eos (&og))
  144359. break;
  144360. }
  144361. }
  144362. }
  144363. return true;
  144364. }
  144365. juce_UseDebuggingNewOperator
  144366. };
  144367. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144368. : AudioFormat (TRANS (oggFormatName), (const juce_wchar**) oggExtensions)
  144369. {
  144370. }
  144371. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144372. {
  144373. }
  144374. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144375. {
  144376. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144377. return Array <int> (rates);
  144378. }
  144379. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144380. {
  144381. Array <int> depths;
  144382. depths.add (32);
  144383. return depths;
  144384. }
  144385. bool OggVorbisAudioFormat::canDoStereo()
  144386. {
  144387. return true;
  144388. }
  144389. bool OggVorbisAudioFormat::canDoMono()
  144390. {
  144391. return true;
  144392. }
  144393. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144394. const bool deleteStreamIfOpeningFails)
  144395. {
  144396. ScopedPointer <OggReader> r (new OggReader (in));
  144397. if (r->sampleRate != 0)
  144398. return r.release();
  144399. if (! deleteStreamIfOpeningFails)
  144400. r->input = 0;
  144401. return 0;
  144402. }
  144403. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144404. double sampleRate,
  144405. unsigned int numChannels,
  144406. int bitsPerSample,
  144407. const StringPairArray& /*metadataValues*/,
  144408. int qualityOptionIndex)
  144409. {
  144410. ScopedPointer <OggWriter> w (new OggWriter (out,
  144411. sampleRate,
  144412. numChannels,
  144413. bitsPerSample,
  144414. qualityOptionIndex));
  144415. return w->ok ? w.release() : 0;
  144416. }
  144417. bool OggVorbisAudioFormat::isCompressed()
  144418. {
  144419. return true;
  144420. }
  144421. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144422. {
  144423. StringArray s;
  144424. s.add ("Low Quality");
  144425. s.add ("Medium Quality");
  144426. s.add ("High Quality");
  144427. return s;
  144428. }
  144429. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144430. {
  144431. FileInputStream* const in = source.createInputStream();
  144432. if (in != 0)
  144433. {
  144434. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144435. if (r != 0)
  144436. {
  144437. const int64 numSamps = r->lengthInSamples;
  144438. r = 0;
  144439. const int64 fileNumSamps = source.getSize() / 4;
  144440. const double ratio = numSamps / (double) fileNumSamps;
  144441. if (ratio > 12.0)
  144442. return 0;
  144443. else if (ratio > 6.0)
  144444. return 1;
  144445. else
  144446. return 2;
  144447. }
  144448. }
  144449. return 1;
  144450. }
  144451. END_JUCE_NAMESPACE
  144452. #endif
  144453. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144454. #endif
  144455. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144456. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144457. #if JUCE_MSVC
  144458. #pragma warning (push)
  144459. #endif
  144460. namespace jpeglibNamespace
  144461. {
  144462. #if JUCE_INCLUDE_JPEGLIB_CODE
  144463. #if JUCE_MINGW
  144464. typedef unsigned char boolean;
  144465. #endif
  144466. extern "C"
  144467. {
  144468. #define JPEG_INTERNALS
  144469. #undef FAR
  144470. /*** Start of inlined file: jpeglib.h ***/
  144471. #ifndef JPEGLIB_H
  144472. #define JPEGLIB_H
  144473. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144474. /*** Start of inlined file: jconfig.h ***/
  144475. // disable all the warnings under MSVC
  144476. #ifdef _MSC_VER
  144477. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144478. #endif
  144479. #ifdef __BORLANDC__
  144480. #pragma warn -8057
  144481. #pragma warn -8019
  144482. #pragma warn -8004
  144483. #pragma warn -8008
  144484. #endif
  144485. #define HAVE_PROTOTYPES
  144486. #define HAVE_UNSIGNED_CHAR
  144487. #define HAVE_UNSIGNED_SHORT
  144488. #undef CHAR_IS_UNSIGNED
  144489. #define HAVE_STDDEF_H
  144490. #define HAVE_STDLIB_H
  144491. #undef NEED_BSD_STRINGS
  144492. #undef NEED_SYS_TYPES_H
  144493. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144494. #undef NEED_SHORT_EXTERNAL_NAMES
  144495. #undef INCOMPLETE_TYPES_BROKEN
  144496. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144497. typedef unsigned char boolean;
  144498. #endif
  144499. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144500. #ifdef JPEG_INTERNALS
  144501. #undef RIGHT_SHIFT_IS_UNSIGNED
  144502. #endif /* JPEG_INTERNALS */
  144503. #ifdef JPEG_CJPEG_DJPEG
  144504. #define BMP_SUPPORTED /* BMP image file format */
  144505. #define GIF_SUPPORTED /* GIF image file format */
  144506. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144507. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144508. #define TARGA_SUPPORTED /* Targa image file format */
  144509. #define TWO_FILE_COMMANDLINE /* optional */
  144510. #define USE_SETMODE /* Microsoft has setmode() */
  144511. #undef NEED_SIGNAL_CATCHER
  144512. #undef DONT_USE_B_MODE
  144513. #undef PROGRESS_REPORT /* optional */
  144514. #endif /* JPEG_CJPEG_DJPEG */
  144515. /*** End of inlined file: jconfig.h ***/
  144516. /* widely used configuration options */
  144517. #endif
  144518. /*** Start of inlined file: jmorecfg.h ***/
  144519. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144520. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144521. #if BITS_IN_JSAMPLE == 8
  144522. #ifdef HAVE_UNSIGNED_CHAR
  144523. typedef unsigned char JSAMPLE;
  144524. #define GETJSAMPLE(value) ((int) (value))
  144525. #else /* not HAVE_UNSIGNED_CHAR */
  144526. typedef char JSAMPLE;
  144527. #ifdef CHAR_IS_UNSIGNED
  144528. #define GETJSAMPLE(value) ((int) (value))
  144529. #else
  144530. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144531. #endif /* CHAR_IS_UNSIGNED */
  144532. #endif /* HAVE_UNSIGNED_CHAR */
  144533. #define MAXJSAMPLE 255
  144534. #define CENTERJSAMPLE 128
  144535. #endif /* BITS_IN_JSAMPLE == 8 */
  144536. #if BITS_IN_JSAMPLE == 12
  144537. typedef short JSAMPLE;
  144538. #define GETJSAMPLE(value) ((int) (value))
  144539. #define MAXJSAMPLE 4095
  144540. #define CENTERJSAMPLE 2048
  144541. #endif /* BITS_IN_JSAMPLE == 12 */
  144542. typedef short JCOEF;
  144543. #ifdef HAVE_UNSIGNED_CHAR
  144544. typedef unsigned char JOCTET;
  144545. #define GETJOCTET(value) (value)
  144546. #else /* not HAVE_UNSIGNED_CHAR */
  144547. typedef char JOCTET;
  144548. #ifdef CHAR_IS_UNSIGNED
  144549. #define GETJOCTET(value) (value)
  144550. #else
  144551. #define GETJOCTET(value) ((value) & 0xFF)
  144552. #endif /* CHAR_IS_UNSIGNED */
  144553. #endif /* HAVE_UNSIGNED_CHAR */
  144554. #ifdef HAVE_UNSIGNED_CHAR
  144555. typedef unsigned char UINT8;
  144556. #else /* not HAVE_UNSIGNED_CHAR */
  144557. #ifdef CHAR_IS_UNSIGNED
  144558. typedef char UINT8;
  144559. #else /* not CHAR_IS_UNSIGNED */
  144560. typedef short UINT8;
  144561. #endif /* CHAR_IS_UNSIGNED */
  144562. #endif /* HAVE_UNSIGNED_CHAR */
  144563. #ifdef HAVE_UNSIGNED_SHORT
  144564. typedef unsigned short UINT16;
  144565. #else /* not HAVE_UNSIGNED_SHORT */
  144566. typedef unsigned int UINT16;
  144567. #endif /* HAVE_UNSIGNED_SHORT */
  144568. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144569. typedef short INT16;
  144570. #endif
  144571. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144572. typedef long INT32;
  144573. #endif
  144574. typedef unsigned int JDIMENSION;
  144575. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144576. #define METHODDEF(type) static type
  144577. #define LOCAL(type) static type
  144578. #define GLOBAL(type) type
  144579. #define EXTERN(type) extern type
  144580. #ifdef HAVE_PROTOTYPES
  144581. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144582. #else
  144583. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144584. #endif
  144585. #ifdef NEED_FAR_POINTERS
  144586. #define FAR far
  144587. #else
  144588. #define FAR
  144589. #endif
  144590. #ifndef HAVE_BOOLEAN
  144591. typedef int boolean;
  144592. #endif
  144593. #ifndef FALSE /* in case these macros already exist */
  144594. #define FALSE 0 /* values of boolean */
  144595. #endif
  144596. #ifndef TRUE
  144597. #define TRUE 1
  144598. #endif
  144599. #ifdef JPEG_INTERNALS
  144600. #define JPEG_INTERNAL_OPTIONS
  144601. #endif
  144602. #ifdef JPEG_INTERNAL_OPTIONS
  144603. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144604. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144605. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144606. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144607. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144608. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144609. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144610. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144611. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144612. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144613. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144614. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144615. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144616. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144617. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144618. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144619. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144620. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144621. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144622. #define RGB_GREEN 1 /* Offset of Green */
  144623. #define RGB_BLUE 2 /* Offset of Blue */
  144624. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144625. #ifndef INLINE
  144626. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144627. #define INLINE __inline__
  144628. #endif
  144629. #ifndef INLINE
  144630. #define INLINE /* default is to define it as empty */
  144631. #endif
  144632. #endif
  144633. #ifndef MULTIPLIER
  144634. #define MULTIPLIER int /* type for fastest integer multiply */
  144635. #endif
  144636. #ifndef FAST_FLOAT
  144637. #ifdef HAVE_PROTOTYPES
  144638. #define FAST_FLOAT float
  144639. #else
  144640. #define FAST_FLOAT double
  144641. #endif
  144642. #endif
  144643. #endif /* JPEG_INTERNAL_OPTIONS */
  144644. /*** End of inlined file: jmorecfg.h ***/
  144645. /* seldom changed options */
  144646. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144647. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144648. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144649. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144650. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144651. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144652. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144653. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144654. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144655. #ifndef D_MAX_BLOCKS_IN_MCU
  144656. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144657. #endif
  144658. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144659. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144660. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144661. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144662. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144663. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144664. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144665. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144666. typedef struct {
  144667. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144668. boolean sent_table; /* TRUE when table has been output */
  144669. } JQUANT_TBL;
  144670. typedef struct {
  144671. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144672. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144673. boolean sent_table; /* TRUE when table has been output */
  144674. } JHUFF_TBL;
  144675. typedef struct {
  144676. int component_id; /* identifier for this component (0..255) */
  144677. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144678. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144679. int v_samp_factor; /* vertical sampling factor (1..4) */
  144680. int quant_tbl_no; /* quantization table selector (0..3) */
  144681. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144682. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144683. JDIMENSION width_in_blocks;
  144684. JDIMENSION height_in_blocks;
  144685. int DCT_scaled_size;
  144686. JDIMENSION downsampled_width; /* actual width in samples */
  144687. JDIMENSION downsampled_height; /* actual height in samples */
  144688. boolean component_needed; /* do we need the value of this component? */
  144689. int MCU_width; /* number of blocks per MCU, horizontally */
  144690. int MCU_height; /* number of blocks per MCU, vertically */
  144691. int MCU_blocks; /* MCU_width * MCU_height */
  144692. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144693. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144694. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144695. JQUANT_TBL * quant_table;
  144696. void * dct_table;
  144697. } jpeg_component_info;
  144698. typedef struct {
  144699. int comps_in_scan; /* number of components encoded in this scan */
  144700. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144701. int Ss, Se; /* progressive JPEG spectral selection parms */
  144702. int Ah, Al; /* progressive JPEG successive approx. parms */
  144703. } jpeg_scan_info;
  144704. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144705. struct jpeg_marker_struct {
  144706. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144707. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144708. unsigned int original_length; /* # bytes of data in the file */
  144709. unsigned int data_length; /* # bytes of data saved at data[] */
  144710. JOCTET FAR * data; /* the data contained in the marker */
  144711. };
  144712. typedef enum {
  144713. JCS_UNKNOWN, /* error/unspecified */
  144714. JCS_GRAYSCALE, /* monochrome */
  144715. JCS_RGB, /* red/green/blue */
  144716. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144717. JCS_CMYK, /* C/M/Y/K */
  144718. JCS_YCCK /* Y/Cb/Cr/K */
  144719. } J_COLOR_SPACE;
  144720. typedef enum {
  144721. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144722. JDCT_IFAST, /* faster, less accurate integer method */
  144723. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144724. } J_DCT_METHOD;
  144725. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144726. #define JDCT_DEFAULT JDCT_ISLOW
  144727. #endif
  144728. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144729. #define JDCT_FASTEST JDCT_IFAST
  144730. #endif
  144731. typedef enum {
  144732. JDITHER_NONE, /* no dithering */
  144733. JDITHER_ORDERED, /* simple ordered dither */
  144734. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144735. } J_DITHER_MODE;
  144736. #define jpeg_common_fields \
  144737. struct jpeg_error_mgr * err; /* Error handler module */\
  144738. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144739. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144740. void * client_data; /* Available for use by application */\
  144741. boolean is_decompressor; /* So common code can tell which is which */\
  144742. int global_state /* For checking call sequence validity */
  144743. struct jpeg_common_struct {
  144744. jpeg_common_fields; /* Fields common to both master struct types */
  144745. };
  144746. typedef struct jpeg_common_struct * j_common_ptr;
  144747. typedef struct jpeg_compress_struct * j_compress_ptr;
  144748. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144749. struct jpeg_compress_struct {
  144750. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144751. struct jpeg_destination_mgr * dest;
  144752. JDIMENSION image_width; /* input image width */
  144753. JDIMENSION image_height; /* input image height */
  144754. int input_components; /* # of color components in input image */
  144755. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144756. double input_gamma; /* image gamma of input image */
  144757. int data_precision; /* bits of precision in image data */
  144758. int num_components; /* # of color components in JPEG image */
  144759. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144760. jpeg_component_info * comp_info;
  144761. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144762. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144763. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144764. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144765. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144766. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144767. int num_scans; /* # of entries in scan_info array */
  144768. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144769. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144770. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144771. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144772. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144773. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144774. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144775. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144776. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144777. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144778. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144779. UINT8 JFIF_minor_version;
  144780. UINT8 density_unit; /* JFIF code for pixel size units */
  144781. UINT16 X_density; /* Horizontal pixel density */
  144782. UINT16 Y_density; /* Vertical pixel density */
  144783. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144784. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144785. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144786. int max_h_samp_factor; /* largest h_samp_factor */
  144787. int max_v_samp_factor; /* largest v_samp_factor */
  144788. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144789. int comps_in_scan; /* # of JPEG components in this scan */
  144790. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144791. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144792. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144793. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144794. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144795. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144796. struct jpeg_comp_master * master;
  144797. struct jpeg_c_main_controller * main;
  144798. struct jpeg_c_prep_controller * prep;
  144799. struct jpeg_c_coef_controller * coef;
  144800. struct jpeg_marker_writer * marker;
  144801. struct jpeg_color_converter * cconvert;
  144802. struct jpeg_downsampler * downsample;
  144803. struct jpeg_forward_dct * fdct;
  144804. struct jpeg_entropy_encoder * entropy;
  144805. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144806. int script_space_size;
  144807. };
  144808. struct jpeg_decompress_struct {
  144809. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144810. struct jpeg_source_mgr * src;
  144811. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144812. JDIMENSION image_height; /* nominal image height */
  144813. int num_components; /* # of color components in JPEG image */
  144814. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144815. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144816. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144817. double output_gamma; /* image gamma wanted in output */
  144818. boolean buffered_image; /* TRUE=multiple output passes */
  144819. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144820. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144821. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144822. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144823. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144824. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144825. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144826. int desired_number_of_colors; /* max # colors to use in created colormap */
  144827. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144828. boolean enable_external_quant;/* enable future use of external colormap */
  144829. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144830. JDIMENSION output_width; /* scaled image width */
  144831. JDIMENSION output_height; /* scaled image height */
  144832. int out_color_components; /* # of color components in out_color_space */
  144833. int output_components; /* # of color components returned */
  144834. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144835. int actual_number_of_colors; /* number of entries in use */
  144836. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144837. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144838. int input_scan_number; /* Number of SOS markers seen so far */
  144839. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144840. int output_scan_number; /* Nominal scan number being displayed */
  144841. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144842. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144843. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144844. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144845. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144846. int data_precision; /* bits of precision in image data */
  144847. jpeg_component_info * comp_info;
  144848. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144849. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144850. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144851. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144852. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144853. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144854. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144855. UINT8 JFIF_major_version; /* JFIF version number */
  144856. UINT8 JFIF_minor_version;
  144857. UINT8 density_unit; /* JFIF code for pixel size units */
  144858. UINT16 X_density; /* Horizontal pixel density */
  144859. UINT16 Y_density; /* Vertical pixel density */
  144860. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144861. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144862. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144863. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144864. int max_h_samp_factor; /* largest h_samp_factor */
  144865. int max_v_samp_factor; /* largest v_samp_factor */
  144866. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144867. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144868. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144869. int comps_in_scan; /* # of JPEG components in this scan */
  144870. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144871. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144872. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144873. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144874. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144875. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144876. int unread_marker;
  144877. struct jpeg_decomp_master * master;
  144878. struct jpeg_d_main_controller * main;
  144879. struct jpeg_d_coef_controller * coef;
  144880. struct jpeg_d_post_controller * post;
  144881. struct jpeg_input_controller * inputctl;
  144882. struct jpeg_marker_reader * marker;
  144883. struct jpeg_entropy_decoder * entropy;
  144884. struct jpeg_inverse_dct * idct;
  144885. struct jpeg_upsampler * upsample;
  144886. struct jpeg_color_deconverter * cconvert;
  144887. struct jpeg_color_quantizer * cquantize;
  144888. };
  144889. struct jpeg_error_mgr {
  144890. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144891. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144892. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144893. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144894. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144895. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144896. int msg_code;
  144897. #define JMSG_STR_PARM_MAX 80
  144898. union {
  144899. int i[8];
  144900. char s[JMSG_STR_PARM_MAX];
  144901. } msg_parm;
  144902. int trace_level; /* max msg_level that will be displayed */
  144903. long num_warnings; /* number of corrupt-data warnings */
  144904. const char * const * jpeg_message_table; /* Library errors */
  144905. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144906. const char * const * addon_message_table; /* Non-library errors */
  144907. int first_addon_message; /* code for first string in addon table */
  144908. int last_addon_message; /* code for last string in addon table */
  144909. };
  144910. struct jpeg_progress_mgr {
  144911. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144912. long pass_counter; /* work units completed in this pass */
  144913. long pass_limit; /* total number of work units in this pass */
  144914. int completed_passes; /* passes completed so far */
  144915. int total_passes; /* total number of passes expected */
  144916. };
  144917. struct jpeg_destination_mgr {
  144918. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144919. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144920. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144921. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144922. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144923. };
  144924. struct jpeg_source_mgr {
  144925. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144926. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144927. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144928. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144929. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  144930. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  144931. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  144932. };
  144933. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  144934. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  144935. #define JPOOL_NUMPOOLS 2
  144936. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  144937. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  144938. struct jpeg_memory_mgr {
  144939. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  144940. size_t sizeofobject));
  144941. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  144942. size_t sizeofobject));
  144943. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  144944. JDIMENSION samplesperrow,
  144945. JDIMENSION numrows));
  144946. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  144947. JDIMENSION blocksperrow,
  144948. JDIMENSION numrows));
  144949. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  144950. int pool_id,
  144951. boolean pre_zero,
  144952. JDIMENSION samplesperrow,
  144953. JDIMENSION numrows,
  144954. JDIMENSION maxaccess));
  144955. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  144956. int pool_id,
  144957. boolean pre_zero,
  144958. JDIMENSION blocksperrow,
  144959. JDIMENSION numrows,
  144960. JDIMENSION maxaccess));
  144961. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  144962. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  144963. jvirt_sarray_ptr ptr,
  144964. JDIMENSION start_row,
  144965. JDIMENSION num_rows,
  144966. boolean writable));
  144967. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  144968. jvirt_barray_ptr ptr,
  144969. JDIMENSION start_row,
  144970. JDIMENSION num_rows,
  144971. boolean writable));
  144972. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  144973. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  144974. long max_memory_to_use;
  144975. long max_alloc_chunk;
  144976. };
  144977. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  144978. #ifdef HAVE_PROTOTYPES
  144979. #define JPP(arglist) arglist
  144980. #else
  144981. #define JPP(arglist) ()
  144982. #endif
  144983. #ifdef NEED_SHORT_EXTERNAL_NAMES
  144984. #define jpeg_std_error jStdError
  144985. #define jpeg_CreateCompress jCreaCompress
  144986. #define jpeg_CreateDecompress jCreaDecompress
  144987. #define jpeg_destroy_compress jDestCompress
  144988. #define jpeg_destroy_decompress jDestDecompress
  144989. #define jpeg_stdio_dest jStdDest
  144990. #define jpeg_stdio_src jStdSrc
  144991. #define jpeg_set_defaults jSetDefaults
  144992. #define jpeg_set_colorspace jSetColorspace
  144993. #define jpeg_default_colorspace jDefColorspace
  144994. #define jpeg_set_quality jSetQuality
  144995. #define jpeg_set_linear_quality jSetLQuality
  144996. #define jpeg_add_quant_table jAddQuantTable
  144997. #define jpeg_quality_scaling jQualityScaling
  144998. #define jpeg_simple_progression jSimProgress
  144999. #define jpeg_suppress_tables jSuppressTables
  145000. #define jpeg_alloc_quant_table jAlcQTable
  145001. #define jpeg_alloc_huff_table jAlcHTable
  145002. #define jpeg_start_compress jStrtCompress
  145003. #define jpeg_write_scanlines jWrtScanlines
  145004. #define jpeg_finish_compress jFinCompress
  145005. #define jpeg_write_raw_data jWrtRawData
  145006. #define jpeg_write_marker jWrtMarker
  145007. #define jpeg_write_m_header jWrtMHeader
  145008. #define jpeg_write_m_byte jWrtMByte
  145009. #define jpeg_write_tables jWrtTables
  145010. #define jpeg_read_header jReadHeader
  145011. #define jpeg_start_decompress jStrtDecompress
  145012. #define jpeg_read_scanlines jReadScanlines
  145013. #define jpeg_finish_decompress jFinDecompress
  145014. #define jpeg_read_raw_data jReadRawData
  145015. #define jpeg_has_multiple_scans jHasMultScn
  145016. #define jpeg_start_output jStrtOutput
  145017. #define jpeg_finish_output jFinOutput
  145018. #define jpeg_input_complete jInComplete
  145019. #define jpeg_new_colormap jNewCMap
  145020. #define jpeg_consume_input jConsumeInput
  145021. #define jpeg_calc_output_dimensions jCalcDimensions
  145022. #define jpeg_save_markers jSaveMarkers
  145023. #define jpeg_set_marker_processor jSetMarker
  145024. #define jpeg_read_coefficients jReadCoefs
  145025. #define jpeg_write_coefficients jWrtCoefs
  145026. #define jpeg_copy_critical_parameters jCopyCrit
  145027. #define jpeg_abort_compress jAbrtCompress
  145028. #define jpeg_abort_decompress jAbrtDecompress
  145029. #define jpeg_abort jAbort
  145030. #define jpeg_destroy jDestroy
  145031. #define jpeg_resync_to_restart jResyncRestart
  145032. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145033. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145034. JPP((struct jpeg_error_mgr * err));
  145035. #define jpeg_create_compress(cinfo) \
  145036. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145037. (size_t) sizeof(struct jpeg_compress_struct))
  145038. #define jpeg_create_decompress(cinfo) \
  145039. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145040. (size_t) sizeof(struct jpeg_decompress_struct))
  145041. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145042. int version, size_t structsize));
  145043. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145044. int version, size_t structsize));
  145045. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145046. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145047. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145048. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145049. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145050. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145051. J_COLOR_SPACE colorspace));
  145052. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145053. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145054. boolean force_baseline));
  145055. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145056. int scale_factor,
  145057. boolean force_baseline));
  145058. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145059. const unsigned int *basic_table,
  145060. int scale_factor,
  145061. boolean force_baseline));
  145062. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145063. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145064. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145065. boolean suppress));
  145066. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145067. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145068. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145069. boolean write_all_tables));
  145070. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145071. JSAMPARRAY scanlines,
  145072. JDIMENSION num_lines));
  145073. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145074. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145075. JSAMPIMAGE data,
  145076. JDIMENSION num_lines));
  145077. EXTERN(void) jpeg_write_marker
  145078. JPP((j_compress_ptr cinfo, int marker,
  145079. const JOCTET * dataptr, unsigned int datalen));
  145080. EXTERN(void) jpeg_write_m_header
  145081. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145082. EXTERN(void) jpeg_write_m_byte
  145083. JPP((j_compress_ptr cinfo, int val));
  145084. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145085. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145086. boolean require_image));
  145087. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145088. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145089. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145090. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145091. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145092. JSAMPARRAY scanlines,
  145093. JDIMENSION max_lines));
  145094. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145095. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145096. JSAMPIMAGE data,
  145097. JDIMENSION max_lines));
  145098. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145099. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145100. int scan_number));
  145101. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145102. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145103. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145104. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145105. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145106. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145107. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145108. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145109. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145110. EXTERN(void) jpeg_save_markers
  145111. JPP((j_decompress_ptr cinfo, int marker_code,
  145112. unsigned int length_limit));
  145113. EXTERN(void) jpeg_set_marker_processor
  145114. JPP((j_decompress_ptr cinfo, int marker_code,
  145115. jpeg_marker_parser_method routine));
  145116. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145117. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145118. jvirt_barray_ptr * coef_arrays));
  145119. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145120. j_compress_ptr dstinfo));
  145121. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145122. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145123. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145124. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145125. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145126. int desired));
  145127. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145128. #define JPEG_EOI 0xD9 /* EOI marker code */
  145129. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145130. #define JPEG_COM 0xFE /* COM marker code */
  145131. #ifdef INCOMPLETE_TYPES_BROKEN
  145132. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145133. struct jvirt_sarray_control { long dummy; };
  145134. struct jvirt_barray_control { long dummy; };
  145135. struct jpeg_comp_master { long dummy; };
  145136. struct jpeg_c_main_controller { long dummy; };
  145137. struct jpeg_c_prep_controller { long dummy; };
  145138. struct jpeg_c_coef_controller { long dummy; };
  145139. struct jpeg_marker_writer { long dummy; };
  145140. struct jpeg_color_converter { long dummy; };
  145141. struct jpeg_downsampler { long dummy; };
  145142. struct jpeg_forward_dct { long dummy; };
  145143. struct jpeg_entropy_encoder { long dummy; };
  145144. struct jpeg_decomp_master { long dummy; };
  145145. struct jpeg_d_main_controller { long dummy; };
  145146. struct jpeg_d_coef_controller { long dummy; };
  145147. struct jpeg_d_post_controller { long dummy; };
  145148. struct jpeg_input_controller { long dummy; };
  145149. struct jpeg_marker_reader { long dummy; };
  145150. struct jpeg_entropy_decoder { long dummy; };
  145151. struct jpeg_inverse_dct { long dummy; };
  145152. struct jpeg_upsampler { long dummy; };
  145153. struct jpeg_color_deconverter { long dummy; };
  145154. struct jpeg_color_quantizer { long dummy; };
  145155. #endif /* JPEG_INTERNALS */
  145156. #endif /* INCOMPLETE_TYPES_BROKEN */
  145157. #ifdef JPEG_INTERNALS
  145158. /*** Start of inlined file: jpegint.h ***/
  145159. typedef enum { /* Operating modes for buffer controllers */
  145160. JBUF_PASS_THRU, /* Plain stripwise operation */
  145161. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145162. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145163. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145164. } J_BUF_MODE;
  145165. #define CSTATE_START 100 /* after create_compress */
  145166. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145167. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145168. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145169. #define DSTATE_START 200 /* after create_decompress */
  145170. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145171. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145172. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145173. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145174. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145175. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145176. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145177. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145178. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145179. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145180. struct jpeg_comp_master {
  145181. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145182. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145183. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145184. boolean call_pass_startup; /* True if pass_startup must be called */
  145185. boolean is_last_pass; /* True during last pass */
  145186. };
  145187. struct jpeg_c_main_controller {
  145188. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145189. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145190. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145191. JDIMENSION in_rows_avail));
  145192. };
  145193. struct jpeg_c_prep_controller {
  145194. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145195. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145196. JSAMPARRAY input_buf,
  145197. JDIMENSION *in_row_ctr,
  145198. JDIMENSION in_rows_avail,
  145199. JSAMPIMAGE output_buf,
  145200. JDIMENSION *out_row_group_ctr,
  145201. JDIMENSION out_row_groups_avail));
  145202. };
  145203. struct jpeg_c_coef_controller {
  145204. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145205. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145206. JSAMPIMAGE input_buf));
  145207. };
  145208. struct jpeg_color_converter {
  145209. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145210. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145211. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145212. JDIMENSION output_row, int num_rows));
  145213. };
  145214. struct jpeg_downsampler {
  145215. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145216. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145217. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145218. JSAMPIMAGE output_buf,
  145219. JDIMENSION out_row_group_index));
  145220. boolean need_context_rows; /* TRUE if need rows above & below */
  145221. };
  145222. struct jpeg_forward_dct {
  145223. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145224. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145225. jpeg_component_info * compptr,
  145226. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145227. JDIMENSION start_row, JDIMENSION start_col,
  145228. JDIMENSION num_blocks));
  145229. };
  145230. struct jpeg_entropy_encoder {
  145231. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145232. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145233. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145234. };
  145235. struct jpeg_marker_writer {
  145236. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145237. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145238. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145239. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145240. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145241. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145242. unsigned int datalen));
  145243. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145244. };
  145245. struct jpeg_decomp_master {
  145246. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145247. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145248. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145249. };
  145250. struct jpeg_input_controller {
  145251. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145252. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145253. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145254. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145255. boolean has_multiple_scans; /* True if file has multiple scans */
  145256. boolean eoi_reached; /* True when EOI has been consumed */
  145257. };
  145258. struct jpeg_d_main_controller {
  145259. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145260. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145261. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145262. JDIMENSION out_rows_avail));
  145263. };
  145264. struct jpeg_d_coef_controller {
  145265. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145266. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145267. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145268. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145269. JSAMPIMAGE output_buf));
  145270. jvirt_barray_ptr *coef_arrays;
  145271. };
  145272. struct jpeg_d_post_controller {
  145273. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145274. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145275. JSAMPIMAGE input_buf,
  145276. JDIMENSION *in_row_group_ctr,
  145277. JDIMENSION in_row_groups_avail,
  145278. JSAMPARRAY output_buf,
  145279. JDIMENSION *out_row_ctr,
  145280. JDIMENSION out_rows_avail));
  145281. };
  145282. struct jpeg_marker_reader {
  145283. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145284. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145285. jpeg_marker_parser_method read_restart_marker;
  145286. boolean saw_SOI; /* found SOI? */
  145287. boolean saw_SOF; /* found SOF? */
  145288. int next_restart_num; /* next restart number expected (0-7) */
  145289. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145290. };
  145291. struct jpeg_entropy_decoder {
  145292. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145293. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145294. JBLOCKROW *MCU_data));
  145295. boolean insufficient_data; /* set TRUE after emitting warning */
  145296. };
  145297. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145298. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145299. JCOEFPTR coef_block,
  145300. JSAMPARRAY output_buf, JDIMENSION output_col));
  145301. struct jpeg_inverse_dct {
  145302. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145303. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145304. };
  145305. struct jpeg_upsampler {
  145306. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145307. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145308. JSAMPIMAGE input_buf,
  145309. JDIMENSION *in_row_group_ctr,
  145310. JDIMENSION in_row_groups_avail,
  145311. JSAMPARRAY output_buf,
  145312. JDIMENSION *out_row_ctr,
  145313. JDIMENSION out_rows_avail));
  145314. boolean need_context_rows; /* TRUE if need rows above & below */
  145315. };
  145316. struct jpeg_color_deconverter {
  145317. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145318. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145319. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145320. JSAMPARRAY output_buf, int num_rows));
  145321. };
  145322. struct jpeg_color_quantizer {
  145323. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145324. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145325. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145326. int num_rows));
  145327. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145328. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145329. };
  145330. #undef MAX
  145331. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145332. #undef MIN
  145333. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145334. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145335. #define SHIFT_TEMPS INT32 shift_temp;
  145336. #define RIGHT_SHIFT(x,shft) \
  145337. ((shift_temp = (x)) < 0 ? \
  145338. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145339. (shift_temp >> (shft)))
  145340. #else
  145341. #define SHIFT_TEMPS
  145342. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145343. #endif
  145344. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145345. #define jinit_compress_master jICompress
  145346. #define jinit_c_master_control jICMaster
  145347. #define jinit_c_main_controller jICMainC
  145348. #define jinit_c_prep_controller jICPrepC
  145349. #define jinit_c_coef_controller jICCoefC
  145350. #define jinit_color_converter jICColor
  145351. #define jinit_downsampler jIDownsampler
  145352. #define jinit_forward_dct jIFDCT
  145353. #define jinit_huff_encoder jIHEncoder
  145354. #define jinit_phuff_encoder jIPHEncoder
  145355. #define jinit_marker_writer jIMWriter
  145356. #define jinit_master_decompress jIDMaster
  145357. #define jinit_d_main_controller jIDMainC
  145358. #define jinit_d_coef_controller jIDCoefC
  145359. #define jinit_d_post_controller jIDPostC
  145360. #define jinit_input_controller jIInCtlr
  145361. #define jinit_marker_reader jIMReader
  145362. #define jinit_huff_decoder jIHDecoder
  145363. #define jinit_phuff_decoder jIPHDecoder
  145364. #define jinit_inverse_dct jIIDCT
  145365. #define jinit_upsampler jIUpsampler
  145366. #define jinit_color_deconverter jIDColor
  145367. #define jinit_1pass_quantizer jI1Quant
  145368. #define jinit_2pass_quantizer jI2Quant
  145369. #define jinit_merged_upsampler jIMUpsampler
  145370. #define jinit_memory_mgr jIMemMgr
  145371. #define jdiv_round_up jDivRound
  145372. #define jround_up jRound
  145373. #define jcopy_sample_rows jCopySamples
  145374. #define jcopy_block_row jCopyBlocks
  145375. #define jzero_far jZeroFar
  145376. #define jpeg_zigzag_order jZIGTable
  145377. #define jpeg_natural_order jZAGTable
  145378. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145379. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145380. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145381. boolean transcode_only));
  145382. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145383. boolean need_full_buffer));
  145384. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145385. boolean need_full_buffer));
  145386. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145387. boolean need_full_buffer));
  145388. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145389. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145390. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145391. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145392. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145393. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145394. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145395. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145396. boolean need_full_buffer));
  145397. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145398. boolean need_full_buffer));
  145399. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145400. boolean need_full_buffer));
  145401. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145402. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145403. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145404. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145405. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145406. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145407. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145408. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145409. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145410. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145411. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145412. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145413. EXTERN(long) jround_up JPP((long a, long b));
  145414. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145415. JSAMPARRAY output_array, int dest_row,
  145416. int num_rows, JDIMENSION num_cols));
  145417. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145418. JDIMENSION num_blocks));
  145419. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145420. #if 0 /* This table is not actually needed in v6a */
  145421. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145422. #endif
  145423. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145424. #ifdef INCOMPLETE_TYPES_BROKEN
  145425. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145426. struct jvirt_sarray_control { long dummy; };
  145427. struct jvirt_barray_control { long dummy; };
  145428. #endif
  145429. #endif /* INCOMPLETE_TYPES_BROKEN */
  145430. /*** End of inlined file: jpegint.h ***/
  145431. /* fetch private declarations */
  145432. /*** Start of inlined file: jerror.h ***/
  145433. #ifndef JMESSAGE
  145434. #ifndef JERROR_H
  145435. #define JMAKE_ENUM_LIST
  145436. #else
  145437. #define JMESSAGE(code,string)
  145438. #endif /* JERROR_H */
  145439. #endif /* JMESSAGE */
  145440. #ifdef JMAKE_ENUM_LIST
  145441. typedef enum {
  145442. #define JMESSAGE(code,string) code ,
  145443. #endif /* JMAKE_ENUM_LIST */
  145444. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145445. JMESSAGE(JERR_ARITH_NOTIMPL,
  145446. "Sorry, there are legal restrictions on arithmetic coding")
  145447. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145448. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145449. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145450. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145451. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145452. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145453. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145454. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145455. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145456. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145457. JMESSAGE(JERR_BAD_LIB_VERSION,
  145458. "Wrong JPEG library version: library is %d, caller expects %d")
  145459. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145460. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145461. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145462. JMESSAGE(JERR_BAD_PROGRESSION,
  145463. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145464. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145465. "Invalid progressive parameters at scan script entry %d")
  145466. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145467. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145468. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145469. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145470. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145471. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145472. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145473. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145474. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145475. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145476. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145477. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145478. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145479. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145480. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145481. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145482. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145483. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145484. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145485. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145486. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145487. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145488. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145489. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145490. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145491. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145492. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145493. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145494. "Cannot transcode due to multiple use of quantization table %d")
  145495. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145496. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145497. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145498. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145499. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145500. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145501. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145502. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145503. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145504. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145505. JMESSAGE(JERR_QUANT_COMPONENTS,
  145506. "Cannot quantize more than %d color components")
  145507. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145508. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145509. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145510. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145511. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145512. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145513. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145514. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145515. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145516. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145517. JMESSAGE(JERR_TFILE_WRITE,
  145518. "Write failed on temporary file --- out of disk space?")
  145519. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145520. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145521. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145522. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145523. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145524. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145525. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145526. JMESSAGE(JMSG_VERSION, JVERSION)
  145527. JMESSAGE(JTRC_16BIT_TABLES,
  145528. "Caution: quantization tables are too coarse for baseline JPEG")
  145529. JMESSAGE(JTRC_ADOBE,
  145530. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145531. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145532. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145533. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145534. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145535. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145536. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145537. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145538. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145539. JMESSAGE(JTRC_EOI, "End Of Image")
  145540. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145541. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145542. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145543. "Warning: thumbnail image size does not match data length %u")
  145544. JMESSAGE(JTRC_JFIF_EXTENSION,
  145545. "JFIF extension marker: type 0x%02x, length %u")
  145546. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145547. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145548. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145549. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145550. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145551. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145552. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145553. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145554. JMESSAGE(JTRC_RST, "RST%d")
  145555. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145556. "Smoothing not supported with nonstandard sampling ratios")
  145557. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145558. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145559. JMESSAGE(JTRC_SOI, "Start of Image")
  145560. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145561. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145562. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145563. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145564. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145565. JMESSAGE(JTRC_THUMB_JPEG,
  145566. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145567. JMESSAGE(JTRC_THUMB_PALETTE,
  145568. "JFIF extension marker: palette thumbnail image, length %u")
  145569. JMESSAGE(JTRC_THUMB_RGB,
  145570. "JFIF extension marker: RGB thumbnail image, length %u")
  145571. JMESSAGE(JTRC_UNKNOWN_IDS,
  145572. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145573. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145574. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145575. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145576. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145577. "Inconsistent progression sequence for component %d coefficient %d")
  145578. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145579. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145580. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145581. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145582. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145583. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145584. JMESSAGE(JWRN_MUST_RESYNC,
  145585. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145586. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145587. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145588. #ifdef JMAKE_ENUM_LIST
  145589. JMSG_LASTMSGCODE
  145590. } J_MESSAGE_CODE;
  145591. #undef JMAKE_ENUM_LIST
  145592. #endif /* JMAKE_ENUM_LIST */
  145593. #undef JMESSAGE
  145594. #ifndef JERROR_H
  145595. #define JERROR_H
  145596. #define ERREXIT(cinfo,code) \
  145597. ((cinfo)->err->msg_code = (code), \
  145598. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145599. #define ERREXIT1(cinfo,code,p1) \
  145600. ((cinfo)->err->msg_code = (code), \
  145601. (cinfo)->err->msg_parm.i[0] = (p1), \
  145602. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145603. #define ERREXIT2(cinfo,code,p1,p2) \
  145604. ((cinfo)->err->msg_code = (code), \
  145605. (cinfo)->err->msg_parm.i[0] = (p1), \
  145606. (cinfo)->err->msg_parm.i[1] = (p2), \
  145607. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145608. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145609. ((cinfo)->err->msg_code = (code), \
  145610. (cinfo)->err->msg_parm.i[0] = (p1), \
  145611. (cinfo)->err->msg_parm.i[1] = (p2), \
  145612. (cinfo)->err->msg_parm.i[2] = (p3), \
  145613. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145614. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145615. ((cinfo)->err->msg_code = (code), \
  145616. (cinfo)->err->msg_parm.i[0] = (p1), \
  145617. (cinfo)->err->msg_parm.i[1] = (p2), \
  145618. (cinfo)->err->msg_parm.i[2] = (p3), \
  145619. (cinfo)->err->msg_parm.i[3] = (p4), \
  145620. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145621. #define ERREXITS(cinfo,code,str) \
  145622. ((cinfo)->err->msg_code = (code), \
  145623. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145624. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145625. #define MAKESTMT(stuff) do { stuff } while (0)
  145626. #define WARNMS(cinfo,code) \
  145627. ((cinfo)->err->msg_code = (code), \
  145628. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145629. #define WARNMS1(cinfo,code,p1) \
  145630. ((cinfo)->err->msg_code = (code), \
  145631. (cinfo)->err->msg_parm.i[0] = (p1), \
  145632. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145633. #define WARNMS2(cinfo,code,p1,p2) \
  145634. ((cinfo)->err->msg_code = (code), \
  145635. (cinfo)->err->msg_parm.i[0] = (p1), \
  145636. (cinfo)->err->msg_parm.i[1] = (p2), \
  145637. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145638. #define TRACEMS(cinfo,lvl,code) \
  145639. ((cinfo)->err->msg_code = (code), \
  145640. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145641. #define TRACEMS1(cinfo,lvl,code,p1) \
  145642. ((cinfo)->err->msg_code = (code), \
  145643. (cinfo)->err->msg_parm.i[0] = (p1), \
  145644. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145645. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145646. ((cinfo)->err->msg_code = (code), \
  145647. (cinfo)->err->msg_parm.i[0] = (p1), \
  145648. (cinfo)->err->msg_parm.i[1] = (p2), \
  145649. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145650. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145651. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145652. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145653. (cinfo)->err->msg_code = (code); \
  145654. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145655. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145656. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145657. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145658. (cinfo)->err->msg_code = (code); \
  145659. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145660. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145661. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145662. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145663. _mp[4] = (p5); \
  145664. (cinfo)->err->msg_code = (code); \
  145665. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145666. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145667. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145668. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145669. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145670. (cinfo)->err->msg_code = (code); \
  145671. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145672. #define TRACEMSS(cinfo,lvl,code,str) \
  145673. ((cinfo)->err->msg_code = (code), \
  145674. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145675. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145676. #endif /* JERROR_H */
  145677. /*** End of inlined file: jerror.h ***/
  145678. /* fetch error codes too */
  145679. #endif
  145680. #endif /* JPEGLIB_H */
  145681. /*** End of inlined file: jpeglib.h ***/
  145682. /*** Start of inlined file: jcapimin.c ***/
  145683. #define JPEG_INTERNALS
  145684. /*** Start of inlined file: jinclude.h ***/
  145685. #ifndef __jinclude_h__
  145686. #define __jinclude_h__
  145687. /*** Start of inlined file: jconfig.h ***/
  145688. // disable all the warnings under MSVC
  145689. #ifdef _MSC_VER
  145690. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145691. #endif
  145692. #ifdef __BORLANDC__
  145693. #pragma warn -8057
  145694. #pragma warn -8019
  145695. #pragma warn -8004
  145696. #pragma warn -8008
  145697. #endif
  145698. #define HAVE_PROTOTYPES
  145699. #define HAVE_UNSIGNED_CHAR
  145700. #define HAVE_UNSIGNED_SHORT
  145701. #undef CHAR_IS_UNSIGNED
  145702. #define HAVE_STDDEF_H
  145703. #define HAVE_STDLIB_H
  145704. #undef NEED_BSD_STRINGS
  145705. #undef NEED_SYS_TYPES_H
  145706. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145707. #undef NEED_SHORT_EXTERNAL_NAMES
  145708. #undef INCOMPLETE_TYPES_BROKEN
  145709. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145710. typedef unsigned char boolean;
  145711. #endif
  145712. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145713. #ifdef JPEG_INTERNALS
  145714. #undef RIGHT_SHIFT_IS_UNSIGNED
  145715. #endif /* JPEG_INTERNALS */
  145716. #ifdef JPEG_CJPEG_DJPEG
  145717. #define BMP_SUPPORTED /* BMP image file format */
  145718. #define GIF_SUPPORTED /* GIF image file format */
  145719. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145720. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145721. #define TARGA_SUPPORTED /* Targa image file format */
  145722. #define TWO_FILE_COMMANDLINE /* optional */
  145723. #define USE_SETMODE /* Microsoft has setmode() */
  145724. #undef NEED_SIGNAL_CATCHER
  145725. #undef DONT_USE_B_MODE
  145726. #undef PROGRESS_REPORT /* optional */
  145727. #endif /* JPEG_CJPEG_DJPEG */
  145728. /*** End of inlined file: jconfig.h ***/
  145729. /* auto configuration options */
  145730. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145731. #ifdef HAVE_STDDEF_H
  145732. #include <stddef.h>
  145733. #endif
  145734. #ifdef HAVE_STDLIB_H
  145735. #include <stdlib.h>
  145736. #endif
  145737. #ifdef NEED_SYS_TYPES_H
  145738. #include <sys/types.h>
  145739. #endif
  145740. #include <stdio.h>
  145741. #ifdef NEED_BSD_STRINGS
  145742. #include <strings.h>
  145743. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145744. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145745. #else /* not BSD, assume ANSI/SysV string lib */
  145746. #include <string.h>
  145747. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145748. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145749. #endif
  145750. #define SIZEOF(object) ((size_t) sizeof(object))
  145751. #define JFREAD(file,buf,sizeofbuf) \
  145752. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145753. #define JFWRITE(file,buf,sizeofbuf) \
  145754. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145755. typedef enum { /* JPEG marker codes */
  145756. M_SOF0 = 0xc0,
  145757. M_SOF1 = 0xc1,
  145758. M_SOF2 = 0xc2,
  145759. M_SOF3 = 0xc3,
  145760. M_SOF5 = 0xc5,
  145761. M_SOF6 = 0xc6,
  145762. M_SOF7 = 0xc7,
  145763. M_JPG = 0xc8,
  145764. M_SOF9 = 0xc9,
  145765. M_SOF10 = 0xca,
  145766. M_SOF11 = 0xcb,
  145767. M_SOF13 = 0xcd,
  145768. M_SOF14 = 0xce,
  145769. M_SOF15 = 0xcf,
  145770. M_DHT = 0xc4,
  145771. M_DAC = 0xcc,
  145772. M_RST0 = 0xd0,
  145773. M_RST1 = 0xd1,
  145774. M_RST2 = 0xd2,
  145775. M_RST3 = 0xd3,
  145776. M_RST4 = 0xd4,
  145777. M_RST5 = 0xd5,
  145778. M_RST6 = 0xd6,
  145779. M_RST7 = 0xd7,
  145780. M_SOI = 0xd8,
  145781. M_EOI = 0xd9,
  145782. M_SOS = 0xda,
  145783. M_DQT = 0xdb,
  145784. M_DNL = 0xdc,
  145785. M_DRI = 0xdd,
  145786. M_DHP = 0xde,
  145787. M_EXP = 0xdf,
  145788. M_APP0 = 0xe0,
  145789. M_APP1 = 0xe1,
  145790. M_APP2 = 0xe2,
  145791. M_APP3 = 0xe3,
  145792. M_APP4 = 0xe4,
  145793. M_APP5 = 0xe5,
  145794. M_APP6 = 0xe6,
  145795. M_APP7 = 0xe7,
  145796. M_APP8 = 0xe8,
  145797. M_APP9 = 0xe9,
  145798. M_APP10 = 0xea,
  145799. M_APP11 = 0xeb,
  145800. M_APP12 = 0xec,
  145801. M_APP13 = 0xed,
  145802. M_APP14 = 0xee,
  145803. M_APP15 = 0xef,
  145804. M_JPG0 = 0xf0,
  145805. M_JPG13 = 0xfd,
  145806. M_COM = 0xfe,
  145807. M_TEM = 0x01,
  145808. M_ERROR = 0x100
  145809. } JPEG_MARKER;
  145810. #ifdef AVOID_TABLES
  145811. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145812. #else
  145813. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145814. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145815. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145816. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145817. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145818. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145819. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145820. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145821. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145822. #endif /* AVOID_TABLES */
  145823. #endif
  145824. /*** End of inlined file: jinclude.h ***/
  145825. GLOBAL(void)
  145826. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145827. {
  145828. int i;
  145829. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145830. if (version != JPEG_LIB_VERSION)
  145831. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145832. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145833. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145834. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145835. {
  145836. struct jpeg_error_mgr * err = cinfo->err;
  145837. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145838. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145839. cinfo->err = err;
  145840. cinfo->client_data = client_data;
  145841. }
  145842. cinfo->is_decompressor = FALSE;
  145843. jinit_memory_mgr((j_common_ptr) cinfo);
  145844. cinfo->progress = NULL;
  145845. cinfo->dest = NULL;
  145846. cinfo->comp_info = NULL;
  145847. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145848. cinfo->quant_tbl_ptrs[i] = NULL;
  145849. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145850. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145851. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145852. }
  145853. cinfo->script_space = NULL;
  145854. cinfo->input_gamma = 1.0; /* in case application forgets */
  145855. cinfo->global_state = CSTATE_START;
  145856. }
  145857. GLOBAL(void)
  145858. jpeg_destroy_compress (j_compress_ptr cinfo)
  145859. {
  145860. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145861. }
  145862. GLOBAL(void)
  145863. jpeg_abort_compress (j_compress_ptr cinfo)
  145864. {
  145865. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145866. }
  145867. GLOBAL(void)
  145868. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145869. {
  145870. int i;
  145871. JQUANT_TBL * qtbl;
  145872. JHUFF_TBL * htbl;
  145873. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145874. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145875. qtbl->sent_table = suppress;
  145876. }
  145877. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145878. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145879. htbl->sent_table = suppress;
  145880. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145881. htbl->sent_table = suppress;
  145882. }
  145883. }
  145884. GLOBAL(void)
  145885. jpeg_finish_compress (j_compress_ptr cinfo)
  145886. {
  145887. JDIMENSION iMCU_row;
  145888. if (cinfo->global_state == CSTATE_SCANNING ||
  145889. cinfo->global_state == CSTATE_RAW_OK) {
  145890. if (cinfo->next_scanline < cinfo->image_height)
  145891. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145892. (*cinfo->master->finish_pass) (cinfo);
  145893. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145894. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145895. while (! cinfo->master->is_last_pass) {
  145896. (*cinfo->master->prepare_for_pass) (cinfo);
  145897. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145898. if (cinfo->progress != NULL) {
  145899. cinfo->progress->pass_counter = (long) iMCU_row;
  145900. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145901. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145902. }
  145903. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145904. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145905. }
  145906. (*cinfo->master->finish_pass) (cinfo);
  145907. }
  145908. (*cinfo->marker->write_file_trailer) (cinfo);
  145909. (*cinfo->dest->term_destination) (cinfo);
  145910. jpeg_abort((j_common_ptr) cinfo);
  145911. }
  145912. GLOBAL(void)
  145913. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145914. const JOCTET *dataptr, unsigned int datalen)
  145915. {
  145916. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145917. if (cinfo->next_scanline != 0 ||
  145918. (cinfo->global_state != CSTATE_SCANNING &&
  145919. cinfo->global_state != CSTATE_RAW_OK &&
  145920. cinfo->global_state != CSTATE_WRCOEFS))
  145921. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145922. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145923. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145924. while (datalen--) {
  145925. (*write_marker_byte) (cinfo, *dataptr);
  145926. dataptr++;
  145927. }
  145928. }
  145929. GLOBAL(void)
  145930. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  145931. {
  145932. if (cinfo->next_scanline != 0 ||
  145933. (cinfo->global_state != CSTATE_SCANNING &&
  145934. cinfo->global_state != CSTATE_RAW_OK &&
  145935. cinfo->global_state != CSTATE_WRCOEFS))
  145936. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145937. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145938. }
  145939. GLOBAL(void)
  145940. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  145941. {
  145942. (*cinfo->marker->write_marker_byte) (cinfo, val);
  145943. }
  145944. GLOBAL(void)
  145945. jpeg_write_tables (j_compress_ptr cinfo)
  145946. {
  145947. if (cinfo->global_state != CSTATE_START)
  145948. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145949. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145950. (*cinfo->dest->init_destination) (cinfo);
  145951. jinit_marker_writer(cinfo);
  145952. (*cinfo->marker->write_tables_only) (cinfo);
  145953. (*cinfo->dest->term_destination) (cinfo);
  145954. }
  145955. /*** End of inlined file: jcapimin.c ***/
  145956. /*** Start of inlined file: jcapistd.c ***/
  145957. #define JPEG_INTERNALS
  145958. GLOBAL(void)
  145959. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  145960. {
  145961. if (cinfo->global_state != CSTATE_START)
  145962. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145963. if (write_all_tables)
  145964. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  145965. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145966. (*cinfo->dest->init_destination) (cinfo);
  145967. jinit_compress_master(cinfo);
  145968. (*cinfo->master->prepare_for_pass) (cinfo);
  145969. cinfo->next_scanline = 0;
  145970. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  145971. }
  145972. GLOBAL(JDIMENSION)
  145973. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  145974. JDIMENSION num_lines)
  145975. {
  145976. JDIMENSION row_ctr, rows_left;
  145977. if (cinfo->global_state != CSTATE_SCANNING)
  145978. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145979. if (cinfo->next_scanline >= cinfo->image_height)
  145980. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145981. if (cinfo->progress != NULL) {
  145982. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145983. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145984. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145985. }
  145986. if (cinfo->master->call_pass_startup)
  145987. (*cinfo->master->pass_startup) (cinfo);
  145988. rows_left = cinfo->image_height - cinfo->next_scanline;
  145989. if (num_lines > rows_left)
  145990. num_lines = rows_left;
  145991. row_ctr = 0;
  145992. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  145993. cinfo->next_scanline += row_ctr;
  145994. return row_ctr;
  145995. }
  145996. GLOBAL(JDIMENSION)
  145997. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  145998. JDIMENSION num_lines)
  145999. {
  146000. JDIMENSION lines_per_iMCU_row;
  146001. if (cinfo->global_state != CSTATE_RAW_OK)
  146002. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146003. if (cinfo->next_scanline >= cinfo->image_height) {
  146004. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146005. return 0;
  146006. }
  146007. if (cinfo->progress != NULL) {
  146008. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146009. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146010. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146011. }
  146012. if (cinfo->master->call_pass_startup)
  146013. (*cinfo->master->pass_startup) (cinfo);
  146014. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146015. if (num_lines < lines_per_iMCU_row)
  146016. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146017. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146018. return 0;
  146019. }
  146020. cinfo->next_scanline += lines_per_iMCU_row;
  146021. return lines_per_iMCU_row;
  146022. }
  146023. /*** End of inlined file: jcapistd.c ***/
  146024. /*** Start of inlined file: jccoefct.c ***/
  146025. #define JPEG_INTERNALS
  146026. #ifdef ENTROPY_OPT_SUPPORTED
  146027. #define FULL_COEF_BUFFER_SUPPORTED
  146028. #else
  146029. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146030. #define FULL_COEF_BUFFER_SUPPORTED
  146031. #endif
  146032. #endif
  146033. typedef struct {
  146034. struct jpeg_c_coef_controller pub; /* public fields */
  146035. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146036. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146037. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146038. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146039. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146040. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146041. } my_coef_controller;
  146042. typedef my_coef_controller * my_coef_ptr;
  146043. METHODDEF(boolean) compress_data
  146044. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146045. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146046. METHODDEF(boolean) compress_first_pass
  146047. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146048. METHODDEF(boolean) compress_output
  146049. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146050. #endif
  146051. LOCAL(void)
  146052. start_iMCU_row (j_compress_ptr cinfo)
  146053. {
  146054. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146055. if (cinfo->comps_in_scan > 1) {
  146056. coef->MCU_rows_per_iMCU_row = 1;
  146057. } else {
  146058. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146059. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146060. else
  146061. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146062. }
  146063. coef->mcu_ctr = 0;
  146064. coef->MCU_vert_offset = 0;
  146065. }
  146066. METHODDEF(void)
  146067. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146068. {
  146069. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146070. coef->iMCU_row_num = 0;
  146071. start_iMCU_row(cinfo);
  146072. switch (pass_mode) {
  146073. case JBUF_PASS_THRU:
  146074. if (coef->whole_image[0] != NULL)
  146075. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146076. coef->pub.compress_data = compress_data;
  146077. break;
  146078. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146079. case JBUF_SAVE_AND_PASS:
  146080. if (coef->whole_image[0] == NULL)
  146081. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146082. coef->pub.compress_data = compress_first_pass;
  146083. break;
  146084. case JBUF_CRANK_DEST:
  146085. if (coef->whole_image[0] == NULL)
  146086. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146087. coef->pub.compress_data = compress_output;
  146088. break;
  146089. #endif
  146090. default:
  146091. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146092. break;
  146093. }
  146094. }
  146095. METHODDEF(boolean)
  146096. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146097. {
  146098. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146099. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146100. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146101. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146102. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146103. JDIMENSION ypos, xpos;
  146104. jpeg_component_info *compptr;
  146105. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146106. yoffset++) {
  146107. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146108. MCU_col_num++) {
  146109. blkn = 0;
  146110. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146111. compptr = cinfo->cur_comp_info[ci];
  146112. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146113. : compptr->last_col_width;
  146114. xpos = MCU_col_num * compptr->MCU_sample_width;
  146115. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146116. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146117. if (coef->iMCU_row_num < last_iMCU_row ||
  146118. yoffset+yindex < compptr->last_row_height) {
  146119. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146120. input_buf[compptr->component_index],
  146121. coef->MCU_buffer[blkn],
  146122. ypos, xpos, (JDIMENSION) blockcnt);
  146123. if (blockcnt < compptr->MCU_width) {
  146124. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146125. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146126. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146127. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146128. }
  146129. }
  146130. } else {
  146131. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146132. compptr->MCU_width * SIZEOF(JBLOCK));
  146133. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146134. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146135. }
  146136. }
  146137. blkn += compptr->MCU_width;
  146138. ypos += DCTSIZE;
  146139. }
  146140. }
  146141. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146142. coef->MCU_vert_offset = yoffset;
  146143. coef->mcu_ctr = MCU_col_num;
  146144. return FALSE;
  146145. }
  146146. }
  146147. coef->mcu_ctr = 0;
  146148. }
  146149. coef->iMCU_row_num++;
  146150. start_iMCU_row(cinfo);
  146151. return TRUE;
  146152. }
  146153. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146154. METHODDEF(boolean)
  146155. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146156. {
  146157. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146158. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146159. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146160. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146161. JCOEF lastDC;
  146162. jpeg_component_info *compptr;
  146163. JBLOCKARRAY buffer;
  146164. JBLOCKROW thisblockrow, lastblockrow;
  146165. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146166. ci++, compptr++) {
  146167. buffer = (*cinfo->mem->access_virt_barray)
  146168. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146169. coef->iMCU_row_num * compptr->v_samp_factor,
  146170. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146171. if (coef->iMCU_row_num < last_iMCU_row)
  146172. block_rows = compptr->v_samp_factor;
  146173. else {
  146174. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146175. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146176. }
  146177. blocks_across = compptr->width_in_blocks;
  146178. h_samp_factor = compptr->h_samp_factor;
  146179. ndummy = (int) (blocks_across % h_samp_factor);
  146180. if (ndummy > 0)
  146181. ndummy = h_samp_factor - ndummy;
  146182. for (block_row = 0; block_row < block_rows; block_row++) {
  146183. thisblockrow = buffer[block_row];
  146184. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146185. input_buf[ci], thisblockrow,
  146186. (JDIMENSION) (block_row * DCTSIZE),
  146187. (JDIMENSION) 0, blocks_across);
  146188. if (ndummy > 0) {
  146189. thisblockrow += blocks_across; /* => first dummy block */
  146190. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146191. lastDC = thisblockrow[-1][0];
  146192. for (bi = 0; bi < ndummy; bi++) {
  146193. thisblockrow[bi][0] = lastDC;
  146194. }
  146195. }
  146196. }
  146197. if (coef->iMCU_row_num == last_iMCU_row) {
  146198. blocks_across += ndummy; /* include lower right corner */
  146199. MCUs_across = blocks_across / h_samp_factor;
  146200. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146201. block_row++) {
  146202. thisblockrow = buffer[block_row];
  146203. lastblockrow = buffer[block_row-1];
  146204. jzero_far((void FAR *) thisblockrow,
  146205. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146206. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146207. lastDC = lastblockrow[h_samp_factor-1][0];
  146208. for (bi = 0; bi < h_samp_factor; bi++) {
  146209. thisblockrow[bi][0] = lastDC;
  146210. }
  146211. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146212. lastblockrow += h_samp_factor;
  146213. }
  146214. }
  146215. }
  146216. }
  146217. return compress_output(cinfo, input_buf);
  146218. }
  146219. METHODDEF(boolean)
  146220. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146221. {
  146222. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146223. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146224. int blkn, ci, xindex, yindex, yoffset;
  146225. JDIMENSION start_col;
  146226. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146227. JBLOCKROW buffer_ptr;
  146228. jpeg_component_info *compptr;
  146229. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146230. compptr = cinfo->cur_comp_info[ci];
  146231. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146232. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146233. coef->iMCU_row_num * compptr->v_samp_factor,
  146234. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146235. }
  146236. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146237. yoffset++) {
  146238. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146239. MCU_col_num++) {
  146240. blkn = 0; /* index of current DCT block within MCU */
  146241. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146242. compptr = cinfo->cur_comp_info[ci];
  146243. start_col = MCU_col_num * compptr->MCU_width;
  146244. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146245. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146246. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146247. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146248. }
  146249. }
  146250. }
  146251. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146252. coef->MCU_vert_offset = yoffset;
  146253. coef->mcu_ctr = MCU_col_num;
  146254. return FALSE;
  146255. }
  146256. }
  146257. coef->mcu_ctr = 0;
  146258. }
  146259. coef->iMCU_row_num++;
  146260. start_iMCU_row(cinfo);
  146261. return TRUE;
  146262. }
  146263. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146264. GLOBAL(void)
  146265. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146266. {
  146267. my_coef_ptr coef;
  146268. coef = (my_coef_ptr)
  146269. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146270. SIZEOF(my_coef_controller));
  146271. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146272. coef->pub.start_pass = start_pass_coef;
  146273. if (need_full_buffer) {
  146274. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146275. int ci;
  146276. jpeg_component_info *compptr;
  146277. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146278. ci++, compptr++) {
  146279. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146280. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146281. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146282. (long) compptr->h_samp_factor),
  146283. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146284. (long) compptr->v_samp_factor),
  146285. (JDIMENSION) compptr->v_samp_factor);
  146286. }
  146287. #else
  146288. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146289. #endif
  146290. } else {
  146291. JBLOCKROW buffer;
  146292. int i;
  146293. buffer = (JBLOCKROW)
  146294. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146295. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146296. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146297. coef->MCU_buffer[i] = buffer + i;
  146298. }
  146299. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146300. }
  146301. }
  146302. /*** End of inlined file: jccoefct.c ***/
  146303. /*** Start of inlined file: jccolor.c ***/
  146304. #define JPEG_INTERNALS
  146305. typedef struct {
  146306. struct jpeg_color_converter pub; /* public fields */
  146307. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146308. } my_color_converter;
  146309. typedef my_color_converter * my_cconvert_ptr;
  146310. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146311. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146312. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146313. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146314. #define R_Y_OFF 0 /* offset to R => Y section */
  146315. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146316. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146317. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146318. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146319. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146320. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146321. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146322. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146323. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146324. METHODDEF(void)
  146325. rgb_ycc_start (j_compress_ptr cinfo)
  146326. {
  146327. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146328. INT32 * rgb_ycc_tab;
  146329. INT32 i;
  146330. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146331. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146332. (TABLE_SIZE * SIZEOF(INT32)));
  146333. for (i = 0; i <= MAXJSAMPLE; i++) {
  146334. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146335. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146336. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146337. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146338. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146339. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146340. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146341. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146342. }
  146343. }
  146344. METHODDEF(void)
  146345. rgb_ycc_convert (j_compress_ptr cinfo,
  146346. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146347. JDIMENSION output_row, int num_rows)
  146348. {
  146349. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146350. register int r, g, b;
  146351. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146352. register JSAMPROW inptr;
  146353. register JSAMPROW outptr0, outptr1, outptr2;
  146354. register JDIMENSION col;
  146355. JDIMENSION num_cols = cinfo->image_width;
  146356. while (--num_rows >= 0) {
  146357. inptr = *input_buf++;
  146358. outptr0 = output_buf[0][output_row];
  146359. outptr1 = output_buf[1][output_row];
  146360. outptr2 = output_buf[2][output_row];
  146361. output_row++;
  146362. for (col = 0; col < num_cols; col++) {
  146363. r = GETJSAMPLE(inptr[RGB_RED]);
  146364. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146365. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146366. inptr += RGB_PIXELSIZE;
  146367. outptr0[col] = (JSAMPLE)
  146368. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146369. >> SCALEBITS);
  146370. outptr1[col] = (JSAMPLE)
  146371. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146372. >> SCALEBITS);
  146373. outptr2[col] = (JSAMPLE)
  146374. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146375. >> SCALEBITS);
  146376. }
  146377. }
  146378. }
  146379. METHODDEF(void)
  146380. rgb_gray_convert (j_compress_ptr cinfo,
  146381. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146382. JDIMENSION output_row, int num_rows)
  146383. {
  146384. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146385. register int r, g, b;
  146386. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146387. register JSAMPROW inptr;
  146388. register JSAMPROW outptr;
  146389. register JDIMENSION col;
  146390. JDIMENSION num_cols = cinfo->image_width;
  146391. while (--num_rows >= 0) {
  146392. inptr = *input_buf++;
  146393. outptr = output_buf[0][output_row];
  146394. output_row++;
  146395. for (col = 0; col < num_cols; col++) {
  146396. r = GETJSAMPLE(inptr[RGB_RED]);
  146397. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146398. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146399. inptr += RGB_PIXELSIZE;
  146400. outptr[col] = (JSAMPLE)
  146401. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146402. >> SCALEBITS);
  146403. }
  146404. }
  146405. }
  146406. METHODDEF(void)
  146407. cmyk_ycck_convert (j_compress_ptr cinfo,
  146408. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146409. JDIMENSION output_row, int num_rows)
  146410. {
  146411. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146412. register int r, g, b;
  146413. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146414. register JSAMPROW inptr;
  146415. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146416. register JDIMENSION col;
  146417. JDIMENSION num_cols = cinfo->image_width;
  146418. while (--num_rows >= 0) {
  146419. inptr = *input_buf++;
  146420. outptr0 = output_buf[0][output_row];
  146421. outptr1 = output_buf[1][output_row];
  146422. outptr2 = output_buf[2][output_row];
  146423. outptr3 = output_buf[3][output_row];
  146424. output_row++;
  146425. for (col = 0; col < num_cols; col++) {
  146426. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146427. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146428. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146429. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146430. inptr += 4;
  146431. outptr0[col] = (JSAMPLE)
  146432. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146433. >> SCALEBITS);
  146434. outptr1[col] = (JSAMPLE)
  146435. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146436. >> SCALEBITS);
  146437. outptr2[col] = (JSAMPLE)
  146438. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146439. >> SCALEBITS);
  146440. }
  146441. }
  146442. }
  146443. METHODDEF(void)
  146444. grayscale_convert (j_compress_ptr cinfo,
  146445. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146446. JDIMENSION output_row, int num_rows)
  146447. {
  146448. register JSAMPROW inptr;
  146449. register JSAMPROW outptr;
  146450. register JDIMENSION col;
  146451. JDIMENSION num_cols = cinfo->image_width;
  146452. int instride = cinfo->input_components;
  146453. while (--num_rows >= 0) {
  146454. inptr = *input_buf++;
  146455. outptr = output_buf[0][output_row];
  146456. output_row++;
  146457. for (col = 0; col < num_cols; col++) {
  146458. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146459. inptr += instride;
  146460. }
  146461. }
  146462. }
  146463. METHODDEF(void)
  146464. null_convert (j_compress_ptr cinfo,
  146465. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146466. JDIMENSION output_row, int num_rows)
  146467. {
  146468. register JSAMPROW inptr;
  146469. register JSAMPROW outptr;
  146470. register JDIMENSION col;
  146471. register int ci;
  146472. int nc = cinfo->num_components;
  146473. JDIMENSION num_cols = cinfo->image_width;
  146474. while (--num_rows >= 0) {
  146475. for (ci = 0; ci < nc; ci++) {
  146476. inptr = *input_buf;
  146477. outptr = output_buf[ci][output_row];
  146478. for (col = 0; col < num_cols; col++) {
  146479. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146480. inptr += nc;
  146481. }
  146482. }
  146483. input_buf++;
  146484. output_row++;
  146485. }
  146486. }
  146487. METHODDEF(void)
  146488. null_method (j_compress_ptr cinfo)
  146489. {
  146490. }
  146491. GLOBAL(void)
  146492. jinit_color_converter (j_compress_ptr cinfo)
  146493. {
  146494. my_cconvert_ptr cconvert;
  146495. cconvert = (my_cconvert_ptr)
  146496. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146497. SIZEOF(my_color_converter));
  146498. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146499. cconvert->pub.start_pass = null_method;
  146500. switch (cinfo->in_color_space) {
  146501. case JCS_GRAYSCALE:
  146502. if (cinfo->input_components != 1)
  146503. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146504. break;
  146505. case JCS_RGB:
  146506. #if RGB_PIXELSIZE != 3
  146507. if (cinfo->input_components != RGB_PIXELSIZE)
  146508. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146509. break;
  146510. #endif /* else share code with YCbCr */
  146511. case JCS_YCbCr:
  146512. if (cinfo->input_components != 3)
  146513. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146514. break;
  146515. case JCS_CMYK:
  146516. case JCS_YCCK:
  146517. if (cinfo->input_components != 4)
  146518. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146519. break;
  146520. default: /* JCS_UNKNOWN can be anything */
  146521. if (cinfo->input_components < 1)
  146522. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146523. break;
  146524. }
  146525. switch (cinfo->jpeg_color_space) {
  146526. case JCS_GRAYSCALE:
  146527. if (cinfo->num_components != 1)
  146528. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146529. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146530. cconvert->pub.color_convert = grayscale_convert;
  146531. else if (cinfo->in_color_space == JCS_RGB) {
  146532. cconvert->pub.start_pass = rgb_ycc_start;
  146533. cconvert->pub.color_convert = rgb_gray_convert;
  146534. } else if (cinfo->in_color_space == JCS_YCbCr)
  146535. cconvert->pub.color_convert = grayscale_convert;
  146536. else
  146537. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146538. break;
  146539. case JCS_RGB:
  146540. if (cinfo->num_components != 3)
  146541. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146542. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146543. cconvert->pub.color_convert = null_convert;
  146544. else
  146545. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146546. break;
  146547. case JCS_YCbCr:
  146548. if (cinfo->num_components != 3)
  146549. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146550. if (cinfo->in_color_space == JCS_RGB) {
  146551. cconvert->pub.start_pass = rgb_ycc_start;
  146552. cconvert->pub.color_convert = rgb_ycc_convert;
  146553. } else if (cinfo->in_color_space == JCS_YCbCr)
  146554. cconvert->pub.color_convert = null_convert;
  146555. else
  146556. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146557. break;
  146558. case JCS_CMYK:
  146559. if (cinfo->num_components != 4)
  146560. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146561. if (cinfo->in_color_space == JCS_CMYK)
  146562. cconvert->pub.color_convert = null_convert;
  146563. else
  146564. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146565. break;
  146566. case JCS_YCCK:
  146567. if (cinfo->num_components != 4)
  146568. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146569. if (cinfo->in_color_space == JCS_CMYK) {
  146570. cconvert->pub.start_pass = rgb_ycc_start;
  146571. cconvert->pub.color_convert = cmyk_ycck_convert;
  146572. } else if (cinfo->in_color_space == JCS_YCCK)
  146573. cconvert->pub.color_convert = null_convert;
  146574. else
  146575. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146576. break;
  146577. default: /* allow null conversion of JCS_UNKNOWN */
  146578. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146579. cinfo->num_components != cinfo->input_components)
  146580. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146581. cconvert->pub.color_convert = null_convert;
  146582. break;
  146583. }
  146584. }
  146585. /*** End of inlined file: jccolor.c ***/
  146586. #undef FIX
  146587. /*** Start of inlined file: jcdctmgr.c ***/
  146588. #define JPEG_INTERNALS
  146589. /*** Start of inlined file: jdct.h ***/
  146590. #ifndef __jdct_h__
  146591. #define __jdct_h__
  146592. #if BITS_IN_JSAMPLE == 8
  146593. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146594. #else
  146595. typedef INT32 DCTELEM; /* must have 32 bits */
  146596. #endif
  146597. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146598. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146599. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146600. #if BITS_IN_JSAMPLE == 8
  146601. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146602. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146603. #else
  146604. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146605. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146606. #endif
  146607. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146608. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146609. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146610. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146611. #define jpeg_fdct_islow jFDislow
  146612. #define jpeg_fdct_ifast jFDifast
  146613. #define jpeg_fdct_float jFDfloat
  146614. #define jpeg_idct_islow jRDislow
  146615. #define jpeg_idct_ifast jRDifast
  146616. #define jpeg_idct_float jRDfloat
  146617. #define jpeg_idct_4x4 jRD4x4
  146618. #define jpeg_idct_2x2 jRD2x2
  146619. #define jpeg_idct_1x1 jRD1x1
  146620. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146621. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146622. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146623. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146624. EXTERN(void) jpeg_idct_islow
  146625. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146626. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146627. EXTERN(void) jpeg_idct_ifast
  146628. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146629. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146630. EXTERN(void) jpeg_idct_float
  146631. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146632. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146633. EXTERN(void) jpeg_idct_4x4
  146634. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146635. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146636. EXTERN(void) jpeg_idct_2x2
  146637. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146638. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146639. EXTERN(void) jpeg_idct_1x1
  146640. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146641. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146642. #define ONE ((INT32) 1)
  146643. #define CONST_SCALE (ONE << CONST_BITS)
  146644. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146645. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146646. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146647. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146648. #endif
  146649. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146650. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146651. #endif
  146652. #ifndef MULTIPLY16C16 /* default definition */
  146653. #define MULTIPLY16C16(var,const) ((var) * (const))
  146654. #endif
  146655. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146656. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146657. #endif
  146658. #ifndef MULTIPLY16V16 /* default definition */
  146659. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146660. #endif
  146661. #endif
  146662. /*** End of inlined file: jdct.h ***/
  146663. /* Private declarations for DCT subsystem */
  146664. typedef struct {
  146665. struct jpeg_forward_dct pub; /* public fields */
  146666. forward_DCT_method_ptr do_dct;
  146667. DCTELEM * divisors[NUM_QUANT_TBLS];
  146668. #ifdef DCT_FLOAT_SUPPORTED
  146669. float_DCT_method_ptr do_float_dct;
  146670. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146671. #endif
  146672. } my_fdct_controller;
  146673. typedef my_fdct_controller * my_fdct_ptr;
  146674. METHODDEF(void)
  146675. start_pass_fdctmgr (j_compress_ptr cinfo)
  146676. {
  146677. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146678. int ci, qtblno, i;
  146679. jpeg_component_info *compptr;
  146680. JQUANT_TBL * qtbl;
  146681. DCTELEM * dtbl;
  146682. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146683. ci++, compptr++) {
  146684. qtblno = compptr->quant_tbl_no;
  146685. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146686. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146687. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146688. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146689. switch (cinfo->dct_method) {
  146690. #ifdef DCT_ISLOW_SUPPORTED
  146691. case JDCT_ISLOW:
  146692. if (fdct->divisors[qtblno] == NULL) {
  146693. fdct->divisors[qtblno] = (DCTELEM *)
  146694. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146695. DCTSIZE2 * SIZEOF(DCTELEM));
  146696. }
  146697. dtbl = fdct->divisors[qtblno];
  146698. for (i = 0; i < DCTSIZE2; i++) {
  146699. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146700. }
  146701. break;
  146702. #endif
  146703. #ifdef DCT_IFAST_SUPPORTED
  146704. case JDCT_IFAST:
  146705. {
  146706. #define CONST_BITS 14
  146707. static const INT16 aanscales[DCTSIZE2] = {
  146708. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146709. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146710. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146711. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146712. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146713. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146714. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146715. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146716. };
  146717. SHIFT_TEMPS
  146718. if (fdct->divisors[qtblno] == NULL) {
  146719. fdct->divisors[qtblno] = (DCTELEM *)
  146720. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146721. DCTSIZE2 * SIZEOF(DCTELEM));
  146722. }
  146723. dtbl = fdct->divisors[qtblno];
  146724. for (i = 0; i < DCTSIZE2; i++) {
  146725. dtbl[i] = (DCTELEM)
  146726. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146727. (INT32) aanscales[i]),
  146728. CONST_BITS-3);
  146729. }
  146730. }
  146731. break;
  146732. #endif
  146733. #ifdef DCT_FLOAT_SUPPORTED
  146734. case JDCT_FLOAT:
  146735. {
  146736. FAST_FLOAT * fdtbl;
  146737. int row, col;
  146738. static const double aanscalefactor[DCTSIZE] = {
  146739. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146740. 1.0, 0.785694958, 0.541196100, 0.275899379
  146741. };
  146742. if (fdct->float_divisors[qtblno] == NULL) {
  146743. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146744. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146745. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146746. }
  146747. fdtbl = fdct->float_divisors[qtblno];
  146748. i = 0;
  146749. for (row = 0; row < DCTSIZE; row++) {
  146750. for (col = 0; col < DCTSIZE; col++) {
  146751. fdtbl[i] = (FAST_FLOAT)
  146752. (1.0 / (((double) qtbl->quantval[i] *
  146753. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146754. i++;
  146755. }
  146756. }
  146757. }
  146758. break;
  146759. #endif
  146760. default:
  146761. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146762. break;
  146763. }
  146764. }
  146765. }
  146766. METHODDEF(void)
  146767. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146768. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146769. JDIMENSION start_row, JDIMENSION start_col,
  146770. JDIMENSION num_blocks)
  146771. {
  146772. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146773. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146774. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146775. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146776. JDIMENSION bi;
  146777. sample_data += start_row; /* fold in the vertical offset once */
  146778. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146779. { register DCTELEM *workspaceptr;
  146780. register JSAMPROW elemptr;
  146781. register int elemr;
  146782. workspaceptr = workspace;
  146783. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146784. elemptr = sample_data[elemr] + start_col;
  146785. #if DCTSIZE == 8 /* unroll the inner loop */
  146786. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146787. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146788. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146789. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146790. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146791. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146792. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146793. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146794. #else
  146795. { register int elemc;
  146796. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146797. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146798. }
  146799. }
  146800. #endif
  146801. }
  146802. }
  146803. (*do_dct) (workspace);
  146804. { register DCTELEM temp, qval;
  146805. register int i;
  146806. register JCOEFPTR output_ptr = coef_blocks[bi];
  146807. for (i = 0; i < DCTSIZE2; i++) {
  146808. qval = divisors[i];
  146809. temp = workspace[i];
  146810. #ifdef FAST_DIVIDE
  146811. #define DIVIDE_BY(a,b) a /= b
  146812. #else
  146813. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146814. #endif
  146815. if (temp < 0) {
  146816. temp = -temp;
  146817. temp += qval>>1; /* for rounding */
  146818. DIVIDE_BY(temp, qval);
  146819. temp = -temp;
  146820. } else {
  146821. temp += qval>>1; /* for rounding */
  146822. DIVIDE_BY(temp, qval);
  146823. }
  146824. output_ptr[i] = (JCOEF) temp;
  146825. }
  146826. }
  146827. }
  146828. }
  146829. #ifdef DCT_FLOAT_SUPPORTED
  146830. METHODDEF(void)
  146831. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146832. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146833. JDIMENSION start_row, JDIMENSION start_col,
  146834. JDIMENSION num_blocks)
  146835. {
  146836. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146837. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146838. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146839. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146840. JDIMENSION bi;
  146841. sample_data += start_row; /* fold in the vertical offset once */
  146842. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146843. { register FAST_FLOAT *workspaceptr;
  146844. register JSAMPROW elemptr;
  146845. register int elemr;
  146846. workspaceptr = workspace;
  146847. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146848. elemptr = sample_data[elemr] + start_col;
  146849. #if DCTSIZE == 8 /* unroll the inner loop */
  146850. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146851. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146852. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146853. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146854. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146855. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146856. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146857. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146858. #else
  146859. { register int elemc;
  146860. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146861. *workspaceptr++ = (FAST_FLOAT)
  146862. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146863. }
  146864. }
  146865. #endif
  146866. }
  146867. }
  146868. (*do_dct) (workspace);
  146869. { register FAST_FLOAT temp;
  146870. register int i;
  146871. register JCOEFPTR output_ptr = coef_blocks[bi];
  146872. for (i = 0; i < DCTSIZE2; i++) {
  146873. temp = workspace[i] * divisors[i];
  146874. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146875. }
  146876. }
  146877. }
  146878. }
  146879. #endif /* DCT_FLOAT_SUPPORTED */
  146880. GLOBAL(void)
  146881. jinit_forward_dct (j_compress_ptr cinfo)
  146882. {
  146883. my_fdct_ptr fdct;
  146884. int i;
  146885. fdct = (my_fdct_ptr)
  146886. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146887. SIZEOF(my_fdct_controller));
  146888. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146889. fdct->pub.start_pass = start_pass_fdctmgr;
  146890. switch (cinfo->dct_method) {
  146891. #ifdef DCT_ISLOW_SUPPORTED
  146892. case JDCT_ISLOW:
  146893. fdct->pub.forward_DCT = forward_DCT;
  146894. fdct->do_dct = jpeg_fdct_islow;
  146895. break;
  146896. #endif
  146897. #ifdef DCT_IFAST_SUPPORTED
  146898. case JDCT_IFAST:
  146899. fdct->pub.forward_DCT = forward_DCT;
  146900. fdct->do_dct = jpeg_fdct_ifast;
  146901. break;
  146902. #endif
  146903. #ifdef DCT_FLOAT_SUPPORTED
  146904. case JDCT_FLOAT:
  146905. fdct->pub.forward_DCT = forward_DCT_float;
  146906. fdct->do_float_dct = jpeg_fdct_float;
  146907. break;
  146908. #endif
  146909. default:
  146910. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146911. break;
  146912. }
  146913. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146914. fdct->divisors[i] = NULL;
  146915. #ifdef DCT_FLOAT_SUPPORTED
  146916. fdct->float_divisors[i] = NULL;
  146917. #endif
  146918. }
  146919. }
  146920. /*** End of inlined file: jcdctmgr.c ***/
  146921. #undef CONST_BITS
  146922. /*** Start of inlined file: jchuff.c ***/
  146923. #define JPEG_INTERNALS
  146924. /*** Start of inlined file: jchuff.h ***/
  146925. #ifndef _jchuff_h_
  146926. #define _jchuff_h_
  146927. #if BITS_IN_JSAMPLE == 8
  146928. #define MAX_COEF_BITS 10
  146929. #else
  146930. #define MAX_COEF_BITS 14
  146931. #endif
  146932. typedef struct {
  146933. unsigned int ehufco[256]; /* code for each symbol */
  146934. char ehufsi[256]; /* length of code for each symbol */
  146935. } c_derived_tbl;
  146936. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146937. #define jpeg_make_c_derived_tbl jMkCDerived
  146938. #define jpeg_gen_optimal_table jGenOptTbl
  146939. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146940. EXTERN(void) jpeg_make_c_derived_tbl
  146941. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  146942. c_derived_tbl ** pdtbl));
  146943. EXTERN(void) jpeg_gen_optimal_table
  146944. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  146945. #endif
  146946. /*** End of inlined file: jchuff.h ***/
  146947. /* Declarations shared with jcphuff.c */
  146948. typedef struct {
  146949. INT32 put_buffer; /* current bit-accumulation buffer */
  146950. int put_bits; /* # of bits now in it */
  146951. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  146952. } savable_state;
  146953. #ifndef NO_STRUCT_ASSIGN
  146954. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  146955. #else
  146956. #if MAX_COMPS_IN_SCAN == 4
  146957. #define ASSIGN_STATE(dest,src) \
  146958. ((dest).put_buffer = (src).put_buffer, \
  146959. (dest).put_bits = (src).put_bits, \
  146960. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  146961. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  146962. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  146963. (dest).last_dc_val[3] = (src).last_dc_val[3])
  146964. #endif
  146965. #endif
  146966. typedef struct {
  146967. struct jpeg_entropy_encoder pub; /* public fields */
  146968. savable_state saved; /* Bit buffer & DC state at start of MCU */
  146969. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  146970. int next_restart_num; /* next restart number to write (0-7) */
  146971. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  146972. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  146973. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  146974. long * dc_count_ptrs[NUM_HUFF_TBLS];
  146975. long * ac_count_ptrs[NUM_HUFF_TBLS];
  146976. #endif
  146977. } huff_entropy_encoder;
  146978. typedef huff_entropy_encoder * huff_entropy_ptr;
  146979. typedef struct {
  146980. JOCTET * next_output_byte; /* => next byte to write in buffer */
  146981. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  146982. savable_state cur; /* Current bit buffer & DC state */
  146983. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  146984. } working_state;
  146985. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  146986. JBLOCKROW *MCU_data));
  146987. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  146988. #ifdef ENTROPY_OPT_SUPPORTED
  146989. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  146990. JBLOCKROW *MCU_data));
  146991. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  146992. #endif
  146993. METHODDEF(void)
  146994. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  146995. {
  146996. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  146997. int ci, dctbl, actbl;
  146998. jpeg_component_info * compptr;
  146999. if (gather_statistics) {
  147000. #ifdef ENTROPY_OPT_SUPPORTED
  147001. entropy->pub.encode_mcu = encode_mcu_gather;
  147002. entropy->pub.finish_pass = finish_pass_gather;
  147003. #else
  147004. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147005. #endif
  147006. } else {
  147007. entropy->pub.encode_mcu = encode_mcu_huff;
  147008. entropy->pub.finish_pass = finish_pass_huff;
  147009. }
  147010. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147011. compptr = cinfo->cur_comp_info[ci];
  147012. dctbl = compptr->dc_tbl_no;
  147013. actbl = compptr->ac_tbl_no;
  147014. if (gather_statistics) {
  147015. #ifdef ENTROPY_OPT_SUPPORTED
  147016. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147017. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147018. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147019. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147020. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147021. entropy->dc_count_ptrs[dctbl] = (long *)
  147022. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147023. 257 * SIZEOF(long));
  147024. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147025. if (entropy->ac_count_ptrs[actbl] == NULL)
  147026. entropy->ac_count_ptrs[actbl] = (long *)
  147027. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147028. 257 * SIZEOF(long));
  147029. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147030. #endif
  147031. } else {
  147032. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147033. & entropy->dc_derived_tbls[dctbl]);
  147034. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147035. & entropy->ac_derived_tbls[actbl]);
  147036. }
  147037. entropy->saved.last_dc_val[ci] = 0;
  147038. }
  147039. entropy->saved.put_buffer = 0;
  147040. entropy->saved.put_bits = 0;
  147041. entropy->restarts_to_go = cinfo->restart_interval;
  147042. entropy->next_restart_num = 0;
  147043. }
  147044. GLOBAL(void)
  147045. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147046. c_derived_tbl ** pdtbl)
  147047. {
  147048. JHUFF_TBL *htbl;
  147049. c_derived_tbl *dtbl;
  147050. int p, i, l, lastp, si, maxsymbol;
  147051. char huffsize[257];
  147052. unsigned int huffcode[257];
  147053. unsigned int code;
  147054. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147055. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147056. htbl =
  147057. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147058. if (htbl == NULL)
  147059. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147060. if (*pdtbl == NULL)
  147061. *pdtbl = (c_derived_tbl *)
  147062. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147063. SIZEOF(c_derived_tbl));
  147064. dtbl = *pdtbl;
  147065. p = 0;
  147066. for (l = 1; l <= 16; l++) {
  147067. i = (int) htbl->bits[l];
  147068. if (i < 0 || p + i > 256) /* protect against table overrun */
  147069. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147070. while (i--)
  147071. huffsize[p++] = (char) l;
  147072. }
  147073. huffsize[p] = 0;
  147074. lastp = p;
  147075. code = 0;
  147076. si = huffsize[0];
  147077. p = 0;
  147078. while (huffsize[p]) {
  147079. while (((int) huffsize[p]) == si) {
  147080. huffcode[p++] = code;
  147081. code++;
  147082. }
  147083. if (((INT32) code) >= (((INT32) 1) << si))
  147084. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147085. code <<= 1;
  147086. si++;
  147087. }
  147088. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147089. maxsymbol = isDC ? 15 : 255;
  147090. for (p = 0; p < lastp; p++) {
  147091. i = htbl->huffval[p];
  147092. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147093. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147094. dtbl->ehufco[i] = huffcode[p];
  147095. dtbl->ehufsi[i] = huffsize[p];
  147096. }
  147097. }
  147098. #define emit_byte(state,val,action) \
  147099. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147100. if (--(state)->free_in_buffer == 0) \
  147101. if (! dump_buffer(state)) \
  147102. { action; } }
  147103. LOCAL(boolean)
  147104. dump_buffer (working_state * state)
  147105. {
  147106. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147107. if (! (*dest->empty_output_buffer) (state->cinfo))
  147108. return FALSE;
  147109. state->next_output_byte = dest->next_output_byte;
  147110. state->free_in_buffer = dest->free_in_buffer;
  147111. return TRUE;
  147112. }
  147113. INLINE
  147114. LOCAL(boolean)
  147115. emit_bits (working_state * state, unsigned int code, int size)
  147116. {
  147117. register INT32 put_buffer = (INT32) code;
  147118. register int put_bits = state->cur.put_bits;
  147119. if (size == 0)
  147120. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147121. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147122. put_bits += size; /* new number of bits in buffer */
  147123. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147124. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147125. while (put_bits >= 8) {
  147126. int c = (int) ((put_buffer >> 16) & 0xFF);
  147127. emit_byte(state, c, return FALSE);
  147128. if (c == 0xFF) { /* need to stuff a zero byte? */
  147129. emit_byte(state, 0, return FALSE);
  147130. }
  147131. put_buffer <<= 8;
  147132. put_bits -= 8;
  147133. }
  147134. state->cur.put_buffer = put_buffer; /* update state variables */
  147135. state->cur.put_bits = put_bits;
  147136. return TRUE;
  147137. }
  147138. LOCAL(boolean)
  147139. flush_bits (working_state * state)
  147140. {
  147141. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147142. return FALSE;
  147143. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147144. state->cur.put_bits = 0;
  147145. return TRUE;
  147146. }
  147147. LOCAL(boolean)
  147148. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147149. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147150. {
  147151. register int temp, temp2;
  147152. register int nbits;
  147153. register int k, r, i;
  147154. temp = temp2 = block[0] - last_dc_val;
  147155. if (temp < 0) {
  147156. temp = -temp; /* temp is abs value of input */
  147157. temp2--;
  147158. }
  147159. nbits = 0;
  147160. while (temp) {
  147161. nbits++;
  147162. temp >>= 1;
  147163. }
  147164. if (nbits > MAX_COEF_BITS+1)
  147165. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147166. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147167. return FALSE;
  147168. if (nbits) /* emit_bits rejects calls with size 0 */
  147169. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147170. return FALSE;
  147171. r = 0; /* r = run length of zeros */
  147172. for (k = 1; k < DCTSIZE2; k++) {
  147173. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147174. r++;
  147175. } else {
  147176. while (r > 15) {
  147177. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147178. return FALSE;
  147179. r -= 16;
  147180. }
  147181. temp2 = temp;
  147182. if (temp < 0) {
  147183. temp = -temp; /* temp is abs value of input */
  147184. temp2--;
  147185. }
  147186. nbits = 1; /* there must be at least one 1 bit */
  147187. while ((temp >>= 1))
  147188. nbits++;
  147189. if (nbits > MAX_COEF_BITS)
  147190. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147191. i = (r << 4) + nbits;
  147192. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147193. return FALSE;
  147194. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147195. return FALSE;
  147196. r = 0;
  147197. }
  147198. }
  147199. if (r > 0)
  147200. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147201. return FALSE;
  147202. return TRUE;
  147203. }
  147204. LOCAL(boolean)
  147205. emit_restart (working_state * state, int restart_num)
  147206. {
  147207. int ci;
  147208. if (! flush_bits(state))
  147209. return FALSE;
  147210. emit_byte(state, 0xFF, return FALSE);
  147211. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147212. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147213. state->cur.last_dc_val[ci] = 0;
  147214. return TRUE;
  147215. }
  147216. METHODDEF(boolean)
  147217. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147218. {
  147219. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147220. working_state state;
  147221. int blkn, ci;
  147222. jpeg_component_info * compptr;
  147223. state.next_output_byte = cinfo->dest->next_output_byte;
  147224. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147225. ASSIGN_STATE(state.cur, entropy->saved);
  147226. state.cinfo = cinfo;
  147227. if (cinfo->restart_interval) {
  147228. if (entropy->restarts_to_go == 0)
  147229. if (! emit_restart(&state, entropy->next_restart_num))
  147230. return FALSE;
  147231. }
  147232. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147233. ci = cinfo->MCU_membership[blkn];
  147234. compptr = cinfo->cur_comp_info[ci];
  147235. if (! encode_one_block(&state,
  147236. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147237. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147238. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147239. return FALSE;
  147240. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147241. }
  147242. cinfo->dest->next_output_byte = state.next_output_byte;
  147243. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147244. ASSIGN_STATE(entropy->saved, state.cur);
  147245. if (cinfo->restart_interval) {
  147246. if (entropy->restarts_to_go == 0) {
  147247. entropy->restarts_to_go = cinfo->restart_interval;
  147248. entropy->next_restart_num++;
  147249. entropy->next_restart_num &= 7;
  147250. }
  147251. entropy->restarts_to_go--;
  147252. }
  147253. return TRUE;
  147254. }
  147255. METHODDEF(void)
  147256. finish_pass_huff (j_compress_ptr cinfo)
  147257. {
  147258. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147259. working_state state;
  147260. state.next_output_byte = cinfo->dest->next_output_byte;
  147261. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147262. ASSIGN_STATE(state.cur, entropy->saved);
  147263. state.cinfo = cinfo;
  147264. if (! flush_bits(&state))
  147265. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147266. cinfo->dest->next_output_byte = state.next_output_byte;
  147267. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147268. ASSIGN_STATE(entropy->saved, state.cur);
  147269. }
  147270. #ifdef ENTROPY_OPT_SUPPORTED
  147271. LOCAL(void)
  147272. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147273. long dc_counts[], long ac_counts[])
  147274. {
  147275. register int temp;
  147276. register int nbits;
  147277. register int k, r;
  147278. temp = block[0] - last_dc_val;
  147279. if (temp < 0)
  147280. temp = -temp;
  147281. nbits = 0;
  147282. while (temp) {
  147283. nbits++;
  147284. temp >>= 1;
  147285. }
  147286. if (nbits > MAX_COEF_BITS+1)
  147287. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147288. dc_counts[nbits]++;
  147289. r = 0; /* r = run length of zeros */
  147290. for (k = 1; k < DCTSIZE2; k++) {
  147291. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147292. r++;
  147293. } else {
  147294. while (r > 15) {
  147295. ac_counts[0xF0]++;
  147296. r -= 16;
  147297. }
  147298. if (temp < 0)
  147299. temp = -temp;
  147300. nbits = 1; /* there must be at least one 1 bit */
  147301. while ((temp >>= 1))
  147302. nbits++;
  147303. if (nbits > MAX_COEF_BITS)
  147304. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147305. ac_counts[(r << 4) + nbits]++;
  147306. r = 0;
  147307. }
  147308. }
  147309. if (r > 0)
  147310. ac_counts[0]++;
  147311. }
  147312. METHODDEF(boolean)
  147313. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147314. {
  147315. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147316. int blkn, ci;
  147317. jpeg_component_info * compptr;
  147318. if (cinfo->restart_interval) {
  147319. if (entropy->restarts_to_go == 0) {
  147320. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147321. entropy->saved.last_dc_val[ci] = 0;
  147322. entropy->restarts_to_go = cinfo->restart_interval;
  147323. }
  147324. entropy->restarts_to_go--;
  147325. }
  147326. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147327. ci = cinfo->MCU_membership[blkn];
  147328. compptr = cinfo->cur_comp_info[ci];
  147329. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147330. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147331. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147332. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147333. }
  147334. return TRUE;
  147335. }
  147336. GLOBAL(void)
  147337. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147338. {
  147339. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147340. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147341. int codesize[257]; /* codesize[k] = code length of symbol k */
  147342. int others[257]; /* next symbol in current branch of tree */
  147343. int c1, c2;
  147344. int p, i, j;
  147345. long v;
  147346. MEMZERO(bits, SIZEOF(bits));
  147347. MEMZERO(codesize, SIZEOF(codesize));
  147348. for (i = 0; i < 257; i++)
  147349. others[i] = -1; /* init links to empty */
  147350. freq[256] = 1; /* make sure 256 has a nonzero count */
  147351. for (;;) {
  147352. c1 = -1;
  147353. v = 1000000000L;
  147354. for (i = 0; i <= 256; i++) {
  147355. if (freq[i] && freq[i] <= v) {
  147356. v = freq[i];
  147357. c1 = i;
  147358. }
  147359. }
  147360. c2 = -1;
  147361. v = 1000000000L;
  147362. for (i = 0; i <= 256; i++) {
  147363. if (freq[i] && freq[i] <= v && i != c1) {
  147364. v = freq[i];
  147365. c2 = i;
  147366. }
  147367. }
  147368. if (c2 < 0)
  147369. break;
  147370. freq[c1] += freq[c2];
  147371. freq[c2] = 0;
  147372. codesize[c1]++;
  147373. while (others[c1] >= 0) {
  147374. c1 = others[c1];
  147375. codesize[c1]++;
  147376. }
  147377. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147378. codesize[c2]++;
  147379. while (others[c2] >= 0) {
  147380. c2 = others[c2];
  147381. codesize[c2]++;
  147382. }
  147383. }
  147384. for (i = 0; i <= 256; i++) {
  147385. if (codesize[i]) {
  147386. if (codesize[i] > MAX_CLEN)
  147387. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147388. bits[codesize[i]]++;
  147389. }
  147390. }
  147391. for (i = MAX_CLEN; i > 16; i--) {
  147392. while (bits[i] > 0) {
  147393. j = i - 2; /* find length of new prefix to be used */
  147394. while (bits[j] == 0)
  147395. j--;
  147396. bits[i] -= 2; /* remove two symbols */
  147397. bits[i-1]++; /* one goes in this length */
  147398. bits[j+1] += 2; /* two new symbols in this length */
  147399. bits[j]--; /* symbol of this length is now a prefix */
  147400. }
  147401. }
  147402. while (bits[i] == 0) /* find largest codelength still in use */
  147403. i--;
  147404. bits[i]--;
  147405. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147406. p = 0;
  147407. for (i = 1; i <= MAX_CLEN; i++) {
  147408. for (j = 0; j <= 255; j++) {
  147409. if (codesize[j] == i) {
  147410. htbl->huffval[p] = (UINT8) j;
  147411. p++;
  147412. }
  147413. }
  147414. }
  147415. htbl->sent_table = FALSE;
  147416. }
  147417. METHODDEF(void)
  147418. finish_pass_gather (j_compress_ptr cinfo)
  147419. {
  147420. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147421. int ci, dctbl, actbl;
  147422. jpeg_component_info * compptr;
  147423. JHUFF_TBL **htblptr;
  147424. boolean did_dc[NUM_HUFF_TBLS];
  147425. boolean did_ac[NUM_HUFF_TBLS];
  147426. MEMZERO(did_dc, SIZEOF(did_dc));
  147427. MEMZERO(did_ac, SIZEOF(did_ac));
  147428. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147429. compptr = cinfo->cur_comp_info[ci];
  147430. dctbl = compptr->dc_tbl_no;
  147431. actbl = compptr->ac_tbl_no;
  147432. if (! did_dc[dctbl]) {
  147433. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147434. if (*htblptr == NULL)
  147435. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147436. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147437. did_dc[dctbl] = TRUE;
  147438. }
  147439. if (! did_ac[actbl]) {
  147440. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147441. if (*htblptr == NULL)
  147442. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147443. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147444. did_ac[actbl] = TRUE;
  147445. }
  147446. }
  147447. }
  147448. #endif /* ENTROPY_OPT_SUPPORTED */
  147449. GLOBAL(void)
  147450. jinit_huff_encoder (j_compress_ptr cinfo)
  147451. {
  147452. huff_entropy_ptr entropy;
  147453. int i;
  147454. entropy = (huff_entropy_ptr)
  147455. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147456. SIZEOF(huff_entropy_encoder));
  147457. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147458. entropy->pub.start_pass = start_pass_huff;
  147459. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147460. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147461. #ifdef ENTROPY_OPT_SUPPORTED
  147462. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147463. #endif
  147464. }
  147465. }
  147466. /*** End of inlined file: jchuff.c ***/
  147467. #undef emit_byte
  147468. /*** Start of inlined file: jcinit.c ***/
  147469. #define JPEG_INTERNALS
  147470. GLOBAL(void)
  147471. jinit_compress_master (j_compress_ptr cinfo)
  147472. {
  147473. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147474. if (! cinfo->raw_data_in) {
  147475. jinit_color_converter(cinfo);
  147476. jinit_downsampler(cinfo);
  147477. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147478. }
  147479. jinit_forward_dct(cinfo);
  147480. if (cinfo->arith_code) {
  147481. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147482. } else {
  147483. if (cinfo->progressive_mode) {
  147484. #ifdef C_PROGRESSIVE_SUPPORTED
  147485. jinit_phuff_encoder(cinfo);
  147486. #else
  147487. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147488. #endif
  147489. } else
  147490. jinit_huff_encoder(cinfo);
  147491. }
  147492. jinit_c_coef_controller(cinfo,
  147493. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147494. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147495. jinit_marker_writer(cinfo);
  147496. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147497. (*cinfo->marker->write_file_header) (cinfo);
  147498. }
  147499. /*** End of inlined file: jcinit.c ***/
  147500. /*** Start of inlined file: jcmainct.c ***/
  147501. #define JPEG_INTERNALS
  147502. #undef FULL_MAIN_BUFFER_SUPPORTED
  147503. typedef struct {
  147504. struct jpeg_c_main_controller pub; /* public fields */
  147505. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147506. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147507. boolean suspended; /* remember if we suspended output */
  147508. J_BUF_MODE pass_mode; /* current operating mode */
  147509. JSAMPARRAY buffer[MAX_COMPONENTS];
  147510. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147511. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147512. #endif
  147513. } my_main_controller;
  147514. typedef my_main_controller * my_main_ptr;
  147515. METHODDEF(void) process_data_simple_main
  147516. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147517. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147518. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147519. METHODDEF(void) process_data_buffer_main
  147520. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147521. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147522. #endif
  147523. METHODDEF(void)
  147524. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147525. {
  147526. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147527. if (cinfo->raw_data_in)
  147528. return;
  147529. main_->cur_iMCU_row = 0; /* initialize counters */
  147530. main_->rowgroup_ctr = 0;
  147531. main_->suspended = FALSE;
  147532. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147533. switch (pass_mode) {
  147534. case JBUF_PASS_THRU:
  147535. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147536. if (main_->whole_image[0] != NULL)
  147537. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147538. #endif
  147539. main_->pub.process_data = process_data_simple_main;
  147540. break;
  147541. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147542. case JBUF_SAVE_SOURCE:
  147543. case JBUF_CRANK_DEST:
  147544. case JBUF_SAVE_AND_PASS:
  147545. if (main_->whole_image[0] == NULL)
  147546. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147547. main_->pub.process_data = process_data_buffer_main;
  147548. break;
  147549. #endif
  147550. default:
  147551. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147552. break;
  147553. }
  147554. }
  147555. METHODDEF(void)
  147556. process_data_simple_main (j_compress_ptr cinfo,
  147557. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147558. JDIMENSION in_rows_avail)
  147559. {
  147560. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147561. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147562. if (main_->rowgroup_ctr < DCTSIZE)
  147563. (*cinfo->prep->pre_process_data) (cinfo,
  147564. input_buf, in_row_ctr, in_rows_avail,
  147565. main_->buffer, &main_->rowgroup_ctr,
  147566. (JDIMENSION) DCTSIZE);
  147567. if (main_->rowgroup_ctr != DCTSIZE)
  147568. return;
  147569. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147570. if (! main_->suspended) {
  147571. (*in_row_ctr)--;
  147572. main_->suspended = TRUE;
  147573. }
  147574. return;
  147575. }
  147576. if (main_->suspended) {
  147577. (*in_row_ctr)++;
  147578. main_->suspended = FALSE;
  147579. }
  147580. main_->rowgroup_ctr = 0;
  147581. main_->cur_iMCU_row++;
  147582. }
  147583. }
  147584. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147585. METHODDEF(void)
  147586. process_data_buffer_main (j_compress_ptr cinfo,
  147587. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147588. JDIMENSION in_rows_avail)
  147589. {
  147590. my_main_ptr main = (my_main_ptr) cinfo->main;
  147591. int ci;
  147592. jpeg_component_info *compptr;
  147593. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147594. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147595. if (main->rowgroup_ctr == 0) {
  147596. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147597. ci++, compptr++) {
  147598. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147599. ((j_common_ptr) cinfo, main->whole_image[ci],
  147600. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147601. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147602. }
  147603. if (! writing) {
  147604. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147605. main->rowgroup_ctr = DCTSIZE;
  147606. }
  147607. }
  147608. if (writing) {
  147609. (*cinfo->prep->pre_process_data) (cinfo,
  147610. input_buf, in_row_ctr, in_rows_avail,
  147611. main->buffer, &main->rowgroup_ctr,
  147612. (JDIMENSION) DCTSIZE);
  147613. if (main->rowgroup_ctr < DCTSIZE)
  147614. return;
  147615. }
  147616. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147617. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147618. if (! main->suspended) {
  147619. (*in_row_ctr)--;
  147620. main->suspended = TRUE;
  147621. }
  147622. return;
  147623. }
  147624. if (main->suspended) {
  147625. (*in_row_ctr)++;
  147626. main->suspended = FALSE;
  147627. }
  147628. }
  147629. main->rowgroup_ctr = 0;
  147630. main->cur_iMCU_row++;
  147631. }
  147632. }
  147633. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147634. GLOBAL(void)
  147635. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147636. {
  147637. my_main_ptr main_;
  147638. int ci;
  147639. jpeg_component_info *compptr;
  147640. main_ = (my_main_ptr)
  147641. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147642. SIZEOF(my_main_controller));
  147643. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147644. main_->pub.start_pass = start_pass_main;
  147645. if (cinfo->raw_data_in)
  147646. return;
  147647. if (need_full_buffer) {
  147648. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147649. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147650. ci++, compptr++) {
  147651. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147652. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147653. compptr->width_in_blocks * DCTSIZE,
  147654. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147655. (long) compptr->v_samp_factor) * DCTSIZE,
  147656. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147657. }
  147658. #else
  147659. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147660. #endif
  147661. } else {
  147662. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147663. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147664. #endif
  147665. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147666. ci++, compptr++) {
  147667. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147668. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147669. compptr->width_in_blocks * DCTSIZE,
  147670. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147671. }
  147672. }
  147673. }
  147674. /*** End of inlined file: jcmainct.c ***/
  147675. /*** Start of inlined file: jcmarker.c ***/
  147676. #define JPEG_INTERNALS
  147677. typedef struct {
  147678. struct jpeg_marker_writer pub; /* public fields */
  147679. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147680. } my_marker_writer;
  147681. typedef my_marker_writer * my_marker_ptr;
  147682. LOCAL(void)
  147683. emit_byte (j_compress_ptr cinfo, int val)
  147684. {
  147685. struct jpeg_destination_mgr * dest = cinfo->dest;
  147686. *(dest->next_output_byte)++ = (JOCTET) val;
  147687. if (--dest->free_in_buffer == 0) {
  147688. if (! (*dest->empty_output_buffer) (cinfo))
  147689. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147690. }
  147691. }
  147692. LOCAL(void)
  147693. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147694. {
  147695. emit_byte(cinfo, 0xFF);
  147696. emit_byte(cinfo, (int) mark);
  147697. }
  147698. LOCAL(void)
  147699. emit_2bytes (j_compress_ptr cinfo, int value)
  147700. {
  147701. emit_byte(cinfo, (value >> 8) & 0xFF);
  147702. emit_byte(cinfo, value & 0xFF);
  147703. }
  147704. LOCAL(int)
  147705. emit_dqt (j_compress_ptr cinfo, int index)
  147706. {
  147707. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147708. int prec;
  147709. int i;
  147710. if (qtbl == NULL)
  147711. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147712. prec = 0;
  147713. for (i = 0; i < DCTSIZE2; i++) {
  147714. if (qtbl->quantval[i] > 255)
  147715. prec = 1;
  147716. }
  147717. if (! qtbl->sent_table) {
  147718. emit_marker(cinfo, M_DQT);
  147719. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147720. emit_byte(cinfo, index + (prec<<4));
  147721. for (i = 0; i < DCTSIZE2; i++) {
  147722. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147723. if (prec)
  147724. emit_byte(cinfo, (int) (qval >> 8));
  147725. emit_byte(cinfo, (int) (qval & 0xFF));
  147726. }
  147727. qtbl->sent_table = TRUE;
  147728. }
  147729. return prec;
  147730. }
  147731. LOCAL(void)
  147732. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147733. {
  147734. JHUFF_TBL * htbl;
  147735. int length, i;
  147736. if (is_ac) {
  147737. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147738. index += 0x10; /* output index has AC bit set */
  147739. } else {
  147740. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147741. }
  147742. if (htbl == NULL)
  147743. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147744. if (! htbl->sent_table) {
  147745. emit_marker(cinfo, M_DHT);
  147746. length = 0;
  147747. for (i = 1; i <= 16; i++)
  147748. length += htbl->bits[i];
  147749. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147750. emit_byte(cinfo, index);
  147751. for (i = 1; i <= 16; i++)
  147752. emit_byte(cinfo, htbl->bits[i]);
  147753. for (i = 0; i < length; i++)
  147754. emit_byte(cinfo, htbl->huffval[i]);
  147755. htbl->sent_table = TRUE;
  147756. }
  147757. }
  147758. LOCAL(void)
  147759. emit_dac (j_compress_ptr cinfo)
  147760. {
  147761. #ifdef C_ARITH_CODING_SUPPORTED
  147762. char dc_in_use[NUM_ARITH_TBLS];
  147763. char ac_in_use[NUM_ARITH_TBLS];
  147764. int length, i;
  147765. jpeg_component_info *compptr;
  147766. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147767. dc_in_use[i] = ac_in_use[i] = 0;
  147768. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147769. compptr = cinfo->cur_comp_info[i];
  147770. dc_in_use[compptr->dc_tbl_no] = 1;
  147771. ac_in_use[compptr->ac_tbl_no] = 1;
  147772. }
  147773. length = 0;
  147774. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147775. length += dc_in_use[i] + ac_in_use[i];
  147776. emit_marker(cinfo, M_DAC);
  147777. emit_2bytes(cinfo, length*2 + 2);
  147778. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147779. if (dc_in_use[i]) {
  147780. emit_byte(cinfo, i);
  147781. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147782. }
  147783. if (ac_in_use[i]) {
  147784. emit_byte(cinfo, i + 0x10);
  147785. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147786. }
  147787. }
  147788. #endif /* C_ARITH_CODING_SUPPORTED */
  147789. }
  147790. LOCAL(void)
  147791. emit_dri (j_compress_ptr cinfo)
  147792. {
  147793. emit_marker(cinfo, M_DRI);
  147794. emit_2bytes(cinfo, 4); /* fixed length */
  147795. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147796. }
  147797. LOCAL(void)
  147798. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147799. {
  147800. int ci;
  147801. jpeg_component_info *compptr;
  147802. emit_marker(cinfo, code);
  147803. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147804. if ((long) cinfo->image_height > 65535L ||
  147805. (long) cinfo->image_width > 65535L)
  147806. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147807. emit_byte(cinfo, cinfo->data_precision);
  147808. emit_2bytes(cinfo, (int) cinfo->image_height);
  147809. emit_2bytes(cinfo, (int) cinfo->image_width);
  147810. emit_byte(cinfo, cinfo->num_components);
  147811. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147812. ci++, compptr++) {
  147813. emit_byte(cinfo, compptr->component_id);
  147814. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147815. emit_byte(cinfo, compptr->quant_tbl_no);
  147816. }
  147817. }
  147818. LOCAL(void)
  147819. emit_sos (j_compress_ptr cinfo)
  147820. {
  147821. int i, td, ta;
  147822. jpeg_component_info *compptr;
  147823. emit_marker(cinfo, M_SOS);
  147824. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147825. emit_byte(cinfo, cinfo->comps_in_scan);
  147826. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147827. compptr = cinfo->cur_comp_info[i];
  147828. emit_byte(cinfo, compptr->component_id);
  147829. td = compptr->dc_tbl_no;
  147830. ta = compptr->ac_tbl_no;
  147831. if (cinfo->progressive_mode) {
  147832. if (cinfo->Ss == 0) {
  147833. ta = 0; /* DC scan */
  147834. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147835. td = 0; /* no DC table either */
  147836. } else {
  147837. td = 0; /* AC scan */
  147838. }
  147839. }
  147840. emit_byte(cinfo, (td << 4) + ta);
  147841. }
  147842. emit_byte(cinfo, cinfo->Ss);
  147843. emit_byte(cinfo, cinfo->Se);
  147844. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147845. }
  147846. LOCAL(void)
  147847. emit_jfif_app0 (j_compress_ptr cinfo)
  147848. {
  147849. emit_marker(cinfo, M_APP0);
  147850. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147851. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147852. emit_byte(cinfo, 0x46);
  147853. emit_byte(cinfo, 0x49);
  147854. emit_byte(cinfo, 0x46);
  147855. emit_byte(cinfo, 0);
  147856. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147857. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147858. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147859. emit_2bytes(cinfo, (int) cinfo->X_density);
  147860. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147861. emit_byte(cinfo, 0); /* No thumbnail image */
  147862. emit_byte(cinfo, 0);
  147863. }
  147864. LOCAL(void)
  147865. emit_adobe_app14 (j_compress_ptr cinfo)
  147866. {
  147867. emit_marker(cinfo, M_APP14);
  147868. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147869. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147870. emit_byte(cinfo, 0x64);
  147871. emit_byte(cinfo, 0x6F);
  147872. emit_byte(cinfo, 0x62);
  147873. emit_byte(cinfo, 0x65);
  147874. emit_2bytes(cinfo, 100); /* Version */
  147875. emit_2bytes(cinfo, 0); /* Flags0 */
  147876. emit_2bytes(cinfo, 0); /* Flags1 */
  147877. switch (cinfo->jpeg_color_space) {
  147878. case JCS_YCbCr:
  147879. emit_byte(cinfo, 1); /* Color transform = 1 */
  147880. break;
  147881. case JCS_YCCK:
  147882. emit_byte(cinfo, 2); /* Color transform = 2 */
  147883. break;
  147884. default:
  147885. emit_byte(cinfo, 0); /* Color transform = 0 */
  147886. break;
  147887. }
  147888. }
  147889. METHODDEF(void)
  147890. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147891. {
  147892. if (datalen > (unsigned int) 65533) /* safety check */
  147893. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147894. emit_marker(cinfo, (JPEG_MARKER) marker);
  147895. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147896. }
  147897. METHODDEF(void)
  147898. write_marker_byte (j_compress_ptr cinfo, int val)
  147899. {
  147900. emit_byte(cinfo, val);
  147901. }
  147902. METHODDEF(void)
  147903. write_file_header (j_compress_ptr cinfo)
  147904. {
  147905. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147906. emit_marker(cinfo, M_SOI); /* first the SOI */
  147907. marker->last_restart_interval = 0;
  147908. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147909. emit_jfif_app0(cinfo);
  147910. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147911. emit_adobe_app14(cinfo);
  147912. }
  147913. METHODDEF(void)
  147914. write_frame_header (j_compress_ptr cinfo)
  147915. {
  147916. int ci, prec;
  147917. boolean is_baseline;
  147918. jpeg_component_info *compptr;
  147919. prec = 0;
  147920. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147921. ci++, compptr++) {
  147922. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147923. }
  147924. if (cinfo->arith_code || cinfo->progressive_mode ||
  147925. cinfo->data_precision != 8) {
  147926. is_baseline = FALSE;
  147927. } else {
  147928. is_baseline = TRUE;
  147929. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147930. ci++, compptr++) {
  147931. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  147932. is_baseline = FALSE;
  147933. }
  147934. if (prec && is_baseline) {
  147935. is_baseline = FALSE;
  147936. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  147937. }
  147938. }
  147939. if (cinfo->arith_code) {
  147940. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  147941. } else {
  147942. if (cinfo->progressive_mode)
  147943. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  147944. else if (is_baseline)
  147945. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  147946. else
  147947. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  147948. }
  147949. }
  147950. METHODDEF(void)
  147951. write_scan_header (j_compress_ptr cinfo)
  147952. {
  147953. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147954. int i;
  147955. jpeg_component_info *compptr;
  147956. if (cinfo->arith_code) {
  147957. emit_dac(cinfo);
  147958. } else {
  147959. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147960. compptr = cinfo->cur_comp_info[i];
  147961. if (cinfo->progressive_mode) {
  147962. if (cinfo->Ss == 0) {
  147963. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  147964. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147965. } else {
  147966. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147967. }
  147968. } else {
  147969. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147970. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147971. }
  147972. }
  147973. }
  147974. if (cinfo->restart_interval != marker->last_restart_interval) {
  147975. emit_dri(cinfo);
  147976. marker->last_restart_interval = cinfo->restart_interval;
  147977. }
  147978. emit_sos(cinfo);
  147979. }
  147980. METHODDEF(void)
  147981. write_file_trailer (j_compress_ptr cinfo)
  147982. {
  147983. emit_marker(cinfo, M_EOI);
  147984. }
  147985. METHODDEF(void)
  147986. write_tables_only (j_compress_ptr cinfo)
  147987. {
  147988. int i;
  147989. emit_marker(cinfo, M_SOI);
  147990. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147991. if (cinfo->quant_tbl_ptrs[i] != NULL)
  147992. (void) emit_dqt(cinfo, i);
  147993. }
  147994. if (! cinfo->arith_code) {
  147995. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147996. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  147997. emit_dht(cinfo, i, FALSE);
  147998. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  147999. emit_dht(cinfo, i, TRUE);
  148000. }
  148001. }
  148002. emit_marker(cinfo, M_EOI);
  148003. }
  148004. GLOBAL(void)
  148005. jinit_marker_writer (j_compress_ptr cinfo)
  148006. {
  148007. my_marker_ptr marker;
  148008. marker = (my_marker_ptr)
  148009. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148010. SIZEOF(my_marker_writer));
  148011. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148012. marker->pub.write_file_header = write_file_header;
  148013. marker->pub.write_frame_header = write_frame_header;
  148014. marker->pub.write_scan_header = write_scan_header;
  148015. marker->pub.write_file_trailer = write_file_trailer;
  148016. marker->pub.write_tables_only = write_tables_only;
  148017. marker->pub.write_marker_header = write_marker_header;
  148018. marker->pub.write_marker_byte = write_marker_byte;
  148019. marker->last_restart_interval = 0;
  148020. }
  148021. /*** End of inlined file: jcmarker.c ***/
  148022. /*** Start of inlined file: jcmaster.c ***/
  148023. #define JPEG_INTERNALS
  148024. typedef enum {
  148025. main_pass, /* input data, also do first output step */
  148026. huff_opt_pass, /* Huffman code optimization pass */
  148027. output_pass /* data output pass */
  148028. } c_pass_type;
  148029. typedef struct {
  148030. struct jpeg_comp_master pub; /* public fields */
  148031. c_pass_type pass_type; /* the type of the current pass */
  148032. int pass_number; /* # of passes completed */
  148033. int total_passes; /* total # of passes needed */
  148034. int scan_number; /* current index in scan_info[] */
  148035. } my_comp_master;
  148036. typedef my_comp_master * my_master_ptr;
  148037. LOCAL(void)
  148038. initial_setup (j_compress_ptr cinfo)
  148039. {
  148040. int ci;
  148041. jpeg_component_info *compptr;
  148042. long samplesperrow;
  148043. JDIMENSION jd_samplesperrow;
  148044. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148045. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148046. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148047. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148048. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148049. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148050. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148051. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148052. if ((long) jd_samplesperrow != samplesperrow)
  148053. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148054. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148055. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148056. if (cinfo->num_components > MAX_COMPONENTS)
  148057. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148058. MAX_COMPONENTS);
  148059. cinfo->max_h_samp_factor = 1;
  148060. cinfo->max_v_samp_factor = 1;
  148061. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148062. ci++, compptr++) {
  148063. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148064. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148065. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148066. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148067. compptr->h_samp_factor);
  148068. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148069. compptr->v_samp_factor);
  148070. }
  148071. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148072. ci++, compptr++) {
  148073. compptr->component_index = ci;
  148074. compptr->DCT_scaled_size = DCTSIZE;
  148075. compptr->width_in_blocks = (JDIMENSION)
  148076. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148077. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148078. compptr->height_in_blocks = (JDIMENSION)
  148079. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148080. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148081. compptr->downsampled_width = (JDIMENSION)
  148082. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148083. (long) cinfo->max_h_samp_factor);
  148084. compptr->downsampled_height = (JDIMENSION)
  148085. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148086. (long) cinfo->max_v_samp_factor);
  148087. compptr->component_needed = TRUE;
  148088. }
  148089. cinfo->total_iMCU_rows = (JDIMENSION)
  148090. jdiv_round_up((long) cinfo->image_height,
  148091. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148092. }
  148093. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148094. LOCAL(void)
  148095. validate_script (j_compress_ptr cinfo)
  148096. {
  148097. const jpeg_scan_info * scanptr;
  148098. int scanno, ncomps, ci, coefi, thisi;
  148099. int Ss, Se, Ah, Al;
  148100. boolean component_sent[MAX_COMPONENTS];
  148101. #ifdef C_PROGRESSIVE_SUPPORTED
  148102. int * last_bitpos_ptr;
  148103. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148104. #endif
  148105. if (cinfo->num_scans <= 0)
  148106. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148107. scanptr = cinfo->scan_info;
  148108. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148109. #ifdef C_PROGRESSIVE_SUPPORTED
  148110. cinfo->progressive_mode = TRUE;
  148111. last_bitpos_ptr = & last_bitpos[0][0];
  148112. for (ci = 0; ci < cinfo->num_components; ci++)
  148113. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148114. *last_bitpos_ptr++ = -1;
  148115. #else
  148116. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148117. #endif
  148118. } else {
  148119. cinfo->progressive_mode = FALSE;
  148120. for (ci = 0; ci < cinfo->num_components; ci++)
  148121. component_sent[ci] = FALSE;
  148122. }
  148123. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148124. ncomps = scanptr->comps_in_scan;
  148125. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148126. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148127. for (ci = 0; ci < ncomps; ci++) {
  148128. thisi = scanptr->component_index[ci];
  148129. if (thisi < 0 || thisi >= cinfo->num_components)
  148130. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148131. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148132. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148133. }
  148134. Ss = scanptr->Ss;
  148135. Se = scanptr->Se;
  148136. Ah = scanptr->Ah;
  148137. Al = scanptr->Al;
  148138. if (cinfo->progressive_mode) {
  148139. #ifdef C_PROGRESSIVE_SUPPORTED
  148140. #if BITS_IN_JSAMPLE == 8
  148141. #define MAX_AH_AL 10
  148142. #else
  148143. #define MAX_AH_AL 13
  148144. #endif
  148145. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148146. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148147. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148148. if (Ss == 0) {
  148149. if (Se != 0) /* DC and AC together not OK */
  148150. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148151. } else {
  148152. if (ncomps != 1) /* AC scans must be for only one component */
  148153. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148154. }
  148155. for (ci = 0; ci < ncomps; ci++) {
  148156. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148157. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148158. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148159. for (coefi = Ss; coefi <= Se; coefi++) {
  148160. if (last_bitpos_ptr[coefi] < 0) {
  148161. if (Ah != 0)
  148162. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148163. } else {
  148164. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148165. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148166. }
  148167. last_bitpos_ptr[coefi] = Al;
  148168. }
  148169. }
  148170. #endif
  148171. } else {
  148172. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148173. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148174. for (ci = 0; ci < ncomps; ci++) {
  148175. thisi = scanptr->component_index[ci];
  148176. if (component_sent[thisi])
  148177. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148178. component_sent[thisi] = TRUE;
  148179. }
  148180. }
  148181. }
  148182. if (cinfo->progressive_mode) {
  148183. #ifdef C_PROGRESSIVE_SUPPORTED
  148184. for (ci = 0; ci < cinfo->num_components; ci++) {
  148185. if (last_bitpos[ci][0] < 0)
  148186. ERREXIT(cinfo, JERR_MISSING_DATA);
  148187. }
  148188. #endif
  148189. } else {
  148190. for (ci = 0; ci < cinfo->num_components; ci++) {
  148191. if (! component_sent[ci])
  148192. ERREXIT(cinfo, JERR_MISSING_DATA);
  148193. }
  148194. }
  148195. }
  148196. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148197. LOCAL(void)
  148198. select_scan_parameters (j_compress_ptr cinfo)
  148199. {
  148200. int ci;
  148201. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148202. if (cinfo->scan_info != NULL) {
  148203. my_master_ptr master = (my_master_ptr) cinfo->master;
  148204. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148205. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148206. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148207. cinfo->cur_comp_info[ci] =
  148208. &cinfo->comp_info[scanptr->component_index[ci]];
  148209. }
  148210. cinfo->Ss = scanptr->Ss;
  148211. cinfo->Se = scanptr->Se;
  148212. cinfo->Ah = scanptr->Ah;
  148213. cinfo->Al = scanptr->Al;
  148214. }
  148215. else
  148216. #endif
  148217. {
  148218. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148219. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148220. MAX_COMPS_IN_SCAN);
  148221. cinfo->comps_in_scan = cinfo->num_components;
  148222. for (ci = 0; ci < cinfo->num_components; ci++) {
  148223. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148224. }
  148225. cinfo->Ss = 0;
  148226. cinfo->Se = DCTSIZE2-1;
  148227. cinfo->Ah = 0;
  148228. cinfo->Al = 0;
  148229. }
  148230. }
  148231. LOCAL(void)
  148232. per_scan_setup (j_compress_ptr cinfo)
  148233. {
  148234. int ci, mcublks, tmp;
  148235. jpeg_component_info *compptr;
  148236. if (cinfo->comps_in_scan == 1) {
  148237. compptr = cinfo->cur_comp_info[0];
  148238. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148239. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148240. compptr->MCU_width = 1;
  148241. compptr->MCU_height = 1;
  148242. compptr->MCU_blocks = 1;
  148243. compptr->MCU_sample_width = DCTSIZE;
  148244. compptr->last_col_width = 1;
  148245. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148246. if (tmp == 0) tmp = compptr->v_samp_factor;
  148247. compptr->last_row_height = tmp;
  148248. cinfo->blocks_in_MCU = 1;
  148249. cinfo->MCU_membership[0] = 0;
  148250. } else {
  148251. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148252. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148253. MAX_COMPS_IN_SCAN);
  148254. cinfo->MCUs_per_row = (JDIMENSION)
  148255. jdiv_round_up((long) cinfo->image_width,
  148256. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148257. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148258. jdiv_round_up((long) cinfo->image_height,
  148259. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148260. cinfo->blocks_in_MCU = 0;
  148261. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148262. compptr = cinfo->cur_comp_info[ci];
  148263. compptr->MCU_width = compptr->h_samp_factor;
  148264. compptr->MCU_height = compptr->v_samp_factor;
  148265. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148266. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148267. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148268. if (tmp == 0) tmp = compptr->MCU_width;
  148269. compptr->last_col_width = tmp;
  148270. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148271. if (tmp == 0) tmp = compptr->MCU_height;
  148272. compptr->last_row_height = tmp;
  148273. mcublks = compptr->MCU_blocks;
  148274. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148275. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148276. while (mcublks-- > 0) {
  148277. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148278. }
  148279. }
  148280. }
  148281. if (cinfo->restart_in_rows > 0) {
  148282. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148283. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148284. }
  148285. }
  148286. METHODDEF(void)
  148287. prepare_for_pass (j_compress_ptr cinfo)
  148288. {
  148289. my_master_ptr master = (my_master_ptr) cinfo->master;
  148290. switch (master->pass_type) {
  148291. case main_pass:
  148292. select_scan_parameters(cinfo);
  148293. per_scan_setup(cinfo);
  148294. if (! cinfo->raw_data_in) {
  148295. (*cinfo->cconvert->start_pass) (cinfo);
  148296. (*cinfo->downsample->start_pass) (cinfo);
  148297. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148298. }
  148299. (*cinfo->fdct->start_pass) (cinfo);
  148300. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148301. (*cinfo->coef->start_pass) (cinfo,
  148302. (master->total_passes > 1 ?
  148303. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148304. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148305. if (cinfo->optimize_coding) {
  148306. master->pub.call_pass_startup = FALSE;
  148307. } else {
  148308. master->pub.call_pass_startup = TRUE;
  148309. }
  148310. break;
  148311. #ifdef ENTROPY_OPT_SUPPORTED
  148312. case huff_opt_pass:
  148313. select_scan_parameters(cinfo);
  148314. per_scan_setup(cinfo);
  148315. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148316. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148317. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148318. master->pub.call_pass_startup = FALSE;
  148319. break;
  148320. }
  148321. master->pass_type = output_pass;
  148322. master->pass_number++;
  148323. #endif
  148324. case output_pass:
  148325. if (! cinfo->optimize_coding) {
  148326. select_scan_parameters(cinfo);
  148327. per_scan_setup(cinfo);
  148328. }
  148329. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148330. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148331. if (master->scan_number == 0)
  148332. (*cinfo->marker->write_frame_header) (cinfo);
  148333. (*cinfo->marker->write_scan_header) (cinfo);
  148334. master->pub.call_pass_startup = FALSE;
  148335. break;
  148336. default:
  148337. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148338. }
  148339. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148340. if (cinfo->progress != NULL) {
  148341. cinfo->progress->completed_passes = master->pass_number;
  148342. cinfo->progress->total_passes = master->total_passes;
  148343. }
  148344. }
  148345. METHODDEF(void)
  148346. pass_startup (j_compress_ptr cinfo)
  148347. {
  148348. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148349. (*cinfo->marker->write_frame_header) (cinfo);
  148350. (*cinfo->marker->write_scan_header) (cinfo);
  148351. }
  148352. METHODDEF(void)
  148353. finish_pass_master (j_compress_ptr cinfo)
  148354. {
  148355. my_master_ptr master = (my_master_ptr) cinfo->master;
  148356. (*cinfo->entropy->finish_pass) (cinfo);
  148357. switch (master->pass_type) {
  148358. case main_pass:
  148359. master->pass_type = output_pass;
  148360. if (! cinfo->optimize_coding)
  148361. master->scan_number++;
  148362. break;
  148363. case huff_opt_pass:
  148364. master->pass_type = output_pass;
  148365. break;
  148366. case output_pass:
  148367. if (cinfo->optimize_coding)
  148368. master->pass_type = huff_opt_pass;
  148369. master->scan_number++;
  148370. break;
  148371. }
  148372. master->pass_number++;
  148373. }
  148374. GLOBAL(void)
  148375. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148376. {
  148377. my_master_ptr master;
  148378. master = (my_master_ptr)
  148379. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148380. SIZEOF(my_comp_master));
  148381. cinfo->master = (struct jpeg_comp_master *) master;
  148382. master->pub.prepare_for_pass = prepare_for_pass;
  148383. master->pub.pass_startup = pass_startup;
  148384. master->pub.finish_pass = finish_pass_master;
  148385. master->pub.is_last_pass = FALSE;
  148386. initial_setup(cinfo);
  148387. if (cinfo->scan_info != NULL) {
  148388. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148389. validate_script(cinfo);
  148390. #else
  148391. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148392. #endif
  148393. } else {
  148394. cinfo->progressive_mode = FALSE;
  148395. cinfo->num_scans = 1;
  148396. }
  148397. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148398. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148399. if (transcode_only) {
  148400. if (cinfo->optimize_coding)
  148401. master->pass_type = huff_opt_pass;
  148402. else
  148403. master->pass_type = output_pass;
  148404. } else {
  148405. master->pass_type = main_pass;
  148406. }
  148407. master->scan_number = 0;
  148408. master->pass_number = 0;
  148409. if (cinfo->optimize_coding)
  148410. master->total_passes = cinfo->num_scans * 2;
  148411. else
  148412. master->total_passes = cinfo->num_scans;
  148413. }
  148414. /*** End of inlined file: jcmaster.c ***/
  148415. /*** Start of inlined file: jcomapi.c ***/
  148416. #define JPEG_INTERNALS
  148417. GLOBAL(void)
  148418. jpeg_abort (j_common_ptr cinfo)
  148419. {
  148420. int pool;
  148421. if (cinfo->mem == NULL)
  148422. return;
  148423. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148424. (*cinfo->mem->free_pool) (cinfo, pool);
  148425. }
  148426. if (cinfo->is_decompressor) {
  148427. cinfo->global_state = DSTATE_START;
  148428. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148429. } else {
  148430. cinfo->global_state = CSTATE_START;
  148431. }
  148432. }
  148433. GLOBAL(void)
  148434. jpeg_destroy (j_common_ptr cinfo)
  148435. {
  148436. if (cinfo->mem != NULL)
  148437. (*cinfo->mem->self_destruct) (cinfo);
  148438. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148439. cinfo->global_state = 0; /* mark it destroyed */
  148440. }
  148441. GLOBAL(JQUANT_TBL *)
  148442. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148443. {
  148444. JQUANT_TBL *tbl;
  148445. tbl = (JQUANT_TBL *)
  148446. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148447. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148448. return tbl;
  148449. }
  148450. GLOBAL(JHUFF_TBL *)
  148451. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148452. {
  148453. JHUFF_TBL *tbl;
  148454. tbl = (JHUFF_TBL *)
  148455. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148456. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148457. return tbl;
  148458. }
  148459. /*** End of inlined file: jcomapi.c ***/
  148460. /*** Start of inlined file: jcparam.c ***/
  148461. #define JPEG_INTERNALS
  148462. GLOBAL(void)
  148463. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148464. const unsigned int *basic_table,
  148465. int scale_factor, boolean force_baseline)
  148466. {
  148467. JQUANT_TBL ** qtblptr;
  148468. int i;
  148469. long temp;
  148470. if (cinfo->global_state != CSTATE_START)
  148471. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148472. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148473. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148474. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148475. if (*qtblptr == NULL)
  148476. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148477. for (i = 0; i < DCTSIZE2; i++) {
  148478. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148479. if (temp <= 0L) temp = 1L;
  148480. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148481. if (force_baseline && temp > 255L)
  148482. temp = 255L; /* limit to baseline range if requested */
  148483. (*qtblptr)->quantval[i] = (UINT16) temp;
  148484. }
  148485. (*qtblptr)->sent_table = FALSE;
  148486. }
  148487. GLOBAL(void)
  148488. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148489. boolean force_baseline)
  148490. {
  148491. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148492. 16, 11, 10, 16, 24, 40, 51, 61,
  148493. 12, 12, 14, 19, 26, 58, 60, 55,
  148494. 14, 13, 16, 24, 40, 57, 69, 56,
  148495. 14, 17, 22, 29, 51, 87, 80, 62,
  148496. 18, 22, 37, 56, 68, 109, 103, 77,
  148497. 24, 35, 55, 64, 81, 104, 113, 92,
  148498. 49, 64, 78, 87, 103, 121, 120, 101,
  148499. 72, 92, 95, 98, 112, 100, 103, 99
  148500. };
  148501. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148502. 17, 18, 24, 47, 99, 99, 99, 99,
  148503. 18, 21, 26, 66, 99, 99, 99, 99,
  148504. 24, 26, 56, 99, 99, 99, 99, 99,
  148505. 47, 66, 99, 99, 99, 99, 99, 99,
  148506. 99, 99, 99, 99, 99, 99, 99, 99,
  148507. 99, 99, 99, 99, 99, 99, 99, 99,
  148508. 99, 99, 99, 99, 99, 99, 99, 99,
  148509. 99, 99, 99, 99, 99, 99, 99, 99
  148510. };
  148511. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148512. scale_factor, force_baseline);
  148513. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148514. scale_factor, force_baseline);
  148515. }
  148516. GLOBAL(int)
  148517. jpeg_quality_scaling (int quality)
  148518. {
  148519. if (quality <= 0) quality = 1;
  148520. if (quality > 100) quality = 100;
  148521. if (quality < 50)
  148522. quality = 5000 / quality;
  148523. else
  148524. quality = 200 - quality*2;
  148525. return quality;
  148526. }
  148527. GLOBAL(void)
  148528. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148529. {
  148530. quality = jpeg_quality_scaling(quality);
  148531. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148532. }
  148533. LOCAL(void)
  148534. add_huff_table (j_compress_ptr cinfo,
  148535. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148536. {
  148537. int nsymbols, len;
  148538. if (*htblptr == NULL)
  148539. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148540. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148541. nsymbols = 0;
  148542. for (len = 1; len <= 16; len++)
  148543. nsymbols += bits[len];
  148544. if (nsymbols < 1 || nsymbols > 256)
  148545. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148546. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148547. (*htblptr)->sent_table = FALSE;
  148548. }
  148549. LOCAL(void)
  148550. std_huff_tables (j_compress_ptr cinfo)
  148551. {
  148552. static const UINT8 bits_dc_luminance[17] =
  148553. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148554. static const UINT8 val_dc_luminance[] =
  148555. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148556. static const UINT8 bits_dc_chrominance[17] =
  148557. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148558. static const UINT8 val_dc_chrominance[] =
  148559. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148560. static const UINT8 bits_ac_luminance[17] =
  148561. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148562. static const UINT8 val_ac_luminance[] =
  148563. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148564. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148565. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148566. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148567. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148568. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148569. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148570. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148571. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148572. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148573. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148574. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148575. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148576. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148577. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148578. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148579. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148580. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148581. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148582. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148583. 0xf9, 0xfa };
  148584. static const UINT8 bits_ac_chrominance[17] =
  148585. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148586. static const UINT8 val_ac_chrominance[] =
  148587. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148588. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148589. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148590. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148591. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148592. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148593. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148594. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148595. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148596. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148597. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148598. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148599. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148600. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148601. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148602. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148603. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148604. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148605. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148606. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148607. 0xf9, 0xfa };
  148608. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148609. bits_dc_luminance, val_dc_luminance);
  148610. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148611. bits_ac_luminance, val_ac_luminance);
  148612. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148613. bits_dc_chrominance, val_dc_chrominance);
  148614. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148615. bits_ac_chrominance, val_ac_chrominance);
  148616. }
  148617. GLOBAL(void)
  148618. jpeg_set_defaults (j_compress_ptr cinfo)
  148619. {
  148620. int i;
  148621. if (cinfo->global_state != CSTATE_START)
  148622. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148623. if (cinfo->comp_info == NULL)
  148624. cinfo->comp_info = (jpeg_component_info *)
  148625. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148626. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148627. cinfo->data_precision = BITS_IN_JSAMPLE;
  148628. jpeg_set_quality(cinfo, 75, TRUE);
  148629. std_huff_tables(cinfo);
  148630. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148631. cinfo->arith_dc_L[i] = 0;
  148632. cinfo->arith_dc_U[i] = 1;
  148633. cinfo->arith_ac_K[i] = 5;
  148634. }
  148635. cinfo->scan_info = NULL;
  148636. cinfo->num_scans = 0;
  148637. cinfo->raw_data_in = FALSE;
  148638. cinfo->arith_code = FALSE;
  148639. cinfo->optimize_coding = FALSE;
  148640. if (cinfo->data_precision > 8)
  148641. cinfo->optimize_coding = TRUE;
  148642. cinfo->CCIR601_sampling = FALSE;
  148643. cinfo->smoothing_factor = 0;
  148644. cinfo->dct_method = JDCT_DEFAULT;
  148645. cinfo->restart_interval = 0;
  148646. cinfo->restart_in_rows = 0;
  148647. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148648. cinfo->JFIF_minor_version = 1;
  148649. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148650. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148651. cinfo->Y_density = 1;
  148652. jpeg_default_colorspace(cinfo);
  148653. }
  148654. GLOBAL(void)
  148655. jpeg_default_colorspace (j_compress_ptr cinfo)
  148656. {
  148657. switch (cinfo->in_color_space) {
  148658. case JCS_GRAYSCALE:
  148659. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148660. break;
  148661. case JCS_RGB:
  148662. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148663. break;
  148664. case JCS_YCbCr:
  148665. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148666. break;
  148667. case JCS_CMYK:
  148668. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148669. break;
  148670. case JCS_YCCK:
  148671. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148672. break;
  148673. case JCS_UNKNOWN:
  148674. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148675. break;
  148676. default:
  148677. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148678. }
  148679. }
  148680. GLOBAL(void)
  148681. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148682. {
  148683. jpeg_component_info * compptr;
  148684. int ci;
  148685. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148686. (compptr = &cinfo->comp_info[index], \
  148687. compptr->component_id = (id), \
  148688. compptr->h_samp_factor = (hsamp), \
  148689. compptr->v_samp_factor = (vsamp), \
  148690. compptr->quant_tbl_no = (quant), \
  148691. compptr->dc_tbl_no = (dctbl), \
  148692. compptr->ac_tbl_no = (actbl) )
  148693. if (cinfo->global_state != CSTATE_START)
  148694. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148695. cinfo->jpeg_color_space = colorspace;
  148696. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148697. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148698. switch (colorspace) {
  148699. case JCS_GRAYSCALE:
  148700. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148701. cinfo->num_components = 1;
  148702. SET_COMP(0, 1, 1,1, 0, 0,0);
  148703. break;
  148704. case JCS_RGB:
  148705. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148706. cinfo->num_components = 3;
  148707. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148708. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148709. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148710. break;
  148711. case JCS_YCbCr:
  148712. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148713. cinfo->num_components = 3;
  148714. SET_COMP(0, 1, 2,2, 0, 0,0);
  148715. SET_COMP(1, 2, 1,1, 1, 1,1);
  148716. SET_COMP(2, 3, 1,1, 1, 1,1);
  148717. break;
  148718. case JCS_CMYK:
  148719. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148720. cinfo->num_components = 4;
  148721. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148722. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148723. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148724. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148725. break;
  148726. case JCS_YCCK:
  148727. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148728. cinfo->num_components = 4;
  148729. SET_COMP(0, 1, 2,2, 0, 0,0);
  148730. SET_COMP(1, 2, 1,1, 1, 1,1);
  148731. SET_COMP(2, 3, 1,1, 1, 1,1);
  148732. SET_COMP(3, 4, 2,2, 0, 0,0);
  148733. break;
  148734. case JCS_UNKNOWN:
  148735. cinfo->num_components = cinfo->input_components;
  148736. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148737. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148738. MAX_COMPONENTS);
  148739. for (ci = 0; ci < cinfo->num_components; ci++) {
  148740. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148741. }
  148742. break;
  148743. default:
  148744. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148745. }
  148746. }
  148747. #ifdef C_PROGRESSIVE_SUPPORTED
  148748. LOCAL(jpeg_scan_info *)
  148749. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148750. int Ss, int Se, int Ah, int Al)
  148751. {
  148752. scanptr->comps_in_scan = 1;
  148753. scanptr->component_index[0] = ci;
  148754. scanptr->Ss = Ss;
  148755. scanptr->Se = Se;
  148756. scanptr->Ah = Ah;
  148757. scanptr->Al = Al;
  148758. scanptr++;
  148759. return scanptr;
  148760. }
  148761. LOCAL(jpeg_scan_info *)
  148762. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148763. int Ss, int Se, int Ah, int Al)
  148764. {
  148765. int ci;
  148766. for (ci = 0; ci < ncomps; ci++) {
  148767. scanptr->comps_in_scan = 1;
  148768. scanptr->component_index[0] = ci;
  148769. scanptr->Ss = Ss;
  148770. scanptr->Se = Se;
  148771. scanptr->Ah = Ah;
  148772. scanptr->Al = Al;
  148773. scanptr++;
  148774. }
  148775. return scanptr;
  148776. }
  148777. LOCAL(jpeg_scan_info *)
  148778. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148779. {
  148780. int ci;
  148781. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148782. scanptr->comps_in_scan = ncomps;
  148783. for (ci = 0; ci < ncomps; ci++)
  148784. scanptr->component_index[ci] = ci;
  148785. scanptr->Ss = scanptr->Se = 0;
  148786. scanptr->Ah = Ah;
  148787. scanptr->Al = Al;
  148788. scanptr++;
  148789. } else {
  148790. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148791. }
  148792. return scanptr;
  148793. }
  148794. GLOBAL(void)
  148795. jpeg_simple_progression (j_compress_ptr cinfo)
  148796. {
  148797. int ncomps = cinfo->num_components;
  148798. int nscans;
  148799. jpeg_scan_info * scanptr;
  148800. if (cinfo->global_state != CSTATE_START)
  148801. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148802. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148803. nscans = 10;
  148804. } else {
  148805. if (ncomps > MAX_COMPS_IN_SCAN)
  148806. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148807. else
  148808. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148809. }
  148810. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148811. cinfo->script_space_size = MAX(nscans, 10);
  148812. cinfo->script_space = (jpeg_scan_info *)
  148813. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148814. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148815. }
  148816. scanptr = cinfo->script_space;
  148817. cinfo->scan_info = scanptr;
  148818. cinfo->num_scans = nscans;
  148819. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148820. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148821. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148822. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148823. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148824. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148825. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148826. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148827. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148828. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148829. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148830. } else {
  148831. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148832. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148833. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148834. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148835. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148836. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148837. }
  148838. }
  148839. #endif /* C_PROGRESSIVE_SUPPORTED */
  148840. /*** End of inlined file: jcparam.c ***/
  148841. /*** Start of inlined file: jcphuff.c ***/
  148842. #define JPEG_INTERNALS
  148843. #ifdef C_PROGRESSIVE_SUPPORTED
  148844. typedef struct {
  148845. struct jpeg_entropy_encoder pub; /* public fields */
  148846. boolean gather_statistics;
  148847. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148848. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148849. INT32 put_buffer; /* current bit-accumulation buffer */
  148850. int put_bits; /* # of bits now in it */
  148851. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148852. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148853. int ac_tbl_no; /* the table number of the single component */
  148854. unsigned int EOBRUN; /* run length of EOBs */
  148855. unsigned int BE; /* # of buffered correction bits before MCU */
  148856. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148857. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148858. int next_restart_num; /* next restart number to write (0-7) */
  148859. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148860. long * count_ptrs[NUM_HUFF_TBLS];
  148861. } phuff_entropy_encoder;
  148862. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148863. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148864. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148865. #define ISHIFT_TEMPS int ishift_temp;
  148866. #define IRIGHT_SHIFT(x,shft) \
  148867. ((ishift_temp = (x)) < 0 ? \
  148868. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148869. (ishift_temp >> (shft)))
  148870. #else
  148871. #define ISHIFT_TEMPS
  148872. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148873. #endif
  148874. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148875. JBLOCKROW *MCU_data));
  148876. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148877. JBLOCKROW *MCU_data));
  148878. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148879. JBLOCKROW *MCU_data));
  148880. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148881. JBLOCKROW *MCU_data));
  148882. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148883. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148884. METHODDEF(void)
  148885. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148886. {
  148887. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148888. boolean is_DC_band;
  148889. int ci, tbl;
  148890. jpeg_component_info * compptr;
  148891. entropy->cinfo = cinfo;
  148892. entropy->gather_statistics = gather_statistics;
  148893. is_DC_band = (cinfo->Ss == 0);
  148894. if (cinfo->Ah == 0) {
  148895. if (is_DC_band)
  148896. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148897. else
  148898. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148899. } else {
  148900. if (is_DC_band)
  148901. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148902. else {
  148903. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148904. if (entropy->bit_buffer == NULL)
  148905. entropy->bit_buffer = (char *)
  148906. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148907. MAX_CORR_BITS * SIZEOF(char));
  148908. }
  148909. }
  148910. if (gather_statistics)
  148911. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148912. else
  148913. entropy->pub.finish_pass = finish_pass_phuff;
  148914. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148915. compptr = cinfo->cur_comp_info[ci];
  148916. entropy->last_dc_val[ci] = 0;
  148917. if (is_DC_band) {
  148918. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148919. continue;
  148920. tbl = compptr->dc_tbl_no;
  148921. } else {
  148922. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148923. }
  148924. if (gather_statistics) {
  148925. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148926. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148927. if (entropy->count_ptrs[tbl] == NULL)
  148928. entropy->count_ptrs[tbl] = (long *)
  148929. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148930. 257 * SIZEOF(long));
  148931. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  148932. } else {
  148933. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  148934. & entropy->derived_tbls[tbl]);
  148935. }
  148936. }
  148937. entropy->EOBRUN = 0;
  148938. entropy->BE = 0;
  148939. entropy->put_buffer = 0;
  148940. entropy->put_bits = 0;
  148941. entropy->restarts_to_go = cinfo->restart_interval;
  148942. entropy->next_restart_num = 0;
  148943. }
  148944. #define emit_byte(entropy,val) \
  148945. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  148946. if (--(entropy)->free_in_buffer == 0) \
  148947. dump_buffer_p(entropy); }
  148948. LOCAL(void)
  148949. dump_buffer_p (phuff_entropy_ptr entropy)
  148950. {
  148951. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  148952. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  148953. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  148954. entropy->next_output_byte = dest->next_output_byte;
  148955. entropy->free_in_buffer = dest->free_in_buffer;
  148956. }
  148957. INLINE
  148958. LOCAL(void)
  148959. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  148960. {
  148961. register INT32 put_buffer = (INT32) code;
  148962. register int put_bits = entropy->put_bits;
  148963. if (size == 0)
  148964. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148965. if (entropy->gather_statistics)
  148966. return; /* do nothing if we're only getting stats */
  148967. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  148968. put_bits += size; /* new number of bits in buffer */
  148969. put_buffer <<= 24 - put_bits; /* align incoming bits */
  148970. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  148971. while (put_bits >= 8) {
  148972. int c = (int) ((put_buffer >> 16) & 0xFF);
  148973. emit_byte(entropy, c);
  148974. if (c == 0xFF) { /* need to stuff a zero byte? */
  148975. emit_byte(entropy, 0);
  148976. }
  148977. put_buffer <<= 8;
  148978. put_bits -= 8;
  148979. }
  148980. entropy->put_buffer = put_buffer; /* update variables */
  148981. entropy->put_bits = put_bits;
  148982. }
  148983. LOCAL(void)
  148984. flush_bits_p (phuff_entropy_ptr entropy)
  148985. {
  148986. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  148987. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  148988. entropy->put_bits = 0;
  148989. }
  148990. INLINE
  148991. LOCAL(void)
  148992. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  148993. {
  148994. if (entropy->gather_statistics)
  148995. entropy->count_ptrs[tbl_no][symbol]++;
  148996. else {
  148997. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  148998. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  148999. }
  149000. }
  149001. LOCAL(void)
  149002. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149003. unsigned int nbits)
  149004. {
  149005. if (entropy->gather_statistics)
  149006. return; /* no real work */
  149007. while (nbits > 0) {
  149008. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149009. bufstart++;
  149010. nbits--;
  149011. }
  149012. }
  149013. LOCAL(void)
  149014. emit_eobrun (phuff_entropy_ptr entropy)
  149015. {
  149016. register int temp, nbits;
  149017. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149018. temp = entropy->EOBRUN;
  149019. nbits = 0;
  149020. while ((temp >>= 1))
  149021. nbits++;
  149022. if (nbits > 14)
  149023. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149024. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149025. if (nbits)
  149026. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149027. entropy->EOBRUN = 0;
  149028. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149029. entropy->BE = 0;
  149030. }
  149031. }
  149032. LOCAL(void)
  149033. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149034. {
  149035. int ci;
  149036. emit_eobrun(entropy);
  149037. if (! entropy->gather_statistics) {
  149038. flush_bits_p(entropy);
  149039. emit_byte(entropy, 0xFF);
  149040. emit_byte(entropy, JPEG_RST0 + restart_num);
  149041. }
  149042. if (entropy->cinfo->Ss == 0) {
  149043. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149044. entropy->last_dc_val[ci] = 0;
  149045. } else {
  149046. entropy->EOBRUN = 0;
  149047. entropy->BE = 0;
  149048. }
  149049. }
  149050. METHODDEF(boolean)
  149051. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149052. {
  149053. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149054. register int temp, temp2;
  149055. register int nbits;
  149056. int blkn, ci;
  149057. int Al = cinfo->Al;
  149058. JBLOCKROW block;
  149059. jpeg_component_info * compptr;
  149060. ISHIFT_TEMPS
  149061. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149062. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149063. if (cinfo->restart_interval)
  149064. if (entropy->restarts_to_go == 0)
  149065. emit_restart_p(entropy, entropy->next_restart_num);
  149066. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149067. block = MCU_data[blkn];
  149068. ci = cinfo->MCU_membership[blkn];
  149069. compptr = cinfo->cur_comp_info[ci];
  149070. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149071. temp = temp2 - entropy->last_dc_val[ci];
  149072. entropy->last_dc_val[ci] = temp2;
  149073. temp2 = temp;
  149074. if (temp < 0) {
  149075. temp = -temp; /* temp is abs value of input */
  149076. temp2--;
  149077. }
  149078. nbits = 0;
  149079. while (temp) {
  149080. nbits++;
  149081. temp >>= 1;
  149082. }
  149083. if (nbits > MAX_COEF_BITS+1)
  149084. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149085. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149086. if (nbits) /* emit_bits rejects calls with size 0 */
  149087. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149088. }
  149089. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149090. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149091. if (cinfo->restart_interval) {
  149092. if (entropy->restarts_to_go == 0) {
  149093. entropy->restarts_to_go = cinfo->restart_interval;
  149094. entropy->next_restart_num++;
  149095. entropy->next_restart_num &= 7;
  149096. }
  149097. entropy->restarts_to_go--;
  149098. }
  149099. return TRUE;
  149100. }
  149101. METHODDEF(boolean)
  149102. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149103. {
  149104. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149105. register int temp, temp2;
  149106. register int nbits;
  149107. register int r, k;
  149108. int Se = cinfo->Se;
  149109. int Al = cinfo->Al;
  149110. JBLOCKROW block;
  149111. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149112. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149113. if (cinfo->restart_interval)
  149114. if (entropy->restarts_to_go == 0)
  149115. emit_restart_p(entropy, entropy->next_restart_num);
  149116. block = MCU_data[0];
  149117. r = 0; /* r = run length of zeros */
  149118. for (k = cinfo->Ss; k <= Se; k++) {
  149119. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149120. r++;
  149121. continue;
  149122. }
  149123. if (temp < 0) {
  149124. temp = -temp; /* temp is abs value of input */
  149125. temp >>= Al; /* apply the point transform */
  149126. temp2 = ~temp;
  149127. } else {
  149128. temp >>= Al; /* apply the point transform */
  149129. temp2 = temp;
  149130. }
  149131. if (temp == 0) {
  149132. r++;
  149133. continue;
  149134. }
  149135. if (entropy->EOBRUN > 0)
  149136. emit_eobrun(entropy);
  149137. while (r > 15) {
  149138. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149139. r -= 16;
  149140. }
  149141. nbits = 1; /* there must be at least one 1 bit */
  149142. while ((temp >>= 1))
  149143. nbits++;
  149144. if (nbits > MAX_COEF_BITS)
  149145. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149146. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149147. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149148. r = 0; /* reset zero run length */
  149149. }
  149150. if (r > 0) { /* If there are trailing zeroes, */
  149151. entropy->EOBRUN++; /* count an EOB */
  149152. if (entropy->EOBRUN == 0x7FFF)
  149153. emit_eobrun(entropy); /* force it out to avoid overflow */
  149154. }
  149155. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149156. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149157. if (cinfo->restart_interval) {
  149158. if (entropy->restarts_to_go == 0) {
  149159. entropy->restarts_to_go = cinfo->restart_interval;
  149160. entropy->next_restart_num++;
  149161. entropy->next_restart_num &= 7;
  149162. }
  149163. entropy->restarts_to_go--;
  149164. }
  149165. return TRUE;
  149166. }
  149167. METHODDEF(boolean)
  149168. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149169. {
  149170. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149171. register int temp;
  149172. int blkn;
  149173. int Al = cinfo->Al;
  149174. JBLOCKROW block;
  149175. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149176. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149177. if (cinfo->restart_interval)
  149178. if (entropy->restarts_to_go == 0)
  149179. emit_restart_p(entropy, entropy->next_restart_num);
  149180. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149181. block = MCU_data[blkn];
  149182. temp = (*block)[0];
  149183. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149184. }
  149185. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149186. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149187. if (cinfo->restart_interval) {
  149188. if (entropy->restarts_to_go == 0) {
  149189. entropy->restarts_to_go = cinfo->restart_interval;
  149190. entropy->next_restart_num++;
  149191. entropy->next_restart_num &= 7;
  149192. }
  149193. entropy->restarts_to_go--;
  149194. }
  149195. return TRUE;
  149196. }
  149197. METHODDEF(boolean)
  149198. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149199. {
  149200. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149201. register int temp;
  149202. register int r, k;
  149203. int EOB;
  149204. char *BR_buffer;
  149205. unsigned int BR;
  149206. int Se = cinfo->Se;
  149207. int Al = cinfo->Al;
  149208. JBLOCKROW block;
  149209. int absvalues[DCTSIZE2];
  149210. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149211. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149212. if (cinfo->restart_interval)
  149213. if (entropy->restarts_to_go == 0)
  149214. emit_restart_p(entropy, entropy->next_restart_num);
  149215. block = MCU_data[0];
  149216. EOB = 0;
  149217. for (k = cinfo->Ss; k <= Se; k++) {
  149218. temp = (*block)[jpeg_natural_order[k]];
  149219. if (temp < 0)
  149220. temp = -temp; /* temp is abs value of input */
  149221. temp >>= Al; /* apply the point transform */
  149222. absvalues[k] = temp; /* save abs value for main pass */
  149223. if (temp == 1)
  149224. EOB = k; /* EOB = index of last newly-nonzero coef */
  149225. }
  149226. r = 0; /* r = run length of zeros */
  149227. BR = 0; /* BR = count of buffered bits added now */
  149228. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149229. for (k = cinfo->Ss; k <= Se; k++) {
  149230. if ((temp = absvalues[k]) == 0) {
  149231. r++;
  149232. continue;
  149233. }
  149234. while (r > 15 && k <= EOB) {
  149235. emit_eobrun(entropy);
  149236. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149237. r -= 16;
  149238. emit_buffered_bits(entropy, BR_buffer, BR);
  149239. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149240. BR = 0;
  149241. }
  149242. if (temp > 1) {
  149243. BR_buffer[BR++] = (char) (temp & 1);
  149244. continue;
  149245. }
  149246. emit_eobrun(entropy);
  149247. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149248. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149249. emit_bits_p(entropy, (unsigned int) temp, 1);
  149250. emit_buffered_bits(entropy, BR_buffer, BR);
  149251. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149252. BR = 0;
  149253. r = 0; /* reset zero run length */
  149254. }
  149255. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149256. entropy->EOBRUN++; /* count an EOB */
  149257. entropy->BE += BR; /* concat my correction bits to older ones */
  149258. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149259. emit_eobrun(entropy);
  149260. }
  149261. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149262. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149263. if (cinfo->restart_interval) {
  149264. if (entropy->restarts_to_go == 0) {
  149265. entropy->restarts_to_go = cinfo->restart_interval;
  149266. entropy->next_restart_num++;
  149267. entropy->next_restart_num &= 7;
  149268. }
  149269. entropy->restarts_to_go--;
  149270. }
  149271. return TRUE;
  149272. }
  149273. METHODDEF(void)
  149274. finish_pass_phuff (j_compress_ptr cinfo)
  149275. {
  149276. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149277. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149278. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149279. emit_eobrun(entropy);
  149280. flush_bits_p(entropy);
  149281. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149282. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149283. }
  149284. METHODDEF(void)
  149285. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149286. {
  149287. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149288. boolean is_DC_band;
  149289. int ci, tbl;
  149290. jpeg_component_info * compptr;
  149291. JHUFF_TBL **htblptr;
  149292. boolean did[NUM_HUFF_TBLS];
  149293. emit_eobrun(entropy);
  149294. is_DC_band = (cinfo->Ss == 0);
  149295. MEMZERO(did, SIZEOF(did));
  149296. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149297. compptr = cinfo->cur_comp_info[ci];
  149298. if (is_DC_band) {
  149299. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149300. continue;
  149301. tbl = compptr->dc_tbl_no;
  149302. } else {
  149303. tbl = compptr->ac_tbl_no;
  149304. }
  149305. if (! did[tbl]) {
  149306. if (is_DC_band)
  149307. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149308. else
  149309. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149310. if (*htblptr == NULL)
  149311. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149312. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149313. did[tbl] = TRUE;
  149314. }
  149315. }
  149316. }
  149317. GLOBAL(void)
  149318. jinit_phuff_encoder (j_compress_ptr cinfo)
  149319. {
  149320. phuff_entropy_ptr entropy;
  149321. int i;
  149322. entropy = (phuff_entropy_ptr)
  149323. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149324. SIZEOF(phuff_entropy_encoder));
  149325. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149326. entropy->pub.start_pass = start_pass_phuff;
  149327. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149328. entropy->derived_tbls[i] = NULL;
  149329. entropy->count_ptrs[i] = NULL;
  149330. }
  149331. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149332. }
  149333. #endif /* C_PROGRESSIVE_SUPPORTED */
  149334. /*** End of inlined file: jcphuff.c ***/
  149335. /*** Start of inlined file: jcprepct.c ***/
  149336. #define JPEG_INTERNALS
  149337. #ifdef INPUT_SMOOTHING_SUPPORTED
  149338. #define CONTEXT_ROWS_SUPPORTED
  149339. #endif
  149340. typedef struct {
  149341. struct jpeg_c_prep_controller pub; /* public fields */
  149342. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149343. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149344. int next_buf_row; /* index of next row to store in color_buf */
  149345. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149346. int this_row_group; /* starting row index of group to process */
  149347. int next_buf_stop; /* downsample when we reach this index */
  149348. #endif
  149349. } my_prep_controller;
  149350. typedef my_prep_controller * my_prep_ptr;
  149351. METHODDEF(void)
  149352. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149353. {
  149354. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149355. if (pass_mode != JBUF_PASS_THRU)
  149356. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149357. prep->rows_to_go = cinfo->image_height;
  149358. prep->next_buf_row = 0;
  149359. #ifdef CONTEXT_ROWS_SUPPORTED
  149360. prep->this_row_group = 0;
  149361. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149362. #endif
  149363. }
  149364. LOCAL(void)
  149365. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149366. int input_rows, int output_rows)
  149367. {
  149368. register int row;
  149369. for (row = input_rows; row < output_rows; row++) {
  149370. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149371. 1, num_cols);
  149372. }
  149373. }
  149374. METHODDEF(void)
  149375. pre_process_data (j_compress_ptr cinfo,
  149376. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149377. JDIMENSION in_rows_avail,
  149378. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149379. JDIMENSION out_row_groups_avail)
  149380. {
  149381. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149382. int numrows, ci;
  149383. JDIMENSION inrows;
  149384. jpeg_component_info * compptr;
  149385. while (*in_row_ctr < in_rows_avail &&
  149386. *out_row_group_ctr < out_row_groups_avail) {
  149387. inrows = in_rows_avail - *in_row_ctr;
  149388. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149389. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149390. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149391. prep->color_buf,
  149392. (JDIMENSION) prep->next_buf_row,
  149393. numrows);
  149394. *in_row_ctr += numrows;
  149395. prep->next_buf_row += numrows;
  149396. prep->rows_to_go -= numrows;
  149397. if (prep->rows_to_go == 0 &&
  149398. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149399. for (ci = 0; ci < cinfo->num_components; ci++) {
  149400. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149401. prep->next_buf_row, cinfo->max_v_samp_factor);
  149402. }
  149403. prep->next_buf_row = cinfo->max_v_samp_factor;
  149404. }
  149405. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149406. (*cinfo->downsample->downsample) (cinfo,
  149407. prep->color_buf, (JDIMENSION) 0,
  149408. output_buf, *out_row_group_ctr);
  149409. prep->next_buf_row = 0;
  149410. (*out_row_group_ctr)++;
  149411. }
  149412. if (prep->rows_to_go == 0 &&
  149413. *out_row_group_ctr < out_row_groups_avail) {
  149414. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149415. ci++, compptr++) {
  149416. expand_bottom_edge(output_buf[ci],
  149417. compptr->width_in_blocks * DCTSIZE,
  149418. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149419. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149420. }
  149421. *out_row_group_ctr = out_row_groups_avail;
  149422. break; /* can exit outer loop without test */
  149423. }
  149424. }
  149425. }
  149426. #ifdef CONTEXT_ROWS_SUPPORTED
  149427. METHODDEF(void)
  149428. pre_process_context (j_compress_ptr cinfo,
  149429. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149430. JDIMENSION in_rows_avail,
  149431. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149432. JDIMENSION out_row_groups_avail)
  149433. {
  149434. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149435. int numrows, ci;
  149436. int buf_height = cinfo->max_v_samp_factor * 3;
  149437. JDIMENSION inrows;
  149438. while (*out_row_group_ctr < out_row_groups_avail) {
  149439. if (*in_row_ctr < in_rows_avail) {
  149440. inrows = in_rows_avail - *in_row_ctr;
  149441. numrows = prep->next_buf_stop - prep->next_buf_row;
  149442. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149443. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149444. prep->color_buf,
  149445. (JDIMENSION) prep->next_buf_row,
  149446. numrows);
  149447. if (prep->rows_to_go == cinfo->image_height) {
  149448. for (ci = 0; ci < cinfo->num_components; ci++) {
  149449. int row;
  149450. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149451. jcopy_sample_rows(prep->color_buf[ci], 0,
  149452. prep->color_buf[ci], -row,
  149453. 1, cinfo->image_width);
  149454. }
  149455. }
  149456. }
  149457. *in_row_ctr += numrows;
  149458. prep->next_buf_row += numrows;
  149459. prep->rows_to_go -= numrows;
  149460. } else {
  149461. if (prep->rows_to_go != 0)
  149462. break;
  149463. if (prep->next_buf_row < prep->next_buf_stop) {
  149464. for (ci = 0; ci < cinfo->num_components; ci++) {
  149465. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149466. prep->next_buf_row, prep->next_buf_stop);
  149467. }
  149468. prep->next_buf_row = prep->next_buf_stop;
  149469. }
  149470. }
  149471. if (prep->next_buf_row == prep->next_buf_stop) {
  149472. (*cinfo->downsample->downsample) (cinfo,
  149473. prep->color_buf,
  149474. (JDIMENSION) prep->this_row_group,
  149475. output_buf, *out_row_group_ctr);
  149476. (*out_row_group_ctr)++;
  149477. prep->this_row_group += cinfo->max_v_samp_factor;
  149478. if (prep->this_row_group >= buf_height)
  149479. prep->this_row_group = 0;
  149480. if (prep->next_buf_row >= buf_height)
  149481. prep->next_buf_row = 0;
  149482. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149483. }
  149484. }
  149485. }
  149486. LOCAL(void)
  149487. create_context_buffer (j_compress_ptr cinfo)
  149488. {
  149489. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149490. int rgroup_height = cinfo->max_v_samp_factor;
  149491. int ci, i;
  149492. jpeg_component_info * compptr;
  149493. JSAMPARRAY true_buffer, fake_buffer;
  149494. fake_buffer = (JSAMPARRAY)
  149495. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149496. (cinfo->num_components * 5 * rgroup_height) *
  149497. SIZEOF(JSAMPROW));
  149498. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149499. ci++, compptr++) {
  149500. true_buffer = (*cinfo->mem->alloc_sarray)
  149501. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149502. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149503. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149504. (JDIMENSION) (3 * rgroup_height));
  149505. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149506. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149507. for (i = 0; i < rgroup_height; i++) {
  149508. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149509. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149510. }
  149511. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149512. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149513. }
  149514. }
  149515. #endif /* CONTEXT_ROWS_SUPPORTED */
  149516. GLOBAL(void)
  149517. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149518. {
  149519. my_prep_ptr prep;
  149520. int ci;
  149521. jpeg_component_info * compptr;
  149522. if (need_full_buffer) /* safety check */
  149523. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149524. prep = (my_prep_ptr)
  149525. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149526. SIZEOF(my_prep_controller));
  149527. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149528. prep->pub.start_pass = start_pass_prep;
  149529. if (cinfo->downsample->need_context_rows) {
  149530. #ifdef CONTEXT_ROWS_SUPPORTED
  149531. prep->pub.pre_process_data = pre_process_context;
  149532. create_context_buffer(cinfo);
  149533. #else
  149534. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149535. #endif
  149536. } else {
  149537. prep->pub.pre_process_data = pre_process_data;
  149538. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149539. ci++, compptr++) {
  149540. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149541. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149542. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149543. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149544. (JDIMENSION) cinfo->max_v_samp_factor);
  149545. }
  149546. }
  149547. }
  149548. /*** End of inlined file: jcprepct.c ***/
  149549. /*** Start of inlined file: jcsample.c ***/
  149550. #define JPEG_INTERNALS
  149551. typedef JMETHOD(void, downsample1_ptr,
  149552. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149553. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149554. typedef struct {
  149555. struct jpeg_downsampler pub; /* public fields */
  149556. downsample1_ptr methods[MAX_COMPONENTS];
  149557. } my_downsampler;
  149558. typedef my_downsampler * my_downsample_ptr;
  149559. METHODDEF(void)
  149560. start_pass_downsample (j_compress_ptr cinfo)
  149561. {
  149562. }
  149563. LOCAL(void)
  149564. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149565. JDIMENSION input_cols, JDIMENSION output_cols)
  149566. {
  149567. register JSAMPROW ptr;
  149568. register JSAMPLE pixval;
  149569. register int count;
  149570. int row;
  149571. int numcols = (int) (output_cols - input_cols);
  149572. if (numcols > 0) {
  149573. for (row = 0; row < num_rows; row++) {
  149574. ptr = image_data[row] + input_cols;
  149575. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149576. for (count = numcols; count > 0; count--)
  149577. *ptr++ = pixval;
  149578. }
  149579. }
  149580. }
  149581. METHODDEF(void)
  149582. sep_downsample (j_compress_ptr cinfo,
  149583. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149584. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149585. {
  149586. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149587. int ci;
  149588. jpeg_component_info * compptr;
  149589. JSAMPARRAY in_ptr, out_ptr;
  149590. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149591. ci++, compptr++) {
  149592. in_ptr = input_buf[ci] + in_row_index;
  149593. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149594. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149595. }
  149596. }
  149597. METHODDEF(void)
  149598. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149599. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149600. {
  149601. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149602. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149603. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149604. JSAMPROW inptr, outptr;
  149605. INT32 outvalue;
  149606. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149607. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149608. numpix = h_expand * v_expand;
  149609. numpix2 = numpix/2;
  149610. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149611. cinfo->image_width, output_cols * h_expand);
  149612. inrow = 0;
  149613. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149614. outptr = output_data[outrow];
  149615. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149616. outcol++, outcol_h += h_expand) {
  149617. outvalue = 0;
  149618. for (v = 0; v < v_expand; v++) {
  149619. inptr = input_data[inrow+v] + outcol_h;
  149620. for (h = 0; h < h_expand; h++) {
  149621. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149622. }
  149623. }
  149624. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149625. }
  149626. inrow += v_expand;
  149627. }
  149628. }
  149629. METHODDEF(void)
  149630. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149631. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149632. {
  149633. jcopy_sample_rows(input_data, 0, output_data, 0,
  149634. cinfo->max_v_samp_factor, cinfo->image_width);
  149635. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149636. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149637. }
  149638. METHODDEF(void)
  149639. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149640. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149641. {
  149642. int outrow;
  149643. JDIMENSION outcol;
  149644. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149645. register JSAMPROW inptr, outptr;
  149646. register int bias;
  149647. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149648. cinfo->image_width, output_cols * 2);
  149649. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149650. outptr = output_data[outrow];
  149651. inptr = input_data[outrow];
  149652. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149653. for (outcol = 0; outcol < output_cols; outcol++) {
  149654. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149655. + bias) >> 1);
  149656. bias ^= 1; /* 0=>1, 1=>0 */
  149657. inptr += 2;
  149658. }
  149659. }
  149660. }
  149661. METHODDEF(void)
  149662. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149663. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149664. {
  149665. int inrow, outrow;
  149666. JDIMENSION outcol;
  149667. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149668. register JSAMPROW inptr0, inptr1, outptr;
  149669. register int bias;
  149670. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149671. cinfo->image_width, output_cols * 2);
  149672. inrow = 0;
  149673. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149674. outptr = output_data[outrow];
  149675. inptr0 = input_data[inrow];
  149676. inptr1 = input_data[inrow+1];
  149677. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149678. for (outcol = 0; outcol < output_cols; outcol++) {
  149679. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149680. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149681. + bias) >> 2);
  149682. bias ^= 3; /* 1=>2, 2=>1 */
  149683. inptr0 += 2; inptr1 += 2;
  149684. }
  149685. inrow += 2;
  149686. }
  149687. }
  149688. #ifdef INPUT_SMOOTHING_SUPPORTED
  149689. METHODDEF(void)
  149690. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149691. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149692. {
  149693. int inrow, outrow;
  149694. JDIMENSION colctr;
  149695. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149696. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149697. INT32 membersum, neighsum, memberscale, neighscale;
  149698. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149699. cinfo->image_width, output_cols * 2);
  149700. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149701. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149702. inrow = 0;
  149703. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149704. outptr = output_data[outrow];
  149705. inptr0 = input_data[inrow];
  149706. inptr1 = input_data[inrow+1];
  149707. above_ptr = input_data[inrow-1];
  149708. below_ptr = input_data[inrow+2];
  149709. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149710. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149711. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149712. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149713. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149714. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149715. neighsum += neighsum;
  149716. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149717. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149718. membersum = membersum * memberscale + neighsum * neighscale;
  149719. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149720. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149721. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149722. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149723. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149724. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149725. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149726. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149727. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149728. neighsum += neighsum;
  149729. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149730. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149731. membersum = membersum * memberscale + neighsum * neighscale;
  149732. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149733. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149734. }
  149735. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149736. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149737. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149738. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149739. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149740. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149741. neighsum += neighsum;
  149742. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149743. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149744. membersum = membersum * memberscale + neighsum * neighscale;
  149745. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149746. inrow += 2;
  149747. }
  149748. }
  149749. METHODDEF(void)
  149750. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149751. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149752. {
  149753. int outrow;
  149754. JDIMENSION colctr;
  149755. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149756. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149757. INT32 membersum, neighsum, memberscale, neighscale;
  149758. int colsum, lastcolsum, nextcolsum;
  149759. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149760. cinfo->image_width, output_cols);
  149761. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149762. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149763. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149764. outptr = output_data[outrow];
  149765. inptr = input_data[outrow];
  149766. above_ptr = input_data[outrow-1];
  149767. below_ptr = input_data[outrow+1];
  149768. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149769. GETJSAMPLE(*inptr);
  149770. membersum = GETJSAMPLE(*inptr++);
  149771. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149772. GETJSAMPLE(*inptr);
  149773. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149774. membersum = membersum * memberscale + neighsum * neighscale;
  149775. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149776. lastcolsum = colsum; colsum = nextcolsum;
  149777. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149778. membersum = GETJSAMPLE(*inptr++);
  149779. above_ptr++; below_ptr++;
  149780. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149781. GETJSAMPLE(*inptr);
  149782. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149783. membersum = membersum * memberscale + neighsum * neighscale;
  149784. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149785. lastcolsum = colsum; colsum = nextcolsum;
  149786. }
  149787. membersum = GETJSAMPLE(*inptr);
  149788. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149789. membersum = membersum * memberscale + neighsum * neighscale;
  149790. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149791. }
  149792. }
  149793. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149794. GLOBAL(void)
  149795. jinit_downsampler (j_compress_ptr cinfo)
  149796. {
  149797. my_downsample_ptr downsample;
  149798. int ci;
  149799. jpeg_component_info * compptr;
  149800. boolean smoothok = TRUE;
  149801. downsample = (my_downsample_ptr)
  149802. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149803. SIZEOF(my_downsampler));
  149804. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149805. downsample->pub.start_pass = start_pass_downsample;
  149806. downsample->pub.downsample = sep_downsample;
  149807. downsample->pub.need_context_rows = FALSE;
  149808. if (cinfo->CCIR601_sampling)
  149809. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149810. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149811. ci++, compptr++) {
  149812. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149813. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149814. #ifdef INPUT_SMOOTHING_SUPPORTED
  149815. if (cinfo->smoothing_factor) {
  149816. downsample->methods[ci] = fullsize_smooth_downsample;
  149817. downsample->pub.need_context_rows = TRUE;
  149818. } else
  149819. #endif
  149820. downsample->methods[ci] = fullsize_downsample;
  149821. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149822. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149823. smoothok = FALSE;
  149824. downsample->methods[ci] = h2v1_downsample;
  149825. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149826. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149827. #ifdef INPUT_SMOOTHING_SUPPORTED
  149828. if (cinfo->smoothing_factor) {
  149829. downsample->methods[ci] = h2v2_smooth_downsample;
  149830. downsample->pub.need_context_rows = TRUE;
  149831. } else
  149832. #endif
  149833. downsample->methods[ci] = h2v2_downsample;
  149834. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149835. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149836. smoothok = FALSE;
  149837. downsample->methods[ci] = int_downsample;
  149838. } else
  149839. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149840. }
  149841. #ifdef INPUT_SMOOTHING_SUPPORTED
  149842. if (cinfo->smoothing_factor && !smoothok)
  149843. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149844. #endif
  149845. }
  149846. /*** End of inlined file: jcsample.c ***/
  149847. /*** Start of inlined file: jctrans.c ***/
  149848. #define JPEG_INTERNALS
  149849. LOCAL(void) transencode_master_selection
  149850. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149851. LOCAL(void) transencode_coef_controller
  149852. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149853. GLOBAL(void)
  149854. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149855. {
  149856. if (cinfo->global_state != CSTATE_START)
  149857. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149858. jpeg_suppress_tables(cinfo, FALSE);
  149859. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149860. (*cinfo->dest->init_destination) (cinfo);
  149861. transencode_master_selection(cinfo, coef_arrays);
  149862. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149863. cinfo->global_state = CSTATE_WRCOEFS;
  149864. }
  149865. GLOBAL(void)
  149866. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149867. j_compress_ptr dstinfo)
  149868. {
  149869. JQUANT_TBL ** qtblptr;
  149870. jpeg_component_info *incomp, *outcomp;
  149871. JQUANT_TBL *c_quant, *slot_quant;
  149872. int tblno, ci, coefi;
  149873. if (dstinfo->global_state != CSTATE_START)
  149874. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149875. dstinfo->image_width = srcinfo->image_width;
  149876. dstinfo->image_height = srcinfo->image_height;
  149877. dstinfo->input_components = srcinfo->num_components;
  149878. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149879. jpeg_set_defaults(dstinfo);
  149880. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149881. dstinfo->data_precision = srcinfo->data_precision;
  149882. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149883. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149884. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149885. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149886. if (*qtblptr == NULL)
  149887. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149888. MEMCOPY((*qtblptr)->quantval,
  149889. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149890. SIZEOF((*qtblptr)->quantval));
  149891. (*qtblptr)->sent_table = FALSE;
  149892. }
  149893. }
  149894. dstinfo->num_components = srcinfo->num_components;
  149895. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149896. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149897. MAX_COMPONENTS);
  149898. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149899. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149900. outcomp->component_id = incomp->component_id;
  149901. outcomp->h_samp_factor = incomp->h_samp_factor;
  149902. outcomp->v_samp_factor = incomp->v_samp_factor;
  149903. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149904. tblno = outcomp->quant_tbl_no;
  149905. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149906. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149907. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149908. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149909. c_quant = incomp->quant_table;
  149910. if (c_quant != NULL) {
  149911. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149912. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149913. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149914. }
  149915. }
  149916. }
  149917. if (srcinfo->saw_JFIF_marker) {
  149918. if (srcinfo->JFIF_major_version == 1) {
  149919. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149920. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149921. }
  149922. dstinfo->density_unit = srcinfo->density_unit;
  149923. dstinfo->X_density = srcinfo->X_density;
  149924. dstinfo->Y_density = srcinfo->Y_density;
  149925. }
  149926. }
  149927. LOCAL(void)
  149928. transencode_master_selection (j_compress_ptr cinfo,
  149929. jvirt_barray_ptr * coef_arrays)
  149930. {
  149931. cinfo->input_components = 1;
  149932. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  149933. if (cinfo->arith_code) {
  149934. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  149935. } else {
  149936. if (cinfo->progressive_mode) {
  149937. #ifdef C_PROGRESSIVE_SUPPORTED
  149938. jinit_phuff_encoder(cinfo);
  149939. #else
  149940. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149941. #endif
  149942. } else
  149943. jinit_huff_encoder(cinfo);
  149944. }
  149945. transencode_coef_controller(cinfo, coef_arrays);
  149946. jinit_marker_writer(cinfo);
  149947. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  149948. (*cinfo->marker->write_file_header) (cinfo);
  149949. }
  149950. typedef struct {
  149951. struct jpeg_c_coef_controller pub; /* public fields */
  149952. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  149953. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  149954. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  149955. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  149956. jvirt_barray_ptr * whole_image;
  149957. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  149958. } my_coef_controller2;
  149959. typedef my_coef_controller2 * my_coef_ptr2;
  149960. LOCAL(void)
  149961. start_iMCU_row2 (j_compress_ptr cinfo)
  149962. {
  149963. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149964. if (cinfo->comps_in_scan > 1) {
  149965. coef->MCU_rows_per_iMCU_row = 1;
  149966. } else {
  149967. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  149968. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  149969. else
  149970. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  149971. }
  149972. coef->mcu_ctr = 0;
  149973. coef->MCU_vert_offset = 0;
  149974. }
  149975. METHODDEF(void)
  149976. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149977. {
  149978. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149979. if (pass_mode != JBUF_CRANK_DEST)
  149980. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149981. coef->iMCU_row_num = 0;
  149982. start_iMCU_row2(cinfo);
  149983. }
  149984. METHODDEF(boolean)
  149985. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  149986. {
  149987. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149988. JDIMENSION MCU_col_num; /* index of current MCU within row */
  149989. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  149990. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  149991. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  149992. JDIMENSION start_col;
  149993. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  149994. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  149995. JBLOCKROW buffer_ptr;
  149996. jpeg_component_info *compptr;
  149997. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149998. compptr = cinfo->cur_comp_info[ci];
  149999. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150000. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150001. coef->iMCU_row_num * compptr->v_samp_factor,
  150002. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150003. }
  150004. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150005. yoffset++) {
  150006. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150007. MCU_col_num++) {
  150008. blkn = 0; /* index of current DCT block within MCU */
  150009. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150010. compptr = cinfo->cur_comp_info[ci];
  150011. start_col = MCU_col_num * compptr->MCU_width;
  150012. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150013. : compptr->last_col_width;
  150014. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150015. if (coef->iMCU_row_num < last_iMCU_row ||
  150016. yindex+yoffset < compptr->last_row_height) {
  150017. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150018. for (xindex = 0; xindex < blockcnt; xindex++)
  150019. MCU_buffer[blkn++] = buffer_ptr++;
  150020. } else {
  150021. xindex = 0;
  150022. }
  150023. for (; xindex < compptr->MCU_width; xindex++) {
  150024. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150025. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150026. blkn++;
  150027. }
  150028. }
  150029. }
  150030. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150031. coef->MCU_vert_offset = yoffset;
  150032. coef->mcu_ctr = MCU_col_num;
  150033. return FALSE;
  150034. }
  150035. }
  150036. coef->mcu_ctr = 0;
  150037. }
  150038. coef->iMCU_row_num++;
  150039. start_iMCU_row2(cinfo);
  150040. return TRUE;
  150041. }
  150042. LOCAL(void)
  150043. transencode_coef_controller (j_compress_ptr cinfo,
  150044. jvirt_barray_ptr * coef_arrays)
  150045. {
  150046. my_coef_ptr2 coef;
  150047. JBLOCKROW buffer;
  150048. int i;
  150049. coef = (my_coef_ptr2)
  150050. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150051. SIZEOF(my_coef_controller2));
  150052. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150053. coef->pub.start_pass = start_pass_coef2;
  150054. coef->pub.compress_data = compress_output2;
  150055. coef->whole_image = coef_arrays;
  150056. buffer = (JBLOCKROW)
  150057. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150058. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150059. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150060. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150061. coef->dummy_buffer[i] = buffer + i;
  150062. }
  150063. }
  150064. /*** End of inlined file: jctrans.c ***/
  150065. /*** Start of inlined file: jdapistd.c ***/
  150066. #define JPEG_INTERNALS
  150067. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150068. GLOBAL(boolean)
  150069. jpeg_start_decompress (j_decompress_ptr cinfo)
  150070. {
  150071. if (cinfo->global_state == DSTATE_READY) {
  150072. jinit_master_decompress(cinfo);
  150073. if (cinfo->buffered_image) {
  150074. cinfo->global_state = DSTATE_BUFIMAGE;
  150075. return TRUE;
  150076. }
  150077. cinfo->global_state = DSTATE_PRELOAD;
  150078. }
  150079. if (cinfo->global_state == DSTATE_PRELOAD) {
  150080. if (cinfo->inputctl->has_multiple_scans) {
  150081. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150082. for (;;) {
  150083. int retcode;
  150084. if (cinfo->progress != NULL)
  150085. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150086. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150087. if (retcode == JPEG_SUSPENDED)
  150088. return FALSE;
  150089. if (retcode == JPEG_REACHED_EOI)
  150090. break;
  150091. if (cinfo->progress != NULL &&
  150092. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150093. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150094. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150095. }
  150096. }
  150097. }
  150098. #else
  150099. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150100. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150101. }
  150102. cinfo->output_scan_number = cinfo->input_scan_number;
  150103. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150104. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150105. return output_pass_setup(cinfo);
  150106. }
  150107. LOCAL(boolean)
  150108. output_pass_setup (j_decompress_ptr cinfo)
  150109. {
  150110. if (cinfo->global_state != DSTATE_PRESCAN) {
  150111. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150112. cinfo->output_scanline = 0;
  150113. cinfo->global_state = DSTATE_PRESCAN;
  150114. }
  150115. while (cinfo->master->is_dummy_pass) {
  150116. #ifdef QUANT_2PASS_SUPPORTED
  150117. while (cinfo->output_scanline < cinfo->output_height) {
  150118. JDIMENSION last_scanline;
  150119. if (cinfo->progress != NULL) {
  150120. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150121. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150122. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150123. }
  150124. last_scanline = cinfo->output_scanline;
  150125. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150126. &cinfo->output_scanline, (JDIMENSION) 0);
  150127. if (cinfo->output_scanline == last_scanline)
  150128. return FALSE; /* No progress made, must suspend */
  150129. }
  150130. (*cinfo->master->finish_output_pass) (cinfo);
  150131. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150132. cinfo->output_scanline = 0;
  150133. #else
  150134. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150135. #endif /* QUANT_2PASS_SUPPORTED */
  150136. }
  150137. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150138. return TRUE;
  150139. }
  150140. GLOBAL(JDIMENSION)
  150141. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150142. JDIMENSION max_lines)
  150143. {
  150144. JDIMENSION row_ctr;
  150145. if (cinfo->global_state != DSTATE_SCANNING)
  150146. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150147. if (cinfo->output_scanline >= cinfo->output_height) {
  150148. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150149. return 0;
  150150. }
  150151. if (cinfo->progress != NULL) {
  150152. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150153. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150154. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150155. }
  150156. row_ctr = 0;
  150157. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150158. cinfo->output_scanline += row_ctr;
  150159. return row_ctr;
  150160. }
  150161. GLOBAL(JDIMENSION)
  150162. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150163. JDIMENSION max_lines)
  150164. {
  150165. JDIMENSION lines_per_iMCU_row;
  150166. if (cinfo->global_state != DSTATE_RAW_OK)
  150167. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150168. if (cinfo->output_scanline >= cinfo->output_height) {
  150169. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150170. return 0;
  150171. }
  150172. if (cinfo->progress != NULL) {
  150173. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150174. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150175. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150176. }
  150177. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150178. if (max_lines < lines_per_iMCU_row)
  150179. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150180. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150181. return 0; /* suspension forced, can do nothing more */
  150182. cinfo->output_scanline += lines_per_iMCU_row;
  150183. return lines_per_iMCU_row;
  150184. }
  150185. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150186. GLOBAL(boolean)
  150187. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150188. {
  150189. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150190. cinfo->global_state != DSTATE_PRESCAN)
  150191. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150192. if (scan_number <= 0)
  150193. scan_number = 1;
  150194. if (cinfo->inputctl->eoi_reached &&
  150195. scan_number > cinfo->input_scan_number)
  150196. scan_number = cinfo->input_scan_number;
  150197. cinfo->output_scan_number = scan_number;
  150198. return output_pass_setup(cinfo);
  150199. }
  150200. GLOBAL(boolean)
  150201. jpeg_finish_output (j_decompress_ptr cinfo)
  150202. {
  150203. if ((cinfo->global_state == DSTATE_SCANNING ||
  150204. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150205. (*cinfo->master->finish_output_pass) (cinfo);
  150206. cinfo->global_state = DSTATE_BUFPOST;
  150207. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150208. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150209. }
  150210. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150211. ! cinfo->inputctl->eoi_reached) {
  150212. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150213. return FALSE; /* Suspend, come back later */
  150214. }
  150215. cinfo->global_state = DSTATE_BUFIMAGE;
  150216. return TRUE;
  150217. }
  150218. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150219. /*** End of inlined file: jdapistd.c ***/
  150220. /*** Start of inlined file: jdapimin.c ***/
  150221. #define JPEG_INTERNALS
  150222. GLOBAL(void)
  150223. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150224. {
  150225. int i;
  150226. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150227. if (version != JPEG_LIB_VERSION)
  150228. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150229. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150230. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150231. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150232. {
  150233. struct jpeg_error_mgr * err = cinfo->err;
  150234. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150235. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150236. cinfo->err = err;
  150237. cinfo->client_data = client_data;
  150238. }
  150239. cinfo->is_decompressor = TRUE;
  150240. jinit_memory_mgr((j_common_ptr) cinfo);
  150241. cinfo->progress = NULL;
  150242. cinfo->src = NULL;
  150243. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150244. cinfo->quant_tbl_ptrs[i] = NULL;
  150245. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150246. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150247. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150248. }
  150249. cinfo->marker_list = NULL;
  150250. jinit_marker_reader(cinfo);
  150251. jinit_input_controller(cinfo);
  150252. cinfo->global_state = DSTATE_START;
  150253. }
  150254. GLOBAL(void)
  150255. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150256. {
  150257. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150258. }
  150259. GLOBAL(void)
  150260. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150261. {
  150262. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150263. }
  150264. LOCAL(void)
  150265. default_decompress_parms (j_decompress_ptr cinfo)
  150266. {
  150267. switch (cinfo->num_components) {
  150268. case 1:
  150269. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150270. cinfo->out_color_space = JCS_GRAYSCALE;
  150271. break;
  150272. case 3:
  150273. if (cinfo->saw_JFIF_marker) {
  150274. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150275. } else if (cinfo->saw_Adobe_marker) {
  150276. switch (cinfo->Adobe_transform) {
  150277. case 0:
  150278. cinfo->jpeg_color_space = JCS_RGB;
  150279. break;
  150280. case 1:
  150281. cinfo->jpeg_color_space = JCS_YCbCr;
  150282. break;
  150283. default:
  150284. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150285. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150286. break;
  150287. }
  150288. } else {
  150289. int cid0 = cinfo->comp_info[0].component_id;
  150290. int cid1 = cinfo->comp_info[1].component_id;
  150291. int cid2 = cinfo->comp_info[2].component_id;
  150292. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150293. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150294. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150295. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150296. else {
  150297. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150298. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150299. }
  150300. }
  150301. cinfo->out_color_space = JCS_RGB;
  150302. break;
  150303. case 4:
  150304. if (cinfo->saw_Adobe_marker) {
  150305. switch (cinfo->Adobe_transform) {
  150306. case 0:
  150307. cinfo->jpeg_color_space = JCS_CMYK;
  150308. break;
  150309. case 2:
  150310. cinfo->jpeg_color_space = JCS_YCCK;
  150311. break;
  150312. default:
  150313. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150314. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150315. break;
  150316. }
  150317. } else {
  150318. cinfo->jpeg_color_space = JCS_CMYK;
  150319. }
  150320. cinfo->out_color_space = JCS_CMYK;
  150321. break;
  150322. default:
  150323. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150324. cinfo->out_color_space = JCS_UNKNOWN;
  150325. break;
  150326. }
  150327. cinfo->scale_num = 1; /* 1:1 scaling */
  150328. cinfo->scale_denom = 1;
  150329. cinfo->output_gamma = 1.0;
  150330. cinfo->buffered_image = FALSE;
  150331. cinfo->raw_data_out = FALSE;
  150332. cinfo->dct_method = JDCT_DEFAULT;
  150333. cinfo->do_fancy_upsampling = TRUE;
  150334. cinfo->do_block_smoothing = TRUE;
  150335. cinfo->quantize_colors = FALSE;
  150336. cinfo->dither_mode = JDITHER_FS;
  150337. #ifdef QUANT_2PASS_SUPPORTED
  150338. cinfo->two_pass_quantize = TRUE;
  150339. #else
  150340. cinfo->two_pass_quantize = FALSE;
  150341. #endif
  150342. cinfo->desired_number_of_colors = 256;
  150343. cinfo->colormap = NULL;
  150344. cinfo->enable_1pass_quant = FALSE;
  150345. cinfo->enable_external_quant = FALSE;
  150346. cinfo->enable_2pass_quant = FALSE;
  150347. }
  150348. GLOBAL(int)
  150349. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150350. {
  150351. int retcode;
  150352. if (cinfo->global_state != DSTATE_START &&
  150353. cinfo->global_state != DSTATE_INHEADER)
  150354. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150355. retcode = jpeg_consume_input(cinfo);
  150356. switch (retcode) {
  150357. case JPEG_REACHED_SOS:
  150358. retcode = JPEG_HEADER_OK;
  150359. break;
  150360. case JPEG_REACHED_EOI:
  150361. if (require_image) /* Complain if application wanted an image */
  150362. ERREXIT(cinfo, JERR_NO_IMAGE);
  150363. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150364. retcode = JPEG_HEADER_TABLES_ONLY;
  150365. break;
  150366. case JPEG_SUSPENDED:
  150367. break;
  150368. }
  150369. return retcode;
  150370. }
  150371. GLOBAL(int)
  150372. jpeg_consume_input (j_decompress_ptr cinfo)
  150373. {
  150374. int retcode = JPEG_SUSPENDED;
  150375. switch (cinfo->global_state) {
  150376. case DSTATE_START:
  150377. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150378. (*cinfo->src->init_source) (cinfo);
  150379. cinfo->global_state = DSTATE_INHEADER;
  150380. case DSTATE_INHEADER:
  150381. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150382. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150383. default_decompress_parms(cinfo);
  150384. cinfo->global_state = DSTATE_READY;
  150385. }
  150386. break;
  150387. case DSTATE_READY:
  150388. retcode = JPEG_REACHED_SOS;
  150389. break;
  150390. case DSTATE_PRELOAD:
  150391. case DSTATE_PRESCAN:
  150392. case DSTATE_SCANNING:
  150393. case DSTATE_RAW_OK:
  150394. case DSTATE_BUFIMAGE:
  150395. case DSTATE_BUFPOST:
  150396. case DSTATE_STOPPING:
  150397. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150398. break;
  150399. default:
  150400. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150401. }
  150402. return retcode;
  150403. }
  150404. GLOBAL(boolean)
  150405. jpeg_input_complete (j_decompress_ptr cinfo)
  150406. {
  150407. if (cinfo->global_state < DSTATE_START ||
  150408. cinfo->global_state > DSTATE_STOPPING)
  150409. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150410. return cinfo->inputctl->eoi_reached;
  150411. }
  150412. GLOBAL(boolean)
  150413. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150414. {
  150415. if (cinfo->global_state < DSTATE_READY ||
  150416. cinfo->global_state > DSTATE_STOPPING)
  150417. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150418. return cinfo->inputctl->has_multiple_scans;
  150419. }
  150420. GLOBAL(boolean)
  150421. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150422. {
  150423. if ((cinfo->global_state == DSTATE_SCANNING ||
  150424. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150425. if (cinfo->output_scanline < cinfo->output_height)
  150426. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150427. (*cinfo->master->finish_output_pass) (cinfo);
  150428. cinfo->global_state = DSTATE_STOPPING;
  150429. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150430. cinfo->global_state = DSTATE_STOPPING;
  150431. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150432. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150433. }
  150434. while (! cinfo->inputctl->eoi_reached) {
  150435. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150436. return FALSE; /* Suspend, come back later */
  150437. }
  150438. (*cinfo->src->term_source) (cinfo);
  150439. jpeg_abort((j_common_ptr) cinfo);
  150440. return TRUE;
  150441. }
  150442. /*** End of inlined file: jdapimin.c ***/
  150443. /*** Start of inlined file: jdatasrc.c ***/
  150444. /*** Start of inlined file: jerror.h ***/
  150445. #ifndef JMESSAGE
  150446. #ifndef JERROR_H
  150447. #define JMAKE_ENUM_LIST
  150448. #else
  150449. #define JMESSAGE(code,string)
  150450. #endif /* JERROR_H */
  150451. #endif /* JMESSAGE */
  150452. #ifdef JMAKE_ENUM_LIST
  150453. typedef enum {
  150454. #define JMESSAGE(code,string) code ,
  150455. #endif /* JMAKE_ENUM_LIST */
  150456. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150457. JMESSAGE(JERR_ARITH_NOTIMPL,
  150458. "Sorry, there are legal restrictions on arithmetic coding")
  150459. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150460. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150461. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150462. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150463. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150464. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150465. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150466. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150467. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150468. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150469. JMESSAGE(JERR_BAD_LIB_VERSION,
  150470. "Wrong JPEG library version: library is %d, caller expects %d")
  150471. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150472. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150473. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150474. JMESSAGE(JERR_BAD_PROGRESSION,
  150475. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150476. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150477. "Invalid progressive parameters at scan script entry %d")
  150478. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150479. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150480. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150481. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150482. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150483. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150484. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150485. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150486. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150487. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150488. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150489. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150490. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150491. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150492. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150493. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150494. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150495. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150496. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150497. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150498. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150499. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150500. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150501. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150502. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150503. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150504. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150505. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150506. "Cannot transcode due to multiple use of quantization table %d")
  150507. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150508. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150509. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150510. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150511. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150512. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150513. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150514. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150515. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150516. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150517. JMESSAGE(JERR_QUANT_COMPONENTS,
  150518. "Cannot quantize more than %d color components")
  150519. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150520. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150521. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150522. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150523. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150524. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150525. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150526. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150527. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150528. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150529. JMESSAGE(JERR_TFILE_WRITE,
  150530. "Write failed on temporary file --- out of disk space?")
  150531. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150532. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150533. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150534. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150535. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150536. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150537. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150538. JMESSAGE(JMSG_VERSION, JVERSION)
  150539. JMESSAGE(JTRC_16BIT_TABLES,
  150540. "Caution: quantization tables are too coarse for baseline JPEG")
  150541. JMESSAGE(JTRC_ADOBE,
  150542. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150543. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150544. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150545. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150546. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150547. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150548. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150549. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150550. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150551. JMESSAGE(JTRC_EOI, "End Of Image")
  150552. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150553. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150554. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150555. "Warning: thumbnail image size does not match data length %u")
  150556. JMESSAGE(JTRC_JFIF_EXTENSION,
  150557. "JFIF extension marker: type 0x%02x, length %u")
  150558. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150559. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150560. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150561. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150562. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150563. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150564. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150565. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150566. JMESSAGE(JTRC_RST, "RST%d")
  150567. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150568. "Smoothing not supported with nonstandard sampling ratios")
  150569. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150570. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150571. JMESSAGE(JTRC_SOI, "Start of Image")
  150572. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150573. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150574. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150575. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150576. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150577. JMESSAGE(JTRC_THUMB_JPEG,
  150578. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150579. JMESSAGE(JTRC_THUMB_PALETTE,
  150580. "JFIF extension marker: palette thumbnail image, length %u")
  150581. JMESSAGE(JTRC_THUMB_RGB,
  150582. "JFIF extension marker: RGB thumbnail image, length %u")
  150583. JMESSAGE(JTRC_UNKNOWN_IDS,
  150584. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150585. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150586. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150587. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150588. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150589. "Inconsistent progression sequence for component %d coefficient %d")
  150590. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150591. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150592. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150593. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150594. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150595. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150596. JMESSAGE(JWRN_MUST_RESYNC,
  150597. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150598. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150599. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150600. #ifdef JMAKE_ENUM_LIST
  150601. JMSG_LASTMSGCODE
  150602. } J_MESSAGE_CODE;
  150603. #undef JMAKE_ENUM_LIST
  150604. #endif /* JMAKE_ENUM_LIST */
  150605. #undef JMESSAGE
  150606. #ifndef JERROR_H
  150607. #define JERROR_H
  150608. #define ERREXIT(cinfo,code) \
  150609. ((cinfo)->err->msg_code = (code), \
  150610. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150611. #define ERREXIT1(cinfo,code,p1) \
  150612. ((cinfo)->err->msg_code = (code), \
  150613. (cinfo)->err->msg_parm.i[0] = (p1), \
  150614. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150615. #define ERREXIT2(cinfo,code,p1,p2) \
  150616. ((cinfo)->err->msg_code = (code), \
  150617. (cinfo)->err->msg_parm.i[0] = (p1), \
  150618. (cinfo)->err->msg_parm.i[1] = (p2), \
  150619. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150620. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150621. ((cinfo)->err->msg_code = (code), \
  150622. (cinfo)->err->msg_parm.i[0] = (p1), \
  150623. (cinfo)->err->msg_parm.i[1] = (p2), \
  150624. (cinfo)->err->msg_parm.i[2] = (p3), \
  150625. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150626. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150627. ((cinfo)->err->msg_code = (code), \
  150628. (cinfo)->err->msg_parm.i[0] = (p1), \
  150629. (cinfo)->err->msg_parm.i[1] = (p2), \
  150630. (cinfo)->err->msg_parm.i[2] = (p3), \
  150631. (cinfo)->err->msg_parm.i[3] = (p4), \
  150632. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150633. #define ERREXITS(cinfo,code,str) \
  150634. ((cinfo)->err->msg_code = (code), \
  150635. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150636. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150637. #define MAKESTMT(stuff) do { stuff } while (0)
  150638. #define WARNMS(cinfo,code) \
  150639. ((cinfo)->err->msg_code = (code), \
  150640. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150641. #define WARNMS1(cinfo,code,p1) \
  150642. ((cinfo)->err->msg_code = (code), \
  150643. (cinfo)->err->msg_parm.i[0] = (p1), \
  150644. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150645. #define WARNMS2(cinfo,code,p1,p2) \
  150646. ((cinfo)->err->msg_code = (code), \
  150647. (cinfo)->err->msg_parm.i[0] = (p1), \
  150648. (cinfo)->err->msg_parm.i[1] = (p2), \
  150649. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150650. #define TRACEMS(cinfo,lvl,code) \
  150651. ((cinfo)->err->msg_code = (code), \
  150652. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150653. #define TRACEMS1(cinfo,lvl,code,p1) \
  150654. ((cinfo)->err->msg_code = (code), \
  150655. (cinfo)->err->msg_parm.i[0] = (p1), \
  150656. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150657. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150658. ((cinfo)->err->msg_code = (code), \
  150659. (cinfo)->err->msg_parm.i[0] = (p1), \
  150660. (cinfo)->err->msg_parm.i[1] = (p2), \
  150661. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150662. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150663. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150664. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150665. (cinfo)->err->msg_code = (code); \
  150666. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150667. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150668. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150669. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150670. (cinfo)->err->msg_code = (code); \
  150671. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150672. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150673. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150674. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150675. _mp[4] = (p5); \
  150676. (cinfo)->err->msg_code = (code); \
  150677. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150678. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150679. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150680. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150681. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150682. (cinfo)->err->msg_code = (code); \
  150683. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150684. #define TRACEMSS(cinfo,lvl,code,str) \
  150685. ((cinfo)->err->msg_code = (code), \
  150686. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150687. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150688. #endif /* JERROR_H */
  150689. /*** End of inlined file: jerror.h ***/
  150690. typedef struct {
  150691. struct jpeg_source_mgr pub; /* public fields */
  150692. FILE * infile; /* source stream */
  150693. JOCTET * buffer; /* start of buffer */
  150694. boolean start_of_file; /* have we gotten any data yet? */
  150695. } my_source_mgr;
  150696. typedef my_source_mgr * my_src_ptr;
  150697. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150698. METHODDEF(void)
  150699. init_source (j_decompress_ptr cinfo)
  150700. {
  150701. my_src_ptr src = (my_src_ptr) cinfo->src;
  150702. src->start_of_file = TRUE;
  150703. }
  150704. METHODDEF(boolean)
  150705. fill_input_buffer (j_decompress_ptr cinfo)
  150706. {
  150707. my_src_ptr src = (my_src_ptr) cinfo->src;
  150708. size_t nbytes;
  150709. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150710. if (nbytes <= 0) {
  150711. if (src->start_of_file) /* Treat empty input file as fatal error */
  150712. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150713. WARNMS(cinfo, JWRN_JPEG_EOF);
  150714. src->buffer[0] = (JOCTET) 0xFF;
  150715. src->buffer[1] = (JOCTET) JPEG_EOI;
  150716. nbytes = 2;
  150717. }
  150718. src->pub.next_input_byte = src->buffer;
  150719. src->pub.bytes_in_buffer = nbytes;
  150720. src->start_of_file = FALSE;
  150721. return TRUE;
  150722. }
  150723. METHODDEF(void)
  150724. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150725. {
  150726. my_src_ptr src = (my_src_ptr) cinfo->src;
  150727. if (num_bytes > 0) {
  150728. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150729. num_bytes -= (long) src->pub.bytes_in_buffer;
  150730. (void) fill_input_buffer(cinfo);
  150731. }
  150732. src->pub.next_input_byte += (size_t) num_bytes;
  150733. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150734. }
  150735. }
  150736. METHODDEF(void)
  150737. term_source (j_decompress_ptr cinfo)
  150738. {
  150739. }
  150740. GLOBAL(void)
  150741. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150742. {
  150743. my_src_ptr src;
  150744. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150745. cinfo->src = (struct jpeg_source_mgr *)
  150746. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150747. SIZEOF(my_source_mgr));
  150748. src = (my_src_ptr) cinfo->src;
  150749. src->buffer = (JOCTET *)
  150750. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150751. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150752. }
  150753. src = (my_src_ptr) cinfo->src;
  150754. src->pub.init_source = init_source;
  150755. src->pub.fill_input_buffer = fill_input_buffer;
  150756. src->pub.skip_input_data = skip_input_data;
  150757. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150758. src->pub.term_source = term_source;
  150759. src->infile = infile;
  150760. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150761. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150762. }
  150763. /*** End of inlined file: jdatasrc.c ***/
  150764. /*** Start of inlined file: jdcoefct.c ***/
  150765. #define JPEG_INTERNALS
  150766. #ifndef D_PROGRESSIVE_SUPPORTED
  150767. #undef BLOCK_SMOOTHING_SUPPORTED
  150768. #endif
  150769. typedef struct {
  150770. struct jpeg_d_coef_controller pub; /* public fields */
  150771. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150772. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150773. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150774. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150775. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150776. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150777. #endif
  150778. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150779. int * coef_bits_latch;
  150780. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150781. #endif
  150782. } my_coef_controller3;
  150783. typedef my_coef_controller3 * my_coef_ptr3;
  150784. METHODDEF(int) decompress_onepass
  150785. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150786. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150787. METHODDEF(int) decompress_data
  150788. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150789. #endif
  150790. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150791. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150792. METHODDEF(int) decompress_smooth_data
  150793. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150794. #endif
  150795. LOCAL(void)
  150796. start_iMCU_row3 (j_decompress_ptr cinfo)
  150797. {
  150798. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150799. if (cinfo->comps_in_scan > 1) {
  150800. coef->MCU_rows_per_iMCU_row = 1;
  150801. } else {
  150802. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150803. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150804. else
  150805. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150806. }
  150807. coef->MCU_ctr = 0;
  150808. coef->MCU_vert_offset = 0;
  150809. }
  150810. METHODDEF(void)
  150811. start_input_pass (j_decompress_ptr cinfo)
  150812. {
  150813. cinfo->input_iMCU_row = 0;
  150814. start_iMCU_row3(cinfo);
  150815. }
  150816. METHODDEF(void)
  150817. start_output_pass (j_decompress_ptr cinfo)
  150818. {
  150819. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150820. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150821. if (coef->pub.coef_arrays != NULL) {
  150822. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150823. coef->pub.decompress_data = decompress_smooth_data;
  150824. else
  150825. coef->pub.decompress_data = decompress_data;
  150826. }
  150827. #endif
  150828. cinfo->output_iMCU_row = 0;
  150829. }
  150830. METHODDEF(int)
  150831. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150832. {
  150833. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150834. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150835. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150836. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150837. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150838. JSAMPARRAY output_ptr;
  150839. JDIMENSION start_col, output_col;
  150840. jpeg_component_info *compptr;
  150841. inverse_DCT_method_ptr inverse_DCT;
  150842. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150843. yoffset++) {
  150844. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150845. MCU_col_num++) {
  150846. jzero_far((void FAR *) coef->MCU_buffer[0],
  150847. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150848. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150849. coef->MCU_vert_offset = yoffset;
  150850. coef->MCU_ctr = MCU_col_num;
  150851. return JPEG_SUSPENDED;
  150852. }
  150853. blkn = 0; /* index of current DCT block within MCU */
  150854. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150855. compptr = cinfo->cur_comp_info[ci];
  150856. if (! compptr->component_needed) {
  150857. blkn += compptr->MCU_blocks;
  150858. continue;
  150859. }
  150860. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150861. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150862. : compptr->last_col_width;
  150863. output_ptr = output_buf[compptr->component_index] +
  150864. yoffset * compptr->DCT_scaled_size;
  150865. start_col = MCU_col_num * compptr->MCU_sample_width;
  150866. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150867. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150868. yoffset+yindex < compptr->last_row_height) {
  150869. output_col = start_col;
  150870. for (xindex = 0; xindex < useful_width; xindex++) {
  150871. (*inverse_DCT) (cinfo, compptr,
  150872. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150873. output_ptr, output_col);
  150874. output_col += compptr->DCT_scaled_size;
  150875. }
  150876. }
  150877. blkn += compptr->MCU_width;
  150878. output_ptr += compptr->DCT_scaled_size;
  150879. }
  150880. }
  150881. }
  150882. coef->MCU_ctr = 0;
  150883. }
  150884. cinfo->output_iMCU_row++;
  150885. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150886. start_iMCU_row3(cinfo);
  150887. return JPEG_ROW_COMPLETED;
  150888. }
  150889. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150890. return JPEG_SCAN_COMPLETED;
  150891. }
  150892. METHODDEF(int)
  150893. dummy_consume_data (j_decompress_ptr cinfo)
  150894. {
  150895. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150896. }
  150897. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150898. METHODDEF(int)
  150899. consume_data (j_decompress_ptr cinfo)
  150900. {
  150901. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150902. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150903. int blkn, ci, xindex, yindex, yoffset;
  150904. JDIMENSION start_col;
  150905. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150906. JBLOCKROW buffer_ptr;
  150907. jpeg_component_info *compptr;
  150908. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150909. compptr = cinfo->cur_comp_info[ci];
  150910. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150911. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150912. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150913. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150914. }
  150915. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150916. yoffset++) {
  150917. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150918. MCU_col_num++) {
  150919. blkn = 0; /* index of current DCT block within MCU */
  150920. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150921. compptr = cinfo->cur_comp_info[ci];
  150922. start_col = MCU_col_num * compptr->MCU_width;
  150923. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150924. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150925. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150926. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150927. }
  150928. }
  150929. }
  150930. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150931. coef->MCU_vert_offset = yoffset;
  150932. coef->MCU_ctr = MCU_col_num;
  150933. return JPEG_SUSPENDED;
  150934. }
  150935. }
  150936. coef->MCU_ctr = 0;
  150937. }
  150938. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150939. start_iMCU_row3(cinfo);
  150940. return JPEG_ROW_COMPLETED;
  150941. }
  150942. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150943. return JPEG_SCAN_COMPLETED;
  150944. }
  150945. METHODDEF(int)
  150946. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150947. {
  150948. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150949. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150950. JDIMENSION block_num;
  150951. int ci, block_row, block_rows;
  150952. JBLOCKARRAY buffer;
  150953. JBLOCKROW buffer_ptr;
  150954. JSAMPARRAY output_ptr;
  150955. JDIMENSION output_col;
  150956. jpeg_component_info *compptr;
  150957. inverse_DCT_method_ptr inverse_DCT;
  150958. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  150959. (cinfo->input_scan_number == cinfo->output_scan_number &&
  150960. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  150961. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150962. return JPEG_SUSPENDED;
  150963. }
  150964. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150965. ci++, compptr++) {
  150966. if (! compptr->component_needed)
  150967. continue;
  150968. buffer = (*cinfo->mem->access_virt_barray)
  150969. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150970. cinfo->output_iMCU_row * compptr->v_samp_factor,
  150971. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150972. if (cinfo->output_iMCU_row < last_iMCU_row)
  150973. block_rows = compptr->v_samp_factor;
  150974. else {
  150975. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150976. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150977. }
  150978. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  150979. output_ptr = output_buf[ci];
  150980. for (block_row = 0; block_row < block_rows; block_row++) {
  150981. buffer_ptr = buffer[block_row];
  150982. output_col = 0;
  150983. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  150984. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  150985. output_ptr, output_col);
  150986. buffer_ptr++;
  150987. output_col += compptr->DCT_scaled_size;
  150988. }
  150989. output_ptr += compptr->DCT_scaled_size;
  150990. }
  150991. }
  150992. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  150993. return JPEG_ROW_COMPLETED;
  150994. return JPEG_SCAN_COMPLETED;
  150995. }
  150996. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150997. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150998. #define Q01_POS 1
  150999. #define Q10_POS 8
  151000. #define Q20_POS 16
  151001. #define Q11_POS 9
  151002. #define Q02_POS 2
  151003. LOCAL(boolean)
  151004. smoothing_ok (j_decompress_ptr cinfo)
  151005. {
  151006. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151007. boolean smoothing_useful = FALSE;
  151008. int ci, coefi;
  151009. jpeg_component_info *compptr;
  151010. JQUANT_TBL * qtable;
  151011. int * coef_bits;
  151012. int * coef_bits_latch;
  151013. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151014. return FALSE;
  151015. if (coef->coef_bits_latch == NULL)
  151016. coef->coef_bits_latch = (int *)
  151017. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151018. cinfo->num_components *
  151019. (SAVED_COEFS * SIZEOF(int)));
  151020. coef_bits_latch = coef->coef_bits_latch;
  151021. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151022. ci++, compptr++) {
  151023. if ((qtable = compptr->quant_table) == NULL)
  151024. return FALSE;
  151025. if (qtable->quantval[0] == 0 ||
  151026. qtable->quantval[Q01_POS] == 0 ||
  151027. qtable->quantval[Q10_POS] == 0 ||
  151028. qtable->quantval[Q20_POS] == 0 ||
  151029. qtable->quantval[Q11_POS] == 0 ||
  151030. qtable->quantval[Q02_POS] == 0)
  151031. return FALSE;
  151032. coef_bits = cinfo->coef_bits[ci];
  151033. if (coef_bits[0] < 0)
  151034. return FALSE;
  151035. for (coefi = 1; coefi <= 5; coefi++) {
  151036. coef_bits_latch[coefi] = coef_bits[coefi];
  151037. if (coef_bits[coefi] != 0)
  151038. smoothing_useful = TRUE;
  151039. }
  151040. coef_bits_latch += SAVED_COEFS;
  151041. }
  151042. return smoothing_useful;
  151043. }
  151044. METHODDEF(int)
  151045. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151046. {
  151047. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151048. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151049. JDIMENSION block_num, last_block_column;
  151050. int ci, block_row, block_rows, access_rows;
  151051. JBLOCKARRAY buffer;
  151052. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151053. JSAMPARRAY output_ptr;
  151054. JDIMENSION output_col;
  151055. jpeg_component_info *compptr;
  151056. inverse_DCT_method_ptr inverse_DCT;
  151057. boolean first_row, last_row;
  151058. JBLOCK workspace;
  151059. int *coef_bits;
  151060. JQUANT_TBL *quanttbl;
  151061. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151062. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151063. int Al, pred;
  151064. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151065. ! cinfo->inputctl->eoi_reached) {
  151066. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151067. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151068. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151069. break;
  151070. }
  151071. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151072. return JPEG_SUSPENDED;
  151073. }
  151074. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151075. ci++, compptr++) {
  151076. if (! compptr->component_needed)
  151077. continue;
  151078. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151079. block_rows = compptr->v_samp_factor;
  151080. access_rows = block_rows * 2; /* this and next iMCU row */
  151081. last_row = FALSE;
  151082. } else {
  151083. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151084. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151085. access_rows = block_rows; /* this iMCU row only */
  151086. last_row = TRUE;
  151087. }
  151088. if (cinfo->output_iMCU_row > 0) {
  151089. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151090. buffer = (*cinfo->mem->access_virt_barray)
  151091. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151092. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151093. (JDIMENSION) access_rows, FALSE);
  151094. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151095. first_row = FALSE;
  151096. } else {
  151097. buffer = (*cinfo->mem->access_virt_barray)
  151098. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151099. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151100. first_row = TRUE;
  151101. }
  151102. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151103. quanttbl = compptr->quant_table;
  151104. Q00 = quanttbl->quantval[0];
  151105. Q01 = quanttbl->quantval[Q01_POS];
  151106. Q10 = quanttbl->quantval[Q10_POS];
  151107. Q20 = quanttbl->quantval[Q20_POS];
  151108. Q11 = quanttbl->quantval[Q11_POS];
  151109. Q02 = quanttbl->quantval[Q02_POS];
  151110. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151111. output_ptr = output_buf[ci];
  151112. for (block_row = 0; block_row < block_rows; block_row++) {
  151113. buffer_ptr = buffer[block_row];
  151114. if (first_row && block_row == 0)
  151115. prev_block_row = buffer_ptr;
  151116. else
  151117. prev_block_row = buffer[block_row-1];
  151118. if (last_row && block_row == block_rows-1)
  151119. next_block_row = buffer_ptr;
  151120. else
  151121. next_block_row = buffer[block_row+1];
  151122. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151123. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151124. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151125. output_col = 0;
  151126. last_block_column = compptr->width_in_blocks - 1;
  151127. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151128. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151129. if (block_num < last_block_column) {
  151130. DC3 = (int) prev_block_row[1][0];
  151131. DC6 = (int) buffer_ptr[1][0];
  151132. DC9 = (int) next_block_row[1][0];
  151133. }
  151134. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151135. num = 36 * Q00 * (DC4 - DC6);
  151136. if (num >= 0) {
  151137. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151138. if (Al > 0 && pred >= (1<<Al))
  151139. pred = (1<<Al)-1;
  151140. } else {
  151141. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151142. if (Al > 0 && pred >= (1<<Al))
  151143. pred = (1<<Al)-1;
  151144. pred = -pred;
  151145. }
  151146. workspace[1] = (JCOEF) pred;
  151147. }
  151148. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151149. num = 36 * Q00 * (DC2 - DC8);
  151150. if (num >= 0) {
  151151. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151152. if (Al > 0 && pred >= (1<<Al))
  151153. pred = (1<<Al)-1;
  151154. } else {
  151155. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151156. if (Al > 0 && pred >= (1<<Al))
  151157. pred = (1<<Al)-1;
  151158. pred = -pred;
  151159. }
  151160. workspace[8] = (JCOEF) pred;
  151161. }
  151162. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151163. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151164. if (num >= 0) {
  151165. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151166. if (Al > 0 && pred >= (1<<Al))
  151167. pred = (1<<Al)-1;
  151168. } else {
  151169. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151170. if (Al > 0 && pred >= (1<<Al))
  151171. pred = (1<<Al)-1;
  151172. pred = -pred;
  151173. }
  151174. workspace[16] = (JCOEF) pred;
  151175. }
  151176. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151177. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151178. if (num >= 0) {
  151179. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151180. if (Al > 0 && pred >= (1<<Al))
  151181. pred = (1<<Al)-1;
  151182. } else {
  151183. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151184. if (Al > 0 && pred >= (1<<Al))
  151185. pred = (1<<Al)-1;
  151186. pred = -pred;
  151187. }
  151188. workspace[9] = (JCOEF) pred;
  151189. }
  151190. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151191. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151192. if (num >= 0) {
  151193. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151194. if (Al > 0 && pred >= (1<<Al))
  151195. pred = (1<<Al)-1;
  151196. } else {
  151197. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151198. if (Al > 0 && pred >= (1<<Al))
  151199. pred = (1<<Al)-1;
  151200. pred = -pred;
  151201. }
  151202. workspace[2] = (JCOEF) pred;
  151203. }
  151204. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151205. output_ptr, output_col);
  151206. DC1 = DC2; DC2 = DC3;
  151207. DC4 = DC5; DC5 = DC6;
  151208. DC7 = DC8; DC8 = DC9;
  151209. buffer_ptr++, prev_block_row++, next_block_row++;
  151210. output_col += compptr->DCT_scaled_size;
  151211. }
  151212. output_ptr += compptr->DCT_scaled_size;
  151213. }
  151214. }
  151215. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151216. return JPEG_ROW_COMPLETED;
  151217. return JPEG_SCAN_COMPLETED;
  151218. }
  151219. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151220. GLOBAL(void)
  151221. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151222. {
  151223. my_coef_ptr3 coef;
  151224. coef = (my_coef_ptr3)
  151225. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151226. SIZEOF(my_coef_controller3));
  151227. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151228. coef->pub.start_input_pass = start_input_pass;
  151229. coef->pub.start_output_pass = start_output_pass;
  151230. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151231. coef->coef_bits_latch = NULL;
  151232. #endif
  151233. if (need_full_buffer) {
  151234. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151235. int ci, access_rows;
  151236. jpeg_component_info *compptr;
  151237. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151238. ci++, compptr++) {
  151239. access_rows = compptr->v_samp_factor;
  151240. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151241. if (cinfo->progressive_mode)
  151242. access_rows *= 3;
  151243. #endif
  151244. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151245. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151246. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151247. (long) compptr->h_samp_factor),
  151248. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151249. (long) compptr->v_samp_factor),
  151250. (JDIMENSION) access_rows);
  151251. }
  151252. coef->pub.consume_data = consume_data;
  151253. coef->pub.decompress_data = decompress_data;
  151254. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151255. #else
  151256. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151257. #endif
  151258. } else {
  151259. JBLOCKROW buffer;
  151260. int i;
  151261. buffer = (JBLOCKROW)
  151262. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151263. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151264. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151265. coef->MCU_buffer[i] = buffer + i;
  151266. }
  151267. coef->pub.consume_data = dummy_consume_data;
  151268. coef->pub.decompress_data = decompress_onepass;
  151269. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151270. }
  151271. }
  151272. /*** End of inlined file: jdcoefct.c ***/
  151273. #undef FIX
  151274. /*** Start of inlined file: jdcolor.c ***/
  151275. #define JPEG_INTERNALS
  151276. typedef struct {
  151277. struct jpeg_color_deconverter pub; /* public fields */
  151278. int * Cr_r_tab; /* => table for Cr to R conversion */
  151279. int * Cb_b_tab; /* => table for Cb to B conversion */
  151280. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151281. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151282. } my_color_deconverter2;
  151283. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151284. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151285. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151286. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151287. LOCAL(void)
  151288. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151289. {
  151290. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151291. int i;
  151292. INT32 x;
  151293. SHIFT_TEMPS
  151294. cconvert->Cr_r_tab = (int *)
  151295. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151296. (MAXJSAMPLE+1) * SIZEOF(int));
  151297. cconvert->Cb_b_tab = (int *)
  151298. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151299. (MAXJSAMPLE+1) * SIZEOF(int));
  151300. cconvert->Cr_g_tab = (INT32 *)
  151301. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151302. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151303. cconvert->Cb_g_tab = (INT32 *)
  151304. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151305. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151306. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151307. cconvert->Cr_r_tab[i] = (int)
  151308. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151309. cconvert->Cb_b_tab[i] = (int)
  151310. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151311. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151312. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151313. }
  151314. }
  151315. METHODDEF(void)
  151316. ycc_rgb_convert (j_decompress_ptr cinfo,
  151317. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151318. JSAMPARRAY output_buf, int num_rows)
  151319. {
  151320. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151321. register int y, cb, cr;
  151322. register JSAMPROW outptr;
  151323. register JSAMPROW inptr0, inptr1, inptr2;
  151324. register JDIMENSION col;
  151325. JDIMENSION num_cols = cinfo->output_width;
  151326. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151327. register int * Crrtab = cconvert->Cr_r_tab;
  151328. register int * Cbbtab = cconvert->Cb_b_tab;
  151329. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151330. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151331. SHIFT_TEMPS
  151332. while (--num_rows >= 0) {
  151333. inptr0 = input_buf[0][input_row];
  151334. inptr1 = input_buf[1][input_row];
  151335. inptr2 = input_buf[2][input_row];
  151336. input_row++;
  151337. outptr = *output_buf++;
  151338. for (col = 0; col < num_cols; col++) {
  151339. y = GETJSAMPLE(inptr0[col]);
  151340. cb = GETJSAMPLE(inptr1[col]);
  151341. cr = GETJSAMPLE(inptr2[col]);
  151342. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151343. outptr[RGB_GREEN] = range_limit[y +
  151344. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151345. SCALEBITS))];
  151346. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151347. outptr += RGB_PIXELSIZE;
  151348. }
  151349. }
  151350. }
  151351. METHODDEF(void)
  151352. null_convert2 (j_decompress_ptr cinfo,
  151353. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151354. JSAMPARRAY output_buf, int num_rows)
  151355. {
  151356. register JSAMPROW inptr, outptr;
  151357. register JDIMENSION count;
  151358. register int num_components = cinfo->num_components;
  151359. JDIMENSION num_cols = cinfo->output_width;
  151360. int ci;
  151361. while (--num_rows >= 0) {
  151362. for (ci = 0; ci < num_components; ci++) {
  151363. inptr = input_buf[ci][input_row];
  151364. outptr = output_buf[0] + ci;
  151365. for (count = num_cols; count > 0; count--) {
  151366. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151367. outptr += num_components;
  151368. }
  151369. }
  151370. input_row++;
  151371. output_buf++;
  151372. }
  151373. }
  151374. METHODDEF(void)
  151375. grayscale_convert2 (j_decompress_ptr cinfo,
  151376. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151377. JSAMPARRAY output_buf, int num_rows)
  151378. {
  151379. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151380. num_rows, cinfo->output_width);
  151381. }
  151382. METHODDEF(void)
  151383. gray_rgb_convert (j_decompress_ptr cinfo,
  151384. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151385. JSAMPARRAY output_buf, int num_rows)
  151386. {
  151387. register JSAMPROW inptr, outptr;
  151388. register JDIMENSION col;
  151389. JDIMENSION num_cols = cinfo->output_width;
  151390. while (--num_rows >= 0) {
  151391. inptr = input_buf[0][input_row++];
  151392. outptr = *output_buf++;
  151393. for (col = 0; col < num_cols; col++) {
  151394. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151395. outptr += RGB_PIXELSIZE;
  151396. }
  151397. }
  151398. }
  151399. METHODDEF(void)
  151400. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151401. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151402. JSAMPARRAY output_buf, int num_rows)
  151403. {
  151404. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151405. register int y, cb, cr;
  151406. register JSAMPROW outptr;
  151407. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151408. register JDIMENSION col;
  151409. JDIMENSION num_cols = cinfo->output_width;
  151410. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151411. register int * Crrtab = cconvert->Cr_r_tab;
  151412. register int * Cbbtab = cconvert->Cb_b_tab;
  151413. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151414. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151415. SHIFT_TEMPS
  151416. while (--num_rows >= 0) {
  151417. inptr0 = input_buf[0][input_row];
  151418. inptr1 = input_buf[1][input_row];
  151419. inptr2 = input_buf[2][input_row];
  151420. inptr3 = input_buf[3][input_row];
  151421. input_row++;
  151422. outptr = *output_buf++;
  151423. for (col = 0; col < num_cols; col++) {
  151424. y = GETJSAMPLE(inptr0[col]);
  151425. cb = GETJSAMPLE(inptr1[col]);
  151426. cr = GETJSAMPLE(inptr2[col]);
  151427. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151428. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151429. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151430. SCALEBITS)))];
  151431. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151432. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151433. outptr += 4;
  151434. }
  151435. }
  151436. }
  151437. METHODDEF(void)
  151438. start_pass_dcolor (j_decompress_ptr cinfo)
  151439. {
  151440. }
  151441. GLOBAL(void)
  151442. jinit_color_deconverter (j_decompress_ptr cinfo)
  151443. {
  151444. my_cconvert_ptr2 cconvert;
  151445. int ci;
  151446. cconvert = (my_cconvert_ptr2)
  151447. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151448. SIZEOF(my_color_deconverter2));
  151449. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151450. cconvert->pub.start_pass = start_pass_dcolor;
  151451. switch (cinfo->jpeg_color_space) {
  151452. case JCS_GRAYSCALE:
  151453. if (cinfo->num_components != 1)
  151454. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151455. break;
  151456. case JCS_RGB:
  151457. case JCS_YCbCr:
  151458. if (cinfo->num_components != 3)
  151459. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151460. break;
  151461. case JCS_CMYK:
  151462. case JCS_YCCK:
  151463. if (cinfo->num_components != 4)
  151464. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151465. break;
  151466. default: /* JCS_UNKNOWN can be anything */
  151467. if (cinfo->num_components < 1)
  151468. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151469. break;
  151470. }
  151471. switch (cinfo->out_color_space) {
  151472. case JCS_GRAYSCALE:
  151473. cinfo->out_color_components = 1;
  151474. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151475. cinfo->jpeg_color_space == JCS_YCbCr) {
  151476. cconvert->pub.color_convert = grayscale_convert2;
  151477. for (ci = 1; ci < cinfo->num_components; ci++)
  151478. cinfo->comp_info[ci].component_needed = FALSE;
  151479. } else
  151480. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151481. break;
  151482. case JCS_RGB:
  151483. cinfo->out_color_components = RGB_PIXELSIZE;
  151484. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151485. cconvert->pub.color_convert = ycc_rgb_convert;
  151486. build_ycc_rgb_table(cinfo);
  151487. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151488. cconvert->pub.color_convert = gray_rgb_convert;
  151489. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151490. cconvert->pub.color_convert = null_convert2;
  151491. } else
  151492. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151493. break;
  151494. case JCS_CMYK:
  151495. cinfo->out_color_components = 4;
  151496. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151497. cconvert->pub.color_convert = ycck_cmyk_convert;
  151498. build_ycc_rgb_table(cinfo);
  151499. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151500. cconvert->pub.color_convert = null_convert2;
  151501. } else
  151502. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151503. break;
  151504. default:
  151505. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151506. cinfo->out_color_components = cinfo->num_components;
  151507. cconvert->pub.color_convert = null_convert2;
  151508. } else /* unsupported non-null conversion */
  151509. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151510. break;
  151511. }
  151512. if (cinfo->quantize_colors)
  151513. cinfo->output_components = 1; /* single colormapped output component */
  151514. else
  151515. cinfo->output_components = cinfo->out_color_components;
  151516. }
  151517. /*** End of inlined file: jdcolor.c ***/
  151518. #undef FIX
  151519. /*** Start of inlined file: jddctmgr.c ***/
  151520. #define JPEG_INTERNALS
  151521. typedef struct {
  151522. struct jpeg_inverse_dct pub; /* public fields */
  151523. int cur_method[MAX_COMPONENTS];
  151524. } my_idct_controller;
  151525. typedef my_idct_controller * my_idct_ptr;
  151526. typedef union {
  151527. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151528. #ifdef DCT_IFAST_SUPPORTED
  151529. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151530. #endif
  151531. #ifdef DCT_FLOAT_SUPPORTED
  151532. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151533. #endif
  151534. } multiplier_table;
  151535. #ifdef DCT_ISLOW_SUPPORTED
  151536. #define PROVIDE_ISLOW_TABLES
  151537. #else
  151538. #ifdef IDCT_SCALING_SUPPORTED
  151539. #define PROVIDE_ISLOW_TABLES
  151540. #endif
  151541. #endif
  151542. METHODDEF(void)
  151543. start_pass (j_decompress_ptr cinfo)
  151544. {
  151545. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151546. int ci, i;
  151547. jpeg_component_info *compptr;
  151548. int method = 0;
  151549. inverse_DCT_method_ptr method_ptr = NULL;
  151550. JQUANT_TBL * qtbl;
  151551. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151552. ci++, compptr++) {
  151553. switch (compptr->DCT_scaled_size) {
  151554. #ifdef IDCT_SCALING_SUPPORTED
  151555. case 1:
  151556. method_ptr = jpeg_idct_1x1;
  151557. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151558. break;
  151559. case 2:
  151560. method_ptr = jpeg_idct_2x2;
  151561. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151562. break;
  151563. case 4:
  151564. method_ptr = jpeg_idct_4x4;
  151565. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151566. break;
  151567. #endif
  151568. case DCTSIZE:
  151569. switch (cinfo->dct_method) {
  151570. #ifdef DCT_ISLOW_SUPPORTED
  151571. case JDCT_ISLOW:
  151572. method_ptr = jpeg_idct_islow;
  151573. method = JDCT_ISLOW;
  151574. break;
  151575. #endif
  151576. #ifdef DCT_IFAST_SUPPORTED
  151577. case JDCT_IFAST:
  151578. method_ptr = jpeg_idct_ifast;
  151579. method = JDCT_IFAST;
  151580. break;
  151581. #endif
  151582. #ifdef DCT_FLOAT_SUPPORTED
  151583. case JDCT_FLOAT:
  151584. method_ptr = jpeg_idct_float;
  151585. method = JDCT_FLOAT;
  151586. break;
  151587. #endif
  151588. default:
  151589. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151590. break;
  151591. }
  151592. break;
  151593. default:
  151594. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151595. break;
  151596. }
  151597. idct->pub.inverse_DCT[ci] = method_ptr;
  151598. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151599. continue;
  151600. qtbl = compptr->quant_table;
  151601. if (qtbl == NULL) /* happens if no data yet for component */
  151602. continue;
  151603. idct->cur_method[ci] = method;
  151604. switch (method) {
  151605. #ifdef PROVIDE_ISLOW_TABLES
  151606. case JDCT_ISLOW:
  151607. {
  151608. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151609. for (i = 0; i < DCTSIZE2; i++) {
  151610. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151611. }
  151612. }
  151613. break;
  151614. #endif
  151615. #ifdef DCT_IFAST_SUPPORTED
  151616. case JDCT_IFAST:
  151617. {
  151618. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151619. #define CONST_BITS 14
  151620. static const INT16 aanscales[DCTSIZE2] = {
  151621. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151622. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151623. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151624. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151625. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151626. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151627. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151628. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151629. };
  151630. SHIFT_TEMPS
  151631. for (i = 0; i < DCTSIZE2; i++) {
  151632. ifmtbl[i] = (IFAST_MULT_TYPE)
  151633. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151634. (INT32) aanscales[i]),
  151635. CONST_BITS-IFAST_SCALE_BITS);
  151636. }
  151637. }
  151638. break;
  151639. #endif
  151640. #ifdef DCT_FLOAT_SUPPORTED
  151641. case JDCT_FLOAT:
  151642. {
  151643. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151644. int row, col;
  151645. static const double aanscalefactor[DCTSIZE] = {
  151646. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151647. 1.0, 0.785694958, 0.541196100, 0.275899379
  151648. };
  151649. i = 0;
  151650. for (row = 0; row < DCTSIZE; row++) {
  151651. for (col = 0; col < DCTSIZE; col++) {
  151652. fmtbl[i] = (FLOAT_MULT_TYPE)
  151653. ((double) qtbl->quantval[i] *
  151654. aanscalefactor[row] * aanscalefactor[col]);
  151655. i++;
  151656. }
  151657. }
  151658. }
  151659. break;
  151660. #endif
  151661. default:
  151662. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151663. break;
  151664. }
  151665. }
  151666. }
  151667. GLOBAL(void)
  151668. jinit_inverse_dct (j_decompress_ptr cinfo)
  151669. {
  151670. my_idct_ptr idct;
  151671. int ci;
  151672. jpeg_component_info *compptr;
  151673. idct = (my_idct_ptr)
  151674. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151675. SIZEOF(my_idct_controller));
  151676. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151677. idct->pub.start_pass = start_pass;
  151678. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151679. ci++, compptr++) {
  151680. compptr->dct_table =
  151681. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151682. SIZEOF(multiplier_table));
  151683. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151684. idct->cur_method[ci] = -1;
  151685. }
  151686. }
  151687. /*** End of inlined file: jddctmgr.c ***/
  151688. #undef CONST_BITS
  151689. #undef ASSIGN_STATE
  151690. /*** Start of inlined file: jdhuff.c ***/
  151691. #define JPEG_INTERNALS
  151692. /*** Start of inlined file: jdhuff.h ***/
  151693. #ifndef __jdhuff_h__
  151694. #define __jdhuff_h__
  151695. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151696. #define jpeg_make_d_derived_tbl jMkDDerived
  151697. #define jpeg_fill_bit_buffer jFilBitBuf
  151698. #define jpeg_huff_decode jHufDecode
  151699. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151700. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151701. typedef struct {
  151702. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151703. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151704. JHUFF_TBL *pub;
  151705. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151706. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151707. } d_derived_tbl;
  151708. EXTERN(void) jpeg_make_d_derived_tbl
  151709. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151710. d_derived_tbl ** pdtbl));
  151711. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151712. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151713. typedef struct { /* Bitreading state saved across MCUs */
  151714. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151715. int bits_left; /* # of unused bits in it */
  151716. } bitread_perm_state;
  151717. typedef struct { /* Bitreading working state within an MCU */
  151718. const JOCTET * next_input_byte; /* => next byte to read from source */
  151719. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151720. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151721. int bits_left; /* # of unused bits in it */
  151722. j_decompress_ptr cinfo; /* back link to decompress master record */
  151723. } bitread_working_state;
  151724. #define BITREAD_STATE_VARS \
  151725. register bit_buf_type get_buffer; \
  151726. register int bits_left; \
  151727. bitread_working_state br_state
  151728. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151729. br_state.cinfo = cinfop; \
  151730. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151731. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151732. get_buffer = permstate.get_buffer; \
  151733. bits_left = permstate.bits_left;
  151734. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151735. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151736. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151737. permstate.get_buffer = get_buffer; \
  151738. permstate.bits_left = bits_left
  151739. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151740. { if (bits_left < (nbits)) { \
  151741. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151742. { action; } \
  151743. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151744. #define GET_BITS(nbits) \
  151745. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151746. #define PEEK_BITS(nbits) \
  151747. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151748. #define DROP_BITS(nbits) \
  151749. (bits_left -= (nbits))
  151750. EXTERN(boolean) jpeg_fill_bit_buffer
  151751. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151752. register int bits_left, int nbits));
  151753. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151754. { register int nb, look; \
  151755. if (bits_left < HUFF_LOOKAHEAD) { \
  151756. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151757. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151758. if (bits_left < HUFF_LOOKAHEAD) { \
  151759. nb = 1; goto slowlabel; \
  151760. } \
  151761. } \
  151762. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151763. if ((nb = htbl->look_nbits[look]) != 0) { \
  151764. DROP_BITS(nb); \
  151765. result = htbl->look_sym[look]; \
  151766. } else { \
  151767. nb = HUFF_LOOKAHEAD+1; \
  151768. slowlabel: \
  151769. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151770. { failaction; } \
  151771. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151772. } \
  151773. }
  151774. EXTERN(int) jpeg_huff_decode
  151775. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151776. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151777. #endif
  151778. /*** End of inlined file: jdhuff.h ***/
  151779. /* Declarations shared with jdphuff.c */
  151780. typedef struct {
  151781. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151782. } savable_state2;
  151783. #ifndef NO_STRUCT_ASSIGN
  151784. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151785. #else
  151786. #if MAX_COMPS_IN_SCAN == 4
  151787. #define ASSIGN_STATE(dest,src) \
  151788. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151789. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151790. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151791. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151792. #endif
  151793. #endif
  151794. typedef struct {
  151795. struct jpeg_entropy_decoder pub; /* public fields */
  151796. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151797. savable_state2 saved; /* Other state at start of MCU */
  151798. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151799. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151800. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151801. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151802. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151803. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151804. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151805. } huff_entropy_decoder2;
  151806. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151807. METHODDEF(void)
  151808. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151809. {
  151810. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151811. int ci, blkn, dctbl, actbl;
  151812. jpeg_component_info * compptr;
  151813. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151814. cinfo->Ah != 0 || cinfo->Al != 0)
  151815. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151816. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151817. compptr = cinfo->cur_comp_info[ci];
  151818. dctbl = compptr->dc_tbl_no;
  151819. actbl = compptr->ac_tbl_no;
  151820. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151821. & entropy->dc_derived_tbls[dctbl]);
  151822. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151823. & entropy->ac_derived_tbls[actbl]);
  151824. entropy->saved.last_dc_val[ci] = 0;
  151825. }
  151826. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151827. ci = cinfo->MCU_membership[blkn];
  151828. compptr = cinfo->cur_comp_info[ci];
  151829. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151830. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151831. if (compptr->component_needed) {
  151832. entropy->dc_needed[blkn] = TRUE;
  151833. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151834. } else {
  151835. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151836. }
  151837. }
  151838. entropy->bitstate.bits_left = 0;
  151839. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151840. entropy->pub.insufficient_data = FALSE;
  151841. entropy->restarts_to_go = cinfo->restart_interval;
  151842. }
  151843. GLOBAL(void)
  151844. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151845. d_derived_tbl ** pdtbl)
  151846. {
  151847. JHUFF_TBL *htbl;
  151848. d_derived_tbl *dtbl;
  151849. int p, i, l, si, numsymbols;
  151850. int lookbits, ctr;
  151851. char huffsize[257];
  151852. unsigned int huffcode[257];
  151853. unsigned int code;
  151854. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151855. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151856. htbl =
  151857. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151858. if (htbl == NULL)
  151859. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151860. if (*pdtbl == NULL)
  151861. *pdtbl = (d_derived_tbl *)
  151862. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151863. SIZEOF(d_derived_tbl));
  151864. dtbl = *pdtbl;
  151865. dtbl->pub = htbl; /* fill in back link */
  151866. p = 0;
  151867. for (l = 1; l <= 16; l++) {
  151868. i = (int) htbl->bits[l];
  151869. if (i < 0 || p + i > 256) /* protect against table overrun */
  151870. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151871. while (i--)
  151872. huffsize[p++] = (char) l;
  151873. }
  151874. huffsize[p] = 0;
  151875. numsymbols = p;
  151876. code = 0;
  151877. si = huffsize[0];
  151878. p = 0;
  151879. while (huffsize[p]) {
  151880. while (((int) huffsize[p]) == si) {
  151881. huffcode[p++] = code;
  151882. code++;
  151883. }
  151884. if (((INT32) code) >= (((INT32) 1) << si))
  151885. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151886. code <<= 1;
  151887. si++;
  151888. }
  151889. p = 0;
  151890. for (l = 1; l <= 16; l++) {
  151891. if (htbl->bits[l]) {
  151892. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151893. p += htbl->bits[l];
  151894. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151895. } else {
  151896. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151897. }
  151898. }
  151899. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151900. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151901. p = 0;
  151902. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151903. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151904. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151905. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151906. dtbl->look_nbits[lookbits] = l;
  151907. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151908. lookbits++;
  151909. }
  151910. }
  151911. }
  151912. if (isDC) {
  151913. for (i = 0; i < numsymbols; i++) {
  151914. int sym = htbl->huffval[i];
  151915. if (sym < 0 || sym > 15)
  151916. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151917. }
  151918. }
  151919. }
  151920. #ifdef SLOW_SHIFT_32
  151921. #define MIN_GET_BITS 15 /* minimum allowable value */
  151922. #else
  151923. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151924. #endif
  151925. GLOBAL(boolean)
  151926. jpeg_fill_bit_buffer (bitread_working_state * state,
  151927. register bit_buf_type get_buffer, register int bits_left,
  151928. int nbits)
  151929. {
  151930. register const JOCTET * next_input_byte = state->next_input_byte;
  151931. register size_t bytes_in_buffer = state->bytes_in_buffer;
  151932. j_decompress_ptr cinfo = state->cinfo;
  151933. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  151934. while (bits_left < MIN_GET_BITS) {
  151935. register int c;
  151936. if (bytes_in_buffer == 0) {
  151937. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151938. return FALSE;
  151939. next_input_byte = cinfo->src->next_input_byte;
  151940. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151941. }
  151942. bytes_in_buffer--;
  151943. c = GETJOCTET(*next_input_byte++);
  151944. if (c == 0xFF) {
  151945. do {
  151946. if (bytes_in_buffer == 0) {
  151947. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151948. return FALSE;
  151949. next_input_byte = cinfo->src->next_input_byte;
  151950. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151951. }
  151952. bytes_in_buffer--;
  151953. c = GETJOCTET(*next_input_byte++);
  151954. } while (c == 0xFF);
  151955. if (c == 0) {
  151956. c = 0xFF;
  151957. } else {
  151958. cinfo->unread_marker = c;
  151959. goto no_more_bytes;
  151960. }
  151961. }
  151962. get_buffer = (get_buffer << 8) | c;
  151963. bits_left += 8;
  151964. } /* end while */
  151965. } else {
  151966. no_more_bytes:
  151967. if (nbits > bits_left) {
  151968. if (! cinfo->entropy->insufficient_data) {
  151969. WARNMS(cinfo, JWRN_HIT_MARKER);
  151970. cinfo->entropy->insufficient_data = TRUE;
  151971. }
  151972. get_buffer <<= MIN_GET_BITS - bits_left;
  151973. bits_left = MIN_GET_BITS;
  151974. }
  151975. }
  151976. state->next_input_byte = next_input_byte;
  151977. state->bytes_in_buffer = bytes_in_buffer;
  151978. state->get_buffer = get_buffer;
  151979. state->bits_left = bits_left;
  151980. return TRUE;
  151981. }
  151982. GLOBAL(int)
  151983. jpeg_huff_decode (bitread_working_state * state,
  151984. register bit_buf_type get_buffer, register int bits_left,
  151985. d_derived_tbl * htbl, int min_bits)
  151986. {
  151987. register int l = min_bits;
  151988. register INT32 code;
  151989. CHECK_BIT_BUFFER(*state, l, return -1);
  151990. code = GET_BITS(l);
  151991. while (code > htbl->maxcode[l]) {
  151992. code <<= 1;
  151993. CHECK_BIT_BUFFER(*state, 1, return -1);
  151994. code |= GET_BITS(1);
  151995. l++;
  151996. }
  151997. state->get_buffer = get_buffer;
  151998. state->bits_left = bits_left;
  151999. if (l > 16) {
  152000. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152001. return 0; /* fake a zero as the safest result */
  152002. }
  152003. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152004. }
  152005. LOCAL(boolean)
  152006. process_restart (j_decompress_ptr cinfo)
  152007. {
  152008. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152009. int ci;
  152010. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152011. entropy->bitstate.bits_left = 0;
  152012. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152013. return FALSE;
  152014. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152015. entropy->saved.last_dc_val[ci] = 0;
  152016. entropy->restarts_to_go = cinfo->restart_interval;
  152017. if (cinfo->unread_marker == 0)
  152018. entropy->pub.insufficient_data = FALSE;
  152019. return TRUE;
  152020. }
  152021. METHODDEF(boolean)
  152022. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152023. {
  152024. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152025. int blkn;
  152026. BITREAD_STATE_VARS;
  152027. savable_state2 state;
  152028. if (cinfo->restart_interval) {
  152029. if (entropy->restarts_to_go == 0)
  152030. if (! process_restart(cinfo))
  152031. return FALSE;
  152032. }
  152033. if (! entropy->pub.insufficient_data) {
  152034. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152035. ASSIGN_STATE(state, entropy->saved);
  152036. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152037. JBLOCKROW block = MCU_data[blkn];
  152038. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152039. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152040. register int s, k, r;
  152041. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152042. if (s) {
  152043. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152044. r = GET_BITS(s);
  152045. s = HUFF_EXTEND(r, s);
  152046. }
  152047. if (entropy->dc_needed[blkn]) {
  152048. int ci = cinfo->MCU_membership[blkn];
  152049. s += state.last_dc_val[ci];
  152050. state.last_dc_val[ci] = s;
  152051. (*block)[0] = (JCOEF) s;
  152052. }
  152053. if (entropy->ac_needed[blkn]) {
  152054. for (k = 1; k < DCTSIZE2; k++) {
  152055. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152056. r = s >> 4;
  152057. s &= 15;
  152058. if (s) {
  152059. k += r;
  152060. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152061. r = GET_BITS(s);
  152062. s = HUFF_EXTEND(r, s);
  152063. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152064. } else {
  152065. if (r != 15)
  152066. break;
  152067. k += 15;
  152068. }
  152069. }
  152070. } else {
  152071. for (k = 1; k < DCTSIZE2; k++) {
  152072. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152073. r = s >> 4;
  152074. s &= 15;
  152075. if (s) {
  152076. k += r;
  152077. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152078. DROP_BITS(s);
  152079. } else {
  152080. if (r != 15)
  152081. break;
  152082. k += 15;
  152083. }
  152084. }
  152085. }
  152086. }
  152087. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152088. ASSIGN_STATE(entropy->saved, state);
  152089. }
  152090. entropy->restarts_to_go--;
  152091. return TRUE;
  152092. }
  152093. GLOBAL(void)
  152094. jinit_huff_decoder (j_decompress_ptr cinfo)
  152095. {
  152096. huff_entropy_ptr2 entropy;
  152097. int i;
  152098. entropy = (huff_entropy_ptr2)
  152099. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152100. SIZEOF(huff_entropy_decoder2));
  152101. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152102. entropy->pub.start_pass = start_pass_huff_decoder;
  152103. entropy->pub.decode_mcu = decode_mcu;
  152104. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152105. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152106. }
  152107. }
  152108. /*** End of inlined file: jdhuff.c ***/
  152109. /*** Start of inlined file: jdinput.c ***/
  152110. #define JPEG_INTERNALS
  152111. typedef struct {
  152112. struct jpeg_input_controller pub; /* public fields */
  152113. boolean inheaders; /* TRUE until first SOS is reached */
  152114. } my_input_controller;
  152115. typedef my_input_controller * my_inputctl_ptr;
  152116. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152117. LOCAL(void)
  152118. initial_setup2 (j_decompress_ptr cinfo)
  152119. {
  152120. int ci;
  152121. jpeg_component_info *compptr;
  152122. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152123. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152124. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152125. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152126. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152127. if (cinfo->num_components > MAX_COMPONENTS)
  152128. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152129. MAX_COMPONENTS);
  152130. cinfo->max_h_samp_factor = 1;
  152131. cinfo->max_v_samp_factor = 1;
  152132. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152133. ci++, compptr++) {
  152134. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152135. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152136. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152137. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152138. compptr->h_samp_factor);
  152139. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152140. compptr->v_samp_factor);
  152141. }
  152142. cinfo->min_DCT_scaled_size = DCTSIZE;
  152143. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152144. ci++, compptr++) {
  152145. compptr->DCT_scaled_size = DCTSIZE;
  152146. compptr->width_in_blocks = (JDIMENSION)
  152147. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152148. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152149. compptr->height_in_blocks = (JDIMENSION)
  152150. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152151. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152152. compptr->downsampled_width = (JDIMENSION)
  152153. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152154. (long) cinfo->max_h_samp_factor);
  152155. compptr->downsampled_height = (JDIMENSION)
  152156. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152157. (long) cinfo->max_v_samp_factor);
  152158. compptr->component_needed = TRUE;
  152159. compptr->quant_table = NULL;
  152160. }
  152161. cinfo->total_iMCU_rows = (JDIMENSION)
  152162. jdiv_round_up((long) cinfo->image_height,
  152163. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152164. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152165. cinfo->inputctl->has_multiple_scans = TRUE;
  152166. else
  152167. cinfo->inputctl->has_multiple_scans = FALSE;
  152168. }
  152169. LOCAL(void)
  152170. per_scan_setup2 (j_decompress_ptr cinfo)
  152171. {
  152172. int ci, mcublks, tmp;
  152173. jpeg_component_info *compptr;
  152174. if (cinfo->comps_in_scan == 1) {
  152175. compptr = cinfo->cur_comp_info[0];
  152176. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152177. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152178. compptr->MCU_width = 1;
  152179. compptr->MCU_height = 1;
  152180. compptr->MCU_blocks = 1;
  152181. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152182. compptr->last_col_width = 1;
  152183. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152184. if (tmp == 0) tmp = compptr->v_samp_factor;
  152185. compptr->last_row_height = tmp;
  152186. cinfo->blocks_in_MCU = 1;
  152187. cinfo->MCU_membership[0] = 0;
  152188. } else {
  152189. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152190. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152191. MAX_COMPS_IN_SCAN);
  152192. cinfo->MCUs_per_row = (JDIMENSION)
  152193. jdiv_round_up((long) cinfo->image_width,
  152194. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152195. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152196. jdiv_round_up((long) cinfo->image_height,
  152197. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152198. cinfo->blocks_in_MCU = 0;
  152199. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152200. compptr = cinfo->cur_comp_info[ci];
  152201. compptr->MCU_width = compptr->h_samp_factor;
  152202. compptr->MCU_height = compptr->v_samp_factor;
  152203. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152204. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152205. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152206. if (tmp == 0) tmp = compptr->MCU_width;
  152207. compptr->last_col_width = tmp;
  152208. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152209. if (tmp == 0) tmp = compptr->MCU_height;
  152210. compptr->last_row_height = tmp;
  152211. mcublks = compptr->MCU_blocks;
  152212. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152213. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152214. while (mcublks-- > 0) {
  152215. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152216. }
  152217. }
  152218. }
  152219. }
  152220. LOCAL(void)
  152221. latch_quant_tables (j_decompress_ptr cinfo)
  152222. {
  152223. int ci, qtblno;
  152224. jpeg_component_info *compptr;
  152225. JQUANT_TBL * qtbl;
  152226. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152227. compptr = cinfo->cur_comp_info[ci];
  152228. if (compptr->quant_table != NULL)
  152229. continue;
  152230. qtblno = compptr->quant_tbl_no;
  152231. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152232. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152233. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152234. qtbl = (JQUANT_TBL *)
  152235. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152236. SIZEOF(JQUANT_TBL));
  152237. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152238. compptr->quant_table = qtbl;
  152239. }
  152240. }
  152241. METHODDEF(void)
  152242. start_input_pass2 (j_decompress_ptr cinfo)
  152243. {
  152244. per_scan_setup2(cinfo);
  152245. latch_quant_tables(cinfo);
  152246. (*cinfo->entropy->start_pass) (cinfo);
  152247. (*cinfo->coef->start_input_pass) (cinfo);
  152248. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152249. }
  152250. METHODDEF(void)
  152251. finish_input_pass (j_decompress_ptr cinfo)
  152252. {
  152253. cinfo->inputctl->consume_input = consume_markers;
  152254. }
  152255. METHODDEF(int)
  152256. consume_markers (j_decompress_ptr cinfo)
  152257. {
  152258. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152259. int val;
  152260. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152261. return JPEG_REACHED_EOI;
  152262. val = (*cinfo->marker->read_markers) (cinfo);
  152263. switch (val) {
  152264. case JPEG_REACHED_SOS: /* Found SOS */
  152265. if (inputctl->inheaders) { /* 1st SOS */
  152266. initial_setup2(cinfo);
  152267. inputctl->inheaders = FALSE;
  152268. } else { /* 2nd or later SOS marker */
  152269. if (! inputctl->pub.has_multiple_scans)
  152270. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152271. start_input_pass2(cinfo);
  152272. }
  152273. break;
  152274. case JPEG_REACHED_EOI: /* Found EOI */
  152275. inputctl->pub.eoi_reached = TRUE;
  152276. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152277. if (cinfo->marker->saw_SOF)
  152278. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152279. } else {
  152280. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152281. cinfo->output_scan_number = cinfo->input_scan_number;
  152282. }
  152283. break;
  152284. case JPEG_SUSPENDED:
  152285. break;
  152286. }
  152287. return val;
  152288. }
  152289. METHODDEF(void)
  152290. reset_input_controller (j_decompress_ptr cinfo)
  152291. {
  152292. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152293. inputctl->pub.consume_input = consume_markers;
  152294. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152295. inputctl->pub.eoi_reached = FALSE;
  152296. inputctl->inheaders = TRUE;
  152297. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152298. (*cinfo->marker->reset_marker_reader) (cinfo);
  152299. cinfo->coef_bits = NULL;
  152300. }
  152301. GLOBAL(void)
  152302. jinit_input_controller (j_decompress_ptr cinfo)
  152303. {
  152304. my_inputctl_ptr inputctl;
  152305. inputctl = (my_inputctl_ptr)
  152306. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152307. SIZEOF(my_input_controller));
  152308. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152309. inputctl->pub.consume_input = consume_markers;
  152310. inputctl->pub.reset_input_controller = reset_input_controller;
  152311. inputctl->pub.start_input_pass = start_input_pass2;
  152312. inputctl->pub.finish_input_pass = finish_input_pass;
  152313. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152314. inputctl->pub.eoi_reached = FALSE;
  152315. inputctl->inheaders = TRUE;
  152316. }
  152317. /*** End of inlined file: jdinput.c ***/
  152318. /*** Start of inlined file: jdmainct.c ***/
  152319. #define JPEG_INTERNALS
  152320. typedef struct {
  152321. struct jpeg_d_main_controller pub; /* public fields */
  152322. JSAMPARRAY buffer[MAX_COMPONENTS];
  152323. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152324. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152325. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152326. int whichptr; /* indicates which pointer set is now in use */
  152327. int context_state; /* process_data state machine status */
  152328. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152329. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152330. } my_main_controller4;
  152331. typedef my_main_controller4 * my_main_ptr4;
  152332. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152333. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152334. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152335. METHODDEF(void) process_data_simple_main2
  152336. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152337. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152338. METHODDEF(void) process_data_context_main
  152339. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152340. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152341. #ifdef QUANT_2PASS_SUPPORTED
  152342. METHODDEF(void) process_data_crank_post
  152343. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152344. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152345. #endif
  152346. LOCAL(void)
  152347. alloc_funny_pointers (j_decompress_ptr cinfo)
  152348. {
  152349. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152350. int ci, rgroup;
  152351. int M = cinfo->min_DCT_scaled_size;
  152352. jpeg_component_info *compptr;
  152353. JSAMPARRAY xbuf;
  152354. main_->xbuffer[0] = (JSAMPIMAGE)
  152355. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152356. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152357. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152358. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152359. ci++, compptr++) {
  152360. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152361. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152362. xbuf = (JSAMPARRAY)
  152363. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152364. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152365. xbuf += rgroup; /* want one row group at negative offsets */
  152366. main_->xbuffer[0][ci] = xbuf;
  152367. xbuf += rgroup * (M + 4);
  152368. main_->xbuffer[1][ci] = xbuf;
  152369. }
  152370. }
  152371. LOCAL(void)
  152372. make_funny_pointers (j_decompress_ptr cinfo)
  152373. {
  152374. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152375. int ci, i, rgroup;
  152376. int M = cinfo->min_DCT_scaled_size;
  152377. jpeg_component_info *compptr;
  152378. JSAMPARRAY buf, xbuf0, xbuf1;
  152379. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152380. ci++, compptr++) {
  152381. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152382. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152383. xbuf0 = main_->xbuffer[0][ci];
  152384. xbuf1 = main_->xbuffer[1][ci];
  152385. buf = main_->buffer[ci];
  152386. for (i = 0; i < rgroup * (M + 2); i++) {
  152387. xbuf0[i] = xbuf1[i] = buf[i];
  152388. }
  152389. for (i = 0; i < rgroup * 2; i++) {
  152390. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152391. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152392. }
  152393. for (i = 0; i < rgroup; i++) {
  152394. xbuf0[i - rgroup] = xbuf0[0];
  152395. }
  152396. }
  152397. }
  152398. LOCAL(void)
  152399. set_wraparound_pointers (j_decompress_ptr cinfo)
  152400. {
  152401. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152402. int ci, i, rgroup;
  152403. int M = cinfo->min_DCT_scaled_size;
  152404. jpeg_component_info *compptr;
  152405. JSAMPARRAY xbuf0, xbuf1;
  152406. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152407. ci++, compptr++) {
  152408. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152409. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152410. xbuf0 = main_->xbuffer[0][ci];
  152411. xbuf1 = main_->xbuffer[1][ci];
  152412. for (i = 0; i < rgroup; i++) {
  152413. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152414. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152415. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152416. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152417. }
  152418. }
  152419. }
  152420. LOCAL(void)
  152421. set_bottom_pointers (j_decompress_ptr cinfo)
  152422. {
  152423. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152424. int ci, i, rgroup, iMCUheight, rows_left;
  152425. jpeg_component_info *compptr;
  152426. JSAMPARRAY xbuf;
  152427. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152428. ci++, compptr++) {
  152429. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152430. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152431. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152432. if (rows_left == 0) rows_left = iMCUheight;
  152433. if (ci == 0) {
  152434. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152435. }
  152436. xbuf = main_->xbuffer[main_->whichptr][ci];
  152437. for (i = 0; i < rgroup * 2; i++) {
  152438. xbuf[rows_left + i] = xbuf[rows_left-1];
  152439. }
  152440. }
  152441. }
  152442. METHODDEF(void)
  152443. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152444. {
  152445. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152446. switch (pass_mode) {
  152447. case JBUF_PASS_THRU:
  152448. if (cinfo->upsample->need_context_rows) {
  152449. main_->pub.process_data = process_data_context_main;
  152450. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152451. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152452. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152453. main_->iMCU_row_ctr = 0;
  152454. } else {
  152455. main_->pub.process_data = process_data_simple_main2;
  152456. }
  152457. main_->buffer_full = FALSE; /* Mark buffer empty */
  152458. main_->rowgroup_ctr = 0;
  152459. break;
  152460. #ifdef QUANT_2PASS_SUPPORTED
  152461. case JBUF_CRANK_DEST:
  152462. main_->pub.process_data = process_data_crank_post;
  152463. break;
  152464. #endif
  152465. default:
  152466. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152467. break;
  152468. }
  152469. }
  152470. METHODDEF(void)
  152471. process_data_simple_main2 (j_decompress_ptr cinfo,
  152472. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152473. JDIMENSION out_rows_avail)
  152474. {
  152475. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152476. JDIMENSION rowgroups_avail;
  152477. if (! main_->buffer_full) {
  152478. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152479. return; /* suspension forced, can do nothing more */
  152480. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152481. }
  152482. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152483. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152484. &main_->rowgroup_ctr, rowgroups_avail,
  152485. output_buf, out_row_ctr, out_rows_avail);
  152486. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152487. main_->buffer_full = FALSE;
  152488. main_->rowgroup_ctr = 0;
  152489. }
  152490. }
  152491. METHODDEF(void)
  152492. process_data_context_main (j_decompress_ptr cinfo,
  152493. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152494. JDIMENSION out_rows_avail)
  152495. {
  152496. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152497. if (! main_->buffer_full) {
  152498. if (! (*cinfo->coef->decompress_data) (cinfo,
  152499. main_->xbuffer[main_->whichptr]))
  152500. return; /* suspension forced, can do nothing more */
  152501. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152502. main_->iMCU_row_ctr++; /* count rows received */
  152503. }
  152504. switch (main_->context_state) {
  152505. case CTX_POSTPONED_ROW:
  152506. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152507. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152508. output_buf, out_row_ctr, out_rows_avail);
  152509. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152510. return; /* Need to suspend */
  152511. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152512. if (*out_row_ctr >= out_rows_avail)
  152513. return; /* Postprocessor exactly filled output buf */
  152514. case CTX_PREPARE_FOR_IMCU:
  152515. main_->rowgroup_ctr = 0;
  152516. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152517. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152518. set_bottom_pointers(cinfo);
  152519. main_->context_state = CTX_PROCESS_IMCU;
  152520. case CTX_PROCESS_IMCU:
  152521. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152522. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152523. output_buf, out_row_ctr, out_rows_avail);
  152524. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152525. return; /* Need to suspend */
  152526. if (main_->iMCU_row_ctr == 1)
  152527. set_wraparound_pointers(cinfo);
  152528. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152529. main_->buffer_full = FALSE;
  152530. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152531. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152532. main_->context_state = CTX_POSTPONED_ROW;
  152533. }
  152534. }
  152535. #ifdef QUANT_2PASS_SUPPORTED
  152536. METHODDEF(void)
  152537. process_data_crank_post (j_decompress_ptr cinfo,
  152538. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152539. JDIMENSION out_rows_avail)
  152540. {
  152541. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152542. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152543. output_buf, out_row_ctr, out_rows_avail);
  152544. }
  152545. #endif /* QUANT_2PASS_SUPPORTED */
  152546. GLOBAL(void)
  152547. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152548. {
  152549. my_main_ptr4 main_;
  152550. int ci, rgroup, ngroups;
  152551. jpeg_component_info *compptr;
  152552. main_ = (my_main_ptr4)
  152553. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152554. SIZEOF(my_main_controller4));
  152555. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152556. main_->pub.start_pass = start_pass_main2;
  152557. if (need_full_buffer) /* shouldn't happen */
  152558. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152559. if (cinfo->upsample->need_context_rows) {
  152560. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152561. ERREXIT(cinfo, JERR_NOTIMPL);
  152562. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152563. ngroups = cinfo->min_DCT_scaled_size + 2;
  152564. } else {
  152565. ngroups = cinfo->min_DCT_scaled_size;
  152566. }
  152567. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152568. ci++, compptr++) {
  152569. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152570. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152571. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152572. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152573. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152574. (JDIMENSION) (rgroup * ngroups));
  152575. }
  152576. }
  152577. /*** End of inlined file: jdmainct.c ***/
  152578. /*** Start of inlined file: jdmarker.c ***/
  152579. #define JPEG_INTERNALS
  152580. typedef struct {
  152581. struct jpeg_marker_reader pub; /* public fields */
  152582. jpeg_marker_parser_method process_COM;
  152583. jpeg_marker_parser_method process_APPn[16];
  152584. unsigned int length_limit_COM;
  152585. unsigned int length_limit_APPn[16];
  152586. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152587. unsigned int bytes_read; /* data bytes read so far in marker */
  152588. } my_marker_reader;
  152589. typedef my_marker_reader * my_marker_ptr2;
  152590. #define INPUT_VARS(cinfo) \
  152591. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152592. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152593. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152594. #define INPUT_SYNC(cinfo) \
  152595. ( datasrc->next_input_byte = next_input_byte, \
  152596. datasrc->bytes_in_buffer = bytes_in_buffer )
  152597. #define INPUT_RELOAD(cinfo) \
  152598. ( next_input_byte = datasrc->next_input_byte, \
  152599. bytes_in_buffer = datasrc->bytes_in_buffer )
  152600. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152601. if (bytes_in_buffer == 0) { \
  152602. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152603. { action; } \
  152604. INPUT_RELOAD(cinfo); \
  152605. }
  152606. #define INPUT_BYTE(cinfo,V,action) \
  152607. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152608. bytes_in_buffer--; \
  152609. V = GETJOCTET(*next_input_byte++); )
  152610. #define INPUT_2BYTES(cinfo,V,action) \
  152611. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152612. bytes_in_buffer--; \
  152613. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152614. MAKE_BYTE_AVAIL(cinfo,action); \
  152615. bytes_in_buffer--; \
  152616. V += GETJOCTET(*next_input_byte++); )
  152617. LOCAL(boolean)
  152618. get_soi (j_decompress_ptr cinfo)
  152619. {
  152620. int i;
  152621. TRACEMS(cinfo, 1, JTRC_SOI);
  152622. if (cinfo->marker->saw_SOI)
  152623. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152624. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152625. cinfo->arith_dc_L[i] = 0;
  152626. cinfo->arith_dc_U[i] = 1;
  152627. cinfo->arith_ac_K[i] = 5;
  152628. }
  152629. cinfo->restart_interval = 0;
  152630. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152631. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152632. cinfo->saw_JFIF_marker = FALSE;
  152633. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152634. cinfo->JFIF_minor_version = 1;
  152635. cinfo->density_unit = 0;
  152636. cinfo->X_density = 1;
  152637. cinfo->Y_density = 1;
  152638. cinfo->saw_Adobe_marker = FALSE;
  152639. cinfo->Adobe_transform = 0;
  152640. cinfo->marker->saw_SOI = TRUE;
  152641. return TRUE;
  152642. }
  152643. LOCAL(boolean)
  152644. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152645. {
  152646. INT32 length;
  152647. int c, ci;
  152648. jpeg_component_info * compptr;
  152649. INPUT_VARS(cinfo);
  152650. cinfo->progressive_mode = is_prog;
  152651. cinfo->arith_code = is_arith;
  152652. INPUT_2BYTES(cinfo, length, return FALSE);
  152653. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152654. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152655. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152656. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152657. length -= 8;
  152658. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152659. (int) cinfo->image_width, (int) cinfo->image_height,
  152660. cinfo->num_components);
  152661. if (cinfo->marker->saw_SOF)
  152662. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152663. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152664. || cinfo->num_components <= 0)
  152665. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152666. if (length != (cinfo->num_components * 3))
  152667. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152668. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152669. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152670. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152671. cinfo->num_components * SIZEOF(jpeg_component_info));
  152672. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152673. ci++, compptr++) {
  152674. compptr->component_index = ci;
  152675. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152676. INPUT_BYTE(cinfo, c, return FALSE);
  152677. compptr->h_samp_factor = (c >> 4) & 15;
  152678. compptr->v_samp_factor = (c ) & 15;
  152679. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152680. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152681. compptr->component_id, compptr->h_samp_factor,
  152682. compptr->v_samp_factor, compptr->quant_tbl_no);
  152683. }
  152684. cinfo->marker->saw_SOF = TRUE;
  152685. INPUT_SYNC(cinfo);
  152686. return TRUE;
  152687. }
  152688. LOCAL(boolean)
  152689. get_sos (j_decompress_ptr cinfo)
  152690. {
  152691. INT32 length;
  152692. int i, ci, n, c, cc;
  152693. jpeg_component_info * compptr;
  152694. INPUT_VARS(cinfo);
  152695. if (! cinfo->marker->saw_SOF)
  152696. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152697. INPUT_2BYTES(cinfo, length, return FALSE);
  152698. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152699. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152700. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152701. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152702. cinfo->comps_in_scan = n;
  152703. for (i = 0; i < n; i++) {
  152704. INPUT_BYTE(cinfo, cc, return FALSE);
  152705. INPUT_BYTE(cinfo, c, return FALSE);
  152706. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152707. ci++, compptr++) {
  152708. if (cc == compptr->component_id)
  152709. goto id_found;
  152710. }
  152711. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152712. id_found:
  152713. cinfo->cur_comp_info[i] = compptr;
  152714. compptr->dc_tbl_no = (c >> 4) & 15;
  152715. compptr->ac_tbl_no = (c ) & 15;
  152716. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152717. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152718. }
  152719. INPUT_BYTE(cinfo, c, return FALSE);
  152720. cinfo->Ss = c;
  152721. INPUT_BYTE(cinfo, c, return FALSE);
  152722. cinfo->Se = c;
  152723. INPUT_BYTE(cinfo, c, return FALSE);
  152724. cinfo->Ah = (c >> 4) & 15;
  152725. cinfo->Al = (c ) & 15;
  152726. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152727. cinfo->Ah, cinfo->Al);
  152728. cinfo->marker->next_restart_num = 0;
  152729. cinfo->input_scan_number++;
  152730. INPUT_SYNC(cinfo);
  152731. return TRUE;
  152732. }
  152733. #ifdef D_ARITH_CODING_SUPPORTED
  152734. LOCAL(boolean)
  152735. get_dac (j_decompress_ptr cinfo)
  152736. {
  152737. INT32 length;
  152738. int index, val;
  152739. INPUT_VARS(cinfo);
  152740. INPUT_2BYTES(cinfo, length, return FALSE);
  152741. length -= 2;
  152742. while (length > 0) {
  152743. INPUT_BYTE(cinfo, index, return FALSE);
  152744. INPUT_BYTE(cinfo, val, return FALSE);
  152745. length -= 2;
  152746. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152747. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152748. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152749. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152750. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152751. } else { /* define DC table */
  152752. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152753. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152754. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152755. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152756. }
  152757. }
  152758. if (length != 0)
  152759. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152760. INPUT_SYNC(cinfo);
  152761. return TRUE;
  152762. }
  152763. #else /* ! D_ARITH_CODING_SUPPORTED */
  152764. #define get_dac(cinfo) skip_variable(cinfo)
  152765. #endif /* D_ARITH_CODING_SUPPORTED */
  152766. LOCAL(boolean)
  152767. get_dht (j_decompress_ptr cinfo)
  152768. {
  152769. INT32 length;
  152770. UINT8 bits[17];
  152771. UINT8 huffval[256];
  152772. int i, index, count;
  152773. JHUFF_TBL **htblptr;
  152774. INPUT_VARS(cinfo);
  152775. INPUT_2BYTES(cinfo, length, return FALSE);
  152776. length -= 2;
  152777. while (length > 16) {
  152778. INPUT_BYTE(cinfo, index, return FALSE);
  152779. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152780. bits[0] = 0;
  152781. count = 0;
  152782. for (i = 1; i <= 16; i++) {
  152783. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152784. count += bits[i];
  152785. }
  152786. length -= 1 + 16;
  152787. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152788. bits[1], bits[2], bits[3], bits[4],
  152789. bits[5], bits[6], bits[7], bits[8]);
  152790. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152791. bits[9], bits[10], bits[11], bits[12],
  152792. bits[13], bits[14], bits[15], bits[16]);
  152793. if (count > 256 || ((INT32) count) > length)
  152794. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152795. for (i = 0; i < count; i++)
  152796. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152797. length -= count;
  152798. if (index & 0x10) { /* AC table definition */
  152799. index -= 0x10;
  152800. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152801. } else { /* DC table definition */
  152802. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152803. }
  152804. if (index < 0 || index >= NUM_HUFF_TBLS)
  152805. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152806. if (*htblptr == NULL)
  152807. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152808. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152809. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152810. }
  152811. if (length != 0)
  152812. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152813. INPUT_SYNC(cinfo);
  152814. return TRUE;
  152815. }
  152816. LOCAL(boolean)
  152817. get_dqt (j_decompress_ptr cinfo)
  152818. {
  152819. INT32 length;
  152820. int n, i, prec;
  152821. unsigned int tmp;
  152822. JQUANT_TBL *quant_ptr;
  152823. INPUT_VARS(cinfo);
  152824. INPUT_2BYTES(cinfo, length, return FALSE);
  152825. length -= 2;
  152826. while (length > 0) {
  152827. INPUT_BYTE(cinfo, n, return FALSE);
  152828. prec = n >> 4;
  152829. n &= 0x0F;
  152830. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152831. if (n >= NUM_QUANT_TBLS)
  152832. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152833. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152834. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152835. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152836. for (i = 0; i < DCTSIZE2; i++) {
  152837. if (prec)
  152838. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152839. else
  152840. INPUT_BYTE(cinfo, tmp, return FALSE);
  152841. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152842. }
  152843. if (cinfo->err->trace_level >= 2) {
  152844. for (i = 0; i < DCTSIZE2; i += 8) {
  152845. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152846. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152847. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152848. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152849. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152850. }
  152851. }
  152852. length -= DCTSIZE2+1;
  152853. if (prec) length -= DCTSIZE2;
  152854. }
  152855. if (length != 0)
  152856. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152857. INPUT_SYNC(cinfo);
  152858. return TRUE;
  152859. }
  152860. LOCAL(boolean)
  152861. get_dri (j_decompress_ptr cinfo)
  152862. {
  152863. INT32 length;
  152864. unsigned int tmp;
  152865. INPUT_VARS(cinfo);
  152866. INPUT_2BYTES(cinfo, length, return FALSE);
  152867. if (length != 4)
  152868. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152869. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152870. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152871. cinfo->restart_interval = tmp;
  152872. INPUT_SYNC(cinfo);
  152873. return TRUE;
  152874. }
  152875. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152876. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152877. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152878. LOCAL(void)
  152879. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152880. unsigned int datalen, INT32 remaining)
  152881. {
  152882. INT32 totallen = (INT32) datalen + remaining;
  152883. if (datalen >= APP0_DATA_LEN &&
  152884. GETJOCTET(data[0]) == 0x4A &&
  152885. GETJOCTET(data[1]) == 0x46 &&
  152886. GETJOCTET(data[2]) == 0x49 &&
  152887. GETJOCTET(data[3]) == 0x46 &&
  152888. GETJOCTET(data[4]) == 0) {
  152889. cinfo->saw_JFIF_marker = TRUE;
  152890. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152891. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152892. cinfo->density_unit = GETJOCTET(data[7]);
  152893. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152894. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152895. if (cinfo->JFIF_major_version != 1)
  152896. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152897. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152898. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152899. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152900. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152901. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152902. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152903. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152904. totallen -= APP0_DATA_LEN;
  152905. if (totallen !=
  152906. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152907. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152908. } else if (datalen >= 6 &&
  152909. GETJOCTET(data[0]) == 0x4A &&
  152910. GETJOCTET(data[1]) == 0x46 &&
  152911. GETJOCTET(data[2]) == 0x58 &&
  152912. GETJOCTET(data[3]) == 0x58 &&
  152913. GETJOCTET(data[4]) == 0) {
  152914. switch (GETJOCTET(data[5])) {
  152915. case 0x10:
  152916. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152917. break;
  152918. case 0x11:
  152919. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152920. break;
  152921. case 0x13:
  152922. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152923. break;
  152924. default:
  152925. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152926. GETJOCTET(data[5]), (int) totallen);
  152927. break;
  152928. }
  152929. } else {
  152930. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  152931. }
  152932. }
  152933. LOCAL(void)
  152934. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152935. unsigned int datalen, INT32 remaining)
  152936. {
  152937. unsigned int version, flags0, flags1, transform;
  152938. if (datalen >= APP14_DATA_LEN &&
  152939. GETJOCTET(data[0]) == 0x41 &&
  152940. GETJOCTET(data[1]) == 0x64 &&
  152941. GETJOCTET(data[2]) == 0x6F &&
  152942. GETJOCTET(data[3]) == 0x62 &&
  152943. GETJOCTET(data[4]) == 0x65) {
  152944. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  152945. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  152946. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  152947. transform = GETJOCTET(data[11]);
  152948. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  152949. cinfo->saw_Adobe_marker = TRUE;
  152950. cinfo->Adobe_transform = (UINT8) transform;
  152951. } else {
  152952. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  152953. }
  152954. }
  152955. METHODDEF(boolean)
  152956. get_interesting_appn (j_decompress_ptr cinfo)
  152957. {
  152958. INT32 length;
  152959. JOCTET b[APPN_DATA_LEN];
  152960. unsigned int i, numtoread;
  152961. INPUT_VARS(cinfo);
  152962. INPUT_2BYTES(cinfo, length, return FALSE);
  152963. length -= 2;
  152964. if (length >= APPN_DATA_LEN)
  152965. numtoread = APPN_DATA_LEN;
  152966. else if (length > 0)
  152967. numtoread = (unsigned int) length;
  152968. else
  152969. numtoread = 0;
  152970. for (i = 0; i < numtoread; i++)
  152971. INPUT_BYTE(cinfo, b[i], return FALSE);
  152972. length -= numtoread;
  152973. switch (cinfo->unread_marker) {
  152974. case M_APP0:
  152975. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  152976. break;
  152977. case M_APP14:
  152978. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  152979. break;
  152980. default:
  152981. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  152982. break;
  152983. }
  152984. INPUT_SYNC(cinfo);
  152985. if (length > 0)
  152986. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152987. return TRUE;
  152988. }
  152989. #ifdef SAVE_MARKERS_SUPPORTED
  152990. METHODDEF(boolean)
  152991. save_marker (j_decompress_ptr cinfo)
  152992. {
  152993. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  152994. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  152995. unsigned int bytes_read, data_length;
  152996. JOCTET FAR * data;
  152997. INT32 length = 0;
  152998. INPUT_VARS(cinfo);
  152999. if (cur_marker == NULL) {
  153000. INPUT_2BYTES(cinfo, length, return FALSE);
  153001. length -= 2;
  153002. if (length >= 0) { /* watch out for bogus length word */
  153003. unsigned int limit;
  153004. if (cinfo->unread_marker == (int) M_COM)
  153005. limit = marker->length_limit_COM;
  153006. else
  153007. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153008. if ((unsigned int) length < limit)
  153009. limit = (unsigned int) length;
  153010. cur_marker = (jpeg_saved_marker_ptr)
  153011. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153012. SIZEOF(struct jpeg_marker_struct) + limit);
  153013. cur_marker->next = NULL;
  153014. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153015. cur_marker->original_length = (unsigned int) length;
  153016. cur_marker->data_length = limit;
  153017. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153018. marker->cur_marker = cur_marker;
  153019. marker->bytes_read = 0;
  153020. bytes_read = 0;
  153021. data_length = limit;
  153022. } else {
  153023. bytes_read = data_length = 0;
  153024. data = NULL;
  153025. }
  153026. } else {
  153027. bytes_read = marker->bytes_read;
  153028. data_length = cur_marker->data_length;
  153029. data = cur_marker->data + bytes_read;
  153030. }
  153031. while (bytes_read < data_length) {
  153032. INPUT_SYNC(cinfo); /* move the restart point to here */
  153033. marker->bytes_read = bytes_read;
  153034. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153035. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153036. *data++ = *next_input_byte++;
  153037. bytes_in_buffer--;
  153038. bytes_read++;
  153039. }
  153040. }
  153041. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153042. if (cinfo->marker_list == NULL) {
  153043. cinfo->marker_list = cur_marker;
  153044. } else {
  153045. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153046. while (prev->next != NULL)
  153047. prev = prev->next;
  153048. prev->next = cur_marker;
  153049. }
  153050. data = cur_marker->data;
  153051. length = cur_marker->original_length - data_length;
  153052. }
  153053. marker->cur_marker = NULL;
  153054. switch (cinfo->unread_marker) {
  153055. case M_APP0:
  153056. examine_app0(cinfo, data, data_length, length);
  153057. break;
  153058. case M_APP14:
  153059. examine_app14(cinfo, data, data_length, length);
  153060. break;
  153061. default:
  153062. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153063. (int) (data_length + length));
  153064. break;
  153065. }
  153066. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153067. if (length > 0)
  153068. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153069. return TRUE;
  153070. }
  153071. #endif /* SAVE_MARKERS_SUPPORTED */
  153072. METHODDEF(boolean)
  153073. skip_variable (j_decompress_ptr cinfo)
  153074. {
  153075. INT32 length;
  153076. INPUT_VARS(cinfo);
  153077. INPUT_2BYTES(cinfo, length, return FALSE);
  153078. length -= 2;
  153079. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153080. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153081. if (length > 0)
  153082. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153083. return TRUE;
  153084. }
  153085. LOCAL(boolean)
  153086. next_marker (j_decompress_ptr cinfo)
  153087. {
  153088. int c;
  153089. INPUT_VARS(cinfo);
  153090. for (;;) {
  153091. INPUT_BYTE(cinfo, c, return FALSE);
  153092. while (c != 0xFF) {
  153093. cinfo->marker->discarded_bytes++;
  153094. INPUT_SYNC(cinfo);
  153095. INPUT_BYTE(cinfo, c, return FALSE);
  153096. }
  153097. do {
  153098. INPUT_BYTE(cinfo, c, return FALSE);
  153099. } while (c == 0xFF);
  153100. if (c != 0)
  153101. break; /* found a valid marker, exit loop */
  153102. cinfo->marker->discarded_bytes += 2;
  153103. INPUT_SYNC(cinfo);
  153104. }
  153105. if (cinfo->marker->discarded_bytes != 0) {
  153106. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153107. cinfo->marker->discarded_bytes = 0;
  153108. }
  153109. cinfo->unread_marker = c;
  153110. INPUT_SYNC(cinfo);
  153111. return TRUE;
  153112. }
  153113. LOCAL(boolean)
  153114. first_marker (j_decompress_ptr cinfo)
  153115. {
  153116. int c, c2;
  153117. INPUT_VARS(cinfo);
  153118. INPUT_BYTE(cinfo, c, return FALSE);
  153119. INPUT_BYTE(cinfo, c2, return FALSE);
  153120. if (c != 0xFF || c2 != (int) M_SOI)
  153121. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153122. cinfo->unread_marker = c2;
  153123. INPUT_SYNC(cinfo);
  153124. return TRUE;
  153125. }
  153126. METHODDEF(int)
  153127. read_markers (j_decompress_ptr cinfo)
  153128. {
  153129. for (;;) {
  153130. if (cinfo->unread_marker == 0) {
  153131. if (! cinfo->marker->saw_SOI) {
  153132. if (! first_marker(cinfo))
  153133. return JPEG_SUSPENDED;
  153134. } else {
  153135. if (! next_marker(cinfo))
  153136. return JPEG_SUSPENDED;
  153137. }
  153138. }
  153139. switch (cinfo->unread_marker) {
  153140. case M_SOI:
  153141. if (! get_soi(cinfo))
  153142. return JPEG_SUSPENDED;
  153143. break;
  153144. case M_SOF0: /* Baseline */
  153145. case M_SOF1: /* Extended sequential, Huffman */
  153146. if (! get_sof(cinfo, FALSE, FALSE))
  153147. return JPEG_SUSPENDED;
  153148. break;
  153149. case M_SOF2: /* Progressive, Huffman */
  153150. if (! get_sof(cinfo, TRUE, FALSE))
  153151. return JPEG_SUSPENDED;
  153152. break;
  153153. case M_SOF9: /* Extended sequential, arithmetic */
  153154. if (! get_sof(cinfo, FALSE, TRUE))
  153155. return JPEG_SUSPENDED;
  153156. break;
  153157. case M_SOF10: /* Progressive, arithmetic */
  153158. if (! get_sof(cinfo, TRUE, TRUE))
  153159. return JPEG_SUSPENDED;
  153160. break;
  153161. case M_SOF3: /* Lossless, Huffman */
  153162. case M_SOF5: /* Differential sequential, Huffman */
  153163. case M_SOF6: /* Differential progressive, Huffman */
  153164. case M_SOF7: /* Differential lossless, Huffman */
  153165. case M_JPG: /* Reserved for JPEG extensions */
  153166. case M_SOF11: /* Lossless, arithmetic */
  153167. case M_SOF13: /* Differential sequential, arithmetic */
  153168. case M_SOF14: /* Differential progressive, arithmetic */
  153169. case M_SOF15: /* Differential lossless, arithmetic */
  153170. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153171. break;
  153172. case M_SOS:
  153173. if (! get_sos(cinfo))
  153174. return JPEG_SUSPENDED;
  153175. cinfo->unread_marker = 0; /* processed the marker */
  153176. return JPEG_REACHED_SOS;
  153177. case M_EOI:
  153178. TRACEMS(cinfo, 1, JTRC_EOI);
  153179. cinfo->unread_marker = 0; /* processed the marker */
  153180. return JPEG_REACHED_EOI;
  153181. case M_DAC:
  153182. if (! get_dac(cinfo))
  153183. return JPEG_SUSPENDED;
  153184. break;
  153185. case M_DHT:
  153186. if (! get_dht(cinfo))
  153187. return JPEG_SUSPENDED;
  153188. break;
  153189. case M_DQT:
  153190. if (! get_dqt(cinfo))
  153191. return JPEG_SUSPENDED;
  153192. break;
  153193. case M_DRI:
  153194. if (! get_dri(cinfo))
  153195. return JPEG_SUSPENDED;
  153196. break;
  153197. case M_APP0:
  153198. case M_APP1:
  153199. case M_APP2:
  153200. case M_APP3:
  153201. case M_APP4:
  153202. case M_APP5:
  153203. case M_APP6:
  153204. case M_APP7:
  153205. case M_APP8:
  153206. case M_APP9:
  153207. case M_APP10:
  153208. case M_APP11:
  153209. case M_APP12:
  153210. case M_APP13:
  153211. case M_APP14:
  153212. case M_APP15:
  153213. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153214. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153215. return JPEG_SUSPENDED;
  153216. break;
  153217. case M_COM:
  153218. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153219. return JPEG_SUSPENDED;
  153220. break;
  153221. case M_RST0: /* these are all parameterless */
  153222. case M_RST1:
  153223. case M_RST2:
  153224. case M_RST3:
  153225. case M_RST4:
  153226. case M_RST5:
  153227. case M_RST6:
  153228. case M_RST7:
  153229. case M_TEM:
  153230. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153231. break;
  153232. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153233. if (! skip_variable(cinfo))
  153234. return JPEG_SUSPENDED;
  153235. break;
  153236. default: /* must be DHP, EXP, JPGn, or RESn */
  153237. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153238. break;
  153239. }
  153240. cinfo->unread_marker = 0;
  153241. } /* end loop */
  153242. }
  153243. METHODDEF(boolean)
  153244. read_restart_marker (j_decompress_ptr cinfo)
  153245. {
  153246. if (cinfo->unread_marker == 0) {
  153247. if (! next_marker(cinfo))
  153248. return FALSE;
  153249. }
  153250. if (cinfo->unread_marker ==
  153251. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153252. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153253. cinfo->unread_marker = 0;
  153254. } else {
  153255. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153256. cinfo->marker->next_restart_num))
  153257. return FALSE;
  153258. }
  153259. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153260. return TRUE;
  153261. }
  153262. GLOBAL(boolean)
  153263. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153264. {
  153265. int marker = cinfo->unread_marker;
  153266. int action = 1;
  153267. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153268. for (;;) {
  153269. if (marker < (int) M_SOF0)
  153270. action = 2; /* invalid marker */
  153271. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153272. action = 3; /* valid non-restart marker */
  153273. else {
  153274. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153275. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153276. action = 3; /* one of the next two expected restarts */
  153277. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153278. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153279. action = 2; /* a prior restart, so advance */
  153280. else
  153281. action = 1; /* desired restart or too far away */
  153282. }
  153283. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153284. switch (action) {
  153285. case 1:
  153286. cinfo->unread_marker = 0;
  153287. return TRUE;
  153288. case 2:
  153289. if (! next_marker(cinfo))
  153290. return FALSE;
  153291. marker = cinfo->unread_marker;
  153292. break;
  153293. case 3:
  153294. return TRUE;
  153295. }
  153296. } /* end loop */
  153297. }
  153298. METHODDEF(void)
  153299. reset_marker_reader (j_decompress_ptr cinfo)
  153300. {
  153301. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153302. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153303. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153304. cinfo->unread_marker = 0; /* no pending marker */
  153305. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153306. marker->pub.saw_SOF = FALSE;
  153307. marker->pub.discarded_bytes = 0;
  153308. marker->cur_marker = NULL;
  153309. }
  153310. GLOBAL(void)
  153311. jinit_marker_reader (j_decompress_ptr cinfo)
  153312. {
  153313. my_marker_ptr2 marker;
  153314. int i;
  153315. marker = (my_marker_ptr2)
  153316. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153317. SIZEOF(my_marker_reader));
  153318. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153319. marker->pub.reset_marker_reader = reset_marker_reader;
  153320. marker->pub.read_markers = read_markers;
  153321. marker->pub.read_restart_marker = read_restart_marker;
  153322. marker->process_COM = skip_variable;
  153323. marker->length_limit_COM = 0;
  153324. for (i = 0; i < 16; i++) {
  153325. marker->process_APPn[i] = skip_variable;
  153326. marker->length_limit_APPn[i] = 0;
  153327. }
  153328. marker->process_APPn[0] = get_interesting_appn;
  153329. marker->process_APPn[14] = get_interesting_appn;
  153330. reset_marker_reader(cinfo);
  153331. }
  153332. #ifdef SAVE_MARKERS_SUPPORTED
  153333. GLOBAL(void)
  153334. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153335. unsigned int length_limit)
  153336. {
  153337. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153338. long maxlength;
  153339. jpeg_marker_parser_method processor;
  153340. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153341. if (((long) length_limit) > maxlength)
  153342. length_limit = (unsigned int) maxlength;
  153343. if (length_limit) {
  153344. processor = save_marker;
  153345. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153346. length_limit = APP0_DATA_LEN;
  153347. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153348. length_limit = APP14_DATA_LEN;
  153349. } else {
  153350. processor = skip_variable;
  153351. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153352. processor = get_interesting_appn;
  153353. }
  153354. if (marker_code == (int) M_COM) {
  153355. marker->process_COM = processor;
  153356. marker->length_limit_COM = length_limit;
  153357. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153358. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153359. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153360. } else
  153361. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153362. }
  153363. #endif /* SAVE_MARKERS_SUPPORTED */
  153364. GLOBAL(void)
  153365. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153366. jpeg_marker_parser_method routine)
  153367. {
  153368. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153369. if (marker_code == (int) M_COM)
  153370. marker->process_COM = routine;
  153371. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153372. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153373. else
  153374. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153375. }
  153376. /*** End of inlined file: jdmarker.c ***/
  153377. /*** Start of inlined file: jdmaster.c ***/
  153378. #define JPEG_INTERNALS
  153379. typedef struct {
  153380. struct jpeg_decomp_master pub; /* public fields */
  153381. int pass_number; /* # of passes completed */
  153382. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153383. struct jpeg_color_quantizer * quantizer_1pass;
  153384. struct jpeg_color_quantizer * quantizer_2pass;
  153385. } my_decomp_master;
  153386. typedef my_decomp_master * my_master_ptr6;
  153387. LOCAL(boolean)
  153388. use_merged_upsample (j_decompress_ptr cinfo)
  153389. {
  153390. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153391. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153392. return FALSE;
  153393. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153394. cinfo->out_color_space != JCS_RGB ||
  153395. cinfo->out_color_components != RGB_PIXELSIZE)
  153396. return FALSE;
  153397. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153398. cinfo->comp_info[1].h_samp_factor != 1 ||
  153399. cinfo->comp_info[2].h_samp_factor != 1 ||
  153400. cinfo->comp_info[0].v_samp_factor > 2 ||
  153401. cinfo->comp_info[1].v_samp_factor != 1 ||
  153402. cinfo->comp_info[2].v_samp_factor != 1)
  153403. return FALSE;
  153404. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153405. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153406. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153407. return FALSE;
  153408. return TRUE; /* by golly, it'll work... */
  153409. #else
  153410. return FALSE;
  153411. #endif
  153412. }
  153413. GLOBAL(void)
  153414. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153415. {
  153416. #ifdef IDCT_SCALING_SUPPORTED
  153417. int ci;
  153418. jpeg_component_info *compptr;
  153419. #endif
  153420. if (cinfo->global_state != DSTATE_READY)
  153421. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153422. #ifdef IDCT_SCALING_SUPPORTED
  153423. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153424. cinfo->output_width = (JDIMENSION)
  153425. jdiv_round_up((long) cinfo->image_width, 8L);
  153426. cinfo->output_height = (JDIMENSION)
  153427. jdiv_round_up((long) cinfo->image_height, 8L);
  153428. cinfo->min_DCT_scaled_size = 1;
  153429. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153430. cinfo->output_width = (JDIMENSION)
  153431. jdiv_round_up((long) cinfo->image_width, 4L);
  153432. cinfo->output_height = (JDIMENSION)
  153433. jdiv_round_up((long) cinfo->image_height, 4L);
  153434. cinfo->min_DCT_scaled_size = 2;
  153435. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153436. cinfo->output_width = (JDIMENSION)
  153437. jdiv_round_up((long) cinfo->image_width, 2L);
  153438. cinfo->output_height = (JDIMENSION)
  153439. jdiv_round_up((long) cinfo->image_height, 2L);
  153440. cinfo->min_DCT_scaled_size = 4;
  153441. } else {
  153442. cinfo->output_width = cinfo->image_width;
  153443. cinfo->output_height = cinfo->image_height;
  153444. cinfo->min_DCT_scaled_size = DCTSIZE;
  153445. }
  153446. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153447. ci++, compptr++) {
  153448. int ssize = cinfo->min_DCT_scaled_size;
  153449. while (ssize < DCTSIZE &&
  153450. (compptr->h_samp_factor * ssize * 2 <=
  153451. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153452. (compptr->v_samp_factor * ssize * 2 <=
  153453. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153454. ssize = ssize * 2;
  153455. }
  153456. compptr->DCT_scaled_size = ssize;
  153457. }
  153458. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153459. ci++, compptr++) {
  153460. compptr->downsampled_width = (JDIMENSION)
  153461. jdiv_round_up((long) cinfo->image_width *
  153462. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153463. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153464. compptr->downsampled_height = (JDIMENSION)
  153465. jdiv_round_up((long) cinfo->image_height *
  153466. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153467. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153468. }
  153469. #else /* !IDCT_SCALING_SUPPORTED */
  153470. cinfo->output_width = cinfo->image_width;
  153471. cinfo->output_height = cinfo->image_height;
  153472. #endif /* IDCT_SCALING_SUPPORTED */
  153473. switch (cinfo->out_color_space) {
  153474. case JCS_GRAYSCALE:
  153475. cinfo->out_color_components = 1;
  153476. break;
  153477. case JCS_RGB:
  153478. #if RGB_PIXELSIZE != 3
  153479. cinfo->out_color_components = RGB_PIXELSIZE;
  153480. break;
  153481. #endif /* else share code with YCbCr */
  153482. case JCS_YCbCr:
  153483. cinfo->out_color_components = 3;
  153484. break;
  153485. case JCS_CMYK:
  153486. case JCS_YCCK:
  153487. cinfo->out_color_components = 4;
  153488. break;
  153489. default: /* else must be same colorspace as in file */
  153490. cinfo->out_color_components = cinfo->num_components;
  153491. break;
  153492. }
  153493. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153494. cinfo->out_color_components);
  153495. if (use_merged_upsample(cinfo))
  153496. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153497. else
  153498. cinfo->rec_outbuf_height = 1;
  153499. }
  153500. LOCAL(void)
  153501. prepare_range_limit_table (j_decompress_ptr cinfo)
  153502. {
  153503. JSAMPLE * table;
  153504. int i;
  153505. table = (JSAMPLE *)
  153506. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153507. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153508. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153509. cinfo->sample_range_limit = table;
  153510. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153511. for (i = 0; i <= MAXJSAMPLE; i++)
  153512. table[i] = (JSAMPLE) i;
  153513. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153514. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153515. table[i] = MAXJSAMPLE;
  153516. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153517. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153518. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153519. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153520. }
  153521. LOCAL(void)
  153522. master_selection (j_decompress_ptr cinfo)
  153523. {
  153524. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153525. boolean use_c_buffer;
  153526. long samplesperrow;
  153527. JDIMENSION jd_samplesperrow;
  153528. jpeg_calc_output_dimensions(cinfo);
  153529. prepare_range_limit_table(cinfo);
  153530. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153531. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153532. if ((long) jd_samplesperrow != samplesperrow)
  153533. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153534. master->pass_number = 0;
  153535. master->using_merged_upsample = use_merged_upsample(cinfo);
  153536. master->quantizer_1pass = NULL;
  153537. master->quantizer_2pass = NULL;
  153538. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153539. cinfo->enable_1pass_quant = FALSE;
  153540. cinfo->enable_external_quant = FALSE;
  153541. cinfo->enable_2pass_quant = FALSE;
  153542. }
  153543. if (cinfo->quantize_colors) {
  153544. if (cinfo->raw_data_out)
  153545. ERREXIT(cinfo, JERR_NOTIMPL);
  153546. if (cinfo->out_color_components != 3) {
  153547. cinfo->enable_1pass_quant = TRUE;
  153548. cinfo->enable_external_quant = FALSE;
  153549. cinfo->enable_2pass_quant = FALSE;
  153550. cinfo->colormap = NULL;
  153551. } else if (cinfo->colormap != NULL) {
  153552. cinfo->enable_external_quant = TRUE;
  153553. } else if (cinfo->two_pass_quantize) {
  153554. cinfo->enable_2pass_quant = TRUE;
  153555. } else {
  153556. cinfo->enable_1pass_quant = TRUE;
  153557. }
  153558. if (cinfo->enable_1pass_quant) {
  153559. #ifdef QUANT_1PASS_SUPPORTED
  153560. jinit_1pass_quantizer(cinfo);
  153561. master->quantizer_1pass = cinfo->cquantize;
  153562. #else
  153563. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153564. #endif
  153565. }
  153566. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153567. #ifdef QUANT_2PASS_SUPPORTED
  153568. jinit_2pass_quantizer(cinfo);
  153569. master->quantizer_2pass = cinfo->cquantize;
  153570. #else
  153571. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153572. #endif
  153573. }
  153574. }
  153575. if (! cinfo->raw_data_out) {
  153576. if (master->using_merged_upsample) {
  153577. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153578. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153579. #else
  153580. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153581. #endif
  153582. } else {
  153583. jinit_color_deconverter(cinfo);
  153584. jinit_upsampler(cinfo);
  153585. }
  153586. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153587. }
  153588. jinit_inverse_dct(cinfo);
  153589. if (cinfo->arith_code) {
  153590. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153591. } else {
  153592. if (cinfo->progressive_mode) {
  153593. #ifdef D_PROGRESSIVE_SUPPORTED
  153594. jinit_phuff_decoder(cinfo);
  153595. #else
  153596. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153597. #endif
  153598. } else
  153599. jinit_huff_decoder(cinfo);
  153600. }
  153601. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153602. jinit_d_coef_controller(cinfo, use_c_buffer);
  153603. if (! cinfo->raw_data_out)
  153604. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153605. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153606. (*cinfo->inputctl->start_input_pass) (cinfo);
  153607. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153608. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153609. cinfo->inputctl->has_multiple_scans) {
  153610. int nscans;
  153611. if (cinfo->progressive_mode) {
  153612. nscans = 2 + 3 * cinfo->num_components;
  153613. } else {
  153614. nscans = cinfo->num_components;
  153615. }
  153616. cinfo->progress->pass_counter = 0L;
  153617. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153618. cinfo->progress->completed_passes = 0;
  153619. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153620. master->pass_number++;
  153621. }
  153622. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153623. }
  153624. METHODDEF(void)
  153625. prepare_for_output_pass (j_decompress_ptr cinfo)
  153626. {
  153627. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153628. if (master->pub.is_dummy_pass) {
  153629. #ifdef QUANT_2PASS_SUPPORTED
  153630. master->pub.is_dummy_pass = FALSE;
  153631. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153632. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153633. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153634. #else
  153635. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153636. #endif /* QUANT_2PASS_SUPPORTED */
  153637. } else {
  153638. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153639. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153640. cinfo->cquantize = master->quantizer_2pass;
  153641. master->pub.is_dummy_pass = TRUE;
  153642. } else if (cinfo->enable_1pass_quant) {
  153643. cinfo->cquantize = master->quantizer_1pass;
  153644. } else {
  153645. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153646. }
  153647. }
  153648. (*cinfo->idct->start_pass) (cinfo);
  153649. (*cinfo->coef->start_output_pass) (cinfo);
  153650. if (! cinfo->raw_data_out) {
  153651. if (! master->using_merged_upsample)
  153652. (*cinfo->cconvert->start_pass) (cinfo);
  153653. (*cinfo->upsample->start_pass) (cinfo);
  153654. if (cinfo->quantize_colors)
  153655. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153656. (*cinfo->post->start_pass) (cinfo,
  153657. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153658. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153659. }
  153660. }
  153661. if (cinfo->progress != NULL) {
  153662. cinfo->progress->completed_passes = master->pass_number;
  153663. cinfo->progress->total_passes = master->pass_number +
  153664. (master->pub.is_dummy_pass ? 2 : 1);
  153665. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153666. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153667. }
  153668. }
  153669. }
  153670. METHODDEF(void)
  153671. finish_output_pass (j_decompress_ptr cinfo)
  153672. {
  153673. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153674. if (cinfo->quantize_colors)
  153675. (*cinfo->cquantize->finish_pass) (cinfo);
  153676. master->pass_number++;
  153677. }
  153678. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153679. GLOBAL(void)
  153680. jpeg_new_colormap (j_decompress_ptr cinfo)
  153681. {
  153682. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153683. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153684. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153685. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153686. cinfo->colormap != NULL) {
  153687. cinfo->cquantize = master->quantizer_2pass;
  153688. (*cinfo->cquantize->new_color_map) (cinfo);
  153689. master->pub.is_dummy_pass = FALSE; /* just in case */
  153690. } else
  153691. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153692. }
  153693. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153694. GLOBAL(void)
  153695. jinit_master_decompress (j_decompress_ptr cinfo)
  153696. {
  153697. my_master_ptr6 master;
  153698. master = (my_master_ptr6)
  153699. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153700. SIZEOF(my_decomp_master));
  153701. cinfo->master = (struct jpeg_decomp_master *) master;
  153702. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153703. master->pub.finish_output_pass = finish_output_pass;
  153704. master->pub.is_dummy_pass = FALSE;
  153705. master_selection(cinfo);
  153706. }
  153707. /*** End of inlined file: jdmaster.c ***/
  153708. #undef FIX
  153709. /*** Start of inlined file: jdmerge.c ***/
  153710. #define JPEG_INTERNALS
  153711. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153712. typedef struct {
  153713. struct jpeg_upsampler pub; /* public fields */
  153714. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153715. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153716. JSAMPARRAY output_buf));
  153717. int * Cr_r_tab; /* => table for Cr to R conversion */
  153718. int * Cb_b_tab; /* => table for Cb to B conversion */
  153719. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153720. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153721. JSAMPROW spare_row;
  153722. boolean spare_full; /* T if spare buffer is occupied */
  153723. JDIMENSION out_row_width; /* samples per output row */
  153724. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153725. } my_upsampler;
  153726. typedef my_upsampler * my_upsample_ptr;
  153727. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153728. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153729. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153730. LOCAL(void)
  153731. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153732. {
  153733. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153734. int i;
  153735. INT32 x;
  153736. SHIFT_TEMPS
  153737. upsample->Cr_r_tab = (int *)
  153738. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153739. (MAXJSAMPLE+1) * SIZEOF(int));
  153740. upsample->Cb_b_tab = (int *)
  153741. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153742. (MAXJSAMPLE+1) * SIZEOF(int));
  153743. upsample->Cr_g_tab = (INT32 *)
  153744. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153745. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153746. upsample->Cb_g_tab = (INT32 *)
  153747. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153748. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153749. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153750. upsample->Cr_r_tab[i] = (int)
  153751. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153752. upsample->Cb_b_tab[i] = (int)
  153753. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153754. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153755. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153756. }
  153757. }
  153758. METHODDEF(void)
  153759. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153760. {
  153761. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153762. upsample->spare_full = FALSE;
  153763. upsample->rows_to_go = cinfo->output_height;
  153764. }
  153765. METHODDEF(void)
  153766. merged_2v_upsample (j_decompress_ptr cinfo,
  153767. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153768. JDIMENSION in_row_groups_avail,
  153769. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153770. JDIMENSION out_rows_avail)
  153771. {
  153772. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153773. JSAMPROW work_ptrs[2];
  153774. JDIMENSION num_rows; /* number of rows returned to caller */
  153775. if (upsample->spare_full) {
  153776. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153777. 1, upsample->out_row_width);
  153778. num_rows = 1;
  153779. upsample->spare_full = FALSE;
  153780. } else {
  153781. num_rows = 2;
  153782. if (num_rows > upsample->rows_to_go)
  153783. num_rows = upsample->rows_to_go;
  153784. out_rows_avail -= *out_row_ctr;
  153785. if (num_rows > out_rows_avail)
  153786. num_rows = out_rows_avail;
  153787. work_ptrs[0] = output_buf[*out_row_ctr];
  153788. if (num_rows > 1) {
  153789. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153790. } else {
  153791. work_ptrs[1] = upsample->spare_row;
  153792. upsample->spare_full = TRUE;
  153793. }
  153794. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153795. }
  153796. *out_row_ctr += num_rows;
  153797. upsample->rows_to_go -= num_rows;
  153798. if (! upsample->spare_full)
  153799. (*in_row_group_ctr)++;
  153800. }
  153801. METHODDEF(void)
  153802. merged_1v_upsample (j_decompress_ptr cinfo,
  153803. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153804. JDIMENSION in_row_groups_avail,
  153805. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153806. JDIMENSION out_rows_avail)
  153807. {
  153808. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153809. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153810. output_buf + *out_row_ctr);
  153811. (*out_row_ctr)++;
  153812. (*in_row_group_ctr)++;
  153813. }
  153814. METHODDEF(void)
  153815. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153816. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153817. JSAMPARRAY output_buf)
  153818. {
  153819. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153820. register int y, cred, cgreen, cblue;
  153821. int cb, cr;
  153822. register JSAMPROW outptr;
  153823. JSAMPROW inptr0, inptr1, inptr2;
  153824. JDIMENSION col;
  153825. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153826. int * Crrtab = upsample->Cr_r_tab;
  153827. int * Cbbtab = upsample->Cb_b_tab;
  153828. INT32 * Crgtab = upsample->Cr_g_tab;
  153829. INT32 * Cbgtab = upsample->Cb_g_tab;
  153830. SHIFT_TEMPS
  153831. inptr0 = input_buf[0][in_row_group_ctr];
  153832. inptr1 = input_buf[1][in_row_group_ctr];
  153833. inptr2 = input_buf[2][in_row_group_ctr];
  153834. outptr = output_buf[0];
  153835. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153836. cb = GETJSAMPLE(*inptr1++);
  153837. cr = GETJSAMPLE(*inptr2++);
  153838. cred = Crrtab[cr];
  153839. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153840. cblue = Cbbtab[cb];
  153841. y = GETJSAMPLE(*inptr0++);
  153842. outptr[RGB_RED] = range_limit[y + cred];
  153843. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153844. outptr[RGB_BLUE] = range_limit[y + cblue];
  153845. outptr += RGB_PIXELSIZE;
  153846. y = GETJSAMPLE(*inptr0++);
  153847. outptr[RGB_RED] = range_limit[y + cred];
  153848. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153849. outptr[RGB_BLUE] = range_limit[y + cblue];
  153850. outptr += RGB_PIXELSIZE;
  153851. }
  153852. if (cinfo->output_width & 1) {
  153853. cb = GETJSAMPLE(*inptr1);
  153854. cr = GETJSAMPLE(*inptr2);
  153855. cred = Crrtab[cr];
  153856. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153857. cblue = Cbbtab[cb];
  153858. y = GETJSAMPLE(*inptr0);
  153859. outptr[RGB_RED] = range_limit[y + cred];
  153860. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153861. outptr[RGB_BLUE] = range_limit[y + cblue];
  153862. }
  153863. }
  153864. METHODDEF(void)
  153865. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153866. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153867. JSAMPARRAY output_buf)
  153868. {
  153869. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153870. register int y, cred, cgreen, cblue;
  153871. int cb, cr;
  153872. register JSAMPROW outptr0, outptr1;
  153873. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153874. JDIMENSION col;
  153875. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153876. int * Crrtab = upsample->Cr_r_tab;
  153877. int * Cbbtab = upsample->Cb_b_tab;
  153878. INT32 * Crgtab = upsample->Cr_g_tab;
  153879. INT32 * Cbgtab = upsample->Cb_g_tab;
  153880. SHIFT_TEMPS
  153881. inptr00 = input_buf[0][in_row_group_ctr*2];
  153882. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153883. inptr1 = input_buf[1][in_row_group_ctr];
  153884. inptr2 = input_buf[2][in_row_group_ctr];
  153885. outptr0 = output_buf[0];
  153886. outptr1 = output_buf[1];
  153887. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153888. cb = GETJSAMPLE(*inptr1++);
  153889. cr = GETJSAMPLE(*inptr2++);
  153890. cred = Crrtab[cr];
  153891. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153892. cblue = Cbbtab[cb];
  153893. y = GETJSAMPLE(*inptr00++);
  153894. outptr0[RGB_RED] = range_limit[y + cred];
  153895. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153896. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153897. outptr0 += RGB_PIXELSIZE;
  153898. y = GETJSAMPLE(*inptr00++);
  153899. outptr0[RGB_RED] = range_limit[y + cred];
  153900. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153901. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153902. outptr0 += RGB_PIXELSIZE;
  153903. y = GETJSAMPLE(*inptr01++);
  153904. outptr1[RGB_RED] = range_limit[y + cred];
  153905. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153906. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153907. outptr1 += RGB_PIXELSIZE;
  153908. y = GETJSAMPLE(*inptr01++);
  153909. outptr1[RGB_RED] = range_limit[y + cred];
  153910. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153911. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153912. outptr1 += RGB_PIXELSIZE;
  153913. }
  153914. if (cinfo->output_width & 1) {
  153915. cb = GETJSAMPLE(*inptr1);
  153916. cr = GETJSAMPLE(*inptr2);
  153917. cred = Crrtab[cr];
  153918. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153919. cblue = Cbbtab[cb];
  153920. y = GETJSAMPLE(*inptr00);
  153921. outptr0[RGB_RED] = range_limit[y + cred];
  153922. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153923. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153924. y = GETJSAMPLE(*inptr01);
  153925. outptr1[RGB_RED] = range_limit[y + cred];
  153926. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153927. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153928. }
  153929. }
  153930. GLOBAL(void)
  153931. jinit_merged_upsampler (j_decompress_ptr cinfo)
  153932. {
  153933. my_upsample_ptr upsample;
  153934. upsample = (my_upsample_ptr)
  153935. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153936. SIZEOF(my_upsampler));
  153937. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  153938. upsample->pub.start_pass = start_pass_merged_upsample;
  153939. upsample->pub.need_context_rows = FALSE;
  153940. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  153941. if (cinfo->max_v_samp_factor == 2) {
  153942. upsample->pub.upsample = merged_2v_upsample;
  153943. upsample->upmethod = h2v2_merged_upsample;
  153944. upsample->spare_row = (JSAMPROW)
  153945. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153946. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  153947. } else {
  153948. upsample->pub.upsample = merged_1v_upsample;
  153949. upsample->upmethod = h2v1_merged_upsample;
  153950. upsample->spare_row = NULL;
  153951. }
  153952. build_ycc_rgb_table2(cinfo);
  153953. }
  153954. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  153955. /*** End of inlined file: jdmerge.c ***/
  153956. #undef ASSIGN_STATE
  153957. /*** Start of inlined file: jdphuff.c ***/
  153958. #define JPEG_INTERNALS
  153959. #ifdef D_PROGRESSIVE_SUPPORTED
  153960. typedef struct {
  153961. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  153962. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  153963. } savable_state3;
  153964. #ifndef NO_STRUCT_ASSIGN
  153965. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  153966. #else
  153967. #if MAX_COMPS_IN_SCAN == 4
  153968. #define ASSIGN_STATE(dest,src) \
  153969. ((dest).EOBRUN = (src).EOBRUN, \
  153970. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  153971. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  153972. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  153973. (dest).last_dc_val[3] = (src).last_dc_val[3])
  153974. #endif
  153975. #endif
  153976. typedef struct {
  153977. struct jpeg_entropy_decoder pub; /* public fields */
  153978. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  153979. savable_state3 saved; /* Other state at start of MCU */
  153980. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  153981. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  153982. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  153983. } phuff_entropy_decoder;
  153984. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  153985. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  153986. JBLOCKROW *MCU_data));
  153987. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  153988. JBLOCKROW *MCU_data));
  153989. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  153990. JBLOCKROW *MCU_data));
  153991. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  153992. JBLOCKROW *MCU_data));
  153993. METHODDEF(void)
  153994. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  153995. {
  153996. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153997. boolean is_DC_band, bad;
  153998. int ci, coefi, tbl;
  153999. int *coef_bit_ptr;
  154000. jpeg_component_info * compptr;
  154001. is_DC_band = (cinfo->Ss == 0);
  154002. bad = FALSE;
  154003. if (is_DC_band) {
  154004. if (cinfo->Se != 0)
  154005. bad = TRUE;
  154006. } else {
  154007. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154008. bad = TRUE;
  154009. if (cinfo->comps_in_scan != 1)
  154010. bad = TRUE;
  154011. }
  154012. if (cinfo->Ah != 0) {
  154013. if (cinfo->Al != cinfo->Ah-1)
  154014. bad = TRUE;
  154015. }
  154016. if (cinfo->Al > 13) /* need not check for < 0 */
  154017. bad = TRUE;
  154018. if (bad)
  154019. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154020. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154021. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154022. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154023. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154024. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154025. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154026. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154027. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154028. if (cinfo->Ah != expected)
  154029. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154030. coef_bit_ptr[coefi] = cinfo->Al;
  154031. }
  154032. }
  154033. if (cinfo->Ah == 0) {
  154034. if (is_DC_band)
  154035. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154036. else
  154037. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154038. } else {
  154039. if (is_DC_band)
  154040. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154041. else
  154042. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154043. }
  154044. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154045. compptr = cinfo->cur_comp_info[ci];
  154046. if (is_DC_band) {
  154047. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154048. tbl = compptr->dc_tbl_no;
  154049. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154050. & entropy->derived_tbls[tbl]);
  154051. }
  154052. } else {
  154053. tbl = compptr->ac_tbl_no;
  154054. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154055. & entropy->derived_tbls[tbl]);
  154056. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154057. }
  154058. entropy->saved.last_dc_val[ci] = 0;
  154059. }
  154060. entropy->bitstate.bits_left = 0;
  154061. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154062. entropy->pub.insufficient_data = FALSE;
  154063. entropy->saved.EOBRUN = 0;
  154064. entropy->restarts_to_go = cinfo->restart_interval;
  154065. }
  154066. LOCAL(boolean)
  154067. process_restartp (j_decompress_ptr cinfo)
  154068. {
  154069. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154070. int ci;
  154071. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154072. entropy->bitstate.bits_left = 0;
  154073. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154074. return FALSE;
  154075. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154076. entropy->saved.last_dc_val[ci] = 0;
  154077. entropy->saved.EOBRUN = 0;
  154078. entropy->restarts_to_go = cinfo->restart_interval;
  154079. if (cinfo->unread_marker == 0)
  154080. entropy->pub.insufficient_data = FALSE;
  154081. return TRUE;
  154082. }
  154083. METHODDEF(boolean)
  154084. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154085. {
  154086. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154087. int Al = cinfo->Al;
  154088. register int s, r;
  154089. int blkn, ci;
  154090. JBLOCKROW block;
  154091. BITREAD_STATE_VARS;
  154092. savable_state3 state;
  154093. d_derived_tbl * tbl;
  154094. jpeg_component_info * compptr;
  154095. if (cinfo->restart_interval) {
  154096. if (entropy->restarts_to_go == 0)
  154097. if (! process_restartp(cinfo))
  154098. return FALSE;
  154099. }
  154100. if (! entropy->pub.insufficient_data) {
  154101. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154102. ASSIGN_STATE(state, entropy->saved);
  154103. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154104. block = MCU_data[blkn];
  154105. ci = cinfo->MCU_membership[blkn];
  154106. compptr = cinfo->cur_comp_info[ci];
  154107. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154108. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154109. if (s) {
  154110. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154111. r = GET_BITS(s);
  154112. s = HUFF_EXTEND(r, s);
  154113. }
  154114. s += state.last_dc_val[ci];
  154115. state.last_dc_val[ci] = s;
  154116. (*block)[0] = (JCOEF) (s << Al);
  154117. }
  154118. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154119. ASSIGN_STATE(entropy->saved, state);
  154120. }
  154121. entropy->restarts_to_go--;
  154122. return TRUE;
  154123. }
  154124. METHODDEF(boolean)
  154125. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154126. {
  154127. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154128. int Se = cinfo->Se;
  154129. int Al = cinfo->Al;
  154130. register int s, k, r;
  154131. unsigned int EOBRUN;
  154132. JBLOCKROW block;
  154133. BITREAD_STATE_VARS;
  154134. d_derived_tbl * tbl;
  154135. if (cinfo->restart_interval) {
  154136. if (entropy->restarts_to_go == 0)
  154137. if (! process_restartp(cinfo))
  154138. return FALSE;
  154139. }
  154140. if (! entropy->pub.insufficient_data) {
  154141. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154142. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154143. EOBRUN--; /* ...process it now (we do nothing) */
  154144. else {
  154145. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154146. block = MCU_data[0];
  154147. tbl = entropy->ac_derived_tbl;
  154148. for (k = cinfo->Ss; k <= Se; k++) {
  154149. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154150. r = s >> 4;
  154151. s &= 15;
  154152. if (s) {
  154153. k += r;
  154154. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154155. r = GET_BITS(s);
  154156. s = HUFF_EXTEND(r, s);
  154157. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154158. } else {
  154159. if (r == 15) { /* ZRL */
  154160. k += 15; /* skip 15 zeroes in band */
  154161. } else { /* EOBr, run length is 2^r + appended bits */
  154162. EOBRUN = 1 << r;
  154163. if (r) { /* EOBr, r > 0 */
  154164. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154165. r = GET_BITS(r);
  154166. EOBRUN += r;
  154167. }
  154168. EOBRUN--; /* this band is processed at this moment */
  154169. break; /* force end-of-band */
  154170. }
  154171. }
  154172. }
  154173. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154174. }
  154175. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154176. }
  154177. entropy->restarts_to_go--;
  154178. return TRUE;
  154179. }
  154180. METHODDEF(boolean)
  154181. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154182. {
  154183. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154184. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154185. int blkn;
  154186. JBLOCKROW block;
  154187. BITREAD_STATE_VARS;
  154188. if (cinfo->restart_interval) {
  154189. if (entropy->restarts_to_go == 0)
  154190. if (! process_restartp(cinfo))
  154191. return FALSE;
  154192. }
  154193. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154194. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154195. block = MCU_data[blkn];
  154196. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154197. if (GET_BITS(1))
  154198. (*block)[0] |= p1;
  154199. }
  154200. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154201. entropy->restarts_to_go--;
  154202. return TRUE;
  154203. }
  154204. METHODDEF(boolean)
  154205. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154206. {
  154207. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154208. int Se = cinfo->Se;
  154209. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154210. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154211. register int s, k, r;
  154212. unsigned int EOBRUN;
  154213. JBLOCKROW block;
  154214. JCOEFPTR thiscoef;
  154215. BITREAD_STATE_VARS;
  154216. d_derived_tbl * tbl;
  154217. int num_newnz;
  154218. int newnz_pos[DCTSIZE2];
  154219. if (cinfo->restart_interval) {
  154220. if (entropy->restarts_to_go == 0)
  154221. if (! process_restartp(cinfo))
  154222. return FALSE;
  154223. }
  154224. if (! entropy->pub.insufficient_data) {
  154225. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154226. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154227. block = MCU_data[0];
  154228. tbl = entropy->ac_derived_tbl;
  154229. num_newnz = 0;
  154230. k = cinfo->Ss;
  154231. if (EOBRUN == 0) {
  154232. for (; k <= Se; k++) {
  154233. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154234. r = s >> 4;
  154235. s &= 15;
  154236. if (s) {
  154237. if (s != 1) /* size of new coef should always be 1 */
  154238. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154239. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154240. if (GET_BITS(1))
  154241. s = p1; /* newly nonzero coef is positive */
  154242. else
  154243. s = m1; /* newly nonzero coef is negative */
  154244. } else {
  154245. if (r != 15) {
  154246. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154247. if (r) {
  154248. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154249. r = GET_BITS(r);
  154250. EOBRUN += r;
  154251. }
  154252. break; /* rest of block is handled by EOB logic */
  154253. }
  154254. }
  154255. do {
  154256. thiscoef = *block + jpeg_natural_order[k];
  154257. if (*thiscoef != 0) {
  154258. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154259. if (GET_BITS(1)) {
  154260. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154261. if (*thiscoef >= 0)
  154262. *thiscoef += p1;
  154263. else
  154264. *thiscoef += m1;
  154265. }
  154266. }
  154267. } else {
  154268. if (--r < 0)
  154269. break; /* reached target zero coefficient */
  154270. }
  154271. k++;
  154272. } while (k <= Se);
  154273. if (s) {
  154274. int pos = jpeg_natural_order[k];
  154275. (*block)[pos] = (JCOEF) s;
  154276. newnz_pos[num_newnz++] = pos;
  154277. }
  154278. }
  154279. }
  154280. if (EOBRUN > 0) {
  154281. for (; k <= Se; k++) {
  154282. thiscoef = *block + jpeg_natural_order[k];
  154283. if (*thiscoef != 0) {
  154284. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154285. if (GET_BITS(1)) {
  154286. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154287. if (*thiscoef >= 0)
  154288. *thiscoef += p1;
  154289. else
  154290. *thiscoef += m1;
  154291. }
  154292. }
  154293. }
  154294. }
  154295. EOBRUN--;
  154296. }
  154297. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154298. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154299. }
  154300. entropy->restarts_to_go--;
  154301. return TRUE;
  154302. undoit:
  154303. while (num_newnz > 0)
  154304. (*block)[newnz_pos[--num_newnz]] = 0;
  154305. return FALSE;
  154306. }
  154307. GLOBAL(void)
  154308. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154309. {
  154310. phuff_entropy_ptr2 entropy;
  154311. int *coef_bit_ptr;
  154312. int ci, i;
  154313. entropy = (phuff_entropy_ptr2)
  154314. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154315. SIZEOF(phuff_entropy_decoder));
  154316. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154317. entropy->pub.start_pass = start_pass_phuff_decoder;
  154318. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154319. entropy->derived_tbls[i] = NULL;
  154320. }
  154321. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154322. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154323. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154324. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154325. for (ci = 0; ci < cinfo->num_components; ci++)
  154326. for (i = 0; i < DCTSIZE2; i++)
  154327. *coef_bit_ptr++ = -1;
  154328. }
  154329. #endif /* D_PROGRESSIVE_SUPPORTED */
  154330. /*** End of inlined file: jdphuff.c ***/
  154331. /*** Start of inlined file: jdpostct.c ***/
  154332. #define JPEG_INTERNALS
  154333. typedef struct {
  154334. struct jpeg_d_post_controller pub; /* public fields */
  154335. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154336. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154337. JDIMENSION strip_height; /* buffer size in rows */
  154338. JDIMENSION starting_row; /* row # of first row in current strip */
  154339. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154340. } my_post_controller;
  154341. typedef my_post_controller * my_post_ptr;
  154342. METHODDEF(void) post_process_1pass
  154343. JPP((j_decompress_ptr cinfo,
  154344. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154345. JDIMENSION in_row_groups_avail,
  154346. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154347. JDIMENSION out_rows_avail));
  154348. #ifdef QUANT_2PASS_SUPPORTED
  154349. METHODDEF(void) post_process_prepass
  154350. JPP((j_decompress_ptr cinfo,
  154351. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154352. JDIMENSION in_row_groups_avail,
  154353. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154354. JDIMENSION out_rows_avail));
  154355. METHODDEF(void) post_process_2pass
  154356. JPP((j_decompress_ptr cinfo,
  154357. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154358. JDIMENSION in_row_groups_avail,
  154359. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154360. JDIMENSION out_rows_avail));
  154361. #endif
  154362. METHODDEF(void)
  154363. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154364. {
  154365. my_post_ptr post = (my_post_ptr) cinfo->post;
  154366. switch (pass_mode) {
  154367. case JBUF_PASS_THRU:
  154368. if (cinfo->quantize_colors) {
  154369. post->pub.post_process_data = post_process_1pass;
  154370. if (post->buffer == NULL) {
  154371. post->buffer = (*cinfo->mem->access_virt_sarray)
  154372. ((j_common_ptr) cinfo, post->whole_image,
  154373. (JDIMENSION) 0, post->strip_height, TRUE);
  154374. }
  154375. } else {
  154376. post->pub.post_process_data = cinfo->upsample->upsample;
  154377. }
  154378. break;
  154379. #ifdef QUANT_2PASS_SUPPORTED
  154380. case JBUF_SAVE_AND_PASS:
  154381. if (post->whole_image == NULL)
  154382. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154383. post->pub.post_process_data = post_process_prepass;
  154384. break;
  154385. case JBUF_CRANK_DEST:
  154386. if (post->whole_image == NULL)
  154387. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154388. post->pub.post_process_data = post_process_2pass;
  154389. break;
  154390. #endif /* QUANT_2PASS_SUPPORTED */
  154391. default:
  154392. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154393. break;
  154394. }
  154395. post->starting_row = post->next_row = 0;
  154396. }
  154397. METHODDEF(void)
  154398. post_process_1pass (j_decompress_ptr cinfo,
  154399. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154400. JDIMENSION in_row_groups_avail,
  154401. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154402. JDIMENSION out_rows_avail)
  154403. {
  154404. my_post_ptr post = (my_post_ptr) cinfo->post;
  154405. JDIMENSION num_rows, max_rows;
  154406. max_rows = out_rows_avail - *out_row_ctr;
  154407. if (max_rows > post->strip_height)
  154408. max_rows = post->strip_height;
  154409. num_rows = 0;
  154410. (*cinfo->upsample->upsample) (cinfo,
  154411. input_buf, in_row_group_ctr, in_row_groups_avail,
  154412. post->buffer, &num_rows, max_rows);
  154413. (*cinfo->cquantize->color_quantize) (cinfo,
  154414. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154415. *out_row_ctr += num_rows;
  154416. }
  154417. #ifdef QUANT_2PASS_SUPPORTED
  154418. METHODDEF(void)
  154419. post_process_prepass (j_decompress_ptr cinfo,
  154420. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154421. JDIMENSION in_row_groups_avail,
  154422. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154423. JDIMENSION out_rows_avail)
  154424. {
  154425. my_post_ptr post = (my_post_ptr) cinfo->post;
  154426. JDIMENSION old_next_row, num_rows;
  154427. if (post->next_row == 0) {
  154428. post->buffer = (*cinfo->mem->access_virt_sarray)
  154429. ((j_common_ptr) cinfo, post->whole_image,
  154430. post->starting_row, post->strip_height, TRUE);
  154431. }
  154432. old_next_row = post->next_row;
  154433. (*cinfo->upsample->upsample) (cinfo,
  154434. input_buf, in_row_group_ctr, in_row_groups_avail,
  154435. post->buffer, &post->next_row, post->strip_height);
  154436. if (post->next_row > old_next_row) {
  154437. num_rows = post->next_row - old_next_row;
  154438. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154439. (JSAMPARRAY) NULL, (int) num_rows);
  154440. *out_row_ctr += num_rows;
  154441. }
  154442. if (post->next_row >= post->strip_height) {
  154443. post->starting_row += post->strip_height;
  154444. post->next_row = 0;
  154445. }
  154446. }
  154447. METHODDEF(void)
  154448. post_process_2pass (j_decompress_ptr cinfo,
  154449. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154450. JDIMENSION in_row_groups_avail,
  154451. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154452. JDIMENSION out_rows_avail)
  154453. {
  154454. my_post_ptr post = (my_post_ptr) cinfo->post;
  154455. JDIMENSION num_rows, max_rows;
  154456. if (post->next_row == 0) {
  154457. post->buffer = (*cinfo->mem->access_virt_sarray)
  154458. ((j_common_ptr) cinfo, post->whole_image,
  154459. post->starting_row, post->strip_height, FALSE);
  154460. }
  154461. num_rows = post->strip_height - post->next_row; /* available in strip */
  154462. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154463. if (num_rows > max_rows)
  154464. num_rows = max_rows;
  154465. max_rows = cinfo->output_height - post->starting_row;
  154466. if (num_rows > max_rows)
  154467. num_rows = max_rows;
  154468. (*cinfo->cquantize->color_quantize) (cinfo,
  154469. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154470. (int) num_rows);
  154471. *out_row_ctr += num_rows;
  154472. post->next_row += num_rows;
  154473. if (post->next_row >= post->strip_height) {
  154474. post->starting_row += post->strip_height;
  154475. post->next_row = 0;
  154476. }
  154477. }
  154478. #endif /* QUANT_2PASS_SUPPORTED */
  154479. GLOBAL(void)
  154480. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154481. {
  154482. my_post_ptr post;
  154483. post = (my_post_ptr)
  154484. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154485. SIZEOF(my_post_controller));
  154486. cinfo->post = (struct jpeg_d_post_controller *) post;
  154487. post->pub.start_pass = start_pass_dpost;
  154488. post->whole_image = NULL; /* flag for no virtual arrays */
  154489. post->buffer = NULL; /* flag for no strip buffer */
  154490. if (cinfo->quantize_colors) {
  154491. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154492. if (need_full_buffer) {
  154493. #ifdef QUANT_2PASS_SUPPORTED
  154494. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154495. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154496. cinfo->output_width * cinfo->out_color_components,
  154497. (JDIMENSION) jround_up((long) cinfo->output_height,
  154498. (long) post->strip_height),
  154499. post->strip_height);
  154500. #else
  154501. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154502. #endif /* QUANT_2PASS_SUPPORTED */
  154503. } else {
  154504. post->buffer = (*cinfo->mem->alloc_sarray)
  154505. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154506. cinfo->output_width * cinfo->out_color_components,
  154507. post->strip_height);
  154508. }
  154509. }
  154510. }
  154511. /*** End of inlined file: jdpostct.c ***/
  154512. #undef FIX
  154513. /*** Start of inlined file: jdsample.c ***/
  154514. #define JPEG_INTERNALS
  154515. typedef JMETHOD(void, upsample1_ptr,
  154516. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154517. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154518. typedef struct {
  154519. struct jpeg_upsampler pub; /* public fields */
  154520. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154521. upsample1_ptr methods[MAX_COMPONENTS];
  154522. int next_row_out; /* counts rows emitted from color_buf */
  154523. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154524. int rowgroup_height[MAX_COMPONENTS];
  154525. UINT8 h_expand[MAX_COMPONENTS];
  154526. UINT8 v_expand[MAX_COMPONENTS];
  154527. } my_upsampler2;
  154528. typedef my_upsampler2 * my_upsample_ptr2;
  154529. METHODDEF(void)
  154530. start_pass_upsample (j_decompress_ptr cinfo)
  154531. {
  154532. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154533. upsample->next_row_out = cinfo->max_v_samp_factor;
  154534. upsample->rows_to_go = cinfo->output_height;
  154535. }
  154536. METHODDEF(void)
  154537. sep_upsample (j_decompress_ptr cinfo,
  154538. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154539. JDIMENSION in_row_groups_avail,
  154540. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154541. JDIMENSION out_rows_avail)
  154542. {
  154543. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154544. int ci;
  154545. jpeg_component_info * compptr;
  154546. JDIMENSION num_rows;
  154547. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154548. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154549. ci++, compptr++) {
  154550. (*upsample->methods[ci]) (cinfo, compptr,
  154551. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154552. upsample->color_buf + ci);
  154553. }
  154554. upsample->next_row_out = 0;
  154555. }
  154556. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154557. if (num_rows > upsample->rows_to_go)
  154558. num_rows = upsample->rows_to_go;
  154559. out_rows_avail -= *out_row_ctr;
  154560. if (num_rows > out_rows_avail)
  154561. num_rows = out_rows_avail;
  154562. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154563. (JDIMENSION) upsample->next_row_out,
  154564. output_buf + *out_row_ctr,
  154565. (int) num_rows);
  154566. *out_row_ctr += num_rows;
  154567. upsample->rows_to_go -= num_rows;
  154568. upsample->next_row_out += num_rows;
  154569. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154570. (*in_row_group_ctr)++;
  154571. }
  154572. METHODDEF(void)
  154573. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154574. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154575. {
  154576. *output_data_ptr = input_data;
  154577. }
  154578. METHODDEF(void)
  154579. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154580. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154581. {
  154582. *output_data_ptr = NULL; /* safety check */
  154583. }
  154584. METHODDEF(void)
  154585. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154586. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154587. {
  154588. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154589. JSAMPARRAY output_data = *output_data_ptr;
  154590. register JSAMPROW inptr, outptr;
  154591. register JSAMPLE invalue;
  154592. register int h;
  154593. JSAMPROW outend;
  154594. int h_expand, v_expand;
  154595. int inrow, outrow;
  154596. h_expand = upsample->h_expand[compptr->component_index];
  154597. v_expand = upsample->v_expand[compptr->component_index];
  154598. inrow = outrow = 0;
  154599. while (outrow < cinfo->max_v_samp_factor) {
  154600. inptr = input_data[inrow];
  154601. outptr = output_data[outrow];
  154602. outend = outptr + cinfo->output_width;
  154603. while (outptr < outend) {
  154604. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154605. for (h = h_expand; h > 0; h--) {
  154606. *outptr++ = invalue;
  154607. }
  154608. }
  154609. if (v_expand > 1) {
  154610. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154611. v_expand-1, cinfo->output_width);
  154612. }
  154613. inrow++;
  154614. outrow += v_expand;
  154615. }
  154616. }
  154617. METHODDEF(void)
  154618. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154619. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154620. {
  154621. JSAMPARRAY output_data = *output_data_ptr;
  154622. register JSAMPROW inptr, outptr;
  154623. register JSAMPLE invalue;
  154624. JSAMPROW outend;
  154625. int inrow;
  154626. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154627. inptr = input_data[inrow];
  154628. outptr = output_data[inrow];
  154629. outend = outptr + cinfo->output_width;
  154630. while (outptr < outend) {
  154631. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154632. *outptr++ = invalue;
  154633. *outptr++ = invalue;
  154634. }
  154635. }
  154636. }
  154637. METHODDEF(void)
  154638. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154639. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154640. {
  154641. JSAMPARRAY output_data = *output_data_ptr;
  154642. register JSAMPROW inptr, outptr;
  154643. register JSAMPLE invalue;
  154644. JSAMPROW outend;
  154645. int inrow, outrow;
  154646. inrow = outrow = 0;
  154647. while (outrow < cinfo->max_v_samp_factor) {
  154648. inptr = input_data[inrow];
  154649. outptr = output_data[outrow];
  154650. outend = outptr + cinfo->output_width;
  154651. while (outptr < outend) {
  154652. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154653. *outptr++ = invalue;
  154654. *outptr++ = invalue;
  154655. }
  154656. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154657. 1, cinfo->output_width);
  154658. inrow++;
  154659. outrow += 2;
  154660. }
  154661. }
  154662. METHODDEF(void)
  154663. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154664. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154665. {
  154666. JSAMPARRAY output_data = *output_data_ptr;
  154667. register JSAMPROW inptr, outptr;
  154668. register int invalue;
  154669. register JDIMENSION colctr;
  154670. int inrow;
  154671. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154672. inptr = input_data[inrow];
  154673. outptr = output_data[inrow];
  154674. invalue = GETJSAMPLE(*inptr++);
  154675. *outptr++ = (JSAMPLE) invalue;
  154676. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154677. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154678. invalue = GETJSAMPLE(*inptr++) * 3;
  154679. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154680. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154681. }
  154682. invalue = GETJSAMPLE(*inptr);
  154683. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154684. *outptr++ = (JSAMPLE) invalue;
  154685. }
  154686. }
  154687. METHODDEF(void)
  154688. h2v2_fancy_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 inptr0, inptr1, outptr;
  154693. #if BITS_IN_JSAMPLE == 8
  154694. register int thiscolsum, lastcolsum, nextcolsum;
  154695. #else
  154696. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154697. #endif
  154698. register JDIMENSION colctr;
  154699. int inrow, outrow, v;
  154700. inrow = outrow = 0;
  154701. while (outrow < cinfo->max_v_samp_factor) {
  154702. for (v = 0; v < 2; v++) {
  154703. inptr0 = input_data[inrow];
  154704. if (v == 0) /* next nearest is row above */
  154705. inptr1 = input_data[inrow-1];
  154706. else /* next nearest is row below */
  154707. inptr1 = input_data[inrow+1];
  154708. outptr = output_data[outrow++];
  154709. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154710. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154711. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154712. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154713. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154714. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154715. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154716. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154717. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154718. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154719. }
  154720. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154721. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154722. }
  154723. inrow++;
  154724. }
  154725. }
  154726. GLOBAL(void)
  154727. jinit_upsampler (j_decompress_ptr cinfo)
  154728. {
  154729. my_upsample_ptr2 upsample;
  154730. int ci;
  154731. jpeg_component_info * compptr;
  154732. boolean need_buffer, do_fancy;
  154733. int h_in_group, v_in_group, h_out_group, v_out_group;
  154734. upsample = (my_upsample_ptr2)
  154735. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154736. SIZEOF(my_upsampler2));
  154737. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154738. upsample->pub.start_pass = start_pass_upsample;
  154739. upsample->pub.upsample = sep_upsample;
  154740. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154741. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154742. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154743. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154744. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154745. ci++, compptr++) {
  154746. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154747. cinfo->min_DCT_scaled_size;
  154748. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154749. cinfo->min_DCT_scaled_size;
  154750. h_out_group = cinfo->max_h_samp_factor;
  154751. v_out_group = cinfo->max_v_samp_factor;
  154752. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154753. need_buffer = TRUE;
  154754. if (! compptr->component_needed) {
  154755. upsample->methods[ci] = noop_upsample;
  154756. need_buffer = FALSE;
  154757. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154758. upsample->methods[ci] = fullsize_upsample;
  154759. need_buffer = FALSE;
  154760. } else if (h_in_group * 2 == h_out_group &&
  154761. v_in_group == v_out_group) {
  154762. if (do_fancy && compptr->downsampled_width > 2)
  154763. upsample->methods[ci] = h2v1_fancy_upsample;
  154764. else
  154765. upsample->methods[ci] = h2v1_upsample;
  154766. } else if (h_in_group * 2 == h_out_group &&
  154767. v_in_group * 2 == v_out_group) {
  154768. if (do_fancy && compptr->downsampled_width > 2) {
  154769. upsample->methods[ci] = h2v2_fancy_upsample;
  154770. upsample->pub.need_context_rows = TRUE;
  154771. } else
  154772. upsample->methods[ci] = h2v2_upsample;
  154773. } else if ((h_out_group % h_in_group) == 0 &&
  154774. (v_out_group % v_in_group) == 0) {
  154775. upsample->methods[ci] = int_upsample;
  154776. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154777. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154778. } else
  154779. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154780. if (need_buffer) {
  154781. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154782. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154783. (JDIMENSION) jround_up((long) cinfo->output_width,
  154784. (long) cinfo->max_h_samp_factor),
  154785. (JDIMENSION) cinfo->max_v_samp_factor);
  154786. }
  154787. }
  154788. }
  154789. /*** End of inlined file: jdsample.c ***/
  154790. /*** Start of inlined file: jdtrans.c ***/
  154791. #define JPEG_INTERNALS
  154792. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154793. GLOBAL(jvirt_barray_ptr *)
  154794. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154795. {
  154796. if (cinfo->global_state == DSTATE_READY) {
  154797. transdecode_master_selection(cinfo);
  154798. cinfo->global_state = DSTATE_RDCOEFS;
  154799. }
  154800. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154801. for (;;) {
  154802. int retcode;
  154803. if (cinfo->progress != NULL)
  154804. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154805. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154806. if (retcode == JPEG_SUSPENDED)
  154807. return NULL;
  154808. if (retcode == JPEG_REACHED_EOI)
  154809. break;
  154810. if (cinfo->progress != NULL &&
  154811. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154812. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154813. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154814. }
  154815. }
  154816. }
  154817. cinfo->global_state = DSTATE_STOPPING;
  154818. }
  154819. if ((cinfo->global_state == DSTATE_STOPPING ||
  154820. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154821. return cinfo->coef->coef_arrays;
  154822. }
  154823. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154824. return NULL; /* keep compiler happy */
  154825. }
  154826. LOCAL(void)
  154827. transdecode_master_selection (j_decompress_ptr cinfo)
  154828. {
  154829. cinfo->buffered_image = TRUE;
  154830. if (cinfo->arith_code) {
  154831. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154832. } else {
  154833. if (cinfo->progressive_mode) {
  154834. #ifdef D_PROGRESSIVE_SUPPORTED
  154835. jinit_phuff_decoder(cinfo);
  154836. #else
  154837. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154838. #endif
  154839. } else
  154840. jinit_huff_decoder(cinfo);
  154841. }
  154842. jinit_d_coef_controller(cinfo, TRUE);
  154843. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154844. (*cinfo->inputctl->start_input_pass) (cinfo);
  154845. if (cinfo->progress != NULL) {
  154846. int nscans;
  154847. if (cinfo->progressive_mode) {
  154848. nscans = 2 + 3 * cinfo->num_components;
  154849. } else if (cinfo->inputctl->has_multiple_scans) {
  154850. nscans = cinfo->num_components;
  154851. } else {
  154852. nscans = 1;
  154853. }
  154854. cinfo->progress->pass_counter = 0L;
  154855. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154856. cinfo->progress->completed_passes = 0;
  154857. cinfo->progress->total_passes = 1;
  154858. }
  154859. }
  154860. /*** End of inlined file: jdtrans.c ***/
  154861. /*** Start of inlined file: jfdctflt.c ***/
  154862. #define JPEG_INTERNALS
  154863. #ifdef DCT_FLOAT_SUPPORTED
  154864. #if DCTSIZE != 8
  154865. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154866. #endif
  154867. GLOBAL(void)
  154868. jpeg_fdct_float (FAST_FLOAT * data)
  154869. {
  154870. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154871. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154872. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154873. FAST_FLOAT *dataptr;
  154874. int ctr;
  154875. dataptr = data;
  154876. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154877. tmp0 = dataptr[0] + dataptr[7];
  154878. tmp7 = dataptr[0] - dataptr[7];
  154879. tmp1 = dataptr[1] + dataptr[6];
  154880. tmp6 = dataptr[1] - dataptr[6];
  154881. tmp2 = dataptr[2] + dataptr[5];
  154882. tmp5 = dataptr[2] - dataptr[5];
  154883. tmp3 = dataptr[3] + dataptr[4];
  154884. tmp4 = dataptr[3] - dataptr[4];
  154885. tmp10 = tmp0 + tmp3; /* phase 2 */
  154886. tmp13 = tmp0 - tmp3;
  154887. tmp11 = tmp1 + tmp2;
  154888. tmp12 = tmp1 - tmp2;
  154889. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154890. dataptr[4] = tmp10 - tmp11;
  154891. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154892. dataptr[2] = tmp13 + z1; /* phase 5 */
  154893. dataptr[6] = tmp13 - z1;
  154894. tmp10 = tmp4 + tmp5; /* phase 2 */
  154895. tmp11 = tmp5 + tmp6;
  154896. tmp12 = tmp6 + tmp7;
  154897. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154898. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154899. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154900. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154901. z11 = tmp7 + z3; /* phase 5 */
  154902. z13 = tmp7 - z3;
  154903. dataptr[5] = z13 + z2; /* phase 6 */
  154904. dataptr[3] = z13 - z2;
  154905. dataptr[1] = z11 + z4;
  154906. dataptr[7] = z11 - z4;
  154907. dataptr += DCTSIZE; /* advance pointer to next row */
  154908. }
  154909. dataptr = data;
  154910. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154911. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154912. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154913. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154914. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154915. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154916. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154917. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154918. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154919. tmp10 = tmp0 + tmp3; /* phase 2 */
  154920. tmp13 = tmp0 - tmp3;
  154921. tmp11 = tmp1 + tmp2;
  154922. tmp12 = tmp1 - tmp2;
  154923. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154924. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154925. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154926. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154927. dataptr[DCTSIZE*6] = tmp13 - z1;
  154928. tmp10 = tmp4 + tmp5; /* phase 2 */
  154929. tmp11 = tmp5 + tmp6;
  154930. tmp12 = tmp6 + tmp7;
  154931. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154932. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154933. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154934. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154935. z11 = tmp7 + z3; /* phase 5 */
  154936. z13 = tmp7 - z3;
  154937. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154938. dataptr[DCTSIZE*3] = z13 - z2;
  154939. dataptr[DCTSIZE*1] = z11 + z4;
  154940. dataptr[DCTSIZE*7] = z11 - z4;
  154941. dataptr++; /* advance pointer to next column */
  154942. }
  154943. }
  154944. #endif /* DCT_FLOAT_SUPPORTED */
  154945. /*** End of inlined file: jfdctflt.c ***/
  154946. /*** Start of inlined file: jfdctint.c ***/
  154947. #define JPEG_INTERNALS
  154948. #ifdef DCT_ISLOW_SUPPORTED
  154949. #if DCTSIZE != 8
  154950. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154951. #endif
  154952. #if BITS_IN_JSAMPLE == 8
  154953. #define CONST_BITS 13
  154954. #define PASS1_BITS 2
  154955. #else
  154956. #define CONST_BITS 13
  154957. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  154958. #endif
  154959. #if CONST_BITS == 13
  154960. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  154961. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  154962. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  154963. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  154964. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  154965. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  154966. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  154967. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  154968. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  154969. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  154970. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  154971. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  154972. #else
  154973. #define FIX_0_298631336 FIX(0.298631336)
  154974. #define FIX_0_390180644 FIX(0.390180644)
  154975. #define FIX_0_541196100 FIX(0.541196100)
  154976. #define FIX_0_765366865 FIX(0.765366865)
  154977. #define FIX_0_899976223 FIX(0.899976223)
  154978. #define FIX_1_175875602 FIX(1.175875602)
  154979. #define FIX_1_501321110 FIX(1.501321110)
  154980. #define FIX_1_847759065 FIX(1.847759065)
  154981. #define FIX_1_961570560 FIX(1.961570560)
  154982. #define FIX_2_053119869 FIX(2.053119869)
  154983. #define FIX_2_562915447 FIX(2.562915447)
  154984. #define FIX_3_072711026 FIX(3.072711026)
  154985. #endif
  154986. #if BITS_IN_JSAMPLE == 8
  154987. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  154988. #else
  154989. #define MULTIPLY(var,const) ((var) * (const))
  154990. #endif
  154991. GLOBAL(void)
  154992. jpeg_fdct_islow (DCTELEM * data)
  154993. {
  154994. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154995. INT32 tmp10, tmp11, tmp12, tmp13;
  154996. INT32 z1, z2, z3, z4, z5;
  154997. DCTELEM *dataptr;
  154998. int ctr;
  154999. SHIFT_TEMPS
  155000. dataptr = data;
  155001. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155002. tmp0 = dataptr[0] + dataptr[7];
  155003. tmp7 = dataptr[0] - dataptr[7];
  155004. tmp1 = dataptr[1] + dataptr[6];
  155005. tmp6 = dataptr[1] - dataptr[6];
  155006. tmp2 = dataptr[2] + dataptr[5];
  155007. tmp5 = dataptr[2] - dataptr[5];
  155008. tmp3 = dataptr[3] + dataptr[4];
  155009. tmp4 = dataptr[3] - dataptr[4];
  155010. tmp10 = tmp0 + tmp3;
  155011. tmp13 = tmp0 - tmp3;
  155012. tmp11 = tmp1 + tmp2;
  155013. tmp12 = tmp1 - tmp2;
  155014. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155015. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155016. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155017. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155018. CONST_BITS-PASS1_BITS);
  155019. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155020. CONST_BITS-PASS1_BITS);
  155021. z1 = tmp4 + tmp7;
  155022. z2 = tmp5 + tmp6;
  155023. z3 = tmp4 + tmp6;
  155024. z4 = tmp5 + tmp7;
  155025. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155026. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155027. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155028. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155029. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155030. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155031. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155032. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155033. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155034. z3 += z5;
  155035. z4 += z5;
  155036. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155037. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155038. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155039. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155040. dataptr += DCTSIZE; /* advance pointer to next row */
  155041. }
  155042. dataptr = data;
  155043. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155044. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155045. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155046. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155047. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155048. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155049. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155050. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155051. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155052. tmp10 = tmp0 + tmp3;
  155053. tmp13 = tmp0 - tmp3;
  155054. tmp11 = tmp1 + tmp2;
  155055. tmp12 = tmp1 - tmp2;
  155056. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155057. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155058. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155059. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155060. CONST_BITS+PASS1_BITS);
  155061. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155062. CONST_BITS+PASS1_BITS);
  155063. z1 = tmp4 + tmp7;
  155064. z2 = tmp5 + tmp6;
  155065. z3 = tmp4 + tmp6;
  155066. z4 = tmp5 + tmp7;
  155067. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155068. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155069. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155070. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155071. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155072. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155073. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155074. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155075. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155076. z3 += z5;
  155077. z4 += z5;
  155078. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155079. CONST_BITS+PASS1_BITS);
  155080. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155081. CONST_BITS+PASS1_BITS);
  155082. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155083. CONST_BITS+PASS1_BITS);
  155084. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155085. CONST_BITS+PASS1_BITS);
  155086. dataptr++; /* advance pointer to next column */
  155087. }
  155088. }
  155089. #endif /* DCT_ISLOW_SUPPORTED */
  155090. /*** End of inlined file: jfdctint.c ***/
  155091. #undef CONST_BITS
  155092. #undef MULTIPLY
  155093. #undef FIX_0_541196100
  155094. /*** Start of inlined file: jfdctfst.c ***/
  155095. #define JPEG_INTERNALS
  155096. #ifdef DCT_IFAST_SUPPORTED
  155097. #if DCTSIZE != 8
  155098. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155099. #endif
  155100. #define CONST_BITS 8
  155101. #if CONST_BITS == 8
  155102. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155103. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155104. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155105. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155106. #else
  155107. #define FIX_0_382683433 FIX(0.382683433)
  155108. #define FIX_0_541196100 FIX(0.541196100)
  155109. #define FIX_0_707106781 FIX(0.707106781)
  155110. #define FIX_1_306562965 FIX(1.306562965)
  155111. #endif
  155112. #ifndef USE_ACCURATE_ROUNDING
  155113. #undef DESCALE
  155114. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155115. #endif
  155116. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155117. GLOBAL(void)
  155118. jpeg_fdct_ifast (DCTELEM * data)
  155119. {
  155120. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155121. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155122. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155123. DCTELEM *dataptr;
  155124. int ctr;
  155125. SHIFT_TEMPS
  155126. dataptr = data;
  155127. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155128. tmp0 = dataptr[0] + dataptr[7];
  155129. tmp7 = dataptr[0] - dataptr[7];
  155130. tmp1 = dataptr[1] + dataptr[6];
  155131. tmp6 = dataptr[1] - dataptr[6];
  155132. tmp2 = dataptr[2] + dataptr[5];
  155133. tmp5 = dataptr[2] - dataptr[5];
  155134. tmp3 = dataptr[3] + dataptr[4];
  155135. tmp4 = dataptr[3] - dataptr[4];
  155136. tmp10 = tmp0 + tmp3; /* phase 2 */
  155137. tmp13 = tmp0 - tmp3;
  155138. tmp11 = tmp1 + tmp2;
  155139. tmp12 = tmp1 - tmp2;
  155140. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155141. dataptr[4] = tmp10 - tmp11;
  155142. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155143. dataptr[2] = tmp13 + z1; /* phase 5 */
  155144. dataptr[6] = tmp13 - z1;
  155145. tmp10 = tmp4 + tmp5; /* phase 2 */
  155146. tmp11 = tmp5 + tmp6;
  155147. tmp12 = tmp6 + tmp7;
  155148. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155149. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155150. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155151. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155152. z11 = tmp7 + z3; /* phase 5 */
  155153. z13 = tmp7 - z3;
  155154. dataptr[5] = z13 + z2; /* phase 6 */
  155155. dataptr[3] = z13 - z2;
  155156. dataptr[1] = z11 + z4;
  155157. dataptr[7] = z11 - z4;
  155158. dataptr += DCTSIZE; /* advance pointer to next row */
  155159. }
  155160. dataptr = data;
  155161. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155162. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155163. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155164. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155165. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155166. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155167. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155168. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155169. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155170. tmp10 = tmp0 + tmp3; /* phase 2 */
  155171. tmp13 = tmp0 - tmp3;
  155172. tmp11 = tmp1 + tmp2;
  155173. tmp12 = tmp1 - tmp2;
  155174. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155175. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155176. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155177. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155178. dataptr[DCTSIZE*6] = tmp13 - z1;
  155179. tmp10 = tmp4 + tmp5; /* phase 2 */
  155180. tmp11 = tmp5 + tmp6;
  155181. tmp12 = tmp6 + tmp7;
  155182. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155183. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155184. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155185. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155186. z11 = tmp7 + z3; /* phase 5 */
  155187. z13 = tmp7 - z3;
  155188. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155189. dataptr[DCTSIZE*3] = z13 - z2;
  155190. dataptr[DCTSIZE*1] = z11 + z4;
  155191. dataptr[DCTSIZE*7] = z11 - z4;
  155192. dataptr++; /* advance pointer to next column */
  155193. }
  155194. }
  155195. #endif /* DCT_IFAST_SUPPORTED */
  155196. /*** End of inlined file: jfdctfst.c ***/
  155197. #undef FIX_0_541196100
  155198. /*** Start of inlined file: jidctflt.c ***/
  155199. #define JPEG_INTERNALS
  155200. #ifdef DCT_FLOAT_SUPPORTED
  155201. #if DCTSIZE != 8
  155202. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155203. #endif
  155204. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155205. GLOBAL(void)
  155206. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155207. JCOEFPTR coef_block,
  155208. JSAMPARRAY output_buf, JDIMENSION output_col)
  155209. {
  155210. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155211. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155212. FAST_FLOAT z5, z10, z11, z12, z13;
  155213. JCOEFPTR inptr;
  155214. FLOAT_MULT_TYPE * quantptr;
  155215. FAST_FLOAT * wsptr;
  155216. JSAMPROW outptr;
  155217. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155218. int ctr;
  155219. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155220. SHIFT_TEMPS
  155221. inptr = coef_block;
  155222. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155223. wsptr = workspace;
  155224. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155225. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155226. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155227. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155228. inptr[DCTSIZE*7] == 0) {
  155229. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155230. wsptr[DCTSIZE*0] = dcval;
  155231. wsptr[DCTSIZE*1] = dcval;
  155232. wsptr[DCTSIZE*2] = dcval;
  155233. wsptr[DCTSIZE*3] = dcval;
  155234. wsptr[DCTSIZE*4] = dcval;
  155235. wsptr[DCTSIZE*5] = dcval;
  155236. wsptr[DCTSIZE*6] = dcval;
  155237. wsptr[DCTSIZE*7] = dcval;
  155238. inptr++; /* advance pointers to next column */
  155239. quantptr++;
  155240. wsptr++;
  155241. continue;
  155242. }
  155243. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155244. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155245. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155246. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155247. tmp10 = tmp0 + tmp2; /* phase 3 */
  155248. tmp11 = tmp0 - tmp2;
  155249. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155250. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155251. tmp0 = tmp10 + tmp13; /* phase 2 */
  155252. tmp3 = tmp10 - tmp13;
  155253. tmp1 = tmp11 + tmp12;
  155254. tmp2 = tmp11 - tmp12;
  155255. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155256. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155257. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155258. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155259. z13 = tmp6 + tmp5; /* phase 6 */
  155260. z10 = tmp6 - tmp5;
  155261. z11 = tmp4 + tmp7;
  155262. z12 = tmp4 - tmp7;
  155263. tmp7 = z11 + z13; /* phase 5 */
  155264. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155265. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155266. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155267. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155268. tmp6 = tmp12 - tmp7; /* phase 2 */
  155269. tmp5 = tmp11 - tmp6;
  155270. tmp4 = tmp10 + tmp5;
  155271. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155272. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155273. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155274. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155275. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155276. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155277. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155278. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155279. inptr++; /* advance pointers to next column */
  155280. quantptr++;
  155281. wsptr++;
  155282. }
  155283. wsptr = workspace;
  155284. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155285. outptr = output_buf[ctr] + output_col;
  155286. tmp10 = wsptr[0] + wsptr[4];
  155287. tmp11 = wsptr[0] - wsptr[4];
  155288. tmp13 = wsptr[2] + wsptr[6];
  155289. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155290. tmp0 = tmp10 + tmp13;
  155291. tmp3 = tmp10 - tmp13;
  155292. tmp1 = tmp11 + tmp12;
  155293. tmp2 = tmp11 - tmp12;
  155294. z13 = wsptr[5] + wsptr[3];
  155295. z10 = wsptr[5] - wsptr[3];
  155296. z11 = wsptr[1] + wsptr[7];
  155297. z12 = wsptr[1] - wsptr[7];
  155298. tmp7 = z11 + z13;
  155299. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155300. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155301. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155302. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155303. tmp6 = tmp12 - tmp7;
  155304. tmp5 = tmp11 - tmp6;
  155305. tmp4 = tmp10 + tmp5;
  155306. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155307. & RANGE_MASK];
  155308. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155309. & RANGE_MASK];
  155310. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155311. & RANGE_MASK];
  155312. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155313. & RANGE_MASK];
  155314. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155315. & RANGE_MASK];
  155316. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155317. & RANGE_MASK];
  155318. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155319. & RANGE_MASK];
  155320. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155321. & RANGE_MASK];
  155322. wsptr += DCTSIZE; /* advance pointer to next row */
  155323. }
  155324. }
  155325. #endif /* DCT_FLOAT_SUPPORTED */
  155326. /*** End of inlined file: jidctflt.c ***/
  155327. #undef CONST_BITS
  155328. #undef FIX_1_847759065
  155329. #undef MULTIPLY
  155330. #undef DEQUANTIZE
  155331. #undef DESCALE
  155332. /*** Start of inlined file: jidctfst.c ***/
  155333. #define JPEG_INTERNALS
  155334. #ifdef DCT_IFAST_SUPPORTED
  155335. #if DCTSIZE != 8
  155336. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155337. #endif
  155338. #if BITS_IN_JSAMPLE == 8
  155339. #define CONST_BITS 8
  155340. #define PASS1_BITS 2
  155341. #else
  155342. #define CONST_BITS 8
  155343. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155344. #endif
  155345. #if CONST_BITS == 8
  155346. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155347. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155348. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155349. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155350. #else
  155351. #define FIX_1_082392200 FIX(1.082392200)
  155352. #define FIX_1_414213562 FIX(1.414213562)
  155353. #define FIX_1_847759065 FIX(1.847759065)
  155354. #define FIX_2_613125930 FIX(2.613125930)
  155355. #endif
  155356. #ifndef USE_ACCURATE_ROUNDING
  155357. #undef DESCALE
  155358. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155359. #endif
  155360. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155361. #if BITS_IN_JSAMPLE == 8
  155362. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155363. #else
  155364. #define DEQUANTIZE(coef,quantval) \
  155365. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155366. #endif
  155367. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155368. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155369. #if BITS_IN_JSAMPLE == 8
  155370. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155371. #else
  155372. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155373. #endif
  155374. #define IRIGHT_SHIFT(x,shft) \
  155375. ((ishift_temp = (x)) < 0 ? \
  155376. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155377. (ishift_temp >> (shft)))
  155378. #else
  155379. #define ISHIFT_TEMPS
  155380. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155381. #endif
  155382. #ifdef USE_ACCURATE_ROUNDING
  155383. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155384. #else
  155385. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155386. #endif
  155387. GLOBAL(void)
  155388. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155389. JCOEFPTR coef_block,
  155390. JSAMPARRAY output_buf, JDIMENSION output_col)
  155391. {
  155392. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155393. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155394. DCTELEM z5, z10, z11, z12, z13;
  155395. JCOEFPTR inptr;
  155396. IFAST_MULT_TYPE * quantptr;
  155397. int * wsptr;
  155398. JSAMPROW outptr;
  155399. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155400. int ctr;
  155401. int workspace[DCTSIZE2]; /* buffers data between passes */
  155402. SHIFT_TEMPS /* for DESCALE */
  155403. ISHIFT_TEMPS /* for IDESCALE */
  155404. inptr = coef_block;
  155405. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155406. wsptr = workspace;
  155407. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155408. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155409. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155410. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155411. inptr[DCTSIZE*7] == 0) {
  155412. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155413. wsptr[DCTSIZE*0] = dcval;
  155414. wsptr[DCTSIZE*1] = dcval;
  155415. wsptr[DCTSIZE*2] = dcval;
  155416. wsptr[DCTSIZE*3] = dcval;
  155417. wsptr[DCTSIZE*4] = dcval;
  155418. wsptr[DCTSIZE*5] = dcval;
  155419. wsptr[DCTSIZE*6] = dcval;
  155420. wsptr[DCTSIZE*7] = dcval;
  155421. inptr++; /* advance pointers to next column */
  155422. quantptr++;
  155423. wsptr++;
  155424. continue;
  155425. }
  155426. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155427. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155428. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155429. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155430. tmp10 = tmp0 + tmp2; /* phase 3 */
  155431. tmp11 = tmp0 - tmp2;
  155432. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155433. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155434. tmp0 = tmp10 + tmp13; /* phase 2 */
  155435. tmp3 = tmp10 - tmp13;
  155436. tmp1 = tmp11 + tmp12;
  155437. tmp2 = tmp11 - tmp12;
  155438. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155439. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155440. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155441. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155442. z13 = tmp6 + tmp5; /* phase 6 */
  155443. z10 = tmp6 - tmp5;
  155444. z11 = tmp4 + tmp7;
  155445. z12 = tmp4 - tmp7;
  155446. tmp7 = z11 + z13; /* phase 5 */
  155447. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155448. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155449. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155450. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155451. tmp6 = tmp12 - tmp7; /* phase 2 */
  155452. tmp5 = tmp11 - tmp6;
  155453. tmp4 = tmp10 + tmp5;
  155454. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155455. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155456. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155457. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155458. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155459. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155460. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155461. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155462. inptr++; /* advance pointers to next column */
  155463. quantptr++;
  155464. wsptr++;
  155465. }
  155466. wsptr = workspace;
  155467. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155468. outptr = output_buf[ctr] + output_col;
  155469. #ifndef NO_ZERO_ROW_TEST
  155470. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155471. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155472. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155473. & RANGE_MASK];
  155474. outptr[0] = dcval;
  155475. outptr[1] = dcval;
  155476. outptr[2] = dcval;
  155477. outptr[3] = dcval;
  155478. outptr[4] = dcval;
  155479. outptr[5] = dcval;
  155480. outptr[6] = dcval;
  155481. outptr[7] = dcval;
  155482. wsptr += DCTSIZE; /* advance pointer to next row */
  155483. continue;
  155484. }
  155485. #endif
  155486. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155487. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155488. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155489. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155490. - tmp13;
  155491. tmp0 = tmp10 + tmp13;
  155492. tmp3 = tmp10 - tmp13;
  155493. tmp1 = tmp11 + tmp12;
  155494. tmp2 = tmp11 - tmp12;
  155495. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155496. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155497. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155498. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155499. tmp7 = z11 + z13; /* phase 5 */
  155500. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155501. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155502. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155503. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155504. tmp6 = tmp12 - tmp7; /* phase 2 */
  155505. tmp5 = tmp11 - tmp6;
  155506. tmp4 = tmp10 + tmp5;
  155507. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155508. & RANGE_MASK];
  155509. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155510. & RANGE_MASK];
  155511. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155512. & RANGE_MASK];
  155513. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155514. & RANGE_MASK];
  155515. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155516. & RANGE_MASK];
  155517. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155518. & RANGE_MASK];
  155519. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155520. & RANGE_MASK];
  155521. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155522. & RANGE_MASK];
  155523. wsptr += DCTSIZE; /* advance pointer to next row */
  155524. }
  155525. }
  155526. #endif /* DCT_IFAST_SUPPORTED */
  155527. /*** End of inlined file: jidctfst.c ***/
  155528. #undef CONST_BITS
  155529. #undef FIX_1_847759065
  155530. #undef MULTIPLY
  155531. #undef DEQUANTIZE
  155532. /*** Start of inlined file: jidctint.c ***/
  155533. #define JPEG_INTERNALS
  155534. #ifdef DCT_ISLOW_SUPPORTED
  155535. #if DCTSIZE != 8
  155536. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155537. #endif
  155538. #if BITS_IN_JSAMPLE == 8
  155539. #define CONST_BITS 13
  155540. #define PASS1_BITS 2
  155541. #else
  155542. #define CONST_BITS 13
  155543. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155544. #endif
  155545. #if CONST_BITS == 13
  155546. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155547. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155548. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155549. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155550. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155551. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155552. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155553. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155554. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155555. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155556. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155557. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155558. #else
  155559. #define FIX_0_298631336 FIX(0.298631336)
  155560. #define FIX_0_390180644 FIX(0.390180644)
  155561. #define FIX_0_541196100 FIX(0.541196100)
  155562. #define FIX_0_765366865 FIX(0.765366865)
  155563. #define FIX_0_899976223 FIX(0.899976223)
  155564. #define FIX_1_175875602 FIX(1.175875602)
  155565. #define FIX_1_501321110 FIX(1.501321110)
  155566. #define FIX_1_847759065 FIX(1.847759065)
  155567. #define FIX_1_961570560 FIX(1.961570560)
  155568. #define FIX_2_053119869 FIX(2.053119869)
  155569. #define FIX_2_562915447 FIX(2.562915447)
  155570. #define FIX_3_072711026 FIX(3.072711026)
  155571. #endif
  155572. #if BITS_IN_JSAMPLE == 8
  155573. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155574. #else
  155575. #define MULTIPLY(var,const) ((var) * (const))
  155576. #endif
  155577. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155578. GLOBAL(void)
  155579. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155580. JCOEFPTR coef_block,
  155581. JSAMPARRAY output_buf, JDIMENSION output_col)
  155582. {
  155583. INT32 tmp0, tmp1, tmp2, tmp3;
  155584. INT32 tmp10, tmp11, tmp12, tmp13;
  155585. INT32 z1, z2, z3, z4, z5;
  155586. JCOEFPTR inptr;
  155587. ISLOW_MULT_TYPE * quantptr;
  155588. int * wsptr;
  155589. JSAMPROW outptr;
  155590. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155591. int ctr;
  155592. int workspace[DCTSIZE2]; /* buffers data between passes */
  155593. SHIFT_TEMPS
  155594. inptr = coef_block;
  155595. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155596. wsptr = workspace;
  155597. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155598. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155599. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155600. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155601. inptr[DCTSIZE*7] == 0) {
  155602. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155603. wsptr[DCTSIZE*0] = dcval;
  155604. wsptr[DCTSIZE*1] = dcval;
  155605. wsptr[DCTSIZE*2] = dcval;
  155606. wsptr[DCTSIZE*3] = dcval;
  155607. wsptr[DCTSIZE*4] = dcval;
  155608. wsptr[DCTSIZE*5] = dcval;
  155609. wsptr[DCTSIZE*6] = dcval;
  155610. wsptr[DCTSIZE*7] = dcval;
  155611. inptr++; /* advance pointers to next column */
  155612. quantptr++;
  155613. wsptr++;
  155614. continue;
  155615. }
  155616. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155617. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155618. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155619. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155620. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155621. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155622. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155623. tmp0 = (z2 + z3) << CONST_BITS;
  155624. tmp1 = (z2 - z3) << CONST_BITS;
  155625. tmp10 = tmp0 + tmp3;
  155626. tmp13 = tmp0 - tmp3;
  155627. tmp11 = tmp1 + tmp2;
  155628. tmp12 = tmp1 - tmp2;
  155629. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155630. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155631. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155632. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155633. z1 = tmp0 + tmp3;
  155634. z2 = tmp1 + tmp2;
  155635. z3 = tmp0 + tmp2;
  155636. z4 = tmp1 + tmp3;
  155637. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155638. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155639. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155640. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155641. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155642. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155643. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155644. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155645. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155646. z3 += z5;
  155647. z4 += z5;
  155648. tmp0 += z1 + z3;
  155649. tmp1 += z2 + z4;
  155650. tmp2 += z2 + z3;
  155651. tmp3 += z1 + z4;
  155652. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155653. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155654. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155655. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155656. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155657. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155658. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155659. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155660. inptr++; /* advance pointers to next column */
  155661. quantptr++;
  155662. wsptr++;
  155663. }
  155664. wsptr = workspace;
  155665. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155666. outptr = output_buf[ctr] + output_col;
  155667. #ifndef NO_ZERO_ROW_TEST
  155668. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155669. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155670. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155671. & RANGE_MASK];
  155672. outptr[0] = dcval;
  155673. outptr[1] = dcval;
  155674. outptr[2] = dcval;
  155675. outptr[3] = dcval;
  155676. outptr[4] = dcval;
  155677. outptr[5] = dcval;
  155678. outptr[6] = dcval;
  155679. outptr[7] = dcval;
  155680. wsptr += DCTSIZE; /* advance pointer to next row */
  155681. continue;
  155682. }
  155683. #endif
  155684. z2 = (INT32) wsptr[2];
  155685. z3 = (INT32) wsptr[6];
  155686. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155687. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155688. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155689. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155690. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155691. tmp10 = tmp0 + tmp3;
  155692. tmp13 = tmp0 - tmp3;
  155693. tmp11 = tmp1 + tmp2;
  155694. tmp12 = tmp1 - tmp2;
  155695. tmp0 = (INT32) wsptr[7];
  155696. tmp1 = (INT32) wsptr[5];
  155697. tmp2 = (INT32) wsptr[3];
  155698. tmp3 = (INT32) wsptr[1];
  155699. z1 = tmp0 + tmp3;
  155700. z2 = tmp1 + tmp2;
  155701. z3 = tmp0 + tmp2;
  155702. z4 = tmp1 + tmp3;
  155703. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155704. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155705. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155706. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155707. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155708. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155709. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155710. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155711. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155712. z3 += z5;
  155713. z4 += z5;
  155714. tmp0 += z1 + z3;
  155715. tmp1 += z2 + z4;
  155716. tmp2 += z2 + z3;
  155717. tmp3 += z1 + z4;
  155718. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155719. CONST_BITS+PASS1_BITS+3)
  155720. & RANGE_MASK];
  155721. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155722. CONST_BITS+PASS1_BITS+3)
  155723. & RANGE_MASK];
  155724. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155725. CONST_BITS+PASS1_BITS+3)
  155726. & RANGE_MASK];
  155727. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155728. CONST_BITS+PASS1_BITS+3)
  155729. & RANGE_MASK];
  155730. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155731. CONST_BITS+PASS1_BITS+3)
  155732. & RANGE_MASK];
  155733. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155734. CONST_BITS+PASS1_BITS+3)
  155735. & RANGE_MASK];
  155736. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155737. CONST_BITS+PASS1_BITS+3)
  155738. & RANGE_MASK];
  155739. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155740. CONST_BITS+PASS1_BITS+3)
  155741. & RANGE_MASK];
  155742. wsptr += DCTSIZE; /* advance pointer to next row */
  155743. }
  155744. }
  155745. #endif /* DCT_ISLOW_SUPPORTED */
  155746. /*** End of inlined file: jidctint.c ***/
  155747. /*** Start of inlined file: jidctred.c ***/
  155748. #define JPEG_INTERNALS
  155749. #ifdef IDCT_SCALING_SUPPORTED
  155750. #if DCTSIZE != 8
  155751. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155752. #endif
  155753. #if BITS_IN_JSAMPLE == 8
  155754. #define CONST_BITS 13
  155755. #define PASS1_BITS 2
  155756. #else
  155757. #define CONST_BITS 13
  155758. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155759. #endif
  155760. #if CONST_BITS == 13
  155761. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155762. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155763. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155764. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155765. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155766. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155767. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155768. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155769. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155770. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155771. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155772. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155773. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155774. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155775. #else
  155776. #define FIX_0_211164243 FIX(0.211164243)
  155777. #define FIX_0_509795579 FIX(0.509795579)
  155778. #define FIX_0_601344887 FIX(0.601344887)
  155779. #define FIX_0_720959822 FIX(0.720959822)
  155780. #define FIX_0_765366865 FIX(0.765366865)
  155781. #define FIX_0_850430095 FIX(0.850430095)
  155782. #define FIX_0_899976223 FIX(0.899976223)
  155783. #define FIX_1_061594337 FIX(1.061594337)
  155784. #define FIX_1_272758580 FIX(1.272758580)
  155785. #define FIX_1_451774981 FIX(1.451774981)
  155786. #define FIX_1_847759065 FIX(1.847759065)
  155787. #define FIX_2_172734803 FIX(2.172734803)
  155788. #define FIX_2_562915447 FIX(2.562915447)
  155789. #define FIX_3_624509785 FIX(3.624509785)
  155790. #endif
  155791. #if BITS_IN_JSAMPLE == 8
  155792. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155793. #else
  155794. #define MULTIPLY(var,const) ((var) * (const))
  155795. #endif
  155796. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155797. GLOBAL(void)
  155798. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155799. JCOEFPTR coef_block,
  155800. JSAMPARRAY output_buf, JDIMENSION output_col)
  155801. {
  155802. INT32 tmp0, tmp2, tmp10, tmp12;
  155803. INT32 z1, z2, z3, z4;
  155804. JCOEFPTR inptr;
  155805. ISLOW_MULT_TYPE * quantptr;
  155806. int * wsptr;
  155807. JSAMPROW outptr;
  155808. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155809. int ctr;
  155810. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155811. SHIFT_TEMPS
  155812. inptr = coef_block;
  155813. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155814. wsptr = workspace;
  155815. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155816. if (ctr == DCTSIZE-4)
  155817. continue;
  155818. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155819. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155820. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155821. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155822. wsptr[DCTSIZE*0] = dcval;
  155823. wsptr[DCTSIZE*1] = dcval;
  155824. wsptr[DCTSIZE*2] = dcval;
  155825. wsptr[DCTSIZE*3] = dcval;
  155826. continue;
  155827. }
  155828. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155829. tmp0 <<= (CONST_BITS+1);
  155830. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155831. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155832. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155833. tmp10 = tmp0 + tmp2;
  155834. tmp12 = tmp0 - tmp2;
  155835. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155836. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155837. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155838. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155839. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155840. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155841. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155842. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155843. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155844. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155845. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155846. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155847. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155848. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155849. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155850. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155851. }
  155852. wsptr = workspace;
  155853. for (ctr = 0; ctr < 4; ctr++) {
  155854. outptr = output_buf[ctr] + output_col;
  155855. #ifndef NO_ZERO_ROW_TEST
  155856. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155857. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155858. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155859. & RANGE_MASK];
  155860. outptr[0] = dcval;
  155861. outptr[1] = dcval;
  155862. outptr[2] = dcval;
  155863. outptr[3] = dcval;
  155864. wsptr += DCTSIZE; /* advance pointer to next row */
  155865. continue;
  155866. }
  155867. #endif
  155868. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155869. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155870. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155871. tmp10 = tmp0 + tmp2;
  155872. tmp12 = tmp0 - tmp2;
  155873. z1 = (INT32) wsptr[7];
  155874. z2 = (INT32) wsptr[5];
  155875. z3 = (INT32) wsptr[3];
  155876. z4 = (INT32) wsptr[1];
  155877. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155878. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155879. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155880. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155881. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155882. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155883. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155884. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155885. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155886. CONST_BITS+PASS1_BITS+3+1)
  155887. & RANGE_MASK];
  155888. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155889. CONST_BITS+PASS1_BITS+3+1)
  155890. & RANGE_MASK];
  155891. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155892. CONST_BITS+PASS1_BITS+3+1)
  155893. & RANGE_MASK];
  155894. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155895. CONST_BITS+PASS1_BITS+3+1)
  155896. & RANGE_MASK];
  155897. wsptr += DCTSIZE; /* advance pointer to next row */
  155898. }
  155899. }
  155900. GLOBAL(void)
  155901. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155902. JCOEFPTR coef_block,
  155903. JSAMPARRAY output_buf, JDIMENSION output_col)
  155904. {
  155905. INT32 tmp0, tmp10, z1;
  155906. JCOEFPTR inptr;
  155907. ISLOW_MULT_TYPE * quantptr;
  155908. int * wsptr;
  155909. JSAMPROW outptr;
  155910. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155911. int ctr;
  155912. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155913. SHIFT_TEMPS
  155914. inptr = coef_block;
  155915. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155916. wsptr = workspace;
  155917. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155918. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155919. continue;
  155920. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155921. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155922. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155923. wsptr[DCTSIZE*0] = dcval;
  155924. wsptr[DCTSIZE*1] = dcval;
  155925. continue;
  155926. }
  155927. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155928. tmp10 = z1 << (CONST_BITS+2);
  155929. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155930. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  155931. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155932. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  155933. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155934. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  155935. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155936. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155937. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  155938. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  155939. }
  155940. wsptr = workspace;
  155941. for (ctr = 0; ctr < 2; ctr++) {
  155942. outptr = output_buf[ctr] + output_col;
  155943. #ifndef NO_ZERO_ROW_TEST
  155944. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  155945. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155946. & RANGE_MASK];
  155947. outptr[0] = dcval;
  155948. outptr[1] = dcval;
  155949. wsptr += DCTSIZE; /* advance pointer to next row */
  155950. continue;
  155951. }
  155952. #endif
  155953. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  155954. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  155955. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  155956. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  155957. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155958. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  155959. CONST_BITS+PASS1_BITS+3+2)
  155960. & RANGE_MASK];
  155961. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  155962. CONST_BITS+PASS1_BITS+3+2)
  155963. & RANGE_MASK];
  155964. wsptr += DCTSIZE; /* advance pointer to next row */
  155965. }
  155966. }
  155967. GLOBAL(void)
  155968. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155969. JCOEFPTR coef_block,
  155970. JSAMPARRAY output_buf, JDIMENSION output_col)
  155971. {
  155972. int dcval;
  155973. ISLOW_MULT_TYPE * quantptr;
  155974. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155975. SHIFT_TEMPS
  155976. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155977. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  155978. dcval = (int) DESCALE((INT32) dcval, 3);
  155979. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  155980. }
  155981. #endif /* IDCT_SCALING_SUPPORTED */
  155982. /*** End of inlined file: jidctred.c ***/
  155983. /*** Start of inlined file: jmemmgr.c ***/
  155984. #define JPEG_INTERNALS
  155985. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  155986. /*** Start of inlined file: jmemsys.h ***/
  155987. #ifndef __jmemsys_h__
  155988. #define __jmemsys_h__
  155989. #ifdef NEED_SHORT_EXTERNAL_NAMES
  155990. #define jpeg_get_small jGetSmall
  155991. #define jpeg_free_small jFreeSmall
  155992. #define jpeg_get_large jGetLarge
  155993. #define jpeg_free_large jFreeLarge
  155994. #define jpeg_mem_available jMemAvail
  155995. #define jpeg_open_backing_store jOpenBackStore
  155996. #define jpeg_mem_init jMemInit
  155997. #define jpeg_mem_term jMemTerm
  155998. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  155999. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156000. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156001. size_t sizeofobject));
  156002. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156003. size_t sizeofobject));
  156004. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156005. size_t sizeofobject));
  156006. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156007. #define MAX_ALLOC_CHUNK 1000000000L
  156008. #endif
  156009. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156010. long min_bytes_needed,
  156011. long max_bytes_needed,
  156012. long already_allocated));
  156013. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156014. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156015. typedef unsigned short XMSH; /* type of extended-memory handles */
  156016. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156017. typedef union {
  156018. short file_handle; /* DOS file handle if it's a temp file */
  156019. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156020. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156021. } handle_union;
  156022. #endif /* USE_MSDOS_MEMMGR */
  156023. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156024. #include <Files.h>
  156025. #endif /* USE_MAC_MEMMGR */
  156026. //typedef struct backing_store_struct * backing_store_ptr;
  156027. typedef struct backing_store_struct {
  156028. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156029. struct backing_store_struct *info,
  156030. void FAR * buffer_address,
  156031. long file_offset, long byte_count));
  156032. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156033. struct backing_store_struct *info,
  156034. void FAR * buffer_address,
  156035. long file_offset, long byte_count));
  156036. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156037. struct backing_store_struct *info));
  156038. #ifdef USE_MSDOS_MEMMGR
  156039. handle_union handle; /* reference to backing-store storage object */
  156040. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156041. #else
  156042. #ifdef USE_MAC_MEMMGR
  156043. short temp_file; /* file reference number to temp file */
  156044. FSSpec tempSpec; /* the FSSpec for the temp file */
  156045. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156046. #else
  156047. FILE * temp_file; /* stdio reference to temp file */
  156048. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156049. #endif
  156050. #endif
  156051. } backing_store_info;
  156052. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156053. struct backing_store_struct *info,
  156054. long total_bytes_needed));
  156055. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156056. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156057. #endif
  156058. /*** End of inlined file: jmemsys.h ***/
  156059. /* import the system-dependent declarations */
  156060. #ifndef NO_GETENV
  156061. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156062. extern char * getenv JPP((const char * name));
  156063. #endif
  156064. #endif
  156065. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156066. #define ALIGN_TYPE double
  156067. #endif
  156068. typedef union small_pool_struct * small_pool_ptr;
  156069. typedef union small_pool_struct {
  156070. struct {
  156071. small_pool_ptr next; /* next in list of pools */
  156072. size_t bytes_used; /* how many bytes already used within pool */
  156073. size_t bytes_left; /* bytes still available in this pool */
  156074. } hdr;
  156075. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156076. } small_pool_hdr;
  156077. typedef union large_pool_struct FAR * large_pool_ptr;
  156078. typedef union large_pool_struct {
  156079. struct {
  156080. large_pool_ptr next; /* next in list of pools */
  156081. size_t bytes_used; /* how many bytes already used within pool */
  156082. size_t bytes_left; /* bytes still available in this pool */
  156083. } hdr;
  156084. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156085. } large_pool_hdr;
  156086. typedef struct {
  156087. struct jpeg_memory_mgr pub; /* public fields */
  156088. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156089. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156090. jvirt_sarray_ptr virt_sarray_list;
  156091. jvirt_barray_ptr virt_barray_list;
  156092. long total_space_allocated;
  156093. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156094. } my_memory_mgr;
  156095. typedef my_memory_mgr * my_mem_ptr;
  156096. struct jvirt_sarray_control {
  156097. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156098. JDIMENSION rows_in_array; /* total virtual array height */
  156099. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156100. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156101. JDIMENSION rows_in_mem; /* height of memory buffer */
  156102. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156103. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156104. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156105. boolean pre_zero; /* pre-zero mode requested? */
  156106. boolean dirty; /* do current buffer contents need written? */
  156107. boolean b_s_open; /* is backing-store data valid? */
  156108. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156109. backing_store_info b_s_info; /* System-dependent control info */
  156110. };
  156111. struct jvirt_barray_control {
  156112. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156113. JDIMENSION rows_in_array; /* total virtual array height */
  156114. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156115. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156116. JDIMENSION rows_in_mem; /* height of memory buffer */
  156117. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156118. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156119. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156120. boolean pre_zero; /* pre-zero mode requested? */
  156121. boolean dirty; /* do current buffer contents need written? */
  156122. boolean b_s_open; /* is backing-store data valid? */
  156123. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156124. backing_store_info b_s_info; /* System-dependent control info */
  156125. };
  156126. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156127. LOCAL(void)
  156128. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156129. {
  156130. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156131. small_pool_ptr shdr_ptr;
  156132. large_pool_ptr lhdr_ptr;
  156133. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156134. pool_id, mem->total_space_allocated);
  156135. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156136. lhdr_ptr = lhdr_ptr->hdr.next) {
  156137. fprintf(stderr, " Large chunk used %ld\n",
  156138. (long) lhdr_ptr->hdr.bytes_used);
  156139. }
  156140. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156141. shdr_ptr = shdr_ptr->hdr.next) {
  156142. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156143. (long) shdr_ptr->hdr.bytes_used,
  156144. (long) shdr_ptr->hdr.bytes_left);
  156145. }
  156146. }
  156147. #endif /* MEM_STATS */
  156148. LOCAL(void)
  156149. out_of_memory (j_common_ptr cinfo, int which)
  156150. {
  156151. #ifdef MEM_STATS
  156152. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156153. #endif
  156154. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156155. }
  156156. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156157. {
  156158. 1600, /* first PERMANENT pool */
  156159. 16000 /* first IMAGE pool */
  156160. };
  156161. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156162. {
  156163. 0, /* additional PERMANENT pools */
  156164. 5000 /* additional IMAGE pools */
  156165. };
  156166. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156167. METHODDEF(void *)
  156168. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156169. {
  156170. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156171. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156172. char * data_ptr;
  156173. size_t odd_bytes, min_request, slop;
  156174. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156175. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156176. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156177. if (odd_bytes > 0)
  156178. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156179. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156180. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156181. prev_hdr_ptr = NULL;
  156182. hdr_ptr = mem->small_list[pool_id];
  156183. while (hdr_ptr != NULL) {
  156184. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156185. break; /* found pool with enough space */
  156186. prev_hdr_ptr = hdr_ptr;
  156187. hdr_ptr = hdr_ptr->hdr.next;
  156188. }
  156189. if (hdr_ptr == NULL) {
  156190. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156191. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156192. slop = first_pool_slop[pool_id];
  156193. else
  156194. slop = extra_pool_slop[pool_id];
  156195. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156196. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156197. for (;;) {
  156198. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156199. if (hdr_ptr != NULL)
  156200. break;
  156201. slop /= 2;
  156202. if (slop < MIN_SLOP) /* give up when it gets real small */
  156203. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156204. }
  156205. mem->total_space_allocated += min_request + slop;
  156206. hdr_ptr->hdr.next = NULL;
  156207. hdr_ptr->hdr.bytes_used = 0;
  156208. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156209. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156210. mem->small_list[pool_id] = hdr_ptr;
  156211. else
  156212. prev_hdr_ptr->hdr.next = hdr_ptr;
  156213. }
  156214. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156215. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156216. hdr_ptr->hdr.bytes_used += sizeofobject;
  156217. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156218. return (void *) data_ptr;
  156219. }
  156220. METHODDEF(void FAR *)
  156221. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156222. {
  156223. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156224. large_pool_ptr hdr_ptr;
  156225. size_t odd_bytes;
  156226. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156227. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156228. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156229. if (odd_bytes > 0)
  156230. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156231. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156232. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156233. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156234. SIZEOF(large_pool_hdr));
  156235. if (hdr_ptr == NULL)
  156236. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156237. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156238. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156239. hdr_ptr->hdr.bytes_used = sizeofobject;
  156240. hdr_ptr->hdr.bytes_left = 0;
  156241. mem->large_list[pool_id] = hdr_ptr;
  156242. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156243. }
  156244. METHODDEF(JSAMPARRAY)
  156245. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156246. JDIMENSION samplesperrow, JDIMENSION numrows)
  156247. {
  156248. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156249. JSAMPARRAY result;
  156250. JSAMPROW workspace;
  156251. JDIMENSION rowsperchunk, currow, i;
  156252. long ltemp;
  156253. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156254. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156255. if (ltemp <= 0)
  156256. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156257. if (ltemp < (long) numrows)
  156258. rowsperchunk = (JDIMENSION) ltemp;
  156259. else
  156260. rowsperchunk = numrows;
  156261. mem->last_rowsperchunk = rowsperchunk;
  156262. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156263. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156264. currow = 0;
  156265. while (currow < numrows) {
  156266. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156267. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156268. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156269. * SIZEOF(JSAMPLE)));
  156270. for (i = rowsperchunk; i > 0; i--) {
  156271. result[currow++] = workspace;
  156272. workspace += samplesperrow;
  156273. }
  156274. }
  156275. return result;
  156276. }
  156277. METHODDEF(JBLOCKARRAY)
  156278. alloc_barray (j_common_ptr cinfo, int pool_id,
  156279. JDIMENSION blocksperrow, JDIMENSION numrows)
  156280. {
  156281. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156282. JBLOCKARRAY result;
  156283. JBLOCKROW workspace;
  156284. JDIMENSION rowsperchunk, currow, i;
  156285. long ltemp;
  156286. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156287. ((long) blocksperrow * SIZEOF(JBLOCK));
  156288. if (ltemp <= 0)
  156289. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156290. if (ltemp < (long) numrows)
  156291. rowsperchunk = (JDIMENSION) ltemp;
  156292. else
  156293. rowsperchunk = numrows;
  156294. mem->last_rowsperchunk = rowsperchunk;
  156295. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156296. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156297. currow = 0;
  156298. while (currow < numrows) {
  156299. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156300. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156301. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156302. * SIZEOF(JBLOCK)));
  156303. for (i = rowsperchunk; i > 0; i--) {
  156304. result[currow++] = workspace;
  156305. workspace += blocksperrow;
  156306. }
  156307. }
  156308. return result;
  156309. }
  156310. METHODDEF(jvirt_sarray_ptr)
  156311. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156312. JDIMENSION samplesperrow, JDIMENSION numrows,
  156313. JDIMENSION maxaccess)
  156314. {
  156315. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156316. jvirt_sarray_ptr result;
  156317. if (pool_id != JPOOL_IMAGE)
  156318. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156319. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156320. SIZEOF(struct jvirt_sarray_control));
  156321. result->mem_buffer = NULL; /* marks array not yet realized */
  156322. result->rows_in_array = numrows;
  156323. result->samplesperrow = samplesperrow;
  156324. result->maxaccess = maxaccess;
  156325. result->pre_zero = pre_zero;
  156326. result->b_s_open = FALSE; /* no associated backing-store object */
  156327. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156328. mem->virt_sarray_list = result;
  156329. return result;
  156330. }
  156331. METHODDEF(jvirt_barray_ptr)
  156332. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156333. JDIMENSION blocksperrow, JDIMENSION numrows,
  156334. JDIMENSION maxaccess)
  156335. {
  156336. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156337. jvirt_barray_ptr result;
  156338. if (pool_id != JPOOL_IMAGE)
  156339. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156340. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156341. SIZEOF(struct jvirt_barray_control));
  156342. result->mem_buffer = NULL; /* marks array not yet realized */
  156343. result->rows_in_array = numrows;
  156344. result->blocksperrow = blocksperrow;
  156345. result->maxaccess = maxaccess;
  156346. result->pre_zero = pre_zero;
  156347. result->b_s_open = FALSE; /* no associated backing-store object */
  156348. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156349. mem->virt_barray_list = result;
  156350. return result;
  156351. }
  156352. METHODDEF(void)
  156353. realize_virt_arrays (j_common_ptr cinfo)
  156354. {
  156355. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156356. long space_per_minheight, maximum_space, avail_mem;
  156357. long minheights, max_minheights;
  156358. jvirt_sarray_ptr sptr;
  156359. jvirt_barray_ptr bptr;
  156360. space_per_minheight = 0;
  156361. maximum_space = 0;
  156362. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156363. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156364. space_per_minheight += (long) sptr->maxaccess *
  156365. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156366. maximum_space += (long) sptr->rows_in_array *
  156367. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156368. }
  156369. }
  156370. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156371. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156372. space_per_minheight += (long) bptr->maxaccess *
  156373. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156374. maximum_space += (long) bptr->rows_in_array *
  156375. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156376. }
  156377. }
  156378. if (space_per_minheight <= 0)
  156379. return; /* no unrealized arrays, no work */
  156380. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156381. mem->total_space_allocated);
  156382. if (avail_mem >= maximum_space)
  156383. max_minheights = 1000000000L;
  156384. else {
  156385. max_minheights = avail_mem / space_per_minheight;
  156386. if (max_minheights <= 0)
  156387. max_minheights = 1;
  156388. }
  156389. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156390. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156391. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156392. if (minheights <= max_minheights) {
  156393. sptr->rows_in_mem = sptr->rows_in_array;
  156394. } else {
  156395. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156396. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156397. (long) sptr->rows_in_array *
  156398. (long) sptr->samplesperrow *
  156399. (long) SIZEOF(JSAMPLE));
  156400. sptr->b_s_open = TRUE;
  156401. }
  156402. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156403. sptr->samplesperrow, sptr->rows_in_mem);
  156404. sptr->rowsperchunk = mem->last_rowsperchunk;
  156405. sptr->cur_start_row = 0;
  156406. sptr->first_undef_row = 0;
  156407. sptr->dirty = FALSE;
  156408. }
  156409. }
  156410. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156411. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156412. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156413. if (minheights <= max_minheights) {
  156414. bptr->rows_in_mem = bptr->rows_in_array;
  156415. } else {
  156416. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156417. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156418. (long) bptr->rows_in_array *
  156419. (long) bptr->blocksperrow *
  156420. (long) SIZEOF(JBLOCK));
  156421. bptr->b_s_open = TRUE;
  156422. }
  156423. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156424. bptr->blocksperrow, bptr->rows_in_mem);
  156425. bptr->rowsperchunk = mem->last_rowsperchunk;
  156426. bptr->cur_start_row = 0;
  156427. bptr->first_undef_row = 0;
  156428. bptr->dirty = FALSE;
  156429. }
  156430. }
  156431. }
  156432. LOCAL(void)
  156433. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156434. {
  156435. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156436. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156437. file_offset = ptr->cur_start_row * bytesperrow;
  156438. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156439. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156440. thisrow = (long) ptr->cur_start_row + i;
  156441. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156442. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156443. if (rows <= 0) /* this chunk might be past end of file! */
  156444. break;
  156445. byte_count = rows * bytesperrow;
  156446. if (writing)
  156447. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156448. (void FAR *) ptr->mem_buffer[i],
  156449. file_offset, byte_count);
  156450. else
  156451. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156452. (void FAR *) ptr->mem_buffer[i],
  156453. file_offset, byte_count);
  156454. file_offset += byte_count;
  156455. }
  156456. }
  156457. LOCAL(void)
  156458. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156459. {
  156460. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156461. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156462. file_offset = ptr->cur_start_row * bytesperrow;
  156463. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156464. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156465. thisrow = (long) ptr->cur_start_row + i;
  156466. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156467. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156468. if (rows <= 0) /* this chunk might be past end of file! */
  156469. break;
  156470. byte_count = rows * bytesperrow;
  156471. if (writing)
  156472. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156473. (void FAR *) ptr->mem_buffer[i],
  156474. file_offset, byte_count);
  156475. else
  156476. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156477. (void FAR *) ptr->mem_buffer[i],
  156478. file_offset, byte_count);
  156479. file_offset += byte_count;
  156480. }
  156481. }
  156482. METHODDEF(JSAMPARRAY)
  156483. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156484. JDIMENSION start_row, JDIMENSION num_rows,
  156485. boolean writable)
  156486. {
  156487. JDIMENSION end_row = start_row + num_rows;
  156488. JDIMENSION undef_row;
  156489. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156490. ptr->mem_buffer == NULL)
  156491. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156492. if (start_row < ptr->cur_start_row ||
  156493. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156494. if (! ptr->b_s_open)
  156495. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156496. if (ptr->dirty) {
  156497. do_sarray_io(cinfo, ptr, TRUE);
  156498. ptr->dirty = FALSE;
  156499. }
  156500. if (start_row > ptr->cur_start_row) {
  156501. ptr->cur_start_row = start_row;
  156502. } else {
  156503. long ltemp;
  156504. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156505. if (ltemp < 0)
  156506. ltemp = 0; /* don't fall off front end of file */
  156507. ptr->cur_start_row = (JDIMENSION) ltemp;
  156508. }
  156509. do_sarray_io(cinfo, ptr, FALSE);
  156510. }
  156511. if (ptr->first_undef_row < end_row) {
  156512. if (ptr->first_undef_row < start_row) {
  156513. if (writable) /* writer skipped over a section of array */
  156514. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156515. undef_row = start_row; /* but reader is allowed to read ahead */
  156516. } else {
  156517. undef_row = ptr->first_undef_row;
  156518. }
  156519. if (writable)
  156520. ptr->first_undef_row = end_row;
  156521. if (ptr->pre_zero) {
  156522. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156523. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156524. end_row -= ptr->cur_start_row;
  156525. while (undef_row < end_row) {
  156526. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156527. undef_row++;
  156528. }
  156529. } else {
  156530. if (! writable) /* reader looking at undefined data */
  156531. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156532. }
  156533. }
  156534. if (writable)
  156535. ptr->dirty = TRUE;
  156536. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156537. }
  156538. METHODDEF(JBLOCKARRAY)
  156539. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156540. JDIMENSION start_row, JDIMENSION num_rows,
  156541. boolean writable)
  156542. {
  156543. JDIMENSION end_row = start_row + num_rows;
  156544. JDIMENSION undef_row;
  156545. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156546. ptr->mem_buffer == NULL)
  156547. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156548. if (start_row < ptr->cur_start_row ||
  156549. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156550. if (! ptr->b_s_open)
  156551. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156552. if (ptr->dirty) {
  156553. do_barray_io(cinfo, ptr, TRUE);
  156554. ptr->dirty = FALSE;
  156555. }
  156556. if (start_row > ptr->cur_start_row) {
  156557. ptr->cur_start_row = start_row;
  156558. } else {
  156559. long ltemp;
  156560. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156561. if (ltemp < 0)
  156562. ltemp = 0; /* don't fall off front end of file */
  156563. ptr->cur_start_row = (JDIMENSION) ltemp;
  156564. }
  156565. do_barray_io(cinfo, ptr, FALSE);
  156566. }
  156567. if (ptr->first_undef_row < end_row) {
  156568. if (ptr->first_undef_row < start_row) {
  156569. if (writable) /* writer skipped over a section of array */
  156570. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156571. undef_row = start_row; /* but reader is allowed to read ahead */
  156572. } else {
  156573. undef_row = ptr->first_undef_row;
  156574. }
  156575. if (writable)
  156576. ptr->first_undef_row = end_row;
  156577. if (ptr->pre_zero) {
  156578. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156579. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156580. end_row -= ptr->cur_start_row;
  156581. while (undef_row < end_row) {
  156582. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156583. undef_row++;
  156584. }
  156585. } else {
  156586. if (! writable) /* reader looking at undefined data */
  156587. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156588. }
  156589. }
  156590. if (writable)
  156591. ptr->dirty = TRUE;
  156592. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156593. }
  156594. METHODDEF(void)
  156595. free_pool (j_common_ptr cinfo, int pool_id)
  156596. {
  156597. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156598. small_pool_ptr shdr_ptr;
  156599. large_pool_ptr lhdr_ptr;
  156600. size_t space_freed;
  156601. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156602. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156603. #ifdef MEM_STATS
  156604. if (cinfo->err->trace_level > 1)
  156605. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156606. #endif
  156607. if (pool_id == JPOOL_IMAGE) {
  156608. jvirt_sarray_ptr sptr;
  156609. jvirt_barray_ptr bptr;
  156610. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156611. if (sptr->b_s_open) { /* there may be no backing store */
  156612. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156613. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156614. }
  156615. }
  156616. mem->virt_sarray_list = NULL;
  156617. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156618. if (bptr->b_s_open) { /* there may be no backing store */
  156619. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156620. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156621. }
  156622. }
  156623. mem->virt_barray_list = NULL;
  156624. }
  156625. lhdr_ptr = mem->large_list[pool_id];
  156626. mem->large_list[pool_id] = NULL;
  156627. while (lhdr_ptr != NULL) {
  156628. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156629. space_freed = lhdr_ptr->hdr.bytes_used +
  156630. lhdr_ptr->hdr.bytes_left +
  156631. SIZEOF(large_pool_hdr);
  156632. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156633. mem->total_space_allocated -= space_freed;
  156634. lhdr_ptr = next_lhdr_ptr;
  156635. }
  156636. shdr_ptr = mem->small_list[pool_id];
  156637. mem->small_list[pool_id] = NULL;
  156638. while (shdr_ptr != NULL) {
  156639. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156640. space_freed = shdr_ptr->hdr.bytes_used +
  156641. shdr_ptr->hdr.bytes_left +
  156642. SIZEOF(small_pool_hdr);
  156643. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156644. mem->total_space_allocated -= space_freed;
  156645. shdr_ptr = next_shdr_ptr;
  156646. }
  156647. }
  156648. METHODDEF(void)
  156649. self_destruct (j_common_ptr cinfo)
  156650. {
  156651. int pool;
  156652. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156653. free_pool(cinfo, pool);
  156654. }
  156655. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156656. cinfo->mem = NULL; /* ensures I will be called only once */
  156657. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156658. }
  156659. GLOBAL(void)
  156660. jinit_memory_mgr (j_common_ptr cinfo)
  156661. {
  156662. my_mem_ptr mem;
  156663. long max_to_use;
  156664. int pool;
  156665. size_t test_mac;
  156666. cinfo->mem = NULL; /* for safety if init fails */
  156667. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156668. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156669. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156670. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156671. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156672. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156673. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156674. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156675. if (mem == NULL) {
  156676. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156677. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156678. }
  156679. mem->pub.alloc_small = alloc_small;
  156680. mem->pub.alloc_large = alloc_large;
  156681. mem->pub.alloc_sarray = alloc_sarray;
  156682. mem->pub.alloc_barray = alloc_barray;
  156683. mem->pub.request_virt_sarray = request_virt_sarray;
  156684. mem->pub.request_virt_barray = request_virt_barray;
  156685. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156686. mem->pub.access_virt_sarray = access_virt_sarray;
  156687. mem->pub.access_virt_barray = access_virt_barray;
  156688. mem->pub.free_pool = free_pool;
  156689. mem->pub.self_destruct = self_destruct;
  156690. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156691. mem->pub.max_memory_to_use = max_to_use;
  156692. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156693. mem->small_list[pool] = NULL;
  156694. mem->large_list[pool] = NULL;
  156695. }
  156696. mem->virt_sarray_list = NULL;
  156697. mem->virt_barray_list = NULL;
  156698. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156699. cinfo->mem = & mem->pub;
  156700. #ifndef NO_GETENV
  156701. { char * memenv;
  156702. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156703. char ch = 'x';
  156704. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156705. if (ch == 'm' || ch == 'M')
  156706. max_to_use *= 1000L;
  156707. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156708. }
  156709. }
  156710. }
  156711. #endif
  156712. }
  156713. /*** End of inlined file: jmemmgr.c ***/
  156714. /*** Start of inlined file: jmemnobs.c ***/
  156715. #define JPEG_INTERNALS
  156716. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156717. extern void * malloc JPP((size_t size));
  156718. extern void free JPP((void *ptr));
  156719. #endif
  156720. GLOBAL(void *)
  156721. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156722. {
  156723. return (void *) malloc(sizeofobject);
  156724. }
  156725. GLOBAL(void)
  156726. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156727. {
  156728. free(object);
  156729. }
  156730. GLOBAL(void FAR *)
  156731. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156732. {
  156733. return (void FAR *) malloc(sizeofobject);
  156734. }
  156735. GLOBAL(void)
  156736. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156737. {
  156738. free(object);
  156739. }
  156740. GLOBAL(long)
  156741. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156742. long max_bytes_needed, long already_allocated)
  156743. {
  156744. return max_bytes_needed;
  156745. }
  156746. GLOBAL(void)
  156747. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156748. long total_bytes_needed)
  156749. {
  156750. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156751. }
  156752. GLOBAL(long)
  156753. jpeg_mem_init (j_common_ptr cinfo)
  156754. {
  156755. return 0; /* just set max_memory_to_use to 0 */
  156756. }
  156757. GLOBAL(void)
  156758. jpeg_mem_term (j_common_ptr cinfo)
  156759. {
  156760. }
  156761. /*** End of inlined file: jmemnobs.c ***/
  156762. /*** Start of inlined file: jquant1.c ***/
  156763. #define JPEG_INTERNALS
  156764. #ifdef QUANT_1PASS_SUPPORTED
  156765. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156766. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156767. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156768. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156769. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156770. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156771. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156772. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156773. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156774. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156775. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156776. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156777. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156778. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156779. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156780. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156781. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156782. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156783. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156784. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156785. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156786. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156787. };
  156788. #if BITS_IN_JSAMPLE == 8
  156789. typedef INT16 FSERROR; /* 16 bits should be enough */
  156790. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156791. #else
  156792. typedef INT32 FSERROR; /* may need more than 16 bits */
  156793. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156794. #endif
  156795. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156796. #define MAX_Q_COMPS 4 /* max components I can handle */
  156797. typedef struct {
  156798. struct jpeg_color_quantizer pub; /* public fields */
  156799. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156800. int sv_actual; /* number of entries in use */
  156801. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156802. boolean is_padded; /* is the colorindex padded for odither? */
  156803. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156804. int row_index; /* cur row's vertical index in dither matrix */
  156805. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156806. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156807. boolean on_odd_row; /* flag to remember which row we are on */
  156808. } my_cquantizer;
  156809. typedef my_cquantizer * my_cquantize_ptr;
  156810. LOCAL(int)
  156811. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156812. {
  156813. int nc = cinfo->out_color_components; /* number of color components */
  156814. int max_colors = cinfo->desired_number_of_colors;
  156815. int total_colors, iroot, i, j;
  156816. boolean changed;
  156817. long temp;
  156818. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156819. iroot = 1;
  156820. do {
  156821. iroot++;
  156822. temp = iroot; /* set temp = iroot ** nc */
  156823. for (i = 1; i < nc; i++)
  156824. temp *= iroot;
  156825. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156826. iroot--; /* now iroot = floor(root) */
  156827. if (iroot < 2)
  156828. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156829. total_colors = 1;
  156830. for (i = 0; i < nc; i++) {
  156831. Ncolors[i] = iroot;
  156832. total_colors *= iroot;
  156833. }
  156834. do {
  156835. changed = FALSE;
  156836. for (i = 0; i < nc; i++) {
  156837. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156838. temp = total_colors / Ncolors[j];
  156839. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156840. if (temp > (long) max_colors)
  156841. break; /* won't fit, done with this pass */
  156842. Ncolors[j]++; /* OK, apply the increment */
  156843. total_colors = (int) temp;
  156844. changed = TRUE;
  156845. }
  156846. } while (changed);
  156847. return total_colors;
  156848. }
  156849. LOCAL(int)
  156850. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156851. {
  156852. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156853. }
  156854. LOCAL(int)
  156855. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156856. {
  156857. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156858. }
  156859. LOCAL(void)
  156860. create_colormap (j_decompress_ptr cinfo)
  156861. {
  156862. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156863. JSAMPARRAY colormap; /* Created colormap */
  156864. int total_colors; /* Number of distinct output colors */
  156865. int i,j,k, nci, blksize, blkdist, ptr, val;
  156866. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156867. if (cinfo->out_color_components == 3)
  156868. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156869. total_colors, cquantize->Ncolors[0],
  156870. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156871. else
  156872. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156873. colormap = (*cinfo->mem->alloc_sarray)
  156874. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156875. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156876. blkdist = total_colors;
  156877. for (i = 0; i < cinfo->out_color_components; i++) {
  156878. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156879. blksize = blkdist / nci;
  156880. for (j = 0; j < nci; j++) {
  156881. val = output_value(cinfo, i, j, nci-1);
  156882. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156883. for (k = 0; k < blksize; k++)
  156884. colormap[i][ptr+k] = (JSAMPLE) val;
  156885. }
  156886. }
  156887. blkdist = blksize; /* blksize of this color is blkdist of next */
  156888. }
  156889. cquantize->sv_colormap = colormap;
  156890. cquantize->sv_actual = total_colors;
  156891. }
  156892. LOCAL(void)
  156893. create_colorindex (j_decompress_ptr cinfo)
  156894. {
  156895. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156896. JSAMPROW indexptr;
  156897. int i,j,k, nci, blksize, val, pad;
  156898. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156899. pad = MAXJSAMPLE*2;
  156900. cquantize->is_padded = TRUE;
  156901. } else {
  156902. pad = 0;
  156903. cquantize->is_padded = FALSE;
  156904. }
  156905. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156906. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156907. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156908. (JDIMENSION) cinfo->out_color_components);
  156909. blksize = cquantize->sv_actual;
  156910. for (i = 0; i < cinfo->out_color_components; i++) {
  156911. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156912. blksize = blksize / nci;
  156913. if (pad)
  156914. cquantize->colorindex[i] += MAXJSAMPLE;
  156915. indexptr = cquantize->colorindex[i];
  156916. val = 0;
  156917. k = largest_input_value(cinfo, i, 0, nci-1);
  156918. for (j = 0; j <= MAXJSAMPLE; j++) {
  156919. while (j > k) /* advance val if past boundary */
  156920. k = largest_input_value(cinfo, i, ++val, nci-1);
  156921. indexptr[j] = (JSAMPLE) (val * blksize);
  156922. }
  156923. if (pad)
  156924. for (j = 1; j <= MAXJSAMPLE; j++) {
  156925. indexptr[-j] = indexptr[0];
  156926. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156927. }
  156928. }
  156929. }
  156930. LOCAL(ODITHER_MATRIX_PTR)
  156931. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  156932. {
  156933. ODITHER_MATRIX_PTR odither;
  156934. int j,k;
  156935. INT32 num,den;
  156936. odither = (ODITHER_MATRIX_PTR)
  156937. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156938. SIZEOF(ODITHER_MATRIX));
  156939. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  156940. for (j = 0; j < ODITHER_SIZE; j++) {
  156941. for (k = 0; k < ODITHER_SIZE; k++) {
  156942. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  156943. * MAXJSAMPLE;
  156944. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  156945. }
  156946. }
  156947. return odither;
  156948. }
  156949. LOCAL(void)
  156950. create_odither_tables (j_decompress_ptr cinfo)
  156951. {
  156952. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156953. ODITHER_MATRIX_PTR odither;
  156954. int i, j, nci;
  156955. for (i = 0; i < cinfo->out_color_components; i++) {
  156956. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156957. odither = NULL; /* search for matching prior component */
  156958. for (j = 0; j < i; j++) {
  156959. if (nci == cquantize->Ncolors[j]) {
  156960. odither = cquantize->odither[j];
  156961. break;
  156962. }
  156963. }
  156964. if (odither == NULL) /* need a new table? */
  156965. odither = make_odither_array(cinfo, nci);
  156966. cquantize->odither[i] = odither;
  156967. }
  156968. }
  156969. METHODDEF(void)
  156970. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156971. JSAMPARRAY output_buf, int num_rows)
  156972. {
  156973. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156974. JSAMPARRAY colorindex = cquantize->colorindex;
  156975. register int pixcode, ci;
  156976. register JSAMPROW ptrin, ptrout;
  156977. int row;
  156978. JDIMENSION col;
  156979. JDIMENSION width = cinfo->output_width;
  156980. register int nc = cinfo->out_color_components;
  156981. for (row = 0; row < num_rows; row++) {
  156982. ptrin = input_buf[row];
  156983. ptrout = output_buf[row];
  156984. for (col = width; col > 0; col--) {
  156985. pixcode = 0;
  156986. for (ci = 0; ci < nc; ci++) {
  156987. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  156988. }
  156989. *ptrout++ = (JSAMPLE) pixcode;
  156990. }
  156991. }
  156992. }
  156993. METHODDEF(void)
  156994. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156995. JSAMPARRAY output_buf, int num_rows)
  156996. {
  156997. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156998. register int pixcode;
  156999. register JSAMPROW ptrin, ptrout;
  157000. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157001. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157002. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157003. int row;
  157004. JDIMENSION col;
  157005. JDIMENSION width = cinfo->output_width;
  157006. for (row = 0; row < num_rows; row++) {
  157007. ptrin = input_buf[row];
  157008. ptrout = output_buf[row];
  157009. for (col = width; col > 0; col--) {
  157010. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157011. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157012. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157013. *ptrout++ = (JSAMPLE) pixcode;
  157014. }
  157015. }
  157016. }
  157017. METHODDEF(void)
  157018. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157019. JSAMPARRAY output_buf, int num_rows)
  157020. {
  157021. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157022. register JSAMPROW input_ptr;
  157023. register JSAMPROW output_ptr;
  157024. JSAMPROW colorindex_ci;
  157025. int * dither; /* points to active row of dither matrix */
  157026. int row_index, col_index; /* current indexes into dither matrix */
  157027. int nc = cinfo->out_color_components;
  157028. int ci;
  157029. int row;
  157030. JDIMENSION col;
  157031. JDIMENSION width = cinfo->output_width;
  157032. for (row = 0; row < num_rows; row++) {
  157033. jzero_far((void FAR *) output_buf[row],
  157034. (size_t) (width * SIZEOF(JSAMPLE)));
  157035. row_index = cquantize->row_index;
  157036. for (ci = 0; ci < nc; ci++) {
  157037. input_ptr = input_buf[row] + ci;
  157038. output_ptr = output_buf[row];
  157039. colorindex_ci = cquantize->colorindex[ci];
  157040. dither = cquantize->odither[ci][row_index];
  157041. col_index = 0;
  157042. for (col = width; col > 0; col--) {
  157043. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157044. input_ptr += nc;
  157045. output_ptr++;
  157046. col_index = (col_index + 1) & ODITHER_MASK;
  157047. }
  157048. }
  157049. row_index = (row_index + 1) & ODITHER_MASK;
  157050. cquantize->row_index = row_index;
  157051. }
  157052. }
  157053. METHODDEF(void)
  157054. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157055. JSAMPARRAY output_buf, int num_rows)
  157056. {
  157057. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157058. register int pixcode;
  157059. register JSAMPROW input_ptr;
  157060. register JSAMPROW output_ptr;
  157061. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157062. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157063. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157064. int * dither0; /* points to active row of dither matrix */
  157065. int * dither1;
  157066. int * dither2;
  157067. int row_index, col_index; /* current indexes into dither matrix */
  157068. int row;
  157069. JDIMENSION col;
  157070. JDIMENSION width = cinfo->output_width;
  157071. for (row = 0; row < num_rows; row++) {
  157072. row_index = cquantize->row_index;
  157073. input_ptr = input_buf[row];
  157074. output_ptr = output_buf[row];
  157075. dither0 = cquantize->odither[0][row_index];
  157076. dither1 = cquantize->odither[1][row_index];
  157077. dither2 = cquantize->odither[2][row_index];
  157078. col_index = 0;
  157079. for (col = width; col > 0; col--) {
  157080. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157081. dither0[col_index]]);
  157082. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157083. dither1[col_index]]);
  157084. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157085. dither2[col_index]]);
  157086. *output_ptr++ = (JSAMPLE) pixcode;
  157087. col_index = (col_index + 1) & ODITHER_MASK;
  157088. }
  157089. row_index = (row_index + 1) & ODITHER_MASK;
  157090. cquantize->row_index = row_index;
  157091. }
  157092. }
  157093. METHODDEF(void)
  157094. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157095. JSAMPARRAY output_buf, int num_rows)
  157096. {
  157097. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157098. register LOCFSERROR cur; /* current error or pixel value */
  157099. LOCFSERROR belowerr; /* error for pixel below cur */
  157100. LOCFSERROR bpreverr; /* error for below/prev col */
  157101. LOCFSERROR bnexterr; /* error for below/next col */
  157102. LOCFSERROR delta;
  157103. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157104. register JSAMPROW input_ptr;
  157105. register JSAMPROW output_ptr;
  157106. JSAMPROW colorindex_ci;
  157107. JSAMPROW colormap_ci;
  157108. int pixcode;
  157109. int nc = cinfo->out_color_components;
  157110. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157111. int dirnc; /* dir * nc */
  157112. int ci;
  157113. int row;
  157114. JDIMENSION col;
  157115. JDIMENSION width = cinfo->output_width;
  157116. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157117. SHIFT_TEMPS
  157118. for (row = 0; row < num_rows; row++) {
  157119. jzero_far((void FAR *) output_buf[row],
  157120. (size_t) (width * SIZEOF(JSAMPLE)));
  157121. for (ci = 0; ci < nc; ci++) {
  157122. input_ptr = input_buf[row] + ci;
  157123. output_ptr = output_buf[row];
  157124. if (cquantize->on_odd_row) {
  157125. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157126. output_ptr += width-1;
  157127. dir = -1;
  157128. dirnc = -nc;
  157129. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157130. } else {
  157131. dir = 1;
  157132. dirnc = nc;
  157133. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157134. }
  157135. colorindex_ci = cquantize->colorindex[ci];
  157136. colormap_ci = cquantize->sv_colormap[ci];
  157137. cur = 0;
  157138. belowerr = bpreverr = 0;
  157139. for (col = width; col > 0; col--) {
  157140. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157141. cur += GETJSAMPLE(*input_ptr);
  157142. cur = GETJSAMPLE(range_limit[cur]);
  157143. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157144. *output_ptr += (JSAMPLE) pixcode;
  157145. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157146. bnexterr = cur;
  157147. delta = cur * 2;
  157148. cur += delta; /* form error * 3 */
  157149. errorptr[0] = (FSERROR) (bpreverr + cur);
  157150. cur += delta; /* form error * 5 */
  157151. bpreverr = belowerr + cur;
  157152. belowerr = bnexterr;
  157153. cur += delta; /* form error * 7 */
  157154. input_ptr += dirnc; /* advance input ptr to next column */
  157155. output_ptr += dir; /* advance output ptr to next column */
  157156. errorptr += dir; /* advance errorptr to current column */
  157157. }
  157158. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157159. }
  157160. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157161. }
  157162. }
  157163. LOCAL(void)
  157164. alloc_fs_workspace (j_decompress_ptr cinfo)
  157165. {
  157166. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157167. size_t arraysize;
  157168. int i;
  157169. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157170. for (i = 0; i < cinfo->out_color_components; i++) {
  157171. cquantize->fserrors[i] = (FSERRPTR)
  157172. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157173. }
  157174. }
  157175. METHODDEF(void)
  157176. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157177. {
  157178. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157179. size_t arraysize;
  157180. int i;
  157181. cinfo->colormap = cquantize->sv_colormap;
  157182. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157183. switch (cinfo->dither_mode) {
  157184. case JDITHER_NONE:
  157185. if (cinfo->out_color_components == 3)
  157186. cquantize->pub.color_quantize = color_quantize3;
  157187. else
  157188. cquantize->pub.color_quantize = color_quantize;
  157189. break;
  157190. case JDITHER_ORDERED:
  157191. if (cinfo->out_color_components == 3)
  157192. cquantize->pub.color_quantize = quantize3_ord_dither;
  157193. else
  157194. cquantize->pub.color_quantize = quantize_ord_dither;
  157195. cquantize->row_index = 0; /* initialize state for ordered dither */
  157196. if (! cquantize->is_padded)
  157197. create_colorindex(cinfo);
  157198. if (cquantize->odither[0] == NULL)
  157199. create_odither_tables(cinfo);
  157200. break;
  157201. case JDITHER_FS:
  157202. cquantize->pub.color_quantize = quantize_fs_dither;
  157203. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157204. if (cquantize->fserrors[0] == NULL)
  157205. alloc_fs_workspace(cinfo);
  157206. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157207. for (i = 0; i < cinfo->out_color_components; i++)
  157208. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157209. break;
  157210. default:
  157211. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157212. break;
  157213. }
  157214. }
  157215. METHODDEF(void)
  157216. finish_pass_1_quant (j_decompress_ptr cinfo)
  157217. {
  157218. }
  157219. METHODDEF(void)
  157220. new_color_map_1_quant (j_decompress_ptr cinfo)
  157221. {
  157222. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157223. }
  157224. GLOBAL(void)
  157225. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157226. {
  157227. my_cquantize_ptr cquantize;
  157228. cquantize = (my_cquantize_ptr)
  157229. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157230. SIZEOF(my_cquantizer));
  157231. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157232. cquantize->pub.start_pass = start_pass_1_quant;
  157233. cquantize->pub.finish_pass = finish_pass_1_quant;
  157234. cquantize->pub.new_color_map = new_color_map_1_quant;
  157235. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157236. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157237. if (cinfo->out_color_components > MAX_Q_COMPS)
  157238. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157239. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157240. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157241. create_colormap(cinfo);
  157242. create_colorindex(cinfo);
  157243. if (cinfo->dither_mode == JDITHER_FS)
  157244. alloc_fs_workspace(cinfo);
  157245. }
  157246. #endif /* QUANT_1PASS_SUPPORTED */
  157247. /*** End of inlined file: jquant1.c ***/
  157248. /*** Start of inlined file: jquant2.c ***/
  157249. #define JPEG_INTERNALS
  157250. #ifdef QUANT_2PASS_SUPPORTED
  157251. #define R_SCALE 2 /* scale R distances by this much */
  157252. #define G_SCALE 3 /* scale G distances by this much */
  157253. #define B_SCALE 1 /* and B by this much */
  157254. #if RGB_RED == 0
  157255. #define C0_SCALE R_SCALE
  157256. #endif
  157257. #if RGB_BLUE == 0
  157258. #define C0_SCALE B_SCALE
  157259. #endif
  157260. #if RGB_GREEN == 1
  157261. #define C1_SCALE G_SCALE
  157262. #endif
  157263. #if RGB_RED == 2
  157264. #define C2_SCALE R_SCALE
  157265. #endif
  157266. #if RGB_BLUE == 2
  157267. #define C2_SCALE B_SCALE
  157268. #endif
  157269. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157270. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157271. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157272. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157273. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157274. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157275. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157276. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157277. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157278. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157279. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157280. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157281. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157282. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157283. typedef hist2d * hist3d; /* type for top-level pointer */
  157284. #if BITS_IN_JSAMPLE == 8
  157285. typedef INT16 FSERROR; /* 16 bits should be enough */
  157286. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157287. #else
  157288. typedef INT32 FSERROR; /* may need more than 16 bits */
  157289. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157290. #endif
  157291. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157292. typedef struct {
  157293. struct jpeg_color_quantizer pub; /* public fields */
  157294. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157295. int desired; /* desired # of colors = size of colormap */
  157296. hist3d histogram; /* pointer to the histogram */
  157297. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157298. FSERRPTR fserrors; /* accumulated errors */
  157299. boolean on_odd_row; /* flag to remember which row we are on */
  157300. int * error_limiter; /* table for clamping the applied error */
  157301. } my_cquantizer2;
  157302. typedef my_cquantizer2 * my_cquantize_ptr2;
  157303. METHODDEF(void)
  157304. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157305. JSAMPARRAY output_buf, int num_rows)
  157306. {
  157307. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157308. register JSAMPROW ptr;
  157309. register histptr histp;
  157310. register hist3d histogram = cquantize->histogram;
  157311. int row;
  157312. JDIMENSION col;
  157313. JDIMENSION width = cinfo->output_width;
  157314. for (row = 0; row < num_rows; row++) {
  157315. ptr = input_buf[row];
  157316. for (col = width; col > 0; col--) {
  157317. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157318. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157319. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157320. if (++(*histp) <= 0)
  157321. (*histp)--;
  157322. ptr += 3;
  157323. }
  157324. }
  157325. }
  157326. typedef struct {
  157327. int c0min, c0max;
  157328. int c1min, c1max;
  157329. int c2min, c2max;
  157330. INT32 volume;
  157331. long colorcount;
  157332. } box;
  157333. typedef box * boxptr;
  157334. LOCAL(boxptr)
  157335. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157336. {
  157337. register boxptr boxp;
  157338. register int i;
  157339. register long maxc = 0;
  157340. boxptr which = NULL;
  157341. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157342. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157343. which = boxp;
  157344. maxc = boxp->colorcount;
  157345. }
  157346. }
  157347. return which;
  157348. }
  157349. LOCAL(boxptr)
  157350. find_biggest_volume (boxptr boxlist, int numboxes)
  157351. {
  157352. register boxptr boxp;
  157353. register int i;
  157354. register INT32 maxv = 0;
  157355. boxptr which = NULL;
  157356. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157357. if (boxp->volume > maxv) {
  157358. which = boxp;
  157359. maxv = boxp->volume;
  157360. }
  157361. }
  157362. return which;
  157363. }
  157364. LOCAL(void)
  157365. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157366. {
  157367. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157368. hist3d histogram = cquantize->histogram;
  157369. histptr histp;
  157370. int c0,c1,c2;
  157371. int c0min,c0max,c1min,c1max,c2min,c2max;
  157372. INT32 dist0,dist1,dist2;
  157373. long ccount;
  157374. c0min = boxp->c0min; c0max = boxp->c0max;
  157375. c1min = boxp->c1min; c1max = boxp->c1max;
  157376. c2min = boxp->c2min; c2max = boxp->c2max;
  157377. if (c0max > c0min)
  157378. for (c0 = c0min; c0 <= c0max; c0++)
  157379. for (c1 = c1min; c1 <= c1max; c1++) {
  157380. histp = & histogram[c0][c1][c2min];
  157381. for (c2 = c2min; c2 <= c2max; c2++)
  157382. if (*histp++ != 0) {
  157383. boxp->c0min = c0min = c0;
  157384. goto have_c0min;
  157385. }
  157386. }
  157387. have_c0min:
  157388. if (c0max > c0min)
  157389. for (c0 = c0max; c0 >= c0min; c0--)
  157390. for (c1 = c1min; c1 <= c1max; c1++) {
  157391. histp = & histogram[c0][c1][c2min];
  157392. for (c2 = c2min; c2 <= c2max; c2++)
  157393. if (*histp++ != 0) {
  157394. boxp->c0max = c0max = c0;
  157395. goto have_c0max;
  157396. }
  157397. }
  157398. have_c0max:
  157399. if (c1max > c1min)
  157400. for (c1 = c1min; c1 <= c1max; c1++)
  157401. for (c0 = c0min; c0 <= c0max; c0++) {
  157402. histp = & histogram[c0][c1][c2min];
  157403. for (c2 = c2min; c2 <= c2max; c2++)
  157404. if (*histp++ != 0) {
  157405. boxp->c1min = c1min = c1;
  157406. goto have_c1min;
  157407. }
  157408. }
  157409. have_c1min:
  157410. if (c1max > c1min)
  157411. for (c1 = c1max; c1 >= c1min; c1--)
  157412. for (c0 = c0min; c0 <= c0max; c0++) {
  157413. histp = & histogram[c0][c1][c2min];
  157414. for (c2 = c2min; c2 <= c2max; c2++)
  157415. if (*histp++ != 0) {
  157416. boxp->c1max = c1max = c1;
  157417. goto have_c1max;
  157418. }
  157419. }
  157420. have_c1max:
  157421. if (c2max > c2min)
  157422. for (c2 = c2min; c2 <= c2max; c2++)
  157423. for (c0 = c0min; c0 <= c0max; c0++) {
  157424. histp = & histogram[c0][c1min][c2];
  157425. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157426. if (*histp != 0) {
  157427. boxp->c2min = c2min = c2;
  157428. goto have_c2min;
  157429. }
  157430. }
  157431. have_c2min:
  157432. if (c2max > c2min)
  157433. for (c2 = c2max; c2 >= c2min; c2--)
  157434. for (c0 = c0min; c0 <= c0max; c0++) {
  157435. histp = & histogram[c0][c1min][c2];
  157436. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157437. if (*histp != 0) {
  157438. boxp->c2max = c2max = c2;
  157439. goto have_c2max;
  157440. }
  157441. }
  157442. have_c2max:
  157443. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157444. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157445. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157446. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157447. ccount = 0;
  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++, histp++)
  157452. if (*histp != 0) {
  157453. ccount++;
  157454. }
  157455. }
  157456. boxp->colorcount = ccount;
  157457. }
  157458. LOCAL(int)
  157459. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157460. int desired_colors)
  157461. {
  157462. int n,lb;
  157463. int c0,c1,c2,cmax;
  157464. register boxptr b1,b2;
  157465. while (numboxes < desired_colors) {
  157466. if (numboxes*2 <= desired_colors) {
  157467. b1 = find_biggest_color_pop(boxlist, numboxes);
  157468. } else {
  157469. b1 = find_biggest_volume(boxlist, numboxes);
  157470. }
  157471. if (b1 == NULL) /* no splittable boxes left! */
  157472. break;
  157473. b2 = &boxlist[numboxes]; /* where new box will go */
  157474. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157475. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157476. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157477. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157478. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157479. #if RGB_RED == 0
  157480. cmax = c1; n = 1;
  157481. if (c0 > cmax) { cmax = c0; n = 0; }
  157482. if (c2 > cmax) { n = 2; }
  157483. #else
  157484. cmax = c1; n = 1;
  157485. if (c2 > cmax) { cmax = c2; n = 2; }
  157486. if (c0 > cmax) { n = 0; }
  157487. #endif
  157488. switch (n) {
  157489. case 0:
  157490. lb = (b1->c0max + b1->c0min) / 2;
  157491. b1->c0max = lb;
  157492. b2->c0min = lb+1;
  157493. break;
  157494. case 1:
  157495. lb = (b1->c1max + b1->c1min) / 2;
  157496. b1->c1max = lb;
  157497. b2->c1min = lb+1;
  157498. break;
  157499. case 2:
  157500. lb = (b1->c2max + b1->c2min) / 2;
  157501. b1->c2max = lb;
  157502. b2->c2min = lb+1;
  157503. break;
  157504. }
  157505. update_box(cinfo, b1);
  157506. update_box(cinfo, b2);
  157507. numboxes++;
  157508. }
  157509. return numboxes;
  157510. }
  157511. LOCAL(void)
  157512. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157513. {
  157514. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157515. hist3d histogram = cquantize->histogram;
  157516. histptr histp;
  157517. int c0,c1,c2;
  157518. int c0min,c0max,c1min,c1max,c2min,c2max;
  157519. long count;
  157520. long total = 0;
  157521. long c0total = 0;
  157522. long c1total = 0;
  157523. long c2total = 0;
  157524. c0min = boxp->c0min; c0max = boxp->c0max;
  157525. c1min = boxp->c1min; c1max = boxp->c1max;
  157526. c2min = boxp->c2min; c2max = boxp->c2max;
  157527. for (c0 = c0min; c0 <= c0max; c0++)
  157528. for (c1 = c1min; c1 <= c1max; c1++) {
  157529. histp = & histogram[c0][c1][c2min];
  157530. for (c2 = c2min; c2 <= c2max; c2++) {
  157531. if ((count = *histp++) != 0) {
  157532. total += count;
  157533. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157534. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157535. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157536. }
  157537. }
  157538. }
  157539. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157540. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157541. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157542. }
  157543. LOCAL(void)
  157544. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157545. {
  157546. boxptr boxlist;
  157547. int numboxes;
  157548. int i;
  157549. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157550. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157551. numboxes = 1;
  157552. boxlist[0].c0min = 0;
  157553. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157554. boxlist[0].c1min = 0;
  157555. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157556. boxlist[0].c2min = 0;
  157557. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157558. update_box(cinfo, & boxlist[0]);
  157559. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157560. for (i = 0; i < numboxes; i++)
  157561. compute_color(cinfo, & boxlist[i], i);
  157562. cinfo->actual_number_of_colors = numboxes;
  157563. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157564. }
  157565. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157566. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157567. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157568. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157569. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157570. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157571. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157572. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157573. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157574. LOCAL(int)
  157575. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157576. JSAMPLE colorlist[])
  157577. {
  157578. int numcolors = cinfo->actual_number_of_colors;
  157579. int maxc0, maxc1, maxc2;
  157580. int centerc0, centerc1, centerc2;
  157581. int i, x, ncolors;
  157582. INT32 minmaxdist, min_dist, max_dist, tdist;
  157583. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157584. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157585. centerc0 = (minc0 + maxc0) >> 1;
  157586. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157587. centerc1 = (minc1 + maxc1) >> 1;
  157588. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157589. centerc2 = (minc2 + maxc2) >> 1;
  157590. minmaxdist = 0x7FFFFFFFL;
  157591. for (i = 0; i < numcolors; i++) {
  157592. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157593. if (x < minc0) {
  157594. tdist = (x - minc0) * C0_SCALE;
  157595. min_dist = tdist*tdist;
  157596. tdist = (x - maxc0) * C0_SCALE;
  157597. max_dist = tdist*tdist;
  157598. } else if (x > maxc0) {
  157599. tdist = (x - maxc0) * C0_SCALE;
  157600. min_dist = tdist*tdist;
  157601. tdist = (x - minc0) * C0_SCALE;
  157602. max_dist = tdist*tdist;
  157603. } else {
  157604. min_dist = 0;
  157605. if (x <= centerc0) {
  157606. tdist = (x - maxc0) * C0_SCALE;
  157607. max_dist = tdist*tdist;
  157608. } else {
  157609. tdist = (x - minc0) * C0_SCALE;
  157610. max_dist = tdist*tdist;
  157611. }
  157612. }
  157613. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157614. if (x < minc1) {
  157615. tdist = (x - minc1) * C1_SCALE;
  157616. min_dist += tdist*tdist;
  157617. tdist = (x - maxc1) * C1_SCALE;
  157618. max_dist += tdist*tdist;
  157619. } else if (x > maxc1) {
  157620. tdist = (x - maxc1) * C1_SCALE;
  157621. min_dist += tdist*tdist;
  157622. tdist = (x - minc1) * C1_SCALE;
  157623. max_dist += tdist*tdist;
  157624. } else {
  157625. if (x <= centerc1) {
  157626. tdist = (x - maxc1) * C1_SCALE;
  157627. max_dist += tdist*tdist;
  157628. } else {
  157629. tdist = (x - minc1) * C1_SCALE;
  157630. max_dist += tdist*tdist;
  157631. }
  157632. }
  157633. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157634. if (x < minc2) {
  157635. tdist = (x - minc2) * C2_SCALE;
  157636. min_dist += tdist*tdist;
  157637. tdist = (x - maxc2) * C2_SCALE;
  157638. max_dist += tdist*tdist;
  157639. } else if (x > maxc2) {
  157640. tdist = (x - maxc2) * C2_SCALE;
  157641. min_dist += tdist*tdist;
  157642. tdist = (x - minc2) * C2_SCALE;
  157643. max_dist += tdist*tdist;
  157644. } else {
  157645. if (x <= centerc2) {
  157646. tdist = (x - maxc2) * C2_SCALE;
  157647. max_dist += tdist*tdist;
  157648. } else {
  157649. tdist = (x - minc2) * C2_SCALE;
  157650. max_dist += tdist*tdist;
  157651. }
  157652. }
  157653. mindist[i] = min_dist; /* save away the results */
  157654. if (max_dist < minmaxdist)
  157655. minmaxdist = max_dist;
  157656. }
  157657. ncolors = 0;
  157658. for (i = 0; i < numcolors; i++) {
  157659. if (mindist[i] <= minmaxdist)
  157660. colorlist[ncolors++] = (JSAMPLE) i;
  157661. }
  157662. return ncolors;
  157663. }
  157664. LOCAL(void)
  157665. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157666. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157667. {
  157668. int ic0, ic1, ic2;
  157669. int i, icolor;
  157670. register INT32 * bptr; /* pointer into bestdist[] array */
  157671. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157672. INT32 dist0, dist1; /* initial distance values */
  157673. register INT32 dist2; /* current distance in inner loop */
  157674. INT32 xx0, xx1; /* distance increments */
  157675. register INT32 xx2;
  157676. INT32 inc0, inc1, inc2; /* initial values for increments */
  157677. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157678. bptr = bestdist;
  157679. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157680. *bptr++ = 0x7FFFFFFFL;
  157681. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157682. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157683. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157684. for (i = 0; i < numcolors; i++) {
  157685. icolor = GETJSAMPLE(colorlist[i]);
  157686. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157687. dist0 = inc0*inc0;
  157688. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157689. dist0 += inc1*inc1;
  157690. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157691. dist0 += inc2*inc2;
  157692. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157693. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157694. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157695. bptr = bestdist;
  157696. cptr = bestcolor;
  157697. xx0 = inc0;
  157698. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157699. dist1 = dist0;
  157700. xx1 = inc1;
  157701. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157702. dist2 = dist1;
  157703. xx2 = inc2;
  157704. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157705. if (dist2 < *bptr) {
  157706. *bptr = dist2;
  157707. *cptr = (JSAMPLE) icolor;
  157708. }
  157709. dist2 += xx2;
  157710. xx2 += 2 * STEP_C2 * STEP_C2;
  157711. bptr++;
  157712. cptr++;
  157713. }
  157714. dist1 += xx1;
  157715. xx1 += 2 * STEP_C1 * STEP_C1;
  157716. }
  157717. dist0 += xx0;
  157718. xx0 += 2 * STEP_C0 * STEP_C0;
  157719. }
  157720. }
  157721. }
  157722. LOCAL(void)
  157723. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157724. {
  157725. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157726. hist3d histogram = cquantize->histogram;
  157727. int minc0, minc1, minc2; /* lower left corner of update box */
  157728. int ic0, ic1, ic2;
  157729. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157730. register histptr cachep; /* pointer into main cache array */
  157731. JSAMPLE colorlist[MAXNUMCOLORS];
  157732. int numcolors; /* number of candidate colors */
  157733. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157734. c0 >>= BOX_C0_LOG;
  157735. c1 >>= BOX_C1_LOG;
  157736. c2 >>= BOX_C2_LOG;
  157737. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157738. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157739. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157740. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157741. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157742. bestcolor);
  157743. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157744. c1 <<= BOX_C1_LOG;
  157745. c2 <<= BOX_C2_LOG;
  157746. cptr = bestcolor;
  157747. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157748. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157749. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157750. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157751. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157752. }
  157753. }
  157754. }
  157755. }
  157756. METHODDEF(void)
  157757. pass2_no_dither (j_decompress_ptr cinfo,
  157758. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157759. {
  157760. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157761. hist3d histogram = cquantize->histogram;
  157762. register JSAMPROW inptr, outptr;
  157763. register histptr cachep;
  157764. register int c0, c1, c2;
  157765. int row;
  157766. JDIMENSION col;
  157767. JDIMENSION width = cinfo->output_width;
  157768. for (row = 0; row < num_rows; row++) {
  157769. inptr = input_buf[row];
  157770. outptr = output_buf[row];
  157771. for (col = width; col > 0; col--) {
  157772. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157773. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157774. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157775. cachep = & histogram[c0][c1][c2];
  157776. if (*cachep == 0)
  157777. fill_inverse_cmap(cinfo, c0,c1,c2);
  157778. *outptr++ = (JSAMPLE) (*cachep - 1);
  157779. }
  157780. }
  157781. }
  157782. METHODDEF(void)
  157783. pass2_fs_dither (j_decompress_ptr cinfo,
  157784. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157785. {
  157786. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157787. hist3d histogram = cquantize->histogram;
  157788. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157789. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157790. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157791. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157792. JSAMPROW inptr; /* => current input pixel */
  157793. JSAMPROW outptr; /* => current output pixel */
  157794. histptr cachep;
  157795. int dir; /* +1 or -1 depending on direction */
  157796. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157797. int row;
  157798. JDIMENSION col;
  157799. JDIMENSION width = cinfo->output_width;
  157800. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157801. int *error_limit = cquantize->error_limiter;
  157802. JSAMPROW colormap0 = cinfo->colormap[0];
  157803. JSAMPROW colormap1 = cinfo->colormap[1];
  157804. JSAMPROW colormap2 = cinfo->colormap[2];
  157805. SHIFT_TEMPS
  157806. for (row = 0; row < num_rows; row++) {
  157807. inptr = input_buf[row];
  157808. outptr = output_buf[row];
  157809. if (cquantize->on_odd_row) {
  157810. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157811. outptr += width-1;
  157812. dir = -1;
  157813. dir3 = -3;
  157814. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157815. cquantize->on_odd_row = FALSE; /* flip for next time */
  157816. } else {
  157817. dir = 1;
  157818. dir3 = 3;
  157819. errorptr = cquantize->fserrors; /* => entry before first real column */
  157820. cquantize->on_odd_row = TRUE; /* flip for next time */
  157821. }
  157822. cur0 = cur1 = cur2 = 0;
  157823. belowerr0 = belowerr1 = belowerr2 = 0;
  157824. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157825. for (col = width; col > 0; col--) {
  157826. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157827. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157828. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157829. cur0 = error_limit[cur0];
  157830. cur1 = error_limit[cur1];
  157831. cur2 = error_limit[cur2];
  157832. cur0 += GETJSAMPLE(inptr[0]);
  157833. cur1 += GETJSAMPLE(inptr[1]);
  157834. cur2 += GETJSAMPLE(inptr[2]);
  157835. cur0 = GETJSAMPLE(range_limit[cur0]);
  157836. cur1 = GETJSAMPLE(range_limit[cur1]);
  157837. cur2 = GETJSAMPLE(range_limit[cur2]);
  157838. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157839. if (*cachep == 0)
  157840. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157841. { register int pixcode = *cachep - 1;
  157842. *outptr = (JSAMPLE) pixcode;
  157843. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157844. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157845. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157846. }
  157847. { register LOCFSERROR bnexterr, delta;
  157848. bnexterr = cur0; /* Process component 0 */
  157849. delta = cur0 * 2;
  157850. cur0 += delta; /* form error * 3 */
  157851. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157852. cur0 += delta; /* form error * 5 */
  157853. bpreverr0 = belowerr0 + cur0;
  157854. belowerr0 = bnexterr;
  157855. cur0 += delta; /* form error * 7 */
  157856. bnexterr = cur1; /* Process component 1 */
  157857. delta = cur1 * 2;
  157858. cur1 += delta; /* form error * 3 */
  157859. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157860. cur1 += delta; /* form error * 5 */
  157861. bpreverr1 = belowerr1 + cur1;
  157862. belowerr1 = bnexterr;
  157863. cur1 += delta; /* form error * 7 */
  157864. bnexterr = cur2; /* Process component 2 */
  157865. delta = cur2 * 2;
  157866. cur2 += delta; /* form error * 3 */
  157867. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157868. cur2 += delta; /* form error * 5 */
  157869. bpreverr2 = belowerr2 + cur2;
  157870. belowerr2 = bnexterr;
  157871. cur2 += delta; /* form error * 7 */
  157872. }
  157873. inptr += dir3; /* Advance pixel pointers to next column */
  157874. outptr += dir;
  157875. errorptr += dir3; /* advance errorptr to current column */
  157876. }
  157877. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157878. errorptr[1] = (FSERROR) bpreverr1;
  157879. errorptr[2] = (FSERROR) bpreverr2;
  157880. }
  157881. }
  157882. LOCAL(void)
  157883. init_error_limit (j_decompress_ptr cinfo)
  157884. {
  157885. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157886. int * table;
  157887. int in, out;
  157888. table = (int *) (*cinfo->mem->alloc_small)
  157889. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157890. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157891. cquantize->error_limiter = table;
  157892. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157893. out = 0;
  157894. for (in = 0; in < STEPSIZE; in++, out++) {
  157895. table[in] = out; table[-in] = -out;
  157896. }
  157897. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157898. table[in] = out; table[-in] = -out;
  157899. }
  157900. for (; in <= MAXJSAMPLE; in++) {
  157901. table[in] = out; table[-in] = -out;
  157902. }
  157903. #undef STEPSIZE
  157904. }
  157905. METHODDEF(void)
  157906. finish_pass1 (j_decompress_ptr cinfo)
  157907. {
  157908. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157909. cinfo->colormap = cquantize->sv_colormap;
  157910. select_colors(cinfo, cquantize->desired);
  157911. cquantize->needs_zeroed = TRUE;
  157912. }
  157913. METHODDEF(void)
  157914. finish_pass2 (j_decompress_ptr cinfo)
  157915. {
  157916. }
  157917. METHODDEF(void)
  157918. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157919. {
  157920. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157921. hist3d histogram = cquantize->histogram;
  157922. int i;
  157923. if (cinfo->dither_mode != JDITHER_NONE)
  157924. cinfo->dither_mode = JDITHER_FS;
  157925. if (is_pre_scan) {
  157926. cquantize->pub.color_quantize = prescan_quantize;
  157927. cquantize->pub.finish_pass = finish_pass1;
  157928. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157929. } else {
  157930. if (cinfo->dither_mode == JDITHER_FS)
  157931. cquantize->pub.color_quantize = pass2_fs_dither;
  157932. else
  157933. cquantize->pub.color_quantize = pass2_no_dither;
  157934. cquantize->pub.finish_pass = finish_pass2;
  157935. i = cinfo->actual_number_of_colors;
  157936. if (i < 1)
  157937. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  157938. if (i > MAXNUMCOLORS)
  157939. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157940. if (cinfo->dither_mode == JDITHER_FS) {
  157941. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  157942. (3 * SIZEOF(FSERROR)));
  157943. if (cquantize->fserrors == NULL)
  157944. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157945. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157946. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  157947. if (cquantize->error_limiter == NULL)
  157948. init_error_limit(cinfo);
  157949. cquantize->on_odd_row = FALSE;
  157950. }
  157951. }
  157952. if (cquantize->needs_zeroed) {
  157953. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157954. jzero_far((void FAR *) histogram[i],
  157955. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157956. }
  157957. cquantize->needs_zeroed = FALSE;
  157958. }
  157959. }
  157960. METHODDEF(void)
  157961. new_color_map_2_quant (j_decompress_ptr cinfo)
  157962. {
  157963. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157964. cquantize->needs_zeroed = TRUE;
  157965. }
  157966. GLOBAL(void)
  157967. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  157968. {
  157969. my_cquantize_ptr2 cquantize;
  157970. int i;
  157971. cquantize = (my_cquantize_ptr2)
  157972. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157973. SIZEOF(my_cquantizer2));
  157974. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157975. cquantize->pub.start_pass = start_pass_2_quant;
  157976. cquantize->pub.new_color_map = new_color_map_2_quant;
  157977. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  157978. cquantize->error_limiter = NULL;
  157979. if (cinfo->out_color_components != 3)
  157980. ERREXIT(cinfo, JERR_NOTIMPL);
  157981. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  157982. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  157983. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157984. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  157985. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157986. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157987. }
  157988. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  157989. if (cinfo->enable_2pass_quant) {
  157990. int desired = cinfo->desired_number_of_colors;
  157991. if (desired < 8)
  157992. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  157993. if (desired > MAXNUMCOLORS)
  157994. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157995. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  157996. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  157997. cquantize->desired = desired;
  157998. } else
  157999. cquantize->sv_colormap = NULL;
  158000. if (cinfo->dither_mode != JDITHER_NONE)
  158001. cinfo->dither_mode = JDITHER_FS;
  158002. if (cinfo->dither_mode == JDITHER_FS) {
  158003. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158004. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158005. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158006. init_error_limit(cinfo);
  158007. }
  158008. }
  158009. #endif /* QUANT_2PASS_SUPPORTED */
  158010. /*** End of inlined file: jquant2.c ***/
  158011. /*** Start of inlined file: jutils.c ***/
  158012. #define JPEG_INTERNALS
  158013. #if 0 /* This table is not actually needed in v6a */
  158014. const int jpeg_zigzag_order[DCTSIZE2] = {
  158015. 0, 1, 5, 6, 14, 15, 27, 28,
  158016. 2, 4, 7, 13, 16, 26, 29, 42,
  158017. 3, 8, 12, 17, 25, 30, 41, 43,
  158018. 9, 11, 18, 24, 31, 40, 44, 53,
  158019. 10, 19, 23, 32, 39, 45, 52, 54,
  158020. 20, 22, 33, 38, 46, 51, 55, 60,
  158021. 21, 34, 37, 47, 50, 56, 59, 61,
  158022. 35, 36, 48, 49, 57, 58, 62, 63
  158023. };
  158024. #endif
  158025. const int jpeg_natural_order[DCTSIZE2+16] = {
  158026. 0, 1, 8, 16, 9, 2, 3, 10,
  158027. 17, 24, 32, 25, 18, 11, 4, 5,
  158028. 12, 19, 26, 33, 40, 48, 41, 34,
  158029. 27, 20, 13, 6, 7, 14, 21, 28,
  158030. 35, 42, 49, 56, 57, 50, 43, 36,
  158031. 29, 22, 15, 23, 30, 37, 44, 51,
  158032. 58, 59, 52, 45, 38, 31, 39, 46,
  158033. 53, 60, 61, 54, 47, 55, 62, 63,
  158034. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158035. 63, 63, 63, 63, 63, 63, 63, 63
  158036. };
  158037. GLOBAL(long)
  158038. jdiv_round_up (long a, long b)
  158039. {
  158040. return (a + b - 1L) / b;
  158041. }
  158042. GLOBAL(long)
  158043. jround_up (long a, long b)
  158044. {
  158045. a += b - 1L;
  158046. return a - (a % b);
  158047. }
  158048. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158049. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158050. #define FMEMZERO(target,size) MEMZERO(target,size)
  158051. #else /* 80x86 case, define if we can */
  158052. #ifdef USE_FMEM
  158053. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158054. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158055. #endif
  158056. #endif
  158057. GLOBAL(void)
  158058. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158059. JSAMPARRAY output_array, int dest_row,
  158060. int num_rows, JDIMENSION num_cols)
  158061. {
  158062. register JSAMPROW inptr, outptr;
  158063. #ifdef FMEMCOPY
  158064. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158065. #else
  158066. register JDIMENSION count;
  158067. #endif
  158068. register int row;
  158069. input_array += source_row;
  158070. output_array += dest_row;
  158071. for (row = num_rows; row > 0; row--) {
  158072. inptr = *input_array++;
  158073. outptr = *output_array++;
  158074. #ifdef FMEMCOPY
  158075. FMEMCOPY(outptr, inptr, count);
  158076. #else
  158077. for (count = num_cols; count > 0; count--)
  158078. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158079. #endif
  158080. }
  158081. }
  158082. GLOBAL(void)
  158083. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158084. JDIMENSION num_blocks)
  158085. {
  158086. #ifdef FMEMCOPY
  158087. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158088. #else
  158089. register JCOEFPTR inptr, outptr;
  158090. register long count;
  158091. inptr = (JCOEFPTR) input_row;
  158092. outptr = (JCOEFPTR) output_row;
  158093. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158094. *outptr++ = *inptr++;
  158095. }
  158096. #endif
  158097. }
  158098. GLOBAL(void)
  158099. jzero_far (void FAR * target, size_t bytestozero)
  158100. {
  158101. #ifdef FMEMZERO
  158102. FMEMZERO(target, bytestozero);
  158103. #else
  158104. register char FAR * ptr = (char FAR *) target;
  158105. register size_t count;
  158106. for (count = bytestozero; count > 0; count--) {
  158107. *ptr++ = 0;
  158108. }
  158109. #endif
  158110. }
  158111. /*** End of inlined file: jutils.c ***/
  158112. /*** Start of inlined file: transupp.c ***/
  158113. #define JPEG_INTERNALS
  158114. /*** Start of inlined file: transupp.h ***/
  158115. #ifndef TRANSFORMS_SUPPORTED
  158116. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158117. #endif
  158118. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158119. #define jtransform_request_workspace jTrRequest
  158120. #define jtransform_adjust_parameters jTrAdjust
  158121. #define jtransform_execute_transformation jTrExec
  158122. #define jcopy_markers_setup jCMrkSetup
  158123. #define jcopy_markers_execute jCMrkExec
  158124. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158125. typedef enum {
  158126. JXFORM_NONE, /* no transformation */
  158127. JXFORM_FLIP_H, /* horizontal flip */
  158128. JXFORM_FLIP_V, /* vertical flip */
  158129. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158130. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158131. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158132. JXFORM_ROT_180, /* 180-degree rotation */
  158133. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158134. } JXFORM_CODE;
  158135. typedef struct {
  158136. JXFORM_CODE transform; /* image transform operator */
  158137. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158138. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158139. int num_components; /* # of components in workspace */
  158140. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158141. } jpeg_transform_info;
  158142. #if TRANSFORMS_SUPPORTED
  158143. EXTERN(void) jtransform_request_workspace
  158144. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158145. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158146. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158147. jvirt_barray_ptr *src_coef_arrays,
  158148. jpeg_transform_info *info));
  158149. EXTERN(void) jtransform_execute_transformation
  158150. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158151. jvirt_barray_ptr *src_coef_arrays,
  158152. jpeg_transform_info *info));
  158153. #endif /* TRANSFORMS_SUPPORTED */
  158154. typedef enum {
  158155. JCOPYOPT_NONE, /* copy no optional markers */
  158156. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158157. JCOPYOPT_ALL /* copy all optional markers */
  158158. } JCOPY_OPTION;
  158159. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158160. EXTERN(void) jcopy_markers_setup
  158161. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158162. EXTERN(void) jcopy_markers_execute
  158163. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158164. JCOPY_OPTION option));
  158165. /*** End of inlined file: transupp.h ***/
  158166. /* My own external interface */
  158167. #if TRANSFORMS_SUPPORTED
  158168. LOCAL(void)
  158169. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158170. jvirt_barray_ptr *src_coef_arrays)
  158171. {
  158172. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158173. int ci, k, offset_y;
  158174. JBLOCKARRAY buffer;
  158175. JCOEFPTR ptr1, ptr2;
  158176. JCOEF temp1, temp2;
  158177. jpeg_component_info *compptr;
  158178. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158179. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158180. compptr = dstinfo->comp_info + ci;
  158181. comp_width = MCU_cols * compptr->h_samp_factor;
  158182. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158183. blk_y += compptr->v_samp_factor) {
  158184. buffer = (*srcinfo->mem->access_virt_barray)
  158185. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158186. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158187. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158188. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158189. ptr1 = buffer[offset_y][blk_x];
  158190. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158191. for (k = 0; k < DCTSIZE2; k += 2) {
  158192. temp1 = *ptr1; /* swap even column */
  158193. temp2 = *ptr2;
  158194. *ptr1++ = temp2;
  158195. *ptr2++ = temp1;
  158196. temp1 = *ptr1; /* swap odd column with sign change */
  158197. temp2 = *ptr2;
  158198. *ptr1++ = -temp2;
  158199. *ptr2++ = -temp1;
  158200. }
  158201. }
  158202. }
  158203. }
  158204. }
  158205. }
  158206. LOCAL(void)
  158207. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158208. jvirt_barray_ptr *src_coef_arrays,
  158209. jvirt_barray_ptr *dst_coef_arrays)
  158210. {
  158211. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158212. int ci, i, j, offset_y;
  158213. JBLOCKARRAY src_buffer, dst_buffer;
  158214. JBLOCKROW src_row_ptr, dst_row_ptr;
  158215. JCOEFPTR src_ptr, dst_ptr;
  158216. jpeg_component_info *compptr;
  158217. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158218. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158219. compptr = dstinfo->comp_info + ci;
  158220. comp_height = MCU_rows * compptr->v_samp_factor;
  158221. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158222. dst_blk_y += compptr->v_samp_factor) {
  158223. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158224. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158225. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158226. if (dst_blk_y < comp_height) {
  158227. src_buffer = (*srcinfo->mem->access_virt_barray)
  158228. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158229. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158230. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158231. } else {
  158232. src_buffer = (*srcinfo->mem->access_virt_barray)
  158233. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158234. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158235. }
  158236. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158237. if (dst_blk_y < comp_height) {
  158238. dst_row_ptr = dst_buffer[offset_y];
  158239. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158240. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158241. dst_blk_x++) {
  158242. dst_ptr = dst_row_ptr[dst_blk_x];
  158243. src_ptr = src_row_ptr[dst_blk_x];
  158244. for (i = 0; i < DCTSIZE; i += 2) {
  158245. for (j = 0; j < DCTSIZE; j++)
  158246. *dst_ptr++ = *src_ptr++;
  158247. for (j = 0; j < DCTSIZE; j++)
  158248. *dst_ptr++ = - *src_ptr++;
  158249. }
  158250. }
  158251. } else {
  158252. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158253. compptr->width_in_blocks);
  158254. }
  158255. }
  158256. }
  158257. }
  158258. }
  158259. LOCAL(void)
  158260. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158261. jvirt_barray_ptr *src_coef_arrays,
  158262. jvirt_barray_ptr *dst_coef_arrays)
  158263. {
  158264. JDIMENSION dst_blk_x, dst_blk_y;
  158265. int ci, i, j, offset_x, offset_y;
  158266. JBLOCKARRAY src_buffer, dst_buffer;
  158267. JCOEFPTR src_ptr, dst_ptr;
  158268. jpeg_component_info *compptr;
  158269. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158270. compptr = dstinfo->comp_info + ci;
  158271. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158272. dst_blk_y += compptr->v_samp_factor) {
  158273. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158274. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158275. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158276. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158277. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158278. dst_blk_x += compptr->h_samp_factor) {
  158279. src_buffer = (*srcinfo->mem->access_virt_barray)
  158280. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158281. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158282. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158283. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158284. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158285. for (i = 0; i < DCTSIZE; i++)
  158286. for (j = 0; j < DCTSIZE; j++)
  158287. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158288. }
  158289. }
  158290. }
  158291. }
  158292. }
  158293. }
  158294. LOCAL(void)
  158295. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158296. jvirt_barray_ptr *src_coef_arrays,
  158297. jvirt_barray_ptr *dst_coef_arrays)
  158298. {
  158299. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158300. int ci, i, j, offset_x, offset_y;
  158301. JBLOCKARRAY src_buffer, dst_buffer;
  158302. JCOEFPTR src_ptr, dst_ptr;
  158303. jpeg_component_info *compptr;
  158304. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158305. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158306. compptr = dstinfo->comp_info + ci;
  158307. comp_width = MCU_cols * compptr->h_samp_factor;
  158308. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158309. dst_blk_y += compptr->v_samp_factor) {
  158310. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158311. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158312. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158313. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158314. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158315. dst_blk_x += compptr->h_samp_factor) {
  158316. src_buffer = (*srcinfo->mem->access_virt_barray)
  158317. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158318. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158319. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158320. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158321. if (dst_blk_x < comp_width) {
  158322. dst_ptr = dst_buffer[offset_y]
  158323. [comp_width - dst_blk_x - offset_x - 1];
  158324. for (i = 0; i < DCTSIZE; i++) {
  158325. for (j = 0; j < DCTSIZE; j++)
  158326. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158327. i++;
  158328. for (j = 0; j < DCTSIZE; j++)
  158329. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158330. }
  158331. } else {
  158332. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158333. for (i = 0; i < DCTSIZE; i++)
  158334. for (j = 0; j < DCTSIZE; j++)
  158335. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158336. }
  158337. }
  158338. }
  158339. }
  158340. }
  158341. }
  158342. }
  158343. LOCAL(void)
  158344. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158345. jvirt_barray_ptr *src_coef_arrays,
  158346. jvirt_barray_ptr *dst_coef_arrays)
  158347. {
  158348. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158349. int ci, i, j, offset_x, offset_y;
  158350. JBLOCKARRAY src_buffer, dst_buffer;
  158351. JCOEFPTR src_ptr, dst_ptr;
  158352. jpeg_component_info *compptr;
  158353. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158354. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158355. compptr = dstinfo->comp_info + ci;
  158356. comp_height = MCU_rows * compptr->v_samp_factor;
  158357. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158358. dst_blk_y += compptr->v_samp_factor) {
  158359. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158360. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158361. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158362. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158363. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158364. dst_blk_x += compptr->h_samp_factor) {
  158365. src_buffer = (*srcinfo->mem->access_virt_barray)
  158366. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158367. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158368. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158369. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158370. if (dst_blk_y < comp_height) {
  158371. src_ptr = src_buffer[offset_x]
  158372. [comp_height - dst_blk_y - offset_y - 1];
  158373. for (i = 0; i < DCTSIZE; i++) {
  158374. for (j = 0; j < DCTSIZE; j++) {
  158375. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158376. j++;
  158377. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158378. }
  158379. }
  158380. } else {
  158381. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158382. for (i = 0; i < DCTSIZE; i++)
  158383. for (j = 0; j < DCTSIZE; j++)
  158384. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158385. }
  158386. }
  158387. }
  158388. }
  158389. }
  158390. }
  158391. }
  158392. LOCAL(void)
  158393. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158394. jvirt_barray_ptr *src_coef_arrays,
  158395. jvirt_barray_ptr *dst_coef_arrays)
  158396. {
  158397. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158398. int ci, i, j, offset_y;
  158399. JBLOCKARRAY src_buffer, dst_buffer;
  158400. JBLOCKROW src_row_ptr, dst_row_ptr;
  158401. JCOEFPTR src_ptr, dst_ptr;
  158402. jpeg_component_info *compptr;
  158403. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158404. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158405. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158406. compptr = dstinfo->comp_info + ci;
  158407. comp_width = MCU_cols * compptr->h_samp_factor;
  158408. comp_height = MCU_rows * compptr->v_samp_factor;
  158409. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158410. dst_blk_y += compptr->v_samp_factor) {
  158411. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158412. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158413. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158414. if (dst_blk_y < comp_height) {
  158415. src_buffer = (*srcinfo->mem->access_virt_barray)
  158416. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158417. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158418. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158419. } else {
  158420. src_buffer = (*srcinfo->mem->access_virt_barray)
  158421. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158422. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158423. }
  158424. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158425. if (dst_blk_y < comp_height) {
  158426. dst_row_ptr = dst_buffer[offset_y];
  158427. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158428. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158429. dst_ptr = dst_row_ptr[dst_blk_x];
  158430. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158431. for (i = 0; i < DCTSIZE; i += 2) {
  158432. for (j = 0; j < DCTSIZE; j += 2) {
  158433. *dst_ptr++ = *src_ptr++;
  158434. *dst_ptr++ = - *src_ptr++;
  158435. }
  158436. for (j = 0; j < DCTSIZE; j += 2) {
  158437. *dst_ptr++ = - *src_ptr++;
  158438. *dst_ptr++ = *src_ptr++;
  158439. }
  158440. }
  158441. }
  158442. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158443. dst_ptr = dst_row_ptr[dst_blk_x];
  158444. src_ptr = src_row_ptr[dst_blk_x];
  158445. for (i = 0; i < DCTSIZE; i += 2) {
  158446. for (j = 0; j < DCTSIZE; j++)
  158447. *dst_ptr++ = *src_ptr++;
  158448. for (j = 0; j < DCTSIZE; j++)
  158449. *dst_ptr++ = - *src_ptr++;
  158450. }
  158451. }
  158452. } else {
  158453. dst_row_ptr = dst_buffer[offset_y];
  158454. src_row_ptr = src_buffer[offset_y];
  158455. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158456. dst_ptr = dst_row_ptr[dst_blk_x];
  158457. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158458. for (i = 0; i < DCTSIZE2; i += 2) {
  158459. *dst_ptr++ = *src_ptr++;
  158460. *dst_ptr++ = - *src_ptr++;
  158461. }
  158462. }
  158463. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158464. dst_ptr = dst_row_ptr[dst_blk_x];
  158465. src_ptr = src_row_ptr[dst_blk_x];
  158466. for (i = 0; i < DCTSIZE2; i++)
  158467. *dst_ptr++ = *src_ptr++;
  158468. }
  158469. }
  158470. }
  158471. }
  158472. }
  158473. }
  158474. LOCAL(void)
  158475. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158476. jvirt_barray_ptr *src_coef_arrays,
  158477. jvirt_barray_ptr *dst_coef_arrays)
  158478. {
  158479. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158480. int ci, i, j, offset_x, offset_y;
  158481. JBLOCKARRAY src_buffer, dst_buffer;
  158482. JCOEFPTR src_ptr, dst_ptr;
  158483. jpeg_component_info *compptr;
  158484. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158485. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158486. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158487. compptr = dstinfo->comp_info + ci;
  158488. comp_width = MCU_cols * compptr->h_samp_factor;
  158489. comp_height = MCU_rows * compptr->v_samp_factor;
  158490. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158491. dst_blk_y += compptr->v_samp_factor) {
  158492. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158493. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158494. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158495. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158496. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158497. dst_blk_x += compptr->h_samp_factor) {
  158498. src_buffer = (*srcinfo->mem->access_virt_barray)
  158499. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158500. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158501. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158502. if (dst_blk_y < comp_height) {
  158503. src_ptr = src_buffer[offset_x]
  158504. [comp_height - dst_blk_y - offset_y - 1];
  158505. if (dst_blk_x < comp_width) {
  158506. dst_ptr = dst_buffer[offset_y]
  158507. [comp_width - dst_blk_x - offset_x - 1];
  158508. for (i = 0; i < DCTSIZE; i++) {
  158509. for (j = 0; j < DCTSIZE; j++) {
  158510. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158511. j++;
  158512. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158513. }
  158514. i++;
  158515. for (j = 0; j < DCTSIZE; j++) {
  158516. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158517. j++;
  158518. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158519. }
  158520. }
  158521. } else {
  158522. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158523. for (i = 0; i < DCTSIZE; i++) {
  158524. for (j = 0; j < DCTSIZE; j++) {
  158525. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158526. j++;
  158527. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158528. }
  158529. }
  158530. }
  158531. } else {
  158532. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158533. if (dst_blk_x < comp_width) {
  158534. dst_ptr = dst_buffer[offset_y]
  158535. [comp_width - dst_blk_x - offset_x - 1];
  158536. for (i = 0; i < DCTSIZE; i++) {
  158537. for (j = 0; j < DCTSIZE; j++)
  158538. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158539. i++;
  158540. for (j = 0; j < DCTSIZE; j++)
  158541. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158542. }
  158543. } else {
  158544. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158545. for (i = 0; i < DCTSIZE; i++)
  158546. for (j = 0; j < DCTSIZE; j++)
  158547. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158548. }
  158549. }
  158550. }
  158551. }
  158552. }
  158553. }
  158554. }
  158555. }
  158556. GLOBAL(void)
  158557. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158558. jpeg_transform_info *info)
  158559. {
  158560. jvirt_barray_ptr *coef_arrays = NULL;
  158561. jpeg_component_info *compptr;
  158562. int ci;
  158563. if (info->force_grayscale &&
  158564. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158565. srcinfo->num_components == 3) {
  158566. info->num_components = 1;
  158567. } else {
  158568. info->num_components = srcinfo->num_components;
  158569. }
  158570. switch (info->transform) {
  158571. case JXFORM_NONE:
  158572. case JXFORM_FLIP_H:
  158573. break;
  158574. case JXFORM_FLIP_V:
  158575. case JXFORM_ROT_180:
  158576. coef_arrays = (jvirt_barray_ptr *)
  158577. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158578. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158579. for (ci = 0; ci < info->num_components; ci++) {
  158580. compptr = srcinfo->comp_info + ci;
  158581. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158582. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158583. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158584. (long) compptr->h_samp_factor),
  158585. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158586. (long) compptr->v_samp_factor),
  158587. (JDIMENSION) compptr->v_samp_factor);
  158588. }
  158589. break;
  158590. case JXFORM_TRANSPOSE:
  158591. case JXFORM_TRANSVERSE:
  158592. case JXFORM_ROT_90:
  158593. case JXFORM_ROT_270:
  158594. coef_arrays = (jvirt_barray_ptr *)
  158595. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158596. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158597. for (ci = 0; ci < info->num_components; ci++) {
  158598. compptr = srcinfo->comp_info + ci;
  158599. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158600. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158601. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158602. (long) compptr->v_samp_factor),
  158603. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158604. (long) compptr->h_samp_factor),
  158605. (JDIMENSION) compptr->h_samp_factor);
  158606. }
  158607. break;
  158608. }
  158609. info->workspace_coef_arrays = coef_arrays;
  158610. }
  158611. LOCAL(void)
  158612. transpose_critical_parameters (j_compress_ptr dstinfo)
  158613. {
  158614. int tblno, i, j, ci, itemp;
  158615. jpeg_component_info *compptr;
  158616. JQUANT_TBL *qtblptr;
  158617. JDIMENSION dtemp;
  158618. UINT16 qtemp;
  158619. dtemp = dstinfo->image_width;
  158620. dstinfo->image_width = dstinfo->image_height;
  158621. dstinfo->image_height = dtemp;
  158622. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158623. compptr = dstinfo->comp_info + ci;
  158624. itemp = compptr->h_samp_factor;
  158625. compptr->h_samp_factor = compptr->v_samp_factor;
  158626. compptr->v_samp_factor = itemp;
  158627. }
  158628. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158629. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158630. if (qtblptr != NULL) {
  158631. for (i = 0; i < DCTSIZE; i++) {
  158632. for (j = 0; j < i; j++) {
  158633. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158634. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158635. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158636. }
  158637. }
  158638. }
  158639. }
  158640. }
  158641. LOCAL(void)
  158642. trim_right_edge (j_compress_ptr dstinfo)
  158643. {
  158644. int ci, max_h_samp_factor;
  158645. JDIMENSION MCU_cols;
  158646. max_h_samp_factor = 1;
  158647. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158648. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158649. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158650. }
  158651. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158652. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158653. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158654. }
  158655. LOCAL(void)
  158656. trim_bottom_edge (j_compress_ptr dstinfo)
  158657. {
  158658. int ci, max_v_samp_factor;
  158659. JDIMENSION MCU_rows;
  158660. max_v_samp_factor = 1;
  158661. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158662. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158663. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158664. }
  158665. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158666. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158667. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158668. }
  158669. GLOBAL(jvirt_barray_ptr *)
  158670. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158671. j_compress_ptr dstinfo,
  158672. jvirt_barray_ptr *src_coef_arrays,
  158673. jpeg_transform_info *info)
  158674. {
  158675. if (info->force_grayscale) {
  158676. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158677. dstinfo->num_components == 3) ||
  158678. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158679. dstinfo->num_components == 1)) {
  158680. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158681. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158682. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158683. } else {
  158684. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158685. }
  158686. }
  158687. switch (info->transform) {
  158688. case JXFORM_NONE:
  158689. break;
  158690. case JXFORM_FLIP_H:
  158691. if (info->trim)
  158692. trim_right_edge(dstinfo);
  158693. break;
  158694. case JXFORM_FLIP_V:
  158695. if (info->trim)
  158696. trim_bottom_edge(dstinfo);
  158697. break;
  158698. case JXFORM_TRANSPOSE:
  158699. transpose_critical_parameters(dstinfo);
  158700. break;
  158701. case JXFORM_TRANSVERSE:
  158702. transpose_critical_parameters(dstinfo);
  158703. if (info->trim) {
  158704. trim_right_edge(dstinfo);
  158705. trim_bottom_edge(dstinfo);
  158706. }
  158707. break;
  158708. case JXFORM_ROT_90:
  158709. transpose_critical_parameters(dstinfo);
  158710. if (info->trim)
  158711. trim_right_edge(dstinfo);
  158712. break;
  158713. case JXFORM_ROT_180:
  158714. if (info->trim) {
  158715. trim_right_edge(dstinfo);
  158716. trim_bottom_edge(dstinfo);
  158717. }
  158718. break;
  158719. case JXFORM_ROT_270:
  158720. transpose_critical_parameters(dstinfo);
  158721. if (info->trim)
  158722. trim_bottom_edge(dstinfo);
  158723. break;
  158724. }
  158725. if (info->workspace_coef_arrays != NULL)
  158726. return info->workspace_coef_arrays;
  158727. return src_coef_arrays;
  158728. }
  158729. GLOBAL(void)
  158730. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158731. j_compress_ptr dstinfo,
  158732. jvirt_barray_ptr *src_coef_arrays,
  158733. jpeg_transform_info *info)
  158734. {
  158735. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158736. switch (info->transform) {
  158737. case JXFORM_NONE:
  158738. break;
  158739. case JXFORM_FLIP_H:
  158740. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158741. break;
  158742. case JXFORM_FLIP_V:
  158743. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158744. break;
  158745. case JXFORM_TRANSPOSE:
  158746. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158747. break;
  158748. case JXFORM_TRANSVERSE:
  158749. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158750. break;
  158751. case JXFORM_ROT_90:
  158752. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158753. break;
  158754. case JXFORM_ROT_180:
  158755. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158756. break;
  158757. case JXFORM_ROT_270:
  158758. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158759. break;
  158760. }
  158761. }
  158762. #endif /* TRANSFORMS_SUPPORTED */
  158763. GLOBAL(void)
  158764. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158765. {
  158766. #ifdef SAVE_MARKERS_SUPPORTED
  158767. int m;
  158768. if (option != JCOPYOPT_NONE) {
  158769. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158770. }
  158771. if (option == JCOPYOPT_ALL) {
  158772. for (m = 0; m < 16; m++)
  158773. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158774. }
  158775. #endif /* SAVE_MARKERS_SUPPORTED */
  158776. }
  158777. GLOBAL(void)
  158778. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158779. JCOPY_OPTION option)
  158780. {
  158781. jpeg_saved_marker_ptr marker;
  158782. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158783. if (dstinfo->write_JFIF_header &&
  158784. marker->marker == JPEG_APP0 &&
  158785. marker->data_length >= 5 &&
  158786. GETJOCTET(marker->data[0]) == 0x4A &&
  158787. GETJOCTET(marker->data[1]) == 0x46 &&
  158788. GETJOCTET(marker->data[2]) == 0x49 &&
  158789. GETJOCTET(marker->data[3]) == 0x46 &&
  158790. GETJOCTET(marker->data[4]) == 0)
  158791. continue; /* reject duplicate JFIF */
  158792. if (dstinfo->write_Adobe_marker &&
  158793. marker->marker == JPEG_APP0+14 &&
  158794. marker->data_length >= 5 &&
  158795. GETJOCTET(marker->data[0]) == 0x41 &&
  158796. GETJOCTET(marker->data[1]) == 0x64 &&
  158797. GETJOCTET(marker->data[2]) == 0x6F &&
  158798. GETJOCTET(marker->data[3]) == 0x62 &&
  158799. GETJOCTET(marker->data[4]) == 0x65)
  158800. continue; /* reject duplicate Adobe */
  158801. #ifdef NEED_FAR_POINTERS
  158802. {
  158803. unsigned int i;
  158804. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158805. for (i = 0; i < marker->data_length; i++)
  158806. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158807. }
  158808. #else
  158809. jpeg_write_marker(dstinfo, marker->marker,
  158810. marker->data, marker->data_length);
  158811. #endif
  158812. }
  158813. }
  158814. /*** End of inlined file: transupp.c ***/
  158815. }
  158816. #else
  158817. #define JPEG_INTERNALS
  158818. #undef FAR
  158819. #include <jpeglib.h>
  158820. #endif
  158821. }
  158822. #undef max
  158823. #undef min
  158824. #if JUCE_MSVC
  158825. #pragma warning (pop)
  158826. #endif
  158827. BEGIN_JUCE_NAMESPACE
  158828. namespace JPEGHelpers
  158829. {
  158830. using namespace jpeglibNamespace;
  158831. #if ! JUCE_MSVC
  158832. using jpeglibNamespace::boolean;
  158833. #endif
  158834. struct JPEGDecodingFailure {};
  158835. static void fatalErrorHandler (j_common_ptr)
  158836. {
  158837. throw JPEGDecodingFailure();
  158838. }
  158839. static void silentErrorCallback1 (j_common_ptr) {}
  158840. static void silentErrorCallback2 (j_common_ptr, int) {}
  158841. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158842. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158843. {
  158844. zerostruct (err);
  158845. err.error_exit = fatalErrorHandler;
  158846. err.emit_message = silentErrorCallback2;
  158847. err.output_message = silentErrorCallback1;
  158848. err.format_message = silentErrorCallback3;
  158849. err.reset_error_mgr = silentErrorCallback1;
  158850. }
  158851. static void dummyCallback1 (j_decompress_ptr)
  158852. {
  158853. }
  158854. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158855. {
  158856. decompStruct->src->next_input_byte += num;
  158857. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158858. decompStruct->src->bytes_in_buffer -= num;
  158859. }
  158860. static boolean jpegFill (j_decompress_ptr)
  158861. {
  158862. return 0;
  158863. }
  158864. static const int jpegBufferSize = 512;
  158865. struct JuceJpegDest : public jpeg_destination_mgr
  158866. {
  158867. OutputStream* output;
  158868. char* buffer;
  158869. };
  158870. static void jpegWriteInit (j_compress_ptr)
  158871. {
  158872. }
  158873. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158874. {
  158875. JuceJpegDest* const dest = static_cast <JuceJpegDest*> (cinfo->dest);
  158876. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158877. dest->output->write (dest->buffer, (int) numToWrite);
  158878. }
  158879. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158880. {
  158881. JuceJpegDest* const dest = static_cast <JuceJpegDest*> (cinfo->dest);
  158882. const int numToWrite = jpegBufferSize;
  158883. dest->next_output_byte = reinterpret_cast <JOCTET*> (dest->buffer);
  158884. dest->free_in_buffer = jpegBufferSize;
  158885. return dest->output->write (dest->buffer, numToWrite);
  158886. }
  158887. }
  158888. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158889. {
  158890. using namespace jpeglibNamespace;
  158891. using namespace JPEGHelpers;
  158892. MemoryBlock mb;
  158893. in.readIntoMemoryBlock (mb);
  158894. Image* image = 0;
  158895. if (mb.getSize() > 16)
  158896. {
  158897. struct jpeg_decompress_struct jpegDecompStruct;
  158898. struct jpeg_error_mgr jerr;
  158899. setupSilentErrorHandler (jerr);
  158900. jpegDecompStruct.err = &jerr;
  158901. jpeg_create_decompress (&jpegDecompStruct);
  158902. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158903. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158904. jpegDecompStruct.src->init_source = dummyCallback1;
  158905. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158906. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158907. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158908. jpegDecompStruct.src->term_source = dummyCallback1;
  158909. jpegDecompStruct.src->next_input_byte = static_cast <const unsigned char*> (mb.getData());
  158910. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158911. try
  158912. {
  158913. jpeg_read_header (&jpegDecompStruct, TRUE);
  158914. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158915. const int width = jpegDecompStruct.output_width;
  158916. const int height = jpegDecompStruct.output_height;
  158917. jpegDecompStruct.out_color_space = JCS_RGB;
  158918. JSAMPARRAY buffer
  158919. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158920. JPOOL_IMAGE,
  158921. width * 3, 1);
  158922. if (jpeg_start_decompress (&jpegDecompStruct))
  158923. {
  158924. image = Image::createNativeImage (Image::RGB, width, height, false);
  158925. const bool hasAlphaChan = image->hasAlphaChannel();
  158926. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158927. for (int y = 0; y < height; ++y)
  158928. {
  158929. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158930. const uint8* src = *buffer;
  158931. uint8* dest = destData.getLinePointer (y);
  158932. if (hasAlphaChan)
  158933. {
  158934. for (int i = width; --i >= 0;)
  158935. {
  158936. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158937. ((PixelARGB*) dest)->premultiply();
  158938. dest += destData.pixelStride;
  158939. src += 3;
  158940. }
  158941. }
  158942. else
  158943. {
  158944. for (int i = width; --i >= 0;)
  158945. {
  158946. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158947. dest += destData.pixelStride;
  158948. src += 3;
  158949. }
  158950. }
  158951. }
  158952. jpeg_finish_decompress (&jpegDecompStruct);
  158953. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  158954. }
  158955. jpeg_destroy_decompress (&jpegDecompStruct);
  158956. }
  158957. catch (...)
  158958. {}
  158959. }
  158960. return image;
  158961. }
  158962. bool juce_writeJPEGImageToStream (const Image& image,
  158963. OutputStream& out,
  158964. float quality)
  158965. {
  158966. using namespace jpeglibNamespace;
  158967. using namespace JPEGHelpers;
  158968. if (image.hasAlphaChannel())
  158969. {
  158970. // this method could fill the background in white and still save the image..
  158971. jassertfalse
  158972. return true;
  158973. }
  158974. struct jpeg_compress_struct jpegCompStruct;
  158975. struct jpeg_error_mgr jerr;
  158976. setupSilentErrorHandler (jerr);
  158977. jpegCompStruct.err = &jerr;
  158978. jpeg_create_compress (&jpegCompStruct);
  158979. JuceJpegDest dest;
  158980. jpegCompStruct.dest = &dest;
  158981. dest.output = &out;
  158982. HeapBlock <char> tempBuffer (jpegBufferSize);
  158983. dest.buffer = tempBuffer;
  158984. dest.next_output_byte = (JOCTET*) dest.buffer;
  158985. dest.free_in_buffer = jpegBufferSize;
  158986. dest.init_destination = jpegWriteInit;
  158987. dest.empty_output_buffer = jpegWriteFlush;
  158988. dest.term_destination = jpegWriteTerminate;
  158989. jpegCompStruct.image_width = image.getWidth();
  158990. jpegCompStruct.image_height = image.getHeight();
  158991. jpegCompStruct.input_components = 3;
  158992. jpegCompStruct.in_color_space = JCS_RGB;
  158993. jpegCompStruct.write_JFIF_header = 1;
  158994. jpegCompStruct.X_density = 72;
  158995. jpegCompStruct.Y_density = 72;
  158996. jpeg_set_defaults (&jpegCompStruct);
  158997. jpegCompStruct.dct_method = JDCT_FLOAT;
  158998. jpegCompStruct.optimize_coding = 1;
  158999. //jpegCompStruct.smoothing_factor = 10;
  159000. if (quality < 0.0f)
  159001. quality = 0.85f;
  159002. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159003. jpeg_start_compress (&jpegCompStruct, TRUE);
  159004. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159005. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159006. JPOOL_IMAGE, strideBytes, 1);
  159007. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159008. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159009. {
  159010. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159011. uint8* dst = *buffer;
  159012. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159013. {
  159014. *dst++ = ((const PixelRGB*) src)->getRed();
  159015. *dst++ = ((const PixelRGB*) src)->getGreen();
  159016. *dst++ = ((const PixelRGB*) src)->getBlue();
  159017. src += srcData.pixelStride;
  159018. }
  159019. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159020. }
  159021. jpeg_finish_compress (&jpegCompStruct);
  159022. jpeg_destroy_compress (&jpegCompStruct);
  159023. out.flush();
  159024. return true;
  159025. }
  159026. END_JUCE_NAMESPACE
  159027. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159028. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159029. #ifdef _MSC_VER
  159030. #pragma warning (push)
  159031. #pragma warning (disable: 4390 4611)
  159032. #endif
  159033. namespace zlibNamespace
  159034. {
  159035. #if JUCE_INCLUDE_ZLIB_CODE
  159036. #undef OS_CODE
  159037. #undef fdopen
  159038. #undef OS_CODE
  159039. #else
  159040. #include <zlib.h>
  159041. #endif
  159042. }
  159043. namespace pnglibNamespace
  159044. {
  159045. using namespace zlibNamespace;
  159046. #if JUCE_INCLUDE_PNGLIB_CODE
  159047. #if _MSC_VER != 1310
  159048. using ::calloc; // (causes conflict in VS.NET 2003)
  159049. using ::malloc;
  159050. using ::free;
  159051. #endif
  159052. extern "C"
  159053. {
  159054. using ::abs;
  159055. #define PNG_INTERNAL
  159056. #define NO_DUMMY_DECL
  159057. #define PNG_SETJMP_NOT_SUPPORTED
  159058. /*** Start of inlined file: png.h ***/
  159059. #ifndef PNG_H
  159060. #define PNG_H
  159061. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159062. #define PNG_HEADER_VERSION_STRING \
  159063. " libpng version 1.2.21 - October 4, 2007\n"
  159064. #define PNG_LIBPNG_VER_SONUM 0
  159065. #define PNG_LIBPNG_VER_DLLNUM 13
  159066. #define PNG_LIBPNG_VER_MAJOR 1
  159067. #define PNG_LIBPNG_VER_MINOR 2
  159068. #define PNG_LIBPNG_VER_RELEASE 21
  159069. #define PNG_LIBPNG_VER_BUILD 0
  159070. #define PNG_LIBPNG_BUILD_ALPHA 1
  159071. #define PNG_LIBPNG_BUILD_BETA 2
  159072. #define PNG_LIBPNG_BUILD_RC 3
  159073. #define PNG_LIBPNG_BUILD_STABLE 4
  159074. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159075. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159076. PNG_LIBPNG_BUILD_STABLE only */
  159077. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159078. PNG_LIBPNG_BUILD_SPECIAL */
  159079. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159080. PNG_LIBPNG_BUILD_PRIVATE */
  159081. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159082. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159083. #ifndef PNG_VERSION_INFO_ONLY
  159084. #endif
  159085. /*** Start of inlined file: pngconf.h ***/
  159086. #ifndef PNGCONF_H
  159087. #define PNGCONF_H
  159088. #define PNG_1_2_X
  159089. // These are some Juce config settings that should remove any unnecessary code bloat..
  159090. #define PNG_NO_STDIO 1
  159091. #define PNG_DEBUG 0
  159092. #define PNG_NO_WARNINGS 1
  159093. #define PNG_NO_ERROR_TEXT 1
  159094. #define PNG_NO_ERROR_NUMBERS 1
  159095. #define PNG_NO_USER_MEM 1
  159096. #define PNG_NO_READ_iCCP 1
  159097. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159098. #define PNG_NO_READ_USER_CHUNKS 1
  159099. #define PNG_NO_READ_iTXt 1
  159100. #define PNG_NO_READ_sCAL 1
  159101. #define PNG_NO_READ_sPLT 1
  159102. #define png_error(a, b) png_err(a)
  159103. #define png_warning(a, b)
  159104. #define png_chunk_error(a, b) png_err(a)
  159105. #define png_chunk_warning(a, b)
  159106. #ifdef PNG_USER_CONFIG
  159107. # ifndef PNG_USER_PRIVATEBUILD
  159108. # define PNG_USER_PRIVATEBUILD
  159109. # endif
  159110. #include "pngusr.h"
  159111. #endif
  159112. #ifdef PNG_CONFIGURE_LIBPNG
  159113. #ifdef HAVE_CONFIG_H
  159114. #include "config.h"
  159115. #endif
  159116. #endif
  159117. #ifdef __STDC__
  159118. #ifdef SPECIALBUILD
  159119. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159120. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159121. #endif
  159122. #ifdef PRIVATEBUILD
  159123. # pragma message("PRIVATEBUILD is deprecated.\
  159124. Use PNG_USER_PRIVATEBUILD instead.")
  159125. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159126. #endif
  159127. #endif /* __STDC__ */
  159128. #ifndef PNG_VERSION_INFO_ONLY
  159129. # define PNG_WARN_UNINITIALIZED_ROW 1
  159130. #ifndef PNG_ZBUF_SIZE
  159131. # define PNG_ZBUF_SIZE 8192
  159132. #endif
  159133. #ifndef PNG_NO_READ_SUPPORTED
  159134. # define PNG_READ_SUPPORTED
  159135. #endif
  159136. #ifndef PNG_NO_WRITE_SUPPORTED
  159137. # define PNG_WRITE_SUPPORTED
  159138. #endif
  159139. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159140. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159141. # define PNG_MNG_FEATURES_SUPPORTED
  159142. # endif
  159143. #endif
  159144. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159145. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159146. # define PNG_FLOATING_POINT_SUPPORTED
  159147. # endif
  159148. #endif
  159149. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159150. # define PNG_MAX_MALLOC_64K
  159151. #endif
  159152. #if defined(__CYGWIN__)
  159153. # if defined(ALL_STATIC)
  159154. # if defined(PNG_BUILD_DLL)
  159155. # undef PNG_BUILD_DLL
  159156. # endif
  159157. # if defined(PNG_USE_DLL)
  159158. # undef PNG_USE_DLL
  159159. # endif
  159160. # if defined(PNG_DLL)
  159161. # undef PNG_DLL
  159162. # endif
  159163. # if !defined(PNG_STATIC)
  159164. # define PNG_STATIC
  159165. # endif
  159166. # else
  159167. # if defined (PNG_BUILD_DLL)
  159168. # if defined(PNG_STATIC)
  159169. # undef PNG_STATIC
  159170. # endif
  159171. # if defined(PNG_USE_DLL)
  159172. # undef PNG_USE_DLL
  159173. # endif
  159174. # if !defined(PNG_DLL)
  159175. # define PNG_DLL
  159176. # endif
  159177. # else
  159178. # if defined(PNG_STATIC)
  159179. # if defined(PNG_USE_DLL)
  159180. # undef PNG_USE_DLL
  159181. # endif
  159182. # if defined(PNG_DLL)
  159183. # undef PNG_DLL
  159184. # endif
  159185. # else
  159186. # if !defined(PNG_USE_DLL)
  159187. # define PNG_USE_DLL
  159188. # endif
  159189. # if !defined(PNG_DLL)
  159190. # define PNG_DLL
  159191. # endif
  159192. # endif
  159193. # endif
  159194. # endif
  159195. #endif
  159196. #if defined(_WIN32_WCE)
  159197. # include <windows.h>
  159198. # define PNG_NO_CONSOLE_IO
  159199. # ifdef PNG_DEBUG
  159200. # undef PNG_DEBUG
  159201. # endif
  159202. #endif
  159203. #ifdef PNG_BUILD_DLL
  159204. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159205. # ifndef PNG_NO_CONSOLE_IO
  159206. # define PNG_NO_CONSOLE_IO
  159207. # endif
  159208. # endif
  159209. #endif
  159210. # ifdef PNG_NO_STDIO
  159211. # ifndef PNG_NO_CONSOLE_IO
  159212. # define PNG_NO_CONSOLE_IO
  159213. # endif
  159214. # ifdef PNG_DEBUG
  159215. # if (PNG_DEBUG > 0)
  159216. # include <stdio.h>
  159217. # endif
  159218. # endif
  159219. # else
  159220. # if !defined(_WIN32_WCE)
  159221. # include <stdio.h>
  159222. # endif
  159223. # endif
  159224. #ifndef PNGARG
  159225. #ifdef OF /* zlib prototype munger */
  159226. # define PNGARG(arglist) OF(arglist)
  159227. #else
  159228. #ifdef _NO_PROTO
  159229. # define PNGARG(arglist) ()
  159230. # ifndef PNG_TYPECAST_NULL
  159231. # define PNG_TYPECAST_NULL
  159232. # endif
  159233. #else
  159234. # define PNGARG(arglist) arglist
  159235. #endif /* _NO_PROTO */
  159236. #endif /* OF */
  159237. #endif /* PNGARG */
  159238. #ifndef MACOS
  159239. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159240. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159241. # define MACOS
  159242. # endif
  159243. #endif
  159244. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159245. # include <sys/types.h>
  159246. #endif
  159247. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159248. # define PNG_SETJMP_SUPPORTED
  159249. #endif
  159250. #ifdef PNG_SETJMP_SUPPORTED
  159251. # ifdef __linux__
  159252. # ifdef _BSD_SOURCE
  159253. # define PNG_SAVE_BSD_SOURCE
  159254. # undef _BSD_SOURCE
  159255. # endif
  159256. # ifdef _SETJMP_H
  159257. __png.h__ already includes setjmp.h;
  159258. __dont__ include it again.;
  159259. # endif
  159260. # endif /* __linux__ */
  159261. # include <setjmp.h>
  159262. # ifdef __linux__
  159263. # ifdef PNG_SAVE_BSD_SOURCE
  159264. # define _BSD_SOURCE
  159265. # undef PNG_SAVE_BSD_SOURCE
  159266. # endif
  159267. # endif /* __linux__ */
  159268. #endif /* PNG_SETJMP_SUPPORTED */
  159269. #ifdef BSD
  159270. #if ! JUCE_MAC
  159271. # include <strings.h>
  159272. #endif
  159273. #else
  159274. # include <string.h>
  159275. #endif
  159276. #ifdef PNG_INTERNAL
  159277. #include <stdlib.h>
  159278. #define PNG_EXTERN
  159279. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159280. # if defined(MACOS)
  159281. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159282. # include <fp.h>
  159283. # endif
  159284. # else
  159285. # include <math.h>
  159286. # endif
  159287. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159288. # include <m68881.h>
  159289. # endif
  159290. #endif
  159291. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159292. # define PNG_ALWAYS_EXTERN
  159293. #endif
  159294. #if defined(__TURBOC__) && defined(__MSDOS__)
  159295. # include <mem.h>
  159296. # include <alloc.h>
  159297. #endif
  159298. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159299. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159300. # include <malloc.h>
  159301. #endif
  159302. #ifndef PNG_DITHER_RED_BITS
  159303. # define PNG_DITHER_RED_BITS 5
  159304. #endif
  159305. #ifndef PNG_DITHER_GREEN_BITS
  159306. # define PNG_DITHER_GREEN_BITS 5
  159307. #endif
  159308. #ifndef PNG_DITHER_BLUE_BITS
  159309. # define PNG_DITHER_BLUE_BITS 5
  159310. #endif
  159311. #ifndef PNG_MAX_GAMMA_8
  159312. # define PNG_MAX_GAMMA_8 11
  159313. #endif
  159314. #ifndef PNG_GAMMA_THRESHOLD
  159315. # define PNG_GAMMA_THRESHOLD 0.05
  159316. #endif
  159317. #endif /* PNG_INTERNAL */
  159318. #ifndef PNG_NO_CONST
  159319. # define PNG_CONST const
  159320. #else
  159321. # define PNG_CONST
  159322. #endif
  159323. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159324. # ifndef PNG_NO_iTXt_SUPPORTED
  159325. # define PNG_NO_iTXt_SUPPORTED
  159326. # endif
  159327. # ifndef PNG_NO_READ_iTXt
  159328. # define PNG_NO_READ_iTXt
  159329. # endif
  159330. # ifndef PNG_NO_WRITE_iTXt
  159331. # define PNG_NO_WRITE_iTXt
  159332. # endif
  159333. #endif
  159334. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159335. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159336. # define PNG_READ_iTXt
  159337. # endif
  159338. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159339. # define PNG_WRITE_iTXt
  159340. # endif
  159341. #endif
  159342. #ifdef PNG_LEGACY_SUPPORTED
  159343. # define PNG_NO_FREE_ME
  159344. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159345. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159346. # define PNG_NO_READ_USER_CHUNKS
  159347. # define PNG_NO_READ_iCCP
  159348. # define PNG_NO_WRITE_iCCP
  159349. # define PNG_NO_READ_iTXt
  159350. # define PNG_NO_WRITE_iTXt
  159351. # define PNG_NO_READ_sCAL
  159352. # define PNG_NO_WRITE_sCAL
  159353. # define PNG_NO_READ_sPLT
  159354. # define PNG_NO_WRITE_sPLT
  159355. # define PNG_NO_INFO_IMAGE
  159356. # define PNG_NO_READ_RGB_TO_GRAY
  159357. # define PNG_NO_READ_USER_TRANSFORM
  159358. # define PNG_NO_WRITE_USER_TRANSFORM
  159359. # define PNG_NO_USER_MEM
  159360. # define PNG_NO_READ_EMPTY_PLTE
  159361. # define PNG_NO_MNG_FEATURES
  159362. # define PNG_NO_FIXED_POINT_SUPPORTED
  159363. #endif
  159364. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159365. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159366. # define PNG_FIXED_POINT_SUPPORTED
  159367. #endif
  159368. #ifndef PNG_NO_FREE_ME
  159369. # define PNG_FREE_ME_SUPPORTED
  159370. #endif
  159371. #if defined(PNG_READ_SUPPORTED)
  159372. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159373. !defined(PNG_NO_READ_TRANSFORMS)
  159374. # define PNG_READ_TRANSFORMS_SUPPORTED
  159375. #endif
  159376. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159377. # ifndef PNG_NO_READ_EXPAND
  159378. # define PNG_READ_EXPAND_SUPPORTED
  159379. # endif
  159380. # ifndef PNG_NO_READ_SHIFT
  159381. # define PNG_READ_SHIFT_SUPPORTED
  159382. # endif
  159383. # ifndef PNG_NO_READ_PACK
  159384. # define PNG_READ_PACK_SUPPORTED
  159385. # endif
  159386. # ifndef PNG_NO_READ_BGR
  159387. # define PNG_READ_BGR_SUPPORTED
  159388. # endif
  159389. # ifndef PNG_NO_READ_SWAP
  159390. # define PNG_READ_SWAP_SUPPORTED
  159391. # endif
  159392. # ifndef PNG_NO_READ_PACKSWAP
  159393. # define PNG_READ_PACKSWAP_SUPPORTED
  159394. # endif
  159395. # ifndef PNG_NO_READ_INVERT
  159396. # define PNG_READ_INVERT_SUPPORTED
  159397. # endif
  159398. # ifndef PNG_NO_READ_DITHER
  159399. # define PNG_READ_DITHER_SUPPORTED
  159400. # endif
  159401. # ifndef PNG_NO_READ_BACKGROUND
  159402. # define PNG_READ_BACKGROUND_SUPPORTED
  159403. # endif
  159404. # ifndef PNG_NO_READ_16_TO_8
  159405. # define PNG_READ_16_TO_8_SUPPORTED
  159406. # endif
  159407. # ifndef PNG_NO_READ_FILLER
  159408. # define PNG_READ_FILLER_SUPPORTED
  159409. # endif
  159410. # ifndef PNG_NO_READ_GAMMA
  159411. # define PNG_READ_GAMMA_SUPPORTED
  159412. # endif
  159413. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159414. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159415. # endif
  159416. # ifndef PNG_NO_READ_SWAP_ALPHA
  159417. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159418. # endif
  159419. # ifndef PNG_NO_READ_INVERT_ALPHA
  159420. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159421. # endif
  159422. # ifndef PNG_NO_READ_STRIP_ALPHA
  159423. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159424. # endif
  159425. # ifndef PNG_NO_READ_USER_TRANSFORM
  159426. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159427. # endif
  159428. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159429. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159430. # endif
  159431. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159432. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159433. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159434. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159435. #endif /* about interlacing capability! You'll */
  159436. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159437. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159438. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159439. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159440. # endif
  159441. #endif
  159442. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159443. #ifndef PNG_NO_READ_EMPTY_PLTE
  159444. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159445. #endif
  159446. #endif
  159447. #endif /* PNG_READ_SUPPORTED */
  159448. #if defined(PNG_WRITE_SUPPORTED)
  159449. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159450. !defined(PNG_NO_WRITE_TRANSFORMS)
  159451. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159452. #endif
  159453. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159454. # ifndef PNG_NO_WRITE_SHIFT
  159455. # define PNG_WRITE_SHIFT_SUPPORTED
  159456. # endif
  159457. # ifndef PNG_NO_WRITE_PACK
  159458. # define PNG_WRITE_PACK_SUPPORTED
  159459. # endif
  159460. # ifndef PNG_NO_WRITE_BGR
  159461. # define PNG_WRITE_BGR_SUPPORTED
  159462. # endif
  159463. # ifndef PNG_NO_WRITE_SWAP
  159464. # define PNG_WRITE_SWAP_SUPPORTED
  159465. # endif
  159466. # ifndef PNG_NO_WRITE_PACKSWAP
  159467. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159468. # endif
  159469. # ifndef PNG_NO_WRITE_INVERT
  159470. # define PNG_WRITE_INVERT_SUPPORTED
  159471. # endif
  159472. # ifndef PNG_NO_WRITE_FILLER
  159473. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159474. # endif
  159475. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159476. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159477. # endif
  159478. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159479. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159480. # endif
  159481. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159482. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159483. # endif
  159484. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159485. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159486. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159487. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159488. encoders, but can cause trouble
  159489. if left undefined */
  159490. #endif
  159491. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159492. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159493. defined(PNG_FLOATING_POINT_SUPPORTED)
  159494. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159495. #endif
  159496. #ifndef PNG_NO_WRITE_FLUSH
  159497. # define PNG_WRITE_FLUSH_SUPPORTED
  159498. #endif
  159499. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159500. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159501. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159502. #endif
  159503. #endif
  159504. #endif /* PNG_WRITE_SUPPORTED */
  159505. #ifndef PNG_1_0_X
  159506. # ifndef PNG_NO_ERROR_NUMBERS
  159507. # define PNG_ERROR_NUMBERS_SUPPORTED
  159508. # endif
  159509. #endif /* PNG_1_0_X */
  159510. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159511. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159512. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159513. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159514. # endif
  159515. #endif
  159516. #ifndef PNG_NO_STDIO
  159517. # define PNG_TIME_RFC1123_SUPPORTED
  159518. #endif
  159519. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159520. # define PNG_EASY_ACCESS_SUPPORTED
  159521. #endif
  159522. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159523. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159524. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159525. # endif
  159526. #endif
  159527. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159528. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159529. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159530. # endif
  159531. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159532. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159533. # define PNG_NO_MMX_CODE
  159534. # endif
  159535. # endif
  159536. # if defined(__APPLE__)
  159537. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159538. # define PNG_NO_MMX_CODE
  159539. # endif
  159540. # endif
  159541. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159542. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159543. # define PNG_NO_MMX_CODE
  159544. # endif
  159545. # endif
  159546. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159547. # define PNG_MMX_CODE_SUPPORTED
  159548. # endif
  159549. #endif
  159550. #if !defined(PNG_1_0_X)
  159551. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159552. # define PNG_USER_MEM_SUPPORTED
  159553. #endif
  159554. #endif /* PNG_1_0_X */
  159555. #if !defined(PNG_1_0_X)
  159556. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159557. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159558. # define PNG_SET_USER_LIMITS_SUPPORTED
  159559. #endif
  159560. #endif
  159561. #endif /* PNG_1_0_X */
  159562. #ifndef PNG_USER_WIDTH_MAX
  159563. # define PNG_USER_WIDTH_MAX 1000000L
  159564. #endif
  159565. #ifndef PNG_USER_HEIGHT_MAX
  159566. # define PNG_USER_HEIGHT_MAX 1000000L
  159567. #endif
  159568. #if defined(PNG_READ_SUPPORTED) && \
  159569. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159570. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159571. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159572. #endif
  159573. #if defined(PNG_WRITE_SUPPORTED) && \
  159574. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159575. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159576. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159577. #endif
  159578. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159579. #ifdef PNG_NO_READ_TEXT
  159580. # define PNG_NO_READ_iTXt
  159581. # define PNG_NO_READ_tEXt
  159582. # define PNG_NO_READ_zTXt
  159583. #endif
  159584. #ifndef PNG_NO_READ_bKGD
  159585. # define PNG_READ_bKGD_SUPPORTED
  159586. # define PNG_bKGD_SUPPORTED
  159587. #endif
  159588. #ifndef PNG_NO_READ_cHRM
  159589. # define PNG_READ_cHRM_SUPPORTED
  159590. # define PNG_cHRM_SUPPORTED
  159591. #endif
  159592. #ifndef PNG_NO_READ_gAMA
  159593. # define PNG_READ_gAMA_SUPPORTED
  159594. # define PNG_gAMA_SUPPORTED
  159595. #endif
  159596. #ifndef PNG_NO_READ_hIST
  159597. # define PNG_READ_hIST_SUPPORTED
  159598. # define PNG_hIST_SUPPORTED
  159599. #endif
  159600. #ifndef PNG_NO_READ_iCCP
  159601. # define PNG_READ_iCCP_SUPPORTED
  159602. # define PNG_iCCP_SUPPORTED
  159603. #endif
  159604. #ifndef PNG_NO_READ_iTXt
  159605. # ifndef PNG_READ_iTXt_SUPPORTED
  159606. # define PNG_READ_iTXt_SUPPORTED
  159607. # endif
  159608. # ifndef PNG_iTXt_SUPPORTED
  159609. # define PNG_iTXt_SUPPORTED
  159610. # endif
  159611. #endif
  159612. #ifndef PNG_NO_READ_oFFs
  159613. # define PNG_READ_oFFs_SUPPORTED
  159614. # define PNG_oFFs_SUPPORTED
  159615. #endif
  159616. #ifndef PNG_NO_READ_pCAL
  159617. # define PNG_READ_pCAL_SUPPORTED
  159618. # define PNG_pCAL_SUPPORTED
  159619. #endif
  159620. #ifndef PNG_NO_READ_sCAL
  159621. # define PNG_READ_sCAL_SUPPORTED
  159622. # define PNG_sCAL_SUPPORTED
  159623. #endif
  159624. #ifndef PNG_NO_READ_pHYs
  159625. # define PNG_READ_pHYs_SUPPORTED
  159626. # define PNG_pHYs_SUPPORTED
  159627. #endif
  159628. #ifndef PNG_NO_READ_sBIT
  159629. # define PNG_READ_sBIT_SUPPORTED
  159630. # define PNG_sBIT_SUPPORTED
  159631. #endif
  159632. #ifndef PNG_NO_READ_sPLT
  159633. # define PNG_READ_sPLT_SUPPORTED
  159634. # define PNG_sPLT_SUPPORTED
  159635. #endif
  159636. #ifndef PNG_NO_READ_sRGB
  159637. # define PNG_READ_sRGB_SUPPORTED
  159638. # define PNG_sRGB_SUPPORTED
  159639. #endif
  159640. #ifndef PNG_NO_READ_tEXt
  159641. # define PNG_READ_tEXt_SUPPORTED
  159642. # define PNG_tEXt_SUPPORTED
  159643. #endif
  159644. #ifndef PNG_NO_READ_tIME
  159645. # define PNG_READ_tIME_SUPPORTED
  159646. # define PNG_tIME_SUPPORTED
  159647. #endif
  159648. #ifndef PNG_NO_READ_tRNS
  159649. # define PNG_READ_tRNS_SUPPORTED
  159650. # define PNG_tRNS_SUPPORTED
  159651. #endif
  159652. #ifndef PNG_NO_READ_zTXt
  159653. # define PNG_READ_zTXt_SUPPORTED
  159654. # define PNG_zTXt_SUPPORTED
  159655. #endif
  159656. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159657. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159658. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159659. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159660. # endif
  159661. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159662. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159663. # endif
  159664. #endif
  159665. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159666. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159667. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159668. # define PNG_USER_CHUNKS_SUPPORTED
  159669. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159670. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159671. # endif
  159672. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159673. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159674. # endif
  159675. #endif
  159676. #ifndef PNG_NO_READ_OPT_PLTE
  159677. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159678. #endif /* optional PLTE chunk in RGB and RGBA images */
  159679. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159680. defined(PNG_READ_zTXt_SUPPORTED)
  159681. # define PNG_READ_TEXT_SUPPORTED
  159682. # define PNG_TEXT_SUPPORTED
  159683. #endif
  159684. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159685. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159686. #ifdef PNG_NO_WRITE_TEXT
  159687. # define PNG_NO_WRITE_iTXt
  159688. # define PNG_NO_WRITE_tEXt
  159689. # define PNG_NO_WRITE_zTXt
  159690. #endif
  159691. #ifndef PNG_NO_WRITE_bKGD
  159692. # define PNG_WRITE_bKGD_SUPPORTED
  159693. # ifndef PNG_bKGD_SUPPORTED
  159694. # define PNG_bKGD_SUPPORTED
  159695. # endif
  159696. #endif
  159697. #ifndef PNG_NO_WRITE_cHRM
  159698. # define PNG_WRITE_cHRM_SUPPORTED
  159699. # ifndef PNG_cHRM_SUPPORTED
  159700. # define PNG_cHRM_SUPPORTED
  159701. # endif
  159702. #endif
  159703. #ifndef PNG_NO_WRITE_gAMA
  159704. # define PNG_WRITE_gAMA_SUPPORTED
  159705. # ifndef PNG_gAMA_SUPPORTED
  159706. # define PNG_gAMA_SUPPORTED
  159707. # endif
  159708. #endif
  159709. #ifndef PNG_NO_WRITE_hIST
  159710. # define PNG_WRITE_hIST_SUPPORTED
  159711. # ifndef PNG_hIST_SUPPORTED
  159712. # define PNG_hIST_SUPPORTED
  159713. # endif
  159714. #endif
  159715. #ifndef PNG_NO_WRITE_iCCP
  159716. # define PNG_WRITE_iCCP_SUPPORTED
  159717. # ifndef PNG_iCCP_SUPPORTED
  159718. # define PNG_iCCP_SUPPORTED
  159719. # endif
  159720. #endif
  159721. #ifndef PNG_NO_WRITE_iTXt
  159722. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159723. # define PNG_WRITE_iTXt_SUPPORTED
  159724. # endif
  159725. # ifndef PNG_iTXt_SUPPORTED
  159726. # define PNG_iTXt_SUPPORTED
  159727. # endif
  159728. #endif
  159729. #ifndef PNG_NO_WRITE_oFFs
  159730. # define PNG_WRITE_oFFs_SUPPORTED
  159731. # ifndef PNG_oFFs_SUPPORTED
  159732. # define PNG_oFFs_SUPPORTED
  159733. # endif
  159734. #endif
  159735. #ifndef PNG_NO_WRITE_pCAL
  159736. # define PNG_WRITE_pCAL_SUPPORTED
  159737. # ifndef PNG_pCAL_SUPPORTED
  159738. # define PNG_pCAL_SUPPORTED
  159739. # endif
  159740. #endif
  159741. #ifndef PNG_NO_WRITE_sCAL
  159742. # define PNG_WRITE_sCAL_SUPPORTED
  159743. # ifndef PNG_sCAL_SUPPORTED
  159744. # define PNG_sCAL_SUPPORTED
  159745. # endif
  159746. #endif
  159747. #ifndef PNG_NO_WRITE_pHYs
  159748. # define PNG_WRITE_pHYs_SUPPORTED
  159749. # ifndef PNG_pHYs_SUPPORTED
  159750. # define PNG_pHYs_SUPPORTED
  159751. # endif
  159752. #endif
  159753. #ifndef PNG_NO_WRITE_sBIT
  159754. # define PNG_WRITE_sBIT_SUPPORTED
  159755. # ifndef PNG_sBIT_SUPPORTED
  159756. # define PNG_sBIT_SUPPORTED
  159757. # endif
  159758. #endif
  159759. #ifndef PNG_NO_WRITE_sPLT
  159760. # define PNG_WRITE_sPLT_SUPPORTED
  159761. # ifndef PNG_sPLT_SUPPORTED
  159762. # define PNG_sPLT_SUPPORTED
  159763. # endif
  159764. #endif
  159765. #ifndef PNG_NO_WRITE_sRGB
  159766. # define PNG_WRITE_sRGB_SUPPORTED
  159767. # ifndef PNG_sRGB_SUPPORTED
  159768. # define PNG_sRGB_SUPPORTED
  159769. # endif
  159770. #endif
  159771. #ifndef PNG_NO_WRITE_tEXt
  159772. # define PNG_WRITE_tEXt_SUPPORTED
  159773. # ifndef PNG_tEXt_SUPPORTED
  159774. # define PNG_tEXt_SUPPORTED
  159775. # endif
  159776. #endif
  159777. #ifndef PNG_NO_WRITE_tIME
  159778. # define PNG_WRITE_tIME_SUPPORTED
  159779. # ifndef PNG_tIME_SUPPORTED
  159780. # define PNG_tIME_SUPPORTED
  159781. # endif
  159782. #endif
  159783. #ifndef PNG_NO_WRITE_tRNS
  159784. # define PNG_WRITE_tRNS_SUPPORTED
  159785. # ifndef PNG_tRNS_SUPPORTED
  159786. # define PNG_tRNS_SUPPORTED
  159787. # endif
  159788. #endif
  159789. #ifndef PNG_NO_WRITE_zTXt
  159790. # define PNG_WRITE_zTXt_SUPPORTED
  159791. # ifndef PNG_zTXt_SUPPORTED
  159792. # define PNG_zTXt_SUPPORTED
  159793. # endif
  159794. #endif
  159795. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159796. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159797. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159798. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159799. # endif
  159800. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159801. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159802. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159803. # endif
  159804. # endif
  159805. #endif
  159806. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159807. defined(PNG_WRITE_zTXt_SUPPORTED)
  159808. # define PNG_WRITE_TEXT_SUPPORTED
  159809. # ifndef PNG_TEXT_SUPPORTED
  159810. # define PNG_TEXT_SUPPORTED
  159811. # endif
  159812. #endif
  159813. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159814. #ifndef PNG_NO_INFO_IMAGE
  159815. # define PNG_INFO_IMAGE_SUPPORTED
  159816. #endif
  159817. #if defined(PNG_tIME_SUPPORTED)
  159818. # if !defined(_WIN32_WCE)
  159819. # include <time.h>
  159820. # endif
  159821. #endif
  159822. typedef unsigned long png_uint_32;
  159823. typedef long png_int_32;
  159824. typedef unsigned short png_uint_16;
  159825. typedef short png_int_16;
  159826. typedef unsigned char png_byte;
  159827. #ifdef PNG_SIZE_T
  159828. typedef PNG_SIZE_T png_size_t;
  159829. # define png_sizeof(x) png_convert_size(sizeof (x))
  159830. #else
  159831. typedef size_t png_size_t;
  159832. # define png_sizeof(x) sizeof (x)
  159833. #endif
  159834. #ifdef __BORLANDC__
  159835. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159836. # define LDATA 1
  159837. # else
  159838. # define LDATA 0
  159839. # endif
  159840. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159841. # define PNG_MAX_MALLOC_64K
  159842. # if (LDATA != 1)
  159843. # ifndef FAR
  159844. # define FAR __far
  159845. # endif
  159846. # define USE_FAR_KEYWORD
  159847. # endif /* LDATA != 1 */
  159848. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159849. #endif /* __BORLANDC__ */
  159850. #if defined(FAR)
  159851. # if defined(M_I86MM)
  159852. # define USE_FAR_KEYWORD
  159853. # define FARDATA FAR
  159854. # include <dos.h>
  159855. # endif
  159856. #endif
  159857. #ifndef FAR
  159858. # define FAR
  159859. #endif
  159860. #ifndef FARDATA
  159861. # define FARDATA
  159862. #endif
  159863. typedef png_int_32 png_fixed_point;
  159864. typedef void FAR * png_voidp;
  159865. typedef png_byte FAR * png_bytep;
  159866. typedef png_uint_32 FAR * png_uint_32p;
  159867. typedef png_int_32 FAR * png_int_32p;
  159868. typedef png_uint_16 FAR * png_uint_16p;
  159869. typedef png_int_16 FAR * png_int_16p;
  159870. typedef PNG_CONST char FAR * png_const_charp;
  159871. typedef char FAR * png_charp;
  159872. typedef png_fixed_point FAR * png_fixed_point_p;
  159873. #ifndef PNG_NO_STDIO
  159874. #if defined(_WIN32_WCE)
  159875. typedef HANDLE png_FILE_p;
  159876. #else
  159877. typedef FILE * png_FILE_p;
  159878. #endif
  159879. #endif
  159880. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159881. typedef double FAR * png_doublep;
  159882. #endif
  159883. typedef png_byte FAR * FAR * png_bytepp;
  159884. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159885. typedef png_int_32 FAR * FAR * png_int_32pp;
  159886. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159887. typedef png_int_16 FAR * FAR * png_int_16pp;
  159888. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159889. typedef char FAR * FAR * png_charpp;
  159890. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159891. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159892. typedef double FAR * FAR * png_doublepp;
  159893. #endif
  159894. typedef char FAR * FAR * FAR * png_charppp;
  159895. #if 0
  159896. typedef charf * png_zcharp;
  159897. typedef charf * FAR * png_zcharpp;
  159898. typedef z_stream FAR * png_zstreamp;
  159899. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159900. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159901. # define PNG_DLL
  159902. #endif
  159903. #if defined(__CYGWIN__)
  159904. # if !defined(PNG_STATIC)
  159905. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159906. # undef PNG_USE_GLOBAL_ARRAYS
  159907. # endif
  159908. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159909. # define PNG_USE_LOCAL_ARRAYS
  159910. # endif
  159911. # else
  159912. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159913. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159914. # undef PNG_USE_GLOBAL_ARRAYS
  159915. # endif
  159916. # endif
  159917. # endif
  159918. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159919. # define PNG_USE_LOCAL_ARRAYS
  159920. # endif
  159921. #endif
  159922. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159923. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159924. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159925. # define PNG_USE_LOCAL_ARRAYS
  159926. # else
  159927. # define PNG_USE_GLOBAL_ARRAYS
  159928. # endif
  159929. #endif
  159930. #if defined(__CYGWIN__)
  159931. # undef PNGAPI
  159932. # define PNGAPI __cdecl
  159933. # undef PNG_IMPEXP
  159934. # define PNG_IMPEXP
  159935. #endif
  159936. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  159937. # ifndef PNG_NO_MODULEDEF
  159938. # define PNG_NO_MODULEDEF
  159939. # endif
  159940. #endif
  159941. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  159942. # define PNG_IMPEXP
  159943. #endif
  159944. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  159945. (( defined(_Windows) || defined(_WINDOWS) || \
  159946. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  159947. # ifndef PNGAPI
  159948. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  159949. # define PNGAPI __cdecl
  159950. # else
  159951. # define PNGAPI _cdecl
  159952. # endif
  159953. # endif
  159954. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  159955. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  159956. # define PNG_IMPEXP
  159957. # endif
  159958. # if !defined(PNG_IMPEXP)
  159959. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159960. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  159961. # if defined(_MSC_VER) || defined(__BORLANDC__)
  159962. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  159963. # define PNG_EXPORT PNG_EXPORT_TYPE1
  159964. # else
  159965. # define PNG_EXPORT PNG_EXPORT_TYPE2
  159966. # if defined(PNG_BUILD_DLL)
  159967. # define PNG_IMPEXP __export
  159968. # else
  159969. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  159970. VC++ */
  159971. # endif /* Exists in Borland C++ for
  159972. C++ classes (== huge) */
  159973. # endif
  159974. # endif
  159975. # if !defined(PNG_IMPEXP)
  159976. # if defined(PNG_BUILD_DLL)
  159977. # define PNG_IMPEXP __declspec(dllexport)
  159978. # else
  159979. # define PNG_IMPEXP __declspec(dllimport)
  159980. # endif
  159981. # endif
  159982. # endif /* PNG_IMPEXP */
  159983. #else /* !(DLL || non-cygwin WINDOWS) */
  159984. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  159985. # ifndef PNGAPI
  159986. # define PNGAPI _System
  159987. # endif
  159988. # else
  159989. # if 0 /* ... other platforms, with other meanings */
  159990. # endif
  159991. # endif
  159992. #endif
  159993. #ifndef PNGAPI
  159994. # define PNGAPI
  159995. #endif
  159996. #ifndef PNG_IMPEXP
  159997. # define PNG_IMPEXP
  159998. #endif
  159999. #ifdef PNG_BUILDSYMS
  160000. # ifndef PNG_EXPORT
  160001. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160002. # endif
  160003. # ifdef PNG_USE_GLOBAL_ARRAYS
  160004. # ifndef PNG_EXPORT_VAR
  160005. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160006. # endif
  160007. # endif
  160008. #endif
  160009. #ifndef PNG_EXPORT
  160010. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160011. #endif
  160012. #ifdef PNG_USE_GLOBAL_ARRAYS
  160013. # ifndef PNG_EXPORT_VAR
  160014. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160015. # endif
  160016. #endif
  160017. #ifndef PNG_ABORT
  160018. # define PNG_ABORT() abort()
  160019. #endif
  160020. #ifdef PNG_SETJMP_SUPPORTED
  160021. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160022. #else
  160023. # define png_jmpbuf(png_ptr) \
  160024. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160025. #endif
  160026. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160027. # define CHECK 1
  160028. # define NOCHECK 0
  160029. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160030. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160031. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160032. # define png_strcpy _fstrcpy
  160033. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160034. # define png_strlen _fstrlen
  160035. # define png_memcmp _fmemcmp /* SJT: added */
  160036. # define png_memcpy _fmemcpy
  160037. # define png_memset _fmemset
  160038. #else /* use the usual functions */
  160039. # define CVT_PTR(ptr) (ptr)
  160040. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160041. # ifndef PNG_NO_SNPRINTF
  160042. # ifdef _MSC_VER
  160043. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160044. # define png_snprintf2 _snprintf
  160045. # define png_snprintf6 _snprintf
  160046. # else
  160047. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160048. # define png_snprintf2 snprintf
  160049. # define png_snprintf6 snprintf
  160050. # endif
  160051. # else
  160052. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160053. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160054. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160055. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160056. # endif
  160057. # define png_strcpy strcpy
  160058. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160059. # define png_strlen strlen
  160060. # define png_memcmp memcmp /* SJT: added */
  160061. # define png_memcpy memcpy
  160062. # define png_memset memset
  160063. #endif
  160064. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160065. # undef PNG_ZBUF_SIZE
  160066. # define PNG_ZBUF_SIZE 65536L
  160067. #endif
  160068. #endif /* PNG_VERSION_INFO_ONLY */
  160069. #endif /* PNGCONF_H */
  160070. /*** End of inlined file: pngconf.h ***/
  160071. #ifdef _MSC_VER
  160072. #pragma warning (disable: 4996 4100)
  160073. #endif
  160074. #if defined(PNG_USER_PRIVATEBUILD)
  160075. # define PNG_LIBPNG_BUILD_TYPE \
  160076. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160077. #else
  160078. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160079. # define PNG_LIBPNG_BUILD_TYPE \
  160080. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160081. # else
  160082. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160083. # endif
  160084. #endif
  160085. #ifndef PNG_VERSION_INFO_ONLY
  160086. #ifdef __cplusplus
  160087. extern "C" {
  160088. #endif /* __cplusplus */
  160089. #ifndef PNG_NO_TYPECAST_NULL
  160090. #define int_p_NULL (int *)NULL
  160091. #define png_bytep_NULL (png_bytep)NULL
  160092. #define png_bytepp_NULL (png_bytepp)NULL
  160093. #define png_doublep_NULL (png_doublep)NULL
  160094. #define png_error_ptr_NULL (png_error_ptr)NULL
  160095. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160096. #define png_free_ptr_NULL (png_free_ptr)NULL
  160097. #define png_infopp_NULL (png_infopp)NULL
  160098. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160099. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160100. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160101. #define png_structp_NULL (png_structp)NULL
  160102. #define png_uint_16p_NULL (png_uint_16p)NULL
  160103. #define png_voidp_NULL (png_voidp)NULL
  160104. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160105. #else
  160106. #define int_p_NULL NULL
  160107. #define png_bytep_NULL NULL
  160108. #define png_bytepp_NULL NULL
  160109. #define png_doublep_NULL NULL
  160110. #define png_error_ptr_NULL NULL
  160111. #define png_flush_ptr_NULL NULL
  160112. #define png_free_ptr_NULL NULL
  160113. #define png_infopp_NULL NULL
  160114. #define png_malloc_ptr_NULL NULL
  160115. #define png_read_status_ptr_NULL NULL
  160116. #define png_rw_ptr_NULL NULL
  160117. #define png_structp_NULL NULL
  160118. #define png_uint_16p_NULL NULL
  160119. #define png_voidp_NULL NULL
  160120. #define png_write_status_ptr_NULL NULL
  160121. #endif
  160122. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160123. #ifdef PNG_USE_GLOBAL_ARRAYS
  160124. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160125. #else
  160126. #define png_libpng_ver png_get_header_ver(NULL)
  160127. #endif
  160128. #ifdef PNG_USE_GLOBAL_ARRAYS
  160129. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160130. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160131. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160132. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160133. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160134. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160135. #endif
  160136. #endif /* PNG_NO_EXTERN */
  160137. typedef struct png_color_struct
  160138. {
  160139. png_byte red;
  160140. png_byte green;
  160141. png_byte blue;
  160142. } png_color;
  160143. typedef png_color FAR * png_colorp;
  160144. typedef png_color FAR * FAR * png_colorpp;
  160145. typedef struct png_color_16_struct
  160146. {
  160147. png_byte index; /* used for palette files */
  160148. png_uint_16 red; /* for use in red green blue files */
  160149. png_uint_16 green;
  160150. png_uint_16 blue;
  160151. png_uint_16 gray; /* for use in grayscale files */
  160152. } png_color_16;
  160153. typedef png_color_16 FAR * png_color_16p;
  160154. typedef png_color_16 FAR * FAR * png_color_16pp;
  160155. typedef struct png_color_8_struct
  160156. {
  160157. png_byte red; /* for use in red green blue files */
  160158. png_byte green;
  160159. png_byte blue;
  160160. png_byte gray; /* for use in grayscale files */
  160161. png_byte alpha; /* for alpha channel files */
  160162. } png_color_8;
  160163. typedef png_color_8 FAR * png_color_8p;
  160164. typedef png_color_8 FAR * FAR * png_color_8pp;
  160165. typedef struct png_sPLT_entry_struct
  160166. {
  160167. png_uint_16 red;
  160168. png_uint_16 green;
  160169. png_uint_16 blue;
  160170. png_uint_16 alpha;
  160171. png_uint_16 frequency;
  160172. } png_sPLT_entry;
  160173. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160174. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160175. typedef struct png_sPLT_struct
  160176. {
  160177. png_charp name; /* palette name */
  160178. png_byte depth; /* depth of palette samples */
  160179. png_sPLT_entryp entries; /* palette entries */
  160180. png_int_32 nentries; /* number of palette entries */
  160181. } png_sPLT_t;
  160182. typedef png_sPLT_t FAR * png_sPLT_tp;
  160183. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160184. #ifdef PNG_TEXT_SUPPORTED
  160185. typedef struct png_text_struct
  160186. {
  160187. int compression; /* compression value:
  160188. -1: tEXt, none
  160189. 0: zTXt, deflate
  160190. 1: iTXt, none
  160191. 2: iTXt, deflate */
  160192. png_charp key; /* keyword, 1-79 character description of "text" */
  160193. png_charp text; /* comment, may be an empty string (ie "")
  160194. or a NULL pointer */
  160195. png_size_t text_length; /* length of the text string */
  160196. #ifdef PNG_iTXt_SUPPORTED
  160197. png_size_t itxt_length; /* length of the itxt string */
  160198. png_charp lang; /* language code, 0-79 characters
  160199. or a NULL pointer */
  160200. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160201. chars or a NULL pointer */
  160202. #endif
  160203. } png_text;
  160204. typedef png_text FAR * png_textp;
  160205. typedef png_text FAR * FAR * png_textpp;
  160206. #endif
  160207. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160208. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160209. #define PNG_TEXT_COMPRESSION_NONE -1
  160210. #define PNG_TEXT_COMPRESSION_zTXt 0
  160211. #define PNG_ITXT_COMPRESSION_NONE 1
  160212. #define PNG_ITXT_COMPRESSION_zTXt 2
  160213. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160214. typedef struct png_time_struct
  160215. {
  160216. png_uint_16 year; /* full year, as in, 1995 */
  160217. png_byte month; /* month of year, 1 - 12 */
  160218. png_byte day; /* day of month, 1 - 31 */
  160219. png_byte hour; /* hour of day, 0 - 23 */
  160220. png_byte minute; /* minute of hour, 0 - 59 */
  160221. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160222. } png_time;
  160223. typedef png_time FAR * png_timep;
  160224. typedef png_time FAR * FAR * png_timepp;
  160225. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160226. typedef struct png_unknown_chunk_t
  160227. {
  160228. png_byte name[5];
  160229. png_byte *data;
  160230. png_size_t size;
  160231. png_byte location; /* mode of operation at read time */
  160232. }
  160233. png_unknown_chunk;
  160234. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160235. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160236. #endif
  160237. typedef struct png_info_struct
  160238. {
  160239. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160240. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160241. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160242. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160243. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160244. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160245. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160246. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160247. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160248. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160249. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160250. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160251. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160252. png_byte pixel_depth; /* number of bits per pixel */
  160253. png_byte spare_byte; /* to align the data, and for future use */
  160254. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160255. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160256. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160257. #endif
  160258. #if defined(PNG_sRGB_SUPPORTED)
  160259. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160260. #endif
  160261. #if defined(PNG_TEXT_SUPPORTED)
  160262. int num_text; /* number of comments read/to write */
  160263. int max_text; /* current size of text array */
  160264. png_textp text; /* array of comments read/to write */
  160265. #endif /* PNG_TEXT_SUPPORTED */
  160266. #if defined(PNG_tIME_SUPPORTED)
  160267. png_time mod_time;
  160268. #endif
  160269. #if defined(PNG_sBIT_SUPPORTED)
  160270. png_color_8 sig_bit; /* significant bits in color channels */
  160271. #endif
  160272. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160273. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160274. png_bytep trans; /* transparent values for paletted image */
  160275. png_color_16 trans_values; /* transparent color for non-palette image */
  160276. #endif
  160277. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160278. png_color_16 background;
  160279. #endif
  160280. #if defined(PNG_oFFs_SUPPORTED)
  160281. png_int_32 x_offset; /* x offset on page */
  160282. png_int_32 y_offset; /* y offset on page */
  160283. png_byte offset_unit_type; /* offset units type */
  160284. #endif
  160285. #if defined(PNG_pHYs_SUPPORTED)
  160286. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160287. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160288. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160289. #endif
  160290. #if defined(PNG_hIST_SUPPORTED)
  160291. png_uint_16p hist;
  160292. #endif
  160293. #ifdef PNG_cHRM_SUPPORTED
  160294. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160295. float x_white;
  160296. float y_white;
  160297. float x_red;
  160298. float y_red;
  160299. float x_green;
  160300. float y_green;
  160301. float x_blue;
  160302. float y_blue;
  160303. #endif
  160304. #endif
  160305. #if defined(PNG_pCAL_SUPPORTED)
  160306. png_charp pcal_purpose; /* pCAL chunk description string */
  160307. png_int_32 pcal_X0; /* minimum value */
  160308. png_int_32 pcal_X1; /* maximum value */
  160309. png_charp pcal_units; /* Latin-1 string giving physical units */
  160310. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160311. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160312. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160313. #endif
  160314. #ifdef PNG_FREE_ME_SUPPORTED
  160315. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160316. #endif
  160317. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160318. png_unknown_chunkp unknown_chunks;
  160319. png_size_t unknown_chunks_num;
  160320. #endif
  160321. #if defined(PNG_iCCP_SUPPORTED)
  160322. png_charp iccp_name; /* profile name */
  160323. png_charp iccp_profile; /* International Color Consortium profile data */
  160324. png_uint_32 iccp_proflen; /* ICC profile data length */
  160325. png_byte iccp_compression; /* Always zero */
  160326. #endif
  160327. #if defined(PNG_sPLT_SUPPORTED)
  160328. png_sPLT_tp splt_palettes;
  160329. png_uint_32 splt_palettes_num;
  160330. #endif
  160331. #if defined(PNG_sCAL_SUPPORTED)
  160332. png_byte scal_unit; /* unit of physical scale */
  160333. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160334. double scal_pixel_width; /* width of one pixel */
  160335. double scal_pixel_height; /* height of one pixel */
  160336. #endif
  160337. #ifdef PNG_FIXED_POINT_SUPPORTED
  160338. png_charp scal_s_width; /* string containing height */
  160339. png_charp scal_s_height; /* string containing width */
  160340. #endif
  160341. #endif
  160342. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160343. png_bytepp row_pointers; /* the image bits */
  160344. #endif
  160345. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160346. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160347. #endif
  160348. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160349. png_fixed_point int_x_white;
  160350. png_fixed_point int_y_white;
  160351. png_fixed_point int_x_red;
  160352. png_fixed_point int_y_red;
  160353. png_fixed_point int_x_green;
  160354. png_fixed_point int_y_green;
  160355. png_fixed_point int_x_blue;
  160356. png_fixed_point int_y_blue;
  160357. #endif
  160358. } png_info;
  160359. typedef png_info FAR * png_infop;
  160360. typedef png_info FAR * FAR * png_infopp;
  160361. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160362. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160363. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160364. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160365. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160366. #endif
  160367. #define PNG_COLOR_MASK_PALETTE 1
  160368. #define PNG_COLOR_MASK_COLOR 2
  160369. #define PNG_COLOR_MASK_ALPHA 4
  160370. #define PNG_COLOR_TYPE_GRAY 0
  160371. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160372. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160373. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160374. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160375. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160376. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160377. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160378. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160379. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160380. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160381. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160382. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160383. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160384. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160385. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160386. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160387. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160388. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160389. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160390. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160391. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160392. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160393. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160394. #define PNG_SCALE_METER 1 /* meters per pixel */
  160395. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160396. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160397. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160398. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160399. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160400. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160401. #define PNG_sRGB_INTENT_RELATIVE 1
  160402. #define PNG_sRGB_INTENT_SATURATION 2
  160403. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160404. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160405. #define PNG_KEYWORD_MAX_LENGTH 79
  160406. #define PNG_MAX_PALETTE_LENGTH 256
  160407. #define PNG_INFO_gAMA 0x0001
  160408. #define PNG_INFO_sBIT 0x0002
  160409. #define PNG_INFO_cHRM 0x0004
  160410. #define PNG_INFO_PLTE 0x0008
  160411. #define PNG_INFO_tRNS 0x0010
  160412. #define PNG_INFO_bKGD 0x0020
  160413. #define PNG_INFO_hIST 0x0040
  160414. #define PNG_INFO_pHYs 0x0080
  160415. #define PNG_INFO_oFFs 0x0100
  160416. #define PNG_INFO_tIME 0x0200
  160417. #define PNG_INFO_pCAL 0x0400
  160418. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160419. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160420. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160421. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160422. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160423. typedef struct png_row_info_struct
  160424. {
  160425. png_uint_32 width; /* width of row */
  160426. png_uint_32 rowbytes; /* number of bytes in row */
  160427. png_byte color_type; /* color type of row */
  160428. png_byte bit_depth; /* bit depth of row */
  160429. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160430. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160431. } png_row_info;
  160432. typedef png_row_info FAR * png_row_infop;
  160433. typedef png_row_info FAR * FAR * png_row_infopp;
  160434. typedef struct png_struct_def png_struct;
  160435. typedef png_struct FAR * png_structp;
  160436. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160437. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160438. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160439. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160440. int));
  160441. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160442. int));
  160443. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160444. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160445. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160446. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160447. png_uint_32, int));
  160448. #endif
  160449. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160450. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160451. defined(PNG_LEGACY_SUPPORTED)
  160452. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160453. png_row_infop, png_bytep));
  160454. #endif
  160455. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160456. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160457. #endif
  160458. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160459. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160460. #endif
  160461. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160462. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160463. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160464. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160465. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160466. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160467. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160468. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160469. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160470. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160471. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160472. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160473. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160474. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160475. #define PNG_FLAG_MNG_FILTER_64 0x04
  160476. #define PNG_ALL_MNG_FEATURES 0x05
  160477. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160478. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160479. struct png_struct_def
  160480. {
  160481. #ifdef PNG_SETJMP_SUPPORTED
  160482. jmp_buf jmpbuf; /* used in png_error */
  160483. #endif
  160484. png_error_ptr error_fn; /* function for printing errors and aborting */
  160485. png_error_ptr warning_fn; /* function for printing warnings */
  160486. png_voidp error_ptr; /* user supplied struct for error functions */
  160487. png_rw_ptr write_data_fn; /* function for writing output data */
  160488. png_rw_ptr read_data_fn; /* function for reading input data */
  160489. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160490. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160491. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160492. #endif
  160493. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160494. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160495. #endif
  160496. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160497. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160498. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160499. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160500. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160501. png_byte user_transform_channels; /* channels in user transformed pixels */
  160502. #endif
  160503. #endif
  160504. png_uint_32 mode; /* tells us where we are in the PNG file */
  160505. png_uint_32 flags; /* flags indicating various things to libpng */
  160506. png_uint_32 transformations; /* which transformations to perform */
  160507. z_stream zstream; /* pointer to decompression structure (below) */
  160508. png_bytep zbuf; /* buffer for zlib */
  160509. png_size_t zbuf_size; /* size of zbuf */
  160510. int zlib_level; /* holds zlib compression level */
  160511. int zlib_method; /* holds zlib compression method */
  160512. int zlib_window_bits; /* holds zlib compression window bits */
  160513. int zlib_mem_level; /* holds zlib compression memory level */
  160514. int zlib_strategy; /* holds zlib compression strategy */
  160515. png_uint_32 width; /* width of image in pixels */
  160516. png_uint_32 height; /* height of image in pixels */
  160517. png_uint_32 num_rows; /* number of rows in current pass */
  160518. png_uint_32 usr_width; /* width of row at start of write */
  160519. png_uint_32 rowbytes; /* size of row in bytes */
  160520. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160521. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160522. png_uint_32 row_number; /* current row in interlace pass */
  160523. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160524. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160525. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160526. png_bytep up_row; /* buffer to save "up" row when filtering */
  160527. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160528. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160529. png_row_info row_info; /* used for transformation routines */
  160530. png_uint_32 idat_size; /* current IDAT size for read */
  160531. png_uint_32 crc; /* current chunk CRC value */
  160532. png_colorp palette; /* palette from the input file */
  160533. png_uint_16 num_palette; /* number of color entries in palette */
  160534. png_uint_16 num_trans; /* number of transparency values */
  160535. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160536. png_byte compression; /* file compression type (always 0) */
  160537. png_byte filter; /* file filter type (always 0) */
  160538. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160539. png_byte pass; /* current interlace pass (0 - 6) */
  160540. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160541. png_byte color_type; /* color type of file */
  160542. png_byte bit_depth; /* bit depth of file */
  160543. png_byte usr_bit_depth; /* bit depth of users row */
  160544. png_byte pixel_depth; /* number of bits per pixel */
  160545. png_byte channels; /* number of channels in file */
  160546. png_byte usr_channels; /* channels at start of write */
  160547. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160548. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160549. #ifdef PNG_LEGACY_SUPPORTED
  160550. png_byte filler; /* filler byte for pixel expansion */
  160551. #else
  160552. png_uint_16 filler; /* filler bytes for pixel expansion */
  160553. #endif
  160554. #endif
  160555. #if defined(PNG_bKGD_SUPPORTED)
  160556. png_byte background_gamma_type;
  160557. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160558. float background_gamma;
  160559. # endif
  160560. png_color_16 background; /* background color in screen gamma space */
  160561. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160562. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160563. #endif
  160564. #endif /* PNG_bKGD_SUPPORTED */
  160565. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160566. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160567. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160568. png_uint_32 flush_rows; /* number of rows written since last flush */
  160569. #endif
  160570. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160571. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160572. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160573. float gamma; /* file gamma value */
  160574. float screen_gamma; /* screen gamma value (display_exponent) */
  160575. #endif
  160576. #endif
  160577. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160578. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160579. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160580. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160581. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160582. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160583. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160584. #endif
  160585. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160586. png_color_8 sig_bit; /* significant bits in each available channel */
  160587. #endif
  160588. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160589. png_color_8 shift; /* shift for significant bit tranformation */
  160590. #endif
  160591. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160592. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160593. png_bytep trans; /* transparency values for paletted files */
  160594. png_color_16 trans_values; /* transparency values for non-paletted files */
  160595. #endif
  160596. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160597. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160598. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160599. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160600. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160601. png_progressive_end_ptr end_fn; /* called after image is complete */
  160602. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160603. png_bytep save_buffer; /* buffer for previously read data */
  160604. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160605. png_bytep current_buffer; /* buffer for recently used data */
  160606. png_uint_32 push_length; /* size of current input chunk */
  160607. png_uint_32 skip_length; /* bytes to skip in input data */
  160608. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160609. png_size_t save_buffer_max; /* total size of save_buffer */
  160610. png_size_t buffer_size; /* total amount of available input data */
  160611. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160612. int process_mode; /* what push library is currently doing */
  160613. int cur_palette; /* current push library palette index */
  160614. # if defined(PNG_TEXT_SUPPORTED)
  160615. png_size_t current_text_size; /* current size of text input data */
  160616. png_size_t current_text_left; /* how much text left to read in input */
  160617. png_charp current_text; /* current text chunk buffer */
  160618. png_charp current_text_ptr; /* current location in current_text */
  160619. # endif /* PNG_TEXT_SUPPORTED */
  160620. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160621. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160622. png_bytepp offset_table_ptr;
  160623. png_bytep offset_table;
  160624. png_uint_16 offset_table_number;
  160625. png_uint_16 offset_table_count;
  160626. png_uint_16 offset_table_count_free;
  160627. #endif
  160628. #if defined(PNG_READ_DITHER_SUPPORTED)
  160629. png_bytep palette_lookup; /* lookup table for dithering */
  160630. png_bytep dither_index; /* index translation for palette files */
  160631. #endif
  160632. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160633. png_uint_16p hist; /* histogram */
  160634. #endif
  160635. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160636. png_byte heuristic_method; /* heuristic for row filter selection */
  160637. png_byte num_prev_filters; /* number of weights for previous rows */
  160638. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160639. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160640. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160641. png_uint_16p filter_costs; /* relative filter calculation cost */
  160642. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160643. #endif
  160644. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160645. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160646. #endif
  160647. #ifdef PNG_FREE_ME_SUPPORTED
  160648. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160649. #endif
  160650. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160651. png_voidp user_chunk_ptr;
  160652. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160653. #endif
  160654. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160655. int num_chunk_list;
  160656. png_bytep chunk_list;
  160657. #endif
  160658. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160659. png_byte rgb_to_gray_status;
  160660. png_uint_16 rgb_to_gray_red_coeff;
  160661. png_uint_16 rgb_to_gray_green_coeff;
  160662. png_uint_16 rgb_to_gray_blue_coeff;
  160663. #endif
  160664. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160665. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160666. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160667. #ifdef PNG_1_0_X
  160668. png_byte mng_features_permitted;
  160669. #else
  160670. png_uint_32 mng_features_permitted;
  160671. #endif /* PNG_1_0_X */
  160672. #endif
  160673. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160674. png_fixed_point int_gamma;
  160675. #endif
  160676. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160677. png_byte filter_type;
  160678. #endif
  160679. #if defined(PNG_1_0_X)
  160680. png_uint_32 row_buf_size;
  160681. #endif
  160682. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160683. # if !defined(PNG_1_0_X)
  160684. # if defined(PNG_MMX_CODE_SUPPORTED)
  160685. png_byte mmx_bitdepth_threshold;
  160686. png_uint_32 mmx_rowbytes_threshold;
  160687. # endif
  160688. png_uint_32 asm_flags;
  160689. # endif
  160690. #endif
  160691. #ifdef PNG_USER_MEM_SUPPORTED
  160692. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160693. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160694. png_free_ptr free_fn; /* function for freeing memory */
  160695. #endif
  160696. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160697. #if defined(PNG_READ_DITHER_SUPPORTED)
  160698. png_bytep dither_sort; /* working sort array */
  160699. png_bytep index_to_palette; /* where the original index currently is */
  160700. png_bytep palette_to_index; /* which original index points to this */
  160701. #endif
  160702. png_byte compression_type;
  160703. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160704. png_uint_32 user_width_max;
  160705. png_uint_32 user_height_max;
  160706. #endif
  160707. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160708. png_unknown_chunk unknown_chunk;
  160709. #endif
  160710. };
  160711. typedef png_structp version_1_2_21;
  160712. typedef png_struct FAR * FAR * png_structpp;
  160713. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160714. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160715. int num_bytes));
  160716. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160717. png_size_t num_to_check));
  160718. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160719. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160720. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160721. png_error_ptr error_fn, png_error_ptr warn_fn));
  160722. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160723. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160724. png_error_ptr error_fn, png_error_ptr warn_fn));
  160725. #ifdef PNG_WRITE_SUPPORTED
  160726. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160727. PNGARG((png_structp png_ptr));
  160728. #endif
  160729. #ifdef PNG_WRITE_SUPPORTED
  160730. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160731. PNGARG((png_structp png_ptr, png_uint_32 size));
  160732. #endif
  160733. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160734. #ifdef PNG_USER_MEM_SUPPORTED
  160735. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160736. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160737. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160738. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160739. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160740. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160741. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160742. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160743. #endif
  160744. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160745. png_bytep chunk_name, png_bytep data, png_size_t length));
  160746. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160747. png_bytep chunk_name, png_uint_32 length));
  160748. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160749. png_bytep data, png_size_t length));
  160750. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160751. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160752. PNGARG((png_structp png_ptr));
  160753. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160754. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160755. #undef png_info_init
  160756. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160757. png_sizeof(png_info));
  160758. #endif
  160759. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160760. png_size_t png_info_struct_size));
  160761. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160762. png_infop info_ptr));
  160763. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160764. png_infop info_ptr));
  160765. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160766. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160767. png_infop info_ptr));
  160768. #endif
  160769. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160770. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160771. PNGARG((png_structp png_ptr, png_timep ptime));
  160772. #endif
  160773. #if !defined(_WIN32_WCE)
  160774. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160775. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160776. struct tm FAR * ttime));
  160777. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160778. time_t ttime));
  160779. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160780. #endif /* _WIN32_WCE */
  160781. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160782. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160783. #if !defined(PNG_1_0_X)
  160784. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160785. png_ptr));
  160786. #endif
  160787. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160788. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160789. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160790. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160791. #endif
  160792. #endif
  160793. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160794. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160795. #endif
  160796. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160797. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160798. #endif
  160799. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160800. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160801. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160802. int error_action, double red, double green ));
  160803. #endif
  160804. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160805. int error_action, png_fixed_point red, png_fixed_point green ));
  160806. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160807. png_ptr));
  160808. #endif
  160809. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160810. png_colorp palette));
  160811. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160812. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160813. #endif
  160814. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160815. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160816. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160817. #endif
  160818. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160819. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160820. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160821. #endif
  160822. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160823. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160824. png_uint_32 filler, int flags));
  160825. #define PNG_FILLER_BEFORE 0
  160826. #define PNG_FILLER_AFTER 1
  160827. #if !defined(PNG_1_0_X)
  160828. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160829. png_uint_32 filler, int flags));
  160830. #endif
  160831. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160832. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160833. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160834. #endif
  160835. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160836. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160837. #endif
  160838. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160839. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160840. #endif
  160841. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160842. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160843. png_color_8p true_bits));
  160844. #endif
  160845. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160846. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160847. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160848. #endif
  160849. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160850. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160851. #endif
  160852. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160853. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160854. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160855. png_color_16p background_color, int background_gamma_code,
  160856. int need_expand, double background_gamma));
  160857. #endif
  160858. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160859. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160860. #define PNG_BACKGROUND_GAMMA_FILE 2
  160861. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160862. #endif
  160863. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160864. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160865. #endif
  160866. #if defined(PNG_READ_DITHER_SUPPORTED)
  160867. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160868. png_colorp palette, int num_palette, int maximum_colors,
  160869. png_uint_16p histogram, int full_dither));
  160870. #endif
  160871. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160872. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160873. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160874. double screen_gamma, double default_file_gamma));
  160875. #endif
  160876. #endif
  160877. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160878. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160879. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160880. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160881. int empty_plte_permitted));
  160882. #endif
  160883. #endif
  160884. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160885. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160886. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160887. #endif
  160888. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160889. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160890. png_infop info_ptr));
  160891. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160892. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160893. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160894. #endif
  160895. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160896. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160897. png_bytep row,
  160898. png_bytep display_row));
  160899. #endif
  160900. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160901. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160902. png_bytepp image));
  160903. #endif
  160904. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160905. png_bytep row));
  160906. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160907. png_bytepp row, png_uint_32 num_rows));
  160908. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160909. png_bytepp image));
  160910. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160911. png_infop info_ptr));
  160912. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160913. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160914. png_infop info_ptr));
  160915. #endif
  160916. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160917. png_infopp info_ptr_ptr));
  160918. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160919. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160920. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160921. png_infop end_info_ptr));
  160922. extern PNG_EXPORT(void,png_destroy_write_struct)
  160923. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160924. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160925. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160926. int crit_action, int ancil_action));
  160927. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160928. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160929. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160930. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  160931. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  160932. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  160933. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  160934. int filters));
  160935. #define PNG_NO_FILTERS 0x00
  160936. #define PNG_FILTER_NONE 0x08
  160937. #define PNG_FILTER_SUB 0x10
  160938. #define PNG_FILTER_UP 0x20
  160939. #define PNG_FILTER_AVG 0x40
  160940. #define PNG_FILTER_PAETH 0x80
  160941. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  160942. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  160943. #define PNG_FILTER_VALUE_NONE 0
  160944. #define PNG_FILTER_VALUE_SUB 1
  160945. #define PNG_FILTER_VALUE_UP 2
  160946. #define PNG_FILTER_VALUE_AVG 3
  160947. #define PNG_FILTER_VALUE_PAETH 4
  160948. #define PNG_FILTER_VALUE_LAST 5
  160949. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  160950. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160951. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  160952. int heuristic_method, int num_weights, png_doublep filter_weights,
  160953. png_doublep filter_costs));
  160954. #endif
  160955. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  160956. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  160957. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  160958. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  160959. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  160960. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  160961. int level));
  160962. extern PNG_EXPORT(void,png_set_compression_mem_level)
  160963. PNGARG((png_structp png_ptr, int mem_level));
  160964. extern PNG_EXPORT(void,png_set_compression_strategy)
  160965. PNGARG((png_structp png_ptr, int strategy));
  160966. extern PNG_EXPORT(void,png_set_compression_window_bits)
  160967. PNGARG((png_structp png_ptr, int window_bits));
  160968. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  160969. int method));
  160970. #if !defined(PNG_NO_STDIO)
  160971. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  160972. #endif
  160973. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  160974. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  160975. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  160976. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  160977. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  160978. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  160979. png_voidp io_ptr, png_rw_ptr read_data_fn));
  160980. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  160981. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  160982. png_read_status_ptr read_row_fn));
  160983. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  160984. png_write_status_ptr write_row_fn));
  160985. #ifdef PNG_USER_MEM_SUPPORTED
  160986. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  160987. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160988. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  160989. #endif
  160990. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160991. defined(PNG_LEGACY_SUPPORTED)
  160992. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  160993. png_ptr, png_user_transform_ptr read_user_transform_fn));
  160994. #endif
  160995. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160996. defined(PNG_LEGACY_SUPPORTED)
  160997. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  160998. png_ptr, png_user_transform_ptr write_user_transform_fn));
  160999. #endif
  161000. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161001. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161002. defined(PNG_LEGACY_SUPPORTED)
  161003. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161004. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161005. int user_transform_channels));
  161006. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161007. PNGARG((png_structp png_ptr));
  161008. #endif
  161009. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161010. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161011. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161012. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161013. png_ptr));
  161014. #endif
  161015. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161016. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161017. png_voidp progressive_ptr,
  161018. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161019. png_progressive_end_ptr end_fn));
  161020. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161021. PNGARG((png_structp png_ptr));
  161022. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161023. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161024. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161025. png_bytep old_row, png_bytep new_row));
  161026. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161027. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161028. png_uint_32 size));
  161029. #if defined(PNG_1_0_X)
  161030. # define png_malloc_warn png_malloc
  161031. #else
  161032. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161033. png_uint_32 size));
  161034. #endif
  161035. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161036. #if defined(PNG_1_0_X)
  161037. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161038. uInt size));
  161039. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161040. #endif
  161041. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161042. png_infop info_ptr, png_uint_32 free_me, int num));
  161043. #ifdef PNG_FREE_ME_SUPPORTED
  161044. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161045. png_infop info_ptr, int freer, png_uint_32 mask));
  161046. #endif
  161047. #define PNG_DESTROY_WILL_FREE_DATA 1
  161048. #define PNG_SET_WILL_FREE_DATA 1
  161049. #define PNG_USER_WILL_FREE_DATA 2
  161050. #define PNG_FREE_HIST 0x0008
  161051. #define PNG_FREE_ICCP 0x0010
  161052. #define PNG_FREE_SPLT 0x0020
  161053. #define PNG_FREE_ROWS 0x0040
  161054. #define PNG_FREE_PCAL 0x0080
  161055. #define PNG_FREE_SCAL 0x0100
  161056. #define PNG_FREE_UNKN 0x0200
  161057. #define PNG_FREE_LIST 0x0400
  161058. #define PNG_FREE_PLTE 0x1000
  161059. #define PNG_FREE_TRNS 0x2000
  161060. #define PNG_FREE_TEXT 0x4000
  161061. #define PNG_FREE_ALL 0x7fff
  161062. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161063. #ifdef PNG_USER_MEM_SUPPORTED
  161064. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161065. png_uint_32 size));
  161066. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161067. png_voidp ptr));
  161068. #endif
  161069. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161070. png_voidp s1, png_voidp s2, png_uint_32 size));
  161071. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161072. png_voidp s1, int value, png_uint_32 size));
  161073. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161074. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161075. int check));
  161076. #endif /* USE_FAR_KEYWORD */
  161077. #ifndef PNG_NO_ERROR_TEXT
  161078. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161079. png_const_charp error_message));
  161080. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161081. png_const_charp error_message));
  161082. #else
  161083. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161084. #endif
  161085. #ifndef PNG_NO_WARNINGS
  161086. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161087. png_const_charp warning_message));
  161088. #ifdef PNG_READ_SUPPORTED
  161089. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161090. png_const_charp warning_message));
  161091. #endif /* PNG_READ_SUPPORTED */
  161092. #endif /* PNG_NO_WARNINGS */
  161093. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161094. png_infop info_ptr, png_uint_32 flag));
  161095. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161096. png_infop info_ptr));
  161097. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161098. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161099. png_infop info_ptr));
  161100. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161101. png_infop info_ptr, png_bytepp row_pointers));
  161102. #endif
  161103. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161104. png_infop info_ptr));
  161105. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161106. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161107. png_ptr, png_infop info_ptr));
  161108. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161109. png_ptr, png_infop info_ptr));
  161110. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161111. png_ptr, png_infop info_ptr));
  161112. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161113. png_ptr, png_infop info_ptr));
  161114. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161115. png_ptr, png_infop info_ptr));
  161116. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161117. png_ptr, png_infop info_ptr));
  161118. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161119. png_ptr, png_infop info_ptr));
  161120. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161121. png_ptr, png_infop info_ptr));
  161122. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161123. png_ptr, png_infop info_ptr));
  161124. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161125. png_ptr, png_infop info_ptr));
  161126. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161127. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161128. png_ptr, png_infop info_ptr));
  161129. #endif
  161130. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161131. png_ptr, png_infop info_ptr));
  161132. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161133. png_ptr, png_infop info_ptr));
  161134. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161135. png_ptr, png_infop info_ptr));
  161136. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161137. png_ptr, png_infop info_ptr));
  161138. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161139. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161140. png_infop info_ptr));
  161141. #if defined(PNG_bKGD_SUPPORTED)
  161142. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161143. png_infop info_ptr, png_color_16p *background));
  161144. #endif
  161145. #if defined(PNG_bKGD_SUPPORTED)
  161146. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161147. png_infop info_ptr, png_color_16p background));
  161148. #endif
  161149. #if defined(PNG_cHRM_SUPPORTED)
  161150. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161151. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161152. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161153. double *red_y, double *green_x, double *green_y, double *blue_x,
  161154. double *blue_y));
  161155. #endif
  161156. #ifdef PNG_FIXED_POINT_SUPPORTED
  161157. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161158. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161159. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161160. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161161. *int_blue_x, png_fixed_point *int_blue_y));
  161162. #endif
  161163. #endif
  161164. #if defined(PNG_cHRM_SUPPORTED)
  161165. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161166. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161167. png_infop info_ptr, double white_x, double white_y, double red_x,
  161168. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161169. #endif
  161170. #ifdef PNG_FIXED_POINT_SUPPORTED
  161171. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161172. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161173. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161174. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161175. png_fixed_point int_blue_y));
  161176. #endif
  161177. #endif
  161178. #if defined(PNG_gAMA_SUPPORTED)
  161179. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161180. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161181. png_infop info_ptr, double *file_gamma));
  161182. #endif
  161183. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161184. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161185. #endif
  161186. #if defined(PNG_gAMA_SUPPORTED)
  161187. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161188. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161189. png_infop info_ptr, double file_gamma));
  161190. #endif
  161191. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161192. png_infop info_ptr, png_fixed_point int_file_gamma));
  161193. #endif
  161194. #if defined(PNG_hIST_SUPPORTED)
  161195. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161196. png_infop info_ptr, png_uint_16p *hist));
  161197. #endif
  161198. #if defined(PNG_hIST_SUPPORTED)
  161199. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161200. png_infop info_ptr, png_uint_16p hist));
  161201. #endif
  161202. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161203. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161204. int *bit_depth, int *color_type, int *interlace_method,
  161205. int *compression_method, int *filter_method));
  161206. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161207. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161208. int color_type, int interlace_method, int compression_method,
  161209. int filter_method));
  161210. #if defined(PNG_oFFs_SUPPORTED)
  161211. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161212. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161213. int *unit_type));
  161214. #endif
  161215. #if defined(PNG_oFFs_SUPPORTED)
  161216. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161217. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161218. int unit_type));
  161219. #endif
  161220. #if defined(PNG_pCAL_SUPPORTED)
  161221. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161222. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161223. int *type, int *nparams, png_charp *units, png_charpp *params));
  161224. #endif
  161225. #if defined(PNG_pCAL_SUPPORTED)
  161226. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161227. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161228. int type, int nparams, png_charp units, png_charpp params));
  161229. #endif
  161230. #if defined(PNG_pHYs_SUPPORTED)
  161231. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161232. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161233. #endif
  161234. #if defined(PNG_pHYs_SUPPORTED)
  161235. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161236. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161237. #endif
  161238. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161239. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161240. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161241. png_infop info_ptr, png_colorp palette, int num_palette));
  161242. #if defined(PNG_sBIT_SUPPORTED)
  161243. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161244. png_infop info_ptr, png_color_8p *sig_bit));
  161245. #endif
  161246. #if defined(PNG_sBIT_SUPPORTED)
  161247. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161248. png_infop info_ptr, png_color_8p sig_bit));
  161249. #endif
  161250. #if defined(PNG_sRGB_SUPPORTED)
  161251. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161252. png_infop info_ptr, int *intent));
  161253. #endif
  161254. #if defined(PNG_sRGB_SUPPORTED)
  161255. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161256. png_infop info_ptr, int intent));
  161257. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161258. png_infop info_ptr, int intent));
  161259. #endif
  161260. #if defined(PNG_iCCP_SUPPORTED)
  161261. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161262. png_infop info_ptr, png_charpp name, int *compression_type,
  161263. png_charpp profile, png_uint_32 *proflen));
  161264. #endif
  161265. #if defined(PNG_iCCP_SUPPORTED)
  161266. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161267. png_infop info_ptr, png_charp name, int compression_type,
  161268. png_charp profile, png_uint_32 proflen));
  161269. #endif
  161270. #if defined(PNG_sPLT_SUPPORTED)
  161271. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161272. png_infop info_ptr, png_sPLT_tpp entries));
  161273. #endif
  161274. #if defined(PNG_sPLT_SUPPORTED)
  161275. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161276. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161277. #endif
  161278. #if defined(PNG_TEXT_SUPPORTED)
  161279. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161280. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161281. #endif
  161282. #if defined(PNG_TEXT_SUPPORTED)
  161283. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161284. png_infop info_ptr, png_textp text_ptr, int num_text));
  161285. #endif
  161286. #if defined(PNG_tIME_SUPPORTED)
  161287. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161288. png_infop info_ptr, png_timep *mod_time));
  161289. #endif
  161290. #if defined(PNG_tIME_SUPPORTED)
  161291. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161292. png_infop info_ptr, png_timep mod_time));
  161293. #endif
  161294. #if defined(PNG_tRNS_SUPPORTED)
  161295. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161296. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161297. png_color_16p *trans_values));
  161298. #endif
  161299. #if defined(PNG_tRNS_SUPPORTED)
  161300. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161301. png_infop info_ptr, png_bytep trans, int num_trans,
  161302. png_color_16p trans_values));
  161303. #endif
  161304. #if defined(PNG_tRNS_SUPPORTED)
  161305. #endif
  161306. #if defined(PNG_sCAL_SUPPORTED)
  161307. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161308. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161309. png_infop info_ptr, int *unit, double *width, double *height));
  161310. #else
  161311. #ifdef PNG_FIXED_POINT_SUPPORTED
  161312. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161313. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161314. #endif
  161315. #endif
  161316. #endif /* PNG_sCAL_SUPPORTED */
  161317. #if defined(PNG_sCAL_SUPPORTED)
  161318. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161319. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161320. png_infop info_ptr, int unit, double width, double height));
  161321. #else
  161322. #ifdef PNG_FIXED_POINT_SUPPORTED
  161323. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161324. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161325. #endif
  161326. #endif
  161327. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161328. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161329. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161330. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161331. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161332. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161333. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161334. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161335. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161336. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161337. #endif
  161338. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161339. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161340. chunk_name));
  161341. #endif
  161342. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161343. png_infop info_ptr, int mask));
  161344. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161345. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161346. png_infop info_ptr,
  161347. int transforms,
  161348. png_voidp params));
  161349. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161350. png_infop info_ptr,
  161351. int transforms,
  161352. png_voidp params));
  161353. #endif
  161354. #ifdef PNG_DEBUG
  161355. #if (PNG_DEBUG > 0)
  161356. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161357. #include <crtdbg.h>
  161358. #if (PNG_DEBUG > 1)
  161359. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161360. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161361. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161362. #endif
  161363. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161364. #ifndef PNG_DEBUG_FILE
  161365. #define PNG_DEBUG_FILE stderr
  161366. #endif /* PNG_DEBUG_FILE */
  161367. #if (PNG_DEBUG > 1)
  161368. #define png_debug(l,m) \
  161369. { \
  161370. int num_tabs=l; \
  161371. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161372. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161373. }
  161374. #define png_debug1(l,m,p1) \
  161375. { \
  161376. int num_tabs=l; \
  161377. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161378. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161379. }
  161380. #define png_debug2(l,m,p1,p2) \
  161381. { \
  161382. int num_tabs=l; \
  161383. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161384. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161385. }
  161386. #endif /* (PNG_DEBUG > 1) */
  161387. #endif /* _MSC_VER */
  161388. #endif /* (PNG_DEBUG > 0) */
  161389. #endif /* PNG_DEBUG */
  161390. #ifndef png_debug
  161391. #define png_debug(l, m)
  161392. #endif
  161393. #ifndef png_debug1
  161394. #define png_debug1(l, m, p1)
  161395. #endif
  161396. #ifndef png_debug2
  161397. #define png_debug2(l, m, p1, p2)
  161398. #endif
  161399. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161400. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161401. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161402. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161403. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161404. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161405. png_ptr, png_uint_32 mng_features_permitted));
  161406. #endif
  161407. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161408. #define PNG_HANDLE_CHUNK_NEVER 1
  161409. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161410. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161411. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161412. #if defined(PNG_MMX_CODE_SUPPORTED)
  161413. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161414. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161415. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161416. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161417. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161418. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161419. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161420. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161421. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161422. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161423. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161424. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161425. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161426. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161427. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161428. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161429. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161430. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161431. | PNG_MMX_READ_FLAGS \
  161432. | PNG_MMX_WRITE_FLAGS )
  161433. #define PNG_SELECT_READ 1
  161434. #define PNG_SELECT_WRITE 2
  161435. #endif /* PNG_MMX_CODE_SUPPORTED */
  161436. #if !defined(PNG_1_0_X)
  161437. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161438. PNGARG((int flag_select, int *compilerID));
  161439. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161440. PNGARG((int flag_select));
  161441. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161442. PNGARG((png_structp png_ptr));
  161443. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161444. PNGARG((png_structp png_ptr));
  161445. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161446. PNGARG((png_structp png_ptr));
  161447. extern PNG_EXPORT(void,png_set_asm_flags)
  161448. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161449. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161450. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161451. png_uint_32 mmx_rowbytes_threshold));
  161452. #endif /* PNG_1_0_X */
  161453. #if !defined(PNG_1_0_X)
  161454. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161455. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161456. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161457. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161458. png_ptr, png_uint_32 strip_mode));
  161459. #endif
  161460. #endif /* PNG_1_0_X */
  161461. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161462. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161463. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161464. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161465. png_ptr));
  161466. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161467. png_ptr));
  161468. #endif
  161469. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161470. # define png_composite(composite, fg, alpha, bg) \
  161471. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161472. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161473. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161474. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161475. # define png_composite_16(composite, fg, alpha, bg) \
  161476. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161477. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161478. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161479. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161480. #else /* standard method using integer division */
  161481. # define png_composite(composite, fg, alpha, bg) \
  161482. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161483. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161484. (png_uint_16)127) / 255)
  161485. # define png_composite_16(composite, fg, alpha, bg) \
  161486. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161487. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161488. (png_uint_32)32767) / (png_uint_32)65535L)
  161489. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161490. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161491. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161492. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161493. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161494. #else
  161495. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161496. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161497. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161498. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161499. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161500. PNGARG((png_structp png_ptr, png_bytep buf));
  161501. extern PNG_EXPORT(void,png_save_uint_32)
  161502. PNGARG((png_bytep buf, png_uint_32 i));
  161503. extern PNG_EXPORT(void,png_save_int_32)
  161504. PNGARG((png_bytep buf, png_int_32 i));
  161505. extern PNG_EXPORT(void,png_save_uint_16)
  161506. PNGARG((png_bytep buf, unsigned int i));
  161507. #define PNG_HAVE_IHDR 0x01
  161508. #define PNG_HAVE_PLTE 0x02
  161509. #define PNG_HAVE_IDAT 0x04
  161510. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161511. #define PNG_HAVE_IEND 0x10
  161512. #if defined(PNG_INTERNAL)
  161513. #define PNG_HAVE_gAMA 0x20
  161514. #define PNG_HAVE_cHRM 0x40
  161515. #define PNG_HAVE_sRGB 0x80
  161516. #define PNG_HAVE_CHUNK_HEADER 0x100
  161517. #define PNG_WROTE_tIME 0x200
  161518. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161519. #define PNG_BACKGROUND_IS_GRAY 0x800
  161520. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161521. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161522. #define PNG_BGR 0x0001
  161523. #define PNG_INTERLACE 0x0002
  161524. #define PNG_PACK 0x0004
  161525. #define PNG_SHIFT 0x0008
  161526. #define PNG_SWAP_BYTES 0x0010
  161527. #define PNG_INVERT_MONO 0x0020
  161528. #define PNG_DITHER 0x0040
  161529. #define PNG_BACKGROUND 0x0080
  161530. #define PNG_BACKGROUND_EXPAND 0x0100
  161531. #define PNG_16_TO_8 0x0400
  161532. #define PNG_RGBA 0x0800
  161533. #define PNG_EXPAND 0x1000
  161534. #define PNG_GAMMA 0x2000
  161535. #define PNG_GRAY_TO_RGB 0x4000
  161536. #define PNG_FILLER 0x8000L
  161537. #define PNG_PACKSWAP 0x10000L
  161538. #define PNG_SWAP_ALPHA 0x20000L
  161539. #define PNG_STRIP_ALPHA 0x40000L
  161540. #define PNG_INVERT_ALPHA 0x80000L
  161541. #define PNG_USER_TRANSFORM 0x100000L
  161542. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161543. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161544. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161545. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161546. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161547. #define PNG_STRUCT_PNG 0x0001
  161548. #define PNG_STRUCT_INFO 0x0002
  161549. #define PNG_WEIGHT_SHIFT 8
  161550. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161551. #define PNG_COST_SHIFT 3
  161552. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161553. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161554. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161555. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161556. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161557. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161558. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161559. #define PNG_FLAG_ROW_INIT 0x0040
  161560. #define PNG_FLAG_FILLER_AFTER 0x0080
  161561. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161562. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161563. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161564. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161565. #define PNG_FLAG_FREE_PLTE 0x1000
  161566. #define PNG_FLAG_FREE_TRNS 0x2000
  161567. #define PNG_FLAG_FREE_HIST 0x4000
  161568. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161569. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161570. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161571. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161572. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161573. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161574. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161575. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161576. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161577. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161578. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161579. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161580. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161581. PNG_FLAG_CRC_CRITICAL_MASK)
  161582. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161583. abs((int)((c1).green) - (int)((c2).green)) + \
  161584. abs((int)((c1).blue) - (int)((c2).blue)))
  161585. #define PNG_ROWBYTES(pixel_bits, width) \
  161586. ((pixel_bits) >= 8 ? \
  161587. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161588. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161589. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161590. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161591. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161592. #ifdef PNG_USE_GLOBAL_ARRAYS
  161593. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161594. #else
  161595. #endif
  161596. #endif /* PNG_NO_EXTERN */
  161597. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161598. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161599. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161600. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161601. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161602. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161603. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161604. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161605. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161606. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161607. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161608. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161609. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161610. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161611. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161612. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161613. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161614. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161615. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161616. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161617. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161618. #ifdef PNG_USE_GLOBAL_ARRAYS
  161619. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161620. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161621. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161622. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161623. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161624. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161625. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161626. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161627. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161628. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161629. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161630. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161631. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161632. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161633. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161634. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161635. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161636. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161637. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161638. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161639. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161640. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161641. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161642. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161643. #undef png_read_init
  161644. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161645. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161646. #endif
  161647. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161648. png_const_charp user_png_ver, png_size_t png_struct_size));
  161649. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161650. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161651. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161652. png_info_size));
  161653. #endif
  161654. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161655. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161656. #undef png_write_init
  161657. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161658. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161659. #endif
  161660. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161661. png_const_charp user_png_ver, png_size_t png_struct_size));
  161662. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161663. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161664. png_info_size));
  161665. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161666. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161667. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161668. malloc_fn, png_voidp mem_ptr));
  161669. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161670. png_free_ptr free_fn, png_voidp mem_ptr));
  161671. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161672. png_infop info_ptr));
  161673. #ifndef PNG_1_0_X
  161674. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161675. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161676. #ifdef PNG_SIZE_T
  161677. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161678. #endif
  161679. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161680. png_bytep data, png_size_t length));
  161681. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161682. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161683. png_bytep buffer, png_size_t length));
  161684. #endif
  161685. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161686. png_bytep data, png_size_t length));
  161687. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161688. #if !defined(PNG_NO_STDIO)
  161689. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161690. #endif
  161691. #endif
  161692. #else /* PNG_1_0_X */
  161693. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161694. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161695. png_bytep buffer, png_size_t length));
  161696. #endif
  161697. #endif /* PNG_1_0_X */
  161698. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161699. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161700. png_size_t length));
  161701. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161702. png_size_t length));
  161703. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161704. png_size_t length));
  161705. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161706. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161707. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161708. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161709. png_size_t prefix_length, png_size_t *data_length));
  161710. #endif
  161711. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161712. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161713. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161714. png_size_t length));
  161715. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161716. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161717. #endif
  161718. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161719. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161720. png_uint_32 height,
  161721. int bit_depth, int color_type, int compression_method, int filter_method,
  161722. int interlace_method));
  161723. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161724. png_uint_32 num_pal));
  161725. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161726. png_size_t length));
  161727. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161728. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161729. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161730. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161731. #endif
  161732. #ifdef PNG_FIXED_POINT_SUPPORTED
  161733. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161734. file_gamma));
  161735. #endif
  161736. #endif
  161737. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161738. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161739. int color_type));
  161740. #endif
  161741. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161742. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161743. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161744. double white_x, double white_y,
  161745. double red_x, double red_y, double green_x, double green_y,
  161746. double blue_x, double blue_y));
  161747. #endif
  161748. #ifdef PNG_FIXED_POINT_SUPPORTED
  161749. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161750. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161751. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161752. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161753. png_fixed_point int_blue_y));
  161754. #endif
  161755. #endif
  161756. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161757. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161758. int intent));
  161759. #endif
  161760. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161761. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161762. png_charp name, int compression_type,
  161763. png_charp profile, int proflen));
  161764. #endif
  161765. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161766. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161767. png_sPLT_tp palette));
  161768. #endif
  161769. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161770. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161771. png_color_16p values, int number, int color_type));
  161772. #endif
  161773. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161774. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161775. png_color_16p values, int color_type));
  161776. #endif
  161777. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161778. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161779. int num_hist));
  161780. #endif
  161781. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161782. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161783. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161784. png_charp key, png_charpp new_key));
  161785. #endif
  161786. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161787. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161788. png_charp text, png_size_t text_len));
  161789. #endif
  161790. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161791. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161792. png_charp text, png_size_t text_len, int compression));
  161793. #endif
  161794. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161795. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161796. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161797. png_charp text));
  161798. #endif
  161799. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161800. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161801. png_infop info_ptr, png_textp text_ptr, int num_text));
  161802. #endif
  161803. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161804. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161805. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161806. #endif
  161807. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161808. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161809. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161810. png_charp units, png_charpp params));
  161811. #endif
  161812. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161813. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161814. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161815. int unit_type));
  161816. #endif
  161817. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161818. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161819. png_timep mod_time));
  161820. #endif
  161821. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161822. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161823. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161824. int unit, double width, double height));
  161825. #else
  161826. #ifdef PNG_FIXED_POINT_SUPPORTED
  161827. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161828. int unit, png_charp width, png_charp height));
  161829. #endif
  161830. #endif
  161831. #endif
  161832. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161833. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161834. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161835. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161836. #endif
  161837. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161838. int mask));
  161839. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161840. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161841. #endif
  161842. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161843. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161844. png_bytep row, int pass));
  161845. #endif
  161846. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161847. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161848. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161849. png_row_infop row_info));
  161850. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161851. png_bytep filtered_row));
  161852. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161853. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161854. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161855. png_infop info_ptr));
  161856. #if defined(PNG_READ_FILLER_SUPPORTED)
  161857. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161858. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161859. #endif
  161860. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161861. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161862. png_bytep row));
  161863. #endif
  161864. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161865. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161866. png_bytep row));
  161867. #endif
  161868. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161869. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161870. png_bytep row));
  161871. #endif
  161872. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161873. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161874. png_bytep row));
  161875. #endif
  161876. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161877. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161878. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161879. png_bytep row, png_uint_32 flags));
  161880. #endif
  161881. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161882. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161883. #endif
  161884. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161885. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161886. #endif
  161887. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161888. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161889. row_info, png_bytep row));
  161890. #endif
  161891. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161892. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161893. png_bytep row));
  161894. #endif
  161895. #if defined(PNG_READ_PACK_SUPPORTED)
  161896. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161897. #endif
  161898. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161899. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161900. png_color_8p sig_bits));
  161901. #endif
  161902. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161903. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161904. #endif
  161905. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161906. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161907. #endif
  161908. #if defined(PNG_READ_DITHER_SUPPORTED)
  161909. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161910. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161911. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161912. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161913. png_colorp palette, int num_palette));
  161914. # endif
  161915. #endif
  161916. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161917. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161918. #endif
  161919. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161920. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161921. png_bytep row, png_uint_32 bit_depth));
  161922. #endif
  161923. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161924. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161925. png_color_8p bit_depth));
  161926. #endif
  161927. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161928. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161929. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161930. png_color_16p trans_values, png_color_16p background,
  161931. png_color_16p background_1,
  161932. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  161933. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  161934. png_uint_16pp gamma_16_to_1, int gamma_shift));
  161935. #else
  161936. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161937. png_color_16p trans_values, png_color_16p background));
  161938. #endif
  161939. #endif
  161940. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161941. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  161942. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  161943. int gamma_shift));
  161944. #endif
  161945. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161946. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  161947. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  161948. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  161949. png_bytep row, png_color_16p trans_value));
  161950. #endif
  161951. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  161952. png_uint_32 length));
  161953. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  161954. png_uint_32 length));
  161955. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  161956. png_uint_32 length));
  161957. #if defined(PNG_READ_bKGD_SUPPORTED)
  161958. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  161959. png_uint_32 length));
  161960. #endif
  161961. #if defined(PNG_READ_cHRM_SUPPORTED)
  161962. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  161963. png_uint_32 length));
  161964. #endif
  161965. #if defined(PNG_READ_gAMA_SUPPORTED)
  161966. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  161967. png_uint_32 length));
  161968. #endif
  161969. #if defined(PNG_READ_hIST_SUPPORTED)
  161970. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  161971. png_uint_32 length));
  161972. #endif
  161973. #if defined(PNG_READ_iCCP_SUPPORTED)
  161974. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  161975. png_uint_32 length));
  161976. #endif /* PNG_READ_iCCP_SUPPORTED */
  161977. #if defined(PNG_READ_iTXt_SUPPORTED)
  161978. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161979. png_uint_32 length));
  161980. #endif
  161981. #if defined(PNG_READ_oFFs_SUPPORTED)
  161982. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161983. png_uint_32 length));
  161984. #endif
  161985. #if defined(PNG_READ_pCAL_SUPPORTED)
  161986. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161987. png_uint_32 length));
  161988. #endif
  161989. #if defined(PNG_READ_pHYs_SUPPORTED)
  161990. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161991. png_uint_32 length));
  161992. #endif
  161993. #if defined(PNG_READ_sBIT_SUPPORTED)
  161994. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161995. png_uint_32 length));
  161996. #endif
  161997. #if defined(PNG_READ_sCAL_SUPPORTED)
  161998. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161999. png_uint_32 length));
  162000. #endif
  162001. #if defined(PNG_READ_sPLT_SUPPORTED)
  162002. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162003. png_uint_32 length));
  162004. #endif /* PNG_READ_sPLT_SUPPORTED */
  162005. #if defined(PNG_READ_sRGB_SUPPORTED)
  162006. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162007. png_uint_32 length));
  162008. #endif
  162009. #if defined(PNG_READ_tEXt_SUPPORTED)
  162010. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162011. png_uint_32 length));
  162012. #endif
  162013. #if defined(PNG_READ_tIME_SUPPORTED)
  162014. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162015. png_uint_32 length));
  162016. #endif
  162017. #if defined(PNG_READ_tRNS_SUPPORTED)
  162018. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162019. png_uint_32 length));
  162020. #endif
  162021. #if defined(PNG_READ_zTXt_SUPPORTED)
  162022. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162023. png_uint_32 length));
  162024. #endif
  162025. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162026. png_infop info_ptr, png_uint_32 length));
  162027. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162028. png_bytep chunk_name));
  162029. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162030. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162031. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162032. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162033. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162034. png_infop info_ptr));
  162035. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162036. png_infop info_ptr));
  162037. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162038. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162039. png_uint_32 length));
  162040. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162041. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162042. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162043. png_bytep buffer, png_size_t buffer_length));
  162044. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162045. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162046. png_bytep buffer, png_size_t buffer_length));
  162047. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162048. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162049. png_infop info_ptr, png_uint_32 length));
  162050. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162051. png_infop info_ptr));
  162052. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162053. png_infop info_ptr));
  162054. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162055. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162056. png_infop info_ptr));
  162057. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162058. png_infop info_ptr));
  162059. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162060. #if defined(PNG_READ_tEXt_SUPPORTED)
  162061. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162062. png_infop info_ptr, png_uint_32 length));
  162063. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162064. png_infop info_ptr));
  162065. #endif
  162066. #if defined(PNG_READ_zTXt_SUPPORTED)
  162067. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162068. png_infop info_ptr, png_uint_32 length));
  162069. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162070. png_infop info_ptr));
  162071. #endif
  162072. #if defined(PNG_READ_iTXt_SUPPORTED)
  162073. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162074. png_infop info_ptr, png_uint_32 length));
  162075. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162076. png_infop info_ptr));
  162077. #endif
  162078. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162079. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162080. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162081. png_bytep row));
  162082. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162083. png_bytep row));
  162084. #endif
  162085. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162086. #if defined(PNG_MMX_CODE_SUPPORTED)
  162087. /* PRIVATE */
  162088. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162089. #endif
  162090. #endif
  162091. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162092. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162093. png_infop info_ptr));
  162094. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162095. png_infop info_ptr));
  162096. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162097. png_infop info_ptr));
  162098. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162099. png_infop info_ptr));
  162100. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162101. png_infop info_ptr));
  162102. #if defined(PNG_pHYs_SUPPORTED)
  162103. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162104. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162105. #endif /* PNG_pHYs_SUPPORTED */
  162106. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162107. #endif /* PNG_INTERNAL */
  162108. #ifdef __cplusplus
  162109. }
  162110. #endif
  162111. #endif /* PNG_VERSION_INFO_ONLY */
  162112. #endif /* PNG_H */
  162113. /*** End of inlined file: png.h ***/
  162114. #define PNG_NO_EXTERN
  162115. /*** Start of inlined file: png.c ***/
  162116. #define PNG_INTERNAL
  162117. #define PNG_NO_EXTERN
  162118. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162119. #ifdef PNG_USE_GLOBAL_ARRAYS
  162120. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162121. #ifdef PNG_READ_SUPPORTED
  162122. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162123. #endif /* PNG_READ_SUPPORTED */
  162124. PNG_IHDR;
  162125. PNG_IDAT;
  162126. PNG_IEND;
  162127. PNG_PLTE;
  162128. PNG_bKGD;
  162129. PNG_cHRM;
  162130. PNG_gAMA;
  162131. PNG_hIST;
  162132. PNG_iCCP;
  162133. PNG_iTXt;
  162134. PNG_oFFs;
  162135. PNG_pCAL;
  162136. PNG_sCAL;
  162137. PNG_pHYs;
  162138. PNG_sBIT;
  162139. PNG_sPLT;
  162140. PNG_sRGB;
  162141. PNG_tEXt;
  162142. PNG_tIME;
  162143. PNG_tRNS;
  162144. PNG_zTXt;
  162145. #ifdef PNG_READ_SUPPORTED
  162146. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162147. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162148. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162149. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162150. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162151. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162152. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162153. #endif /* PNG_READ_SUPPORTED */
  162154. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162155. #ifdef PNG_READ_SUPPORTED
  162156. void PNGAPI
  162157. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162158. {
  162159. if(png_ptr == NULL) return;
  162160. png_debug(1, "in png_set_sig_bytes\n");
  162161. if (num_bytes > 8)
  162162. png_error(png_ptr, "Too many bytes for PNG signature.");
  162163. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162164. }
  162165. int PNGAPI
  162166. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162167. {
  162168. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162169. if (num_to_check > 8)
  162170. num_to_check = 8;
  162171. else if (num_to_check < 1)
  162172. return (-1);
  162173. if (start > 7)
  162174. return (-1);
  162175. if (start + num_to_check > 8)
  162176. num_to_check = 8 - start;
  162177. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162178. }
  162179. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162180. int PNGAPI
  162181. png_check_sig(png_bytep sig, int num)
  162182. {
  162183. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162184. }
  162185. #endif
  162186. #endif /* PNG_READ_SUPPORTED */
  162187. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162188. #ifdef PNG_1_0_X
  162189. voidpf PNGAPI
  162190. #else
  162191. voidpf /* private */
  162192. #endif
  162193. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162194. {
  162195. png_voidp ptr;
  162196. png_structp p=(png_structp)png_ptr;
  162197. png_uint_32 save_flags=p->flags;
  162198. png_uint_32 num_bytes;
  162199. if(png_ptr == NULL) return (NULL);
  162200. if (items > PNG_UINT_32_MAX/size)
  162201. {
  162202. png_warning (p, "Potential overflow in png_zalloc()");
  162203. return (NULL);
  162204. }
  162205. num_bytes = (png_uint_32)items * size;
  162206. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162207. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162208. p->flags=save_flags;
  162209. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162210. if (ptr == NULL)
  162211. return ((voidpf)ptr);
  162212. if (num_bytes > (png_uint_32)0x8000L)
  162213. {
  162214. png_memset(ptr, 0, (png_size_t)0x8000L);
  162215. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162216. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162217. }
  162218. else
  162219. {
  162220. png_memset(ptr, 0, (png_size_t)num_bytes);
  162221. }
  162222. #endif
  162223. return ((voidpf)ptr);
  162224. }
  162225. #ifdef PNG_1_0_X
  162226. void PNGAPI
  162227. #else
  162228. void /* private */
  162229. #endif
  162230. png_zfree(voidpf png_ptr, voidpf ptr)
  162231. {
  162232. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162233. }
  162234. void /* PRIVATE */
  162235. png_reset_crc(png_structp png_ptr)
  162236. {
  162237. png_ptr->crc = crc32(0, Z_NULL, 0);
  162238. }
  162239. void /* PRIVATE */
  162240. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162241. {
  162242. int need_crc = 1;
  162243. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162244. {
  162245. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162246. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162247. need_crc = 0;
  162248. }
  162249. else /* critical */
  162250. {
  162251. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162252. need_crc = 0;
  162253. }
  162254. if (need_crc)
  162255. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162256. }
  162257. png_infop PNGAPI
  162258. png_create_info_struct(png_structp png_ptr)
  162259. {
  162260. png_infop info_ptr;
  162261. png_debug(1, "in png_create_info_struct\n");
  162262. if(png_ptr == NULL) return (NULL);
  162263. #ifdef PNG_USER_MEM_SUPPORTED
  162264. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162265. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162266. #else
  162267. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162268. #endif
  162269. if (info_ptr != NULL)
  162270. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162271. return (info_ptr);
  162272. }
  162273. void PNGAPI
  162274. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162275. {
  162276. png_infop info_ptr = NULL;
  162277. if(png_ptr == NULL) return;
  162278. png_debug(1, "in png_destroy_info_struct\n");
  162279. if (info_ptr_ptr != NULL)
  162280. info_ptr = *info_ptr_ptr;
  162281. if (info_ptr != NULL)
  162282. {
  162283. png_info_destroy(png_ptr, info_ptr);
  162284. #ifdef PNG_USER_MEM_SUPPORTED
  162285. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162286. png_ptr->mem_ptr);
  162287. #else
  162288. png_destroy_struct((png_voidp)info_ptr);
  162289. #endif
  162290. *info_ptr_ptr = NULL;
  162291. }
  162292. }
  162293. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162294. #undef png_info_init
  162295. void PNGAPI
  162296. png_info_init(png_infop info_ptr)
  162297. {
  162298. png_info_init_3(&info_ptr, 0);
  162299. }
  162300. #endif
  162301. void PNGAPI
  162302. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162303. {
  162304. png_infop info_ptr = *ptr_ptr;
  162305. if(info_ptr == NULL) return;
  162306. png_debug(1, "in png_info_init_3\n");
  162307. if(png_sizeof(png_info) > png_info_struct_size)
  162308. {
  162309. png_destroy_struct(info_ptr);
  162310. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162311. *ptr_ptr = info_ptr;
  162312. }
  162313. png_memset(info_ptr, 0, png_sizeof (png_info));
  162314. }
  162315. #ifdef PNG_FREE_ME_SUPPORTED
  162316. void PNGAPI
  162317. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162318. int freer, png_uint_32 mask)
  162319. {
  162320. png_debug(1, "in png_data_freer\n");
  162321. if (png_ptr == NULL || info_ptr == NULL)
  162322. return;
  162323. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162324. info_ptr->free_me |= mask;
  162325. else if(freer == PNG_USER_WILL_FREE_DATA)
  162326. info_ptr->free_me &= ~mask;
  162327. else
  162328. png_warning(png_ptr,
  162329. "Unknown freer parameter in png_data_freer.");
  162330. }
  162331. #endif
  162332. void PNGAPI
  162333. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162334. int num)
  162335. {
  162336. png_debug(1, "in png_free_data\n");
  162337. if (png_ptr == NULL || info_ptr == NULL)
  162338. return;
  162339. #if defined(PNG_TEXT_SUPPORTED)
  162340. #ifdef PNG_FREE_ME_SUPPORTED
  162341. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162342. #else
  162343. if (mask & PNG_FREE_TEXT)
  162344. #endif
  162345. {
  162346. if (num != -1)
  162347. {
  162348. if (info_ptr->text && info_ptr->text[num].key)
  162349. {
  162350. png_free(png_ptr, info_ptr->text[num].key);
  162351. info_ptr->text[num].key = NULL;
  162352. }
  162353. }
  162354. else
  162355. {
  162356. int i;
  162357. for (i = 0; i < info_ptr->num_text; i++)
  162358. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162359. png_free(png_ptr, info_ptr->text);
  162360. info_ptr->text = NULL;
  162361. info_ptr->num_text=0;
  162362. }
  162363. }
  162364. #endif
  162365. #if defined(PNG_tRNS_SUPPORTED)
  162366. #ifdef PNG_FREE_ME_SUPPORTED
  162367. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162368. #else
  162369. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162370. #endif
  162371. {
  162372. png_free(png_ptr, info_ptr->trans);
  162373. info_ptr->valid &= ~PNG_INFO_tRNS;
  162374. #ifndef PNG_FREE_ME_SUPPORTED
  162375. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162376. #endif
  162377. info_ptr->trans = NULL;
  162378. }
  162379. #endif
  162380. #if defined(PNG_sCAL_SUPPORTED)
  162381. #ifdef PNG_FREE_ME_SUPPORTED
  162382. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162383. #else
  162384. if (mask & PNG_FREE_SCAL)
  162385. #endif
  162386. {
  162387. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162388. png_free(png_ptr, info_ptr->scal_s_width);
  162389. png_free(png_ptr, info_ptr->scal_s_height);
  162390. info_ptr->scal_s_width = NULL;
  162391. info_ptr->scal_s_height = NULL;
  162392. #endif
  162393. info_ptr->valid &= ~PNG_INFO_sCAL;
  162394. }
  162395. #endif
  162396. #if defined(PNG_pCAL_SUPPORTED)
  162397. #ifdef PNG_FREE_ME_SUPPORTED
  162398. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162399. #else
  162400. if (mask & PNG_FREE_PCAL)
  162401. #endif
  162402. {
  162403. png_free(png_ptr, info_ptr->pcal_purpose);
  162404. png_free(png_ptr, info_ptr->pcal_units);
  162405. info_ptr->pcal_purpose = NULL;
  162406. info_ptr->pcal_units = NULL;
  162407. if (info_ptr->pcal_params != NULL)
  162408. {
  162409. int i;
  162410. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162411. {
  162412. png_free(png_ptr, info_ptr->pcal_params[i]);
  162413. info_ptr->pcal_params[i]=NULL;
  162414. }
  162415. png_free(png_ptr, info_ptr->pcal_params);
  162416. info_ptr->pcal_params = NULL;
  162417. }
  162418. info_ptr->valid &= ~PNG_INFO_pCAL;
  162419. }
  162420. #endif
  162421. #if defined(PNG_iCCP_SUPPORTED)
  162422. #ifdef PNG_FREE_ME_SUPPORTED
  162423. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162424. #else
  162425. if (mask & PNG_FREE_ICCP)
  162426. #endif
  162427. {
  162428. png_free(png_ptr, info_ptr->iccp_name);
  162429. png_free(png_ptr, info_ptr->iccp_profile);
  162430. info_ptr->iccp_name = NULL;
  162431. info_ptr->iccp_profile = NULL;
  162432. info_ptr->valid &= ~PNG_INFO_iCCP;
  162433. }
  162434. #endif
  162435. #if defined(PNG_sPLT_SUPPORTED)
  162436. #ifdef PNG_FREE_ME_SUPPORTED
  162437. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162438. #else
  162439. if (mask & PNG_FREE_SPLT)
  162440. #endif
  162441. {
  162442. if (num != -1)
  162443. {
  162444. if(info_ptr->splt_palettes)
  162445. {
  162446. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162447. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162448. info_ptr->splt_palettes[num].name = NULL;
  162449. info_ptr->splt_palettes[num].entries = NULL;
  162450. }
  162451. }
  162452. else
  162453. {
  162454. if(info_ptr->splt_palettes_num)
  162455. {
  162456. int i;
  162457. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162458. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162459. png_free(png_ptr, info_ptr->splt_palettes);
  162460. info_ptr->splt_palettes = NULL;
  162461. info_ptr->splt_palettes_num = 0;
  162462. }
  162463. info_ptr->valid &= ~PNG_INFO_sPLT;
  162464. }
  162465. }
  162466. #endif
  162467. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162468. if(png_ptr->unknown_chunk.data)
  162469. {
  162470. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162471. png_ptr->unknown_chunk.data = NULL;
  162472. }
  162473. #ifdef PNG_FREE_ME_SUPPORTED
  162474. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162475. #else
  162476. if (mask & PNG_FREE_UNKN)
  162477. #endif
  162478. {
  162479. if (num != -1)
  162480. {
  162481. if(info_ptr->unknown_chunks)
  162482. {
  162483. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162484. info_ptr->unknown_chunks[num].data = NULL;
  162485. }
  162486. }
  162487. else
  162488. {
  162489. int i;
  162490. if(info_ptr->unknown_chunks_num)
  162491. {
  162492. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162493. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162494. png_free(png_ptr, info_ptr->unknown_chunks);
  162495. info_ptr->unknown_chunks = NULL;
  162496. info_ptr->unknown_chunks_num = 0;
  162497. }
  162498. }
  162499. }
  162500. #endif
  162501. #if defined(PNG_hIST_SUPPORTED)
  162502. #ifdef PNG_FREE_ME_SUPPORTED
  162503. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162504. #else
  162505. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162506. #endif
  162507. {
  162508. png_free(png_ptr, info_ptr->hist);
  162509. info_ptr->hist = NULL;
  162510. info_ptr->valid &= ~PNG_INFO_hIST;
  162511. #ifndef PNG_FREE_ME_SUPPORTED
  162512. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162513. #endif
  162514. }
  162515. #endif
  162516. #ifdef PNG_FREE_ME_SUPPORTED
  162517. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162518. #else
  162519. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162520. #endif
  162521. {
  162522. png_zfree(png_ptr, info_ptr->palette);
  162523. info_ptr->palette = NULL;
  162524. info_ptr->valid &= ~PNG_INFO_PLTE;
  162525. #ifndef PNG_FREE_ME_SUPPORTED
  162526. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162527. #endif
  162528. info_ptr->num_palette = 0;
  162529. }
  162530. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162531. #ifdef PNG_FREE_ME_SUPPORTED
  162532. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162533. #else
  162534. if (mask & PNG_FREE_ROWS)
  162535. #endif
  162536. {
  162537. if(info_ptr->row_pointers)
  162538. {
  162539. int row;
  162540. for (row = 0; row < (int)info_ptr->height; row++)
  162541. {
  162542. png_free(png_ptr, info_ptr->row_pointers[row]);
  162543. info_ptr->row_pointers[row]=NULL;
  162544. }
  162545. png_free(png_ptr, info_ptr->row_pointers);
  162546. info_ptr->row_pointers=NULL;
  162547. }
  162548. info_ptr->valid &= ~PNG_INFO_IDAT;
  162549. }
  162550. #endif
  162551. #ifdef PNG_FREE_ME_SUPPORTED
  162552. if(num == -1)
  162553. info_ptr->free_me &= ~mask;
  162554. else
  162555. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162556. #endif
  162557. }
  162558. void /* PRIVATE */
  162559. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162560. {
  162561. png_debug(1, "in png_info_destroy\n");
  162562. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162563. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162564. if (png_ptr->num_chunk_list)
  162565. {
  162566. png_free(png_ptr, png_ptr->chunk_list);
  162567. png_ptr->chunk_list=NULL;
  162568. png_ptr->num_chunk_list=0;
  162569. }
  162570. #endif
  162571. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162572. }
  162573. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162574. png_voidp PNGAPI
  162575. png_get_io_ptr(png_structp png_ptr)
  162576. {
  162577. if(png_ptr == NULL) return (NULL);
  162578. return (png_ptr->io_ptr);
  162579. }
  162580. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162581. #if !defined(PNG_NO_STDIO)
  162582. void PNGAPI
  162583. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162584. {
  162585. png_debug(1, "in png_init_io\n");
  162586. if(png_ptr == NULL) return;
  162587. png_ptr->io_ptr = (png_voidp)fp;
  162588. }
  162589. #endif
  162590. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162591. png_charp PNGAPI
  162592. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162593. {
  162594. static PNG_CONST char short_months[12][4] =
  162595. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162596. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162597. if(png_ptr == NULL) return (NULL);
  162598. if (png_ptr->time_buffer == NULL)
  162599. {
  162600. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162601. png_sizeof(char)));
  162602. }
  162603. #if defined(_WIN32_WCE)
  162604. {
  162605. wchar_t time_buf[29];
  162606. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162607. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162608. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162609. ptime->second % 61);
  162610. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162611. NULL, NULL);
  162612. }
  162613. #else
  162614. #ifdef USE_FAR_KEYWORD
  162615. {
  162616. char near_time_buf[29];
  162617. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162618. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162619. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162620. ptime->second % 61);
  162621. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162622. 29*png_sizeof(char));
  162623. }
  162624. #else
  162625. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162626. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162627. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162628. ptime->second % 61);
  162629. #endif
  162630. #endif /* _WIN32_WCE */
  162631. return ((png_charp)png_ptr->time_buffer);
  162632. }
  162633. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162634. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162635. png_charp PNGAPI
  162636. png_get_copyright(png_structp png_ptr)
  162637. {
  162638. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162639. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162640. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162641. Copyright (c) 1996-1997 Andreas Dilger\n\
  162642. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162643. }
  162644. png_charp PNGAPI
  162645. png_get_libpng_ver(png_structp png_ptr)
  162646. {
  162647. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162648. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162649. }
  162650. png_charp PNGAPI
  162651. png_get_header_ver(png_structp png_ptr)
  162652. {
  162653. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162654. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162655. }
  162656. png_charp PNGAPI
  162657. png_get_header_version(png_structp png_ptr)
  162658. {
  162659. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162660. return ((png_charp) PNG_HEADER_VERSION_STRING
  162661. #ifndef PNG_READ_SUPPORTED
  162662. " (NO READ SUPPORT)"
  162663. #endif
  162664. "\n");
  162665. }
  162666. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162667. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162668. int PNGAPI
  162669. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162670. {
  162671. int i;
  162672. png_bytep p;
  162673. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162674. return 0;
  162675. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162676. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162677. if (!png_memcmp(chunk_name, p, 4))
  162678. return ((int)*(p+4));
  162679. return 0;
  162680. }
  162681. #endif
  162682. int PNGAPI
  162683. png_reset_zstream(png_structp png_ptr)
  162684. {
  162685. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162686. return (inflateReset(&png_ptr->zstream));
  162687. }
  162688. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162689. png_uint_32 PNGAPI
  162690. png_access_version_number(void)
  162691. {
  162692. return((png_uint_32) PNG_LIBPNG_VER);
  162693. }
  162694. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162695. #if !defined(PNG_1_0_X)
  162696. int PNGAPI
  162697. png_mmx_support(void)
  162698. {
  162699. return -1;
  162700. }
  162701. #endif /* PNG_1_0_X */
  162702. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162703. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162704. #ifdef PNG_SIZE_T
  162705. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162706. png_size_t PNGAPI
  162707. png_convert_size(size_t size)
  162708. {
  162709. if (size > (png_size_t)-1)
  162710. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162711. return ((png_size_t)size);
  162712. }
  162713. #endif /* PNG_SIZE_T */
  162714. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162715. /*** End of inlined file: png.c ***/
  162716. /*** Start of inlined file: pngerror.c ***/
  162717. #define PNG_INTERNAL
  162718. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162719. static void /* PRIVATE */
  162720. png_default_error PNGARG((png_structp png_ptr,
  162721. png_const_charp error_message));
  162722. #ifndef PNG_NO_WARNINGS
  162723. static void /* PRIVATE */
  162724. png_default_warning PNGARG((png_structp png_ptr,
  162725. png_const_charp warning_message));
  162726. #endif /* PNG_NO_WARNINGS */
  162727. #ifndef PNG_NO_ERROR_TEXT
  162728. void PNGAPI
  162729. png_error(png_structp png_ptr, png_const_charp error_message)
  162730. {
  162731. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162732. char msg[16];
  162733. if (png_ptr != NULL)
  162734. {
  162735. if (png_ptr->flags&
  162736. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162737. {
  162738. if (*error_message == '#')
  162739. {
  162740. int offset;
  162741. for (offset=1; offset<15; offset++)
  162742. if (*(error_message+offset) == ' ')
  162743. break;
  162744. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162745. {
  162746. int i;
  162747. for (i=0; i<offset-1; i++)
  162748. msg[i]=error_message[i+1];
  162749. msg[i]='\0';
  162750. error_message=msg;
  162751. }
  162752. else
  162753. error_message+=offset;
  162754. }
  162755. else
  162756. {
  162757. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162758. {
  162759. msg[0]='0';
  162760. msg[1]='\0';
  162761. error_message=msg;
  162762. }
  162763. }
  162764. }
  162765. }
  162766. #endif
  162767. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162768. (*(png_ptr->error_fn))(png_ptr, error_message);
  162769. png_default_error(png_ptr, error_message);
  162770. }
  162771. #else
  162772. void PNGAPI
  162773. png_err(png_structp png_ptr)
  162774. {
  162775. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162776. (*(png_ptr->error_fn))(png_ptr, '\0');
  162777. png_default_error(png_ptr, '\0');
  162778. }
  162779. #endif /* PNG_NO_ERROR_TEXT */
  162780. #ifndef PNG_NO_WARNINGS
  162781. void PNGAPI
  162782. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162783. {
  162784. int offset = 0;
  162785. if (png_ptr != NULL)
  162786. {
  162787. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162788. if (png_ptr->flags&
  162789. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162790. #endif
  162791. {
  162792. if (*warning_message == '#')
  162793. {
  162794. for (offset=1; offset<15; offset++)
  162795. if (*(warning_message+offset) == ' ')
  162796. break;
  162797. }
  162798. }
  162799. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162800. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162801. }
  162802. else
  162803. png_default_warning(png_ptr, warning_message+offset);
  162804. }
  162805. #endif /* PNG_NO_WARNINGS */
  162806. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162807. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162808. static void /* PRIVATE */
  162809. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162810. error_message)
  162811. {
  162812. int iout = 0, iin = 0;
  162813. while (iin < 4)
  162814. {
  162815. int c = png_ptr->chunk_name[iin++];
  162816. if (isnonalpha(c))
  162817. {
  162818. buffer[iout++] = '[';
  162819. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162820. buffer[iout++] = png_digit[c & 0x0f];
  162821. buffer[iout++] = ']';
  162822. }
  162823. else
  162824. {
  162825. buffer[iout++] = (png_byte)c;
  162826. }
  162827. }
  162828. if (error_message == NULL)
  162829. buffer[iout] = 0;
  162830. else
  162831. {
  162832. buffer[iout++] = ':';
  162833. buffer[iout++] = ' ';
  162834. png_strncpy(buffer+iout, error_message, 63);
  162835. buffer[iout+63] = 0;
  162836. }
  162837. }
  162838. #ifdef PNG_READ_SUPPORTED
  162839. void PNGAPI
  162840. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162841. {
  162842. char msg[18+64];
  162843. if (png_ptr == NULL)
  162844. png_error(png_ptr, error_message);
  162845. else
  162846. {
  162847. png_format_buffer(png_ptr, msg, error_message);
  162848. png_error(png_ptr, msg);
  162849. }
  162850. }
  162851. #endif /* PNG_READ_SUPPORTED */
  162852. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162853. #ifndef PNG_NO_WARNINGS
  162854. void PNGAPI
  162855. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162856. {
  162857. char msg[18+64];
  162858. if (png_ptr == NULL)
  162859. png_warning(png_ptr, warning_message);
  162860. else
  162861. {
  162862. png_format_buffer(png_ptr, msg, warning_message);
  162863. png_warning(png_ptr, msg);
  162864. }
  162865. }
  162866. #endif /* PNG_NO_WARNINGS */
  162867. static void /* PRIVATE */
  162868. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162869. {
  162870. #ifndef PNG_NO_CONSOLE_IO
  162871. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162872. if (*error_message == '#')
  162873. {
  162874. int offset;
  162875. char error_number[16];
  162876. for (offset=0; offset<15; offset++)
  162877. {
  162878. error_number[offset] = *(error_message+offset+1);
  162879. if (*(error_message+offset) == ' ')
  162880. break;
  162881. }
  162882. if((offset > 1) && (offset < 15))
  162883. {
  162884. error_number[offset-1]='\0';
  162885. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162886. error_message+offset);
  162887. }
  162888. else
  162889. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162890. }
  162891. else
  162892. #endif
  162893. fprintf(stderr, "libpng error: %s\n", error_message);
  162894. #endif
  162895. #ifdef PNG_SETJMP_SUPPORTED
  162896. if (png_ptr)
  162897. {
  162898. # ifdef USE_FAR_KEYWORD
  162899. {
  162900. jmp_buf jmpbuf;
  162901. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162902. longjmp(jmpbuf, 1);
  162903. }
  162904. # else
  162905. longjmp(png_ptr->jmpbuf, 1);
  162906. # endif
  162907. }
  162908. #else
  162909. PNG_ABORT();
  162910. #endif
  162911. #ifdef PNG_NO_CONSOLE_IO
  162912. error_message = error_message; /* make compiler happy */
  162913. #endif
  162914. }
  162915. #ifndef PNG_NO_WARNINGS
  162916. static void /* PRIVATE */
  162917. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162918. {
  162919. #ifndef PNG_NO_CONSOLE_IO
  162920. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162921. if (*warning_message == '#')
  162922. {
  162923. int offset;
  162924. char warning_number[16];
  162925. for (offset=0; offset<15; offset++)
  162926. {
  162927. warning_number[offset]=*(warning_message+offset+1);
  162928. if (*(warning_message+offset) == ' ')
  162929. break;
  162930. }
  162931. if((offset > 1) && (offset < 15))
  162932. {
  162933. warning_number[offset-1]='\0';
  162934. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  162935. warning_message+offset);
  162936. }
  162937. else
  162938. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162939. }
  162940. else
  162941. # endif
  162942. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162943. #else
  162944. warning_message = warning_message; /* make compiler happy */
  162945. #endif
  162946. png_ptr = png_ptr; /* make compiler happy */
  162947. }
  162948. #endif /* PNG_NO_WARNINGS */
  162949. void PNGAPI
  162950. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  162951. png_error_ptr error_fn, png_error_ptr warning_fn)
  162952. {
  162953. if (png_ptr == NULL)
  162954. return;
  162955. png_ptr->error_ptr = error_ptr;
  162956. png_ptr->error_fn = error_fn;
  162957. png_ptr->warning_fn = warning_fn;
  162958. }
  162959. png_voidp PNGAPI
  162960. png_get_error_ptr(png_structp png_ptr)
  162961. {
  162962. if (png_ptr == NULL)
  162963. return NULL;
  162964. return ((png_voidp)png_ptr->error_ptr);
  162965. }
  162966. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162967. void PNGAPI
  162968. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  162969. {
  162970. if(png_ptr != NULL)
  162971. {
  162972. png_ptr->flags &=
  162973. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  162974. }
  162975. }
  162976. #endif
  162977. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  162978. /*** End of inlined file: pngerror.c ***/
  162979. /*** Start of inlined file: pngget.c ***/
  162980. #define PNG_INTERNAL
  162981. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162982. png_uint_32 PNGAPI
  162983. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  162984. {
  162985. if (png_ptr != NULL && info_ptr != NULL)
  162986. return(info_ptr->valid & flag);
  162987. else
  162988. return(0);
  162989. }
  162990. png_uint_32 PNGAPI
  162991. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  162992. {
  162993. if (png_ptr != NULL && info_ptr != NULL)
  162994. return(info_ptr->rowbytes);
  162995. else
  162996. return(0);
  162997. }
  162998. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162999. png_bytepp PNGAPI
  163000. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163001. {
  163002. if (png_ptr != NULL && info_ptr != NULL)
  163003. return(info_ptr->row_pointers);
  163004. else
  163005. return(0);
  163006. }
  163007. #endif
  163008. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163009. png_uint_32 PNGAPI
  163010. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163011. {
  163012. if (png_ptr != NULL && info_ptr != NULL)
  163013. {
  163014. return info_ptr->width;
  163015. }
  163016. return (0);
  163017. }
  163018. png_uint_32 PNGAPI
  163019. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163020. {
  163021. if (png_ptr != NULL && info_ptr != NULL)
  163022. {
  163023. return info_ptr->height;
  163024. }
  163025. return (0);
  163026. }
  163027. png_byte PNGAPI
  163028. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163029. {
  163030. if (png_ptr != NULL && info_ptr != NULL)
  163031. {
  163032. return info_ptr->bit_depth;
  163033. }
  163034. return (0);
  163035. }
  163036. png_byte PNGAPI
  163037. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163038. {
  163039. if (png_ptr != NULL && info_ptr != NULL)
  163040. {
  163041. return info_ptr->color_type;
  163042. }
  163043. return (0);
  163044. }
  163045. png_byte PNGAPI
  163046. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163047. {
  163048. if (png_ptr != NULL && info_ptr != NULL)
  163049. {
  163050. return info_ptr->filter_type;
  163051. }
  163052. return (0);
  163053. }
  163054. png_byte PNGAPI
  163055. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163056. {
  163057. if (png_ptr != NULL && info_ptr != NULL)
  163058. {
  163059. return info_ptr->interlace_type;
  163060. }
  163061. return (0);
  163062. }
  163063. png_byte PNGAPI
  163064. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163065. {
  163066. if (png_ptr != NULL && info_ptr != NULL)
  163067. {
  163068. return info_ptr->compression_type;
  163069. }
  163070. return (0);
  163071. }
  163072. png_uint_32 PNGAPI
  163073. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163074. {
  163075. if (png_ptr != NULL && info_ptr != NULL)
  163076. #if defined(PNG_pHYs_SUPPORTED)
  163077. if (info_ptr->valid & PNG_INFO_pHYs)
  163078. {
  163079. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163080. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163081. return (0);
  163082. else return (info_ptr->x_pixels_per_unit);
  163083. }
  163084. #else
  163085. return (0);
  163086. #endif
  163087. return (0);
  163088. }
  163089. png_uint_32 PNGAPI
  163090. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163091. {
  163092. if (png_ptr != NULL && info_ptr != NULL)
  163093. #if defined(PNG_pHYs_SUPPORTED)
  163094. if (info_ptr->valid & PNG_INFO_pHYs)
  163095. {
  163096. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163097. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163098. return (0);
  163099. else return (info_ptr->y_pixels_per_unit);
  163100. }
  163101. #else
  163102. return (0);
  163103. #endif
  163104. return (0);
  163105. }
  163106. png_uint_32 PNGAPI
  163107. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163108. {
  163109. if (png_ptr != NULL && info_ptr != NULL)
  163110. #if defined(PNG_pHYs_SUPPORTED)
  163111. if (info_ptr->valid & PNG_INFO_pHYs)
  163112. {
  163113. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163114. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163115. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163116. return (0);
  163117. else return (info_ptr->x_pixels_per_unit);
  163118. }
  163119. #else
  163120. return (0);
  163121. #endif
  163122. return (0);
  163123. }
  163124. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163125. float PNGAPI
  163126. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163127. {
  163128. if (png_ptr != NULL && info_ptr != NULL)
  163129. #if defined(PNG_pHYs_SUPPORTED)
  163130. if (info_ptr->valid & PNG_INFO_pHYs)
  163131. {
  163132. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163133. if (info_ptr->x_pixels_per_unit == 0)
  163134. return ((float)0.0);
  163135. else
  163136. return ((float)((float)info_ptr->y_pixels_per_unit
  163137. /(float)info_ptr->x_pixels_per_unit));
  163138. }
  163139. #else
  163140. return (0.0);
  163141. #endif
  163142. return ((float)0.0);
  163143. }
  163144. #endif
  163145. png_int_32 PNGAPI
  163146. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163147. {
  163148. if (png_ptr != NULL && info_ptr != NULL)
  163149. #if defined(PNG_oFFs_SUPPORTED)
  163150. if (info_ptr->valid & PNG_INFO_oFFs)
  163151. {
  163152. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163153. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163154. return (0);
  163155. else return (info_ptr->x_offset);
  163156. }
  163157. #else
  163158. return (0);
  163159. #endif
  163160. return (0);
  163161. }
  163162. png_int_32 PNGAPI
  163163. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163164. {
  163165. if (png_ptr != NULL && info_ptr != NULL)
  163166. #if defined(PNG_oFFs_SUPPORTED)
  163167. if (info_ptr->valid & PNG_INFO_oFFs)
  163168. {
  163169. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163170. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163171. return (0);
  163172. else return (info_ptr->y_offset);
  163173. }
  163174. #else
  163175. return (0);
  163176. #endif
  163177. return (0);
  163178. }
  163179. png_int_32 PNGAPI
  163180. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163181. {
  163182. if (png_ptr != NULL && info_ptr != NULL)
  163183. #if defined(PNG_oFFs_SUPPORTED)
  163184. if (info_ptr->valid & PNG_INFO_oFFs)
  163185. {
  163186. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163187. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163188. return (0);
  163189. else return (info_ptr->x_offset);
  163190. }
  163191. #else
  163192. return (0);
  163193. #endif
  163194. return (0);
  163195. }
  163196. png_int_32 PNGAPI
  163197. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163198. {
  163199. if (png_ptr != NULL && info_ptr != NULL)
  163200. #if defined(PNG_oFFs_SUPPORTED)
  163201. if (info_ptr->valid & PNG_INFO_oFFs)
  163202. {
  163203. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163204. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163205. return (0);
  163206. else return (info_ptr->y_offset);
  163207. }
  163208. #else
  163209. return (0);
  163210. #endif
  163211. return (0);
  163212. }
  163213. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163214. png_uint_32 PNGAPI
  163215. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163216. {
  163217. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163218. *.0254 +.5));
  163219. }
  163220. png_uint_32 PNGAPI
  163221. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163222. {
  163223. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163224. *.0254 +.5));
  163225. }
  163226. png_uint_32 PNGAPI
  163227. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163228. {
  163229. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163230. *.0254 +.5));
  163231. }
  163232. float PNGAPI
  163233. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163234. {
  163235. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163236. *.00003937);
  163237. }
  163238. float PNGAPI
  163239. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163240. {
  163241. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163242. *.00003937);
  163243. }
  163244. #if defined(PNG_pHYs_SUPPORTED)
  163245. png_uint_32 PNGAPI
  163246. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163247. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163248. {
  163249. png_uint_32 retval = 0;
  163250. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163251. {
  163252. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163253. if (res_x != NULL)
  163254. {
  163255. *res_x = info_ptr->x_pixels_per_unit;
  163256. retval |= PNG_INFO_pHYs;
  163257. }
  163258. if (res_y != NULL)
  163259. {
  163260. *res_y = info_ptr->y_pixels_per_unit;
  163261. retval |= PNG_INFO_pHYs;
  163262. }
  163263. if (unit_type != NULL)
  163264. {
  163265. *unit_type = (int)info_ptr->phys_unit_type;
  163266. retval |= PNG_INFO_pHYs;
  163267. if(*unit_type == 1)
  163268. {
  163269. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163270. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163271. }
  163272. }
  163273. }
  163274. return (retval);
  163275. }
  163276. #endif /* PNG_pHYs_SUPPORTED */
  163277. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163278. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163279. png_byte PNGAPI
  163280. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163281. {
  163282. if (png_ptr != NULL && info_ptr != NULL)
  163283. return(info_ptr->channels);
  163284. else
  163285. return (0);
  163286. }
  163287. png_bytep PNGAPI
  163288. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163289. {
  163290. if (png_ptr != NULL && info_ptr != NULL)
  163291. return(info_ptr->signature);
  163292. else
  163293. return (NULL);
  163294. }
  163295. #if defined(PNG_bKGD_SUPPORTED)
  163296. png_uint_32 PNGAPI
  163297. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163298. png_color_16p *background)
  163299. {
  163300. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163301. && background != NULL)
  163302. {
  163303. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163304. *background = &(info_ptr->background);
  163305. return (PNG_INFO_bKGD);
  163306. }
  163307. return (0);
  163308. }
  163309. #endif
  163310. #if defined(PNG_cHRM_SUPPORTED)
  163311. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163312. png_uint_32 PNGAPI
  163313. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163314. double *white_x, double *white_y, double *red_x, double *red_y,
  163315. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163316. {
  163317. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163318. {
  163319. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163320. if (white_x != NULL)
  163321. *white_x = (double)info_ptr->x_white;
  163322. if (white_y != NULL)
  163323. *white_y = (double)info_ptr->y_white;
  163324. if (red_x != NULL)
  163325. *red_x = (double)info_ptr->x_red;
  163326. if (red_y != NULL)
  163327. *red_y = (double)info_ptr->y_red;
  163328. if (green_x != NULL)
  163329. *green_x = (double)info_ptr->x_green;
  163330. if (green_y != NULL)
  163331. *green_y = (double)info_ptr->y_green;
  163332. if (blue_x != NULL)
  163333. *blue_x = (double)info_ptr->x_blue;
  163334. if (blue_y != NULL)
  163335. *blue_y = (double)info_ptr->y_blue;
  163336. return (PNG_INFO_cHRM);
  163337. }
  163338. return (0);
  163339. }
  163340. #endif
  163341. #ifdef PNG_FIXED_POINT_SUPPORTED
  163342. png_uint_32 PNGAPI
  163343. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163344. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163345. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163346. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163347. {
  163348. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163349. {
  163350. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163351. if (white_x != NULL)
  163352. *white_x = info_ptr->int_x_white;
  163353. if (white_y != NULL)
  163354. *white_y = info_ptr->int_y_white;
  163355. if (red_x != NULL)
  163356. *red_x = info_ptr->int_x_red;
  163357. if (red_y != NULL)
  163358. *red_y = info_ptr->int_y_red;
  163359. if (green_x != NULL)
  163360. *green_x = info_ptr->int_x_green;
  163361. if (green_y != NULL)
  163362. *green_y = info_ptr->int_y_green;
  163363. if (blue_x != NULL)
  163364. *blue_x = info_ptr->int_x_blue;
  163365. if (blue_y != NULL)
  163366. *blue_y = info_ptr->int_y_blue;
  163367. return (PNG_INFO_cHRM);
  163368. }
  163369. return (0);
  163370. }
  163371. #endif
  163372. #endif
  163373. #if defined(PNG_gAMA_SUPPORTED)
  163374. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163375. png_uint_32 PNGAPI
  163376. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163377. {
  163378. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163379. && file_gamma != NULL)
  163380. {
  163381. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163382. *file_gamma = (double)info_ptr->gamma;
  163383. return (PNG_INFO_gAMA);
  163384. }
  163385. return (0);
  163386. }
  163387. #endif
  163388. #ifdef PNG_FIXED_POINT_SUPPORTED
  163389. png_uint_32 PNGAPI
  163390. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163391. png_fixed_point *int_file_gamma)
  163392. {
  163393. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163394. && int_file_gamma != NULL)
  163395. {
  163396. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163397. *int_file_gamma = info_ptr->int_gamma;
  163398. return (PNG_INFO_gAMA);
  163399. }
  163400. return (0);
  163401. }
  163402. #endif
  163403. #endif
  163404. #if defined(PNG_sRGB_SUPPORTED)
  163405. png_uint_32 PNGAPI
  163406. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163407. {
  163408. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163409. && file_srgb_intent != NULL)
  163410. {
  163411. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163412. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163413. return (PNG_INFO_sRGB);
  163414. }
  163415. return (0);
  163416. }
  163417. #endif
  163418. #if defined(PNG_iCCP_SUPPORTED)
  163419. png_uint_32 PNGAPI
  163420. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163421. png_charpp name, int *compression_type,
  163422. png_charpp profile, png_uint_32 *proflen)
  163423. {
  163424. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163425. && name != NULL && profile != NULL && proflen != NULL)
  163426. {
  163427. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163428. *name = info_ptr->iccp_name;
  163429. *profile = info_ptr->iccp_profile;
  163430. *proflen = (int)info_ptr->iccp_proflen;
  163431. *compression_type = (int)info_ptr->iccp_compression;
  163432. return (PNG_INFO_iCCP);
  163433. }
  163434. return (0);
  163435. }
  163436. #endif
  163437. #if defined(PNG_sPLT_SUPPORTED)
  163438. png_uint_32 PNGAPI
  163439. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163440. png_sPLT_tpp spalettes)
  163441. {
  163442. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163443. {
  163444. *spalettes = info_ptr->splt_palettes;
  163445. return ((png_uint_32)info_ptr->splt_palettes_num);
  163446. }
  163447. return (0);
  163448. }
  163449. #endif
  163450. #if defined(PNG_hIST_SUPPORTED)
  163451. png_uint_32 PNGAPI
  163452. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163453. {
  163454. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163455. && hist != NULL)
  163456. {
  163457. png_debug1(1, "in %s retrieval function\n", "hIST");
  163458. *hist = info_ptr->hist;
  163459. return (PNG_INFO_hIST);
  163460. }
  163461. return (0);
  163462. }
  163463. #endif
  163464. png_uint_32 PNGAPI
  163465. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163466. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163467. int *color_type, int *interlace_type, int *compression_type,
  163468. int *filter_type)
  163469. {
  163470. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163471. bit_depth != NULL && color_type != NULL)
  163472. {
  163473. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163474. *width = info_ptr->width;
  163475. *height = info_ptr->height;
  163476. *bit_depth = info_ptr->bit_depth;
  163477. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163478. png_error(png_ptr, "Invalid bit depth");
  163479. *color_type = info_ptr->color_type;
  163480. if (info_ptr->color_type > 6)
  163481. png_error(png_ptr, "Invalid color type");
  163482. if (compression_type != NULL)
  163483. *compression_type = info_ptr->compression_type;
  163484. if (filter_type != NULL)
  163485. *filter_type = info_ptr->filter_type;
  163486. if (interlace_type != NULL)
  163487. *interlace_type = info_ptr->interlace_type;
  163488. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163489. png_error(png_ptr, "Invalid image width");
  163490. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163491. png_error(png_ptr, "Invalid image height");
  163492. if (info_ptr->width > (PNG_UINT_32_MAX
  163493. >> 3) /* 8-byte RGBA pixels */
  163494. - 64 /* bigrowbuf hack */
  163495. - 1 /* filter byte */
  163496. - 7*8 /* rounding of width to multiple of 8 pixels */
  163497. - 8) /* extra max_pixel_depth pad */
  163498. {
  163499. png_warning(png_ptr,
  163500. "Width too large for libpng to process image data.");
  163501. }
  163502. return (1);
  163503. }
  163504. return (0);
  163505. }
  163506. #if defined(PNG_oFFs_SUPPORTED)
  163507. png_uint_32 PNGAPI
  163508. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163509. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163510. {
  163511. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163512. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163513. {
  163514. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163515. *offset_x = info_ptr->x_offset;
  163516. *offset_y = info_ptr->y_offset;
  163517. *unit_type = (int)info_ptr->offset_unit_type;
  163518. return (PNG_INFO_oFFs);
  163519. }
  163520. return (0);
  163521. }
  163522. #endif
  163523. #if defined(PNG_pCAL_SUPPORTED)
  163524. png_uint_32 PNGAPI
  163525. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163526. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163527. png_charp *units, png_charpp *params)
  163528. {
  163529. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163530. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163531. nparams != NULL && units != NULL && params != NULL)
  163532. {
  163533. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163534. *purpose = info_ptr->pcal_purpose;
  163535. *X0 = info_ptr->pcal_X0;
  163536. *X1 = info_ptr->pcal_X1;
  163537. *type = (int)info_ptr->pcal_type;
  163538. *nparams = (int)info_ptr->pcal_nparams;
  163539. *units = info_ptr->pcal_units;
  163540. *params = info_ptr->pcal_params;
  163541. return (PNG_INFO_pCAL);
  163542. }
  163543. return (0);
  163544. }
  163545. #endif
  163546. #if defined(PNG_sCAL_SUPPORTED)
  163547. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163548. png_uint_32 PNGAPI
  163549. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163550. int *unit, double *width, double *height)
  163551. {
  163552. if (png_ptr != NULL && info_ptr != NULL &&
  163553. (info_ptr->valid & PNG_INFO_sCAL))
  163554. {
  163555. *unit = info_ptr->scal_unit;
  163556. *width = info_ptr->scal_pixel_width;
  163557. *height = info_ptr->scal_pixel_height;
  163558. return (PNG_INFO_sCAL);
  163559. }
  163560. return(0);
  163561. }
  163562. #else
  163563. #ifdef PNG_FIXED_POINT_SUPPORTED
  163564. png_uint_32 PNGAPI
  163565. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163566. int *unit, png_charpp width, png_charpp height)
  163567. {
  163568. if (png_ptr != NULL && info_ptr != NULL &&
  163569. (info_ptr->valid & PNG_INFO_sCAL))
  163570. {
  163571. *unit = info_ptr->scal_unit;
  163572. *width = info_ptr->scal_s_width;
  163573. *height = info_ptr->scal_s_height;
  163574. return (PNG_INFO_sCAL);
  163575. }
  163576. return(0);
  163577. }
  163578. #endif
  163579. #endif
  163580. #endif
  163581. #if defined(PNG_pHYs_SUPPORTED)
  163582. png_uint_32 PNGAPI
  163583. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163584. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163585. {
  163586. png_uint_32 retval = 0;
  163587. if (png_ptr != NULL && info_ptr != NULL &&
  163588. (info_ptr->valid & PNG_INFO_pHYs))
  163589. {
  163590. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163591. if (res_x != NULL)
  163592. {
  163593. *res_x = info_ptr->x_pixels_per_unit;
  163594. retval |= PNG_INFO_pHYs;
  163595. }
  163596. if (res_y != NULL)
  163597. {
  163598. *res_y = info_ptr->y_pixels_per_unit;
  163599. retval |= PNG_INFO_pHYs;
  163600. }
  163601. if (unit_type != NULL)
  163602. {
  163603. *unit_type = (int)info_ptr->phys_unit_type;
  163604. retval |= PNG_INFO_pHYs;
  163605. }
  163606. }
  163607. return (retval);
  163608. }
  163609. #endif
  163610. png_uint_32 PNGAPI
  163611. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163612. int *num_palette)
  163613. {
  163614. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163615. && palette != NULL)
  163616. {
  163617. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163618. *palette = info_ptr->palette;
  163619. *num_palette = info_ptr->num_palette;
  163620. png_debug1(3, "num_palette = %d\n", *num_palette);
  163621. return (PNG_INFO_PLTE);
  163622. }
  163623. return (0);
  163624. }
  163625. #if defined(PNG_sBIT_SUPPORTED)
  163626. png_uint_32 PNGAPI
  163627. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163628. {
  163629. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163630. && sig_bit != NULL)
  163631. {
  163632. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163633. *sig_bit = &(info_ptr->sig_bit);
  163634. return (PNG_INFO_sBIT);
  163635. }
  163636. return (0);
  163637. }
  163638. #endif
  163639. #if defined(PNG_TEXT_SUPPORTED)
  163640. png_uint_32 PNGAPI
  163641. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163642. int *num_text)
  163643. {
  163644. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163645. {
  163646. png_debug1(1, "in %s retrieval function\n",
  163647. (png_ptr->chunk_name[0] == '\0' ? "text"
  163648. : (png_const_charp)png_ptr->chunk_name));
  163649. if (text_ptr != NULL)
  163650. *text_ptr = info_ptr->text;
  163651. if (num_text != NULL)
  163652. *num_text = info_ptr->num_text;
  163653. return ((png_uint_32)info_ptr->num_text);
  163654. }
  163655. if (num_text != NULL)
  163656. *num_text = 0;
  163657. return(0);
  163658. }
  163659. #endif
  163660. #if defined(PNG_tIME_SUPPORTED)
  163661. png_uint_32 PNGAPI
  163662. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163663. {
  163664. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163665. && mod_time != NULL)
  163666. {
  163667. png_debug1(1, "in %s retrieval function\n", "tIME");
  163668. *mod_time = &(info_ptr->mod_time);
  163669. return (PNG_INFO_tIME);
  163670. }
  163671. return (0);
  163672. }
  163673. #endif
  163674. #if defined(PNG_tRNS_SUPPORTED)
  163675. png_uint_32 PNGAPI
  163676. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163677. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163678. {
  163679. png_uint_32 retval = 0;
  163680. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163681. {
  163682. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163683. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163684. {
  163685. if (trans != NULL)
  163686. {
  163687. *trans = info_ptr->trans;
  163688. retval |= PNG_INFO_tRNS;
  163689. }
  163690. if (trans_values != NULL)
  163691. *trans_values = &(info_ptr->trans_values);
  163692. }
  163693. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163694. {
  163695. if (trans_values != NULL)
  163696. {
  163697. *trans_values = &(info_ptr->trans_values);
  163698. retval |= PNG_INFO_tRNS;
  163699. }
  163700. if(trans != NULL)
  163701. *trans = NULL;
  163702. }
  163703. if(num_trans != NULL)
  163704. {
  163705. *num_trans = info_ptr->num_trans;
  163706. retval |= PNG_INFO_tRNS;
  163707. }
  163708. }
  163709. return (retval);
  163710. }
  163711. #endif
  163712. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163713. png_uint_32 PNGAPI
  163714. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163715. png_unknown_chunkpp unknowns)
  163716. {
  163717. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163718. {
  163719. *unknowns = info_ptr->unknown_chunks;
  163720. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163721. }
  163722. return (0);
  163723. }
  163724. #endif
  163725. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163726. png_byte PNGAPI
  163727. png_get_rgb_to_gray_status (png_structp png_ptr)
  163728. {
  163729. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163730. }
  163731. #endif
  163732. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163733. png_voidp PNGAPI
  163734. png_get_user_chunk_ptr(png_structp png_ptr)
  163735. {
  163736. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163737. }
  163738. #endif
  163739. #ifdef PNG_WRITE_SUPPORTED
  163740. png_uint_32 PNGAPI
  163741. png_get_compression_buffer_size(png_structp png_ptr)
  163742. {
  163743. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163744. }
  163745. #endif
  163746. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163747. #ifndef PNG_1_0_X
  163748. png_uint_32 PNGAPI
  163749. png_get_asm_flags (png_structp png_ptr)
  163750. {
  163751. return (png_ptr? 0L: 0L);
  163752. }
  163753. png_uint_32 PNGAPI
  163754. png_get_asm_flagmask (int flag_select)
  163755. {
  163756. flag_select=flag_select;
  163757. return 0L;
  163758. }
  163759. png_uint_32 PNGAPI
  163760. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163761. {
  163762. flag_select=flag_select;
  163763. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163764. return 0L;
  163765. }
  163766. png_byte PNGAPI
  163767. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163768. {
  163769. return (png_ptr? 0: 0);
  163770. }
  163771. png_uint_32 PNGAPI
  163772. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163773. {
  163774. return (png_ptr? 0L: 0L);
  163775. }
  163776. #endif /* ?PNG_1_0_X */
  163777. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163778. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163779. png_uint_32 PNGAPI
  163780. png_get_user_width_max (png_structp png_ptr)
  163781. {
  163782. return (png_ptr? png_ptr->user_width_max : 0);
  163783. }
  163784. png_uint_32 PNGAPI
  163785. png_get_user_height_max (png_structp png_ptr)
  163786. {
  163787. return (png_ptr? png_ptr->user_height_max : 0);
  163788. }
  163789. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163790. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163791. /*** End of inlined file: pngget.c ***/
  163792. /*** Start of inlined file: pngmem.c ***/
  163793. #define PNG_INTERNAL
  163794. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163795. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163796. png_voidp /* PRIVATE */
  163797. png_create_struct(int type)
  163798. {
  163799. #ifdef PNG_USER_MEM_SUPPORTED
  163800. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163801. }
  163802. png_voidp /* PRIVATE */
  163803. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163804. {
  163805. #endif /* PNG_USER_MEM_SUPPORTED */
  163806. png_size_t size;
  163807. png_voidp struct_ptr;
  163808. if (type == PNG_STRUCT_INFO)
  163809. size = png_sizeof(png_info);
  163810. else if (type == PNG_STRUCT_PNG)
  163811. size = png_sizeof(png_struct);
  163812. else
  163813. return (png_get_copyright(NULL));
  163814. #ifdef PNG_USER_MEM_SUPPORTED
  163815. if(malloc_fn != NULL)
  163816. {
  163817. png_struct dummy_struct;
  163818. png_structp png_ptr = &dummy_struct;
  163819. png_ptr->mem_ptr=mem_ptr;
  163820. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163821. }
  163822. else
  163823. #endif /* PNG_USER_MEM_SUPPORTED */
  163824. struct_ptr = (png_voidp)farmalloc(size);
  163825. if (struct_ptr != NULL)
  163826. png_memset(struct_ptr, 0, size);
  163827. return (struct_ptr);
  163828. }
  163829. void /* PRIVATE */
  163830. png_destroy_struct(png_voidp struct_ptr)
  163831. {
  163832. #ifdef PNG_USER_MEM_SUPPORTED
  163833. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163834. }
  163835. void /* PRIVATE */
  163836. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163837. png_voidp mem_ptr)
  163838. {
  163839. #endif
  163840. if (struct_ptr != NULL)
  163841. {
  163842. #ifdef PNG_USER_MEM_SUPPORTED
  163843. if(free_fn != NULL)
  163844. {
  163845. png_struct dummy_struct;
  163846. png_structp png_ptr = &dummy_struct;
  163847. png_ptr->mem_ptr=mem_ptr;
  163848. (*(free_fn))(png_ptr, struct_ptr);
  163849. return;
  163850. }
  163851. #endif /* PNG_USER_MEM_SUPPORTED */
  163852. farfree (struct_ptr);
  163853. }
  163854. }
  163855. png_voidp PNGAPI
  163856. png_malloc(png_structp png_ptr, png_uint_32 size)
  163857. {
  163858. png_voidp ret;
  163859. if (png_ptr == NULL || size == 0)
  163860. return (NULL);
  163861. #ifdef PNG_USER_MEM_SUPPORTED
  163862. if(png_ptr->malloc_fn != NULL)
  163863. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163864. else
  163865. ret = (png_malloc_default(png_ptr, size));
  163866. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163867. png_error(png_ptr, "Out of memory!");
  163868. return (ret);
  163869. }
  163870. png_voidp PNGAPI
  163871. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163872. {
  163873. png_voidp ret;
  163874. #endif /* PNG_USER_MEM_SUPPORTED */
  163875. if (png_ptr == NULL || size == 0)
  163876. return (NULL);
  163877. #ifdef PNG_MAX_MALLOC_64K
  163878. if (size > (png_uint_32)65536L)
  163879. {
  163880. png_warning(png_ptr, "Cannot Allocate > 64K");
  163881. ret = NULL;
  163882. }
  163883. else
  163884. #endif
  163885. if (size != (size_t)size)
  163886. ret = NULL;
  163887. else if (size == (png_uint_32)65536L)
  163888. {
  163889. if (png_ptr->offset_table == NULL)
  163890. {
  163891. ret = farmalloc(size);
  163892. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163893. {
  163894. int num_blocks;
  163895. png_uint_32 total_size;
  163896. png_bytep table;
  163897. int i;
  163898. png_byte huge * hptr;
  163899. if (ret != NULL)
  163900. {
  163901. farfree(ret);
  163902. ret = NULL;
  163903. }
  163904. if(png_ptr->zlib_window_bits > 14)
  163905. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163906. else
  163907. num_blocks = 1;
  163908. if (png_ptr->zlib_mem_level >= 7)
  163909. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163910. else
  163911. num_blocks++;
  163912. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163913. table = farmalloc(total_size);
  163914. if (table == NULL)
  163915. {
  163916. #ifndef PNG_USER_MEM_SUPPORTED
  163917. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163918. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163919. else
  163920. png_warning(png_ptr, "Out Of Memory.");
  163921. #endif
  163922. return (NULL);
  163923. }
  163924. if ((png_size_t)table & 0xfff0)
  163925. {
  163926. #ifndef PNG_USER_MEM_SUPPORTED
  163927. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163928. png_error(png_ptr,
  163929. "Farmalloc didn't return normalized pointer");
  163930. else
  163931. png_warning(png_ptr,
  163932. "Farmalloc didn't return normalized pointer");
  163933. #endif
  163934. return (NULL);
  163935. }
  163936. png_ptr->offset_table = table;
  163937. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  163938. png_sizeof (png_bytep));
  163939. if (png_ptr->offset_table_ptr == NULL)
  163940. {
  163941. #ifndef PNG_USER_MEM_SUPPORTED
  163942. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163943. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  163944. else
  163945. png_warning(png_ptr, "Out Of memory.");
  163946. #endif
  163947. return (NULL);
  163948. }
  163949. hptr = (png_byte huge *)table;
  163950. if ((png_size_t)hptr & 0xf)
  163951. {
  163952. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  163953. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  163954. }
  163955. for (i = 0; i < num_blocks; i++)
  163956. {
  163957. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  163958. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  163959. }
  163960. png_ptr->offset_table_number = num_blocks;
  163961. png_ptr->offset_table_count = 0;
  163962. png_ptr->offset_table_count_free = 0;
  163963. }
  163964. }
  163965. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  163966. {
  163967. #ifndef PNG_USER_MEM_SUPPORTED
  163968. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163969. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  163970. else
  163971. png_warning(png_ptr, "Out of Memory.");
  163972. #endif
  163973. return (NULL);
  163974. }
  163975. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  163976. }
  163977. else
  163978. ret = farmalloc(size);
  163979. #ifndef PNG_USER_MEM_SUPPORTED
  163980. if (ret == NULL)
  163981. {
  163982. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163983. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163984. else
  163985. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163986. }
  163987. #endif
  163988. return (ret);
  163989. }
  163990. void PNGAPI
  163991. png_free(png_structp png_ptr, png_voidp ptr)
  163992. {
  163993. if (png_ptr == NULL || ptr == NULL)
  163994. return;
  163995. #ifdef PNG_USER_MEM_SUPPORTED
  163996. if (png_ptr->free_fn != NULL)
  163997. {
  163998. (*(png_ptr->free_fn))(png_ptr, ptr);
  163999. return;
  164000. }
  164001. else png_free_default(png_ptr, ptr);
  164002. }
  164003. void PNGAPI
  164004. png_free_default(png_structp png_ptr, png_voidp ptr)
  164005. {
  164006. #endif /* PNG_USER_MEM_SUPPORTED */
  164007. if(png_ptr == NULL) return;
  164008. if (png_ptr->offset_table != NULL)
  164009. {
  164010. int i;
  164011. for (i = 0; i < png_ptr->offset_table_count; i++)
  164012. {
  164013. if (ptr == png_ptr->offset_table_ptr[i])
  164014. {
  164015. ptr = NULL;
  164016. png_ptr->offset_table_count_free++;
  164017. break;
  164018. }
  164019. }
  164020. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164021. {
  164022. farfree(png_ptr->offset_table);
  164023. farfree(png_ptr->offset_table_ptr);
  164024. png_ptr->offset_table = NULL;
  164025. png_ptr->offset_table_ptr = NULL;
  164026. }
  164027. }
  164028. if (ptr != NULL)
  164029. {
  164030. farfree(ptr);
  164031. }
  164032. }
  164033. #else /* Not the Borland DOS special memory handler */
  164034. png_voidp /* PRIVATE */
  164035. png_create_struct(int type)
  164036. {
  164037. #ifdef PNG_USER_MEM_SUPPORTED
  164038. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164039. }
  164040. png_voidp /* PRIVATE */
  164041. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164042. {
  164043. #endif /* PNG_USER_MEM_SUPPORTED */
  164044. png_size_t size;
  164045. png_voidp struct_ptr;
  164046. if (type == PNG_STRUCT_INFO)
  164047. size = png_sizeof(png_info);
  164048. else if (type == PNG_STRUCT_PNG)
  164049. size = png_sizeof(png_struct);
  164050. else
  164051. return (NULL);
  164052. #ifdef PNG_USER_MEM_SUPPORTED
  164053. if(malloc_fn != NULL)
  164054. {
  164055. png_struct dummy_struct;
  164056. png_structp png_ptr = &dummy_struct;
  164057. png_ptr->mem_ptr=mem_ptr;
  164058. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164059. if (struct_ptr != NULL)
  164060. png_memset(struct_ptr, 0, size);
  164061. return (struct_ptr);
  164062. }
  164063. #endif /* PNG_USER_MEM_SUPPORTED */
  164064. #if defined(__TURBOC__) && !defined(__FLAT__)
  164065. struct_ptr = (png_voidp)farmalloc(size);
  164066. #else
  164067. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164068. struct_ptr = (png_voidp)halloc(size,1);
  164069. # else
  164070. struct_ptr = (png_voidp)malloc(size);
  164071. # endif
  164072. #endif
  164073. if (struct_ptr != NULL)
  164074. png_memset(struct_ptr, 0, size);
  164075. return (struct_ptr);
  164076. }
  164077. void /* PRIVATE */
  164078. png_destroy_struct(png_voidp struct_ptr)
  164079. {
  164080. #ifdef PNG_USER_MEM_SUPPORTED
  164081. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164082. }
  164083. void /* PRIVATE */
  164084. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164085. png_voidp mem_ptr)
  164086. {
  164087. #endif /* PNG_USER_MEM_SUPPORTED */
  164088. if (struct_ptr != NULL)
  164089. {
  164090. #ifdef PNG_USER_MEM_SUPPORTED
  164091. if(free_fn != NULL)
  164092. {
  164093. png_struct dummy_struct;
  164094. png_structp png_ptr = &dummy_struct;
  164095. png_ptr->mem_ptr=mem_ptr;
  164096. (*(free_fn))(png_ptr, struct_ptr);
  164097. return;
  164098. }
  164099. #endif /* PNG_USER_MEM_SUPPORTED */
  164100. #if defined(__TURBOC__) && !defined(__FLAT__)
  164101. farfree(struct_ptr);
  164102. #else
  164103. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164104. hfree(struct_ptr);
  164105. # else
  164106. free(struct_ptr);
  164107. # endif
  164108. #endif
  164109. }
  164110. }
  164111. png_voidp PNGAPI
  164112. png_malloc(png_structp png_ptr, png_uint_32 size)
  164113. {
  164114. png_voidp ret;
  164115. #ifdef PNG_USER_MEM_SUPPORTED
  164116. if (png_ptr == NULL || size == 0)
  164117. return (NULL);
  164118. if(png_ptr->malloc_fn != NULL)
  164119. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164120. else
  164121. ret = (png_malloc_default(png_ptr, size));
  164122. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164123. png_error(png_ptr, "Out of Memory!");
  164124. return (ret);
  164125. }
  164126. png_voidp PNGAPI
  164127. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164128. {
  164129. png_voidp ret;
  164130. #endif /* PNG_USER_MEM_SUPPORTED */
  164131. if (png_ptr == NULL || size == 0)
  164132. return (NULL);
  164133. #ifdef PNG_MAX_MALLOC_64K
  164134. if (size > (png_uint_32)65536L)
  164135. {
  164136. #ifndef PNG_USER_MEM_SUPPORTED
  164137. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164138. png_error(png_ptr, "Cannot Allocate > 64K");
  164139. else
  164140. #endif
  164141. return NULL;
  164142. }
  164143. #endif
  164144. #if defined(__TURBOC__) && !defined(__FLAT__)
  164145. if (size != (unsigned long)size)
  164146. ret = NULL;
  164147. else
  164148. ret = farmalloc(size);
  164149. #else
  164150. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164151. if (size != (unsigned long)size)
  164152. ret = NULL;
  164153. else
  164154. ret = halloc(size, 1);
  164155. # else
  164156. if (size != (size_t)size)
  164157. ret = NULL;
  164158. else
  164159. ret = malloc((size_t)size);
  164160. # endif
  164161. #endif
  164162. #ifndef PNG_USER_MEM_SUPPORTED
  164163. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164164. png_error(png_ptr, "Out of Memory");
  164165. #endif
  164166. return (ret);
  164167. }
  164168. void PNGAPI
  164169. png_free(png_structp png_ptr, png_voidp ptr)
  164170. {
  164171. if (png_ptr == NULL || ptr == NULL)
  164172. return;
  164173. #ifdef PNG_USER_MEM_SUPPORTED
  164174. if (png_ptr->free_fn != NULL)
  164175. {
  164176. (*(png_ptr->free_fn))(png_ptr, ptr);
  164177. return;
  164178. }
  164179. else png_free_default(png_ptr, ptr);
  164180. }
  164181. void PNGAPI
  164182. png_free_default(png_structp png_ptr, png_voidp ptr)
  164183. {
  164184. if (png_ptr == NULL || ptr == NULL)
  164185. return;
  164186. #endif /* PNG_USER_MEM_SUPPORTED */
  164187. #if defined(__TURBOC__) && !defined(__FLAT__)
  164188. farfree(ptr);
  164189. #else
  164190. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164191. hfree(ptr);
  164192. # else
  164193. free(ptr);
  164194. # endif
  164195. #endif
  164196. }
  164197. #endif /* Not Borland DOS special memory handler */
  164198. #if defined(PNG_1_0_X)
  164199. # define png_malloc_warn png_malloc
  164200. #else
  164201. png_voidp PNGAPI
  164202. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164203. {
  164204. png_voidp ptr;
  164205. png_uint_32 save_flags;
  164206. if(png_ptr == NULL) return (NULL);
  164207. save_flags=png_ptr->flags;
  164208. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164209. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164210. png_ptr->flags=save_flags;
  164211. return(ptr);
  164212. }
  164213. #endif
  164214. png_voidp PNGAPI
  164215. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164216. png_uint_32 length)
  164217. {
  164218. png_size_t size;
  164219. size = (png_size_t)length;
  164220. if ((png_uint_32)size != length)
  164221. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164222. return(png_memcpy (s1, s2, size));
  164223. }
  164224. png_voidp PNGAPI
  164225. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164226. png_uint_32 length)
  164227. {
  164228. png_size_t size;
  164229. size = (png_size_t)length;
  164230. if ((png_uint_32)size != length)
  164231. png_error(png_ptr,"Overflow in png_memset_check.");
  164232. return (png_memset (s1, value, size));
  164233. }
  164234. #ifdef PNG_USER_MEM_SUPPORTED
  164235. void PNGAPI
  164236. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164237. malloc_fn, png_free_ptr free_fn)
  164238. {
  164239. if(png_ptr != NULL) {
  164240. png_ptr->mem_ptr = mem_ptr;
  164241. png_ptr->malloc_fn = malloc_fn;
  164242. png_ptr->free_fn = free_fn;
  164243. }
  164244. }
  164245. png_voidp PNGAPI
  164246. png_get_mem_ptr(png_structp png_ptr)
  164247. {
  164248. if(png_ptr == NULL) return (NULL);
  164249. return ((png_voidp)png_ptr->mem_ptr);
  164250. }
  164251. #endif /* PNG_USER_MEM_SUPPORTED */
  164252. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164253. /*** End of inlined file: pngmem.c ***/
  164254. /*** Start of inlined file: pngread.c ***/
  164255. #define PNG_INTERNAL
  164256. #if defined(PNG_READ_SUPPORTED)
  164257. png_structp PNGAPI
  164258. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164259. png_error_ptr error_fn, png_error_ptr warn_fn)
  164260. {
  164261. #ifdef PNG_USER_MEM_SUPPORTED
  164262. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164263. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164264. }
  164265. png_structp PNGAPI
  164266. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164267. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164268. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164269. {
  164270. #endif /* PNG_USER_MEM_SUPPORTED */
  164271. png_structp png_ptr;
  164272. #ifdef PNG_SETJMP_SUPPORTED
  164273. #ifdef USE_FAR_KEYWORD
  164274. jmp_buf jmpbuf;
  164275. #endif
  164276. #endif
  164277. int i;
  164278. png_debug(1, "in png_create_read_struct\n");
  164279. #ifdef PNG_USER_MEM_SUPPORTED
  164280. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164281. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164282. #else
  164283. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164284. #endif
  164285. if (png_ptr == NULL)
  164286. return (NULL);
  164287. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164288. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164289. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164290. #endif
  164291. #ifdef PNG_SETJMP_SUPPORTED
  164292. #ifdef USE_FAR_KEYWORD
  164293. if (setjmp(jmpbuf))
  164294. #else
  164295. if (setjmp(png_ptr->jmpbuf))
  164296. #endif
  164297. {
  164298. png_free(png_ptr, png_ptr->zbuf);
  164299. png_ptr->zbuf=NULL;
  164300. #ifdef PNG_USER_MEM_SUPPORTED
  164301. png_destroy_struct_2((png_voidp)png_ptr,
  164302. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164303. #else
  164304. png_destroy_struct((png_voidp)png_ptr);
  164305. #endif
  164306. return (NULL);
  164307. }
  164308. #ifdef USE_FAR_KEYWORD
  164309. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164310. #endif
  164311. #endif
  164312. #ifdef PNG_USER_MEM_SUPPORTED
  164313. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164314. #endif
  164315. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164316. i=0;
  164317. do
  164318. {
  164319. if(user_png_ver[i] != png_libpng_ver[i])
  164320. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164321. } while (png_libpng_ver[i++]);
  164322. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164323. {
  164324. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164325. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164326. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164327. {
  164328. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164329. char msg[80];
  164330. if (user_png_ver)
  164331. {
  164332. png_snprintf(msg, 80,
  164333. "Application was compiled with png.h from libpng-%.20s",
  164334. user_png_ver);
  164335. png_warning(png_ptr, msg);
  164336. }
  164337. png_snprintf(msg, 80,
  164338. "Application is running with png.c from libpng-%.20s",
  164339. png_libpng_ver);
  164340. png_warning(png_ptr, msg);
  164341. #endif
  164342. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164343. png_ptr->flags=0;
  164344. #endif
  164345. png_error(png_ptr,
  164346. "Incompatible libpng version in application and library");
  164347. }
  164348. }
  164349. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164350. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164351. (png_uint_32)png_ptr->zbuf_size);
  164352. png_ptr->zstream.zalloc = png_zalloc;
  164353. png_ptr->zstream.zfree = png_zfree;
  164354. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164355. switch (inflateInit(&png_ptr->zstream))
  164356. {
  164357. case Z_OK: /* Do nothing */ break;
  164358. case Z_MEM_ERROR:
  164359. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164360. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164361. default: png_error(png_ptr, "Unknown zlib error");
  164362. }
  164363. png_ptr->zstream.next_out = png_ptr->zbuf;
  164364. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164365. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164366. #ifdef PNG_SETJMP_SUPPORTED
  164367. #ifdef USE_FAR_KEYWORD
  164368. if (setjmp(jmpbuf))
  164369. PNG_ABORT();
  164370. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164371. #else
  164372. if (setjmp(png_ptr->jmpbuf))
  164373. PNG_ABORT();
  164374. #endif
  164375. #endif
  164376. return (png_ptr);
  164377. }
  164378. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164379. #undef png_read_init
  164380. void PNGAPI
  164381. png_read_init(png_structp png_ptr)
  164382. {
  164383. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164384. }
  164385. void PNGAPI
  164386. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164387. png_size_t png_struct_size, png_size_t png_info_size)
  164388. {
  164389. if(png_ptr == NULL) return;
  164390. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164391. if(png_sizeof(png_struct) > png_struct_size ||
  164392. png_sizeof(png_info) > png_info_size)
  164393. {
  164394. char msg[80];
  164395. png_ptr->warning_fn=NULL;
  164396. if (user_png_ver)
  164397. {
  164398. png_snprintf(msg, 80,
  164399. "Application was compiled with png.h from libpng-%.20s",
  164400. user_png_ver);
  164401. png_warning(png_ptr, msg);
  164402. }
  164403. png_snprintf(msg, 80,
  164404. "Application is running with png.c from libpng-%.20s",
  164405. png_libpng_ver);
  164406. png_warning(png_ptr, msg);
  164407. }
  164408. #endif
  164409. if(png_sizeof(png_struct) > png_struct_size)
  164410. {
  164411. png_ptr->error_fn=NULL;
  164412. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164413. png_ptr->flags=0;
  164414. #endif
  164415. png_error(png_ptr,
  164416. "The png struct allocated by the application for reading is too small.");
  164417. }
  164418. if(png_sizeof(png_info) > png_info_size)
  164419. {
  164420. png_ptr->error_fn=NULL;
  164421. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164422. png_ptr->flags=0;
  164423. #endif
  164424. png_error(png_ptr,
  164425. "The info struct allocated by application for reading is too small.");
  164426. }
  164427. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164428. }
  164429. #endif /* PNG_1_0_X || PNG_1_2_X */
  164430. void PNGAPI
  164431. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164432. png_size_t png_struct_size)
  164433. {
  164434. #ifdef PNG_SETJMP_SUPPORTED
  164435. jmp_buf tmp_jmp; /* to save current jump buffer */
  164436. #endif
  164437. int i=0;
  164438. png_structp png_ptr=*ptr_ptr;
  164439. if(png_ptr == NULL) return;
  164440. do
  164441. {
  164442. if(user_png_ver[i] != png_libpng_ver[i])
  164443. {
  164444. #ifdef PNG_LEGACY_SUPPORTED
  164445. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164446. #else
  164447. png_ptr->warning_fn=NULL;
  164448. png_warning(png_ptr,
  164449. "Application uses deprecated png_read_init() and should be recompiled.");
  164450. break;
  164451. #endif
  164452. }
  164453. } while (png_libpng_ver[i++]);
  164454. png_debug(1, "in png_read_init_3\n");
  164455. #ifdef PNG_SETJMP_SUPPORTED
  164456. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164457. #endif
  164458. if(png_sizeof(png_struct) > png_struct_size)
  164459. {
  164460. png_destroy_struct(png_ptr);
  164461. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164462. png_ptr = *ptr_ptr;
  164463. }
  164464. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164465. #ifdef PNG_SETJMP_SUPPORTED
  164466. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164467. #endif
  164468. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164469. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164470. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164471. #endif
  164472. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164473. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164474. (png_uint_32)png_ptr->zbuf_size);
  164475. png_ptr->zstream.zalloc = png_zalloc;
  164476. png_ptr->zstream.zfree = png_zfree;
  164477. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164478. switch (inflateInit(&png_ptr->zstream))
  164479. {
  164480. case Z_OK: /* Do nothing */ break;
  164481. case Z_MEM_ERROR:
  164482. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164483. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164484. default: png_error(png_ptr, "Unknown zlib error");
  164485. }
  164486. png_ptr->zstream.next_out = png_ptr->zbuf;
  164487. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164488. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164489. }
  164490. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164491. void PNGAPI
  164492. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164493. {
  164494. if(png_ptr == NULL) return;
  164495. png_debug(1, "in png_read_info\n");
  164496. if (png_ptr->sig_bytes < 8)
  164497. {
  164498. png_size_t num_checked = png_ptr->sig_bytes,
  164499. num_to_check = 8 - num_checked;
  164500. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164501. png_ptr->sig_bytes = 8;
  164502. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164503. {
  164504. if (num_checked < 4 &&
  164505. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164506. png_error(png_ptr, "Not a PNG file");
  164507. else
  164508. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164509. }
  164510. if (num_checked < 3)
  164511. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164512. }
  164513. for(;;)
  164514. {
  164515. #ifdef PNG_USE_LOCAL_ARRAYS
  164516. PNG_CONST PNG_IHDR;
  164517. PNG_CONST PNG_IDAT;
  164518. PNG_CONST PNG_IEND;
  164519. PNG_CONST PNG_PLTE;
  164520. #if defined(PNG_READ_bKGD_SUPPORTED)
  164521. PNG_CONST PNG_bKGD;
  164522. #endif
  164523. #if defined(PNG_READ_cHRM_SUPPORTED)
  164524. PNG_CONST PNG_cHRM;
  164525. #endif
  164526. #if defined(PNG_READ_gAMA_SUPPORTED)
  164527. PNG_CONST PNG_gAMA;
  164528. #endif
  164529. #if defined(PNG_READ_hIST_SUPPORTED)
  164530. PNG_CONST PNG_hIST;
  164531. #endif
  164532. #if defined(PNG_READ_iCCP_SUPPORTED)
  164533. PNG_CONST PNG_iCCP;
  164534. #endif
  164535. #if defined(PNG_READ_iTXt_SUPPORTED)
  164536. PNG_CONST PNG_iTXt;
  164537. #endif
  164538. #if defined(PNG_READ_oFFs_SUPPORTED)
  164539. PNG_CONST PNG_oFFs;
  164540. #endif
  164541. #if defined(PNG_READ_pCAL_SUPPORTED)
  164542. PNG_CONST PNG_pCAL;
  164543. #endif
  164544. #if defined(PNG_READ_pHYs_SUPPORTED)
  164545. PNG_CONST PNG_pHYs;
  164546. #endif
  164547. #if defined(PNG_READ_sBIT_SUPPORTED)
  164548. PNG_CONST PNG_sBIT;
  164549. #endif
  164550. #if defined(PNG_READ_sCAL_SUPPORTED)
  164551. PNG_CONST PNG_sCAL;
  164552. #endif
  164553. #if defined(PNG_READ_sPLT_SUPPORTED)
  164554. PNG_CONST PNG_sPLT;
  164555. #endif
  164556. #if defined(PNG_READ_sRGB_SUPPORTED)
  164557. PNG_CONST PNG_sRGB;
  164558. #endif
  164559. #if defined(PNG_READ_tEXt_SUPPORTED)
  164560. PNG_CONST PNG_tEXt;
  164561. #endif
  164562. #if defined(PNG_READ_tIME_SUPPORTED)
  164563. PNG_CONST PNG_tIME;
  164564. #endif
  164565. #if defined(PNG_READ_tRNS_SUPPORTED)
  164566. PNG_CONST PNG_tRNS;
  164567. #endif
  164568. #if defined(PNG_READ_zTXt_SUPPORTED)
  164569. PNG_CONST PNG_zTXt;
  164570. #endif
  164571. #endif /* PNG_USE_LOCAL_ARRAYS */
  164572. png_byte chunk_length[4];
  164573. png_uint_32 length;
  164574. png_read_data(png_ptr, chunk_length, 4);
  164575. length = png_get_uint_31(png_ptr,chunk_length);
  164576. png_reset_crc(png_ptr);
  164577. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164578. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164579. length);
  164580. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164581. if(png_ptr->mode & PNG_AFTER_IDAT)
  164582. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164583. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164584. png_handle_IHDR(png_ptr, info_ptr, length);
  164585. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164586. png_handle_IEND(png_ptr, info_ptr, length);
  164587. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164588. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164589. {
  164590. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164591. png_ptr->mode |= PNG_HAVE_IDAT;
  164592. png_handle_unknown(png_ptr, info_ptr, length);
  164593. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164594. png_ptr->mode |= PNG_HAVE_PLTE;
  164595. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164596. {
  164597. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164598. png_error(png_ptr, "Missing IHDR before IDAT");
  164599. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164600. !(png_ptr->mode & PNG_HAVE_PLTE))
  164601. png_error(png_ptr, "Missing PLTE before IDAT");
  164602. break;
  164603. }
  164604. }
  164605. #endif
  164606. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164607. png_handle_PLTE(png_ptr, info_ptr, length);
  164608. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164609. {
  164610. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164611. png_error(png_ptr, "Missing IHDR before IDAT");
  164612. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164613. !(png_ptr->mode & PNG_HAVE_PLTE))
  164614. png_error(png_ptr, "Missing PLTE before IDAT");
  164615. png_ptr->idat_size = length;
  164616. png_ptr->mode |= PNG_HAVE_IDAT;
  164617. break;
  164618. }
  164619. #if defined(PNG_READ_bKGD_SUPPORTED)
  164620. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164621. png_handle_bKGD(png_ptr, info_ptr, length);
  164622. #endif
  164623. #if defined(PNG_READ_cHRM_SUPPORTED)
  164624. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164625. png_handle_cHRM(png_ptr, info_ptr, length);
  164626. #endif
  164627. #if defined(PNG_READ_gAMA_SUPPORTED)
  164628. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164629. png_handle_gAMA(png_ptr, info_ptr, length);
  164630. #endif
  164631. #if defined(PNG_READ_hIST_SUPPORTED)
  164632. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164633. png_handle_hIST(png_ptr, info_ptr, length);
  164634. #endif
  164635. #if defined(PNG_READ_oFFs_SUPPORTED)
  164636. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164637. png_handle_oFFs(png_ptr, info_ptr, length);
  164638. #endif
  164639. #if defined(PNG_READ_pCAL_SUPPORTED)
  164640. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164641. png_handle_pCAL(png_ptr, info_ptr, length);
  164642. #endif
  164643. #if defined(PNG_READ_sCAL_SUPPORTED)
  164644. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164645. png_handle_sCAL(png_ptr, info_ptr, length);
  164646. #endif
  164647. #if defined(PNG_READ_pHYs_SUPPORTED)
  164648. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164649. png_handle_pHYs(png_ptr, info_ptr, length);
  164650. #endif
  164651. #if defined(PNG_READ_sBIT_SUPPORTED)
  164652. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164653. png_handle_sBIT(png_ptr, info_ptr, length);
  164654. #endif
  164655. #if defined(PNG_READ_sRGB_SUPPORTED)
  164656. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164657. png_handle_sRGB(png_ptr, info_ptr, length);
  164658. #endif
  164659. #if defined(PNG_READ_iCCP_SUPPORTED)
  164660. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164661. png_handle_iCCP(png_ptr, info_ptr, length);
  164662. #endif
  164663. #if defined(PNG_READ_sPLT_SUPPORTED)
  164664. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164665. png_handle_sPLT(png_ptr, info_ptr, length);
  164666. #endif
  164667. #if defined(PNG_READ_tEXt_SUPPORTED)
  164668. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164669. png_handle_tEXt(png_ptr, info_ptr, length);
  164670. #endif
  164671. #if defined(PNG_READ_tIME_SUPPORTED)
  164672. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164673. png_handle_tIME(png_ptr, info_ptr, length);
  164674. #endif
  164675. #if defined(PNG_READ_tRNS_SUPPORTED)
  164676. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164677. png_handle_tRNS(png_ptr, info_ptr, length);
  164678. #endif
  164679. #if defined(PNG_READ_zTXt_SUPPORTED)
  164680. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164681. png_handle_zTXt(png_ptr, info_ptr, length);
  164682. #endif
  164683. #if defined(PNG_READ_iTXt_SUPPORTED)
  164684. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164685. png_handle_iTXt(png_ptr, info_ptr, length);
  164686. #endif
  164687. else
  164688. png_handle_unknown(png_ptr, info_ptr, length);
  164689. }
  164690. }
  164691. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164692. void PNGAPI
  164693. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164694. {
  164695. png_debug(1, "in png_read_update_info\n");
  164696. if(png_ptr == NULL) return;
  164697. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164698. png_read_start_row(png_ptr);
  164699. else
  164700. png_warning(png_ptr,
  164701. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164702. png_read_transform_info(png_ptr, info_ptr);
  164703. }
  164704. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164705. void PNGAPI
  164706. png_start_read_image(png_structp png_ptr)
  164707. {
  164708. png_debug(1, "in png_start_read_image\n");
  164709. if(png_ptr == NULL) return;
  164710. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164711. png_read_start_row(png_ptr);
  164712. }
  164713. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164714. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164715. void PNGAPI
  164716. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164717. {
  164718. #ifdef PNG_USE_LOCAL_ARRAYS
  164719. PNG_CONST PNG_IDAT;
  164720. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164721. 0xff};
  164722. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164723. #endif
  164724. int ret;
  164725. if(png_ptr == NULL) return;
  164726. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164727. png_ptr->row_number, png_ptr->pass);
  164728. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164729. png_read_start_row(png_ptr);
  164730. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164731. {
  164732. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164733. if (png_ptr->transformations & PNG_INVERT_MONO)
  164734. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164735. #endif
  164736. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164737. if (png_ptr->transformations & PNG_FILLER)
  164738. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164739. #endif
  164740. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164741. if (png_ptr->transformations & PNG_PACKSWAP)
  164742. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164743. #endif
  164744. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164745. if (png_ptr->transformations & PNG_PACK)
  164746. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164747. #endif
  164748. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164749. if (png_ptr->transformations & PNG_SHIFT)
  164750. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164751. #endif
  164752. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164753. if (png_ptr->transformations & PNG_BGR)
  164754. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164755. #endif
  164756. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164757. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164758. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164759. #endif
  164760. }
  164761. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164762. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164763. {
  164764. switch (png_ptr->pass)
  164765. {
  164766. case 0:
  164767. if (png_ptr->row_number & 0x07)
  164768. {
  164769. if (dsp_row != NULL)
  164770. png_combine_row(png_ptr, dsp_row,
  164771. png_pass_dsp_mask[png_ptr->pass]);
  164772. png_read_finish_row(png_ptr);
  164773. return;
  164774. }
  164775. break;
  164776. case 1:
  164777. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164778. {
  164779. if (dsp_row != NULL)
  164780. png_combine_row(png_ptr, dsp_row,
  164781. png_pass_dsp_mask[png_ptr->pass]);
  164782. png_read_finish_row(png_ptr);
  164783. return;
  164784. }
  164785. break;
  164786. case 2:
  164787. if ((png_ptr->row_number & 0x07) != 4)
  164788. {
  164789. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164790. png_combine_row(png_ptr, dsp_row,
  164791. png_pass_dsp_mask[png_ptr->pass]);
  164792. png_read_finish_row(png_ptr);
  164793. return;
  164794. }
  164795. break;
  164796. case 3:
  164797. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164798. {
  164799. if (dsp_row != NULL)
  164800. png_combine_row(png_ptr, dsp_row,
  164801. png_pass_dsp_mask[png_ptr->pass]);
  164802. png_read_finish_row(png_ptr);
  164803. return;
  164804. }
  164805. break;
  164806. case 4:
  164807. if ((png_ptr->row_number & 3) != 2)
  164808. {
  164809. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164810. png_combine_row(png_ptr, dsp_row,
  164811. png_pass_dsp_mask[png_ptr->pass]);
  164812. png_read_finish_row(png_ptr);
  164813. return;
  164814. }
  164815. break;
  164816. case 5:
  164817. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164818. {
  164819. if (dsp_row != NULL)
  164820. png_combine_row(png_ptr, dsp_row,
  164821. png_pass_dsp_mask[png_ptr->pass]);
  164822. png_read_finish_row(png_ptr);
  164823. return;
  164824. }
  164825. break;
  164826. case 6:
  164827. if (!(png_ptr->row_number & 1))
  164828. {
  164829. png_read_finish_row(png_ptr);
  164830. return;
  164831. }
  164832. break;
  164833. }
  164834. }
  164835. #endif
  164836. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164837. png_error(png_ptr, "Invalid attempt to read row data");
  164838. png_ptr->zstream.next_out = png_ptr->row_buf;
  164839. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164840. do
  164841. {
  164842. if (!(png_ptr->zstream.avail_in))
  164843. {
  164844. while (!png_ptr->idat_size)
  164845. {
  164846. png_byte chunk_length[4];
  164847. png_crc_finish(png_ptr, 0);
  164848. png_read_data(png_ptr, chunk_length, 4);
  164849. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164850. png_reset_crc(png_ptr);
  164851. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164852. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164853. png_error(png_ptr, "Not enough image data");
  164854. }
  164855. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164856. png_ptr->zstream.next_in = png_ptr->zbuf;
  164857. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164858. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164859. png_crc_read(png_ptr, png_ptr->zbuf,
  164860. (png_size_t)png_ptr->zstream.avail_in);
  164861. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164862. }
  164863. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164864. if (ret == Z_STREAM_END)
  164865. {
  164866. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164867. png_ptr->idat_size)
  164868. png_error(png_ptr, "Extra compressed data");
  164869. png_ptr->mode |= PNG_AFTER_IDAT;
  164870. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164871. break;
  164872. }
  164873. if (ret != Z_OK)
  164874. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164875. "Decompression error");
  164876. } while (png_ptr->zstream.avail_out);
  164877. png_ptr->row_info.color_type = png_ptr->color_type;
  164878. png_ptr->row_info.width = png_ptr->iwidth;
  164879. png_ptr->row_info.channels = png_ptr->channels;
  164880. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164881. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164882. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164883. png_ptr->row_info.width);
  164884. if(png_ptr->row_buf[0])
  164885. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164886. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164887. (int)(png_ptr->row_buf[0]));
  164888. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164889. png_ptr->rowbytes + 1);
  164890. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164891. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164892. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164893. {
  164894. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164895. }
  164896. #endif
  164897. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164898. png_do_read_transformations(png_ptr);
  164899. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164900. if (png_ptr->interlaced &&
  164901. (png_ptr->transformations & PNG_INTERLACE))
  164902. {
  164903. if (png_ptr->pass < 6)
  164904. png_do_read_interlace(png_ptr);
  164905. if (dsp_row != NULL)
  164906. png_combine_row(png_ptr, dsp_row,
  164907. png_pass_dsp_mask[png_ptr->pass]);
  164908. if (row != NULL)
  164909. png_combine_row(png_ptr, row,
  164910. png_pass_mask[png_ptr->pass]);
  164911. }
  164912. else
  164913. #endif
  164914. {
  164915. if (row != NULL)
  164916. png_combine_row(png_ptr, row, 0xff);
  164917. if (dsp_row != NULL)
  164918. png_combine_row(png_ptr, dsp_row, 0xff);
  164919. }
  164920. png_read_finish_row(png_ptr);
  164921. if (png_ptr->read_row_fn != NULL)
  164922. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164923. }
  164924. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164925. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164926. void PNGAPI
  164927. png_read_rows(png_structp png_ptr, png_bytepp row,
  164928. png_bytepp display_row, png_uint_32 num_rows)
  164929. {
  164930. png_uint_32 i;
  164931. png_bytepp rp;
  164932. png_bytepp dp;
  164933. png_debug(1, "in png_read_rows\n");
  164934. if(png_ptr == NULL) return;
  164935. rp = row;
  164936. dp = display_row;
  164937. if (rp != NULL && dp != NULL)
  164938. for (i = 0; i < num_rows; i++)
  164939. {
  164940. png_bytep rptr = *rp++;
  164941. png_bytep dptr = *dp++;
  164942. png_read_row(png_ptr, rptr, dptr);
  164943. }
  164944. else if(rp != NULL)
  164945. for (i = 0; i < num_rows; i++)
  164946. {
  164947. png_bytep rptr = *rp;
  164948. png_read_row(png_ptr, rptr, png_bytep_NULL);
  164949. rp++;
  164950. }
  164951. else if(dp != NULL)
  164952. for (i = 0; i < num_rows; i++)
  164953. {
  164954. png_bytep dptr = *dp;
  164955. png_read_row(png_ptr, png_bytep_NULL, dptr);
  164956. dp++;
  164957. }
  164958. }
  164959. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164960. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164961. void PNGAPI
  164962. png_read_image(png_structp png_ptr, png_bytepp image)
  164963. {
  164964. png_uint_32 i,image_height;
  164965. int pass, j;
  164966. png_bytepp rp;
  164967. png_debug(1, "in png_read_image\n");
  164968. if(png_ptr == NULL) return;
  164969. #ifdef PNG_READ_INTERLACING_SUPPORTED
  164970. pass = png_set_interlace_handling(png_ptr);
  164971. #else
  164972. if (png_ptr->interlaced)
  164973. png_error(png_ptr,
  164974. "Cannot read interlaced image -- interlace handler disabled.");
  164975. pass = 1;
  164976. #endif
  164977. image_height=png_ptr->height;
  164978. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  164979. for (j = 0; j < pass; j++)
  164980. {
  164981. rp = image;
  164982. for (i = 0; i < image_height; i++)
  164983. {
  164984. png_read_row(png_ptr, *rp, png_bytep_NULL);
  164985. rp++;
  164986. }
  164987. }
  164988. }
  164989. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164990. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164991. void PNGAPI
  164992. png_read_end(png_structp png_ptr, png_infop info_ptr)
  164993. {
  164994. png_byte chunk_length[4];
  164995. png_uint_32 length;
  164996. png_debug(1, "in png_read_end\n");
  164997. if(png_ptr == NULL) return;
  164998. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  164999. do
  165000. {
  165001. #ifdef PNG_USE_LOCAL_ARRAYS
  165002. PNG_CONST PNG_IHDR;
  165003. PNG_CONST PNG_IDAT;
  165004. PNG_CONST PNG_IEND;
  165005. PNG_CONST PNG_PLTE;
  165006. #if defined(PNG_READ_bKGD_SUPPORTED)
  165007. PNG_CONST PNG_bKGD;
  165008. #endif
  165009. #if defined(PNG_READ_cHRM_SUPPORTED)
  165010. PNG_CONST PNG_cHRM;
  165011. #endif
  165012. #if defined(PNG_READ_gAMA_SUPPORTED)
  165013. PNG_CONST PNG_gAMA;
  165014. #endif
  165015. #if defined(PNG_READ_hIST_SUPPORTED)
  165016. PNG_CONST PNG_hIST;
  165017. #endif
  165018. #if defined(PNG_READ_iCCP_SUPPORTED)
  165019. PNG_CONST PNG_iCCP;
  165020. #endif
  165021. #if defined(PNG_READ_iTXt_SUPPORTED)
  165022. PNG_CONST PNG_iTXt;
  165023. #endif
  165024. #if defined(PNG_READ_oFFs_SUPPORTED)
  165025. PNG_CONST PNG_oFFs;
  165026. #endif
  165027. #if defined(PNG_READ_pCAL_SUPPORTED)
  165028. PNG_CONST PNG_pCAL;
  165029. #endif
  165030. #if defined(PNG_READ_pHYs_SUPPORTED)
  165031. PNG_CONST PNG_pHYs;
  165032. #endif
  165033. #if defined(PNG_READ_sBIT_SUPPORTED)
  165034. PNG_CONST PNG_sBIT;
  165035. #endif
  165036. #if defined(PNG_READ_sCAL_SUPPORTED)
  165037. PNG_CONST PNG_sCAL;
  165038. #endif
  165039. #if defined(PNG_READ_sPLT_SUPPORTED)
  165040. PNG_CONST PNG_sPLT;
  165041. #endif
  165042. #if defined(PNG_READ_sRGB_SUPPORTED)
  165043. PNG_CONST PNG_sRGB;
  165044. #endif
  165045. #if defined(PNG_READ_tEXt_SUPPORTED)
  165046. PNG_CONST PNG_tEXt;
  165047. #endif
  165048. #if defined(PNG_READ_tIME_SUPPORTED)
  165049. PNG_CONST PNG_tIME;
  165050. #endif
  165051. #if defined(PNG_READ_tRNS_SUPPORTED)
  165052. PNG_CONST PNG_tRNS;
  165053. #endif
  165054. #if defined(PNG_READ_zTXt_SUPPORTED)
  165055. PNG_CONST PNG_zTXt;
  165056. #endif
  165057. #endif /* PNG_USE_LOCAL_ARRAYS */
  165058. png_read_data(png_ptr, chunk_length, 4);
  165059. length = png_get_uint_31(png_ptr,chunk_length);
  165060. png_reset_crc(png_ptr);
  165061. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165062. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165063. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165064. png_handle_IHDR(png_ptr, info_ptr, length);
  165065. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165066. png_handle_IEND(png_ptr, info_ptr, length);
  165067. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165068. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165069. {
  165070. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165071. {
  165072. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165073. png_error(png_ptr, "Too many IDAT's found");
  165074. }
  165075. png_handle_unknown(png_ptr, info_ptr, length);
  165076. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165077. png_ptr->mode |= PNG_HAVE_PLTE;
  165078. }
  165079. #endif
  165080. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165081. {
  165082. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165083. png_error(png_ptr, "Too many IDAT's found");
  165084. png_crc_finish(png_ptr, length);
  165085. }
  165086. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165087. png_handle_PLTE(png_ptr, info_ptr, length);
  165088. #if defined(PNG_READ_bKGD_SUPPORTED)
  165089. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165090. png_handle_bKGD(png_ptr, info_ptr, length);
  165091. #endif
  165092. #if defined(PNG_READ_cHRM_SUPPORTED)
  165093. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165094. png_handle_cHRM(png_ptr, info_ptr, length);
  165095. #endif
  165096. #if defined(PNG_READ_gAMA_SUPPORTED)
  165097. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165098. png_handle_gAMA(png_ptr, info_ptr, length);
  165099. #endif
  165100. #if defined(PNG_READ_hIST_SUPPORTED)
  165101. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165102. png_handle_hIST(png_ptr, info_ptr, length);
  165103. #endif
  165104. #if defined(PNG_READ_oFFs_SUPPORTED)
  165105. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165106. png_handle_oFFs(png_ptr, info_ptr, length);
  165107. #endif
  165108. #if defined(PNG_READ_pCAL_SUPPORTED)
  165109. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165110. png_handle_pCAL(png_ptr, info_ptr, length);
  165111. #endif
  165112. #if defined(PNG_READ_sCAL_SUPPORTED)
  165113. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165114. png_handle_sCAL(png_ptr, info_ptr, length);
  165115. #endif
  165116. #if defined(PNG_READ_pHYs_SUPPORTED)
  165117. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165118. png_handle_pHYs(png_ptr, info_ptr, length);
  165119. #endif
  165120. #if defined(PNG_READ_sBIT_SUPPORTED)
  165121. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165122. png_handle_sBIT(png_ptr, info_ptr, length);
  165123. #endif
  165124. #if defined(PNG_READ_sRGB_SUPPORTED)
  165125. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165126. png_handle_sRGB(png_ptr, info_ptr, length);
  165127. #endif
  165128. #if defined(PNG_READ_iCCP_SUPPORTED)
  165129. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165130. png_handle_iCCP(png_ptr, info_ptr, length);
  165131. #endif
  165132. #if defined(PNG_READ_sPLT_SUPPORTED)
  165133. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165134. png_handle_sPLT(png_ptr, info_ptr, length);
  165135. #endif
  165136. #if defined(PNG_READ_tEXt_SUPPORTED)
  165137. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165138. png_handle_tEXt(png_ptr, info_ptr, length);
  165139. #endif
  165140. #if defined(PNG_READ_tIME_SUPPORTED)
  165141. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165142. png_handle_tIME(png_ptr, info_ptr, length);
  165143. #endif
  165144. #if defined(PNG_READ_tRNS_SUPPORTED)
  165145. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165146. png_handle_tRNS(png_ptr, info_ptr, length);
  165147. #endif
  165148. #if defined(PNG_READ_zTXt_SUPPORTED)
  165149. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165150. png_handle_zTXt(png_ptr, info_ptr, length);
  165151. #endif
  165152. #if defined(PNG_READ_iTXt_SUPPORTED)
  165153. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165154. png_handle_iTXt(png_ptr, info_ptr, length);
  165155. #endif
  165156. else
  165157. png_handle_unknown(png_ptr, info_ptr, length);
  165158. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165159. }
  165160. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165161. void PNGAPI
  165162. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165163. png_infopp end_info_ptr_ptr)
  165164. {
  165165. png_structp png_ptr = NULL;
  165166. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165167. #ifdef PNG_USER_MEM_SUPPORTED
  165168. png_free_ptr free_fn;
  165169. png_voidp mem_ptr;
  165170. #endif
  165171. png_debug(1, "in png_destroy_read_struct\n");
  165172. if (png_ptr_ptr != NULL)
  165173. png_ptr = *png_ptr_ptr;
  165174. if (info_ptr_ptr != NULL)
  165175. info_ptr = *info_ptr_ptr;
  165176. if (end_info_ptr_ptr != NULL)
  165177. end_info_ptr = *end_info_ptr_ptr;
  165178. #ifdef PNG_USER_MEM_SUPPORTED
  165179. free_fn = png_ptr->free_fn;
  165180. mem_ptr = png_ptr->mem_ptr;
  165181. #endif
  165182. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165183. if (info_ptr != NULL)
  165184. {
  165185. #if defined(PNG_TEXT_SUPPORTED)
  165186. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165187. #endif
  165188. #ifdef PNG_USER_MEM_SUPPORTED
  165189. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165190. (png_voidp)mem_ptr);
  165191. #else
  165192. png_destroy_struct((png_voidp)info_ptr);
  165193. #endif
  165194. *info_ptr_ptr = NULL;
  165195. }
  165196. if (end_info_ptr != NULL)
  165197. {
  165198. #if defined(PNG_READ_TEXT_SUPPORTED)
  165199. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165200. #endif
  165201. #ifdef PNG_USER_MEM_SUPPORTED
  165202. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165203. (png_voidp)mem_ptr);
  165204. #else
  165205. png_destroy_struct((png_voidp)end_info_ptr);
  165206. #endif
  165207. *end_info_ptr_ptr = NULL;
  165208. }
  165209. if (png_ptr != NULL)
  165210. {
  165211. #ifdef PNG_USER_MEM_SUPPORTED
  165212. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165213. (png_voidp)mem_ptr);
  165214. #else
  165215. png_destroy_struct((png_voidp)png_ptr);
  165216. #endif
  165217. *png_ptr_ptr = NULL;
  165218. }
  165219. }
  165220. void /* PRIVATE */
  165221. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165222. {
  165223. #ifdef PNG_SETJMP_SUPPORTED
  165224. jmp_buf tmp_jmp;
  165225. #endif
  165226. png_error_ptr error_fn;
  165227. png_error_ptr warning_fn;
  165228. png_voidp error_ptr;
  165229. #ifdef PNG_USER_MEM_SUPPORTED
  165230. png_free_ptr free_fn;
  165231. #endif
  165232. png_debug(1, "in png_read_destroy\n");
  165233. if (info_ptr != NULL)
  165234. png_info_destroy(png_ptr, info_ptr);
  165235. if (end_info_ptr != NULL)
  165236. png_info_destroy(png_ptr, end_info_ptr);
  165237. png_free(png_ptr, png_ptr->zbuf);
  165238. png_free(png_ptr, png_ptr->big_row_buf);
  165239. png_free(png_ptr, png_ptr->prev_row);
  165240. #if defined(PNG_READ_DITHER_SUPPORTED)
  165241. png_free(png_ptr, png_ptr->palette_lookup);
  165242. png_free(png_ptr, png_ptr->dither_index);
  165243. #endif
  165244. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165245. png_free(png_ptr, png_ptr->gamma_table);
  165246. #endif
  165247. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165248. png_free(png_ptr, png_ptr->gamma_from_1);
  165249. png_free(png_ptr, png_ptr->gamma_to_1);
  165250. #endif
  165251. #ifdef PNG_FREE_ME_SUPPORTED
  165252. if (png_ptr->free_me & PNG_FREE_PLTE)
  165253. png_zfree(png_ptr, png_ptr->palette);
  165254. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165255. #else
  165256. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165257. png_zfree(png_ptr, png_ptr->palette);
  165258. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165259. #endif
  165260. #if defined(PNG_tRNS_SUPPORTED) || \
  165261. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165262. #ifdef PNG_FREE_ME_SUPPORTED
  165263. if (png_ptr->free_me & PNG_FREE_TRNS)
  165264. png_free(png_ptr, png_ptr->trans);
  165265. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165266. #else
  165267. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165268. png_free(png_ptr, png_ptr->trans);
  165269. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165270. #endif
  165271. #endif
  165272. #if defined(PNG_READ_hIST_SUPPORTED)
  165273. #ifdef PNG_FREE_ME_SUPPORTED
  165274. if (png_ptr->free_me & PNG_FREE_HIST)
  165275. png_free(png_ptr, png_ptr->hist);
  165276. png_ptr->free_me &= ~PNG_FREE_HIST;
  165277. #else
  165278. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165279. png_free(png_ptr, png_ptr->hist);
  165280. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165281. #endif
  165282. #endif
  165283. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165284. if (png_ptr->gamma_16_table != NULL)
  165285. {
  165286. int i;
  165287. int istop = (1 << (8 - png_ptr->gamma_shift));
  165288. for (i = 0; i < istop; i++)
  165289. {
  165290. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165291. }
  165292. png_free(png_ptr, png_ptr->gamma_16_table);
  165293. }
  165294. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165295. if (png_ptr->gamma_16_from_1 != NULL)
  165296. {
  165297. int i;
  165298. int istop = (1 << (8 - png_ptr->gamma_shift));
  165299. for (i = 0; i < istop; i++)
  165300. {
  165301. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165302. }
  165303. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165304. }
  165305. if (png_ptr->gamma_16_to_1 != NULL)
  165306. {
  165307. int i;
  165308. int istop = (1 << (8 - png_ptr->gamma_shift));
  165309. for (i = 0; i < istop; i++)
  165310. {
  165311. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165312. }
  165313. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165314. }
  165315. #endif
  165316. #endif
  165317. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165318. png_free(png_ptr, png_ptr->time_buffer);
  165319. #endif
  165320. inflateEnd(&png_ptr->zstream);
  165321. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165322. png_free(png_ptr, png_ptr->save_buffer);
  165323. #endif
  165324. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165325. #ifdef PNG_TEXT_SUPPORTED
  165326. png_free(png_ptr, png_ptr->current_text);
  165327. #endif /* PNG_TEXT_SUPPORTED */
  165328. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165329. #ifdef PNG_SETJMP_SUPPORTED
  165330. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165331. #endif
  165332. error_fn = png_ptr->error_fn;
  165333. warning_fn = png_ptr->warning_fn;
  165334. error_ptr = png_ptr->error_ptr;
  165335. #ifdef PNG_USER_MEM_SUPPORTED
  165336. free_fn = png_ptr->free_fn;
  165337. #endif
  165338. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165339. png_ptr->error_fn = error_fn;
  165340. png_ptr->warning_fn = warning_fn;
  165341. png_ptr->error_ptr = error_ptr;
  165342. #ifdef PNG_USER_MEM_SUPPORTED
  165343. png_ptr->free_fn = free_fn;
  165344. #endif
  165345. #ifdef PNG_SETJMP_SUPPORTED
  165346. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165347. #endif
  165348. }
  165349. void PNGAPI
  165350. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165351. {
  165352. if(png_ptr == NULL) return;
  165353. png_ptr->read_row_fn = read_row_fn;
  165354. }
  165355. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165356. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165357. void PNGAPI
  165358. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165359. int transforms,
  165360. voidp params)
  165361. {
  165362. int row;
  165363. if(png_ptr == NULL) return;
  165364. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165365. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165366. png_set_invert_alpha(png_ptr);
  165367. #endif
  165368. png_read_info(png_ptr, info_ptr);
  165369. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165370. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165371. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165372. if (transforms & PNG_TRANSFORM_STRIP_16)
  165373. png_set_strip_16(png_ptr);
  165374. #endif
  165375. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165376. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165377. png_set_strip_alpha(png_ptr);
  165378. #endif
  165379. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165380. if (transforms & PNG_TRANSFORM_PACKING)
  165381. png_set_packing(png_ptr);
  165382. #endif
  165383. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165384. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165385. png_set_packswap(png_ptr);
  165386. #endif
  165387. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165388. if (transforms & PNG_TRANSFORM_EXPAND)
  165389. if ((png_ptr->bit_depth < 8) ||
  165390. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165391. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165392. png_set_expand(png_ptr);
  165393. #endif
  165394. #if defined(PNG_READ_INVERT_SUPPORTED)
  165395. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165396. png_set_invert_mono(png_ptr);
  165397. #endif
  165398. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165399. if ((transforms & PNG_TRANSFORM_SHIFT)
  165400. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165401. {
  165402. png_color_8p sig_bit;
  165403. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165404. png_set_shift(png_ptr, sig_bit);
  165405. }
  165406. #endif
  165407. #if defined(PNG_READ_BGR_SUPPORTED)
  165408. if (transforms & PNG_TRANSFORM_BGR)
  165409. png_set_bgr(png_ptr);
  165410. #endif
  165411. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165412. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165413. png_set_swap_alpha(png_ptr);
  165414. #endif
  165415. #if defined(PNG_READ_SWAP_SUPPORTED)
  165416. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165417. png_set_swap(png_ptr);
  165418. #endif
  165419. png_read_update_info(png_ptr, info_ptr);
  165420. #ifdef PNG_FREE_ME_SUPPORTED
  165421. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165422. #endif
  165423. if(info_ptr->row_pointers == NULL)
  165424. {
  165425. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165426. info_ptr->height * png_sizeof(png_bytep));
  165427. #ifdef PNG_FREE_ME_SUPPORTED
  165428. info_ptr->free_me |= PNG_FREE_ROWS;
  165429. #endif
  165430. for (row = 0; row < (int)info_ptr->height; row++)
  165431. {
  165432. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165433. png_get_rowbytes(png_ptr, info_ptr));
  165434. }
  165435. }
  165436. png_read_image(png_ptr, info_ptr->row_pointers);
  165437. info_ptr->valid |= PNG_INFO_IDAT;
  165438. png_read_end(png_ptr, info_ptr);
  165439. transforms = transforms; /* quiet compiler warnings */
  165440. params = params;
  165441. }
  165442. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165443. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165444. #endif /* PNG_READ_SUPPORTED */
  165445. /*** End of inlined file: pngread.c ***/
  165446. /*** Start of inlined file: pngpread.c ***/
  165447. #define PNG_INTERNAL
  165448. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165449. #define PNG_READ_SIG_MODE 0
  165450. #define PNG_READ_CHUNK_MODE 1
  165451. #define PNG_READ_IDAT_MODE 2
  165452. #define PNG_SKIP_MODE 3
  165453. #define PNG_READ_tEXt_MODE 4
  165454. #define PNG_READ_zTXt_MODE 5
  165455. #define PNG_READ_DONE_MODE 6
  165456. #define PNG_READ_iTXt_MODE 7
  165457. #define PNG_ERROR_MODE 8
  165458. void PNGAPI
  165459. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165460. png_bytep buffer, png_size_t buffer_size)
  165461. {
  165462. if(png_ptr == NULL) return;
  165463. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165464. while (png_ptr->buffer_size)
  165465. {
  165466. png_process_some_data(png_ptr, info_ptr);
  165467. }
  165468. }
  165469. void /* PRIVATE */
  165470. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165471. {
  165472. if(png_ptr == NULL) return;
  165473. switch (png_ptr->process_mode)
  165474. {
  165475. case PNG_READ_SIG_MODE:
  165476. {
  165477. png_push_read_sig(png_ptr, info_ptr);
  165478. break;
  165479. }
  165480. case PNG_READ_CHUNK_MODE:
  165481. {
  165482. png_push_read_chunk(png_ptr, info_ptr);
  165483. break;
  165484. }
  165485. case PNG_READ_IDAT_MODE:
  165486. {
  165487. png_push_read_IDAT(png_ptr);
  165488. break;
  165489. }
  165490. #if defined(PNG_READ_tEXt_SUPPORTED)
  165491. case PNG_READ_tEXt_MODE:
  165492. {
  165493. png_push_read_tEXt(png_ptr, info_ptr);
  165494. break;
  165495. }
  165496. #endif
  165497. #if defined(PNG_READ_zTXt_SUPPORTED)
  165498. case PNG_READ_zTXt_MODE:
  165499. {
  165500. png_push_read_zTXt(png_ptr, info_ptr);
  165501. break;
  165502. }
  165503. #endif
  165504. #if defined(PNG_READ_iTXt_SUPPORTED)
  165505. case PNG_READ_iTXt_MODE:
  165506. {
  165507. png_push_read_iTXt(png_ptr, info_ptr);
  165508. break;
  165509. }
  165510. #endif
  165511. case PNG_SKIP_MODE:
  165512. {
  165513. png_push_crc_finish(png_ptr);
  165514. break;
  165515. }
  165516. default:
  165517. {
  165518. png_ptr->buffer_size = 0;
  165519. break;
  165520. }
  165521. }
  165522. }
  165523. void /* PRIVATE */
  165524. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165525. {
  165526. png_size_t num_checked = png_ptr->sig_bytes,
  165527. num_to_check = 8 - num_checked;
  165528. if (png_ptr->buffer_size < num_to_check)
  165529. {
  165530. num_to_check = png_ptr->buffer_size;
  165531. }
  165532. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165533. num_to_check);
  165534. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165535. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165536. {
  165537. if (num_checked < 4 &&
  165538. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165539. png_error(png_ptr, "Not a PNG file");
  165540. else
  165541. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165542. }
  165543. else
  165544. {
  165545. if (png_ptr->sig_bytes >= 8)
  165546. {
  165547. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165548. }
  165549. }
  165550. }
  165551. void /* PRIVATE */
  165552. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165553. {
  165554. #ifdef PNG_USE_LOCAL_ARRAYS
  165555. PNG_CONST PNG_IHDR;
  165556. PNG_CONST PNG_IDAT;
  165557. PNG_CONST PNG_IEND;
  165558. PNG_CONST PNG_PLTE;
  165559. #if defined(PNG_READ_bKGD_SUPPORTED)
  165560. PNG_CONST PNG_bKGD;
  165561. #endif
  165562. #if defined(PNG_READ_cHRM_SUPPORTED)
  165563. PNG_CONST PNG_cHRM;
  165564. #endif
  165565. #if defined(PNG_READ_gAMA_SUPPORTED)
  165566. PNG_CONST PNG_gAMA;
  165567. #endif
  165568. #if defined(PNG_READ_hIST_SUPPORTED)
  165569. PNG_CONST PNG_hIST;
  165570. #endif
  165571. #if defined(PNG_READ_iCCP_SUPPORTED)
  165572. PNG_CONST PNG_iCCP;
  165573. #endif
  165574. #if defined(PNG_READ_iTXt_SUPPORTED)
  165575. PNG_CONST PNG_iTXt;
  165576. #endif
  165577. #if defined(PNG_READ_oFFs_SUPPORTED)
  165578. PNG_CONST PNG_oFFs;
  165579. #endif
  165580. #if defined(PNG_READ_pCAL_SUPPORTED)
  165581. PNG_CONST PNG_pCAL;
  165582. #endif
  165583. #if defined(PNG_READ_pHYs_SUPPORTED)
  165584. PNG_CONST PNG_pHYs;
  165585. #endif
  165586. #if defined(PNG_READ_sBIT_SUPPORTED)
  165587. PNG_CONST PNG_sBIT;
  165588. #endif
  165589. #if defined(PNG_READ_sCAL_SUPPORTED)
  165590. PNG_CONST PNG_sCAL;
  165591. #endif
  165592. #if defined(PNG_READ_sRGB_SUPPORTED)
  165593. PNG_CONST PNG_sRGB;
  165594. #endif
  165595. #if defined(PNG_READ_sPLT_SUPPORTED)
  165596. PNG_CONST PNG_sPLT;
  165597. #endif
  165598. #if defined(PNG_READ_tEXt_SUPPORTED)
  165599. PNG_CONST PNG_tEXt;
  165600. #endif
  165601. #if defined(PNG_READ_tIME_SUPPORTED)
  165602. PNG_CONST PNG_tIME;
  165603. #endif
  165604. #if defined(PNG_READ_tRNS_SUPPORTED)
  165605. PNG_CONST PNG_tRNS;
  165606. #endif
  165607. #if defined(PNG_READ_zTXt_SUPPORTED)
  165608. PNG_CONST PNG_zTXt;
  165609. #endif
  165610. #endif /* PNG_USE_LOCAL_ARRAYS */
  165611. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165612. {
  165613. png_byte chunk_length[4];
  165614. if (png_ptr->buffer_size < 8)
  165615. {
  165616. png_push_save_buffer(png_ptr);
  165617. return;
  165618. }
  165619. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165620. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165621. png_reset_crc(png_ptr);
  165622. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165623. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165624. }
  165625. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165626. if(png_ptr->mode & PNG_AFTER_IDAT)
  165627. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165628. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165629. {
  165630. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165631. {
  165632. png_push_save_buffer(png_ptr);
  165633. return;
  165634. }
  165635. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165636. }
  165637. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165638. {
  165639. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165640. {
  165641. png_push_save_buffer(png_ptr);
  165642. return;
  165643. }
  165644. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165645. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165646. png_push_have_end(png_ptr, info_ptr);
  165647. }
  165648. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165649. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165650. {
  165651. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165652. {
  165653. png_push_save_buffer(png_ptr);
  165654. return;
  165655. }
  165656. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165657. png_ptr->mode |= PNG_HAVE_IDAT;
  165658. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165659. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165660. png_ptr->mode |= PNG_HAVE_PLTE;
  165661. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165662. {
  165663. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165664. png_error(png_ptr, "Missing IHDR before IDAT");
  165665. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165666. !(png_ptr->mode & PNG_HAVE_PLTE))
  165667. png_error(png_ptr, "Missing PLTE before IDAT");
  165668. }
  165669. }
  165670. #endif
  165671. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165672. {
  165673. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165674. {
  165675. png_push_save_buffer(png_ptr);
  165676. return;
  165677. }
  165678. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165679. }
  165680. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165681. {
  165682. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165683. png_error(png_ptr, "Missing IHDR before IDAT");
  165684. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165685. !(png_ptr->mode & PNG_HAVE_PLTE))
  165686. png_error(png_ptr, "Missing PLTE before IDAT");
  165687. if (png_ptr->mode & PNG_HAVE_IDAT)
  165688. {
  165689. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165690. if (png_ptr->push_length == 0)
  165691. return;
  165692. if (png_ptr->mode & PNG_AFTER_IDAT)
  165693. png_error(png_ptr, "Too many IDAT's found");
  165694. }
  165695. png_ptr->idat_size = png_ptr->push_length;
  165696. png_ptr->mode |= PNG_HAVE_IDAT;
  165697. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165698. png_push_have_info(png_ptr, info_ptr);
  165699. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165700. png_ptr->zstream.next_out = png_ptr->row_buf;
  165701. return;
  165702. }
  165703. #if defined(PNG_READ_gAMA_SUPPORTED)
  165704. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165705. {
  165706. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165707. {
  165708. png_push_save_buffer(png_ptr);
  165709. return;
  165710. }
  165711. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165712. }
  165713. #endif
  165714. #if defined(PNG_READ_sBIT_SUPPORTED)
  165715. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165716. {
  165717. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165718. {
  165719. png_push_save_buffer(png_ptr);
  165720. return;
  165721. }
  165722. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165723. }
  165724. #endif
  165725. #if defined(PNG_READ_cHRM_SUPPORTED)
  165726. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165727. {
  165728. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165729. {
  165730. png_push_save_buffer(png_ptr);
  165731. return;
  165732. }
  165733. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165734. }
  165735. #endif
  165736. #if defined(PNG_READ_sRGB_SUPPORTED)
  165737. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165738. {
  165739. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165740. {
  165741. png_push_save_buffer(png_ptr);
  165742. return;
  165743. }
  165744. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165745. }
  165746. #endif
  165747. #if defined(PNG_READ_iCCP_SUPPORTED)
  165748. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165749. {
  165750. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165751. {
  165752. png_push_save_buffer(png_ptr);
  165753. return;
  165754. }
  165755. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165756. }
  165757. #endif
  165758. #if defined(PNG_READ_sPLT_SUPPORTED)
  165759. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165760. {
  165761. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165762. {
  165763. png_push_save_buffer(png_ptr);
  165764. return;
  165765. }
  165766. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165767. }
  165768. #endif
  165769. #if defined(PNG_READ_tRNS_SUPPORTED)
  165770. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165771. {
  165772. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165773. {
  165774. png_push_save_buffer(png_ptr);
  165775. return;
  165776. }
  165777. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165778. }
  165779. #endif
  165780. #if defined(PNG_READ_bKGD_SUPPORTED)
  165781. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165782. {
  165783. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165784. {
  165785. png_push_save_buffer(png_ptr);
  165786. return;
  165787. }
  165788. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165789. }
  165790. #endif
  165791. #if defined(PNG_READ_hIST_SUPPORTED)
  165792. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165793. {
  165794. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165795. {
  165796. png_push_save_buffer(png_ptr);
  165797. return;
  165798. }
  165799. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165800. }
  165801. #endif
  165802. #if defined(PNG_READ_pHYs_SUPPORTED)
  165803. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165804. {
  165805. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165806. {
  165807. png_push_save_buffer(png_ptr);
  165808. return;
  165809. }
  165810. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165811. }
  165812. #endif
  165813. #if defined(PNG_READ_oFFs_SUPPORTED)
  165814. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165815. {
  165816. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165817. {
  165818. png_push_save_buffer(png_ptr);
  165819. return;
  165820. }
  165821. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165822. }
  165823. #endif
  165824. #if defined(PNG_READ_pCAL_SUPPORTED)
  165825. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165826. {
  165827. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165828. {
  165829. png_push_save_buffer(png_ptr);
  165830. return;
  165831. }
  165832. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165833. }
  165834. #endif
  165835. #if defined(PNG_READ_sCAL_SUPPORTED)
  165836. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165837. {
  165838. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165839. {
  165840. png_push_save_buffer(png_ptr);
  165841. return;
  165842. }
  165843. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165844. }
  165845. #endif
  165846. #if defined(PNG_READ_tIME_SUPPORTED)
  165847. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165848. {
  165849. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165850. {
  165851. png_push_save_buffer(png_ptr);
  165852. return;
  165853. }
  165854. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165855. }
  165856. #endif
  165857. #if defined(PNG_READ_tEXt_SUPPORTED)
  165858. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165859. {
  165860. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165861. {
  165862. png_push_save_buffer(png_ptr);
  165863. return;
  165864. }
  165865. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165866. }
  165867. #endif
  165868. #if defined(PNG_READ_zTXt_SUPPORTED)
  165869. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165870. {
  165871. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165872. {
  165873. png_push_save_buffer(png_ptr);
  165874. return;
  165875. }
  165876. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165877. }
  165878. #endif
  165879. #if defined(PNG_READ_iTXt_SUPPORTED)
  165880. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165881. {
  165882. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165883. {
  165884. png_push_save_buffer(png_ptr);
  165885. return;
  165886. }
  165887. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165888. }
  165889. #endif
  165890. else
  165891. {
  165892. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165893. {
  165894. png_push_save_buffer(png_ptr);
  165895. return;
  165896. }
  165897. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165898. }
  165899. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165900. }
  165901. void /* PRIVATE */
  165902. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165903. {
  165904. png_ptr->process_mode = PNG_SKIP_MODE;
  165905. png_ptr->skip_length = skip;
  165906. }
  165907. void /* PRIVATE */
  165908. png_push_crc_finish(png_structp png_ptr)
  165909. {
  165910. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165911. {
  165912. png_size_t save_size;
  165913. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165914. save_size = (png_size_t)png_ptr->skip_length;
  165915. else
  165916. save_size = png_ptr->save_buffer_size;
  165917. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165918. png_ptr->skip_length -= save_size;
  165919. png_ptr->buffer_size -= save_size;
  165920. png_ptr->save_buffer_size -= save_size;
  165921. png_ptr->save_buffer_ptr += save_size;
  165922. }
  165923. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165924. {
  165925. png_size_t save_size;
  165926. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165927. save_size = (png_size_t)png_ptr->skip_length;
  165928. else
  165929. save_size = png_ptr->current_buffer_size;
  165930. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165931. png_ptr->skip_length -= save_size;
  165932. png_ptr->buffer_size -= save_size;
  165933. png_ptr->current_buffer_size -= save_size;
  165934. png_ptr->current_buffer_ptr += save_size;
  165935. }
  165936. if (!png_ptr->skip_length)
  165937. {
  165938. if (png_ptr->buffer_size < 4)
  165939. {
  165940. png_push_save_buffer(png_ptr);
  165941. return;
  165942. }
  165943. png_crc_finish(png_ptr, 0);
  165944. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165945. }
  165946. }
  165947. void PNGAPI
  165948. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  165949. {
  165950. png_bytep ptr;
  165951. if(png_ptr == NULL) return;
  165952. ptr = buffer;
  165953. if (png_ptr->save_buffer_size)
  165954. {
  165955. png_size_t save_size;
  165956. if (length < png_ptr->save_buffer_size)
  165957. save_size = length;
  165958. else
  165959. save_size = png_ptr->save_buffer_size;
  165960. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  165961. length -= save_size;
  165962. ptr += save_size;
  165963. png_ptr->buffer_size -= save_size;
  165964. png_ptr->save_buffer_size -= save_size;
  165965. png_ptr->save_buffer_ptr += save_size;
  165966. }
  165967. if (length && png_ptr->current_buffer_size)
  165968. {
  165969. png_size_t save_size;
  165970. if (length < png_ptr->current_buffer_size)
  165971. save_size = length;
  165972. else
  165973. save_size = png_ptr->current_buffer_size;
  165974. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  165975. png_ptr->buffer_size -= save_size;
  165976. png_ptr->current_buffer_size -= save_size;
  165977. png_ptr->current_buffer_ptr += save_size;
  165978. }
  165979. }
  165980. void /* PRIVATE */
  165981. png_push_save_buffer(png_structp png_ptr)
  165982. {
  165983. if (png_ptr->save_buffer_size)
  165984. {
  165985. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  165986. {
  165987. png_size_t i,istop;
  165988. png_bytep sp;
  165989. png_bytep dp;
  165990. istop = png_ptr->save_buffer_size;
  165991. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  165992. i < istop; i++, sp++, dp++)
  165993. {
  165994. *dp = *sp;
  165995. }
  165996. }
  165997. }
  165998. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  165999. png_ptr->save_buffer_max)
  166000. {
  166001. png_size_t new_max;
  166002. png_bytep old_buffer;
  166003. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166004. (png_ptr->current_buffer_size + 256))
  166005. {
  166006. png_error(png_ptr, "Potential overflow of save_buffer");
  166007. }
  166008. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166009. old_buffer = png_ptr->save_buffer;
  166010. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166011. (png_uint_32)new_max);
  166012. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166013. png_free(png_ptr, old_buffer);
  166014. png_ptr->save_buffer_max = new_max;
  166015. }
  166016. if (png_ptr->current_buffer_size)
  166017. {
  166018. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166019. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166020. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166021. png_ptr->current_buffer_size = 0;
  166022. }
  166023. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166024. png_ptr->buffer_size = 0;
  166025. }
  166026. void /* PRIVATE */
  166027. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166028. png_size_t buffer_length)
  166029. {
  166030. png_ptr->current_buffer = buffer;
  166031. png_ptr->current_buffer_size = buffer_length;
  166032. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166033. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166034. }
  166035. void /* PRIVATE */
  166036. png_push_read_IDAT(png_structp png_ptr)
  166037. {
  166038. #ifdef PNG_USE_LOCAL_ARRAYS
  166039. PNG_CONST PNG_IDAT;
  166040. #endif
  166041. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166042. {
  166043. png_byte chunk_length[4];
  166044. if (png_ptr->buffer_size < 8)
  166045. {
  166046. png_push_save_buffer(png_ptr);
  166047. return;
  166048. }
  166049. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166050. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166051. png_reset_crc(png_ptr);
  166052. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166053. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166054. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166055. {
  166056. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166057. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166058. png_error(png_ptr, "Not enough compressed data");
  166059. return;
  166060. }
  166061. png_ptr->idat_size = png_ptr->push_length;
  166062. }
  166063. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166064. {
  166065. png_size_t save_size;
  166066. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166067. {
  166068. save_size = (png_size_t)png_ptr->idat_size;
  166069. if((png_uint_32)save_size != png_ptr->idat_size)
  166070. png_error(png_ptr, "save_size overflowed in pngpread");
  166071. }
  166072. else
  166073. save_size = png_ptr->save_buffer_size;
  166074. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166075. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166076. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166077. png_ptr->idat_size -= save_size;
  166078. png_ptr->buffer_size -= save_size;
  166079. png_ptr->save_buffer_size -= save_size;
  166080. png_ptr->save_buffer_ptr += save_size;
  166081. }
  166082. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166083. {
  166084. png_size_t save_size;
  166085. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166086. {
  166087. save_size = (png_size_t)png_ptr->idat_size;
  166088. if((png_uint_32)save_size != png_ptr->idat_size)
  166089. png_error(png_ptr, "save_size overflowed in pngpread");
  166090. }
  166091. else
  166092. save_size = png_ptr->current_buffer_size;
  166093. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166094. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166095. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166096. png_ptr->idat_size -= save_size;
  166097. png_ptr->buffer_size -= save_size;
  166098. png_ptr->current_buffer_size -= save_size;
  166099. png_ptr->current_buffer_ptr += save_size;
  166100. }
  166101. if (!png_ptr->idat_size)
  166102. {
  166103. if (png_ptr->buffer_size < 4)
  166104. {
  166105. png_push_save_buffer(png_ptr);
  166106. return;
  166107. }
  166108. png_crc_finish(png_ptr, 0);
  166109. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166110. png_ptr->mode |= PNG_AFTER_IDAT;
  166111. }
  166112. }
  166113. void /* PRIVATE */
  166114. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166115. png_size_t buffer_length)
  166116. {
  166117. int ret;
  166118. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166119. png_error(png_ptr, "Extra compression data");
  166120. png_ptr->zstream.next_in = buffer;
  166121. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166122. for(;;)
  166123. {
  166124. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166125. if (ret != Z_OK)
  166126. {
  166127. if (ret == Z_STREAM_END)
  166128. {
  166129. if (png_ptr->zstream.avail_in)
  166130. png_error(png_ptr, "Extra compressed data");
  166131. if (!(png_ptr->zstream.avail_out))
  166132. {
  166133. png_push_process_row(png_ptr);
  166134. }
  166135. png_ptr->mode |= PNG_AFTER_IDAT;
  166136. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166137. break;
  166138. }
  166139. else if (ret == Z_BUF_ERROR)
  166140. break;
  166141. else
  166142. png_error(png_ptr, "Decompression Error");
  166143. }
  166144. if (!(png_ptr->zstream.avail_out))
  166145. {
  166146. if ((
  166147. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166148. png_ptr->interlaced && png_ptr->pass > 6) ||
  166149. (!png_ptr->interlaced &&
  166150. #endif
  166151. png_ptr->row_number == png_ptr->num_rows))
  166152. {
  166153. if (png_ptr->zstream.avail_in)
  166154. {
  166155. png_warning(png_ptr, "Too much data in IDAT chunks");
  166156. }
  166157. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166158. break;
  166159. }
  166160. png_push_process_row(png_ptr);
  166161. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166162. png_ptr->zstream.next_out = png_ptr->row_buf;
  166163. }
  166164. else
  166165. break;
  166166. }
  166167. }
  166168. void /* PRIVATE */
  166169. png_push_process_row(png_structp png_ptr)
  166170. {
  166171. png_ptr->row_info.color_type = png_ptr->color_type;
  166172. png_ptr->row_info.width = png_ptr->iwidth;
  166173. png_ptr->row_info.channels = png_ptr->channels;
  166174. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166175. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166176. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166177. png_ptr->row_info.width);
  166178. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166179. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166180. (int)(png_ptr->row_buf[0]));
  166181. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166182. png_ptr->rowbytes + 1);
  166183. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166184. png_do_read_transformations(png_ptr);
  166185. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166186. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166187. {
  166188. if (png_ptr->pass < 6)
  166189. png_do_read_interlace(png_ptr);
  166190. switch (png_ptr->pass)
  166191. {
  166192. case 0:
  166193. {
  166194. int i;
  166195. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166196. {
  166197. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166198. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166199. }
  166200. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166201. {
  166202. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166203. {
  166204. png_push_have_row(png_ptr, png_bytep_NULL);
  166205. png_read_push_finish_row(png_ptr);
  166206. }
  166207. }
  166208. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166209. {
  166210. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166211. {
  166212. png_push_have_row(png_ptr, png_bytep_NULL);
  166213. png_read_push_finish_row(png_ptr);
  166214. }
  166215. }
  166216. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166217. {
  166218. png_push_have_row(png_ptr, png_bytep_NULL);
  166219. png_read_push_finish_row(png_ptr);
  166220. }
  166221. break;
  166222. }
  166223. case 1:
  166224. {
  166225. int i;
  166226. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166227. {
  166228. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166229. png_read_push_finish_row(png_ptr);
  166230. }
  166231. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166232. {
  166233. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166234. {
  166235. png_push_have_row(png_ptr, png_bytep_NULL);
  166236. png_read_push_finish_row(png_ptr);
  166237. }
  166238. }
  166239. break;
  166240. }
  166241. case 2:
  166242. {
  166243. int i;
  166244. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166245. {
  166246. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166247. png_read_push_finish_row(png_ptr);
  166248. }
  166249. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166250. {
  166251. png_push_have_row(png_ptr, png_bytep_NULL);
  166252. png_read_push_finish_row(png_ptr);
  166253. }
  166254. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166255. {
  166256. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166257. {
  166258. png_push_have_row(png_ptr, png_bytep_NULL);
  166259. png_read_push_finish_row(png_ptr);
  166260. }
  166261. }
  166262. break;
  166263. }
  166264. case 3:
  166265. {
  166266. int i;
  166267. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166268. {
  166269. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166270. png_read_push_finish_row(png_ptr);
  166271. }
  166272. if (png_ptr->pass == 4) /* skip top two generated rows */
  166273. {
  166274. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166275. {
  166276. png_push_have_row(png_ptr, png_bytep_NULL);
  166277. png_read_push_finish_row(png_ptr);
  166278. }
  166279. }
  166280. break;
  166281. }
  166282. case 4:
  166283. {
  166284. int i;
  166285. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166286. {
  166287. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166288. png_read_push_finish_row(png_ptr);
  166289. }
  166290. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166291. {
  166292. png_push_have_row(png_ptr, png_bytep_NULL);
  166293. png_read_push_finish_row(png_ptr);
  166294. }
  166295. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166296. {
  166297. png_push_have_row(png_ptr, png_bytep_NULL);
  166298. png_read_push_finish_row(png_ptr);
  166299. }
  166300. break;
  166301. }
  166302. case 5:
  166303. {
  166304. int i;
  166305. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166306. {
  166307. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166308. png_read_push_finish_row(png_ptr);
  166309. }
  166310. if (png_ptr->pass == 6) /* skip top generated row */
  166311. {
  166312. png_push_have_row(png_ptr, png_bytep_NULL);
  166313. png_read_push_finish_row(png_ptr);
  166314. }
  166315. break;
  166316. }
  166317. case 6:
  166318. {
  166319. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166320. png_read_push_finish_row(png_ptr);
  166321. if (png_ptr->pass != 6)
  166322. break;
  166323. png_push_have_row(png_ptr, png_bytep_NULL);
  166324. png_read_push_finish_row(png_ptr);
  166325. }
  166326. }
  166327. }
  166328. else
  166329. #endif
  166330. {
  166331. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166332. png_read_push_finish_row(png_ptr);
  166333. }
  166334. }
  166335. void /* PRIVATE */
  166336. png_read_push_finish_row(png_structp png_ptr)
  166337. {
  166338. #ifdef PNG_USE_LOCAL_ARRAYS
  166339. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166340. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166341. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166342. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166343. #endif
  166344. png_ptr->row_number++;
  166345. if (png_ptr->row_number < png_ptr->num_rows)
  166346. return;
  166347. if (png_ptr->interlaced)
  166348. {
  166349. png_ptr->row_number = 0;
  166350. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166351. png_ptr->rowbytes + 1);
  166352. do
  166353. {
  166354. png_ptr->pass++;
  166355. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166356. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166357. (png_ptr->pass == 5 && png_ptr->width < 2))
  166358. png_ptr->pass++;
  166359. if (png_ptr->pass > 7)
  166360. png_ptr->pass--;
  166361. if (png_ptr->pass >= 7)
  166362. break;
  166363. png_ptr->iwidth = (png_ptr->width +
  166364. png_pass_inc[png_ptr->pass] - 1 -
  166365. png_pass_start[png_ptr->pass]) /
  166366. png_pass_inc[png_ptr->pass];
  166367. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166368. png_ptr->iwidth) + 1;
  166369. if (png_ptr->transformations & PNG_INTERLACE)
  166370. break;
  166371. png_ptr->num_rows = (png_ptr->height +
  166372. png_pass_yinc[png_ptr->pass] - 1 -
  166373. png_pass_ystart[png_ptr->pass]) /
  166374. png_pass_yinc[png_ptr->pass];
  166375. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166376. }
  166377. }
  166378. #if defined(PNG_READ_tEXt_SUPPORTED)
  166379. void /* PRIVATE */
  166380. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166381. length)
  166382. {
  166383. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166384. {
  166385. png_error(png_ptr, "Out of place tEXt");
  166386. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166387. }
  166388. #ifdef PNG_MAX_MALLOC_64K
  166389. png_ptr->skip_length = 0; /* This may not be necessary */
  166390. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166391. {
  166392. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166393. png_ptr->skip_length = length - (png_uint_32)65535L;
  166394. length = (png_uint_32)65535L;
  166395. }
  166396. #endif
  166397. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166398. (png_uint_32)(length+1));
  166399. png_ptr->current_text[length] = '\0';
  166400. png_ptr->current_text_ptr = png_ptr->current_text;
  166401. png_ptr->current_text_size = (png_size_t)length;
  166402. png_ptr->current_text_left = (png_size_t)length;
  166403. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166404. }
  166405. void /* PRIVATE */
  166406. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166407. {
  166408. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166409. {
  166410. png_size_t text_size;
  166411. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166412. text_size = png_ptr->buffer_size;
  166413. else
  166414. text_size = png_ptr->current_text_left;
  166415. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166416. png_ptr->current_text_left -= text_size;
  166417. png_ptr->current_text_ptr += text_size;
  166418. }
  166419. if (!(png_ptr->current_text_left))
  166420. {
  166421. png_textp text_ptr;
  166422. png_charp text;
  166423. png_charp key;
  166424. int ret;
  166425. if (png_ptr->buffer_size < 4)
  166426. {
  166427. png_push_save_buffer(png_ptr);
  166428. return;
  166429. }
  166430. png_push_crc_finish(png_ptr);
  166431. #if defined(PNG_MAX_MALLOC_64K)
  166432. if (png_ptr->skip_length)
  166433. return;
  166434. #endif
  166435. key = png_ptr->current_text;
  166436. for (text = key; *text; text++)
  166437. ;
  166438. if (text < key + png_ptr->current_text_size)
  166439. text++;
  166440. text_ptr = (png_textp)png_malloc(png_ptr,
  166441. (png_uint_32)png_sizeof(png_text));
  166442. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166443. text_ptr->key = key;
  166444. #ifdef PNG_iTXt_SUPPORTED
  166445. text_ptr->lang = NULL;
  166446. text_ptr->lang_key = NULL;
  166447. #endif
  166448. text_ptr->text = text;
  166449. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166450. png_free(png_ptr, key);
  166451. png_free(png_ptr, text_ptr);
  166452. png_ptr->current_text = NULL;
  166453. if (ret)
  166454. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166455. }
  166456. }
  166457. #endif
  166458. #if defined(PNG_READ_zTXt_SUPPORTED)
  166459. void /* PRIVATE */
  166460. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166461. length)
  166462. {
  166463. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166464. {
  166465. png_error(png_ptr, "Out of place zTXt");
  166466. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166467. }
  166468. #ifdef PNG_MAX_MALLOC_64K
  166469. if (length > (png_uint_32)65535L)
  166470. {
  166471. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166472. png_push_crc_skip(png_ptr, length);
  166473. return;
  166474. }
  166475. #endif
  166476. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166477. (png_uint_32)(length+1));
  166478. png_ptr->current_text[length] = '\0';
  166479. png_ptr->current_text_ptr = png_ptr->current_text;
  166480. png_ptr->current_text_size = (png_size_t)length;
  166481. png_ptr->current_text_left = (png_size_t)length;
  166482. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166483. }
  166484. void /* PRIVATE */
  166485. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166486. {
  166487. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166488. {
  166489. png_size_t text_size;
  166490. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166491. text_size = png_ptr->buffer_size;
  166492. else
  166493. text_size = png_ptr->current_text_left;
  166494. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166495. png_ptr->current_text_left -= text_size;
  166496. png_ptr->current_text_ptr += text_size;
  166497. }
  166498. if (!(png_ptr->current_text_left))
  166499. {
  166500. png_textp text_ptr;
  166501. png_charp text;
  166502. png_charp key;
  166503. int ret;
  166504. png_size_t text_size, key_size;
  166505. if (png_ptr->buffer_size < 4)
  166506. {
  166507. png_push_save_buffer(png_ptr);
  166508. return;
  166509. }
  166510. png_push_crc_finish(png_ptr);
  166511. key = png_ptr->current_text;
  166512. for (text = key; *text; text++)
  166513. ;
  166514. if (text >= key + png_ptr->current_text_size)
  166515. {
  166516. png_ptr->current_text = NULL;
  166517. png_free(png_ptr, key);
  166518. return;
  166519. }
  166520. text++;
  166521. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166522. {
  166523. png_ptr->current_text = NULL;
  166524. png_free(png_ptr, key);
  166525. return;
  166526. }
  166527. text++;
  166528. png_ptr->zstream.next_in = (png_bytep )text;
  166529. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166530. (text - key));
  166531. png_ptr->zstream.next_out = png_ptr->zbuf;
  166532. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166533. key_size = text - key;
  166534. text_size = 0;
  166535. text = NULL;
  166536. ret = Z_STREAM_END;
  166537. while (png_ptr->zstream.avail_in)
  166538. {
  166539. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166540. if (ret != Z_OK && ret != Z_STREAM_END)
  166541. {
  166542. inflateReset(&png_ptr->zstream);
  166543. png_ptr->zstream.avail_in = 0;
  166544. png_ptr->current_text = NULL;
  166545. png_free(png_ptr, key);
  166546. png_free(png_ptr, text);
  166547. return;
  166548. }
  166549. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166550. {
  166551. if (text == NULL)
  166552. {
  166553. text = (png_charp)png_malloc(png_ptr,
  166554. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166555. + key_size + 1));
  166556. png_memcpy(text + key_size, png_ptr->zbuf,
  166557. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166558. png_memcpy(text, key, key_size);
  166559. text_size = key_size + png_ptr->zbuf_size -
  166560. png_ptr->zstream.avail_out;
  166561. *(text + text_size) = '\0';
  166562. }
  166563. else
  166564. {
  166565. png_charp tmp;
  166566. tmp = text;
  166567. text = (png_charp)png_malloc(png_ptr, text_size +
  166568. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166569. + 1));
  166570. png_memcpy(text, tmp, text_size);
  166571. png_free(png_ptr, tmp);
  166572. png_memcpy(text + text_size, png_ptr->zbuf,
  166573. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166574. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166575. *(text + text_size) = '\0';
  166576. }
  166577. if (ret != Z_STREAM_END)
  166578. {
  166579. png_ptr->zstream.next_out = png_ptr->zbuf;
  166580. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166581. }
  166582. }
  166583. else
  166584. {
  166585. break;
  166586. }
  166587. if (ret == Z_STREAM_END)
  166588. break;
  166589. }
  166590. inflateReset(&png_ptr->zstream);
  166591. png_ptr->zstream.avail_in = 0;
  166592. if (ret != Z_STREAM_END)
  166593. {
  166594. png_ptr->current_text = NULL;
  166595. png_free(png_ptr, key);
  166596. png_free(png_ptr, text);
  166597. return;
  166598. }
  166599. png_ptr->current_text = NULL;
  166600. png_free(png_ptr, key);
  166601. key = text;
  166602. text += key_size;
  166603. text_ptr = (png_textp)png_malloc(png_ptr,
  166604. (png_uint_32)png_sizeof(png_text));
  166605. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166606. text_ptr->key = key;
  166607. #ifdef PNG_iTXt_SUPPORTED
  166608. text_ptr->lang = NULL;
  166609. text_ptr->lang_key = NULL;
  166610. #endif
  166611. text_ptr->text = text;
  166612. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166613. png_free(png_ptr, key);
  166614. png_free(png_ptr, text_ptr);
  166615. if (ret)
  166616. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166617. }
  166618. }
  166619. #endif
  166620. #if defined(PNG_READ_iTXt_SUPPORTED)
  166621. void /* PRIVATE */
  166622. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166623. length)
  166624. {
  166625. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166626. {
  166627. png_error(png_ptr, "Out of place iTXt");
  166628. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166629. }
  166630. #ifdef PNG_MAX_MALLOC_64K
  166631. png_ptr->skip_length = 0; /* This may not be necessary */
  166632. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166633. {
  166634. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166635. png_ptr->skip_length = length - (png_uint_32)65535L;
  166636. length = (png_uint_32)65535L;
  166637. }
  166638. #endif
  166639. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166640. (png_uint_32)(length+1));
  166641. png_ptr->current_text[length] = '\0';
  166642. png_ptr->current_text_ptr = png_ptr->current_text;
  166643. png_ptr->current_text_size = (png_size_t)length;
  166644. png_ptr->current_text_left = (png_size_t)length;
  166645. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166646. }
  166647. void /* PRIVATE */
  166648. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166649. {
  166650. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166651. {
  166652. png_size_t text_size;
  166653. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166654. text_size = png_ptr->buffer_size;
  166655. else
  166656. text_size = png_ptr->current_text_left;
  166657. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166658. png_ptr->current_text_left -= text_size;
  166659. png_ptr->current_text_ptr += text_size;
  166660. }
  166661. if (!(png_ptr->current_text_left))
  166662. {
  166663. png_textp text_ptr;
  166664. png_charp key;
  166665. int comp_flag;
  166666. png_charp lang;
  166667. png_charp lang_key;
  166668. png_charp text;
  166669. int ret;
  166670. if (png_ptr->buffer_size < 4)
  166671. {
  166672. png_push_save_buffer(png_ptr);
  166673. return;
  166674. }
  166675. png_push_crc_finish(png_ptr);
  166676. #if defined(PNG_MAX_MALLOC_64K)
  166677. if (png_ptr->skip_length)
  166678. return;
  166679. #endif
  166680. key = png_ptr->current_text;
  166681. for (lang = key; *lang; lang++)
  166682. ;
  166683. if (lang < key + png_ptr->current_text_size - 3)
  166684. lang++;
  166685. comp_flag = *lang++;
  166686. lang++; /* skip comp_type, always zero */
  166687. for (lang_key = lang; *lang_key; lang_key++)
  166688. ;
  166689. lang_key++; /* skip NUL separator */
  166690. text=lang_key;
  166691. if (lang_key < key + png_ptr->current_text_size - 1)
  166692. {
  166693. for (; *text; text++)
  166694. ;
  166695. }
  166696. if (text < key + png_ptr->current_text_size)
  166697. text++;
  166698. text_ptr = (png_textp)png_malloc(png_ptr,
  166699. (png_uint_32)png_sizeof(png_text));
  166700. text_ptr->compression = comp_flag + 2;
  166701. text_ptr->key = key;
  166702. text_ptr->lang = lang;
  166703. text_ptr->lang_key = lang_key;
  166704. text_ptr->text = text;
  166705. text_ptr->text_length = 0;
  166706. text_ptr->itxt_length = png_strlen(text);
  166707. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166708. png_ptr->current_text = NULL;
  166709. png_free(png_ptr, text_ptr);
  166710. if (ret)
  166711. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166712. }
  166713. }
  166714. #endif
  166715. void /* PRIVATE */
  166716. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166717. length)
  166718. {
  166719. png_uint_32 skip=0;
  166720. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166721. if (!(png_ptr->chunk_name[0] & 0x20))
  166722. {
  166723. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166724. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166725. PNG_HANDLE_CHUNK_ALWAYS
  166726. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166727. && png_ptr->read_user_chunk_fn == NULL
  166728. #endif
  166729. )
  166730. #endif
  166731. png_chunk_error(png_ptr, "unknown critical chunk");
  166732. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166733. }
  166734. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166735. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166736. {
  166737. #ifdef PNG_MAX_MALLOC_64K
  166738. if (length > (png_uint_32)65535L)
  166739. {
  166740. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166741. skip = length - (png_uint_32)65535L;
  166742. length = (png_uint_32)65535L;
  166743. }
  166744. #endif
  166745. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166746. (png_charp)png_ptr->chunk_name, 5);
  166747. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166748. png_ptr->unknown_chunk.size = (png_size_t)length;
  166749. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166750. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166751. if(png_ptr->read_user_chunk_fn != NULL)
  166752. {
  166753. int ret;
  166754. ret = (*(png_ptr->read_user_chunk_fn))
  166755. (png_ptr, &png_ptr->unknown_chunk);
  166756. if (ret < 0)
  166757. png_chunk_error(png_ptr, "error in user chunk");
  166758. if (ret == 0)
  166759. {
  166760. if (!(png_ptr->chunk_name[0] & 0x20))
  166761. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166762. PNG_HANDLE_CHUNK_ALWAYS)
  166763. png_chunk_error(png_ptr, "unknown critical chunk");
  166764. png_set_unknown_chunks(png_ptr, info_ptr,
  166765. &png_ptr->unknown_chunk, 1);
  166766. }
  166767. }
  166768. #else
  166769. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166770. #endif
  166771. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166772. png_ptr->unknown_chunk.data = NULL;
  166773. }
  166774. else
  166775. #endif
  166776. skip=length;
  166777. png_push_crc_skip(png_ptr, skip);
  166778. }
  166779. void /* PRIVATE */
  166780. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166781. {
  166782. if (png_ptr->info_fn != NULL)
  166783. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166784. }
  166785. void /* PRIVATE */
  166786. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166787. {
  166788. if (png_ptr->end_fn != NULL)
  166789. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166790. }
  166791. void /* PRIVATE */
  166792. png_push_have_row(png_structp png_ptr, png_bytep row)
  166793. {
  166794. if (png_ptr->row_fn != NULL)
  166795. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166796. (int)png_ptr->pass);
  166797. }
  166798. void PNGAPI
  166799. png_progressive_combine_row (png_structp png_ptr,
  166800. png_bytep old_row, png_bytep new_row)
  166801. {
  166802. #ifdef PNG_USE_LOCAL_ARRAYS
  166803. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166804. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166805. #endif
  166806. if(png_ptr == NULL) return;
  166807. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166808. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166809. }
  166810. void PNGAPI
  166811. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166812. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166813. png_progressive_end_ptr end_fn)
  166814. {
  166815. if(png_ptr == NULL) return;
  166816. png_ptr->info_fn = info_fn;
  166817. png_ptr->row_fn = row_fn;
  166818. png_ptr->end_fn = end_fn;
  166819. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166820. }
  166821. png_voidp PNGAPI
  166822. png_get_progressive_ptr(png_structp png_ptr)
  166823. {
  166824. if(png_ptr == NULL) return (NULL);
  166825. return png_ptr->io_ptr;
  166826. }
  166827. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166828. /*** End of inlined file: pngpread.c ***/
  166829. /*** Start of inlined file: pngrio.c ***/
  166830. #define PNG_INTERNAL
  166831. #if defined(PNG_READ_SUPPORTED)
  166832. void /* PRIVATE */
  166833. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166834. {
  166835. png_debug1(4,"reading %d bytes\n", (int)length);
  166836. if (png_ptr->read_data_fn != NULL)
  166837. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166838. else
  166839. png_error(png_ptr, "Call to NULL read function");
  166840. }
  166841. #if !defined(PNG_NO_STDIO)
  166842. #ifndef USE_FAR_KEYWORD
  166843. void PNGAPI
  166844. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166845. {
  166846. png_size_t check;
  166847. if(png_ptr == NULL) return;
  166848. #if defined(_WIN32_WCE)
  166849. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166850. check = 0;
  166851. #else
  166852. check = (png_size_t)fread(data, (png_size_t)1, length,
  166853. (png_FILE_p)png_ptr->io_ptr);
  166854. #endif
  166855. if (check != length)
  166856. png_error(png_ptr, "Read Error");
  166857. }
  166858. #else
  166859. #define NEAR_BUF_SIZE 1024
  166860. #define MIN(a,b) (a <= b ? a : b)
  166861. static void PNGAPI
  166862. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166863. {
  166864. int check;
  166865. png_byte *n_data;
  166866. png_FILE_p io_ptr;
  166867. if(png_ptr == NULL) return;
  166868. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166869. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166870. if ((png_bytep)n_data == data)
  166871. {
  166872. #if defined(_WIN32_WCE)
  166873. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166874. check = 0;
  166875. #else
  166876. check = fread(n_data, 1, length, io_ptr);
  166877. #endif
  166878. }
  166879. else
  166880. {
  166881. png_byte buf[NEAR_BUF_SIZE];
  166882. png_size_t read, remaining, err;
  166883. check = 0;
  166884. remaining = length;
  166885. do
  166886. {
  166887. read = MIN(NEAR_BUF_SIZE, remaining);
  166888. #if defined(_WIN32_WCE)
  166889. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166890. err = 0;
  166891. #else
  166892. err = fread(buf, (png_size_t)1, read, io_ptr);
  166893. #endif
  166894. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166895. if(err != read)
  166896. break;
  166897. else
  166898. check += err;
  166899. data += read;
  166900. remaining -= read;
  166901. }
  166902. while (remaining != 0);
  166903. }
  166904. if ((png_uint_32)check != (png_uint_32)length)
  166905. png_error(png_ptr, "read Error");
  166906. }
  166907. #endif
  166908. #endif
  166909. void PNGAPI
  166910. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166911. png_rw_ptr read_data_fn)
  166912. {
  166913. if(png_ptr == NULL) return;
  166914. png_ptr->io_ptr = io_ptr;
  166915. #if !defined(PNG_NO_STDIO)
  166916. if (read_data_fn != NULL)
  166917. png_ptr->read_data_fn = read_data_fn;
  166918. else
  166919. png_ptr->read_data_fn = png_default_read_data;
  166920. #else
  166921. png_ptr->read_data_fn = read_data_fn;
  166922. #endif
  166923. if (png_ptr->write_data_fn != NULL)
  166924. {
  166925. png_ptr->write_data_fn = NULL;
  166926. png_warning(png_ptr,
  166927. "It's an error to set both read_data_fn and write_data_fn in the ");
  166928. png_warning(png_ptr,
  166929. "same structure. Resetting write_data_fn to NULL.");
  166930. }
  166931. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  166932. png_ptr->output_flush_fn = NULL;
  166933. #endif
  166934. }
  166935. #endif /* PNG_READ_SUPPORTED */
  166936. /*** End of inlined file: pngrio.c ***/
  166937. /*** Start of inlined file: pngrtran.c ***/
  166938. #define PNG_INTERNAL
  166939. #if defined(PNG_READ_SUPPORTED)
  166940. void PNGAPI
  166941. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  166942. {
  166943. png_debug(1, "in png_set_crc_action\n");
  166944. if(png_ptr == NULL) return;
  166945. switch (crit_action)
  166946. {
  166947. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166948. break;
  166949. case PNG_CRC_WARN_USE: /* warn/use data */
  166950. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166951. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  166952. break;
  166953. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166954. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166955. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  166956. PNG_FLAG_CRC_CRITICAL_IGNORE;
  166957. break;
  166958. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  166959. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  166960. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166961. case PNG_CRC_DEFAULT:
  166962. default:
  166963. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166964. break;
  166965. }
  166966. switch (ancil_action)
  166967. {
  166968. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166969. break;
  166970. case PNG_CRC_WARN_USE: /* warn/use data */
  166971. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166972. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  166973. break;
  166974. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166975. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166976. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  166977. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166978. break;
  166979. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166980. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166981. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166982. break;
  166983. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  166984. case PNG_CRC_DEFAULT:
  166985. default:
  166986. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166987. break;
  166988. }
  166989. }
  166990. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  166991. defined(PNG_FLOATING_POINT_SUPPORTED)
  166992. void PNGAPI
  166993. png_set_background(png_structp png_ptr,
  166994. png_color_16p background_color, int background_gamma_code,
  166995. int need_expand, double background_gamma)
  166996. {
  166997. png_debug(1, "in png_set_background\n");
  166998. if(png_ptr == NULL) return;
  166999. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167000. {
  167001. png_warning(png_ptr, "Application must supply a known background gamma");
  167002. return;
  167003. }
  167004. png_ptr->transformations |= PNG_BACKGROUND;
  167005. png_memcpy(&(png_ptr->background), background_color,
  167006. png_sizeof(png_color_16));
  167007. png_ptr->background_gamma = (float)background_gamma;
  167008. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167009. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167010. }
  167011. #endif
  167012. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167013. void PNGAPI
  167014. png_set_strip_16(png_structp png_ptr)
  167015. {
  167016. png_debug(1, "in png_set_strip_16\n");
  167017. if(png_ptr == NULL) return;
  167018. png_ptr->transformations |= PNG_16_TO_8;
  167019. }
  167020. #endif
  167021. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167022. void PNGAPI
  167023. png_set_strip_alpha(png_structp png_ptr)
  167024. {
  167025. png_debug(1, "in png_set_strip_alpha\n");
  167026. if(png_ptr == NULL) return;
  167027. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167028. }
  167029. #endif
  167030. #if defined(PNG_READ_DITHER_SUPPORTED)
  167031. typedef struct png_dsort_struct
  167032. {
  167033. struct png_dsort_struct FAR * next;
  167034. png_byte left;
  167035. png_byte right;
  167036. } png_dsort;
  167037. typedef png_dsort FAR * png_dsortp;
  167038. typedef png_dsort FAR * FAR * png_dsortpp;
  167039. void PNGAPI
  167040. png_set_dither(png_structp png_ptr, png_colorp palette,
  167041. int num_palette, int maximum_colors, png_uint_16p histogram,
  167042. int full_dither)
  167043. {
  167044. png_debug(1, "in png_set_dither\n");
  167045. if(png_ptr == NULL) return;
  167046. png_ptr->transformations |= PNG_DITHER;
  167047. if (!full_dither)
  167048. {
  167049. int i;
  167050. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167051. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167052. for (i = 0; i < num_palette; i++)
  167053. png_ptr->dither_index[i] = (png_byte)i;
  167054. }
  167055. if (num_palette > maximum_colors)
  167056. {
  167057. if (histogram != NULL)
  167058. {
  167059. int i;
  167060. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167061. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167062. for (i = 0; i < num_palette; i++)
  167063. png_ptr->dither_sort[i] = (png_byte)i;
  167064. for (i = num_palette - 1; i >= maximum_colors; i--)
  167065. {
  167066. int done; /* to stop early if the list is pre-sorted */
  167067. int j;
  167068. done = 1;
  167069. for (j = 0; j < i; j++)
  167070. {
  167071. if (histogram[png_ptr->dither_sort[j]]
  167072. < histogram[png_ptr->dither_sort[j + 1]])
  167073. {
  167074. png_byte t;
  167075. t = png_ptr->dither_sort[j];
  167076. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167077. png_ptr->dither_sort[j + 1] = t;
  167078. done = 0;
  167079. }
  167080. }
  167081. if (done)
  167082. break;
  167083. }
  167084. if (full_dither)
  167085. {
  167086. int j = num_palette;
  167087. for (i = 0; i < maximum_colors; i++)
  167088. {
  167089. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167090. {
  167091. do
  167092. j--;
  167093. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167094. palette[i] = palette[j];
  167095. }
  167096. }
  167097. }
  167098. else
  167099. {
  167100. int j = num_palette;
  167101. for (i = 0; i < maximum_colors; i++)
  167102. {
  167103. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167104. {
  167105. png_color tmp_color;
  167106. do
  167107. j--;
  167108. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167109. tmp_color = palette[j];
  167110. palette[j] = palette[i];
  167111. palette[i] = tmp_color;
  167112. png_ptr->dither_index[j] = (png_byte)i;
  167113. png_ptr->dither_index[i] = (png_byte)j;
  167114. }
  167115. }
  167116. for (i = 0; i < num_palette; i++)
  167117. {
  167118. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167119. {
  167120. int min_d, k, min_k, d_index;
  167121. d_index = png_ptr->dither_index[i];
  167122. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167123. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167124. {
  167125. int d;
  167126. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167127. if (d < min_d)
  167128. {
  167129. min_d = d;
  167130. min_k = k;
  167131. }
  167132. }
  167133. png_ptr->dither_index[i] = (png_byte)min_k;
  167134. }
  167135. }
  167136. }
  167137. png_free(png_ptr, png_ptr->dither_sort);
  167138. png_ptr->dither_sort=NULL;
  167139. }
  167140. else
  167141. {
  167142. int i;
  167143. int max_d;
  167144. int num_new_palette;
  167145. png_dsortp t;
  167146. png_dsortpp hash;
  167147. t=NULL;
  167148. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167149. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167150. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167151. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167152. for (i = 0; i < num_palette; i++)
  167153. {
  167154. png_ptr->index_to_palette[i] = (png_byte)i;
  167155. png_ptr->palette_to_index[i] = (png_byte)i;
  167156. }
  167157. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167158. png_sizeof (png_dsortp)));
  167159. for (i = 0; i < 769; i++)
  167160. hash[i] = NULL;
  167161. num_new_palette = num_palette;
  167162. max_d = 96;
  167163. while (num_new_palette > maximum_colors)
  167164. {
  167165. for (i = 0; i < num_new_palette - 1; i++)
  167166. {
  167167. int j;
  167168. for (j = i + 1; j < num_new_palette; j++)
  167169. {
  167170. int d;
  167171. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167172. if (d <= max_d)
  167173. {
  167174. t = (png_dsortp)png_malloc_warn(png_ptr,
  167175. (png_uint_32)(png_sizeof(png_dsort)));
  167176. if (t == NULL)
  167177. break;
  167178. t->next = hash[d];
  167179. t->left = (png_byte)i;
  167180. t->right = (png_byte)j;
  167181. hash[d] = t;
  167182. }
  167183. }
  167184. if (t == NULL)
  167185. break;
  167186. }
  167187. if (t != NULL)
  167188. for (i = 0; i <= max_d; i++)
  167189. {
  167190. if (hash[i] != NULL)
  167191. {
  167192. png_dsortp p;
  167193. for (p = hash[i]; p; p = p->next)
  167194. {
  167195. if ((int)png_ptr->index_to_palette[p->left]
  167196. < num_new_palette &&
  167197. (int)png_ptr->index_to_palette[p->right]
  167198. < num_new_palette)
  167199. {
  167200. int j, next_j;
  167201. if (num_new_palette & 0x01)
  167202. {
  167203. j = p->left;
  167204. next_j = p->right;
  167205. }
  167206. else
  167207. {
  167208. j = p->right;
  167209. next_j = p->left;
  167210. }
  167211. num_new_palette--;
  167212. palette[png_ptr->index_to_palette[j]]
  167213. = palette[num_new_palette];
  167214. if (!full_dither)
  167215. {
  167216. int k;
  167217. for (k = 0; k < num_palette; k++)
  167218. {
  167219. if (png_ptr->dither_index[k] ==
  167220. png_ptr->index_to_palette[j])
  167221. png_ptr->dither_index[k] =
  167222. png_ptr->index_to_palette[next_j];
  167223. if ((int)png_ptr->dither_index[k] ==
  167224. num_new_palette)
  167225. png_ptr->dither_index[k] =
  167226. png_ptr->index_to_palette[j];
  167227. }
  167228. }
  167229. png_ptr->index_to_palette[png_ptr->palette_to_index
  167230. [num_new_palette]] = png_ptr->index_to_palette[j];
  167231. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167232. = png_ptr->palette_to_index[num_new_palette];
  167233. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167234. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167235. }
  167236. if (num_new_palette <= maximum_colors)
  167237. break;
  167238. }
  167239. if (num_new_palette <= maximum_colors)
  167240. break;
  167241. }
  167242. }
  167243. for (i = 0; i < 769; i++)
  167244. {
  167245. if (hash[i] != NULL)
  167246. {
  167247. png_dsortp p = hash[i];
  167248. while (p)
  167249. {
  167250. t = p->next;
  167251. png_free(png_ptr, p);
  167252. p = t;
  167253. }
  167254. }
  167255. hash[i] = 0;
  167256. }
  167257. max_d += 96;
  167258. }
  167259. png_free(png_ptr, hash);
  167260. png_free(png_ptr, png_ptr->palette_to_index);
  167261. png_free(png_ptr, png_ptr->index_to_palette);
  167262. png_ptr->palette_to_index=NULL;
  167263. png_ptr->index_to_palette=NULL;
  167264. }
  167265. num_palette = maximum_colors;
  167266. }
  167267. if (png_ptr->palette == NULL)
  167268. {
  167269. png_ptr->palette = palette;
  167270. }
  167271. png_ptr->num_palette = (png_uint_16)num_palette;
  167272. if (full_dither)
  167273. {
  167274. int i;
  167275. png_bytep distance;
  167276. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167277. PNG_DITHER_BLUE_BITS;
  167278. int num_red = (1 << PNG_DITHER_RED_BITS);
  167279. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167280. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167281. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167282. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167283. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167284. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167285. png_sizeof (png_byte));
  167286. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167287. png_sizeof(png_byte)));
  167288. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167289. for (i = 0; i < num_palette; i++)
  167290. {
  167291. int ir, ig, ib;
  167292. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167293. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167294. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167295. for (ir = 0; ir < num_red; ir++)
  167296. {
  167297. int dr = ((ir > r) ? ir - r : r - ir);
  167298. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167299. for (ig = 0; ig < num_green; ig++)
  167300. {
  167301. int dg = ((ig > g) ? ig - g : g - ig);
  167302. int dt = dr + dg;
  167303. int dm = ((dr > dg) ? dr : dg);
  167304. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167305. for (ib = 0; ib < num_blue; ib++)
  167306. {
  167307. int d_index = index_g | ib;
  167308. int db = ((ib > b) ? ib - b : b - ib);
  167309. int dmax = ((dm > db) ? dm : db);
  167310. int d = dmax + dt + db;
  167311. if (d < (int)distance[d_index])
  167312. {
  167313. distance[d_index] = (png_byte)d;
  167314. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167315. }
  167316. }
  167317. }
  167318. }
  167319. }
  167320. png_free(png_ptr, distance);
  167321. }
  167322. }
  167323. #endif
  167324. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167325. void PNGAPI
  167326. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167327. {
  167328. png_debug(1, "in png_set_gamma\n");
  167329. if(png_ptr == NULL) return;
  167330. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167331. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167332. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167333. png_ptr->transformations |= PNG_GAMMA;
  167334. png_ptr->gamma = (float)file_gamma;
  167335. png_ptr->screen_gamma = (float)scrn_gamma;
  167336. }
  167337. #endif
  167338. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167339. void PNGAPI
  167340. png_set_expand(png_structp png_ptr)
  167341. {
  167342. png_debug(1, "in png_set_expand\n");
  167343. if(png_ptr == NULL) return;
  167344. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167345. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167346. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167347. #endif
  167348. }
  167349. void PNGAPI
  167350. png_set_palette_to_rgb(png_structp png_ptr)
  167351. {
  167352. png_debug(1, "in png_set_palette_to_rgb\n");
  167353. if(png_ptr == NULL) return;
  167354. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167355. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167356. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167357. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167358. #endif
  167359. }
  167360. #if !defined(PNG_1_0_X)
  167361. void PNGAPI
  167362. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167363. {
  167364. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167365. if(png_ptr == NULL) return;
  167366. png_ptr->transformations |= PNG_EXPAND;
  167367. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167368. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167369. #endif
  167370. }
  167371. #endif
  167372. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167373. void PNGAPI
  167374. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167375. {
  167376. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167377. if(png_ptr == NULL) return;
  167378. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167379. }
  167380. #endif
  167381. void PNGAPI
  167382. png_set_tRNS_to_alpha(png_structp png_ptr)
  167383. {
  167384. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167385. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167386. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167387. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167388. #endif
  167389. }
  167390. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167391. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167392. void PNGAPI
  167393. png_set_gray_to_rgb(png_structp png_ptr)
  167394. {
  167395. png_debug(1, "in png_set_gray_to_rgb\n");
  167396. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167397. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167398. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167399. #endif
  167400. }
  167401. #endif
  167402. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167403. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167404. void PNGAPI
  167405. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167406. double green)
  167407. {
  167408. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167409. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167410. if(png_ptr == NULL) return;
  167411. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167412. }
  167413. #endif
  167414. void PNGAPI
  167415. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167416. png_fixed_point red, png_fixed_point green)
  167417. {
  167418. png_debug(1, "in png_set_rgb_to_gray\n");
  167419. if(png_ptr == NULL) return;
  167420. switch(error_action)
  167421. {
  167422. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167423. break;
  167424. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167425. break;
  167426. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167427. }
  167428. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167429. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167430. png_ptr->transformations |= PNG_EXPAND;
  167431. #else
  167432. {
  167433. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167434. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167435. }
  167436. #endif
  167437. {
  167438. png_uint_16 red_int, green_int;
  167439. if(red < 0 || green < 0)
  167440. {
  167441. red_int = 6968; /* .212671 * 32768 + .5 */
  167442. green_int = 23434; /* .715160 * 32768 + .5 */
  167443. }
  167444. else if(red + green < 100000L)
  167445. {
  167446. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167447. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167448. }
  167449. else
  167450. {
  167451. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167452. red_int = 6968;
  167453. green_int = 23434;
  167454. }
  167455. png_ptr->rgb_to_gray_red_coeff = red_int;
  167456. png_ptr->rgb_to_gray_green_coeff = green_int;
  167457. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167458. }
  167459. }
  167460. #endif
  167461. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167462. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167463. defined(PNG_LEGACY_SUPPORTED)
  167464. void PNGAPI
  167465. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167466. read_user_transform_fn)
  167467. {
  167468. png_debug(1, "in png_set_read_user_transform_fn\n");
  167469. if(png_ptr == NULL) return;
  167470. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167471. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167472. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167473. #endif
  167474. #ifdef PNG_LEGACY_SUPPORTED
  167475. if(read_user_transform_fn)
  167476. png_warning(png_ptr,
  167477. "This version of libpng does not support user transforms");
  167478. #endif
  167479. }
  167480. #endif
  167481. void /* PRIVATE */
  167482. png_init_read_transformations(png_structp png_ptr)
  167483. {
  167484. png_debug(1, "in png_init_read_transformations\n");
  167485. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167486. if(png_ptr != NULL)
  167487. #endif
  167488. {
  167489. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167490. || defined(PNG_READ_GAMMA_SUPPORTED)
  167491. int color_type = png_ptr->color_type;
  167492. #endif
  167493. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167494. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167495. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167496. !(color_type & PNG_COLOR_MASK_COLOR))
  167497. {
  167498. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167499. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167500. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167501. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167502. png_ptr->background.red == png_ptr->background.green &&
  167503. png_ptr->background.red == png_ptr->background.blue)
  167504. {
  167505. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167506. png_ptr->background.gray = png_ptr->background.red;
  167507. }
  167508. #endif
  167509. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167510. (png_ptr->transformations & PNG_EXPAND))
  167511. {
  167512. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167513. {
  167514. switch (png_ptr->bit_depth)
  167515. {
  167516. case 1:
  167517. png_ptr->background.gray *= (png_uint_16)0xff;
  167518. png_ptr->background.red = png_ptr->background.green
  167519. = png_ptr->background.blue = png_ptr->background.gray;
  167520. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167521. {
  167522. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167523. png_ptr->trans_values.red = png_ptr->trans_values.green
  167524. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167525. }
  167526. break;
  167527. case 2:
  167528. png_ptr->background.gray *= (png_uint_16)0x55;
  167529. png_ptr->background.red = png_ptr->background.green
  167530. = png_ptr->background.blue = png_ptr->background.gray;
  167531. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167532. {
  167533. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167534. png_ptr->trans_values.red = png_ptr->trans_values.green
  167535. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167536. }
  167537. break;
  167538. case 4:
  167539. png_ptr->background.gray *= (png_uint_16)0x11;
  167540. png_ptr->background.red = png_ptr->background.green
  167541. = png_ptr->background.blue = png_ptr->background.gray;
  167542. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167543. {
  167544. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167545. png_ptr->trans_values.red = png_ptr->trans_values.green
  167546. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167547. }
  167548. break;
  167549. case 8:
  167550. case 16:
  167551. png_ptr->background.red = png_ptr->background.green
  167552. = png_ptr->background.blue = png_ptr->background.gray;
  167553. break;
  167554. }
  167555. }
  167556. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167557. {
  167558. png_ptr->background.red =
  167559. png_ptr->palette[png_ptr->background.index].red;
  167560. png_ptr->background.green =
  167561. png_ptr->palette[png_ptr->background.index].green;
  167562. png_ptr->background.blue =
  167563. png_ptr->palette[png_ptr->background.index].blue;
  167564. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167565. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167566. {
  167567. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167568. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167569. #endif
  167570. {
  167571. int i,istop;
  167572. istop=(int)png_ptr->num_trans;
  167573. for (i=0; i<istop; i++)
  167574. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167575. }
  167576. }
  167577. #endif
  167578. }
  167579. }
  167580. #endif
  167581. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167582. png_ptr->background_1 = png_ptr->background;
  167583. #endif
  167584. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167585. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167586. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167587. < PNG_GAMMA_THRESHOLD))
  167588. {
  167589. int i,k;
  167590. k=0;
  167591. for (i=0; i<png_ptr->num_trans; i++)
  167592. {
  167593. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167594. k=1; /* partial transparency is present */
  167595. }
  167596. if (k == 0)
  167597. png_ptr->transformations &= (~PNG_GAMMA);
  167598. }
  167599. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167600. png_ptr->gamma != 0.0)
  167601. {
  167602. png_build_gamma_table(png_ptr);
  167603. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167604. if (png_ptr->transformations & PNG_BACKGROUND)
  167605. {
  167606. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167607. {
  167608. png_color back, back_1;
  167609. png_colorp palette = png_ptr->palette;
  167610. int num_palette = png_ptr->num_palette;
  167611. int i;
  167612. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167613. {
  167614. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167615. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167616. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167617. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167618. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167619. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167620. }
  167621. else
  167622. {
  167623. double g, gs;
  167624. switch (png_ptr->background_gamma_type)
  167625. {
  167626. case PNG_BACKGROUND_GAMMA_SCREEN:
  167627. g = (png_ptr->screen_gamma);
  167628. gs = 1.0;
  167629. break;
  167630. case PNG_BACKGROUND_GAMMA_FILE:
  167631. g = 1.0 / (png_ptr->gamma);
  167632. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167633. break;
  167634. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167635. g = 1.0 / (png_ptr->background_gamma);
  167636. gs = 1.0 / (png_ptr->background_gamma *
  167637. png_ptr->screen_gamma);
  167638. break;
  167639. default:
  167640. g = 1.0; /* back_1 */
  167641. gs = 1.0; /* back */
  167642. }
  167643. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167644. {
  167645. back.red = (png_byte)png_ptr->background.red;
  167646. back.green = (png_byte)png_ptr->background.green;
  167647. back.blue = (png_byte)png_ptr->background.blue;
  167648. }
  167649. else
  167650. {
  167651. back.red = (png_byte)(pow(
  167652. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167653. back.green = (png_byte)(pow(
  167654. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167655. back.blue = (png_byte)(pow(
  167656. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167657. }
  167658. back_1.red = (png_byte)(pow(
  167659. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167660. back_1.green = (png_byte)(pow(
  167661. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167662. back_1.blue = (png_byte)(pow(
  167663. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167664. }
  167665. for (i = 0; i < num_palette; i++)
  167666. {
  167667. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167668. {
  167669. if (png_ptr->trans[i] == 0)
  167670. {
  167671. palette[i] = back;
  167672. }
  167673. else /* if (png_ptr->trans[i] != 0xff) */
  167674. {
  167675. png_byte v, w;
  167676. v = png_ptr->gamma_to_1[palette[i].red];
  167677. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167678. palette[i].red = png_ptr->gamma_from_1[w];
  167679. v = png_ptr->gamma_to_1[palette[i].green];
  167680. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167681. palette[i].green = png_ptr->gamma_from_1[w];
  167682. v = png_ptr->gamma_to_1[palette[i].blue];
  167683. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167684. palette[i].blue = png_ptr->gamma_from_1[w];
  167685. }
  167686. }
  167687. else
  167688. {
  167689. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167690. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167691. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167692. }
  167693. }
  167694. }
  167695. else
  167696. {
  167697. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167698. double g = 1.0;
  167699. double gs = 1.0;
  167700. switch (png_ptr->background_gamma_type)
  167701. {
  167702. case PNG_BACKGROUND_GAMMA_SCREEN:
  167703. g = (png_ptr->screen_gamma);
  167704. gs = 1.0;
  167705. break;
  167706. case PNG_BACKGROUND_GAMMA_FILE:
  167707. g = 1.0 / (png_ptr->gamma);
  167708. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167709. break;
  167710. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167711. g = 1.0 / (png_ptr->background_gamma);
  167712. gs = 1.0 / (png_ptr->background_gamma *
  167713. png_ptr->screen_gamma);
  167714. break;
  167715. }
  167716. png_ptr->background_1.gray = (png_uint_16)(pow(
  167717. (double)png_ptr->background.gray / m, g) * m + .5);
  167718. png_ptr->background.gray = (png_uint_16)(pow(
  167719. (double)png_ptr->background.gray / m, gs) * m + .5);
  167720. if ((png_ptr->background.red != png_ptr->background.green) ||
  167721. (png_ptr->background.red != png_ptr->background.blue) ||
  167722. (png_ptr->background.red != png_ptr->background.gray))
  167723. {
  167724. png_ptr->background_1.red = (png_uint_16)(pow(
  167725. (double)png_ptr->background.red / m, g) * m + .5);
  167726. png_ptr->background_1.green = (png_uint_16)(pow(
  167727. (double)png_ptr->background.green / m, g) * m + .5);
  167728. png_ptr->background_1.blue = (png_uint_16)(pow(
  167729. (double)png_ptr->background.blue / m, g) * m + .5);
  167730. png_ptr->background.red = (png_uint_16)(pow(
  167731. (double)png_ptr->background.red / m, gs) * m + .5);
  167732. png_ptr->background.green = (png_uint_16)(pow(
  167733. (double)png_ptr->background.green / m, gs) * m + .5);
  167734. png_ptr->background.blue = (png_uint_16)(pow(
  167735. (double)png_ptr->background.blue / m, gs) * m + .5);
  167736. }
  167737. else
  167738. {
  167739. png_ptr->background_1.red = png_ptr->background_1.green
  167740. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167741. png_ptr->background.red = png_ptr->background.green
  167742. = png_ptr->background.blue = png_ptr->background.gray;
  167743. }
  167744. }
  167745. }
  167746. else
  167747. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167748. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167749. {
  167750. png_colorp palette = png_ptr->palette;
  167751. int num_palette = png_ptr->num_palette;
  167752. int i;
  167753. for (i = 0; i < num_palette; i++)
  167754. {
  167755. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167756. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167757. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167758. }
  167759. }
  167760. }
  167761. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167762. else
  167763. #endif
  167764. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167765. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167766. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167767. (color_type == PNG_COLOR_TYPE_PALETTE))
  167768. {
  167769. int i;
  167770. int istop = (int)png_ptr->num_trans;
  167771. png_color back;
  167772. png_colorp palette = png_ptr->palette;
  167773. back.red = (png_byte)png_ptr->background.red;
  167774. back.green = (png_byte)png_ptr->background.green;
  167775. back.blue = (png_byte)png_ptr->background.blue;
  167776. for (i = 0; i < istop; i++)
  167777. {
  167778. if (png_ptr->trans[i] == 0)
  167779. {
  167780. palette[i] = back;
  167781. }
  167782. else if (png_ptr->trans[i] != 0xff)
  167783. {
  167784. png_composite(palette[i].red, palette[i].red,
  167785. png_ptr->trans[i], back.red);
  167786. png_composite(palette[i].green, palette[i].green,
  167787. png_ptr->trans[i], back.green);
  167788. png_composite(palette[i].blue, palette[i].blue,
  167789. png_ptr->trans[i], back.blue);
  167790. }
  167791. }
  167792. }
  167793. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167794. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167795. if ((png_ptr->transformations & PNG_SHIFT) &&
  167796. (color_type == PNG_COLOR_TYPE_PALETTE))
  167797. {
  167798. png_uint_16 i;
  167799. png_uint_16 istop = png_ptr->num_palette;
  167800. int sr = 8 - png_ptr->sig_bit.red;
  167801. int sg = 8 - png_ptr->sig_bit.green;
  167802. int sb = 8 - png_ptr->sig_bit.blue;
  167803. if (sr < 0 || sr > 8)
  167804. sr = 0;
  167805. if (sg < 0 || sg > 8)
  167806. sg = 0;
  167807. if (sb < 0 || sb > 8)
  167808. sb = 0;
  167809. for (i = 0; i < istop; i++)
  167810. {
  167811. png_ptr->palette[i].red >>= sr;
  167812. png_ptr->palette[i].green >>= sg;
  167813. png_ptr->palette[i].blue >>= sb;
  167814. }
  167815. }
  167816. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167817. }
  167818. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167819. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167820. if(png_ptr)
  167821. return;
  167822. #endif
  167823. }
  167824. void /* PRIVATE */
  167825. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167826. {
  167827. png_debug(1, "in png_read_transform_info\n");
  167828. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167829. if (png_ptr->transformations & PNG_EXPAND)
  167830. {
  167831. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167832. {
  167833. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167834. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167835. else
  167836. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167837. info_ptr->bit_depth = 8;
  167838. info_ptr->num_trans = 0;
  167839. }
  167840. else
  167841. {
  167842. if (png_ptr->num_trans)
  167843. {
  167844. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167845. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167846. else
  167847. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167848. }
  167849. if (info_ptr->bit_depth < 8)
  167850. info_ptr->bit_depth = 8;
  167851. info_ptr->num_trans = 0;
  167852. }
  167853. }
  167854. #endif
  167855. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167856. if (png_ptr->transformations & PNG_BACKGROUND)
  167857. {
  167858. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167859. info_ptr->num_trans = 0;
  167860. info_ptr->background = png_ptr->background;
  167861. }
  167862. #endif
  167863. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167864. if (png_ptr->transformations & PNG_GAMMA)
  167865. {
  167866. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167867. info_ptr->gamma = png_ptr->gamma;
  167868. #endif
  167869. #ifdef PNG_FIXED_POINT_SUPPORTED
  167870. info_ptr->int_gamma = png_ptr->int_gamma;
  167871. #endif
  167872. }
  167873. #endif
  167874. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167875. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167876. info_ptr->bit_depth = 8;
  167877. #endif
  167878. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167879. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167880. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167881. #endif
  167882. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167883. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167884. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167885. #endif
  167886. #if defined(PNG_READ_DITHER_SUPPORTED)
  167887. if (png_ptr->transformations & PNG_DITHER)
  167888. {
  167889. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167890. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167891. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167892. {
  167893. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167894. }
  167895. }
  167896. #endif
  167897. #if defined(PNG_READ_PACK_SUPPORTED)
  167898. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167899. info_ptr->bit_depth = 8;
  167900. #endif
  167901. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167902. info_ptr->channels = 1;
  167903. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167904. info_ptr->channels = 3;
  167905. else
  167906. info_ptr->channels = 1;
  167907. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167908. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167909. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167910. #endif
  167911. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167912. info_ptr->channels++;
  167913. #if defined(PNG_READ_FILLER_SUPPORTED)
  167914. if ((png_ptr->transformations & PNG_FILLER) &&
  167915. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167916. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167917. {
  167918. info_ptr->channels++;
  167919. #if !defined(PNG_1_0_X)
  167920. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167921. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167922. #endif
  167923. }
  167924. #endif
  167925. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167926. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167927. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167928. {
  167929. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167930. info_ptr->bit_depth = png_ptr->user_transform_depth;
  167931. if(info_ptr->channels < png_ptr->user_transform_channels)
  167932. info_ptr->channels = png_ptr->user_transform_channels;
  167933. }
  167934. #endif
  167935. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  167936. info_ptr->bit_depth);
  167937. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  167938. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  167939. if(png_ptr)
  167940. return;
  167941. #endif
  167942. }
  167943. void /* PRIVATE */
  167944. png_do_read_transformations(png_structp png_ptr)
  167945. {
  167946. png_debug(1, "in png_do_read_transformations\n");
  167947. if (png_ptr->row_buf == NULL)
  167948. {
  167949. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  167950. char msg[50];
  167951. png_snprintf2(msg, 50,
  167952. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  167953. png_ptr->pass);
  167954. png_error(png_ptr, msg);
  167955. #else
  167956. png_error(png_ptr, "NULL row buffer");
  167957. #endif
  167958. }
  167959. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167960. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  167961. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  167962. png_error(png_ptr, "Uninitialized row");
  167963. #else
  167964. png_warning(png_ptr, "Uninitialized row");
  167965. #endif
  167966. #endif
  167967. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167968. if (png_ptr->transformations & PNG_EXPAND)
  167969. {
  167970. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  167971. {
  167972. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167973. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  167974. }
  167975. else
  167976. {
  167977. if (png_ptr->num_trans &&
  167978. (png_ptr->transformations & PNG_EXPAND_tRNS))
  167979. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167980. &(png_ptr->trans_values));
  167981. else
  167982. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167983. NULL);
  167984. }
  167985. }
  167986. #endif
  167987. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167988. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167989. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167990. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  167991. #endif
  167992. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167993. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167994. {
  167995. int rgb_error =
  167996. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  167997. if(rgb_error)
  167998. {
  167999. png_ptr->rgb_to_gray_status=1;
  168000. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168001. PNG_RGB_TO_GRAY_WARN)
  168002. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168003. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168004. PNG_RGB_TO_GRAY_ERR)
  168005. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168006. }
  168007. }
  168008. #endif
  168009. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168010. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168011. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168012. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168013. #endif
  168014. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168015. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168016. ((png_ptr->num_trans != 0 ) ||
  168017. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168018. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168019. &(png_ptr->trans_values), &(png_ptr->background)
  168020. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168021. , &(png_ptr->background_1),
  168022. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168023. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168024. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168025. png_ptr->gamma_shift
  168026. #endif
  168027. );
  168028. #endif
  168029. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168030. if ((png_ptr->transformations & PNG_GAMMA) &&
  168031. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168032. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168033. ((png_ptr->num_trans != 0) ||
  168034. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168035. #endif
  168036. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168037. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168038. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168039. png_ptr->gamma_shift);
  168040. #endif
  168041. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168042. if (png_ptr->transformations & PNG_16_TO_8)
  168043. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168044. #endif
  168045. #if defined(PNG_READ_DITHER_SUPPORTED)
  168046. if (png_ptr->transformations & PNG_DITHER)
  168047. {
  168048. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168049. png_ptr->palette_lookup, png_ptr->dither_index);
  168050. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168051. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168052. }
  168053. #endif
  168054. #if defined(PNG_READ_INVERT_SUPPORTED)
  168055. if (png_ptr->transformations & PNG_INVERT_MONO)
  168056. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168057. #endif
  168058. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168059. if (png_ptr->transformations & PNG_SHIFT)
  168060. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168061. &(png_ptr->shift));
  168062. #endif
  168063. #if defined(PNG_READ_PACK_SUPPORTED)
  168064. if (png_ptr->transformations & PNG_PACK)
  168065. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168066. #endif
  168067. #if defined(PNG_READ_BGR_SUPPORTED)
  168068. if (png_ptr->transformations & PNG_BGR)
  168069. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168070. #endif
  168071. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168072. if (png_ptr->transformations & PNG_PACKSWAP)
  168073. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168074. #endif
  168075. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168076. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168077. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168078. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168079. #endif
  168080. #if defined(PNG_READ_FILLER_SUPPORTED)
  168081. if (png_ptr->transformations & PNG_FILLER)
  168082. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168083. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168084. #endif
  168085. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168086. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168087. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168088. #endif
  168089. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168090. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168091. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168092. #endif
  168093. #if defined(PNG_READ_SWAP_SUPPORTED)
  168094. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168095. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168096. #endif
  168097. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168098. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168099. {
  168100. if(png_ptr->read_user_transform_fn != NULL)
  168101. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168102. (png_ptr, /* png_ptr */
  168103. &(png_ptr->row_info), /* row_info: */
  168104. png_ptr->row_buf + 1); /* start of pixel data for row */
  168105. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168106. if(png_ptr->user_transform_depth)
  168107. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168108. if(png_ptr->user_transform_channels)
  168109. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168110. #endif
  168111. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168112. png_ptr->row_info.channels);
  168113. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168114. png_ptr->row_info.width);
  168115. }
  168116. #endif
  168117. }
  168118. #if defined(PNG_READ_PACK_SUPPORTED)
  168119. void /* PRIVATE */
  168120. png_do_unpack(png_row_infop row_info, png_bytep row)
  168121. {
  168122. png_debug(1, "in png_do_unpack\n");
  168123. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168124. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168125. #else
  168126. if (row_info->bit_depth < 8)
  168127. #endif
  168128. {
  168129. png_uint_32 i;
  168130. png_uint_32 row_width=row_info->width;
  168131. switch (row_info->bit_depth)
  168132. {
  168133. case 1:
  168134. {
  168135. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168136. png_bytep dp = row + (png_size_t)row_width - 1;
  168137. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168138. for (i = 0; i < row_width; i++)
  168139. {
  168140. *dp = (png_byte)((*sp >> shift) & 0x01);
  168141. if (shift == 7)
  168142. {
  168143. shift = 0;
  168144. sp--;
  168145. }
  168146. else
  168147. shift++;
  168148. dp--;
  168149. }
  168150. break;
  168151. }
  168152. case 2:
  168153. {
  168154. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168155. png_bytep dp = row + (png_size_t)row_width - 1;
  168156. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168157. for (i = 0; i < row_width; i++)
  168158. {
  168159. *dp = (png_byte)((*sp >> shift) & 0x03);
  168160. if (shift == 6)
  168161. {
  168162. shift = 0;
  168163. sp--;
  168164. }
  168165. else
  168166. shift += 2;
  168167. dp--;
  168168. }
  168169. break;
  168170. }
  168171. case 4:
  168172. {
  168173. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168174. png_bytep dp = row + (png_size_t)row_width - 1;
  168175. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168176. for (i = 0; i < row_width; i++)
  168177. {
  168178. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168179. if (shift == 4)
  168180. {
  168181. shift = 0;
  168182. sp--;
  168183. }
  168184. else
  168185. shift = 4;
  168186. dp--;
  168187. }
  168188. break;
  168189. }
  168190. }
  168191. row_info->bit_depth = 8;
  168192. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168193. row_info->rowbytes = row_width * row_info->channels;
  168194. }
  168195. }
  168196. #endif
  168197. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168198. void /* PRIVATE */
  168199. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168200. {
  168201. png_debug(1, "in png_do_unshift\n");
  168202. if (
  168203. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168204. row != NULL && row_info != NULL && sig_bits != NULL &&
  168205. #endif
  168206. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168207. {
  168208. int shift[4];
  168209. int channels = 0;
  168210. int c;
  168211. png_uint_16 value = 0;
  168212. png_uint_32 row_width = row_info->width;
  168213. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168214. {
  168215. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168216. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168217. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168218. }
  168219. else
  168220. {
  168221. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168222. }
  168223. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168224. {
  168225. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168226. }
  168227. for (c = 0; c < channels; c++)
  168228. {
  168229. if (shift[c] <= 0)
  168230. shift[c] = 0;
  168231. else
  168232. value = 1;
  168233. }
  168234. if (!value)
  168235. return;
  168236. switch (row_info->bit_depth)
  168237. {
  168238. case 2:
  168239. {
  168240. png_bytep bp;
  168241. png_uint_32 i;
  168242. png_uint_32 istop = row_info->rowbytes;
  168243. for (bp = row, i = 0; i < istop; i++)
  168244. {
  168245. *bp >>= 1;
  168246. *bp++ &= 0x55;
  168247. }
  168248. break;
  168249. }
  168250. case 4:
  168251. {
  168252. png_bytep bp = row;
  168253. png_uint_32 i;
  168254. png_uint_32 istop = row_info->rowbytes;
  168255. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168256. (png_byte)((int)0xf >> shift[0]));
  168257. for (i = 0; i < istop; i++)
  168258. {
  168259. *bp >>= shift[0];
  168260. *bp++ &= mask;
  168261. }
  168262. break;
  168263. }
  168264. case 8:
  168265. {
  168266. png_bytep bp = row;
  168267. png_uint_32 i;
  168268. png_uint_32 istop = row_width * channels;
  168269. for (i = 0; i < istop; i++)
  168270. {
  168271. *bp++ >>= shift[i%channels];
  168272. }
  168273. break;
  168274. }
  168275. case 16:
  168276. {
  168277. png_bytep bp = row;
  168278. png_uint_32 i;
  168279. png_uint_32 istop = channels * row_width;
  168280. for (i = 0; i < istop; i++)
  168281. {
  168282. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168283. value >>= shift[i%channels];
  168284. *bp++ = (png_byte)(value >> 8);
  168285. *bp++ = (png_byte)(value & 0xff);
  168286. }
  168287. break;
  168288. }
  168289. }
  168290. }
  168291. }
  168292. #endif
  168293. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168294. void /* PRIVATE */
  168295. png_do_chop(png_row_infop row_info, png_bytep row)
  168296. {
  168297. png_debug(1, "in png_do_chop\n");
  168298. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168299. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168300. #else
  168301. if (row_info->bit_depth == 16)
  168302. #endif
  168303. {
  168304. png_bytep sp = row;
  168305. png_bytep dp = row;
  168306. png_uint_32 i;
  168307. png_uint_32 istop = row_info->width * row_info->channels;
  168308. for (i = 0; i<istop; i++, sp += 2, dp++)
  168309. {
  168310. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168311. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168312. #else
  168313. *dp = *sp;
  168314. #endif
  168315. }
  168316. row_info->bit_depth = 8;
  168317. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168318. row_info->rowbytes = row_info->width * row_info->channels;
  168319. }
  168320. }
  168321. #endif
  168322. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168323. void /* PRIVATE */
  168324. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168325. {
  168326. png_debug(1, "in png_do_read_swap_alpha\n");
  168327. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168328. if (row != NULL && row_info != NULL)
  168329. #endif
  168330. {
  168331. png_uint_32 row_width = row_info->width;
  168332. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168333. {
  168334. if (row_info->bit_depth == 8)
  168335. {
  168336. png_bytep sp = row + row_info->rowbytes;
  168337. png_bytep dp = sp;
  168338. png_byte save;
  168339. png_uint_32 i;
  168340. for (i = 0; i < row_width; i++)
  168341. {
  168342. save = *(--sp);
  168343. *(--dp) = *(--sp);
  168344. *(--dp) = *(--sp);
  168345. *(--dp) = *(--sp);
  168346. *(--dp) = save;
  168347. }
  168348. }
  168349. else
  168350. {
  168351. png_bytep sp = row + row_info->rowbytes;
  168352. png_bytep dp = sp;
  168353. png_byte save[2];
  168354. png_uint_32 i;
  168355. for (i = 0; i < row_width; i++)
  168356. {
  168357. save[0] = *(--sp);
  168358. save[1] = *(--sp);
  168359. *(--dp) = *(--sp);
  168360. *(--dp) = *(--sp);
  168361. *(--dp) = *(--sp);
  168362. *(--dp) = *(--sp);
  168363. *(--dp) = *(--sp);
  168364. *(--dp) = *(--sp);
  168365. *(--dp) = save[0];
  168366. *(--dp) = save[1];
  168367. }
  168368. }
  168369. }
  168370. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168371. {
  168372. if (row_info->bit_depth == 8)
  168373. {
  168374. png_bytep sp = row + row_info->rowbytes;
  168375. png_bytep dp = sp;
  168376. png_byte save;
  168377. png_uint_32 i;
  168378. for (i = 0; i < row_width; i++)
  168379. {
  168380. save = *(--sp);
  168381. *(--dp) = *(--sp);
  168382. *(--dp) = save;
  168383. }
  168384. }
  168385. else
  168386. {
  168387. png_bytep sp = row + row_info->rowbytes;
  168388. png_bytep dp = sp;
  168389. png_byte save[2];
  168390. png_uint_32 i;
  168391. for (i = 0; i < row_width; i++)
  168392. {
  168393. save[0] = *(--sp);
  168394. save[1] = *(--sp);
  168395. *(--dp) = *(--sp);
  168396. *(--dp) = *(--sp);
  168397. *(--dp) = save[0];
  168398. *(--dp) = save[1];
  168399. }
  168400. }
  168401. }
  168402. }
  168403. }
  168404. #endif
  168405. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168406. void /* PRIVATE */
  168407. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168408. {
  168409. png_debug(1, "in png_do_read_invert_alpha\n");
  168410. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168411. if (row != NULL && row_info != NULL)
  168412. #endif
  168413. {
  168414. png_uint_32 row_width = row_info->width;
  168415. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168416. {
  168417. if (row_info->bit_depth == 8)
  168418. {
  168419. png_bytep sp = row + row_info->rowbytes;
  168420. png_bytep dp = sp;
  168421. png_uint_32 i;
  168422. for (i = 0; i < row_width; i++)
  168423. {
  168424. *(--dp) = (png_byte)(255 - *(--sp));
  168425. sp-=3;
  168426. dp=sp;
  168427. }
  168428. }
  168429. else
  168430. {
  168431. png_bytep sp = row + row_info->rowbytes;
  168432. png_bytep dp = sp;
  168433. png_uint_32 i;
  168434. for (i = 0; i < row_width; i++)
  168435. {
  168436. *(--dp) = (png_byte)(255 - *(--sp));
  168437. *(--dp) = (png_byte)(255 - *(--sp));
  168438. sp-=6;
  168439. dp=sp;
  168440. }
  168441. }
  168442. }
  168443. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168444. {
  168445. if (row_info->bit_depth == 8)
  168446. {
  168447. png_bytep sp = row + row_info->rowbytes;
  168448. png_bytep dp = sp;
  168449. png_uint_32 i;
  168450. for (i = 0; i < row_width; i++)
  168451. {
  168452. *(--dp) = (png_byte)(255 - *(--sp));
  168453. *(--dp) = *(--sp);
  168454. }
  168455. }
  168456. else
  168457. {
  168458. png_bytep sp = row + row_info->rowbytes;
  168459. png_bytep dp = sp;
  168460. png_uint_32 i;
  168461. for (i = 0; i < row_width; i++)
  168462. {
  168463. *(--dp) = (png_byte)(255 - *(--sp));
  168464. *(--dp) = (png_byte)(255 - *(--sp));
  168465. sp-=2;
  168466. dp=sp;
  168467. }
  168468. }
  168469. }
  168470. }
  168471. }
  168472. #endif
  168473. #if defined(PNG_READ_FILLER_SUPPORTED)
  168474. void /* PRIVATE */
  168475. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168476. png_uint_32 filler, png_uint_32 flags)
  168477. {
  168478. png_uint_32 i;
  168479. png_uint_32 row_width = row_info->width;
  168480. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168481. png_byte lo_filler = (png_byte)(filler & 0xff);
  168482. png_debug(1, "in png_do_read_filler\n");
  168483. if (
  168484. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168485. row != NULL && row_info != NULL &&
  168486. #endif
  168487. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168488. {
  168489. if(row_info->bit_depth == 8)
  168490. {
  168491. if (flags & PNG_FLAG_FILLER_AFTER)
  168492. {
  168493. png_bytep sp = row + (png_size_t)row_width;
  168494. png_bytep dp = sp + (png_size_t)row_width;
  168495. for (i = 1; i < row_width; i++)
  168496. {
  168497. *(--dp) = lo_filler;
  168498. *(--dp) = *(--sp);
  168499. }
  168500. *(--dp) = lo_filler;
  168501. row_info->channels = 2;
  168502. row_info->pixel_depth = 16;
  168503. row_info->rowbytes = row_width * 2;
  168504. }
  168505. else
  168506. {
  168507. png_bytep sp = row + (png_size_t)row_width;
  168508. png_bytep dp = sp + (png_size_t)row_width;
  168509. for (i = 0; i < row_width; i++)
  168510. {
  168511. *(--dp) = *(--sp);
  168512. *(--dp) = lo_filler;
  168513. }
  168514. row_info->channels = 2;
  168515. row_info->pixel_depth = 16;
  168516. row_info->rowbytes = row_width * 2;
  168517. }
  168518. }
  168519. else if(row_info->bit_depth == 16)
  168520. {
  168521. if (flags & PNG_FLAG_FILLER_AFTER)
  168522. {
  168523. png_bytep sp = row + (png_size_t)row_width * 2;
  168524. png_bytep dp = sp + (png_size_t)row_width * 2;
  168525. for (i = 1; i < row_width; i++)
  168526. {
  168527. *(--dp) = hi_filler;
  168528. *(--dp) = lo_filler;
  168529. *(--dp) = *(--sp);
  168530. *(--dp) = *(--sp);
  168531. }
  168532. *(--dp) = hi_filler;
  168533. *(--dp) = lo_filler;
  168534. row_info->channels = 2;
  168535. row_info->pixel_depth = 32;
  168536. row_info->rowbytes = row_width * 4;
  168537. }
  168538. else
  168539. {
  168540. png_bytep sp = row + (png_size_t)row_width * 2;
  168541. png_bytep dp = sp + (png_size_t)row_width * 2;
  168542. for (i = 0; i < row_width; i++)
  168543. {
  168544. *(--dp) = *(--sp);
  168545. *(--dp) = *(--sp);
  168546. *(--dp) = hi_filler;
  168547. *(--dp) = lo_filler;
  168548. }
  168549. row_info->channels = 2;
  168550. row_info->pixel_depth = 32;
  168551. row_info->rowbytes = row_width * 4;
  168552. }
  168553. }
  168554. } /* COLOR_TYPE == GRAY */
  168555. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168556. {
  168557. if(row_info->bit_depth == 8)
  168558. {
  168559. if (flags & PNG_FLAG_FILLER_AFTER)
  168560. {
  168561. png_bytep sp = row + (png_size_t)row_width * 3;
  168562. png_bytep dp = sp + (png_size_t)row_width;
  168563. for (i = 1; i < row_width; i++)
  168564. {
  168565. *(--dp) = lo_filler;
  168566. *(--dp) = *(--sp);
  168567. *(--dp) = *(--sp);
  168568. *(--dp) = *(--sp);
  168569. }
  168570. *(--dp) = lo_filler;
  168571. row_info->channels = 4;
  168572. row_info->pixel_depth = 32;
  168573. row_info->rowbytes = row_width * 4;
  168574. }
  168575. else
  168576. {
  168577. png_bytep sp = row + (png_size_t)row_width * 3;
  168578. png_bytep dp = sp + (png_size_t)row_width;
  168579. for (i = 0; i < row_width; i++)
  168580. {
  168581. *(--dp) = *(--sp);
  168582. *(--dp) = *(--sp);
  168583. *(--dp) = *(--sp);
  168584. *(--dp) = lo_filler;
  168585. }
  168586. row_info->channels = 4;
  168587. row_info->pixel_depth = 32;
  168588. row_info->rowbytes = row_width * 4;
  168589. }
  168590. }
  168591. else if(row_info->bit_depth == 16)
  168592. {
  168593. if (flags & PNG_FLAG_FILLER_AFTER)
  168594. {
  168595. png_bytep sp = row + (png_size_t)row_width * 6;
  168596. png_bytep dp = sp + (png_size_t)row_width * 2;
  168597. for (i = 1; i < row_width; i++)
  168598. {
  168599. *(--dp) = hi_filler;
  168600. *(--dp) = lo_filler;
  168601. *(--dp) = *(--sp);
  168602. *(--dp) = *(--sp);
  168603. *(--dp) = *(--sp);
  168604. *(--dp) = *(--sp);
  168605. *(--dp) = *(--sp);
  168606. *(--dp) = *(--sp);
  168607. }
  168608. *(--dp) = hi_filler;
  168609. *(--dp) = lo_filler;
  168610. row_info->channels = 4;
  168611. row_info->pixel_depth = 64;
  168612. row_info->rowbytes = row_width * 8;
  168613. }
  168614. else
  168615. {
  168616. png_bytep sp = row + (png_size_t)row_width * 6;
  168617. png_bytep dp = sp + (png_size_t)row_width * 2;
  168618. for (i = 0; i < row_width; i++)
  168619. {
  168620. *(--dp) = *(--sp);
  168621. *(--dp) = *(--sp);
  168622. *(--dp) = *(--sp);
  168623. *(--dp) = *(--sp);
  168624. *(--dp) = *(--sp);
  168625. *(--dp) = *(--sp);
  168626. *(--dp) = hi_filler;
  168627. *(--dp) = lo_filler;
  168628. }
  168629. row_info->channels = 4;
  168630. row_info->pixel_depth = 64;
  168631. row_info->rowbytes = row_width * 8;
  168632. }
  168633. }
  168634. } /* COLOR_TYPE == RGB */
  168635. }
  168636. #endif
  168637. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168638. void /* PRIVATE */
  168639. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168640. {
  168641. png_uint_32 i;
  168642. png_uint_32 row_width = row_info->width;
  168643. png_debug(1, "in png_do_gray_to_rgb\n");
  168644. if (row_info->bit_depth >= 8 &&
  168645. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168646. row != NULL && row_info != NULL &&
  168647. #endif
  168648. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168649. {
  168650. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168651. {
  168652. if (row_info->bit_depth == 8)
  168653. {
  168654. png_bytep sp = row + (png_size_t)row_width - 1;
  168655. png_bytep dp = sp + (png_size_t)row_width * 2;
  168656. for (i = 0; i < row_width; i++)
  168657. {
  168658. *(dp--) = *sp;
  168659. *(dp--) = *sp;
  168660. *(dp--) = *(sp--);
  168661. }
  168662. }
  168663. else
  168664. {
  168665. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168666. png_bytep dp = sp + (png_size_t)row_width * 4;
  168667. for (i = 0; i < row_width; i++)
  168668. {
  168669. *(dp--) = *sp;
  168670. *(dp--) = *(sp - 1);
  168671. *(dp--) = *sp;
  168672. *(dp--) = *(sp - 1);
  168673. *(dp--) = *(sp--);
  168674. *(dp--) = *(sp--);
  168675. }
  168676. }
  168677. }
  168678. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168679. {
  168680. if (row_info->bit_depth == 8)
  168681. {
  168682. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168683. png_bytep dp = sp + (png_size_t)row_width * 2;
  168684. for (i = 0; i < row_width; i++)
  168685. {
  168686. *(dp--) = *(sp--);
  168687. *(dp--) = *sp;
  168688. *(dp--) = *sp;
  168689. *(dp--) = *(sp--);
  168690. }
  168691. }
  168692. else
  168693. {
  168694. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168695. png_bytep dp = sp + (png_size_t)row_width * 4;
  168696. for (i = 0; i < row_width; i++)
  168697. {
  168698. *(dp--) = *(sp--);
  168699. *(dp--) = *(sp--);
  168700. *(dp--) = *sp;
  168701. *(dp--) = *(sp - 1);
  168702. *(dp--) = *sp;
  168703. *(dp--) = *(sp - 1);
  168704. *(dp--) = *(sp--);
  168705. *(dp--) = *(sp--);
  168706. }
  168707. }
  168708. }
  168709. row_info->channels += (png_byte)2;
  168710. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168711. row_info->pixel_depth = (png_byte)(row_info->channels *
  168712. row_info->bit_depth);
  168713. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168714. }
  168715. }
  168716. #endif
  168717. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168718. int /* PRIVATE */
  168719. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168720. {
  168721. png_uint_32 i;
  168722. png_uint_32 row_width = row_info->width;
  168723. int rgb_error = 0;
  168724. png_debug(1, "in png_do_rgb_to_gray\n");
  168725. if (
  168726. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168727. row != NULL && row_info != NULL &&
  168728. #endif
  168729. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168730. {
  168731. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168732. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168733. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168734. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168735. {
  168736. if (row_info->bit_depth == 8)
  168737. {
  168738. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168739. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168740. {
  168741. png_bytep sp = row;
  168742. png_bytep dp = row;
  168743. for (i = 0; i < row_width; i++)
  168744. {
  168745. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168746. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168747. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168748. if(red != green || red != blue)
  168749. {
  168750. rgb_error |= 1;
  168751. *(dp++) = png_ptr->gamma_from_1[
  168752. (rc*red+gc*green+bc*blue)>>15];
  168753. }
  168754. else
  168755. *(dp++) = *(sp-1);
  168756. }
  168757. }
  168758. else
  168759. #endif
  168760. {
  168761. png_bytep sp = row;
  168762. png_bytep dp = row;
  168763. for (i = 0; i < row_width; i++)
  168764. {
  168765. png_byte red = *(sp++);
  168766. png_byte green = *(sp++);
  168767. png_byte blue = *(sp++);
  168768. if(red != green || red != blue)
  168769. {
  168770. rgb_error |= 1;
  168771. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168772. }
  168773. else
  168774. *(dp++) = *(sp-1);
  168775. }
  168776. }
  168777. }
  168778. else /* RGB bit_depth == 16 */
  168779. {
  168780. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168781. if (png_ptr->gamma_16_to_1 != NULL &&
  168782. png_ptr->gamma_16_from_1 != NULL)
  168783. {
  168784. png_bytep sp = row;
  168785. png_bytep dp = row;
  168786. for (i = 0; i < row_width; i++)
  168787. {
  168788. png_uint_16 red, green, blue, w;
  168789. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168790. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168791. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168792. if(red == green && red == blue)
  168793. w = red;
  168794. else
  168795. {
  168796. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168797. png_ptr->gamma_shift][red>>8];
  168798. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168799. png_ptr->gamma_shift][green>>8];
  168800. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168801. png_ptr->gamma_shift][blue>>8];
  168802. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168803. + bc*blue_1)>>15);
  168804. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168805. png_ptr->gamma_shift][gray16 >> 8];
  168806. rgb_error |= 1;
  168807. }
  168808. *(dp++) = (png_byte)((w>>8) & 0xff);
  168809. *(dp++) = (png_byte)(w & 0xff);
  168810. }
  168811. }
  168812. else
  168813. #endif
  168814. {
  168815. png_bytep sp = row;
  168816. png_bytep dp = row;
  168817. for (i = 0; i < row_width; i++)
  168818. {
  168819. png_uint_16 red, green, blue, gray16;
  168820. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168821. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168822. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168823. if(red != green || red != blue)
  168824. rgb_error |= 1;
  168825. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168826. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168827. *(dp++) = (png_byte)(gray16 & 0xff);
  168828. }
  168829. }
  168830. }
  168831. }
  168832. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168833. {
  168834. if (row_info->bit_depth == 8)
  168835. {
  168836. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168837. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168838. {
  168839. png_bytep sp = row;
  168840. png_bytep dp = row;
  168841. for (i = 0; i < row_width; i++)
  168842. {
  168843. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168844. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168845. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168846. if(red != green || red != blue)
  168847. rgb_error |= 1;
  168848. *(dp++) = png_ptr->gamma_from_1
  168849. [(rc*red + gc*green + bc*blue)>>15];
  168850. *(dp++) = *(sp++); /* alpha */
  168851. }
  168852. }
  168853. else
  168854. #endif
  168855. {
  168856. png_bytep sp = row;
  168857. png_bytep dp = row;
  168858. for (i = 0; i < row_width; i++)
  168859. {
  168860. png_byte red = *(sp++);
  168861. png_byte green = *(sp++);
  168862. png_byte blue = *(sp++);
  168863. if(red != green || red != blue)
  168864. rgb_error |= 1;
  168865. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168866. *(dp++) = *(sp++); /* alpha */
  168867. }
  168868. }
  168869. }
  168870. else /* RGBA bit_depth == 16 */
  168871. {
  168872. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168873. if (png_ptr->gamma_16_to_1 != NULL &&
  168874. png_ptr->gamma_16_from_1 != NULL)
  168875. {
  168876. png_bytep sp = row;
  168877. png_bytep dp = row;
  168878. for (i = 0; i < row_width; i++)
  168879. {
  168880. png_uint_16 red, green, blue, w;
  168881. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168882. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168883. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168884. if(red == green && red == blue)
  168885. w = red;
  168886. else
  168887. {
  168888. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168889. png_ptr->gamma_shift][red>>8];
  168890. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168891. png_ptr->gamma_shift][green>>8];
  168892. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168893. png_ptr->gamma_shift][blue>>8];
  168894. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168895. + gc * green_1 + bc * blue_1)>>15);
  168896. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168897. png_ptr->gamma_shift][gray16 >> 8];
  168898. rgb_error |= 1;
  168899. }
  168900. *(dp++) = (png_byte)((w>>8) & 0xff);
  168901. *(dp++) = (png_byte)(w & 0xff);
  168902. *(dp++) = *(sp++); /* alpha */
  168903. *(dp++) = *(sp++);
  168904. }
  168905. }
  168906. else
  168907. #endif
  168908. {
  168909. png_bytep sp = row;
  168910. png_bytep dp = row;
  168911. for (i = 0; i < row_width; i++)
  168912. {
  168913. png_uint_16 red, green, blue, gray16;
  168914. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168915. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168916. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168917. if(red != green || red != blue)
  168918. rgb_error |= 1;
  168919. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168920. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168921. *(dp++) = (png_byte)(gray16 & 0xff);
  168922. *(dp++) = *(sp++); /* alpha */
  168923. *(dp++) = *(sp++);
  168924. }
  168925. }
  168926. }
  168927. }
  168928. row_info->channels -= (png_byte)2;
  168929. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168930. row_info->pixel_depth = (png_byte)(row_info->channels *
  168931. row_info->bit_depth);
  168932. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168933. }
  168934. return rgb_error;
  168935. }
  168936. #endif
  168937. void PNGAPI
  168938. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  168939. {
  168940. int num_palette;
  168941. int color_inc;
  168942. int i;
  168943. int v;
  168944. png_debug(1, "in png_do_build_grayscale_palette\n");
  168945. if (palette == NULL)
  168946. return;
  168947. switch (bit_depth)
  168948. {
  168949. case 1:
  168950. num_palette = 2;
  168951. color_inc = 0xff;
  168952. break;
  168953. case 2:
  168954. num_palette = 4;
  168955. color_inc = 0x55;
  168956. break;
  168957. case 4:
  168958. num_palette = 16;
  168959. color_inc = 0x11;
  168960. break;
  168961. case 8:
  168962. num_palette = 256;
  168963. color_inc = 1;
  168964. break;
  168965. default:
  168966. num_palette = 0;
  168967. color_inc = 0;
  168968. break;
  168969. }
  168970. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  168971. {
  168972. palette[i].red = (png_byte)v;
  168973. palette[i].green = (png_byte)v;
  168974. palette[i].blue = (png_byte)v;
  168975. }
  168976. }
  168977. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  168978. void /* PRIVATE */
  168979. png_correct_palette(png_structp png_ptr, png_colorp palette,
  168980. int num_palette)
  168981. {
  168982. png_debug(1, "in png_correct_palette\n");
  168983. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  168984. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168985. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  168986. {
  168987. png_color back, back_1;
  168988. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168989. {
  168990. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168991. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168992. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168993. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168994. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168995. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168996. }
  168997. else
  168998. {
  168999. double g;
  169000. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169001. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169002. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169003. {
  169004. back.red = png_ptr->background.red;
  169005. back.green = png_ptr->background.green;
  169006. back.blue = png_ptr->background.blue;
  169007. }
  169008. else
  169009. {
  169010. back.red =
  169011. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169012. 255.0 + 0.5);
  169013. back.green =
  169014. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169015. 255.0 + 0.5);
  169016. back.blue =
  169017. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169018. 255.0 + 0.5);
  169019. }
  169020. g = 1.0 / png_ptr->background_gamma;
  169021. back_1.red =
  169022. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169023. 255.0 + 0.5);
  169024. back_1.green =
  169025. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169026. 255.0 + 0.5);
  169027. back_1.blue =
  169028. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169029. 255.0 + 0.5);
  169030. }
  169031. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169032. {
  169033. png_uint_32 i;
  169034. for (i = 0; i < (png_uint_32)num_palette; i++)
  169035. {
  169036. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169037. {
  169038. palette[i] = back;
  169039. }
  169040. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169041. {
  169042. png_byte v, w;
  169043. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169044. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169045. palette[i].red = png_ptr->gamma_from_1[w];
  169046. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169047. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169048. palette[i].green = png_ptr->gamma_from_1[w];
  169049. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169050. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169051. palette[i].blue = png_ptr->gamma_from_1[w];
  169052. }
  169053. else
  169054. {
  169055. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169056. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169057. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169058. }
  169059. }
  169060. }
  169061. else
  169062. {
  169063. int i;
  169064. for (i = 0; i < num_palette; i++)
  169065. {
  169066. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169067. {
  169068. palette[i] = back;
  169069. }
  169070. else
  169071. {
  169072. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169073. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169074. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169075. }
  169076. }
  169077. }
  169078. }
  169079. else
  169080. #endif
  169081. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169082. if (png_ptr->transformations & PNG_GAMMA)
  169083. {
  169084. int i;
  169085. for (i = 0; i < num_palette; i++)
  169086. {
  169087. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169088. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169089. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169090. }
  169091. }
  169092. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169093. else
  169094. #endif
  169095. #endif
  169096. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169097. if (png_ptr->transformations & PNG_BACKGROUND)
  169098. {
  169099. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169100. {
  169101. png_color back;
  169102. back.red = (png_byte)png_ptr->background.red;
  169103. back.green = (png_byte)png_ptr->background.green;
  169104. back.blue = (png_byte)png_ptr->background.blue;
  169105. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169106. {
  169107. if (png_ptr->trans[i] == 0)
  169108. {
  169109. palette[i].red = back.red;
  169110. palette[i].green = back.green;
  169111. palette[i].blue = back.blue;
  169112. }
  169113. else if (png_ptr->trans[i] != 0xff)
  169114. {
  169115. png_composite(palette[i].red, png_ptr->palette[i].red,
  169116. png_ptr->trans[i], back.red);
  169117. png_composite(palette[i].green, png_ptr->palette[i].green,
  169118. png_ptr->trans[i], back.green);
  169119. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169120. png_ptr->trans[i], back.blue);
  169121. }
  169122. }
  169123. }
  169124. else /* assume grayscale palette (what else could it be?) */
  169125. {
  169126. int i;
  169127. for (i = 0; i < num_palette; i++)
  169128. {
  169129. if (i == (png_byte)png_ptr->trans_values.gray)
  169130. {
  169131. palette[i].red = (png_byte)png_ptr->background.red;
  169132. palette[i].green = (png_byte)png_ptr->background.green;
  169133. palette[i].blue = (png_byte)png_ptr->background.blue;
  169134. }
  169135. }
  169136. }
  169137. }
  169138. #endif
  169139. }
  169140. #endif
  169141. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169142. void /* PRIVATE */
  169143. png_do_background(png_row_infop row_info, png_bytep row,
  169144. png_color_16p trans_values, png_color_16p background
  169145. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169146. , png_color_16p background_1,
  169147. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169148. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169149. png_uint_16pp gamma_16_to_1, int gamma_shift
  169150. #endif
  169151. )
  169152. {
  169153. png_bytep sp, dp;
  169154. png_uint_32 i;
  169155. png_uint_32 row_width=row_info->width;
  169156. int shift;
  169157. png_debug(1, "in png_do_background\n");
  169158. if (background != NULL &&
  169159. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169160. row != NULL && row_info != NULL &&
  169161. #endif
  169162. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169163. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169164. {
  169165. switch (row_info->color_type)
  169166. {
  169167. case PNG_COLOR_TYPE_GRAY:
  169168. {
  169169. switch (row_info->bit_depth)
  169170. {
  169171. case 1:
  169172. {
  169173. sp = row;
  169174. shift = 7;
  169175. for (i = 0; i < row_width; i++)
  169176. {
  169177. if ((png_uint_16)((*sp >> shift) & 0x01)
  169178. == trans_values->gray)
  169179. {
  169180. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169181. *sp |= (png_byte)(background->gray << shift);
  169182. }
  169183. if (!shift)
  169184. {
  169185. shift = 7;
  169186. sp++;
  169187. }
  169188. else
  169189. shift--;
  169190. }
  169191. break;
  169192. }
  169193. case 2:
  169194. {
  169195. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169196. if (gamma_table != NULL)
  169197. {
  169198. sp = row;
  169199. shift = 6;
  169200. for (i = 0; i < row_width; i++)
  169201. {
  169202. if ((png_uint_16)((*sp >> shift) & 0x03)
  169203. == trans_values->gray)
  169204. {
  169205. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169206. *sp |= (png_byte)(background->gray << shift);
  169207. }
  169208. else
  169209. {
  169210. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169211. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169212. (p << 4) | (p << 6)] >> 6) & 0x03);
  169213. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169214. *sp |= (png_byte)(g << shift);
  169215. }
  169216. if (!shift)
  169217. {
  169218. shift = 6;
  169219. sp++;
  169220. }
  169221. else
  169222. shift -= 2;
  169223. }
  169224. }
  169225. else
  169226. #endif
  169227. {
  169228. sp = row;
  169229. shift = 6;
  169230. for (i = 0; i < row_width; i++)
  169231. {
  169232. if ((png_uint_16)((*sp >> shift) & 0x03)
  169233. == trans_values->gray)
  169234. {
  169235. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169236. *sp |= (png_byte)(background->gray << shift);
  169237. }
  169238. if (!shift)
  169239. {
  169240. shift = 6;
  169241. sp++;
  169242. }
  169243. else
  169244. shift -= 2;
  169245. }
  169246. }
  169247. break;
  169248. }
  169249. case 4:
  169250. {
  169251. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169252. if (gamma_table != NULL)
  169253. {
  169254. sp = row;
  169255. shift = 4;
  169256. for (i = 0; i < row_width; i++)
  169257. {
  169258. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169259. == trans_values->gray)
  169260. {
  169261. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169262. *sp |= (png_byte)(background->gray << shift);
  169263. }
  169264. else
  169265. {
  169266. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169267. png_byte g = (png_byte)((gamma_table[p |
  169268. (p << 4)] >> 4) & 0x0f);
  169269. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169270. *sp |= (png_byte)(g << shift);
  169271. }
  169272. if (!shift)
  169273. {
  169274. shift = 4;
  169275. sp++;
  169276. }
  169277. else
  169278. shift -= 4;
  169279. }
  169280. }
  169281. else
  169282. #endif
  169283. {
  169284. sp = row;
  169285. shift = 4;
  169286. for (i = 0; i < row_width; i++)
  169287. {
  169288. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169289. == trans_values->gray)
  169290. {
  169291. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169292. *sp |= (png_byte)(background->gray << shift);
  169293. }
  169294. if (!shift)
  169295. {
  169296. shift = 4;
  169297. sp++;
  169298. }
  169299. else
  169300. shift -= 4;
  169301. }
  169302. }
  169303. break;
  169304. }
  169305. case 8:
  169306. {
  169307. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169308. if (gamma_table != NULL)
  169309. {
  169310. sp = row;
  169311. for (i = 0; i < row_width; i++, sp++)
  169312. {
  169313. if (*sp == trans_values->gray)
  169314. {
  169315. *sp = (png_byte)background->gray;
  169316. }
  169317. else
  169318. {
  169319. *sp = gamma_table[*sp];
  169320. }
  169321. }
  169322. }
  169323. else
  169324. #endif
  169325. {
  169326. sp = row;
  169327. for (i = 0; i < row_width; i++, sp++)
  169328. {
  169329. if (*sp == trans_values->gray)
  169330. {
  169331. *sp = (png_byte)background->gray;
  169332. }
  169333. }
  169334. }
  169335. break;
  169336. }
  169337. case 16:
  169338. {
  169339. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169340. if (gamma_16 != NULL)
  169341. {
  169342. sp = row;
  169343. for (i = 0; i < row_width; i++, sp += 2)
  169344. {
  169345. png_uint_16 v;
  169346. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169347. if (v == trans_values->gray)
  169348. {
  169349. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169350. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169351. }
  169352. else
  169353. {
  169354. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169355. *sp = (png_byte)((v >> 8) & 0xff);
  169356. *(sp + 1) = (png_byte)(v & 0xff);
  169357. }
  169358. }
  169359. }
  169360. else
  169361. #endif
  169362. {
  169363. sp = row;
  169364. for (i = 0; i < row_width; i++, sp += 2)
  169365. {
  169366. png_uint_16 v;
  169367. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169368. if (v == trans_values->gray)
  169369. {
  169370. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169371. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169372. }
  169373. }
  169374. }
  169375. break;
  169376. }
  169377. }
  169378. break;
  169379. }
  169380. case PNG_COLOR_TYPE_RGB:
  169381. {
  169382. if (row_info->bit_depth == 8)
  169383. {
  169384. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169385. if (gamma_table != NULL)
  169386. {
  169387. sp = row;
  169388. for (i = 0; i < row_width; i++, sp += 3)
  169389. {
  169390. if (*sp == trans_values->red &&
  169391. *(sp + 1) == trans_values->green &&
  169392. *(sp + 2) == trans_values->blue)
  169393. {
  169394. *sp = (png_byte)background->red;
  169395. *(sp + 1) = (png_byte)background->green;
  169396. *(sp + 2) = (png_byte)background->blue;
  169397. }
  169398. else
  169399. {
  169400. *sp = gamma_table[*sp];
  169401. *(sp + 1) = gamma_table[*(sp + 1)];
  169402. *(sp + 2) = gamma_table[*(sp + 2)];
  169403. }
  169404. }
  169405. }
  169406. else
  169407. #endif
  169408. {
  169409. sp = row;
  169410. for (i = 0; i < row_width; i++, sp += 3)
  169411. {
  169412. if (*sp == trans_values->red &&
  169413. *(sp + 1) == trans_values->green &&
  169414. *(sp + 2) == trans_values->blue)
  169415. {
  169416. *sp = (png_byte)background->red;
  169417. *(sp + 1) = (png_byte)background->green;
  169418. *(sp + 2) = (png_byte)background->blue;
  169419. }
  169420. }
  169421. }
  169422. }
  169423. else /* if (row_info->bit_depth == 16) */
  169424. {
  169425. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169426. if (gamma_16 != NULL)
  169427. {
  169428. sp = row;
  169429. for (i = 0; i < row_width; i++, sp += 6)
  169430. {
  169431. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169432. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169433. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169434. if (r == trans_values->red && g == trans_values->green &&
  169435. b == trans_values->blue)
  169436. {
  169437. *sp = (png_byte)((background->red >> 8) & 0xff);
  169438. *(sp + 1) = (png_byte)(background->red & 0xff);
  169439. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169440. *(sp + 3) = (png_byte)(background->green & 0xff);
  169441. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169442. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169443. }
  169444. else
  169445. {
  169446. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169447. *sp = (png_byte)((v >> 8) & 0xff);
  169448. *(sp + 1) = (png_byte)(v & 0xff);
  169449. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169450. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169451. *(sp + 3) = (png_byte)(v & 0xff);
  169452. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169453. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169454. *(sp + 5) = (png_byte)(v & 0xff);
  169455. }
  169456. }
  169457. }
  169458. else
  169459. #endif
  169460. {
  169461. sp = row;
  169462. for (i = 0; i < row_width; i++, sp += 6)
  169463. {
  169464. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169465. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169466. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169467. if (r == trans_values->red && g == trans_values->green &&
  169468. b == trans_values->blue)
  169469. {
  169470. *sp = (png_byte)((background->red >> 8) & 0xff);
  169471. *(sp + 1) = (png_byte)(background->red & 0xff);
  169472. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169473. *(sp + 3) = (png_byte)(background->green & 0xff);
  169474. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169475. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169476. }
  169477. }
  169478. }
  169479. }
  169480. break;
  169481. }
  169482. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169483. {
  169484. if (row_info->bit_depth == 8)
  169485. {
  169486. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169487. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169488. gamma_table != NULL)
  169489. {
  169490. sp = row;
  169491. dp = row;
  169492. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169493. {
  169494. png_uint_16 a = *(sp + 1);
  169495. if (a == 0xff)
  169496. {
  169497. *dp = gamma_table[*sp];
  169498. }
  169499. else if (a == 0)
  169500. {
  169501. *dp = (png_byte)background->gray;
  169502. }
  169503. else
  169504. {
  169505. png_byte v, w;
  169506. v = gamma_to_1[*sp];
  169507. png_composite(w, v, a, background_1->gray);
  169508. *dp = gamma_from_1[w];
  169509. }
  169510. }
  169511. }
  169512. else
  169513. #endif
  169514. {
  169515. sp = row;
  169516. dp = row;
  169517. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169518. {
  169519. png_byte a = *(sp + 1);
  169520. if (a == 0xff)
  169521. {
  169522. *dp = *sp;
  169523. }
  169524. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169525. else if (a == 0)
  169526. {
  169527. *dp = (png_byte)background->gray;
  169528. }
  169529. else
  169530. {
  169531. png_composite(*dp, *sp, a, background_1->gray);
  169532. }
  169533. #else
  169534. *dp = (png_byte)background->gray;
  169535. #endif
  169536. }
  169537. }
  169538. }
  169539. else /* if (png_ptr->bit_depth == 16) */
  169540. {
  169541. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169542. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169543. gamma_16_to_1 != NULL)
  169544. {
  169545. sp = row;
  169546. dp = row;
  169547. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169548. {
  169549. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169550. if (a == (png_uint_16)0xffff)
  169551. {
  169552. png_uint_16 v;
  169553. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169554. *dp = (png_byte)((v >> 8) & 0xff);
  169555. *(dp + 1) = (png_byte)(v & 0xff);
  169556. }
  169557. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169558. else if (a == 0)
  169559. #else
  169560. else
  169561. #endif
  169562. {
  169563. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169564. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169565. }
  169566. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169567. else
  169568. {
  169569. png_uint_16 g, v, w;
  169570. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169571. png_composite_16(v, g, a, background_1->gray);
  169572. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169573. *dp = (png_byte)((w >> 8) & 0xff);
  169574. *(dp + 1) = (png_byte)(w & 0xff);
  169575. }
  169576. #endif
  169577. }
  169578. }
  169579. else
  169580. #endif
  169581. {
  169582. sp = row;
  169583. dp = row;
  169584. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169585. {
  169586. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169587. if (a == (png_uint_16)0xffff)
  169588. {
  169589. png_memcpy(dp, sp, 2);
  169590. }
  169591. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169592. else if (a == 0)
  169593. #else
  169594. else
  169595. #endif
  169596. {
  169597. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169598. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169599. }
  169600. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169601. else
  169602. {
  169603. png_uint_16 g, v;
  169604. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169605. png_composite_16(v, g, a, background_1->gray);
  169606. *dp = (png_byte)((v >> 8) & 0xff);
  169607. *(dp + 1) = (png_byte)(v & 0xff);
  169608. }
  169609. #endif
  169610. }
  169611. }
  169612. }
  169613. break;
  169614. }
  169615. case PNG_COLOR_TYPE_RGB_ALPHA:
  169616. {
  169617. if (row_info->bit_depth == 8)
  169618. {
  169619. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169620. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169621. gamma_table != NULL)
  169622. {
  169623. sp = row;
  169624. dp = row;
  169625. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169626. {
  169627. png_byte a = *(sp + 3);
  169628. if (a == 0xff)
  169629. {
  169630. *dp = gamma_table[*sp];
  169631. *(dp + 1) = gamma_table[*(sp + 1)];
  169632. *(dp + 2) = gamma_table[*(sp + 2)];
  169633. }
  169634. else if (a == 0)
  169635. {
  169636. *dp = (png_byte)background->red;
  169637. *(dp + 1) = (png_byte)background->green;
  169638. *(dp + 2) = (png_byte)background->blue;
  169639. }
  169640. else
  169641. {
  169642. png_byte v, w;
  169643. v = gamma_to_1[*sp];
  169644. png_composite(w, v, a, background_1->red);
  169645. *dp = gamma_from_1[w];
  169646. v = gamma_to_1[*(sp + 1)];
  169647. png_composite(w, v, a, background_1->green);
  169648. *(dp + 1) = gamma_from_1[w];
  169649. v = gamma_to_1[*(sp + 2)];
  169650. png_composite(w, v, a, background_1->blue);
  169651. *(dp + 2) = gamma_from_1[w];
  169652. }
  169653. }
  169654. }
  169655. else
  169656. #endif
  169657. {
  169658. sp = row;
  169659. dp = row;
  169660. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169661. {
  169662. png_byte a = *(sp + 3);
  169663. if (a == 0xff)
  169664. {
  169665. *dp = *sp;
  169666. *(dp + 1) = *(sp + 1);
  169667. *(dp + 2) = *(sp + 2);
  169668. }
  169669. else if (a == 0)
  169670. {
  169671. *dp = (png_byte)background->red;
  169672. *(dp + 1) = (png_byte)background->green;
  169673. *(dp + 2) = (png_byte)background->blue;
  169674. }
  169675. else
  169676. {
  169677. png_composite(*dp, *sp, a, background->red);
  169678. png_composite(*(dp + 1), *(sp + 1), a,
  169679. background->green);
  169680. png_composite(*(dp + 2), *(sp + 2), a,
  169681. background->blue);
  169682. }
  169683. }
  169684. }
  169685. }
  169686. else /* if (row_info->bit_depth == 16) */
  169687. {
  169688. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169689. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169690. gamma_16_to_1 != NULL)
  169691. {
  169692. sp = row;
  169693. dp = row;
  169694. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169695. {
  169696. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169697. << 8) + (png_uint_16)(*(sp + 7)));
  169698. if (a == (png_uint_16)0xffff)
  169699. {
  169700. png_uint_16 v;
  169701. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169702. *dp = (png_byte)((v >> 8) & 0xff);
  169703. *(dp + 1) = (png_byte)(v & 0xff);
  169704. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169705. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169706. *(dp + 3) = (png_byte)(v & 0xff);
  169707. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169708. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169709. *(dp + 5) = (png_byte)(v & 0xff);
  169710. }
  169711. else if (a == 0)
  169712. {
  169713. *dp = (png_byte)((background->red >> 8) & 0xff);
  169714. *(dp + 1) = (png_byte)(background->red & 0xff);
  169715. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169716. *(dp + 3) = (png_byte)(background->green & 0xff);
  169717. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169718. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169719. }
  169720. else
  169721. {
  169722. png_uint_16 v, w, x;
  169723. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169724. png_composite_16(w, v, a, background_1->red);
  169725. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169726. *dp = (png_byte)((x >> 8) & 0xff);
  169727. *(dp + 1) = (png_byte)(x & 0xff);
  169728. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169729. png_composite_16(w, v, a, background_1->green);
  169730. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169731. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169732. *(dp + 3) = (png_byte)(x & 0xff);
  169733. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169734. png_composite_16(w, v, a, background_1->blue);
  169735. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169736. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169737. *(dp + 5) = (png_byte)(x & 0xff);
  169738. }
  169739. }
  169740. }
  169741. else
  169742. #endif
  169743. {
  169744. sp = row;
  169745. dp = row;
  169746. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169747. {
  169748. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169749. << 8) + (png_uint_16)(*(sp + 7)));
  169750. if (a == (png_uint_16)0xffff)
  169751. {
  169752. png_memcpy(dp, sp, 6);
  169753. }
  169754. else if (a == 0)
  169755. {
  169756. *dp = (png_byte)((background->red >> 8) & 0xff);
  169757. *(dp + 1) = (png_byte)(background->red & 0xff);
  169758. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169759. *(dp + 3) = (png_byte)(background->green & 0xff);
  169760. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169761. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169762. }
  169763. else
  169764. {
  169765. png_uint_16 v;
  169766. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169767. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169768. + *(sp + 3));
  169769. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169770. + *(sp + 5));
  169771. png_composite_16(v, r, a, background->red);
  169772. *dp = (png_byte)((v >> 8) & 0xff);
  169773. *(dp + 1) = (png_byte)(v & 0xff);
  169774. png_composite_16(v, g, a, background->green);
  169775. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169776. *(dp + 3) = (png_byte)(v & 0xff);
  169777. png_composite_16(v, b, a, background->blue);
  169778. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169779. *(dp + 5) = (png_byte)(v & 0xff);
  169780. }
  169781. }
  169782. }
  169783. }
  169784. break;
  169785. }
  169786. }
  169787. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169788. {
  169789. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169790. row_info->channels--;
  169791. row_info->pixel_depth = (png_byte)(row_info->channels *
  169792. row_info->bit_depth);
  169793. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169794. }
  169795. }
  169796. }
  169797. #endif
  169798. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169799. void /* PRIVATE */
  169800. png_do_gamma(png_row_infop row_info, png_bytep row,
  169801. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169802. int gamma_shift)
  169803. {
  169804. png_bytep sp;
  169805. png_uint_32 i;
  169806. png_uint_32 row_width=row_info->width;
  169807. png_debug(1, "in png_do_gamma\n");
  169808. if (
  169809. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169810. row != NULL && row_info != NULL &&
  169811. #endif
  169812. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169813. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169814. {
  169815. switch (row_info->color_type)
  169816. {
  169817. case PNG_COLOR_TYPE_RGB:
  169818. {
  169819. if (row_info->bit_depth == 8)
  169820. {
  169821. sp = row;
  169822. for (i = 0; i < row_width; i++)
  169823. {
  169824. *sp = gamma_table[*sp];
  169825. sp++;
  169826. *sp = gamma_table[*sp];
  169827. sp++;
  169828. *sp = gamma_table[*sp];
  169829. sp++;
  169830. }
  169831. }
  169832. else /* if (row_info->bit_depth == 16) */
  169833. {
  169834. sp = row;
  169835. for (i = 0; i < row_width; i++)
  169836. {
  169837. png_uint_16 v;
  169838. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169839. *sp = (png_byte)((v >> 8) & 0xff);
  169840. *(sp + 1) = (png_byte)(v & 0xff);
  169841. sp += 2;
  169842. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169843. *sp = (png_byte)((v >> 8) & 0xff);
  169844. *(sp + 1) = (png_byte)(v & 0xff);
  169845. sp += 2;
  169846. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169847. *sp = (png_byte)((v >> 8) & 0xff);
  169848. *(sp + 1) = (png_byte)(v & 0xff);
  169849. sp += 2;
  169850. }
  169851. }
  169852. break;
  169853. }
  169854. case PNG_COLOR_TYPE_RGB_ALPHA:
  169855. {
  169856. if (row_info->bit_depth == 8)
  169857. {
  169858. sp = row;
  169859. for (i = 0; i < row_width; i++)
  169860. {
  169861. *sp = gamma_table[*sp];
  169862. sp++;
  169863. *sp = gamma_table[*sp];
  169864. sp++;
  169865. *sp = gamma_table[*sp];
  169866. sp++;
  169867. sp++;
  169868. }
  169869. }
  169870. else /* if (row_info->bit_depth == 16) */
  169871. {
  169872. sp = row;
  169873. for (i = 0; i < row_width; i++)
  169874. {
  169875. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169876. *sp = (png_byte)((v >> 8) & 0xff);
  169877. *(sp + 1) = (png_byte)(v & 0xff);
  169878. sp += 2;
  169879. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169880. *sp = (png_byte)((v >> 8) & 0xff);
  169881. *(sp + 1) = (png_byte)(v & 0xff);
  169882. sp += 2;
  169883. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169884. *sp = (png_byte)((v >> 8) & 0xff);
  169885. *(sp + 1) = (png_byte)(v & 0xff);
  169886. sp += 4;
  169887. }
  169888. }
  169889. break;
  169890. }
  169891. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169892. {
  169893. if (row_info->bit_depth == 8)
  169894. {
  169895. sp = row;
  169896. for (i = 0; i < row_width; i++)
  169897. {
  169898. *sp = gamma_table[*sp];
  169899. sp += 2;
  169900. }
  169901. }
  169902. else /* if (row_info->bit_depth == 16) */
  169903. {
  169904. sp = row;
  169905. for (i = 0; i < row_width; i++)
  169906. {
  169907. png_uint_16 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 += 4;
  169911. }
  169912. }
  169913. break;
  169914. }
  169915. case PNG_COLOR_TYPE_GRAY:
  169916. {
  169917. if (row_info->bit_depth == 2)
  169918. {
  169919. sp = row;
  169920. for (i = 0; i < row_width; i += 4)
  169921. {
  169922. int a = *sp & 0xc0;
  169923. int b = *sp & 0x30;
  169924. int c = *sp & 0x0c;
  169925. int d = *sp & 0x03;
  169926. *sp = (png_byte)(
  169927. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169928. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169929. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169930. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  169931. sp++;
  169932. }
  169933. }
  169934. if (row_info->bit_depth == 4)
  169935. {
  169936. sp = row;
  169937. for (i = 0; i < row_width; i += 2)
  169938. {
  169939. int msb = *sp & 0xf0;
  169940. int lsb = *sp & 0x0f;
  169941. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  169942. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  169943. sp++;
  169944. }
  169945. }
  169946. else if (row_info->bit_depth == 8)
  169947. {
  169948. sp = row;
  169949. for (i = 0; i < row_width; i++)
  169950. {
  169951. *sp = gamma_table[*sp];
  169952. sp++;
  169953. }
  169954. }
  169955. else if (row_info->bit_depth == 16)
  169956. {
  169957. sp = row;
  169958. for (i = 0; i < row_width; i++)
  169959. {
  169960. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169961. *sp = (png_byte)((v >> 8) & 0xff);
  169962. *(sp + 1) = (png_byte)(v & 0xff);
  169963. sp += 2;
  169964. }
  169965. }
  169966. break;
  169967. }
  169968. }
  169969. }
  169970. }
  169971. #endif
  169972. #if defined(PNG_READ_EXPAND_SUPPORTED)
  169973. void /* PRIVATE */
  169974. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  169975. png_colorp palette, png_bytep trans, int num_trans)
  169976. {
  169977. int shift, value;
  169978. png_bytep sp, dp;
  169979. png_uint_32 i;
  169980. png_uint_32 row_width=row_info->width;
  169981. png_debug(1, "in png_do_expand_palette\n");
  169982. if (
  169983. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169984. row != NULL && row_info != NULL &&
  169985. #endif
  169986. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  169987. {
  169988. if (row_info->bit_depth < 8)
  169989. {
  169990. switch (row_info->bit_depth)
  169991. {
  169992. case 1:
  169993. {
  169994. sp = row + (png_size_t)((row_width - 1) >> 3);
  169995. dp = row + (png_size_t)row_width - 1;
  169996. shift = 7 - (int)((row_width + 7) & 0x07);
  169997. for (i = 0; i < row_width; i++)
  169998. {
  169999. if ((*sp >> shift) & 0x01)
  170000. *dp = 1;
  170001. else
  170002. *dp = 0;
  170003. if (shift == 7)
  170004. {
  170005. shift = 0;
  170006. sp--;
  170007. }
  170008. else
  170009. shift++;
  170010. dp--;
  170011. }
  170012. break;
  170013. }
  170014. case 2:
  170015. {
  170016. sp = row + (png_size_t)((row_width - 1) >> 2);
  170017. dp = row + (png_size_t)row_width - 1;
  170018. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170019. for (i = 0; i < row_width; i++)
  170020. {
  170021. value = (*sp >> shift) & 0x03;
  170022. *dp = (png_byte)value;
  170023. if (shift == 6)
  170024. {
  170025. shift = 0;
  170026. sp--;
  170027. }
  170028. else
  170029. shift += 2;
  170030. dp--;
  170031. }
  170032. break;
  170033. }
  170034. case 4:
  170035. {
  170036. sp = row + (png_size_t)((row_width - 1) >> 1);
  170037. dp = row + (png_size_t)row_width - 1;
  170038. shift = (int)((row_width & 0x01) << 2);
  170039. for (i = 0; i < row_width; i++)
  170040. {
  170041. value = (*sp >> shift) & 0x0f;
  170042. *dp = (png_byte)value;
  170043. if (shift == 4)
  170044. {
  170045. shift = 0;
  170046. sp--;
  170047. }
  170048. else
  170049. shift += 4;
  170050. dp--;
  170051. }
  170052. break;
  170053. }
  170054. }
  170055. row_info->bit_depth = 8;
  170056. row_info->pixel_depth = 8;
  170057. row_info->rowbytes = row_width;
  170058. }
  170059. switch (row_info->bit_depth)
  170060. {
  170061. case 8:
  170062. {
  170063. if (trans != NULL)
  170064. {
  170065. sp = row + (png_size_t)row_width - 1;
  170066. dp = row + (png_size_t)(row_width << 2) - 1;
  170067. for (i = 0; i < row_width; i++)
  170068. {
  170069. if ((int)(*sp) >= num_trans)
  170070. *dp-- = 0xff;
  170071. else
  170072. *dp-- = trans[*sp];
  170073. *dp-- = palette[*sp].blue;
  170074. *dp-- = palette[*sp].green;
  170075. *dp-- = palette[*sp].red;
  170076. sp--;
  170077. }
  170078. row_info->bit_depth = 8;
  170079. row_info->pixel_depth = 32;
  170080. row_info->rowbytes = row_width * 4;
  170081. row_info->color_type = 6;
  170082. row_info->channels = 4;
  170083. }
  170084. else
  170085. {
  170086. sp = row + (png_size_t)row_width - 1;
  170087. dp = row + (png_size_t)(row_width * 3) - 1;
  170088. for (i = 0; i < row_width; i++)
  170089. {
  170090. *dp-- = palette[*sp].blue;
  170091. *dp-- = palette[*sp].green;
  170092. *dp-- = palette[*sp].red;
  170093. sp--;
  170094. }
  170095. row_info->bit_depth = 8;
  170096. row_info->pixel_depth = 24;
  170097. row_info->rowbytes = row_width * 3;
  170098. row_info->color_type = 2;
  170099. row_info->channels = 3;
  170100. }
  170101. break;
  170102. }
  170103. }
  170104. }
  170105. }
  170106. void /* PRIVATE */
  170107. png_do_expand(png_row_infop row_info, png_bytep row,
  170108. png_color_16p trans_value)
  170109. {
  170110. int shift, value;
  170111. png_bytep sp, dp;
  170112. png_uint_32 i;
  170113. png_uint_32 row_width=row_info->width;
  170114. png_debug(1, "in png_do_expand\n");
  170115. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170116. if (row != NULL && row_info != NULL)
  170117. #endif
  170118. {
  170119. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170120. {
  170121. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170122. if (row_info->bit_depth < 8)
  170123. {
  170124. switch (row_info->bit_depth)
  170125. {
  170126. case 1:
  170127. {
  170128. gray = (png_uint_16)((gray&0x01)*0xff);
  170129. sp = row + (png_size_t)((row_width - 1) >> 3);
  170130. dp = row + (png_size_t)row_width - 1;
  170131. shift = 7 - (int)((row_width + 7) & 0x07);
  170132. for (i = 0; i < row_width; i++)
  170133. {
  170134. if ((*sp >> shift) & 0x01)
  170135. *dp = 0xff;
  170136. else
  170137. *dp = 0;
  170138. if (shift == 7)
  170139. {
  170140. shift = 0;
  170141. sp--;
  170142. }
  170143. else
  170144. shift++;
  170145. dp--;
  170146. }
  170147. break;
  170148. }
  170149. case 2:
  170150. {
  170151. gray = (png_uint_16)((gray&0x03)*0x55);
  170152. sp = row + (png_size_t)((row_width - 1) >> 2);
  170153. dp = row + (png_size_t)row_width - 1;
  170154. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170155. for (i = 0; i < row_width; i++)
  170156. {
  170157. value = (*sp >> shift) & 0x03;
  170158. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170159. (value << 6));
  170160. if (shift == 6)
  170161. {
  170162. shift = 0;
  170163. sp--;
  170164. }
  170165. else
  170166. shift += 2;
  170167. dp--;
  170168. }
  170169. break;
  170170. }
  170171. case 4:
  170172. {
  170173. gray = (png_uint_16)((gray&0x0f)*0x11);
  170174. sp = row + (png_size_t)((row_width - 1) >> 1);
  170175. dp = row + (png_size_t)row_width - 1;
  170176. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170177. for (i = 0; i < row_width; i++)
  170178. {
  170179. value = (*sp >> shift) & 0x0f;
  170180. *dp = (png_byte)(value | (value << 4));
  170181. if (shift == 4)
  170182. {
  170183. shift = 0;
  170184. sp--;
  170185. }
  170186. else
  170187. shift = 4;
  170188. dp--;
  170189. }
  170190. break;
  170191. }
  170192. }
  170193. row_info->bit_depth = 8;
  170194. row_info->pixel_depth = 8;
  170195. row_info->rowbytes = row_width;
  170196. }
  170197. if (trans_value != NULL)
  170198. {
  170199. if (row_info->bit_depth == 8)
  170200. {
  170201. gray = gray & 0xff;
  170202. sp = row + (png_size_t)row_width - 1;
  170203. dp = row + (png_size_t)(row_width << 1) - 1;
  170204. for (i = 0; i < row_width; i++)
  170205. {
  170206. if (*sp == gray)
  170207. *dp-- = 0;
  170208. else
  170209. *dp-- = 0xff;
  170210. *dp-- = *sp--;
  170211. }
  170212. }
  170213. else if (row_info->bit_depth == 16)
  170214. {
  170215. png_byte gray_high = (gray >> 8) & 0xff;
  170216. png_byte gray_low = gray & 0xff;
  170217. sp = row + row_info->rowbytes - 1;
  170218. dp = row + (row_info->rowbytes << 1) - 1;
  170219. for (i = 0; i < row_width; i++)
  170220. {
  170221. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170222. {
  170223. *dp-- = 0;
  170224. *dp-- = 0;
  170225. }
  170226. else
  170227. {
  170228. *dp-- = 0xff;
  170229. *dp-- = 0xff;
  170230. }
  170231. *dp-- = *sp--;
  170232. *dp-- = *sp--;
  170233. }
  170234. }
  170235. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170236. row_info->channels = 2;
  170237. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170238. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170239. row_width);
  170240. }
  170241. }
  170242. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170243. {
  170244. if (row_info->bit_depth == 8)
  170245. {
  170246. png_byte red = trans_value->red & 0xff;
  170247. png_byte green = trans_value->green & 0xff;
  170248. png_byte blue = trans_value->blue & 0xff;
  170249. sp = row + (png_size_t)row_info->rowbytes - 1;
  170250. dp = row + (png_size_t)(row_width << 2) - 1;
  170251. for (i = 0; i < row_width; i++)
  170252. {
  170253. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170254. *dp-- = 0;
  170255. else
  170256. *dp-- = 0xff;
  170257. *dp-- = *sp--;
  170258. *dp-- = *sp--;
  170259. *dp-- = *sp--;
  170260. }
  170261. }
  170262. else if (row_info->bit_depth == 16)
  170263. {
  170264. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170265. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170266. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170267. png_byte red_low = trans_value->red & 0xff;
  170268. png_byte green_low = trans_value->green & 0xff;
  170269. png_byte blue_low = trans_value->blue & 0xff;
  170270. sp = row + row_info->rowbytes - 1;
  170271. dp = row + (png_size_t)(row_width << 3) - 1;
  170272. for (i = 0; i < row_width; i++)
  170273. {
  170274. if (*(sp - 5) == red_high &&
  170275. *(sp - 4) == red_low &&
  170276. *(sp - 3) == green_high &&
  170277. *(sp - 2) == green_low &&
  170278. *(sp - 1) == blue_high &&
  170279. *(sp ) == blue_low)
  170280. {
  170281. *dp-- = 0;
  170282. *dp-- = 0;
  170283. }
  170284. else
  170285. {
  170286. *dp-- = 0xff;
  170287. *dp-- = 0xff;
  170288. }
  170289. *dp-- = *sp--;
  170290. *dp-- = *sp--;
  170291. *dp-- = *sp--;
  170292. *dp-- = *sp--;
  170293. *dp-- = *sp--;
  170294. *dp-- = *sp--;
  170295. }
  170296. }
  170297. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170298. row_info->channels = 4;
  170299. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170300. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170301. }
  170302. }
  170303. }
  170304. #endif
  170305. #if defined(PNG_READ_DITHER_SUPPORTED)
  170306. void /* PRIVATE */
  170307. png_do_dither(png_row_infop row_info, png_bytep row,
  170308. png_bytep palette_lookup, png_bytep dither_lookup)
  170309. {
  170310. png_bytep sp, dp;
  170311. png_uint_32 i;
  170312. png_uint_32 row_width=row_info->width;
  170313. png_debug(1, "in png_do_dither\n");
  170314. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170315. if (row != NULL && row_info != NULL)
  170316. #endif
  170317. {
  170318. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170319. palette_lookup && row_info->bit_depth == 8)
  170320. {
  170321. int r, g, b, p;
  170322. sp = row;
  170323. dp = row;
  170324. for (i = 0; i < row_width; i++)
  170325. {
  170326. r = *sp++;
  170327. g = *sp++;
  170328. b = *sp++;
  170329. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170330. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170331. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170332. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170333. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170334. (PNG_DITHER_BLUE_BITS)) |
  170335. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170336. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170337. *dp++ = palette_lookup[p];
  170338. }
  170339. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170340. row_info->channels = 1;
  170341. row_info->pixel_depth = row_info->bit_depth;
  170342. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170343. }
  170344. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170345. palette_lookup != NULL && row_info->bit_depth == 8)
  170346. {
  170347. int r, g, b, p;
  170348. sp = row;
  170349. dp = row;
  170350. for (i = 0; i < row_width; i++)
  170351. {
  170352. r = *sp++;
  170353. g = *sp++;
  170354. b = *sp++;
  170355. sp++;
  170356. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170357. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170358. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170359. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170360. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170361. (PNG_DITHER_BLUE_BITS)) |
  170362. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170363. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170364. *dp++ = palette_lookup[p];
  170365. }
  170366. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170367. row_info->channels = 1;
  170368. row_info->pixel_depth = row_info->bit_depth;
  170369. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170370. }
  170371. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170372. dither_lookup && row_info->bit_depth == 8)
  170373. {
  170374. sp = row;
  170375. for (i = 0; i < row_width; i++, sp++)
  170376. {
  170377. *sp = dither_lookup[*sp];
  170378. }
  170379. }
  170380. }
  170381. }
  170382. #endif
  170383. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170384. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170385. static PNG_CONST int png_gamma_shift[] =
  170386. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170387. void /* PRIVATE */
  170388. png_build_gamma_table(png_structp png_ptr)
  170389. {
  170390. png_debug(1, "in png_build_gamma_table\n");
  170391. if (png_ptr->bit_depth <= 8)
  170392. {
  170393. int i;
  170394. double g;
  170395. if (png_ptr->screen_gamma > .000001)
  170396. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170397. else
  170398. g = 1.0;
  170399. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170400. (png_uint_32)256);
  170401. for (i = 0; i < 256; i++)
  170402. {
  170403. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170404. g) * 255.0 + .5);
  170405. }
  170406. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170407. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170408. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170409. {
  170410. g = 1.0 / (png_ptr->gamma);
  170411. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170412. (png_uint_32)256);
  170413. for (i = 0; i < 256; i++)
  170414. {
  170415. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170416. g) * 255.0 + .5);
  170417. }
  170418. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170419. (png_uint_32)256);
  170420. if(png_ptr->screen_gamma > 0.000001)
  170421. g = 1.0 / png_ptr->screen_gamma;
  170422. else
  170423. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170424. for (i = 0; i < 256; i++)
  170425. {
  170426. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170427. g) * 255.0 + .5);
  170428. }
  170429. }
  170430. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170431. }
  170432. else
  170433. {
  170434. double g;
  170435. int i, j, shift, num;
  170436. int sig_bit;
  170437. png_uint_32 ig;
  170438. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170439. {
  170440. sig_bit = (int)png_ptr->sig_bit.red;
  170441. if ((int)png_ptr->sig_bit.green > sig_bit)
  170442. sig_bit = png_ptr->sig_bit.green;
  170443. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170444. sig_bit = png_ptr->sig_bit.blue;
  170445. }
  170446. else
  170447. {
  170448. sig_bit = (int)png_ptr->sig_bit.gray;
  170449. }
  170450. if (sig_bit > 0)
  170451. shift = 16 - sig_bit;
  170452. else
  170453. shift = 0;
  170454. if (png_ptr->transformations & PNG_16_TO_8)
  170455. {
  170456. if (shift < (16 - PNG_MAX_GAMMA_8))
  170457. shift = (16 - PNG_MAX_GAMMA_8);
  170458. }
  170459. if (shift > 8)
  170460. shift = 8;
  170461. if (shift < 0)
  170462. shift = 0;
  170463. png_ptr->gamma_shift = (png_byte)shift;
  170464. num = (1 << (8 - shift));
  170465. if (png_ptr->screen_gamma > .000001)
  170466. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170467. else
  170468. g = 1.0;
  170469. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170470. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170471. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170472. {
  170473. double fin, fout;
  170474. png_uint_32 last, max;
  170475. for (i = 0; i < num; i++)
  170476. {
  170477. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170478. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170479. }
  170480. g = 1.0 / g;
  170481. last = 0;
  170482. for (i = 0; i < 256; i++)
  170483. {
  170484. fout = ((double)i + 0.5) / 256.0;
  170485. fin = pow(fout, g);
  170486. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170487. while (last <= max)
  170488. {
  170489. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170490. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170491. (png_uint_16)i | ((png_uint_16)i << 8));
  170492. last++;
  170493. }
  170494. }
  170495. while (last < ((png_uint_32)num << 8))
  170496. {
  170497. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170498. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170499. last++;
  170500. }
  170501. }
  170502. else
  170503. {
  170504. for (i = 0; i < num; i++)
  170505. {
  170506. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170507. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170508. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170509. for (j = 0; j < 256; j++)
  170510. {
  170511. png_ptr->gamma_16_table[i][j] =
  170512. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170513. 65535.0, g) * 65535.0 + .5);
  170514. }
  170515. }
  170516. }
  170517. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170518. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170519. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170520. {
  170521. g = 1.0 / (png_ptr->gamma);
  170522. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170523. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170524. for (i = 0; i < num; i++)
  170525. {
  170526. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170527. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170528. ig = (((png_uint_32)i *
  170529. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170530. for (j = 0; j < 256; j++)
  170531. {
  170532. png_ptr->gamma_16_to_1[i][j] =
  170533. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170534. 65535.0, g) * 65535.0 + .5);
  170535. }
  170536. }
  170537. if(png_ptr->screen_gamma > 0.000001)
  170538. g = 1.0 / png_ptr->screen_gamma;
  170539. else
  170540. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170541. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170542. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170543. for (i = 0; i < num; i++)
  170544. {
  170545. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170546. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170547. ig = (((png_uint_32)i *
  170548. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170549. for (j = 0; j < 256; j++)
  170550. {
  170551. png_ptr->gamma_16_from_1[i][j] =
  170552. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170553. 65535.0, g) * 65535.0 + .5);
  170554. }
  170555. }
  170556. }
  170557. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170558. }
  170559. }
  170560. #endif
  170561. #endif
  170562. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170563. void /* PRIVATE */
  170564. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170565. {
  170566. png_debug(1, "in png_do_read_intrapixel\n");
  170567. if (
  170568. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170569. row != NULL && row_info != NULL &&
  170570. #endif
  170571. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170572. {
  170573. int bytes_per_pixel;
  170574. png_uint_32 row_width = row_info->width;
  170575. if (row_info->bit_depth == 8)
  170576. {
  170577. png_bytep rp;
  170578. png_uint_32 i;
  170579. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170580. bytes_per_pixel = 3;
  170581. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170582. bytes_per_pixel = 4;
  170583. else
  170584. return;
  170585. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170586. {
  170587. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170588. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170589. }
  170590. }
  170591. else if (row_info->bit_depth == 16)
  170592. {
  170593. png_bytep rp;
  170594. png_uint_32 i;
  170595. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170596. bytes_per_pixel = 6;
  170597. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170598. bytes_per_pixel = 8;
  170599. else
  170600. return;
  170601. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170602. {
  170603. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170604. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170605. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170606. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170607. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170608. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170609. *(rp+1) = (png_byte)(red & 0xff);
  170610. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170611. *(rp+5) = (png_byte)(blue & 0xff);
  170612. }
  170613. }
  170614. }
  170615. }
  170616. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170617. #endif /* PNG_READ_SUPPORTED */
  170618. /*** End of inlined file: pngrtran.c ***/
  170619. /*** Start of inlined file: pngrutil.c ***/
  170620. #define PNG_INTERNAL
  170621. #if defined(PNG_READ_SUPPORTED)
  170622. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170623. # define WIN32_WCE_OLD
  170624. #endif
  170625. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170626. # if defined(WIN32_WCE_OLD)
  170627. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170628. {
  170629. double result = 0;
  170630. int len;
  170631. wchar_t *str, *end;
  170632. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170633. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170634. if ( NULL != str )
  170635. {
  170636. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170637. result = wcstod(str, &end);
  170638. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170639. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170640. png_free(png_ptr, str);
  170641. }
  170642. return result;
  170643. }
  170644. # else
  170645. # define png_strtod(p,a,b) strtod(a,b)
  170646. # endif
  170647. #endif
  170648. png_uint_32 PNGAPI
  170649. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170650. {
  170651. png_uint_32 i = png_get_uint_32(buf);
  170652. if (i > PNG_UINT_31_MAX)
  170653. png_error(png_ptr, "PNG unsigned integer out of range.");
  170654. return (i);
  170655. }
  170656. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170657. png_uint_32 PNGAPI
  170658. png_get_uint_32(png_bytep buf)
  170659. {
  170660. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170661. ((png_uint_32)(*(buf + 1)) << 16) +
  170662. ((png_uint_32)(*(buf + 2)) << 8) +
  170663. (png_uint_32)(*(buf + 3));
  170664. return (i);
  170665. }
  170666. png_int_32 PNGAPI
  170667. png_get_int_32(png_bytep buf)
  170668. {
  170669. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170670. ((png_int_32)(*(buf + 1)) << 16) +
  170671. ((png_int_32)(*(buf + 2)) << 8) +
  170672. (png_int_32)(*(buf + 3));
  170673. return (i);
  170674. }
  170675. png_uint_16 PNGAPI
  170676. png_get_uint_16(png_bytep buf)
  170677. {
  170678. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170679. (png_uint_16)(*(buf + 1)));
  170680. return (i);
  170681. }
  170682. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170683. void /* PRIVATE */
  170684. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170685. {
  170686. if(png_ptr == NULL) return;
  170687. png_read_data(png_ptr, buf, length);
  170688. png_calculate_crc(png_ptr, buf, length);
  170689. }
  170690. int /* PRIVATE */
  170691. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170692. {
  170693. png_size_t i;
  170694. png_size_t istop = png_ptr->zbuf_size;
  170695. for (i = (png_size_t)skip; i > istop; i -= istop)
  170696. {
  170697. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170698. }
  170699. if (i)
  170700. {
  170701. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170702. }
  170703. if (png_crc_error(png_ptr))
  170704. {
  170705. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170706. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170707. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170708. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170709. {
  170710. png_chunk_warning(png_ptr, "CRC error");
  170711. }
  170712. else
  170713. {
  170714. png_chunk_error(png_ptr, "CRC error");
  170715. }
  170716. return (1);
  170717. }
  170718. return (0);
  170719. }
  170720. int /* PRIVATE */
  170721. png_crc_error(png_structp png_ptr)
  170722. {
  170723. png_byte crc_bytes[4];
  170724. png_uint_32 crc;
  170725. int need_crc = 1;
  170726. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170727. {
  170728. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170729. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170730. need_crc = 0;
  170731. }
  170732. else /* critical */
  170733. {
  170734. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170735. need_crc = 0;
  170736. }
  170737. png_read_data(png_ptr, crc_bytes, 4);
  170738. if (need_crc)
  170739. {
  170740. crc = png_get_uint_32(crc_bytes);
  170741. return ((int)(crc != png_ptr->crc));
  170742. }
  170743. else
  170744. return (0);
  170745. }
  170746. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170747. defined(PNG_READ_iCCP_SUPPORTED)
  170748. png_charp /* PRIVATE */
  170749. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170750. png_charp chunkdata, png_size_t chunklength,
  170751. png_size_t prefix_size, png_size_t *newlength)
  170752. {
  170753. static PNG_CONST char msg[] = "Error decoding compressed text";
  170754. png_charp text;
  170755. png_size_t text_size;
  170756. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170757. {
  170758. int ret = Z_OK;
  170759. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170760. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170761. png_ptr->zstream.next_out = png_ptr->zbuf;
  170762. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170763. text_size = 0;
  170764. text = NULL;
  170765. while (png_ptr->zstream.avail_in)
  170766. {
  170767. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170768. if (ret != Z_OK && ret != Z_STREAM_END)
  170769. {
  170770. if (png_ptr->zstream.msg != NULL)
  170771. png_warning(png_ptr, png_ptr->zstream.msg);
  170772. else
  170773. png_warning(png_ptr, msg);
  170774. inflateReset(&png_ptr->zstream);
  170775. png_ptr->zstream.avail_in = 0;
  170776. if (text == NULL)
  170777. {
  170778. text_size = prefix_size + png_sizeof(msg) + 1;
  170779. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170780. if (text == NULL)
  170781. {
  170782. png_free(png_ptr,chunkdata);
  170783. png_error(png_ptr,"Not enough memory to decompress chunk");
  170784. }
  170785. png_memcpy(text, chunkdata, prefix_size);
  170786. }
  170787. text[text_size - 1] = 0x00;
  170788. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170789. text_size = png_sizeof(msg) > text_size ? text_size :
  170790. png_sizeof(msg);
  170791. png_memcpy(text + prefix_size, msg, text_size + 1);
  170792. break;
  170793. }
  170794. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170795. {
  170796. if (text == NULL)
  170797. {
  170798. text_size = prefix_size +
  170799. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170800. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170801. if (text == NULL)
  170802. {
  170803. png_free(png_ptr,chunkdata);
  170804. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170805. }
  170806. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170807. text_size - prefix_size);
  170808. png_memcpy(text, chunkdata, prefix_size);
  170809. *(text + text_size) = 0x00;
  170810. }
  170811. else
  170812. {
  170813. png_charp tmp;
  170814. tmp = text;
  170815. text = (png_charp)png_malloc_warn(png_ptr,
  170816. (png_uint_32)(text_size +
  170817. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170818. if (text == NULL)
  170819. {
  170820. png_free(png_ptr, tmp);
  170821. png_free(png_ptr, chunkdata);
  170822. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170823. }
  170824. png_memcpy(text, tmp, text_size);
  170825. png_free(png_ptr, tmp);
  170826. png_memcpy(text + text_size, png_ptr->zbuf,
  170827. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170828. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170829. *(text + text_size) = 0x00;
  170830. }
  170831. if (ret == Z_STREAM_END)
  170832. break;
  170833. else
  170834. {
  170835. png_ptr->zstream.next_out = png_ptr->zbuf;
  170836. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170837. }
  170838. }
  170839. }
  170840. if (ret != Z_STREAM_END)
  170841. {
  170842. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170843. char umsg[52];
  170844. if (ret == Z_BUF_ERROR)
  170845. png_snprintf(umsg, 52,
  170846. "Buffer error in compressed datastream in %s chunk",
  170847. png_ptr->chunk_name);
  170848. else if (ret == Z_DATA_ERROR)
  170849. png_snprintf(umsg, 52,
  170850. "Data error in compressed datastream in %s chunk",
  170851. png_ptr->chunk_name);
  170852. else
  170853. png_snprintf(umsg, 52,
  170854. "Incomplete compressed datastream in %s chunk",
  170855. png_ptr->chunk_name);
  170856. png_warning(png_ptr, umsg);
  170857. #else
  170858. png_warning(png_ptr,
  170859. "Incomplete compressed datastream in chunk other than IDAT");
  170860. #endif
  170861. text_size=prefix_size;
  170862. if (text == NULL)
  170863. {
  170864. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170865. if (text == NULL)
  170866. {
  170867. png_free(png_ptr, chunkdata);
  170868. png_error(png_ptr,"Not enough memory for text.");
  170869. }
  170870. png_memcpy(text, chunkdata, prefix_size);
  170871. }
  170872. *(text + text_size) = 0x00;
  170873. }
  170874. inflateReset(&png_ptr->zstream);
  170875. png_ptr->zstream.avail_in = 0;
  170876. png_free(png_ptr, chunkdata);
  170877. chunkdata = text;
  170878. *newlength=text_size;
  170879. }
  170880. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170881. {
  170882. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170883. char umsg[50];
  170884. png_snprintf(umsg, 50,
  170885. "Unknown zTXt compression type %d", comp_type);
  170886. png_warning(png_ptr, umsg);
  170887. #else
  170888. png_warning(png_ptr, "Unknown zTXt compression type");
  170889. #endif
  170890. *(chunkdata + prefix_size) = 0x00;
  170891. *newlength=prefix_size;
  170892. }
  170893. return chunkdata;
  170894. }
  170895. #endif
  170896. void /* PRIVATE */
  170897. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170898. {
  170899. png_byte buf[13];
  170900. png_uint_32 width, height;
  170901. int bit_depth, color_type, compression_type, filter_type;
  170902. int interlace_type;
  170903. png_debug(1, "in png_handle_IHDR\n");
  170904. if (png_ptr->mode & PNG_HAVE_IHDR)
  170905. png_error(png_ptr, "Out of place IHDR");
  170906. if (length != 13)
  170907. png_error(png_ptr, "Invalid IHDR chunk");
  170908. png_ptr->mode |= PNG_HAVE_IHDR;
  170909. png_crc_read(png_ptr, buf, 13);
  170910. png_crc_finish(png_ptr, 0);
  170911. width = png_get_uint_31(png_ptr, buf);
  170912. height = png_get_uint_31(png_ptr, buf + 4);
  170913. bit_depth = buf[8];
  170914. color_type = buf[9];
  170915. compression_type = buf[10];
  170916. filter_type = buf[11];
  170917. interlace_type = buf[12];
  170918. png_ptr->width = width;
  170919. png_ptr->height = height;
  170920. png_ptr->bit_depth = (png_byte)bit_depth;
  170921. png_ptr->interlaced = (png_byte)interlace_type;
  170922. png_ptr->color_type = (png_byte)color_type;
  170923. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170924. png_ptr->filter_type = (png_byte)filter_type;
  170925. #endif
  170926. png_ptr->compression_type = (png_byte)compression_type;
  170927. switch (png_ptr->color_type)
  170928. {
  170929. case PNG_COLOR_TYPE_GRAY:
  170930. case PNG_COLOR_TYPE_PALETTE:
  170931. png_ptr->channels = 1;
  170932. break;
  170933. case PNG_COLOR_TYPE_RGB:
  170934. png_ptr->channels = 3;
  170935. break;
  170936. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170937. png_ptr->channels = 2;
  170938. break;
  170939. case PNG_COLOR_TYPE_RGB_ALPHA:
  170940. png_ptr->channels = 4;
  170941. break;
  170942. }
  170943. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  170944. png_ptr->channels);
  170945. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  170946. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  170947. png_debug1(3,"channels = %d\n", png_ptr->channels);
  170948. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  170949. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  170950. color_type, interlace_type, compression_type, filter_type);
  170951. }
  170952. void /* PRIVATE */
  170953. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170954. {
  170955. png_color palette[PNG_MAX_PALETTE_LENGTH];
  170956. int num, i;
  170957. #ifndef PNG_NO_POINTER_INDEXING
  170958. png_colorp pal_ptr;
  170959. #endif
  170960. png_debug(1, "in png_handle_PLTE\n");
  170961. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170962. png_error(png_ptr, "Missing IHDR before PLTE");
  170963. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170964. {
  170965. png_warning(png_ptr, "Invalid PLTE after IDAT");
  170966. png_crc_finish(png_ptr, length);
  170967. return;
  170968. }
  170969. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170970. png_error(png_ptr, "Duplicate PLTE chunk");
  170971. png_ptr->mode |= PNG_HAVE_PLTE;
  170972. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  170973. {
  170974. png_warning(png_ptr,
  170975. "Ignoring PLTE chunk in grayscale PNG");
  170976. png_crc_finish(png_ptr, length);
  170977. return;
  170978. }
  170979. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170980. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170981. {
  170982. png_crc_finish(png_ptr, length);
  170983. return;
  170984. }
  170985. #endif
  170986. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  170987. {
  170988. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170989. {
  170990. png_warning(png_ptr, "Invalid palette chunk");
  170991. png_crc_finish(png_ptr, length);
  170992. return;
  170993. }
  170994. else
  170995. {
  170996. png_error(png_ptr, "Invalid palette chunk");
  170997. }
  170998. }
  170999. num = (int)length / 3;
  171000. #ifndef PNG_NO_POINTER_INDEXING
  171001. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171002. {
  171003. png_byte buf[3];
  171004. png_crc_read(png_ptr, buf, 3);
  171005. pal_ptr->red = buf[0];
  171006. pal_ptr->green = buf[1];
  171007. pal_ptr->blue = buf[2];
  171008. }
  171009. #else
  171010. for (i = 0; i < num; i++)
  171011. {
  171012. png_byte buf[3];
  171013. png_crc_read(png_ptr, buf, 3);
  171014. palette[i].red = buf[0];
  171015. palette[i].green = buf[1];
  171016. palette[i].blue = buf[2];
  171017. }
  171018. #endif
  171019. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171020. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171021. #endif
  171022. {
  171023. png_crc_finish(png_ptr, 0);
  171024. }
  171025. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171026. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171027. {
  171028. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171029. {
  171030. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171031. {
  171032. png_chunk_error(png_ptr, "CRC error");
  171033. }
  171034. else
  171035. {
  171036. png_chunk_warning(png_ptr, "CRC error");
  171037. return;
  171038. }
  171039. }
  171040. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171041. {
  171042. png_chunk_warning(png_ptr, "CRC error");
  171043. }
  171044. }
  171045. #endif
  171046. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171047. #if defined(PNG_READ_tRNS_SUPPORTED)
  171048. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171049. {
  171050. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171051. {
  171052. if (png_ptr->num_trans > (png_uint_16)num)
  171053. {
  171054. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171055. png_ptr->num_trans = (png_uint_16)num;
  171056. }
  171057. if (info_ptr->num_trans > (png_uint_16)num)
  171058. {
  171059. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171060. info_ptr->num_trans = (png_uint_16)num;
  171061. }
  171062. }
  171063. }
  171064. #endif
  171065. }
  171066. void /* PRIVATE */
  171067. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171068. {
  171069. png_debug(1, "in png_handle_IEND\n");
  171070. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171071. {
  171072. png_error(png_ptr, "No image in file");
  171073. }
  171074. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171075. if (length != 0)
  171076. {
  171077. png_warning(png_ptr, "Incorrect IEND chunk length");
  171078. }
  171079. png_crc_finish(png_ptr, length);
  171080. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171081. }
  171082. #if defined(PNG_READ_gAMA_SUPPORTED)
  171083. void /* PRIVATE */
  171084. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171085. {
  171086. png_fixed_point igamma;
  171087. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171088. float file_gamma;
  171089. #endif
  171090. png_byte buf[4];
  171091. png_debug(1, "in png_handle_gAMA\n");
  171092. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171093. png_error(png_ptr, "Missing IHDR before gAMA");
  171094. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171095. {
  171096. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171097. png_crc_finish(png_ptr, length);
  171098. return;
  171099. }
  171100. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171101. png_warning(png_ptr, "Out of place gAMA chunk");
  171102. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171103. #if defined(PNG_READ_sRGB_SUPPORTED)
  171104. && !(info_ptr->valid & PNG_INFO_sRGB)
  171105. #endif
  171106. )
  171107. {
  171108. png_warning(png_ptr, "Duplicate gAMA chunk");
  171109. png_crc_finish(png_ptr, length);
  171110. return;
  171111. }
  171112. if (length != 4)
  171113. {
  171114. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171115. png_crc_finish(png_ptr, length);
  171116. return;
  171117. }
  171118. png_crc_read(png_ptr, buf, 4);
  171119. if (png_crc_finish(png_ptr, 0))
  171120. return;
  171121. igamma = (png_fixed_point)png_get_uint_32(buf);
  171122. if (igamma == 0)
  171123. {
  171124. png_warning(png_ptr,
  171125. "Ignoring gAMA chunk with gamma=0");
  171126. return;
  171127. }
  171128. #if defined(PNG_READ_sRGB_SUPPORTED)
  171129. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171130. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171131. {
  171132. png_warning(png_ptr,
  171133. "Ignoring incorrect gAMA value when sRGB is also present");
  171134. #ifndef PNG_NO_CONSOLE_IO
  171135. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171136. #endif
  171137. return;
  171138. }
  171139. #endif /* PNG_READ_sRGB_SUPPORTED */
  171140. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171141. file_gamma = (float)igamma / (float)100000.0;
  171142. # ifdef PNG_READ_GAMMA_SUPPORTED
  171143. png_ptr->gamma = file_gamma;
  171144. # endif
  171145. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171146. #endif
  171147. #ifdef PNG_FIXED_POINT_SUPPORTED
  171148. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171149. #endif
  171150. }
  171151. #endif
  171152. #if defined(PNG_READ_sBIT_SUPPORTED)
  171153. void /* PRIVATE */
  171154. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171155. {
  171156. png_size_t truelen;
  171157. png_byte buf[4];
  171158. png_debug(1, "in png_handle_sBIT\n");
  171159. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171160. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171161. png_error(png_ptr, "Missing IHDR before sBIT");
  171162. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171163. {
  171164. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171165. png_crc_finish(png_ptr, length);
  171166. return;
  171167. }
  171168. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171169. {
  171170. png_warning(png_ptr, "Out of place sBIT chunk");
  171171. }
  171172. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171173. {
  171174. png_warning(png_ptr, "Duplicate sBIT chunk");
  171175. png_crc_finish(png_ptr, length);
  171176. return;
  171177. }
  171178. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171179. truelen = 3;
  171180. else
  171181. truelen = (png_size_t)png_ptr->channels;
  171182. if (length != truelen || length > 4)
  171183. {
  171184. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171185. png_crc_finish(png_ptr, length);
  171186. return;
  171187. }
  171188. png_crc_read(png_ptr, buf, truelen);
  171189. if (png_crc_finish(png_ptr, 0))
  171190. return;
  171191. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171192. {
  171193. png_ptr->sig_bit.red = buf[0];
  171194. png_ptr->sig_bit.green = buf[1];
  171195. png_ptr->sig_bit.blue = buf[2];
  171196. png_ptr->sig_bit.alpha = buf[3];
  171197. }
  171198. else
  171199. {
  171200. png_ptr->sig_bit.gray = buf[0];
  171201. png_ptr->sig_bit.red = buf[0];
  171202. png_ptr->sig_bit.green = buf[0];
  171203. png_ptr->sig_bit.blue = buf[0];
  171204. png_ptr->sig_bit.alpha = buf[1];
  171205. }
  171206. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171207. }
  171208. #endif
  171209. #if defined(PNG_READ_cHRM_SUPPORTED)
  171210. void /* PRIVATE */
  171211. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171212. {
  171213. png_byte buf[4];
  171214. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171215. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171216. #endif
  171217. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171218. int_y_green, int_x_blue, int_y_blue;
  171219. png_uint_32 uint_x, uint_y;
  171220. png_debug(1, "in png_handle_cHRM\n");
  171221. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171222. png_error(png_ptr, "Missing IHDR before cHRM");
  171223. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171224. {
  171225. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171226. png_crc_finish(png_ptr, length);
  171227. return;
  171228. }
  171229. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171230. png_warning(png_ptr, "Missing PLTE before cHRM");
  171231. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171232. #if defined(PNG_READ_sRGB_SUPPORTED)
  171233. && !(info_ptr->valid & PNG_INFO_sRGB)
  171234. #endif
  171235. )
  171236. {
  171237. png_warning(png_ptr, "Duplicate cHRM chunk");
  171238. png_crc_finish(png_ptr, length);
  171239. return;
  171240. }
  171241. if (length != 32)
  171242. {
  171243. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171244. png_crc_finish(png_ptr, length);
  171245. return;
  171246. }
  171247. png_crc_read(png_ptr, buf, 4);
  171248. uint_x = png_get_uint_32(buf);
  171249. png_crc_read(png_ptr, buf, 4);
  171250. uint_y = png_get_uint_32(buf);
  171251. if (uint_x > 80000L || uint_y > 80000L ||
  171252. uint_x + uint_y > 100000L)
  171253. {
  171254. png_warning(png_ptr, "Invalid cHRM white point");
  171255. png_crc_finish(png_ptr, 24);
  171256. return;
  171257. }
  171258. int_x_white = (png_fixed_point)uint_x;
  171259. int_y_white = (png_fixed_point)uint_y;
  171260. png_crc_read(png_ptr, buf, 4);
  171261. uint_x = png_get_uint_32(buf);
  171262. png_crc_read(png_ptr, buf, 4);
  171263. uint_y = png_get_uint_32(buf);
  171264. if (uint_x + uint_y > 100000L)
  171265. {
  171266. png_warning(png_ptr, "Invalid cHRM red point");
  171267. png_crc_finish(png_ptr, 16);
  171268. return;
  171269. }
  171270. int_x_red = (png_fixed_point)uint_x;
  171271. int_y_red = (png_fixed_point)uint_y;
  171272. png_crc_read(png_ptr, buf, 4);
  171273. uint_x = png_get_uint_32(buf);
  171274. png_crc_read(png_ptr, buf, 4);
  171275. uint_y = png_get_uint_32(buf);
  171276. if (uint_x + uint_y > 100000L)
  171277. {
  171278. png_warning(png_ptr, "Invalid cHRM green point");
  171279. png_crc_finish(png_ptr, 8);
  171280. return;
  171281. }
  171282. int_x_green = (png_fixed_point)uint_x;
  171283. int_y_green = (png_fixed_point)uint_y;
  171284. png_crc_read(png_ptr, buf, 4);
  171285. uint_x = png_get_uint_32(buf);
  171286. png_crc_read(png_ptr, buf, 4);
  171287. uint_y = png_get_uint_32(buf);
  171288. if (uint_x + uint_y > 100000L)
  171289. {
  171290. png_warning(png_ptr, "Invalid cHRM blue point");
  171291. png_crc_finish(png_ptr, 0);
  171292. return;
  171293. }
  171294. int_x_blue = (png_fixed_point)uint_x;
  171295. int_y_blue = (png_fixed_point)uint_y;
  171296. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171297. white_x = (float)int_x_white / (float)100000.0;
  171298. white_y = (float)int_y_white / (float)100000.0;
  171299. red_x = (float)int_x_red / (float)100000.0;
  171300. red_y = (float)int_y_red / (float)100000.0;
  171301. green_x = (float)int_x_green / (float)100000.0;
  171302. green_y = (float)int_y_green / (float)100000.0;
  171303. blue_x = (float)int_x_blue / (float)100000.0;
  171304. blue_y = (float)int_y_blue / (float)100000.0;
  171305. #endif
  171306. #if defined(PNG_READ_sRGB_SUPPORTED)
  171307. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171308. {
  171309. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171310. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171311. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171312. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171313. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171314. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171315. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171316. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171317. {
  171318. png_warning(png_ptr,
  171319. "Ignoring incorrect cHRM value when sRGB is also present");
  171320. #ifndef PNG_NO_CONSOLE_IO
  171321. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171322. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171323. white_x, white_y, red_x, red_y);
  171324. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171325. green_x, green_y, blue_x, blue_y);
  171326. #else
  171327. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171328. int_x_white, int_y_white, int_x_red, int_y_red);
  171329. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171330. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171331. #endif
  171332. #endif /* PNG_NO_CONSOLE_IO */
  171333. }
  171334. png_crc_finish(png_ptr, 0);
  171335. return;
  171336. }
  171337. #endif /* PNG_READ_sRGB_SUPPORTED */
  171338. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171339. png_set_cHRM(png_ptr, info_ptr,
  171340. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171341. #endif
  171342. #ifdef PNG_FIXED_POINT_SUPPORTED
  171343. png_set_cHRM_fixed(png_ptr, info_ptr,
  171344. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171345. int_y_green, int_x_blue, int_y_blue);
  171346. #endif
  171347. if (png_crc_finish(png_ptr, 0))
  171348. return;
  171349. }
  171350. #endif
  171351. #if defined(PNG_READ_sRGB_SUPPORTED)
  171352. void /* PRIVATE */
  171353. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171354. {
  171355. int intent;
  171356. png_byte buf[1];
  171357. png_debug(1, "in png_handle_sRGB\n");
  171358. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171359. png_error(png_ptr, "Missing IHDR before sRGB");
  171360. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171361. {
  171362. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171363. png_crc_finish(png_ptr, length);
  171364. return;
  171365. }
  171366. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171367. png_warning(png_ptr, "Out of place sRGB chunk");
  171368. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171369. {
  171370. png_warning(png_ptr, "Duplicate sRGB chunk");
  171371. png_crc_finish(png_ptr, length);
  171372. return;
  171373. }
  171374. if (length != 1)
  171375. {
  171376. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171377. png_crc_finish(png_ptr, length);
  171378. return;
  171379. }
  171380. png_crc_read(png_ptr, buf, 1);
  171381. if (png_crc_finish(png_ptr, 0))
  171382. return;
  171383. intent = buf[0];
  171384. if (intent >= PNG_sRGB_INTENT_LAST)
  171385. {
  171386. png_warning(png_ptr, "Unknown sRGB intent");
  171387. return;
  171388. }
  171389. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171390. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171391. {
  171392. png_fixed_point igamma;
  171393. #ifdef PNG_FIXED_POINT_SUPPORTED
  171394. igamma=info_ptr->int_gamma;
  171395. #else
  171396. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171397. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171398. # endif
  171399. #endif
  171400. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171401. {
  171402. png_warning(png_ptr,
  171403. "Ignoring incorrect gAMA value when sRGB is also present");
  171404. #ifndef PNG_NO_CONSOLE_IO
  171405. # ifdef PNG_FIXED_POINT_SUPPORTED
  171406. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171407. # else
  171408. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171409. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171410. # endif
  171411. # endif
  171412. #endif
  171413. }
  171414. }
  171415. #endif /* PNG_READ_gAMA_SUPPORTED */
  171416. #ifdef PNG_READ_cHRM_SUPPORTED
  171417. #ifdef PNG_FIXED_POINT_SUPPORTED
  171418. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171419. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171420. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171421. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171422. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171423. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171424. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171425. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171426. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171427. {
  171428. png_warning(png_ptr,
  171429. "Ignoring incorrect cHRM value when sRGB is also present");
  171430. }
  171431. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171432. #endif /* PNG_READ_cHRM_SUPPORTED */
  171433. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171434. }
  171435. #endif /* PNG_READ_sRGB_SUPPORTED */
  171436. #if defined(PNG_READ_iCCP_SUPPORTED)
  171437. void /* PRIVATE */
  171438. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171439. {
  171440. png_charp chunkdata;
  171441. png_byte compression_type;
  171442. png_bytep pC;
  171443. png_charp profile;
  171444. png_uint_32 skip = 0;
  171445. png_uint_32 profile_size, profile_length;
  171446. png_size_t slength, prefix_length, data_length;
  171447. png_debug(1, "in png_handle_iCCP\n");
  171448. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171449. png_error(png_ptr, "Missing IHDR before iCCP");
  171450. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171451. {
  171452. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171453. png_crc_finish(png_ptr, length);
  171454. return;
  171455. }
  171456. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171457. png_warning(png_ptr, "Out of place iCCP chunk");
  171458. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171459. {
  171460. png_warning(png_ptr, "Duplicate iCCP chunk");
  171461. png_crc_finish(png_ptr, length);
  171462. return;
  171463. }
  171464. #ifdef PNG_MAX_MALLOC_64K
  171465. if (length > (png_uint_32)65535L)
  171466. {
  171467. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171468. skip = length - (png_uint_32)65535L;
  171469. length = (png_uint_32)65535L;
  171470. }
  171471. #endif
  171472. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171473. slength = (png_size_t)length;
  171474. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171475. if (png_crc_finish(png_ptr, skip))
  171476. {
  171477. png_free(png_ptr, chunkdata);
  171478. return;
  171479. }
  171480. chunkdata[slength] = 0x00;
  171481. for (profile = chunkdata; *profile; profile++)
  171482. ;
  171483. ++profile;
  171484. if ( profile >= chunkdata + slength - 1)
  171485. {
  171486. png_free(png_ptr, chunkdata);
  171487. png_warning(png_ptr, "Malformed iCCP chunk");
  171488. return;
  171489. }
  171490. compression_type = *profile++;
  171491. if (compression_type)
  171492. {
  171493. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171494. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171495. wrote nonzero) */
  171496. }
  171497. prefix_length = profile - chunkdata;
  171498. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171499. slength, prefix_length, &data_length);
  171500. profile_length = data_length - prefix_length;
  171501. if ( prefix_length > data_length || profile_length < 4)
  171502. {
  171503. png_free(png_ptr, chunkdata);
  171504. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171505. return;
  171506. }
  171507. pC = (png_bytep)(chunkdata+prefix_length);
  171508. profile_size = ((*(pC ))<<24) |
  171509. ((*(pC+1))<<16) |
  171510. ((*(pC+2))<< 8) |
  171511. ((*(pC+3)) );
  171512. if(profile_size < profile_length)
  171513. profile_length = profile_size;
  171514. if(profile_size > profile_length)
  171515. {
  171516. png_free(png_ptr, chunkdata);
  171517. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171518. return;
  171519. }
  171520. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171521. chunkdata + prefix_length, profile_length);
  171522. png_free(png_ptr, chunkdata);
  171523. }
  171524. #endif /* PNG_READ_iCCP_SUPPORTED */
  171525. #if defined(PNG_READ_sPLT_SUPPORTED)
  171526. void /* PRIVATE */
  171527. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171528. {
  171529. png_bytep chunkdata;
  171530. png_bytep entry_start;
  171531. png_sPLT_t new_palette;
  171532. #ifdef PNG_NO_POINTER_INDEXING
  171533. png_sPLT_entryp pp;
  171534. #endif
  171535. int data_length, entry_size, i;
  171536. png_uint_32 skip = 0;
  171537. png_size_t slength;
  171538. png_debug(1, "in png_handle_sPLT\n");
  171539. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171540. png_error(png_ptr, "Missing IHDR before sPLT");
  171541. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171542. {
  171543. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171544. png_crc_finish(png_ptr, length);
  171545. return;
  171546. }
  171547. #ifdef PNG_MAX_MALLOC_64K
  171548. if (length > (png_uint_32)65535L)
  171549. {
  171550. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171551. skip = length - (png_uint_32)65535L;
  171552. length = (png_uint_32)65535L;
  171553. }
  171554. #endif
  171555. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171556. slength = (png_size_t)length;
  171557. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171558. if (png_crc_finish(png_ptr, skip))
  171559. {
  171560. png_free(png_ptr, chunkdata);
  171561. return;
  171562. }
  171563. chunkdata[slength] = 0x00;
  171564. for (entry_start = chunkdata; *entry_start; entry_start++)
  171565. ;
  171566. ++entry_start;
  171567. if (entry_start > chunkdata + slength - 2)
  171568. {
  171569. png_free(png_ptr, chunkdata);
  171570. png_warning(png_ptr, "malformed sPLT chunk");
  171571. return;
  171572. }
  171573. new_palette.depth = *entry_start++;
  171574. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171575. data_length = (slength - (entry_start - chunkdata));
  171576. if (data_length % entry_size)
  171577. {
  171578. png_free(png_ptr, chunkdata);
  171579. png_warning(png_ptr, "sPLT chunk has bad length");
  171580. return;
  171581. }
  171582. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171583. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171584. png_sizeof(png_sPLT_entry)))
  171585. {
  171586. png_warning(png_ptr, "sPLT chunk too long");
  171587. return;
  171588. }
  171589. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171590. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171591. if (new_palette.entries == NULL)
  171592. {
  171593. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171594. return;
  171595. }
  171596. #ifndef PNG_NO_POINTER_INDEXING
  171597. for (i = 0; i < new_palette.nentries; i++)
  171598. {
  171599. png_sPLT_entryp pp = new_palette.entries + i;
  171600. if (new_palette.depth == 8)
  171601. {
  171602. pp->red = *entry_start++;
  171603. pp->green = *entry_start++;
  171604. pp->blue = *entry_start++;
  171605. pp->alpha = *entry_start++;
  171606. }
  171607. else
  171608. {
  171609. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171610. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171611. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171612. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171613. }
  171614. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171615. }
  171616. #else
  171617. pp = new_palette.entries;
  171618. for (i = 0; i < new_palette.nentries; i++)
  171619. {
  171620. if (new_palette.depth == 8)
  171621. {
  171622. pp[i].red = *entry_start++;
  171623. pp[i].green = *entry_start++;
  171624. pp[i].blue = *entry_start++;
  171625. pp[i].alpha = *entry_start++;
  171626. }
  171627. else
  171628. {
  171629. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171630. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171631. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171632. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171633. }
  171634. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171635. }
  171636. #endif
  171637. new_palette.name = (png_charp)chunkdata;
  171638. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171639. png_free(png_ptr, chunkdata);
  171640. png_free(png_ptr, new_palette.entries);
  171641. }
  171642. #endif /* PNG_READ_sPLT_SUPPORTED */
  171643. #if defined(PNG_READ_tRNS_SUPPORTED)
  171644. void /* PRIVATE */
  171645. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171646. {
  171647. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171648. int bit_mask;
  171649. png_debug(1, "in png_handle_tRNS\n");
  171650. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171651. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171652. png_error(png_ptr, "Missing IHDR before tRNS");
  171653. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171654. {
  171655. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171656. png_crc_finish(png_ptr, length);
  171657. return;
  171658. }
  171659. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171660. {
  171661. png_warning(png_ptr, "Duplicate tRNS chunk");
  171662. png_crc_finish(png_ptr, length);
  171663. return;
  171664. }
  171665. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171666. {
  171667. png_byte buf[2];
  171668. if (length != 2)
  171669. {
  171670. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171671. png_crc_finish(png_ptr, length);
  171672. return;
  171673. }
  171674. png_crc_read(png_ptr, buf, 2);
  171675. png_ptr->num_trans = 1;
  171676. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171677. }
  171678. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171679. {
  171680. png_byte buf[6];
  171681. if (length != 6)
  171682. {
  171683. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171684. png_crc_finish(png_ptr, length);
  171685. return;
  171686. }
  171687. png_crc_read(png_ptr, buf, (png_size_t)length);
  171688. png_ptr->num_trans = 1;
  171689. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171690. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171691. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171692. }
  171693. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171694. {
  171695. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171696. {
  171697. png_warning(png_ptr, "Missing PLTE before tRNS");
  171698. }
  171699. if (length > (png_uint_32)png_ptr->num_palette ||
  171700. length > PNG_MAX_PALETTE_LENGTH)
  171701. {
  171702. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171703. png_crc_finish(png_ptr, length);
  171704. return;
  171705. }
  171706. if (length == 0)
  171707. {
  171708. png_warning(png_ptr, "Zero length tRNS chunk");
  171709. png_crc_finish(png_ptr, length);
  171710. return;
  171711. }
  171712. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171713. png_ptr->num_trans = (png_uint_16)length;
  171714. }
  171715. else
  171716. {
  171717. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171718. png_crc_finish(png_ptr, length);
  171719. return;
  171720. }
  171721. if (png_crc_finish(png_ptr, 0))
  171722. {
  171723. png_ptr->num_trans = 0;
  171724. return;
  171725. }
  171726. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171727. &(png_ptr->trans_values));
  171728. }
  171729. #endif
  171730. #if defined(PNG_READ_bKGD_SUPPORTED)
  171731. void /* PRIVATE */
  171732. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171733. {
  171734. png_size_t truelen;
  171735. png_byte buf[6];
  171736. png_debug(1, "in png_handle_bKGD\n");
  171737. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171738. png_error(png_ptr, "Missing IHDR before bKGD");
  171739. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171740. {
  171741. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171742. png_crc_finish(png_ptr, length);
  171743. return;
  171744. }
  171745. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171746. !(png_ptr->mode & PNG_HAVE_PLTE))
  171747. {
  171748. png_warning(png_ptr, "Missing PLTE before bKGD");
  171749. png_crc_finish(png_ptr, length);
  171750. return;
  171751. }
  171752. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171753. {
  171754. png_warning(png_ptr, "Duplicate bKGD chunk");
  171755. png_crc_finish(png_ptr, length);
  171756. return;
  171757. }
  171758. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171759. truelen = 1;
  171760. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171761. truelen = 6;
  171762. else
  171763. truelen = 2;
  171764. if (length != truelen)
  171765. {
  171766. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171767. png_crc_finish(png_ptr, length);
  171768. return;
  171769. }
  171770. png_crc_read(png_ptr, buf, truelen);
  171771. if (png_crc_finish(png_ptr, 0))
  171772. return;
  171773. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171774. {
  171775. png_ptr->background.index = buf[0];
  171776. if(info_ptr->num_palette)
  171777. {
  171778. if(buf[0] > info_ptr->num_palette)
  171779. {
  171780. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171781. return;
  171782. }
  171783. png_ptr->background.red =
  171784. (png_uint_16)png_ptr->palette[buf[0]].red;
  171785. png_ptr->background.green =
  171786. (png_uint_16)png_ptr->palette[buf[0]].green;
  171787. png_ptr->background.blue =
  171788. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171789. }
  171790. }
  171791. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171792. {
  171793. png_ptr->background.red =
  171794. png_ptr->background.green =
  171795. png_ptr->background.blue =
  171796. png_ptr->background.gray = png_get_uint_16(buf);
  171797. }
  171798. else
  171799. {
  171800. png_ptr->background.red = png_get_uint_16(buf);
  171801. png_ptr->background.green = png_get_uint_16(buf + 2);
  171802. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171803. }
  171804. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171805. }
  171806. #endif
  171807. #if defined(PNG_READ_hIST_SUPPORTED)
  171808. void /* PRIVATE */
  171809. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171810. {
  171811. unsigned int num, i;
  171812. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171813. png_debug(1, "in png_handle_hIST\n");
  171814. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171815. png_error(png_ptr, "Missing IHDR before hIST");
  171816. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171817. {
  171818. png_warning(png_ptr, "Invalid hIST after IDAT");
  171819. png_crc_finish(png_ptr, length);
  171820. return;
  171821. }
  171822. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171823. {
  171824. png_warning(png_ptr, "Missing PLTE before hIST");
  171825. png_crc_finish(png_ptr, length);
  171826. return;
  171827. }
  171828. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171829. {
  171830. png_warning(png_ptr, "Duplicate hIST chunk");
  171831. png_crc_finish(png_ptr, length);
  171832. return;
  171833. }
  171834. num = length / 2 ;
  171835. if (num != (unsigned int) png_ptr->num_palette || num >
  171836. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171837. {
  171838. png_warning(png_ptr, "Incorrect hIST chunk length");
  171839. png_crc_finish(png_ptr, length);
  171840. return;
  171841. }
  171842. for (i = 0; i < num; i++)
  171843. {
  171844. png_byte buf[2];
  171845. png_crc_read(png_ptr, buf, 2);
  171846. readbuf[i] = png_get_uint_16(buf);
  171847. }
  171848. if (png_crc_finish(png_ptr, 0))
  171849. return;
  171850. png_set_hIST(png_ptr, info_ptr, readbuf);
  171851. }
  171852. #endif
  171853. #if defined(PNG_READ_pHYs_SUPPORTED)
  171854. void /* PRIVATE */
  171855. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171856. {
  171857. png_byte buf[9];
  171858. png_uint_32 res_x, res_y;
  171859. int unit_type;
  171860. png_debug(1, "in png_handle_pHYs\n");
  171861. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171862. png_error(png_ptr, "Missing IHDR before pHYs");
  171863. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171864. {
  171865. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171866. png_crc_finish(png_ptr, length);
  171867. return;
  171868. }
  171869. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171870. {
  171871. png_warning(png_ptr, "Duplicate pHYs chunk");
  171872. png_crc_finish(png_ptr, length);
  171873. return;
  171874. }
  171875. if (length != 9)
  171876. {
  171877. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171878. png_crc_finish(png_ptr, length);
  171879. return;
  171880. }
  171881. png_crc_read(png_ptr, buf, 9);
  171882. if (png_crc_finish(png_ptr, 0))
  171883. return;
  171884. res_x = png_get_uint_32(buf);
  171885. res_y = png_get_uint_32(buf + 4);
  171886. unit_type = buf[8];
  171887. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171888. }
  171889. #endif
  171890. #if defined(PNG_READ_oFFs_SUPPORTED)
  171891. void /* PRIVATE */
  171892. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171893. {
  171894. png_byte buf[9];
  171895. png_int_32 offset_x, offset_y;
  171896. int unit_type;
  171897. png_debug(1, "in png_handle_oFFs\n");
  171898. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171899. png_error(png_ptr, "Missing IHDR before oFFs");
  171900. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171901. {
  171902. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171903. png_crc_finish(png_ptr, length);
  171904. return;
  171905. }
  171906. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171907. {
  171908. png_warning(png_ptr, "Duplicate oFFs chunk");
  171909. png_crc_finish(png_ptr, length);
  171910. return;
  171911. }
  171912. if (length != 9)
  171913. {
  171914. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171915. png_crc_finish(png_ptr, length);
  171916. return;
  171917. }
  171918. png_crc_read(png_ptr, buf, 9);
  171919. if (png_crc_finish(png_ptr, 0))
  171920. return;
  171921. offset_x = png_get_int_32(buf);
  171922. offset_y = png_get_int_32(buf + 4);
  171923. unit_type = buf[8];
  171924. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171925. }
  171926. #endif
  171927. #if defined(PNG_READ_pCAL_SUPPORTED)
  171928. void /* PRIVATE */
  171929. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171930. {
  171931. png_charp purpose;
  171932. png_int_32 X0, X1;
  171933. png_byte type, nparams;
  171934. png_charp buf, units, endptr;
  171935. png_charpp params;
  171936. png_size_t slength;
  171937. int i;
  171938. png_debug(1, "in png_handle_pCAL\n");
  171939. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171940. png_error(png_ptr, "Missing IHDR before pCAL");
  171941. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171942. {
  171943. png_warning(png_ptr, "Invalid pCAL after IDAT");
  171944. png_crc_finish(png_ptr, length);
  171945. return;
  171946. }
  171947. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  171948. {
  171949. png_warning(png_ptr, "Duplicate pCAL chunk");
  171950. png_crc_finish(png_ptr, length);
  171951. return;
  171952. }
  171953. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  171954. length + 1);
  171955. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171956. if (purpose == NULL)
  171957. {
  171958. png_warning(png_ptr, "No memory for pCAL purpose.");
  171959. return;
  171960. }
  171961. slength = (png_size_t)length;
  171962. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  171963. if (png_crc_finish(png_ptr, 0))
  171964. {
  171965. png_free(png_ptr, purpose);
  171966. return;
  171967. }
  171968. purpose[slength] = 0x00; /* null terminate the last string */
  171969. png_debug(3, "Finding end of pCAL purpose string\n");
  171970. for (buf = purpose; *buf; buf++)
  171971. ;
  171972. endptr = purpose + slength;
  171973. if (endptr <= buf + 12)
  171974. {
  171975. png_warning(png_ptr, "Invalid pCAL data");
  171976. png_free(png_ptr, purpose);
  171977. return;
  171978. }
  171979. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  171980. X0 = png_get_int_32((png_bytep)buf+1);
  171981. X1 = png_get_int_32((png_bytep)buf+5);
  171982. type = buf[9];
  171983. nparams = buf[10];
  171984. units = buf + 11;
  171985. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  171986. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  171987. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  171988. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  171989. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  171990. {
  171991. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  171992. png_free(png_ptr, purpose);
  171993. return;
  171994. }
  171995. else if (type >= PNG_EQUATION_LAST)
  171996. {
  171997. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  171998. }
  171999. for (buf = units; *buf; buf++)
  172000. ;
  172001. png_debug(3, "Allocating pCAL parameters array\n");
  172002. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172003. *png_sizeof(png_charp))) ;
  172004. if (params == NULL)
  172005. {
  172006. png_free(png_ptr, purpose);
  172007. png_warning(png_ptr, "No memory for pCAL params.");
  172008. return;
  172009. }
  172010. for (i = 0; i < (int)nparams; i++)
  172011. {
  172012. buf++; /* Skip the null string terminator from previous parameter. */
  172013. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172014. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172015. ;
  172016. if (buf > endptr)
  172017. {
  172018. png_warning(png_ptr, "Invalid pCAL data");
  172019. png_free(png_ptr, purpose);
  172020. png_free(png_ptr, params);
  172021. return;
  172022. }
  172023. }
  172024. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172025. units, params);
  172026. png_free(png_ptr, purpose);
  172027. png_free(png_ptr, params);
  172028. }
  172029. #endif
  172030. #if defined(PNG_READ_sCAL_SUPPORTED)
  172031. void /* PRIVATE */
  172032. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172033. {
  172034. png_charp buffer, ep;
  172035. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172036. double width, height;
  172037. png_charp vp;
  172038. #else
  172039. #ifdef PNG_FIXED_POINT_SUPPORTED
  172040. png_charp swidth, sheight;
  172041. #endif
  172042. #endif
  172043. png_size_t slength;
  172044. png_debug(1, "in png_handle_sCAL\n");
  172045. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172046. png_error(png_ptr, "Missing IHDR before sCAL");
  172047. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172048. {
  172049. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172050. png_crc_finish(png_ptr, length);
  172051. return;
  172052. }
  172053. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172054. {
  172055. png_warning(png_ptr, "Duplicate sCAL chunk");
  172056. png_crc_finish(png_ptr, length);
  172057. return;
  172058. }
  172059. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172060. length + 1);
  172061. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172062. if (buffer == NULL)
  172063. {
  172064. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172065. return;
  172066. }
  172067. slength = (png_size_t)length;
  172068. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172069. if (png_crc_finish(png_ptr, 0))
  172070. {
  172071. png_free(png_ptr, buffer);
  172072. return;
  172073. }
  172074. buffer[slength] = 0x00; /* null terminate the last string */
  172075. ep = buffer + 1; /* skip unit byte */
  172076. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172077. width = png_strtod(png_ptr, ep, &vp);
  172078. if (*vp)
  172079. {
  172080. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172081. return;
  172082. }
  172083. #else
  172084. #ifdef PNG_FIXED_POINT_SUPPORTED
  172085. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172086. if (swidth == NULL)
  172087. {
  172088. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172089. return;
  172090. }
  172091. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172092. #endif
  172093. #endif
  172094. for (ep = buffer; *ep; ep++)
  172095. ;
  172096. ep++;
  172097. if (buffer + slength < ep)
  172098. {
  172099. png_warning(png_ptr, "Truncated sCAL chunk");
  172100. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172101. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172102. png_free(png_ptr, swidth);
  172103. #endif
  172104. png_free(png_ptr, buffer);
  172105. return;
  172106. }
  172107. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172108. height = png_strtod(png_ptr, ep, &vp);
  172109. if (*vp)
  172110. {
  172111. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172112. return;
  172113. }
  172114. #else
  172115. #ifdef PNG_FIXED_POINT_SUPPORTED
  172116. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172117. if (swidth == NULL)
  172118. {
  172119. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172120. return;
  172121. }
  172122. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172123. #endif
  172124. #endif
  172125. if (buffer + slength < ep
  172126. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172127. || width <= 0. || height <= 0.
  172128. #endif
  172129. )
  172130. {
  172131. png_warning(png_ptr, "Invalid sCAL data");
  172132. png_free(png_ptr, buffer);
  172133. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172134. png_free(png_ptr, swidth);
  172135. png_free(png_ptr, sheight);
  172136. #endif
  172137. return;
  172138. }
  172139. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172140. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172141. #else
  172142. #ifdef PNG_FIXED_POINT_SUPPORTED
  172143. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172144. #endif
  172145. #endif
  172146. png_free(png_ptr, buffer);
  172147. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172148. png_free(png_ptr, swidth);
  172149. png_free(png_ptr, sheight);
  172150. #endif
  172151. }
  172152. #endif
  172153. #if defined(PNG_READ_tIME_SUPPORTED)
  172154. void /* PRIVATE */
  172155. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172156. {
  172157. png_byte buf[7];
  172158. png_time mod_time;
  172159. png_debug(1, "in png_handle_tIME\n");
  172160. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172161. png_error(png_ptr, "Out of place tIME chunk");
  172162. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172163. {
  172164. png_warning(png_ptr, "Duplicate tIME chunk");
  172165. png_crc_finish(png_ptr, length);
  172166. return;
  172167. }
  172168. if (png_ptr->mode & PNG_HAVE_IDAT)
  172169. png_ptr->mode |= PNG_AFTER_IDAT;
  172170. if (length != 7)
  172171. {
  172172. png_warning(png_ptr, "Incorrect tIME chunk length");
  172173. png_crc_finish(png_ptr, length);
  172174. return;
  172175. }
  172176. png_crc_read(png_ptr, buf, 7);
  172177. if (png_crc_finish(png_ptr, 0))
  172178. return;
  172179. mod_time.second = buf[6];
  172180. mod_time.minute = buf[5];
  172181. mod_time.hour = buf[4];
  172182. mod_time.day = buf[3];
  172183. mod_time.month = buf[2];
  172184. mod_time.year = png_get_uint_16(buf);
  172185. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172186. }
  172187. #endif
  172188. #if defined(PNG_READ_tEXt_SUPPORTED)
  172189. void /* PRIVATE */
  172190. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172191. {
  172192. png_textp text_ptr;
  172193. png_charp key;
  172194. png_charp text;
  172195. png_uint_32 skip = 0;
  172196. png_size_t slength;
  172197. int ret;
  172198. png_debug(1, "in png_handle_tEXt\n");
  172199. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172200. png_error(png_ptr, "Missing IHDR before tEXt");
  172201. if (png_ptr->mode & PNG_HAVE_IDAT)
  172202. png_ptr->mode |= PNG_AFTER_IDAT;
  172203. #ifdef PNG_MAX_MALLOC_64K
  172204. if (length > (png_uint_32)65535L)
  172205. {
  172206. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172207. skip = length - (png_uint_32)65535L;
  172208. length = (png_uint_32)65535L;
  172209. }
  172210. #endif
  172211. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172212. if (key == NULL)
  172213. {
  172214. png_warning(png_ptr, "No memory to process text chunk.");
  172215. return;
  172216. }
  172217. slength = (png_size_t)length;
  172218. png_crc_read(png_ptr, (png_bytep)key, slength);
  172219. if (png_crc_finish(png_ptr, skip))
  172220. {
  172221. png_free(png_ptr, key);
  172222. return;
  172223. }
  172224. key[slength] = 0x00;
  172225. for (text = key; *text; text++)
  172226. ;
  172227. if (text != key + slength)
  172228. text++;
  172229. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172230. (png_uint_32)png_sizeof(png_text));
  172231. if (text_ptr == NULL)
  172232. {
  172233. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172234. png_free(png_ptr, key);
  172235. return;
  172236. }
  172237. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172238. text_ptr->key = key;
  172239. #ifdef PNG_iTXt_SUPPORTED
  172240. text_ptr->lang = NULL;
  172241. text_ptr->lang_key = NULL;
  172242. text_ptr->itxt_length = 0;
  172243. #endif
  172244. text_ptr->text = text;
  172245. text_ptr->text_length = png_strlen(text);
  172246. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172247. png_free(png_ptr, key);
  172248. png_free(png_ptr, text_ptr);
  172249. if (ret)
  172250. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172251. }
  172252. #endif
  172253. #if defined(PNG_READ_zTXt_SUPPORTED)
  172254. void /* PRIVATE */
  172255. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172256. {
  172257. png_textp text_ptr;
  172258. png_charp chunkdata;
  172259. png_charp text;
  172260. int comp_type;
  172261. int ret;
  172262. png_size_t slength, prefix_len, data_len;
  172263. png_debug(1, "in png_handle_zTXt\n");
  172264. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172265. png_error(png_ptr, "Missing IHDR before zTXt");
  172266. if (png_ptr->mode & PNG_HAVE_IDAT)
  172267. png_ptr->mode |= PNG_AFTER_IDAT;
  172268. #ifdef PNG_MAX_MALLOC_64K
  172269. if (length > (png_uint_32)65535L)
  172270. {
  172271. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172272. png_crc_finish(png_ptr, length);
  172273. return;
  172274. }
  172275. #endif
  172276. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172277. if (chunkdata == NULL)
  172278. {
  172279. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172280. return;
  172281. }
  172282. slength = (png_size_t)length;
  172283. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172284. if (png_crc_finish(png_ptr, 0))
  172285. {
  172286. png_free(png_ptr, chunkdata);
  172287. return;
  172288. }
  172289. chunkdata[slength] = 0x00;
  172290. for (text = chunkdata; *text; text++)
  172291. ;
  172292. if (text >= chunkdata + slength - 2)
  172293. {
  172294. png_warning(png_ptr, "Truncated zTXt chunk");
  172295. png_free(png_ptr, chunkdata);
  172296. return;
  172297. }
  172298. else
  172299. {
  172300. comp_type = *(++text);
  172301. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172302. {
  172303. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172304. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172305. }
  172306. text++; /* skip the compression_method byte */
  172307. }
  172308. prefix_len = text - chunkdata;
  172309. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172310. (png_size_t)length, prefix_len, &data_len);
  172311. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172312. (png_uint_32)png_sizeof(png_text));
  172313. if (text_ptr == NULL)
  172314. {
  172315. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172316. png_free(png_ptr, chunkdata);
  172317. return;
  172318. }
  172319. text_ptr->compression = comp_type;
  172320. text_ptr->key = chunkdata;
  172321. #ifdef PNG_iTXt_SUPPORTED
  172322. text_ptr->lang = NULL;
  172323. text_ptr->lang_key = NULL;
  172324. text_ptr->itxt_length = 0;
  172325. #endif
  172326. text_ptr->text = chunkdata + prefix_len;
  172327. text_ptr->text_length = data_len;
  172328. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172329. png_free(png_ptr, text_ptr);
  172330. png_free(png_ptr, chunkdata);
  172331. if (ret)
  172332. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172333. }
  172334. #endif
  172335. #if defined(PNG_READ_iTXt_SUPPORTED)
  172336. void /* PRIVATE */
  172337. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172338. {
  172339. png_textp text_ptr;
  172340. png_charp chunkdata;
  172341. png_charp key, lang, text, lang_key;
  172342. int comp_flag;
  172343. int comp_type = 0;
  172344. int ret;
  172345. png_size_t slength, prefix_len, data_len;
  172346. png_debug(1, "in png_handle_iTXt\n");
  172347. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172348. png_error(png_ptr, "Missing IHDR before iTXt");
  172349. if (png_ptr->mode & PNG_HAVE_IDAT)
  172350. png_ptr->mode |= PNG_AFTER_IDAT;
  172351. #ifdef PNG_MAX_MALLOC_64K
  172352. if (length > (png_uint_32)65535L)
  172353. {
  172354. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172355. png_crc_finish(png_ptr, length);
  172356. return;
  172357. }
  172358. #endif
  172359. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172360. if (chunkdata == NULL)
  172361. {
  172362. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172363. return;
  172364. }
  172365. slength = (png_size_t)length;
  172366. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172367. if (png_crc_finish(png_ptr, 0))
  172368. {
  172369. png_free(png_ptr, chunkdata);
  172370. return;
  172371. }
  172372. chunkdata[slength] = 0x00;
  172373. for (lang = chunkdata; *lang; lang++)
  172374. ;
  172375. lang++; /* skip NUL separator */
  172376. if (lang >= chunkdata + slength - 3)
  172377. {
  172378. png_warning(png_ptr, "Truncated iTXt chunk");
  172379. png_free(png_ptr, chunkdata);
  172380. return;
  172381. }
  172382. else
  172383. {
  172384. comp_flag = *lang++;
  172385. comp_type = *lang++;
  172386. }
  172387. for (lang_key = lang; *lang_key; lang_key++)
  172388. ;
  172389. lang_key++; /* skip NUL separator */
  172390. if (lang_key >= chunkdata + slength)
  172391. {
  172392. png_warning(png_ptr, "Truncated iTXt chunk");
  172393. png_free(png_ptr, chunkdata);
  172394. return;
  172395. }
  172396. for (text = lang_key; *text; text++)
  172397. ;
  172398. text++; /* skip NUL separator */
  172399. if (text >= chunkdata + slength)
  172400. {
  172401. png_warning(png_ptr, "Malformed iTXt chunk");
  172402. png_free(png_ptr, chunkdata);
  172403. return;
  172404. }
  172405. prefix_len = text - chunkdata;
  172406. key=chunkdata;
  172407. if (comp_flag)
  172408. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172409. (size_t)length, prefix_len, &data_len);
  172410. else
  172411. data_len=png_strlen(chunkdata + prefix_len);
  172412. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172413. (png_uint_32)png_sizeof(png_text));
  172414. if (text_ptr == NULL)
  172415. {
  172416. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172417. png_free(png_ptr, chunkdata);
  172418. return;
  172419. }
  172420. text_ptr->compression = (int)comp_flag + 1;
  172421. text_ptr->lang_key = chunkdata+(lang_key-key);
  172422. text_ptr->lang = chunkdata+(lang-key);
  172423. text_ptr->itxt_length = data_len;
  172424. text_ptr->text_length = 0;
  172425. text_ptr->key = chunkdata;
  172426. text_ptr->text = chunkdata + prefix_len;
  172427. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172428. png_free(png_ptr, text_ptr);
  172429. png_free(png_ptr, chunkdata);
  172430. if (ret)
  172431. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172432. }
  172433. #endif
  172434. void /* PRIVATE */
  172435. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172436. {
  172437. png_uint_32 skip = 0;
  172438. png_debug(1, "in png_handle_unknown\n");
  172439. if (png_ptr->mode & PNG_HAVE_IDAT)
  172440. {
  172441. #ifdef PNG_USE_LOCAL_ARRAYS
  172442. PNG_CONST PNG_IDAT;
  172443. #endif
  172444. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172445. png_ptr->mode |= PNG_AFTER_IDAT;
  172446. }
  172447. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172448. if (!(png_ptr->chunk_name[0] & 0x20))
  172449. {
  172450. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172451. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172452. PNG_HANDLE_CHUNK_ALWAYS
  172453. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172454. && png_ptr->read_user_chunk_fn == NULL
  172455. #endif
  172456. )
  172457. #endif
  172458. png_chunk_error(png_ptr, "unknown critical chunk");
  172459. }
  172460. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172461. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172462. (png_ptr->read_user_chunk_fn != NULL))
  172463. {
  172464. #ifdef PNG_MAX_MALLOC_64K
  172465. if (length > (png_uint_32)65535L)
  172466. {
  172467. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172468. skip = length - (png_uint_32)65535L;
  172469. length = (png_uint_32)65535L;
  172470. }
  172471. #endif
  172472. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172473. (png_charp)png_ptr->chunk_name, 5);
  172474. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172475. png_ptr->unknown_chunk.size = (png_size_t)length;
  172476. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172477. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172478. if(png_ptr->read_user_chunk_fn != NULL)
  172479. {
  172480. int ret;
  172481. ret = (*(png_ptr->read_user_chunk_fn))
  172482. (png_ptr, &png_ptr->unknown_chunk);
  172483. if (ret < 0)
  172484. png_chunk_error(png_ptr, "error in user chunk");
  172485. if (ret == 0)
  172486. {
  172487. if (!(png_ptr->chunk_name[0] & 0x20))
  172488. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172489. PNG_HANDLE_CHUNK_ALWAYS)
  172490. png_chunk_error(png_ptr, "unknown critical chunk");
  172491. png_set_unknown_chunks(png_ptr, info_ptr,
  172492. &png_ptr->unknown_chunk, 1);
  172493. }
  172494. }
  172495. #else
  172496. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172497. #endif
  172498. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172499. png_ptr->unknown_chunk.data = NULL;
  172500. }
  172501. else
  172502. #endif
  172503. skip = length;
  172504. png_crc_finish(png_ptr, skip);
  172505. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172506. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172507. #endif
  172508. }
  172509. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172510. void /* PRIVATE */
  172511. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172512. {
  172513. png_debug(1, "in png_check_chunk_name\n");
  172514. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172515. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172516. {
  172517. png_chunk_error(png_ptr, "invalid chunk type");
  172518. }
  172519. }
  172520. void /* PRIVATE */
  172521. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172522. {
  172523. png_debug(1,"in png_combine_row\n");
  172524. if (mask == 0xff)
  172525. {
  172526. png_memcpy(row, png_ptr->row_buf + 1,
  172527. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172528. }
  172529. else
  172530. {
  172531. switch (png_ptr->row_info.pixel_depth)
  172532. {
  172533. case 1:
  172534. {
  172535. png_bytep sp = png_ptr->row_buf + 1;
  172536. png_bytep dp = row;
  172537. int s_inc, s_start, s_end;
  172538. int m = 0x80;
  172539. int shift;
  172540. png_uint_32 i;
  172541. png_uint_32 row_width = png_ptr->width;
  172542. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172543. if (png_ptr->transformations & PNG_PACKSWAP)
  172544. {
  172545. s_start = 0;
  172546. s_end = 7;
  172547. s_inc = 1;
  172548. }
  172549. else
  172550. #endif
  172551. {
  172552. s_start = 7;
  172553. s_end = 0;
  172554. s_inc = -1;
  172555. }
  172556. shift = s_start;
  172557. for (i = 0; i < row_width; i++)
  172558. {
  172559. if (m & mask)
  172560. {
  172561. int value;
  172562. value = (*sp >> shift) & 0x01;
  172563. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172564. *dp |= (png_byte)(value << shift);
  172565. }
  172566. if (shift == s_end)
  172567. {
  172568. shift = s_start;
  172569. sp++;
  172570. dp++;
  172571. }
  172572. else
  172573. shift += s_inc;
  172574. if (m == 1)
  172575. m = 0x80;
  172576. else
  172577. m >>= 1;
  172578. }
  172579. break;
  172580. }
  172581. case 2:
  172582. {
  172583. png_bytep sp = png_ptr->row_buf + 1;
  172584. png_bytep dp = row;
  172585. int s_start, s_end, s_inc;
  172586. int m = 0x80;
  172587. int shift;
  172588. png_uint_32 i;
  172589. png_uint_32 row_width = png_ptr->width;
  172590. int value;
  172591. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172592. if (png_ptr->transformations & PNG_PACKSWAP)
  172593. {
  172594. s_start = 0;
  172595. s_end = 6;
  172596. s_inc = 2;
  172597. }
  172598. else
  172599. #endif
  172600. {
  172601. s_start = 6;
  172602. s_end = 0;
  172603. s_inc = -2;
  172604. }
  172605. shift = s_start;
  172606. for (i = 0; i < row_width; i++)
  172607. {
  172608. if (m & mask)
  172609. {
  172610. value = (*sp >> shift) & 0x03;
  172611. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172612. *dp |= (png_byte)(value << shift);
  172613. }
  172614. if (shift == s_end)
  172615. {
  172616. shift = s_start;
  172617. sp++;
  172618. dp++;
  172619. }
  172620. else
  172621. shift += s_inc;
  172622. if (m == 1)
  172623. m = 0x80;
  172624. else
  172625. m >>= 1;
  172626. }
  172627. break;
  172628. }
  172629. case 4:
  172630. {
  172631. png_bytep sp = png_ptr->row_buf + 1;
  172632. png_bytep dp = row;
  172633. int s_start, s_end, s_inc;
  172634. int m = 0x80;
  172635. int shift;
  172636. png_uint_32 i;
  172637. png_uint_32 row_width = png_ptr->width;
  172638. int value;
  172639. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172640. if (png_ptr->transformations & PNG_PACKSWAP)
  172641. {
  172642. s_start = 0;
  172643. s_end = 4;
  172644. s_inc = 4;
  172645. }
  172646. else
  172647. #endif
  172648. {
  172649. s_start = 4;
  172650. s_end = 0;
  172651. s_inc = -4;
  172652. }
  172653. shift = s_start;
  172654. for (i = 0; i < row_width; i++)
  172655. {
  172656. if (m & mask)
  172657. {
  172658. value = (*sp >> shift) & 0xf;
  172659. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172660. *dp |= (png_byte)(value << shift);
  172661. }
  172662. if (shift == s_end)
  172663. {
  172664. shift = s_start;
  172665. sp++;
  172666. dp++;
  172667. }
  172668. else
  172669. shift += s_inc;
  172670. if (m == 1)
  172671. m = 0x80;
  172672. else
  172673. m >>= 1;
  172674. }
  172675. break;
  172676. }
  172677. default:
  172678. {
  172679. png_bytep sp = png_ptr->row_buf + 1;
  172680. png_bytep dp = row;
  172681. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172682. png_uint_32 i;
  172683. png_uint_32 row_width = png_ptr->width;
  172684. png_byte m = 0x80;
  172685. for (i = 0; i < row_width; i++)
  172686. {
  172687. if (m & mask)
  172688. {
  172689. png_memcpy(dp, sp, pixel_bytes);
  172690. }
  172691. sp += pixel_bytes;
  172692. dp += pixel_bytes;
  172693. if (m == 1)
  172694. m = 0x80;
  172695. else
  172696. m >>= 1;
  172697. }
  172698. break;
  172699. }
  172700. }
  172701. }
  172702. }
  172703. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172704. void /* PRIVATE */
  172705. png_do_read_interlace(png_structp png_ptr)
  172706. {
  172707. png_row_infop row_info = &(png_ptr->row_info);
  172708. png_bytep row = png_ptr->row_buf + 1;
  172709. int pass = png_ptr->pass;
  172710. png_uint_32 transformations = png_ptr->transformations;
  172711. #ifdef PNG_USE_LOCAL_ARRAYS
  172712. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172713. #endif
  172714. png_debug(1,"in png_do_read_interlace\n");
  172715. if (row != NULL && row_info != NULL)
  172716. {
  172717. png_uint_32 final_width;
  172718. final_width = row_info->width * png_pass_inc[pass];
  172719. switch (row_info->pixel_depth)
  172720. {
  172721. case 1:
  172722. {
  172723. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172724. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172725. int sshift, dshift;
  172726. int s_start, s_end, s_inc;
  172727. int jstop = png_pass_inc[pass];
  172728. png_byte v;
  172729. png_uint_32 i;
  172730. int j;
  172731. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172732. if (transformations & PNG_PACKSWAP)
  172733. {
  172734. sshift = (int)((row_info->width + 7) & 0x07);
  172735. dshift = (int)((final_width + 7) & 0x07);
  172736. s_start = 7;
  172737. s_end = 0;
  172738. s_inc = -1;
  172739. }
  172740. else
  172741. #endif
  172742. {
  172743. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172744. dshift = 7 - (int)((final_width + 7) & 0x07);
  172745. s_start = 0;
  172746. s_end = 7;
  172747. s_inc = 1;
  172748. }
  172749. for (i = 0; i < row_info->width; i++)
  172750. {
  172751. v = (png_byte)((*sp >> sshift) & 0x01);
  172752. for (j = 0; j < jstop; j++)
  172753. {
  172754. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172755. *dp |= (png_byte)(v << dshift);
  172756. if (dshift == s_end)
  172757. {
  172758. dshift = s_start;
  172759. dp--;
  172760. }
  172761. else
  172762. dshift += s_inc;
  172763. }
  172764. if (sshift == s_end)
  172765. {
  172766. sshift = s_start;
  172767. sp--;
  172768. }
  172769. else
  172770. sshift += s_inc;
  172771. }
  172772. break;
  172773. }
  172774. case 2:
  172775. {
  172776. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172777. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172778. int sshift, dshift;
  172779. int s_start, s_end, s_inc;
  172780. int jstop = png_pass_inc[pass];
  172781. png_uint_32 i;
  172782. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172783. if (transformations & PNG_PACKSWAP)
  172784. {
  172785. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172786. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172787. s_start = 6;
  172788. s_end = 0;
  172789. s_inc = -2;
  172790. }
  172791. else
  172792. #endif
  172793. {
  172794. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172795. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172796. s_start = 0;
  172797. s_end = 6;
  172798. s_inc = 2;
  172799. }
  172800. for (i = 0; i < row_info->width; i++)
  172801. {
  172802. png_byte v;
  172803. int j;
  172804. v = (png_byte)((*sp >> sshift) & 0x03);
  172805. for (j = 0; j < jstop; j++)
  172806. {
  172807. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172808. *dp |= (png_byte)(v << dshift);
  172809. if (dshift == s_end)
  172810. {
  172811. dshift = s_start;
  172812. dp--;
  172813. }
  172814. else
  172815. dshift += s_inc;
  172816. }
  172817. if (sshift == s_end)
  172818. {
  172819. sshift = s_start;
  172820. sp--;
  172821. }
  172822. else
  172823. sshift += s_inc;
  172824. }
  172825. break;
  172826. }
  172827. case 4:
  172828. {
  172829. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172830. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172831. int sshift, dshift;
  172832. int s_start, s_end, s_inc;
  172833. png_uint_32 i;
  172834. int jstop = png_pass_inc[pass];
  172835. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172836. if (transformations & PNG_PACKSWAP)
  172837. {
  172838. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172839. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172840. s_start = 4;
  172841. s_end = 0;
  172842. s_inc = -4;
  172843. }
  172844. else
  172845. #endif
  172846. {
  172847. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172848. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172849. s_start = 0;
  172850. s_end = 4;
  172851. s_inc = 4;
  172852. }
  172853. for (i = 0; i < row_info->width; i++)
  172854. {
  172855. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172856. int j;
  172857. for (j = 0; j < jstop; j++)
  172858. {
  172859. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172860. *dp |= (png_byte)(v << dshift);
  172861. if (dshift == s_end)
  172862. {
  172863. dshift = s_start;
  172864. dp--;
  172865. }
  172866. else
  172867. dshift += s_inc;
  172868. }
  172869. if (sshift == s_end)
  172870. {
  172871. sshift = s_start;
  172872. sp--;
  172873. }
  172874. else
  172875. sshift += s_inc;
  172876. }
  172877. break;
  172878. }
  172879. default:
  172880. {
  172881. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172882. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172883. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172884. int jstop = png_pass_inc[pass];
  172885. png_uint_32 i;
  172886. for (i = 0; i < row_info->width; i++)
  172887. {
  172888. png_byte v[8];
  172889. int j;
  172890. png_memcpy(v, sp, pixel_bytes);
  172891. for (j = 0; j < jstop; j++)
  172892. {
  172893. png_memcpy(dp, v, pixel_bytes);
  172894. dp -= pixel_bytes;
  172895. }
  172896. sp -= pixel_bytes;
  172897. }
  172898. break;
  172899. }
  172900. }
  172901. row_info->width = final_width;
  172902. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172903. }
  172904. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172905. transformations = transformations; /* silence compiler warning */
  172906. #endif
  172907. }
  172908. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172909. void /* PRIVATE */
  172910. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172911. png_bytep prev_row, int filter)
  172912. {
  172913. png_debug(1, "in png_read_filter_row\n");
  172914. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172915. switch (filter)
  172916. {
  172917. case PNG_FILTER_VALUE_NONE:
  172918. break;
  172919. case PNG_FILTER_VALUE_SUB:
  172920. {
  172921. png_uint_32 i;
  172922. png_uint_32 istop = row_info->rowbytes;
  172923. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172924. png_bytep rp = row + bpp;
  172925. png_bytep lp = row;
  172926. for (i = bpp; i < istop; i++)
  172927. {
  172928. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172929. rp++;
  172930. }
  172931. break;
  172932. }
  172933. case PNG_FILTER_VALUE_UP:
  172934. {
  172935. png_uint_32 i;
  172936. png_uint_32 istop = row_info->rowbytes;
  172937. png_bytep rp = row;
  172938. png_bytep pp = prev_row;
  172939. for (i = 0; i < istop; i++)
  172940. {
  172941. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172942. rp++;
  172943. }
  172944. break;
  172945. }
  172946. case PNG_FILTER_VALUE_AVG:
  172947. {
  172948. png_uint_32 i;
  172949. png_bytep rp = row;
  172950. png_bytep pp = prev_row;
  172951. png_bytep lp = row;
  172952. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172953. png_uint_32 istop = row_info->rowbytes - bpp;
  172954. for (i = 0; i < bpp; i++)
  172955. {
  172956. *rp = (png_byte)(((int)(*rp) +
  172957. ((int)(*pp++) / 2 )) & 0xff);
  172958. rp++;
  172959. }
  172960. for (i = 0; i < istop; i++)
  172961. {
  172962. *rp = (png_byte)(((int)(*rp) +
  172963. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  172964. rp++;
  172965. }
  172966. break;
  172967. }
  172968. case PNG_FILTER_VALUE_PAETH:
  172969. {
  172970. png_uint_32 i;
  172971. png_bytep rp = row;
  172972. png_bytep pp = prev_row;
  172973. png_bytep lp = row;
  172974. png_bytep cp = prev_row;
  172975. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172976. png_uint_32 istop=row_info->rowbytes - bpp;
  172977. for (i = 0; i < bpp; i++)
  172978. {
  172979. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172980. rp++;
  172981. }
  172982. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  172983. {
  172984. int a, b, c, pa, pb, pc, p;
  172985. a = *lp++;
  172986. b = *pp++;
  172987. c = *cp++;
  172988. p = b - c;
  172989. pc = a - c;
  172990. #ifdef PNG_USE_ABS
  172991. pa = abs(p);
  172992. pb = abs(pc);
  172993. pc = abs(p + pc);
  172994. #else
  172995. pa = p < 0 ? -p : p;
  172996. pb = pc < 0 ? -pc : pc;
  172997. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  172998. #endif
  172999. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173000. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173001. rp++;
  173002. }
  173003. break;
  173004. }
  173005. default:
  173006. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173007. *row=0;
  173008. break;
  173009. }
  173010. }
  173011. void /* PRIVATE */
  173012. png_read_finish_row(png_structp png_ptr)
  173013. {
  173014. #ifdef PNG_USE_LOCAL_ARRAYS
  173015. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173016. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173017. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173018. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173019. #endif
  173020. png_debug(1, "in png_read_finish_row\n");
  173021. png_ptr->row_number++;
  173022. if (png_ptr->row_number < png_ptr->num_rows)
  173023. return;
  173024. if (png_ptr->interlaced)
  173025. {
  173026. png_ptr->row_number = 0;
  173027. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173028. png_ptr->rowbytes + 1);
  173029. do
  173030. {
  173031. png_ptr->pass++;
  173032. if (png_ptr->pass >= 7)
  173033. break;
  173034. png_ptr->iwidth = (png_ptr->width +
  173035. png_pass_inc[png_ptr->pass] - 1 -
  173036. png_pass_start[png_ptr->pass]) /
  173037. png_pass_inc[png_ptr->pass];
  173038. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173039. png_ptr->iwidth) + 1;
  173040. if (!(png_ptr->transformations & PNG_INTERLACE))
  173041. {
  173042. png_ptr->num_rows = (png_ptr->height +
  173043. png_pass_yinc[png_ptr->pass] - 1 -
  173044. png_pass_ystart[png_ptr->pass]) /
  173045. png_pass_yinc[png_ptr->pass];
  173046. if (!(png_ptr->num_rows))
  173047. continue;
  173048. }
  173049. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173050. break;
  173051. } while (png_ptr->iwidth == 0);
  173052. if (png_ptr->pass < 7)
  173053. return;
  173054. }
  173055. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173056. {
  173057. #ifdef PNG_USE_LOCAL_ARRAYS
  173058. PNG_CONST PNG_IDAT;
  173059. #endif
  173060. char extra;
  173061. int ret;
  173062. png_ptr->zstream.next_out = (Bytef *)&extra;
  173063. png_ptr->zstream.avail_out = (uInt)1;
  173064. for(;;)
  173065. {
  173066. if (!(png_ptr->zstream.avail_in))
  173067. {
  173068. while (!png_ptr->idat_size)
  173069. {
  173070. png_byte chunk_length[4];
  173071. png_crc_finish(png_ptr, 0);
  173072. png_read_data(png_ptr, chunk_length, 4);
  173073. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173074. png_reset_crc(png_ptr);
  173075. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173076. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173077. png_error(png_ptr, "Not enough image data");
  173078. }
  173079. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173080. png_ptr->zstream.next_in = png_ptr->zbuf;
  173081. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173082. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173083. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173084. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173085. }
  173086. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173087. if (ret == Z_STREAM_END)
  173088. {
  173089. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173090. png_ptr->idat_size)
  173091. png_warning(png_ptr, "Extra compressed data");
  173092. png_ptr->mode |= PNG_AFTER_IDAT;
  173093. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173094. break;
  173095. }
  173096. if (ret != Z_OK)
  173097. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173098. "Decompression Error");
  173099. if (!(png_ptr->zstream.avail_out))
  173100. {
  173101. png_warning(png_ptr, "Extra compressed data.");
  173102. png_ptr->mode |= PNG_AFTER_IDAT;
  173103. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173104. break;
  173105. }
  173106. }
  173107. png_ptr->zstream.avail_out = 0;
  173108. }
  173109. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173110. png_warning(png_ptr, "Extra compression data");
  173111. inflateReset(&png_ptr->zstream);
  173112. png_ptr->mode |= PNG_AFTER_IDAT;
  173113. }
  173114. void /* PRIVATE */
  173115. png_read_start_row(png_structp png_ptr)
  173116. {
  173117. #ifdef PNG_USE_LOCAL_ARRAYS
  173118. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173119. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173120. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173121. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173122. #endif
  173123. int max_pixel_depth;
  173124. png_uint_32 row_bytes;
  173125. png_debug(1, "in png_read_start_row\n");
  173126. png_ptr->zstream.avail_in = 0;
  173127. png_init_read_transformations(png_ptr);
  173128. if (png_ptr->interlaced)
  173129. {
  173130. if (!(png_ptr->transformations & PNG_INTERLACE))
  173131. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173132. png_pass_ystart[0]) / png_pass_yinc[0];
  173133. else
  173134. png_ptr->num_rows = png_ptr->height;
  173135. png_ptr->iwidth = (png_ptr->width +
  173136. png_pass_inc[png_ptr->pass] - 1 -
  173137. png_pass_start[png_ptr->pass]) /
  173138. png_pass_inc[png_ptr->pass];
  173139. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173140. png_ptr->irowbytes = (png_size_t)row_bytes;
  173141. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173142. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173143. }
  173144. else
  173145. {
  173146. png_ptr->num_rows = png_ptr->height;
  173147. png_ptr->iwidth = png_ptr->width;
  173148. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173149. }
  173150. max_pixel_depth = png_ptr->pixel_depth;
  173151. #if defined(PNG_READ_PACK_SUPPORTED)
  173152. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173153. max_pixel_depth = 8;
  173154. #endif
  173155. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173156. if (png_ptr->transformations & PNG_EXPAND)
  173157. {
  173158. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173159. {
  173160. if (png_ptr->num_trans)
  173161. max_pixel_depth = 32;
  173162. else
  173163. max_pixel_depth = 24;
  173164. }
  173165. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173166. {
  173167. if (max_pixel_depth < 8)
  173168. max_pixel_depth = 8;
  173169. if (png_ptr->num_trans)
  173170. max_pixel_depth *= 2;
  173171. }
  173172. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173173. {
  173174. if (png_ptr->num_trans)
  173175. {
  173176. max_pixel_depth *= 4;
  173177. max_pixel_depth /= 3;
  173178. }
  173179. }
  173180. }
  173181. #endif
  173182. #if defined(PNG_READ_FILLER_SUPPORTED)
  173183. if (png_ptr->transformations & (PNG_FILLER))
  173184. {
  173185. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173186. max_pixel_depth = 32;
  173187. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173188. {
  173189. if (max_pixel_depth <= 8)
  173190. max_pixel_depth = 16;
  173191. else
  173192. max_pixel_depth = 32;
  173193. }
  173194. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173195. {
  173196. if (max_pixel_depth <= 32)
  173197. max_pixel_depth = 32;
  173198. else
  173199. max_pixel_depth = 64;
  173200. }
  173201. }
  173202. #endif
  173203. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173204. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173205. {
  173206. if (
  173207. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173208. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173209. #endif
  173210. #if defined(PNG_READ_FILLER_SUPPORTED)
  173211. (png_ptr->transformations & (PNG_FILLER)) ||
  173212. #endif
  173213. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173214. {
  173215. if (max_pixel_depth <= 16)
  173216. max_pixel_depth = 32;
  173217. else
  173218. max_pixel_depth = 64;
  173219. }
  173220. else
  173221. {
  173222. if (max_pixel_depth <= 8)
  173223. {
  173224. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173225. max_pixel_depth = 32;
  173226. else
  173227. max_pixel_depth = 24;
  173228. }
  173229. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173230. max_pixel_depth = 64;
  173231. else
  173232. max_pixel_depth = 48;
  173233. }
  173234. }
  173235. #endif
  173236. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173237. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173238. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173239. {
  173240. int user_pixel_depth=png_ptr->user_transform_depth*
  173241. png_ptr->user_transform_channels;
  173242. if(user_pixel_depth > max_pixel_depth)
  173243. max_pixel_depth=user_pixel_depth;
  173244. }
  173245. #endif
  173246. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173247. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173248. 1 + ((max_pixel_depth + 7) >> 3);
  173249. #ifdef PNG_MAX_MALLOC_64K
  173250. if (row_bytes > (png_uint_32)65536L)
  173251. png_error(png_ptr, "This image requires a row greater than 64KB");
  173252. #endif
  173253. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173254. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173255. #ifdef PNG_MAX_MALLOC_64K
  173256. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173257. png_error(png_ptr, "This image requires a row greater than 64KB");
  173258. #endif
  173259. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173260. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173261. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173262. png_ptr->rowbytes + 1));
  173263. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173264. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173265. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173266. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173267. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173268. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173269. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173270. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173271. }
  173272. #endif /* PNG_READ_SUPPORTED */
  173273. /*** End of inlined file: pngrutil.c ***/
  173274. /*** Start of inlined file: pngset.c ***/
  173275. #define PNG_INTERNAL
  173276. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173277. #if defined(PNG_bKGD_SUPPORTED)
  173278. void PNGAPI
  173279. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173280. {
  173281. png_debug1(1, "in %s storage function\n", "bKGD");
  173282. if (png_ptr == NULL || info_ptr == NULL)
  173283. return;
  173284. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173285. info_ptr->valid |= PNG_INFO_bKGD;
  173286. }
  173287. #endif
  173288. #if defined(PNG_cHRM_SUPPORTED)
  173289. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173290. void PNGAPI
  173291. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173292. double white_x, double white_y, double red_x, double red_y,
  173293. double green_x, double green_y, double blue_x, double blue_y)
  173294. {
  173295. png_debug1(1, "in %s storage function\n", "cHRM");
  173296. if (png_ptr == NULL || info_ptr == NULL)
  173297. return;
  173298. if (white_x < 0.0 || white_y < 0.0 ||
  173299. red_x < 0.0 || red_y < 0.0 ||
  173300. green_x < 0.0 || green_y < 0.0 ||
  173301. blue_x < 0.0 || blue_y < 0.0)
  173302. {
  173303. png_warning(png_ptr,
  173304. "Ignoring attempt to set negative chromaticity value");
  173305. return;
  173306. }
  173307. if (white_x > 21474.83 || white_y > 21474.83 ||
  173308. red_x > 21474.83 || red_y > 21474.83 ||
  173309. green_x > 21474.83 || green_y > 21474.83 ||
  173310. blue_x > 21474.83 || blue_y > 21474.83)
  173311. {
  173312. png_warning(png_ptr,
  173313. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173314. return;
  173315. }
  173316. info_ptr->x_white = (float)white_x;
  173317. info_ptr->y_white = (float)white_y;
  173318. info_ptr->x_red = (float)red_x;
  173319. info_ptr->y_red = (float)red_y;
  173320. info_ptr->x_green = (float)green_x;
  173321. info_ptr->y_green = (float)green_y;
  173322. info_ptr->x_blue = (float)blue_x;
  173323. info_ptr->y_blue = (float)blue_y;
  173324. #ifdef PNG_FIXED_POINT_SUPPORTED
  173325. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173326. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173327. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173328. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173329. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173330. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173331. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173332. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173333. #endif
  173334. info_ptr->valid |= PNG_INFO_cHRM;
  173335. }
  173336. #endif
  173337. #ifdef PNG_FIXED_POINT_SUPPORTED
  173338. void PNGAPI
  173339. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173340. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173341. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173342. png_fixed_point blue_x, png_fixed_point blue_y)
  173343. {
  173344. png_debug1(1, "in %s storage function\n", "cHRM");
  173345. if (png_ptr == NULL || info_ptr == NULL)
  173346. return;
  173347. if (white_x < 0 || white_y < 0 ||
  173348. red_x < 0 || red_y < 0 ||
  173349. green_x < 0 || green_y < 0 ||
  173350. blue_x < 0 || blue_y < 0)
  173351. {
  173352. png_warning(png_ptr,
  173353. "Ignoring attempt to set negative chromaticity value");
  173354. return;
  173355. }
  173356. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173357. if (white_x > (double) PNG_UINT_31_MAX ||
  173358. white_y > (double) PNG_UINT_31_MAX ||
  173359. red_x > (double) PNG_UINT_31_MAX ||
  173360. red_y > (double) PNG_UINT_31_MAX ||
  173361. green_x > (double) PNG_UINT_31_MAX ||
  173362. green_y > (double) PNG_UINT_31_MAX ||
  173363. blue_x > (double) PNG_UINT_31_MAX ||
  173364. blue_y > (double) PNG_UINT_31_MAX)
  173365. #else
  173366. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173367. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173368. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173369. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173370. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173371. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173372. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173373. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173374. #endif
  173375. {
  173376. png_warning(png_ptr,
  173377. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173378. return;
  173379. }
  173380. info_ptr->int_x_white = white_x;
  173381. info_ptr->int_y_white = white_y;
  173382. info_ptr->int_x_red = red_x;
  173383. info_ptr->int_y_red = red_y;
  173384. info_ptr->int_x_green = green_x;
  173385. info_ptr->int_y_green = green_y;
  173386. info_ptr->int_x_blue = blue_x;
  173387. info_ptr->int_y_blue = blue_y;
  173388. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173389. info_ptr->x_white = (float)(white_x/100000.);
  173390. info_ptr->y_white = (float)(white_y/100000.);
  173391. info_ptr->x_red = (float)( red_x/100000.);
  173392. info_ptr->y_red = (float)( red_y/100000.);
  173393. info_ptr->x_green = (float)(green_x/100000.);
  173394. info_ptr->y_green = (float)(green_y/100000.);
  173395. info_ptr->x_blue = (float)( blue_x/100000.);
  173396. info_ptr->y_blue = (float)( blue_y/100000.);
  173397. #endif
  173398. info_ptr->valid |= PNG_INFO_cHRM;
  173399. }
  173400. #endif
  173401. #endif
  173402. #if defined(PNG_gAMA_SUPPORTED)
  173403. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173404. void PNGAPI
  173405. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173406. {
  173407. double gamma;
  173408. png_debug1(1, "in %s storage function\n", "gAMA");
  173409. if (png_ptr == NULL || info_ptr == NULL)
  173410. return;
  173411. if (file_gamma > 21474.83)
  173412. {
  173413. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173414. gamma=21474.83;
  173415. }
  173416. else
  173417. gamma=file_gamma;
  173418. info_ptr->gamma = (float)gamma;
  173419. #ifdef PNG_FIXED_POINT_SUPPORTED
  173420. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173421. #endif
  173422. info_ptr->valid |= PNG_INFO_gAMA;
  173423. if(gamma == 0.0)
  173424. png_warning(png_ptr, "Setting gamma=0");
  173425. }
  173426. #endif
  173427. void PNGAPI
  173428. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173429. int_gamma)
  173430. {
  173431. png_fixed_point gamma;
  173432. png_debug1(1, "in %s storage function\n", "gAMA");
  173433. if (png_ptr == NULL || info_ptr == NULL)
  173434. return;
  173435. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173436. {
  173437. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173438. gamma=PNG_UINT_31_MAX;
  173439. }
  173440. else
  173441. {
  173442. if (int_gamma < 0)
  173443. {
  173444. png_warning(png_ptr, "Setting negative gamma to zero");
  173445. gamma=0;
  173446. }
  173447. else
  173448. gamma=int_gamma;
  173449. }
  173450. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173451. info_ptr->gamma = (float)(gamma/100000.);
  173452. #endif
  173453. #ifdef PNG_FIXED_POINT_SUPPORTED
  173454. info_ptr->int_gamma = gamma;
  173455. #endif
  173456. info_ptr->valid |= PNG_INFO_gAMA;
  173457. if(gamma == 0)
  173458. png_warning(png_ptr, "Setting gamma=0");
  173459. }
  173460. #endif
  173461. #if defined(PNG_hIST_SUPPORTED)
  173462. void PNGAPI
  173463. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173464. {
  173465. int i;
  173466. png_debug1(1, "in %s storage function\n", "hIST");
  173467. if (png_ptr == NULL || info_ptr == NULL)
  173468. return;
  173469. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173470. > PNG_MAX_PALETTE_LENGTH)
  173471. {
  173472. png_warning(png_ptr,
  173473. "Invalid palette size, hIST allocation skipped.");
  173474. return;
  173475. }
  173476. #ifdef PNG_FREE_ME_SUPPORTED
  173477. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173478. #endif
  173479. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173480. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173481. if (png_ptr->hist == NULL)
  173482. {
  173483. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173484. return;
  173485. }
  173486. for (i = 0; i < info_ptr->num_palette; i++)
  173487. png_ptr->hist[i] = hist[i];
  173488. info_ptr->hist = png_ptr->hist;
  173489. info_ptr->valid |= PNG_INFO_hIST;
  173490. #ifdef PNG_FREE_ME_SUPPORTED
  173491. info_ptr->free_me |= PNG_FREE_HIST;
  173492. #else
  173493. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173494. #endif
  173495. }
  173496. #endif
  173497. void PNGAPI
  173498. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173499. png_uint_32 width, png_uint_32 height, int bit_depth,
  173500. int color_type, int interlace_type, int compression_type,
  173501. int filter_type)
  173502. {
  173503. png_debug1(1, "in %s storage function\n", "IHDR");
  173504. if (png_ptr == NULL || info_ptr == NULL)
  173505. return;
  173506. if (width == 0 || height == 0)
  173507. png_error(png_ptr, "Image width or height is zero in IHDR");
  173508. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173509. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173510. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173511. #else
  173512. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173513. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173514. #endif
  173515. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173516. png_error(png_ptr, "Invalid image size in IHDR");
  173517. if ( width > (PNG_UINT_32_MAX
  173518. >> 3) /* 8-byte RGBA pixels */
  173519. - 64 /* bigrowbuf hack */
  173520. - 1 /* filter byte */
  173521. - 7*8 /* rounding of width to multiple of 8 pixels */
  173522. - 8) /* extra max_pixel_depth pad */
  173523. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173524. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173525. bit_depth != 8 && bit_depth != 16)
  173526. png_error(png_ptr, "Invalid bit depth in IHDR");
  173527. if (color_type < 0 || color_type == 1 ||
  173528. color_type == 5 || color_type > 6)
  173529. png_error(png_ptr, "Invalid color type in IHDR");
  173530. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173531. ((color_type == PNG_COLOR_TYPE_RGB ||
  173532. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173533. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173534. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173535. if (interlace_type >= PNG_INTERLACE_LAST)
  173536. png_error(png_ptr, "Unknown interlace method in IHDR");
  173537. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173538. png_error(png_ptr, "Unknown compression method in IHDR");
  173539. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173540. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173541. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173542. if(filter_type != PNG_FILTER_TYPE_BASE)
  173543. {
  173544. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173545. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173546. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173547. (color_type == PNG_COLOR_TYPE_RGB ||
  173548. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173549. png_error(png_ptr, "Unknown filter method in IHDR");
  173550. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173551. png_warning(png_ptr, "Invalid filter method in IHDR");
  173552. }
  173553. #else
  173554. if(filter_type != PNG_FILTER_TYPE_BASE)
  173555. png_error(png_ptr, "Unknown filter method in IHDR");
  173556. #endif
  173557. info_ptr->width = width;
  173558. info_ptr->height = height;
  173559. info_ptr->bit_depth = (png_byte)bit_depth;
  173560. info_ptr->color_type =(png_byte) color_type;
  173561. info_ptr->compression_type = (png_byte)compression_type;
  173562. info_ptr->filter_type = (png_byte)filter_type;
  173563. info_ptr->interlace_type = (png_byte)interlace_type;
  173564. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173565. info_ptr->channels = 1;
  173566. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173567. info_ptr->channels = 3;
  173568. else
  173569. info_ptr->channels = 1;
  173570. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173571. info_ptr->channels++;
  173572. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173573. if (width > (PNG_UINT_32_MAX
  173574. >> 3) /* 8-byte RGBA pixels */
  173575. - 64 /* bigrowbuf hack */
  173576. - 1 /* filter byte */
  173577. - 7*8 /* rounding of width to multiple of 8 pixels */
  173578. - 8) /* extra max_pixel_depth pad */
  173579. info_ptr->rowbytes = (png_size_t)0;
  173580. else
  173581. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173582. }
  173583. #if defined(PNG_oFFs_SUPPORTED)
  173584. void PNGAPI
  173585. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173586. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173587. {
  173588. png_debug1(1, "in %s storage function\n", "oFFs");
  173589. if (png_ptr == NULL || info_ptr == NULL)
  173590. return;
  173591. info_ptr->x_offset = offset_x;
  173592. info_ptr->y_offset = offset_y;
  173593. info_ptr->offset_unit_type = (png_byte)unit_type;
  173594. info_ptr->valid |= PNG_INFO_oFFs;
  173595. }
  173596. #endif
  173597. #if defined(PNG_pCAL_SUPPORTED)
  173598. void PNGAPI
  173599. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173600. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173601. png_charp units, png_charpp params)
  173602. {
  173603. png_uint_32 length;
  173604. int i;
  173605. png_debug1(1, "in %s storage function\n", "pCAL");
  173606. if (png_ptr == NULL || info_ptr == NULL)
  173607. return;
  173608. length = png_strlen(purpose) + 1;
  173609. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173610. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173611. if (info_ptr->pcal_purpose == NULL)
  173612. {
  173613. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173614. return;
  173615. }
  173616. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173617. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173618. info_ptr->pcal_X0 = X0;
  173619. info_ptr->pcal_X1 = X1;
  173620. info_ptr->pcal_type = (png_byte)type;
  173621. info_ptr->pcal_nparams = (png_byte)nparams;
  173622. length = png_strlen(units) + 1;
  173623. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173624. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173625. if (info_ptr->pcal_units == NULL)
  173626. {
  173627. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173628. return;
  173629. }
  173630. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173631. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173632. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173633. if (info_ptr->pcal_params == NULL)
  173634. {
  173635. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173636. return;
  173637. }
  173638. info_ptr->pcal_params[nparams] = NULL;
  173639. for (i = 0; i < nparams; i++)
  173640. {
  173641. length = png_strlen(params[i]) + 1;
  173642. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173643. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173644. if (info_ptr->pcal_params[i] == NULL)
  173645. {
  173646. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173647. return;
  173648. }
  173649. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173650. }
  173651. info_ptr->valid |= PNG_INFO_pCAL;
  173652. #ifdef PNG_FREE_ME_SUPPORTED
  173653. info_ptr->free_me |= PNG_FREE_PCAL;
  173654. #endif
  173655. }
  173656. #endif
  173657. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173658. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173659. void PNGAPI
  173660. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173661. int unit, double width, double height)
  173662. {
  173663. png_debug1(1, "in %s storage function\n", "sCAL");
  173664. if (png_ptr == NULL || info_ptr == NULL)
  173665. return;
  173666. info_ptr->scal_unit = (png_byte)unit;
  173667. info_ptr->scal_pixel_width = width;
  173668. info_ptr->scal_pixel_height = height;
  173669. info_ptr->valid |= PNG_INFO_sCAL;
  173670. }
  173671. #else
  173672. #ifdef PNG_FIXED_POINT_SUPPORTED
  173673. void PNGAPI
  173674. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173675. int unit, png_charp swidth, png_charp sheight)
  173676. {
  173677. png_uint_32 length;
  173678. png_debug1(1, "in %s storage function\n", "sCAL");
  173679. if (png_ptr == NULL || info_ptr == NULL)
  173680. return;
  173681. info_ptr->scal_unit = (png_byte)unit;
  173682. length = png_strlen(swidth) + 1;
  173683. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173684. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173685. if (info_ptr->scal_s_width == NULL)
  173686. {
  173687. png_warning(png_ptr,
  173688. "Memory allocation failed while processing sCAL.");
  173689. }
  173690. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173691. length = png_strlen(sheight) + 1;
  173692. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173693. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173694. if (info_ptr->scal_s_height == NULL)
  173695. {
  173696. png_free (png_ptr, info_ptr->scal_s_width);
  173697. png_warning(png_ptr,
  173698. "Memory allocation failed while processing sCAL.");
  173699. }
  173700. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173701. info_ptr->valid |= PNG_INFO_sCAL;
  173702. #ifdef PNG_FREE_ME_SUPPORTED
  173703. info_ptr->free_me |= PNG_FREE_SCAL;
  173704. #endif
  173705. }
  173706. #endif
  173707. #endif
  173708. #endif
  173709. #if defined(PNG_pHYs_SUPPORTED)
  173710. void PNGAPI
  173711. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173712. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173713. {
  173714. png_debug1(1, "in %s storage function\n", "pHYs");
  173715. if (png_ptr == NULL || info_ptr == NULL)
  173716. return;
  173717. info_ptr->x_pixels_per_unit = res_x;
  173718. info_ptr->y_pixels_per_unit = res_y;
  173719. info_ptr->phys_unit_type = (png_byte)unit_type;
  173720. info_ptr->valid |= PNG_INFO_pHYs;
  173721. }
  173722. #endif
  173723. void PNGAPI
  173724. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173725. png_colorp palette, int num_palette)
  173726. {
  173727. png_debug1(1, "in %s storage function\n", "PLTE");
  173728. if (png_ptr == NULL || info_ptr == NULL)
  173729. return;
  173730. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173731. {
  173732. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173733. png_error(png_ptr, "Invalid palette length");
  173734. else
  173735. {
  173736. png_warning(png_ptr, "Invalid palette length");
  173737. return;
  173738. }
  173739. }
  173740. #ifdef PNG_FREE_ME_SUPPORTED
  173741. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173742. #endif
  173743. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173744. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173745. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173746. png_sizeof(png_color));
  173747. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173748. info_ptr->palette = png_ptr->palette;
  173749. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173750. #ifdef PNG_FREE_ME_SUPPORTED
  173751. info_ptr->free_me |= PNG_FREE_PLTE;
  173752. #else
  173753. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173754. #endif
  173755. info_ptr->valid |= PNG_INFO_PLTE;
  173756. }
  173757. #if defined(PNG_sBIT_SUPPORTED)
  173758. void PNGAPI
  173759. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173760. png_color_8p sig_bit)
  173761. {
  173762. png_debug1(1, "in %s storage function\n", "sBIT");
  173763. if (png_ptr == NULL || info_ptr == NULL)
  173764. return;
  173765. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173766. info_ptr->valid |= PNG_INFO_sBIT;
  173767. }
  173768. #endif
  173769. #if defined(PNG_sRGB_SUPPORTED)
  173770. void PNGAPI
  173771. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173772. {
  173773. png_debug1(1, "in %s storage function\n", "sRGB");
  173774. if (png_ptr == NULL || info_ptr == NULL)
  173775. return;
  173776. info_ptr->srgb_intent = (png_byte)intent;
  173777. info_ptr->valid |= PNG_INFO_sRGB;
  173778. }
  173779. void PNGAPI
  173780. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173781. int intent)
  173782. {
  173783. #if defined(PNG_gAMA_SUPPORTED)
  173784. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173785. float file_gamma;
  173786. #endif
  173787. #ifdef PNG_FIXED_POINT_SUPPORTED
  173788. png_fixed_point int_file_gamma;
  173789. #endif
  173790. #endif
  173791. #if defined(PNG_cHRM_SUPPORTED)
  173792. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173793. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173794. #endif
  173795. #ifdef PNG_FIXED_POINT_SUPPORTED
  173796. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173797. int_green_y, int_blue_x, int_blue_y;
  173798. #endif
  173799. #endif
  173800. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173801. if (png_ptr == NULL || info_ptr == NULL)
  173802. return;
  173803. png_set_sRGB(png_ptr, info_ptr, intent);
  173804. #if defined(PNG_gAMA_SUPPORTED)
  173805. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173806. file_gamma = (float).45455;
  173807. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173808. #endif
  173809. #ifdef PNG_FIXED_POINT_SUPPORTED
  173810. int_file_gamma = 45455L;
  173811. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173812. #endif
  173813. #endif
  173814. #if defined(PNG_cHRM_SUPPORTED)
  173815. #ifdef PNG_FIXED_POINT_SUPPORTED
  173816. int_white_x = 31270L;
  173817. int_white_y = 32900L;
  173818. int_red_x = 64000L;
  173819. int_red_y = 33000L;
  173820. int_green_x = 30000L;
  173821. int_green_y = 60000L;
  173822. int_blue_x = 15000L;
  173823. int_blue_y = 6000L;
  173824. png_set_cHRM_fixed(png_ptr, info_ptr,
  173825. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173826. int_blue_x, int_blue_y);
  173827. #endif
  173828. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173829. white_x = (float).3127;
  173830. white_y = (float).3290;
  173831. red_x = (float).64;
  173832. red_y = (float).33;
  173833. green_x = (float).30;
  173834. green_y = (float).60;
  173835. blue_x = (float).15;
  173836. blue_y = (float).06;
  173837. png_set_cHRM(png_ptr, info_ptr,
  173838. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173839. #endif
  173840. #endif
  173841. }
  173842. #endif
  173843. #if defined(PNG_iCCP_SUPPORTED)
  173844. void PNGAPI
  173845. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173846. png_charp name, int compression_type,
  173847. png_charp profile, png_uint_32 proflen)
  173848. {
  173849. png_charp new_iccp_name;
  173850. png_charp new_iccp_profile;
  173851. png_debug1(1, "in %s storage function\n", "iCCP");
  173852. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173853. return;
  173854. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173855. if (new_iccp_name == NULL)
  173856. {
  173857. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173858. return;
  173859. }
  173860. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173861. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173862. if (new_iccp_profile == NULL)
  173863. {
  173864. png_free (png_ptr, new_iccp_name);
  173865. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173866. return;
  173867. }
  173868. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173869. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173870. info_ptr->iccp_proflen = proflen;
  173871. info_ptr->iccp_name = new_iccp_name;
  173872. info_ptr->iccp_profile = new_iccp_profile;
  173873. info_ptr->iccp_compression = (png_byte)compression_type;
  173874. #ifdef PNG_FREE_ME_SUPPORTED
  173875. info_ptr->free_me |= PNG_FREE_ICCP;
  173876. #endif
  173877. info_ptr->valid |= PNG_INFO_iCCP;
  173878. }
  173879. #endif
  173880. #if defined(PNG_TEXT_SUPPORTED)
  173881. void PNGAPI
  173882. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173883. int num_text)
  173884. {
  173885. int ret;
  173886. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173887. if (ret)
  173888. png_error(png_ptr, "Insufficient memory to store text");
  173889. }
  173890. int /* PRIVATE */
  173891. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173892. int num_text)
  173893. {
  173894. int i;
  173895. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173896. "text" : (png_const_charp)png_ptr->chunk_name));
  173897. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173898. return(0);
  173899. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173900. {
  173901. if (info_ptr->text != NULL)
  173902. {
  173903. png_textp old_text;
  173904. int old_max;
  173905. old_max = info_ptr->max_text;
  173906. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173907. old_text = info_ptr->text;
  173908. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173909. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173910. if (info_ptr->text == NULL)
  173911. {
  173912. png_free(png_ptr, old_text);
  173913. return(1);
  173914. }
  173915. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173916. png_sizeof(png_text)));
  173917. png_free(png_ptr, old_text);
  173918. }
  173919. else
  173920. {
  173921. info_ptr->max_text = num_text + 8;
  173922. info_ptr->num_text = 0;
  173923. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173924. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173925. if (info_ptr->text == NULL)
  173926. return(1);
  173927. #ifdef PNG_FREE_ME_SUPPORTED
  173928. info_ptr->free_me |= PNG_FREE_TEXT;
  173929. #endif
  173930. }
  173931. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  173932. info_ptr->max_text);
  173933. }
  173934. for (i = 0; i < num_text; i++)
  173935. {
  173936. png_size_t text_length,key_len;
  173937. png_size_t lang_len,lang_key_len;
  173938. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  173939. if (text_ptr[i].key == NULL)
  173940. continue;
  173941. key_len = png_strlen(text_ptr[i].key);
  173942. if(text_ptr[i].compression <= 0)
  173943. {
  173944. lang_len = 0;
  173945. lang_key_len = 0;
  173946. }
  173947. else
  173948. #ifdef PNG_iTXt_SUPPORTED
  173949. {
  173950. if (text_ptr[i].lang != NULL)
  173951. lang_len = png_strlen(text_ptr[i].lang);
  173952. else
  173953. lang_len = 0;
  173954. if (text_ptr[i].lang_key != NULL)
  173955. lang_key_len = png_strlen(text_ptr[i].lang_key);
  173956. else
  173957. lang_key_len = 0;
  173958. }
  173959. #else
  173960. {
  173961. png_warning(png_ptr, "iTXt chunk not supported.");
  173962. continue;
  173963. }
  173964. #endif
  173965. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  173966. {
  173967. text_length = 0;
  173968. #ifdef PNG_iTXt_SUPPORTED
  173969. if(text_ptr[i].compression > 0)
  173970. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  173971. else
  173972. #endif
  173973. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  173974. }
  173975. else
  173976. {
  173977. text_length = png_strlen(text_ptr[i].text);
  173978. textp->compression = text_ptr[i].compression;
  173979. }
  173980. textp->key = (png_charp)png_malloc_warn(png_ptr,
  173981. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  173982. if (textp->key == NULL)
  173983. return(1);
  173984. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  173985. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  173986. (int)textp->key);
  173987. png_memcpy(textp->key, text_ptr[i].key,
  173988. (png_size_t)(key_len));
  173989. *(textp->key+key_len) = '\0';
  173990. #ifdef PNG_iTXt_SUPPORTED
  173991. if (text_ptr[i].compression > 0)
  173992. {
  173993. textp->lang=textp->key + key_len + 1;
  173994. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  173995. *(textp->lang+lang_len) = '\0';
  173996. textp->lang_key=textp->lang + lang_len + 1;
  173997. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  173998. *(textp->lang_key+lang_key_len) = '\0';
  173999. textp->text=textp->lang_key + lang_key_len + 1;
  174000. }
  174001. else
  174002. #endif
  174003. {
  174004. #ifdef PNG_iTXt_SUPPORTED
  174005. textp->lang=NULL;
  174006. textp->lang_key=NULL;
  174007. #endif
  174008. textp->text=textp->key + key_len + 1;
  174009. }
  174010. if(text_length)
  174011. png_memcpy(textp->text, text_ptr[i].text,
  174012. (png_size_t)(text_length));
  174013. *(textp->text+text_length) = '\0';
  174014. #ifdef PNG_iTXt_SUPPORTED
  174015. if(textp->compression > 0)
  174016. {
  174017. textp->text_length = 0;
  174018. textp->itxt_length = text_length;
  174019. }
  174020. else
  174021. #endif
  174022. {
  174023. textp->text_length = text_length;
  174024. #ifdef PNG_iTXt_SUPPORTED
  174025. textp->itxt_length = 0;
  174026. #endif
  174027. }
  174028. info_ptr->num_text++;
  174029. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174030. }
  174031. return(0);
  174032. }
  174033. #endif
  174034. #if defined(PNG_tIME_SUPPORTED)
  174035. void PNGAPI
  174036. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174037. {
  174038. png_debug1(1, "in %s storage function\n", "tIME");
  174039. if (png_ptr == NULL || info_ptr == NULL ||
  174040. (png_ptr->mode & PNG_WROTE_tIME))
  174041. return;
  174042. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174043. info_ptr->valid |= PNG_INFO_tIME;
  174044. }
  174045. #endif
  174046. #if defined(PNG_tRNS_SUPPORTED)
  174047. void PNGAPI
  174048. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174049. png_bytep trans, int num_trans, png_color_16p trans_values)
  174050. {
  174051. png_debug1(1, "in %s storage function\n", "tRNS");
  174052. if (png_ptr == NULL || info_ptr == NULL)
  174053. return;
  174054. if (trans != NULL)
  174055. {
  174056. #ifdef PNG_FREE_ME_SUPPORTED
  174057. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174058. #endif
  174059. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174060. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174061. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174062. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174063. #ifdef PNG_FREE_ME_SUPPORTED
  174064. info_ptr->free_me |= PNG_FREE_TRNS;
  174065. #else
  174066. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174067. #endif
  174068. }
  174069. if (trans_values != NULL)
  174070. {
  174071. png_memcpy(&(info_ptr->trans_values), trans_values,
  174072. png_sizeof(png_color_16));
  174073. if (num_trans == 0)
  174074. num_trans = 1;
  174075. }
  174076. info_ptr->num_trans = (png_uint_16)num_trans;
  174077. info_ptr->valid |= PNG_INFO_tRNS;
  174078. }
  174079. #endif
  174080. #if defined(PNG_sPLT_SUPPORTED)
  174081. void PNGAPI
  174082. png_set_sPLT(png_structp png_ptr,
  174083. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174084. {
  174085. png_sPLT_tp np;
  174086. int i;
  174087. if (png_ptr == NULL || info_ptr == NULL)
  174088. return;
  174089. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174090. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174091. if (np == NULL)
  174092. {
  174093. png_warning(png_ptr, "No memory for sPLT palettes.");
  174094. return;
  174095. }
  174096. png_memcpy(np, info_ptr->splt_palettes,
  174097. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174098. png_free(png_ptr, info_ptr->splt_palettes);
  174099. info_ptr->splt_palettes=NULL;
  174100. for (i = 0; i < nentries; i++)
  174101. {
  174102. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174103. png_sPLT_tp from = entries + i;
  174104. to->name = (png_charp)png_malloc_warn(png_ptr,
  174105. png_strlen(from->name) + 1);
  174106. if (to->name == NULL)
  174107. {
  174108. png_warning(png_ptr,
  174109. "Out of memory while processing sPLT chunk");
  174110. }
  174111. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174112. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174113. from->nentries * png_sizeof(png_sPLT_entry));
  174114. png_memcpy(to->entries, from->entries,
  174115. from->nentries * png_sizeof(png_sPLT_entry));
  174116. if (to->entries == NULL)
  174117. {
  174118. png_warning(png_ptr,
  174119. "Out of memory while processing sPLT chunk");
  174120. png_free(png_ptr,to->name);
  174121. to->name = NULL;
  174122. }
  174123. to->nentries = from->nentries;
  174124. to->depth = from->depth;
  174125. }
  174126. info_ptr->splt_palettes = np;
  174127. info_ptr->splt_palettes_num += nentries;
  174128. info_ptr->valid |= PNG_INFO_sPLT;
  174129. #ifdef PNG_FREE_ME_SUPPORTED
  174130. info_ptr->free_me |= PNG_FREE_SPLT;
  174131. #endif
  174132. }
  174133. #endif /* PNG_sPLT_SUPPORTED */
  174134. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174135. void PNGAPI
  174136. png_set_unknown_chunks(png_structp png_ptr,
  174137. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174138. {
  174139. png_unknown_chunkp np;
  174140. int i;
  174141. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174142. return;
  174143. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174144. (info_ptr->unknown_chunks_num + num_unknowns) *
  174145. png_sizeof(png_unknown_chunk));
  174146. if (np == NULL)
  174147. {
  174148. png_warning(png_ptr,
  174149. "Out of memory while processing unknown chunk.");
  174150. return;
  174151. }
  174152. png_memcpy(np, info_ptr->unknown_chunks,
  174153. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174154. png_free(png_ptr, info_ptr->unknown_chunks);
  174155. info_ptr->unknown_chunks=NULL;
  174156. for (i = 0; i < num_unknowns; i++)
  174157. {
  174158. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174159. png_unknown_chunkp from = unknowns + i;
  174160. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174161. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174162. if (to->data == NULL)
  174163. {
  174164. png_warning(png_ptr,
  174165. "Out of memory while processing unknown chunk.");
  174166. }
  174167. else
  174168. {
  174169. png_memcpy(to->data, from->data, from->size);
  174170. to->size = from->size;
  174171. to->location = (png_byte)(png_ptr->mode & 0xff);
  174172. }
  174173. }
  174174. info_ptr->unknown_chunks = np;
  174175. info_ptr->unknown_chunks_num += num_unknowns;
  174176. #ifdef PNG_FREE_ME_SUPPORTED
  174177. info_ptr->free_me |= PNG_FREE_UNKN;
  174178. #endif
  174179. }
  174180. void PNGAPI
  174181. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174182. int chunk, int location)
  174183. {
  174184. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174185. (int)info_ptr->unknown_chunks_num)
  174186. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174187. }
  174188. #endif
  174189. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174190. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174191. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174192. void PNGAPI
  174193. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174194. {
  174195. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174196. if (png_ptr == NULL)
  174197. return;
  174198. png_ptr->mng_features_permitted = (png_byte)
  174199. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174200. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174201. }
  174202. #endif
  174203. #endif
  174204. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174205. png_uint_32 PNGAPI
  174206. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174207. {
  174208. png_debug(1, "in png_permit_mng_features\n");
  174209. if (png_ptr == NULL)
  174210. return (png_uint_32)0;
  174211. png_ptr->mng_features_permitted =
  174212. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174213. return (png_uint_32)png_ptr->mng_features_permitted;
  174214. }
  174215. #endif
  174216. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174217. void PNGAPI
  174218. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174219. chunk_list, int num_chunks)
  174220. {
  174221. png_bytep new_list, p;
  174222. int i, old_num_chunks;
  174223. if (png_ptr == NULL)
  174224. return;
  174225. if (num_chunks == 0)
  174226. {
  174227. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174228. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174229. else
  174230. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174231. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174232. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174233. else
  174234. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174235. return;
  174236. }
  174237. if (chunk_list == NULL)
  174238. return;
  174239. old_num_chunks=png_ptr->num_chunk_list;
  174240. new_list=(png_bytep)png_malloc(png_ptr,
  174241. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174242. if(png_ptr->chunk_list != NULL)
  174243. {
  174244. png_memcpy(new_list, png_ptr->chunk_list,
  174245. (png_size_t)(5*old_num_chunks));
  174246. png_free(png_ptr, png_ptr->chunk_list);
  174247. png_ptr->chunk_list=NULL;
  174248. }
  174249. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174250. (png_size_t)(5*num_chunks));
  174251. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174252. *p=(png_byte)keep;
  174253. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174254. png_ptr->chunk_list=new_list;
  174255. #ifdef PNG_FREE_ME_SUPPORTED
  174256. png_ptr->free_me |= PNG_FREE_LIST;
  174257. #endif
  174258. }
  174259. #endif
  174260. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174261. void PNGAPI
  174262. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174263. png_user_chunk_ptr read_user_chunk_fn)
  174264. {
  174265. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174266. if (png_ptr == NULL)
  174267. return;
  174268. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174269. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174270. }
  174271. #endif
  174272. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174273. void PNGAPI
  174274. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174275. {
  174276. png_debug1(1, "in %s storage function\n", "rows");
  174277. if (png_ptr == NULL || info_ptr == NULL)
  174278. return;
  174279. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174280. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174281. info_ptr->row_pointers = row_pointers;
  174282. if(row_pointers)
  174283. info_ptr->valid |= PNG_INFO_IDAT;
  174284. }
  174285. #endif
  174286. #ifdef PNG_WRITE_SUPPORTED
  174287. void PNGAPI
  174288. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174289. {
  174290. if (png_ptr == NULL)
  174291. return;
  174292. if(png_ptr->zbuf)
  174293. png_free(png_ptr, png_ptr->zbuf);
  174294. png_ptr->zbuf_size = (png_size_t)size;
  174295. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174296. png_ptr->zstream.next_out = png_ptr->zbuf;
  174297. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174298. }
  174299. #endif
  174300. void PNGAPI
  174301. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174302. {
  174303. if (png_ptr && info_ptr)
  174304. info_ptr->valid &= ~(mask);
  174305. }
  174306. #ifndef PNG_1_0_X
  174307. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174308. void PNGAPI
  174309. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174310. {
  174311. if (png_ptr != NULL)
  174312. png_ptr->asm_flags = 0;
  174313. }
  174314. void PNGAPI
  174315. png_set_mmx_thresholds (png_structp png_ptr,
  174316. png_byte mmx_bitdepth_threshold,
  174317. png_uint_32 mmx_rowbytes_threshold)
  174318. {
  174319. if (png_ptr == NULL)
  174320. return;
  174321. }
  174322. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174323. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174324. void PNGAPI
  174325. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174326. png_uint_32 user_height_max)
  174327. {
  174328. if(png_ptr == NULL) return;
  174329. png_ptr->user_width_max = user_width_max;
  174330. png_ptr->user_height_max = user_height_max;
  174331. }
  174332. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174333. #endif /* ?PNG_1_0_X */
  174334. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174335. /*** End of inlined file: pngset.c ***/
  174336. /*** Start of inlined file: pngtrans.c ***/
  174337. #define PNG_INTERNAL
  174338. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174339. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174340. void PNGAPI
  174341. png_set_bgr(png_structp png_ptr)
  174342. {
  174343. png_debug(1, "in png_set_bgr\n");
  174344. if(png_ptr == NULL) return;
  174345. png_ptr->transformations |= PNG_BGR;
  174346. }
  174347. #endif
  174348. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174349. void PNGAPI
  174350. png_set_swap(png_structp png_ptr)
  174351. {
  174352. png_debug(1, "in png_set_swap\n");
  174353. if(png_ptr == NULL) return;
  174354. if (png_ptr->bit_depth == 16)
  174355. png_ptr->transformations |= PNG_SWAP_BYTES;
  174356. }
  174357. #endif
  174358. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174359. void PNGAPI
  174360. png_set_packing(png_structp png_ptr)
  174361. {
  174362. png_debug(1, "in png_set_packing\n");
  174363. if(png_ptr == NULL) return;
  174364. if (png_ptr->bit_depth < 8)
  174365. {
  174366. png_ptr->transformations |= PNG_PACK;
  174367. png_ptr->usr_bit_depth = 8;
  174368. }
  174369. }
  174370. #endif
  174371. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174372. void PNGAPI
  174373. png_set_packswap(png_structp png_ptr)
  174374. {
  174375. png_debug(1, "in png_set_packswap\n");
  174376. if(png_ptr == NULL) return;
  174377. if (png_ptr->bit_depth < 8)
  174378. png_ptr->transformations |= PNG_PACKSWAP;
  174379. }
  174380. #endif
  174381. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174382. void PNGAPI
  174383. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174384. {
  174385. png_debug(1, "in png_set_shift\n");
  174386. if(png_ptr == NULL) return;
  174387. png_ptr->transformations |= PNG_SHIFT;
  174388. png_ptr->shift = *true_bits;
  174389. }
  174390. #endif
  174391. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174392. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174393. int PNGAPI
  174394. png_set_interlace_handling(png_structp png_ptr)
  174395. {
  174396. png_debug(1, "in png_set_interlace handling\n");
  174397. if (png_ptr && png_ptr->interlaced)
  174398. {
  174399. png_ptr->transformations |= PNG_INTERLACE;
  174400. return (7);
  174401. }
  174402. return (1);
  174403. }
  174404. #endif
  174405. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174406. void PNGAPI
  174407. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174408. {
  174409. png_debug(1, "in png_set_filler\n");
  174410. if(png_ptr == NULL) return;
  174411. png_ptr->transformations |= PNG_FILLER;
  174412. png_ptr->filler = (png_byte)filler;
  174413. if (filler_loc == PNG_FILLER_AFTER)
  174414. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174415. else
  174416. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174417. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174418. {
  174419. png_ptr->usr_channels = 4;
  174420. }
  174421. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174422. {
  174423. png_ptr->usr_channels = 2;
  174424. }
  174425. }
  174426. #if !defined(PNG_1_0_X)
  174427. void PNGAPI
  174428. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174429. {
  174430. png_debug(1, "in png_set_add_alpha\n");
  174431. if(png_ptr == NULL) return;
  174432. png_set_filler(png_ptr, filler, filler_loc);
  174433. png_ptr->transformations |= PNG_ADD_ALPHA;
  174434. }
  174435. #endif
  174436. #endif
  174437. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174438. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174439. void PNGAPI
  174440. png_set_swap_alpha(png_structp png_ptr)
  174441. {
  174442. png_debug(1, "in png_set_swap_alpha\n");
  174443. if(png_ptr == NULL) return;
  174444. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174445. }
  174446. #endif
  174447. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174448. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174449. void PNGAPI
  174450. png_set_invert_alpha(png_structp png_ptr)
  174451. {
  174452. png_debug(1, "in png_set_invert_alpha\n");
  174453. if(png_ptr == NULL) return;
  174454. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174455. }
  174456. #endif
  174457. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174458. void PNGAPI
  174459. png_set_invert_mono(png_structp png_ptr)
  174460. {
  174461. png_debug(1, "in png_set_invert_mono\n");
  174462. if(png_ptr == NULL) return;
  174463. png_ptr->transformations |= PNG_INVERT_MONO;
  174464. }
  174465. void /* PRIVATE */
  174466. png_do_invert(png_row_infop row_info, png_bytep row)
  174467. {
  174468. png_debug(1, "in png_do_invert\n");
  174469. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174470. if (row == NULL || row_info == NULL)
  174471. return;
  174472. #endif
  174473. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174474. {
  174475. png_bytep rp = row;
  174476. png_uint_32 i;
  174477. png_uint_32 istop = row_info->rowbytes;
  174478. for (i = 0; i < istop; i++)
  174479. {
  174480. *rp = (png_byte)(~(*rp));
  174481. rp++;
  174482. }
  174483. }
  174484. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174485. row_info->bit_depth == 8)
  174486. {
  174487. png_bytep rp = row;
  174488. png_uint_32 i;
  174489. png_uint_32 istop = row_info->rowbytes;
  174490. for (i = 0; i < istop; i+=2)
  174491. {
  174492. *rp = (png_byte)(~(*rp));
  174493. rp+=2;
  174494. }
  174495. }
  174496. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174497. row_info->bit_depth == 16)
  174498. {
  174499. png_bytep rp = row;
  174500. png_uint_32 i;
  174501. png_uint_32 istop = row_info->rowbytes;
  174502. for (i = 0; i < istop; i+=4)
  174503. {
  174504. *rp = (png_byte)(~(*rp));
  174505. *(rp+1) = (png_byte)(~(*(rp+1)));
  174506. rp+=4;
  174507. }
  174508. }
  174509. }
  174510. #endif
  174511. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174512. void /* PRIVATE */
  174513. png_do_swap(png_row_infop row_info, png_bytep row)
  174514. {
  174515. png_debug(1, "in png_do_swap\n");
  174516. if (
  174517. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174518. row != NULL && row_info != NULL &&
  174519. #endif
  174520. row_info->bit_depth == 16)
  174521. {
  174522. png_bytep rp = row;
  174523. png_uint_32 i;
  174524. png_uint_32 istop= row_info->width * row_info->channels;
  174525. for (i = 0; i < istop; i++, rp += 2)
  174526. {
  174527. png_byte t = *rp;
  174528. *rp = *(rp + 1);
  174529. *(rp + 1) = t;
  174530. }
  174531. }
  174532. }
  174533. #endif
  174534. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174535. static PNG_CONST png_byte onebppswaptable[256] = {
  174536. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174537. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174538. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174539. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174540. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174541. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174542. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174543. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174544. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174545. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174546. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174547. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174548. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174549. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174550. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174551. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174552. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174553. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174554. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174555. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174556. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174557. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174558. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174559. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174560. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174561. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174562. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174563. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174564. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174565. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174566. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174567. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174568. };
  174569. static PNG_CONST png_byte twobppswaptable[256] = {
  174570. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174571. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174572. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174573. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174574. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174575. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174576. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174577. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174578. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174579. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174580. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174581. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174582. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174583. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174584. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174585. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174586. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174587. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174588. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174589. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174590. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174591. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174592. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174593. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174594. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174595. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174596. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174597. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174598. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174599. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174600. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174601. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174602. };
  174603. static PNG_CONST png_byte fourbppswaptable[256] = {
  174604. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174605. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174606. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174607. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174608. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174609. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174610. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174611. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174612. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174613. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174614. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174615. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174616. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174617. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174618. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174619. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174620. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174621. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174622. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174623. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174624. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174625. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174626. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174627. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174628. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174629. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174630. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174631. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174632. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174633. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174634. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174635. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174636. };
  174637. void /* PRIVATE */
  174638. png_do_packswap(png_row_infop row_info, png_bytep row)
  174639. {
  174640. png_debug(1, "in png_do_packswap\n");
  174641. if (
  174642. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174643. row != NULL && row_info != NULL &&
  174644. #endif
  174645. row_info->bit_depth < 8)
  174646. {
  174647. png_bytep rp, end, table;
  174648. end = row + row_info->rowbytes;
  174649. if (row_info->bit_depth == 1)
  174650. table = (png_bytep)onebppswaptable;
  174651. else if (row_info->bit_depth == 2)
  174652. table = (png_bytep)twobppswaptable;
  174653. else if (row_info->bit_depth == 4)
  174654. table = (png_bytep)fourbppswaptable;
  174655. else
  174656. return;
  174657. for (rp = row; rp < end; rp++)
  174658. *rp = table[*rp];
  174659. }
  174660. }
  174661. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174662. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174663. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174664. void /* PRIVATE */
  174665. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174666. {
  174667. png_debug(1, "in png_do_strip_filler\n");
  174668. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174669. if (row != NULL && row_info != NULL)
  174670. #endif
  174671. {
  174672. png_bytep sp=row;
  174673. png_bytep dp=row;
  174674. png_uint_32 row_width=row_info->width;
  174675. png_uint_32 i;
  174676. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174677. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174678. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174679. row_info->channels == 4)
  174680. {
  174681. if (row_info->bit_depth == 8)
  174682. {
  174683. if (flags & PNG_FLAG_FILLER_AFTER)
  174684. {
  174685. dp+=3; sp+=4;
  174686. for (i = 1; i < row_width; i++)
  174687. {
  174688. *dp++ = *sp++;
  174689. *dp++ = *sp++;
  174690. *dp++ = *sp++;
  174691. sp++;
  174692. }
  174693. }
  174694. else
  174695. {
  174696. for (i = 0; i < row_width; i++)
  174697. {
  174698. sp++;
  174699. *dp++ = *sp++;
  174700. *dp++ = *sp++;
  174701. *dp++ = *sp++;
  174702. }
  174703. }
  174704. row_info->pixel_depth = 24;
  174705. row_info->rowbytes = row_width * 3;
  174706. }
  174707. else /* if (row_info->bit_depth == 16) */
  174708. {
  174709. if (flags & PNG_FLAG_FILLER_AFTER)
  174710. {
  174711. sp += 8; dp += 6;
  174712. for (i = 1; i < row_width; i++)
  174713. {
  174714. *dp++ = *sp++;
  174715. *dp++ = *sp++;
  174716. *dp++ = *sp++;
  174717. *dp++ = *sp++;
  174718. *dp++ = *sp++;
  174719. *dp++ = *sp++;
  174720. sp += 2;
  174721. }
  174722. }
  174723. else
  174724. {
  174725. for (i = 0; i < row_width; i++)
  174726. {
  174727. sp+=2;
  174728. *dp++ = *sp++;
  174729. *dp++ = *sp++;
  174730. *dp++ = *sp++;
  174731. *dp++ = *sp++;
  174732. *dp++ = *sp++;
  174733. *dp++ = *sp++;
  174734. }
  174735. }
  174736. row_info->pixel_depth = 48;
  174737. row_info->rowbytes = row_width * 6;
  174738. }
  174739. row_info->channels = 3;
  174740. }
  174741. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174742. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174743. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174744. row_info->channels == 2)
  174745. {
  174746. if (row_info->bit_depth == 8)
  174747. {
  174748. if (flags & PNG_FLAG_FILLER_AFTER)
  174749. {
  174750. for (i = 0; i < row_width; i++)
  174751. {
  174752. *dp++ = *sp++;
  174753. sp++;
  174754. }
  174755. }
  174756. else
  174757. {
  174758. for (i = 0; i < row_width; i++)
  174759. {
  174760. sp++;
  174761. *dp++ = *sp++;
  174762. }
  174763. }
  174764. row_info->pixel_depth = 8;
  174765. row_info->rowbytes = row_width;
  174766. }
  174767. else /* if (row_info->bit_depth == 16) */
  174768. {
  174769. if (flags & PNG_FLAG_FILLER_AFTER)
  174770. {
  174771. sp += 4; dp += 2;
  174772. for (i = 1; i < row_width; i++)
  174773. {
  174774. *dp++ = *sp++;
  174775. *dp++ = *sp++;
  174776. sp += 2;
  174777. }
  174778. }
  174779. else
  174780. {
  174781. for (i = 0; i < row_width; i++)
  174782. {
  174783. sp += 2;
  174784. *dp++ = *sp++;
  174785. *dp++ = *sp++;
  174786. }
  174787. }
  174788. row_info->pixel_depth = 16;
  174789. row_info->rowbytes = row_width * 2;
  174790. }
  174791. row_info->channels = 1;
  174792. }
  174793. if (flags & PNG_FLAG_STRIP_ALPHA)
  174794. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174795. }
  174796. }
  174797. #endif
  174798. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174799. void /* PRIVATE */
  174800. png_do_bgr(png_row_infop row_info, png_bytep row)
  174801. {
  174802. png_debug(1, "in png_do_bgr\n");
  174803. if (
  174804. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174805. row != NULL && row_info != NULL &&
  174806. #endif
  174807. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174808. {
  174809. png_uint_32 row_width = row_info->width;
  174810. if (row_info->bit_depth == 8)
  174811. {
  174812. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174813. {
  174814. png_bytep rp;
  174815. png_uint_32 i;
  174816. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174817. {
  174818. png_byte save = *rp;
  174819. *rp = *(rp + 2);
  174820. *(rp + 2) = save;
  174821. }
  174822. }
  174823. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174824. {
  174825. png_bytep rp;
  174826. png_uint_32 i;
  174827. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174828. {
  174829. png_byte save = *rp;
  174830. *rp = *(rp + 2);
  174831. *(rp + 2) = save;
  174832. }
  174833. }
  174834. }
  174835. else if (row_info->bit_depth == 16)
  174836. {
  174837. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174838. {
  174839. png_bytep rp;
  174840. png_uint_32 i;
  174841. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174842. {
  174843. png_byte save = *rp;
  174844. *rp = *(rp + 4);
  174845. *(rp + 4) = save;
  174846. save = *(rp + 1);
  174847. *(rp + 1) = *(rp + 5);
  174848. *(rp + 5) = save;
  174849. }
  174850. }
  174851. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174852. {
  174853. png_bytep rp;
  174854. png_uint_32 i;
  174855. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174856. {
  174857. png_byte save = *rp;
  174858. *rp = *(rp + 4);
  174859. *(rp + 4) = save;
  174860. save = *(rp + 1);
  174861. *(rp + 1) = *(rp + 5);
  174862. *(rp + 5) = save;
  174863. }
  174864. }
  174865. }
  174866. }
  174867. }
  174868. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174869. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174870. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174871. defined(PNG_LEGACY_SUPPORTED)
  174872. void PNGAPI
  174873. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174874. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174875. {
  174876. png_debug(1, "in png_set_user_transform_info\n");
  174877. if(png_ptr == NULL) return;
  174878. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174879. png_ptr->user_transform_ptr = user_transform_ptr;
  174880. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174881. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174882. #else
  174883. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174884. png_warning(png_ptr,
  174885. "This version of libpng does not support user transform info");
  174886. #endif
  174887. }
  174888. #endif
  174889. png_voidp PNGAPI
  174890. png_get_user_transform_ptr(png_structp png_ptr)
  174891. {
  174892. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174893. if (png_ptr == NULL) return (NULL);
  174894. return ((png_voidp)png_ptr->user_transform_ptr);
  174895. #else
  174896. return (NULL);
  174897. #endif
  174898. }
  174899. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174900. /*** End of inlined file: pngtrans.c ***/
  174901. /*** Start of inlined file: pngwio.c ***/
  174902. #define PNG_INTERNAL
  174903. #ifdef PNG_WRITE_SUPPORTED
  174904. void /* PRIVATE */
  174905. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174906. {
  174907. if (png_ptr->write_data_fn != NULL )
  174908. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174909. else
  174910. png_error(png_ptr, "Call to NULL write function");
  174911. }
  174912. #if !defined(PNG_NO_STDIO)
  174913. #ifndef USE_FAR_KEYWORD
  174914. void PNGAPI
  174915. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174916. {
  174917. png_uint_32 check;
  174918. if(png_ptr == NULL) return;
  174919. #if defined(_WIN32_WCE)
  174920. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174921. check = 0;
  174922. #else
  174923. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174924. #endif
  174925. if (check != length)
  174926. png_error(png_ptr, "Write Error");
  174927. }
  174928. #else
  174929. #define NEAR_BUF_SIZE 1024
  174930. #define MIN(a,b) (a <= b ? a : b)
  174931. void PNGAPI
  174932. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174933. {
  174934. png_uint_32 check;
  174935. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  174936. png_FILE_p io_ptr;
  174937. if(png_ptr == NULL) return;
  174938. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  174939. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  174940. if ((png_bytep)near_data == data)
  174941. {
  174942. #if defined(_WIN32_WCE)
  174943. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  174944. check = 0;
  174945. #else
  174946. check = fwrite(near_data, 1, length, io_ptr);
  174947. #endif
  174948. }
  174949. else
  174950. {
  174951. png_byte buf[NEAR_BUF_SIZE];
  174952. png_size_t written, remaining, err;
  174953. check = 0;
  174954. remaining = length;
  174955. do
  174956. {
  174957. written = MIN(NEAR_BUF_SIZE, remaining);
  174958. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  174959. #if defined(_WIN32_WCE)
  174960. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  174961. err = 0;
  174962. #else
  174963. err = fwrite(buf, 1, written, io_ptr);
  174964. #endif
  174965. if (err != written)
  174966. break;
  174967. else
  174968. check += err;
  174969. data += written;
  174970. remaining -= written;
  174971. }
  174972. while (remaining != 0);
  174973. }
  174974. if (check != length)
  174975. png_error(png_ptr, "Write Error");
  174976. }
  174977. #endif
  174978. #endif
  174979. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174980. void /* PRIVATE */
  174981. png_flush(png_structp png_ptr)
  174982. {
  174983. if (png_ptr->output_flush_fn != NULL)
  174984. (*(png_ptr->output_flush_fn))(png_ptr);
  174985. }
  174986. #if !defined(PNG_NO_STDIO)
  174987. void PNGAPI
  174988. png_default_flush(png_structp png_ptr)
  174989. {
  174990. #if !defined(_WIN32_WCE)
  174991. png_FILE_p io_ptr;
  174992. #endif
  174993. if(png_ptr == NULL) return;
  174994. #if !defined(_WIN32_WCE)
  174995. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  174996. if (io_ptr != NULL)
  174997. fflush(io_ptr);
  174998. #endif
  174999. }
  175000. #endif
  175001. #endif
  175002. void PNGAPI
  175003. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175004. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175005. {
  175006. if(png_ptr == NULL) return;
  175007. png_ptr->io_ptr = io_ptr;
  175008. #if !defined(PNG_NO_STDIO)
  175009. if (write_data_fn != NULL)
  175010. png_ptr->write_data_fn = write_data_fn;
  175011. else
  175012. png_ptr->write_data_fn = png_default_write_data;
  175013. #else
  175014. png_ptr->write_data_fn = write_data_fn;
  175015. #endif
  175016. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175017. #if !defined(PNG_NO_STDIO)
  175018. if (output_flush_fn != NULL)
  175019. png_ptr->output_flush_fn = output_flush_fn;
  175020. else
  175021. png_ptr->output_flush_fn = png_default_flush;
  175022. #else
  175023. png_ptr->output_flush_fn = output_flush_fn;
  175024. #endif
  175025. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175026. if (png_ptr->read_data_fn != NULL)
  175027. {
  175028. png_ptr->read_data_fn = NULL;
  175029. png_warning(png_ptr,
  175030. "Attempted to set both read_data_fn and write_data_fn in");
  175031. png_warning(png_ptr,
  175032. "the same structure. Resetting read_data_fn to NULL.");
  175033. }
  175034. }
  175035. #if defined(USE_FAR_KEYWORD)
  175036. #if defined(_MSC_VER)
  175037. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175038. {
  175039. void *near_ptr;
  175040. void FAR *far_ptr;
  175041. FP_OFF(near_ptr) = FP_OFF(ptr);
  175042. far_ptr = (void FAR *)near_ptr;
  175043. if(check != 0)
  175044. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175045. png_error(png_ptr,"segment lost in conversion");
  175046. return(near_ptr);
  175047. }
  175048. # else
  175049. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175050. {
  175051. void *near_ptr;
  175052. void FAR *far_ptr;
  175053. near_ptr = (void FAR *)ptr;
  175054. far_ptr = (void FAR *)near_ptr;
  175055. if(check != 0)
  175056. if(far_ptr != ptr)
  175057. png_error(png_ptr,"segment lost in conversion");
  175058. return(near_ptr);
  175059. }
  175060. # endif
  175061. # endif
  175062. #endif /* PNG_WRITE_SUPPORTED */
  175063. /*** End of inlined file: pngwio.c ***/
  175064. /*** Start of inlined file: pngwrite.c ***/
  175065. #define PNG_INTERNAL
  175066. #ifdef PNG_WRITE_SUPPORTED
  175067. void PNGAPI
  175068. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175069. {
  175070. png_debug(1, "in png_write_info_before_PLTE\n");
  175071. if (png_ptr == NULL || info_ptr == NULL)
  175072. return;
  175073. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175074. {
  175075. png_write_sig(png_ptr); /* write PNG signature */
  175076. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175077. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175078. {
  175079. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175080. png_ptr->mng_features_permitted=0;
  175081. }
  175082. #endif
  175083. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175084. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175085. info_ptr->filter_type,
  175086. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175087. info_ptr->interlace_type);
  175088. #else
  175089. 0);
  175090. #endif
  175091. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175092. if (info_ptr->valid & PNG_INFO_gAMA)
  175093. {
  175094. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175095. png_write_gAMA(png_ptr, info_ptr->gamma);
  175096. #else
  175097. #ifdef PNG_FIXED_POINT_SUPPORTED
  175098. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175099. # endif
  175100. #endif
  175101. }
  175102. #endif
  175103. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175104. if (info_ptr->valid & PNG_INFO_sRGB)
  175105. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175106. #endif
  175107. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175108. if (info_ptr->valid & PNG_INFO_iCCP)
  175109. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175110. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175111. #endif
  175112. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175113. if (info_ptr->valid & PNG_INFO_sBIT)
  175114. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175115. #endif
  175116. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175117. if (info_ptr->valid & PNG_INFO_cHRM)
  175118. {
  175119. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175120. png_write_cHRM(png_ptr,
  175121. info_ptr->x_white, info_ptr->y_white,
  175122. info_ptr->x_red, info_ptr->y_red,
  175123. info_ptr->x_green, info_ptr->y_green,
  175124. info_ptr->x_blue, info_ptr->y_blue);
  175125. #else
  175126. # ifdef PNG_FIXED_POINT_SUPPORTED
  175127. png_write_cHRM_fixed(png_ptr,
  175128. info_ptr->int_x_white, info_ptr->int_y_white,
  175129. info_ptr->int_x_red, info_ptr->int_y_red,
  175130. info_ptr->int_x_green, info_ptr->int_y_green,
  175131. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175132. # endif
  175133. #endif
  175134. }
  175135. #endif
  175136. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175137. if (info_ptr->unknown_chunks_num)
  175138. {
  175139. png_unknown_chunk *up;
  175140. png_debug(5, "writing extra chunks\n");
  175141. for (up = info_ptr->unknown_chunks;
  175142. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175143. up++)
  175144. {
  175145. int keep=png_handle_as_unknown(png_ptr, up->name);
  175146. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175147. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175148. !(up->location & PNG_HAVE_IDAT) &&
  175149. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175150. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175151. {
  175152. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175153. }
  175154. }
  175155. }
  175156. #endif
  175157. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175158. }
  175159. }
  175160. void PNGAPI
  175161. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175162. {
  175163. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175164. int i;
  175165. #endif
  175166. png_debug(1, "in png_write_info\n");
  175167. if (png_ptr == NULL || info_ptr == NULL)
  175168. return;
  175169. png_write_info_before_PLTE(png_ptr, info_ptr);
  175170. if (info_ptr->valid & PNG_INFO_PLTE)
  175171. png_write_PLTE(png_ptr, info_ptr->palette,
  175172. (png_uint_32)info_ptr->num_palette);
  175173. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175174. png_error(png_ptr, "Valid palette required for paletted images");
  175175. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175176. if (info_ptr->valid & PNG_INFO_tRNS)
  175177. {
  175178. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175179. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175180. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175181. {
  175182. int j;
  175183. for (j=0; j<(int)info_ptr->num_trans; j++)
  175184. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175185. }
  175186. #endif
  175187. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175188. info_ptr->num_trans, info_ptr->color_type);
  175189. }
  175190. #endif
  175191. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175192. if (info_ptr->valid & PNG_INFO_bKGD)
  175193. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175194. #endif
  175195. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175196. if (info_ptr->valid & PNG_INFO_hIST)
  175197. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175198. #endif
  175199. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175200. if (info_ptr->valid & PNG_INFO_oFFs)
  175201. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175202. info_ptr->offset_unit_type);
  175203. #endif
  175204. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175205. if (info_ptr->valid & PNG_INFO_pCAL)
  175206. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175207. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175208. info_ptr->pcal_units, info_ptr->pcal_params);
  175209. #endif
  175210. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175211. if (info_ptr->valid & PNG_INFO_sCAL)
  175212. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175213. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175214. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175215. #else
  175216. #ifdef PNG_FIXED_POINT_SUPPORTED
  175217. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175218. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175219. #else
  175220. png_warning(png_ptr,
  175221. "png_write_sCAL not supported; sCAL chunk not written.");
  175222. #endif
  175223. #endif
  175224. #endif
  175225. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175226. if (info_ptr->valid & PNG_INFO_pHYs)
  175227. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175228. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175229. #endif
  175230. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175231. if (info_ptr->valid & PNG_INFO_tIME)
  175232. {
  175233. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175234. png_ptr->mode |= PNG_WROTE_tIME;
  175235. }
  175236. #endif
  175237. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175238. if (info_ptr->valid & PNG_INFO_sPLT)
  175239. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175240. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175241. #endif
  175242. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175243. for (i = 0; i < info_ptr->num_text; i++)
  175244. {
  175245. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175246. info_ptr->text[i].compression);
  175247. if (info_ptr->text[i].compression > 0)
  175248. {
  175249. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175250. png_write_iTXt(png_ptr,
  175251. info_ptr->text[i].compression,
  175252. info_ptr->text[i].key,
  175253. info_ptr->text[i].lang,
  175254. info_ptr->text[i].lang_key,
  175255. info_ptr->text[i].text);
  175256. #else
  175257. png_warning(png_ptr, "Unable to write international text");
  175258. #endif
  175259. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175260. }
  175261. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175262. {
  175263. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175264. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175265. info_ptr->text[i].text, 0,
  175266. info_ptr->text[i].compression);
  175267. #else
  175268. png_warning(png_ptr, "Unable to write compressed text");
  175269. #endif
  175270. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175271. }
  175272. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175273. {
  175274. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175275. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175276. info_ptr->text[i].text,
  175277. 0);
  175278. #else
  175279. png_warning(png_ptr, "Unable to write uncompressed text");
  175280. #endif
  175281. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175282. }
  175283. }
  175284. #endif
  175285. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175286. if (info_ptr->unknown_chunks_num)
  175287. {
  175288. png_unknown_chunk *up;
  175289. png_debug(5, "writing extra chunks\n");
  175290. for (up = info_ptr->unknown_chunks;
  175291. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175292. up++)
  175293. {
  175294. int keep=png_handle_as_unknown(png_ptr, up->name);
  175295. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175296. up->location && (up->location & PNG_HAVE_PLTE) &&
  175297. !(up->location & PNG_HAVE_IDAT) &&
  175298. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175299. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175300. {
  175301. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175302. }
  175303. }
  175304. }
  175305. #endif
  175306. }
  175307. void PNGAPI
  175308. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175309. {
  175310. png_debug(1, "in png_write_end\n");
  175311. if (png_ptr == NULL)
  175312. return;
  175313. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175314. png_error(png_ptr, "No IDATs written into file");
  175315. if (info_ptr != NULL)
  175316. {
  175317. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175318. int i; /* local index variable */
  175319. #endif
  175320. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175321. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175322. !(png_ptr->mode & PNG_WROTE_tIME))
  175323. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175324. #endif
  175325. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175326. for (i = 0; i < info_ptr->num_text; i++)
  175327. {
  175328. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175329. info_ptr->text[i].compression);
  175330. if (info_ptr->text[i].compression > 0)
  175331. {
  175332. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175333. png_write_iTXt(png_ptr,
  175334. info_ptr->text[i].compression,
  175335. info_ptr->text[i].key,
  175336. info_ptr->text[i].lang,
  175337. info_ptr->text[i].lang_key,
  175338. info_ptr->text[i].text);
  175339. #else
  175340. png_warning(png_ptr, "Unable to write international text");
  175341. #endif
  175342. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175343. }
  175344. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175345. {
  175346. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175347. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175348. info_ptr->text[i].text, 0,
  175349. info_ptr->text[i].compression);
  175350. #else
  175351. png_warning(png_ptr, "Unable to write compressed text");
  175352. #endif
  175353. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175354. }
  175355. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175356. {
  175357. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175358. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175359. info_ptr->text[i].text, 0);
  175360. #else
  175361. png_warning(png_ptr, "Unable to write uncompressed text");
  175362. #endif
  175363. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175364. }
  175365. }
  175366. #endif
  175367. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175368. if (info_ptr->unknown_chunks_num)
  175369. {
  175370. png_unknown_chunk *up;
  175371. png_debug(5, "writing extra chunks\n");
  175372. for (up = info_ptr->unknown_chunks;
  175373. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175374. up++)
  175375. {
  175376. int keep=png_handle_as_unknown(png_ptr, up->name);
  175377. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175378. up->location && (up->location & PNG_AFTER_IDAT) &&
  175379. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175380. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175381. {
  175382. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175383. }
  175384. }
  175385. }
  175386. #endif
  175387. }
  175388. png_ptr->mode |= PNG_AFTER_IDAT;
  175389. png_write_IEND(png_ptr);
  175390. }
  175391. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175392. #if !defined(_WIN32_WCE)
  175393. void PNGAPI
  175394. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175395. {
  175396. png_debug(1, "in png_convert_from_struct_tm\n");
  175397. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175398. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175399. ptime->day = (png_byte)ttime->tm_mday;
  175400. ptime->hour = (png_byte)ttime->tm_hour;
  175401. ptime->minute = (png_byte)ttime->tm_min;
  175402. ptime->second = (png_byte)ttime->tm_sec;
  175403. }
  175404. void PNGAPI
  175405. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175406. {
  175407. struct tm *tbuf;
  175408. png_debug(1, "in png_convert_from_time_t\n");
  175409. tbuf = gmtime(&ttime);
  175410. png_convert_from_struct_tm(ptime, tbuf);
  175411. }
  175412. #endif
  175413. #endif
  175414. png_structp PNGAPI
  175415. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175416. png_error_ptr error_fn, png_error_ptr warn_fn)
  175417. {
  175418. #ifdef PNG_USER_MEM_SUPPORTED
  175419. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175420. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175421. }
  175422. png_structp PNGAPI
  175423. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175424. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175425. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175426. {
  175427. #endif /* PNG_USER_MEM_SUPPORTED */
  175428. png_structp png_ptr;
  175429. #ifdef PNG_SETJMP_SUPPORTED
  175430. #ifdef USE_FAR_KEYWORD
  175431. jmp_buf jmpbuf;
  175432. #endif
  175433. #endif
  175434. int i;
  175435. png_debug(1, "in png_create_write_struct\n");
  175436. #ifdef PNG_USER_MEM_SUPPORTED
  175437. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175438. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175439. #else
  175440. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175441. #endif /* PNG_USER_MEM_SUPPORTED */
  175442. if (png_ptr == NULL)
  175443. return (NULL);
  175444. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175445. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175446. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175447. #endif
  175448. #ifdef PNG_SETJMP_SUPPORTED
  175449. #ifdef USE_FAR_KEYWORD
  175450. if (setjmp(jmpbuf))
  175451. #else
  175452. if (setjmp(png_ptr->jmpbuf))
  175453. #endif
  175454. {
  175455. png_free(png_ptr, png_ptr->zbuf);
  175456. png_ptr->zbuf=NULL;
  175457. png_destroy_struct(png_ptr);
  175458. return (NULL);
  175459. }
  175460. #ifdef USE_FAR_KEYWORD
  175461. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175462. #endif
  175463. #endif
  175464. #ifdef PNG_USER_MEM_SUPPORTED
  175465. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175466. #endif /* PNG_USER_MEM_SUPPORTED */
  175467. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175468. i=0;
  175469. do
  175470. {
  175471. if(user_png_ver[i] != png_libpng_ver[i])
  175472. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175473. } while (png_libpng_ver[i++]);
  175474. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175475. {
  175476. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175477. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175478. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175479. {
  175480. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175481. char msg[80];
  175482. if (user_png_ver)
  175483. {
  175484. png_snprintf(msg, 80,
  175485. "Application was compiled with png.h from libpng-%.20s",
  175486. user_png_ver);
  175487. png_warning(png_ptr, msg);
  175488. }
  175489. png_snprintf(msg, 80,
  175490. "Application is running with png.c from libpng-%.20s",
  175491. png_libpng_ver);
  175492. png_warning(png_ptr, msg);
  175493. #endif
  175494. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175495. png_ptr->flags=0;
  175496. #endif
  175497. png_error(png_ptr,
  175498. "Incompatible libpng version in application and library");
  175499. }
  175500. }
  175501. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175502. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175503. (png_uint_32)png_ptr->zbuf_size);
  175504. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175505. png_flush_ptr_NULL);
  175506. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175507. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175508. 1, png_doublep_NULL, png_doublep_NULL);
  175509. #endif
  175510. #ifdef PNG_SETJMP_SUPPORTED
  175511. #ifdef USE_FAR_KEYWORD
  175512. if (setjmp(jmpbuf))
  175513. PNG_ABORT();
  175514. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175515. #else
  175516. if (setjmp(png_ptr->jmpbuf))
  175517. PNG_ABORT();
  175518. #endif
  175519. #endif
  175520. return (png_ptr);
  175521. }
  175522. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175523. #undef png_write_init
  175524. void PNGAPI
  175525. png_write_init(png_structp png_ptr)
  175526. {
  175527. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175528. }
  175529. void PNGAPI
  175530. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175531. png_size_t png_struct_size, png_size_t png_info_size)
  175532. {
  175533. if(png_ptr == NULL) return;
  175534. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175535. if(png_sizeof(png_struct) > png_struct_size ||
  175536. png_sizeof(png_info) > png_info_size)
  175537. {
  175538. char msg[80];
  175539. png_ptr->warning_fn=NULL;
  175540. if (user_png_ver)
  175541. {
  175542. png_snprintf(msg, 80,
  175543. "Application was compiled with png.h from libpng-%.20s",
  175544. user_png_ver);
  175545. png_warning(png_ptr, msg);
  175546. }
  175547. png_snprintf(msg, 80,
  175548. "Application is running with png.c from libpng-%.20s",
  175549. png_libpng_ver);
  175550. png_warning(png_ptr, msg);
  175551. }
  175552. #endif
  175553. if(png_sizeof(png_struct) > png_struct_size)
  175554. {
  175555. png_ptr->error_fn=NULL;
  175556. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175557. png_ptr->flags=0;
  175558. #endif
  175559. png_error(png_ptr,
  175560. "The png struct allocated by the application for writing is too small.");
  175561. }
  175562. if(png_sizeof(png_info) > png_info_size)
  175563. {
  175564. png_ptr->error_fn=NULL;
  175565. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175566. png_ptr->flags=0;
  175567. #endif
  175568. png_error(png_ptr,
  175569. "The info struct allocated by the application for writing is too small.");
  175570. }
  175571. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175572. }
  175573. #endif /* PNG_1_0_X || PNG_1_2_X */
  175574. void PNGAPI
  175575. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175576. png_size_t png_struct_size)
  175577. {
  175578. png_structp png_ptr=*ptr_ptr;
  175579. #ifdef PNG_SETJMP_SUPPORTED
  175580. jmp_buf tmp_jmp; /* to save current jump buffer */
  175581. #endif
  175582. int i = 0;
  175583. if (png_ptr == NULL)
  175584. return;
  175585. do
  175586. {
  175587. if (user_png_ver[i] != png_libpng_ver[i])
  175588. {
  175589. #ifdef PNG_LEGACY_SUPPORTED
  175590. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175591. #else
  175592. png_ptr->warning_fn=NULL;
  175593. png_warning(png_ptr,
  175594. "Application uses deprecated png_write_init() and should be recompiled.");
  175595. break;
  175596. #endif
  175597. }
  175598. } while (png_libpng_ver[i++]);
  175599. png_debug(1, "in png_write_init_3\n");
  175600. #ifdef PNG_SETJMP_SUPPORTED
  175601. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175602. #endif
  175603. if (png_sizeof(png_struct) > png_struct_size)
  175604. {
  175605. png_destroy_struct(png_ptr);
  175606. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175607. *ptr_ptr = png_ptr;
  175608. }
  175609. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175610. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175611. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175612. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175613. #endif
  175614. #ifdef PNG_SETJMP_SUPPORTED
  175615. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175616. #endif
  175617. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175618. png_flush_ptr_NULL);
  175619. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175620. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175621. (png_uint_32)png_ptr->zbuf_size);
  175622. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175623. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175624. 1, png_doublep_NULL, png_doublep_NULL);
  175625. #endif
  175626. }
  175627. void PNGAPI
  175628. png_write_rows(png_structp png_ptr, png_bytepp row,
  175629. png_uint_32 num_rows)
  175630. {
  175631. png_uint_32 i; /* row counter */
  175632. png_bytepp rp; /* row pointer */
  175633. png_debug(1, "in png_write_rows\n");
  175634. if (png_ptr == NULL)
  175635. return;
  175636. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175637. {
  175638. png_write_row(png_ptr, *rp);
  175639. }
  175640. }
  175641. void PNGAPI
  175642. png_write_image(png_structp png_ptr, png_bytepp image)
  175643. {
  175644. png_uint_32 i; /* row index */
  175645. int pass, num_pass; /* pass variables */
  175646. png_bytepp rp; /* points to current row */
  175647. if (png_ptr == NULL)
  175648. return;
  175649. png_debug(1, "in png_write_image\n");
  175650. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175651. num_pass = png_set_interlace_handling(png_ptr);
  175652. #else
  175653. num_pass = 1;
  175654. #endif
  175655. for (pass = 0; pass < num_pass; pass++)
  175656. {
  175657. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175658. {
  175659. png_write_row(png_ptr, *rp);
  175660. }
  175661. }
  175662. }
  175663. void PNGAPI
  175664. png_write_row(png_structp png_ptr, png_bytep row)
  175665. {
  175666. if (png_ptr == NULL)
  175667. return;
  175668. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175669. png_ptr->row_number, png_ptr->pass);
  175670. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175671. {
  175672. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175673. png_error(png_ptr,
  175674. "png_write_info was never called before png_write_row.");
  175675. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175676. if (png_ptr->transformations & PNG_INVERT_MONO)
  175677. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175678. #endif
  175679. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175680. if (png_ptr->transformations & PNG_FILLER)
  175681. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175682. #endif
  175683. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175684. if (png_ptr->transformations & PNG_PACKSWAP)
  175685. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175686. #endif
  175687. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175688. if (png_ptr->transformations & PNG_PACK)
  175689. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175690. #endif
  175691. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175692. if (png_ptr->transformations & PNG_SHIFT)
  175693. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175694. #endif
  175695. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175696. if (png_ptr->transformations & PNG_BGR)
  175697. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175698. #endif
  175699. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175700. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175701. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175702. #endif
  175703. png_write_start_row(png_ptr);
  175704. }
  175705. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175706. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175707. {
  175708. switch (png_ptr->pass)
  175709. {
  175710. case 0:
  175711. if (png_ptr->row_number & 0x07)
  175712. {
  175713. png_write_finish_row(png_ptr);
  175714. return;
  175715. }
  175716. break;
  175717. case 1:
  175718. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175719. {
  175720. png_write_finish_row(png_ptr);
  175721. return;
  175722. }
  175723. break;
  175724. case 2:
  175725. if ((png_ptr->row_number & 0x07) != 4)
  175726. {
  175727. png_write_finish_row(png_ptr);
  175728. return;
  175729. }
  175730. break;
  175731. case 3:
  175732. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175733. {
  175734. png_write_finish_row(png_ptr);
  175735. return;
  175736. }
  175737. break;
  175738. case 4:
  175739. if ((png_ptr->row_number & 0x03) != 2)
  175740. {
  175741. png_write_finish_row(png_ptr);
  175742. return;
  175743. }
  175744. break;
  175745. case 5:
  175746. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175747. {
  175748. png_write_finish_row(png_ptr);
  175749. return;
  175750. }
  175751. break;
  175752. case 6:
  175753. if (!(png_ptr->row_number & 0x01))
  175754. {
  175755. png_write_finish_row(png_ptr);
  175756. return;
  175757. }
  175758. break;
  175759. }
  175760. }
  175761. #endif
  175762. png_ptr->row_info.color_type = png_ptr->color_type;
  175763. png_ptr->row_info.width = png_ptr->usr_width;
  175764. png_ptr->row_info.channels = png_ptr->usr_channels;
  175765. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175766. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175767. png_ptr->row_info.channels);
  175768. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175769. png_ptr->row_info.width);
  175770. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175771. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175772. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175773. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175774. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175775. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175776. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175777. png_ptr->row_info.rowbytes);
  175778. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175779. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175780. (png_ptr->transformations & PNG_INTERLACE))
  175781. {
  175782. png_do_write_interlace(&(png_ptr->row_info),
  175783. png_ptr->row_buf + 1, png_ptr->pass);
  175784. if (!(png_ptr->row_info.width))
  175785. {
  175786. png_write_finish_row(png_ptr);
  175787. return;
  175788. }
  175789. }
  175790. #endif
  175791. if (png_ptr->transformations)
  175792. png_do_write_transformations(png_ptr);
  175793. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175794. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175795. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175796. {
  175797. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175798. }
  175799. #endif
  175800. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175801. if (png_ptr->write_row_fn != NULL)
  175802. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175803. }
  175804. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175805. void PNGAPI
  175806. png_set_flush(png_structp png_ptr, int nrows)
  175807. {
  175808. png_debug(1, "in png_set_flush\n");
  175809. if (png_ptr == NULL)
  175810. return;
  175811. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175812. }
  175813. void PNGAPI
  175814. png_write_flush(png_structp png_ptr)
  175815. {
  175816. int wrote_IDAT;
  175817. png_debug(1, "in png_write_flush\n");
  175818. if (png_ptr == NULL)
  175819. return;
  175820. if (png_ptr->row_number >= png_ptr->num_rows)
  175821. return;
  175822. do
  175823. {
  175824. int ret;
  175825. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175826. wrote_IDAT = 0;
  175827. if (ret != Z_OK)
  175828. {
  175829. if (png_ptr->zstream.msg != NULL)
  175830. png_error(png_ptr, png_ptr->zstream.msg);
  175831. else
  175832. png_error(png_ptr, "zlib error");
  175833. }
  175834. if (!(png_ptr->zstream.avail_out))
  175835. {
  175836. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175837. png_ptr->zbuf_size);
  175838. png_ptr->zstream.next_out = png_ptr->zbuf;
  175839. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175840. wrote_IDAT = 1;
  175841. }
  175842. } while(wrote_IDAT == 1);
  175843. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175844. {
  175845. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175846. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175847. png_ptr->zstream.next_out = png_ptr->zbuf;
  175848. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175849. }
  175850. png_ptr->flush_rows = 0;
  175851. png_flush(png_ptr);
  175852. }
  175853. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175854. void PNGAPI
  175855. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175856. {
  175857. png_structp png_ptr = NULL;
  175858. png_infop info_ptr = NULL;
  175859. #ifdef PNG_USER_MEM_SUPPORTED
  175860. png_free_ptr free_fn = NULL;
  175861. png_voidp mem_ptr = NULL;
  175862. #endif
  175863. png_debug(1, "in png_destroy_write_struct\n");
  175864. if (png_ptr_ptr != NULL)
  175865. {
  175866. png_ptr = *png_ptr_ptr;
  175867. #ifdef PNG_USER_MEM_SUPPORTED
  175868. free_fn = png_ptr->free_fn;
  175869. mem_ptr = png_ptr->mem_ptr;
  175870. #endif
  175871. }
  175872. if (info_ptr_ptr != NULL)
  175873. info_ptr = *info_ptr_ptr;
  175874. if (info_ptr != NULL)
  175875. {
  175876. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175877. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175878. if (png_ptr->num_chunk_list)
  175879. {
  175880. png_free(png_ptr, png_ptr->chunk_list);
  175881. png_ptr->chunk_list=NULL;
  175882. png_ptr->num_chunk_list=0;
  175883. }
  175884. #endif
  175885. #ifdef PNG_USER_MEM_SUPPORTED
  175886. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175887. (png_voidp)mem_ptr);
  175888. #else
  175889. png_destroy_struct((png_voidp)info_ptr);
  175890. #endif
  175891. *info_ptr_ptr = NULL;
  175892. }
  175893. if (png_ptr != NULL)
  175894. {
  175895. png_write_destroy(png_ptr);
  175896. #ifdef PNG_USER_MEM_SUPPORTED
  175897. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175898. (png_voidp)mem_ptr);
  175899. #else
  175900. png_destroy_struct((png_voidp)png_ptr);
  175901. #endif
  175902. *png_ptr_ptr = NULL;
  175903. }
  175904. }
  175905. void /* PRIVATE */
  175906. png_write_destroy(png_structp png_ptr)
  175907. {
  175908. #ifdef PNG_SETJMP_SUPPORTED
  175909. jmp_buf tmp_jmp; /* save jump buffer */
  175910. #endif
  175911. png_error_ptr error_fn;
  175912. png_error_ptr warning_fn;
  175913. png_voidp error_ptr;
  175914. #ifdef PNG_USER_MEM_SUPPORTED
  175915. png_free_ptr free_fn;
  175916. #endif
  175917. png_debug(1, "in png_write_destroy\n");
  175918. deflateEnd(&png_ptr->zstream);
  175919. png_free(png_ptr, png_ptr->zbuf);
  175920. png_free(png_ptr, png_ptr->row_buf);
  175921. png_free(png_ptr, png_ptr->prev_row);
  175922. png_free(png_ptr, png_ptr->sub_row);
  175923. png_free(png_ptr, png_ptr->up_row);
  175924. png_free(png_ptr, png_ptr->avg_row);
  175925. png_free(png_ptr, png_ptr->paeth_row);
  175926. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175927. png_free(png_ptr, png_ptr->time_buffer);
  175928. #endif
  175929. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175930. png_free(png_ptr, png_ptr->prev_filters);
  175931. png_free(png_ptr, png_ptr->filter_weights);
  175932. png_free(png_ptr, png_ptr->inv_filter_weights);
  175933. png_free(png_ptr, png_ptr->filter_costs);
  175934. png_free(png_ptr, png_ptr->inv_filter_costs);
  175935. #endif
  175936. #ifdef PNG_SETJMP_SUPPORTED
  175937. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175938. #endif
  175939. error_fn = png_ptr->error_fn;
  175940. warning_fn = png_ptr->warning_fn;
  175941. error_ptr = png_ptr->error_ptr;
  175942. #ifdef PNG_USER_MEM_SUPPORTED
  175943. free_fn = png_ptr->free_fn;
  175944. #endif
  175945. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175946. png_ptr->error_fn = error_fn;
  175947. png_ptr->warning_fn = warning_fn;
  175948. png_ptr->error_ptr = error_ptr;
  175949. #ifdef PNG_USER_MEM_SUPPORTED
  175950. png_ptr->free_fn = free_fn;
  175951. #endif
  175952. #ifdef PNG_SETJMP_SUPPORTED
  175953. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175954. #endif
  175955. }
  175956. void PNGAPI
  175957. png_set_filter(png_structp png_ptr, int method, int filters)
  175958. {
  175959. png_debug(1, "in png_set_filter\n");
  175960. if (png_ptr == NULL)
  175961. return;
  175962. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175963. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175964. (method == PNG_INTRAPIXEL_DIFFERENCING))
  175965. method = PNG_FILTER_TYPE_BASE;
  175966. #endif
  175967. if (method == PNG_FILTER_TYPE_BASE)
  175968. {
  175969. switch (filters & (PNG_ALL_FILTERS | 0x07))
  175970. {
  175971. #ifndef PNG_NO_WRITE_FILTER
  175972. case 5:
  175973. case 6:
  175974. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  175975. #endif /* PNG_NO_WRITE_FILTER */
  175976. case PNG_FILTER_VALUE_NONE:
  175977. png_ptr->do_filter=PNG_FILTER_NONE; break;
  175978. #ifndef PNG_NO_WRITE_FILTER
  175979. case PNG_FILTER_VALUE_SUB:
  175980. png_ptr->do_filter=PNG_FILTER_SUB; break;
  175981. case PNG_FILTER_VALUE_UP:
  175982. png_ptr->do_filter=PNG_FILTER_UP; break;
  175983. case PNG_FILTER_VALUE_AVG:
  175984. png_ptr->do_filter=PNG_FILTER_AVG; break;
  175985. case PNG_FILTER_VALUE_PAETH:
  175986. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  175987. default: png_ptr->do_filter = (png_byte)filters; break;
  175988. #else
  175989. default: png_warning(png_ptr, "Unknown row filter for method 0");
  175990. #endif /* PNG_NO_WRITE_FILTER */
  175991. }
  175992. if (png_ptr->row_buf != NULL)
  175993. {
  175994. #ifndef PNG_NO_WRITE_FILTER
  175995. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  175996. {
  175997. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  175998. (png_ptr->rowbytes + 1));
  175999. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176000. }
  176001. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176002. {
  176003. if (png_ptr->prev_row == NULL)
  176004. {
  176005. png_warning(png_ptr, "Can't add Up filter after starting");
  176006. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176007. }
  176008. else
  176009. {
  176010. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176011. (png_ptr->rowbytes + 1));
  176012. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176013. }
  176014. }
  176015. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176016. {
  176017. if (png_ptr->prev_row == NULL)
  176018. {
  176019. png_warning(png_ptr, "Can't add Average filter after starting");
  176020. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176021. }
  176022. else
  176023. {
  176024. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176025. (png_ptr->rowbytes + 1));
  176026. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176027. }
  176028. }
  176029. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176030. png_ptr->paeth_row == NULL)
  176031. {
  176032. if (png_ptr->prev_row == NULL)
  176033. {
  176034. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176035. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176036. }
  176037. else
  176038. {
  176039. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176040. (png_ptr->rowbytes + 1));
  176041. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176042. }
  176043. }
  176044. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176045. #endif /* PNG_NO_WRITE_FILTER */
  176046. png_ptr->do_filter = PNG_FILTER_NONE;
  176047. }
  176048. }
  176049. else
  176050. png_error(png_ptr, "Unknown custom filter method");
  176051. }
  176052. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176053. void PNGAPI
  176054. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176055. int num_weights, png_doublep filter_weights,
  176056. png_doublep filter_costs)
  176057. {
  176058. int i;
  176059. png_debug(1, "in png_set_filter_heuristics\n");
  176060. if (png_ptr == NULL)
  176061. return;
  176062. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176063. {
  176064. png_warning(png_ptr, "Unknown filter heuristic method");
  176065. return;
  176066. }
  176067. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176068. {
  176069. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176070. }
  176071. if (num_weights < 0 || filter_weights == NULL ||
  176072. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176073. {
  176074. num_weights = 0;
  176075. }
  176076. png_ptr->num_prev_filters = (png_byte)num_weights;
  176077. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176078. if (num_weights > 0)
  176079. {
  176080. if (png_ptr->prev_filters == NULL)
  176081. {
  176082. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176083. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176084. for (i = 0; i < num_weights; i++)
  176085. {
  176086. png_ptr->prev_filters[i] = 255;
  176087. }
  176088. }
  176089. if (png_ptr->filter_weights == NULL)
  176090. {
  176091. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176092. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176093. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176094. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176095. for (i = 0; i < num_weights; i++)
  176096. {
  176097. png_ptr->inv_filter_weights[i] =
  176098. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176099. }
  176100. }
  176101. for (i = 0; i < num_weights; i++)
  176102. {
  176103. if (filter_weights[i] < 0.0)
  176104. {
  176105. png_ptr->inv_filter_weights[i] =
  176106. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176107. }
  176108. else
  176109. {
  176110. png_ptr->inv_filter_weights[i] =
  176111. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176112. png_ptr->filter_weights[i] =
  176113. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176114. }
  176115. }
  176116. }
  176117. if (png_ptr->filter_costs == NULL)
  176118. {
  176119. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176120. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176121. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176122. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176123. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176124. {
  176125. png_ptr->inv_filter_costs[i] =
  176126. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176127. }
  176128. }
  176129. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176130. {
  176131. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176132. {
  176133. png_ptr->inv_filter_costs[i] =
  176134. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176135. }
  176136. else if (filter_costs[i] >= 1.0)
  176137. {
  176138. png_ptr->inv_filter_costs[i] =
  176139. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176140. png_ptr->filter_costs[i] =
  176141. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176142. }
  176143. }
  176144. }
  176145. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176146. void PNGAPI
  176147. png_set_compression_level(png_structp png_ptr, int level)
  176148. {
  176149. png_debug(1, "in png_set_compression_level\n");
  176150. if (png_ptr == NULL)
  176151. return;
  176152. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176153. png_ptr->zlib_level = level;
  176154. }
  176155. void PNGAPI
  176156. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176157. {
  176158. png_debug(1, "in png_set_compression_mem_level\n");
  176159. if (png_ptr == NULL)
  176160. return;
  176161. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176162. png_ptr->zlib_mem_level = mem_level;
  176163. }
  176164. void PNGAPI
  176165. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176166. {
  176167. png_debug(1, "in png_set_compression_strategy\n");
  176168. if (png_ptr == NULL)
  176169. return;
  176170. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176171. png_ptr->zlib_strategy = strategy;
  176172. }
  176173. void PNGAPI
  176174. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176175. {
  176176. if (png_ptr == NULL)
  176177. return;
  176178. if (window_bits > 15)
  176179. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176180. else if (window_bits < 8)
  176181. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176182. #ifndef WBITS_8_OK
  176183. if (window_bits == 8)
  176184. {
  176185. png_warning(png_ptr, "Compression window is being reset to 512");
  176186. window_bits=9;
  176187. }
  176188. #endif
  176189. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176190. png_ptr->zlib_window_bits = window_bits;
  176191. }
  176192. void PNGAPI
  176193. png_set_compression_method(png_structp png_ptr, int method)
  176194. {
  176195. png_debug(1, "in png_set_compression_method\n");
  176196. if (png_ptr == NULL)
  176197. return;
  176198. if (method != 8)
  176199. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176200. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176201. png_ptr->zlib_method = method;
  176202. }
  176203. void PNGAPI
  176204. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176205. {
  176206. if (png_ptr == NULL)
  176207. return;
  176208. png_ptr->write_row_fn = write_row_fn;
  176209. }
  176210. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176211. void PNGAPI
  176212. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176213. write_user_transform_fn)
  176214. {
  176215. png_debug(1, "in png_set_write_user_transform_fn\n");
  176216. if (png_ptr == NULL)
  176217. return;
  176218. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176219. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176220. }
  176221. #endif
  176222. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176223. void PNGAPI
  176224. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176225. int transforms, voidp params)
  176226. {
  176227. if (png_ptr == NULL || info_ptr == NULL)
  176228. return;
  176229. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176230. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176231. png_set_invert_alpha(png_ptr);
  176232. #endif
  176233. png_write_info(png_ptr, info_ptr);
  176234. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176235. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176236. png_set_invert_mono(png_ptr);
  176237. #endif
  176238. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176239. if ((transforms & PNG_TRANSFORM_SHIFT)
  176240. && (info_ptr->valid & PNG_INFO_sBIT))
  176241. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176242. #endif
  176243. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176244. if (transforms & PNG_TRANSFORM_PACKING)
  176245. png_set_packing(png_ptr);
  176246. #endif
  176247. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176248. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176249. png_set_swap_alpha(png_ptr);
  176250. #endif
  176251. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176252. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176253. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176254. #endif
  176255. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176256. if (transforms & PNG_TRANSFORM_BGR)
  176257. png_set_bgr(png_ptr);
  176258. #endif
  176259. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176260. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176261. png_set_swap(png_ptr);
  176262. #endif
  176263. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176264. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176265. png_set_packswap(png_ptr);
  176266. #endif
  176267. if (info_ptr->valid & PNG_INFO_IDAT)
  176268. png_write_image(png_ptr, info_ptr->row_pointers);
  176269. png_write_end(png_ptr, info_ptr);
  176270. transforms = transforms; /* quiet compiler warnings */
  176271. params = params;
  176272. }
  176273. #endif
  176274. #endif /* PNG_WRITE_SUPPORTED */
  176275. /*** End of inlined file: pngwrite.c ***/
  176276. /*** Start of inlined file: pngwtran.c ***/
  176277. #define PNG_INTERNAL
  176278. #ifdef PNG_WRITE_SUPPORTED
  176279. void /* PRIVATE */
  176280. png_do_write_transformations(png_structp png_ptr)
  176281. {
  176282. png_debug(1, "in png_do_write_transformations\n");
  176283. if (png_ptr == NULL)
  176284. return;
  176285. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176286. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176287. if(png_ptr->write_user_transform_fn != NULL)
  176288. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176289. (png_ptr, /* png_ptr */
  176290. &(png_ptr->row_info), /* row_info: */
  176291. png_ptr->row_buf + 1); /* start of pixel data for row */
  176292. #endif
  176293. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176294. if (png_ptr->transformations & PNG_FILLER)
  176295. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176296. png_ptr->flags);
  176297. #endif
  176298. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176299. if (png_ptr->transformations & PNG_PACKSWAP)
  176300. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176301. #endif
  176302. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176303. if (png_ptr->transformations & PNG_PACK)
  176304. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176305. (png_uint_32)png_ptr->bit_depth);
  176306. #endif
  176307. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176308. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176309. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176310. #endif
  176311. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176312. if (png_ptr->transformations & PNG_SHIFT)
  176313. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176314. &(png_ptr->shift));
  176315. #endif
  176316. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176317. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176318. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176319. #endif
  176320. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176321. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176322. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176323. #endif
  176324. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176325. if (png_ptr->transformations & PNG_BGR)
  176326. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176327. #endif
  176328. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176329. if (png_ptr->transformations & PNG_INVERT_MONO)
  176330. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176331. #endif
  176332. }
  176333. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176334. void /* PRIVATE */
  176335. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176336. {
  176337. png_debug(1, "in png_do_pack\n");
  176338. if (row_info->bit_depth == 8 &&
  176339. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176340. row != NULL && row_info != NULL &&
  176341. #endif
  176342. row_info->channels == 1)
  176343. {
  176344. switch ((int)bit_depth)
  176345. {
  176346. case 1:
  176347. {
  176348. png_bytep sp, dp;
  176349. int mask, v;
  176350. png_uint_32 i;
  176351. png_uint_32 row_width = row_info->width;
  176352. sp = row;
  176353. dp = row;
  176354. mask = 0x80;
  176355. v = 0;
  176356. for (i = 0; i < row_width; i++)
  176357. {
  176358. if (*sp != 0)
  176359. v |= mask;
  176360. sp++;
  176361. if (mask > 1)
  176362. mask >>= 1;
  176363. else
  176364. {
  176365. mask = 0x80;
  176366. *dp = (png_byte)v;
  176367. dp++;
  176368. v = 0;
  176369. }
  176370. }
  176371. if (mask != 0x80)
  176372. *dp = (png_byte)v;
  176373. break;
  176374. }
  176375. case 2:
  176376. {
  176377. png_bytep sp, dp;
  176378. int shift, v;
  176379. png_uint_32 i;
  176380. png_uint_32 row_width = row_info->width;
  176381. sp = row;
  176382. dp = row;
  176383. shift = 6;
  176384. v = 0;
  176385. for (i = 0; i < row_width; i++)
  176386. {
  176387. png_byte value;
  176388. value = (png_byte)(*sp & 0x03);
  176389. v |= (value << shift);
  176390. if (shift == 0)
  176391. {
  176392. shift = 6;
  176393. *dp = (png_byte)v;
  176394. dp++;
  176395. v = 0;
  176396. }
  176397. else
  176398. shift -= 2;
  176399. sp++;
  176400. }
  176401. if (shift != 6)
  176402. *dp = (png_byte)v;
  176403. break;
  176404. }
  176405. case 4:
  176406. {
  176407. png_bytep sp, dp;
  176408. int shift, v;
  176409. png_uint_32 i;
  176410. png_uint_32 row_width = row_info->width;
  176411. sp = row;
  176412. dp = row;
  176413. shift = 4;
  176414. v = 0;
  176415. for (i = 0; i < row_width; i++)
  176416. {
  176417. png_byte value;
  176418. value = (png_byte)(*sp & 0x0f);
  176419. v |= (value << shift);
  176420. if (shift == 0)
  176421. {
  176422. shift = 4;
  176423. *dp = (png_byte)v;
  176424. dp++;
  176425. v = 0;
  176426. }
  176427. else
  176428. shift -= 4;
  176429. sp++;
  176430. }
  176431. if (shift != 4)
  176432. *dp = (png_byte)v;
  176433. break;
  176434. }
  176435. }
  176436. row_info->bit_depth = (png_byte)bit_depth;
  176437. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176438. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176439. row_info->width);
  176440. }
  176441. }
  176442. #endif
  176443. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176444. void /* PRIVATE */
  176445. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176446. {
  176447. png_debug(1, "in png_do_shift\n");
  176448. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176449. if (row != NULL && row_info != NULL &&
  176450. #else
  176451. if (
  176452. #endif
  176453. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176454. {
  176455. int shift_start[4], shift_dec[4];
  176456. int channels = 0;
  176457. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176458. {
  176459. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176460. shift_dec[channels] = bit_depth->red;
  176461. channels++;
  176462. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176463. shift_dec[channels] = bit_depth->green;
  176464. channels++;
  176465. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176466. shift_dec[channels] = bit_depth->blue;
  176467. channels++;
  176468. }
  176469. else
  176470. {
  176471. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176472. shift_dec[channels] = bit_depth->gray;
  176473. channels++;
  176474. }
  176475. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176476. {
  176477. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176478. shift_dec[channels] = bit_depth->alpha;
  176479. channels++;
  176480. }
  176481. if (row_info->bit_depth < 8)
  176482. {
  176483. png_bytep bp = row;
  176484. png_uint_32 i;
  176485. png_byte mask;
  176486. png_uint_32 row_bytes = row_info->rowbytes;
  176487. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176488. mask = 0x55;
  176489. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176490. mask = 0x11;
  176491. else
  176492. mask = 0xff;
  176493. for (i = 0; i < row_bytes; i++, bp++)
  176494. {
  176495. png_uint_16 v;
  176496. int j;
  176497. v = *bp;
  176498. *bp = 0;
  176499. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176500. {
  176501. if (j > 0)
  176502. *bp |= (png_byte)((v << j) & 0xff);
  176503. else
  176504. *bp |= (png_byte)((v >> (-j)) & mask);
  176505. }
  176506. }
  176507. }
  176508. else if (row_info->bit_depth == 8)
  176509. {
  176510. png_bytep bp = row;
  176511. png_uint_32 i;
  176512. png_uint_32 istop = channels * row_info->width;
  176513. for (i = 0; i < istop; i++, bp++)
  176514. {
  176515. png_uint_16 v;
  176516. int j;
  176517. int c = (int)(i%channels);
  176518. v = *bp;
  176519. *bp = 0;
  176520. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176521. {
  176522. if (j > 0)
  176523. *bp |= (png_byte)((v << j) & 0xff);
  176524. else
  176525. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176526. }
  176527. }
  176528. }
  176529. else
  176530. {
  176531. png_bytep bp;
  176532. png_uint_32 i;
  176533. png_uint_32 istop = channels * row_info->width;
  176534. for (bp = row, i = 0; i < istop; i++)
  176535. {
  176536. int c = (int)(i%channels);
  176537. png_uint_16 value, v;
  176538. int j;
  176539. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176540. value = 0;
  176541. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176542. {
  176543. if (j > 0)
  176544. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176545. else
  176546. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176547. }
  176548. *bp++ = (png_byte)(value >> 8);
  176549. *bp++ = (png_byte)(value & 0xff);
  176550. }
  176551. }
  176552. }
  176553. }
  176554. #endif
  176555. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176556. void /* PRIVATE */
  176557. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176558. {
  176559. png_debug(1, "in png_do_write_swap_alpha\n");
  176560. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176561. if (row != NULL && row_info != NULL)
  176562. #endif
  176563. {
  176564. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176565. {
  176566. if (row_info->bit_depth == 8)
  176567. {
  176568. png_bytep sp, dp;
  176569. png_uint_32 i;
  176570. png_uint_32 row_width = row_info->width;
  176571. for (i = 0, sp = dp = row; i < row_width; i++)
  176572. {
  176573. png_byte save = *(sp++);
  176574. *(dp++) = *(sp++);
  176575. *(dp++) = *(sp++);
  176576. *(dp++) = *(sp++);
  176577. *(dp++) = save;
  176578. }
  176579. }
  176580. else
  176581. {
  176582. png_bytep sp, dp;
  176583. png_uint_32 i;
  176584. png_uint_32 row_width = row_info->width;
  176585. for (i = 0, sp = dp = row; i < row_width; i++)
  176586. {
  176587. png_byte save[2];
  176588. save[0] = *(sp++);
  176589. save[1] = *(sp++);
  176590. *(dp++) = *(sp++);
  176591. *(dp++) = *(sp++);
  176592. *(dp++) = *(sp++);
  176593. *(dp++) = *(sp++);
  176594. *(dp++) = *(sp++);
  176595. *(dp++) = *(sp++);
  176596. *(dp++) = save[0];
  176597. *(dp++) = save[1];
  176598. }
  176599. }
  176600. }
  176601. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176602. {
  176603. if (row_info->bit_depth == 8)
  176604. {
  176605. png_bytep sp, dp;
  176606. png_uint_32 i;
  176607. png_uint_32 row_width = row_info->width;
  176608. for (i = 0, sp = dp = row; i < row_width; i++)
  176609. {
  176610. png_byte save = *(sp++);
  176611. *(dp++) = *(sp++);
  176612. *(dp++) = save;
  176613. }
  176614. }
  176615. else
  176616. {
  176617. png_bytep sp, dp;
  176618. png_uint_32 i;
  176619. png_uint_32 row_width = row_info->width;
  176620. for (i = 0, sp = dp = row; i < row_width; i++)
  176621. {
  176622. png_byte save[2];
  176623. save[0] = *(sp++);
  176624. save[1] = *(sp++);
  176625. *(dp++) = *(sp++);
  176626. *(dp++) = *(sp++);
  176627. *(dp++) = save[0];
  176628. *(dp++) = save[1];
  176629. }
  176630. }
  176631. }
  176632. }
  176633. }
  176634. #endif
  176635. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176636. void /* PRIVATE */
  176637. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176638. {
  176639. png_debug(1, "in png_do_write_invert_alpha\n");
  176640. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176641. if (row != NULL && row_info != NULL)
  176642. #endif
  176643. {
  176644. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176645. {
  176646. if (row_info->bit_depth == 8)
  176647. {
  176648. png_bytep sp, dp;
  176649. png_uint_32 i;
  176650. png_uint_32 row_width = row_info->width;
  176651. for (i = 0, sp = dp = row; i < row_width; i++)
  176652. {
  176653. sp+=3; dp = sp;
  176654. *(dp++) = (png_byte)(255 - *(sp++));
  176655. }
  176656. }
  176657. else
  176658. {
  176659. png_bytep sp, dp;
  176660. png_uint_32 i;
  176661. png_uint_32 row_width = row_info->width;
  176662. for (i = 0, sp = dp = row; i < row_width; i++)
  176663. {
  176664. sp+=6; dp = sp;
  176665. *(dp++) = (png_byte)(255 - *(sp++));
  176666. *(dp++) = (png_byte)(255 - *(sp++));
  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. *(dp++) = *(sp++);
  176680. *(dp++) = (png_byte)(255 - *(sp++));
  176681. }
  176682. }
  176683. else
  176684. {
  176685. png_bytep sp, dp;
  176686. png_uint_32 i;
  176687. png_uint_32 row_width = row_info->width;
  176688. for (i = 0, sp = dp = row; i < row_width; i++)
  176689. {
  176690. sp+=2; dp = sp;
  176691. *(dp++) = (png_byte)(255 - *(sp++));
  176692. *(dp++) = (png_byte)(255 - *(sp++));
  176693. }
  176694. }
  176695. }
  176696. }
  176697. }
  176698. #endif
  176699. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176700. void /* PRIVATE */
  176701. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176702. {
  176703. png_debug(1, "in png_do_write_intrapixel\n");
  176704. if (
  176705. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176706. row != NULL && row_info != NULL &&
  176707. #endif
  176708. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176709. {
  176710. int bytes_per_pixel;
  176711. png_uint_32 row_width = row_info->width;
  176712. if (row_info->bit_depth == 8)
  176713. {
  176714. png_bytep rp;
  176715. png_uint_32 i;
  176716. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176717. bytes_per_pixel = 3;
  176718. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176719. bytes_per_pixel = 4;
  176720. else
  176721. return;
  176722. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176723. {
  176724. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176725. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176726. }
  176727. }
  176728. else if (row_info->bit_depth == 16)
  176729. {
  176730. png_bytep rp;
  176731. png_uint_32 i;
  176732. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176733. bytes_per_pixel = 6;
  176734. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176735. bytes_per_pixel = 8;
  176736. else
  176737. return;
  176738. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176739. {
  176740. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176741. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176742. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176743. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176744. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176745. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176746. *(rp+1) = (png_byte)(red & 0xff);
  176747. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176748. *(rp+5) = (png_byte)(blue & 0xff);
  176749. }
  176750. }
  176751. }
  176752. }
  176753. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176754. #endif /* PNG_WRITE_SUPPORTED */
  176755. /*** End of inlined file: pngwtran.c ***/
  176756. /*** Start of inlined file: pngwutil.c ***/
  176757. #define PNG_INTERNAL
  176758. #ifdef PNG_WRITE_SUPPORTED
  176759. void PNGAPI
  176760. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176761. {
  176762. buf[0] = (png_byte)((i >> 24) & 0xff);
  176763. buf[1] = (png_byte)((i >> 16) & 0xff);
  176764. buf[2] = (png_byte)((i >> 8) & 0xff);
  176765. buf[3] = (png_byte)(i & 0xff);
  176766. }
  176767. void PNGAPI
  176768. png_save_int_32(png_bytep buf, png_int_32 i)
  176769. {
  176770. buf[0] = (png_byte)((i >> 24) & 0xff);
  176771. buf[1] = (png_byte)((i >> 16) & 0xff);
  176772. buf[2] = (png_byte)((i >> 8) & 0xff);
  176773. buf[3] = (png_byte)(i & 0xff);
  176774. }
  176775. void PNGAPI
  176776. png_save_uint_16(png_bytep buf, unsigned int i)
  176777. {
  176778. buf[0] = (png_byte)((i >> 8) & 0xff);
  176779. buf[1] = (png_byte)(i & 0xff);
  176780. }
  176781. void PNGAPI
  176782. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176783. png_bytep data, png_size_t length)
  176784. {
  176785. if(png_ptr == NULL) return;
  176786. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176787. png_write_chunk_data(png_ptr, data, length);
  176788. png_write_chunk_end(png_ptr);
  176789. }
  176790. void PNGAPI
  176791. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176792. png_uint_32 length)
  176793. {
  176794. png_byte buf[4];
  176795. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176796. if(png_ptr == NULL) return;
  176797. png_save_uint_32(buf, length);
  176798. png_write_data(png_ptr, buf, (png_size_t)4);
  176799. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176800. png_reset_crc(png_ptr);
  176801. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176802. }
  176803. void PNGAPI
  176804. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176805. {
  176806. if(png_ptr == NULL) return;
  176807. if (data != NULL && length > 0)
  176808. {
  176809. png_calculate_crc(png_ptr, data, length);
  176810. png_write_data(png_ptr, data, length);
  176811. }
  176812. }
  176813. void PNGAPI
  176814. png_write_chunk_end(png_structp png_ptr)
  176815. {
  176816. png_byte buf[4];
  176817. if(png_ptr == NULL) return;
  176818. png_save_uint_32(buf, png_ptr->crc);
  176819. png_write_data(png_ptr, buf, (png_size_t)4);
  176820. }
  176821. void /* PRIVATE */
  176822. png_write_sig(png_structp png_ptr)
  176823. {
  176824. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176825. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176826. (png_size_t)8 - png_ptr->sig_bytes);
  176827. if(png_ptr->sig_bytes < 3)
  176828. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176829. }
  176830. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176831. typedef struct
  176832. {
  176833. char *input; /* the uncompressed input data */
  176834. int input_len; /* its length */
  176835. int num_output_ptr; /* number of output pointers used */
  176836. int max_output_ptr; /* size of output_ptr */
  176837. png_charpp output_ptr; /* array of pointers to output */
  176838. } compression_state;
  176839. static int /* PRIVATE */
  176840. png_text_compress(png_structp png_ptr,
  176841. png_charp text, png_size_t text_len, int compression,
  176842. compression_state *comp)
  176843. {
  176844. int ret;
  176845. comp->num_output_ptr = 0;
  176846. comp->max_output_ptr = 0;
  176847. comp->output_ptr = NULL;
  176848. comp->input = NULL;
  176849. comp->input_len = 0;
  176850. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176851. {
  176852. comp->input = text;
  176853. comp->input_len = text_len;
  176854. return((int)text_len);
  176855. }
  176856. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176857. {
  176858. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176859. char msg[50];
  176860. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176861. png_warning(png_ptr, msg);
  176862. #else
  176863. png_warning(png_ptr, "Unknown compression type");
  176864. #endif
  176865. }
  176866. png_ptr->zstream.avail_in = (uInt)text_len;
  176867. png_ptr->zstream.next_in = (Bytef *)text;
  176868. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176869. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176870. do
  176871. {
  176872. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176873. if (ret != Z_OK)
  176874. {
  176875. if (png_ptr->zstream.msg != NULL)
  176876. png_error(png_ptr, png_ptr->zstream.msg);
  176877. else
  176878. png_error(png_ptr, "zlib error");
  176879. }
  176880. if (!(png_ptr->zstream.avail_out))
  176881. {
  176882. if (comp->num_output_ptr >= comp->max_output_ptr)
  176883. {
  176884. int old_max;
  176885. old_max = comp->max_output_ptr;
  176886. comp->max_output_ptr = comp->num_output_ptr + 4;
  176887. if (comp->output_ptr != NULL)
  176888. {
  176889. png_charpp old_ptr;
  176890. old_ptr = comp->output_ptr;
  176891. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176892. (png_uint_32)(comp->max_output_ptr *
  176893. png_sizeof (png_charpp)));
  176894. png_memcpy(comp->output_ptr, old_ptr, old_max
  176895. * png_sizeof (png_charp));
  176896. png_free(png_ptr, old_ptr);
  176897. }
  176898. else
  176899. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176900. (png_uint_32)(comp->max_output_ptr *
  176901. png_sizeof (png_charp)));
  176902. }
  176903. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176904. (png_uint_32)png_ptr->zbuf_size);
  176905. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176906. png_ptr->zbuf_size);
  176907. comp->num_output_ptr++;
  176908. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176909. png_ptr->zstream.next_out = png_ptr->zbuf;
  176910. }
  176911. } while (png_ptr->zstream.avail_in);
  176912. do
  176913. {
  176914. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176915. if (ret == Z_OK)
  176916. {
  176917. if (!(png_ptr->zstream.avail_out))
  176918. {
  176919. if (comp->num_output_ptr >= comp->max_output_ptr)
  176920. {
  176921. int old_max;
  176922. old_max = comp->max_output_ptr;
  176923. comp->max_output_ptr = comp->num_output_ptr + 4;
  176924. if (comp->output_ptr != NULL)
  176925. {
  176926. png_charpp old_ptr;
  176927. old_ptr = comp->output_ptr;
  176928. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176929. (png_uint_32)(comp->max_output_ptr *
  176930. png_sizeof (png_charpp)));
  176931. png_memcpy(comp->output_ptr, old_ptr,
  176932. old_max * png_sizeof (png_charp));
  176933. png_free(png_ptr, old_ptr);
  176934. }
  176935. else
  176936. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176937. (png_uint_32)(comp->max_output_ptr *
  176938. png_sizeof (png_charp)));
  176939. }
  176940. comp->output_ptr[comp->num_output_ptr] =
  176941. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  176942. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176943. png_ptr->zbuf_size);
  176944. comp->num_output_ptr++;
  176945. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176946. png_ptr->zstream.next_out = png_ptr->zbuf;
  176947. }
  176948. }
  176949. else if (ret != Z_STREAM_END)
  176950. {
  176951. if (png_ptr->zstream.msg != NULL)
  176952. png_error(png_ptr, png_ptr->zstream.msg);
  176953. else
  176954. png_error(png_ptr, "zlib error");
  176955. }
  176956. } while (ret != Z_STREAM_END);
  176957. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  176958. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  176959. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  176960. return((int)text_len);
  176961. }
  176962. static void /* PRIVATE */
  176963. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  176964. {
  176965. int i;
  176966. if (comp->input)
  176967. {
  176968. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  176969. (png_size_t)comp->input_len);
  176970. return;
  176971. }
  176972. for (i = 0; i < comp->num_output_ptr; i++)
  176973. {
  176974. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  176975. png_ptr->zbuf_size);
  176976. png_free(png_ptr, comp->output_ptr[i]);
  176977. comp->output_ptr[i]=NULL;
  176978. }
  176979. if (comp->max_output_ptr != 0)
  176980. png_free(png_ptr, comp->output_ptr);
  176981. comp->output_ptr=NULL;
  176982. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  176983. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  176984. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176985. deflateReset(&png_ptr->zstream);
  176986. png_ptr->zstream.data_type = Z_BINARY;
  176987. }
  176988. #endif
  176989. void /* PRIVATE */
  176990. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  176991. int bit_depth, int color_type, int compression_type, int filter_type,
  176992. int interlace_type)
  176993. {
  176994. #ifdef PNG_USE_LOCAL_ARRAYS
  176995. PNG_IHDR;
  176996. #endif
  176997. png_byte buf[13]; /* buffer to store the IHDR info */
  176998. png_debug(1, "in png_write_IHDR\n");
  176999. switch (color_type)
  177000. {
  177001. case PNG_COLOR_TYPE_GRAY:
  177002. switch (bit_depth)
  177003. {
  177004. case 1:
  177005. case 2:
  177006. case 4:
  177007. case 8:
  177008. case 16: png_ptr->channels = 1; break;
  177009. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177010. }
  177011. break;
  177012. case PNG_COLOR_TYPE_RGB:
  177013. if (bit_depth != 8 && bit_depth != 16)
  177014. png_error(png_ptr, "Invalid bit depth for RGB image");
  177015. png_ptr->channels = 3;
  177016. break;
  177017. case PNG_COLOR_TYPE_PALETTE:
  177018. switch (bit_depth)
  177019. {
  177020. case 1:
  177021. case 2:
  177022. case 4:
  177023. case 8: png_ptr->channels = 1; break;
  177024. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177025. }
  177026. break;
  177027. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177028. if (bit_depth != 8 && bit_depth != 16)
  177029. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177030. png_ptr->channels = 2;
  177031. break;
  177032. case PNG_COLOR_TYPE_RGB_ALPHA:
  177033. if (bit_depth != 8 && bit_depth != 16)
  177034. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177035. png_ptr->channels = 4;
  177036. break;
  177037. default:
  177038. png_error(png_ptr, "Invalid image color type specified");
  177039. }
  177040. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177041. {
  177042. png_warning(png_ptr, "Invalid compression type specified");
  177043. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177044. }
  177045. if (
  177046. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177047. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177048. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177049. (color_type == PNG_COLOR_TYPE_RGB ||
  177050. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177051. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177052. #endif
  177053. filter_type != PNG_FILTER_TYPE_BASE)
  177054. {
  177055. png_warning(png_ptr, "Invalid filter type specified");
  177056. filter_type = PNG_FILTER_TYPE_BASE;
  177057. }
  177058. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177059. if (interlace_type != PNG_INTERLACE_NONE &&
  177060. interlace_type != PNG_INTERLACE_ADAM7)
  177061. {
  177062. png_warning(png_ptr, "Invalid interlace type specified");
  177063. interlace_type = PNG_INTERLACE_ADAM7;
  177064. }
  177065. #else
  177066. interlace_type=PNG_INTERLACE_NONE;
  177067. #endif
  177068. png_ptr->bit_depth = (png_byte)bit_depth;
  177069. png_ptr->color_type = (png_byte)color_type;
  177070. png_ptr->interlaced = (png_byte)interlace_type;
  177071. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177072. png_ptr->filter_type = (png_byte)filter_type;
  177073. #endif
  177074. png_ptr->compression_type = (png_byte)compression_type;
  177075. png_ptr->width = width;
  177076. png_ptr->height = height;
  177077. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177078. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177079. png_ptr->usr_width = png_ptr->width;
  177080. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177081. png_ptr->usr_channels = png_ptr->channels;
  177082. png_save_uint_32(buf, width);
  177083. png_save_uint_32(buf + 4, height);
  177084. buf[8] = (png_byte)bit_depth;
  177085. buf[9] = (png_byte)color_type;
  177086. buf[10] = (png_byte)compression_type;
  177087. buf[11] = (png_byte)filter_type;
  177088. buf[12] = (png_byte)interlace_type;
  177089. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177090. png_ptr->zstream.zalloc = png_zalloc;
  177091. png_ptr->zstream.zfree = png_zfree;
  177092. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177093. if (!(png_ptr->do_filter))
  177094. {
  177095. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177096. png_ptr->bit_depth < 8)
  177097. png_ptr->do_filter = PNG_FILTER_NONE;
  177098. else
  177099. png_ptr->do_filter = PNG_ALL_FILTERS;
  177100. }
  177101. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177102. {
  177103. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177104. png_ptr->zlib_strategy = Z_FILTERED;
  177105. else
  177106. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177107. }
  177108. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177109. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177110. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177111. png_ptr->zlib_mem_level = 8;
  177112. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177113. png_ptr->zlib_window_bits = 15;
  177114. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177115. png_ptr->zlib_method = 8;
  177116. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177117. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177118. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177119. png_error(png_ptr, "zlib failed to initialize compressor");
  177120. png_ptr->zstream.next_out = png_ptr->zbuf;
  177121. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177122. png_ptr->zstream.data_type = Z_BINARY;
  177123. png_ptr->mode = PNG_HAVE_IHDR;
  177124. }
  177125. void /* PRIVATE */
  177126. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177127. {
  177128. #ifdef PNG_USE_LOCAL_ARRAYS
  177129. PNG_PLTE;
  177130. #endif
  177131. png_uint_32 i;
  177132. png_colorp pal_ptr;
  177133. png_byte buf[3];
  177134. png_debug(1, "in png_write_PLTE\n");
  177135. if ((
  177136. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177137. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177138. #endif
  177139. num_pal == 0) || num_pal > 256)
  177140. {
  177141. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177142. {
  177143. png_error(png_ptr, "Invalid number of colors in palette");
  177144. }
  177145. else
  177146. {
  177147. png_warning(png_ptr, "Invalid number of colors in palette");
  177148. return;
  177149. }
  177150. }
  177151. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177152. {
  177153. png_warning(png_ptr,
  177154. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177155. return;
  177156. }
  177157. png_ptr->num_palette = (png_uint_16)num_pal;
  177158. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177159. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177160. #ifndef PNG_NO_POINTER_INDEXING
  177161. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177162. {
  177163. buf[0] = pal_ptr->red;
  177164. buf[1] = pal_ptr->green;
  177165. buf[2] = pal_ptr->blue;
  177166. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177167. }
  177168. #else
  177169. pal_ptr=palette;
  177170. for (i = 0; i < num_pal; i++)
  177171. {
  177172. buf[0] = pal_ptr[i].red;
  177173. buf[1] = pal_ptr[i].green;
  177174. buf[2] = pal_ptr[i].blue;
  177175. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177176. }
  177177. #endif
  177178. png_write_chunk_end(png_ptr);
  177179. png_ptr->mode |= PNG_HAVE_PLTE;
  177180. }
  177181. void /* PRIVATE */
  177182. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177183. {
  177184. #ifdef PNG_USE_LOCAL_ARRAYS
  177185. PNG_IDAT;
  177186. #endif
  177187. png_debug(1, "in png_write_IDAT\n");
  177188. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177189. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177190. {
  177191. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177192. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177193. {
  177194. if (length >= 2 &&
  177195. png_ptr->height < 16384 && png_ptr->width < 16384)
  177196. {
  177197. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177198. ((png_ptr->width *
  177199. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177200. unsigned int z_cinfo = z_cmf >> 4;
  177201. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177202. while (uncompressed_idat_size <= half_z_window_size &&
  177203. half_z_window_size >= 256)
  177204. {
  177205. z_cinfo--;
  177206. half_z_window_size >>= 1;
  177207. }
  177208. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177209. if (data[0] != (png_byte)z_cmf)
  177210. {
  177211. data[0] = (png_byte)z_cmf;
  177212. data[1] &= 0xe0;
  177213. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177214. }
  177215. }
  177216. }
  177217. else
  177218. png_error(png_ptr,
  177219. "Invalid zlib compression method or flags in IDAT");
  177220. }
  177221. png_write_chunk(png_ptr, png_IDAT, data, length);
  177222. png_ptr->mode |= PNG_HAVE_IDAT;
  177223. }
  177224. void /* PRIVATE */
  177225. png_write_IEND(png_structp png_ptr)
  177226. {
  177227. #ifdef PNG_USE_LOCAL_ARRAYS
  177228. PNG_IEND;
  177229. #endif
  177230. png_debug(1, "in png_write_IEND\n");
  177231. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177232. (png_size_t)0);
  177233. png_ptr->mode |= PNG_HAVE_IEND;
  177234. }
  177235. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177236. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177237. void /* PRIVATE */
  177238. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177239. {
  177240. #ifdef PNG_USE_LOCAL_ARRAYS
  177241. PNG_gAMA;
  177242. #endif
  177243. png_uint_32 igamma;
  177244. png_byte buf[4];
  177245. png_debug(1, "in png_write_gAMA\n");
  177246. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177247. png_save_uint_32(buf, igamma);
  177248. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177249. }
  177250. #endif
  177251. #ifdef PNG_FIXED_POINT_SUPPORTED
  177252. void /* PRIVATE */
  177253. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177254. {
  177255. #ifdef PNG_USE_LOCAL_ARRAYS
  177256. PNG_gAMA;
  177257. #endif
  177258. png_byte buf[4];
  177259. png_debug(1, "in png_write_gAMA\n");
  177260. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177261. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177262. }
  177263. #endif
  177264. #endif
  177265. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177266. void /* PRIVATE */
  177267. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177268. {
  177269. #ifdef PNG_USE_LOCAL_ARRAYS
  177270. PNG_sRGB;
  177271. #endif
  177272. png_byte buf[1];
  177273. png_debug(1, "in png_write_sRGB\n");
  177274. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177275. png_warning(png_ptr,
  177276. "Invalid sRGB rendering intent specified");
  177277. buf[0]=(png_byte)srgb_intent;
  177278. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177279. }
  177280. #endif
  177281. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177282. void /* PRIVATE */
  177283. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177284. png_charp profile, int profile_len)
  177285. {
  177286. #ifdef PNG_USE_LOCAL_ARRAYS
  177287. PNG_iCCP;
  177288. #endif
  177289. png_size_t name_len;
  177290. png_charp new_name;
  177291. compression_state comp;
  177292. int embedded_profile_len = 0;
  177293. png_debug(1, "in png_write_iCCP\n");
  177294. comp.num_output_ptr = 0;
  177295. comp.max_output_ptr = 0;
  177296. comp.output_ptr = NULL;
  177297. comp.input = NULL;
  177298. comp.input_len = 0;
  177299. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177300. &new_name)) == 0)
  177301. {
  177302. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177303. return;
  177304. }
  177305. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177306. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177307. if (profile == NULL)
  177308. profile_len = 0;
  177309. if (profile_len > 3)
  177310. embedded_profile_len =
  177311. ((*( (png_bytep)profile ))<<24) |
  177312. ((*( (png_bytep)profile+1))<<16) |
  177313. ((*( (png_bytep)profile+2))<< 8) |
  177314. ((*( (png_bytep)profile+3)) );
  177315. if (profile_len < embedded_profile_len)
  177316. {
  177317. png_warning(png_ptr,
  177318. "Embedded profile length too large in iCCP chunk");
  177319. return;
  177320. }
  177321. if (profile_len > embedded_profile_len)
  177322. {
  177323. png_warning(png_ptr,
  177324. "Truncating profile to actual length in iCCP chunk");
  177325. profile_len = embedded_profile_len;
  177326. }
  177327. if (profile_len)
  177328. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177329. PNG_COMPRESSION_TYPE_BASE, &comp);
  177330. png_write_chunk_start(png_ptr, png_iCCP,
  177331. (png_uint_32)name_len+profile_len+2);
  177332. new_name[name_len+1]=0x00;
  177333. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177334. if (profile_len)
  177335. png_write_compressed_data_out(png_ptr, &comp);
  177336. png_write_chunk_end(png_ptr);
  177337. png_free(png_ptr, new_name);
  177338. }
  177339. #endif
  177340. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177341. void /* PRIVATE */
  177342. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177343. {
  177344. #ifdef PNG_USE_LOCAL_ARRAYS
  177345. PNG_sPLT;
  177346. #endif
  177347. png_size_t name_len;
  177348. png_charp new_name;
  177349. png_byte entrybuf[10];
  177350. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177351. int palette_size = entry_size * spalette->nentries;
  177352. png_sPLT_entryp ep;
  177353. #ifdef PNG_NO_POINTER_INDEXING
  177354. int i;
  177355. #endif
  177356. png_debug(1, "in png_write_sPLT\n");
  177357. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177358. spalette->name, &new_name))==0)
  177359. {
  177360. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177361. return;
  177362. }
  177363. png_write_chunk_start(png_ptr, png_sPLT,
  177364. (png_uint_32)(name_len + 2 + palette_size));
  177365. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177366. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177367. #ifndef PNG_NO_POINTER_INDEXING
  177368. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177369. {
  177370. if (spalette->depth == 8)
  177371. {
  177372. entrybuf[0] = (png_byte)ep->red;
  177373. entrybuf[1] = (png_byte)ep->green;
  177374. entrybuf[2] = (png_byte)ep->blue;
  177375. entrybuf[3] = (png_byte)ep->alpha;
  177376. png_save_uint_16(entrybuf + 4, ep->frequency);
  177377. }
  177378. else
  177379. {
  177380. png_save_uint_16(entrybuf + 0, ep->red);
  177381. png_save_uint_16(entrybuf + 2, ep->green);
  177382. png_save_uint_16(entrybuf + 4, ep->blue);
  177383. png_save_uint_16(entrybuf + 6, ep->alpha);
  177384. png_save_uint_16(entrybuf + 8, ep->frequency);
  177385. }
  177386. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177387. }
  177388. #else
  177389. ep=spalette->entries;
  177390. for (i=0; i>spalette->nentries; i++)
  177391. {
  177392. if (spalette->depth == 8)
  177393. {
  177394. entrybuf[0] = (png_byte)ep[i].red;
  177395. entrybuf[1] = (png_byte)ep[i].green;
  177396. entrybuf[2] = (png_byte)ep[i].blue;
  177397. entrybuf[3] = (png_byte)ep[i].alpha;
  177398. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177399. }
  177400. else
  177401. {
  177402. png_save_uint_16(entrybuf + 0, ep[i].red);
  177403. png_save_uint_16(entrybuf + 2, ep[i].green);
  177404. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177405. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177406. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177407. }
  177408. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177409. }
  177410. #endif
  177411. png_write_chunk_end(png_ptr);
  177412. png_free(png_ptr, new_name);
  177413. }
  177414. #endif
  177415. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177416. void /* PRIVATE */
  177417. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177418. {
  177419. #ifdef PNG_USE_LOCAL_ARRAYS
  177420. PNG_sBIT;
  177421. #endif
  177422. png_byte buf[4];
  177423. png_size_t size;
  177424. png_debug(1, "in png_write_sBIT\n");
  177425. if (color_type & PNG_COLOR_MASK_COLOR)
  177426. {
  177427. png_byte maxbits;
  177428. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177429. png_ptr->usr_bit_depth);
  177430. if (sbit->red == 0 || sbit->red > maxbits ||
  177431. sbit->green == 0 || sbit->green > maxbits ||
  177432. sbit->blue == 0 || sbit->blue > maxbits)
  177433. {
  177434. png_warning(png_ptr, "Invalid sBIT depth specified");
  177435. return;
  177436. }
  177437. buf[0] = sbit->red;
  177438. buf[1] = sbit->green;
  177439. buf[2] = sbit->blue;
  177440. size = 3;
  177441. }
  177442. else
  177443. {
  177444. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177445. {
  177446. png_warning(png_ptr, "Invalid sBIT depth specified");
  177447. return;
  177448. }
  177449. buf[0] = sbit->gray;
  177450. size = 1;
  177451. }
  177452. if (color_type & PNG_COLOR_MASK_ALPHA)
  177453. {
  177454. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177455. {
  177456. png_warning(png_ptr, "Invalid sBIT depth specified");
  177457. return;
  177458. }
  177459. buf[size++] = sbit->alpha;
  177460. }
  177461. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177462. }
  177463. #endif
  177464. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177465. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177466. void /* PRIVATE */
  177467. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177468. double red_x, double red_y, double green_x, double green_y,
  177469. double blue_x, double blue_y)
  177470. {
  177471. #ifdef PNG_USE_LOCAL_ARRAYS
  177472. PNG_cHRM;
  177473. #endif
  177474. png_byte buf[32];
  177475. png_uint_32 itemp;
  177476. png_debug(1, "in png_write_cHRM\n");
  177477. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177478. white_x + white_y > 1.0)
  177479. {
  177480. png_warning(png_ptr, "Invalid cHRM white point specified");
  177481. #if !defined(PNG_NO_CONSOLE_IO)
  177482. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177483. #endif
  177484. return;
  177485. }
  177486. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177487. png_save_uint_32(buf, itemp);
  177488. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177489. png_save_uint_32(buf + 4, itemp);
  177490. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177491. {
  177492. png_warning(png_ptr, "Invalid cHRM red point specified");
  177493. return;
  177494. }
  177495. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177496. png_save_uint_32(buf + 8, itemp);
  177497. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177498. png_save_uint_32(buf + 12, itemp);
  177499. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177500. {
  177501. png_warning(png_ptr, "Invalid cHRM green point specified");
  177502. return;
  177503. }
  177504. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177505. png_save_uint_32(buf + 16, itemp);
  177506. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177507. png_save_uint_32(buf + 20, itemp);
  177508. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177509. {
  177510. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177511. return;
  177512. }
  177513. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177514. png_save_uint_32(buf + 24, itemp);
  177515. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177516. png_save_uint_32(buf + 28, itemp);
  177517. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177518. }
  177519. #endif
  177520. #ifdef PNG_FIXED_POINT_SUPPORTED
  177521. void /* PRIVATE */
  177522. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177523. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177524. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177525. png_fixed_point blue_y)
  177526. {
  177527. #ifdef PNG_USE_LOCAL_ARRAYS
  177528. PNG_cHRM;
  177529. #endif
  177530. png_byte buf[32];
  177531. png_debug(1, "in png_write_cHRM\n");
  177532. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177533. {
  177534. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177535. #if !defined(PNG_NO_CONSOLE_IO)
  177536. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177537. #endif
  177538. return;
  177539. }
  177540. png_save_uint_32(buf, (png_uint_32)white_x);
  177541. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177542. if (red_x + red_y > 100000L)
  177543. {
  177544. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177545. return;
  177546. }
  177547. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177548. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177549. if (green_x + green_y > 100000L)
  177550. {
  177551. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177552. return;
  177553. }
  177554. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177555. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177556. if (blue_x + blue_y > 100000L)
  177557. {
  177558. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177559. return;
  177560. }
  177561. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177562. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177563. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177564. }
  177565. #endif
  177566. #endif
  177567. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177568. void /* PRIVATE */
  177569. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177570. int num_trans, int color_type)
  177571. {
  177572. #ifdef PNG_USE_LOCAL_ARRAYS
  177573. PNG_tRNS;
  177574. #endif
  177575. png_byte buf[6];
  177576. png_debug(1, "in png_write_tRNS\n");
  177577. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177578. {
  177579. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177580. {
  177581. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177582. return;
  177583. }
  177584. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177585. }
  177586. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177587. {
  177588. if(tran->gray >= (1 << png_ptr->bit_depth))
  177589. {
  177590. png_warning(png_ptr,
  177591. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177592. return;
  177593. }
  177594. png_save_uint_16(buf, tran->gray);
  177595. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177596. }
  177597. else if (color_type == PNG_COLOR_TYPE_RGB)
  177598. {
  177599. png_save_uint_16(buf, tran->red);
  177600. png_save_uint_16(buf + 2, tran->green);
  177601. png_save_uint_16(buf + 4, tran->blue);
  177602. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177603. {
  177604. png_warning(png_ptr,
  177605. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177606. return;
  177607. }
  177608. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177609. }
  177610. else
  177611. {
  177612. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177613. }
  177614. }
  177615. #endif
  177616. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177617. void /* PRIVATE */
  177618. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177619. {
  177620. #ifdef PNG_USE_LOCAL_ARRAYS
  177621. PNG_bKGD;
  177622. #endif
  177623. png_byte buf[6];
  177624. png_debug(1, "in png_write_bKGD\n");
  177625. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177626. {
  177627. if (
  177628. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177629. (png_ptr->num_palette ||
  177630. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177631. #endif
  177632. back->index > png_ptr->num_palette)
  177633. {
  177634. png_warning(png_ptr, "Invalid background palette index");
  177635. return;
  177636. }
  177637. buf[0] = back->index;
  177638. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177639. }
  177640. else if (color_type & PNG_COLOR_MASK_COLOR)
  177641. {
  177642. png_save_uint_16(buf, back->red);
  177643. png_save_uint_16(buf + 2, back->green);
  177644. png_save_uint_16(buf + 4, back->blue);
  177645. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177646. {
  177647. png_warning(png_ptr,
  177648. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177649. return;
  177650. }
  177651. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177652. }
  177653. else
  177654. {
  177655. if(back->gray >= (1 << png_ptr->bit_depth))
  177656. {
  177657. png_warning(png_ptr,
  177658. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177659. return;
  177660. }
  177661. png_save_uint_16(buf, back->gray);
  177662. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177663. }
  177664. }
  177665. #endif
  177666. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177667. void /* PRIVATE */
  177668. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177669. {
  177670. #ifdef PNG_USE_LOCAL_ARRAYS
  177671. PNG_hIST;
  177672. #endif
  177673. int i;
  177674. png_byte buf[3];
  177675. png_debug(1, "in png_write_hIST\n");
  177676. if (num_hist > (int)png_ptr->num_palette)
  177677. {
  177678. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177679. png_ptr->num_palette);
  177680. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177681. return;
  177682. }
  177683. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177684. for (i = 0; i < num_hist; i++)
  177685. {
  177686. png_save_uint_16(buf, hist[i]);
  177687. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177688. }
  177689. png_write_chunk_end(png_ptr);
  177690. }
  177691. #endif
  177692. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177693. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177694. png_size_t /* PRIVATE */
  177695. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177696. {
  177697. png_size_t key_len;
  177698. png_charp kp, dp;
  177699. int kflag;
  177700. int kwarn=0;
  177701. png_debug(1, "in png_check_keyword\n");
  177702. *new_key = NULL;
  177703. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177704. {
  177705. png_warning(png_ptr, "zero length keyword");
  177706. return ((png_size_t)0);
  177707. }
  177708. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177709. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177710. if (*new_key == NULL)
  177711. {
  177712. png_warning(png_ptr, "Out of memory while procesing keyword");
  177713. return ((png_size_t)0);
  177714. }
  177715. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177716. {
  177717. if ((png_byte)*kp < 0x20 ||
  177718. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177719. {
  177720. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177721. char msg[40];
  177722. png_snprintf(msg, 40,
  177723. "invalid keyword character 0x%02X", (png_byte)*kp);
  177724. png_warning(png_ptr, msg);
  177725. #else
  177726. png_warning(png_ptr, "invalid character in keyword");
  177727. #endif
  177728. *dp = ' ';
  177729. }
  177730. else
  177731. {
  177732. *dp = *kp;
  177733. }
  177734. }
  177735. *dp = '\0';
  177736. kp = *new_key + key_len - 1;
  177737. if (*kp == ' ')
  177738. {
  177739. png_warning(png_ptr, "trailing spaces removed from keyword");
  177740. while (*kp == ' ')
  177741. {
  177742. *(kp--) = '\0';
  177743. key_len--;
  177744. }
  177745. }
  177746. kp = *new_key;
  177747. if (*kp == ' ')
  177748. {
  177749. png_warning(png_ptr, "leading spaces removed from keyword");
  177750. while (*kp == ' ')
  177751. {
  177752. kp++;
  177753. key_len--;
  177754. }
  177755. }
  177756. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177757. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177758. {
  177759. if (*kp == ' ' && kflag == 0)
  177760. {
  177761. *(dp++) = *kp;
  177762. kflag = 1;
  177763. }
  177764. else if (*kp == ' ')
  177765. {
  177766. key_len--;
  177767. kwarn=1;
  177768. }
  177769. else
  177770. {
  177771. *(dp++) = *kp;
  177772. kflag = 0;
  177773. }
  177774. }
  177775. *dp = '\0';
  177776. if(kwarn)
  177777. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177778. if (key_len == 0)
  177779. {
  177780. png_free(png_ptr, *new_key);
  177781. *new_key=NULL;
  177782. png_warning(png_ptr, "Zero length keyword");
  177783. }
  177784. if (key_len > 79)
  177785. {
  177786. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177787. new_key[79] = '\0';
  177788. key_len = 79;
  177789. }
  177790. return (key_len);
  177791. }
  177792. #endif
  177793. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177794. void /* PRIVATE */
  177795. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177796. png_size_t text_len)
  177797. {
  177798. #ifdef PNG_USE_LOCAL_ARRAYS
  177799. PNG_tEXt;
  177800. #endif
  177801. png_size_t key_len;
  177802. png_charp new_key;
  177803. png_debug(1, "in png_write_tEXt\n");
  177804. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177805. {
  177806. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177807. return;
  177808. }
  177809. if (text == NULL || *text == '\0')
  177810. text_len = 0;
  177811. else
  177812. text_len = png_strlen(text);
  177813. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177814. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177815. if (text_len)
  177816. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177817. png_write_chunk_end(png_ptr);
  177818. png_free(png_ptr, new_key);
  177819. }
  177820. #endif
  177821. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177822. void /* PRIVATE */
  177823. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177824. png_size_t text_len, int compression)
  177825. {
  177826. #ifdef PNG_USE_LOCAL_ARRAYS
  177827. PNG_zTXt;
  177828. #endif
  177829. png_size_t key_len;
  177830. char buf[1];
  177831. png_charp new_key;
  177832. compression_state comp;
  177833. png_debug(1, "in png_write_zTXt\n");
  177834. comp.num_output_ptr = 0;
  177835. comp.max_output_ptr = 0;
  177836. comp.output_ptr = NULL;
  177837. comp.input = NULL;
  177838. comp.input_len = 0;
  177839. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177840. {
  177841. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177842. return;
  177843. }
  177844. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177845. {
  177846. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177847. png_free(png_ptr, new_key);
  177848. return;
  177849. }
  177850. text_len = png_strlen(text);
  177851. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177852. &comp);
  177853. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177854. (key_len+text_len+2));
  177855. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177856. png_free(png_ptr, new_key);
  177857. buf[0] = (png_byte)compression;
  177858. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177859. png_write_compressed_data_out(png_ptr, &comp);
  177860. png_write_chunk_end(png_ptr);
  177861. }
  177862. #endif
  177863. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177864. void /* PRIVATE */
  177865. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177866. png_charp lang, png_charp lang_key, png_charp text)
  177867. {
  177868. #ifdef PNG_USE_LOCAL_ARRAYS
  177869. PNG_iTXt;
  177870. #endif
  177871. png_size_t lang_len, key_len, lang_key_len, text_len;
  177872. png_charp new_lang, new_key;
  177873. png_byte cbuf[2];
  177874. compression_state comp;
  177875. png_debug(1, "in png_write_iTXt\n");
  177876. comp.num_output_ptr = 0;
  177877. comp.max_output_ptr = 0;
  177878. comp.output_ptr = NULL;
  177879. comp.input = NULL;
  177880. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177881. {
  177882. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177883. return;
  177884. }
  177885. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177886. {
  177887. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177888. new_lang = NULL;
  177889. lang_len = 0;
  177890. }
  177891. if (lang_key == NULL)
  177892. lang_key_len = 0;
  177893. else
  177894. lang_key_len = png_strlen(lang_key);
  177895. if (text == NULL)
  177896. text_len = 0;
  177897. else
  177898. text_len = png_strlen(text);
  177899. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177900. &comp);
  177901. png_write_chunk_start(png_ptr, png_iTXt,
  177902. (png_uint_32)(
  177903. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177904. + key_len
  177905. + lang_len
  177906. + lang_key_len
  177907. + text_len));
  177908. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177909. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177910. compression == PNG_TEXT_COMPRESSION_NONE)
  177911. cbuf[0] = 0;
  177912. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177913. cbuf[0] = 1;
  177914. cbuf[1] = 0;
  177915. png_write_chunk_data(png_ptr, cbuf, 2);
  177916. cbuf[0] = 0;
  177917. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177918. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177919. png_write_compressed_data_out(png_ptr, &comp);
  177920. png_write_chunk_end(png_ptr);
  177921. png_free(png_ptr, new_key);
  177922. if (new_lang)
  177923. png_free(png_ptr, new_lang);
  177924. }
  177925. #endif
  177926. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177927. void /* PRIVATE */
  177928. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177929. int unit_type)
  177930. {
  177931. #ifdef PNG_USE_LOCAL_ARRAYS
  177932. PNG_oFFs;
  177933. #endif
  177934. png_byte buf[9];
  177935. png_debug(1, "in png_write_oFFs\n");
  177936. if (unit_type >= PNG_OFFSET_LAST)
  177937. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  177938. png_save_int_32(buf, x_offset);
  177939. png_save_int_32(buf + 4, y_offset);
  177940. buf[8] = (png_byte)unit_type;
  177941. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  177942. }
  177943. #endif
  177944. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  177945. void /* PRIVATE */
  177946. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  177947. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  177948. {
  177949. #ifdef PNG_USE_LOCAL_ARRAYS
  177950. PNG_pCAL;
  177951. #endif
  177952. png_size_t purpose_len, units_len, total_len;
  177953. png_uint_32p params_len;
  177954. png_byte buf[10];
  177955. png_charp new_purpose;
  177956. int i;
  177957. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  177958. if (type >= PNG_EQUATION_LAST)
  177959. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  177960. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  177961. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  177962. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  177963. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  177964. total_len = purpose_len + units_len + 10;
  177965. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  177966. *png_sizeof(png_uint_32)));
  177967. for (i = 0; i < nparams; i++)
  177968. {
  177969. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  177970. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  177971. total_len += (png_size_t)params_len[i];
  177972. }
  177973. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  177974. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  177975. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  177976. png_save_int_32(buf, X0);
  177977. png_save_int_32(buf + 4, X1);
  177978. buf[8] = (png_byte)type;
  177979. buf[9] = (png_byte)nparams;
  177980. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  177981. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  177982. png_free(png_ptr, new_purpose);
  177983. for (i = 0; i < nparams; i++)
  177984. {
  177985. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  177986. (png_size_t)params_len[i]);
  177987. }
  177988. png_free(png_ptr, params_len);
  177989. png_write_chunk_end(png_ptr);
  177990. }
  177991. #endif
  177992. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  177993. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  177994. void /* PRIVATE */
  177995. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  177996. {
  177997. #ifdef PNG_USE_LOCAL_ARRAYS
  177998. PNG_sCAL;
  177999. #endif
  178000. char buf[64];
  178001. png_size_t total_len;
  178002. png_debug(1, "in png_write_sCAL\n");
  178003. buf[0] = (char)unit;
  178004. #if defined(_WIN32_WCE)
  178005. {
  178006. wchar_t wc_buf[32];
  178007. size_t wc_len;
  178008. swprintf(wc_buf, TEXT("%12.12e"), width);
  178009. wc_len = wcslen(wc_buf);
  178010. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178011. total_len = wc_len + 2;
  178012. swprintf(wc_buf, TEXT("%12.12e"), height);
  178013. wc_len = wcslen(wc_buf);
  178014. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178015. NULL, NULL);
  178016. total_len += wc_len;
  178017. }
  178018. #else
  178019. png_snprintf(buf + 1, 63, "%12.12e", width);
  178020. total_len = 1 + png_strlen(buf + 1) + 1;
  178021. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178022. total_len += png_strlen(buf + total_len);
  178023. #endif
  178024. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178025. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178026. }
  178027. #else
  178028. #ifdef PNG_FIXED_POINT_SUPPORTED
  178029. void /* PRIVATE */
  178030. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178031. png_charp height)
  178032. {
  178033. #ifdef PNG_USE_LOCAL_ARRAYS
  178034. PNG_sCAL;
  178035. #endif
  178036. png_byte buf[64];
  178037. png_size_t wlen, hlen, total_len;
  178038. png_debug(1, "in png_write_sCAL_s\n");
  178039. wlen = png_strlen(width);
  178040. hlen = png_strlen(height);
  178041. total_len = wlen + hlen + 2;
  178042. if (total_len > 64)
  178043. {
  178044. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178045. return;
  178046. }
  178047. buf[0] = (png_byte)unit;
  178048. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178049. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178050. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178051. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178052. }
  178053. #endif
  178054. #endif
  178055. #endif
  178056. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178057. void /* PRIVATE */
  178058. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178059. png_uint_32 y_pixels_per_unit,
  178060. int unit_type)
  178061. {
  178062. #ifdef PNG_USE_LOCAL_ARRAYS
  178063. PNG_pHYs;
  178064. #endif
  178065. png_byte buf[9];
  178066. png_debug(1, "in png_write_pHYs\n");
  178067. if (unit_type >= PNG_RESOLUTION_LAST)
  178068. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178069. png_save_uint_32(buf, x_pixels_per_unit);
  178070. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178071. buf[8] = (png_byte)unit_type;
  178072. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178073. }
  178074. #endif
  178075. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178076. void /* PRIVATE */
  178077. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178078. {
  178079. #ifdef PNG_USE_LOCAL_ARRAYS
  178080. PNG_tIME;
  178081. #endif
  178082. png_byte buf[7];
  178083. png_debug(1, "in png_write_tIME\n");
  178084. if (mod_time->month > 12 || mod_time->month < 1 ||
  178085. mod_time->day > 31 || mod_time->day < 1 ||
  178086. mod_time->hour > 23 || mod_time->second > 60)
  178087. {
  178088. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178089. return;
  178090. }
  178091. png_save_uint_16(buf, mod_time->year);
  178092. buf[2] = mod_time->month;
  178093. buf[3] = mod_time->day;
  178094. buf[4] = mod_time->hour;
  178095. buf[5] = mod_time->minute;
  178096. buf[6] = mod_time->second;
  178097. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178098. }
  178099. #endif
  178100. void /* PRIVATE */
  178101. png_write_start_row(png_structp png_ptr)
  178102. {
  178103. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178104. #ifdef PNG_USE_LOCAL_ARRAYS
  178105. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178106. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178107. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178108. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178109. #endif
  178110. #endif
  178111. png_size_t buf_size;
  178112. png_debug(1, "in png_write_start_row\n");
  178113. buf_size = (png_size_t)(PNG_ROWBYTES(
  178114. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178115. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178116. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178117. #ifndef PNG_NO_WRITE_FILTERING
  178118. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178119. {
  178120. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178121. (png_ptr->rowbytes + 1));
  178122. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178123. }
  178124. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178125. {
  178126. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178127. png_memset(png_ptr->prev_row, 0, buf_size);
  178128. if (png_ptr->do_filter & PNG_FILTER_UP)
  178129. {
  178130. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178131. (png_ptr->rowbytes + 1));
  178132. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178133. }
  178134. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178135. {
  178136. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178137. (png_ptr->rowbytes + 1));
  178138. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178139. }
  178140. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178141. {
  178142. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178143. (png_ptr->rowbytes + 1));
  178144. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178145. }
  178146. #endif /* PNG_NO_WRITE_FILTERING */
  178147. }
  178148. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178149. if (png_ptr->interlaced)
  178150. {
  178151. if (!(png_ptr->transformations & PNG_INTERLACE))
  178152. {
  178153. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178154. png_pass_ystart[0]) / png_pass_yinc[0];
  178155. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178156. png_pass_start[0]) / png_pass_inc[0];
  178157. }
  178158. else
  178159. {
  178160. png_ptr->num_rows = png_ptr->height;
  178161. png_ptr->usr_width = png_ptr->width;
  178162. }
  178163. }
  178164. else
  178165. #endif
  178166. {
  178167. png_ptr->num_rows = png_ptr->height;
  178168. png_ptr->usr_width = png_ptr->width;
  178169. }
  178170. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178171. png_ptr->zstream.next_out = png_ptr->zbuf;
  178172. }
  178173. void /* PRIVATE */
  178174. png_write_finish_row(png_structp png_ptr)
  178175. {
  178176. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178177. #ifdef PNG_USE_LOCAL_ARRAYS
  178178. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178179. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178180. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178181. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178182. #endif
  178183. #endif
  178184. int ret;
  178185. png_debug(1, "in png_write_finish_row\n");
  178186. png_ptr->row_number++;
  178187. if (png_ptr->row_number < png_ptr->num_rows)
  178188. return;
  178189. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178190. if (png_ptr->interlaced)
  178191. {
  178192. png_ptr->row_number = 0;
  178193. if (png_ptr->transformations & PNG_INTERLACE)
  178194. {
  178195. png_ptr->pass++;
  178196. }
  178197. else
  178198. {
  178199. do
  178200. {
  178201. png_ptr->pass++;
  178202. if (png_ptr->pass >= 7)
  178203. break;
  178204. png_ptr->usr_width = (png_ptr->width +
  178205. png_pass_inc[png_ptr->pass] - 1 -
  178206. png_pass_start[png_ptr->pass]) /
  178207. png_pass_inc[png_ptr->pass];
  178208. png_ptr->num_rows = (png_ptr->height +
  178209. png_pass_yinc[png_ptr->pass] - 1 -
  178210. png_pass_ystart[png_ptr->pass]) /
  178211. png_pass_yinc[png_ptr->pass];
  178212. if (png_ptr->transformations & PNG_INTERLACE)
  178213. break;
  178214. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178215. }
  178216. if (png_ptr->pass < 7)
  178217. {
  178218. if (png_ptr->prev_row != NULL)
  178219. png_memset(png_ptr->prev_row, 0,
  178220. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178221. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178222. return;
  178223. }
  178224. }
  178225. #endif
  178226. do
  178227. {
  178228. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178229. if (ret == Z_OK)
  178230. {
  178231. if (!(png_ptr->zstream.avail_out))
  178232. {
  178233. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178234. png_ptr->zstream.next_out = png_ptr->zbuf;
  178235. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178236. }
  178237. }
  178238. else if (ret != Z_STREAM_END)
  178239. {
  178240. if (png_ptr->zstream.msg != NULL)
  178241. png_error(png_ptr, png_ptr->zstream.msg);
  178242. else
  178243. png_error(png_ptr, "zlib error");
  178244. }
  178245. } while (ret != Z_STREAM_END);
  178246. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178247. {
  178248. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178249. png_ptr->zstream.avail_out);
  178250. }
  178251. deflateReset(&png_ptr->zstream);
  178252. png_ptr->zstream.data_type = Z_BINARY;
  178253. }
  178254. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178255. void /* PRIVATE */
  178256. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178257. {
  178258. #ifdef PNG_USE_LOCAL_ARRAYS
  178259. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178260. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178261. #endif
  178262. png_debug(1, "in png_do_write_interlace\n");
  178263. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178264. if (row != NULL && row_info != NULL && pass < 6)
  178265. #else
  178266. if (pass < 6)
  178267. #endif
  178268. {
  178269. switch (row_info->pixel_depth)
  178270. {
  178271. case 1:
  178272. {
  178273. png_bytep sp;
  178274. png_bytep dp;
  178275. int shift;
  178276. int d;
  178277. int value;
  178278. png_uint_32 i;
  178279. png_uint_32 row_width = row_info->width;
  178280. dp = row;
  178281. d = 0;
  178282. shift = 7;
  178283. for (i = png_pass_start[pass]; i < row_width;
  178284. i += png_pass_inc[pass])
  178285. {
  178286. sp = row + (png_size_t)(i >> 3);
  178287. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178288. d |= (value << shift);
  178289. if (shift == 0)
  178290. {
  178291. shift = 7;
  178292. *dp++ = (png_byte)d;
  178293. d = 0;
  178294. }
  178295. else
  178296. shift--;
  178297. }
  178298. if (shift != 7)
  178299. *dp = (png_byte)d;
  178300. break;
  178301. }
  178302. case 2:
  178303. {
  178304. png_bytep sp;
  178305. png_bytep dp;
  178306. int shift;
  178307. int d;
  178308. int value;
  178309. png_uint_32 i;
  178310. png_uint_32 row_width = row_info->width;
  178311. dp = row;
  178312. shift = 6;
  178313. d = 0;
  178314. for (i = png_pass_start[pass]; i < row_width;
  178315. i += png_pass_inc[pass])
  178316. {
  178317. sp = row + (png_size_t)(i >> 2);
  178318. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178319. d |= (value << shift);
  178320. if (shift == 0)
  178321. {
  178322. shift = 6;
  178323. *dp++ = (png_byte)d;
  178324. d = 0;
  178325. }
  178326. else
  178327. shift -= 2;
  178328. }
  178329. if (shift != 6)
  178330. *dp = (png_byte)d;
  178331. break;
  178332. }
  178333. case 4:
  178334. {
  178335. png_bytep sp;
  178336. png_bytep dp;
  178337. int shift;
  178338. int d;
  178339. int value;
  178340. png_uint_32 i;
  178341. png_uint_32 row_width = row_info->width;
  178342. dp = row;
  178343. shift = 4;
  178344. d = 0;
  178345. for (i = png_pass_start[pass]; i < row_width;
  178346. i += png_pass_inc[pass])
  178347. {
  178348. sp = row + (png_size_t)(i >> 1);
  178349. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178350. d |= (value << shift);
  178351. if (shift == 0)
  178352. {
  178353. shift = 4;
  178354. *dp++ = (png_byte)d;
  178355. d = 0;
  178356. }
  178357. else
  178358. shift -= 4;
  178359. }
  178360. if (shift != 4)
  178361. *dp = (png_byte)d;
  178362. break;
  178363. }
  178364. default:
  178365. {
  178366. png_bytep sp;
  178367. png_bytep dp;
  178368. png_uint_32 i;
  178369. png_uint_32 row_width = row_info->width;
  178370. png_size_t pixel_bytes;
  178371. dp = row;
  178372. pixel_bytes = (row_info->pixel_depth >> 3);
  178373. for (i = png_pass_start[pass]; i < row_width;
  178374. i += png_pass_inc[pass])
  178375. {
  178376. sp = row + (png_size_t)i * pixel_bytes;
  178377. if (dp != sp)
  178378. png_memcpy(dp, sp, pixel_bytes);
  178379. dp += pixel_bytes;
  178380. }
  178381. break;
  178382. }
  178383. }
  178384. row_info->width = (row_info->width +
  178385. png_pass_inc[pass] - 1 -
  178386. png_pass_start[pass]) /
  178387. png_pass_inc[pass];
  178388. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178389. row_info->width);
  178390. }
  178391. }
  178392. #endif
  178393. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178394. #define PNG_HISHIFT 10
  178395. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178396. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178397. void /* PRIVATE */
  178398. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178399. {
  178400. png_bytep best_row;
  178401. #ifndef PNG_NO_WRITE_FILTER
  178402. png_bytep prev_row, row_buf;
  178403. png_uint_32 mins, bpp;
  178404. png_byte filter_to_do = png_ptr->do_filter;
  178405. png_uint_32 row_bytes = row_info->rowbytes;
  178406. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178407. int num_p_filters = (int)png_ptr->num_prev_filters;
  178408. #endif
  178409. png_debug(1, "in png_write_find_filter\n");
  178410. bpp = (row_info->pixel_depth + 7) >> 3;
  178411. prev_row = png_ptr->prev_row;
  178412. #endif
  178413. best_row = png_ptr->row_buf;
  178414. #ifndef PNG_NO_WRITE_FILTER
  178415. row_buf = best_row;
  178416. mins = PNG_MAXSUM;
  178417. if ((filter_to_do & PNG_FILTER_NONE) &&
  178418. filter_to_do != PNG_FILTER_NONE)
  178419. {
  178420. png_bytep rp;
  178421. png_uint_32 sum = 0;
  178422. png_uint_32 i;
  178423. int v;
  178424. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178425. {
  178426. v = *rp;
  178427. sum += (v < 128) ? v : 256 - v;
  178428. }
  178429. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178430. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178431. {
  178432. png_uint_32 sumhi, sumlo;
  178433. int j;
  178434. sumlo = sum & PNG_LOMASK;
  178435. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178436. for (j = 0; j < num_p_filters; j++)
  178437. {
  178438. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178439. {
  178440. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178441. PNG_WEIGHT_SHIFT;
  178442. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178443. PNG_WEIGHT_SHIFT;
  178444. }
  178445. }
  178446. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178447. PNG_COST_SHIFT;
  178448. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178449. PNG_COST_SHIFT;
  178450. if (sumhi > PNG_HIMASK)
  178451. sum = PNG_MAXSUM;
  178452. else
  178453. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178454. }
  178455. #endif
  178456. mins = sum;
  178457. }
  178458. if (filter_to_do == PNG_FILTER_SUB)
  178459. {
  178460. png_bytep rp, lp, dp;
  178461. png_uint_32 i;
  178462. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178463. i++, rp++, dp++)
  178464. {
  178465. *dp = *rp;
  178466. }
  178467. for (lp = row_buf + 1; i < row_bytes;
  178468. i++, rp++, lp++, dp++)
  178469. {
  178470. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178471. }
  178472. best_row = png_ptr->sub_row;
  178473. }
  178474. else if (filter_to_do & PNG_FILTER_SUB)
  178475. {
  178476. png_bytep rp, dp, lp;
  178477. png_uint_32 sum = 0, lmins = mins;
  178478. png_uint_32 i;
  178479. int v;
  178480. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178481. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178482. {
  178483. int j;
  178484. png_uint_32 lmhi, lmlo;
  178485. lmlo = lmins & PNG_LOMASK;
  178486. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178487. for (j = 0; j < num_p_filters; j++)
  178488. {
  178489. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178490. {
  178491. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178492. PNG_WEIGHT_SHIFT;
  178493. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178494. PNG_WEIGHT_SHIFT;
  178495. }
  178496. }
  178497. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178498. PNG_COST_SHIFT;
  178499. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178500. PNG_COST_SHIFT;
  178501. if (lmhi > PNG_HIMASK)
  178502. lmins = PNG_MAXSUM;
  178503. else
  178504. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178505. }
  178506. #endif
  178507. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178508. i++, rp++, dp++)
  178509. {
  178510. v = *dp = *rp;
  178511. sum += (v < 128) ? v : 256 - v;
  178512. }
  178513. for (lp = row_buf + 1; i < row_bytes;
  178514. i++, rp++, lp++, dp++)
  178515. {
  178516. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178517. sum += (v < 128) ? v : 256 - v;
  178518. if (sum > lmins) /* We are already worse, don't continue. */
  178519. break;
  178520. }
  178521. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178522. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178523. {
  178524. int j;
  178525. png_uint_32 sumhi, sumlo;
  178526. sumlo = sum & PNG_LOMASK;
  178527. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178528. for (j = 0; j < num_p_filters; j++)
  178529. {
  178530. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178531. {
  178532. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178533. PNG_WEIGHT_SHIFT;
  178534. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178535. PNG_WEIGHT_SHIFT;
  178536. }
  178537. }
  178538. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178539. PNG_COST_SHIFT;
  178540. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178541. PNG_COST_SHIFT;
  178542. if (sumhi > PNG_HIMASK)
  178543. sum = PNG_MAXSUM;
  178544. else
  178545. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178546. }
  178547. #endif
  178548. if (sum < mins)
  178549. {
  178550. mins = sum;
  178551. best_row = png_ptr->sub_row;
  178552. }
  178553. }
  178554. if (filter_to_do == PNG_FILTER_UP)
  178555. {
  178556. png_bytep rp, dp, pp;
  178557. png_uint_32 i;
  178558. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178559. pp = prev_row + 1; i < row_bytes;
  178560. i++, rp++, pp++, dp++)
  178561. {
  178562. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178563. }
  178564. best_row = png_ptr->up_row;
  178565. }
  178566. else if (filter_to_do & PNG_FILTER_UP)
  178567. {
  178568. png_bytep rp, dp, pp;
  178569. png_uint_32 sum = 0, lmins = mins;
  178570. png_uint_32 i;
  178571. int v;
  178572. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178573. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178574. {
  178575. int j;
  178576. png_uint_32 lmhi, lmlo;
  178577. lmlo = lmins & PNG_LOMASK;
  178578. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178579. for (j = 0; j < num_p_filters; j++)
  178580. {
  178581. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178582. {
  178583. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178584. PNG_WEIGHT_SHIFT;
  178585. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178586. PNG_WEIGHT_SHIFT;
  178587. }
  178588. }
  178589. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178590. PNG_COST_SHIFT;
  178591. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178592. PNG_COST_SHIFT;
  178593. if (lmhi > PNG_HIMASK)
  178594. lmins = PNG_MAXSUM;
  178595. else
  178596. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178597. }
  178598. #endif
  178599. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178600. pp = prev_row + 1; i < row_bytes; i++)
  178601. {
  178602. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178603. sum += (v < 128) ? v : 256 - v;
  178604. if (sum > lmins) /* We are already worse, don't continue. */
  178605. break;
  178606. }
  178607. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178608. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178609. {
  178610. int j;
  178611. png_uint_32 sumhi, sumlo;
  178612. sumlo = sum & PNG_LOMASK;
  178613. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178614. for (j = 0; j < num_p_filters; j++)
  178615. {
  178616. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178617. {
  178618. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178619. PNG_WEIGHT_SHIFT;
  178620. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178621. PNG_WEIGHT_SHIFT;
  178622. }
  178623. }
  178624. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178625. PNG_COST_SHIFT;
  178626. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178627. PNG_COST_SHIFT;
  178628. if (sumhi > PNG_HIMASK)
  178629. sum = PNG_MAXSUM;
  178630. else
  178631. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178632. }
  178633. #endif
  178634. if (sum < mins)
  178635. {
  178636. mins = sum;
  178637. best_row = png_ptr->up_row;
  178638. }
  178639. }
  178640. if (filter_to_do == PNG_FILTER_AVG)
  178641. {
  178642. png_bytep rp, dp, pp, lp;
  178643. png_uint_32 i;
  178644. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178645. pp = prev_row + 1; i < bpp; i++)
  178646. {
  178647. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178648. }
  178649. for (lp = row_buf + 1; i < row_bytes; i++)
  178650. {
  178651. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178652. & 0xff);
  178653. }
  178654. best_row = png_ptr->avg_row;
  178655. }
  178656. else if (filter_to_do & PNG_FILTER_AVG)
  178657. {
  178658. png_bytep rp, dp, pp, lp;
  178659. png_uint_32 sum = 0, lmins = mins;
  178660. png_uint_32 i;
  178661. int v;
  178662. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178663. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178664. {
  178665. int j;
  178666. png_uint_32 lmhi, lmlo;
  178667. lmlo = lmins & PNG_LOMASK;
  178668. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178669. for (j = 0; j < num_p_filters; j++)
  178670. {
  178671. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178672. {
  178673. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178674. PNG_WEIGHT_SHIFT;
  178675. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178676. PNG_WEIGHT_SHIFT;
  178677. }
  178678. }
  178679. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178680. PNG_COST_SHIFT;
  178681. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178682. PNG_COST_SHIFT;
  178683. if (lmhi > PNG_HIMASK)
  178684. lmins = PNG_MAXSUM;
  178685. else
  178686. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178687. }
  178688. #endif
  178689. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178690. pp = prev_row + 1; i < bpp; i++)
  178691. {
  178692. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178693. sum += (v < 128) ? v : 256 - v;
  178694. }
  178695. for (lp = row_buf + 1; i < row_bytes; i++)
  178696. {
  178697. v = *dp++ =
  178698. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178699. sum += (v < 128) ? v : 256 - v;
  178700. if (sum > lmins) /* We are already worse, don't continue. */
  178701. break;
  178702. }
  178703. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178704. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178705. {
  178706. int j;
  178707. png_uint_32 sumhi, sumlo;
  178708. sumlo = sum & PNG_LOMASK;
  178709. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178710. for (j = 0; j < num_p_filters; j++)
  178711. {
  178712. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178713. {
  178714. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178715. PNG_WEIGHT_SHIFT;
  178716. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178717. PNG_WEIGHT_SHIFT;
  178718. }
  178719. }
  178720. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178721. PNG_COST_SHIFT;
  178722. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178723. PNG_COST_SHIFT;
  178724. if (sumhi > PNG_HIMASK)
  178725. sum = PNG_MAXSUM;
  178726. else
  178727. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178728. }
  178729. #endif
  178730. if (sum < mins)
  178731. {
  178732. mins = sum;
  178733. best_row = png_ptr->avg_row;
  178734. }
  178735. }
  178736. if (filter_to_do == PNG_FILTER_PAETH)
  178737. {
  178738. png_bytep rp, dp, pp, cp, lp;
  178739. png_uint_32 i;
  178740. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178741. pp = prev_row + 1; i < bpp; i++)
  178742. {
  178743. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178744. }
  178745. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178746. {
  178747. int a, b, c, pa, pb, pc, p;
  178748. b = *pp++;
  178749. c = *cp++;
  178750. a = *lp++;
  178751. p = b - c;
  178752. pc = a - c;
  178753. #ifdef PNG_USE_ABS
  178754. pa = abs(p);
  178755. pb = abs(pc);
  178756. pc = abs(p + pc);
  178757. #else
  178758. pa = p < 0 ? -p : p;
  178759. pb = pc < 0 ? -pc : pc;
  178760. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178761. #endif
  178762. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178763. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178764. }
  178765. best_row = png_ptr->paeth_row;
  178766. }
  178767. else if (filter_to_do & PNG_FILTER_PAETH)
  178768. {
  178769. png_bytep rp, dp, pp, cp, lp;
  178770. png_uint_32 sum = 0, lmins = mins;
  178771. png_uint_32 i;
  178772. int v;
  178773. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178774. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178775. {
  178776. int j;
  178777. png_uint_32 lmhi, lmlo;
  178778. lmlo = lmins & PNG_LOMASK;
  178779. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178780. for (j = 0; j < num_p_filters; j++)
  178781. {
  178782. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178783. {
  178784. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178785. PNG_WEIGHT_SHIFT;
  178786. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178787. PNG_WEIGHT_SHIFT;
  178788. }
  178789. }
  178790. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178791. PNG_COST_SHIFT;
  178792. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178793. PNG_COST_SHIFT;
  178794. if (lmhi > PNG_HIMASK)
  178795. lmins = PNG_MAXSUM;
  178796. else
  178797. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178798. }
  178799. #endif
  178800. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178801. pp = prev_row + 1; i < bpp; i++)
  178802. {
  178803. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178804. sum += (v < 128) ? v : 256 - v;
  178805. }
  178806. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178807. {
  178808. int a, b, c, pa, pb, pc, p;
  178809. b = *pp++;
  178810. c = *cp++;
  178811. a = *lp++;
  178812. #ifndef PNG_SLOW_PAETH
  178813. p = b - c;
  178814. pc = a - c;
  178815. #ifdef PNG_USE_ABS
  178816. pa = abs(p);
  178817. pb = abs(pc);
  178818. pc = abs(p + pc);
  178819. #else
  178820. pa = p < 0 ? -p : p;
  178821. pb = pc < 0 ? -pc : pc;
  178822. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178823. #endif
  178824. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178825. #else /* PNG_SLOW_PAETH */
  178826. p = a + b - c;
  178827. pa = abs(p - a);
  178828. pb = abs(p - b);
  178829. pc = abs(p - c);
  178830. if (pa <= pb && pa <= pc)
  178831. p = a;
  178832. else if (pb <= pc)
  178833. p = b;
  178834. else
  178835. p = c;
  178836. #endif /* PNG_SLOW_PAETH */
  178837. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178838. sum += (v < 128) ? v : 256 - v;
  178839. if (sum > lmins) /* We are already worse, don't continue. */
  178840. break;
  178841. }
  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 sumhi, sumlo;
  178847. sumlo = sum & PNG_LOMASK;
  178848. sumhi = (sum >> 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. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178854. PNG_WEIGHT_SHIFT;
  178855. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178856. PNG_WEIGHT_SHIFT;
  178857. }
  178858. }
  178859. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178860. PNG_COST_SHIFT;
  178861. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178862. PNG_COST_SHIFT;
  178863. if (sumhi > PNG_HIMASK)
  178864. sum = PNG_MAXSUM;
  178865. else
  178866. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178867. }
  178868. #endif
  178869. if (sum < mins)
  178870. {
  178871. best_row = png_ptr->paeth_row;
  178872. }
  178873. }
  178874. #endif /* PNG_NO_WRITE_FILTER */
  178875. png_write_filtered_row(png_ptr, best_row);
  178876. #ifndef PNG_NO_WRITE_FILTER
  178877. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178878. if (png_ptr->num_prev_filters > 0)
  178879. {
  178880. int j;
  178881. for (j = 1; j < num_p_filters; j++)
  178882. {
  178883. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178884. }
  178885. png_ptr->prev_filters[j] = best_row[0];
  178886. }
  178887. #endif
  178888. #endif /* PNG_NO_WRITE_FILTER */
  178889. }
  178890. void /* PRIVATE */
  178891. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178892. {
  178893. png_debug(1, "in png_write_filtered_row\n");
  178894. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178895. png_ptr->zstream.next_in = filtered_row;
  178896. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178897. do
  178898. {
  178899. int ret; /* return of zlib */
  178900. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178901. if (ret != Z_OK)
  178902. {
  178903. if (png_ptr->zstream.msg != NULL)
  178904. png_error(png_ptr, png_ptr->zstream.msg);
  178905. else
  178906. png_error(png_ptr, "zlib error");
  178907. }
  178908. if (!(png_ptr->zstream.avail_out))
  178909. {
  178910. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178911. png_ptr->zstream.next_out = png_ptr->zbuf;
  178912. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178913. }
  178914. } while (png_ptr->zstream.avail_in);
  178915. if (png_ptr->prev_row != NULL)
  178916. {
  178917. png_bytep tptr;
  178918. tptr = png_ptr->prev_row;
  178919. png_ptr->prev_row = png_ptr->row_buf;
  178920. png_ptr->row_buf = tptr;
  178921. }
  178922. png_write_finish_row(png_ptr);
  178923. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178924. png_ptr->flush_rows++;
  178925. if (png_ptr->flush_dist > 0 &&
  178926. png_ptr->flush_rows >= png_ptr->flush_dist)
  178927. {
  178928. png_write_flush(png_ptr);
  178929. }
  178930. #endif
  178931. }
  178932. #endif /* PNG_WRITE_SUPPORTED */
  178933. /*** End of inlined file: pngwutil.c ***/
  178934. }
  178935. #else
  178936. #define PNG_INTERNAL
  178937. #define PNG_SETJMP_NOT_SUPPORTED
  178938. #include <png.h>
  178939. #include <pngconf.h>
  178940. #endif
  178941. }
  178942. #undef max
  178943. #undef min
  178944. #ifdef _MSC_VER
  178945. #pragma warning (pop)
  178946. #endif
  178947. BEGIN_JUCE_NAMESPACE
  178948. using ::calloc;
  178949. using ::malloc;
  178950. using ::free;
  178951. namespace PNGHelpers
  178952. {
  178953. using namespace pnglibNamespace;
  178954. static void readCallback (png_structp png, png_bytep data, png_size_t length)
  178955. {
  178956. static_cast<InputStream*> (png_get_io_ptr (png))->read (data, (int) length);
  178957. }
  178958. static void writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  178959. {
  178960. static_cast<OutputStream*> (png_get_io_ptr (png))->write (data, (int) length);
  178961. }
  178962. struct PNGErrorStruct {};
  178963. static void errorCallback (png_structp, png_const_charp)
  178964. {
  178965. throw PNGErrorStruct();
  178966. }
  178967. }
  178968. Image* juce_loadPNGImageFromStream (InputStream& in)
  178969. {
  178970. using namespace pnglibNamespace;
  178971. Image* image = 0;
  178972. png_structp pngReadStruct;
  178973. png_infop pngInfoStruct;
  178974. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178975. if (pngReadStruct != 0)
  178976. {
  178977. pngInfoStruct = png_create_info_struct (pngReadStruct);
  178978. if (pngInfoStruct == 0)
  178979. {
  178980. png_destroy_read_struct (&pngReadStruct, 0, 0);
  178981. return 0;
  178982. }
  178983. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  178984. // read the header..
  178985. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  178986. png_uint_32 width, height;
  178987. int bitDepth, colorType, interlaceType;
  178988. png_read_info (pngReadStruct, pngInfoStruct);
  178989. png_get_IHDR (pngReadStruct, pngInfoStruct,
  178990. &width, &height,
  178991. &bitDepth, &colorType,
  178992. &interlaceType, 0, 0);
  178993. if (bitDepth == 16)
  178994. png_set_strip_16 (pngReadStruct);
  178995. if (colorType == PNG_COLOR_TYPE_PALETTE)
  178996. png_set_expand (pngReadStruct);
  178997. if (bitDepth < 8)
  178998. png_set_expand (pngReadStruct);
  178999. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179000. png_set_expand (pngReadStruct);
  179001. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179002. png_set_gray_to_rgb (pngReadStruct);
  179003. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179004. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179005. || pngInfoStruct->num_trans > 0;
  179006. // Load the image into a temp buffer in the pnglib format..
  179007. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179008. {
  179009. HeapBlock <png_bytep> rows (height);
  179010. for (int y = (int) height; --y >= 0;)
  179011. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179012. png_read_image (pngReadStruct, rows);
  179013. png_read_end (pngReadStruct, pngInfoStruct);
  179014. }
  179015. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179016. // now convert the data to a juce image format..
  179017. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179018. (int) width, (int) height, hasAlphaChan);
  179019. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179020. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179021. uint8* srcRow = tempBuffer;
  179022. uint8* destRow = destData.data;
  179023. for (int y = 0; y < (int) height; ++y)
  179024. {
  179025. const uint8* src = srcRow;
  179026. srcRow += (width << 2);
  179027. uint8* dest = destRow;
  179028. destRow += destData.lineStride;
  179029. if (hasAlphaChan)
  179030. {
  179031. for (int i = (int) width; --i >= 0;)
  179032. {
  179033. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179034. ((PixelARGB*) dest)->premultiply();
  179035. dest += destData.pixelStride;
  179036. src += 4;
  179037. }
  179038. }
  179039. else
  179040. {
  179041. for (int i = (int) width; --i >= 0;)
  179042. {
  179043. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179044. dest += destData.pixelStride;
  179045. src += 4;
  179046. }
  179047. }
  179048. }
  179049. }
  179050. return image;
  179051. }
  179052. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179053. {
  179054. using namespace pnglibNamespace;
  179055. const int width = image.getWidth();
  179056. const int height = image.getHeight();
  179057. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179058. if (pngWriteStruct == 0)
  179059. return false;
  179060. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179061. if (pngInfoStruct == 0)
  179062. {
  179063. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179064. return false;
  179065. }
  179066. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  179067. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179068. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179069. : PNG_COLOR_TYPE_RGB,
  179070. PNG_INTERLACE_NONE,
  179071. PNG_COMPRESSION_TYPE_BASE,
  179072. PNG_FILTER_TYPE_BASE);
  179073. HeapBlock <uint8> rowData (width * 4);
  179074. png_color_8 sig_bit;
  179075. sig_bit.red = 8;
  179076. sig_bit.green = 8;
  179077. sig_bit.blue = 8;
  179078. sig_bit.alpha = 8;
  179079. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179080. png_write_info (pngWriteStruct, pngInfoStruct);
  179081. png_set_shift (pngWriteStruct, &sig_bit);
  179082. png_set_packing (pngWriteStruct);
  179083. const Image::BitmapData srcData (image, 0, 0, width, height);
  179084. for (int y = 0; y < height; ++y)
  179085. {
  179086. uint8* dst = rowData;
  179087. const uint8* src = srcData.getLinePointer (y);
  179088. if (image.hasAlphaChannel())
  179089. {
  179090. for (int i = width; --i >= 0;)
  179091. {
  179092. PixelARGB p (*(const PixelARGB*) src);
  179093. p.unpremultiply();
  179094. *dst++ = p.getRed();
  179095. *dst++ = p.getGreen();
  179096. *dst++ = p.getBlue();
  179097. *dst++ = p.getAlpha();
  179098. src += srcData.pixelStride;
  179099. }
  179100. }
  179101. else
  179102. {
  179103. for (int i = width; --i >= 0;)
  179104. {
  179105. *dst++ = ((const PixelRGB*) src)->getRed();
  179106. *dst++ = ((const PixelRGB*) src)->getGreen();
  179107. *dst++ = ((const PixelRGB*) src)->getBlue();
  179108. src += srcData.pixelStride;
  179109. }
  179110. }
  179111. png_write_rows (pngWriteStruct, &rowData, 1);
  179112. }
  179113. png_write_end (pngWriteStruct, pngInfoStruct);
  179114. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179115. out.flush();
  179116. return true;
  179117. }
  179118. END_JUCE_NAMESPACE
  179119. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179120. #endif
  179121. //==============================================================================
  179122. #if JUCE_BUILD_NATIVE
  179123. #if JUCE_WINDOWS
  179124. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179125. #if JUCE_WINDOWS
  179126. BEGIN_JUCE_NAMESPACE
  179127. #define JUCE_INCLUDED_FILE 1
  179128. // Now include the actual code files..
  179129. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179130. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179131. // compiled on its own).
  179132. #if JUCE_INCLUDED_FILE
  179133. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179134. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179135. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179136. #ifndef DOXYGEN
  179137. // use with DynamicLibraryLoader to simplify importing functions
  179138. //
  179139. // functionName: function to import
  179140. // localFunctionName: name you want to use to actually call it (must be different)
  179141. // returnType: the return type
  179142. // object: the DynamicLibraryLoader to use
  179143. // params: list of params (bracketed)
  179144. //
  179145. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179146. typedef returnType (WINAPI *type##localFunctionName) params; \
  179147. type##localFunctionName localFunctionName \
  179148. = (type##localFunctionName)object.findProcAddress (#functionName);
  179149. // loads and unloads a DLL automatically
  179150. class JUCE_API DynamicLibraryLoader
  179151. {
  179152. public:
  179153. DynamicLibraryLoader (const String& name);
  179154. ~DynamicLibraryLoader();
  179155. void* findProcAddress (const String& functionName);
  179156. private:
  179157. void* libHandle;
  179158. };
  179159. #endif
  179160. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179161. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179162. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179163. {
  179164. libHandle = LoadLibrary (name);
  179165. }
  179166. DynamicLibraryLoader::~DynamicLibraryLoader()
  179167. {
  179168. FreeLibrary ((HMODULE) libHandle);
  179169. }
  179170. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179171. {
  179172. return GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179173. }
  179174. #endif
  179175. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179176. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179177. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179178. // compiled on its own).
  179179. #if JUCE_INCLUDED_FILE
  179180. extern void juce_initialiseThreadEvents();
  179181. void Logger::outputDebugString (const String& text) throw()
  179182. {
  179183. OutputDebugString (text + "\n");
  179184. }
  179185. static int64 hiResTicksPerSecond;
  179186. static double hiResTicksScaleFactor;
  179187. #if JUCE_USE_INTRINSICS
  179188. // CPU info functions using intrinsics...
  179189. #pragma intrinsic (__cpuid)
  179190. #pragma intrinsic (__rdtsc)
  179191. const String SystemStats::getCpuVendor() throw()
  179192. {
  179193. int info [4];
  179194. __cpuid (info, 0);
  179195. char v [12];
  179196. memcpy (v, info + 1, 4);
  179197. memcpy (v + 4, info + 3, 4);
  179198. memcpy (v + 8, info + 2, 4);
  179199. return String (v, 12);
  179200. }
  179201. #else
  179202. // CPU info functions using old fashioned inline asm...
  179203. static void juce_getCpuVendor (char* const v)
  179204. {
  179205. int vendor[4];
  179206. zeromem (vendor, 16);
  179207. #ifdef JUCE_64BIT
  179208. #else
  179209. #ifndef __MINGW32__
  179210. __try
  179211. #endif
  179212. {
  179213. #if JUCE_GCC
  179214. unsigned int dummy = 0;
  179215. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179216. #else
  179217. __asm
  179218. {
  179219. mov eax, 0
  179220. cpuid
  179221. mov [vendor], ebx
  179222. mov [vendor + 4], edx
  179223. mov [vendor + 8], ecx
  179224. }
  179225. #endif
  179226. }
  179227. #ifndef __MINGW32__
  179228. __except (EXCEPTION_EXECUTE_HANDLER)
  179229. {
  179230. *v = 0;
  179231. }
  179232. #endif
  179233. #endif
  179234. memcpy (v, vendor, 16);
  179235. }
  179236. const String SystemStats::getCpuVendor() throw()
  179237. {
  179238. char v [16];
  179239. juce_getCpuVendor (v);
  179240. return String (v, 16);
  179241. }
  179242. #endif
  179243. struct CPUFlags
  179244. {
  179245. bool hasMMX : 1;
  179246. bool hasSSE : 1;
  179247. bool hasSSE2 : 1;
  179248. bool has3DNow : 1;
  179249. };
  179250. static CPUFlags cpuFlags;
  179251. bool SystemStats::hasMMX() throw()
  179252. {
  179253. return cpuFlags.hasMMX;
  179254. }
  179255. bool SystemStats::hasSSE() throw()
  179256. {
  179257. return cpuFlags.hasSSE;
  179258. }
  179259. bool SystemStats::hasSSE2() throw()
  179260. {
  179261. return cpuFlags.hasSSE2;
  179262. }
  179263. bool SystemStats::has3DNow() throw()
  179264. {
  179265. return cpuFlags.has3DNow;
  179266. }
  179267. void SystemStats::initialiseStats() throw()
  179268. {
  179269. juce_initialiseThreadEvents();
  179270. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179271. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179272. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179273. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179274. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179275. #else
  179276. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179277. #endif
  179278. LARGE_INTEGER f;
  179279. QueryPerformanceFrequency (&f);
  179280. hiResTicksPerSecond = f.QuadPart;
  179281. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179282. String s (SystemStats::getJUCEVersion());
  179283. #ifdef JUCE_DEBUG
  179284. const MMRESULT res = timeBeginPeriod (1);
  179285. jassert (res == TIMERR_NOERROR);
  179286. #else
  179287. timeBeginPeriod (1);
  179288. #endif
  179289. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179290. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179291. #endif
  179292. }
  179293. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179294. {
  179295. OSVERSIONINFO info;
  179296. info.dwOSVersionInfoSize = sizeof (info);
  179297. GetVersionEx (&info);
  179298. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179299. {
  179300. switch (info.dwMajorVersion)
  179301. {
  179302. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179303. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179304. default: jassertfalse; break; // !! not a supported OS!
  179305. }
  179306. }
  179307. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179308. {
  179309. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179310. return Win98;
  179311. }
  179312. return UnknownOS;
  179313. }
  179314. const String SystemStats::getOperatingSystemName() throw()
  179315. {
  179316. const char* name = "Unknown OS";
  179317. switch (getOperatingSystemType())
  179318. {
  179319. case Windows7: name = "Windows 7"; break;
  179320. case WinVista: name = "Windows Vista"; break;
  179321. case WinXP: name = "Windows XP"; break;
  179322. case Win2000: name = "Windows 2000"; break;
  179323. case Win98: name = "Windows 98"; break;
  179324. default: jassertfalse; break; // !! new type of OS?
  179325. }
  179326. return name;
  179327. }
  179328. bool SystemStats::isOperatingSystem64Bit() throw()
  179329. {
  179330. #ifdef _WIN64
  179331. return true;
  179332. #else
  179333. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179334. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179335. BOOL isWow64 = FALSE;
  179336. return (fnIsWow64Process != 0)
  179337. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179338. && (isWow64 != FALSE);
  179339. #endif
  179340. }
  179341. int SystemStats::getMemorySizeInMegabytes() throw()
  179342. {
  179343. MEMORYSTATUSEX mem;
  179344. mem.dwLength = sizeof (mem);
  179345. GlobalMemoryStatusEx (&mem);
  179346. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179347. }
  179348. int SystemStats::getNumCpus() throw()
  179349. {
  179350. SYSTEM_INFO systemInfo;
  179351. GetSystemInfo (&systemInfo);
  179352. return systemInfo.dwNumberOfProcessors;
  179353. }
  179354. uint32 juce_millisecondsSinceStartup() throw()
  179355. {
  179356. return (uint32) GetTickCount();
  179357. }
  179358. int64 Time::getHighResolutionTicks() throw()
  179359. {
  179360. LARGE_INTEGER ticks;
  179361. QueryPerformanceCounter (&ticks);
  179362. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179363. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179364. // fix for a very obscure PCI hardware bug that can make the counter
  179365. // sometimes jump forwards by a few seconds..
  179366. static int64 hiResTicksOffset = 0;
  179367. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179368. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179369. hiResTicksOffset = newOffset;
  179370. return ticks.QuadPart + hiResTicksOffset;
  179371. }
  179372. double Time::getMillisecondCounterHiRes() throw()
  179373. {
  179374. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179375. }
  179376. int64 Time::getHighResolutionTicksPerSecond() throw()
  179377. {
  179378. return hiResTicksPerSecond;
  179379. }
  179380. int64 SystemStats::getClockCycleCounter() throw()
  179381. {
  179382. #if JUCE_USE_INTRINSICS
  179383. // MS intrinsics version...
  179384. return __rdtsc();
  179385. #elif JUCE_GCC
  179386. // GNU inline asm version...
  179387. unsigned int hi = 0, lo = 0;
  179388. __asm__ __volatile__ (
  179389. "xor %%eax, %%eax \n\
  179390. xor %%edx, %%edx \n\
  179391. rdtsc \n\
  179392. movl %%eax, %[lo] \n\
  179393. movl %%edx, %[hi]"
  179394. :
  179395. : [hi] "m" (hi),
  179396. [lo] "m" (lo)
  179397. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179398. return (int64) ((((uint64) hi) << 32) | lo);
  179399. #else
  179400. // MSVC inline asm version...
  179401. unsigned int hi = 0, lo = 0;
  179402. __asm
  179403. {
  179404. xor eax, eax
  179405. xor edx, edx
  179406. rdtsc
  179407. mov lo, eax
  179408. mov hi, edx
  179409. }
  179410. return (int64) ((((uint64) hi) << 32) | lo);
  179411. #endif
  179412. }
  179413. int SystemStats::getCpuSpeedInMegaherz() throw()
  179414. {
  179415. const int64 cycles = SystemStats::getClockCycleCounter();
  179416. const uint32 millis = Time::getMillisecondCounter();
  179417. int lastResult = 0;
  179418. for (;;)
  179419. {
  179420. int n = 1000000;
  179421. while (--n > 0) {}
  179422. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179423. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179424. if (millisElapsed > 80)
  179425. {
  179426. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179427. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179428. return newResult;
  179429. lastResult = newResult;
  179430. }
  179431. }
  179432. }
  179433. bool Time::setSystemTimeToThisTime() const throw()
  179434. {
  179435. SYSTEMTIME st;
  179436. st.wDayOfWeek = 0;
  179437. st.wYear = (WORD) getYear();
  179438. st.wMonth = (WORD) (getMonth() + 1);
  179439. st.wDay = (WORD) getDayOfMonth();
  179440. st.wHour = (WORD) getHours();
  179441. st.wMinute = (WORD) getMinutes();
  179442. st.wSecond = (WORD) getSeconds();
  179443. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179444. // do this twice because of daylight saving conversion problems - the
  179445. // first one sets it up, the second one kicks it in.
  179446. return SetLocalTime (&st) != 0
  179447. && SetLocalTime (&st) != 0;
  179448. }
  179449. int SystemStats::getPageSize() throw()
  179450. {
  179451. SYSTEM_INFO systemInfo;
  179452. GetSystemInfo (&systemInfo);
  179453. return systemInfo.dwPageSize;
  179454. }
  179455. const String SystemStats::getLogonName()
  179456. {
  179457. TCHAR text [256];
  179458. DWORD len = numElementsInArray (text) - 2;
  179459. zerostruct (text);
  179460. GetUserName (text, &len);
  179461. return String (text, len);
  179462. }
  179463. const String SystemStats::getFullUserName()
  179464. {
  179465. return getLogonName();
  179466. }
  179467. #endif
  179468. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179469. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179470. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179471. // compiled on its own).
  179472. #if JUCE_INCLUDED_FILE
  179473. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179474. extern HWND juce_messageWindowHandle;
  179475. #endif
  179476. #if ! JUCE_USE_INTRINSICS
  179477. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179478. // older ones we have to actually call the ops as win32 functions..
  179479. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179480. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179481. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179482. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179483. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179484. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179485. #endif
  179486. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179487. CriticalSection::CriticalSection() throw()
  179488. {
  179489. // (just to check the MS haven't changed this structure and broken things...)
  179490. #if _MSC_VER >= 1400
  179491. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179492. #else
  179493. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179494. #endif
  179495. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179496. }
  179497. CriticalSection::~CriticalSection() throw()
  179498. {
  179499. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179500. }
  179501. void CriticalSection::enter() const throw()
  179502. {
  179503. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179504. }
  179505. bool CriticalSection::tryEnter() const throw()
  179506. {
  179507. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179508. }
  179509. void CriticalSection::exit() const throw()
  179510. {
  179511. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179512. }
  179513. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  179514. : internal (CreateEvent (0, manualReset ? TRUE : FALSE, FALSE, 0))
  179515. {
  179516. }
  179517. WaitableEvent::~WaitableEvent() throw()
  179518. {
  179519. CloseHandle (internal);
  179520. }
  179521. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179522. {
  179523. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179524. }
  179525. void WaitableEvent::signal() const throw()
  179526. {
  179527. SetEvent (internal);
  179528. }
  179529. void WaitableEvent::reset() const throw()
  179530. {
  179531. ResetEvent (internal);
  179532. }
  179533. void JUCE_API juce_threadEntryPoint (void*);
  179534. static unsigned int __stdcall threadEntryProc (void* userData)
  179535. {
  179536. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179537. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179538. GetCurrentThreadId(), TRUE);
  179539. #endif
  179540. juce_threadEntryPoint (userData);
  179541. _endthreadex (0);
  179542. return 0;
  179543. }
  179544. void juce_CloseThreadHandle (void* handle)
  179545. {
  179546. CloseHandle ((HANDLE) handle);
  179547. }
  179548. void* juce_createThread (void* userData)
  179549. {
  179550. unsigned int threadId;
  179551. return (void*) _beginthreadex (0, 0,
  179552. &threadEntryProc,
  179553. userData,
  179554. 0, &threadId);
  179555. }
  179556. void juce_killThread (void* handle)
  179557. {
  179558. if (handle != 0)
  179559. {
  179560. #ifdef JUCE_DEBUG
  179561. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179562. #endif
  179563. TerminateThread (handle, 0);
  179564. }
  179565. }
  179566. void juce_setCurrentThreadName (const String& name)
  179567. {
  179568. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179569. struct
  179570. {
  179571. DWORD dwType;
  179572. LPCSTR szName;
  179573. DWORD dwThreadID;
  179574. DWORD dwFlags;
  179575. } info;
  179576. info.dwType = 0x1000;
  179577. info.szName = name.toCString();
  179578. info.dwThreadID = GetCurrentThreadId();
  179579. info.dwFlags = 0;
  179580. __try
  179581. {
  179582. RaiseException (0x406d1388 /*MS_VC_EXCEPTION*/, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179583. }
  179584. __except (EXCEPTION_CONTINUE_EXECUTION)
  179585. {}
  179586. #else
  179587. (void) name;
  179588. #endif
  179589. }
  179590. Thread::ThreadID Thread::getCurrentThreadId()
  179591. {
  179592. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179593. }
  179594. // priority 1 to 10 where 5=normal, 1=low
  179595. bool juce_setThreadPriority (void* threadHandle, int priority)
  179596. {
  179597. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179598. if (priority < 1)
  179599. pri = THREAD_PRIORITY_IDLE;
  179600. else if (priority < 2)
  179601. pri = THREAD_PRIORITY_LOWEST;
  179602. else if (priority < 5)
  179603. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179604. else if (priority < 7)
  179605. pri = THREAD_PRIORITY_NORMAL;
  179606. else if (priority < 9)
  179607. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179608. else if (priority < 10)
  179609. pri = THREAD_PRIORITY_HIGHEST;
  179610. if (threadHandle == 0)
  179611. threadHandle = GetCurrentThread();
  179612. return SetThreadPriority (threadHandle, pri) != FALSE;
  179613. }
  179614. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179615. {
  179616. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179617. }
  179618. static HANDLE sleepEvent = 0;
  179619. void juce_initialiseThreadEvents()
  179620. {
  179621. if (sleepEvent == 0)
  179622. #ifdef JUCE_DEBUG
  179623. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179624. #else
  179625. sleepEvent = CreateEvent (0, 0, 0, 0);
  179626. #endif
  179627. }
  179628. void Thread::yield()
  179629. {
  179630. Sleep (0);
  179631. }
  179632. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179633. {
  179634. if (millisecs >= 10)
  179635. {
  179636. Sleep (millisecs);
  179637. }
  179638. else
  179639. {
  179640. jassert (sleepEvent != 0);
  179641. // unlike Sleep() this is guaranteed to return to the current thread after
  179642. // the time expires, so we'll use this for short waits, which are more likely
  179643. // to need to be accurate
  179644. WaitForSingleObject (sleepEvent, millisecs);
  179645. }
  179646. }
  179647. static int lastProcessPriority = -1;
  179648. // called by WindowDriver because Windows does wierd things to process priority
  179649. // when you swap apps, and this forces an update when the app is brought to the front.
  179650. void juce_repeatLastProcessPriority()
  179651. {
  179652. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179653. {
  179654. DWORD p;
  179655. switch (lastProcessPriority)
  179656. {
  179657. case Process::LowPriority: p = IDLE_PRIORITY_CLASS; break;
  179658. case Process::NormalPriority: p = NORMAL_PRIORITY_CLASS; break;
  179659. case Process::HighPriority: p = HIGH_PRIORITY_CLASS; break;
  179660. case Process::RealtimePriority: p = REALTIME_PRIORITY_CLASS; break;
  179661. default: jassertfalse; return; // bad priority value
  179662. }
  179663. SetPriorityClass (GetCurrentProcess(), p);
  179664. }
  179665. }
  179666. void Process::setPriority (ProcessPriority prior)
  179667. {
  179668. if (lastProcessPriority != (int) prior)
  179669. {
  179670. lastProcessPriority = (int) prior;
  179671. juce_repeatLastProcessPriority();
  179672. }
  179673. }
  179674. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179675. {
  179676. return IsDebuggerPresent() != FALSE;
  179677. }
  179678. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179679. {
  179680. return juce_isRunningUnderDebugger();
  179681. }
  179682. void Process::raisePrivilege()
  179683. {
  179684. jassertfalse // xxx not implemented
  179685. }
  179686. void Process::lowerPrivilege()
  179687. {
  179688. jassertfalse // xxx not implemented
  179689. }
  179690. void Process::terminate()
  179691. {
  179692. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179693. _CrtDumpMemoryLeaks();
  179694. #endif
  179695. // bullet in the head in case there's a problem shutting down..
  179696. ExitProcess (0);
  179697. }
  179698. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179699. {
  179700. void* result = 0;
  179701. JUCE_TRY
  179702. {
  179703. result = LoadLibrary (name);
  179704. }
  179705. JUCE_CATCH_ALL
  179706. return result;
  179707. }
  179708. void PlatformUtilities::freeDynamicLibrary (void* h)
  179709. {
  179710. JUCE_TRY
  179711. {
  179712. if (h != 0)
  179713. FreeLibrary ((HMODULE) h);
  179714. }
  179715. JUCE_CATCH_ALL
  179716. }
  179717. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179718. {
  179719. return (h != 0) ? GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179720. }
  179721. class InterProcessLock::Pimpl
  179722. {
  179723. public:
  179724. Pimpl (const String& name, const int timeOutMillisecs)
  179725. : handle (0), refCount (1)
  179726. {
  179727. handle = CreateMutex (0, TRUE, "Global\\" + name.replaceCharacter ('\\','/'));
  179728. if (handle != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179729. {
  179730. if (timeOutMillisecs == 0)
  179731. {
  179732. close();
  179733. return;
  179734. }
  179735. switch (WaitForSingleObject (handle, timeOutMillisecs < 0 ? INFINITE : timeOutMillisecs))
  179736. {
  179737. case WAIT_OBJECT_0:
  179738. case WAIT_ABANDONED:
  179739. break;
  179740. case WAIT_TIMEOUT:
  179741. default:
  179742. close();
  179743. break;
  179744. }
  179745. }
  179746. }
  179747. ~Pimpl()
  179748. {
  179749. close();
  179750. }
  179751. void close()
  179752. {
  179753. if (handle != 0)
  179754. {
  179755. ReleaseMutex (handle);
  179756. CloseHandle (handle);
  179757. handle = 0;
  179758. }
  179759. }
  179760. HANDLE handle;
  179761. int refCount;
  179762. };
  179763. InterProcessLock::InterProcessLock (const String& name_)
  179764. : name (name_)
  179765. {
  179766. }
  179767. InterProcessLock::~InterProcessLock()
  179768. {
  179769. }
  179770. bool InterProcessLock::enter (const int timeOutMillisecs)
  179771. {
  179772. const ScopedLock sl (lock);
  179773. if (pimpl == 0)
  179774. {
  179775. pimpl = new Pimpl (name, timeOutMillisecs);
  179776. if (pimpl->handle == 0)
  179777. pimpl = 0;
  179778. }
  179779. else
  179780. {
  179781. pimpl->refCount++;
  179782. }
  179783. return pimpl != 0;
  179784. }
  179785. void InterProcessLock::exit()
  179786. {
  179787. const ScopedLock sl (lock);
  179788. // Trying to release the lock too many times!
  179789. jassert (pimpl != 0);
  179790. if (pimpl != 0 && --(pimpl->refCount) == 0)
  179791. pimpl = 0;
  179792. }
  179793. #endif
  179794. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179795. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179796. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179797. // compiled on its own).
  179798. #if JUCE_INCLUDED_FILE
  179799. #ifndef CSIDL_MYMUSIC
  179800. #define CSIDL_MYMUSIC 0x000d
  179801. #endif
  179802. #ifndef CSIDL_MYVIDEO
  179803. #define CSIDL_MYVIDEO 0x000e
  179804. #endif
  179805. #ifndef INVALID_FILE_ATTRIBUTES
  179806. #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
  179807. #endif
  179808. const juce_wchar File::separator = '\\';
  179809. const juce_wchar* File::separatorString = T("\\");
  179810. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179811. {
  179812. if (fileName.isEmpty())
  179813. return false;
  179814. const DWORD attr = GetFileAttributes (fileName);
  179815. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179816. : (attr != INVALID_FILE_ATTRIBUTES);
  179817. }
  179818. bool juce_isDirectory (const String& fileName)
  179819. {
  179820. const DWORD attr = GetFileAttributes (fileName);
  179821. return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
  179822. }
  179823. bool juce_canWriteToFile (const String& fileName)
  179824. {
  179825. const DWORD attr = GetFileAttributes (fileName);
  179826. return (attr & FILE_ATTRIBUTE_READONLY) == 0;
  179827. }
  179828. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179829. {
  179830. DWORD attr = GetFileAttributes (fileName);
  179831. if (attr == INVALID_FILE_ATTRIBUTES)
  179832. return false;
  179833. if (isReadOnly != juce_canWriteToFile (fileName))
  179834. return true;
  179835. if (isReadOnly)
  179836. attr |= FILE_ATTRIBUTE_READONLY;
  179837. else
  179838. attr &= ~FILE_ATTRIBUTE_READONLY;
  179839. return SetFileAttributes (fileName, attr) != FALSE;
  179840. }
  179841. bool File::isHidden() const
  179842. {
  179843. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179844. }
  179845. bool juce_deleteFile (const String& fileName)
  179846. {
  179847. if (juce_isDirectory (fileName))
  179848. return RemoveDirectory (fileName) != 0;
  179849. return DeleteFile (fileName) != 0;
  179850. }
  179851. bool File::moveToTrash() const
  179852. {
  179853. if (! exists())
  179854. return true;
  179855. SHFILEOPSTRUCT fos;
  179856. zerostruct (fos);
  179857. // The string we pass in must be double null terminated..
  179858. String doubleNullTermPath (getFullPathName() + " ");
  179859. TCHAR* const p = const_cast <TCHAR*> (static_cast <const TCHAR*> (doubleNullTermPath));
  179860. p [getFullPathName().length()] = 0;
  179861. fos.wFunc = FO_DELETE;
  179862. fos.pFrom = p;
  179863. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179864. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179865. return SHFileOperation (&fos) == 0;
  179866. }
  179867. bool juce_moveFile (const String& source, const String& dest)
  179868. {
  179869. return MoveFile (source, dest) != 0;
  179870. }
  179871. bool juce_copyFile (const String& source, const String& dest)
  179872. {
  179873. return CopyFile (source, dest, false) != 0;
  179874. }
  179875. void juce_createDirectory (const String& fileName)
  179876. {
  179877. if (! juce_fileExists (fileName, true))
  179878. CreateDirectory (fileName, 0);
  179879. }
  179880. // return 0 if not possible
  179881. void* juce_fileOpen (const String& fileName, bool forWriting)
  179882. {
  179883. HANDLE h;
  179884. if (forWriting)
  179885. {
  179886. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179887. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179888. if (h != INVALID_HANDLE_VALUE)
  179889. SetFilePointer (h, 0, 0, FILE_END);
  179890. else
  179891. h = 0;
  179892. }
  179893. else
  179894. {
  179895. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179896. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179897. if (h == INVALID_HANDLE_VALUE)
  179898. h = 0;
  179899. }
  179900. return h;
  179901. }
  179902. void juce_fileClose (void* handle)
  179903. {
  179904. CloseHandle (handle);
  179905. }
  179906. int juce_fileRead (void* handle, void* buffer, int size)
  179907. {
  179908. DWORD num = 0;
  179909. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179910. return (int) num;
  179911. }
  179912. int juce_fileWrite (void* handle, const void* buffer, int size)
  179913. {
  179914. DWORD num;
  179915. WriteFile ((HANDLE) handle, buffer, size, &num, 0);
  179916. return (int) num;
  179917. }
  179918. int64 juce_fileSetPosition (void* handle, int64 pos)
  179919. {
  179920. LARGE_INTEGER li;
  179921. li.QuadPart = pos;
  179922. li.LowPart = SetFilePointer ((HANDLE) handle, li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
  179923. return li.QuadPart;
  179924. }
  179925. int64 juce_fileGetPosition (void* handle)
  179926. {
  179927. LARGE_INTEGER li;
  179928. li.QuadPart = 0;
  179929. li.LowPart = SetFilePointer ((HANDLE) handle, 0, &li.HighPart, FILE_CURRENT); // (returns -1 if it fails)
  179930. return jmax ((int64) 0, li.QuadPart);
  179931. }
  179932. void juce_fileFlush (void* handle)
  179933. {
  179934. FlushFileBuffers ((HANDLE) handle);
  179935. }
  179936. int64 juce_getFileSize (const String& fileName)
  179937. {
  179938. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179939. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179940. return (((int64) attributes.nFileSizeHigh) << 32) | attributes.nFileSizeLow;
  179941. return 0;
  179942. }
  179943. static int64 fileTimeToTime (const FILETIME* const ft)
  179944. {
  179945. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME)); // tell me if this fails!
  179946. return (reinterpret_cast<const ULARGE_INTEGER*> (ft)->QuadPart - literal64bit (116444736000000000)) / 10000;
  179947. }
  179948. static void timeToFileTime (const int64 time, FILETIME* const ft)
  179949. {
  179950. reinterpret_cast<ULARGE_INTEGER*> (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000);
  179951. }
  179952. void juce_getFileTimes (const String& fileName,
  179953. int64& modificationTime,
  179954. int64& accessTime,
  179955. int64& creationTime)
  179956. {
  179957. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179958. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179959. {
  179960. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  179961. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  179962. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  179963. }
  179964. else
  179965. {
  179966. creationTime = accessTime = modificationTime = 0;
  179967. }
  179968. }
  179969. bool juce_setFileTimes (const String& fileName,
  179970. int64 modificationTime,
  179971. int64 accessTime,
  179972. int64 creationTime)
  179973. {
  179974. void* const h = juce_fileOpen (fileName, true);
  179975. bool ok = false;
  179976. if (h != 0)
  179977. {
  179978. FILETIME m, a, c;
  179979. timeToFileTime (modificationTime, &m);
  179980. timeToFileTime (accessTime, &a);
  179981. timeToFileTime (creationTime, &c);
  179982. ok = SetFileTime ((HANDLE) h,
  179983. creationTime > 0 ? &c : 0,
  179984. accessTime > 0 ? &a : 0,
  179985. modificationTime > 0 ? &m : 0) != 0;
  179986. juce_fileClose (h);
  179987. }
  179988. return ok;
  179989. }
  179990. // return '\0' separated list of strings
  179991. const StringArray juce_getFileSystemRoots()
  179992. {
  179993. TCHAR buffer [2048];
  179994. buffer[0] = 0;
  179995. buffer[1] = 0;
  179996. GetLogicalDriveStrings (2048, buffer);
  179997. const TCHAR* n = buffer;
  179998. StringArray roots;
  179999. while (*n != 0)
  180000. {
  180001. roots.add (String (n));
  180002. while (*n++ != 0)
  180003. {}
  180004. }
  180005. roots.sort (true);
  180006. return roots;
  180007. }
  180008. static const String getDriveFromPath (const String& path)
  180009. {
  180010. if (path.isNotEmpty() && path[1] == ':')
  180011. return path.substring (0, 2) + '\\';
  180012. return path;
  180013. }
  180014. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180015. int& volumeSerialNumber)
  180016. {
  180017. TCHAR dest[64];
  180018. DWORD serialNum;
  180019. if (! GetVolumeInformation (getDriveFromPath (filenameOnVolume), dest,
  180020. numElementsInArray (dest), &serialNum, 0, 0, 0, 0))
  180021. {
  180022. dest[0] = 0;
  180023. serialNum = 0;
  180024. }
  180025. volumeSerialNumber = serialNum;
  180026. return dest;
  180027. }
  180028. static int64 getDiskSpaceInfo (const String& path, const bool total)
  180029. {
  180030. ULARGE_INTEGER spc, tot, totFree;
  180031. if (GetDiskFreeSpaceEx (getDriveFromPath (path), &spc, &tot, &totFree))
  180032. return total ? (int64) tot.QuadPart
  180033. : (int64) spc.QuadPart;
  180034. return 0;
  180035. }
  180036. int64 File::getBytesFreeOnVolume() const
  180037. {
  180038. return getDiskSpaceInfo (getFullPathName(), false);
  180039. }
  180040. int64 File::getVolumeTotalSize() const
  180041. {
  180042. return getDiskSpaceInfo (getFullPathName(), true);
  180043. }
  180044. static unsigned int getWindowsDriveType (const String& path)
  180045. {
  180046. return GetDriveType (getDriveFromPath (path));
  180047. }
  180048. bool File::isOnCDRomDrive() const
  180049. {
  180050. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180051. }
  180052. bool File::isOnHardDisk() const
  180053. {
  180054. if (fullPath.isEmpty())
  180055. return false;
  180056. const unsigned int n = getWindowsDriveType (getFullPathName());
  180057. if (fullPath.toLowerCase()[0] <= 'b' && fullPath[1] == ':')
  180058. return n != DRIVE_REMOVABLE;
  180059. else
  180060. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180061. }
  180062. bool File::isOnRemovableDrive() const
  180063. {
  180064. if (fullPath.isEmpty())
  180065. return false;
  180066. const unsigned int n = getWindowsDriveType (getFullPathName());
  180067. return n == DRIVE_CDROM
  180068. || n == DRIVE_REMOTE
  180069. || n == DRIVE_REMOVABLE
  180070. || n == DRIVE_RAMDISK;
  180071. }
  180072. static const File juce_getSpecialFolderPath (int type)
  180073. {
  180074. WCHAR path [MAX_PATH + 256];
  180075. if (SHGetSpecialFolderPath (0, path, type, FALSE))
  180076. return File (String (path));
  180077. return File::nonexistent;
  180078. }
  180079. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180080. {
  180081. int csidlType = 0;
  180082. switch (type)
  180083. {
  180084. case userHomeDirectory: csidlType = CSIDL_PROFILE; break;
  180085. case userDocumentsDirectory: csidlType = CSIDL_PERSONAL; break;
  180086. case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break;
  180087. case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break;
  180088. case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break;
  180089. case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break;
  180090. case userMusicDirectory: csidlType = CSIDL_MYMUSIC; break;
  180091. case userMoviesDirectory: csidlType = CSIDL_MYVIDEO; break;
  180092. case tempDirectory:
  180093. {
  180094. WCHAR dest [2048];
  180095. dest[0] = 0;
  180096. GetTempPath (numElementsInArray (dest), dest);
  180097. return File (String (dest));
  180098. }
  180099. case invokedExecutableFile:
  180100. case currentExecutableFile:
  180101. case currentApplicationFile:
  180102. {
  180103. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180104. WCHAR dest [MAX_PATH + 256];
  180105. dest[0] = 0;
  180106. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180107. return File (String (dest));
  180108. }
  180109. break;
  180110. default:
  180111. jassertfalse // unknown type?
  180112. return File::nonexistent;
  180113. }
  180114. return juce_getSpecialFolderPath (csidlType);
  180115. }
  180116. const File File::getCurrentWorkingDirectory()
  180117. {
  180118. WCHAR dest [MAX_PATH + 256];
  180119. dest[0] = 0;
  180120. GetCurrentDirectory (numElementsInArray (dest), dest);
  180121. return File (String (dest));
  180122. }
  180123. bool File::setAsCurrentWorkingDirectory() const
  180124. {
  180125. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180126. }
  180127. const String File::getVersion() const
  180128. {
  180129. String result;
  180130. DWORD handle = 0;
  180131. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180132. HeapBlock<char> buffer;
  180133. buffer.calloc (bufferSize);
  180134. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180135. {
  180136. VS_FIXEDFILEINFO* vffi;
  180137. UINT len = 0;
  180138. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180139. {
  180140. result << (int) HIWORD (vffi->dwFileVersionMS) << '.'
  180141. << (int) LOWORD (vffi->dwFileVersionMS) << '.'
  180142. << (int) HIWORD (vffi->dwFileVersionLS) << '.'
  180143. << (int) LOWORD (vffi->dwFileVersionLS);
  180144. }
  180145. }
  180146. return result;
  180147. }
  180148. const File File::getLinkedTarget() const
  180149. {
  180150. File result (*this);
  180151. String p (getFullPathName());
  180152. if (! exists())
  180153. p += ".lnk";
  180154. else if (getFileExtension() != ".lnk")
  180155. return result;
  180156. ComSmartPtr <IShellLink> shellLink;
  180157. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180158. {
  180159. ComSmartPtr <IPersistFile> persistFile;
  180160. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180161. {
  180162. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180163. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180164. {
  180165. WIN32_FIND_DATA winFindData;
  180166. WCHAR resolvedPath [MAX_PATH];
  180167. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180168. result = File (resolvedPath);
  180169. }
  180170. }
  180171. }
  180172. return result;
  180173. }
  180174. template <class FindDataType>
  180175. static void getFindFileInfo (FindDataType& findData,
  180176. String& filename, bool* const isDir, bool* const isHidden,
  180177. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180178. bool* const isReadOnly)
  180179. {
  180180. filename = findData.cFileName;
  180181. if (isDir != 0)
  180182. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180183. if (isHidden != 0)
  180184. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180185. if (fileSize != 0)
  180186. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180187. if (modTime != 0)
  180188. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180189. if (creationTime != 0)
  180190. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180191. if (isReadOnly != 0)
  180192. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180193. }
  180194. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180195. bool* isDir, bool* isHidden, int64* fileSize,
  180196. Time* modTime, Time* creationTime, bool* isReadOnly)
  180197. {
  180198. String wc (directory);
  180199. if (! wc.endsWithChar (File::separator))
  180200. wc += File::separator;
  180201. wc += wildCard;
  180202. WIN32_FIND_DATA findData;
  180203. HANDLE h = FindFirstFile (wc, &findData);
  180204. if (h != INVALID_HANDLE_VALUE)
  180205. {
  180206. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180207. modTime, creationTime, isReadOnly);
  180208. return h;
  180209. }
  180210. firstResult = String::empty;
  180211. return 0;
  180212. }
  180213. bool juce_findFileNext (void* handle, String& resultFile,
  180214. bool* isDir, bool* isHidden, int64* fileSize,
  180215. Time* modTime, Time* creationTime, bool* isReadOnly)
  180216. {
  180217. WIN32_FIND_DATA findData;
  180218. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180219. {
  180220. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180221. modTime, creationTime, isReadOnly);
  180222. return true;
  180223. }
  180224. resultFile = String::empty;
  180225. return false;
  180226. }
  180227. void juce_findFileClose (void* handle)
  180228. {
  180229. FindClose (handle);
  180230. }
  180231. bool juce_launchFile (const String& fileName, const String& parameters)
  180232. {
  180233. HINSTANCE hInstance = 0;
  180234. JUCE_TRY
  180235. {
  180236. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180237. }
  180238. JUCE_CATCH_ALL
  180239. return hInstance > (HINSTANCE) 32;
  180240. }
  180241. void File::revealToUser() const
  180242. {
  180243. if (isDirectory())
  180244. startAsProcess();
  180245. else if (getParentDirectory().exists())
  180246. getParentDirectory().startAsProcess();
  180247. }
  180248. class NamedPipeInternal
  180249. {
  180250. public:
  180251. NamedPipeInternal (const String& file, const bool isPipe_)
  180252. : pipeH (0),
  180253. cancelEvent (0),
  180254. connected (false),
  180255. isPipe (isPipe_)
  180256. {
  180257. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180258. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180259. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180260. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180261. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180262. }
  180263. ~NamedPipeInternal()
  180264. {
  180265. disconnectPipe();
  180266. if (pipeH != 0)
  180267. CloseHandle (pipeH);
  180268. CloseHandle (cancelEvent);
  180269. }
  180270. bool connect (const int timeOutMs)
  180271. {
  180272. if (! isPipe)
  180273. return true;
  180274. if (! connected)
  180275. {
  180276. OVERLAPPED over;
  180277. zerostruct (over);
  180278. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180279. if (ConnectNamedPipe (pipeH, &over))
  180280. {
  180281. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180282. }
  180283. else
  180284. {
  180285. const int err = GetLastError();
  180286. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180287. {
  180288. HANDLE handles[] = { over.hEvent, cancelEvent };
  180289. if (WaitForMultipleObjects (2, handles, FALSE,
  180290. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180291. connected = true;
  180292. }
  180293. else if (err == ERROR_PIPE_CONNECTED)
  180294. {
  180295. connected = true;
  180296. }
  180297. }
  180298. CloseHandle (over.hEvent);
  180299. }
  180300. return connected;
  180301. }
  180302. void disconnectPipe()
  180303. {
  180304. if (connected)
  180305. {
  180306. DisconnectNamedPipe (pipeH);
  180307. connected = false;
  180308. }
  180309. }
  180310. HANDLE pipeH;
  180311. HANDLE cancelEvent;
  180312. bool connected, isPipe;
  180313. };
  180314. void NamedPipe::close()
  180315. {
  180316. cancelPendingReads();
  180317. const ScopedLock sl (lock);
  180318. delete static_cast<NamedPipeInternal*> (internal);
  180319. internal = 0;
  180320. }
  180321. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180322. {
  180323. close();
  180324. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180325. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180326. {
  180327. internal = intern.release();
  180328. return true;
  180329. }
  180330. return false;
  180331. }
  180332. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180333. {
  180334. const ScopedLock sl (lock);
  180335. int bytesRead = -1;
  180336. bool waitAgain = true;
  180337. while (waitAgain && internal != 0)
  180338. {
  180339. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180340. waitAgain = false;
  180341. if (! intern->connect (timeOutMilliseconds))
  180342. break;
  180343. if (maxBytesToRead <= 0)
  180344. return 0;
  180345. OVERLAPPED over;
  180346. zerostruct (over);
  180347. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180348. unsigned long numRead;
  180349. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180350. {
  180351. bytesRead = (int) numRead;
  180352. }
  180353. else if (GetLastError() == ERROR_IO_PENDING)
  180354. {
  180355. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180356. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180357. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180358. : INFINITE);
  180359. if (waitResult != WAIT_OBJECT_0)
  180360. {
  180361. // if the operation timed out, let's cancel it...
  180362. CancelIo (intern->pipeH);
  180363. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180364. }
  180365. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180366. {
  180367. bytesRead = (int) numRead;
  180368. }
  180369. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180370. {
  180371. intern->disconnectPipe();
  180372. waitAgain = true;
  180373. }
  180374. }
  180375. else
  180376. {
  180377. waitAgain = internal != 0;
  180378. Sleep (5);
  180379. }
  180380. CloseHandle (over.hEvent);
  180381. }
  180382. return bytesRead;
  180383. }
  180384. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180385. {
  180386. int bytesWritten = -1;
  180387. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180388. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180389. {
  180390. if (numBytesToWrite <= 0)
  180391. return 0;
  180392. OVERLAPPED over;
  180393. zerostruct (over);
  180394. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180395. unsigned long numWritten;
  180396. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180397. {
  180398. bytesWritten = (int) numWritten;
  180399. }
  180400. else if (GetLastError() == ERROR_IO_PENDING)
  180401. {
  180402. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180403. DWORD waitResult;
  180404. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180405. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180406. : INFINITE);
  180407. if (waitResult != WAIT_OBJECT_0)
  180408. {
  180409. CancelIo (intern->pipeH);
  180410. WaitForSingleObject (over.hEvent, INFINITE);
  180411. }
  180412. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180413. {
  180414. bytesWritten = (int) numWritten;
  180415. }
  180416. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180417. {
  180418. intern->disconnectPipe();
  180419. }
  180420. }
  180421. CloseHandle (over.hEvent);
  180422. }
  180423. return bytesWritten;
  180424. }
  180425. void NamedPipe::cancelPendingReads()
  180426. {
  180427. if (internal != 0)
  180428. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180429. }
  180430. #endif
  180431. /*** End of inlined file: juce_win32_Files.cpp ***/
  180432. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180433. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180434. // compiled on its own).
  180435. #if JUCE_INCLUDED_FILE
  180436. #ifndef INTERNET_FLAG_NEED_FILE
  180437. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180438. #endif
  180439. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180440. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180441. #endif
  180442. bool juce_isOnLine()
  180443. {
  180444. DWORD connectionType;
  180445. return InternetGetConnectedState (&connectionType, 0) != 0
  180446. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180447. }
  180448. struct ConnectionAndRequestStruct
  180449. {
  180450. HINTERNET connection, request;
  180451. };
  180452. static HINTERNET sessionHandle = 0;
  180453. #ifndef WORKAROUND_TIMEOUT_BUG
  180454. //#define WORKAROUND_TIMEOUT_BUG 1
  180455. #endif
  180456. #if WORKAROUND_TIMEOUT_BUG
  180457. // Required because of a Microsoft bug in setting a timeout
  180458. class InternetConnectThread : public Thread
  180459. {
  180460. public:
  180461. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180462. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180463. {
  180464. startThread();
  180465. }
  180466. ~InternetConnectThread()
  180467. {
  180468. stopThread (60000);
  180469. }
  180470. void run()
  180471. {
  180472. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180473. uc.nPort, _T(""), _T(""),
  180474. isFtp ? INTERNET_SERVICE_FTP
  180475. : INTERNET_SERVICE_HTTP,
  180476. 0, 0);
  180477. notify();
  180478. }
  180479. juce_UseDebuggingNewOperator
  180480. private:
  180481. URL_COMPONENTS& uc;
  180482. HINTERNET& connection;
  180483. const bool isFtp;
  180484. InternetConnectThread (const InternetConnectThread&);
  180485. InternetConnectThread& operator= (const InternetConnectThread&);
  180486. };
  180487. #endif
  180488. void* juce_openInternetFile (const String& url,
  180489. const String& headers,
  180490. const MemoryBlock& postData,
  180491. const bool isPost,
  180492. URL::OpenStreamProgressCallback* callback,
  180493. void* callbackContext,
  180494. int timeOutMs)
  180495. {
  180496. if (sessionHandle == 0)
  180497. sessionHandle = InternetOpen (_T("juce"),
  180498. INTERNET_OPEN_TYPE_PRECONFIG,
  180499. 0, 0, 0);
  180500. if (sessionHandle != 0)
  180501. {
  180502. // break up the url..
  180503. TCHAR file[1024], server[1024];
  180504. URL_COMPONENTS uc;
  180505. zerostruct (uc);
  180506. uc.dwStructSize = sizeof (uc);
  180507. uc.dwUrlPathLength = sizeof (file);
  180508. uc.dwHostNameLength = sizeof (server);
  180509. uc.lpszUrlPath = file;
  180510. uc.lpszHostName = server;
  180511. if (InternetCrackUrl (url, 0, 0, &uc))
  180512. {
  180513. int disable = 1;
  180514. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180515. if (timeOutMs == 0)
  180516. timeOutMs = 30000;
  180517. else if (timeOutMs < 0)
  180518. timeOutMs = -1;
  180519. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180520. const bool isFtp = url.startsWithIgnoreCase ("ftp:");
  180521. #if WORKAROUND_TIMEOUT_BUG
  180522. HINTERNET connection = 0;
  180523. {
  180524. InternetConnectThread connectThread (uc, connection, isFtp);
  180525. connectThread.wait (timeOutMs);
  180526. if (connection == 0)
  180527. {
  180528. InternetCloseHandle (sessionHandle);
  180529. sessionHandle = 0;
  180530. }
  180531. }
  180532. #else
  180533. HINTERNET connection = InternetConnect (sessionHandle,
  180534. uc.lpszHostName,
  180535. uc.nPort,
  180536. _T(""), _T(""),
  180537. isFtp ? INTERNET_SERVICE_FTP
  180538. : INTERNET_SERVICE_HTTP,
  180539. 0, 0);
  180540. #endif
  180541. if (connection != 0)
  180542. {
  180543. if (isFtp)
  180544. {
  180545. HINTERNET request = FtpOpenFile (connection,
  180546. uc.lpszUrlPath,
  180547. GENERIC_READ,
  180548. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180549. 0);
  180550. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180551. result->connection = connection;
  180552. result->request = request;
  180553. return result;
  180554. }
  180555. else
  180556. {
  180557. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180558. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180559. if (url.startsWithIgnoreCase ("https:"))
  180560. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180561. // IE7 seems to automatically work out when it's https)
  180562. HINTERNET request = HttpOpenRequest (connection,
  180563. isPost ? _T("POST")
  180564. : _T("GET"),
  180565. uc.lpszUrlPath,
  180566. 0, 0, mimeTypes, flags, 0);
  180567. if (request != 0)
  180568. {
  180569. INTERNET_BUFFERS buffers;
  180570. zerostruct (buffers);
  180571. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180572. buffers.lpcszHeader = (LPCTSTR) headers;
  180573. buffers.dwHeadersLength = headers.length();
  180574. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180575. ConnectionAndRequestStruct* result = 0;
  180576. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180577. {
  180578. int bytesSent = 0;
  180579. for (;;)
  180580. {
  180581. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180582. DWORD bytesDone = 0;
  180583. if (bytesToDo > 0
  180584. && ! InternetWriteFile (request,
  180585. static_cast <const char*> (postData.getData()) + bytesSent,
  180586. bytesToDo, &bytesDone))
  180587. {
  180588. break;
  180589. }
  180590. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180591. {
  180592. result = new ConnectionAndRequestStruct();
  180593. result->connection = connection;
  180594. result->request = request;
  180595. HttpEndRequest (request, 0, 0, 0);
  180596. return result;
  180597. }
  180598. bytesSent += bytesDone;
  180599. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180600. break;
  180601. }
  180602. }
  180603. InternetCloseHandle (request);
  180604. }
  180605. InternetCloseHandle (connection);
  180606. }
  180607. }
  180608. }
  180609. }
  180610. return 0;
  180611. }
  180612. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180613. {
  180614. DWORD bytesRead = 0;
  180615. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180616. if (crs != 0)
  180617. InternetReadFile (crs->request,
  180618. buffer, bytesToRead,
  180619. &bytesRead);
  180620. return bytesRead;
  180621. }
  180622. int juce_seekInInternetFile (void* handle, int newPosition)
  180623. {
  180624. if (handle != 0)
  180625. {
  180626. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180627. return InternetSetFilePointer (crs->request, newPosition, 0, FILE_BEGIN, 0);
  180628. }
  180629. else
  180630. {
  180631. return -1;
  180632. }
  180633. }
  180634. int64 juce_getInternetFileContentLength (void* handle)
  180635. {
  180636. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180637. if (crs != 0)
  180638. {
  180639. DWORD index = 0, result = 0, size = sizeof (result);
  180640. if (HttpQueryInfo (crs->request, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180641. &result, &size, &index))
  180642. {
  180643. return (int64) result;
  180644. }
  180645. }
  180646. return -1;
  180647. }
  180648. void juce_closeInternetFile (void* handle)
  180649. {
  180650. if (handle != 0)
  180651. {
  180652. ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180653. InternetCloseHandle (crs->request);
  180654. InternetCloseHandle (crs->connection);
  180655. delete crs;
  180656. }
  180657. }
  180658. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180659. {
  180660. int numFound = 0;
  180661. DynamicLibraryLoader dll ("iphlpapi.dll");
  180662. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180663. if (getAdaptersInfo != 0)
  180664. {
  180665. ULONG len = sizeof (IP_ADAPTER_INFO);
  180666. MemoryBlock mb;
  180667. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180668. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180669. {
  180670. mb.setSize (len);
  180671. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180672. }
  180673. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180674. {
  180675. PIP_ADAPTER_INFO adapter = adapterInfo;
  180676. while (adapter != 0)
  180677. {
  180678. int64 mac = 0;
  180679. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180680. mac = (mac << 8) | adapter->Address[i];
  180681. if (littleEndian)
  180682. mac = (int64) ByteOrder::swap ((uint64) mac);
  180683. if (numFound < maxNum && mac != 0)
  180684. addresses [numFound++] = mac;
  180685. adapter = adapter->Next;
  180686. }
  180687. }
  180688. }
  180689. return numFound;
  180690. }
  180691. struct ASTAT
  180692. {
  180693. ADAPTER_STATUS adapt;
  180694. NAME_BUFFER NameBuff [30];
  180695. };
  180696. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180697. {
  180698. int numFound = 0;
  180699. DynamicLibraryLoader dll ("netapi32.dll");
  180700. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180701. if (NetbiosCall != 0)
  180702. {
  180703. NCB ncb;
  180704. zerostruct (ncb);
  180705. ASTAT astat;
  180706. zerostruct (astat);
  180707. LANA_ENUM enums;
  180708. zerostruct (enums);
  180709. ncb.ncb_command = NCBENUM;
  180710. ncb.ncb_buffer = (unsigned char*) &enums;
  180711. ncb.ncb_length = sizeof (LANA_ENUM);
  180712. NetbiosCall (&ncb);
  180713. for (int i = 0; i < enums.length; ++i)
  180714. {
  180715. zerostruct (ncb);
  180716. ncb.ncb_command = NCBRESET;
  180717. ncb.ncb_lana_num = enums.lana[i];
  180718. if (NetbiosCall (&ncb) == 0)
  180719. {
  180720. zerostruct (ncb);
  180721. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180722. ncb.ncb_command = NCBASTAT;
  180723. ncb.ncb_lana_num = enums.lana[i];
  180724. ncb.ncb_buffer = (unsigned char*) &astat;
  180725. ncb.ncb_length = sizeof (ASTAT);
  180726. if (NetbiosCall (&ncb) == 0)
  180727. {
  180728. if (astat.adapt.adapter_type == 0xfe)
  180729. {
  180730. uint64 mac = 0;
  180731. for (int i = 6; --i >= 0;)
  180732. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180733. if (numFound < maxNum && mac != 0)
  180734. addresses [numFound++] = mac;
  180735. }
  180736. }
  180737. }
  180738. }
  180739. }
  180740. return numFound;
  180741. }
  180742. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180743. {
  180744. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180745. if (numFound == 0)
  180746. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180747. return numFound;
  180748. }
  180749. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180750. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180751. const String& emailSubject,
  180752. const String& bodyText,
  180753. const StringArray& filesToAttach)
  180754. {
  180755. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180756. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180757. bool ok = false;
  180758. if (mapiSendMail != 0)
  180759. {
  180760. MapiMessage message;
  180761. zerostruct (message);
  180762. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180763. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180764. MapiRecipDesc recip;
  180765. zerostruct (recip);
  180766. recip.ulRecipClass = MAPI_TO;
  180767. String targetEmailAddress_ (targetEmailAddress);
  180768. if (targetEmailAddress_.isEmpty())
  180769. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180770. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180771. message.nRecipCount = 1;
  180772. message.lpRecips = &recip;
  180773. HeapBlock <MapiFileDesc> files;
  180774. files.calloc (filesToAttach.size());
  180775. message.nFileCount = filesToAttach.size();
  180776. message.lpFiles = files;
  180777. for (int i = 0; i < filesToAttach.size(); ++i)
  180778. {
  180779. files[i].nPosition = (ULONG) -1;
  180780. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180781. }
  180782. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180783. }
  180784. FreeLibrary (h);
  180785. return ok;
  180786. }
  180787. #endif
  180788. /*** End of inlined file: juce_win32_Network.cpp ***/
  180789. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180790. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180791. // compiled on its own).
  180792. #if JUCE_INCLUDED_FILE
  180793. static HKEY findKeyForPath (String name,
  180794. const bool createForWriting,
  180795. String& valueName)
  180796. {
  180797. HKEY rootKey = 0;
  180798. if (name.startsWithIgnoreCase ("HKEY_CURRENT_USER\\"))
  180799. rootKey = HKEY_CURRENT_USER;
  180800. else if (name.startsWithIgnoreCase ("HKEY_LOCAL_MACHINE\\"))
  180801. rootKey = HKEY_LOCAL_MACHINE;
  180802. else if (name.startsWithIgnoreCase ("HKEY_CLASSES_ROOT\\"))
  180803. rootKey = HKEY_CLASSES_ROOT;
  180804. if (rootKey != 0)
  180805. {
  180806. name = name.substring (name.indexOfChar ('\\') + 1);
  180807. const int lastSlash = name.lastIndexOfChar ('\\');
  180808. valueName = name.substring (lastSlash + 1);
  180809. name = name.substring (0, lastSlash);
  180810. HKEY key;
  180811. DWORD result;
  180812. if (createForWriting)
  180813. {
  180814. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180815. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180816. return key;
  180817. }
  180818. else
  180819. {
  180820. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180821. return key;
  180822. }
  180823. }
  180824. return 0;
  180825. }
  180826. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180827. const String& defaultValue)
  180828. {
  180829. String valueName, result (defaultValue);
  180830. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180831. if (k != 0)
  180832. {
  180833. WCHAR buffer [2048];
  180834. unsigned long bufferSize = sizeof (buffer);
  180835. DWORD type = REG_SZ;
  180836. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180837. {
  180838. if (type == REG_SZ)
  180839. result = buffer;
  180840. else if (type == REG_DWORD)
  180841. result = String ((int) *(DWORD*) buffer);
  180842. }
  180843. RegCloseKey (k);
  180844. }
  180845. return result;
  180846. }
  180847. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180848. const String& value)
  180849. {
  180850. String valueName;
  180851. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180852. if (k != 0)
  180853. {
  180854. RegSetValueEx (k, valueName, 0, REG_SZ,
  180855. (const BYTE*) (const WCHAR*) value,
  180856. sizeof (WCHAR) * (value.length() + 1));
  180857. RegCloseKey (k);
  180858. }
  180859. }
  180860. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180861. {
  180862. bool exists = false;
  180863. String valueName;
  180864. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180865. if (k != 0)
  180866. {
  180867. unsigned char buffer [2048];
  180868. unsigned long bufferSize = sizeof (buffer);
  180869. DWORD type = 0;
  180870. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180871. exists = true;
  180872. RegCloseKey (k);
  180873. }
  180874. return exists;
  180875. }
  180876. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180877. {
  180878. String valueName;
  180879. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180880. if (k != 0)
  180881. {
  180882. RegDeleteValue (k, valueName);
  180883. RegCloseKey (k);
  180884. }
  180885. }
  180886. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180887. {
  180888. String valueName;
  180889. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180890. if (k != 0)
  180891. {
  180892. RegDeleteKey (k, valueName);
  180893. RegCloseKey (k);
  180894. }
  180895. }
  180896. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  180897. const String& symbolicDescription,
  180898. const String& fullDescription,
  180899. const File& targetExecutable,
  180900. int iconResourceNumber)
  180901. {
  180902. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  180903. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  180904. if (iconResourceNumber != 0)
  180905. setRegistryValue (key + "\\DefaultIcon\\",
  180906. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  180907. setRegistryValue (key + "\\", fullDescription);
  180908. setRegistryValue (key + "\\shell\\open\\command\\",
  180909. targetExecutable.getFullPathName() + " %1");
  180910. }
  180911. bool juce_IsRunningInWine()
  180912. {
  180913. HKEY key;
  180914. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  180915. {
  180916. RegCloseKey (key);
  180917. return true;
  180918. }
  180919. return false;
  180920. }
  180921. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  180922. {
  180923. String s (::GetCommandLineW());
  180924. StringArray tokens;
  180925. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  180926. return tokens.joinIntoString (" ", 1);
  180927. }
  180928. static void* currentModuleHandle = 0;
  180929. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  180930. {
  180931. if (currentModuleHandle == 0)
  180932. currentModuleHandle = GetModuleHandle (0);
  180933. return currentModuleHandle;
  180934. }
  180935. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  180936. {
  180937. currentModuleHandle = newHandle;
  180938. }
  180939. void PlatformUtilities::fpuReset()
  180940. {
  180941. #if JUCE_MSVC
  180942. _clearfp();
  180943. #endif
  180944. }
  180945. void PlatformUtilities::beep()
  180946. {
  180947. MessageBeep (MB_OK);
  180948. }
  180949. #endif
  180950. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  180951. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180952. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  180953. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180954. // compiled on its own).
  180955. #if JUCE_INCLUDED_FILE
  180956. static const unsigned int specialId = WM_APP + 0x4400;
  180957. static const unsigned int broadcastId = WM_APP + 0x4403;
  180958. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  180959. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  180960. HWND juce_messageWindowHandle = 0;
  180961. extern long improbableWindowNumber; // defined in windowing.cpp
  180962. #ifndef WM_APPCOMMAND
  180963. #define WM_APPCOMMAND 0x0319
  180964. #endif
  180965. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  180966. const UINT message,
  180967. const WPARAM wParam,
  180968. const LPARAM lParam) throw()
  180969. {
  180970. JUCE_TRY
  180971. {
  180972. if (h == juce_messageWindowHandle)
  180973. {
  180974. if (message == specialCallbackId)
  180975. {
  180976. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  180977. return (LRESULT) (*func) ((void*) lParam);
  180978. }
  180979. else if (message == specialId)
  180980. {
  180981. // these are trapped early in the dispatch call, but must also be checked
  180982. // here in case there are windows modal dialog boxes doing their own
  180983. // dispatch loop and not calling our version
  180984. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  180985. return 0;
  180986. }
  180987. else if (message == broadcastId)
  180988. {
  180989. const ScopedPointer <String> messageString ((String*) lParam);
  180990. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  180991. return 0;
  180992. }
  180993. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  180994. {
  180995. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  180996. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  180997. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  180998. return 0;
  180999. }
  181000. }
  181001. }
  181002. JUCE_CATCH_EXCEPTION
  181003. return DefWindowProc (h, message, wParam, lParam);
  181004. }
  181005. static bool isEventBlockedByModalComps (MSG& m)
  181006. {
  181007. if (Component::getNumCurrentlyModalComponents() == 0
  181008. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181009. return false;
  181010. switch (m.message)
  181011. {
  181012. case WM_MOUSEMOVE:
  181013. case WM_NCMOUSEMOVE:
  181014. case 0x020A: /* WM_MOUSEWHEEL */
  181015. case 0x020E: /* WM_MOUSEHWHEEL */
  181016. case WM_KEYUP:
  181017. case WM_SYSKEYUP:
  181018. case WM_CHAR:
  181019. case WM_APPCOMMAND:
  181020. case WM_LBUTTONUP:
  181021. case WM_MBUTTONUP:
  181022. case WM_RBUTTONUP:
  181023. case WM_MOUSEACTIVATE:
  181024. case WM_NCMOUSEHOVER:
  181025. case WM_MOUSEHOVER:
  181026. return true;
  181027. case WM_NCLBUTTONDOWN:
  181028. case WM_NCLBUTTONDBLCLK:
  181029. case WM_NCRBUTTONDOWN:
  181030. case WM_NCRBUTTONDBLCLK:
  181031. case WM_NCMBUTTONDOWN:
  181032. case WM_NCMBUTTONDBLCLK:
  181033. case WM_LBUTTONDOWN:
  181034. case WM_LBUTTONDBLCLK:
  181035. case WM_MBUTTONDOWN:
  181036. case WM_MBUTTONDBLCLK:
  181037. case WM_RBUTTONDOWN:
  181038. case WM_RBUTTONDBLCLK:
  181039. case WM_KEYDOWN:
  181040. case WM_SYSKEYDOWN:
  181041. {
  181042. Component* const modal = Component::getCurrentlyModalComponent (0);
  181043. if (modal != 0)
  181044. modal->inputAttemptWhenModal();
  181045. return true;
  181046. }
  181047. default:
  181048. break;
  181049. }
  181050. return false;
  181051. }
  181052. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181053. {
  181054. MSG m;
  181055. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181056. return false;
  181057. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181058. {
  181059. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181060. {
  181061. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181062. }
  181063. else if (m.message == WM_QUIT)
  181064. {
  181065. if (JUCEApplication::getInstance())
  181066. JUCEApplication::getInstance()->systemRequestedQuit();
  181067. }
  181068. else if (! isEventBlockedByModalComps (m))
  181069. {
  181070. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181071. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181072. {
  181073. // if it's someone else's window being clicked on, and the focus is
  181074. // currently on a juce window, pass the kb focus over..
  181075. HWND currentFocus = GetFocus();
  181076. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181077. SetFocus (m.hwnd);
  181078. }
  181079. TranslateMessage (&m);
  181080. DispatchMessage (&m);
  181081. }
  181082. }
  181083. return true;
  181084. }
  181085. bool juce_postMessageToSystemQueue (void* message)
  181086. {
  181087. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181088. }
  181089. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181090. void* userData)
  181091. {
  181092. if (MessageManager::getInstance()->isThisTheMessageThread())
  181093. {
  181094. return (*callback) (userData);
  181095. }
  181096. else
  181097. {
  181098. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181099. // deadlock because the message manager is blocked from running, and can't
  181100. // call your function..
  181101. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181102. return (void*) SendMessage (juce_messageWindowHandle,
  181103. specialCallbackId,
  181104. (WPARAM) callback,
  181105. (LPARAM) userData);
  181106. }
  181107. }
  181108. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181109. {
  181110. if (hwnd != juce_messageWindowHandle)
  181111. reinterpret_cast <VoidArray*> (lParam)->add ((void*) hwnd);
  181112. return TRUE;
  181113. }
  181114. void MessageManager::broadcastMessage (const String& value) throw()
  181115. {
  181116. VoidArray windows;
  181117. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181118. const String localCopy (value);
  181119. COPYDATASTRUCT data;
  181120. data.dwData = broadcastId;
  181121. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181122. data.lpData = (void*) static_cast <const juce_wchar*> (localCopy);
  181123. for (int i = windows.size(); --i >= 0;)
  181124. {
  181125. HWND hwnd = (HWND) windows.getUnchecked(i);
  181126. TCHAR windowName [64]; // no need to read longer strings than this
  181127. GetWindowText (hwnd, windowName, 64);
  181128. windowName [63] = 0;
  181129. if (String (windowName) == String (messageWindowName))
  181130. {
  181131. DWORD_PTR result;
  181132. SendMessageTimeout (hwnd, WM_COPYDATA,
  181133. (WPARAM) juce_messageWindowHandle,
  181134. (LPARAM) &data,
  181135. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181136. 8000,
  181137. &result);
  181138. }
  181139. }
  181140. }
  181141. static const String getMessageWindowClassName()
  181142. {
  181143. // this name has to be different for each app/dll instance because otherwise
  181144. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181145. // window class).
  181146. static int number = 0;
  181147. if (number == 0)
  181148. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181149. return "JUCEcs_" + String (number);
  181150. }
  181151. void MessageManager::doPlatformSpecificInitialisation()
  181152. {
  181153. OleInitialize (0);
  181154. const String className (getMessageWindowClassName());
  181155. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181156. WNDCLASSEX wc;
  181157. zerostruct (wc);
  181158. wc.cbSize = sizeof (wc);
  181159. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181160. wc.cbWndExtra = 4;
  181161. wc.hInstance = hmod;
  181162. wc.lpszClassName = className;
  181163. RegisterClassEx (&wc);
  181164. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181165. messageWindowName,
  181166. 0, 0, 0, 0, 0, 0, 0,
  181167. hmod, 0);
  181168. }
  181169. void MessageManager::doPlatformSpecificShutdown()
  181170. {
  181171. DestroyWindow (juce_messageWindowHandle);
  181172. UnregisterClass (getMessageWindowClassName(), 0);
  181173. OleUninitialize();
  181174. }
  181175. #endif
  181176. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181177. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181178. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181179. // compiled on its own).
  181180. #if JUCE_INCLUDED_FILE
  181181. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181182. // these are in the windows SDK, but need to be repeated here for GCC..
  181183. #ifndef GET_APPCOMMAND_LPARAM
  181184. #define FAPPCOMMAND_MASK 0xF000
  181185. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181186. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181187. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181188. #define APPCOMMAND_MEDIA_STOP 13
  181189. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181190. #define WM_APPCOMMAND 0x0319
  181191. #endif
  181192. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181193. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181194. extern bool juce_IsRunningInWine();
  181195. #ifndef ULW_ALPHA
  181196. #define ULW_ALPHA 0x00000002
  181197. #endif
  181198. #ifndef AC_SRC_ALPHA
  181199. #define AC_SRC_ALPHA 0x01
  181200. #endif
  181201. static HPALETTE palette = 0;
  181202. static bool createPaletteIfNeeded = true;
  181203. static bool shouldDeactivateTitleBar = true;
  181204. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181205. #define WM_TRAYNOTIFY WM_USER + 100
  181206. using ::abs;
  181207. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181208. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181209. bool Desktop::canUseSemiTransparentWindows() throw()
  181210. {
  181211. if (updateLayeredWindow == 0)
  181212. {
  181213. if (! juce_IsRunningInWine())
  181214. {
  181215. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181216. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181217. }
  181218. }
  181219. return updateLayeredWindow != 0;
  181220. }
  181221. const int extendedKeyModifier = 0x10000;
  181222. const int KeyPress::spaceKey = VK_SPACE;
  181223. const int KeyPress::returnKey = VK_RETURN;
  181224. const int KeyPress::escapeKey = VK_ESCAPE;
  181225. const int KeyPress::backspaceKey = VK_BACK;
  181226. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181227. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181228. const int KeyPress::tabKey = VK_TAB;
  181229. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181230. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181231. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181232. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181233. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181234. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181235. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181236. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181237. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181238. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181239. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181240. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181241. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181242. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181243. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181244. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181245. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181246. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181247. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181248. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181249. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181250. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181251. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181252. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181253. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181254. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181255. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181256. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181257. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181258. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181259. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181260. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181261. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181262. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181263. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181264. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181265. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181266. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181267. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181268. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181269. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181270. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181271. const int KeyPress::playKey = 0x30000;
  181272. const int KeyPress::stopKey = 0x30001;
  181273. const int KeyPress::fastForwardKey = 0x30002;
  181274. const int KeyPress::rewindKey = 0x30003;
  181275. class WindowsBitmapImage : public Image
  181276. {
  181277. public:
  181278. HBITMAP hBitmap;
  181279. BITMAPV4HEADER bitmapInfo;
  181280. HDC hdc;
  181281. unsigned char* bitmapData;
  181282. WindowsBitmapImage (const PixelFormat format_,
  181283. const int w, const int h, const bool clearImage)
  181284. : Image (format_, w, h)
  181285. {
  181286. jassert (format_ == RGB || format_ == ARGB);
  181287. pixelStride = (format_ == RGB) ? 3 : 4;
  181288. zerostruct (bitmapInfo);
  181289. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181290. bitmapInfo.bV4Width = w;
  181291. bitmapInfo.bV4Height = h;
  181292. bitmapInfo.bV4Planes = 1;
  181293. bitmapInfo.bV4CSType = 1;
  181294. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181295. if (format_ == ARGB)
  181296. {
  181297. bitmapInfo.bV4AlphaMask = 0xff000000;
  181298. bitmapInfo.bV4RedMask = 0xff0000;
  181299. bitmapInfo.bV4GreenMask = 0xff00;
  181300. bitmapInfo.bV4BlueMask = 0xff;
  181301. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181302. }
  181303. else
  181304. {
  181305. bitmapInfo.bV4V4Compression = BI_RGB;
  181306. }
  181307. lineStride = -((w * pixelStride + 3) & ~3);
  181308. HDC dc = GetDC (0);
  181309. hdc = CreateCompatibleDC (dc);
  181310. ReleaseDC (0, dc);
  181311. SetMapMode (hdc, MM_TEXT);
  181312. hBitmap = CreateDIBSection (hdc,
  181313. (BITMAPINFO*) &(bitmapInfo),
  181314. DIB_RGB_COLORS,
  181315. (void**) &bitmapData,
  181316. 0, 0);
  181317. SelectObject (hdc, hBitmap);
  181318. if (format_ == ARGB && clearImage)
  181319. zeromem (bitmapData, abs (h * lineStride));
  181320. imageData = bitmapData - (lineStride * (h - 1));
  181321. }
  181322. ~WindowsBitmapImage()
  181323. {
  181324. DeleteDC (hdc);
  181325. DeleteObject (hBitmap);
  181326. }
  181327. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181328. const int x, const int y,
  181329. const RectangleList& maskedRegion) throw()
  181330. {
  181331. static HDRAWDIB hdd = 0;
  181332. static bool needToCreateDrawDib = true;
  181333. if (needToCreateDrawDib)
  181334. {
  181335. needToCreateDrawDib = false;
  181336. HDC dc = GetDC (0);
  181337. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181338. ReleaseDC (0, dc);
  181339. // only open if we're not palettised
  181340. if (n > 8)
  181341. hdd = DrawDibOpen();
  181342. }
  181343. if (createPaletteIfNeeded)
  181344. {
  181345. HDC dc = GetDC (0);
  181346. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181347. ReleaseDC (0, dc);
  181348. if (n <= 8)
  181349. palette = CreateHalftonePalette (dc);
  181350. createPaletteIfNeeded = false;
  181351. }
  181352. if (palette != 0)
  181353. {
  181354. SelectPalette (dc, palette, FALSE);
  181355. RealizePalette (dc);
  181356. SetStretchBltMode (dc, HALFTONE);
  181357. }
  181358. SetMapMode (dc, MM_TEXT);
  181359. if (transparent)
  181360. {
  181361. POINT p, pos;
  181362. SIZE size;
  181363. RECT windowBounds;
  181364. GetWindowRect (hwnd, &windowBounds);
  181365. p.x = -x;
  181366. p.y = -y;
  181367. pos.x = windowBounds.left;
  181368. pos.y = windowBounds.top;
  181369. size.cx = windowBounds.right - windowBounds.left;
  181370. size.cy = windowBounds.bottom - windowBounds.top;
  181371. BLENDFUNCTION bf;
  181372. bf.AlphaFormat = AC_SRC_ALPHA;
  181373. bf.BlendFlags = 0;
  181374. bf.BlendOp = AC_SRC_OVER;
  181375. bf.SourceConstantAlpha = 0xff;
  181376. if (! maskedRegion.isEmpty())
  181377. {
  181378. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181379. {
  181380. const Rectangle<int>& r = *i.getRectangle();
  181381. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181382. }
  181383. }
  181384. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181385. }
  181386. else
  181387. {
  181388. int savedDC = 0;
  181389. if (! maskedRegion.isEmpty())
  181390. {
  181391. savedDC = SaveDC (dc);
  181392. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181393. {
  181394. const Rectangle<int>& r = *i.getRectangle();
  181395. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181396. }
  181397. }
  181398. const int w = getWidth();
  181399. const int h = getHeight();
  181400. if (hdd == 0)
  181401. {
  181402. StretchDIBits (dc,
  181403. x, y, w, h,
  181404. 0, 0, w, h,
  181405. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181406. DIB_RGB_COLORS, SRCCOPY);
  181407. }
  181408. else
  181409. {
  181410. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181411. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181412. 0, 0, w, h, 0);
  181413. }
  181414. if (! maskedRegion.isEmpty())
  181415. RestoreDC (dc, savedDC);
  181416. }
  181417. }
  181418. juce_UseDebuggingNewOperator
  181419. private:
  181420. WindowsBitmapImage (const WindowsBitmapImage&);
  181421. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181422. };
  181423. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181424. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  181425. {
  181426. SHORT k = (SHORT) keyCode;
  181427. if ((keyCode & extendedKeyModifier) == 0
  181428. && (k >= (SHORT) 'a' && k <= (SHORT) 'z'))
  181429. k += (SHORT) 'A' - (SHORT) 'a';
  181430. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181431. (SHORT) '+', VK_OEM_PLUS,
  181432. (SHORT) '-', VK_OEM_MINUS,
  181433. (SHORT) '.', VK_OEM_PERIOD,
  181434. (SHORT) ';', VK_OEM_1,
  181435. (SHORT) ':', VK_OEM_1,
  181436. (SHORT) '/', VK_OEM_2,
  181437. (SHORT) '?', VK_OEM_2,
  181438. (SHORT) '[', VK_OEM_4,
  181439. (SHORT) ']', VK_OEM_6 };
  181440. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181441. if (k == translatedValues [i])
  181442. k = translatedValues [i + 1];
  181443. return (GetKeyState (k) & 0x8000) != 0;
  181444. }
  181445. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181446. {
  181447. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181448. return callback (userData);
  181449. else
  181450. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181451. }
  181452. class Win32ComponentPeer : public ComponentPeer
  181453. {
  181454. public:
  181455. Win32ComponentPeer (Component* const component,
  181456. const int windowStyleFlags)
  181457. : ComponentPeer (component, windowStyleFlags),
  181458. dontRepaint (false),
  181459. fullScreen (false),
  181460. isDragging (false),
  181461. isMouseOver (false),
  181462. hasCreatedCaret (false),
  181463. currentWindowIcon (0),
  181464. taskBarIcon (0),
  181465. dropTarget (0)
  181466. {
  181467. callFunctionIfNotLocked (&createWindowCallback, this);
  181468. setTitle (component->getName());
  181469. if ((windowStyleFlags & windowHasDropShadow) != 0
  181470. && Desktop::canUseSemiTransparentWindows())
  181471. {
  181472. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181473. if (shadower != 0)
  181474. shadower->setOwner (component);
  181475. }
  181476. else
  181477. {
  181478. shadower = 0;
  181479. }
  181480. }
  181481. ~Win32ComponentPeer()
  181482. {
  181483. setTaskBarIcon (0);
  181484. deleteAndZero (shadower);
  181485. // do this before the next bit to avoid messages arriving for this window
  181486. // before it's destroyed
  181487. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181488. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181489. if (currentWindowIcon != 0)
  181490. DestroyIcon (currentWindowIcon);
  181491. if (dropTarget != 0)
  181492. {
  181493. dropTarget->Release();
  181494. dropTarget = 0;
  181495. }
  181496. }
  181497. void* getNativeHandle() const
  181498. {
  181499. return hwnd;
  181500. }
  181501. void setVisible (bool shouldBeVisible)
  181502. {
  181503. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181504. if (shouldBeVisible)
  181505. InvalidateRect (hwnd, 0, 0);
  181506. else
  181507. lastPaintTime = 0;
  181508. }
  181509. void setTitle (const String& title)
  181510. {
  181511. SetWindowText (hwnd, title);
  181512. }
  181513. void setPosition (int x, int y)
  181514. {
  181515. offsetWithinParent (x, y);
  181516. SetWindowPos (hwnd, 0,
  181517. x - windowBorder.getLeft(),
  181518. y - windowBorder.getTop(),
  181519. 0, 0,
  181520. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181521. }
  181522. void repaintNowIfTransparent()
  181523. {
  181524. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181525. handlePaintMessage();
  181526. }
  181527. void updateBorderSize()
  181528. {
  181529. WINDOWINFO info;
  181530. info.cbSize = sizeof (info);
  181531. if (GetWindowInfo (hwnd, &info))
  181532. {
  181533. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181534. info.rcClient.left - info.rcWindow.left,
  181535. info.rcWindow.bottom - info.rcClient.bottom,
  181536. info.rcWindow.right - info.rcClient.right);
  181537. }
  181538. }
  181539. void setSize (int w, int h)
  181540. {
  181541. SetWindowPos (hwnd, 0, 0, 0,
  181542. w + windowBorder.getLeftAndRight(),
  181543. h + windowBorder.getTopAndBottom(),
  181544. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181545. updateBorderSize();
  181546. repaintNowIfTransparent();
  181547. }
  181548. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  181549. {
  181550. fullScreen = isNowFullScreen;
  181551. offsetWithinParent (x, y);
  181552. SetWindowPos (hwnd, 0,
  181553. x - windowBorder.getLeft(),
  181554. y - windowBorder.getTop(),
  181555. w + windowBorder.getLeftAndRight(),
  181556. h + windowBorder.getTopAndBottom(),
  181557. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181558. updateBorderSize();
  181559. repaintNowIfTransparent();
  181560. }
  181561. const Rectangle<int> getBounds() const
  181562. {
  181563. RECT r;
  181564. GetWindowRect (hwnd, &r);
  181565. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181566. HWND parentH = GetParent (hwnd);
  181567. if (parentH != 0)
  181568. {
  181569. GetWindowRect (parentH, &r);
  181570. bounds.translate (-r.left, -r.top);
  181571. }
  181572. return windowBorder.subtractedFrom (bounds);
  181573. }
  181574. const Point<int> getScreenPosition() const
  181575. {
  181576. RECT r;
  181577. GetWindowRect (hwnd, &r);
  181578. return Point<int> (r.left + windowBorder.getLeft(),
  181579. r.top + windowBorder.getTop());
  181580. }
  181581. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181582. {
  181583. return relativePosition + getScreenPosition();
  181584. }
  181585. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181586. {
  181587. return screenPosition - getScreenPosition();
  181588. }
  181589. void setMinimised (bool shouldBeMinimised)
  181590. {
  181591. if (shouldBeMinimised != isMinimised())
  181592. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181593. }
  181594. bool isMinimised() const
  181595. {
  181596. WINDOWPLACEMENT wp;
  181597. wp.length = sizeof (WINDOWPLACEMENT);
  181598. GetWindowPlacement (hwnd, &wp);
  181599. return wp.showCmd == SW_SHOWMINIMIZED;
  181600. }
  181601. void setFullScreen (bool shouldBeFullScreen)
  181602. {
  181603. setMinimised (false);
  181604. if (fullScreen != shouldBeFullScreen)
  181605. {
  181606. fullScreen = shouldBeFullScreen;
  181607. const Component::SafePointer<Component> deletionChecker (component);
  181608. if (! fullScreen)
  181609. {
  181610. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181611. if (hasTitleBar())
  181612. ShowWindow (hwnd, SW_SHOWNORMAL);
  181613. if (! boundsCopy.isEmpty())
  181614. {
  181615. setBounds (boundsCopy.getX(),
  181616. boundsCopy.getY(),
  181617. boundsCopy.getWidth(),
  181618. boundsCopy.getHeight(),
  181619. false);
  181620. }
  181621. }
  181622. else
  181623. {
  181624. if (hasTitleBar())
  181625. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181626. else
  181627. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181628. }
  181629. if (deletionChecker != 0)
  181630. handleMovedOrResized();
  181631. }
  181632. }
  181633. bool isFullScreen() const
  181634. {
  181635. if (! hasTitleBar())
  181636. return fullScreen;
  181637. WINDOWPLACEMENT wp;
  181638. wp.length = sizeof (wp);
  181639. GetWindowPlacement (hwnd, &wp);
  181640. return wp.showCmd == SW_SHOWMAXIMIZED;
  181641. }
  181642. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181643. {
  181644. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181645. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181646. return false;
  181647. RECT r;
  181648. GetWindowRect (hwnd, &r);
  181649. POINT p;
  181650. p.x = position.getX() + r.left + windowBorder.getLeft();
  181651. p.y = position.getY() + r.top + windowBorder.getTop();
  181652. HWND w = WindowFromPoint (p);
  181653. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181654. }
  181655. const BorderSize getFrameSize() const
  181656. {
  181657. return windowBorder;
  181658. }
  181659. bool setAlwaysOnTop (bool alwaysOnTop)
  181660. {
  181661. const bool oldDeactivate = shouldDeactivateTitleBar;
  181662. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181663. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181664. 0, 0, 0, 0,
  181665. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181666. shouldDeactivateTitleBar = oldDeactivate;
  181667. if (shadower != 0)
  181668. shadower->componentBroughtToFront (*component);
  181669. return true;
  181670. }
  181671. void toFront (bool makeActive)
  181672. {
  181673. setMinimised (false);
  181674. const bool oldDeactivate = shouldDeactivateTitleBar;
  181675. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181676. callFunctionIfNotLocked (makeActive ? &toFrontCallback1 : &toFrontCallback2, hwnd);
  181677. shouldDeactivateTitleBar = oldDeactivate;
  181678. if (! makeActive)
  181679. {
  181680. // in this case a broughttofront call won't have occured, so do it now..
  181681. handleBroughtToFront();
  181682. }
  181683. }
  181684. void toBehind (ComponentPeer* other)
  181685. {
  181686. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181687. jassert (otherPeer != 0); // wrong type of window?
  181688. if (otherPeer != 0)
  181689. {
  181690. setMinimised (false);
  181691. // must be careful not to try to put a topmost window behind a normal one, or win32
  181692. // promotes the normal one to be topmost!
  181693. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181694. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181695. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181696. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181697. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181698. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181699. }
  181700. }
  181701. bool isFocused() const
  181702. {
  181703. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181704. }
  181705. void grabFocus()
  181706. {
  181707. const bool oldDeactivate = shouldDeactivateTitleBar;
  181708. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181709. callFunctionIfNotLocked (&setFocusCallback, hwnd);
  181710. shouldDeactivateTitleBar = oldDeactivate;
  181711. }
  181712. void textInputRequired (const Point<int>&)
  181713. {
  181714. if (! hasCreatedCaret)
  181715. {
  181716. hasCreatedCaret = true;
  181717. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181718. }
  181719. ShowCaret (hwnd);
  181720. SetCaretPos (0, 0);
  181721. }
  181722. void repaint (int x, int y, int w, int h)
  181723. {
  181724. const RECT r = { x, y, x + w, y + h };
  181725. InvalidateRect (hwnd, &r, FALSE);
  181726. }
  181727. void performAnyPendingRepaintsNow()
  181728. {
  181729. MSG m;
  181730. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181731. DispatchMessage (&m);
  181732. }
  181733. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181734. {
  181735. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181736. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181737. return 0;
  181738. }
  181739. void setTaskBarIcon (const Image* const image)
  181740. {
  181741. if (image != 0)
  181742. {
  181743. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181744. if (taskBarIcon == 0)
  181745. {
  181746. taskBarIcon = new NOTIFYICONDATA();
  181747. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181748. taskBarIcon->hWnd = (HWND) hwnd;
  181749. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181750. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181751. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181752. taskBarIcon->hIcon = hicon;
  181753. taskBarIcon->szTip[0] = 0;
  181754. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181755. }
  181756. else
  181757. {
  181758. HICON oldIcon = taskBarIcon->hIcon;
  181759. taskBarIcon->hIcon = hicon;
  181760. taskBarIcon->uFlags = NIF_ICON;
  181761. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181762. DestroyIcon (oldIcon);
  181763. }
  181764. DestroyIcon (hicon);
  181765. }
  181766. else if (taskBarIcon != 0)
  181767. {
  181768. taskBarIcon->uFlags = 0;
  181769. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181770. DestroyIcon (taskBarIcon->hIcon);
  181771. deleteAndZero (taskBarIcon);
  181772. }
  181773. }
  181774. void setTaskBarIconToolTip (const String& toolTip) const
  181775. {
  181776. if (taskBarIcon != 0)
  181777. {
  181778. taskBarIcon->uFlags = NIF_TIP;
  181779. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181780. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181781. }
  181782. }
  181783. bool isInside (HWND h) const
  181784. {
  181785. return GetAncestor (hwnd, GA_ROOT) == h;
  181786. }
  181787. static void updateKeyModifiers() throw()
  181788. {
  181789. int keyMods = 0;
  181790. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181791. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181792. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181793. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181794. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181795. }
  181796. static void updateModifiersFromWParam (const WPARAM wParam)
  181797. {
  181798. int mouseMods = 0;
  181799. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181800. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181801. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181802. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181803. updateKeyModifiers();
  181804. }
  181805. static int64 getMouseEventTime()
  181806. {
  181807. static int64 eventTimeOffset = 0;
  181808. static DWORD lastMessageTime = 0;
  181809. const DWORD thisMessageTime = GetMessageTime();
  181810. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181811. {
  181812. lastMessageTime = thisMessageTime;
  181813. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181814. }
  181815. return eventTimeOffset + thisMessageTime;
  181816. }
  181817. juce_UseDebuggingNewOperator
  181818. bool dontRepaint;
  181819. static ModifierKeys currentModifiers;
  181820. static ModifierKeys modifiersAtLastCallback;
  181821. private:
  181822. HWND hwnd;
  181823. DropShadower* shadower;
  181824. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181825. BorderSize windowBorder;
  181826. HICON currentWindowIcon;
  181827. NOTIFYICONDATA* taskBarIcon;
  181828. IDropTarget* dropTarget;
  181829. class TemporaryImage : public Timer
  181830. {
  181831. public:
  181832. TemporaryImage()
  181833. : image (0)
  181834. {
  181835. }
  181836. ~TemporaryImage()
  181837. {
  181838. delete image;
  181839. }
  181840. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181841. {
  181842. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181843. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181844. {
  181845. delete image;
  181846. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181847. }
  181848. startTimer (3000);
  181849. return image;
  181850. }
  181851. void timerCallback()
  181852. {
  181853. stopTimer();
  181854. deleteAndZero (image);
  181855. }
  181856. private:
  181857. WindowsBitmapImage* image;
  181858. TemporaryImage (const TemporaryImage&);
  181859. TemporaryImage& operator= (const TemporaryImage&);
  181860. };
  181861. TemporaryImage offscreenImageGenerator;
  181862. class WindowClassHolder : public DeletedAtShutdown
  181863. {
  181864. public:
  181865. WindowClassHolder()
  181866. : windowClassName ("JUCE_")
  181867. {
  181868. // this name has to be different for each app/dll instance because otherwise
  181869. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181870. // window class).
  181871. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181872. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181873. TCHAR moduleFile [1024];
  181874. moduleFile[0] = 0;
  181875. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181876. WORD iconNum = 0;
  181877. WNDCLASSEX wcex;
  181878. wcex.cbSize = sizeof (wcex);
  181879. wcex.style = CS_OWNDC;
  181880. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181881. wcex.lpszClassName = windowClassName;
  181882. wcex.cbClsExtra = 0;
  181883. wcex.cbWndExtra = 32;
  181884. wcex.hInstance = moduleHandle;
  181885. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181886. iconNum = 1;
  181887. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181888. wcex.hCursor = 0;
  181889. wcex.hbrBackground = 0;
  181890. wcex.lpszMenuName = 0;
  181891. RegisterClassEx (&wcex);
  181892. }
  181893. ~WindowClassHolder()
  181894. {
  181895. if (ComponentPeer::getNumPeers() == 0)
  181896. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  181897. clearSingletonInstance();
  181898. }
  181899. String windowClassName;
  181900. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  181901. };
  181902. static void* createWindowCallback (void* userData)
  181903. {
  181904. static_cast <Win32ComponentPeer*> (userData)->createWindow();
  181905. return 0;
  181906. }
  181907. void createWindow()
  181908. {
  181909. DWORD exstyle = WS_EX_ACCEPTFILES;
  181910. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  181911. if (hasTitleBar())
  181912. {
  181913. type |= WS_OVERLAPPED;
  181914. exstyle |= WS_EX_APPWINDOW;
  181915. if ((styleFlags & windowHasCloseButton) != 0)
  181916. {
  181917. type |= WS_SYSMENU;
  181918. }
  181919. else
  181920. {
  181921. // annoyingly, windows won't let you have a min/max button without a close button
  181922. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  181923. }
  181924. if ((styleFlags & windowIsResizable) != 0)
  181925. type |= WS_THICKFRAME;
  181926. }
  181927. else
  181928. {
  181929. type |= WS_POPUP | WS_SYSMENU;
  181930. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  181931. exstyle |= WS_EX_TOOLWINDOW;
  181932. else
  181933. exstyle |= WS_EX_APPWINDOW;
  181934. }
  181935. if ((styleFlags & windowHasMinimiseButton) != 0)
  181936. type |= WS_MINIMIZEBOX;
  181937. if ((styleFlags & windowHasMaximiseButton) != 0)
  181938. type |= WS_MAXIMIZEBOX;
  181939. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  181940. exstyle |= WS_EX_TRANSPARENT;
  181941. if ((styleFlags & windowIsSemiTransparent) != 0
  181942. && Desktop::canUseSemiTransparentWindows())
  181943. exstyle |= WS_EX_LAYERED;
  181944. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  181945. if (hwnd != 0)
  181946. {
  181947. SetWindowLongPtr (hwnd, 0, 0);
  181948. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  181949. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  181950. if (dropTarget == 0)
  181951. dropTarget = new JuceDropTarget (this);
  181952. RegisterDragDrop (hwnd, dropTarget);
  181953. updateBorderSize();
  181954. // Calling this function here is (for some reason) necessary to make Windows
  181955. // correctly enable the menu items that we specify in the wm_initmenu message.
  181956. GetSystemMenu (hwnd, false);
  181957. }
  181958. else
  181959. {
  181960. jassertfalse
  181961. }
  181962. }
  181963. static void* destroyWindowCallback (void* handle)
  181964. {
  181965. RevokeDragDrop ((HWND) handle);
  181966. DestroyWindow ((HWND) handle);
  181967. return 0;
  181968. }
  181969. static void* toFrontCallback1 (void* h)
  181970. {
  181971. SetForegroundWindow ((HWND) h);
  181972. return 0;
  181973. }
  181974. static void* toFrontCallback2 (void* h)
  181975. {
  181976. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181977. return 0;
  181978. }
  181979. static void* setFocusCallback (void* h)
  181980. {
  181981. SetFocus ((HWND) h);
  181982. return 0;
  181983. }
  181984. static void* getFocusCallback (void*)
  181985. {
  181986. return GetFocus();
  181987. }
  181988. void offsetWithinParent (int& x, int& y) const
  181989. {
  181990. if (isTransparent())
  181991. {
  181992. HWND parentHwnd = GetParent (hwnd);
  181993. if (parentHwnd != 0)
  181994. {
  181995. RECT parentRect;
  181996. GetWindowRect (parentHwnd, &parentRect);
  181997. x += parentRect.left;
  181998. y += parentRect.top;
  181999. }
  182000. }
  182001. }
  182002. bool isTransparent() const
  182003. {
  182004. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182005. }
  182006. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182007. void setIcon (const Image& newIcon)
  182008. {
  182009. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182010. if (hicon != 0)
  182011. {
  182012. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182013. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182014. if (currentWindowIcon != 0)
  182015. DestroyIcon (currentWindowIcon);
  182016. currentWindowIcon = hicon;
  182017. }
  182018. }
  182019. void handlePaintMessage()
  182020. {
  182021. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182022. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182023. PAINTSTRUCT paintStruct;
  182024. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182025. // message and become re-entrant, but that's OK
  182026. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182027. // corrupt the image it's using to paint into, so do a check here.
  182028. static bool reentrant = false;
  182029. if (reentrant)
  182030. {
  182031. DeleteObject (rgn);
  182032. EndPaint (hwnd, &paintStruct);
  182033. return;
  182034. }
  182035. reentrant = true;
  182036. // this is the rectangle to update..
  182037. int x = paintStruct.rcPaint.left;
  182038. int y = paintStruct.rcPaint.top;
  182039. int w = paintStruct.rcPaint.right - x;
  182040. int h = paintStruct.rcPaint.bottom - y;
  182041. const bool transparent = isTransparent();
  182042. if (transparent)
  182043. {
  182044. // it's not possible to have a transparent window with a title bar at the moment!
  182045. jassert (! hasTitleBar());
  182046. RECT r;
  182047. GetWindowRect (hwnd, &r);
  182048. x = y = 0;
  182049. w = r.right - r.left;
  182050. h = r.bottom - r.top;
  182051. }
  182052. if (w > 0 && h > 0)
  182053. {
  182054. clearMaskedRegion();
  182055. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182056. RectangleList contextClip;
  182057. bool needToPaintAll = true;
  182058. if (regionType == COMPLEXREGION && ! transparent)
  182059. {
  182060. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182061. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182062. DeleteObject (clipRgn);
  182063. char rgnData [8192];
  182064. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182065. if (res > 0 && res <= sizeof (rgnData))
  182066. {
  182067. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182068. if (hdr->iType == RDH_RECTANGLES
  182069. && hdr->rcBound.right - hdr->rcBound.left >= w
  182070. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182071. {
  182072. needToPaintAll = false;
  182073. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182074. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182075. while (--num >= 0)
  182076. {
  182077. // (need to move this one pixel to the left because of a win32 bug)
  182078. const int cx = jmax (x, (int) rects->left - 1);
  182079. const int cy = rects->top;
  182080. const int cw = rects->right - cx;
  182081. const int ch = rects->bottom - rects->top;
  182082. if (cx + cw - x <= w && cy + ch - y <= h)
  182083. {
  182084. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182085. }
  182086. else
  182087. {
  182088. needToPaintAll = true;
  182089. break;
  182090. }
  182091. ++rects;
  182092. }
  182093. }
  182094. }
  182095. }
  182096. if (needToPaintAll)
  182097. {
  182098. contextClip.clear();
  182099. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182100. }
  182101. if (transparent)
  182102. {
  182103. RectangleList::Iterator i (contextClip);
  182104. while (i.next())
  182105. {
  182106. const Rectangle<int>& r = *i.getRectangle();
  182107. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182108. }
  182109. }
  182110. // if the component's not opaque, this won't draw properly unless the platform can support this
  182111. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182112. updateCurrentModifiers();
  182113. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182114. context.clipToRectangleList (contextClip);
  182115. context.setOrigin (-x, -y);
  182116. handlePaint (context);
  182117. if (! dontRepaint)
  182118. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182119. }
  182120. DeleteObject (rgn);
  182121. EndPaint (hwnd, &paintStruct);
  182122. reentrant = false;
  182123. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182124. _fpreset(); // because some graphics cards can unmask FP exceptions
  182125. #endif
  182126. lastPaintTime = Time::getMillisecondCounter();
  182127. }
  182128. void doMouseEvent (const Point<int>& position)
  182129. {
  182130. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182131. }
  182132. void doMouseMove (const Point<int>& position)
  182133. {
  182134. if (! isMouseOver)
  182135. {
  182136. isMouseOver = true;
  182137. updateKeyModifiers();
  182138. TRACKMOUSEEVENT tme;
  182139. tme.cbSize = sizeof (tme);
  182140. tme.dwFlags = TME_LEAVE;
  182141. tme.hwndTrack = hwnd;
  182142. tme.dwHoverTime = 0;
  182143. if (! TrackMouseEvent (&tme))
  182144. jassertfalse;
  182145. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182146. }
  182147. else if (! isDragging)
  182148. {
  182149. if (! contains (position, false))
  182150. return;
  182151. }
  182152. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182153. static uint32 lastMouseTime = 0;
  182154. const uint32 now = Time::getMillisecondCounter();
  182155. const int maxMouseMovesPerSecond = 60;
  182156. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182157. {
  182158. lastMouseTime = now;
  182159. doMouseEvent (position);
  182160. }
  182161. }
  182162. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182163. {
  182164. if (GetCapture() != hwnd)
  182165. SetCapture (hwnd);
  182166. doMouseMove (position);
  182167. updateModifiersFromWParam (wParam);
  182168. isDragging = true;
  182169. doMouseEvent (position);
  182170. }
  182171. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182172. {
  182173. updateModifiersFromWParam (wParam);
  182174. isDragging = false;
  182175. // release the mouse capture if the user has released all buttons
  182176. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182177. ReleaseCapture();
  182178. doMouseEvent (position);
  182179. }
  182180. void doCaptureChanged()
  182181. {
  182182. if (isDragging)
  182183. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182184. }
  182185. void doMouseExit()
  182186. {
  182187. isMouseOver = false;
  182188. doMouseEvent (getCurrentMousePos());
  182189. }
  182190. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182191. {
  182192. updateKeyModifiers();
  182193. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182194. handleMouseWheel (0, position, getMouseEventTime(),
  182195. isVertical ? 0.0f : amount,
  182196. isVertical ? amount : 0.0f);
  182197. }
  182198. void sendModifierKeyChangeIfNeeded()
  182199. {
  182200. if (modifiersAtLastCallback != currentModifiers)
  182201. {
  182202. modifiersAtLastCallback = currentModifiers;
  182203. handleModifierKeysChange();
  182204. }
  182205. }
  182206. bool doKeyUp (const WPARAM key)
  182207. {
  182208. updateKeyModifiers();
  182209. switch (key)
  182210. {
  182211. case VK_SHIFT:
  182212. case VK_CONTROL:
  182213. case VK_MENU:
  182214. case VK_CAPITAL:
  182215. case VK_LWIN:
  182216. case VK_RWIN:
  182217. case VK_APPS:
  182218. case VK_NUMLOCK:
  182219. case VK_SCROLL:
  182220. case VK_LSHIFT:
  182221. case VK_RSHIFT:
  182222. case VK_LCONTROL:
  182223. case VK_LMENU:
  182224. case VK_RCONTROL:
  182225. case VK_RMENU:
  182226. sendModifierKeyChangeIfNeeded();
  182227. }
  182228. return handleKeyUpOrDown (false)
  182229. || Component::getCurrentlyModalComponent() != 0;
  182230. }
  182231. bool doKeyDown (const WPARAM key)
  182232. {
  182233. updateKeyModifiers();
  182234. bool used = false;
  182235. switch (key)
  182236. {
  182237. case VK_SHIFT:
  182238. case VK_LSHIFT:
  182239. case VK_RSHIFT:
  182240. case VK_CONTROL:
  182241. case VK_LCONTROL:
  182242. case VK_RCONTROL:
  182243. case VK_MENU:
  182244. case VK_LMENU:
  182245. case VK_RMENU:
  182246. case VK_LWIN:
  182247. case VK_RWIN:
  182248. case VK_CAPITAL:
  182249. case VK_NUMLOCK:
  182250. case VK_SCROLL:
  182251. case VK_APPS:
  182252. sendModifierKeyChangeIfNeeded();
  182253. break;
  182254. case VK_LEFT:
  182255. case VK_RIGHT:
  182256. case VK_UP:
  182257. case VK_DOWN:
  182258. case VK_PRIOR:
  182259. case VK_NEXT:
  182260. case VK_HOME:
  182261. case VK_END:
  182262. case VK_DELETE:
  182263. case VK_INSERT:
  182264. case VK_F1:
  182265. case VK_F2:
  182266. case VK_F3:
  182267. case VK_F4:
  182268. case VK_F5:
  182269. case VK_F6:
  182270. case VK_F7:
  182271. case VK_F8:
  182272. case VK_F9:
  182273. case VK_F10:
  182274. case VK_F11:
  182275. case VK_F12:
  182276. case VK_F13:
  182277. case VK_F14:
  182278. case VK_F15:
  182279. case VK_F16:
  182280. used = handleKeyUpOrDown (true);
  182281. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182282. break;
  182283. case VK_ADD:
  182284. case VK_SUBTRACT:
  182285. case VK_MULTIPLY:
  182286. case VK_DIVIDE:
  182287. case VK_SEPARATOR:
  182288. case VK_DECIMAL:
  182289. used = handleKeyUpOrDown (true);
  182290. break;
  182291. default:
  182292. used = handleKeyUpOrDown (true);
  182293. {
  182294. MSG msg;
  182295. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182296. {
  182297. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182298. // manually generate the key-press event that matches this key-down.
  182299. const UINT keyChar = MapVirtualKey (key, 2);
  182300. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182301. }
  182302. }
  182303. break;
  182304. }
  182305. if (Component::getCurrentlyModalComponent() != 0)
  182306. used = true;
  182307. return used;
  182308. }
  182309. bool doKeyChar (int key, const LPARAM flags)
  182310. {
  182311. updateKeyModifiers();
  182312. juce_wchar textChar = (juce_wchar) key;
  182313. const int virtualScanCode = (flags >> 16) & 0xff;
  182314. if (key >= '0' && key <= '9')
  182315. {
  182316. switch (virtualScanCode) // check for a numeric keypad scan-code
  182317. {
  182318. case 0x52:
  182319. case 0x4f:
  182320. case 0x50:
  182321. case 0x51:
  182322. case 0x4b:
  182323. case 0x4c:
  182324. case 0x4d:
  182325. case 0x47:
  182326. case 0x48:
  182327. case 0x49:
  182328. key = (key - '0') + KeyPress::numberPad0;
  182329. break;
  182330. default:
  182331. break;
  182332. }
  182333. }
  182334. else
  182335. {
  182336. // convert the scan code to an unmodified character code..
  182337. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182338. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182339. keyChar = LOWORD (keyChar);
  182340. if (keyChar != 0)
  182341. key = (int) keyChar;
  182342. // avoid sending junk text characters for some control-key combinations
  182343. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182344. textChar = 0;
  182345. }
  182346. return handleKeyPress (key, textChar);
  182347. }
  182348. bool doAppCommand (const LPARAM lParam)
  182349. {
  182350. int key = 0;
  182351. switch (GET_APPCOMMAND_LPARAM (lParam))
  182352. {
  182353. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182354. key = KeyPress::playKey;
  182355. break;
  182356. case APPCOMMAND_MEDIA_STOP:
  182357. key = KeyPress::stopKey;
  182358. break;
  182359. case APPCOMMAND_MEDIA_NEXTTRACK:
  182360. key = KeyPress::fastForwardKey;
  182361. break;
  182362. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182363. key = KeyPress::rewindKey;
  182364. break;
  182365. }
  182366. if (key != 0)
  182367. {
  182368. updateKeyModifiers();
  182369. if (hwnd == GetActiveWindow())
  182370. {
  182371. handleKeyPress (key, 0);
  182372. return true;
  182373. }
  182374. }
  182375. return false;
  182376. }
  182377. class JuceDropTarget : public IDropTarget
  182378. {
  182379. public:
  182380. JuceDropTarget (Win32ComponentPeer* const owner_)
  182381. : owner (owner_),
  182382. refCount (1)
  182383. {
  182384. }
  182385. virtual ~JuceDropTarget()
  182386. {
  182387. jassert (refCount == 0);
  182388. }
  182389. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182390. {
  182391. if (id == IID_IUnknown || id == IID_IDropTarget)
  182392. {
  182393. AddRef();
  182394. *result = this;
  182395. return S_OK;
  182396. }
  182397. *result = 0;
  182398. return E_NOINTERFACE;
  182399. }
  182400. ULONG __stdcall AddRef() { return ++refCount; }
  182401. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182402. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182403. {
  182404. updateFileList (pDataObject);
  182405. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182406. *pdwEffect = DROPEFFECT_COPY;
  182407. return S_OK;
  182408. }
  182409. HRESULT __stdcall DragLeave()
  182410. {
  182411. owner->handleFileDragExit (files);
  182412. return S_OK;
  182413. }
  182414. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182415. {
  182416. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182417. *pdwEffect = DROPEFFECT_COPY;
  182418. return S_OK;
  182419. }
  182420. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182421. {
  182422. updateFileList (pDataObject);
  182423. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182424. *pdwEffect = DROPEFFECT_COPY;
  182425. return S_OK;
  182426. }
  182427. private:
  182428. Win32ComponentPeer* const owner;
  182429. int refCount;
  182430. StringArray files;
  182431. void updateFileList (IDataObject* const pDataObject)
  182432. {
  182433. files.clear();
  182434. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182435. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182436. if (pDataObject->GetData (&format, &medium) == S_OK)
  182437. {
  182438. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182439. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182440. unsigned int i = 0;
  182441. if (pDropFiles->fWide)
  182442. {
  182443. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182444. for (;;)
  182445. {
  182446. unsigned int len = 0;
  182447. while (i + len < totalLen && fname [i + len] != 0)
  182448. ++len;
  182449. if (len == 0)
  182450. break;
  182451. files.add (String (fname + i, len));
  182452. i += len + 1;
  182453. }
  182454. }
  182455. else
  182456. {
  182457. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182458. for (;;)
  182459. {
  182460. unsigned int len = 0;
  182461. while (i + len < totalLen && fname [i + len] != 0)
  182462. ++len;
  182463. if (len == 0)
  182464. break;
  182465. files.add (String (fname + i, len));
  182466. i += len + 1;
  182467. }
  182468. }
  182469. GlobalUnlock (medium.hGlobal);
  182470. }
  182471. }
  182472. JuceDropTarget (const JuceDropTarget&);
  182473. JuceDropTarget& operator= (const JuceDropTarget&);
  182474. };
  182475. void doSettingChange()
  182476. {
  182477. Desktop::getInstance().refreshMonitorSizes();
  182478. if (fullScreen && ! isMinimised())
  182479. {
  182480. const Rectangle<int> r (component->getParentMonitorArea());
  182481. SetWindowPos (hwnd, 0,
  182482. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182483. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182484. }
  182485. }
  182486. public:
  182487. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182488. {
  182489. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182490. if (peer != 0)
  182491. return peer->peerWindowProc (h, message, wParam, lParam);
  182492. return DefWindowProcW (h, message, wParam, lParam);
  182493. }
  182494. private:
  182495. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182496. {
  182497. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182498. }
  182499. const Point<int> getCurrentMousePos() throw()
  182500. {
  182501. RECT wr;
  182502. GetWindowRect (hwnd, &wr);
  182503. const DWORD mp = GetMessagePos();
  182504. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182505. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182506. }
  182507. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182508. {
  182509. if (isValidPeer (this))
  182510. {
  182511. switch (message)
  182512. {
  182513. case WM_NCHITTEST:
  182514. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182515. return HTTRANSPARENT;
  182516. if (hasTitleBar())
  182517. break;
  182518. return HTCLIENT;
  182519. case WM_PAINT:
  182520. handlePaintMessage();
  182521. return 0;
  182522. case WM_NCPAINT:
  182523. if (wParam != 1)
  182524. handlePaintMessage();
  182525. if (hasTitleBar())
  182526. break;
  182527. return 0;
  182528. case WM_ERASEBKGND:
  182529. case WM_NCCALCSIZE:
  182530. if (hasTitleBar())
  182531. break;
  182532. return 1;
  182533. case WM_MOUSEMOVE:
  182534. doMouseMove (getPointFromLParam (lParam));
  182535. return 0;
  182536. case WM_MOUSELEAVE:
  182537. doMouseExit();
  182538. return 0;
  182539. case WM_LBUTTONDOWN:
  182540. case WM_MBUTTONDOWN:
  182541. case WM_RBUTTONDOWN:
  182542. doMouseDown (getPointFromLParam (lParam), wParam);
  182543. return 0;
  182544. case WM_LBUTTONUP:
  182545. case WM_MBUTTONUP:
  182546. case WM_RBUTTONUP:
  182547. doMouseUp (getPointFromLParam (lParam), wParam);
  182548. return 0;
  182549. case WM_CAPTURECHANGED:
  182550. doCaptureChanged();
  182551. return 0;
  182552. case WM_NCMOUSEMOVE:
  182553. if (hasTitleBar())
  182554. break;
  182555. return 0;
  182556. case 0x020A: /* WM_MOUSEWHEEL */
  182557. doMouseWheel (getCurrentMousePos(), wParam, true);
  182558. return 0;
  182559. case 0x020E: /* WM_MOUSEHWHEEL */
  182560. doMouseWheel (getCurrentMousePos(), wParam, false);
  182561. return 0;
  182562. case WM_WINDOWPOSCHANGING:
  182563. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182564. {
  182565. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182566. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182567. {
  182568. if (constrainer != 0)
  182569. {
  182570. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182571. component->getY() - windowBorder.getTop(),
  182572. component->getWidth() + windowBorder.getLeftAndRight(),
  182573. component->getHeight() + windowBorder.getTopAndBottom());
  182574. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182575. constrainer->checkBounds (pos, current,
  182576. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182577. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182578. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182579. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182580. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182581. wp->x = pos.getX();
  182582. wp->y = pos.getY();
  182583. wp->cx = pos.getWidth();
  182584. wp->cy = pos.getHeight();
  182585. }
  182586. }
  182587. }
  182588. return 0;
  182589. case WM_WINDOWPOSCHANGED:
  182590. handleMovedOrResized();
  182591. if (dontRepaint)
  182592. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182593. return 0;
  182594. case WM_KEYDOWN:
  182595. case WM_SYSKEYDOWN:
  182596. if (doKeyDown (wParam))
  182597. return 0;
  182598. break;
  182599. case WM_KEYUP:
  182600. case WM_SYSKEYUP:
  182601. if (doKeyUp (wParam))
  182602. return 0;
  182603. break;
  182604. case WM_CHAR:
  182605. if (doKeyChar ((int) wParam, lParam))
  182606. return 0;
  182607. break;
  182608. case WM_APPCOMMAND:
  182609. if (doAppCommand (lParam))
  182610. return TRUE;
  182611. break;
  182612. case WM_SETFOCUS:
  182613. updateKeyModifiers();
  182614. handleFocusGain();
  182615. break;
  182616. case WM_KILLFOCUS:
  182617. if (hasCreatedCaret)
  182618. {
  182619. hasCreatedCaret = false;
  182620. DestroyCaret();
  182621. }
  182622. handleFocusLoss();
  182623. break;
  182624. case WM_ACTIVATEAPP:
  182625. // Windows does weird things to process priority when you swap apps,
  182626. // so this forces an update when the app is brought to the front
  182627. if (wParam != FALSE)
  182628. juce_repeatLastProcessPriority();
  182629. else
  182630. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182631. juce_CheckCurrentlyFocusedTopLevelWindow();
  182632. modifiersAtLastCallback = -1;
  182633. return 0;
  182634. case WM_ACTIVATE:
  182635. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182636. {
  182637. modifiersAtLastCallback = -1;
  182638. updateKeyModifiers();
  182639. if (isMinimised())
  182640. {
  182641. component->repaint();
  182642. handleMovedOrResized();
  182643. if (! ComponentPeer::isValidPeer (this))
  182644. return 0;
  182645. }
  182646. if (LOWORD (wParam) == WA_CLICKACTIVE
  182647. && component->isCurrentlyBlockedByAnotherModalComponent())
  182648. {
  182649. const Point<int> mousePos (component->getMouseXYRelative());
  182650. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182651. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182652. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182653. return 0;
  182654. }
  182655. handleBroughtToFront();
  182656. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182657. Component::getCurrentlyModalComponent()->toFront (true);
  182658. return 0;
  182659. }
  182660. break;
  182661. case WM_NCACTIVATE:
  182662. // while a temporary window is being shown, prevent Windows from deactivating the
  182663. // title bars of our main windows.
  182664. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182665. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182666. break;
  182667. case WM_MOUSEACTIVATE:
  182668. if (! component->getMouseClickGrabsKeyboardFocus())
  182669. return MA_NOACTIVATE;
  182670. break;
  182671. case WM_SHOWWINDOW:
  182672. if (wParam != 0)
  182673. handleBroughtToFront();
  182674. break;
  182675. case WM_CLOSE:
  182676. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182677. handleUserClosingWindow();
  182678. return 0;
  182679. case WM_QUERYENDSESSION:
  182680. if (JUCEApplication::getInstance() != 0)
  182681. {
  182682. JUCEApplication::getInstance()->systemRequestedQuit();
  182683. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182684. }
  182685. return TRUE;
  182686. case WM_TRAYNOTIFY:
  182687. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182688. {
  182689. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182690. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182691. {
  182692. Component* const current = Component::getCurrentlyModalComponent();
  182693. if (current != 0)
  182694. current->inputAttemptWhenModal();
  182695. }
  182696. }
  182697. else
  182698. {
  182699. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182700. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182701. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182702. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182703. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182704. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182705. eventMods = eventMods.withoutMouseButtons();
  182706. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182707. Point<int>(), eventMods, component, getMouseEventTime(),
  182708. Point<int>(), getMouseEventTime(), 1, false);
  182709. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182710. {
  182711. SetFocus (hwnd);
  182712. SetForegroundWindow (hwnd);
  182713. component->mouseDown (e);
  182714. }
  182715. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182716. {
  182717. component->mouseUp (e);
  182718. }
  182719. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182720. {
  182721. component->mouseDoubleClick (e);
  182722. }
  182723. else if (lParam == WM_MOUSEMOVE)
  182724. {
  182725. component->mouseMove (e);
  182726. }
  182727. }
  182728. break;
  182729. case WM_SYNCPAINT:
  182730. return 0;
  182731. case WM_PALETTECHANGED:
  182732. InvalidateRect (h, 0, 0);
  182733. break;
  182734. case WM_DISPLAYCHANGE:
  182735. InvalidateRect (h, 0, 0);
  182736. createPaletteIfNeeded = true;
  182737. // intentional fall-through...
  182738. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182739. doSettingChange();
  182740. break;
  182741. case WM_INITMENU:
  182742. if (! hasTitleBar())
  182743. {
  182744. if (isFullScreen())
  182745. {
  182746. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182747. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182748. }
  182749. else if (! isMinimised())
  182750. {
  182751. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182752. }
  182753. }
  182754. break;
  182755. case WM_SYSCOMMAND:
  182756. switch (wParam & 0xfff0)
  182757. {
  182758. case SC_CLOSE:
  182759. if (sendInputAttemptWhenModalMessage())
  182760. return 0;
  182761. if (hasTitleBar())
  182762. {
  182763. PostMessage (h, WM_CLOSE, 0, 0);
  182764. return 0;
  182765. }
  182766. break;
  182767. case SC_KEYMENU:
  182768. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182769. // obscure situations that can arise if a modal loop is started from an alt-key
  182770. // keypress).
  182771. if (hasTitleBar() && h == GetCapture())
  182772. ReleaseCapture();
  182773. break;
  182774. case SC_MAXIMIZE:
  182775. if (sendInputAttemptWhenModalMessage())
  182776. return 0;
  182777. setFullScreen (true);
  182778. return 0;
  182779. case SC_MINIMIZE:
  182780. if (sendInputAttemptWhenModalMessage())
  182781. return 0;
  182782. if (! hasTitleBar())
  182783. {
  182784. setMinimised (true);
  182785. return 0;
  182786. }
  182787. break;
  182788. case SC_RESTORE:
  182789. if (sendInputAttemptWhenModalMessage())
  182790. return 0;
  182791. if (hasTitleBar())
  182792. {
  182793. if (isFullScreen())
  182794. {
  182795. setFullScreen (false);
  182796. return 0;
  182797. }
  182798. }
  182799. else
  182800. {
  182801. if (isMinimised())
  182802. setMinimised (false);
  182803. else if (isFullScreen())
  182804. setFullScreen (false);
  182805. return 0;
  182806. }
  182807. break;
  182808. }
  182809. break;
  182810. case WM_NCLBUTTONDOWN:
  182811. case WM_NCRBUTTONDOWN:
  182812. case WM_NCMBUTTONDOWN:
  182813. sendInputAttemptWhenModalMessage();
  182814. break;
  182815. //case WM_IME_STARTCOMPOSITION;
  182816. // return 0;
  182817. case WM_GETDLGCODE:
  182818. return DLGC_WANTALLKEYS;
  182819. default:
  182820. break;
  182821. }
  182822. }
  182823. return DefWindowProcW (h, message, wParam, lParam);
  182824. }
  182825. bool sendInputAttemptWhenModalMessage()
  182826. {
  182827. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182828. {
  182829. Component* const current = Component::getCurrentlyModalComponent();
  182830. if (current != 0)
  182831. current->inputAttemptWhenModal();
  182832. return true;
  182833. }
  182834. return false;
  182835. }
  182836. Win32ComponentPeer (const Win32ComponentPeer&);
  182837. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182838. };
  182839. ModifierKeys Win32ComponentPeer::currentModifiers;
  182840. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182841. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182842. {
  182843. return new Win32ComponentPeer (this, styleFlags);
  182844. }
  182845. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182846. void ModifierKeys::updateCurrentModifiers() throw()
  182847. {
  182848. currentModifiers = Win32ComponentPeer::currentModifiers;
  182849. }
  182850. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182851. {
  182852. Win32ComponentPeer::updateKeyModifiers();
  182853. int keyMods = 0;
  182854. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182855. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182856. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182857. Win32ComponentPeer::currentModifiers
  182858. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182859. return Win32ComponentPeer::currentModifiers;
  182860. }
  182861. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182862. {
  182863. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182864. if (wp != 0)
  182865. wp->setTaskBarIcon (&newImage);
  182866. }
  182867. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182868. {
  182869. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182870. if (wp != 0)
  182871. wp->setTaskBarIconToolTip (tooltip);
  182872. }
  182873. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182874. {
  182875. DWORD val = GetWindowLong (h, styleType);
  182876. if (bitIsSet)
  182877. val |= feature;
  182878. else
  182879. val &= ~feature;
  182880. SetWindowLongPtr (h, styleType, val);
  182881. SetWindowPos (h, 0, 0, 0, 0, 0,
  182882. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182883. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182884. }
  182885. bool Process::isForegroundProcess()
  182886. {
  182887. HWND fg = GetForegroundWindow();
  182888. if (fg == 0)
  182889. return true;
  182890. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  182891. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  182892. // have to see if any of our windows are children of the foreground window
  182893. fg = GetAncestor (fg, GA_ROOT);
  182894. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  182895. {
  182896. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  182897. if (wp != 0 && wp->isInside (fg))
  182898. return true;
  182899. }
  182900. return false;
  182901. }
  182902. bool AlertWindow::showNativeDialogBox (const String& title,
  182903. const String& bodyText,
  182904. bool isOkCancel)
  182905. {
  182906. return MessageBox (0, bodyText, title,
  182907. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  182908. : MB_OK)) == IDOK;
  182909. }
  182910. void Desktop::createMouseInputSources()
  182911. {
  182912. mouseSources.add (new MouseInputSource (0, true));
  182913. }
  182914. const Point<int> Desktop::getMousePosition()
  182915. {
  182916. POINT mousePos;
  182917. GetCursorPos (&mousePos);
  182918. return Point<int> (mousePos.x, mousePos.y);
  182919. }
  182920. void Desktop::setMousePosition (const Point<int>& newPosition)
  182921. {
  182922. SetCursorPos (newPosition.getX(), newPosition.getY());
  182923. }
  182924. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  182925. {
  182926. return new Image (format, imageWidth, imageHeight, clearImage);
  182927. }
  182928. class ScreenSaverDefeater : public Timer,
  182929. public DeletedAtShutdown
  182930. {
  182931. public:
  182932. ScreenSaverDefeater() throw()
  182933. {
  182934. startTimer (10000);
  182935. timerCallback();
  182936. }
  182937. ~ScreenSaverDefeater() {}
  182938. void timerCallback()
  182939. {
  182940. if (Process::isForegroundProcess())
  182941. {
  182942. // simulate a shift key getting pressed..
  182943. INPUT input[2];
  182944. input[0].type = INPUT_KEYBOARD;
  182945. input[0].ki.wVk = VK_SHIFT;
  182946. input[0].ki.dwFlags = 0;
  182947. input[0].ki.dwExtraInfo = 0;
  182948. input[1].type = INPUT_KEYBOARD;
  182949. input[1].ki.wVk = VK_SHIFT;
  182950. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  182951. input[1].ki.dwExtraInfo = 0;
  182952. SendInput (2, input, sizeof (INPUT));
  182953. }
  182954. }
  182955. };
  182956. static ScreenSaverDefeater* screenSaverDefeater = 0;
  182957. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  182958. {
  182959. if (isEnabled)
  182960. {
  182961. deleteAndZero (screenSaverDefeater);
  182962. }
  182963. else if (screenSaverDefeater == 0)
  182964. {
  182965. screenSaverDefeater = new ScreenSaverDefeater();
  182966. }
  182967. }
  182968. bool Desktop::isScreenSaverEnabled() throw()
  182969. {
  182970. return screenSaverDefeater == 0;
  182971. }
  182972. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  182973. {
  182974. if (enableOrDisable)
  182975. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  182976. }
  182977. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  182978. {
  182979. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  182980. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  182981. return TRUE;
  182982. }
  182983. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  182984. {
  182985. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  182986. // make sure the first in the list is the main monitor
  182987. for (int i = 1; i < monitorCoords.size(); ++i)
  182988. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  182989. monitorCoords.swap (i, 0);
  182990. if (monitorCoords.size() == 0)
  182991. {
  182992. RECT r;
  182993. GetWindowRect (GetDesktopWindow(), &r);
  182994. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  182995. }
  182996. if (clipToWorkArea)
  182997. {
  182998. // clip the main monitor to the active non-taskbar area
  182999. RECT r;
  183000. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183001. Rectangle<int>& screen = monitorCoords.getReference (0);
  183002. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183003. jmax (screen.getY(), (int) r.top));
  183004. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183005. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183006. }
  183007. }
  183008. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183009. {
  183010. Image* im = 0;
  183011. if (bitmap != 0)
  183012. {
  183013. BITMAP bm;
  183014. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183015. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183016. {
  183017. HDC tempDC = GetDC (0);
  183018. HDC dc = CreateCompatibleDC (tempDC);
  183019. ReleaseDC (0, tempDC);
  183020. SelectObject (dc, bitmap);
  183021. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183022. for (int y = bm.bmHeight; --y >= 0;)
  183023. {
  183024. for (int x = bm.bmWidth; --x >= 0;)
  183025. {
  183026. COLORREF col = GetPixel (dc, x, y);
  183027. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183028. (uint8) GetGValue (col),
  183029. (uint8) GetBValue (col)));
  183030. }
  183031. }
  183032. DeleteDC (dc);
  183033. }
  183034. }
  183035. return im;
  183036. }
  183037. static Image* createImageFromHICON (HICON icon) throw()
  183038. {
  183039. ICONINFO info;
  183040. if (GetIconInfo (icon, &info))
  183041. {
  183042. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183043. if (mask == 0)
  183044. return 0;
  183045. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183046. if (image == 0)
  183047. return mask;
  183048. for (int y = image->getHeight(); --y >= 0;)
  183049. {
  183050. for (int x = image->getWidth(); --x >= 0;)
  183051. {
  183052. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183053. if (brightness > 0.0f)
  183054. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183055. }
  183056. }
  183057. delete mask;
  183058. return image;
  183059. }
  183060. return 0;
  183061. }
  183062. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183063. {
  183064. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183065. ICONINFO info;
  183066. info.fIcon = isIcon;
  183067. info.xHotspot = hotspotX;
  183068. info.yHotspot = hotspotY;
  183069. info.hbmMask = mask;
  183070. HICON hi = 0;
  183071. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183072. {
  183073. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183074. Graphics g (bitmap);
  183075. g.drawImageAt (&image, 0, 0);
  183076. info.hbmColor = bitmap.hBitmap;
  183077. hi = CreateIconIndirect (&info);
  183078. }
  183079. else
  183080. {
  183081. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183082. HDC colDC = CreateCompatibleDC (GetDC (0));
  183083. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183084. SelectObject (colDC, colour);
  183085. SelectObject (alphaDC, mask);
  183086. for (int y = image.getHeight(); --y >= 0;)
  183087. {
  183088. for (int x = image.getWidth(); --x >= 0;)
  183089. {
  183090. const Colour c (image.getPixelAt (x, y));
  183091. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183092. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183093. }
  183094. }
  183095. DeleteDC (colDC);
  183096. DeleteDC (alphaDC);
  183097. info.hbmColor = colour;
  183098. hi = CreateIconIndirect (&info);
  183099. DeleteObject (colour);
  183100. }
  183101. DeleteObject (mask);
  183102. return hi;
  183103. }
  183104. Image* juce_createIconForFile (const File& file)
  183105. {
  183106. Image* image = 0;
  183107. WCHAR filename [1024];
  183108. file.getFullPathName().copyToUnicode (filename, 1023);
  183109. WORD iconNum = 0;
  183110. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183111. filename, &iconNum);
  183112. if (icon != 0)
  183113. {
  183114. image = createImageFromHICON (icon);
  183115. DestroyIcon (icon);
  183116. }
  183117. return image;
  183118. }
  183119. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  183120. {
  183121. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183122. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183123. const Image* im = &image;
  183124. Image* newIm = 0;
  183125. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183126. {
  183127. im = newIm = image.createCopy (maxW, maxH);
  183128. hotspotX = (hotspotX * maxW) / image.getWidth();
  183129. hotspotY = (hotspotY * maxH) / image.getHeight();
  183130. }
  183131. void* cursorH = 0;
  183132. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183133. if (os == SystemStats::WinXP)
  183134. {
  183135. cursorH = createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183136. }
  183137. else
  183138. {
  183139. const int stride = (maxW + 7) >> 3;
  183140. HeapBlock <uint8> andPlane, xorPlane;
  183141. andPlane.calloc (stride * maxH);
  183142. xorPlane.calloc (stride * maxH);
  183143. int index = 0;
  183144. for (int y = 0; y < maxH; ++y)
  183145. {
  183146. for (int x = 0; x < maxW; ++x)
  183147. {
  183148. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183149. const Colour pixelColour (im->getPixelAt (x, y));
  183150. if (pixelColour.getAlpha() < 127)
  183151. andPlane [index + (x >> 3)] |= bit;
  183152. else if (pixelColour.getBrightness() >= 0.5f)
  183153. xorPlane [index + (x >> 3)] |= bit;
  183154. }
  183155. index += stride;
  183156. }
  183157. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183158. }
  183159. delete newIm;
  183160. return cursorH;
  183161. }
  183162. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  183163. {
  183164. if (cursorHandle != 0 && ! isStandard)
  183165. DestroyCursor ((HCURSOR) cursorHandle);
  183166. }
  183167. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  183168. {
  183169. LPCTSTR cursorName = IDC_ARROW;
  183170. switch (type)
  183171. {
  183172. case MouseCursor::NormalCursor:
  183173. cursorName = IDC_ARROW;
  183174. break;
  183175. case MouseCursor::NoCursor:
  183176. return 0;
  183177. case MouseCursor::DraggingHandCursor:
  183178. {
  183179. static void* dragHandCursor = 0;
  183180. if (dragHandCursor == 0)
  183181. {
  183182. static const unsigned char dragHandData[] =
  183183. { 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,
  183184. 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,
  183185. 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 };
  183186. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183187. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183188. }
  183189. return dragHandCursor;
  183190. }
  183191. case MouseCursor::WaitCursor:
  183192. cursorName = IDC_WAIT;
  183193. break;
  183194. case MouseCursor::IBeamCursor:
  183195. cursorName = IDC_IBEAM;
  183196. break;
  183197. case MouseCursor::PointingHandCursor:
  183198. cursorName = MAKEINTRESOURCE(32649);
  183199. break;
  183200. case MouseCursor::LeftRightResizeCursor:
  183201. case MouseCursor::LeftEdgeResizeCursor:
  183202. case MouseCursor::RightEdgeResizeCursor:
  183203. cursorName = IDC_SIZEWE;
  183204. break;
  183205. case MouseCursor::UpDownResizeCursor:
  183206. case MouseCursor::TopEdgeResizeCursor:
  183207. case MouseCursor::BottomEdgeResizeCursor:
  183208. cursorName = IDC_SIZENS;
  183209. break;
  183210. case MouseCursor::TopLeftCornerResizeCursor:
  183211. case MouseCursor::BottomRightCornerResizeCursor:
  183212. cursorName = IDC_SIZENWSE;
  183213. break;
  183214. case MouseCursor::TopRightCornerResizeCursor:
  183215. case MouseCursor::BottomLeftCornerResizeCursor:
  183216. cursorName = IDC_SIZENESW;
  183217. break;
  183218. case MouseCursor::UpDownLeftRightResizeCursor:
  183219. cursorName = IDC_SIZEALL;
  183220. break;
  183221. case MouseCursor::CrosshairCursor:
  183222. cursorName = IDC_CROSS;
  183223. break;
  183224. case MouseCursor::CopyingCursor:
  183225. // can't seem to find one of these in the win32 list..
  183226. break;
  183227. }
  183228. HCURSOR cursorH = LoadCursor (0, cursorName);
  183229. if (cursorH == 0)
  183230. cursorH = LoadCursor (0, IDC_ARROW);
  183231. return cursorH;
  183232. }
  183233. void MouseCursor::showInWindow (ComponentPeer*) const
  183234. {
  183235. SetCursor ((HCURSOR) getHandle());
  183236. }
  183237. void MouseCursor::showInAllWindows() const
  183238. {
  183239. showInWindow (0);
  183240. }
  183241. class JuceDropSource : public IDropSource
  183242. {
  183243. int refCount;
  183244. public:
  183245. JuceDropSource()
  183246. : refCount (1)
  183247. {
  183248. }
  183249. virtual ~JuceDropSource()
  183250. {
  183251. jassert (refCount == 0);
  183252. }
  183253. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183254. {
  183255. if (id == IID_IUnknown || id == IID_IDropSource)
  183256. {
  183257. AddRef();
  183258. *result = this;
  183259. return S_OK;
  183260. }
  183261. *result = 0;
  183262. return E_NOINTERFACE;
  183263. }
  183264. ULONG __stdcall AddRef() { return ++refCount; }
  183265. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183266. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183267. {
  183268. if (escapePressed)
  183269. return DRAGDROP_S_CANCEL;
  183270. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183271. return DRAGDROP_S_DROP;
  183272. return S_OK;
  183273. }
  183274. HRESULT __stdcall GiveFeedback (DWORD)
  183275. {
  183276. return DRAGDROP_S_USEDEFAULTCURSORS;
  183277. }
  183278. };
  183279. class JuceEnumFormatEtc : public IEnumFORMATETC
  183280. {
  183281. public:
  183282. JuceEnumFormatEtc (const FORMATETC* const format_)
  183283. : refCount (1),
  183284. format (format_),
  183285. index (0)
  183286. {
  183287. }
  183288. virtual ~JuceEnumFormatEtc()
  183289. {
  183290. jassert (refCount == 0);
  183291. }
  183292. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183293. {
  183294. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183295. {
  183296. AddRef();
  183297. *result = this;
  183298. return S_OK;
  183299. }
  183300. *result = 0;
  183301. return E_NOINTERFACE;
  183302. }
  183303. ULONG __stdcall AddRef() { return ++refCount; }
  183304. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183305. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183306. {
  183307. if (result == 0)
  183308. return E_POINTER;
  183309. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183310. newOne->index = index;
  183311. *result = newOne;
  183312. return S_OK;
  183313. }
  183314. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183315. {
  183316. if (pceltFetched != 0)
  183317. *pceltFetched = 0;
  183318. else if (celt != 1)
  183319. return S_FALSE;
  183320. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183321. {
  183322. copyFormatEtc (lpFormatEtc [0], *format);
  183323. ++index;
  183324. if (pceltFetched != 0)
  183325. *pceltFetched = 1;
  183326. return S_OK;
  183327. }
  183328. return S_FALSE;
  183329. }
  183330. HRESULT __stdcall Skip (ULONG celt)
  183331. {
  183332. if (index + (int) celt >= 1)
  183333. return S_FALSE;
  183334. index += celt;
  183335. return S_OK;
  183336. }
  183337. HRESULT __stdcall Reset()
  183338. {
  183339. index = 0;
  183340. return S_OK;
  183341. }
  183342. private:
  183343. int refCount;
  183344. const FORMATETC* const format;
  183345. int index;
  183346. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183347. {
  183348. dest = source;
  183349. if (source.ptd != 0)
  183350. {
  183351. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183352. *(dest.ptd) = *(source.ptd);
  183353. }
  183354. }
  183355. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183356. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183357. };
  183358. class JuceDataObject : public IDataObject
  183359. {
  183360. JuceDropSource* const dropSource;
  183361. const FORMATETC* const format;
  183362. const STGMEDIUM* const medium;
  183363. int refCount;
  183364. JuceDataObject (const JuceDataObject&);
  183365. JuceDataObject& operator= (const JuceDataObject&);
  183366. public:
  183367. JuceDataObject (JuceDropSource* const dropSource_,
  183368. const FORMATETC* const format_,
  183369. const STGMEDIUM* const medium_)
  183370. : dropSource (dropSource_),
  183371. format (format_),
  183372. medium (medium_),
  183373. refCount (1)
  183374. {
  183375. }
  183376. virtual ~JuceDataObject()
  183377. {
  183378. jassert (refCount == 0);
  183379. }
  183380. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183381. {
  183382. if (id == IID_IUnknown || id == IID_IDataObject)
  183383. {
  183384. AddRef();
  183385. *result = this;
  183386. return S_OK;
  183387. }
  183388. *result = 0;
  183389. return E_NOINTERFACE;
  183390. }
  183391. ULONG __stdcall AddRef() { return ++refCount; }
  183392. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183393. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183394. {
  183395. if ((pFormatEtc->tymed & format->tymed) != 0
  183396. && pFormatEtc->cfFormat == format->cfFormat
  183397. && pFormatEtc->dwAspect == format->dwAspect)
  183398. {
  183399. pMedium->tymed = format->tymed;
  183400. pMedium->pUnkForRelease = 0;
  183401. if (format->tymed == TYMED_HGLOBAL)
  183402. {
  183403. const SIZE_T len = GlobalSize (medium->hGlobal);
  183404. void* const src = GlobalLock (medium->hGlobal);
  183405. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183406. memcpy (dst, src, len);
  183407. GlobalUnlock (medium->hGlobal);
  183408. pMedium->hGlobal = dst;
  183409. return S_OK;
  183410. }
  183411. }
  183412. return DV_E_FORMATETC;
  183413. }
  183414. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183415. {
  183416. if (f == 0)
  183417. return E_INVALIDARG;
  183418. if (f->tymed == format->tymed
  183419. && f->cfFormat == format->cfFormat
  183420. && f->dwAspect == format->dwAspect)
  183421. return S_OK;
  183422. return DV_E_FORMATETC;
  183423. }
  183424. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183425. {
  183426. pFormatEtcOut->ptd = 0;
  183427. return E_NOTIMPL;
  183428. }
  183429. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183430. {
  183431. if (result == 0)
  183432. return E_POINTER;
  183433. if (direction == DATADIR_GET)
  183434. {
  183435. *result = new JuceEnumFormatEtc (format);
  183436. return S_OK;
  183437. }
  183438. *result = 0;
  183439. return E_NOTIMPL;
  183440. }
  183441. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183442. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183443. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183444. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183445. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183446. };
  183447. static HDROP createHDrop (const StringArray& fileNames) throw()
  183448. {
  183449. int totalChars = 0;
  183450. for (int i = fileNames.size(); --i >= 0;)
  183451. totalChars += fileNames[i].length() + 1;
  183452. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183453. sizeof (DROPFILES)
  183454. + sizeof (WCHAR) * (totalChars + 2));
  183455. if (hDrop != 0)
  183456. {
  183457. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183458. pDropFiles->pFiles = sizeof (DROPFILES);
  183459. pDropFiles->fWide = true;
  183460. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183461. for (int i = 0; i < fileNames.size(); ++i)
  183462. {
  183463. fileNames[i].copyToUnicode (fname, 2048);
  183464. fname += fileNames[i].length() + 1;
  183465. }
  183466. *fname = 0;
  183467. GlobalUnlock (hDrop);
  183468. }
  183469. return hDrop;
  183470. }
  183471. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183472. {
  183473. JuceDropSource* const source = new JuceDropSource();
  183474. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183475. DWORD effect;
  183476. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183477. data->Release();
  183478. source->Release();
  183479. return res == DRAGDROP_S_DROP;
  183480. }
  183481. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183482. {
  183483. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183484. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183485. medium.hGlobal = createHDrop (files);
  183486. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183487. : DROPEFFECT_COPY);
  183488. }
  183489. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183490. {
  183491. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183492. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183493. const int numChars = text.length();
  183494. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183495. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (medium.hGlobal));
  183496. text.copyToUnicode (data, numChars + 1);
  183497. format.cfFormat = CF_UNICODETEXT;
  183498. GlobalUnlock (medium.hGlobal);
  183499. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183500. }
  183501. #endif
  183502. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183503. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183504. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183505. // compiled on its own).
  183506. #if JUCE_INCLUDED_FILE
  183507. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183508. NEWTEXTMETRICEXW*,
  183509. int type,
  183510. LPARAM lParam)
  183511. {
  183512. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183513. {
  183514. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183515. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters ("@"));
  183516. }
  183517. return 1;
  183518. }
  183519. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183520. NEWTEXTMETRICEXW*,
  183521. int type,
  183522. LPARAM lParam)
  183523. {
  183524. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183525. {
  183526. LOGFONTW lf;
  183527. zerostruct (lf);
  183528. lf.lfWeight = FW_DONTCARE;
  183529. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183530. lf.lfQuality = DEFAULT_QUALITY;
  183531. lf.lfCharSet = DEFAULT_CHARSET;
  183532. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183533. lf.lfPitchAndFamily = FF_DONTCARE;
  183534. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183535. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183536. HDC dc = CreateCompatibleDC (0);
  183537. EnumFontFamiliesEx (dc, &lf,
  183538. (FONTENUMPROCW) &wfontEnum2,
  183539. lParam, 0);
  183540. DeleteDC (dc);
  183541. }
  183542. return 1;
  183543. }
  183544. const StringArray Font::findAllTypefaceNames()
  183545. {
  183546. StringArray results;
  183547. HDC dc = CreateCompatibleDC (0);
  183548. {
  183549. LOGFONTW lf;
  183550. zerostruct (lf);
  183551. lf.lfWeight = FW_DONTCARE;
  183552. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183553. lf.lfQuality = DEFAULT_QUALITY;
  183554. lf.lfCharSet = DEFAULT_CHARSET;
  183555. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183556. lf.lfPitchAndFamily = FF_DONTCARE;
  183557. lf.lfFaceName[0] = 0;
  183558. EnumFontFamiliesEx (dc, &lf,
  183559. (FONTENUMPROCW) &wfontEnum1,
  183560. (LPARAM) &results, 0);
  183561. }
  183562. DeleteDC (dc);
  183563. results.sort (true);
  183564. return results;
  183565. }
  183566. extern bool juce_IsRunningInWine();
  183567. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  183568. {
  183569. if (juce_IsRunningInWine())
  183570. {
  183571. // If we're running in Wine, then use fonts that might be available on Linux..
  183572. defaultSans = "Bitstream Vera Sans";
  183573. defaultSerif = "Bitstream Vera Serif";
  183574. defaultFixed = "Bitstream Vera Sans Mono";
  183575. }
  183576. else
  183577. {
  183578. defaultSans = "Verdana";
  183579. defaultSerif = "Times";
  183580. defaultFixed = "Lucida Console";
  183581. }
  183582. }
  183583. class FontDCHolder : private DeletedAtShutdown
  183584. {
  183585. public:
  183586. FontDCHolder() throw()
  183587. : dc (0), numKPs (0), size (0),
  183588. bold (false), italic (false)
  183589. {
  183590. }
  183591. ~FontDCHolder() throw()
  183592. {
  183593. if (dc != 0)
  183594. {
  183595. DeleteDC (dc);
  183596. DeleteObject (fontH);
  183597. }
  183598. clearSingletonInstance();
  183599. }
  183600. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183601. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183602. {
  183603. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183604. {
  183605. fontName = fontName_;
  183606. bold = bold_;
  183607. italic = italic_;
  183608. size = size_;
  183609. if (dc != 0)
  183610. {
  183611. DeleteDC (dc);
  183612. DeleteObject (fontH);
  183613. kps.free();
  183614. }
  183615. fontH = 0;
  183616. dc = CreateCompatibleDC (0);
  183617. SetMapperFlags (dc, 0);
  183618. SetMapMode (dc, MM_TEXT);
  183619. LOGFONTW lfw;
  183620. zerostruct (lfw);
  183621. lfw.lfCharSet = DEFAULT_CHARSET;
  183622. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183623. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183624. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183625. lfw.lfQuality = PROOF_QUALITY;
  183626. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183627. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183628. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183629. lfw.lfHeight = size > 0 ? size : -256;
  183630. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183631. if (standardSizedFont != 0)
  183632. {
  183633. if (SelectObject (dc, standardSizedFont) != 0)
  183634. {
  183635. fontH = standardSizedFont;
  183636. if (size == 0)
  183637. {
  183638. OUTLINETEXTMETRIC otm;
  183639. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183640. {
  183641. lfw.lfHeight = -(int) otm.otmEMSquare;
  183642. fontH = CreateFontIndirect (&lfw);
  183643. SelectObject (dc, fontH);
  183644. DeleteObject (standardSizedFont);
  183645. }
  183646. }
  183647. }
  183648. else
  183649. {
  183650. jassertfalse
  183651. }
  183652. }
  183653. else
  183654. {
  183655. jassertfalse
  183656. }
  183657. }
  183658. return dc;
  183659. }
  183660. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183661. {
  183662. if (kps == 0)
  183663. {
  183664. numKPs = GetKerningPairs (dc, 0, 0);
  183665. kps.calloc (numKPs);
  183666. GetKerningPairs (dc, numKPs, kps);
  183667. }
  183668. numKPs_ = numKPs;
  183669. return kps;
  183670. }
  183671. private:
  183672. HFONT fontH;
  183673. HDC dc;
  183674. String fontName;
  183675. HeapBlock <KERNINGPAIR> kps;
  183676. int numKPs, size;
  183677. bool bold, italic;
  183678. FontDCHolder (const FontDCHolder&);
  183679. FontDCHolder& operator= (const FontDCHolder&);
  183680. };
  183681. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183682. class WindowsTypeface : public CustomTypeface
  183683. {
  183684. public:
  183685. WindowsTypeface (const Font& font)
  183686. {
  183687. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183688. font.isBold(), font.isItalic(), 0);
  183689. TEXTMETRIC tm;
  183690. tm.tmAscent = tm.tmHeight = 1;
  183691. tm.tmDefaultChar = 0;
  183692. GetTextMetrics (dc, &tm);
  183693. setCharacteristics (font.getTypefaceName(),
  183694. tm.tmAscent / (float) tm.tmHeight,
  183695. font.isBold(), font.isItalic(),
  183696. tm.tmDefaultChar);
  183697. }
  183698. bool loadGlyphIfPossible (juce_wchar character)
  183699. {
  183700. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183701. GLYPHMETRICS gm;
  183702. {
  183703. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183704. WORD index = 0;
  183705. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183706. && index == 0xffff)
  183707. {
  183708. return false;
  183709. }
  183710. }
  183711. Path glyphPath;
  183712. TEXTMETRIC tm;
  183713. if (! GetTextMetrics (dc, &tm))
  183714. {
  183715. addGlyph (character, glyphPath, 0);
  183716. return true;
  183717. }
  183718. const float height = (float) tm.tmHeight;
  183719. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183720. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183721. &gm, 0, 0, &identityMatrix);
  183722. if (bufSize > 0)
  183723. {
  183724. HeapBlock<char> data (bufSize);
  183725. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183726. bufSize, data, &identityMatrix);
  183727. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183728. const float scaleX = 1.0f / height;
  183729. const float scaleY = -1.0f / height;
  183730. while ((char*) pheader < data + bufSize)
  183731. {
  183732. float x = scaleX * pheader->pfxStart.x.value;
  183733. float y = scaleY * pheader->pfxStart.y.value;
  183734. glyphPath.startNewSubPath (x, y);
  183735. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183736. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183737. while ((const char*) curve < curveEnd)
  183738. {
  183739. if (curve->wType == TT_PRIM_LINE)
  183740. {
  183741. for (int i = 0; i < curve->cpfx; ++i)
  183742. {
  183743. x = scaleX * curve->apfx[i].x.value;
  183744. y = scaleY * curve->apfx[i].y.value;
  183745. glyphPath.lineTo (x, y);
  183746. }
  183747. }
  183748. else if (curve->wType == TT_PRIM_QSPLINE)
  183749. {
  183750. for (int i = 0; i < curve->cpfx - 1; ++i)
  183751. {
  183752. const float x2 = scaleX * curve->apfx[i].x.value;
  183753. const float y2 = scaleY * curve->apfx[i].y.value;
  183754. float x3, y3;
  183755. if (i < curve->cpfx - 2)
  183756. {
  183757. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183758. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183759. }
  183760. else
  183761. {
  183762. x3 = scaleX * curve->apfx[i + 1].x.value;
  183763. y3 = scaleY * curve->apfx[i + 1].y.value;
  183764. }
  183765. glyphPath.quadraticTo (x2, y2, x3, y3);
  183766. x = x3;
  183767. y = y3;
  183768. }
  183769. }
  183770. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183771. }
  183772. pheader = (const TTPOLYGONHEADER*) curve;
  183773. glyphPath.closeSubPath();
  183774. }
  183775. }
  183776. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183777. int numKPs;
  183778. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183779. for (int i = 0; i < numKPs; ++i)
  183780. {
  183781. if (kps[i].wFirst == character)
  183782. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183783. kps[i].iKernAmount / height);
  183784. }
  183785. return true;
  183786. }
  183787. };
  183788. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183789. {
  183790. return new WindowsTypeface (font);
  183791. }
  183792. #endif
  183793. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183794. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183795. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183796. // compiled on its own).
  183797. #if JUCE_INCLUDED_FILE
  183798. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183799. namespace FileChooserHelpers
  183800. {
  183801. static const void* defaultDirPath = 0;
  183802. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183803. static Component* currentExtraFileWin = 0;
  183804. static bool areThereAnyAlwaysOnTopWindows()
  183805. {
  183806. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183807. {
  183808. Component* c = Desktop::getInstance().getComponent (i);
  183809. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183810. return true;
  183811. }
  183812. return false;
  183813. }
  183814. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183815. {
  183816. if (msg == BFFM_INITIALIZED)
  183817. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183818. else if (msg == BFFM_VALIDATEFAILEDW)
  183819. returnedString = (LPCWSTR) lParam;
  183820. else if (msg == BFFM_VALIDATEFAILEDA)
  183821. returnedString = (const char*) lParam;
  183822. return 0;
  183823. }
  183824. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183825. {
  183826. if (currentExtraFileWin != 0)
  183827. {
  183828. if (uiMsg == WM_INITDIALOG)
  183829. {
  183830. HWND dialogH = GetParent (hdlg);
  183831. jassert (dialogH != 0);
  183832. if (dialogH == 0)
  183833. dialogH = hdlg;
  183834. RECT r, cr;
  183835. GetWindowRect (dialogH, &r);
  183836. GetClientRect (dialogH, &cr);
  183837. SetWindowPos (dialogH, 0,
  183838. r.left, r.top,
  183839. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183840. jmax (150, (int) (r.bottom - r.top)),
  183841. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183842. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183843. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183844. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183845. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183846. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183847. }
  183848. else if (uiMsg == WM_NOTIFY)
  183849. {
  183850. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183851. if (ofn->hdr.code == CDN_SELCHANGE)
  183852. {
  183853. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183854. if (comp != 0)
  183855. {
  183856. TCHAR path [MAX_PATH * 2];
  183857. path[0] = 0;
  183858. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183859. const String fn ((const WCHAR*) path);
  183860. comp->selectedFileChanged (File (fn));
  183861. }
  183862. }
  183863. }
  183864. }
  183865. return 0;
  183866. }
  183867. class FPComponentHolder : public Component
  183868. {
  183869. public:
  183870. FPComponentHolder()
  183871. {
  183872. setVisible (true);
  183873. setOpaque (true);
  183874. }
  183875. ~FPComponentHolder()
  183876. {
  183877. }
  183878. void paint (Graphics& g)
  183879. {
  183880. g.fillAll (Colours::lightgrey);
  183881. }
  183882. private:
  183883. FPComponentHolder (const FPComponentHolder&);
  183884. FPComponentHolder& operator= (const FPComponentHolder&);
  183885. };
  183886. }
  183887. void FileChooser::showPlatformDialog (Array<File>& results,
  183888. const String& title,
  183889. const File& currentFileOrDirectory,
  183890. const String& filter,
  183891. bool selectsDirectory,
  183892. bool /*selectsFiles*/,
  183893. bool isSaveDialogue,
  183894. bool warnAboutOverwritingExistingFiles,
  183895. bool selectMultipleFiles,
  183896. FilePreviewComponent* extraInfoComponent)
  183897. {
  183898. using namespace FileChooserHelpers;
  183899. const int numCharsAvailable = 32768;
  183900. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  183901. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  183902. int fnameIdx = 0;
  183903. JUCE_TRY
  183904. {
  183905. // use a modal window as the parent for this dialog box
  183906. // to block input from other app windows
  183907. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  183908. Component w (String::empty);
  183909. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  183910. mainMon.getY() + mainMon.getHeight() / 4,
  183911. 0, 0);
  183912. w.setOpaque (true);
  183913. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  183914. w.addToDesktop (0);
  183915. if (extraInfoComponent == 0)
  183916. w.enterModalState();
  183917. String initialDir;
  183918. if (currentFileOrDirectory.isDirectory())
  183919. {
  183920. initialDir = currentFileOrDirectory.getFullPathName();
  183921. }
  183922. else
  183923. {
  183924. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  183925. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  183926. }
  183927. if (currentExtraFileWin->isValidComponent())
  183928. {
  183929. jassertfalse
  183930. return;
  183931. }
  183932. if (selectsDirectory)
  183933. {
  183934. LPITEMIDLIST list = 0;
  183935. filenameSpace.fillWith (0);
  183936. {
  183937. BROWSEINFO bi;
  183938. zerostruct (bi);
  183939. bi.hwndOwner = (HWND) w.getWindowHandle();
  183940. bi.pszDisplayName = fname;
  183941. bi.lpszTitle = title;
  183942. bi.lpfn = browseCallbackProc;
  183943. #ifdef BIF_USENEWUI
  183944. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  183945. #else
  183946. bi.ulFlags = 0x50;
  183947. #endif
  183948. defaultDirPath = (const WCHAR*) initialDir;
  183949. list = SHBrowseForFolder (&bi);
  183950. if (! SHGetPathFromIDListW (list, fname))
  183951. {
  183952. fname[0] = 0;
  183953. returnedString = String::empty;
  183954. }
  183955. }
  183956. LPMALLOC al;
  183957. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  183958. al->Free (list);
  183959. defaultDirPath = 0;
  183960. if (returnedString.isNotEmpty())
  183961. {
  183962. const String stringFName (fname);
  183963. results.add (File (stringFName).getSiblingFile (returnedString));
  183964. returnedString = String::empty;
  183965. return;
  183966. }
  183967. }
  183968. else
  183969. {
  183970. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  183971. if (warnAboutOverwritingExistingFiles)
  183972. flags |= OFN_OVERWRITEPROMPT;
  183973. if (selectMultipleFiles)
  183974. flags |= OFN_ALLOWMULTISELECT;
  183975. if (extraInfoComponent != 0)
  183976. {
  183977. flags |= OFN_ENABLEHOOK;
  183978. currentExtraFileWin = new FPComponentHolder();
  183979. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  183980. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  183981. extraInfoComponent->getHeight());
  183982. currentExtraFileWin->addToDesktop (0);
  183983. currentExtraFileWin->enterModalState();
  183984. }
  183985. {
  183986. WCHAR filters [1024];
  183987. zeromem (filters, sizeof (filters));
  183988. filter.copyToUnicode (filters, 1024);
  183989. filter.copyToUnicode (filters + filter.length() + 1,
  183990. 1022 - filter.length());
  183991. OPENFILENAMEW of;
  183992. zerostruct (of);
  183993. #ifdef OPENFILENAME_SIZE_VERSION_400W
  183994. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  183995. #else
  183996. of.lStructSize = sizeof (of);
  183997. #endif
  183998. of.hwndOwner = (HWND) w.getWindowHandle();
  183999. of.lpstrFilter = filters;
  184000. of.nFilterIndex = 1;
  184001. of.lpstrFile = fname;
  184002. of.nMaxFile = numCharsAvailable;
  184003. of.lpstrInitialDir = initialDir;
  184004. of.lpstrTitle = title;
  184005. of.Flags = flags;
  184006. if (extraInfoComponent != 0)
  184007. of.lpfnHook = &openCallback;
  184008. if (isSaveDialogue)
  184009. {
  184010. if (! GetSaveFileName (&of))
  184011. fname[0] = 0;
  184012. else
  184013. fnameIdx = of.nFileOffset;
  184014. }
  184015. else
  184016. {
  184017. if (! GetOpenFileName (&of))
  184018. fname[0] = 0;
  184019. else
  184020. fnameIdx = of.nFileOffset;
  184021. }
  184022. }
  184023. }
  184024. }
  184025. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184026. catch (...)
  184027. {
  184028. fname[0] = 0;
  184029. }
  184030. #endif
  184031. deleteAndZero (currentExtraFileWin);
  184032. const WCHAR* const files = fname;
  184033. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184034. {
  184035. const WCHAR* filename = files + fnameIdx;
  184036. while (*filename != 0)
  184037. {
  184038. const String filepath (String (files) + "\\" + String (filename));
  184039. results.add (File (filepath));
  184040. filename += CharacterFunctions::length (filename) + 1;
  184041. }
  184042. }
  184043. else if (files[0] != 0)
  184044. {
  184045. results.add (File (files));
  184046. }
  184047. }
  184048. #endif
  184049. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184050. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184051. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184052. // compiled on its own).
  184053. #if JUCE_INCLUDED_FILE
  184054. void SystemClipboard::copyTextToClipboard (const String& text)
  184055. {
  184056. if (OpenClipboard (0) != 0)
  184057. {
  184058. if (EmptyClipboard() != 0)
  184059. {
  184060. const int len = text.length();
  184061. if (len > 0)
  184062. {
  184063. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184064. (len + 1) * sizeof (wchar_t));
  184065. if (bufH != 0)
  184066. {
  184067. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH));
  184068. text.copyToUnicode (data, len);
  184069. GlobalUnlock (bufH);
  184070. SetClipboardData (CF_UNICODETEXT, bufH);
  184071. }
  184072. }
  184073. }
  184074. CloseClipboard();
  184075. }
  184076. }
  184077. const String SystemClipboard::getTextFromClipboard()
  184078. {
  184079. String result;
  184080. if (OpenClipboard (0) != 0)
  184081. {
  184082. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184083. if (bufH != 0)
  184084. {
  184085. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184086. if (data != 0)
  184087. {
  184088. result = String (data, (int) (GlobalSize (bufH) / sizeof (wchar_t)));
  184089. GlobalUnlock (bufH);
  184090. }
  184091. }
  184092. CloseClipboard();
  184093. }
  184094. return result;
  184095. }
  184096. #endif
  184097. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184098. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184099. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184100. // compiled on its own).
  184101. #if JUCE_INCLUDED_FILE
  184102. namespace ActiveXHelpers
  184103. {
  184104. class JuceIStorage : public IStorage
  184105. {
  184106. int refCount;
  184107. public:
  184108. JuceIStorage() : refCount (1) {}
  184109. virtual ~JuceIStorage()
  184110. {
  184111. jassert (refCount == 0);
  184112. }
  184113. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184114. {
  184115. if (id == IID_IUnknown || id == IID_IStorage)
  184116. {
  184117. AddRef();
  184118. *result = this;
  184119. return S_OK;
  184120. }
  184121. *result = 0;
  184122. return E_NOINTERFACE;
  184123. }
  184124. ULONG __stdcall AddRef() { return ++refCount; }
  184125. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184126. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184127. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184128. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184129. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184130. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184131. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184132. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184133. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184134. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184135. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184136. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184137. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184138. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184139. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184140. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184141. juce_UseDebuggingNewOperator
  184142. };
  184143. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184144. {
  184145. int refCount;
  184146. HWND window;
  184147. public:
  184148. JuceOleInPlaceFrame (HWND window_)
  184149. : refCount (1),
  184150. window (window_)
  184151. {
  184152. }
  184153. virtual ~JuceOleInPlaceFrame()
  184154. {
  184155. jassert (refCount == 0);
  184156. }
  184157. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184158. {
  184159. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184160. {
  184161. AddRef();
  184162. *result = this;
  184163. return S_OK;
  184164. }
  184165. *result = 0;
  184166. return E_NOINTERFACE;
  184167. }
  184168. ULONG __stdcall AddRef() { return ++refCount; }
  184169. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184170. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184171. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184172. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184173. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184174. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184175. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184176. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184177. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184178. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184179. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184180. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184181. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184182. juce_UseDebuggingNewOperator
  184183. };
  184184. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184185. {
  184186. int refCount;
  184187. HWND window;
  184188. JuceOleInPlaceFrame* frame;
  184189. public:
  184190. JuceIOleInPlaceSite (HWND window_)
  184191. : refCount (1),
  184192. window (window_)
  184193. {
  184194. frame = new JuceOleInPlaceFrame (window);
  184195. }
  184196. virtual ~JuceIOleInPlaceSite()
  184197. {
  184198. jassert (refCount == 0);
  184199. frame->Release();
  184200. }
  184201. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184202. {
  184203. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184204. {
  184205. AddRef();
  184206. *result = this;
  184207. return S_OK;
  184208. }
  184209. *result = 0;
  184210. return E_NOINTERFACE;
  184211. }
  184212. ULONG __stdcall AddRef() { return ++refCount; }
  184213. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184214. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184215. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184216. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184217. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184218. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184219. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184220. {
  184221. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184222. *lplpFrame = frame;
  184223. *lplpDoc = 0;
  184224. lpFrameInfo->fMDIApp = FALSE;
  184225. lpFrameInfo->hwndFrame = window;
  184226. lpFrameInfo->haccel = 0;
  184227. lpFrameInfo->cAccelEntries = 0;
  184228. return S_OK;
  184229. }
  184230. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184231. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184232. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184233. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184234. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184235. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184236. juce_UseDebuggingNewOperator
  184237. };
  184238. class JuceIOleClientSite : public IOleClientSite
  184239. {
  184240. int refCount;
  184241. JuceIOleInPlaceSite* inplaceSite;
  184242. public:
  184243. JuceIOleClientSite (HWND window)
  184244. : refCount (1)
  184245. {
  184246. inplaceSite = new JuceIOleInPlaceSite (window);
  184247. }
  184248. virtual ~JuceIOleClientSite()
  184249. {
  184250. jassert (refCount == 0);
  184251. inplaceSite->Release();
  184252. }
  184253. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184254. {
  184255. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184256. {
  184257. AddRef();
  184258. *result = this;
  184259. return S_OK;
  184260. }
  184261. else if (id == IID_IOleInPlaceSite)
  184262. {
  184263. inplaceSite->AddRef();
  184264. *result = inplaceSite;
  184265. return S_OK;
  184266. }
  184267. *result = 0;
  184268. return E_NOINTERFACE;
  184269. }
  184270. ULONG __stdcall AddRef() { return ++refCount; }
  184271. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184272. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184273. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184274. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184275. HRESULT __stdcall ShowObject() { return S_OK; }
  184276. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184277. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184278. juce_UseDebuggingNewOperator
  184279. };
  184280. static VoidArray activeXComps;
  184281. static HWND getHWND (const ActiveXControlComponent* const component)
  184282. {
  184283. HWND hwnd = 0;
  184284. const IID iid = IID_IOleWindow;
  184285. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184286. if (window != 0)
  184287. {
  184288. window->GetWindow (&hwnd);
  184289. window->Release();
  184290. }
  184291. return hwnd;
  184292. }
  184293. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184294. {
  184295. RECT activeXRect, peerRect;
  184296. GetWindowRect (hwnd, &activeXRect);
  184297. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184298. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184299. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184300. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184301. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184302. switch (message)
  184303. {
  184304. case WM_MOUSEMOVE:
  184305. case WM_LBUTTONDOWN:
  184306. case WM_MBUTTONDOWN:
  184307. case WM_RBUTTONDOWN:
  184308. case WM_LBUTTONUP:
  184309. case WM_MBUTTONUP:
  184310. case WM_RBUTTONUP:
  184311. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184312. break;
  184313. default:
  184314. break;
  184315. }
  184316. }
  184317. }
  184318. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184319. {
  184320. ActiveXControlComponent* const owner;
  184321. bool wasShowing;
  184322. public:
  184323. HWND controlHWND;
  184324. IStorage* storage;
  184325. IOleClientSite* clientSite;
  184326. IOleObject* control;
  184327. ActiveXControlData (HWND hwnd,
  184328. ActiveXControlComponent* const owner_)
  184329. : ComponentMovementWatcher (owner_),
  184330. owner (owner_),
  184331. wasShowing (owner_ != 0 && owner_->isShowing()),
  184332. controlHWND (0),
  184333. storage (new ActiveXHelpers::JuceIStorage()),
  184334. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184335. control (0)
  184336. {
  184337. }
  184338. ~ActiveXControlData()
  184339. {
  184340. if (control != 0)
  184341. {
  184342. control->Close (OLECLOSE_NOSAVE);
  184343. control->Release();
  184344. }
  184345. clientSite->Release();
  184346. storage->Release();
  184347. }
  184348. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184349. {
  184350. Component* const topComp = owner->getTopLevelComponent();
  184351. if (topComp->getPeer() != 0)
  184352. {
  184353. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184354. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184355. }
  184356. }
  184357. void componentPeerChanged()
  184358. {
  184359. const bool isShowingNow = owner->isShowing();
  184360. if (wasShowing != isShowingNow)
  184361. {
  184362. wasShowing = isShowingNow;
  184363. owner->setControlVisible (isShowingNow);
  184364. }
  184365. componentMovedOrResized (true, true);
  184366. }
  184367. void componentVisibilityChanged (Component&)
  184368. {
  184369. componentPeerChanged();
  184370. }
  184371. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184372. {
  184373. return ((ActiveXControlData*) ax->control) != 0
  184374. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184375. }
  184376. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184377. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184378. {
  184379. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184380. {
  184381. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184382. if (doesWindowMatch (ax, hwnd))
  184383. {
  184384. switch (message)
  184385. {
  184386. case WM_MOUSEMOVE:
  184387. case WM_LBUTTONDOWN:
  184388. case WM_MBUTTONDOWN:
  184389. case WM_RBUTTONDOWN:
  184390. case WM_LBUTTONUP:
  184391. case WM_MBUTTONUP:
  184392. case WM_RBUTTONUP:
  184393. case WM_LBUTTONDBLCLK:
  184394. case WM_MBUTTONDBLCLK:
  184395. case WM_RBUTTONDBLCLK:
  184396. if (ax->isShowing())
  184397. {
  184398. ComponentPeer* const peer = ax->getPeer();
  184399. if (peer != 0)
  184400. {
  184401. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184402. if (! ax->areMouseEventsAllowed())
  184403. return 0;
  184404. }
  184405. }
  184406. break;
  184407. default:
  184408. break;
  184409. }
  184410. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184411. }
  184412. }
  184413. return DefWindowProc (hwnd, message, wParam, lParam);
  184414. }
  184415. };
  184416. ActiveXControlComponent::ActiveXControlComponent()
  184417. : originalWndProc (0),
  184418. control (0),
  184419. mouseEventsAllowed (true)
  184420. {
  184421. ActiveXHelpers::activeXComps.add (this);
  184422. }
  184423. ActiveXControlComponent::~ActiveXControlComponent()
  184424. {
  184425. deleteControl();
  184426. ActiveXHelpers::activeXComps.removeValue (this);
  184427. }
  184428. void ActiveXControlComponent::paint (Graphics& g)
  184429. {
  184430. if (control == 0)
  184431. g.fillAll (Colours::lightgrey);
  184432. }
  184433. bool ActiveXControlComponent::createControl (const void* controlIID)
  184434. {
  184435. deleteControl();
  184436. ComponentPeer* const peer = getPeer();
  184437. // the component must have already been added to a real window when you call this!
  184438. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184439. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184440. {
  184441. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184442. HWND hwnd = (HWND) peer->getNativeHandle();
  184443. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184444. HRESULT hr;
  184445. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184446. info->clientSite, info->storage,
  184447. (void**) &(info->control))) == S_OK)
  184448. {
  184449. info->control->SetHostNames (L"Juce", 0);
  184450. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184451. {
  184452. RECT rect;
  184453. rect.left = pos.getX();
  184454. rect.top = pos.getY();
  184455. rect.right = pos.getX() + getWidth();
  184456. rect.bottom = pos.getY() + getHeight();
  184457. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184458. {
  184459. control = info.release();
  184460. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184461. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184462. if (((ActiveXControlData*) control)->controlHWND != 0)
  184463. {
  184464. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184465. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184466. }
  184467. return true;
  184468. }
  184469. }
  184470. }
  184471. }
  184472. return false;
  184473. }
  184474. void ActiveXControlComponent::deleteControl()
  184475. {
  184476. ActiveXControlData* const info = (ActiveXControlData*) control;
  184477. if (info != 0)
  184478. {
  184479. delete info;
  184480. control = 0;
  184481. originalWndProc = 0;
  184482. }
  184483. }
  184484. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184485. {
  184486. ActiveXControlData* const info = (ActiveXControlData*) control;
  184487. void* result = 0;
  184488. if (info != 0 && info->control != 0
  184489. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184490. return result;
  184491. return 0;
  184492. }
  184493. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184494. {
  184495. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184496. if (hwnd != 0)
  184497. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184498. }
  184499. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184500. {
  184501. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184502. if (hwnd != 0)
  184503. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184504. }
  184505. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184506. {
  184507. mouseEventsAllowed = eventsCanReachControl;
  184508. }
  184509. #endif
  184510. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184511. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184512. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184513. // compiled on its own).
  184514. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184515. using namespace QTOLibrary;
  184516. using namespace QTOControlLib;
  184517. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184518. static bool isQTAvailable = false;
  184519. class QuickTimeMovieComponent::Pimpl
  184520. {
  184521. public:
  184522. Pimpl() : dataHandle (0)
  184523. {
  184524. }
  184525. ~Pimpl()
  184526. {
  184527. clearHandle();
  184528. }
  184529. void clearHandle()
  184530. {
  184531. if (dataHandle != 0)
  184532. {
  184533. DisposeHandle (dataHandle);
  184534. dataHandle = 0;
  184535. }
  184536. }
  184537. IQTControlPtr qtControl;
  184538. IQTMoviePtr qtMovie;
  184539. Handle dataHandle;
  184540. };
  184541. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184542. : movieLoaded (false),
  184543. controllerVisible (true)
  184544. {
  184545. pimpl = new Pimpl();
  184546. setMouseEventsAllowed (false);
  184547. }
  184548. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184549. {
  184550. closeMovie();
  184551. pimpl->qtControl = 0;
  184552. deleteControl();
  184553. pimpl = 0;
  184554. }
  184555. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184556. {
  184557. if (! isQTAvailable)
  184558. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184559. return isQTAvailable;
  184560. }
  184561. void QuickTimeMovieComponent::createControlIfNeeded()
  184562. {
  184563. if (isShowing() && ! isControlCreated())
  184564. {
  184565. const IID qtIID = __uuidof (QTControl);
  184566. if (createControl (&qtIID))
  184567. {
  184568. const IID qtInterfaceIID = __uuidof (IQTControl);
  184569. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184570. if (pimpl->qtControl != 0)
  184571. {
  184572. pimpl->qtControl->Release(); // it has one ref too many at this point
  184573. pimpl->qtControl->QuickTimeInitialize();
  184574. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184575. if (movieFile != File::nonexistent)
  184576. loadMovie (movieFile, controllerVisible);
  184577. }
  184578. }
  184579. }
  184580. }
  184581. bool QuickTimeMovieComponent::isControlCreated() const
  184582. {
  184583. return isControlOpen();
  184584. }
  184585. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184586. const bool isControllerVisible)
  184587. {
  184588. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184589. movieFile = File::nonexistent;
  184590. movieLoaded = false;
  184591. pimpl->qtMovie = 0;
  184592. controllerVisible = isControllerVisible;
  184593. createControlIfNeeded();
  184594. if (isControlCreated())
  184595. {
  184596. if (pimpl->qtControl != 0)
  184597. {
  184598. pimpl->qtControl->Put_MovieHandle (0);
  184599. pimpl->clearHandle();
  184600. Movie movie;
  184601. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184602. {
  184603. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184604. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184605. if (pimpl->qtMovie != 0)
  184606. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184607. : qtMovieControllerTypeNone);
  184608. }
  184609. if (movie == 0)
  184610. pimpl->clearHandle();
  184611. }
  184612. movieLoaded = (pimpl->qtMovie != 0);
  184613. }
  184614. else
  184615. {
  184616. // You're trying to open a movie when the control hasn't yet been created, probably because
  184617. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184618. jassertfalse
  184619. }
  184620. return movieLoaded;
  184621. }
  184622. void QuickTimeMovieComponent::closeMovie()
  184623. {
  184624. stop();
  184625. movieFile = File::nonexistent;
  184626. movieLoaded = false;
  184627. pimpl->qtMovie = 0;
  184628. if (pimpl->qtControl != 0)
  184629. pimpl->qtControl->Put_MovieHandle (0);
  184630. pimpl->clearHandle();
  184631. }
  184632. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184633. {
  184634. return movieFile;
  184635. }
  184636. bool QuickTimeMovieComponent::isMovieOpen() const
  184637. {
  184638. return movieLoaded;
  184639. }
  184640. double QuickTimeMovieComponent::getMovieDuration() const
  184641. {
  184642. if (pimpl->qtMovie != 0)
  184643. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184644. return 0.0;
  184645. }
  184646. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184647. {
  184648. if (pimpl->qtMovie != 0)
  184649. {
  184650. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184651. width = r.right - r.left;
  184652. height = r.bottom - r.top;
  184653. }
  184654. else
  184655. {
  184656. width = height = 0;
  184657. }
  184658. }
  184659. void QuickTimeMovieComponent::play()
  184660. {
  184661. if (pimpl->qtMovie != 0)
  184662. pimpl->qtMovie->Play();
  184663. }
  184664. void QuickTimeMovieComponent::stop()
  184665. {
  184666. if (pimpl->qtMovie != 0)
  184667. pimpl->qtMovie->Stop();
  184668. }
  184669. bool QuickTimeMovieComponent::isPlaying() const
  184670. {
  184671. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184672. }
  184673. void QuickTimeMovieComponent::setPosition (const double seconds)
  184674. {
  184675. if (pimpl->qtMovie != 0)
  184676. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184677. }
  184678. double QuickTimeMovieComponent::getPosition() const
  184679. {
  184680. if (pimpl->qtMovie != 0)
  184681. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184682. return 0.0;
  184683. }
  184684. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184685. {
  184686. if (pimpl->qtMovie != 0)
  184687. pimpl->qtMovie->PutRate (newSpeed);
  184688. }
  184689. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184690. {
  184691. if (pimpl->qtMovie != 0)
  184692. {
  184693. pimpl->qtMovie->PutAudioVolume (newVolume);
  184694. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184695. }
  184696. }
  184697. float QuickTimeMovieComponent::getMovieVolume() const
  184698. {
  184699. if (pimpl->qtMovie != 0)
  184700. return pimpl->qtMovie->GetAudioVolume();
  184701. return 0.0f;
  184702. }
  184703. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184704. {
  184705. if (pimpl->qtMovie != 0)
  184706. pimpl->qtMovie->PutLoop (shouldLoop);
  184707. }
  184708. bool QuickTimeMovieComponent::isLooping() const
  184709. {
  184710. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184711. }
  184712. bool QuickTimeMovieComponent::isControllerVisible() const
  184713. {
  184714. return controllerVisible;
  184715. }
  184716. void QuickTimeMovieComponent::parentHierarchyChanged()
  184717. {
  184718. createControlIfNeeded();
  184719. QTCompBaseClass::parentHierarchyChanged();
  184720. }
  184721. void QuickTimeMovieComponent::visibilityChanged()
  184722. {
  184723. createControlIfNeeded();
  184724. QTCompBaseClass::visibilityChanged();
  184725. }
  184726. void QuickTimeMovieComponent::paint (Graphics& g)
  184727. {
  184728. if (! isControlCreated())
  184729. g.fillAll (Colours::black);
  184730. }
  184731. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184732. {
  184733. Handle dataRef = 0;
  184734. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184735. if (err == noErr)
  184736. {
  184737. Str255 suffix;
  184738. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184739. StringPtr name = suffix;
  184740. err = PtrAndHand (name, dataRef, name[0] + 1);
  184741. if (err == noErr)
  184742. {
  184743. long atoms[3];
  184744. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184745. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184746. atoms[2] = EndianU32_NtoB (MovieFileType);
  184747. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184748. if (err == noErr)
  184749. return dataRef;
  184750. }
  184751. DisposeHandle (dataRef);
  184752. }
  184753. return 0;
  184754. }
  184755. static CFStringRef juceStringToCFString (const String& s)
  184756. {
  184757. const int len = s.length();
  184758. const juce_wchar* const t = s;
  184759. HeapBlock <UniChar> temp (len + 2);
  184760. for (int i = 0; i <= len; ++i)
  184761. temp[i] = t[i];
  184762. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184763. }
  184764. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184765. {
  184766. Boolean trueBool = true;
  184767. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184768. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184769. props[prop].propValueSize = sizeof (trueBool);
  184770. props[prop].propValueAddress = &trueBool;
  184771. ++prop;
  184772. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184773. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184774. props[prop].propValueSize = sizeof (trueBool);
  184775. props[prop].propValueAddress = &trueBool;
  184776. ++prop;
  184777. Boolean isActive = true;
  184778. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184779. props[prop].propID = kQTNewMoviePropertyID_Active;
  184780. props[prop].propValueSize = sizeof (isActive);
  184781. props[prop].propValueAddress = &isActive;
  184782. ++prop;
  184783. MacSetPort (0);
  184784. jassert (prop <= 5);
  184785. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184786. return err == noErr;
  184787. }
  184788. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184789. {
  184790. if (input == 0)
  184791. return false;
  184792. dataHandle = 0;
  184793. bool ok = false;
  184794. QTNewMoviePropertyElement props[5];
  184795. zeromem (props, sizeof (props));
  184796. int prop = 0;
  184797. DataReferenceRecord dr;
  184798. props[prop].propClass = kQTPropertyClass_DataLocation;
  184799. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184800. props[prop].propValueSize = sizeof (dr);
  184801. props[prop].propValueAddress = &dr;
  184802. ++prop;
  184803. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184804. if (fin != 0)
  184805. {
  184806. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184807. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184808. &dr.dataRef, &dr.dataRefType);
  184809. ok = openMovie (props, prop, movie);
  184810. DisposeHandle (dr.dataRef);
  184811. CFRelease (filePath);
  184812. }
  184813. else
  184814. {
  184815. // sanity-check because this currently needs to load the whole stream into memory..
  184816. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184817. dataHandle = NewHandle ((Size) input->getTotalLength());
  184818. HLock (dataHandle);
  184819. // read the entire stream into memory - this is a pain, but can't get it to work
  184820. // properly using a custom callback to supply the data.
  184821. input->read (*dataHandle, (int) input->getTotalLength());
  184822. HUnlock (dataHandle);
  184823. // different types to get QT to try. (We should really be a bit smarter here by
  184824. // working out in advance which one the stream contains, rather than just trying
  184825. // each one)
  184826. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184827. "\04.avi", "\04.m4a" };
  184828. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184829. {
  184830. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184831. dr.dataRefType = HandleDataHandlerSubType;
  184832. ok = openMovie (props, prop, movie);
  184833. DisposeHandle (dr.dataRef);
  184834. }
  184835. }
  184836. return ok;
  184837. }
  184838. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184839. const bool isControllerVisible)
  184840. {
  184841. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184842. movieFile = movieFile_;
  184843. return ok;
  184844. }
  184845. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184846. const bool isControllerVisible)
  184847. {
  184848. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184849. }
  184850. void QuickTimeMovieComponent::goToStart()
  184851. {
  184852. setPosition (0.0);
  184853. }
  184854. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184855. const RectanglePlacement& placement)
  184856. {
  184857. int normalWidth, normalHeight;
  184858. getMovieNormalSize (normalWidth, normalHeight);
  184859. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184860. {
  184861. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184862. placement.applyTo (x, y, w, h,
  184863. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184864. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184865. if (w > 0 && h > 0)
  184866. {
  184867. setBounds (roundToInt (x), roundToInt (y),
  184868. roundToInt (w), roundToInt (h));
  184869. }
  184870. }
  184871. else
  184872. {
  184873. setBounds (spaceToFitWithin);
  184874. }
  184875. }
  184876. #endif
  184877. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184878. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184879. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184880. // compiled on its own).
  184881. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184882. class WebBrowserComponentInternal : public ActiveXControlComponent
  184883. {
  184884. public:
  184885. WebBrowserComponentInternal()
  184886. : browser (0),
  184887. connectionPoint (0),
  184888. adviseCookie (0)
  184889. {
  184890. }
  184891. ~WebBrowserComponentInternal()
  184892. {
  184893. if (connectionPoint != 0)
  184894. connectionPoint->Unadvise (adviseCookie);
  184895. if (browser != 0)
  184896. browser->Release();
  184897. }
  184898. void createBrowser()
  184899. {
  184900. createControl (&CLSID_WebBrowser);
  184901. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  184902. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  184903. if (connectionPointContainer != 0)
  184904. {
  184905. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  184906. &connectionPoint);
  184907. if (connectionPoint != 0)
  184908. {
  184909. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  184910. jassert (owner != 0);
  184911. EventHandler* handler = new EventHandler (owner);
  184912. connectionPoint->Advise (handler, &adviseCookie);
  184913. }
  184914. }
  184915. }
  184916. void goToURL (const String& url,
  184917. const StringArray* headers,
  184918. const MemoryBlock* postData)
  184919. {
  184920. if (browser != 0)
  184921. {
  184922. LPSAFEARRAY sa = 0;
  184923. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  184924. VariantInit (&flags);
  184925. VariantInit (&frame);
  184926. VariantInit (&postDataVar);
  184927. VariantInit (&headersVar);
  184928. if (headers != 0)
  184929. {
  184930. V_VT (&headersVar) = VT_BSTR;
  184931. V_BSTR (&headersVar) = SysAllocString ((const OLECHAR*) headers->joinIntoString ("\r\n"));
  184932. }
  184933. if (postData != 0 && postData->getSize() > 0)
  184934. {
  184935. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  184936. if (sa != 0)
  184937. {
  184938. void* data = 0;
  184939. SafeArrayAccessData (sa, &data);
  184940. jassert (data != 0);
  184941. if (data != 0)
  184942. {
  184943. postData->copyTo (data, 0, postData->getSize());
  184944. SafeArrayUnaccessData (sa);
  184945. VARIANT postDataVar2;
  184946. VariantInit (&postDataVar2);
  184947. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  184948. V_ARRAY (&postDataVar2) = sa;
  184949. postDataVar = postDataVar2;
  184950. }
  184951. }
  184952. }
  184953. browser->Navigate ((BSTR) (const OLECHAR*) url,
  184954. &flags, &frame,
  184955. &postDataVar, &headersVar);
  184956. if (sa != 0)
  184957. SafeArrayDestroy (sa);
  184958. VariantClear (&flags);
  184959. VariantClear (&frame);
  184960. VariantClear (&postDataVar);
  184961. VariantClear (&headersVar);
  184962. }
  184963. }
  184964. IWebBrowser2* browser;
  184965. juce_UseDebuggingNewOperator
  184966. private:
  184967. IConnectionPoint* connectionPoint;
  184968. DWORD adviseCookie;
  184969. class EventHandler : public IDispatch,
  184970. public ComponentMovementWatcher
  184971. {
  184972. public:
  184973. EventHandler (WebBrowserComponent* owner_)
  184974. : ComponentMovementWatcher (owner_),
  184975. owner (owner_),
  184976. refCount (0)
  184977. {
  184978. }
  184979. ~EventHandler()
  184980. {
  184981. }
  184982. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184983. {
  184984. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  184985. {
  184986. AddRef();
  184987. *result = this;
  184988. return S_OK;
  184989. }
  184990. *result = 0;
  184991. return E_NOINTERFACE;
  184992. }
  184993. ULONG __stdcall AddRef() { return ++refCount; }
  184994. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184995. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  184996. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  184997. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  184998. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  184999. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185000. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185001. UINT __RPC_FAR* /*puArgErr*/)
  185002. {
  185003. switch (dispIdMember)
  185004. {
  185005. case DISPID_BEFORENAVIGATE2:
  185006. {
  185007. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185008. String url;
  185009. if ((vurl->vt & VT_BYREF) != 0)
  185010. url = *vurl->pbstrVal;
  185011. else
  185012. url = vurl->bstrVal;
  185013. *pDispParams->rgvarg->pboolVal
  185014. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185015. : VARIANT_TRUE;
  185016. return S_OK;
  185017. }
  185018. default:
  185019. break;
  185020. }
  185021. return E_NOTIMPL;
  185022. }
  185023. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185024. void componentPeerChanged() {}
  185025. void componentVisibilityChanged (Component&)
  185026. {
  185027. owner->visibilityChanged();
  185028. }
  185029. juce_UseDebuggingNewOperator
  185030. private:
  185031. WebBrowserComponent* const owner;
  185032. int refCount;
  185033. EventHandler (const EventHandler&);
  185034. EventHandler& operator= (const EventHandler&);
  185035. };
  185036. };
  185037. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185038. : browser (0),
  185039. blankPageShown (false),
  185040. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185041. {
  185042. setOpaque (true);
  185043. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185044. }
  185045. WebBrowserComponent::~WebBrowserComponent()
  185046. {
  185047. delete browser;
  185048. }
  185049. void WebBrowserComponent::goToURL (const String& url,
  185050. const StringArray* headers,
  185051. const MemoryBlock* postData)
  185052. {
  185053. lastURL = url;
  185054. lastHeaders.clear();
  185055. if (headers != 0)
  185056. lastHeaders = *headers;
  185057. lastPostData.setSize (0);
  185058. if (postData != 0)
  185059. lastPostData = *postData;
  185060. blankPageShown = false;
  185061. browser->goToURL (url, headers, postData);
  185062. }
  185063. void WebBrowserComponent::stop()
  185064. {
  185065. if (browser->browser != 0)
  185066. browser->browser->Stop();
  185067. }
  185068. void WebBrowserComponent::goBack()
  185069. {
  185070. lastURL = String::empty;
  185071. blankPageShown = false;
  185072. if (browser->browser != 0)
  185073. browser->browser->GoBack();
  185074. }
  185075. void WebBrowserComponent::goForward()
  185076. {
  185077. lastURL = String::empty;
  185078. if (browser->browser != 0)
  185079. browser->browser->GoForward();
  185080. }
  185081. void WebBrowserComponent::refresh()
  185082. {
  185083. if (browser->browser != 0)
  185084. browser->browser->Refresh();
  185085. }
  185086. void WebBrowserComponent::paint (Graphics& g)
  185087. {
  185088. if (browser->browser == 0)
  185089. g.fillAll (Colours::white);
  185090. }
  185091. void WebBrowserComponent::checkWindowAssociation()
  185092. {
  185093. if (isShowing())
  185094. {
  185095. if (browser->browser == 0 && getPeer() != 0)
  185096. {
  185097. browser->createBrowser();
  185098. reloadLastURL();
  185099. }
  185100. else
  185101. {
  185102. if (blankPageShown)
  185103. goBack();
  185104. }
  185105. }
  185106. else
  185107. {
  185108. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185109. {
  185110. // when the component becomes invisible, some stuff like flash
  185111. // carries on playing audio, so we need to force it onto a blank
  185112. // page to avoid this..
  185113. blankPageShown = true;
  185114. browser->goToURL ("about:blank", 0, 0);
  185115. }
  185116. }
  185117. }
  185118. void WebBrowserComponent::reloadLastURL()
  185119. {
  185120. if (lastURL.isNotEmpty())
  185121. {
  185122. goToURL (lastURL, &lastHeaders, &lastPostData);
  185123. lastURL = String::empty;
  185124. }
  185125. }
  185126. void WebBrowserComponent::parentHierarchyChanged()
  185127. {
  185128. checkWindowAssociation();
  185129. }
  185130. void WebBrowserComponent::resized()
  185131. {
  185132. browser->setSize (getWidth(), getHeight());
  185133. }
  185134. void WebBrowserComponent::visibilityChanged()
  185135. {
  185136. checkWindowAssociation();
  185137. }
  185138. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185139. {
  185140. return true;
  185141. }
  185142. #endif
  185143. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185144. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185145. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185146. // compiled on its own).
  185147. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185148. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185149. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185150. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185151. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185152. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185153. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185154. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185155. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185156. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185157. #define WGL_ACCELERATION_ARB 0x2003
  185158. #define WGL_SWAP_METHOD_ARB 0x2007
  185159. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185160. #define WGL_PIXEL_TYPE_ARB 0x2013
  185161. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185162. #define WGL_COLOR_BITS_ARB 0x2014
  185163. #define WGL_RED_BITS_ARB 0x2015
  185164. #define WGL_GREEN_BITS_ARB 0x2017
  185165. #define WGL_BLUE_BITS_ARB 0x2019
  185166. #define WGL_ALPHA_BITS_ARB 0x201B
  185167. #define WGL_DEPTH_BITS_ARB 0x2022
  185168. #define WGL_STENCIL_BITS_ARB 0x2023
  185169. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185170. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185171. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185172. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185173. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185174. #define WGL_STEREO_ARB 0x2012
  185175. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185176. #define WGL_SAMPLES_ARB 0x2042
  185177. #define WGL_TYPE_RGBA_ARB 0x202B
  185178. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185179. {
  185180. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185181. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185182. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185183. else
  185184. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185185. }
  185186. class WindowedGLContext : public OpenGLContext
  185187. {
  185188. public:
  185189. WindowedGLContext (Component* const component_,
  185190. HGLRC contextToShareWith,
  185191. const OpenGLPixelFormat& pixelFormat)
  185192. : renderContext (0),
  185193. nativeWindow (0),
  185194. dc (0),
  185195. component (component_)
  185196. {
  185197. jassert (component != 0);
  185198. createNativeWindow();
  185199. // Use a default pixel format that should be supported everywhere
  185200. PIXELFORMATDESCRIPTOR pfd;
  185201. zerostruct (pfd);
  185202. pfd.nSize = sizeof (pfd);
  185203. pfd.nVersion = 1;
  185204. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185205. pfd.iPixelType = PFD_TYPE_RGBA;
  185206. pfd.cColorBits = 24;
  185207. pfd.cDepthBits = 16;
  185208. const int format = ChoosePixelFormat (dc, &pfd);
  185209. if (format != 0)
  185210. SetPixelFormat (dc, format, &pfd);
  185211. renderContext = wglCreateContext (dc);
  185212. makeActive();
  185213. setPixelFormat (pixelFormat);
  185214. if (contextToShareWith != 0 && renderContext != 0)
  185215. wglShareLists (contextToShareWith, renderContext);
  185216. }
  185217. ~WindowedGLContext()
  185218. {
  185219. makeInactive();
  185220. wglDeleteContext (renderContext);
  185221. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185222. delete nativeWindow;
  185223. }
  185224. bool makeActive() const throw()
  185225. {
  185226. jassert (renderContext != 0);
  185227. return wglMakeCurrent (dc, renderContext) != 0;
  185228. }
  185229. bool makeInactive() const throw()
  185230. {
  185231. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185232. }
  185233. bool isActive() const throw()
  185234. {
  185235. return wglGetCurrentContext() == renderContext;
  185236. }
  185237. const OpenGLPixelFormat getPixelFormat() const
  185238. {
  185239. OpenGLPixelFormat pf;
  185240. makeActive();
  185241. StringArray availableExtensions;
  185242. getWglExtensions (dc, availableExtensions);
  185243. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185244. return pf;
  185245. }
  185246. void* getRawContext() const throw()
  185247. {
  185248. return renderContext;
  185249. }
  185250. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185251. {
  185252. makeActive();
  185253. PIXELFORMATDESCRIPTOR pfd;
  185254. zerostruct (pfd);
  185255. pfd.nSize = sizeof (pfd);
  185256. pfd.nVersion = 1;
  185257. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185258. pfd.iPixelType = PFD_TYPE_RGBA;
  185259. pfd.iLayerType = PFD_MAIN_PLANE;
  185260. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185261. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185262. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185263. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185264. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185265. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185266. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185267. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185268. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185269. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185270. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185271. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185272. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185273. int format = 0;
  185274. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185275. StringArray availableExtensions;
  185276. getWglExtensions (dc, availableExtensions);
  185277. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185278. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185279. {
  185280. int attributes[64];
  185281. int n = 0;
  185282. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185283. attributes[n++] = GL_TRUE;
  185284. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185285. attributes[n++] = GL_TRUE;
  185286. attributes[n++] = WGL_ACCELERATION_ARB;
  185287. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185288. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185289. attributes[n++] = GL_TRUE;
  185290. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185291. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185292. attributes[n++] = WGL_COLOR_BITS_ARB;
  185293. attributes[n++] = pfd.cColorBits;
  185294. attributes[n++] = WGL_RED_BITS_ARB;
  185295. attributes[n++] = pixelFormat.redBits;
  185296. attributes[n++] = WGL_GREEN_BITS_ARB;
  185297. attributes[n++] = pixelFormat.greenBits;
  185298. attributes[n++] = WGL_BLUE_BITS_ARB;
  185299. attributes[n++] = pixelFormat.blueBits;
  185300. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185301. attributes[n++] = pixelFormat.alphaBits;
  185302. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185303. attributes[n++] = pixelFormat.depthBufferBits;
  185304. if (pixelFormat.stencilBufferBits > 0)
  185305. {
  185306. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185307. attributes[n++] = pixelFormat.stencilBufferBits;
  185308. }
  185309. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185310. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185311. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185312. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185313. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185314. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185315. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185316. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185317. if (availableExtensions.contains ("WGL_ARB_multisample")
  185318. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185319. {
  185320. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185321. attributes[n++] = 1;
  185322. attributes[n++] = WGL_SAMPLES_ARB;
  185323. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185324. }
  185325. attributes[n++] = 0;
  185326. UINT formatsCount;
  185327. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185328. (void) ok;
  185329. jassert (ok);
  185330. }
  185331. else
  185332. {
  185333. format = ChoosePixelFormat (dc, &pfd);
  185334. }
  185335. if (format != 0)
  185336. {
  185337. makeInactive();
  185338. // win32 can't change the pixel format of a window, so need to delete the
  185339. // old one and create a new one..
  185340. jassert (nativeWindow != 0);
  185341. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185342. delete nativeWindow;
  185343. createNativeWindow();
  185344. if (SetPixelFormat (dc, format, &pfd))
  185345. {
  185346. wglDeleteContext (renderContext);
  185347. renderContext = wglCreateContext (dc);
  185348. jassert (renderContext != 0);
  185349. return renderContext != 0;
  185350. }
  185351. }
  185352. return false;
  185353. }
  185354. void updateWindowPosition (int x, int y, int w, int h, int)
  185355. {
  185356. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185357. x, y, w, h,
  185358. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185359. }
  185360. void repaint()
  185361. {
  185362. const Rectangle<int> bounds (nativeWindow->getBounds());
  185363. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185364. }
  185365. void swapBuffers()
  185366. {
  185367. SwapBuffers (dc);
  185368. }
  185369. bool setSwapInterval (int numFramesPerSwap)
  185370. {
  185371. makeActive();
  185372. StringArray availableExtensions;
  185373. getWglExtensions (dc, availableExtensions);
  185374. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185375. return availableExtensions.contains ("WGL_EXT_swap_control")
  185376. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185377. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185378. }
  185379. int getSwapInterval() const
  185380. {
  185381. makeActive();
  185382. StringArray availableExtensions;
  185383. getWglExtensions (dc, availableExtensions);
  185384. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185385. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185386. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185387. return wglGetSwapIntervalEXT();
  185388. return 0;
  185389. }
  185390. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185391. {
  185392. jassert (isActive());
  185393. StringArray availableExtensions;
  185394. getWglExtensions (dc, availableExtensions);
  185395. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185396. int numTypes = 0;
  185397. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185398. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185399. {
  185400. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185401. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185402. jassertfalse
  185403. }
  185404. else
  185405. {
  185406. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185407. }
  185408. OpenGLPixelFormat pf;
  185409. for (int i = 0; i < numTypes; ++i)
  185410. {
  185411. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185412. {
  185413. bool alreadyListed = false;
  185414. for (int j = results.size(); --j >= 0;)
  185415. if (pf == *results.getUnchecked(j))
  185416. alreadyListed = true;
  185417. if (! alreadyListed)
  185418. results.add (new OpenGLPixelFormat (pf));
  185419. }
  185420. }
  185421. }
  185422. void* getNativeWindowHandle() const
  185423. {
  185424. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185425. }
  185426. juce_UseDebuggingNewOperator
  185427. HGLRC renderContext;
  185428. private:
  185429. Win32ComponentPeer* nativeWindow;
  185430. Component* const component;
  185431. HDC dc;
  185432. void createNativeWindow()
  185433. {
  185434. nativeWindow = new Win32ComponentPeer (component, 0);
  185435. nativeWindow->dontRepaint = true;
  185436. nativeWindow->setVisible (true);
  185437. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185438. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185439. if (peer != 0)
  185440. {
  185441. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185442. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185443. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185444. }
  185445. dc = GetDC (hwnd);
  185446. }
  185447. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185448. OpenGLPixelFormat& result,
  185449. const StringArray& availableExtensions) const throw()
  185450. {
  185451. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185452. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185453. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185454. {
  185455. int attributes[32];
  185456. int numAttributes = 0;
  185457. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185458. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185459. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185460. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185461. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185462. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185463. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185464. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185465. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185466. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185467. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185468. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185469. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185470. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185471. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185472. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185473. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185474. int values[32];
  185475. zeromem (values, sizeof (values));
  185476. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185477. {
  185478. int n = 0;
  185479. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185480. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185481. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185482. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185483. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185484. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185485. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185486. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185487. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185488. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185489. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185490. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185491. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185492. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185493. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185494. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185495. return isValidFormat;
  185496. }
  185497. else
  185498. {
  185499. jassertfalse
  185500. }
  185501. }
  185502. else
  185503. {
  185504. PIXELFORMATDESCRIPTOR pfd;
  185505. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185506. {
  185507. result.redBits = pfd.cRedBits;
  185508. result.greenBits = pfd.cGreenBits;
  185509. result.blueBits = pfd.cBlueBits;
  185510. result.alphaBits = pfd.cAlphaBits;
  185511. result.depthBufferBits = pfd.cDepthBits;
  185512. result.stencilBufferBits = pfd.cStencilBits;
  185513. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185514. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185515. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185516. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185517. result.fullSceneAntiAliasingNumSamples = 0;
  185518. return true;
  185519. }
  185520. else
  185521. {
  185522. jassertfalse
  185523. }
  185524. }
  185525. return false;
  185526. }
  185527. WindowedGLContext (const WindowedGLContext&);
  185528. WindowedGLContext& operator= (const WindowedGLContext&);
  185529. };
  185530. OpenGLContext* OpenGLComponent::createContext()
  185531. {
  185532. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185533. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185534. preferredPixelFormat));
  185535. return (c->renderContext != 0) ? c.release() : 0;
  185536. }
  185537. void* OpenGLComponent::getNativeWindowHandle() const
  185538. {
  185539. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle() : 0;
  185540. }
  185541. void juce_glViewport (const int w, const int h)
  185542. {
  185543. glViewport (0, 0, w, h);
  185544. }
  185545. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185546. OwnedArray <OpenGLPixelFormat>& results)
  185547. {
  185548. Component tempComp;
  185549. {
  185550. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185551. wc.makeActive();
  185552. wc.findAlternativeOpenGLPixelFormats (results);
  185553. }
  185554. }
  185555. #endif
  185556. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185557. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185558. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185559. // compiled on its own).
  185560. #if JUCE_INCLUDED_FILE
  185561. #if JUCE_USE_CDREADER
  185562. namespace CDReaderHelpers
  185563. {
  185564. //***************************************************************************
  185565. // %%% TARGET STATUS VALUES %%%
  185566. //***************************************************************************
  185567. #define STATUS_GOOD 0x00 // Status Good
  185568. #define STATUS_CHKCOND 0x02 // Check Condition
  185569. #define STATUS_CONDMET 0x04 // Condition Met
  185570. #define STATUS_BUSY 0x08 // Busy
  185571. #define STATUS_INTERM 0x10 // Intermediate
  185572. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185573. #define STATUS_RESCONF 0x18 // Reservation conflict
  185574. #define STATUS_COMTERM 0x22 // Command Terminated
  185575. #define STATUS_QFULL 0x28 // Queue full
  185576. //***************************************************************************
  185577. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185578. //***************************************************************************
  185579. #define MAXLUN 7 // Maximum Logical Unit Id
  185580. #define MAXTARG 7 // Maximum Target Id
  185581. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185582. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185583. //***************************************************************************
  185584. // %%% Commands for all Device Types %%%
  185585. //***************************************************************************
  185586. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185587. #define SCSI_COMPARE 0x39 // Compare (O)
  185588. #define SCSI_COPY 0x18 // Copy (O)
  185589. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185590. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185591. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185592. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185593. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185594. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185595. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185596. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185597. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185598. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185599. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185600. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185601. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185602. //***************************************************************************
  185603. // %%% Commands Unique to Direct Access Devices %%%
  185604. //***************************************************************************
  185605. #define SCSI_COMPARE 0x39 // Compare (O)
  185606. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185607. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185608. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185609. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185610. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185611. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185612. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185613. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185614. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185615. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185616. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185617. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185618. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185619. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185620. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185621. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185622. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185623. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185624. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185625. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185626. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185627. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185628. #define SCSI_VERIFY 0x2F // Verify (O)
  185629. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185630. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185631. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185632. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185633. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185634. //***************************************************************************
  185635. // %%% Commands Unique to Sequential Access Devices %%%
  185636. //***************************************************************************
  185637. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185638. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185639. #define SCSI_LOCATE 0x2B // Locate (O)
  185640. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185641. #define SCSI_READ_POS 0x34 // Read Position (O)
  185642. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185643. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185644. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185645. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185646. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185647. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185648. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185649. //***************************************************************************
  185650. // %%% Commands Unique to Printer Devices %%%
  185651. //***************************************************************************
  185652. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185653. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185654. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185655. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185656. //***************************************************************************
  185657. // %%% Commands Unique to Processor Devices %%%
  185658. //***************************************************************************
  185659. #define SCSI_RECEIVE 0x08 // Receive (O)
  185660. #define SCSI_SEND 0x0A // Send (O)
  185661. //***************************************************************************
  185662. // %%% Commands Unique to Write-Once Devices %%%
  185663. //***************************************************************************
  185664. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185665. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185666. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185667. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185668. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185669. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185670. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185671. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185672. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185673. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185674. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185675. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185676. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185677. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185678. //***************************************************************************
  185679. // %%% Commands Unique to CD-ROM Devices %%%
  185680. //***************************************************************************
  185681. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185682. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185683. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185684. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185685. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185686. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185687. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185688. #define SCSI_READHEADER 0x44 // Read Header (O)
  185689. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185690. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185691. //***************************************************************************
  185692. // %%% Commands Unique to Scanner Devices %%%
  185693. //***************************************************************************
  185694. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185695. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185696. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185697. #define SCSI_SCAN 0x1B // Scan (O)
  185698. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185699. //***************************************************************************
  185700. // %%% Commands Unique to Optical Memory Devices %%%
  185701. //***************************************************************************
  185702. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185703. //***************************************************************************
  185704. // %%% Commands Unique to Medium Changer Devices %%%
  185705. //***************************************************************************
  185706. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185707. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185708. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185709. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185710. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185711. //***************************************************************************
  185712. // %%% Commands Unique to Communication Devices %%%
  185713. //***************************************************************************
  185714. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185715. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185716. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185717. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185718. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185719. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185720. //***************************************************************************
  185721. // %%% Request Sense Data Format %%%
  185722. //***************************************************************************
  185723. typedef struct {
  185724. BYTE ErrorCode; // Error Code (70H or 71H)
  185725. BYTE SegmentNum; // Number of current segment descriptor
  185726. BYTE SenseKey; // Sense Key(See bit definitions too)
  185727. BYTE InfoByte0; // Information MSB
  185728. BYTE InfoByte1; // Information MID
  185729. BYTE InfoByte2; // Information MID
  185730. BYTE InfoByte3; // Information LSB
  185731. BYTE AddSenLen; // Additional Sense Length
  185732. BYTE ComSpecInf0; // Command Specific Information MSB
  185733. BYTE ComSpecInf1; // Command Specific Information MID
  185734. BYTE ComSpecInf2; // Command Specific Information MID
  185735. BYTE ComSpecInf3; // Command Specific Information LSB
  185736. BYTE AddSenseCode; // Additional Sense Code
  185737. BYTE AddSenQual; // Additional Sense Code Qualifier
  185738. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185739. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185740. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185741. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185742. BYTE AddSenseBytes; // Additional Sense Bytes
  185743. } SENSE_DATA_FMT;
  185744. //***************************************************************************
  185745. // %%% REQUEST SENSE ERROR CODE %%%
  185746. //***************************************************************************
  185747. #define SERROR_CURRENT 0x70 // Current Errors
  185748. #define SERROR_DEFERED 0x71 // Deferred Errors
  185749. //***************************************************************************
  185750. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185751. //***************************************************************************
  185752. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185753. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185754. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185755. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185756. //***************************************************************************
  185757. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185758. //***************************************************************************
  185759. #define KEY_NOSENSE 0x00 // No Sense
  185760. #define KEY_RECERROR 0x01 // Recovered Error
  185761. #define KEY_NOTREADY 0x02 // Not Ready
  185762. #define KEY_MEDIUMERR 0x03 // Medium Error
  185763. #define KEY_HARDERROR 0x04 // Hardware Error
  185764. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185765. #define KEY_UNITATT 0x06 // Unit Attention
  185766. #define KEY_DATAPROT 0x07 // Data Protect
  185767. #define KEY_BLANKCHK 0x08 // Blank Check
  185768. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185769. #define KEY_COPYABORT 0x0A // Copy Abort
  185770. #define KEY_EQUAL 0x0C // Equal (Search)
  185771. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185772. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185773. #define KEY_RESERVED 0x0F // Reserved
  185774. //***************************************************************************
  185775. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185776. //***************************************************************************
  185777. #define DTYPE_DASD 0x00 // Disk Device
  185778. #define DTYPE_SEQD 0x01 // Tape Device
  185779. #define DTYPE_PRNT 0x02 // Printer
  185780. #define DTYPE_PROC 0x03 // Processor
  185781. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185782. #define DTYPE_CROM 0x05 // CD-ROM device
  185783. #define DTYPE_SCAN 0x06 // Scanner device
  185784. #define DTYPE_OPTI 0x07 // Optical memory device
  185785. #define DTYPE_JUKE 0x08 // Medium Changer device
  185786. #define DTYPE_COMM 0x09 // Communications device
  185787. #define DTYPE_RESL 0x0A // Reserved (low)
  185788. #define DTYPE_RESH 0x1E // Reserved (high)
  185789. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185790. //***************************************************************************
  185791. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185792. //***************************************************************************
  185793. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185794. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185795. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185796. #define ANSI_RESLO 0x3 // Reserved (low)
  185797. #define ANSI_RESHI 0x7 // Reserved (high)
  185798. typedef struct
  185799. {
  185800. USHORT Length;
  185801. UCHAR ScsiStatus;
  185802. UCHAR PathId;
  185803. UCHAR TargetId;
  185804. UCHAR Lun;
  185805. UCHAR CdbLength;
  185806. UCHAR SenseInfoLength;
  185807. UCHAR DataIn;
  185808. ULONG DataTransferLength;
  185809. ULONG TimeOutValue;
  185810. ULONG DataBufferOffset;
  185811. ULONG SenseInfoOffset;
  185812. UCHAR Cdb[16];
  185813. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185814. typedef struct
  185815. {
  185816. USHORT Length;
  185817. UCHAR ScsiStatus;
  185818. UCHAR PathId;
  185819. UCHAR TargetId;
  185820. UCHAR Lun;
  185821. UCHAR CdbLength;
  185822. UCHAR SenseInfoLength;
  185823. UCHAR DataIn;
  185824. ULONG DataTransferLength;
  185825. ULONG TimeOutValue;
  185826. PVOID DataBuffer;
  185827. ULONG SenseInfoOffset;
  185828. UCHAR Cdb[16];
  185829. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185830. typedef struct
  185831. {
  185832. SCSI_PASS_THROUGH_DIRECT spt;
  185833. ULONG Filler;
  185834. UCHAR ucSenseBuf[32];
  185835. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185836. typedef struct
  185837. {
  185838. ULONG Length;
  185839. UCHAR PortNumber;
  185840. UCHAR PathId;
  185841. UCHAR TargetId;
  185842. UCHAR Lun;
  185843. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185844. #define METHOD_BUFFERED 0
  185845. #define METHOD_IN_DIRECT 1
  185846. #define METHOD_OUT_DIRECT 2
  185847. #define METHOD_NEITHER 3
  185848. #define FILE_ANY_ACCESS 0
  185849. #ifndef FILE_READ_ACCESS
  185850. #define FILE_READ_ACCESS (0x0001)
  185851. #endif
  185852. #ifndef FILE_WRITE_ACCESS
  185853. #define FILE_WRITE_ACCESS (0x0002)
  185854. #endif
  185855. #define IOCTL_SCSI_BASE 0x00000004
  185856. #define SCSI_IOCTL_DATA_OUT 0
  185857. #define SCSI_IOCTL_DATA_IN 1
  185858. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185859. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185860. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185861. )
  185862. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185863. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185864. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185865. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185866. #define SENSE_LEN 14
  185867. #define SRB_DIR_SCSI 0x00
  185868. #define SRB_POSTING 0x01
  185869. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185870. #define SRB_DIR_IN 0x08
  185871. #define SRB_DIR_OUT 0x10
  185872. #define SRB_EVENT_NOTIFY 0x40
  185873. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185874. #define MAX_SRB_TIMEOUT 1080001u
  185875. #define DEFAULT_SRB_TIMEOUT 1080001u
  185876. #define SC_HA_INQUIRY 0x00
  185877. #define SC_GET_DEV_TYPE 0x01
  185878. #define SC_EXEC_SCSI_CMD 0x02
  185879. #define SC_ABORT_SRB 0x03
  185880. #define SC_RESET_DEV 0x04
  185881. #define SC_SET_HA_PARMS 0x05
  185882. #define SC_GET_DISK_INFO 0x06
  185883. #define SC_RESCAN_SCSI_BUS 0x07
  185884. #define SC_GETSET_TIMEOUTS 0x08
  185885. #define SS_PENDING 0x00
  185886. #define SS_COMP 0x01
  185887. #define SS_ABORTED 0x02
  185888. #define SS_ABORT_FAIL 0x03
  185889. #define SS_ERR 0x04
  185890. #define SS_INVALID_CMD 0x80
  185891. #define SS_INVALID_HA 0x81
  185892. #define SS_NO_DEVICE 0x82
  185893. #define SS_INVALID_SRB 0xE0
  185894. #define SS_OLD_MANAGER 0xE1
  185895. #define SS_BUFFER_ALIGN 0xE1
  185896. #define SS_ILLEGAL_MODE 0xE2
  185897. #define SS_NO_ASPI 0xE3
  185898. #define SS_FAILED_INIT 0xE4
  185899. #define SS_ASPI_IS_BUSY 0xE5
  185900. #define SS_BUFFER_TO_BIG 0xE6
  185901. #define SS_BUFFER_TOO_BIG 0xE6
  185902. #define SS_MISMATCHED_COMPONENTS 0xE7
  185903. #define SS_NO_ADAPTERS 0xE8
  185904. #define SS_INSUFFICIENT_RESOURCES 0xE9
  185905. #define SS_ASPI_IS_SHUTDOWN 0xEA
  185906. #define SS_BAD_INSTALL 0xEB
  185907. #define HASTAT_OK 0x00
  185908. #define HASTAT_SEL_TO 0x11
  185909. #define HASTAT_DO_DU 0x12
  185910. #define HASTAT_BUS_FREE 0x13
  185911. #define HASTAT_PHASE_ERR 0x14
  185912. #define HASTAT_TIMEOUT 0x09
  185913. #define HASTAT_COMMAND_TIMEOUT 0x0B
  185914. #define HASTAT_MESSAGE_REJECT 0x0D
  185915. #define HASTAT_BUS_RESET 0x0E
  185916. #define HASTAT_PARITY_ERROR 0x0F
  185917. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  185918. #define PACKED
  185919. #pragma pack(1)
  185920. typedef struct
  185921. {
  185922. BYTE SRB_Cmd;
  185923. BYTE SRB_Status;
  185924. BYTE SRB_HaID;
  185925. BYTE SRB_Flags;
  185926. DWORD SRB_Hdr_Rsvd;
  185927. BYTE HA_Count;
  185928. BYTE HA_SCSI_ID;
  185929. BYTE HA_ManagerId[16];
  185930. BYTE HA_Identifier[16];
  185931. BYTE HA_Unique[16];
  185932. WORD HA_Rsvd1;
  185933. BYTE pad[20];
  185934. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  185935. typedef struct
  185936. {
  185937. BYTE SRB_Cmd;
  185938. BYTE SRB_Status;
  185939. BYTE SRB_HaID;
  185940. BYTE SRB_Flags;
  185941. DWORD SRB_Hdr_Rsvd;
  185942. BYTE SRB_Target;
  185943. BYTE SRB_Lun;
  185944. BYTE SRB_DeviceType;
  185945. BYTE SRB_Rsvd1;
  185946. BYTE pad[68];
  185947. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  185948. typedef struct
  185949. {
  185950. BYTE SRB_Cmd;
  185951. BYTE SRB_Status;
  185952. BYTE SRB_HaID;
  185953. BYTE SRB_Flags;
  185954. DWORD SRB_Hdr_Rsvd;
  185955. BYTE SRB_Target;
  185956. BYTE SRB_Lun;
  185957. WORD SRB_Rsvd1;
  185958. DWORD SRB_BufLen;
  185959. BYTE FAR *SRB_BufPointer;
  185960. BYTE SRB_SenseLen;
  185961. BYTE SRB_CDBLen;
  185962. BYTE SRB_HaStat;
  185963. BYTE SRB_TargStat;
  185964. VOID FAR *SRB_PostProc;
  185965. BYTE SRB_Rsvd2[20];
  185966. BYTE CDBByte[16];
  185967. BYTE SenseArea[SENSE_LEN+2];
  185968. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  185969. typedef struct
  185970. {
  185971. BYTE SRB_Cmd;
  185972. BYTE SRB_Status;
  185973. BYTE SRB_HaId;
  185974. BYTE SRB_Flags;
  185975. DWORD SRB_Hdr_Rsvd;
  185976. } PACKED SRB, *PSRB, FAR *LPSRB;
  185977. #pragma pack()
  185978. struct CDDeviceInfo
  185979. {
  185980. char vendor[9];
  185981. char productId[17];
  185982. char rev[5];
  185983. char vendorSpec[21];
  185984. BYTE ha;
  185985. BYTE tgt;
  185986. BYTE lun;
  185987. char scsiDriveLetter; // will be 0 if not using scsi
  185988. };
  185989. class CDReadBuffer
  185990. {
  185991. public:
  185992. int startFrame;
  185993. int numFrames;
  185994. int dataStartOffset;
  185995. int dataLength;
  185996. BYTE* buffer;
  185997. int bufferSize;
  185998. int index;
  185999. bool wantsIndex;
  186000. CDReadBuffer (const int numberOfFrames)
  186001. : startFrame (0),
  186002. numFrames (0),
  186003. dataStartOffset (0),
  186004. dataLength (0),
  186005. index (0),
  186006. wantsIndex (false)
  186007. {
  186008. bufferSize = 2352 * numberOfFrames;
  186009. buffer = (BYTE*) juce_malloc (bufferSize);
  186010. }
  186011. ~CDReadBuffer()
  186012. {
  186013. juce_free (buffer);
  186014. }
  186015. bool isZero() const
  186016. {
  186017. BYTE* p = buffer + dataStartOffset;
  186018. for (int i = dataLength; --i >= 0;)
  186019. if (*p++ != 0)
  186020. return false;
  186021. return true;
  186022. }
  186023. };
  186024. class CDDeviceHandle;
  186025. class CDController
  186026. {
  186027. public:
  186028. CDController();
  186029. virtual ~CDController();
  186030. virtual bool read (CDReadBuffer* t) = 0;
  186031. virtual void shutDown();
  186032. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186033. int getLastIndex();
  186034. public:
  186035. bool initialised;
  186036. CDDeviceHandle* deviceInfo;
  186037. int framesToCheck, framesOverlap;
  186038. void prepare (SRB_ExecSCSICmd& s);
  186039. void perform (SRB_ExecSCSICmd& s);
  186040. void setPaused (bool paused);
  186041. };
  186042. #pragma pack(1)
  186043. struct TOCTRACK
  186044. {
  186045. BYTE rsvd;
  186046. BYTE ADR;
  186047. BYTE trackNumber;
  186048. BYTE rsvd2;
  186049. BYTE addr[4];
  186050. };
  186051. struct TOC
  186052. {
  186053. WORD tocLen;
  186054. BYTE firstTrack;
  186055. BYTE lastTrack;
  186056. TOCTRACK tracks[100];
  186057. };
  186058. #pragma pack()
  186059. enum
  186060. {
  186061. READTYPE_ANY = 0,
  186062. READTYPE_ATAPI1 = 1,
  186063. READTYPE_ATAPI2 = 2,
  186064. READTYPE_READ6 = 3,
  186065. READTYPE_READ10 = 4,
  186066. READTYPE_READ_D8 = 5,
  186067. READTYPE_READ_D4 = 6,
  186068. READTYPE_READ_D4_1 = 7,
  186069. READTYPE_READ10_2 = 8
  186070. };
  186071. class CDDeviceHandle
  186072. {
  186073. public:
  186074. CDDeviceHandle (const CDDeviceInfo* const device)
  186075. : scsiHandle (0),
  186076. readType (READTYPE_ANY),
  186077. controller (0)
  186078. {
  186079. memcpy (&info, device, sizeof (info));
  186080. }
  186081. ~CDDeviceHandle()
  186082. {
  186083. if (controller != 0)
  186084. {
  186085. controller->shutDown();
  186086. controller = 0;
  186087. }
  186088. if (scsiHandle != 0)
  186089. CloseHandle (scsiHandle);
  186090. }
  186091. bool readTOC (TOC* lpToc, bool useMSF);
  186092. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186093. void openDrawer (bool shouldBeOpen);
  186094. CDDeviceInfo info;
  186095. HANDLE scsiHandle;
  186096. BYTE readType;
  186097. private:
  186098. ScopedPointer<CDController> controller;
  186099. bool testController (const int readType,
  186100. CDController* const newController,
  186101. CDReadBuffer* const bufferToUse);
  186102. };
  186103. DWORD (*fGetASPI32SupportInfo)(void);
  186104. DWORD (*fSendASPI32Command)(LPSRB);
  186105. static HINSTANCE winAspiLib = 0;
  186106. static bool usingScsi = false;
  186107. static bool initialised = false;
  186108. static bool InitialiseCDRipper()
  186109. {
  186110. if (! initialised)
  186111. {
  186112. initialised = true;
  186113. OSVERSIONINFO info;
  186114. info.dwOSVersionInfoSize = sizeof (info);
  186115. GetVersionEx (&info);
  186116. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186117. if (! usingScsi)
  186118. {
  186119. fGetASPI32SupportInfo = 0;
  186120. fSendASPI32Command = 0;
  186121. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186122. if (winAspiLib != 0)
  186123. {
  186124. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186125. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186126. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186127. return false;
  186128. }
  186129. else
  186130. {
  186131. usingScsi = true;
  186132. }
  186133. }
  186134. }
  186135. return true;
  186136. }
  186137. static void DeinitialiseCDRipper()
  186138. {
  186139. if (winAspiLib != 0)
  186140. {
  186141. fGetASPI32SupportInfo = 0;
  186142. fSendASPI32Command = 0;
  186143. FreeLibrary (winAspiLib);
  186144. winAspiLib = 0;
  186145. }
  186146. initialised = false;
  186147. }
  186148. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186149. {
  186150. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186151. OSVERSIONINFO info;
  186152. info.dwOSVersionInfoSize = sizeof (info);
  186153. GetVersionEx (&info);
  186154. DWORD flags = GENERIC_READ;
  186155. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186156. flags = GENERIC_READ | GENERIC_WRITE;
  186157. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186158. if (h == INVALID_HANDLE_VALUE)
  186159. {
  186160. flags ^= GENERIC_WRITE;
  186161. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186162. }
  186163. return h;
  186164. }
  186165. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186166. const char driveLetter,
  186167. HANDLE& deviceHandle,
  186168. const bool retryOnFailure = true)
  186169. {
  186170. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186171. zerostruct (s);
  186172. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186173. s.spt.CdbLength = srb->SRB_CDBLen;
  186174. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186175. ? SCSI_IOCTL_DATA_IN
  186176. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186177. ? SCSI_IOCTL_DATA_OUT
  186178. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186179. s.spt.DataTransferLength = srb->SRB_BufLen;
  186180. s.spt.TimeOutValue = 5;
  186181. s.spt.DataBuffer = srb->SRB_BufPointer;
  186182. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186183. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186184. srb->SRB_Status = SS_ERR;
  186185. srb->SRB_TargStat = 0x0004;
  186186. DWORD bytesReturned = 0;
  186187. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186188. &s, sizeof (s),
  186189. &s, sizeof (s),
  186190. &bytesReturned, 0) != 0)
  186191. {
  186192. srb->SRB_Status = SS_COMP;
  186193. }
  186194. else if (retryOnFailure)
  186195. {
  186196. const DWORD error = GetLastError();
  186197. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186198. {
  186199. if (error != ERROR_INVALID_HANDLE)
  186200. CloseHandle (deviceHandle);
  186201. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186202. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186203. }
  186204. }
  186205. return srb->SRB_Status;
  186206. }
  186207. // Controller types..
  186208. class ControllerType1 : public CDController
  186209. {
  186210. public:
  186211. ControllerType1() {}
  186212. ~ControllerType1() {}
  186213. bool read (CDReadBuffer* rb)
  186214. {
  186215. if (rb->numFrames * 2352 > rb->bufferSize)
  186216. return false;
  186217. SRB_ExecSCSICmd s;
  186218. prepare (s);
  186219. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186220. s.SRB_BufLen = rb->bufferSize;
  186221. s.SRB_BufPointer = rb->buffer;
  186222. s.SRB_CDBLen = 12;
  186223. s.CDBByte[0] = 0xBE;
  186224. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186225. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186226. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186227. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186228. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186229. perform (s);
  186230. if (s.SRB_Status != SS_COMP)
  186231. return false;
  186232. rb->dataLength = rb->numFrames * 2352;
  186233. rb->dataStartOffset = 0;
  186234. return true;
  186235. }
  186236. };
  186237. class ControllerType2 : public CDController
  186238. {
  186239. public:
  186240. ControllerType2() {}
  186241. ~ControllerType2() {}
  186242. void shutDown()
  186243. {
  186244. if (initialised)
  186245. {
  186246. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186247. SRB_ExecSCSICmd s;
  186248. prepare (s);
  186249. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186250. s.SRB_BufLen = 0x0C;
  186251. s.SRB_BufPointer = bufPointer;
  186252. s.SRB_CDBLen = 6;
  186253. s.CDBByte[0] = 0x15;
  186254. s.CDBByte[4] = 0x0C;
  186255. perform (s);
  186256. }
  186257. }
  186258. bool init()
  186259. {
  186260. SRB_ExecSCSICmd s;
  186261. s.SRB_Status = SS_ERR;
  186262. if (deviceInfo->readType == READTYPE_READ10_2)
  186263. {
  186264. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186265. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186266. for (int i = 0; i < 2; ++i)
  186267. {
  186268. prepare (s);
  186269. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186270. s.SRB_BufLen = 0x14;
  186271. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186272. s.SRB_CDBLen = 6;
  186273. s.CDBByte[0] = 0x15;
  186274. s.CDBByte[1] = 0x10;
  186275. s.CDBByte[4] = 0x14;
  186276. perform (s);
  186277. if (s.SRB_Status != SS_COMP)
  186278. return false;
  186279. }
  186280. }
  186281. else
  186282. {
  186283. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186284. prepare (s);
  186285. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186286. s.SRB_BufLen = 0x0C;
  186287. s.SRB_BufPointer = bufPointer;
  186288. s.SRB_CDBLen = 6;
  186289. s.CDBByte[0] = 0x15;
  186290. s.CDBByte[4] = 0x0C;
  186291. perform (s);
  186292. }
  186293. return s.SRB_Status == SS_COMP;
  186294. }
  186295. bool read (CDReadBuffer* rb)
  186296. {
  186297. if (rb->numFrames * 2352 > rb->bufferSize)
  186298. return false;
  186299. if (!initialised)
  186300. {
  186301. initialised = init();
  186302. if (!initialised)
  186303. return false;
  186304. }
  186305. SRB_ExecSCSICmd s;
  186306. prepare (s);
  186307. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186308. s.SRB_BufLen = rb->bufferSize;
  186309. s.SRB_BufPointer = rb->buffer;
  186310. s.SRB_CDBLen = 10;
  186311. s.CDBByte[0] = 0x28;
  186312. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186313. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186314. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186315. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186316. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186317. perform (s);
  186318. if (s.SRB_Status != SS_COMP)
  186319. return false;
  186320. rb->dataLength = rb->numFrames * 2352;
  186321. rb->dataStartOffset = 0;
  186322. return true;
  186323. }
  186324. };
  186325. class ControllerType3 : public CDController
  186326. {
  186327. public:
  186328. ControllerType3() {}
  186329. ~ControllerType3() {}
  186330. bool read (CDReadBuffer* rb)
  186331. {
  186332. if (rb->numFrames * 2352 > rb->bufferSize)
  186333. return false;
  186334. if (!initialised)
  186335. {
  186336. setPaused (false);
  186337. initialised = true;
  186338. }
  186339. SRB_ExecSCSICmd s;
  186340. prepare (s);
  186341. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186342. s.SRB_BufLen = rb->numFrames * 2352;
  186343. s.SRB_BufPointer = rb->buffer;
  186344. s.SRB_CDBLen = 12;
  186345. s.CDBByte[0] = 0xD8;
  186346. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186347. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186348. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186349. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186350. perform (s);
  186351. if (s.SRB_Status != SS_COMP)
  186352. return false;
  186353. rb->dataLength = rb->numFrames * 2352;
  186354. rb->dataStartOffset = 0;
  186355. return true;
  186356. }
  186357. };
  186358. class ControllerType4 : public CDController
  186359. {
  186360. public:
  186361. ControllerType4() {}
  186362. ~ControllerType4() {}
  186363. bool selectD4Mode()
  186364. {
  186365. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186366. SRB_ExecSCSICmd s;
  186367. prepare (s);
  186368. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186369. s.SRB_CDBLen = 6;
  186370. s.SRB_BufLen = 12;
  186371. s.SRB_BufPointer = bufPointer;
  186372. s.CDBByte[0] = 0x15;
  186373. s.CDBByte[1] = 0x10;
  186374. s.CDBByte[4] = 0x08;
  186375. perform (s);
  186376. return s.SRB_Status == SS_COMP;
  186377. }
  186378. bool read (CDReadBuffer* rb)
  186379. {
  186380. if (rb->numFrames * 2352 > rb->bufferSize)
  186381. return false;
  186382. if (!initialised)
  186383. {
  186384. setPaused (true);
  186385. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186386. selectD4Mode();
  186387. initialised = true;
  186388. }
  186389. SRB_ExecSCSICmd s;
  186390. prepare (s);
  186391. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186392. s.SRB_BufLen = rb->bufferSize;
  186393. s.SRB_BufPointer = rb->buffer;
  186394. s.SRB_CDBLen = 10;
  186395. s.CDBByte[0] = 0xD4;
  186396. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186397. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186398. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186399. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186400. perform (s);
  186401. if (s.SRB_Status != SS_COMP)
  186402. return false;
  186403. rb->dataLength = rb->numFrames * 2352;
  186404. rb->dataStartOffset = 0;
  186405. return true;
  186406. }
  186407. };
  186408. CDController::CDController() : initialised (false)
  186409. {
  186410. }
  186411. CDController::~CDController()
  186412. {
  186413. }
  186414. void CDController::prepare (SRB_ExecSCSICmd& s)
  186415. {
  186416. zerostruct (s);
  186417. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186418. s.SRB_HaID = deviceInfo->info.ha;
  186419. s.SRB_Target = deviceInfo->info.tgt;
  186420. s.SRB_Lun = deviceInfo->info.lun;
  186421. s.SRB_SenseLen = SENSE_LEN;
  186422. }
  186423. void CDController::perform (SRB_ExecSCSICmd& s)
  186424. {
  186425. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186426. s.SRB_PostProc = event;
  186427. ResetEvent (event);
  186428. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186429. deviceInfo->info.scsiDriveLetter,
  186430. deviceInfo->scsiHandle)
  186431. : fSendASPI32Command ((LPSRB)&s);
  186432. if (status == SS_PENDING)
  186433. WaitForSingleObject (event, 4000);
  186434. CloseHandle (event);
  186435. }
  186436. void CDController::setPaused (bool paused)
  186437. {
  186438. SRB_ExecSCSICmd s;
  186439. prepare (s);
  186440. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186441. s.SRB_CDBLen = 10;
  186442. s.CDBByte[0] = 0x4B;
  186443. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186444. perform (s);
  186445. }
  186446. void CDController::shutDown()
  186447. {
  186448. }
  186449. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186450. {
  186451. if (overlapBuffer != 0)
  186452. {
  186453. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186454. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186455. if (doJitter
  186456. && overlapBuffer->startFrame > 0
  186457. && overlapBuffer->numFrames > 0
  186458. && overlapBuffer->dataLength > 0)
  186459. {
  186460. const int numFrames = rb->numFrames;
  186461. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186462. {
  186463. rb->startFrame -= framesOverlap;
  186464. if (framesToCheck < framesOverlap
  186465. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186466. rb->numFrames += framesOverlap;
  186467. }
  186468. else
  186469. {
  186470. overlapBuffer->dataLength = 0;
  186471. overlapBuffer->startFrame = 0;
  186472. overlapBuffer->numFrames = 0;
  186473. }
  186474. }
  186475. if (! read (rb))
  186476. return false;
  186477. if (doJitter)
  186478. {
  186479. const int checkLen = framesToCheck * 2352;
  186480. const int maxToCheck = rb->dataLength - checkLen;
  186481. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186482. return true;
  186483. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186484. bool found = false;
  186485. for (int i = 0; i < maxToCheck; ++i)
  186486. {
  186487. if (memcmp (p, rb->buffer + i, checkLen) == 0)
  186488. {
  186489. i += checkLen;
  186490. rb->dataStartOffset = i;
  186491. rb->dataLength -= i;
  186492. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186493. found = true;
  186494. break;
  186495. }
  186496. }
  186497. rb->numFrames = rb->dataLength / 2352;
  186498. rb->dataLength = 2352 * rb->numFrames;
  186499. if (!found)
  186500. return false;
  186501. }
  186502. if (canDoJitter)
  186503. {
  186504. memcpy (overlapBuffer->buffer,
  186505. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186506. 2352 * framesToCheck);
  186507. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186508. overlapBuffer->numFrames = framesToCheck;
  186509. overlapBuffer->dataLength = 2352 * framesToCheck;
  186510. overlapBuffer->dataStartOffset = 0;
  186511. }
  186512. else
  186513. {
  186514. overlapBuffer->startFrame = 0;
  186515. overlapBuffer->numFrames = 0;
  186516. overlapBuffer->dataLength = 0;
  186517. }
  186518. return true;
  186519. }
  186520. else
  186521. {
  186522. return read (rb);
  186523. }
  186524. }
  186525. int CDController::getLastIndex()
  186526. {
  186527. char qdata[100];
  186528. SRB_ExecSCSICmd s;
  186529. prepare (s);
  186530. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186531. s.SRB_BufLen = sizeof (qdata);
  186532. s.SRB_BufPointer = (BYTE*)qdata;
  186533. s.SRB_CDBLen = 12;
  186534. s.CDBByte[0] = 0x42;
  186535. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186536. s.CDBByte[2] = 64;
  186537. s.CDBByte[3] = 1; // get current position
  186538. s.CDBByte[7] = 0;
  186539. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186540. perform (s);
  186541. if (s.SRB_Status == SS_COMP)
  186542. return qdata[7];
  186543. return 0;
  186544. }
  186545. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186546. {
  186547. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186548. SRB_ExecSCSICmd s;
  186549. zerostruct (s);
  186550. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186551. s.SRB_HaID = info.ha;
  186552. s.SRB_Target = info.tgt;
  186553. s.SRB_Lun = info.lun;
  186554. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186555. s.SRB_BufLen = 0x324;
  186556. s.SRB_BufPointer = (BYTE*)lpToc;
  186557. s.SRB_SenseLen = 0x0E;
  186558. s.SRB_CDBLen = 0x0A;
  186559. s.SRB_PostProc = event;
  186560. s.CDBByte[0] = 0x43;
  186561. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186562. s.CDBByte[7] = 0x03;
  186563. s.CDBByte[8] = 0x24;
  186564. ResetEvent (event);
  186565. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186566. : fSendASPI32Command ((LPSRB)&s);
  186567. if (status == SS_PENDING)
  186568. WaitForSingleObject (event, 4000);
  186569. CloseHandle (event);
  186570. return (s.SRB_Status == SS_COMP);
  186571. }
  186572. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186573. CDReadBuffer* const overlapBuffer)
  186574. {
  186575. if (controller == 0)
  186576. {
  186577. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186578. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186579. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186580. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186581. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186582. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186583. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186584. }
  186585. buffer->index = 0;
  186586. if ((controller != 0)
  186587. && controller->readAudio (buffer, overlapBuffer))
  186588. {
  186589. if (buffer->wantsIndex)
  186590. buffer->index = controller->getLastIndex();
  186591. return true;
  186592. }
  186593. return false;
  186594. }
  186595. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186596. {
  186597. if (shouldBeOpen)
  186598. {
  186599. if (controller != 0)
  186600. {
  186601. controller->shutDown();
  186602. controller = 0;
  186603. }
  186604. if (scsiHandle != 0)
  186605. {
  186606. CloseHandle (scsiHandle);
  186607. scsiHandle = 0;
  186608. }
  186609. }
  186610. SRB_ExecSCSICmd s;
  186611. zerostruct (s);
  186612. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186613. s.SRB_HaID = info.ha;
  186614. s.SRB_Target = info.tgt;
  186615. s.SRB_Lun = info.lun;
  186616. s.SRB_SenseLen = SENSE_LEN;
  186617. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186618. s.SRB_BufLen = 0;
  186619. s.SRB_BufPointer = 0;
  186620. s.SRB_CDBLen = 12;
  186621. s.CDBByte[0] = 0x1b;
  186622. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186623. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186624. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186625. s.SRB_PostProc = event;
  186626. ResetEvent (event);
  186627. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186628. : fSendASPI32Command ((LPSRB)&s);
  186629. if (status == SS_PENDING)
  186630. WaitForSingleObject (event, 4000);
  186631. CloseHandle (event);
  186632. }
  186633. bool CDDeviceHandle::testController (const int type,
  186634. CDController* const newController,
  186635. CDReadBuffer* const rb)
  186636. {
  186637. controller = newController;
  186638. readType = (BYTE)type;
  186639. controller->deviceInfo = this;
  186640. controller->framesToCheck = 1;
  186641. controller->framesOverlap = 3;
  186642. bool passed = false;
  186643. memset (rb->buffer, 0xcd, rb->bufferSize);
  186644. if (controller->read (rb))
  186645. {
  186646. passed = true;
  186647. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186648. int wrong = 0;
  186649. for (int i = rb->dataLength / 4; --i >= 0;)
  186650. {
  186651. if (*p++ == (int) 0xcdcdcdcd)
  186652. {
  186653. if (++wrong == 4)
  186654. {
  186655. passed = false;
  186656. break;
  186657. }
  186658. }
  186659. else
  186660. {
  186661. wrong = 0;
  186662. }
  186663. }
  186664. }
  186665. if (! passed)
  186666. {
  186667. controller->shutDown();
  186668. controller = 0;
  186669. }
  186670. return passed;
  186671. }
  186672. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186673. {
  186674. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186675. const int bufSize = 128;
  186676. BYTE buffer[bufSize];
  186677. zeromem (buffer, bufSize);
  186678. SRB_ExecSCSICmd s;
  186679. zerostruct (s);
  186680. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186681. s.SRB_HaID = ha;
  186682. s.SRB_Target = tgt;
  186683. s.SRB_Lun = lun;
  186684. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186685. s.SRB_BufLen = bufSize;
  186686. s.SRB_BufPointer = buffer;
  186687. s.SRB_SenseLen = SENSE_LEN;
  186688. s.SRB_CDBLen = 6;
  186689. s.SRB_PostProc = event;
  186690. s.CDBByte[0] = SCSI_INQUIRY;
  186691. s.CDBByte[4] = 100;
  186692. ResetEvent (event);
  186693. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186694. WaitForSingleObject (event, 4000);
  186695. CloseHandle (event);
  186696. if (s.SRB_Status == SS_COMP)
  186697. {
  186698. memcpy (dev->vendor, &buffer[8], 8);
  186699. memcpy (dev->productId, &buffer[16], 16);
  186700. memcpy (dev->rev, &buffer[32], 4);
  186701. memcpy (dev->vendorSpec, &buffer[36], 20);
  186702. }
  186703. }
  186704. static int FindCDDevices (CDDeviceInfo* const list,
  186705. int maxItems)
  186706. {
  186707. int count = 0;
  186708. if (usingScsi)
  186709. {
  186710. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186711. {
  186712. TCHAR drivePath[8];
  186713. drivePath[0] = driveLetter;
  186714. drivePath[1] = ':';
  186715. drivePath[2] = '\\';
  186716. drivePath[3] = 0;
  186717. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186718. {
  186719. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186720. if (h != INVALID_HANDLE_VALUE)
  186721. {
  186722. BYTE buffer[100], passThroughStruct[1024];
  186723. zeromem (buffer, sizeof (buffer));
  186724. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186725. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186726. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186727. p->spt.CdbLength = 6;
  186728. p->spt.SenseInfoLength = 24;
  186729. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186730. p->spt.DataTransferLength = 100;
  186731. p->spt.TimeOutValue = 2;
  186732. p->spt.DataBuffer = buffer;
  186733. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186734. p->spt.Cdb[0] = 0x12;
  186735. p->spt.Cdb[4] = 100;
  186736. DWORD bytesReturned = 0;
  186737. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186738. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186739. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186740. &bytesReturned, 0) != 0)
  186741. {
  186742. zeromem (&list[count], sizeof (CDDeviceInfo));
  186743. list[count].scsiDriveLetter = driveLetter;
  186744. memcpy (list[count].vendor, &buffer[8], 8);
  186745. memcpy (list[count].productId, &buffer[16], 16);
  186746. memcpy (list[count].rev, &buffer[32], 4);
  186747. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186748. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186749. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186750. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186751. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186752. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186753. &bytesReturned, 0) != 0)
  186754. {
  186755. list[count].ha = scsiAddr->PortNumber;
  186756. list[count].tgt = scsiAddr->TargetId;
  186757. list[count].lun = scsiAddr->Lun;
  186758. ++count;
  186759. }
  186760. }
  186761. CloseHandle (h);
  186762. }
  186763. }
  186764. }
  186765. }
  186766. else
  186767. {
  186768. const DWORD d = fGetASPI32SupportInfo();
  186769. BYTE status = HIBYTE (LOWORD (d));
  186770. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186771. return 0;
  186772. const int numAdapters = LOBYTE (LOWORD (d));
  186773. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186774. {
  186775. SRB_HAInquiry s;
  186776. zerostruct (s);
  186777. s.SRB_Cmd = SC_HA_INQUIRY;
  186778. s.SRB_HaID = ha;
  186779. fSendASPI32Command ((LPSRB)&s);
  186780. if (s.SRB_Status == SS_COMP)
  186781. {
  186782. maxItems = (int)s.HA_Unique[3];
  186783. if (maxItems == 0)
  186784. maxItems = 8;
  186785. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186786. {
  186787. for (BYTE lun = 0; lun < 8; ++lun)
  186788. {
  186789. SRB_GDEVBlock sb;
  186790. zerostruct (sb);
  186791. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186792. sb.SRB_HaID = ha;
  186793. sb.SRB_Target = tgt;
  186794. sb.SRB_Lun = lun;
  186795. fSendASPI32Command ((LPSRB) &sb);
  186796. if (sb.SRB_Status == SS_COMP
  186797. && sb.SRB_DeviceType == DTYPE_CROM)
  186798. {
  186799. zeromem (&list[count], sizeof (CDDeviceInfo));
  186800. list[count].ha = ha;
  186801. list[count].tgt = tgt;
  186802. list[count].lun = lun;
  186803. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186804. ++count;
  186805. }
  186806. }
  186807. }
  186808. }
  186809. }
  186810. }
  186811. return count;
  186812. }
  186813. static int ripperUsers = 0;
  186814. static bool initialisedOk = false;
  186815. class DeinitialiseTimer : private Timer,
  186816. private DeletedAtShutdown
  186817. {
  186818. DeinitialiseTimer (const DeinitialiseTimer&);
  186819. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186820. public:
  186821. DeinitialiseTimer()
  186822. {
  186823. startTimer (4000);
  186824. }
  186825. ~DeinitialiseTimer()
  186826. {
  186827. if (--ripperUsers == 0)
  186828. DeinitialiseCDRipper();
  186829. }
  186830. void timerCallback()
  186831. {
  186832. delete this;
  186833. }
  186834. juce_UseDebuggingNewOperator
  186835. };
  186836. static void incUserCount()
  186837. {
  186838. if (ripperUsers++ == 0)
  186839. initialisedOk = InitialiseCDRipper();
  186840. }
  186841. static void decUserCount()
  186842. {
  186843. new DeinitialiseTimer();
  186844. }
  186845. struct CDDeviceWrapper
  186846. {
  186847. ScopedPointer<CDDeviceHandle> cdH;
  186848. ScopedPointer<CDReadBuffer> overlapBuffer;
  186849. bool jitter;
  186850. };
  186851. static int getAddressOf (const TOCTRACK* const t)
  186852. {
  186853. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186854. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186855. }
  186856. static int getMSFAddressOf (const TOCTRACK* const t)
  186857. {
  186858. return 60 * t->addr[1] + t->addr[2];
  186859. }
  186860. static const int samplesPerFrame = 44100 / 75;
  186861. static const int bytesPerFrame = samplesPerFrame * 4;
  186862. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186863. {
  186864. SRB_GDEVBlock s;
  186865. zerostruct (s);
  186866. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186867. s.SRB_HaID = device->ha;
  186868. s.SRB_Target = device->tgt;
  186869. s.SRB_Lun = device->lun;
  186870. if (usingScsi)
  186871. {
  186872. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186873. if (h != INVALID_HANDLE_VALUE)
  186874. {
  186875. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186876. cdh->scsiHandle = h;
  186877. return cdh;
  186878. }
  186879. }
  186880. else
  186881. {
  186882. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186883. && s.SRB_DeviceType == DTYPE_CROM)
  186884. {
  186885. return new CDDeviceHandle (device);
  186886. }
  186887. }
  186888. return 0;
  186889. }
  186890. }
  186891. const StringArray AudioCDReader::getAvailableCDNames()
  186892. {
  186893. using namespace CDReaderHelpers;
  186894. StringArray results;
  186895. incUserCount();
  186896. if (initialisedOk)
  186897. {
  186898. CDDeviceInfo list[8];
  186899. const int num = FindCDDevices (list, 8);
  186900. decUserCount();
  186901. for (int i = 0; i < num; ++i)
  186902. {
  186903. String s;
  186904. if (list[i].scsiDriveLetter > 0)
  186905. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << ": ";
  186906. s << String (list[i].vendor).trim()
  186907. << ' ' << String (list[i].productId).trim()
  186908. << ' ' << String (list[i].rev).trim();
  186909. results.add (s);
  186910. }
  186911. }
  186912. return results;
  186913. }
  186914. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  186915. {
  186916. using namespace CDReaderHelpers;
  186917. incUserCount();
  186918. if (initialisedOk)
  186919. {
  186920. CDDeviceInfo list[8];
  186921. const int num = FindCDDevices (list, 8);
  186922. if (((unsigned int) deviceIndex) < (unsigned int) num)
  186923. {
  186924. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  186925. if (handle != 0)
  186926. {
  186927. CDDeviceWrapper* const d = new CDDeviceWrapper();
  186928. d->cdH = handle;
  186929. d->overlapBuffer = new CDReadBuffer(3);
  186930. return new AudioCDReader (d);
  186931. }
  186932. }
  186933. }
  186934. decUserCount();
  186935. return 0;
  186936. }
  186937. AudioCDReader::AudioCDReader (void* handle_)
  186938. : AudioFormatReader (0, "CD Audio"),
  186939. handle (handle_),
  186940. indexingEnabled (false),
  186941. lastIndex (0),
  186942. firstFrameInBuffer (0),
  186943. samplesInBuffer (0)
  186944. {
  186945. using namespace CDReaderHelpers;
  186946. jassert (handle_ != 0);
  186947. refreshTrackLengths();
  186948. sampleRate = 44100.0;
  186949. bitsPerSample = 16;
  186950. lengthInSamples = getPositionOfTrackStart (numTracks);
  186951. numChannels = 2;
  186952. usesFloatingPointData = false;
  186953. buffer.setSize (4 * bytesPerFrame, true);
  186954. }
  186955. AudioCDReader::~AudioCDReader()
  186956. {
  186957. using namespace CDReaderHelpers;
  186958. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186959. delete device;
  186960. decUserCount();
  186961. }
  186962. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  186963. int64 startSampleInFile, int numSamples)
  186964. {
  186965. using namespace CDReaderHelpers;
  186966. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186967. bool ok = true;
  186968. while (numSamples > 0)
  186969. {
  186970. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  186971. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  186972. if (startSampleInFile >= bufferStartSample
  186973. && startSampleInFile < bufferEndSample)
  186974. {
  186975. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  186976. int* const l = destSamples[0] + startOffsetInDestBuffer;
  186977. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186978. const short* src = (const short*) buffer.getData();
  186979. src += 2 * (startSampleInFile - bufferStartSample);
  186980. for (int i = 0; i < toDo; ++i)
  186981. {
  186982. l[i] = src [i << 1] << 16;
  186983. if (r != 0)
  186984. r[i] = src [(i << 1) + 1] << 16;
  186985. }
  186986. startOffsetInDestBuffer += toDo;
  186987. startSampleInFile += toDo;
  186988. numSamples -= toDo;
  186989. }
  186990. else
  186991. {
  186992. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  186993. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  186994. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  186995. {
  186996. device->overlapBuffer->dataLength = 0;
  186997. device->overlapBuffer->startFrame = 0;
  186998. device->overlapBuffer->numFrames = 0;
  186999. device->jitter = false;
  187000. }
  187001. firstFrameInBuffer = frameNeeded;
  187002. lastIndex = 0;
  187003. CDReadBuffer readBuffer (framesInBuffer + 4);
  187004. readBuffer.wantsIndex = indexingEnabled;
  187005. int i;
  187006. for (i = 5; --i >= 0;)
  187007. {
  187008. readBuffer.startFrame = frameNeeded;
  187009. readBuffer.numFrames = framesInBuffer;
  187010. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187011. break;
  187012. else
  187013. device->overlapBuffer->dataLength = 0;
  187014. }
  187015. if (i >= 0)
  187016. {
  187017. memcpy ((char*) buffer.getData(),
  187018. readBuffer.buffer + readBuffer.dataStartOffset,
  187019. readBuffer.dataLength);
  187020. samplesInBuffer = readBuffer.dataLength >> 2;
  187021. lastIndex = readBuffer.index;
  187022. }
  187023. else
  187024. {
  187025. int* l = destSamples[0] + startOffsetInDestBuffer;
  187026. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187027. while (--numSamples >= 0)
  187028. {
  187029. *l++ = 0;
  187030. if (r != 0)
  187031. *r++ = 0;
  187032. }
  187033. // sometimes the read fails for just the very last couple of blocks, so
  187034. // we'll ignore and errors in the last half-second of the disk..
  187035. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187036. break;
  187037. }
  187038. }
  187039. }
  187040. return ok;
  187041. }
  187042. bool AudioCDReader::isCDStillPresent() const
  187043. {
  187044. using namespace CDReaderHelpers;
  187045. TOC toc;
  187046. zerostruct (toc);
  187047. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  187048. }
  187049. int AudioCDReader::getNumTracks() const
  187050. {
  187051. return numTracks;
  187052. }
  187053. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187054. {
  187055. using namespace CDReaderHelpers;
  187056. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187057. : 0;
  187058. }
  187059. void AudioCDReader::refreshTrackLengths()
  187060. {
  187061. using namespace CDReaderHelpers;
  187062. zeromem (trackStarts, sizeof (trackStarts));
  187063. zeromem (audioTracks, sizeof (audioTracks));
  187064. TOC toc;
  187065. zerostruct (toc);
  187066. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187067. {
  187068. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187069. for (int i = 0; i <= numTracks; ++i)
  187070. {
  187071. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187072. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187073. }
  187074. }
  187075. else
  187076. {
  187077. numTracks = 0;
  187078. }
  187079. }
  187080. bool AudioCDReader::isTrackAudio (int trackNum) const
  187081. {
  187082. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187083. : false;
  187084. }
  187085. void AudioCDReader::enableIndexScanning (bool b)
  187086. {
  187087. indexingEnabled = b;
  187088. }
  187089. int AudioCDReader::getLastIndex() const
  187090. {
  187091. return lastIndex;
  187092. }
  187093. const int framesPerIndexRead = 4;
  187094. int AudioCDReader::getIndexAt (int samplePos)
  187095. {
  187096. using namespace CDReaderHelpers;
  187097. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187098. const int frameNeeded = samplePos / samplesPerFrame;
  187099. device->overlapBuffer->dataLength = 0;
  187100. device->overlapBuffer->startFrame = 0;
  187101. device->overlapBuffer->numFrames = 0;
  187102. device->jitter = false;
  187103. firstFrameInBuffer = 0;
  187104. lastIndex = 0;
  187105. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187106. readBuffer.wantsIndex = true;
  187107. int i;
  187108. for (i = 5; --i >= 0;)
  187109. {
  187110. readBuffer.startFrame = frameNeeded;
  187111. readBuffer.numFrames = framesPerIndexRead;
  187112. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187113. break;
  187114. }
  187115. if (i >= 0)
  187116. return readBuffer.index;
  187117. return -1;
  187118. }
  187119. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187120. {
  187121. using namespace CDReaderHelpers;
  187122. Array <int> indexes;
  187123. const int trackStart = getPositionOfTrackStart (trackNumber);
  187124. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187125. bool needToScan = true;
  187126. if (trackEnd - trackStart > 20 * 44100)
  187127. {
  187128. // check the end of the track for indexes before scanning the whole thing
  187129. needToScan = false;
  187130. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187131. bool seenAnIndex = false;
  187132. while (pos <= trackEnd - samplesPerFrame)
  187133. {
  187134. const int index = getIndexAt (pos);
  187135. if (index == 0)
  187136. {
  187137. // lead-out, so skip back a bit if we've not found any indexes yet..
  187138. if (seenAnIndex)
  187139. break;
  187140. pos -= 44100 * 5;
  187141. if (pos < trackStart)
  187142. break;
  187143. }
  187144. else
  187145. {
  187146. if (index > 0)
  187147. seenAnIndex = true;
  187148. if (index > 1)
  187149. {
  187150. needToScan = true;
  187151. break;
  187152. }
  187153. pos += samplesPerFrame * framesPerIndexRead;
  187154. }
  187155. }
  187156. }
  187157. if (needToScan)
  187158. {
  187159. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187160. int pos = trackStart;
  187161. int last = -1;
  187162. while (pos < trackEnd - samplesPerFrame * 10)
  187163. {
  187164. const int frameNeeded = pos / samplesPerFrame;
  187165. device->overlapBuffer->dataLength = 0;
  187166. device->overlapBuffer->startFrame = 0;
  187167. device->overlapBuffer->numFrames = 0;
  187168. device->jitter = false;
  187169. firstFrameInBuffer = 0;
  187170. CDReadBuffer readBuffer (4);
  187171. readBuffer.wantsIndex = true;
  187172. int i;
  187173. for (i = 5; --i >= 0;)
  187174. {
  187175. readBuffer.startFrame = frameNeeded;
  187176. readBuffer.numFrames = framesPerIndexRead;
  187177. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187178. break;
  187179. }
  187180. if (i < 0)
  187181. break;
  187182. if (readBuffer.index > last && readBuffer.index > 1)
  187183. {
  187184. last = readBuffer.index;
  187185. indexes.add (pos);
  187186. }
  187187. pos += samplesPerFrame * framesPerIndexRead;
  187188. }
  187189. indexes.removeValue (trackStart);
  187190. }
  187191. return indexes;
  187192. }
  187193. int AudioCDReader::getCDDBId()
  187194. {
  187195. using namespace CDReaderHelpers;
  187196. refreshTrackLengths();
  187197. if (numTracks > 0)
  187198. {
  187199. TOC toc;
  187200. zerostruct (toc);
  187201. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187202. {
  187203. int n = 0;
  187204. for (int i = numTracks; --i >= 0;)
  187205. {
  187206. int j = getMSFAddressOf (&toc.tracks[i]);
  187207. while (j > 0)
  187208. {
  187209. n += (j % 10);
  187210. j /= 10;
  187211. }
  187212. }
  187213. if (n != 0)
  187214. {
  187215. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187216. - getMSFAddressOf (&toc.tracks[0]);
  187217. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187218. }
  187219. }
  187220. }
  187221. return 0;
  187222. }
  187223. void AudioCDReader::ejectDisk()
  187224. {
  187225. using namespace CDReaderHelpers;
  187226. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187227. }
  187228. #endif
  187229. #if JUCE_USE_CDBURNER
  187230. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187231. {
  187232. CoInitialize (0);
  187233. IDiscMaster* dm;
  187234. IDiscRecorder* result = 0;
  187235. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187236. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187237. IID_IDiscMaster,
  187238. (void**) &dm)))
  187239. {
  187240. if (SUCCEEDED (dm->Open()))
  187241. {
  187242. IEnumDiscRecorders* drEnum = 0;
  187243. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187244. {
  187245. IDiscRecorder* dr = 0;
  187246. DWORD dummy;
  187247. int index = 0;
  187248. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187249. {
  187250. if (indexToOpen == index)
  187251. {
  187252. result = dr;
  187253. break;
  187254. }
  187255. else if (list != 0)
  187256. {
  187257. BSTR path;
  187258. if (SUCCEEDED (dr->GetPath (&path)))
  187259. list->add ((const WCHAR*) path);
  187260. }
  187261. ++index;
  187262. dr->Release();
  187263. }
  187264. drEnum->Release();
  187265. }
  187266. if (master == 0)
  187267. dm->Close();
  187268. }
  187269. if (master != 0)
  187270. *master = dm;
  187271. else
  187272. dm->Release();
  187273. }
  187274. return result;
  187275. }
  187276. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187277. public Timer
  187278. {
  187279. public:
  187280. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187281. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187282. listener (0), progress (0), shouldCancel (false), refCount (1)
  187283. {
  187284. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187285. jassert (SUCCEEDED (hr));
  187286. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187287. //jassert (SUCCEEDED (hr));
  187288. lastState = getDiskState();
  187289. startTimer (2000);
  187290. }
  187291. ~Pimpl() {}
  187292. void releaseObjects()
  187293. {
  187294. discRecorder->Close();
  187295. if (redbook != 0)
  187296. redbook->Release();
  187297. discRecorder->Release();
  187298. discMaster->Release();
  187299. Release();
  187300. }
  187301. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187302. {
  187303. if (result == 0)
  187304. return E_POINTER;
  187305. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187306. {
  187307. AddRef();
  187308. *result = this;
  187309. return S_OK;
  187310. }
  187311. *result = 0;
  187312. return E_NOINTERFACE;
  187313. }
  187314. ULONG __stdcall AddRef() { return ++refCount; }
  187315. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187316. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187317. {
  187318. if (listener != 0 && ! shouldCancel)
  187319. shouldCancel = listener->audioCDBurnProgress (progress);
  187320. *pbCancel = shouldCancel;
  187321. return S_OK;
  187322. }
  187323. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187324. {
  187325. progress = nCompleted / (float) nTotal;
  187326. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187327. return E_NOTIMPL;
  187328. }
  187329. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187330. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187331. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187332. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187333. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187334. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187335. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187336. class ScopedDiscOpener
  187337. {
  187338. public:
  187339. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187340. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187341. private:
  187342. Pimpl& pimpl;
  187343. ScopedDiscOpener (const ScopedDiscOpener&);
  187344. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187345. };
  187346. DiskState getDiskState()
  187347. {
  187348. const ScopedDiscOpener opener (*this);
  187349. long type, flags;
  187350. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187351. if (FAILED (hr))
  187352. return unknown;
  187353. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187354. return writableDiskPresent;
  187355. if (type == 0)
  187356. return noDisc;
  187357. else
  187358. return readOnlyDiskPresent;
  187359. }
  187360. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187361. {
  187362. ComSmartPtr<IPropertyStorage> prop;
  187363. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187364. return defaultReturn;
  187365. PROPSPEC iPropSpec;
  187366. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187367. iPropSpec.lpwstr = name;
  187368. PROPVARIANT iPropVariant;
  187369. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187370. ? defaultReturn : (int) iPropVariant.lVal;
  187371. }
  187372. bool setIntProperty (const LPOLESTR name, const int value) const
  187373. {
  187374. ComSmartPtr<IPropertyStorage> prop;
  187375. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187376. return false;
  187377. PROPSPEC iPropSpec;
  187378. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187379. iPropSpec.lpwstr = name;
  187380. PROPVARIANT iPropVariant;
  187381. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187382. return false;
  187383. iPropVariant.lVal = (long) value;
  187384. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187385. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187386. }
  187387. void timerCallback()
  187388. {
  187389. const DiskState state = getDiskState();
  187390. if (state != lastState)
  187391. {
  187392. lastState = state;
  187393. owner.sendChangeMessage (&owner);
  187394. }
  187395. }
  187396. AudioCDBurner& owner;
  187397. DiskState lastState;
  187398. IDiscMaster* discMaster;
  187399. IDiscRecorder* discRecorder;
  187400. IRedbookDiscMaster* redbook;
  187401. AudioCDBurner::BurnProgressListener* listener;
  187402. float progress;
  187403. bool shouldCancel;
  187404. private:
  187405. int refCount;
  187406. };
  187407. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187408. {
  187409. IDiscMaster* discMaster = 0;
  187410. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187411. if (discRecorder != 0)
  187412. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187413. }
  187414. AudioCDBurner::~AudioCDBurner()
  187415. {
  187416. if (pimpl != 0)
  187417. pimpl.release()->releaseObjects();
  187418. }
  187419. const StringArray AudioCDBurner::findAvailableDevices()
  187420. {
  187421. StringArray devs;
  187422. enumCDBurners (&devs, -1, 0);
  187423. return devs;
  187424. }
  187425. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187426. {
  187427. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187428. if (b->pimpl == 0)
  187429. b = 0;
  187430. return b.release();
  187431. }
  187432. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187433. {
  187434. return pimpl->getDiskState();
  187435. }
  187436. bool AudioCDBurner::isDiskPresent() const
  187437. {
  187438. return getDiskState() == writableDiskPresent;
  187439. }
  187440. bool AudioCDBurner::openTray()
  187441. {
  187442. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187443. return SUCCEEDED (pimpl->discRecorder->Eject());
  187444. }
  187445. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187446. {
  187447. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187448. DiskState oldState = getDiskState();
  187449. DiskState newState = oldState;
  187450. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187451. {
  187452. newState = getDiskState();
  187453. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187454. }
  187455. return newState;
  187456. }
  187457. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187458. {
  187459. Array<int> results;
  187460. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187461. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187462. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187463. if (speeds[i] <= maxSpeed)
  187464. results.add (speeds[i]);
  187465. results.addIfNotAlreadyThere (maxSpeed);
  187466. return results;
  187467. }
  187468. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187469. {
  187470. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187471. return false;
  187472. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187473. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187474. }
  187475. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187476. {
  187477. long blocksFree = 0;
  187478. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187479. return blocksFree;
  187480. }
  187481. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187482. bool performFakeBurnForTesting, int writeSpeed)
  187483. {
  187484. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187485. pimpl->listener = listener;
  187486. pimpl->progress = 0;
  187487. pimpl->shouldCancel = false;
  187488. UINT_PTR cookie;
  187489. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187490. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187491. ejectDiscAfterwards);
  187492. String error;
  187493. if (hr != S_OK)
  187494. {
  187495. const char* e = "Couldn't open or write to the CD device";
  187496. if (hr == IMAPI_E_USERABORT)
  187497. e = "User cancelled the write operation";
  187498. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187499. e = "No Disk present";
  187500. error = e;
  187501. }
  187502. pimpl->discMaster->ProgressUnadvise (cookie);
  187503. pimpl->listener = 0;
  187504. return error;
  187505. }
  187506. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187507. {
  187508. if (audioSource == 0)
  187509. return false;
  187510. ScopedPointer<AudioSource> source (audioSource);
  187511. long bytesPerBlock;
  187512. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187513. const int samplesPerBlock = bytesPerBlock / 4;
  187514. bool ok = true;
  187515. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187516. HeapBlock <byte> buffer (bytesPerBlock);
  187517. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187518. int samplesDone = 0;
  187519. source->prepareToPlay (samplesPerBlock, 44100.0);
  187520. while (ok)
  187521. {
  187522. {
  187523. AudioSourceChannelInfo info;
  187524. info.buffer = &sourceBuffer;
  187525. info.numSamples = samplesPerBlock;
  187526. info.startSample = 0;
  187527. sourceBuffer.clear();
  187528. source->getNextAudioBlock (info);
  187529. }
  187530. zeromem (buffer, bytesPerBlock);
  187531. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187532. buffer, samplesPerBlock, 4);
  187533. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187534. buffer + 2, samplesPerBlock, 4);
  187535. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187536. if (FAILED (hr))
  187537. ok = false;
  187538. samplesDone += samplesPerBlock;
  187539. if (samplesDone >= numSamples)
  187540. break;
  187541. }
  187542. hr = pimpl->redbook->CloseAudioTrack();
  187543. return ok && hr == S_OK;
  187544. }
  187545. #endif
  187546. #endif
  187547. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187548. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187549. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187550. // compiled on its own).
  187551. #if JUCE_INCLUDED_FILE
  187552. using ::free;
  187553. namespace MidiConstants
  187554. {
  187555. static const int midiBufferSize = 1024 * 10;
  187556. static const int numInHeaders = 32;
  187557. static const int inBufferSize = 256;
  187558. }
  187559. class MidiInThread : public Thread
  187560. {
  187561. public:
  187562. MidiInThread (MidiInput* const input_,
  187563. MidiInputCallback* const callback_)
  187564. : Thread ("Juce Midi"),
  187565. hIn (0),
  187566. input (input_),
  187567. callback (callback_),
  187568. isStarted (false),
  187569. startTime (0),
  187570. pendingLength(0)
  187571. {
  187572. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187573. {
  187574. zeromem (&hdr[i], sizeof (MIDIHDR));
  187575. hdr[i].lpData = inData[i];
  187576. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187577. }
  187578. };
  187579. ~MidiInThread()
  187580. {
  187581. stop();
  187582. if (hIn != 0)
  187583. {
  187584. int count = 5;
  187585. while (--count >= 0)
  187586. {
  187587. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187588. break;
  187589. Sleep (20);
  187590. }
  187591. }
  187592. }
  187593. void handle (const uint32 message, const uint32 timeStamp) throw()
  187594. {
  187595. const int byte = message & 0xff;
  187596. if (byte < 0x80)
  187597. return;
  187598. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187599. const double time = timeStampToTime (timeStamp);
  187600. {
  187601. const ScopedLock sl (lock);
  187602. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187603. {
  187604. char* const p = pending + pendingLength;
  187605. *(double*) p = time;
  187606. *(uint32*) (p + 8) = numBytes;
  187607. *(uint32*) (p + 12) = message;
  187608. pendingLength += 12 + numBytes;
  187609. }
  187610. else
  187611. {
  187612. jassertfalse // midi buffer overflow! You might need to increase the size..
  187613. }
  187614. }
  187615. notify();
  187616. }
  187617. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187618. {
  187619. const int num = hdr->dwBytesRecorded;
  187620. if (num > 0)
  187621. {
  187622. const double time = timeStampToTime (timeStamp);
  187623. {
  187624. const ScopedLock sl (lock);
  187625. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187626. {
  187627. char* const p = pending + pendingLength;
  187628. *(double*) p = time;
  187629. *(uint32*) (p + 8) = num;
  187630. memcpy (p + 12, hdr->lpData, num);
  187631. pendingLength += 12 + num;
  187632. }
  187633. else
  187634. {
  187635. jassertfalse // midi buffer overflow! You might need to increase the size..
  187636. }
  187637. }
  187638. notify();
  187639. }
  187640. }
  187641. void writeBlock (const int i) throw()
  187642. {
  187643. hdr[i].dwBytesRecorded = 0;
  187644. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187645. jassert (res == MMSYSERR_NOERROR);
  187646. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187647. jassert (res == MMSYSERR_NOERROR);
  187648. }
  187649. void run()
  187650. {
  187651. MemoryBlock pendingCopy (64);
  187652. while (! threadShouldExit())
  187653. {
  187654. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187655. {
  187656. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187657. {
  187658. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187659. (void) res;
  187660. jassert (res == MMSYSERR_NOERROR);
  187661. writeBlock (i);
  187662. }
  187663. }
  187664. int len;
  187665. {
  187666. const ScopedLock sl (lock);
  187667. len = pendingLength;
  187668. if (len > 0)
  187669. {
  187670. pendingCopy.ensureSize (len);
  187671. pendingCopy.copyFrom (pending, 0, len);
  187672. pendingLength = 0;
  187673. }
  187674. }
  187675. //xxx needs to figure out if blocks are broken up or not
  187676. if (len == 0)
  187677. {
  187678. wait (500);
  187679. }
  187680. else
  187681. {
  187682. const char* p = (const char*) pendingCopy.getData();
  187683. while (len > 0)
  187684. {
  187685. const double time = *(const double*) p;
  187686. const int messageLen = *(const int*) (p + 8);
  187687. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187688. callback->handleIncomingMidiMessage (input, message);
  187689. p += 12 + messageLen;
  187690. len -= 12 + messageLen;
  187691. }
  187692. }
  187693. }
  187694. }
  187695. void start() throw()
  187696. {
  187697. jassert (hIn != 0);
  187698. if (hIn != 0 && ! isStarted)
  187699. {
  187700. stop();
  187701. activeMidiThreads.addIfNotAlreadyThere (this);
  187702. int i;
  187703. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187704. writeBlock (i);
  187705. startTime = Time::getMillisecondCounter();
  187706. MMRESULT res = midiInStart (hIn);
  187707. jassert (res == MMSYSERR_NOERROR);
  187708. if (res == MMSYSERR_NOERROR)
  187709. {
  187710. isStarted = true;
  187711. pendingLength = 0;
  187712. startThread (6);
  187713. }
  187714. }
  187715. }
  187716. void stop() throw()
  187717. {
  187718. if (isStarted)
  187719. {
  187720. stopThread (5000);
  187721. midiInReset (hIn);
  187722. midiInStop (hIn);
  187723. activeMidiThreads.removeValue (this);
  187724. { const ScopedLock sl (lock); }
  187725. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187726. {
  187727. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187728. {
  187729. int c = 10;
  187730. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187731. Sleep (20);
  187732. jassert (c >= 0);
  187733. }
  187734. }
  187735. isStarted = false;
  187736. pendingLength = 0;
  187737. }
  187738. }
  187739. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187740. {
  187741. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187742. if (thread != 0 && activeMidiThreads.contains (thread))
  187743. {
  187744. if (uMsg == MIM_DATA)
  187745. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187746. else if (uMsg == MIM_LONGDATA)
  187747. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187748. }
  187749. }
  187750. juce_UseDebuggingNewOperator
  187751. HMIDIIN hIn;
  187752. private:
  187753. static Array <void*, CriticalSection> activeMidiThreads;
  187754. MidiInput* input;
  187755. MidiInputCallback* callback;
  187756. bool isStarted;
  187757. uint32 startTime;
  187758. CriticalSection lock;
  187759. MIDIHDR hdr [MidiConstants::numInHeaders];
  187760. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187761. int pendingLength;
  187762. char pending [MidiConstants::midiBufferSize];
  187763. double timeStampToTime (uint32 timeStamp) throw()
  187764. {
  187765. timeStamp += startTime;
  187766. const uint32 now = Time::getMillisecondCounter();
  187767. if (timeStamp > now)
  187768. {
  187769. if (timeStamp > now + 2)
  187770. --startTime;
  187771. timeStamp = now;
  187772. }
  187773. return 0.001 * timeStamp;
  187774. }
  187775. MidiInThread (const MidiInThread&);
  187776. MidiInThread& operator= (const MidiInThread&);
  187777. };
  187778. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187779. const StringArray MidiInput::getDevices()
  187780. {
  187781. StringArray s;
  187782. const int num = midiInGetNumDevs();
  187783. for (int i = 0; i < num; ++i)
  187784. {
  187785. MIDIINCAPS mc;
  187786. zerostruct (mc);
  187787. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187788. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187789. }
  187790. return s;
  187791. }
  187792. int MidiInput::getDefaultDeviceIndex()
  187793. {
  187794. return 0;
  187795. }
  187796. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187797. {
  187798. if (callback == 0)
  187799. return 0;
  187800. UINT deviceId = MIDI_MAPPER;
  187801. int n = 0;
  187802. String name;
  187803. const int num = midiInGetNumDevs();
  187804. for (int i = 0; i < num; ++i)
  187805. {
  187806. MIDIINCAPS mc;
  187807. zerostruct (mc);
  187808. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187809. {
  187810. if (index == n)
  187811. {
  187812. deviceId = i;
  187813. name = String (mc.szPname, sizeof (mc.szPname));
  187814. break;
  187815. }
  187816. ++n;
  187817. }
  187818. }
  187819. ScopedPointer <MidiInput> in (new MidiInput (name));
  187820. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187821. HMIDIIN h;
  187822. HRESULT err = midiInOpen (&h, deviceId,
  187823. (DWORD_PTR) &MidiInThread::midiInCallback,
  187824. (DWORD_PTR) (MidiInThread*) thread,
  187825. CALLBACK_FUNCTION);
  187826. if (err == MMSYSERR_NOERROR)
  187827. {
  187828. thread->hIn = h;
  187829. in->internal = thread.release();
  187830. return in.release();
  187831. }
  187832. return 0;
  187833. }
  187834. MidiInput::MidiInput (const String& name_)
  187835. : name (name_),
  187836. internal (0)
  187837. {
  187838. }
  187839. MidiInput::~MidiInput()
  187840. {
  187841. delete static_cast <MidiInThread*> (internal);
  187842. }
  187843. void MidiInput::start()
  187844. {
  187845. static_cast <MidiInThread*> (internal)->start();
  187846. }
  187847. void MidiInput::stop()
  187848. {
  187849. static_cast <MidiInThread*> (internal)->stop();
  187850. }
  187851. struct MidiOutHandle
  187852. {
  187853. int refCount;
  187854. UINT deviceId;
  187855. HMIDIOUT handle;
  187856. static Array<MidiOutHandle*> activeHandles;
  187857. juce_UseDebuggingNewOperator
  187858. };
  187859. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187860. const StringArray MidiOutput::getDevices()
  187861. {
  187862. StringArray s;
  187863. const int num = midiOutGetNumDevs();
  187864. for (int i = 0; i < num; ++i)
  187865. {
  187866. MIDIOUTCAPS mc;
  187867. zerostruct (mc);
  187868. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187869. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187870. }
  187871. return s;
  187872. }
  187873. int MidiOutput::getDefaultDeviceIndex()
  187874. {
  187875. const int num = midiOutGetNumDevs();
  187876. int n = 0;
  187877. for (int i = 0; i < num; ++i)
  187878. {
  187879. MIDIOUTCAPS mc;
  187880. zerostruct (mc);
  187881. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187882. {
  187883. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187884. return n;
  187885. ++n;
  187886. }
  187887. }
  187888. return 0;
  187889. }
  187890. MidiOutput* MidiOutput::openDevice (int index)
  187891. {
  187892. UINT deviceId = MIDI_MAPPER;
  187893. const int num = midiOutGetNumDevs();
  187894. int i, n = 0;
  187895. for (i = 0; i < num; ++i)
  187896. {
  187897. MIDIOUTCAPS mc;
  187898. zerostruct (mc);
  187899. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187900. {
  187901. // use the microsoft sw synth as a default - best not to allow deviceId
  187902. // to be MIDI_MAPPER, or else device sharing breaks
  187903. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase ("microsoft"))
  187904. deviceId = i;
  187905. if (index == n)
  187906. {
  187907. deviceId = i;
  187908. break;
  187909. }
  187910. ++n;
  187911. }
  187912. }
  187913. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  187914. {
  187915. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  187916. if (han != 0 && han->deviceId == deviceId)
  187917. {
  187918. han->refCount++;
  187919. MidiOutput* const out = new MidiOutput();
  187920. out->internal = han;
  187921. return out;
  187922. }
  187923. }
  187924. for (i = 4; --i >= 0;)
  187925. {
  187926. HMIDIOUT h = 0;
  187927. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  187928. if (res == MMSYSERR_NOERROR)
  187929. {
  187930. MidiOutHandle* const han = new MidiOutHandle();
  187931. han->deviceId = deviceId;
  187932. han->refCount = 1;
  187933. han->handle = h;
  187934. MidiOutHandle::activeHandles.add (han);
  187935. MidiOutput* const out = new MidiOutput();
  187936. out->internal = han;
  187937. return out;
  187938. }
  187939. else if (res == MMSYSERR_ALLOCATED)
  187940. {
  187941. Sleep (100);
  187942. }
  187943. else
  187944. {
  187945. break;
  187946. }
  187947. }
  187948. return 0;
  187949. }
  187950. MidiOutput::~MidiOutput()
  187951. {
  187952. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  187953. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  187954. {
  187955. midiOutClose (h->handle);
  187956. MidiOutHandle::activeHandles.removeValue (h);
  187957. delete h;
  187958. }
  187959. }
  187960. void MidiOutput::reset()
  187961. {
  187962. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  187963. midiOutReset (h->handle);
  187964. }
  187965. bool MidiOutput::getVolume (float& leftVol,
  187966. float& rightVol)
  187967. {
  187968. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187969. DWORD n;
  187970. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  187971. {
  187972. const unsigned short* const nn = (const unsigned short*) &n;
  187973. rightVol = nn[0] / (float) 0xffff;
  187974. leftVol = nn[1] / (float) 0xffff;
  187975. return true;
  187976. }
  187977. else
  187978. {
  187979. rightVol = leftVol = 1.0f;
  187980. return false;
  187981. }
  187982. }
  187983. void MidiOutput::setVolume (float leftVol,
  187984. float rightVol)
  187985. {
  187986. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  187987. DWORD n;
  187988. unsigned short* const nn = (unsigned short*) &n;
  187989. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  187990. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  187991. midiOutSetVolume (handle->handle, n);
  187992. }
  187993. void MidiOutput::sendMessageNow (const MidiMessage& message)
  187994. {
  187995. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187996. if (message.getRawDataSize() > 3
  187997. || message.isSysEx())
  187998. {
  187999. MIDIHDR h;
  188000. zerostruct (h);
  188001. h.lpData = (char*) message.getRawData();
  188002. h.dwBufferLength = message.getRawDataSize();
  188003. h.dwBytesRecorded = message.getRawDataSize();
  188004. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188005. {
  188006. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188007. if (res == MMSYSERR_NOERROR)
  188008. {
  188009. while ((h.dwFlags & MHDR_DONE) == 0)
  188010. Sleep (1);
  188011. int count = 500; // 1 sec timeout
  188012. while (--count >= 0)
  188013. {
  188014. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188015. if (res == MIDIERR_STILLPLAYING)
  188016. Sleep (2);
  188017. else
  188018. break;
  188019. }
  188020. }
  188021. }
  188022. }
  188023. else
  188024. {
  188025. midiOutShortMsg (handle->handle,
  188026. *(unsigned int*) message.getRawData());
  188027. }
  188028. }
  188029. #endif
  188030. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188031. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188032. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188033. // compiled on its own).
  188034. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188035. #undef WINDOWS
  188036. // #define ASIO_DEBUGGING
  188037. #ifdef ASIO_DEBUGGING
  188038. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188039. #else
  188040. #define log(a) {}
  188041. #endif
  188042. #ifdef ASIO_DEBUGGING
  188043. static void logError (const String& context, long error)
  188044. {
  188045. String err ("unknown error");
  188046. if (error == ASE_NotPresent)
  188047. err = "Not Present";
  188048. else if (error == ASE_HWMalfunction)
  188049. err = "Hardware Malfunction";
  188050. else if (error == ASE_InvalidParameter)
  188051. err = "Invalid Parameter";
  188052. else if (error == ASE_InvalidMode)
  188053. err = "Invalid Mode";
  188054. else if (error == ASE_SPNotAdvancing)
  188055. err = "Sample position not advancing";
  188056. else if (error == ASE_NoClock)
  188057. err = "No Clock";
  188058. else if (error == ASE_NoMemory)
  188059. err = "Out of memory";
  188060. log ("!!error: " + context + " - " + err);
  188061. }
  188062. #else
  188063. #define logError(a, b) {}
  188064. #endif
  188065. class ASIOAudioIODevice;
  188066. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188067. static const int maxASIOChannels = 160;
  188068. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188069. private Timer
  188070. {
  188071. public:
  188072. Component ourWindow;
  188073. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188074. const String& optionalDllForDirectLoading_)
  188075. : AudioIODevice (name_, "ASIO"),
  188076. asioObject (0),
  188077. classId (classId_),
  188078. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188079. currentBitDepth (16),
  188080. currentSampleRate (0),
  188081. isOpen_ (false),
  188082. isStarted (false),
  188083. postOutput (true),
  188084. insideControlPanelModalLoop (false),
  188085. shouldUsePreferredSize (false)
  188086. {
  188087. name = name_;
  188088. ourWindow.addToDesktop (0);
  188089. windowHandle = ourWindow.getWindowHandle();
  188090. jassert (currentASIODev [slotNumber] == 0);
  188091. currentASIODev [slotNumber] = this;
  188092. openDevice();
  188093. }
  188094. ~ASIOAudioIODevice()
  188095. {
  188096. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188097. if (currentASIODev[i] == this)
  188098. currentASIODev[i] = 0;
  188099. close();
  188100. log ("ASIO - exiting");
  188101. removeCurrentDriver();
  188102. }
  188103. void updateSampleRates()
  188104. {
  188105. // find a list of sample rates..
  188106. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188107. sampleRates.clear();
  188108. if (asioObject != 0)
  188109. {
  188110. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188111. {
  188112. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188113. if (err == 0)
  188114. {
  188115. sampleRates.add ((int) possibleSampleRates[index]);
  188116. log ("rate: " + String ((int) possibleSampleRates[index]));
  188117. }
  188118. else if (err != ASE_NoClock)
  188119. {
  188120. logError ("CanSampleRate", err);
  188121. }
  188122. }
  188123. if (sampleRates.size() == 0)
  188124. {
  188125. double cr = 0;
  188126. const long err = asioObject->getSampleRate (&cr);
  188127. log ("No sample rates supported - current rate: " + String ((int) cr));
  188128. if (err == 0)
  188129. sampleRates.add ((int) cr);
  188130. }
  188131. }
  188132. }
  188133. const StringArray getOutputChannelNames()
  188134. {
  188135. return outputChannelNames;
  188136. }
  188137. const StringArray getInputChannelNames()
  188138. {
  188139. return inputChannelNames;
  188140. }
  188141. int getNumSampleRates()
  188142. {
  188143. return sampleRates.size();
  188144. }
  188145. double getSampleRate (int index)
  188146. {
  188147. return sampleRates [index];
  188148. }
  188149. int getNumBufferSizesAvailable()
  188150. {
  188151. return bufferSizes.size();
  188152. }
  188153. int getBufferSizeSamples (int index)
  188154. {
  188155. return bufferSizes [index];
  188156. }
  188157. int getDefaultBufferSize()
  188158. {
  188159. return preferredSize;
  188160. }
  188161. const String open (const BigInteger& inputChannels,
  188162. const BigInteger& outputChannels,
  188163. double sr,
  188164. int bufferSizeSamples)
  188165. {
  188166. close();
  188167. currentCallback = 0;
  188168. if (bufferSizeSamples <= 0)
  188169. shouldUsePreferredSize = true;
  188170. if (asioObject == 0 || ! isASIOOpen)
  188171. {
  188172. log ("Warning: device not open");
  188173. const String err (openDevice());
  188174. if (asioObject == 0 || ! isASIOOpen)
  188175. return err;
  188176. }
  188177. isStarted = false;
  188178. bufferIndex = -1;
  188179. long err = 0;
  188180. long newPreferredSize = 0;
  188181. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188182. minSize = 0;
  188183. maxSize = 0;
  188184. newPreferredSize = 0;
  188185. granularity = 0;
  188186. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188187. {
  188188. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188189. shouldUsePreferredSize = true;
  188190. preferredSize = newPreferredSize;
  188191. }
  188192. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188193. // dynamic changes to the buffer size...
  188194. shouldUsePreferredSize = shouldUsePreferredSize
  188195. || getName().containsIgnoreCase ("Digidesign");
  188196. if (shouldUsePreferredSize)
  188197. {
  188198. log ("Using preferred size for buffer..");
  188199. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188200. {
  188201. bufferSizeSamples = preferredSize;
  188202. }
  188203. else
  188204. {
  188205. bufferSizeSamples = 1024;
  188206. logError ("GetBufferSize1", err);
  188207. }
  188208. shouldUsePreferredSize = false;
  188209. }
  188210. int sampleRate = roundDoubleToInt (sr);
  188211. currentSampleRate = sampleRate;
  188212. currentBlockSizeSamples = bufferSizeSamples;
  188213. currentChansOut.clear();
  188214. currentChansIn.clear();
  188215. zeromem (inBuffers, sizeof (inBuffers));
  188216. zeromem (outBuffers, sizeof (outBuffers));
  188217. updateSampleRates();
  188218. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188219. sampleRate = sampleRates[0];
  188220. jassert (sampleRate != 0);
  188221. if (sampleRate == 0)
  188222. sampleRate = 44100;
  188223. long numSources = 32;
  188224. ASIOClockSource clocks[32];
  188225. zeromem (clocks, sizeof (clocks));
  188226. asioObject->getClockSources (clocks, &numSources);
  188227. bool isSourceSet = false;
  188228. // careful not to remove this loop because it does more than just logging!
  188229. int i;
  188230. for (i = 0; i < numSources; ++i)
  188231. {
  188232. String s ("clock: ");
  188233. s += clocks[i].name;
  188234. if (clocks[i].isCurrentSource)
  188235. {
  188236. isSourceSet = true;
  188237. s << " (cur)";
  188238. }
  188239. log (s);
  188240. }
  188241. if (numSources > 1 && ! isSourceSet)
  188242. {
  188243. log ("setting clock source");
  188244. asioObject->setClockSource (clocks[0].index);
  188245. Thread::sleep (20);
  188246. }
  188247. else
  188248. {
  188249. if (numSources == 0)
  188250. {
  188251. log ("ASIO - no clock sources!");
  188252. }
  188253. }
  188254. double cr = 0;
  188255. err = asioObject->getSampleRate (&cr);
  188256. if (err == 0)
  188257. {
  188258. currentSampleRate = cr;
  188259. }
  188260. else
  188261. {
  188262. logError ("GetSampleRate", err);
  188263. currentSampleRate = 0;
  188264. }
  188265. error = String::empty;
  188266. needToReset = false;
  188267. isReSync = false;
  188268. err = 0;
  188269. bool buffersCreated = false;
  188270. if (currentSampleRate != sampleRate)
  188271. {
  188272. log ("ASIO samplerate: " + String (currentSampleRate) + " to " + String (sampleRate));
  188273. err = asioObject->setSampleRate (sampleRate);
  188274. if (err == ASE_NoClock && numSources > 0)
  188275. {
  188276. log ("trying to set a clock source..");
  188277. Thread::sleep (10);
  188278. err = asioObject->setClockSource (clocks[0].index);
  188279. if (err != 0)
  188280. {
  188281. logError ("SetClock", err);
  188282. }
  188283. Thread::sleep (10);
  188284. err = asioObject->setSampleRate (sampleRate);
  188285. }
  188286. }
  188287. if (err == 0)
  188288. {
  188289. currentSampleRate = sampleRate;
  188290. if (needToReset)
  188291. {
  188292. if (isReSync)
  188293. {
  188294. log ("Resync request");
  188295. }
  188296. log ("! Resetting ASIO after sample rate change");
  188297. removeCurrentDriver();
  188298. loadDriver();
  188299. const String error (initDriver());
  188300. if (error.isNotEmpty())
  188301. {
  188302. log ("ASIOInit: " + error);
  188303. }
  188304. needToReset = false;
  188305. isReSync = false;
  188306. }
  188307. numActiveInputChans = 0;
  188308. numActiveOutputChans = 0;
  188309. ASIOBufferInfo* info = bufferInfos;
  188310. int i;
  188311. for (i = 0; i < totalNumInputChans; ++i)
  188312. {
  188313. if (inputChannels[i])
  188314. {
  188315. currentChansIn.setBit (i);
  188316. info->isInput = 1;
  188317. info->channelNum = i;
  188318. info->buffers[0] = info->buffers[1] = 0;
  188319. ++info;
  188320. ++numActiveInputChans;
  188321. }
  188322. }
  188323. for (i = 0; i < totalNumOutputChans; ++i)
  188324. {
  188325. if (outputChannels[i])
  188326. {
  188327. currentChansOut.setBit (i);
  188328. info->isInput = 0;
  188329. info->channelNum = i;
  188330. info->buffers[0] = info->buffers[1] = 0;
  188331. ++info;
  188332. ++numActiveOutputChans;
  188333. }
  188334. }
  188335. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188336. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188337. if (currentASIODev[0] == this)
  188338. {
  188339. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188340. callbacks.asioMessage = &asioMessagesCallback0;
  188341. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188342. }
  188343. else if (currentASIODev[1] == this)
  188344. {
  188345. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188346. callbacks.asioMessage = &asioMessagesCallback1;
  188347. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188348. }
  188349. else if (currentASIODev[2] == this)
  188350. {
  188351. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188352. callbacks.asioMessage = &asioMessagesCallback2;
  188353. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188354. }
  188355. else
  188356. {
  188357. jassertfalse
  188358. }
  188359. log ("disposing buffers");
  188360. err = asioObject->disposeBuffers();
  188361. log ("creating buffers: " + String (totalBuffers) + ", " + String (currentBlockSizeSamples));
  188362. err = asioObject->createBuffers (bufferInfos,
  188363. totalBuffers,
  188364. currentBlockSizeSamples,
  188365. &callbacks);
  188366. if (err != 0)
  188367. {
  188368. currentBlockSizeSamples = preferredSize;
  188369. logError ("create buffers 2", err);
  188370. asioObject->disposeBuffers();
  188371. err = asioObject->createBuffers (bufferInfos,
  188372. totalBuffers,
  188373. currentBlockSizeSamples,
  188374. &callbacks);
  188375. }
  188376. if (err == 0)
  188377. {
  188378. buffersCreated = true;
  188379. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188380. int n = 0;
  188381. Array <int> types;
  188382. currentBitDepth = 16;
  188383. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188384. {
  188385. if (inputChannels[i])
  188386. {
  188387. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188388. ASIOChannelInfo channelInfo;
  188389. zerostruct (channelInfo);
  188390. channelInfo.channel = i;
  188391. channelInfo.isInput = 1;
  188392. asioObject->getChannelInfo (&channelInfo);
  188393. types.addIfNotAlreadyThere (channelInfo.type);
  188394. typeToFormatParameters (channelInfo.type,
  188395. inputChannelBitDepths[n],
  188396. inputChannelBytesPerSample[n],
  188397. inputChannelIsFloat[n],
  188398. inputChannelLittleEndian[n]);
  188399. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188400. ++n;
  188401. }
  188402. }
  188403. jassert (numActiveInputChans == n);
  188404. n = 0;
  188405. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188406. {
  188407. if (outputChannels[i])
  188408. {
  188409. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188410. ASIOChannelInfo channelInfo;
  188411. zerostruct (channelInfo);
  188412. channelInfo.channel = i;
  188413. channelInfo.isInput = 0;
  188414. asioObject->getChannelInfo (&channelInfo);
  188415. types.addIfNotAlreadyThere (channelInfo.type);
  188416. typeToFormatParameters (channelInfo.type,
  188417. outputChannelBitDepths[n],
  188418. outputChannelBytesPerSample[n],
  188419. outputChannelIsFloat[n],
  188420. outputChannelLittleEndian[n]);
  188421. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188422. ++n;
  188423. }
  188424. }
  188425. jassert (numActiveOutputChans == n);
  188426. for (i = types.size(); --i >= 0;)
  188427. {
  188428. log ("channel format: " + String (types[i]));
  188429. }
  188430. jassert (n <= totalBuffers);
  188431. for (i = 0; i < numActiveOutputChans; ++i)
  188432. {
  188433. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188434. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188435. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188436. {
  188437. log ("!! Null buffers");
  188438. }
  188439. else
  188440. {
  188441. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188442. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188443. }
  188444. }
  188445. inputLatency = outputLatency = 0;
  188446. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188447. {
  188448. log ("ASIO - no latencies");
  188449. }
  188450. else
  188451. {
  188452. log ("ASIO latencies: " + String ((int) outputLatency) + ", " + String ((int) inputLatency));
  188453. }
  188454. isOpen_ = true;
  188455. log ("starting ASIO");
  188456. calledback = false;
  188457. err = asioObject->start();
  188458. if (err != 0)
  188459. {
  188460. isOpen_ = false;
  188461. log ("ASIO - stop on failure");
  188462. Thread::sleep (10);
  188463. asioObject->stop();
  188464. error = "Can't start device";
  188465. Thread::sleep (10);
  188466. }
  188467. else
  188468. {
  188469. int count = 300;
  188470. while (--count > 0 && ! calledback)
  188471. Thread::sleep (10);
  188472. isStarted = true;
  188473. if (! calledback)
  188474. {
  188475. error = "Device didn't start correctly";
  188476. log ("ASIO didn't callback - stopping..");
  188477. asioObject->stop();
  188478. }
  188479. }
  188480. }
  188481. else
  188482. {
  188483. error = "Can't create i/o buffers";
  188484. }
  188485. }
  188486. else
  188487. {
  188488. error = "Can't set sample rate: ";
  188489. error << sampleRate;
  188490. }
  188491. if (error.isNotEmpty())
  188492. {
  188493. logError (error, err);
  188494. if (asioObject != 0 && buffersCreated)
  188495. asioObject->disposeBuffers();
  188496. Thread::sleep (20);
  188497. isStarted = false;
  188498. isOpen_ = false;
  188499. close();
  188500. }
  188501. needToReset = false;
  188502. isReSync = false;
  188503. return error;
  188504. }
  188505. void close()
  188506. {
  188507. error = String::empty;
  188508. stopTimer();
  188509. stop();
  188510. if (isASIOOpen && isOpen_)
  188511. {
  188512. const ScopedLock sl (callbackLock);
  188513. isOpen_ = false;
  188514. isStarted = false;
  188515. needToReset = false;
  188516. isReSync = false;
  188517. log ("ASIO - stopping");
  188518. if (asioObject != 0)
  188519. {
  188520. Thread::sleep (20);
  188521. asioObject->stop();
  188522. Thread::sleep (10);
  188523. asioObject->disposeBuffers();
  188524. }
  188525. Thread::sleep (10);
  188526. }
  188527. }
  188528. bool isOpen()
  188529. {
  188530. return isOpen_ || insideControlPanelModalLoop;
  188531. }
  188532. int getCurrentBufferSizeSamples()
  188533. {
  188534. return currentBlockSizeSamples;
  188535. }
  188536. double getCurrentSampleRate()
  188537. {
  188538. return currentSampleRate;
  188539. }
  188540. const BigInteger getActiveOutputChannels() const
  188541. {
  188542. return currentChansOut;
  188543. }
  188544. const BigInteger getActiveInputChannels() const
  188545. {
  188546. return currentChansIn;
  188547. }
  188548. int getCurrentBitDepth()
  188549. {
  188550. return currentBitDepth;
  188551. }
  188552. int getOutputLatencyInSamples()
  188553. {
  188554. return outputLatency + currentBlockSizeSamples / 4;
  188555. }
  188556. int getInputLatencyInSamples()
  188557. {
  188558. return inputLatency + currentBlockSizeSamples / 4;
  188559. }
  188560. void start (AudioIODeviceCallback* callback)
  188561. {
  188562. if (callback != 0)
  188563. {
  188564. callback->audioDeviceAboutToStart (this);
  188565. const ScopedLock sl (callbackLock);
  188566. currentCallback = callback;
  188567. }
  188568. }
  188569. void stop()
  188570. {
  188571. AudioIODeviceCallback* const lastCallback = currentCallback;
  188572. {
  188573. const ScopedLock sl (callbackLock);
  188574. currentCallback = 0;
  188575. }
  188576. if (lastCallback != 0)
  188577. lastCallback->audioDeviceStopped();
  188578. }
  188579. bool isPlaying()
  188580. {
  188581. return isASIOOpen && (currentCallback != 0);
  188582. }
  188583. const String getLastError()
  188584. {
  188585. return error;
  188586. }
  188587. bool hasControlPanel() const
  188588. {
  188589. return true;
  188590. }
  188591. bool showControlPanel()
  188592. {
  188593. log ("ASIO - showing control panel");
  188594. Component modalWindow (String::empty);
  188595. modalWindow.setOpaque (true);
  188596. modalWindow.addToDesktop (0);
  188597. modalWindow.enterModalState();
  188598. bool done = false;
  188599. JUCE_TRY
  188600. {
  188601. // are there are devices that need to be closed before showing their control panel?
  188602. // close();
  188603. insideControlPanelModalLoop = true;
  188604. const uint32 started = Time::getMillisecondCounter();
  188605. if (asioObject != 0)
  188606. {
  188607. asioObject->controlPanel();
  188608. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188609. log ("spent: " + String (spent));
  188610. if (spent > 300)
  188611. {
  188612. shouldUsePreferredSize = true;
  188613. done = true;
  188614. }
  188615. }
  188616. }
  188617. JUCE_CATCH_ALL
  188618. insideControlPanelModalLoop = false;
  188619. return done;
  188620. }
  188621. void resetRequest() throw()
  188622. {
  188623. needToReset = true;
  188624. }
  188625. void resyncRequest() throw()
  188626. {
  188627. needToReset = true;
  188628. isReSync = true;
  188629. }
  188630. void timerCallback()
  188631. {
  188632. if (! insideControlPanelModalLoop)
  188633. {
  188634. stopTimer();
  188635. // used to cause a reset
  188636. log ("! ASIO restart request!");
  188637. if (isOpen_)
  188638. {
  188639. AudioIODeviceCallback* const oldCallback = currentCallback;
  188640. close();
  188641. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188642. currentSampleRate, currentBlockSizeSamples);
  188643. if (oldCallback != 0)
  188644. start (oldCallback);
  188645. }
  188646. }
  188647. else
  188648. {
  188649. startTimer (100);
  188650. }
  188651. }
  188652. juce_UseDebuggingNewOperator
  188653. private:
  188654. IASIO* volatile asioObject;
  188655. ASIOCallbacks callbacks;
  188656. void* windowHandle;
  188657. CLSID classId;
  188658. const String optionalDllForDirectLoading;
  188659. String error;
  188660. long totalNumInputChans, totalNumOutputChans;
  188661. StringArray inputChannelNames, outputChannelNames;
  188662. Array<int> sampleRates, bufferSizes;
  188663. long inputLatency, outputLatency;
  188664. long minSize, maxSize, preferredSize, granularity;
  188665. int volatile currentBlockSizeSamples;
  188666. int volatile currentBitDepth;
  188667. double volatile currentSampleRate;
  188668. BigInteger currentChansOut, currentChansIn;
  188669. AudioIODeviceCallback* volatile currentCallback;
  188670. CriticalSection callbackLock;
  188671. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188672. float* inBuffers [maxASIOChannels];
  188673. float* outBuffers [maxASIOChannels];
  188674. int inputChannelBitDepths [maxASIOChannels];
  188675. int outputChannelBitDepths [maxASIOChannels];
  188676. int inputChannelBytesPerSample [maxASIOChannels];
  188677. int outputChannelBytesPerSample [maxASIOChannels];
  188678. bool inputChannelIsFloat [maxASIOChannels];
  188679. bool outputChannelIsFloat [maxASIOChannels];
  188680. bool inputChannelLittleEndian [maxASIOChannels];
  188681. bool outputChannelLittleEndian [maxASIOChannels];
  188682. WaitableEvent event1;
  188683. HeapBlock <float> tempBuffer;
  188684. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188685. bool isOpen_, isStarted;
  188686. bool volatile isASIOOpen;
  188687. bool volatile calledback;
  188688. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188689. bool volatile insideControlPanelModalLoop;
  188690. bool volatile shouldUsePreferredSize;
  188691. void removeCurrentDriver()
  188692. {
  188693. if (asioObject != 0)
  188694. {
  188695. asioObject->Release();
  188696. asioObject = 0;
  188697. }
  188698. }
  188699. bool loadDriver()
  188700. {
  188701. removeCurrentDriver();
  188702. JUCE_TRY
  188703. {
  188704. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188705. classId, (void**) &asioObject) == S_OK)
  188706. {
  188707. return true;
  188708. }
  188709. // If a class isn't registered but we have a path for it, we can fallback to
  188710. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188711. if (optionalDllForDirectLoading.isNotEmpty())
  188712. {
  188713. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188714. if (h != 0)
  188715. {
  188716. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188717. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188718. if (dllGetClassObject != 0)
  188719. {
  188720. IClassFactory* classFactory = 0;
  188721. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188722. if (classFactory != 0)
  188723. {
  188724. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188725. classFactory->Release();
  188726. }
  188727. return asioObject != 0;
  188728. }
  188729. }
  188730. }
  188731. }
  188732. JUCE_CATCH_ALL
  188733. asioObject = 0;
  188734. return false;
  188735. }
  188736. const String initDriver()
  188737. {
  188738. if (asioObject != 0)
  188739. {
  188740. char buffer [256];
  188741. zeromem (buffer, sizeof (buffer));
  188742. if (! asioObject->init (windowHandle))
  188743. {
  188744. asioObject->getErrorMessage (buffer);
  188745. return String (buffer, sizeof (buffer) - 1);
  188746. }
  188747. // just in case any daft drivers expect this to be called..
  188748. asioObject->getDriverName (buffer);
  188749. return String::empty;
  188750. }
  188751. return "No Driver";
  188752. }
  188753. const String openDevice()
  188754. {
  188755. // use this in case the driver starts opening dialog boxes..
  188756. Component modalWindow (String::empty);
  188757. modalWindow.setOpaque (true);
  188758. modalWindow.addToDesktop (0);
  188759. modalWindow.enterModalState();
  188760. // open the device and get its info..
  188761. log ("opening ASIO device: " + getName());
  188762. needToReset = false;
  188763. isReSync = false;
  188764. outputChannelNames.clear();
  188765. inputChannelNames.clear();
  188766. bufferSizes.clear();
  188767. sampleRates.clear();
  188768. isASIOOpen = false;
  188769. isOpen_ = false;
  188770. totalNumInputChans = 0;
  188771. totalNumOutputChans = 0;
  188772. numActiveInputChans = 0;
  188773. numActiveOutputChans = 0;
  188774. currentCallback = 0;
  188775. error = String::empty;
  188776. if (getName().isEmpty())
  188777. return error;
  188778. long err = 0;
  188779. if (loadDriver())
  188780. {
  188781. if ((error = initDriver()).isEmpty())
  188782. {
  188783. numActiveInputChans = 0;
  188784. numActiveOutputChans = 0;
  188785. totalNumInputChans = 0;
  188786. totalNumOutputChans = 0;
  188787. if (asioObject != 0
  188788. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188789. {
  188790. log (String ((int) totalNumInputChans) + " in, " + String ((int) totalNumOutputChans) + " out");
  188791. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188792. {
  188793. // find a list of buffer sizes..
  188794. log (String ((int) minSize) + " " + String ((int) maxSize) + " " + String ((int) preferredSize) + " " + String ((int) granularity));
  188795. if (granularity >= 0)
  188796. {
  188797. granularity = jmax (1, (int) granularity);
  188798. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188799. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188800. }
  188801. else if (granularity < 0)
  188802. {
  188803. for (int i = 0; i < 18; ++i)
  188804. {
  188805. const int s = (1 << i);
  188806. if (s >= minSize && s <= maxSize)
  188807. bufferSizes.add (s);
  188808. }
  188809. }
  188810. if (! bufferSizes.contains (preferredSize))
  188811. bufferSizes.insert (0, preferredSize);
  188812. double currentRate = 0;
  188813. asioObject->getSampleRate (&currentRate);
  188814. if (currentRate <= 0.0 || currentRate > 192001.0)
  188815. {
  188816. log ("setting sample rate");
  188817. err = asioObject->setSampleRate (44100.0);
  188818. if (err != 0)
  188819. {
  188820. logError ("setting sample rate", err);
  188821. }
  188822. asioObject->getSampleRate (&currentRate);
  188823. }
  188824. currentSampleRate = currentRate;
  188825. postOutput = (asioObject->outputReady() == 0);
  188826. if (postOutput)
  188827. {
  188828. log ("ASIO outputReady = ok");
  188829. }
  188830. updateSampleRates();
  188831. // ..because cubase does it at this point
  188832. inputLatency = outputLatency = 0;
  188833. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188834. {
  188835. log ("ASIO - no latencies");
  188836. }
  188837. log ("latencies: " + String ((int) inputLatency) + ", " + String ((int) outputLatency));
  188838. // create some dummy buffers now.. because cubase does..
  188839. numActiveInputChans = 0;
  188840. numActiveOutputChans = 0;
  188841. ASIOBufferInfo* info = bufferInfos;
  188842. int i, numChans = 0;
  188843. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188844. {
  188845. info->isInput = 1;
  188846. info->channelNum = i;
  188847. info->buffers[0] = info->buffers[1] = 0;
  188848. ++info;
  188849. ++numChans;
  188850. }
  188851. const int outputBufferIndex = numChans;
  188852. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188853. {
  188854. info->isInput = 0;
  188855. info->channelNum = i;
  188856. info->buffers[0] = info->buffers[1] = 0;
  188857. ++info;
  188858. ++numChans;
  188859. }
  188860. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188861. if (currentASIODev[0] == this)
  188862. {
  188863. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188864. callbacks.asioMessage = &asioMessagesCallback0;
  188865. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188866. }
  188867. else if (currentASIODev[1] == this)
  188868. {
  188869. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188870. callbacks.asioMessage = &asioMessagesCallback1;
  188871. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188872. }
  188873. else if (currentASIODev[2] == this)
  188874. {
  188875. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188876. callbacks.asioMessage = &asioMessagesCallback2;
  188877. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188878. }
  188879. else
  188880. {
  188881. jassertfalse
  188882. }
  188883. log ("creating buffers (dummy): " + String (numChans) + ", " + String ((int) preferredSize));
  188884. if (preferredSize > 0)
  188885. {
  188886. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  188887. if (err != 0)
  188888. {
  188889. logError ("dummy buffers", err);
  188890. }
  188891. }
  188892. long newInps = 0, newOuts = 0;
  188893. asioObject->getChannels (&newInps, &newOuts);
  188894. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  188895. {
  188896. totalNumInputChans = newInps;
  188897. totalNumOutputChans = newOuts;
  188898. log (String ((int) totalNumInputChans) + " in; " + String ((int) totalNumOutputChans) + " out");
  188899. }
  188900. updateSampleRates();
  188901. ASIOChannelInfo channelInfo;
  188902. channelInfo.type = 0;
  188903. for (i = 0; i < totalNumInputChans; ++i)
  188904. {
  188905. zerostruct (channelInfo);
  188906. channelInfo.channel = i;
  188907. channelInfo.isInput = 1;
  188908. asioObject->getChannelInfo (&channelInfo);
  188909. inputChannelNames.add (String (channelInfo.name));
  188910. }
  188911. for (i = 0; i < totalNumOutputChans; ++i)
  188912. {
  188913. zerostruct (channelInfo);
  188914. channelInfo.channel = i;
  188915. channelInfo.isInput = 0;
  188916. asioObject->getChannelInfo (&channelInfo);
  188917. outputChannelNames.add (String (channelInfo.name));
  188918. typeToFormatParameters (channelInfo.type,
  188919. outputChannelBitDepths[i],
  188920. outputChannelBytesPerSample[i],
  188921. outputChannelIsFloat[i],
  188922. outputChannelLittleEndian[i]);
  188923. if (i < 2)
  188924. {
  188925. // clear the channels that are used with the dummy stuff
  188926. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  188927. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  188928. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  188929. }
  188930. }
  188931. outputChannelNames.trim();
  188932. inputChannelNames.trim();
  188933. outputChannelNames.appendNumbersToDuplicates (false, true);
  188934. inputChannelNames.appendNumbersToDuplicates (false, true);
  188935. // start and stop because cubase does it..
  188936. asioObject->getLatencies (&inputLatency, &outputLatency);
  188937. if ((err = asioObject->start()) != 0)
  188938. {
  188939. // ignore an error here, as it might start later after setting other stuff up
  188940. logError ("ASIO start", err);
  188941. }
  188942. Thread::sleep (100);
  188943. asioObject->stop();
  188944. }
  188945. else
  188946. {
  188947. error = "Can't detect buffer sizes";
  188948. }
  188949. }
  188950. else
  188951. {
  188952. error = "Can't detect asio channels";
  188953. }
  188954. }
  188955. }
  188956. else
  188957. {
  188958. error = "No such device";
  188959. }
  188960. if (error.isNotEmpty())
  188961. {
  188962. logError (error, err);
  188963. if (asioObject != 0)
  188964. asioObject->disposeBuffers();
  188965. removeCurrentDriver();
  188966. isASIOOpen = false;
  188967. }
  188968. else
  188969. {
  188970. isASIOOpen = true;
  188971. log ("ASIO device open");
  188972. }
  188973. isOpen_ = false;
  188974. needToReset = false;
  188975. isReSync = false;
  188976. return error;
  188977. }
  188978. void callback (const long index) throw()
  188979. {
  188980. if (isStarted)
  188981. {
  188982. bufferIndex = index;
  188983. processBuffer();
  188984. }
  188985. else
  188986. {
  188987. if (postOutput && (asioObject != 0))
  188988. asioObject->outputReady();
  188989. }
  188990. calledback = true;
  188991. }
  188992. void processBuffer() throw()
  188993. {
  188994. const ASIOBufferInfo* const infos = bufferInfos;
  188995. const int bi = bufferIndex;
  188996. const ScopedLock sl (callbackLock);
  188997. if (needToReset)
  188998. {
  188999. needToReset = false;
  189000. if (isReSync)
  189001. {
  189002. log ("! ASIO resync");
  189003. isReSync = false;
  189004. }
  189005. else
  189006. {
  189007. startTimer (20);
  189008. }
  189009. }
  189010. if (bi >= 0)
  189011. {
  189012. const int samps = currentBlockSizeSamples;
  189013. if (currentCallback != 0)
  189014. {
  189015. int i;
  189016. for (i = 0; i < numActiveInputChans; ++i)
  189017. {
  189018. float* const dst = inBuffers[i];
  189019. jassert (dst != 0);
  189020. const char* const src = (const char*) (infos[i].buffers[bi]);
  189021. if (inputChannelIsFloat[i])
  189022. {
  189023. memcpy (dst, src, samps * sizeof (float));
  189024. }
  189025. else
  189026. {
  189027. jassert (dst == tempBuffer + (samps * i));
  189028. switch (inputChannelBitDepths[i])
  189029. {
  189030. case 16:
  189031. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189032. samps, inputChannelLittleEndian[i]);
  189033. break;
  189034. case 24:
  189035. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189036. samps, inputChannelLittleEndian[i]);
  189037. break;
  189038. case 32:
  189039. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189040. samps, inputChannelLittleEndian[i]);
  189041. break;
  189042. case 64:
  189043. jassertfalse
  189044. break;
  189045. }
  189046. }
  189047. }
  189048. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189049. numActiveInputChans,
  189050. outBuffers,
  189051. numActiveOutputChans,
  189052. samps);
  189053. for (i = 0; i < numActiveOutputChans; ++i)
  189054. {
  189055. float* const src = outBuffers[i];
  189056. jassert (src != 0);
  189057. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189058. if (outputChannelIsFloat[i])
  189059. {
  189060. memcpy (dst, src, samps * sizeof (float));
  189061. }
  189062. else
  189063. {
  189064. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189065. switch (outputChannelBitDepths[i])
  189066. {
  189067. case 16:
  189068. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189069. samps, outputChannelLittleEndian[i]);
  189070. break;
  189071. case 24:
  189072. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189073. samps, outputChannelLittleEndian[i]);
  189074. break;
  189075. case 32:
  189076. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189077. samps, outputChannelLittleEndian[i]);
  189078. break;
  189079. case 64:
  189080. jassertfalse
  189081. break;
  189082. }
  189083. }
  189084. }
  189085. }
  189086. else
  189087. {
  189088. for (int i = 0; i < numActiveOutputChans; ++i)
  189089. {
  189090. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189091. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189092. }
  189093. }
  189094. }
  189095. if (postOutput)
  189096. asioObject->outputReady();
  189097. }
  189098. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189099. {
  189100. if (currentASIODev[0] != 0)
  189101. currentASIODev[0]->callback (index);
  189102. return 0;
  189103. }
  189104. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189105. {
  189106. if (currentASIODev[1] != 0)
  189107. currentASIODev[1]->callback (index);
  189108. return 0;
  189109. }
  189110. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189111. {
  189112. if (currentASIODev[2] != 0)
  189113. currentASIODev[2]->callback (index);
  189114. return 0;
  189115. }
  189116. static void bufferSwitchCallback0 (long index, long) throw()
  189117. {
  189118. if (currentASIODev[0] != 0)
  189119. currentASIODev[0]->callback (index);
  189120. }
  189121. static void bufferSwitchCallback1 (long index, long) throw()
  189122. {
  189123. if (currentASIODev[1] != 0)
  189124. currentASIODev[1]->callback (index);
  189125. }
  189126. static void bufferSwitchCallback2 (long index, long) throw()
  189127. {
  189128. if (currentASIODev[2] != 0)
  189129. currentASIODev[2]->callback (index);
  189130. }
  189131. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189132. {
  189133. return asioMessagesCallback (selector, value, 0);
  189134. }
  189135. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189136. {
  189137. return asioMessagesCallback (selector, value, 1);
  189138. }
  189139. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189140. {
  189141. return asioMessagesCallback (selector, value, 2);
  189142. }
  189143. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189144. {
  189145. switch (selector)
  189146. {
  189147. case kAsioSelectorSupported:
  189148. if (value == kAsioResetRequest
  189149. || value == kAsioEngineVersion
  189150. || value == kAsioResyncRequest
  189151. || value == kAsioLatenciesChanged
  189152. || value == kAsioSupportsInputMonitor)
  189153. return 1;
  189154. break;
  189155. case kAsioBufferSizeChange:
  189156. break;
  189157. case kAsioResetRequest:
  189158. if (currentASIODev[deviceIndex] != 0)
  189159. currentASIODev[deviceIndex]->resetRequest();
  189160. return 1;
  189161. case kAsioResyncRequest:
  189162. if (currentASIODev[deviceIndex] != 0)
  189163. currentASIODev[deviceIndex]->resyncRequest();
  189164. return 1;
  189165. case kAsioLatenciesChanged:
  189166. return 1;
  189167. case kAsioEngineVersion:
  189168. return 2;
  189169. case kAsioSupportsTimeInfo:
  189170. case kAsioSupportsTimeCode:
  189171. return 0;
  189172. }
  189173. return 0;
  189174. }
  189175. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189176. {
  189177. }
  189178. static void convertInt16ToFloat (const char* src,
  189179. float* dest,
  189180. const int srcStrideBytes,
  189181. int numSamples,
  189182. const bool littleEndian) throw()
  189183. {
  189184. const double g = 1.0 / 32768.0;
  189185. if (littleEndian)
  189186. {
  189187. while (--numSamples >= 0)
  189188. {
  189189. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189190. src += srcStrideBytes;
  189191. }
  189192. }
  189193. else
  189194. {
  189195. while (--numSamples >= 0)
  189196. {
  189197. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189198. src += srcStrideBytes;
  189199. }
  189200. }
  189201. }
  189202. static void convertFloatToInt16 (const float* src,
  189203. char* dest,
  189204. const int dstStrideBytes,
  189205. int numSamples,
  189206. const bool littleEndian) throw()
  189207. {
  189208. const double maxVal = (double) 0x7fff;
  189209. if (littleEndian)
  189210. {
  189211. while (--numSamples >= 0)
  189212. {
  189213. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189214. dest += dstStrideBytes;
  189215. }
  189216. }
  189217. else
  189218. {
  189219. while (--numSamples >= 0)
  189220. {
  189221. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189222. dest += dstStrideBytes;
  189223. }
  189224. }
  189225. }
  189226. static void convertInt24ToFloat (const char* src,
  189227. float* dest,
  189228. const int srcStrideBytes,
  189229. int numSamples,
  189230. const bool littleEndian) throw()
  189231. {
  189232. const double g = 1.0 / 0x7fffff;
  189233. if (littleEndian)
  189234. {
  189235. while (--numSamples >= 0)
  189236. {
  189237. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189238. src += srcStrideBytes;
  189239. }
  189240. }
  189241. else
  189242. {
  189243. while (--numSamples >= 0)
  189244. {
  189245. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189246. src += srcStrideBytes;
  189247. }
  189248. }
  189249. }
  189250. static void convertFloatToInt24 (const float* src,
  189251. char* dest,
  189252. const int dstStrideBytes,
  189253. int numSamples,
  189254. const bool littleEndian) throw()
  189255. {
  189256. const double maxVal = (double) 0x7fffff;
  189257. if (littleEndian)
  189258. {
  189259. while (--numSamples >= 0)
  189260. {
  189261. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189262. dest += dstStrideBytes;
  189263. }
  189264. }
  189265. else
  189266. {
  189267. while (--numSamples >= 0)
  189268. {
  189269. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189270. dest += dstStrideBytes;
  189271. }
  189272. }
  189273. }
  189274. static void convertInt32ToFloat (const char* src,
  189275. float* dest,
  189276. const int srcStrideBytes,
  189277. int numSamples,
  189278. const bool littleEndian) throw()
  189279. {
  189280. const double g = 1.0 / 0x7fffffff;
  189281. if (littleEndian)
  189282. {
  189283. while (--numSamples >= 0)
  189284. {
  189285. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189286. src += srcStrideBytes;
  189287. }
  189288. }
  189289. else
  189290. {
  189291. while (--numSamples >= 0)
  189292. {
  189293. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189294. src += srcStrideBytes;
  189295. }
  189296. }
  189297. }
  189298. static void convertFloatToInt32 (const float* src,
  189299. char* dest,
  189300. const int dstStrideBytes,
  189301. int numSamples,
  189302. const bool littleEndian) throw()
  189303. {
  189304. const double maxVal = (double) 0x7fffffff;
  189305. if (littleEndian)
  189306. {
  189307. while (--numSamples >= 0)
  189308. {
  189309. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189310. dest += dstStrideBytes;
  189311. }
  189312. }
  189313. else
  189314. {
  189315. while (--numSamples >= 0)
  189316. {
  189317. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189318. dest += dstStrideBytes;
  189319. }
  189320. }
  189321. }
  189322. static void typeToFormatParameters (const long type,
  189323. int& bitDepth,
  189324. int& byteStride,
  189325. bool& formatIsFloat,
  189326. bool& littleEndian) throw()
  189327. {
  189328. bitDepth = 0;
  189329. littleEndian = false;
  189330. formatIsFloat = false;
  189331. switch (type)
  189332. {
  189333. case ASIOSTInt16MSB:
  189334. case ASIOSTInt16LSB:
  189335. case ASIOSTInt32MSB16:
  189336. case ASIOSTInt32LSB16:
  189337. bitDepth = 16; break;
  189338. case ASIOSTFloat32MSB:
  189339. case ASIOSTFloat32LSB:
  189340. formatIsFloat = true;
  189341. bitDepth = 32; break;
  189342. case ASIOSTInt32MSB:
  189343. case ASIOSTInt32LSB:
  189344. bitDepth = 32; break;
  189345. case ASIOSTInt24MSB:
  189346. case ASIOSTInt24LSB:
  189347. case ASIOSTInt32MSB24:
  189348. case ASIOSTInt32LSB24:
  189349. case ASIOSTInt32MSB18:
  189350. case ASIOSTInt32MSB20:
  189351. case ASIOSTInt32LSB18:
  189352. case ASIOSTInt32LSB20:
  189353. bitDepth = 24; break;
  189354. case ASIOSTFloat64MSB:
  189355. case ASIOSTFloat64LSB:
  189356. default:
  189357. bitDepth = 64;
  189358. break;
  189359. }
  189360. switch (type)
  189361. {
  189362. case ASIOSTInt16MSB:
  189363. case ASIOSTInt32MSB16:
  189364. case ASIOSTFloat32MSB:
  189365. case ASIOSTFloat64MSB:
  189366. case ASIOSTInt32MSB:
  189367. case ASIOSTInt32MSB18:
  189368. case ASIOSTInt32MSB20:
  189369. case ASIOSTInt32MSB24:
  189370. case ASIOSTInt24MSB:
  189371. littleEndian = false; break;
  189372. case ASIOSTInt16LSB:
  189373. case ASIOSTInt32LSB16:
  189374. case ASIOSTFloat32LSB:
  189375. case ASIOSTFloat64LSB:
  189376. case ASIOSTInt32LSB:
  189377. case ASIOSTInt32LSB18:
  189378. case ASIOSTInt32LSB20:
  189379. case ASIOSTInt32LSB24:
  189380. case ASIOSTInt24LSB:
  189381. littleEndian = true; break;
  189382. default:
  189383. break;
  189384. }
  189385. switch (type)
  189386. {
  189387. case ASIOSTInt16LSB:
  189388. case ASIOSTInt16MSB:
  189389. byteStride = 2; break;
  189390. case ASIOSTInt24LSB:
  189391. case ASIOSTInt24MSB:
  189392. byteStride = 3; break;
  189393. case ASIOSTInt32MSB16:
  189394. case ASIOSTInt32LSB16:
  189395. case ASIOSTInt32MSB:
  189396. case ASIOSTInt32MSB18:
  189397. case ASIOSTInt32MSB20:
  189398. case ASIOSTInt32MSB24:
  189399. case ASIOSTInt32LSB:
  189400. case ASIOSTInt32LSB18:
  189401. case ASIOSTInt32LSB20:
  189402. case ASIOSTInt32LSB24:
  189403. case ASIOSTFloat32LSB:
  189404. case ASIOSTFloat32MSB:
  189405. byteStride = 4; break;
  189406. case ASIOSTFloat64MSB:
  189407. case ASIOSTFloat64LSB:
  189408. byteStride = 8; break;
  189409. default:
  189410. break;
  189411. }
  189412. }
  189413. };
  189414. class ASIOAudioIODeviceType : public AudioIODeviceType
  189415. {
  189416. public:
  189417. ASIOAudioIODeviceType()
  189418. : AudioIODeviceType ("ASIO"),
  189419. hasScanned (false)
  189420. {
  189421. CoInitialize (0);
  189422. }
  189423. ~ASIOAudioIODeviceType()
  189424. {
  189425. }
  189426. void scanForDevices()
  189427. {
  189428. hasScanned = true;
  189429. deviceNames.clear();
  189430. classIds.clear();
  189431. HKEY hk = 0;
  189432. int index = 0;
  189433. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189434. {
  189435. for (;;)
  189436. {
  189437. char name [256];
  189438. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189439. {
  189440. addDriverInfo (name, hk);
  189441. }
  189442. else
  189443. {
  189444. break;
  189445. }
  189446. }
  189447. RegCloseKey (hk);
  189448. }
  189449. }
  189450. const StringArray getDeviceNames (bool /*wantInputNames*/) const
  189451. {
  189452. jassert (hasScanned); // need to call scanForDevices() before doing this
  189453. return deviceNames;
  189454. }
  189455. int getDefaultDeviceIndex (bool) const
  189456. {
  189457. jassert (hasScanned); // need to call scanForDevices() before doing this
  189458. for (int i = deviceNames.size(); --i >= 0;)
  189459. if (deviceNames[i].containsIgnoreCase ("asio4all"))
  189460. return i; // asio4all is a safe choice for a default..
  189461. #if JUCE_DEBUG
  189462. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase ("digidesign"))
  189463. return 1; // (the digi m-box driver crashes the app when you run
  189464. // it in the debugger, which can be a bit annoying)
  189465. #endif
  189466. return 0;
  189467. }
  189468. static int findFreeSlot()
  189469. {
  189470. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189471. if (currentASIODev[i] == 0)
  189472. return i;
  189473. jassertfalse; // unfortunately you can only have a finite number
  189474. // of ASIO devices open at the same time..
  189475. return -1;
  189476. }
  189477. int getIndexOfDevice (AudioIODevice* d, bool /*asInput*/) const
  189478. {
  189479. jassert (hasScanned); // need to call scanForDevices() before doing this
  189480. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189481. }
  189482. bool hasSeparateInputsAndOutputs() const { return false; }
  189483. AudioIODevice* createDevice (const String& outputDeviceName,
  189484. const String& inputDeviceName)
  189485. {
  189486. // ASIO can't open two different devices for input and output - they must be the same one.
  189487. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189488. jassert (hasScanned); // need to call scanForDevices() before doing this
  189489. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189490. : inputDeviceName);
  189491. if (index >= 0)
  189492. {
  189493. const int freeSlot = findFreeSlot();
  189494. if (freeSlot >= 0)
  189495. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189496. }
  189497. return 0;
  189498. }
  189499. juce_UseDebuggingNewOperator
  189500. private:
  189501. StringArray deviceNames;
  189502. OwnedArray <CLSID> classIds;
  189503. bool hasScanned;
  189504. static bool checkClassIsOk (const String& classId)
  189505. {
  189506. HKEY hk = 0;
  189507. bool ok = false;
  189508. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189509. {
  189510. int index = 0;
  189511. for (;;)
  189512. {
  189513. WCHAR buf [512];
  189514. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189515. {
  189516. if (classId.equalsIgnoreCase (buf))
  189517. {
  189518. HKEY subKey, pathKey;
  189519. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189520. {
  189521. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189522. {
  189523. WCHAR pathName [1024];
  189524. DWORD dtype = REG_SZ;
  189525. DWORD dsize = sizeof (pathName);
  189526. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189527. ok = File (pathName).exists();
  189528. RegCloseKey (pathKey);
  189529. }
  189530. RegCloseKey (subKey);
  189531. }
  189532. break;
  189533. }
  189534. }
  189535. else
  189536. {
  189537. break;
  189538. }
  189539. }
  189540. RegCloseKey (hk);
  189541. }
  189542. return ok;
  189543. }
  189544. void addDriverInfo (const String& keyName, HKEY hk)
  189545. {
  189546. HKEY subKey;
  189547. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189548. {
  189549. WCHAR buf [256];
  189550. zerostruct (buf);
  189551. DWORD dtype = REG_SZ;
  189552. DWORD dsize = sizeof (buf);
  189553. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189554. {
  189555. if (dsize > 0 && checkClassIsOk (buf))
  189556. {
  189557. CLSID classId;
  189558. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189559. {
  189560. dtype = REG_SZ;
  189561. dsize = sizeof (buf);
  189562. String deviceName;
  189563. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189564. deviceName = buf;
  189565. else
  189566. deviceName = keyName;
  189567. log ("found " + deviceName);
  189568. deviceNames.add (deviceName);
  189569. classIds.add (new CLSID (classId));
  189570. }
  189571. }
  189572. RegCloseKey (subKey);
  189573. }
  189574. }
  189575. }
  189576. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189577. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189578. };
  189579. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189580. {
  189581. return new ASIOAudioIODeviceType();
  189582. }
  189583. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189584. void* guid,
  189585. const String& optionalDllForDirectLoading)
  189586. {
  189587. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189588. if (freeSlot < 0)
  189589. return 0;
  189590. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189591. }
  189592. #undef log
  189593. #endif
  189594. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189595. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189596. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189597. // compiled on its own).
  189598. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189599. END_JUCE_NAMESPACE
  189600. extern "C"
  189601. {
  189602. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189603. typedef struct typeDSBUFFERDESC
  189604. {
  189605. DWORD dwSize;
  189606. DWORD dwFlags;
  189607. DWORD dwBufferBytes;
  189608. DWORD dwReserved;
  189609. LPWAVEFORMATEX lpwfxFormat;
  189610. GUID guid3DAlgorithm;
  189611. } DSBUFFERDESC;
  189612. struct IDirectSoundBuffer;
  189613. #undef INTERFACE
  189614. #define INTERFACE IDirectSound
  189615. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189616. {
  189617. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189618. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189619. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189620. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189621. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189622. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189623. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189624. STDMETHOD(Compact) (THIS) PURE;
  189625. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189626. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189627. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189628. };
  189629. #undef INTERFACE
  189630. #define INTERFACE IDirectSoundBuffer
  189631. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189632. {
  189633. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189634. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189635. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189636. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189637. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189638. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189639. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189640. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189641. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189642. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189643. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189644. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189645. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189646. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189647. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189648. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189649. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189650. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189651. STDMETHOD(Stop) (THIS) PURE;
  189652. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189653. STDMETHOD(Restore) (THIS) PURE;
  189654. };
  189655. typedef struct typeDSCBUFFERDESC
  189656. {
  189657. DWORD dwSize;
  189658. DWORD dwFlags;
  189659. DWORD dwBufferBytes;
  189660. DWORD dwReserved;
  189661. LPWAVEFORMATEX lpwfxFormat;
  189662. } DSCBUFFERDESC;
  189663. struct IDirectSoundCaptureBuffer;
  189664. #undef INTERFACE
  189665. #define INTERFACE IDirectSoundCapture
  189666. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189667. {
  189668. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189669. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189670. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189671. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189672. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189673. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189674. };
  189675. #undef INTERFACE
  189676. #define INTERFACE IDirectSoundCaptureBuffer
  189677. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189678. {
  189679. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189680. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189681. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189682. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189683. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189684. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189685. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189686. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189687. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189688. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189689. STDMETHOD(Stop) (THIS) PURE;
  189690. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189691. };
  189692. };
  189693. BEGIN_JUCE_NAMESPACE
  189694. static const String getDSErrorMessage (HRESULT hr)
  189695. {
  189696. const char* result = 0;
  189697. switch (hr)
  189698. {
  189699. case MAKE_HRESULT(1, 0x878, 10):
  189700. result = "Device already allocated";
  189701. break;
  189702. case MAKE_HRESULT(1, 0x878, 30):
  189703. result = "Control unavailable";
  189704. break;
  189705. case E_INVALIDARG:
  189706. result = "Invalid parameter";
  189707. break;
  189708. case MAKE_HRESULT(1, 0x878, 50):
  189709. result = "Invalid call";
  189710. break;
  189711. case E_FAIL:
  189712. result = "Generic error";
  189713. break;
  189714. case MAKE_HRESULT(1, 0x878, 70):
  189715. result = "Priority level error";
  189716. break;
  189717. case E_OUTOFMEMORY:
  189718. result = "Out of memory";
  189719. break;
  189720. case MAKE_HRESULT(1, 0x878, 100):
  189721. result = "Bad format";
  189722. break;
  189723. case E_NOTIMPL:
  189724. result = "Unsupported function";
  189725. break;
  189726. case MAKE_HRESULT(1, 0x878, 120):
  189727. result = "No driver";
  189728. break;
  189729. case MAKE_HRESULT(1, 0x878, 130):
  189730. result = "Already initialised";
  189731. break;
  189732. case CLASS_E_NOAGGREGATION:
  189733. result = "No aggregation";
  189734. break;
  189735. case MAKE_HRESULT(1, 0x878, 150):
  189736. result = "Buffer lost";
  189737. break;
  189738. case MAKE_HRESULT(1, 0x878, 160):
  189739. result = "Another app has priority";
  189740. break;
  189741. case MAKE_HRESULT(1, 0x878, 170):
  189742. result = "Uninitialised";
  189743. break;
  189744. case E_NOINTERFACE:
  189745. result = "No interface";
  189746. break;
  189747. case S_OK:
  189748. result = "No error";
  189749. break;
  189750. default:
  189751. return "Unknown error: " + String ((int) hr);
  189752. }
  189753. return result;
  189754. }
  189755. #define DS_DEBUGGING 1
  189756. #ifdef DS_DEBUGGING
  189757. #define CATCH JUCE_CATCH_EXCEPTION
  189758. #undef log
  189759. #define log(a) Logger::writeToLog(a);
  189760. #undef logError
  189761. #define logError(a) logDSError(a, __LINE__);
  189762. static void logDSError (HRESULT hr, int lineNum)
  189763. {
  189764. if (hr != S_OK)
  189765. {
  189766. String error ("DS error at line ");
  189767. error << lineNum << " - " << getDSErrorMessage (hr);
  189768. log (error);
  189769. }
  189770. }
  189771. #else
  189772. #define CATCH JUCE_CATCH_ALL
  189773. #define log(a)
  189774. #define logError(a)
  189775. #endif
  189776. #define DSOUND_FUNCTION(functionName, params) \
  189777. typedef HRESULT (WINAPI *type##functionName) params; \
  189778. static type##functionName ds##functionName = 0;
  189779. #define DSOUND_FUNCTION_LOAD(functionName) \
  189780. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189781. jassert (ds##functionName != 0);
  189782. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189783. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189784. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189785. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189786. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189787. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189788. static void initialiseDSoundFunctions()
  189789. {
  189790. if (dsDirectSoundCreate == 0)
  189791. {
  189792. HMODULE h = LoadLibraryA ("dsound.dll");
  189793. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189794. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189795. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189796. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189797. }
  189798. }
  189799. class DSoundInternalOutChannel
  189800. {
  189801. String name;
  189802. LPGUID guid;
  189803. int sampleRate, bufferSizeSamples;
  189804. float* leftBuffer;
  189805. float* rightBuffer;
  189806. IDirectSound* pDirectSound;
  189807. IDirectSoundBuffer* pOutputBuffer;
  189808. DWORD writeOffset;
  189809. int totalBytesPerBuffer;
  189810. int bytesPerBuffer;
  189811. unsigned int lastPlayCursor;
  189812. public:
  189813. int bitDepth;
  189814. bool doneFlag;
  189815. DSoundInternalOutChannel (const String& name_,
  189816. LPGUID guid_,
  189817. int rate,
  189818. int bufferSize,
  189819. float* left,
  189820. float* right)
  189821. : name (name_),
  189822. guid (guid_),
  189823. sampleRate (rate),
  189824. bufferSizeSamples (bufferSize),
  189825. leftBuffer (left),
  189826. rightBuffer (right),
  189827. pDirectSound (0),
  189828. pOutputBuffer (0),
  189829. bitDepth (16)
  189830. {
  189831. }
  189832. ~DSoundInternalOutChannel()
  189833. {
  189834. close();
  189835. }
  189836. void close()
  189837. {
  189838. HRESULT hr;
  189839. if (pOutputBuffer != 0)
  189840. {
  189841. JUCE_TRY
  189842. {
  189843. log ("closing dsound out: " + name);
  189844. hr = pOutputBuffer->Stop();
  189845. logError (hr);
  189846. }
  189847. CATCH
  189848. JUCE_TRY
  189849. {
  189850. hr = pOutputBuffer->Release();
  189851. logError (hr);
  189852. }
  189853. CATCH
  189854. pOutputBuffer = 0;
  189855. }
  189856. if (pDirectSound != 0)
  189857. {
  189858. JUCE_TRY
  189859. {
  189860. hr = pDirectSound->Release();
  189861. logError (hr);
  189862. }
  189863. CATCH
  189864. pDirectSound = 0;
  189865. }
  189866. }
  189867. const String open()
  189868. {
  189869. log ("opening dsound out device: " + name + " rate=" + String (sampleRate)
  189870. + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  189871. pDirectSound = 0;
  189872. pOutputBuffer = 0;
  189873. writeOffset = 0;
  189874. String error;
  189875. HRESULT hr = E_NOINTERFACE;
  189876. if (dsDirectSoundCreate != 0)
  189877. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  189878. if (hr == S_OK)
  189879. {
  189880. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189881. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189882. const int numChannels = 2;
  189883. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  189884. logError (hr);
  189885. if (hr == S_OK)
  189886. {
  189887. IDirectSoundBuffer* pPrimaryBuffer;
  189888. DSBUFFERDESC primaryDesc;
  189889. zerostruct (primaryDesc);
  189890. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189891. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  189892. primaryDesc.dwBufferBytes = 0;
  189893. primaryDesc.lpwfxFormat = 0;
  189894. log ("opening dsound out step 2");
  189895. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  189896. logError (hr);
  189897. if (hr == S_OK)
  189898. {
  189899. WAVEFORMATEX wfFormat;
  189900. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189901. wfFormat.nChannels = (unsigned short) numChannels;
  189902. wfFormat.nSamplesPerSec = sampleRate;
  189903. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  189904. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  189905. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189906. wfFormat.cbSize = 0;
  189907. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  189908. logError (hr);
  189909. if (hr == S_OK)
  189910. {
  189911. DSBUFFERDESC secondaryDesc;
  189912. zerostruct (secondaryDesc);
  189913. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189914. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  189915. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  189916. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  189917. secondaryDesc.lpwfxFormat = &wfFormat;
  189918. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  189919. logError (hr);
  189920. if (hr == S_OK)
  189921. {
  189922. log ("opening dsound out step 3");
  189923. DWORD dwDataLen;
  189924. unsigned char* pDSBuffData;
  189925. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  189926. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  189927. logError (hr);
  189928. if (hr == S_OK)
  189929. {
  189930. zeromem (pDSBuffData, dwDataLen);
  189931. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  189932. if (hr == S_OK)
  189933. {
  189934. hr = pOutputBuffer->SetCurrentPosition (0);
  189935. if (hr == S_OK)
  189936. {
  189937. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  189938. if (hr == S_OK)
  189939. return String::empty;
  189940. }
  189941. }
  189942. }
  189943. }
  189944. }
  189945. }
  189946. }
  189947. }
  189948. error = getDSErrorMessage (hr);
  189949. close();
  189950. return error;
  189951. }
  189952. void synchronisePosition()
  189953. {
  189954. if (pOutputBuffer != 0)
  189955. {
  189956. DWORD playCursor;
  189957. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  189958. }
  189959. }
  189960. bool service()
  189961. {
  189962. if (pOutputBuffer == 0)
  189963. return true;
  189964. DWORD playCursor, writeCursor;
  189965. for (;;)
  189966. {
  189967. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  189968. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189969. {
  189970. pOutputBuffer->Restore();
  189971. continue;
  189972. }
  189973. if (hr == S_OK)
  189974. break;
  189975. logError (hr);
  189976. jassertfalse
  189977. return true;
  189978. }
  189979. int playWriteGap = writeCursor - playCursor;
  189980. if (playWriteGap < 0)
  189981. playWriteGap += totalBytesPerBuffer;
  189982. int bytesEmpty = playCursor - writeOffset;
  189983. if (bytesEmpty < 0)
  189984. bytesEmpty += totalBytesPerBuffer;
  189985. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  189986. {
  189987. writeOffset = writeCursor;
  189988. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  189989. }
  189990. if (bytesEmpty >= bytesPerBuffer)
  189991. {
  189992. LPBYTE lpbuf1 = 0;
  189993. LPBYTE lpbuf2 = 0;
  189994. DWORD dwSize1 = 0;
  189995. DWORD dwSize2 = 0;
  189996. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  189997. bytesPerBuffer,
  189998. (void**) &lpbuf1, &dwSize1,
  189999. (void**) &lpbuf2, &dwSize2, 0);
  190000. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190001. {
  190002. pOutputBuffer->Restore();
  190003. hr = pOutputBuffer->Lock (writeOffset,
  190004. bytesPerBuffer,
  190005. (void**) &lpbuf1, &dwSize1,
  190006. (void**) &lpbuf2, &dwSize2, 0);
  190007. }
  190008. if (hr == S_OK)
  190009. {
  190010. if (bitDepth == 16)
  190011. {
  190012. const float gainL = 32767.0f;
  190013. const float gainR = 32767.0f;
  190014. int* dest = (int*)lpbuf1;
  190015. const float* left = leftBuffer;
  190016. const float* right = rightBuffer;
  190017. int samples1 = dwSize1 >> 2;
  190018. int samples2 = dwSize2 >> 2;
  190019. if (left == 0)
  190020. {
  190021. while (--samples1 >= 0)
  190022. {
  190023. int r = roundToInt (gainR * *right++);
  190024. if (r < -32768)
  190025. r = -32768;
  190026. else if (r > 32767)
  190027. r = 32767;
  190028. *dest++ = (r << 16);
  190029. }
  190030. dest = (int*)lpbuf2;
  190031. while (--samples2 >= 0)
  190032. {
  190033. int r = roundToInt (gainR * *right++);
  190034. if (r < -32768)
  190035. r = -32768;
  190036. else if (r > 32767)
  190037. r = 32767;
  190038. *dest++ = (r << 16);
  190039. }
  190040. }
  190041. else if (right == 0)
  190042. {
  190043. while (--samples1 >= 0)
  190044. {
  190045. int l = roundToInt (gainL * *left++);
  190046. if (l < -32768)
  190047. l = -32768;
  190048. else if (l > 32767)
  190049. l = 32767;
  190050. l &= 0xffff;
  190051. *dest++ = l;
  190052. }
  190053. dest = (int*)lpbuf2;
  190054. while (--samples2 >= 0)
  190055. {
  190056. int l = roundToInt (gainL * *left++);
  190057. if (l < -32768)
  190058. l = -32768;
  190059. else if (l > 32767)
  190060. l = 32767;
  190061. l &= 0xffff;
  190062. *dest++ = l;
  190063. }
  190064. }
  190065. else
  190066. {
  190067. while (--samples1 >= 0)
  190068. {
  190069. int l = roundToInt (gainL * *left++);
  190070. if (l < -32768)
  190071. l = -32768;
  190072. else if (l > 32767)
  190073. l = 32767;
  190074. l &= 0xffff;
  190075. int r = roundToInt (gainR * *right++);
  190076. if (r < -32768)
  190077. r = -32768;
  190078. else if (r > 32767)
  190079. r = 32767;
  190080. *dest++ = (r << 16) | l;
  190081. }
  190082. dest = (int*)lpbuf2;
  190083. while (--samples2 >= 0)
  190084. {
  190085. int l = roundToInt (gainL * *left++);
  190086. if (l < -32768)
  190087. l = -32768;
  190088. else if (l > 32767)
  190089. l = 32767;
  190090. l &= 0xffff;
  190091. int r = roundToInt (gainR * *right++);
  190092. if (r < -32768)
  190093. r = -32768;
  190094. else if (r > 32767)
  190095. r = 32767;
  190096. *dest++ = (r << 16) | l;
  190097. }
  190098. }
  190099. }
  190100. else
  190101. {
  190102. jassertfalse
  190103. }
  190104. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190105. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190106. }
  190107. else
  190108. {
  190109. jassertfalse
  190110. logError (hr);
  190111. }
  190112. bytesEmpty -= bytesPerBuffer;
  190113. return true;
  190114. }
  190115. else
  190116. {
  190117. return false;
  190118. }
  190119. }
  190120. };
  190121. struct DSoundInternalInChannel
  190122. {
  190123. String name;
  190124. LPGUID guid;
  190125. int sampleRate, bufferSizeSamples;
  190126. float* leftBuffer;
  190127. float* rightBuffer;
  190128. IDirectSound* pDirectSound;
  190129. IDirectSoundCapture* pDirectSoundCapture;
  190130. IDirectSoundCaptureBuffer* pInputBuffer;
  190131. public:
  190132. unsigned int readOffset;
  190133. int bytesPerBuffer, totalBytesPerBuffer;
  190134. int bitDepth;
  190135. bool doneFlag;
  190136. DSoundInternalInChannel (const String& name_,
  190137. LPGUID guid_,
  190138. int rate,
  190139. int bufferSize,
  190140. float* left,
  190141. float* right)
  190142. : name (name_),
  190143. guid (guid_),
  190144. sampleRate (rate),
  190145. bufferSizeSamples (bufferSize),
  190146. leftBuffer (left),
  190147. rightBuffer (right),
  190148. pDirectSound (0),
  190149. pDirectSoundCapture (0),
  190150. pInputBuffer (0),
  190151. bitDepth (16)
  190152. {
  190153. }
  190154. ~DSoundInternalInChannel()
  190155. {
  190156. close();
  190157. }
  190158. void close()
  190159. {
  190160. HRESULT hr;
  190161. if (pInputBuffer != 0)
  190162. {
  190163. JUCE_TRY
  190164. {
  190165. log ("closing dsound in: " + name);
  190166. hr = pInputBuffer->Stop();
  190167. logError (hr);
  190168. }
  190169. CATCH
  190170. JUCE_TRY
  190171. {
  190172. hr = pInputBuffer->Release();
  190173. logError (hr);
  190174. }
  190175. CATCH
  190176. pInputBuffer = 0;
  190177. }
  190178. if (pDirectSoundCapture != 0)
  190179. {
  190180. JUCE_TRY
  190181. {
  190182. hr = pDirectSoundCapture->Release();
  190183. logError (hr);
  190184. }
  190185. CATCH
  190186. pDirectSoundCapture = 0;
  190187. }
  190188. if (pDirectSound != 0)
  190189. {
  190190. JUCE_TRY
  190191. {
  190192. hr = pDirectSound->Release();
  190193. logError (hr);
  190194. }
  190195. CATCH
  190196. pDirectSound = 0;
  190197. }
  190198. }
  190199. const String open()
  190200. {
  190201. log ("opening dsound in device: " + name
  190202. + " rate=" + String (sampleRate) + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  190203. pDirectSound = 0;
  190204. pDirectSoundCapture = 0;
  190205. pInputBuffer = 0;
  190206. readOffset = 0;
  190207. totalBytesPerBuffer = 0;
  190208. String error;
  190209. HRESULT hr = E_NOINTERFACE;
  190210. if (dsDirectSoundCaptureCreate != 0)
  190211. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190212. logError (hr);
  190213. if (hr == S_OK)
  190214. {
  190215. const int numChannels = 2;
  190216. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190217. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190218. WAVEFORMATEX wfFormat;
  190219. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190220. wfFormat.nChannels = (unsigned short)numChannels;
  190221. wfFormat.nSamplesPerSec = sampleRate;
  190222. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190223. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190224. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190225. wfFormat.cbSize = 0;
  190226. DSCBUFFERDESC captureDesc;
  190227. zerostruct (captureDesc);
  190228. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190229. captureDesc.dwFlags = 0;
  190230. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190231. captureDesc.lpwfxFormat = &wfFormat;
  190232. log ("opening dsound in step 2");
  190233. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190234. logError (hr);
  190235. if (hr == S_OK)
  190236. {
  190237. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190238. logError (hr);
  190239. if (hr == S_OK)
  190240. return String::empty;
  190241. }
  190242. }
  190243. error = getDSErrorMessage (hr);
  190244. close();
  190245. return error;
  190246. }
  190247. void synchronisePosition()
  190248. {
  190249. if (pInputBuffer != 0)
  190250. {
  190251. DWORD capturePos;
  190252. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190253. }
  190254. }
  190255. bool service()
  190256. {
  190257. if (pInputBuffer == 0)
  190258. return true;
  190259. DWORD capturePos, readPos;
  190260. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190261. logError (hr);
  190262. if (hr != S_OK)
  190263. return true;
  190264. int bytesFilled = readPos - readOffset;
  190265. if (bytesFilled < 0)
  190266. bytesFilled += totalBytesPerBuffer;
  190267. if (bytesFilled >= bytesPerBuffer)
  190268. {
  190269. LPBYTE lpbuf1 = 0;
  190270. LPBYTE lpbuf2 = 0;
  190271. DWORD dwsize1 = 0;
  190272. DWORD dwsize2 = 0;
  190273. HRESULT hr = pInputBuffer->Lock (readOffset,
  190274. bytesPerBuffer,
  190275. (void**) &lpbuf1, &dwsize1,
  190276. (void**) &lpbuf2, &dwsize2, 0);
  190277. if (hr == S_OK)
  190278. {
  190279. if (bitDepth == 16)
  190280. {
  190281. const float g = 1.0f / 32768.0f;
  190282. float* destL = leftBuffer;
  190283. float* destR = rightBuffer;
  190284. int samples1 = dwsize1 >> 2;
  190285. int samples2 = dwsize2 >> 2;
  190286. const short* src = (const short*)lpbuf1;
  190287. if (destL == 0)
  190288. {
  190289. while (--samples1 >= 0)
  190290. {
  190291. ++src;
  190292. *destR++ = *src++ * g;
  190293. }
  190294. src = (const short*)lpbuf2;
  190295. while (--samples2 >= 0)
  190296. {
  190297. ++src;
  190298. *destR++ = *src++ * g;
  190299. }
  190300. }
  190301. else if (destR == 0)
  190302. {
  190303. while (--samples1 >= 0)
  190304. {
  190305. *destL++ = *src++ * g;
  190306. ++src;
  190307. }
  190308. src = (const short*)lpbuf2;
  190309. while (--samples2 >= 0)
  190310. {
  190311. *destL++ = *src++ * g;
  190312. ++src;
  190313. }
  190314. }
  190315. else
  190316. {
  190317. while (--samples1 >= 0)
  190318. {
  190319. *destL++ = *src++ * g;
  190320. *destR++ = *src++ * g;
  190321. }
  190322. src = (const short*)lpbuf2;
  190323. while (--samples2 >= 0)
  190324. {
  190325. *destL++ = *src++ * g;
  190326. *destR++ = *src++ * g;
  190327. }
  190328. }
  190329. }
  190330. else
  190331. {
  190332. jassertfalse
  190333. }
  190334. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190335. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190336. }
  190337. else
  190338. {
  190339. logError (hr);
  190340. jassertfalse
  190341. }
  190342. bytesFilled -= bytesPerBuffer;
  190343. return true;
  190344. }
  190345. else
  190346. {
  190347. return false;
  190348. }
  190349. }
  190350. };
  190351. class DSoundAudioIODevice : public AudioIODevice,
  190352. public Thread
  190353. {
  190354. public:
  190355. DSoundAudioIODevice (const String& deviceName,
  190356. const int outputDeviceIndex_,
  190357. const int inputDeviceIndex_)
  190358. : AudioIODevice (deviceName, "DirectSound"),
  190359. Thread ("Juce DSound"),
  190360. isOpen_ (false),
  190361. isStarted (false),
  190362. outputDeviceIndex (outputDeviceIndex_),
  190363. inputDeviceIndex (inputDeviceIndex_),
  190364. numInputBuffers (0),
  190365. numOutputBuffers (0),
  190366. totalSamplesOut (0),
  190367. sampleRate (0.0),
  190368. inputBuffers (0),
  190369. outputBuffers (0),
  190370. callback (0),
  190371. bufferSizeSamples (0)
  190372. {
  190373. if (outputDeviceIndex_ >= 0)
  190374. {
  190375. outChannels.add (TRANS("Left"));
  190376. outChannels.add (TRANS("Right"));
  190377. }
  190378. if (inputDeviceIndex_ >= 0)
  190379. {
  190380. inChannels.add (TRANS("Left"));
  190381. inChannels.add (TRANS("Right"));
  190382. }
  190383. }
  190384. ~DSoundAudioIODevice()
  190385. {
  190386. close();
  190387. }
  190388. const StringArray getOutputChannelNames()
  190389. {
  190390. return outChannels;
  190391. }
  190392. const StringArray getInputChannelNames()
  190393. {
  190394. return inChannels;
  190395. }
  190396. int getNumSampleRates()
  190397. {
  190398. return 4;
  190399. }
  190400. double getSampleRate (int index)
  190401. {
  190402. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190403. return samps [jlimit (0, 3, index)];
  190404. }
  190405. int getNumBufferSizesAvailable()
  190406. {
  190407. return 50;
  190408. }
  190409. int getBufferSizeSamples (int index)
  190410. {
  190411. int n = 64;
  190412. for (int i = 0; i < index; ++i)
  190413. n += (n < 512) ? 32
  190414. : ((n < 1024) ? 64
  190415. : ((n < 2048) ? 128 : 256));
  190416. return n;
  190417. }
  190418. int getDefaultBufferSize()
  190419. {
  190420. return 2560;
  190421. }
  190422. const String open (const BigInteger& inputChannels,
  190423. const BigInteger& outputChannels,
  190424. double sampleRate,
  190425. int bufferSizeSamples)
  190426. {
  190427. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190428. isOpen_ = lastError.isEmpty();
  190429. return lastError;
  190430. }
  190431. void close()
  190432. {
  190433. stop();
  190434. if (isOpen_)
  190435. {
  190436. closeDevice();
  190437. isOpen_ = false;
  190438. }
  190439. }
  190440. bool isOpen()
  190441. {
  190442. return isOpen_ && isThreadRunning();
  190443. }
  190444. int getCurrentBufferSizeSamples()
  190445. {
  190446. return bufferSizeSamples;
  190447. }
  190448. double getCurrentSampleRate()
  190449. {
  190450. return sampleRate;
  190451. }
  190452. int getCurrentBitDepth()
  190453. {
  190454. int i, bits = 256;
  190455. for (i = inChans.size(); --i >= 0;)
  190456. bits = jmin (bits, inChans[i]->bitDepth);
  190457. for (i = outChans.size(); --i >= 0;)
  190458. bits = jmin (bits, outChans[i]->bitDepth);
  190459. if (bits > 32)
  190460. bits = 16;
  190461. return bits;
  190462. }
  190463. const BigInteger getActiveOutputChannels() const
  190464. {
  190465. return enabledOutputs;
  190466. }
  190467. const BigInteger getActiveInputChannels() const
  190468. {
  190469. return enabledInputs;
  190470. }
  190471. int getOutputLatencyInSamples()
  190472. {
  190473. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190474. }
  190475. int getInputLatencyInSamples()
  190476. {
  190477. return getOutputLatencyInSamples();
  190478. }
  190479. void start (AudioIODeviceCallback* call)
  190480. {
  190481. if (isOpen_ && call != 0 && ! isStarted)
  190482. {
  190483. if (! isThreadRunning())
  190484. {
  190485. // something gone wrong and the thread's stopped..
  190486. isOpen_ = false;
  190487. return;
  190488. }
  190489. call->audioDeviceAboutToStart (this);
  190490. const ScopedLock sl (startStopLock);
  190491. callback = call;
  190492. isStarted = true;
  190493. }
  190494. }
  190495. void stop()
  190496. {
  190497. if (isStarted)
  190498. {
  190499. AudioIODeviceCallback* const callbackLocal = callback;
  190500. {
  190501. const ScopedLock sl (startStopLock);
  190502. isStarted = false;
  190503. }
  190504. if (callbackLocal != 0)
  190505. callbackLocal->audioDeviceStopped();
  190506. }
  190507. }
  190508. bool isPlaying()
  190509. {
  190510. return isStarted && isOpen_ && isThreadRunning();
  190511. }
  190512. const String getLastError()
  190513. {
  190514. return lastError;
  190515. }
  190516. juce_UseDebuggingNewOperator
  190517. StringArray inChannels, outChannels;
  190518. int outputDeviceIndex, inputDeviceIndex;
  190519. private:
  190520. bool isOpen_;
  190521. bool isStarted;
  190522. String lastError;
  190523. OwnedArray <DSoundInternalInChannel> inChans;
  190524. OwnedArray <DSoundInternalOutChannel> outChans;
  190525. WaitableEvent startEvent;
  190526. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190527. int volatile totalSamplesOut;
  190528. int64 volatile lastBlockTime;
  190529. double sampleRate;
  190530. BigInteger enabledInputs, enabledOutputs;
  190531. HeapBlock <float*> inputBuffers, outputBuffers;
  190532. AudioIODeviceCallback* callback;
  190533. CriticalSection startStopLock;
  190534. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190535. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190536. const String openDevice (const BigInteger& inputChannels,
  190537. const BigInteger& outputChannels,
  190538. double sampleRate_,
  190539. int bufferSizeSamples_);
  190540. void closeDevice()
  190541. {
  190542. isStarted = false;
  190543. stopThread (5000);
  190544. inChans.clear();
  190545. outChans.clear();
  190546. int i;
  190547. for (i = 0; i < numInputBuffers; ++i)
  190548. juce_free (inputBuffers[i]);
  190549. inputBuffers.free();
  190550. numInputBuffers = 0;
  190551. for (i = 0; i < numOutputBuffers; ++i)
  190552. juce_free (outputBuffers[i]);
  190553. outputBuffers.free();
  190554. numOutputBuffers = 0;
  190555. }
  190556. void resync()
  190557. {
  190558. if (! threadShouldExit())
  190559. {
  190560. sleep (5);
  190561. int i;
  190562. for (i = 0; i < outChans.size(); ++i)
  190563. outChans.getUnchecked(i)->synchronisePosition();
  190564. for (i = 0; i < inChans.size(); ++i)
  190565. inChans.getUnchecked(i)->synchronisePosition();
  190566. }
  190567. }
  190568. public:
  190569. void run()
  190570. {
  190571. while (! threadShouldExit())
  190572. {
  190573. if (wait (100))
  190574. break;
  190575. }
  190576. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190577. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190578. while (! threadShouldExit())
  190579. {
  190580. int numToDo = 0;
  190581. uint32 startTime = Time::getMillisecondCounter();
  190582. int i;
  190583. for (i = inChans.size(); --i >= 0;)
  190584. {
  190585. inChans.getUnchecked(i)->doneFlag = false;
  190586. ++numToDo;
  190587. }
  190588. for (i = outChans.size(); --i >= 0;)
  190589. {
  190590. outChans.getUnchecked(i)->doneFlag = false;
  190591. ++numToDo;
  190592. }
  190593. if (numToDo > 0)
  190594. {
  190595. const int maxCount = 3;
  190596. int count = maxCount;
  190597. for (;;)
  190598. {
  190599. for (i = inChans.size(); --i >= 0;)
  190600. {
  190601. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190602. if ((! in->doneFlag) && in->service())
  190603. {
  190604. in->doneFlag = true;
  190605. --numToDo;
  190606. }
  190607. }
  190608. for (i = outChans.size(); --i >= 0;)
  190609. {
  190610. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190611. if ((! out->doneFlag) && out->service())
  190612. {
  190613. out->doneFlag = true;
  190614. --numToDo;
  190615. }
  190616. }
  190617. if (numToDo <= 0)
  190618. break;
  190619. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190620. {
  190621. resync();
  190622. break;
  190623. }
  190624. if (--count <= 0)
  190625. {
  190626. Sleep (1);
  190627. count = maxCount;
  190628. }
  190629. if (threadShouldExit())
  190630. return;
  190631. }
  190632. }
  190633. else
  190634. {
  190635. sleep (1);
  190636. }
  190637. const ScopedLock sl (startStopLock);
  190638. if (isStarted)
  190639. {
  190640. JUCE_TRY
  190641. {
  190642. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190643. numInputBuffers,
  190644. outputBuffers,
  190645. numOutputBuffers,
  190646. bufferSizeSamples);
  190647. }
  190648. JUCE_CATCH_EXCEPTION
  190649. totalSamplesOut += bufferSizeSamples;
  190650. }
  190651. else
  190652. {
  190653. for (i = 0; i < numOutputBuffers; ++i)
  190654. if (outputBuffers[i] != 0)
  190655. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190656. totalSamplesOut = 0;
  190657. sleep (1);
  190658. }
  190659. }
  190660. }
  190661. };
  190662. class DSoundAudioIODeviceType : public AudioIODeviceType
  190663. {
  190664. public:
  190665. DSoundAudioIODeviceType()
  190666. : AudioIODeviceType ("DirectSound"),
  190667. hasScanned (false)
  190668. {
  190669. initialiseDSoundFunctions();
  190670. }
  190671. ~DSoundAudioIODeviceType()
  190672. {
  190673. }
  190674. void scanForDevices()
  190675. {
  190676. hasScanned = true;
  190677. outputDeviceNames.clear();
  190678. outputGuids.clear();
  190679. inputDeviceNames.clear();
  190680. inputGuids.clear();
  190681. if (dsDirectSoundEnumerateW != 0)
  190682. {
  190683. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190684. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190685. }
  190686. }
  190687. const StringArray getDeviceNames (bool wantInputNames) const
  190688. {
  190689. jassert (hasScanned); // need to call scanForDevices() before doing this
  190690. return wantInputNames ? inputDeviceNames
  190691. : outputDeviceNames;
  190692. }
  190693. int getDefaultDeviceIndex (bool /*forInput*/) const
  190694. {
  190695. jassert (hasScanned); // need to call scanForDevices() before doing this
  190696. return 0;
  190697. }
  190698. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  190699. {
  190700. jassert (hasScanned); // need to call scanForDevices() before doing this
  190701. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190702. if (d == 0)
  190703. return -1;
  190704. return asInput ? d->inputDeviceIndex
  190705. : d->outputDeviceIndex;
  190706. }
  190707. bool hasSeparateInputsAndOutputs() const { return true; }
  190708. AudioIODevice* createDevice (const String& outputDeviceName,
  190709. const String& inputDeviceName)
  190710. {
  190711. jassert (hasScanned); // need to call scanForDevices() before doing this
  190712. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190713. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190714. if (outputIndex >= 0 || inputIndex >= 0)
  190715. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190716. : inputDeviceName,
  190717. outputIndex, inputIndex);
  190718. return 0;
  190719. }
  190720. juce_UseDebuggingNewOperator
  190721. StringArray outputDeviceNames;
  190722. OwnedArray <GUID> outputGuids;
  190723. StringArray inputDeviceNames;
  190724. OwnedArray <GUID> inputGuids;
  190725. private:
  190726. bool hasScanned;
  190727. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190728. {
  190729. desc = desc.trim();
  190730. if (desc.isNotEmpty())
  190731. {
  190732. const String origDesc (desc);
  190733. int n = 2;
  190734. while (outputDeviceNames.contains (desc))
  190735. desc = origDesc + " (" + String (n++) + ")";
  190736. outputDeviceNames.add (desc);
  190737. if (lpGUID != 0)
  190738. outputGuids.add (new GUID (*lpGUID));
  190739. else
  190740. outputGuids.add (0);
  190741. }
  190742. return TRUE;
  190743. }
  190744. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190745. {
  190746. return ((DSoundAudioIODeviceType*) object)
  190747. ->outputEnumProc (lpGUID, String (description));
  190748. }
  190749. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190750. {
  190751. return ((DSoundAudioIODeviceType*) object)
  190752. ->outputEnumProc (lpGUID, String (description));
  190753. }
  190754. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190755. {
  190756. desc = desc.trim();
  190757. if (desc.isNotEmpty())
  190758. {
  190759. const String origDesc (desc);
  190760. int n = 2;
  190761. while (inputDeviceNames.contains (desc))
  190762. desc = origDesc + " (" + String (n++) + ")";
  190763. inputDeviceNames.add (desc);
  190764. if (lpGUID != 0)
  190765. inputGuids.add (new GUID (*lpGUID));
  190766. else
  190767. inputGuids.add (0);
  190768. }
  190769. return TRUE;
  190770. }
  190771. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190772. {
  190773. return ((DSoundAudioIODeviceType*) object)
  190774. ->inputEnumProc (lpGUID, String (description));
  190775. }
  190776. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190777. {
  190778. return ((DSoundAudioIODeviceType*) object)
  190779. ->inputEnumProc (lpGUID, String (description));
  190780. }
  190781. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190782. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190783. };
  190784. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190785. const BigInteger& outputChannels,
  190786. double sampleRate_,
  190787. int bufferSizeSamples_)
  190788. {
  190789. closeDevice();
  190790. totalSamplesOut = 0;
  190791. sampleRate = sampleRate_;
  190792. if (bufferSizeSamples_ <= 0)
  190793. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190794. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190795. DSoundAudioIODeviceType dlh;
  190796. dlh.scanForDevices();
  190797. enabledInputs = inputChannels;
  190798. enabledInputs.setRange (inChannels.size(),
  190799. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190800. false);
  190801. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190802. inputBuffers.calloc (numInputBuffers + 2);
  190803. int i, numIns = 0;
  190804. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190805. {
  190806. float* left = 0;
  190807. float* right = 0;
  190808. if (enabledInputs[i])
  190809. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190810. if (enabledInputs[i + 1])
  190811. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190812. if (left != 0 || right != 0)
  190813. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190814. dlh.inputGuids [inputDeviceIndex],
  190815. (int) sampleRate, bufferSizeSamples,
  190816. left, right));
  190817. }
  190818. enabledOutputs = outputChannels;
  190819. enabledOutputs.setRange (outChannels.size(),
  190820. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190821. false);
  190822. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190823. outputBuffers.calloc (numOutputBuffers + 2);
  190824. int numOuts = 0;
  190825. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190826. {
  190827. float* left = 0;
  190828. float* right = 0;
  190829. if (enabledOutputs[i])
  190830. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190831. if (enabledOutputs[i + 1])
  190832. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190833. if (left != 0 || right != 0)
  190834. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190835. dlh.outputGuids [outputDeviceIndex],
  190836. (int) sampleRate, bufferSizeSamples,
  190837. left, right));
  190838. }
  190839. String error;
  190840. // boost our priority while opening the devices to try to get better sync between them
  190841. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190842. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190843. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190844. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190845. for (i = 0; i < outChans.size(); ++i)
  190846. {
  190847. error = outChans[i]->open();
  190848. if (error.isNotEmpty())
  190849. {
  190850. error = "Error opening " + dlh.outputDeviceNames[i] + ": \"" + error + "\"";
  190851. break;
  190852. }
  190853. }
  190854. if (error.isEmpty())
  190855. {
  190856. for (i = 0; i < inChans.size(); ++i)
  190857. {
  190858. error = inChans[i]->open();
  190859. if (error.isNotEmpty())
  190860. {
  190861. error = "Error opening " + dlh.inputDeviceNames[i] + ": \"" + error + "\"";
  190862. break;
  190863. }
  190864. }
  190865. }
  190866. if (error.isEmpty())
  190867. {
  190868. totalSamplesOut = 0;
  190869. for (i = 0; i < outChans.size(); ++i)
  190870. outChans.getUnchecked(i)->synchronisePosition();
  190871. for (i = 0; i < inChans.size(); ++i)
  190872. inChans.getUnchecked(i)->synchronisePosition();
  190873. startThread (9);
  190874. sleep (10);
  190875. notify();
  190876. }
  190877. else
  190878. {
  190879. log (error);
  190880. }
  190881. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  190882. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  190883. return error;
  190884. }
  190885. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  190886. {
  190887. return new DSoundAudioIODeviceType();
  190888. }
  190889. #undef log
  190890. #endif
  190891. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  190892. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  190893. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190894. // compiled on its own).
  190895. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  190896. #if 1
  190897. const String getAudioErrorDesc (HRESULT hr)
  190898. {
  190899. const char* e = 0;
  190900. switch (hr)
  190901. {
  190902. case E_POINTER: e = "E_POINTER"; break;
  190903. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  190904. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  190905. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  190906. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  190907. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  190908. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  190909. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  190910. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  190911. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  190912. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  190913. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  190914. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  190915. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  190916. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  190917. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  190918. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  190919. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  190920. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  190921. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  190922. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  190923. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  190924. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  190925. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  190926. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  190927. default: return String::toHexString ((int) hr);
  190928. }
  190929. return e;
  190930. }
  190931. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  190932. #define OK(a) wasapi_checkResult(a)
  190933. static bool wasapi_checkResult (HRESULT hr)
  190934. {
  190935. logFailure (hr);
  190936. return SUCCEEDED (hr);
  190937. }
  190938. #else
  190939. #define logFailure(hr) {}
  190940. #define OK(a) SUCCEEDED(a)
  190941. #endif
  190942. static const String wasapi_getDeviceID (IMMDevice* const device)
  190943. {
  190944. String s;
  190945. WCHAR* deviceId = 0;
  190946. if (OK (device->GetId (&deviceId)))
  190947. {
  190948. s = String (deviceId);
  190949. CoTaskMemFree (deviceId);
  190950. }
  190951. return s;
  190952. }
  190953. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  190954. {
  190955. EDataFlow flow = eRender;
  190956. ComSmartPtr <IMMEndpoint> endPoint;
  190957. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  190958. (void) OK (endPoint->GetDataFlow (&flow));
  190959. return flow;
  190960. }
  190961. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  190962. {
  190963. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  190964. }
  190965. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  190966. {
  190967. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  190968. : sizeof (WAVEFORMATEX));
  190969. }
  190970. class WASAPIDeviceBase
  190971. {
  190972. public:
  190973. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190974. : device (device_),
  190975. sampleRate (0),
  190976. numChannels (0),
  190977. actualNumChannels (0),
  190978. defaultSampleRate (0),
  190979. minBufferSize (0),
  190980. defaultBufferSize (0),
  190981. latencySamples (0),
  190982. useExclusiveMode (useExclusiveMode_)
  190983. {
  190984. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  190985. ComSmartPtr <IAudioClient> tempClient (createClient());
  190986. if (tempClient == 0)
  190987. return;
  190988. REFERENCE_TIME defaultPeriod, minPeriod;
  190989. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  190990. return;
  190991. WAVEFORMATEX* mixFormat = 0;
  190992. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  190993. return;
  190994. WAVEFORMATEXTENSIBLE format;
  190995. wasapi_copyWavFormat (format, mixFormat);
  190996. CoTaskMemFree (mixFormat);
  190997. actualNumChannels = numChannels = format.Format.nChannels;
  190998. defaultSampleRate = format.Format.nSamplesPerSec;
  190999. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191000. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191001. FloatElementComparator<double> comparator;
  191002. rates.addSorted (comparator, defaultSampleRate);
  191003. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191004. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191005. {
  191006. if (ratesToTest[i] == defaultSampleRate)
  191007. continue;
  191008. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191009. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191010. (WAVEFORMATEX*) &format, 0)))
  191011. if (! rates.contains (ratesToTest[i]))
  191012. rates.addSorted (comparator, ratesToTest[i]);
  191013. }
  191014. }
  191015. ~WASAPIDeviceBase()
  191016. {
  191017. device = 0;
  191018. CloseHandle (clientEvent);
  191019. }
  191020. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191021. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  191022. {
  191023. sampleRate = newSampleRate;
  191024. channels = newChannels;
  191025. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191026. numChannels = channels.getHighestBit() + 1;
  191027. if (numChannels == 0)
  191028. return true;
  191029. client = createClient();
  191030. if (client != 0
  191031. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191032. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191033. {
  191034. channelMaps.clear();
  191035. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191036. if (channels[i])
  191037. channelMaps.add (i);
  191038. REFERENCE_TIME latency;
  191039. if (OK (client->GetStreamLatency (&latency)))
  191040. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191041. (void) OK (client->GetBufferSize (&actualBufferSize));
  191042. return OK (client->SetEventHandle (clientEvent));
  191043. }
  191044. return false;
  191045. }
  191046. void closeClient()
  191047. {
  191048. if (client != 0)
  191049. client->Stop();
  191050. client = 0;
  191051. ResetEvent (clientEvent);
  191052. }
  191053. ComSmartPtr <IMMDevice> device;
  191054. ComSmartPtr <IAudioClient> client;
  191055. double sampleRate, defaultSampleRate;
  191056. int numChannels, actualNumChannels;
  191057. int minBufferSize, defaultBufferSize, latencySamples;
  191058. const bool useExclusiveMode;
  191059. Array <double> rates;
  191060. HANDLE clientEvent;
  191061. BigInteger channels;
  191062. AudioDataConverters::DataFormat dataFormat;
  191063. Array <int> channelMaps;
  191064. UINT32 actualBufferSize;
  191065. int bytesPerSample;
  191066. private:
  191067. const ComSmartPtr <IAudioClient> createClient()
  191068. {
  191069. ComSmartPtr <IAudioClient> client;
  191070. if (device != 0)
  191071. {
  191072. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191073. logFailure (hr);
  191074. }
  191075. return client;
  191076. }
  191077. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191078. {
  191079. WAVEFORMATEXTENSIBLE format;
  191080. zerostruct (format);
  191081. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191082. {
  191083. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191084. }
  191085. else
  191086. {
  191087. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191088. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191089. }
  191090. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191091. format.Format.nChannels = (WORD) numChannels;
  191092. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191093. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191094. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191095. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191096. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191097. switch (numChannels)
  191098. {
  191099. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191100. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191101. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191102. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191103. 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;
  191104. default: break;
  191105. }
  191106. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191107. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191108. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191109. logFailure (hr);
  191110. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191111. {
  191112. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191113. hr = S_OK;
  191114. }
  191115. CoTaskMemFree (nearestFormat);
  191116. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191117. if (useExclusiveMode)
  191118. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191119. GUID session;
  191120. if (hr == S_OK
  191121. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191122. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191123. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191124. {
  191125. actualNumChannels = format.Format.nChannels;
  191126. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191127. bytesPerSample = format.Format.wBitsPerSample / 8;
  191128. dataFormat = isFloat ? AudioDataConverters::float32LE
  191129. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191130. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191131. : AudioDataConverters::int16LE)));
  191132. return true;
  191133. }
  191134. return false;
  191135. }
  191136. };
  191137. class WASAPIInputDevice : public WASAPIDeviceBase
  191138. {
  191139. public:
  191140. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191141. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191142. reservoir (1, 1)
  191143. {
  191144. }
  191145. ~WASAPIInputDevice()
  191146. {
  191147. close();
  191148. }
  191149. bool open (const double newSampleRate, const BigInteger& newChannels)
  191150. {
  191151. reservoirSize = 0;
  191152. reservoirCapacity = 16384;
  191153. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191154. return openClient (newSampleRate, newChannels)
  191155. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191156. }
  191157. void close()
  191158. {
  191159. closeClient();
  191160. captureClient = 0;
  191161. reservoir.setSize (0);
  191162. }
  191163. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191164. {
  191165. if (numChannels <= 0)
  191166. return;
  191167. int offset = 0;
  191168. while (bufferSize > 0)
  191169. {
  191170. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191171. {
  191172. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191173. for (int i = 0; i < numDestBuffers; ++i)
  191174. {
  191175. float* const dest = destBuffers[i] + offset;
  191176. const int srcChan = channelMaps.getUnchecked(i);
  191177. switch (dataFormat)
  191178. {
  191179. case AudioDataConverters::float32LE:
  191180. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191181. break;
  191182. case AudioDataConverters::int32LE:
  191183. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191184. break;
  191185. case AudioDataConverters::int24LE:
  191186. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191187. break;
  191188. case AudioDataConverters::int16LE:
  191189. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191190. break;
  191191. default: jassertfalse; break;
  191192. }
  191193. }
  191194. bufferSize -= samplesToDo;
  191195. offset += samplesToDo;
  191196. reservoirSize -= samplesToDo;
  191197. }
  191198. else
  191199. {
  191200. UINT32 packetLength = 0;
  191201. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191202. break;
  191203. if (packetLength == 0)
  191204. {
  191205. if (thread.threadShouldExit())
  191206. break;
  191207. Thread::sleep (1);
  191208. continue;
  191209. }
  191210. uint8* inputData = 0;
  191211. UINT32 numSamplesAvailable;
  191212. DWORD flags;
  191213. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191214. {
  191215. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191216. for (int i = 0; i < numDestBuffers; ++i)
  191217. {
  191218. float* const dest = destBuffers[i] + offset;
  191219. const int srcChan = channelMaps.getUnchecked(i);
  191220. switch (dataFormat)
  191221. {
  191222. case AudioDataConverters::float32LE:
  191223. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191224. break;
  191225. case AudioDataConverters::int32LE:
  191226. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191227. break;
  191228. case AudioDataConverters::int24LE:
  191229. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191230. break;
  191231. case AudioDataConverters::int16LE:
  191232. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191233. break;
  191234. default: jassertfalse; break;
  191235. }
  191236. }
  191237. bufferSize -= samplesToDo;
  191238. offset += samplesToDo;
  191239. if (samplesToDo < (int) numSamplesAvailable)
  191240. {
  191241. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191242. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191243. bytesPerSample * actualNumChannels * reservoirSize);
  191244. }
  191245. captureClient->ReleaseBuffer (numSamplesAvailable);
  191246. }
  191247. }
  191248. }
  191249. }
  191250. ComSmartPtr <IAudioCaptureClient> captureClient;
  191251. MemoryBlock reservoir;
  191252. int reservoirSize, reservoirCapacity;
  191253. };
  191254. class WASAPIOutputDevice : public WASAPIDeviceBase
  191255. {
  191256. public:
  191257. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191258. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191259. {
  191260. }
  191261. ~WASAPIOutputDevice()
  191262. {
  191263. close();
  191264. }
  191265. bool open (const double newSampleRate, const BigInteger& newChannels)
  191266. {
  191267. return openClient (newSampleRate, newChannels)
  191268. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191269. }
  191270. void close()
  191271. {
  191272. closeClient();
  191273. renderClient = 0;
  191274. }
  191275. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191276. {
  191277. if (numChannels <= 0)
  191278. return;
  191279. int offset = 0;
  191280. while (bufferSize > 0)
  191281. {
  191282. UINT32 padding = 0;
  191283. if (! OK (client->GetCurrentPadding (&padding)))
  191284. return;
  191285. int samplesToDo = useExclusiveMode ? bufferSize
  191286. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191287. if (samplesToDo <= 0)
  191288. {
  191289. if (thread.threadShouldExit())
  191290. break;
  191291. Thread::sleep (0);
  191292. continue;
  191293. }
  191294. uint8* outputData = 0;
  191295. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191296. {
  191297. for (int i = 0; i < numSrcBuffers; ++i)
  191298. {
  191299. const float* const source = srcBuffers[i] + offset;
  191300. const int destChan = channelMaps.getUnchecked(i);
  191301. switch (dataFormat)
  191302. {
  191303. case AudioDataConverters::float32LE:
  191304. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191305. break;
  191306. case AudioDataConverters::int32LE:
  191307. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191308. break;
  191309. case AudioDataConverters::int24LE:
  191310. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191311. break;
  191312. case AudioDataConverters::int16LE:
  191313. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191314. break;
  191315. default: jassertfalse; break;
  191316. }
  191317. }
  191318. renderClient->ReleaseBuffer (samplesToDo, 0);
  191319. offset += samplesToDo;
  191320. bufferSize -= samplesToDo;
  191321. }
  191322. }
  191323. }
  191324. ComSmartPtr <IAudioRenderClient> renderClient;
  191325. };
  191326. class WASAPIAudioIODevice : public AudioIODevice,
  191327. public Thread
  191328. {
  191329. public:
  191330. WASAPIAudioIODevice (const String& deviceName,
  191331. const String& outputDeviceId_,
  191332. const String& inputDeviceId_,
  191333. const bool useExclusiveMode_)
  191334. : AudioIODevice (deviceName, "Windows Audio"),
  191335. Thread ("Juce WASAPI"),
  191336. isOpen_ (false),
  191337. isStarted (false),
  191338. outputDevice (0),
  191339. outputDeviceId (outputDeviceId_),
  191340. inputDevice (0),
  191341. inputDeviceId (inputDeviceId_),
  191342. useExclusiveMode (useExclusiveMode_),
  191343. currentBufferSizeSamples (0),
  191344. currentSampleRate (0),
  191345. callback (0)
  191346. {
  191347. }
  191348. ~WASAPIAudioIODevice()
  191349. {
  191350. close();
  191351. deleteAndZero (inputDevice);
  191352. deleteAndZero (outputDevice);
  191353. }
  191354. bool initialise()
  191355. {
  191356. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191357. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191358. latencyIn = latencyOut = 0;
  191359. Array <double> ratesIn, ratesOut;
  191360. if (createDevices())
  191361. {
  191362. jassert (inputDevice != 0 || outputDevice != 0);
  191363. if (inputDevice != 0 && outputDevice != 0)
  191364. {
  191365. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191366. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191367. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191368. sampleRates = inputDevice->rates;
  191369. sampleRates.removeValuesNotIn (outputDevice->rates);
  191370. }
  191371. else
  191372. {
  191373. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191374. defaultSampleRate = d->defaultSampleRate;
  191375. minBufferSize = d->minBufferSize;
  191376. defaultBufferSize = d->defaultBufferSize;
  191377. sampleRates = d->rates;
  191378. }
  191379. IntegerElementComparator<int> comparator;
  191380. bufferSizes.addSorted (comparator, defaultBufferSize);
  191381. if (minBufferSize != defaultBufferSize)
  191382. bufferSizes.addSorted (comparator, minBufferSize);
  191383. int n = 64;
  191384. for (int i = 0; i < 40; ++i)
  191385. {
  191386. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191387. bufferSizes.addSorted (comparator, n);
  191388. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191389. }
  191390. return true;
  191391. }
  191392. return false;
  191393. }
  191394. const StringArray getOutputChannelNames()
  191395. {
  191396. StringArray outChannels;
  191397. if (outputDevice != 0)
  191398. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191399. outChannels.add ("Output channel " + String (i));
  191400. return outChannels;
  191401. }
  191402. const StringArray getInputChannelNames()
  191403. {
  191404. StringArray inChannels;
  191405. if (inputDevice != 0)
  191406. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191407. inChannels.add ("Input channel " + String (i));
  191408. return inChannels;
  191409. }
  191410. int getNumSampleRates() { return sampleRates.size(); }
  191411. double getSampleRate (int index) { return sampleRates [index]; }
  191412. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191413. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191414. int getDefaultBufferSize() { return defaultBufferSize; }
  191415. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191416. double getCurrentSampleRate() { return currentSampleRate; }
  191417. int getCurrentBitDepth() { return 32; }
  191418. int getOutputLatencyInSamples() { return latencyOut; }
  191419. int getInputLatencyInSamples() { return latencyIn; }
  191420. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191421. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191422. const String getLastError() { return lastError; }
  191423. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191424. double sampleRate, int bufferSizeSamples)
  191425. {
  191426. close();
  191427. lastError = String::empty;
  191428. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191429. {
  191430. lastError = "The input and output devices don't share a common sample rate!";
  191431. return lastError;
  191432. }
  191433. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191434. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191435. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191436. {
  191437. lastError = "Couldn't open the input device!";
  191438. return lastError;
  191439. }
  191440. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191441. {
  191442. close();
  191443. lastError = "Couldn't open the output device!";
  191444. return lastError;
  191445. }
  191446. if (inputDevice != 0)
  191447. ResetEvent (inputDevice->clientEvent);
  191448. if (outputDevice != 0)
  191449. ResetEvent (outputDevice->clientEvent);
  191450. startThread (8);
  191451. Thread::sleep (5);
  191452. if (inputDevice != 0 && inputDevice->client != 0)
  191453. {
  191454. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191455. HRESULT hr = inputDevice->client->Start();
  191456. logFailure (hr); //xxx handle this
  191457. }
  191458. if (outputDevice != 0 && outputDevice->client != 0)
  191459. {
  191460. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191461. HRESULT hr = outputDevice->client->Start();
  191462. logFailure (hr); //xxx handle this
  191463. }
  191464. isOpen_ = true;
  191465. return lastError;
  191466. }
  191467. void close()
  191468. {
  191469. stop();
  191470. if (inputDevice != 0)
  191471. SetEvent (inputDevice->clientEvent);
  191472. if (outputDevice != 0)
  191473. SetEvent (outputDevice->clientEvent);
  191474. stopThread (5000);
  191475. if (inputDevice != 0)
  191476. inputDevice->close();
  191477. if (outputDevice != 0)
  191478. outputDevice->close();
  191479. isOpen_ = false;
  191480. }
  191481. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191482. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191483. void start (AudioIODeviceCallback* call)
  191484. {
  191485. if (isOpen_ && call != 0 && ! isStarted)
  191486. {
  191487. if (! isThreadRunning())
  191488. {
  191489. // something's gone wrong and the thread's stopped..
  191490. isOpen_ = false;
  191491. return;
  191492. }
  191493. call->audioDeviceAboutToStart (this);
  191494. const ScopedLock sl (startStopLock);
  191495. callback = call;
  191496. isStarted = true;
  191497. }
  191498. }
  191499. void stop()
  191500. {
  191501. if (isStarted)
  191502. {
  191503. AudioIODeviceCallback* const callbackLocal = callback;
  191504. {
  191505. const ScopedLock sl (startStopLock);
  191506. isStarted = false;
  191507. }
  191508. if (callbackLocal != 0)
  191509. callbackLocal->audioDeviceStopped();
  191510. }
  191511. }
  191512. void setMMThreadPriority()
  191513. {
  191514. DynamicLibraryLoader dll ("avrt.dll");
  191515. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191516. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191517. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191518. {
  191519. DWORD dummy = 0;
  191520. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191521. if (h != 0)
  191522. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191523. }
  191524. }
  191525. void run()
  191526. {
  191527. setMMThreadPriority();
  191528. const int bufferSize = currentBufferSizeSamples;
  191529. HANDLE events[2];
  191530. int numEvents = 0;
  191531. if (inputDevice != 0)
  191532. events [numEvents++] = inputDevice->clientEvent;
  191533. if (outputDevice != 0)
  191534. events [numEvents++] = outputDevice->clientEvent;
  191535. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191536. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191537. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191538. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191539. float** const inputBuffers = ins.getArrayOfChannels();
  191540. float** const outputBuffers = outs.getArrayOfChannels();
  191541. ins.clear();
  191542. while (! threadShouldExit())
  191543. {
  191544. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191545. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191546. if (result == WAIT_TIMEOUT)
  191547. continue;
  191548. if (threadShouldExit())
  191549. break;
  191550. if (inputDevice != 0)
  191551. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191552. // Make the callback..
  191553. {
  191554. const ScopedLock sl (startStopLock);
  191555. if (isStarted)
  191556. {
  191557. JUCE_TRY
  191558. {
  191559. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191560. numInputBuffers,
  191561. outputBuffers,
  191562. numOutputBuffers,
  191563. bufferSize);
  191564. }
  191565. JUCE_CATCH_EXCEPTION
  191566. }
  191567. else
  191568. {
  191569. outs.clear();
  191570. }
  191571. }
  191572. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191573. continue;
  191574. if (outputDevice != 0)
  191575. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191576. }
  191577. }
  191578. juce_UseDebuggingNewOperator
  191579. String outputDeviceId, inputDeviceId;
  191580. String lastError;
  191581. private:
  191582. // Device stats...
  191583. WASAPIInputDevice* inputDevice;
  191584. WASAPIOutputDevice* outputDevice;
  191585. const bool useExclusiveMode;
  191586. double defaultSampleRate;
  191587. int minBufferSize, defaultBufferSize;
  191588. int latencyIn, latencyOut;
  191589. Array <double> sampleRates;
  191590. Array <int> bufferSizes;
  191591. // Active state...
  191592. bool isOpen_, isStarted;
  191593. int currentBufferSizeSamples;
  191594. double currentSampleRate;
  191595. AudioIODeviceCallback* callback;
  191596. CriticalSection startStopLock;
  191597. bool createDevices()
  191598. {
  191599. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191600. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191601. return false;
  191602. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191603. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191604. return false;
  191605. UINT32 numDevices = 0;
  191606. if (! OK (deviceCollection->GetCount (&numDevices)))
  191607. return false;
  191608. for (UINT32 i = 0; i < numDevices; ++i)
  191609. {
  191610. ComSmartPtr <IMMDevice> device;
  191611. if (! OK (deviceCollection->Item (i, &device)))
  191612. continue;
  191613. const String deviceId (wasapi_getDeviceID (device));
  191614. if (deviceId.isEmpty())
  191615. continue;
  191616. const EDataFlow flow = wasapi_getDataFlow (device);
  191617. if (deviceId == inputDeviceId && flow == eCapture)
  191618. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191619. else if (deviceId == outputDeviceId && flow == eRender)
  191620. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191621. }
  191622. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191623. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191624. }
  191625. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191626. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191627. };
  191628. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191629. {
  191630. public:
  191631. WASAPIAudioIODeviceType()
  191632. : AudioIODeviceType ("Windows Audio"),
  191633. hasScanned (false)
  191634. {
  191635. }
  191636. ~WASAPIAudioIODeviceType()
  191637. {
  191638. }
  191639. void scanForDevices()
  191640. {
  191641. hasScanned = true;
  191642. outputDeviceNames.clear();
  191643. inputDeviceNames.clear();
  191644. outputDeviceIds.clear();
  191645. inputDeviceIds.clear();
  191646. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191647. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191648. return;
  191649. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191650. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191651. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191652. UINT32 numDevices = 0;
  191653. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191654. && OK (deviceCollection->GetCount (&numDevices))))
  191655. return;
  191656. for (UINT32 i = 0; i < numDevices; ++i)
  191657. {
  191658. ComSmartPtr <IMMDevice> device;
  191659. if (! OK (deviceCollection->Item (i, &device)))
  191660. continue;
  191661. const String deviceId (wasapi_getDeviceID (device));
  191662. DWORD state = 0;
  191663. if (! OK (device->GetState (&state)))
  191664. continue;
  191665. if (state != DEVICE_STATE_ACTIVE)
  191666. continue;
  191667. String name;
  191668. {
  191669. ComSmartPtr <IPropertyStore> properties;
  191670. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191671. continue;
  191672. PROPVARIANT value;
  191673. PropVariantInit (&value);
  191674. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191675. name = value.pwszVal;
  191676. PropVariantClear (&value);
  191677. }
  191678. const EDataFlow flow = wasapi_getDataFlow (device);
  191679. if (flow == eRender)
  191680. {
  191681. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191682. outputDeviceIds.insert (index, deviceId);
  191683. outputDeviceNames.insert (index, name);
  191684. }
  191685. else if (flow == eCapture)
  191686. {
  191687. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191688. inputDeviceIds.insert (index, deviceId);
  191689. inputDeviceNames.insert (index, name);
  191690. }
  191691. }
  191692. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191693. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191694. }
  191695. const StringArray getDeviceNames (bool wantInputNames) const
  191696. {
  191697. jassert (hasScanned); // need to call scanForDevices() before doing this
  191698. return wantInputNames ? inputDeviceNames
  191699. : outputDeviceNames;
  191700. }
  191701. int getDefaultDeviceIndex (bool /*forInput*/) const
  191702. {
  191703. jassert (hasScanned); // need to call scanForDevices() before doing this
  191704. return 0;
  191705. }
  191706. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  191707. {
  191708. jassert (hasScanned); // need to call scanForDevices() before doing this
  191709. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191710. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191711. : outputDeviceIds.indexOf (d->outputDeviceId));
  191712. }
  191713. bool hasSeparateInputsAndOutputs() const { return true; }
  191714. AudioIODevice* createDevice (const String& outputDeviceName,
  191715. const String& inputDeviceName)
  191716. {
  191717. jassert (hasScanned); // need to call scanForDevices() before doing this
  191718. const bool useExclusiveMode = false;
  191719. ScopedPointer<WASAPIAudioIODevice> device;
  191720. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191721. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191722. if (outputIndex >= 0 || inputIndex >= 0)
  191723. {
  191724. device = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191725. : inputDeviceName,
  191726. outputDeviceIds [outputIndex],
  191727. inputDeviceIds [inputIndex],
  191728. useExclusiveMode);
  191729. if (! device->initialise())
  191730. device = 0;
  191731. }
  191732. return device.release();
  191733. }
  191734. juce_UseDebuggingNewOperator
  191735. StringArray outputDeviceNames, outputDeviceIds;
  191736. StringArray inputDeviceNames, inputDeviceIds;
  191737. private:
  191738. bool hasScanned;
  191739. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191740. {
  191741. String s;
  191742. IMMDevice* dev = 0;
  191743. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191744. eMultimedia, &dev)))
  191745. {
  191746. WCHAR* deviceId = 0;
  191747. if (OK (dev->GetId (&deviceId)))
  191748. {
  191749. s = String (deviceId);
  191750. CoTaskMemFree (deviceId);
  191751. }
  191752. dev->Release();
  191753. }
  191754. return s;
  191755. }
  191756. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191757. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191758. };
  191759. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191760. {
  191761. return new WASAPIAudioIODeviceType();
  191762. }
  191763. #undef logFailure
  191764. #undef OK
  191765. #endif
  191766. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191767. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191768. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191769. // compiled on its own).
  191770. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191771. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191772. {
  191773. public:
  191774. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191775. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191776. const ComSmartPtr <IBaseFilter>& filter_,
  191777. int minWidth, int minHeight,
  191778. int maxWidth, int maxHeight)
  191779. : owner (owner_),
  191780. captureGraphBuilder (captureGraphBuilder_),
  191781. filter (filter_),
  191782. ok (false),
  191783. imageNeedsFlipping (false),
  191784. width (0),
  191785. height (0),
  191786. activeUsers (0),
  191787. recordNextFrameTime (false),
  191788. activeImage (0),
  191789. loadingImage (0)
  191790. {
  191791. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191792. if (FAILED (hr))
  191793. return;
  191794. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191795. if (FAILED (hr))
  191796. return;
  191797. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191798. if (FAILED (hr))
  191799. return;
  191800. {
  191801. ComSmartPtr <IAMStreamConfig> streamConfig;
  191802. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191803. IID_IAMStreamConfig, (void**) &streamConfig);
  191804. if (streamConfig != 0)
  191805. {
  191806. getVideoSizes (streamConfig);
  191807. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191808. return;
  191809. }
  191810. }
  191811. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191812. if (FAILED (hr))
  191813. return;
  191814. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191815. if (FAILED (hr))
  191816. return;
  191817. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191818. if (FAILED (hr))
  191819. return;
  191820. if (! connectFilters (filter, smartTee))
  191821. return;
  191822. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191823. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191824. if (FAILED (hr))
  191825. return;
  191826. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191827. if (FAILED (hr))
  191828. return;
  191829. AM_MEDIA_TYPE mt;
  191830. zerostruct (mt);
  191831. mt.majortype = MEDIATYPE_Video;
  191832. mt.subtype = MEDIASUBTYPE_RGB24;
  191833. mt.formattype = FORMAT_VideoInfo;
  191834. sampleGrabber->SetMediaType (&mt);
  191835. callback = new GrabberCallback (*this);
  191836. sampleGrabber->SetCallback (callback, 1);
  191837. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191838. if (FAILED (hr))
  191839. return;
  191840. ComSmartPtr <IPin> grabberInputPin;
  191841. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191842. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191843. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191844. return;
  191845. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191846. if (FAILED (hr))
  191847. return;
  191848. zerostruct (mt);
  191849. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191850. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191851. width = pVih->bmiHeader.biWidth;
  191852. height = pVih->bmiHeader.biHeight;
  191853. ComSmartPtr <IBaseFilter> nullFilter;
  191854. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  191855. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191856. if (connectFilters (sampleGrabberBase, nullFilter)
  191857. && addGraphToRot())
  191858. {
  191859. activeImage = new Image (Image::RGB, width, height, true);
  191860. loadingImage = new Image (Image::RGB, width, height, true);
  191861. ok = true;
  191862. }
  191863. }
  191864. ~DShowCameraDeviceInteral()
  191865. {
  191866. if (mediaControl != 0)
  191867. mediaControl->Stop();
  191868. removeGraphFromRot();
  191869. for (int i = viewerComps.size(); --i >= 0;)
  191870. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191871. callback = 0;
  191872. graphBuilder = 0;
  191873. sampleGrabber = 0;
  191874. mediaControl = 0;
  191875. filter = 0;
  191876. captureGraphBuilder = 0;
  191877. smartTee = 0;
  191878. smartTeePreviewOutputPin = 0;
  191879. smartTeeCaptureOutputPin = 0;
  191880. asfWriter = 0;
  191881. delete activeImage;
  191882. delete loadingImage;
  191883. }
  191884. void addUser()
  191885. {
  191886. if (ok && activeUsers++ == 0)
  191887. mediaControl->Run();
  191888. }
  191889. void removeUser()
  191890. {
  191891. if (ok && --activeUsers == 0)
  191892. mediaControl->Stop();
  191893. }
  191894. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  191895. {
  191896. if (recordNextFrameTime)
  191897. {
  191898. const double defaultCameraLatency = 0.1;
  191899. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  191900. recordNextFrameTime = false;
  191901. ComSmartPtr <IPin> pin;
  191902. if (getPin (filter, PINDIR_OUTPUT, &pin))
  191903. {
  191904. ComSmartPtr <IAMPushSource> pushSource;
  191905. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  191906. if (pushSource != 0)
  191907. {
  191908. REFERENCE_TIME latency = 0;
  191909. hr = pushSource->GetLatency (&latency);
  191910. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  191911. }
  191912. }
  191913. }
  191914. {
  191915. const int lineStride = width * 3;
  191916. const ScopedLock sl (imageSwapLock);
  191917. {
  191918. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  191919. for (int i = 0; i < height; ++i)
  191920. memcpy (destData.getLinePointer ((height - 1) - i),
  191921. buffer + lineStride * i,
  191922. lineStride);
  191923. }
  191924. imageNeedsFlipping = true;
  191925. }
  191926. if (listeners.size() > 0)
  191927. callListeners (*loadingImage);
  191928. sendChangeMessage (this);
  191929. }
  191930. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  191931. {
  191932. if (imageNeedsFlipping)
  191933. {
  191934. const ScopedLock sl (imageSwapLock);
  191935. swapVariables (loadingImage, activeImage);
  191936. imageNeedsFlipping = false;
  191937. }
  191938. RectanglePlacement rp (RectanglePlacement::centred);
  191939. double dx = 0, dy = 0, dw = width, dh = height;
  191940. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  191941. const int rx = roundToInt (dx), ry = roundToInt (dy);
  191942. const int rw = roundToInt (dw), rh = roundToInt (dh);
  191943. g.saveState();
  191944. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  191945. g.fillAll (Colours::black);
  191946. g.restoreState();
  191947. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  191948. }
  191949. bool createFileCaptureFilter (const File& file)
  191950. {
  191951. removeFileCaptureFilter();
  191952. file.deleteFile();
  191953. mediaControl->Stop();
  191954. firstRecordedTime = Time();
  191955. recordNextFrameTime = true;
  191956. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  191957. if (SUCCEEDED (hr))
  191958. {
  191959. ComSmartPtr <IFileSinkFilter> fileSink;
  191960. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  191961. if (SUCCEEDED (hr))
  191962. {
  191963. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  191964. if (SUCCEEDED (hr))
  191965. {
  191966. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  191967. if (SUCCEEDED (hr))
  191968. {
  191969. ComSmartPtr <IConfigAsfWriter> asfConfig;
  191970. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  191971. asfConfig->SetIndexMode (true);
  191972. ComSmartPtr <IWMProfileManager> profileManager;
  191973. hr = WMCreateProfileManager (&profileManager);
  191974. // This gibberish is the DirectShow profile for a video-only wmv file.
  191975. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  191976. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  191977. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  191978. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  191979. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  191980. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  191981. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  191982. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  191983. prof = prof.replace ("$WIDTH", String (width))
  191984. .replace ("$HEIGHT", String (height));
  191985. ComSmartPtr <IWMProfile> currentProfile;
  191986. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  191987. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  191988. if (SUCCEEDED (hr))
  191989. {
  191990. ComSmartPtr <IPin> asfWriterInputPin;
  191991. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  191992. {
  191993. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  191994. if (SUCCEEDED (hr)
  191995. && ok && activeUsers > 0
  191996. && SUCCEEDED (mediaControl->Run()))
  191997. {
  191998. return true;
  191999. }
  192000. }
  192001. }
  192002. }
  192003. }
  192004. }
  192005. }
  192006. removeFileCaptureFilter();
  192007. if (ok && activeUsers > 0)
  192008. mediaControl->Run();
  192009. return false;
  192010. }
  192011. void removeFileCaptureFilter()
  192012. {
  192013. mediaControl->Stop();
  192014. if (asfWriter != 0)
  192015. {
  192016. graphBuilder->RemoveFilter (asfWriter);
  192017. asfWriter = 0;
  192018. }
  192019. if (ok && activeUsers > 0)
  192020. mediaControl->Run();
  192021. }
  192022. void addListener (CameraImageListener* listenerToAdd)
  192023. {
  192024. const ScopedLock sl (listenerLock);
  192025. if (listeners.size() == 0)
  192026. addUser();
  192027. listeners.addIfNotAlreadyThere (listenerToAdd);
  192028. }
  192029. void removeListener (CameraImageListener* listenerToRemove)
  192030. {
  192031. const ScopedLock sl (listenerLock);
  192032. listeners.removeValue (listenerToRemove);
  192033. if (listeners.size() == 0)
  192034. removeUser();
  192035. }
  192036. void callListeners (Image& image)
  192037. {
  192038. const ScopedLock sl (listenerLock);
  192039. for (int i = listeners.size(); --i >= 0;)
  192040. {
  192041. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192042. if (l != 0)
  192043. l->imageReceived (image);
  192044. }
  192045. }
  192046. class DShowCaptureViewerComp : public Component,
  192047. public ChangeListener
  192048. {
  192049. public:
  192050. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192051. : owner (owner_)
  192052. {
  192053. setOpaque (true);
  192054. owner->addChangeListener (this);
  192055. owner->addUser();
  192056. owner->viewerComps.add (this);
  192057. setSize (owner_->width, owner_->height);
  192058. }
  192059. ~DShowCaptureViewerComp()
  192060. {
  192061. if (owner != 0)
  192062. {
  192063. owner->viewerComps.removeValue (this);
  192064. owner->removeUser();
  192065. owner->removeChangeListener (this);
  192066. }
  192067. }
  192068. void ownerDeleted()
  192069. {
  192070. owner = 0;
  192071. }
  192072. void paint (Graphics& g)
  192073. {
  192074. g.setColour (Colours::black);
  192075. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192076. if (owner != 0)
  192077. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192078. else
  192079. g.fillAll (Colours::black);
  192080. }
  192081. void changeListenerCallback (void*)
  192082. {
  192083. repaint();
  192084. }
  192085. private:
  192086. DShowCameraDeviceInteral* owner;
  192087. };
  192088. bool ok;
  192089. int width, height;
  192090. Time firstRecordedTime;
  192091. VoidArray viewerComps;
  192092. private:
  192093. CameraDevice* const owner;
  192094. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192095. ComSmartPtr <IBaseFilter> filter;
  192096. ComSmartPtr <IBaseFilter> smartTee;
  192097. ComSmartPtr <IGraphBuilder> graphBuilder;
  192098. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192099. ComSmartPtr <IMediaControl> mediaControl;
  192100. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192101. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192102. ComSmartPtr <IBaseFilter> asfWriter;
  192103. int activeUsers;
  192104. Array <int> widths, heights;
  192105. DWORD graphRegistrationID;
  192106. CriticalSection imageSwapLock;
  192107. bool imageNeedsFlipping;
  192108. Image* loadingImage;
  192109. Image* activeImage;
  192110. bool recordNextFrameTime;
  192111. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192112. {
  192113. widths.clear();
  192114. heights.clear();
  192115. int count = 0, size = 0;
  192116. streamConfig->GetNumberOfCapabilities (&count, &size);
  192117. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192118. {
  192119. for (int i = 0; i < count; ++i)
  192120. {
  192121. VIDEO_STREAM_CONFIG_CAPS scc;
  192122. AM_MEDIA_TYPE* config;
  192123. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192124. if (SUCCEEDED (hr))
  192125. {
  192126. const int w = scc.InputSize.cx;
  192127. const int h = scc.InputSize.cy;
  192128. bool duplicate = false;
  192129. for (int j = widths.size(); --j >= 0;)
  192130. {
  192131. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192132. {
  192133. duplicate = true;
  192134. break;
  192135. }
  192136. }
  192137. if (! duplicate)
  192138. {
  192139. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192140. widths.add (w);
  192141. heights.add (h);
  192142. }
  192143. deleteMediaType (config);
  192144. }
  192145. }
  192146. }
  192147. }
  192148. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192149. const int minWidth, const int minHeight,
  192150. const int maxWidth, const int maxHeight)
  192151. {
  192152. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192153. streamConfig->GetNumberOfCapabilities (&count, &size);
  192154. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192155. {
  192156. AM_MEDIA_TYPE* config;
  192157. VIDEO_STREAM_CONFIG_CAPS scc;
  192158. for (int i = 0; i < count; ++i)
  192159. {
  192160. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192161. if (SUCCEEDED (hr))
  192162. {
  192163. if (scc.InputSize.cx >= minWidth
  192164. && scc.InputSize.cy >= minHeight
  192165. && scc.InputSize.cx <= maxWidth
  192166. && scc.InputSize.cy <= maxHeight)
  192167. {
  192168. int area = scc.InputSize.cx * scc.InputSize.cy;
  192169. if (area > bestArea)
  192170. {
  192171. bestIndex = i;
  192172. bestArea = area;
  192173. }
  192174. }
  192175. deleteMediaType (config);
  192176. }
  192177. }
  192178. if (bestIndex >= 0)
  192179. {
  192180. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192181. hr = streamConfig->SetFormat (config);
  192182. deleteMediaType (config);
  192183. return SUCCEEDED (hr);
  192184. }
  192185. }
  192186. return false;
  192187. }
  192188. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192189. {
  192190. ComSmartPtr <IEnumPins> enumerator;
  192191. ComSmartPtr <IPin> pin;
  192192. filter->EnumPins (&enumerator);
  192193. while (enumerator->Next (1, &pin, 0) == S_OK)
  192194. {
  192195. PIN_DIRECTION dir;
  192196. pin->QueryDirection (&dir);
  192197. if (wantedDirection == dir)
  192198. {
  192199. PIN_INFO info;
  192200. zerostruct (info);
  192201. pin->QueryPinInfo (&info);
  192202. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192203. {
  192204. pin.p->AddRef();
  192205. *result = pin;
  192206. return true;
  192207. }
  192208. }
  192209. }
  192210. return false;
  192211. }
  192212. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192213. {
  192214. ComSmartPtr <IPin> in, out;
  192215. return getPin (first, PINDIR_OUTPUT, &out)
  192216. && getPin (second, PINDIR_INPUT, &in)
  192217. && SUCCEEDED (graphBuilder->Connect (out, in));
  192218. }
  192219. bool addGraphToRot()
  192220. {
  192221. ComSmartPtr <IRunningObjectTable> rot;
  192222. if (FAILED (GetRunningObjectTable (0, &rot)))
  192223. return false;
  192224. ComSmartPtr <IMoniker> moniker;
  192225. WCHAR buffer[128];
  192226. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192227. if (FAILED (hr))
  192228. return false;
  192229. graphRegistrationID = 0;
  192230. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192231. }
  192232. void removeGraphFromRot()
  192233. {
  192234. ComSmartPtr <IRunningObjectTable> rot;
  192235. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192236. rot->Revoke (graphRegistrationID);
  192237. }
  192238. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192239. {
  192240. if (pmt->cbFormat != 0)
  192241. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192242. if (pmt->pUnk != 0)
  192243. pmt->pUnk->Release();
  192244. CoTaskMemFree (pmt);
  192245. }
  192246. class GrabberCallback : public ISampleGrabberCB
  192247. {
  192248. public:
  192249. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192250. : owner (owner_)
  192251. {
  192252. }
  192253. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192254. {
  192255. if (id == IID_IUnknown)
  192256. *result = dynamic_cast <IUnknown*> (this);
  192257. else if (id == IID_ISampleGrabberCB)
  192258. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192259. else
  192260. {
  192261. *result = 0;
  192262. return E_NOINTERFACE;
  192263. }
  192264. AddRef();
  192265. return S_OK;
  192266. }
  192267. ULONG __stdcall AddRef() { return ++refCount; }
  192268. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192269. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192270. {
  192271. return E_FAIL;
  192272. }
  192273. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192274. {
  192275. owner.handleFrame (time, buffer, bufferSize);
  192276. return S_OK;
  192277. }
  192278. private:
  192279. int refCount;
  192280. DShowCameraDeviceInteral& owner;
  192281. GrabberCallback (const GrabberCallback&);
  192282. GrabberCallback& operator= (const GrabberCallback&);
  192283. };
  192284. ComSmartPtr <GrabberCallback> callback;
  192285. VoidArray listeners;
  192286. CriticalSection listenerLock;
  192287. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192288. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192289. };
  192290. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192291. : name (name_)
  192292. {
  192293. isRecording = false;
  192294. }
  192295. CameraDevice::~CameraDevice()
  192296. {
  192297. stopRecording();
  192298. delete (DShowCameraDeviceInteral*) internal;
  192299. internal = 0;
  192300. }
  192301. Component* CameraDevice::createViewerComponent()
  192302. {
  192303. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192304. }
  192305. const String CameraDevice::getFileExtension()
  192306. {
  192307. return ".wmv";
  192308. }
  192309. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192310. {
  192311. stopRecording();
  192312. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192313. d->addUser();
  192314. isRecording = d->createFileCaptureFilter (file);
  192315. }
  192316. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192317. {
  192318. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192319. return d->firstRecordedTime;
  192320. }
  192321. void CameraDevice::stopRecording()
  192322. {
  192323. if (isRecording)
  192324. {
  192325. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192326. d->removeFileCaptureFilter();
  192327. d->removeUser();
  192328. isRecording = false;
  192329. }
  192330. }
  192331. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192332. {
  192333. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192334. if (listenerToAdd != 0)
  192335. d->addListener (listenerToAdd);
  192336. }
  192337. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192338. {
  192339. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192340. if (listenerToRemove != 0)
  192341. d->removeListener (listenerToRemove);
  192342. }
  192343. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192344. const int deviceIndexToOpen,
  192345. String& name)
  192346. {
  192347. int index = 0;
  192348. ComSmartPtr <IBaseFilter> result;
  192349. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192350. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192351. if (SUCCEEDED (hr))
  192352. {
  192353. ComSmartPtr <IEnumMoniker> enumerator;
  192354. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192355. if (SUCCEEDED (hr) && enumerator != 0)
  192356. {
  192357. ComSmartPtr <IBaseFilter> captureFilter;
  192358. ComSmartPtr <IMoniker> moniker;
  192359. ULONG fetched;
  192360. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192361. {
  192362. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192363. if (SUCCEEDED (hr))
  192364. {
  192365. ComSmartPtr <IPropertyBag> propertyBag;
  192366. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192367. if (SUCCEEDED (hr))
  192368. {
  192369. VARIANT var;
  192370. var.vt = VT_BSTR;
  192371. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192372. propertyBag = 0;
  192373. if (SUCCEEDED (hr))
  192374. {
  192375. if (names != 0)
  192376. names->add (var.bstrVal);
  192377. if (index == deviceIndexToOpen)
  192378. {
  192379. name = var.bstrVal;
  192380. result = captureFilter;
  192381. captureFilter = 0;
  192382. break;
  192383. }
  192384. ++index;
  192385. }
  192386. moniker = 0;
  192387. }
  192388. captureFilter = 0;
  192389. }
  192390. }
  192391. }
  192392. }
  192393. return result;
  192394. }
  192395. const StringArray CameraDevice::getAvailableDevices()
  192396. {
  192397. StringArray devs;
  192398. String dummy;
  192399. enumerateCameras (&devs, -1, dummy);
  192400. return devs;
  192401. }
  192402. CameraDevice* CameraDevice::openDevice (int index,
  192403. int minWidth, int minHeight,
  192404. int maxWidth, int maxHeight)
  192405. {
  192406. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192407. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192408. if (SUCCEEDED (hr))
  192409. {
  192410. String name;
  192411. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192412. if (filter != 0)
  192413. {
  192414. CameraDevice* const cam = new CameraDevice (name, index);
  192415. DShowCameraDeviceInteral* const intern
  192416. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192417. minWidth, minHeight, maxWidth, maxHeight);
  192418. cam->internal = intern;
  192419. if (intern->ok)
  192420. return cam;
  192421. else
  192422. delete cam;
  192423. }
  192424. }
  192425. return 0;
  192426. }
  192427. #endif
  192428. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192429. #endif
  192430. // Auto-link the other win32 libs that are needed by library calls..
  192431. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192432. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192433. // Auto-links to various win32 libs that are needed by library calls..
  192434. #pragma comment(lib, "kernel32.lib")
  192435. #pragma comment(lib, "user32.lib")
  192436. #pragma comment(lib, "shell32.lib")
  192437. #pragma comment(lib, "gdi32.lib")
  192438. #pragma comment(lib, "vfw32.lib")
  192439. #pragma comment(lib, "comdlg32.lib")
  192440. #pragma comment(lib, "winmm.lib")
  192441. #pragma comment(lib, "wininet.lib")
  192442. #pragma comment(lib, "ole32.lib")
  192443. #pragma comment(lib, "oleaut32.lib")
  192444. #pragma comment(lib, "advapi32.lib")
  192445. #pragma comment(lib, "ws2_32.lib")
  192446. #pragma comment(lib, "comsupp.lib")
  192447. #pragma comment(lib, "version.lib")
  192448. #if JUCE_OPENGL
  192449. #pragma comment(lib, "OpenGL32.Lib")
  192450. #pragma comment(lib, "GlU32.Lib")
  192451. #endif
  192452. #if JUCE_QUICKTIME
  192453. #pragma comment (lib, "QTMLClient.lib")
  192454. #endif
  192455. #if JUCE_USE_CAMERA
  192456. #pragma comment (lib, "Strmiids.lib")
  192457. #pragma comment (lib, "wmvcore.lib")
  192458. #endif
  192459. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192460. #endif
  192461. END_JUCE_NAMESPACE
  192462. #endif
  192463. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192464. #endif
  192465. #if JUCE_LINUX
  192466. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192467. #if JUCE_LINUX
  192468. BEGIN_JUCE_NAMESPACE
  192469. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192470. #define SUPPORT_AFFINITIES 1
  192471. #endif
  192472. #define JUCE_INCLUDED_FILE 1
  192473. // Now include the actual code files..
  192474. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192475. CriticalSection::CriticalSection() throw()
  192476. {
  192477. pthread_mutexattr_t atts;
  192478. pthread_mutexattr_init (&atts);
  192479. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192480. pthread_mutex_init (&internal, &atts);
  192481. }
  192482. CriticalSection::~CriticalSection() throw()
  192483. {
  192484. pthread_mutex_destroy (&internal);
  192485. }
  192486. void CriticalSection::enter() const throw()
  192487. {
  192488. pthread_mutex_lock (&internal);
  192489. }
  192490. bool CriticalSection::tryEnter() const throw()
  192491. {
  192492. return pthread_mutex_trylock (&internal) == 0;
  192493. }
  192494. void CriticalSection::exit() const throw()
  192495. {
  192496. pthread_mutex_unlock (&internal);
  192497. }
  192498. class WaitableEventImpl
  192499. {
  192500. public:
  192501. WaitableEventImpl (const bool manualReset_)
  192502. : triggered (false),
  192503. manualReset (manualReset_)
  192504. {
  192505. pthread_cond_init (&condition, 0);
  192506. pthread_mutex_init (&mutex, 0);
  192507. }
  192508. ~WaitableEventImpl()
  192509. {
  192510. pthread_cond_destroy (&condition);
  192511. pthread_mutex_destroy (&mutex);
  192512. }
  192513. bool wait (const int timeOutMillisecs) throw()
  192514. {
  192515. pthread_mutex_lock (&mutex);
  192516. if (! triggered)
  192517. {
  192518. if (timeOutMillisecs < 0)
  192519. {
  192520. do
  192521. {
  192522. pthread_cond_wait (&condition, &mutex);
  192523. }
  192524. while (! triggered);
  192525. }
  192526. else
  192527. {
  192528. struct timeval now;
  192529. gettimeofday (&now, 0);
  192530. struct timespec time;
  192531. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192532. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192533. if (time.tv_nsec >= 1000000000)
  192534. {
  192535. time.tv_nsec -= 1000000000;
  192536. time.tv_sec++;
  192537. }
  192538. do
  192539. {
  192540. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192541. {
  192542. pthread_mutex_unlock (&mutex);
  192543. return false;
  192544. }
  192545. }
  192546. while (! triggered);
  192547. }
  192548. }
  192549. if (! manualReset)
  192550. triggered = false;
  192551. pthread_mutex_unlock (&mutex);
  192552. return true;
  192553. }
  192554. void signal() throw()
  192555. {
  192556. pthread_mutex_lock (&mutex);
  192557. triggered = true;
  192558. pthread_cond_broadcast (&condition);
  192559. pthread_mutex_unlock (&mutex);
  192560. }
  192561. void reset() throw()
  192562. {
  192563. pthread_mutex_lock (&mutex);
  192564. triggered = false;
  192565. pthread_mutex_unlock (&mutex);
  192566. }
  192567. private:
  192568. pthread_cond_t condition;
  192569. pthread_mutex_t mutex;
  192570. bool triggered;
  192571. const bool manualReset;
  192572. WaitableEventImpl (const WaitableEventImpl&);
  192573. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192574. };
  192575. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  192576. : internal (new WaitableEventImpl (manualReset))
  192577. {
  192578. }
  192579. WaitableEvent::~WaitableEvent() throw()
  192580. {
  192581. delete static_cast <WaitableEventImpl*> (internal);
  192582. }
  192583. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192584. {
  192585. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192586. }
  192587. void WaitableEvent::signal() const throw()
  192588. {
  192589. static_cast <WaitableEventImpl*> (internal)->signal();
  192590. }
  192591. void WaitableEvent::reset() const throw()
  192592. {
  192593. static_cast <WaitableEventImpl*> (internal)->reset();
  192594. }
  192595. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192596. {
  192597. struct timespec time;
  192598. time.tv_sec = millisecs / 1000;
  192599. time.tv_nsec = (millisecs % 1000) * 1000000;
  192600. nanosleep (&time, 0);
  192601. }
  192602. const juce_wchar File::separator = '/';
  192603. const juce_wchar* File::separatorString = L"/";
  192604. const File File::getCurrentWorkingDirectory()
  192605. {
  192606. HeapBlock<char> heapBuffer;
  192607. char localBuffer [1024];
  192608. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192609. int bufferSize = 4096;
  192610. while (cwd == 0 && errno == ERANGE)
  192611. {
  192612. heapBuffer.malloc (bufferSize);
  192613. cwd = getcwd (heapBuffer, bufferSize - 1);
  192614. bufferSize += 1024;
  192615. }
  192616. return File (String::fromUTF8 (cwd));
  192617. }
  192618. bool File::setAsCurrentWorkingDirectory() const
  192619. {
  192620. return chdir (getFullPathName().toUTF8()) == 0;
  192621. }
  192622. bool juce_copyFile (const String& s, const String& d);
  192623. static bool juce_stat (const String& fileName, struct stat& info)
  192624. {
  192625. return fileName.isNotEmpty()
  192626. && (stat (fileName.toUTF8(), &info) == 0);
  192627. }
  192628. bool juce_isDirectory (const String& fileName)
  192629. {
  192630. struct stat info;
  192631. return fileName.isEmpty()
  192632. || (juce_stat (fileName, info)
  192633. && ((info.st_mode & S_IFDIR) != 0));
  192634. }
  192635. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192636. {
  192637. if (fileName.isEmpty())
  192638. return false;
  192639. const char* const fileNameUTF8 = fileName.toUTF8();
  192640. bool exists = access (fileNameUTF8, F_OK) == 0;
  192641. if (exists && dontCountDirectories)
  192642. {
  192643. struct stat info;
  192644. const int res = stat (fileNameUTF8, &info);
  192645. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192646. exists = false;
  192647. }
  192648. return exists;
  192649. }
  192650. int64 juce_getFileSize (const String& fileName)
  192651. {
  192652. struct stat info;
  192653. return juce_stat (fileName, info) ? info.st_size : 0;
  192654. }
  192655. bool juce_canWriteToFile (const String& fileName)
  192656. {
  192657. return access (fileName.toUTF8(), W_OK) == 0;
  192658. }
  192659. bool juce_deleteFile (const String& fileName)
  192660. {
  192661. if (juce_isDirectory (fileName))
  192662. return rmdir (fileName.toUTF8()) == 0;
  192663. else
  192664. return remove (fileName.toUTF8()) == 0;
  192665. }
  192666. bool juce_moveFile (const String& source, const String& dest)
  192667. {
  192668. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192669. return true;
  192670. if (juce_canWriteToFile (source)
  192671. && juce_copyFile (source, dest))
  192672. {
  192673. if (juce_deleteFile (source))
  192674. return true;
  192675. juce_deleteFile (dest);
  192676. }
  192677. return false;
  192678. }
  192679. void juce_createDirectory (const String& fileName)
  192680. {
  192681. mkdir (fileName.toUTF8(), 0777);
  192682. }
  192683. void* juce_fileOpen (const String& fileName, bool forWriting)
  192684. {
  192685. int flags = O_RDONLY;
  192686. if (forWriting)
  192687. {
  192688. if (juce_fileExists (fileName, false))
  192689. {
  192690. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  192691. if (f != -1)
  192692. lseek (f, 0, SEEK_END);
  192693. return (void*) f;
  192694. }
  192695. else
  192696. {
  192697. flags = O_RDWR + O_CREAT;
  192698. }
  192699. }
  192700. return (void*) open (fileName.toUTF8(), flags, 00644);
  192701. }
  192702. void juce_fileClose (void* handle)
  192703. {
  192704. if (handle != 0)
  192705. close ((int) (pointer_sized_int) handle);
  192706. }
  192707. int juce_fileRead (void* handle, void* buffer, int size)
  192708. {
  192709. if (handle != 0)
  192710. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  192711. return 0;
  192712. }
  192713. int juce_fileWrite (void* handle, const void* buffer, int size)
  192714. {
  192715. if (handle != 0)
  192716. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192717. return 0;
  192718. }
  192719. int64 juce_fileSetPosition (void* handle, int64 pos)
  192720. {
  192721. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192722. return pos;
  192723. return -1;
  192724. }
  192725. int64 juce_fileGetPosition (void* handle)
  192726. {
  192727. if (handle != 0)
  192728. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192729. return -1;
  192730. }
  192731. void juce_fileFlush (void* handle)
  192732. {
  192733. if (handle != 0)
  192734. fsync ((int) (pointer_sized_int) handle);
  192735. }
  192736. const File juce_getExecutableFile()
  192737. {
  192738. Dl_info exeInfo;
  192739. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192740. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  192741. }
  192742. // if this file doesn't exist, find a parent of it that does..
  192743. static bool doStatFS (const File* file, struct statfs& result)
  192744. {
  192745. File f (*file);
  192746. for (int i = 5; --i >= 0;)
  192747. {
  192748. if (f.exists())
  192749. break;
  192750. f = f.getParentDirectory();
  192751. }
  192752. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192753. }
  192754. int64 File::getBytesFreeOnVolume() const
  192755. {
  192756. struct statfs buf;
  192757. if (doStatFS (this, buf))
  192758. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192759. return 0;
  192760. }
  192761. int64 File::getVolumeTotalSize() const
  192762. {
  192763. struct statfs buf;
  192764. if (doStatFS (this, buf))
  192765. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192766. return 0;
  192767. }
  192768. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192769. int& volumeSerialNumber)
  192770. {
  192771. volumeSerialNumber = 0;
  192772. #if JUCE_MAC
  192773. struct VolAttrBuf
  192774. {
  192775. u_int32_t length;
  192776. attrreference_t mountPointRef;
  192777. char mountPointSpace [MAXPATHLEN];
  192778. } attrBuf;
  192779. struct attrlist attrList;
  192780. zerostruct (attrList);
  192781. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192782. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192783. File f (filenameOnVolume);
  192784. for (;;)
  192785. {
  192786. if (getattrlist (f.getFullPathName().toUTF8(),
  192787. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192788. {
  192789. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192790. (int) attrBuf.mountPointRef.attr_length);
  192791. }
  192792. const File parent (f.getParentDirectory());
  192793. if (f == parent)
  192794. break;
  192795. f = parent;
  192796. }
  192797. #endif
  192798. return String::empty;
  192799. }
  192800. void juce_runSystemCommand (const String& command)
  192801. {
  192802. int result = system (command.toUTF8());
  192803. (void) result;
  192804. }
  192805. const String juce_getOutputFromCommand (const String& command)
  192806. {
  192807. // slight bodge here, as we just pipe the output into a temp file and read it...
  192808. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192809. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192810. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192811. String result (tempFile.loadFileAsString());
  192812. tempFile.deleteFile();
  192813. return result;
  192814. }
  192815. class InterProcessLock::Pimpl
  192816. {
  192817. public:
  192818. Pimpl (const String& name, const int timeOutMillisecs)
  192819. : handle (0), refCount (1)
  192820. {
  192821. #if JUCE_MAC
  192822. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192823. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  192824. #else
  192825. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192826. #endif
  192827. temp.create();
  192828. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192829. if (handle != 0)
  192830. {
  192831. struct flock fl;
  192832. zerostruct (fl);
  192833. fl.l_whence = SEEK_SET;
  192834. fl.l_type = F_WRLCK;
  192835. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192836. for (;;)
  192837. {
  192838. const int result = fcntl (handle, F_SETLK, &fl);
  192839. if (result >= 0)
  192840. return;
  192841. if (errno != EINTR)
  192842. {
  192843. if (timeOutMillisecs == 0
  192844. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192845. break;
  192846. Thread::sleep (10);
  192847. }
  192848. }
  192849. }
  192850. closeFile();
  192851. }
  192852. ~Pimpl()
  192853. {
  192854. closeFile();
  192855. }
  192856. void closeFile()
  192857. {
  192858. if (handle != 0)
  192859. {
  192860. struct flock fl;
  192861. zerostruct (fl);
  192862. fl.l_whence = SEEK_SET;
  192863. fl.l_type = F_UNLCK;
  192864. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  192865. {}
  192866. close (handle);
  192867. handle = 0;
  192868. }
  192869. }
  192870. int handle, refCount;
  192871. };
  192872. InterProcessLock::InterProcessLock (const String& name_)
  192873. : name (name_)
  192874. {
  192875. }
  192876. InterProcessLock::~InterProcessLock()
  192877. {
  192878. }
  192879. bool InterProcessLock::enter (const int timeOutMillisecs)
  192880. {
  192881. const ScopedLock sl (lock);
  192882. if (pimpl == 0)
  192883. {
  192884. pimpl = new Pimpl (name, timeOutMillisecs);
  192885. if (pimpl->handle == 0)
  192886. pimpl = 0;
  192887. }
  192888. else
  192889. {
  192890. pimpl->refCount++;
  192891. }
  192892. return pimpl != 0;
  192893. }
  192894. void InterProcessLock::exit()
  192895. {
  192896. const ScopedLock sl (lock);
  192897. // Trying to release the lock too many times!
  192898. jassert (pimpl != 0);
  192899. if (pimpl != 0 && --(pimpl->refCount) == 0)
  192900. pimpl = 0;
  192901. }
  192902. /*** End of inlined file: juce_posix_SharedCode.h ***/
  192903. /*** Start of inlined file: juce_linux_Files.cpp ***/
  192904. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192905. // compiled on its own).
  192906. #if JUCE_INCLUDED_FILE
  192907. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  192908. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  192909. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  192910. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  192911. void juce_getFileTimes (const String& fileName,
  192912. int64& modificationTime,
  192913. int64& accessTime,
  192914. int64& creationTime)
  192915. {
  192916. modificationTime = 0;
  192917. accessTime = 0;
  192918. creationTime = 0;
  192919. struct stat info;
  192920. const int res = stat (fileName.toUTF8(), &info);
  192921. if (res == 0)
  192922. {
  192923. modificationTime = (int64) info.st_mtime * 1000;
  192924. accessTime = (int64) info.st_atime * 1000;
  192925. creationTime = (int64) info.st_ctime * 1000;
  192926. }
  192927. }
  192928. bool juce_setFileTimes (const String& fileName,
  192929. int64 modificationTime,
  192930. int64 accessTime,
  192931. int64 creationTime)
  192932. {
  192933. struct utimbuf times;
  192934. times.actime = (time_t) (accessTime / 1000);
  192935. times.modtime = (time_t) (modificationTime / 1000);
  192936. return utime (fileName.toUTF8(), &times) == 0;
  192937. }
  192938. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  192939. {
  192940. struct stat info;
  192941. const int res = stat (fileName.toUTF8(), &info);
  192942. if (res != 0)
  192943. return false;
  192944. info.st_mode &= 0777; // Just permissions
  192945. if( isReadOnly )
  192946. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  192947. else
  192948. // Give everybody write permission?
  192949. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  192950. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  192951. }
  192952. bool juce_copyFile (const String& s, const String& d)
  192953. {
  192954. const File source (s), dest (d);
  192955. FileInputStream* in = source.createInputStream();
  192956. bool ok = false;
  192957. if (in != 0)
  192958. {
  192959. if (dest.deleteFile())
  192960. {
  192961. FileOutputStream* const out = dest.createOutputStream();
  192962. if (out != 0)
  192963. {
  192964. const int bytesCopied = out->writeFromInputStream (*in, -1);
  192965. delete out;
  192966. ok = (bytesCopied == source.getSize());
  192967. if (! ok)
  192968. dest.deleteFile();
  192969. }
  192970. }
  192971. delete in;
  192972. }
  192973. return ok;
  192974. }
  192975. const StringArray juce_getFileSystemRoots()
  192976. {
  192977. StringArray s;
  192978. s.add ("/");
  192979. return s;
  192980. }
  192981. bool File::isOnCDRomDrive() const
  192982. {
  192983. struct statfs buf;
  192984. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192985. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  192986. // Assume not if this fails for some reason
  192987. return false;
  192988. }
  192989. bool File::isOnHardDisk() const
  192990. {
  192991. struct statfs buf;
  192992. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192993. {
  192994. switch (buf.f_type)
  192995. {
  192996. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  192997. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  192998. case U_NFS_SUPER_MAGIC: // Network NFS
  192999. case U_SMB_SUPER_MAGIC: // Network Samba
  193000. return false;
  193001. default:
  193002. // Assume anything else is a hard-disk (but note it could
  193003. // be a RAM disk. There isn't a good way of determining
  193004. // this for sure)
  193005. return true;
  193006. }
  193007. }
  193008. // Assume so if this fails for some reason
  193009. return true;
  193010. }
  193011. bool File::isOnRemovableDrive() const
  193012. {
  193013. jassertfalse // xxx not implemented for linux!
  193014. return false;
  193015. }
  193016. bool File::isHidden() const
  193017. {
  193018. return getFileName().startsWithChar ('.');
  193019. }
  193020. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193021. const File File::getSpecialLocation (const SpecialLocationType type)
  193022. {
  193023. switch (type)
  193024. {
  193025. case userHomeDirectory:
  193026. {
  193027. const char* homeDir = getenv ("HOME");
  193028. if (homeDir == 0)
  193029. {
  193030. struct passwd* const pw = getpwuid (getuid());
  193031. if (pw != 0)
  193032. homeDir = pw->pw_dir;
  193033. }
  193034. return File (String::fromUTF8 (homeDir));
  193035. }
  193036. case userDocumentsDirectory:
  193037. case userMusicDirectory:
  193038. case userMoviesDirectory:
  193039. case userApplicationDataDirectory:
  193040. return File ("~");
  193041. case userDesktopDirectory:
  193042. return File ("~/Desktop");
  193043. case commonApplicationDataDirectory:
  193044. return File ("/var");
  193045. case globalApplicationsDirectory:
  193046. return File ("/usr");
  193047. case tempDirectory:
  193048. {
  193049. File tmp ("/var/tmp");
  193050. if (! tmp.isDirectory())
  193051. {
  193052. tmp = "/tmp";
  193053. if (! tmp.isDirectory())
  193054. tmp = File::getCurrentWorkingDirectory();
  193055. }
  193056. return tmp;
  193057. }
  193058. case invokedExecutableFile:
  193059. if (juce_Argv0 != 0)
  193060. return File (String::fromUTF8 (juce_Argv0));
  193061. // deliberate fall-through...
  193062. case currentExecutableFile:
  193063. case currentApplicationFile:
  193064. return juce_getExecutableFile();
  193065. default:
  193066. jassertfalse // unknown type?
  193067. break;
  193068. }
  193069. return File::nonexistent;
  193070. }
  193071. const String File::getVersion() const
  193072. {
  193073. return String::empty; // xxx not yet implemented
  193074. }
  193075. const File File::getLinkedTarget() const
  193076. {
  193077. char buffer [4096];
  193078. size_t numChars = readlink (getFullPathName().toUTF8(),
  193079. buffer, sizeof (buffer));
  193080. if (numChars > 0 && numChars <= sizeof (buffer))
  193081. return File (String::fromUTF8 (buffer, (int) numChars));
  193082. return *this;
  193083. }
  193084. bool File::moveToTrash() const
  193085. {
  193086. if (! exists())
  193087. return true;
  193088. File trashCan ("~/.Trash");
  193089. if (! trashCan.isDirectory())
  193090. trashCan = "~/.local/share/Trash/files";
  193091. if (! trashCan.isDirectory())
  193092. return false;
  193093. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193094. getFileExtension()));
  193095. }
  193096. struct FindFileStruct
  193097. {
  193098. String parentDir, wildCard;
  193099. DIR* dir;
  193100. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193101. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193102. {
  193103. const char* const wildcardUTF8 = wildCard.toUTF8();
  193104. for (;;)
  193105. {
  193106. struct dirent* const de = readdir (dir);
  193107. if (de == 0)
  193108. break;
  193109. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193110. {
  193111. result = String::fromUTF8 (de->d_name);
  193112. const String path (parentDir + result);
  193113. if (isDir != 0 || fileSize != 0)
  193114. {
  193115. struct stat info;
  193116. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193117. if (isDir != 0)
  193118. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193119. if (isHidden != 0)
  193120. *isHidden = (de->d_name[0] == '.');
  193121. if (fileSize != 0)
  193122. *fileSize = statOk ? info.st_size : 0;
  193123. }
  193124. if (modTime != 0 || creationTime != 0)
  193125. {
  193126. int64 m, a, c;
  193127. juce_getFileTimes (path, m, a, c);
  193128. if (modTime != 0)
  193129. *modTime = m;
  193130. if (creationTime != 0)
  193131. *creationTime = c;
  193132. }
  193133. if (isReadOnly != 0)
  193134. *isReadOnly = ! juce_canWriteToFile (path);
  193135. return true;
  193136. }
  193137. }
  193138. return false;
  193139. }
  193140. };
  193141. // returns 0 on failure
  193142. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193143. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193144. Time* creationTime, bool* isReadOnly)
  193145. {
  193146. DIR* d = opendir (directory.toUTF8());
  193147. if (d != 0)
  193148. {
  193149. FindFileStruct* ff = new FindFileStruct();
  193150. ff->parentDir = directory;
  193151. if (!ff->parentDir.endsWithChar (File::separator))
  193152. ff->parentDir += File::separator;
  193153. ff->wildCard = wildCard;
  193154. if (wildCard == "*.*")
  193155. ff->wildCard = "*";
  193156. ff->dir = d;
  193157. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193158. {
  193159. return ff;
  193160. }
  193161. else
  193162. {
  193163. firstResultFile = String::empty;
  193164. isDir = false;
  193165. isHidden = false;
  193166. closedir (d);
  193167. delete ff;
  193168. }
  193169. }
  193170. return 0;
  193171. }
  193172. bool juce_findFileNext (void* handle, String& resultFile,
  193173. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193174. {
  193175. FindFileStruct* const ff = (FindFileStruct*) handle;
  193176. if (ff != 0)
  193177. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193178. return false;
  193179. }
  193180. void juce_findFileClose (void* handle)
  193181. {
  193182. FindFileStruct* const ff = (FindFileStruct*) handle;
  193183. if (ff != 0)
  193184. {
  193185. closedir (ff->dir);
  193186. delete ff;
  193187. }
  193188. }
  193189. bool juce_launchFile (const String& fileName,
  193190. const String& parameters)
  193191. {
  193192. String cmdString (fileName.replace (" ", "\\ ",false));
  193193. cmdString << " " << parameters;
  193194. if (URL::isProbablyAWebsiteURL (fileName)
  193195. || cmdString.startsWithIgnoreCase ("file:")
  193196. || URL::isProbablyAnEmailAddress (fileName))
  193197. {
  193198. // create a command that tries to launch a bunch of likely browsers
  193199. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193200. StringArray cmdLines;
  193201. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193202. cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
  193203. cmdString = cmdLines.joinIntoString (" || ");
  193204. }
  193205. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  193206. const int cpid = fork();
  193207. if (cpid == 0)
  193208. {
  193209. setsid();
  193210. // Child process
  193211. execve (argv[0], (char**) argv, environ);
  193212. exit (0);
  193213. }
  193214. return cpid >= 0;
  193215. }
  193216. void File::revealToUser() const
  193217. {
  193218. if (isDirectory())
  193219. startAsProcess();
  193220. else if (getParentDirectory().exists())
  193221. getParentDirectory().startAsProcess();
  193222. }
  193223. #endif
  193224. /*** End of inlined file: juce_linux_Files.cpp ***/
  193225. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193226. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193227. // compiled on its own).
  193228. #if JUCE_INCLUDED_FILE
  193229. struct NamedPipeInternal
  193230. {
  193231. String pipeInName, pipeOutName;
  193232. int pipeIn, pipeOut;
  193233. bool volatile createdPipe, blocked, stopReadOperation;
  193234. static void signalHandler (int) {}
  193235. };
  193236. void NamedPipe::cancelPendingReads()
  193237. {
  193238. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193239. {
  193240. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193241. intern->stopReadOperation = true;
  193242. char buffer [1] = { 0 };
  193243. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193244. (void) bytesWritten;
  193245. int timeout = 2000;
  193246. while (intern->blocked && --timeout >= 0)
  193247. Thread::sleep (2);
  193248. intern->stopReadOperation = false;
  193249. }
  193250. }
  193251. void NamedPipe::close()
  193252. {
  193253. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193254. if (intern != 0)
  193255. {
  193256. internal = 0;
  193257. if (intern->pipeIn != -1)
  193258. ::close (intern->pipeIn);
  193259. if (intern->pipeOut != -1)
  193260. ::close (intern->pipeOut);
  193261. if (intern->createdPipe)
  193262. {
  193263. unlink (intern->pipeInName.toUTF8());
  193264. unlink (intern->pipeOutName.toUTF8());
  193265. }
  193266. delete intern;
  193267. }
  193268. }
  193269. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193270. {
  193271. close();
  193272. NamedPipeInternal* const intern = new NamedPipeInternal();
  193273. internal = intern;
  193274. intern->createdPipe = createPipe;
  193275. intern->blocked = false;
  193276. intern->stopReadOperation = false;
  193277. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193278. siginterrupt (SIGPIPE, 1);
  193279. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  193280. intern->pipeInName = pipePath + "_in";
  193281. intern->pipeOutName = pipePath + "_out";
  193282. intern->pipeIn = -1;
  193283. intern->pipeOut = -1;
  193284. if (createPipe)
  193285. {
  193286. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193287. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193288. {
  193289. delete intern;
  193290. internal = 0;
  193291. return false;
  193292. }
  193293. }
  193294. return true;
  193295. }
  193296. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193297. {
  193298. int bytesRead = -1;
  193299. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193300. if (intern != 0)
  193301. {
  193302. intern->blocked = true;
  193303. if (intern->pipeIn == -1)
  193304. {
  193305. if (intern->createdPipe)
  193306. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193307. else
  193308. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193309. if (intern->pipeIn == -1)
  193310. {
  193311. intern->blocked = false;
  193312. return -1;
  193313. }
  193314. }
  193315. bytesRead = 0;
  193316. char* p = (char*) destBuffer;
  193317. while (bytesRead < maxBytesToRead)
  193318. {
  193319. const int bytesThisTime = maxBytesToRead - bytesRead;
  193320. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193321. if (numRead <= 0 || intern->stopReadOperation)
  193322. {
  193323. bytesRead = -1;
  193324. break;
  193325. }
  193326. bytesRead += numRead;
  193327. p += bytesRead;
  193328. }
  193329. intern->blocked = false;
  193330. }
  193331. return bytesRead;
  193332. }
  193333. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193334. {
  193335. int bytesWritten = -1;
  193336. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193337. if (intern != 0)
  193338. {
  193339. if (intern->pipeOut == -1)
  193340. {
  193341. if (intern->createdPipe)
  193342. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193343. else
  193344. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193345. if (intern->pipeOut == -1)
  193346. {
  193347. return -1;
  193348. }
  193349. }
  193350. const char* p = (const char*) sourceBuffer;
  193351. bytesWritten = 0;
  193352. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193353. while (bytesWritten < numBytesToWrite
  193354. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193355. {
  193356. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193357. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193358. if (numWritten <= 0)
  193359. {
  193360. bytesWritten = -1;
  193361. break;
  193362. }
  193363. bytesWritten += numWritten;
  193364. p += bytesWritten;
  193365. }
  193366. }
  193367. return bytesWritten;
  193368. }
  193369. #endif
  193370. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193371. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193372. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193373. // compiled on its own).
  193374. #if JUCE_INCLUDED_FILE
  193375. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193376. {
  193377. int numResults = 0;
  193378. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193379. if (s != -1)
  193380. {
  193381. char buf [1024];
  193382. struct ifconf ifc;
  193383. ifc.ifc_len = sizeof (buf);
  193384. ifc.ifc_buf = buf;
  193385. ioctl (s, SIOCGIFCONF, &ifc);
  193386. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193387. {
  193388. struct ifreq ifr;
  193389. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193390. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193391. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193392. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193393. && numResults < maxNum)
  193394. {
  193395. int64 a = 0;
  193396. for (int j = 6; --j >= 0;)
  193397. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193398. *addresses++ = a;
  193399. ++numResults;
  193400. }
  193401. }
  193402. close (s);
  193403. }
  193404. return numResults;
  193405. }
  193406. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193407. const String& emailSubject,
  193408. const String& bodyText,
  193409. const StringArray& filesToAttach)
  193410. {
  193411. jassertfalse // xxx todo
  193412. return false;
  193413. }
  193414. class JUCE_HTTPSocketStream
  193415. {
  193416. public:
  193417. JUCE_HTTPSocketStream()
  193418. : readPosition (0),
  193419. socketHandle (-1),
  193420. levelsOfRedirection (0),
  193421. timeoutSeconds (15)
  193422. {
  193423. }
  193424. ~JUCE_HTTPSocketStream()
  193425. {
  193426. closeSocket();
  193427. }
  193428. bool open (const String& url,
  193429. const String& headers,
  193430. const MemoryBlock& postData,
  193431. const bool isPost,
  193432. URL::OpenStreamProgressCallback* callback,
  193433. void* callbackContext,
  193434. int timeOutMs)
  193435. {
  193436. closeSocket();
  193437. uint32 timeOutTime = Time::getMillisecondCounter();
  193438. if (timeOutMs == 0)
  193439. timeOutTime += 60000;
  193440. else if (timeOutMs < 0)
  193441. timeOutTime = 0xffffffff;
  193442. else
  193443. timeOutTime += timeOutMs;
  193444. String hostName, hostPath;
  193445. int hostPort;
  193446. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193447. return false;
  193448. const struct hostent* host = 0;
  193449. int port = 0;
  193450. String proxyName, proxyPath;
  193451. int proxyPort = 0;
  193452. String proxyURL (getenv ("http_proxy"));
  193453. if (proxyURL.startsWithIgnoreCase ("http://"))
  193454. {
  193455. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193456. return false;
  193457. host = gethostbyname (proxyName.toUTF8());
  193458. port = proxyPort;
  193459. }
  193460. else
  193461. {
  193462. host = gethostbyname (hostName.toUTF8());
  193463. port = hostPort;
  193464. }
  193465. if (host == 0)
  193466. return false;
  193467. struct sockaddr_in address;
  193468. zerostruct (address);
  193469. memcpy (&address.sin_addr, host->h_addr, host->h_length);
  193470. address.sin_family = host->h_addrtype;
  193471. address.sin_port = htons (port);
  193472. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193473. if (socketHandle == -1)
  193474. return false;
  193475. int receiveBufferSize = 16384;
  193476. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193477. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193478. #if JUCE_MAC
  193479. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193480. #endif
  193481. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193482. {
  193483. closeSocket();
  193484. return false;
  193485. }
  193486. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193487. proxyName, proxyPort,
  193488. hostPath, url,
  193489. headers, postData,
  193490. isPost));
  193491. size_t totalHeaderSent = 0;
  193492. while (totalHeaderSent < requestHeader.getSize())
  193493. {
  193494. if (Time::getMillisecondCounter() > timeOutTime)
  193495. {
  193496. closeSocket();
  193497. return false;
  193498. }
  193499. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193500. if (send (socketHandle,
  193501. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193502. numToSend, 0)
  193503. != numToSend)
  193504. {
  193505. closeSocket();
  193506. return false;
  193507. }
  193508. totalHeaderSent += numToSend;
  193509. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193510. {
  193511. closeSocket();
  193512. return false;
  193513. }
  193514. }
  193515. const String responseHeader (readResponse (timeOutTime));
  193516. if (responseHeader.isNotEmpty())
  193517. {
  193518. //DBG (responseHeader);
  193519. StringArray lines;
  193520. lines.addLines (responseHeader);
  193521. const int statusCode = responseHeader.fromFirstOccurrenceOf (" ", false, false)
  193522. .substring (0, 3).getIntValue();
  193523. //int contentLength = findHeaderItem (lines, "Content-Length:").getIntValue();
  193524. //bool isChunked = findHeaderItem (lines, "Transfer-Encoding:").equalsIgnoreCase ("chunked");
  193525. String location (findHeaderItem (lines, "Location:"));
  193526. if (statusCode >= 300 && statusCode < 400
  193527. && location.isNotEmpty())
  193528. {
  193529. if (! location.startsWithIgnoreCase ("http://"))
  193530. location = "http://" + location;
  193531. if (levelsOfRedirection++ < 3)
  193532. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193533. }
  193534. else
  193535. {
  193536. levelsOfRedirection = 0;
  193537. return true;
  193538. }
  193539. }
  193540. closeSocket();
  193541. return false;
  193542. }
  193543. int read (void* buffer, int bytesToRead)
  193544. {
  193545. fd_set readbits;
  193546. FD_ZERO (&readbits);
  193547. FD_SET (socketHandle, &readbits);
  193548. struct timeval tv;
  193549. tv.tv_sec = timeoutSeconds;
  193550. tv.tv_usec = 0;
  193551. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193552. return 0; // (timeout)
  193553. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193554. readPosition += bytesRead;
  193555. return bytesRead;
  193556. }
  193557. int readPosition;
  193558. juce_UseDebuggingNewOperator
  193559. private:
  193560. int socketHandle, levelsOfRedirection;
  193561. const int timeoutSeconds;
  193562. void closeSocket()
  193563. {
  193564. if (socketHandle >= 0)
  193565. close (socketHandle);
  193566. socketHandle = -1;
  193567. }
  193568. const MemoryBlock createRequestHeader (const String& hostName,
  193569. const int hostPort,
  193570. const String& proxyName,
  193571. const int proxyPort,
  193572. const String& hostPath,
  193573. const String& originalURL,
  193574. const String& headers,
  193575. const MemoryBlock& postData,
  193576. const bool isPost)
  193577. {
  193578. String header (isPost ? "POST " : "GET ");
  193579. if (proxyName.isEmpty())
  193580. {
  193581. header << hostPath << " HTTP/1.0\r\nHost: "
  193582. << hostName << ':' << hostPort;
  193583. }
  193584. else
  193585. {
  193586. header << originalURL << " HTTP/1.0\r\nHost: "
  193587. << proxyName << ':' << proxyPort;
  193588. }
  193589. header << "\r\nUser-Agent: JUCE/"
  193590. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193591. << "\r\nConnection: Close\r\nContent-Length: "
  193592. << postData.getSize() << "\r\n"
  193593. << headers << "\r\n";
  193594. MemoryBlock mb;
  193595. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193596. mb.append (postData.getData(), postData.getSize());
  193597. return mb;
  193598. }
  193599. const String readResponse (const uint32 timeOutTime)
  193600. {
  193601. int bytesRead = 0, numConsecutiveLFs = 0;
  193602. MemoryBlock buffer (1024, true);
  193603. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193604. && Time::getMillisecondCounter() <= timeOutTime)
  193605. {
  193606. fd_set readbits;
  193607. FD_ZERO (&readbits);
  193608. FD_SET (socketHandle, &readbits);
  193609. struct timeval tv;
  193610. tv.tv_sec = timeoutSeconds;
  193611. tv.tv_usec = 0;
  193612. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193613. return String::empty; // (timeout)
  193614. buffer.ensureSize (bytesRead + 8, true);
  193615. char* const dest = (char*) buffer.getData() + bytesRead;
  193616. if (recv (socketHandle, dest, 1, 0) == -1)
  193617. return String::empty;
  193618. const char lastByte = *dest;
  193619. ++bytesRead;
  193620. if (lastByte == '\n')
  193621. ++numConsecutiveLFs;
  193622. else if (lastByte != '\r')
  193623. numConsecutiveLFs = 0;
  193624. }
  193625. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193626. if (header.startsWithIgnoreCase ("HTTP/"))
  193627. return header.trimEnd();
  193628. return String::empty;
  193629. }
  193630. static bool decomposeURL (const String& url,
  193631. String& host, String& path, int& port)
  193632. {
  193633. if (! url.startsWithIgnoreCase ("http://"))
  193634. return false;
  193635. const int nextSlash = url.indexOfChar (7, '/');
  193636. int nextColon = url.indexOfChar (7, ':');
  193637. if (nextColon > nextSlash && nextSlash > 0)
  193638. nextColon = -1;
  193639. if (nextColon >= 0)
  193640. {
  193641. host = url.substring (7, nextColon);
  193642. if (nextSlash >= 0)
  193643. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193644. else
  193645. port = url.substring (nextColon + 1).getIntValue();
  193646. }
  193647. else
  193648. {
  193649. port = 80;
  193650. if (nextSlash >= 0)
  193651. host = url.substring (7, nextSlash);
  193652. else
  193653. host = url.substring (7);
  193654. }
  193655. if (nextSlash >= 0)
  193656. path = url.substring (nextSlash);
  193657. else
  193658. path = "/";
  193659. return true;
  193660. }
  193661. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193662. {
  193663. for (int i = 0; i < lines.size(); ++i)
  193664. if (lines[i].startsWithIgnoreCase (itemName))
  193665. return lines[i].substring (itemName.length()).trim();
  193666. return String::empty;
  193667. }
  193668. };
  193669. bool juce_isOnLine()
  193670. {
  193671. return true;
  193672. }
  193673. void* juce_openInternetFile (const String& url,
  193674. const String& headers,
  193675. const MemoryBlock& postData,
  193676. const bool isPost,
  193677. URL::OpenStreamProgressCallback* callback,
  193678. void* callbackContext,
  193679. int timeOutMs)
  193680. {
  193681. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193682. if (s->open (url, headers, postData, isPost,
  193683. callback, callbackContext, timeOutMs))
  193684. return s;
  193685. delete s;
  193686. return 0;
  193687. }
  193688. void juce_closeInternetFile (void* handle)
  193689. {
  193690. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193691. if (s != 0)
  193692. delete s;
  193693. }
  193694. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193695. {
  193696. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193697. if (s != 0)
  193698. return s->read (buffer, bytesToRead);
  193699. return 0;
  193700. }
  193701. int64 juce_getInternetFileContentLength (void* handle)
  193702. {
  193703. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193704. if (s != 0)
  193705. {
  193706. //xxx todo
  193707. jassertfalse
  193708. }
  193709. return -1;
  193710. }
  193711. int juce_seekInInternetFile (void* handle, int newPosition)
  193712. {
  193713. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193714. if (s != 0)
  193715. return s->readPosition;
  193716. return 0;
  193717. }
  193718. #endif
  193719. /*** End of inlined file: juce_linux_Network.cpp ***/
  193720. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193721. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193722. // compiled on its own).
  193723. #if JUCE_INCLUDED_FILE
  193724. void Logger::outputDebugString (const String& text) throw()
  193725. {
  193726. std::cerr << text << std::endl;
  193727. }
  193728. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193729. {
  193730. return Linux;
  193731. }
  193732. const String SystemStats::getOperatingSystemName() throw()
  193733. {
  193734. return "Linux";
  193735. }
  193736. bool SystemStats::isOperatingSystem64Bit() throw()
  193737. {
  193738. #if JUCE_64BIT
  193739. return true;
  193740. #else
  193741. //xxx not sure how to find this out?..
  193742. return false;
  193743. #endif
  193744. }
  193745. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193746. {
  193747. String info;
  193748. char buf [256];
  193749. FILE* f = fopen ("/proc/cpuinfo", "r");
  193750. while (f != 0 && fgets (buf, sizeof(buf), f))
  193751. {
  193752. if (strncmp (buf, key, strlen (key)) == 0)
  193753. {
  193754. char* p = buf;
  193755. while (*p && *p != '\n')
  193756. ++p;
  193757. if (*p != 0)
  193758. *p = 0;
  193759. p = buf;
  193760. while (*p != 0 && *p != ':')
  193761. ++p;
  193762. if (*p != 0 && *(p + 1) != 0)
  193763. info = p + 2;
  193764. if (! lastOne)
  193765. break;
  193766. }
  193767. }
  193768. fclose (f);
  193769. return info;
  193770. }
  193771. bool SystemStats::hasMMX() throw()
  193772. {
  193773. return getCpuInfo ("flags").contains ("mmx");
  193774. }
  193775. bool SystemStats::hasSSE() throw()
  193776. {
  193777. return getCpuInfo ("flags").contains ("sse");
  193778. }
  193779. bool SystemStats::hasSSE2() throw()
  193780. {
  193781. return getCpuInfo ("flags").contains ("sse2");
  193782. }
  193783. bool SystemStats::has3DNow() throw()
  193784. {
  193785. return getCpuInfo ("flags").contains ("3dnow");
  193786. }
  193787. const String SystemStats::getCpuVendor() throw()
  193788. {
  193789. return getCpuInfo ("vendor_id");
  193790. }
  193791. int SystemStats::getCpuSpeedInMegaherz() throw()
  193792. {
  193793. const String speed (getCpuInfo ("cpu MHz"));
  193794. return (int) (speed.getFloatValue() + 0.5f);
  193795. }
  193796. int SystemStats::getMemorySizeInMegabytes() throw()
  193797. {
  193798. struct sysinfo sysi;
  193799. if (sysinfo (&sysi) == 0)
  193800. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193801. return 0;
  193802. }
  193803. uint32 juce_millisecondsSinceStartup() throw()
  193804. {
  193805. static unsigned int calibrate = 0;
  193806. static bool calibrated = false;
  193807. timeval t;
  193808. unsigned int ret = 0;
  193809. if (! gettimeofday (&t, 0))
  193810. {
  193811. if (! calibrated)
  193812. {
  193813. struct sysinfo sysi;
  193814. if (sysinfo (&sysi) == 0)
  193815. // Safe to assume system was not brought up earlier than 1970!
  193816. calibrate = t.tv_sec - sysi.uptime;
  193817. calibrated = true;
  193818. }
  193819. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193820. }
  193821. return ret;
  193822. }
  193823. double Time::getMillisecondCounterHiRes() throw()
  193824. {
  193825. return getHighResolutionTicks() * 0.001;
  193826. }
  193827. int64 Time::getHighResolutionTicks() throw()
  193828. {
  193829. timeval t;
  193830. if (gettimeofday (&t, 0))
  193831. return 0;
  193832. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193833. }
  193834. int64 Time::getHighResolutionTicksPerSecond() throw()
  193835. {
  193836. // Microseconds
  193837. return 1000000;
  193838. }
  193839. bool Time::setSystemTimeToThisTime() const throw()
  193840. {
  193841. timeval t;
  193842. t.tv_sec = millisSinceEpoch % 1000000;
  193843. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193844. return settimeofday (&t, NULL) ? false : true;
  193845. }
  193846. int SystemStats::getPageSize() throw()
  193847. {
  193848. static int systemPageSize = 0;
  193849. if (systemPageSize == 0)
  193850. systemPageSize = sysconf (_SC_PAGESIZE);
  193851. return systemPageSize;
  193852. }
  193853. int SystemStats::getNumCpus() throw()
  193854. {
  193855. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193856. return lastCpu + 1;
  193857. }
  193858. const String SystemStats::getLogonName()
  193859. {
  193860. const char* user = getenv ("USER");
  193861. if (user == 0)
  193862. {
  193863. struct passwd* const pw = getpwuid (getuid());
  193864. if (pw != 0)
  193865. user = pw->pw_name;
  193866. }
  193867. return String::fromUTF8 (user);
  193868. }
  193869. const String SystemStats::getFullUserName()
  193870. {
  193871. return getLogonName();
  193872. }
  193873. void SystemStats::initialiseStats() throw()
  193874. {
  193875. // Process starts off as root when running suid
  193876. Process::lowerPrivilege();
  193877. String s (SystemStats::getJUCEVersion());
  193878. }
  193879. void PlatformUtilities::fpuReset()
  193880. {
  193881. }
  193882. #endif
  193883. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193884. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193885. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193886. // compiled on its own).
  193887. #if JUCE_INCLUDED_FILE
  193888. void JUCE_API juce_threadEntryPoint (void*);
  193889. void* threadEntryProc (void* value)
  193890. {
  193891. // New threads start off as root when running suid
  193892. Process::lowerPrivilege();
  193893. juce_threadEntryPoint (value);
  193894. return 0;
  193895. }
  193896. void* juce_createThread (void* userData)
  193897. {
  193898. pthread_t handle = 0;
  193899. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  193900. {
  193901. pthread_detach (handle);
  193902. return (void*) handle;
  193903. }
  193904. return 0;
  193905. }
  193906. void juce_killThread (void* handle)
  193907. {
  193908. if (handle != 0)
  193909. pthread_cancel ((pthread_t)handle);
  193910. }
  193911. void juce_setCurrentThreadName (const String& /*name*/)
  193912. {
  193913. }
  193914. Thread::ThreadID Thread::getCurrentThreadId()
  193915. {
  193916. return (ThreadID) pthread_self();
  193917. }
  193918. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  193919. // priority of the current thread
  193920. bool juce_setThreadPriority (void* handle, int priority)
  193921. {
  193922. struct sched_param param;
  193923. int policy, maxp, minp, pri;
  193924. if (handle == 0)
  193925. handle = (void*) pthread_self();
  193926. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  193927. && policy != SCHED_OTHER)
  193928. {
  193929. minp = sched_get_priority_min(policy);
  193930. maxp = sched_get_priority_max(policy);
  193931. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  193932. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  193933. // Realtime process priority
  193934. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  193935. else
  193936. // High process priority
  193937. param.__sched_priority = minp + pri;
  193938. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  193939. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  193940. }
  193941. return false;
  193942. }
  193943. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  193944. {
  193945. #if SUPPORT_AFFINITIES
  193946. cpu_set_t affinity;
  193947. CPU_ZERO (&affinity);
  193948. for (int i = 0; i < 32; ++i)
  193949. if ((affinityMask & (1 << i)) != 0)
  193950. CPU_SET (i, &affinity);
  193951. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  193952. sched_yield();
  193953. #else
  193954. /* affinities aren't supported because either the appropriate header files weren't found,
  193955. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  193956. */
  193957. jassertfalse
  193958. #endif
  193959. }
  193960. void Thread::yield()
  193961. {
  193962. sched_yield();
  193963. }
  193964. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  193965. void Process::setPriority (ProcessPriority prior)
  193966. {
  193967. struct sched_param param;
  193968. int policy, maxp, minp;
  193969. const int p = (int) prior;
  193970. if (p <= 1)
  193971. policy = SCHED_OTHER;
  193972. else
  193973. policy = SCHED_RR;
  193974. minp = sched_get_priority_min (policy);
  193975. maxp = sched_get_priority_max (policy);
  193976. if (p < 2)
  193977. param.__sched_priority = 0;
  193978. else if (p == 2 )
  193979. // Set to middle of lower realtime priority range
  193980. param.__sched_priority = minp + (maxp - minp) / 4;
  193981. else
  193982. // Set to middle of higher realtime priority range
  193983. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  193984. pthread_setschedparam (pthread_self(), policy, &param);
  193985. }
  193986. void Process::terminate()
  193987. {
  193988. exit (0);
  193989. }
  193990. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  193991. {
  193992. static char testResult = 0;
  193993. if (testResult == 0)
  193994. {
  193995. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  193996. if (testResult >= 0)
  193997. {
  193998. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  193999. testResult = 1;
  194000. }
  194001. }
  194002. return testResult < 0;
  194003. }
  194004. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194005. {
  194006. return juce_isRunningUnderDebugger();
  194007. }
  194008. void Process::raisePrivilege()
  194009. {
  194010. // If running suid root, change effective user
  194011. // to root
  194012. if (geteuid() != 0 && getuid() == 0)
  194013. {
  194014. setreuid (geteuid(), getuid());
  194015. setregid (getegid(), getgid());
  194016. }
  194017. }
  194018. void Process::lowerPrivilege()
  194019. {
  194020. // If runing suid root, change effective user
  194021. // back to real user
  194022. if (geteuid() == 0 && getuid() != 0)
  194023. {
  194024. setreuid (geteuid(), getuid());
  194025. setregid (getegid(), getgid());
  194026. }
  194027. }
  194028. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194029. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194030. {
  194031. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194032. }
  194033. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194034. {
  194035. dlclose(handle);
  194036. }
  194037. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194038. {
  194039. return dlsym (libraryHandle, procedureName.toCString());
  194040. }
  194041. #endif
  194042. #endif
  194043. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194044. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194045. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194046. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194047. // compiled on its own).
  194048. #if JUCE_INCLUDED_FILE
  194049. #ifdef JUCE_DEBUG
  194050. #define JUCE_DEBUG_XERRORS 1
  194051. #endif
  194052. extern Display* display;
  194053. extern Window juce_messageWindowHandle;
  194054. static String localClipboardContent;
  194055. static Atom atom_UTF8_STRING;
  194056. static Atom atom_CLIPBOARD;
  194057. static Atom atom_TARGETS;
  194058. static void initSelectionAtoms()
  194059. {
  194060. static bool isInitialised = false;
  194061. if (! isInitialised)
  194062. {
  194063. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194064. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194065. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194066. }
  194067. }
  194068. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194069. // works only for strings shorter than 1000000 bytes
  194070. static String juce_readWindowProperty (Window window, Atom prop,
  194071. Atom fmt, // XA_STRING or UTF8_STRING
  194072. bool deleteAfterReading)
  194073. {
  194074. String returnData;
  194075. char* clipData;
  194076. Atom actualType;
  194077. int actualFormat;
  194078. unsigned long numItems, bytesLeft;
  194079. if (XGetWindowProperty (display, window, prop,
  194080. 0L /* offset */, 1000000 /* length (max) */, False,
  194081. AnyPropertyType /* format */,
  194082. &actualType, &actualFormat, &numItems, &bytesLeft,
  194083. (unsigned char**) &clipData) == Success)
  194084. {
  194085. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194086. {
  194087. returnData = String::fromUTF8 (clipData, numItems);
  194088. }
  194089. else if (actualType == XA_STRING && actualFormat == 8)
  194090. {
  194091. returnData = String (clipData, numItems);
  194092. }
  194093. if (clipData != 0)
  194094. XFree (clipData);
  194095. jassert (bytesLeft == 0 || numItems == 1000000);
  194096. }
  194097. if (deleteAfterReading)
  194098. XDeleteProperty (display, window, prop);
  194099. return returnData;
  194100. }
  194101. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194102. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194103. {
  194104. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194105. // The selection owner will be asked to set the JUCE_SEL property on the
  194106. // juce_messageWindowHandle with the selection content
  194107. XConvertSelection (display, selection, requested_format, property_name,
  194108. juce_messageWindowHandle, CurrentTime);
  194109. int timeoutMs = 200; // will wait at most for 200 ms
  194110. do
  194111. {
  194112. XEvent event;
  194113. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194114. {
  194115. if (event.xselection.property == property_name)
  194116. {
  194117. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194118. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194119. event.xselection.property,
  194120. requested_format, true);
  194121. return true;
  194122. }
  194123. else
  194124. {
  194125. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194126. }
  194127. }
  194128. // not very elegant.. we could do a select() or something like that...
  194129. // however clipboard content requesting is inherently slow on x11, it
  194130. // often takes 50ms or more so...
  194131. Thread::sleep (4);
  194132. timeoutMs -= 4;
  194133. }
  194134. while (timeoutMs > 0);
  194135. DBG("timeout for juce_requestSelectionContent");
  194136. return false;
  194137. }
  194138. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194139. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194140. {
  194141. initSelectionAtoms();
  194142. // the selection content is sent to the target window as a window property
  194143. XSelectionEvent reply;
  194144. reply.type = SelectionNotify;
  194145. reply.display = evt.display;
  194146. reply.requestor = evt.requestor;
  194147. reply.selection = evt.selection;
  194148. reply.target = evt.target;
  194149. reply.property = None; // == "fail"
  194150. reply.time = evt.time;
  194151. HeapBlock <char> data;
  194152. int propertyFormat = 0, numDataItems = 0;
  194153. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194154. {
  194155. if (evt.target == XA_STRING)
  194156. {
  194157. // format data according to system locale
  194158. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194159. data.calloc (numDataItems + 1);
  194160. localClipboardContent.copyToCString (data, numDataItems);
  194161. propertyFormat = 8; // bits/item
  194162. }
  194163. else if (evt.target == atom_UTF8_STRING)
  194164. {
  194165. // translate to utf8
  194166. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194167. data.calloc (numDataItems + 1);
  194168. localClipboardContent.copyToUTF8 (data, numDataItems);
  194169. propertyFormat = 8; // bits/item
  194170. }
  194171. else if (evt.target == atom_TARGETS)
  194172. {
  194173. // another application wants to know what we are able to send
  194174. numDataItems = 2;
  194175. propertyFormat = 32; // atoms are 32-bit
  194176. data.calloc (numDataItems * 4);
  194177. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194178. atoms[0] = atom_UTF8_STRING;
  194179. atoms[1] = XA_STRING;
  194180. }
  194181. }
  194182. else
  194183. {
  194184. DBG ("requested unsupported clipboard");
  194185. }
  194186. if (data != 0)
  194187. {
  194188. const int maxReasonableSelectionSize = 1000000;
  194189. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194190. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194191. {
  194192. XChangeProperty (evt.display, evt.requestor,
  194193. evt.property, evt.target,
  194194. propertyFormat /* 8 or 32 */, PropModeReplace,
  194195. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194196. reply.property = evt.property; // " == success"
  194197. }
  194198. }
  194199. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194200. }
  194201. void SystemClipboard::copyTextToClipboard (const String& clipText)
  194202. {
  194203. initSelectionAtoms();
  194204. localClipboardContent = clipText;
  194205. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194206. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194207. }
  194208. const String SystemClipboard::getTextFromClipboard()
  194209. {
  194210. initSelectionAtoms();
  194211. String content;
  194212. Atom selection = XA_PRIMARY;
  194213. Window selectionOwner = None;
  194214. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194215. {
  194216. selection = atom_CLIPBOARD;
  194217. selectionOwner = XGetSelectionOwner (display, selection);
  194218. }
  194219. if (selectionOwner != None)
  194220. {
  194221. if (selectionOwner == juce_messageWindowHandle)
  194222. {
  194223. content = localClipboardContent;
  194224. }
  194225. else
  194226. {
  194227. // first try: we want an utf8 string
  194228. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194229. if (! ok)
  194230. {
  194231. // second chance, ask for a good old locale-dependent string ..
  194232. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194233. }
  194234. }
  194235. }
  194236. return content;
  194237. }
  194238. #endif
  194239. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194240. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194241. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194242. // compiled on its own).
  194243. #if JUCE_INCLUDED_FILE
  194244. #ifdef JUCE_DEBUG
  194245. #define JUCE_DEBUG_XERRORS 1
  194246. #endif
  194247. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194248. Window juce_messageWindowHandle = None;
  194249. XContext improbableNumber; // This is referenced from Windowing.cpp
  194250. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194251. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194252. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194253. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194254. class InternalMessageQueue
  194255. {
  194256. public:
  194257. InternalMessageQueue()
  194258. : bytesInSocket (0)
  194259. {
  194260. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194261. (void) ret; jassert (ret == 0);
  194262. //setNonBlocking (fd[0]);
  194263. //setNonBlocking (fd[1]);
  194264. }
  194265. ~InternalMessageQueue()
  194266. {
  194267. close (fd[0]);
  194268. close (fd[1]);
  194269. }
  194270. void postMessage (Message* msg)
  194271. {
  194272. const int maxBytesInSocketQueue = 128;
  194273. ScopedLock sl (lock);
  194274. queue.add (msg);
  194275. if (bytesInSocket < maxBytesInSocketQueue)
  194276. {
  194277. ++bytesInSocket;
  194278. ScopedUnlock ul (lock);
  194279. const unsigned char x = 0xff;
  194280. size_t bytesWritten = write (fd[0], &x, 1);
  194281. (void) bytesWritten;
  194282. }
  194283. }
  194284. bool isEmpty() const
  194285. {
  194286. ScopedLock sl (lock);
  194287. return queue.size() == 0;
  194288. }
  194289. Message* popNextMessage()
  194290. {
  194291. ScopedLock sl (lock);
  194292. if (bytesInSocket > 0)
  194293. {
  194294. --bytesInSocket;
  194295. ScopedUnlock ul (lock);
  194296. unsigned char x;
  194297. size_t numBytes = read (fd[1], &x, 1);
  194298. (void) numBytes;
  194299. }
  194300. Message* m = queue[0];
  194301. queue.remove (0, false /* deleteObject */);
  194302. return m;
  194303. }
  194304. int getWaitHandle() const { return fd[1]; }
  194305. private:
  194306. CriticalSection lock;
  194307. OwnedArray <Message> queue;
  194308. int fd[2];
  194309. int bytesInSocket;
  194310. static bool setNonBlocking (int handle)
  194311. {
  194312. int socketFlags = fcntl (handle, F_GETFL, 0);
  194313. if (socketFlags == -1)
  194314. return false;
  194315. socketFlags |= O_NONBLOCK;
  194316. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194317. }
  194318. };
  194319. struct MessageThreadFuncCall
  194320. {
  194321. enum { uniqueID = 0x73774623 };
  194322. MessageCallbackFunction* func;
  194323. void* parameter;
  194324. void* result;
  194325. CriticalSection lock;
  194326. WaitableEvent event;
  194327. };
  194328. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194329. // error handling in X11
  194330. static bool errorOccurred = false;
  194331. static bool keyboardBreakOccurred = false;
  194332. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194333. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194334. // Usually happens when client-server connection is broken
  194335. static int ioErrorHandler (Display* display)
  194336. {
  194337. DBG ("ERROR: connection to X server broken.. terminating.");
  194338. errorOccurred = true;
  194339. if (JUCEApplication::getInstance() != 0)
  194340. Process::terminate();
  194341. return 0;
  194342. }
  194343. // A protocol error has occurred
  194344. static int errorHandler (Display* display, XErrorEvent* event)
  194345. {
  194346. #ifdef JUCE_DEBUG_XERRORS
  194347. char errorStr[64] = { 0 };
  194348. char requestStr[64] = { 0 };
  194349. XGetErrorText (display, event->error_code, errorStr, 64);
  194350. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194351. "Unknown", requestStr, 64);
  194352. DBG ("ERROR: X returned " + String (errorStr) + " for operation " + String (requestStr));
  194353. #endif
  194354. return 0;
  194355. }
  194356. // Breakin from keyboard
  194357. static void signalHandler (int sig)
  194358. {
  194359. if (sig == SIGINT)
  194360. {
  194361. keyboardBreakOccurred = true;
  194362. return;
  194363. }
  194364. static bool reentrant = false;
  194365. if (! reentrant)
  194366. {
  194367. reentrant = true;
  194368. // Illegal instruction
  194369. fflush (stdout);
  194370. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194371. errorOccurred = true;
  194372. if (JUCEApplication::getInstance() != 0)
  194373. Process::terminate();
  194374. }
  194375. else
  194376. {
  194377. if (JUCEApplication::getInstance() != 0)
  194378. exit(0);
  194379. }
  194380. }
  194381. void MessageManager::doPlatformSpecificInitialisation()
  194382. {
  194383. // Initialise xlib for multiple thread support
  194384. static bool initThreadCalled = false;
  194385. if (! initThreadCalled)
  194386. {
  194387. if (! XInitThreads())
  194388. {
  194389. // This is fatal! Print error and closedown
  194390. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194391. if (JUCEApplication::getInstance() != 0)
  194392. Process::terminate();
  194393. return;
  194394. }
  194395. initThreadCalled = true;
  194396. }
  194397. // This is called if the client/server connection is broken
  194398. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194399. // This is called if a protocol error occurs
  194400. oldErrorHandler = XSetErrorHandler (errorHandler);
  194401. // Install signal handler for break-in
  194402. struct sigaction saction;
  194403. sigset_t maskSet;
  194404. sigemptyset (&maskSet);
  194405. saction.sa_handler = signalHandler;
  194406. saction.sa_mask = maskSet;
  194407. saction.sa_flags = 0;
  194408. sigaction (SIGINT, &saction, NULL);
  194409. #ifndef _DEBUG
  194410. // Setup signal handlers for various fatal errors
  194411. sigaction (SIGILL, &saction, NULL);
  194412. sigaction (SIGBUS, &saction, NULL);
  194413. sigaction (SIGFPE, &saction, NULL);
  194414. sigaction (SIGSEGV, &saction, NULL);
  194415. sigaction (SIGSYS, &saction, NULL);
  194416. #endif
  194417. // Create the internal message queue
  194418. juce_internalMessageQueue = new InternalMessageQueue();
  194419. // Try to connect to a display
  194420. String displayName (getenv ("DISPLAY"));
  194421. if (displayName.isEmpty())
  194422. displayName = ":0.0";
  194423. display = XOpenDisplay (displayName.toCString());
  194424. if (display == 0)
  194425. {
  194426. // This is not fatal! we can run headless.
  194427. return;
  194428. }
  194429. // Get defaults for various properties
  194430. int screen = DefaultScreen (display);
  194431. Window root = RootWindow (display, screen);
  194432. Visual* visual = DefaultVisual (display, screen);
  194433. // Create a context to store user data associated with Windows we
  194434. // create in WindowDriver
  194435. improbableNumber = XUniqueContext();
  194436. // We're only interested in client messages for this window
  194437. // which are always sent
  194438. XSetWindowAttributes swa;
  194439. swa.event_mask = NoEventMask;
  194440. // Create our message window (this will never be mapped)
  194441. juce_messageWindowHandle = XCreateWindow (display, root,
  194442. 0, 0, 1, 1, 0, 0, InputOnly,
  194443. visual, CWEventMask, &swa);
  194444. }
  194445. void MessageManager::doPlatformSpecificShutdown()
  194446. {
  194447. deleteAndZero (juce_internalMessageQueue);
  194448. if (display != 0 && ! errorOccurred)
  194449. {
  194450. XDestroyWindow (display, juce_messageWindowHandle);
  194451. XCloseDisplay (display);
  194452. // reset pointers
  194453. juce_messageWindowHandle = 0;
  194454. display = 0;
  194455. // Restore original error handlers
  194456. XSetIOErrorHandler (oldIOErrorHandler);
  194457. oldIOErrorHandler = 0;
  194458. XSetErrorHandler (oldErrorHandler);
  194459. oldErrorHandler = 0;
  194460. }
  194461. }
  194462. bool juce_postMessageToSystemQueue (void* message)
  194463. {
  194464. if (errorOccurred)
  194465. return false;
  194466. juce_internalMessageQueue->postMessage ((Message*) message);
  194467. return true;
  194468. }
  194469. void MessageManager::broadcastMessage (const String& value) throw()
  194470. {
  194471. }
  194472. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194473. void* parameter)
  194474. {
  194475. if (errorOccurred)
  194476. return 0;
  194477. if (! isThisTheMessageThread())
  194478. {
  194479. MessageThreadFuncCall messageCallContext;
  194480. messageCallContext.func = func;
  194481. messageCallContext.parameter = parameter;
  194482. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194483. 0, 0, &messageCallContext));
  194484. // Wait for it to complete before continuing
  194485. messageCallContext.event.wait();
  194486. return messageCallContext.result;
  194487. }
  194488. else
  194489. {
  194490. // Just call the function directly
  194491. return func (parameter);
  194492. }
  194493. }
  194494. // Wait for an event (either XEvent, or an internal Message)
  194495. static bool juce_sleepUntilEvent (const int timeoutMs)
  194496. {
  194497. if (! juce_internalMessageQueue->isEmpty())
  194498. return true;
  194499. if (display != 0)
  194500. {
  194501. ScopedXLock xlock;
  194502. if (XPending (display))
  194503. return true;
  194504. }
  194505. struct timeval tv;
  194506. tv.tv_sec = 0;
  194507. tv.tv_usec = timeoutMs * 1000;
  194508. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194509. int fdmax = fd0;
  194510. fd_set readset;
  194511. FD_ZERO (&readset);
  194512. FD_SET (fd0, &readset);
  194513. if (display != 0)
  194514. {
  194515. ScopedXLock xlock;
  194516. int fd1 = XConnectionNumber (display);
  194517. FD_SET (fd1, &readset);
  194518. fdmax = jmax (fd0, fd1);
  194519. }
  194520. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194521. return (ret > 0); // ret <= 0 if error or timeout
  194522. }
  194523. // Handle next XEvent (if any)
  194524. static bool juce_dispatchNextXEvent()
  194525. {
  194526. if (display == 0)
  194527. return false;
  194528. XEvent evt;
  194529. {
  194530. ScopedXLock xlock;
  194531. if (! XPending (display))
  194532. return false;
  194533. XNextEvent (display, &evt);
  194534. }
  194535. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194536. {
  194537. juce_handleSelectionRequest (evt.xselectionrequest);
  194538. }
  194539. else if (evt.xany.window != juce_messageWindowHandle)
  194540. {
  194541. juce_windowMessageReceive (&evt);
  194542. }
  194543. return true;
  194544. }
  194545. // Handle next internal Message (if any)
  194546. static bool juce_dispatchNextInternalMessage()
  194547. {
  194548. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194549. if (msg == 0)
  194550. return false;
  194551. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194552. {
  194553. // Handle callback message
  194554. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194555. call->result = (*(call->func)) (call->parameter);
  194556. call->event.signal();
  194557. }
  194558. else
  194559. {
  194560. // Handle "normal" messages
  194561. MessageManager::getInstance()->deliverMessage (msg.release());
  194562. }
  194563. return true;
  194564. }
  194565. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194566. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194567. {
  194568. for (;;)
  194569. {
  194570. if (errorOccurred)
  194571. break;
  194572. if (keyboardBreakOccurred)
  194573. {
  194574. errorOccurred = true;
  194575. if (JUCEApplication::getInstance() != 0)
  194576. Process::terminate();
  194577. break;
  194578. }
  194579. static int totalEventCount = 0;
  194580. ++totalEventCount;
  194581. // The purpose here is to give either priority to XEvents or
  194582. // to internal messages This is necessary to keep a "good"
  194583. // behaviour when the cpu is overloaded
  194584. if (totalEventCount & 1)
  194585. {
  194586. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194587. return true;
  194588. }
  194589. else
  194590. {
  194591. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194592. return true;
  194593. }
  194594. if (returnIfNoPendingMessages) // early exit
  194595. break;
  194596. // the timeout is to be on the safe side, but it does not seem to be useful
  194597. juce_sleepUntilEvent (2000);
  194598. }
  194599. return false;
  194600. }
  194601. #endif
  194602. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194603. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194604. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194605. // compiled on its own).
  194606. #if JUCE_INCLUDED_FILE
  194607. class FreeTypeFontFace
  194608. {
  194609. public:
  194610. enum FontStyle
  194611. {
  194612. Plain = 0,
  194613. Bold = 1,
  194614. Italic = 2
  194615. };
  194616. struct FontNameIndex
  194617. {
  194618. String fileName;
  194619. int faceIndex;
  194620. };
  194621. FreeTypeFontFace (const String& familyName)
  194622. : hasSerif (false),
  194623. monospaced (false)
  194624. {
  194625. family = familyName;
  194626. }
  194627. void setFileName (const String& name, const int faceIndex, FontStyle style)
  194628. {
  194629. if (names [(int) style].fileName.isEmpty())
  194630. {
  194631. names [(int) style].fileName = name;
  194632. names [(int) style].faceIndex = faceIndex;
  194633. }
  194634. }
  194635. const String& getFamilyName() const throw() { return family; }
  194636. const String& getFileName (const int style, int& faceIndex) const throw()
  194637. {
  194638. faceIndex = names[style].faceIndex;
  194639. return names[style].fileName;
  194640. }
  194641. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194642. bool getMonospaced() const throw() { return monospaced; }
  194643. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194644. bool getSerif() const throw() { return hasSerif; }
  194645. private:
  194646. String family;
  194647. FontNameIndex names[4];
  194648. bool hasSerif, monospaced;
  194649. };
  194650. class FreeTypeInterface : public DeletedAtShutdown
  194651. {
  194652. public:
  194653. FreeTypeInterface()
  194654. : ftLib (0),
  194655. lastFace (0),
  194656. lastBold (false),
  194657. lastItalic (false)
  194658. {
  194659. if (FT_Init_FreeType (&ftLib) != 0)
  194660. {
  194661. ftLib = 0;
  194662. DBG ("Failed to initialize FreeType");
  194663. }
  194664. StringArray fontDirs;
  194665. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194666. fontDirs.removeEmptyStrings (true);
  194667. if (fontDirs.size() == 0)
  194668. {
  194669. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194670. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194671. if (fontsInfo != 0)
  194672. {
  194673. forEachXmlChildElementWithTagName (*fontsInfo, e, "dir")
  194674. {
  194675. fontDirs.add (e->getAllSubText().trim());
  194676. }
  194677. delete fontsInfo;
  194678. }
  194679. }
  194680. if (fontDirs.size() == 0)
  194681. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194682. for (int i = 0; i < fontDirs.size(); ++i)
  194683. enumerateFaces (fontDirs[i]);
  194684. }
  194685. ~FreeTypeInterface()
  194686. {
  194687. if (lastFace != 0)
  194688. FT_Done_Face (lastFace);
  194689. if (ftLib != 0)
  194690. FT_Done_FreeType (ftLib);
  194691. clearSingletonInstance();
  194692. }
  194693. FreeTypeFontFace* findOrCreate (const String& familyName, const bool create = false)
  194694. {
  194695. for (int i = 0; i < faces.size(); i++)
  194696. if (faces[i]->getFamilyName() == familyName)
  194697. return faces[i];
  194698. if (! create)
  194699. return NULL;
  194700. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194701. faces.add (newFace);
  194702. return newFace;
  194703. }
  194704. // Enumerate all font faces available in a given directory
  194705. void enumerateFaces (const String& path)
  194706. {
  194707. File dirPath (path);
  194708. if (path.isEmpty() || ! dirPath.isDirectory())
  194709. return;
  194710. DirectoryIterator di (dirPath, true);
  194711. while (di.next())
  194712. {
  194713. File possible (di.getFile());
  194714. if (possible.hasFileExtension ("ttf")
  194715. || possible.hasFileExtension ("pfb")
  194716. || possible.hasFileExtension ("pcf"))
  194717. {
  194718. FT_Face face;
  194719. int faceIndex = 0;
  194720. int numFaces = 0;
  194721. do
  194722. {
  194723. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194724. faceIndex, &face) == 0)
  194725. {
  194726. if (faceIndex == 0)
  194727. numFaces = face->num_faces;
  194728. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194729. {
  194730. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194731. int style = (int) FreeTypeFontFace::Plain;
  194732. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194733. style |= (int) FreeTypeFontFace::Bold;
  194734. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194735. style |= (int) FreeTypeFontFace::Italic;
  194736. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194737. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194738. // Surely there must be a better way to do this?
  194739. const String name (face->family_name);
  194740. newFace->setSerif (! (name.containsIgnoreCase ("Sans")
  194741. || name.containsIgnoreCase ("Verdana")
  194742. || name.containsIgnoreCase ("Arial")));
  194743. }
  194744. FT_Done_Face (face);
  194745. }
  194746. ++faceIndex;
  194747. }
  194748. while (faceIndex < numFaces);
  194749. }
  194750. }
  194751. }
  194752. // Create a FreeType face object for a given font
  194753. FT_Face createFT_Face (const String& fontName, const bool bold, const bool italic)
  194754. {
  194755. FT_Face face = 0;
  194756. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194757. {
  194758. face = lastFace;
  194759. }
  194760. else
  194761. {
  194762. if (lastFace != 0)
  194763. {
  194764. FT_Done_Face (lastFace);
  194765. lastFace = 0;
  194766. }
  194767. lastFontName = fontName;
  194768. lastBold = bold;
  194769. lastItalic = italic;
  194770. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194771. if (ftFace != 0)
  194772. {
  194773. int style = (int) FreeTypeFontFace::Plain;
  194774. if (bold)
  194775. style |= (int) FreeTypeFontFace::Bold;
  194776. if (italic)
  194777. style |= (int) FreeTypeFontFace::Italic;
  194778. int faceIndex;
  194779. String fileName (ftFace->getFileName (style, faceIndex));
  194780. if (fileName.isEmpty())
  194781. {
  194782. style ^= (int) FreeTypeFontFace::Bold;
  194783. fileName = ftFace->getFileName (style, faceIndex);
  194784. if (fileName.isEmpty())
  194785. {
  194786. style ^= (int) FreeTypeFontFace::Bold;
  194787. style ^= (int) FreeTypeFontFace::Italic;
  194788. fileName = ftFace->getFileName (style, faceIndex);
  194789. if (! fileName.length())
  194790. {
  194791. style ^= (int) FreeTypeFontFace::Bold;
  194792. fileName = ftFace->getFileName (style, faceIndex);
  194793. }
  194794. }
  194795. }
  194796. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194797. {
  194798. face = lastFace;
  194799. // If there isn't a unicode charmap then select the first one.
  194800. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194801. FT_Set_Charmap (face, face->charmaps[0]);
  194802. }
  194803. }
  194804. }
  194805. return face;
  194806. }
  194807. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character)
  194808. {
  194809. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194810. const float height = (float) (face->ascender - face->descender);
  194811. const float scaleX = 1.0f / height;
  194812. const float scaleY = -1.0f / height;
  194813. Path destShape;
  194814. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194815. || face->glyph->format != ft_glyph_format_outline)
  194816. {
  194817. return false;
  194818. }
  194819. const FT_Outline* const outline = &face->glyph->outline;
  194820. const short* const contours = outline->contours;
  194821. const char* const tags = outline->tags;
  194822. FT_Vector* const points = outline->points;
  194823. for (int c = 0; c < outline->n_contours; c++)
  194824. {
  194825. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194826. const int endPoint = contours[c];
  194827. for (int p = startPoint; p <= endPoint; p++)
  194828. {
  194829. const float x = scaleX * points[p].x;
  194830. const float y = scaleY * points[p].y;
  194831. if (p == startPoint)
  194832. {
  194833. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194834. {
  194835. float x2 = scaleX * points [endPoint].x;
  194836. float y2 = scaleY * points [endPoint].y;
  194837. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194838. {
  194839. x2 = (x + x2) * 0.5f;
  194840. y2 = (y + y2) * 0.5f;
  194841. }
  194842. destShape.startNewSubPath (x2, y2);
  194843. }
  194844. else
  194845. {
  194846. destShape.startNewSubPath (x, y);
  194847. }
  194848. }
  194849. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194850. {
  194851. if (p != startPoint)
  194852. destShape.lineTo (x, y);
  194853. }
  194854. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194855. {
  194856. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194857. float x2 = scaleX * points [nextIndex].x;
  194858. float y2 = scaleY * points [nextIndex].y;
  194859. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194860. {
  194861. x2 = (x + x2) * 0.5f;
  194862. y2 = (y + y2) * 0.5f;
  194863. }
  194864. else
  194865. {
  194866. ++p;
  194867. }
  194868. destShape.quadraticTo (x, y, x2, y2);
  194869. }
  194870. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194871. {
  194872. if (p >= endPoint)
  194873. return false;
  194874. const int next1 = p + 1;
  194875. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194876. const float x2 = scaleX * points [next1].x;
  194877. const float y2 = scaleY * points [next1].y;
  194878. const float x3 = scaleX * points [next2].x;
  194879. const float y3 = scaleY * points [next2].y;
  194880. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194881. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194882. return false;
  194883. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194884. p += 2;
  194885. }
  194886. }
  194887. destShape.closeSubPath();
  194888. }
  194889. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194890. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194891. addKerning (face, dest, character, glyphIndex);
  194892. return true;
  194893. }
  194894. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex)
  194895. {
  194896. const float height = (float) (face->ascender - face->descender);
  194897. uint32 rightGlyphIndex;
  194898. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  194899. while (rightGlyphIndex != 0)
  194900. {
  194901. FT_Vector kerning;
  194902. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  194903. {
  194904. if (kerning.x != 0)
  194905. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  194906. }
  194907. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  194908. }
  194909. }
  194910. // Add a glyph to a font
  194911. bool addGlyphToFont (const uint32 character, const String& fontName,
  194912. bool bold, bool italic, CustomTypeface& dest)
  194913. {
  194914. FT_Face face = createFT_Face (fontName, bold, italic);
  194915. return face != 0 && addGlyph (face, dest, character);
  194916. }
  194917. void getFamilyNames (StringArray& familyNames) const
  194918. {
  194919. for (int i = 0; i < faces.size(); i++)
  194920. familyNames.add (faces[i]->getFamilyName());
  194921. }
  194922. void getMonospacedNames (StringArray& monoSpaced) const
  194923. {
  194924. for (int i = 0; i < faces.size(); i++)
  194925. if (faces[i]->getMonospaced())
  194926. monoSpaced.add (faces[i]->getFamilyName());
  194927. }
  194928. void getSerifNames (StringArray& serif) const
  194929. {
  194930. for (int i = 0; i < faces.size(); i++)
  194931. if (faces[i]->getSerif())
  194932. serif.add (faces[i]->getFamilyName());
  194933. }
  194934. void getSansSerifNames (StringArray& sansSerif) const
  194935. {
  194936. for (int i = 0; i < faces.size(); i++)
  194937. if (! faces[i]->getSerif())
  194938. sansSerif.add (faces[i]->getFamilyName());
  194939. }
  194940. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  194941. private:
  194942. FT_Library ftLib;
  194943. FT_Face lastFace;
  194944. String lastFontName;
  194945. bool lastBold, lastItalic;
  194946. OwnedArray<FreeTypeFontFace> faces;
  194947. };
  194948. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  194949. class FreetypeTypeface : public CustomTypeface
  194950. {
  194951. public:
  194952. FreetypeTypeface (const Font& font)
  194953. {
  194954. FT_Face face = FreeTypeInterface::getInstance()
  194955. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  194956. if (face == 0)
  194957. {
  194958. #ifdef JUCE_DEBUG
  194959. String msg ("Failed to create typeface: ");
  194960. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  194961. DBG (msg);
  194962. #endif
  194963. }
  194964. else
  194965. {
  194966. setCharacteristics (font.getTypefaceName(),
  194967. face->ascender / (float) (face->ascender - face->descender),
  194968. font.isBold(), font.isItalic(),
  194969. L' ');
  194970. }
  194971. }
  194972. bool loadGlyphIfPossible (juce_wchar character)
  194973. {
  194974. return FreeTypeInterface::getInstance()
  194975. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  194976. }
  194977. };
  194978. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  194979. {
  194980. return new FreetypeTypeface (font);
  194981. }
  194982. const StringArray Font::findAllTypefaceNames()
  194983. {
  194984. StringArray s;
  194985. FreeTypeInterface::getInstance()->getFamilyNames (s);
  194986. s.sort (true);
  194987. return s;
  194988. }
  194989. static const String pickBestFont (const StringArray& names,
  194990. const char* const choicesString)
  194991. {
  194992. StringArray choices;
  194993. choices.addTokens (String (choicesString), ",", String::empty);
  194994. choices.trim();
  194995. choices.removeEmptyStrings();
  194996. int i, j;
  194997. for (j = 0; j < choices.size(); ++j)
  194998. if (names.contains (choices[j], true))
  194999. return choices[j];
  195000. for (j = 0; j < choices.size(); ++j)
  195001. for (i = 0; i < names.size(); i++)
  195002. if (names[i].startsWithIgnoreCase (choices[j]))
  195003. return names[i];
  195004. for (j = 0; j < choices.size(); ++j)
  195005. for (i = 0; i < names.size(); i++)
  195006. if (names[i].containsIgnoreCase (choices[j]))
  195007. return names[i];
  195008. return names[0];
  195009. }
  195010. static const String linux_getDefaultSansSerifFontName()
  195011. {
  195012. StringArray allFonts;
  195013. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195014. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195015. }
  195016. static const String linux_getDefaultSerifFontName()
  195017. {
  195018. StringArray allFonts;
  195019. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195020. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195021. }
  195022. static const String linux_getDefaultMonospacedFontName()
  195023. {
  195024. StringArray allFonts;
  195025. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195026. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195027. }
  195028. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  195029. {
  195030. defaultSans = linux_getDefaultSansSerifFontName();
  195031. defaultSerif = linux_getDefaultSerifFontName();
  195032. defaultFixed = linux_getDefaultMonospacedFontName();
  195033. }
  195034. #endif
  195035. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195036. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195037. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195038. // compiled on its own).
  195039. #if JUCE_INCLUDED_FILE
  195040. // These are defined in juce_linux_Messaging.cpp
  195041. extern Display* display;
  195042. extern XContext improbableNumber;
  195043. namespace Atoms
  195044. {
  195045. enum ProtocolItems
  195046. {
  195047. TAKE_FOCUS = 0,
  195048. DELETE_WINDOW = 1,
  195049. PING = 2
  195050. };
  195051. static Atom Protocols, ProtocolList[3], ChangeState, State,
  195052. ActiveWin, Pid, WindowType, WindowState,
  195053. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  195054. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  195055. XdndActionDescription, XdndActionCopy,
  195056. allowedActions[5],
  195057. allowedMimeTypes[2];
  195058. const unsigned long DndVersion = 3;
  195059. static void initialiseAtoms()
  195060. {
  195061. static bool atomsInitialised = false;
  195062. if (! atomsInitialised)
  195063. {
  195064. atomsInitialised = true;
  195065. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  195066. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  195067. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  195068. ProtocolList [PING] = XInternAtom (display, "_NET_WM_PING", True);
  195069. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  195070. State = XInternAtom (display, "WM_STATE", True);
  195071. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  195072. Pid = XInternAtom (display, "_NET_WM_PID", False);
  195073. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  195074. WindowState = XInternAtom (display, "_NET_WM_STATE", True);
  195075. XdndAware = XInternAtom (display, "XdndAware", False);
  195076. XdndEnter = XInternAtom (display, "XdndEnter", False);
  195077. XdndLeave = XInternAtom (display, "XdndLeave", False);
  195078. XdndPosition = XInternAtom (display, "XdndPosition", False);
  195079. XdndStatus = XInternAtom (display, "XdndStatus", False);
  195080. XdndDrop = XInternAtom (display, "XdndDrop", False);
  195081. XdndFinished = XInternAtom (display, "XdndFinished", False);
  195082. XdndSelection = XInternAtom (display, "XdndSelection", False);
  195083. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  195084. XdndActionList = XInternAtom (display, "XdndActionList", False);
  195085. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  195086. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195087. allowedMimeTypes[0] = XInternAtom (display, "text/plain", False);
  195088. allowedMimeTypes[1] = XInternAtom (display, "text/uri-list", False);
  195089. allowedActions[0] = XInternAtom (display, "XdndActionMove", False);
  195090. allowedActions[1] = XdndActionCopy;
  195091. allowedActions[2] = XInternAtom (display, "XdndActionLink", False);
  195092. allowedActions[3] = XInternAtom (display, "XdndActionAsk", False);
  195093. allowedActions[4] = XInternAtom (display, "XdndActionPrivate", False);
  195094. }
  195095. }
  195096. }
  195097. namespace Keys
  195098. {
  195099. enum MouseButtons
  195100. {
  195101. NoButton = 0,
  195102. LeftButton = 1,
  195103. MiddleButton = 2,
  195104. RightButton = 3,
  195105. WheelUp = 4,
  195106. WheelDown = 5
  195107. };
  195108. static int AltMask = 0;
  195109. static int NumLockMask = 0;
  195110. static bool numLock = false;
  195111. static bool capsLock = false;
  195112. static char keyStates [32];
  195113. static const int extendedKeyModifier = 0x10000000;
  195114. }
  195115. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  195116. {
  195117. int keysym;
  195118. if (keyCode & Keys::extendedKeyModifier)
  195119. {
  195120. keysym = 0xff00 | (keyCode & 0xff);
  195121. }
  195122. else
  195123. {
  195124. keysym = keyCode;
  195125. if (keysym == (XK_Tab & 0xff)
  195126. || keysym == (XK_Return & 0xff)
  195127. || keysym == (XK_Escape & 0xff)
  195128. || keysym == (XK_BackSpace & 0xff))
  195129. {
  195130. keysym |= 0xff00;
  195131. }
  195132. }
  195133. ScopedXLock xlock;
  195134. const int keycode = XKeysymToKeycode (display, keysym);
  195135. const int keybyte = keycode >> 3;
  195136. const int keybit = (1 << (keycode & 7));
  195137. return (Keys::keyStates [keybyte] & keybit) != 0;
  195138. }
  195139. #if JUCE_USE_XSHM
  195140. namespace XSHMHelpers
  195141. {
  195142. static int trappedErrorCode = 0;
  195143. extern "C" int errorTrapHandler (Display*, XErrorEvent* err)
  195144. {
  195145. trappedErrorCode = err->error_code;
  195146. return 0;
  195147. }
  195148. static bool isShmAvailable() throw()
  195149. {
  195150. static bool isChecked = false;
  195151. static bool isAvailable = false;
  195152. if (! isChecked)
  195153. {
  195154. isChecked = true;
  195155. int major, minor;
  195156. Bool pixmaps;
  195157. ScopedXLock xlock;
  195158. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195159. {
  195160. trappedErrorCode = 0;
  195161. XErrorHandler oldHandler = XSetErrorHandler (errorTrapHandler);
  195162. XShmSegmentInfo segmentInfo;
  195163. zerostruct (segmentInfo);
  195164. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195165. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195166. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195167. xImage->bytes_per_line * xImage->height,
  195168. IPC_CREAT | 0777)) >= 0)
  195169. {
  195170. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195171. if (segmentInfo.shmaddr != (void*) -1)
  195172. {
  195173. segmentInfo.readOnly = False;
  195174. xImage->data = segmentInfo.shmaddr;
  195175. XSync (display, False);
  195176. if (XShmAttach (display, &segmentInfo) != 0)
  195177. {
  195178. XSync (display, False);
  195179. XShmDetach (display, &segmentInfo);
  195180. isAvailable = true;
  195181. }
  195182. }
  195183. XFlush (display);
  195184. XDestroyImage (xImage);
  195185. shmdt (segmentInfo.shmaddr);
  195186. }
  195187. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195188. XSetErrorHandler (oldHandler);
  195189. if (trappedErrorCode != 0)
  195190. isAvailable = false;
  195191. }
  195192. }
  195193. return isAvailable;
  195194. }
  195195. }
  195196. #endif
  195197. #if JUCE_USE_XRENDER
  195198. namespace XRender
  195199. {
  195200. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195201. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195202. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195203. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195204. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195205. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195206. static tXRenderFindFormat xRenderFindFormat = 0;
  195207. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195208. static bool isAvailable()
  195209. {
  195210. static bool hasLoaded = false;
  195211. if (! hasLoaded)
  195212. {
  195213. ScopedXLock xlock;
  195214. hasLoaded = true;
  195215. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195216. if (h != 0)
  195217. {
  195218. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195219. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195220. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195221. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195222. }
  195223. if (xRenderQueryVersion != 0
  195224. && xRenderFindStandardFormat != 0
  195225. && xRenderFindFormat != 0
  195226. && xRenderFindVisualFormat != 0)
  195227. {
  195228. int major, minor;
  195229. if (xRenderQueryVersion (display, &major, &minor))
  195230. return true;
  195231. }
  195232. xRenderQueryVersion = 0;
  195233. }
  195234. return xRenderQueryVersion != 0;
  195235. }
  195236. static XRenderPictFormat* findPictureFormat()
  195237. {
  195238. ScopedXLock xlock;
  195239. XRenderPictFormat* pictFormat = 0;
  195240. if (isAvailable())
  195241. {
  195242. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195243. if (pictFormat == 0)
  195244. {
  195245. XRenderPictFormat desiredFormat;
  195246. desiredFormat.type = PictTypeDirect;
  195247. desiredFormat.depth = 32;
  195248. desiredFormat.direct.alphaMask = 0xff;
  195249. desiredFormat.direct.redMask = 0xff;
  195250. desiredFormat.direct.greenMask = 0xff;
  195251. desiredFormat.direct.blueMask = 0xff;
  195252. desiredFormat.direct.alpha = 24;
  195253. desiredFormat.direct.red = 16;
  195254. desiredFormat.direct.green = 8;
  195255. desiredFormat.direct.blue = 0;
  195256. pictFormat = xRenderFindFormat (display,
  195257. PictFormatType | PictFormatDepth
  195258. | PictFormatRedMask | PictFormatRed
  195259. | PictFormatGreenMask | PictFormatGreen
  195260. | PictFormatBlueMask | PictFormatBlue
  195261. | PictFormatAlphaMask | PictFormatAlpha,
  195262. &desiredFormat,
  195263. 0);
  195264. }
  195265. }
  195266. return pictFormat;
  195267. }
  195268. }
  195269. #endif
  195270. namespace Visuals
  195271. {
  195272. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195273. {
  195274. ScopedXLock xlock;
  195275. Visual* visual = 0;
  195276. int numVisuals = 0;
  195277. long desiredMask = VisualNoMask;
  195278. XVisualInfo desiredVisual;
  195279. desiredVisual.screen = DefaultScreen (display);
  195280. desiredVisual.depth = desiredDepth;
  195281. desiredMask = VisualScreenMask | VisualDepthMask;
  195282. if (desiredDepth == 32)
  195283. {
  195284. desiredVisual.c_class = TrueColor;
  195285. desiredVisual.red_mask = 0x00FF0000;
  195286. desiredVisual.green_mask = 0x0000FF00;
  195287. desiredVisual.blue_mask = 0x000000FF;
  195288. desiredVisual.bits_per_rgb = 8;
  195289. desiredMask |= VisualClassMask;
  195290. desiredMask |= VisualRedMaskMask;
  195291. desiredMask |= VisualGreenMaskMask;
  195292. desiredMask |= VisualBlueMaskMask;
  195293. desiredMask |= VisualBitsPerRGBMask;
  195294. }
  195295. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195296. desiredMask,
  195297. &desiredVisual,
  195298. &numVisuals);
  195299. if (xvinfos != 0)
  195300. {
  195301. for (int i = 0; i < numVisuals; i++)
  195302. {
  195303. if (xvinfos[i].depth == desiredDepth)
  195304. {
  195305. visual = xvinfos[i].visual;
  195306. break;
  195307. }
  195308. }
  195309. XFree (xvinfos);
  195310. }
  195311. return visual;
  195312. }
  195313. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195314. {
  195315. Visual* visual = 0;
  195316. if (desiredDepth == 32)
  195317. {
  195318. #if JUCE_USE_XSHM
  195319. if (XSHMHelpers::isShmAvailable())
  195320. {
  195321. #if JUCE_USE_XRENDER
  195322. if (XRender::isAvailable())
  195323. {
  195324. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195325. if (pictFormat != 0)
  195326. {
  195327. int numVisuals = 0;
  195328. XVisualInfo desiredVisual;
  195329. desiredVisual.screen = DefaultScreen (display);
  195330. desiredVisual.depth = 32;
  195331. desiredVisual.bits_per_rgb = 8;
  195332. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195333. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195334. &desiredVisual, &numVisuals);
  195335. if (xvinfos != 0)
  195336. {
  195337. for (int i = 0; i < numVisuals; ++i)
  195338. {
  195339. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195340. if (pictVisualFormat != 0
  195341. && pictVisualFormat->type == PictTypeDirect
  195342. && pictVisualFormat->direct.alphaMask)
  195343. {
  195344. visual = xvinfos[i].visual;
  195345. matchedDepth = 32;
  195346. break;
  195347. }
  195348. }
  195349. XFree (xvinfos);
  195350. }
  195351. }
  195352. }
  195353. #endif
  195354. if (visual == 0)
  195355. {
  195356. visual = findVisualWithDepth (32);
  195357. if (visual != 0)
  195358. matchedDepth = 32;
  195359. }
  195360. }
  195361. #endif
  195362. }
  195363. if (visual == 0 && desiredDepth >= 24)
  195364. {
  195365. visual = findVisualWithDepth (24);
  195366. if (visual != 0)
  195367. matchedDepth = 24;
  195368. }
  195369. if (visual == 0 && desiredDepth >= 16)
  195370. {
  195371. visual = findVisualWithDepth (16);
  195372. if (visual != 0)
  195373. matchedDepth = 16;
  195374. }
  195375. return visual;
  195376. }
  195377. }
  195378. class XBitmapImage : public Image
  195379. {
  195380. public:
  195381. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195382. const bool clearImage, const int imageDepth_, Visual* visual)
  195383. : Image (format_, w, h),
  195384. imageDepth (imageDepth_),
  195385. gc (None)
  195386. {
  195387. jassert (format_ == RGB || format_ == ARGB);
  195388. pixelStride = (format_ == RGB) ? 3 : 4;
  195389. lineStride = ((w * pixelStride + 3) & ~3);
  195390. ScopedXLock xlock;
  195391. #if JUCE_USE_XSHM
  195392. usingXShm = false;
  195393. if ((imageDepth > 16) && XSHMHelpers::isShmAvailable())
  195394. {
  195395. zerostruct (segmentInfo);
  195396. segmentInfo.shmid = -1;
  195397. segmentInfo.shmaddr = (char *) -1;
  195398. segmentInfo.readOnly = False;
  195399. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195400. if (xImage != 0)
  195401. {
  195402. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195403. xImage->bytes_per_line * xImage->height,
  195404. IPC_CREAT | 0777)) >= 0)
  195405. {
  195406. if (segmentInfo.shmid != -1)
  195407. {
  195408. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195409. if (segmentInfo.shmaddr != (void*) -1)
  195410. {
  195411. segmentInfo.readOnly = False;
  195412. xImage->data = segmentInfo.shmaddr;
  195413. imageData = (uint8*) segmentInfo.shmaddr;
  195414. if (XShmAttach (display, &segmentInfo) != 0)
  195415. {
  195416. usingXShm = true;
  195417. }
  195418. else
  195419. {
  195420. jassertfalse
  195421. }
  195422. }
  195423. else
  195424. {
  195425. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195426. }
  195427. }
  195428. }
  195429. }
  195430. }
  195431. if (! usingXShm)
  195432. #endif
  195433. {
  195434. imageDataAllocated.malloc (lineStride * h);
  195435. imageData = imageDataAllocated;
  195436. if (format_ == ARGB && clearImage)
  195437. zeromem (imageData, h * lineStride);
  195438. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195439. xImage->width = w;
  195440. xImage->height = h;
  195441. xImage->xoffset = 0;
  195442. xImage->format = ZPixmap;
  195443. xImage->data = (char*) imageData;
  195444. xImage->byte_order = ImageByteOrder (display);
  195445. xImage->bitmap_unit = BitmapUnit (display);
  195446. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195447. xImage->bitmap_pad = 32;
  195448. xImage->depth = pixelStride * 8;
  195449. xImage->bytes_per_line = lineStride;
  195450. xImage->bits_per_pixel = pixelStride * 8;
  195451. xImage->red_mask = 0x00FF0000;
  195452. xImage->green_mask = 0x0000FF00;
  195453. xImage->blue_mask = 0x000000FF;
  195454. if (imageDepth == 16)
  195455. {
  195456. const int pixelStride = 2;
  195457. const int lineStride = ((w * pixelStride + 3) & ~3);
  195458. imageData16Bit.malloc (lineStride * h);
  195459. xImage->data = imageData16Bit;
  195460. xImage->bitmap_pad = 16;
  195461. xImage->depth = pixelStride * 8;
  195462. xImage->bytes_per_line = lineStride;
  195463. xImage->bits_per_pixel = pixelStride * 8;
  195464. xImage->red_mask = visual->red_mask;
  195465. xImage->green_mask = visual->green_mask;
  195466. xImage->blue_mask = visual->blue_mask;
  195467. }
  195468. if (! XInitImage (xImage))
  195469. {
  195470. jassertfalse
  195471. }
  195472. }
  195473. }
  195474. ~XBitmapImage()
  195475. {
  195476. ScopedXLock xlock;
  195477. if (gc != None)
  195478. XFreeGC (display, gc);
  195479. #if JUCE_USE_XSHM
  195480. if (usingXShm)
  195481. {
  195482. XShmDetach (display, &segmentInfo);
  195483. XFlush (display);
  195484. XDestroyImage (xImage);
  195485. shmdt (segmentInfo.shmaddr);
  195486. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195487. }
  195488. else
  195489. #endif
  195490. {
  195491. xImage->data = 0;
  195492. XDestroyImage (xImage);
  195493. }
  195494. }
  195495. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195496. {
  195497. ScopedXLock xlock;
  195498. if (gc == None)
  195499. {
  195500. XGCValues gcvalues;
  195501. gcvalues.foreground = None;
  195502. gcvalues.background = None;
  195503. gcvalues.function = GXcopy;
  195504. gcvalues.plane_mask = AllPlanes;
  195505. gcvalues.clip_mask = None;
  195506. gcvalues.graphics_exposures = False;
  195507. gc = XCreateGC (display, window,
  195508. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195509. &gcvalues);
  195510. }
  195511. if (imageDepth == 16)
  195512. {
  195513. const uint32 rMask = xImage->red_mask;
  195514. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195515. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195516. const uint32 gMask = xImage->green_mask;
  195517. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195518. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195519. const uint32 bMask = xImage->blue_mask;
  195520. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195521. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195522. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195523. for (int y = sy; y < sy + dh; ++y)
  195524. {
  195525. const uint8* p = srcData.getPixelPointer (sx, y);
  195526. for (int x = sx; x < sx + dw; ++x)
  195527. {
  195528. const PixelRGB* const pixel = (const PixelRGB*) p;
  195529. p += srcData.pixelStride;
  195530. XPutPixel (xImage, x, y,
  195531. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195532. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195533. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195534. }
  195535. }
  195536. }
  195537. // blit results to screen.
  195538. #if JUCE_USE_XSHM
  195539. if (usingXShm)
  195540. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195541. else
  195542. #endif
  195543. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195544. }
  195545. juce_UseDebuggingNewOperator
  195546. private:
  195547. XImage* xImage;
  195548. const int imageDepth;
  195549. HeapBlock <char> imageData16Bit;
  195550. GC gc;
  195551. #if JUCE_USE_XSHM
  195552. XShmSegmentInfo segmentInfo;
  195553. bool usingXShm;
  195554. #endif
  195555. static int getShiftNeeded (const uint32 mask) throw()
  195556. {
  195557. for (int i = 32; --i >= 0;)
  195558. if (((mask >> i) & 1) != 0)
  195559. return i - 7;
  195560. jassertfalse
  195561. return 0;
  195562. }
  195563. };
  195564. class LinuxComponentPeer : public ComponentPeer
  195565. {
  195566. public:
  195567. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195568. : ComponentPeer (component, windowStyleFlags),
  195569. windowH (0),
  195570. parentWindow (0),
  195571. wx (0),
  195572. wy (0),
  195573. ww (0),
  195574. wh (0),
  195575. fullScreen (false),
  195576. mapped (false),
  195577. visual (0),
  195578. depth (0)
  195579. {
  195580. // it's dangerous to create a window on a thread other than the message thread..
  195581. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195582. repainter = new LinuxRepaintManager (this);
  195583. createWindow();
  195584. setTitle (component->getName());
  195585. }
  195586. ~LinuxComponentPeer()
  195587. {
  195588. // it's dangerous to delete a window on a thread other than the message thread..
  195589. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195590. deleteIconPixmaps();
  195591. destroyWindow();
  195592. windowH = 0;
  195593. }
  195594. void* getNativeHandle() const
  195595. {
  195596. return (void*) windowH;
  195597. }
  195598. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195599. {
  195600. XPointer peer = 0;
  195601. ScopedXLock xlock;
  195602. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195603. {
  195604. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195605. peer = 0;
  195606. }
  195607. return (LinuxComponentPeer*) peer;
  195608. }
  195609. void setVisible (bool shouldBeVisible)
  195610. {
  195611. ScopedXLock xlock;
  195612. if (shouldBeVisible)
  195613. XMapWindow (display, windowH);
  195614. else
  195615. XUnmapWindow (display, windowH);
  195616. }
  195617. void setTitle (const String& title)
  195618. {
  195619. setWindowTitle (windowH, title);
  195620. }
  195621. void setPosition (int x, int y)
  195622. {
  195623. setBounds (x, y, ww, wh, false);
  195624. }
  195625. void setSize (int w, int h)
  195626. {
  195627. setBounds (wx, wy, w, h, false);
  195628. }
  195629. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  195630. {
  195631. fullScreen = isNowFullScreen;
  195632. if (windowH != 0)
  195633. {
  195634. Component::SafePointer<Component> deletionChecker (component);
  195635. wx = x;
  195636. wy = y;
  195637. ww = jmax (1, w);
  195638. wh = jmax (1, h);
  195639. ScopedXLock xlock;
  195640. // Make sure the Window manager does what we want
  195641. XSizeHints* hints = XAllocSizeHints();
  195642. hints->flags = USSize | USPosition;
  195643. hints->width = ww;
  195644. hints->height = wh;
  195645. hints->x = wx;
  195646. hints->y = wy;
  195647. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195648. {
  195649. hints->min_width = hints->max_width = hints->width;
  195650. hints->min_height = hints->max_height = hints->height;
  195651. hints->flags |= PMinSize | PMaxSize;
  195652. }
  195653. XSetWMNormalHints (display, windowH, hints);
  195654. XFree (hints);
  195655. XMoveResizeWindow (display, windowH,
  195656. wx - windowBorder.getLeft(),
  195657. wy - windowBorder.getTop(), ww, wh);
  195658. if (deletionChecker != 0)
  195659. {
  195660. updateBorderSize();
  195661. handleMovedOrResized();
  195662. }
  195663. }
  195664. }
  195665. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195666. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195667. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195668. {
  195669. return relativePosition + getScreenPosition();
  195670. }
  195671. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195672. {
  195673. return screenPosition - getScreenPosition();
  195674. }
  195675. void setMinimised (bool shouldBeMinimised)
  195676. {
  195677. if (shouldBeMinimised)
  195678. {
  195679. Window root = RootWindow (display, DefaultScreen (display));
  195680. XClientMessageEvent clientMsg;
  195681. clientMsg.display = display;
  195682. clientMsg.window = windowH;
  195683. clientMsg.type = ClientMessage;
  195684. clientMsg.format = 32;
  195685. clientMsg.message_type = Atoms::ChangeState;
  195686. clientMsg.data.l[0] = IconicState;
  195687. ScopedXLock xlock;
  195688. XSendEvent (display, root, false,
  195689. SubstructureRedirectMask | SubstructureNotifyMask,
  195690. (XEvent*) &clientMsg);
  195691. }
  195692. else
  195693. {
  195694. setVisible (true);
  195695. }
  195696. }
  195697. bool isMinimised() const
  195698. {
  195699. bool minimised = false;
  195700. unsigned char* stateProp;
  195701. unsigned long nitems, bytesLeft;
  195702. Atom actualType;
  195703. int actualFormat;
  195704. ScopedXLock xlock;
  195705. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195706. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195707. &stateProp) == Success
  195708. && actualType == Atoms::State
  195709. && actualFormat == 32
  195710. && nitems > 0)
  195711. {
  195712. if (((unsigned long*) stateProp)[0] == IconicState)
  195713. minimised = true;
  195714. XFree (stateProp);
  195715. }
  195716. return minimised;
  195717. }
  195718. void setFullScreen (const bool shouldBeFullScreen)
  195719. {
  195720. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195721. setMinimised (false);
  195722. if (fullScreen != shouldBeFullScreen)
  195723. {
  195724. if (shouldBeFullScreen)
  195725. r = Desktop::getInstance().getMainMonitorArea();
  195726. if (! r.isEmpty())
  195727. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195728. getComponent()->repaint();
  195729. }
  195730. }
  195731. bool isFullScreen() const
  195732. {
  195733. return fullScreen;
  195734. }
  195735. bool isChildWindowOf (Window possibleParent) const
  195736. {
  195737. Window* windowList = 0;
  195738. uint32 windowListSize = 0;
  195739. Window parent, root;
  195740. ScopedXLock xlock;
  195741. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195742. {
  195743. if (windowList != 0)
  195744. XFree (windowList);
  195745. return parent == possibleParent;
  195746. }
  195747. return false;
  195748. }
  195749. bool isFrontWindow() const
  195750. {
  195751. Window* windowList = 0;
  195752. uint32 windowListSize = 0;
  195753. bool result = false;
  195754. ScopedXLock xlock;
  195755. Window parent, root = RootWindow (display, DefaultScreen (display));
  195756. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195757. {
  195758. for (int i = windowListSize; --i >= 0;)
  195759. {
  195760. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195761. if (peer != 0)
  195762. {
  195763. result = (peer == this);
  195764. break;
  195765. }
  195766. }
  195767. }
  195768. if (windowList != 0)
  195769. XFree (windowList);
  195770. return result;
  195771. }
  195772. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195773. {
  195774. int x = position.getX();
  195775. int y = position.getY();
  195776. if (((unsigned int) x) >= (unsigned int) ww
  195777. || ((unsigned int) y) >= (unsigned int) wh)
  195778. return false;
  195779. bool inFront = false;
  195780. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195781. {
  195782. Component* const c = Desktop::getInstance().getComponent (i);
  195783. if (inFront)
  195784. {
  195785. if (c->contains (x + wx - c->getScreenX(),
  195786. y + wy - c->getScreenY()))
  195787. {
  195788. return false;
  195789. }
  195790. }
  195791. else if (c == getComponent())
  195792. {
  195793. inFront = true;
  195794. }
  195795. }
  195796. if (trueIfInAChildWindow)
  195797. return true;
  195798. ::Window root, child;
  195799. unsigned int bw, depth;
  195800. int wx, wy, w, h;
  195801. ScopedXLock xlock;
  195802. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195803. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195804. &bw, &depth))
  195805. {
  195806. return false;
  195807. }
  195808. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195809. return false;
  195810. return child == None;
  195811. }
  195812. const BorderSize getFrameSize() const
  195813. {
  195814. return BorderSize();
  195815. }
  195816. bool setAlwaysOnTop (bool alwaysOnTop)
  195817. {
  195818. if (windowH != 0)
  195819. {
  195820. const bool wasVisible = component->isVisible();
  195821. if (wasVisible)
  195822. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195823. {
  195824. ScopedXLock xlock;
  195825. XSetWindowAttributes swa;
  195826. swa.override_redirect = alwaysOnTop ? True : False;
  195827. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195828. }
  195829. if (wasVisible)
  195830. setVisible (true);
  195831. }
  195832. return true;
  195833. }
  195834. void toFront (bool makeActive)
  195835. {
  195836. if (makeActive)
  195837. {
  195838. setVisible (true);
  195839. grabFocus();
  195840. }
  195841. XEvent ev;
  195842. ev.xclient.type = ClientMessage;
  195843. ev.xclient.serial = 0;
  195844. ev.xclient.send_event = True;
  195845. ev.xclient.message_type = Atoms::ActiveWin;
  195846. ev.xclient.window = windowH;
  195847. ev.xclient.format = 32;
  195848. ev.xclient.data.l[0] = 2;
  195849. ev.xclient.data.l[1] = CurrentTime;
  195850. ev.xclient.data.l[2] = 0;
  195851. ev.xclient.data.l[3] = 0;
  195852. ev.xclient.data.l[4] = 0;
  195853. {
  195854. ScopedXLock xlock;
  195855. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195856. False,
  195857. SubstructureRedirectMask | SubstructureNotifyMask,
  195858. &ev);
  195859. XWindowAttributes attr;
  195860. XGetWindowAttributes (display, windowH, &attr);
  195861. if (attr.override_redirect)
  195862. XRaiseWindow (display, windowH);
  195863. XSync (display, False);
  195864. }
  195865. handleBroughtToFront();
  195866. }
  195867. void toBehind (ComponentPeer* other)
  195868. {
  195869. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195870. jassert (otherPeer != 0); // wrong type of window?
  195871. if (otherPeer != 0)
  195872. {
  195873. setMinimised (false);
  195874. Window newStack[] = { otherPeer->windowH, windowH };
  195875. ScopedXLock xlock;
  195876. XRestackWindows (display, newStack, 2);
  195877. }
  195878. }
  195879. bool isFocused() const
  195880. {
  195881. int revert;
  195882. Window focusedWindow = 0;
  195883. ScopedXLock xlock;
  195884. XGetInputFocus (display, &focusedWindow, &revert);
  195885. return focusedWindow == windowH;
  195886. }
  195887. void grabFocus()
  195888. {
  195889. XWindowAttributes atts;
  195890. ScopedXLock xlock;
  195891. if (windowH != 0
  195892. && XGetWindowAttributes (display, windowH, &atts)
  195893. && atts.map_state == IsViewable
  195894. && ! isFocused())
  195895. {
  195896. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  195897. isActiveApplication = true;
  195898. }
  195899. }
  195900. void textInputRequired (const Point<int>&)
  195901. {
  195902. }
  195903. void repaint (int x, int y, int w, int h)
  195904. {
  195905. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  195906. 0, 0,
  195907. getComponent()->getWidth(),
  195908. getComponent()->getHeight()))
  195909. {
  195910. repainter->repaint (x, y, w, h);
  195911. }
  195912. }
  195913. void performAnyPendingRepaintsNow()
  195914. {
  195915. repainter->performAnyPendingRepaintsNow();
  195916. }
  195917. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195918. {
  195919. ScopedXLock xlock;
  195920. const int width = image.getWidth();
  195921. const int height = image.getHeight();
  195922. HeapBlock <char> colour (width * height);
  195923. int index = 0;
  195924. for (int y = 0; y < height; ++y)
  195925. for (int x = 0; x < width; ++x)
  195926. colour[index++] = static_cast<char> (image.getPixelAt (x, y).getARGB());
  195927. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195928. 0, colour.getData(),
  195929. width, height, 32, 0);
  195930. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195931. width, height, 24);
  195932. GC gc = XCreateGC (display, pixmap, 0, 0);
  195933. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195934. XFreeGC (display, gc);
  195935. return pixmap;
  195936. }
  195937. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195938. {
  195939. ScopedXLock xlock;
  195940. const int width = image.getWidth();
  195941. const int height = image.getHeight();
  195942. const int stride = (width + 7) >> 3;
  195943. HeapBlock <char> mask;
  195944. mask.calloc (stride * height);
  195945. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195946. for (int y = 0; y < height; ++y)
  195947. {
  195948. for (int x = 0; x < width; ++x)
  195949. {
  195950. const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195951. const int offset = y * stride + (x >> 3);
  195952. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195953. mask[offset] |= bit;
  195954. }
  195955. }
  195956. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195957. mask.getData(), width, height, 1, 0, 1);
  195958. }
  195959. void setIcon (const Image& newIcon)
  195960. {
  195961. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  195962. HeapBlock <unsigned long> data (dataSize);
  195963. int index = 0;
  195964. data[index++] = newIcon.getWidth();
  195965. data[index++] = newIcon.getHeight();
  195966. for (int y = 0; y < newIcon.getHeight(); ++y)
  195967. for (int x = 0; x < newIcon.getWidth(); ++x)
  195968. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  195969. ScopedXLock xlock;
  195970. XChangeProperty (display, windowH,
  195971. XInternAtom (display, "_NET_WM_ICON", False),
  195972. XA_CARDINAL, 32, PropModeReplace,
  195973. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  195974. deleteIconPixmaps();
  195975. XWMHints* wmHints = XGetWMHints (display, windowH);
  195976. if (wmHints == 0)
  195977. wmHints = XAllocWMHints();
  195978. wmHints->flags |= IconPixmapHint | IconMaskHint;
  195979. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  195980. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  195981. XSetWMHints (display, windowH, wmHints);
  195982. XFree (wmHints);
  195983. XSync (display, False);
  195984. }
  195985. void deleteIconPixmaps()
  195986. {
  195987. ScopedXLock xlock;
  195988. XWMHints* wmHints = XGetWMHints (display, windowH);
  195989. if (wmHints != 0)
  195990. {
  195991. if ((wmHints->flags & IconPixmapHint) != 0)
  195992. {
  195993. wmHints->flags &= ~IconPixmapHint;
  195994. XFreePixmap (display, wmHints->icon_pixmap);
  195995. }
  195996. if ((wmHints->flags & IconMaskHint) != 0)
  195997. {
  195998. wmHints->flags &= ~IconMaskHint;
  195999. XFreePixmap (display, wmHints->icon_mask);
  196000. }
  196001. XSetWMHints (display, windowH, wmHints);
  196002. XFree (wmHints);
  196003. }
  196004. }
  196005. void handleWindowMessage (XEvent* event)
  196006. {
  196007. switch (event->xany.type)
  196008. {
  196009. case 2: // 'KeyPress'
  196010. {
  196011. ScopedXLock xlock;
  196012. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196013. updateKeyStates (keyEvent->keycode, true);
  196014. char utf8 [64];
  196015. zeromem (utf8, sizeof (utf8));
  196016. KeySym sym;
  196017. {
  196018. const char* oldLocale = ::setlocale (LC_ALL, 0);
  196019. ::setlocale (LC_ALL, "");
  196020. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196021. ::setlocale (LC_ALL, oldLocale);
  196022. }
  196023. const juce_wchar unicodeChar = String::fromUTF8 (utf8, sizeof (utf8) - 1) [0];
  196024. int keyCode = (int) unicodeChar;
  196025. if (keyCode < 0x20)
  196026. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  196027. const ModifierKeys oldMods (currentModifiers);
  196028. bool keyPressed = false;
  196029. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196030. if ((sym & 0xff00) == 0xff00)
  196031. {
  196032. // Translate keypad
  196033. if (sym == XK_KP_Divide)
  196034. keyCode = XK_slash;
  196035. else if (sym == XK_KP_Multiply)
  196036. keyCode = XK_asterisk;
  196037. else if (sym == XK_KP_Subtract)
  196038. keyCode = XK_hyphen;
  196039. else if (sym == XK_KP_Add)
  196040. keyCode = XK_plus;
  196041. else if (sym == XK_KP_Enter)
  196042. keyCode = XK_Return;
  196043. else if (sym == XK_KP_Decimal)
  196044. keyCode = Keys::numLock ? XK_period : XK_Delete;
  196045. else if (sym == XK_KP_0)
  196046. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  196047. else if (sym == XK_KP_1)
  196048. keyCode = Keys::numLock ? XK_1 : XK_End;
  196049. else if (sym == XK_KP_2)
  196050. keyCode = Keys::numLock ? XK_2 : XK_Down;
  196051. else if (sym == XK_KP_3)
  196052. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  196053. else if (sym == XK_KP_4)
  196054. keyCode = Keys::numLock ? XK_4 : XK_Left;
  196055. else if (sym == XK_KP_5)
  196056. keyCode = XK_5;
  196057. else if (sym == XK_KP_6)
  196058. keyCode = Keys::numLock ? XK_6 : XK_Right;
  196059. else if (sym == XK_KP_7)
  196060. keyCode = Keys::numLock ? XK_7 : XK_Home;
  196061. else if (sym == XK_KP_8)
  196062. keyCode = Keys::numLock ? XK_8 : XK_Up;
  196063. else if (sym == XK_KP_9)
  196064. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  196065. switch (sym)
  196066. {
  196067. case XK_Left:
  196068. case XK_Right:
  196069. case XK_Up:
  196070. case XK_Down:
  196071. case XK_Page_Up:
  196072. case XK_Page_Down:
  196073. case XK_End:
  196074. case XK_Home:
  196075. case XK_Delete:
  196076. case XK_Insert:
  196077. keyPressed = true;
  196078. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196079. break;
  196080. case XK_Tab:
  196081. case XK_Return:
  196082. case XK_Escape:
  196083. case XK_BackSpace:
  196084. keyPressed = true;
  196085. keyCode &= 0xff;
  196086. break;
  196087. default:
  196088. {
  196089. if (sym >= XK_F1 && sym <= XK_F16)
  196090. {
  196091. keyPressed = true;
  196092. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196093. }
  196094. break;
  196095. }
  196096. }
  196097. }
  196098. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196099. keyPressed = true;
  196100. if (oldMods != currentModifiers)
  196101. handleModifierKeysChange();
  196102. if (keyDownChange)
  196103. handleKeyUpOrDown (true);
  196104. if (keyPressed)
  196105. handleKeyPress (keyCode, unicodeChar);
  196106. break;
  196107. }
  196108. case KeyRelease:
  196109. {
  196110. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196111. updateKeyStates (keyEvent->keycode, false);
  196112. ScopedXLock xlock;
  196113. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196114. const ModifierKeys oldMods (currentModifiers);
  196115. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196116. if (oldMods != currentModifiers)
  196117. handleModifierKeysChange();
  196118. if (keyDownChange)
  196119. handleKeyUpOrDown (false);
  196120. break;
  196121. }
  196122. case ButtonPress:
  196123. {
  196124. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196125. updateKeyModifiers (buttonPressEvent->state);
  196126. bool buttonMsg = false;
  196127. const int map = pointerMap [buttonPressEvent->button - Button1];
  196128. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196129. {
  196130. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196131. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196132. }
  196133. if (map == Keys::LeftButton)
  196134. {
  196135. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196136. buttonMsg = true;
  196137. }
  196138. else if (map == Keys::RightButton)
  196139. {
  196140. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196141. buttonMsg = true;
  196142. }
  196143. else if (map == Keys::MiddleButton)
  196144. {
  196145. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196146. buttonMsg = true;
  196147. }
  196148. if (buttonMsg)
  196149. {
  196150. toFront (true);
  196151. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196152. getEventTime (buttonPressEvent->time));
  196153. }
  196154. clearLastMousePos();
  196155. break;
  196156. }
  196157. case ButtonRelease:
  196158. {
  196159. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196160. updateKeyModifiers (buttonRelEvent->state);
  196161. const int map = pointerMap [buttonRelEvent->button - Button1];
  196162. if (map == Keys::LeftButton)
  196163. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196164. else if (map == Keys::RightButton)
  196165. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196166. else if (map == Keys::MiddleButton)
  196167. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196168. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196169. getEventTime (buttonRelEvent->time));
  196170. clearLastMousePos();
  196171. break;
  196172. }
  196173. case MotionNotify:
  196174. {
  196175. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196176. updateKeyModifiers (movedEvent->state);
  196177. const Point<int> mousePos (Desktop::getMousePosition());
  196178. if (lastMousePos != mousePos)
  196179. {
  196180. lastMousePos = mousePos;
  196181. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196182. {
  196183. Window wRoot = 0, wParent = 0;
  196184. {
  196185. ScopedXLock xlock;
  196186. unsigned int numChildren;
  196187. Window* wChild = 0;
  196188. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196189. }
  196190. if (wParent != 0
  196191. && wParent != windowH
  196192. && wParent != wRoot)
  196193. {
  196194. parentWindow = wParent;
  196195. updateBounds();
  196196. }
  196197. else
  196198. {
  196199. parentWindow = 0;
  196200. }
  196201. }
  196202. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196203. }
  196204. break;
  196205. }
  196206. case EnterNotify:
  196207. {
  196208. clearLastMousePos();
  196209. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196210. if (! currentModifiers.isAnyMouseButtonDown())
  196211. {
  196212. updateKeyModifiers (enterEvent->state);
  196213. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196214. }
  196215. break;
  196216. }
  196217. case LeaveNotify:
  196218. {
  196219. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196220. // Suppress the normal leave if we've got a pointer grab, or if
  196221. // it's a bogus one caused by clicking a mouse button when running
  196222. // in a Window manager
  196223. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196224. || leaveEvent->mode == NotifyUngrab)
  196225. {
  196226. updateKeyModifiers (leaveEvent->state);
  196227. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196228. }
  196229. break;
  196230. }
  196231. case FocusIn:
  196232. {
  196233. isActiveApplication = true;
  196234. if (isFocused())
  196235. handleFocusGain();
  196236. break;
  196237. }
  196238. case FocusOut:
  196239. {
  196240. isActiveApplication = false;
  196241. if (! isFocused())
  196242. handleFocusLoss();
  196243. break;
  196244. }
  196245. case Expose:
  196246. {
  196247. // Batch together all pending expose events
  196248. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196249. XEvent nextEvent;
  196250. ScopedXLock xlock;
  196251. if (exposeEvent->window != windowH)
  196252. {
  196253. Window child;
  196254. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196255. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196256. &child);
  196257. }
  196258. repaint (exposeEvent->x, exposeEvent->y,
  196259. exposeEvent->width, exposeEvent->height);
  196260. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196261. {
  196262. XPeekEvent (display, (XEvent*) &nextEvent);
  196263. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196264. break;
  196265. XNextEvent (display, (XEvent*) &nextEvent);
  196266. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196267. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196268. nextExposeEvent->width, nextExposeEvent->height);
  196269. }
  196270. break;
  196271. }
  196272. case CirculateNotify:
  196273. case CreateNotify:
  196274. case DestroyNotify:
  196275. // Think we can ignore these
  196276. break;
  196277. case ConfigureNotify:
  196278. {
  196279. updateBounds();
  196280. updateBorderSize();
  196281. handleMovedOrResized();
  196282. // if the native title bar is dragged, need to tell any active menus, etc.
  196283. if ((styleFlags & windowHasTitleBar) != 0
  196284. && component->isCurrentlyBlockedByAnotherModalComponent())
  196285. {
  196286. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196287. if (currentModalComp != 0)
  196288. currentModalComp->inputAttemptWhenModal();
  196289. }
  196290. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196291. if (confEvent->window == windowH
  196292. && confEvent->above != 0
  196293. && isFrontWindow())
  196294. {
  196295. handleBroughtToFront();
  196296. }
  196297. break;
  196298. }
  196299. case ReparentNotify:
  196300. {
  196301. parentWindow = 0;
  196302. Window wRoot = 0;
  196303. Window* wChild = 0;
  196304. unsigned int numChildren;
  196305. {
  196306. ScopedXLock xlock;
  196307. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196308. }
  196309. if (parentWindow == windowH || parentWindow == wRoot)
  196310. parentWindow = 0;
  196311. updateBounds();
  196312. updateBorderSize();
  196313. handleMovedOrResized();
  196314. break;
  196315. }
  196316. case GravityNotify:
  196317. {
  196318. updateBounds();
  196319. updateBorderSize();
  196320. handleMovedOrResized();
  196321. break;
  196322. }
  196323. case MapNotify:
  196324. mapped = true;
  196325. handleBroughtToFront();
  196326. break;
  196327. case UnmapNotify:
  196328. mapped = false;
  196329. break;
  196330. case MappingNotify:
  196331. {
  196332. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196333. if (mappingEvent->request != MappingPointer)
  196334. {
  196335. // Deal with modifier/keyboard mapping
  196336. ScopedXLock xlock;
  196337. XRefreshKeyboardMapping (mappingEvent);
  196338. updateModifierMappings();
  196339. }
  196340. break;
  196341. }
  196342. case ClientMessage:
  196343. {
  196344. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196345. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196346. {
  196347. const Atom atom = (Atom) clientMsg->data.l[0];
  196348. if (atom == Atoms::ProtocolList [Atoms::PING])
  196349. {
  196350. Window root = RootWindow (display, DefaultScreen (display));
  196351. event->xclient.window = root;
  196352. XSendEvent (display, root, False, NoEventMask, event);
  196353. XFlush (display);
  196354. }
  196355. else if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196356. {
  196357. XWindowAttributes atts;
  196358. ScopedXLock xlock;
  196359. if (clientMsg->window != 0
  196360. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196361. {
  196362. if (atts.map_state == IsViewable)
  196363. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196364. }
  196365. }
  196366. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196367. {
  196368. handleUserClosingWindow();
  196369. }
  196370. }
  196371. else if (clientMsg->message_type == Atoms::XdndEnter)
  196372. {
  196373. handleDragAndDropEnter (clientMsg);
  196374. }
  196375. else if (clientMsg->message_type == Atoms::XdndLeave)
  196376. {
  196377. resetDragAndDrop();
  196378. }
  196379. else if (clientMsg->message_type == Atoms::XdndPosition)
  196380. {
  196381. handleDragAndDropPosition (clientMsg);
  196382. }
  196383. else if (clientMsg->message_type == Atoms::XdndDrop)
  196384. {
  196385. handleDragAndDropDrop (clientMsg);
  196386. }
  196387. else if (clientMsg->message_type == Atoms::XdndStatus)
  196388. {
  196389. handleDragAndDropStatus (clientMsg);
  196390. }
  196391. else if (clientMsg->message_type == Atoms::XdndFinished)
  196392. {
  196393. resetDragAndDrop();
  196394. }
  196395. break;
  196396. }
  196397. case SelectionNotify:
  196398. handleDragAndDropSelection (event);
  196399. break;
  196400. case SelectionClear:
  196401. case SelectionRequest:
  196402. break;
  196403. default:
  196404. #if JUCE_USE_XSHM
  196405. {
  196406. ScopedXLock xlock;
  196407. if (event->xany.type == XShmGetEventBase (display))
  196408. repainter->notifyPaintCompleted();
  196409. }
  196410. #endif
  196411. break;
  196412. }
  196413. }
  196414. void showMouseCursor (Cursor cursor) throw()
  196415. {
  196416. ScopedXLock xlock;
  196417. XDefineCursor (display, windowH, cursor);
  196418. }
  196419. void setTaskBarIcon (const Image& image)
  196420. {
  196421. ScopedXLock xlock;
  196422. taskbarImage = image.createCopy();
  196423. Screen* const screen = XDefaultScreenOfDisplay (display);
  196424. const int screenNumber = XScreenNumberOfScreen (screen);
  196425. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196426. screenAtom << screenNumber;
  196427. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196428. XGrabServer (display);
  196429. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196430. if (managerWin != None)
  196431. XSelectInput (display, managerWin, StructureNotifyMask);
  196432. XUngrabServer (display);
  196433. XFlush (display);
  196434. if (managerWin != None)
  196435. {
  196436. XEvent ev;
  196437. zerostruct (ev);
  196438. ev.xclient.type = ClientMessage;
  196439. ev.xclient.window = managerWin;
  196440. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196441. ev.xclient.format = 32;
  196442. ev.xclient.data.l[0] = CurrentTime;
  196443. ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
  196444. ev.xclient.data.l[2] = windowH;
  196445. ev.xclient.data.l[3] = 0;
  196446. ev.xclient.data.l[4] = 0;
  196447. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196448. XSync (display, False);
  196449. }
  196450. // For older KDE's ...
  196451. long atomData = 1;
  196452. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196453. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196454. // For more recent KDE's...
  196455. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196456. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196457. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196458. XSizeHints* hints = XAllocSizeHints();
  196459. hints->flags = PMinSize;
  196460. hints->min_width = 22;
  196461. hints->min_height = 22;
  196462. XSetWMNormalHints (display, windowH, hints);
  196463. XFree (hints);
  196464. }
  196465. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196466. juce_UseDebuggingNewOperator
  196467. bool dontRepaint;
  196468. static ModifierKeys currentModifiers;
  196469. static bool isActiveApplication;
  196470. private:
  196471. class LinuxRepaintManager : public Timer
  196472. {
  196473. public:
  196474. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196475. : peer (peer_),
  196476. lastTimeImageUsed (0)
  196477. {
  196478. #if JUCE_USE_XSHM
  196479. shmCompletedDrawing = true;
  196480. useARGBImagesForRendering = XSHMHelpers::isShmAvailable();
  196481. if (useARGBImagesForRendering)
  196482. {
  196483. ScopedXLock xlock;
  196484. XShmSegmentInfo segmentinfo;
  196485. XImage* const testImage
  196486. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196487. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196488. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196489. XDestroyImage (testImage);
  196490. }
  196491. #endif
  196492. }
  196493. ~LinuxRepaintManager()
  196494. {
  196495. }
  196496. void timerCallback()
  196497. {
  196498. #if JUCE_USE_XSHM
  196499. if (! shmCompletedDrawing)
  196500. return;
  196501. #endif
  196502. if (! regionsNeedingRepaint.isEmpty())
  196503. {
  196504. stopTimer();
  196505. performAnyPendingRepaintsNow();
  196506. }
  196507. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196508. {
  196509. stopTimer();
  196510. image = 0;
  196511. }
  196512. }
  196513. void repaint (int x, int y, int w, int h)
  196514. {
  196515. if (! isTimerRunning())
  196516. startTimer (repaintTimerPeriod);
  196517. regionsNeedingRepaint.add (x, y, w, h);
  196518. }
  196519. void performAnyPendingRepaintsNow()
  196520. {
  196521. #if JUCE_USE_XSHM
  196522. if (! shmCompletedDrawing)
  196523. {
  196524. startTimer (repaintTimerPeriod);
  196525. return;
  196526. }
  196527. #endif
  196528. peer->clearMaskedRegion();
  196529. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196530. regionsNeedingRepaint.clear();
  196531. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196532. if (! totalArea.isEmpty())
  196533. {
  196534. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196535. || image->getHeight() < totalArea.getHeight())
  196536. {
  196537. #if JUCE_USE_XSHM
  196538. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196539. : Image::RGB,
  196540. #else
  196541. image = new XBitmapImage (Image::RGB,
  196542. #endif
  196543. (totalArea.getWidth() + 31) & ~31,
  196544. (totalArea.getHeight() + 31) & ~31,
  196545. false,
  196546. peer->depth,
  196547. peer->visual);
  196548. }
  196549. startTimer (repaintTimerPeriod);
  196550. LowLevelGraphicsSoftwareRenderer context (*image);
  196551. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196552. if (context.clipToRectangleList (originalRepaintRegion))
  196553. {
  196554. if (peer->depth == 32)
  196555. {
  196556. RectangleList::Iterator i (originalRepaintRegion);
  196557. while (i.next())
  196558. {
  196559. const Rectangle<int>& r = *i.getRectangle();
  196560. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196561. }
  196562. }
  196563. peer->handlePaint (context);
  196564. }
  196565. if (! peer->maskedRegion.isEmpty())
  196566. originalRepaintRegion.subtract (peer->maskedRegion);
  196567. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196568. {
  196569. #if JUCE_USE_XSHM
  196570. shmCompletedDrawing = false;
  196571. #endif
  196572. const Rectangle<int>& r = *i.getRectangle();
  196573. image->blitToWindow (peer->windowH,
  196574. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196575. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196576. }
  196577. }
  196578. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196579. startTimer (repaintTimerPeriod);
  196580. }
  196581. #if JUCE_USE_XSHM
  196582. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196583. #endif
  196584. private:
  196585. enum { repaintTimerPeriod = 1000 / 100 };
  196586. LinuxComponentPeer* const peer;
  196587. ScopedPointer <XBitmapImage> image;
  196588. uint32 lastTimeImageUsed;
  196589. RectangleList regionsNeedingRepaint;
  196590. #if JUCE_USE_XSHM
  196591. bool useARGBImagesForRendering, shmCompletedDrawing;
  196592. #endif
  196593. LinuxRepaintManager (const LinuxRepaintManager&);
  196594. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196595. };
  196596. ScopedPointer <LinuxRepaintManager> repainter;
  196597. friend class LinuxRepaintManager;
  196598. Window windowH, parentWindow;
  196599. int wx, wy, ww, wh;
  196600. ScopedPointer<Image> taskbarImage;
  196601. bool fullScreen, mapped;
  196602. Visual* visual;
  196603. int depth;
  196604. BorderSize windowBorder;
  196605. struct MotifWmHints
  196606. {
  196607. unsigned long flags;
  196608. unsigned long functions;
  196609. unsigned long decorations;
  196610. long input_mode;
  196611. unsigned long status;
  196612. };
  196613. static void updateKeyStates (const int keycode, const bool press) throw()
  196614. {
  196615. const int keybyte = keycode >> 3;
  196616. const int keybit = (1 << (keycode & 7));
  196617. if (press)
  196618. Keys::keyStates [keybyte] |= keybit;
  196619. else
  196620. Keys::keyStates [keybyte] &= ~keybit;
  196621. }
  196622. static void updateKeyModifiers (const int status) throw()
  196623. {
  196624. int keyMods = 0;
  196625. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196626. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196627. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196628. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196629. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196630. Keys::capsLock = ((status & LockMask) != 0);
  196631. }
  196632. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196633. {
  196634. int modifier = 0;
  196635. bool isModifier = true;
  196636. switch (sym)
  196637. {
  196638. case XK_Shift_L:
  196639. case XK_Shift_R:
  196640. modifier = ModifierKeys::shiftModifier;
  196641. break;
  196642. case XK_Control_L:
  196643. case XK_Control_R:
  196644. modifier = ModifierKeys::ctrlModifier;
  196645. break;
  196646. case XK_Alt_L:
  196647. case XK_Alt_R:
  196648. modifier = ModifierKeys::altModifier;
  196649. break;
  196650. case XK_Num_Lock:
  196651. if (press)
  196652. Keys::numLock = ! Keys::numLock;
  196653. break;
  196654. case XK_Caps_Lock:
  196655. if (press)
  196656. Keys::capsLock = ! Keys::capsLock;
  196657. break;
  196658. case XK_Scroll_Lock:
  196659. break;
  196660. default:
  196661. isModifier = false;
  196662. break;
  196663. }
  196664. if (modifier != 0)
  196665. {
  196666. if (press)
  196667. currentModifiers = currentModifiers.withFlags (modifier);
  196668. else
  196669. currentModifiers = currentModifiers.withoutFlags (modifier);
  196670. }
  196671. return isModifier;
  196672. }
  196673. // Alt and Num lock are not defined by standard X
  196674. // modifier constants: check what they're mapped to
  196675. static void updateModifierMappings() throw()
  196676. {
  196677. ScopedXLock xlock;
  196678. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196679. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196680. Keys::AltMask = 0;
  196681. Keys::NumLockMask = 0;
  196682. XModifierKeymap* mapping = XGetModifierMapping (display);
  196683. if (mapping)
  196684. {
  196685. for (int i = 0; i < 8; i++)
  196686. {
  196687. if (mapping->modifiermap [i << 1] == altLeftCode)
  196688. Keys::AltMask = 1 << i;
  196689. else if (mapping->modifiermap [i << 1] == numLockCode)
  196690. Keys::NumLockMask = 1 << i;
  196691. }
  196692. XFreeModifiermap (mapping);
  196693. }
  196694. }
  196695. void removeWindowDecorations (Window wndH)
  196696. {
  196697. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196698. if (hints != None)
  196699. {
  196700. MotifWmHints motifHints;
  196701. zerostruct (motifHints);
  196702. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196703. motifHints.decorations = 0;
  196704. ScopedXLock xlock;
  196705. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196706. (unsigned char*) &motifHints, 4);
  196707. }
  196708. hints = XInternAtom (display, "_WIN_HINTS", True);
  196709. if (hints != None)
  196710. {
  196711. long gnomeHints = 0;
  196712. ScopedXLock xlock;
  196713. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196714. (unsigned char*) &gnomeHints, 1);
  196715. }
  196716. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196717. if (hints != None)
  196718. {
  196719. long kwmHints = 2; /*KDE_tinyDecoration*/
  196720. ScopedXLock xlock;
  196721. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196722. (unsigned char*) &kwmHints, 1);
  196723. }
  196724. }
  196725. void addWindowButtons (Window wndH)
  196726. {
  196727. ScopedXLock xlock;
  196728. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196729. if (hints != None)
  196730. {
  196731. MotifWmHints motifHints;
  196732. zerostruct (motifHints);
  196733. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196734. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196735. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196736. if ((styleFlags & windowHasCloseButton) != 0)
  196737. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196738. if ((styleFlags & windowHasMinimiseButton) != 0)
  196739. {
  196740. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196741. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196742. }
  196743. if ((styleFlags & windowHasMaximiseButton) != 0)
  196744. {
  196745. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196746. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196747. }
  196748. if ((styleFlags & windowIsResizable) != 0)
  196749. {
  196750. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196751. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196752. }
  196753. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196754. }
  196755. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196756. if (hints != None)
  196757. {
  196758. int netHints [6];
  196759. int num = 0;
  196760. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196761. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196762. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196763. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196764. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196765. (unsigned char*) &netHints, num);
  196766. }
  196767. }
  196768. void setWindowType (Window wndH)
  196769. {
  196770. int netHints [2];
  196771. int numHints = 0;
  196772. if ((styleFlags & windowIsTemporary) != 0
  196773. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196774. {
  196775. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196776. }
  196777. else
  196778. {
  196779. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196780. }
  196781. if (netHints [numHints] != 0)
  196782. ++numHints;
  196783. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196784. if (netHints [numHints] != 0)
  196785. ++numHints;
  196786. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196787. (unsigned char*) &netHints, numHints);
  196788. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196789. {
  196790. Atom skipTaskbar = XInternAtom (display, "_NET_WM_STATE_SKIP_TASKBAR", False);
  196791. XChangeProperty (display, wndH, Atoms::WindowState, XA_ATOM, 32, PropModeReplace,
  196792. (unsigned char*) &skipTaskbar, 1);
  196793. }
  196794. }
  196795. void createWindow()
  196796. {
  196797. ScopedXLock xlock;
  196798. Atoms::initialiseAtoms();
  196799. resetDragAndDrop();
  196800. // Get defaults for various properties
  196801. const int screen = DefaultScreen (display);
  196802. Window root = RootWindow (display, screen);
  196803. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196804. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196805. if (visual == 0)
  196806. {
  196807. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196808. Process::terminate();
  196809. }
  196810. // Create and install a colormap suitable fr our visual
  196811. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196812. XInstallColormap (display, colormap);
  196813. // Set up the window attributes
  196814. XSetWindowAttributes swa;
  196815. swa.border_pixel = 0;
  196816. swa.background_pixmap = None;
  196817. swa.colormap = colormap;
  196818. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196819. swa.event_mask = getAllEventsMask();
  196820. Window wndH = XCreateWindow (display, root,
  196821. 0, 0, 1, 1,
  196822. 0, depth, InputOutput, visual,
  196823. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196824. &swa);
  196825. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196826. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196827. GrabModeAsync, GrabModeAsync, None, None);
  196828. // Set the window context to identify the window handle object
  196829. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196830. {
  196831. // Failed
  196832. jassertfalse
  196833. Logger::outputDebugString ("Failed to create context information for window.\n");
  196834. XDestroyWindow (display, wndH);
  196835. wndH = 0;
  196836. }
  196837. // Set window manager hints
  196838. XWMHints* wmHints = XAllocWMHints();
  196839. wmHints->flags = InputHint | StateHint;
  196840. wmHints->input = True; // Locally active input model
  196841. wmHints->initial_state = NormalState;
  196842. XSetWMHints (display, wndH, wmHints);
  196843. XFree (wmHints);
  196844. // Set the window type
  196845. setWindowType (wndH);
  196846. // Define decoration
  196847. if ((styleFlags & windowHasTitleBar) == 0)
  196848. removeWindowDecorations (wndH);
  196849. else
  196850. addWindowButtons (wndH);
  196851. // Set window name
  196852. setWindowTitle (wndH, getComponent()->getName());
  196853. // Associate the PID, allowing to be shut down when something goes wrong
  196854. unsigned long pid = getpid();
  196855. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196856. (unsigned char*) &pid, 1);
  196857. // Set window manager protocols
  196858. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196859. (unsigned char*) Atoms::ProtocolList, 2);
  196860. // Set drag and drop flags
  196861. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196862. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196863. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196864. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196865. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196866. (const unsigned char*) "", 0);
  196867. unsigned long dndVersion = Atoms::DndVersion;
  196868. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196869. (const unsigned char*) &dndVersion, 1);
  196870. // Initialise the pointer and keyboard mapping
  196871. // This is not the same as the logical pointer mapping the X server uses:
  196872. // we don't mess with this.
  196873. static bool mappingInitialised = false;
  196874. if (! mappingInitialised)
  196875. {
  196876. mappingInitialised = true;
  196877. const int numButtons = XGetPointerMapping (display, 0, 0);
  196878. if (numButtons == 2)
  196879. {
  196880. pointerMap[0] = Keys::LeftButton;
  196881. pointerMap[1] = Keys::RightButton;
  196882. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196883. }
  196884. else if (numButtons >= 3)
  196885. {
  196886. pointerMap[0] = Keys::LeftButton;
  196887. pointerMap[1] = Keys::MiddleButton;
  196888. pointerMap[2] = Keys::RightButton;
  196889. if (numButtons >= 5)
  196890. {
  196891. pointerMap[3] = Keys::WheelUp;
  196892. pointerMap[4] = Keys::WheelDown;
  196893. }
  196894. }
  196895. updateModifierMappings();
  196896. }
  196897. windowH = wndH;
  196898. }
  196899. void destroyWindow()
  196900. {
  196901. ScopedXLock xlock;
  196902. XPointer handlePointer;
  196903. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  196904. XDeleteContext (display, (XID) windowH, improbableNumber);
  196905. XDestroyWindow (display, windowH);
  196906. // Wait for it to complete and then remove any events for this
  196907. // window from the event queue.
  196908. XSync (display, false);
  196909. XEvent event;
  196910. while (XCheckWindowEvent (display, windowH, getAllEventsMask(), &event) == True)
  196911. {}
  196912. }
  196913. static int getAllEventsMask() throw()
  196914. {
  196915. return NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  196916. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  196917. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  196918. }
  196919. static int64 getEventTime (::Time t)
  196920. {
  196921. static int64 eventTimeOffset = 0x12345678;
  196922. const int64 thisMessageTime = t;
  196923. if (eventTimeOffset == 0x12345678)
  196924. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  196925. return eventTimeOffset + thisMessageTime;
  196926. }
  196927. static void setWindowTitle (Window xwin, const String& title)
  196928. {
  196929. XTextProperty nameProperty;
  196930. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  196931. ScopedXLock xlock;
  196932. if (XStringListToTextProperty (strings, 1, &nameProperty))
  196933. {
  196934. XSetWMName (display, xwin, &nameProperty);
  196935. XSetWMIconName (display, xwin, &nameProperty);
  196936. XFree (nameProperty.value);
  196937. }
  196938. }
  196939. void updateBorderSize()
  196940. {
  196941. if ((styleFlags & windowHasTitleBar) == 0)
  196942. {
  196943. windowBorder = BorderSize (0);
  196944. }
  196945. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  196946. {
  196947. ScopedXLock xlock;
  196948. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  196949. if (hints != None)
  196950. {
  196951. unsigned char* data = 0;
  196952. unsigned long nitems, bytesLeft;
  196953. Atom actualType;
  196954. int actualFormat;
  196955. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  196956. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  196957. &data) == Success)
  196958. {
  196959. const unsigned long* const sizes = (const unsigned long*) data;
  196960. if (actualFormat == 32)
  196961. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  196962. (int) sizes[3], (int) sizes[1]);
  196963. XFree (data);
  196964. }
  196965. }
  196966. }
  196967. }
  196968. void updateBounds()
  196969. {
  196970. jassert (windowH != 0);
  196971. if (windowH != 0)
  196972. {
  196973. Window root, child;
  196974. unsigned int bw, depth;
  196975. ScopedXLock xlock;
  196976. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196977. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  196978. &bw, &depth))
  196979. {
  196980. wx = wy = ww = wh = 0;
  196981. }
  196982. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  196983. {
  196984. wx = wy = 0;
  196985. }
  196986. }
  196987. }
  196988. void resetDragAndDrop()
  196989. {
  196990. dragAndDropFiles.clear();
  196991. lastDropPos = Point<int> (-1, -1);
  196992. dragAndDropCurrentMimeType = 0;
  196993. dragAndDropSourceWindow = 0;
  196994. srcMimeTypeAtomList.clear();
  196995. }
  196996. void sendDragAndDropMessage (XClientMessageEvent& msg)
  196997. {
  196998. msg.type = ClientMessage;
  196999. msg.display = display;
  197000. msg.window = dragAndDropSourceWindow;
  197001. msg.format = 32;
  197002. msg.data.l[0] = windowH;
  197003. ScopedXLock xlock;
  197004. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197005. }
  197006. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197007. {
  197008. XClientMessageEvent msg;
  197009. zerostruct (msg);
  197010. msg.message_type = Atoms::XdndStatus;
  197011. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197012. msg.data.l[4] = dropAction;
  197013. sendDragAndDropMessage (msg);
  197014. }
  197015. void sendDragAndDropLeave()
  197016. {
  197017. XClientMessageEvent msg;
  197018. zerostruct (msg);
  197019. msg.message_type = Atoms::XdndLeave;
  197020. sendDragAndDropMessage (msg);
  197021. }
  197022. void sendDragAndDropFinish()
  197023. {
  197024. XClientMessageEvent msg;
  197025. zerostruct (msg);
  197026. msg.message_type = Atoms::XdndFinished;
  197027. sendDragAndDropMessage (msg);
  197028. }
  197029. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197030. {
  197031. if ((clientMsg->data.l[1] & 1) == 0)
  197032. {
  197033. sendDragAndDropLeave();
  197034. if (dragAndDropFiles.size() > 0)
  197035. handleFileDragExit (dragAndDropFiles);
  197036. dragAndDropFiles.clear();
  197037. }
  197038. }
  197039. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197040. {
  197041. if (dragAndDropSourceWindow == 0)
  197042. return;
  197043. dragAndDropSourceWindow = clientMsg->data.l[0];
  197044. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197045. (int) clientMsg->data.l[2] & 0xffff);
  197046. dropPos -= getScreenPosition();
  197047. if (lastDropPos != dropPos)
  197048. {
  197049. lastDropPos = dropPos;
  197050. dragAndDropTimestamp = clientMsg->data.l[3];
  197051. Atom targetAction = Atoms::XdndActionCopy;
  197052. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  197053. {
  197054. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  197055. {
  197056. targetAction = Atoms::allowedActions[i];
  197057. break;
  197058. }
  197059. }
  197060. sendDragAndDropStatus (true, targetAction);
  197061. if (dragAndDropFiles.size() == 0)
  197062. updateDraggedFileList (clientMsg);
  197063. if (dragAndDropFiles.size() > 0)
  197064. handleFileDragMove (dragAndDropFiles, dropPos);
  197065. }
  197066. }
  197067. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197068. {
  197069. if (dragAndDropFiles.size() == 0)
  197070. updateDraggedFileList (clientMsg);
  197071. const StringArray files (dragAndDropFiles);
  197072. const Point<int> lastPos (lastDropPos);
  197073. sendDragAndDropFinish();
  197074. resetDragAndDrop();
  197075. if (files.size() > 0)
  197076. handleFileDragDrop (files, lastPos);
  197077. }
  197078. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197079. {
  197080. dragAndDropFiles.clear();
  197081. srcMimeTypeAtomList.clear();
  197082. dragAndDropCurrentMimeType = 0;
  197083. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  197084. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  197085. {
  197086. dragAndDropSourceWindow = 0;
  197087. return;
  197088. }
  197089. dragAndDropSourceWindow = clientMsg->data.l[0];
  197090. if ((clientMsg->data.l[1] & 1) != 0)
  197091. {
  197092. Atom actual;
  197093. int format;
  197094. unsigned long count = 0, remaining = 0;
  197095. unsigned char* data = 0;
  197096. ScopedXLock xlock;
  197097. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197098. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197099. &count, &remaining, &data);
  197100. if (data != 0)
  197101. {
  197102. if (actual == XA_ATOM && format == 32 && count != 0)
  197103. {
  197104. const unsigned long* const types = (const unsigned long*) data;
  197105. for (unsigned int i = 0; i < count; ++i)
  197106. if (types[i] != None)
  197107. srcMimeTypeAtomList.add (types[i]);
  197108. }
  197109. XFree (data);
  197110. }
  197111. }
  197112. if (srcMimeTypeAtomList.size() == 0)
  197113. {
  197114. for (int i = 2; i < 5; ++i)
  197115. if (clientMsg->data.l[i] != None)
  197116. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197117. if (srcMimeTypeAtomList.size() == 0)
  197118. {
  197119. dragAndDropSourceWindow = 0;
  197120. return;
  197121. }
  197122. }
  197123. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197124. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197125. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197126. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197127. handleDragAndDropPosition (clientMsg);
  197128. }
  197129. void handleDragAndDropSelection (const XEvent* const evt)
  197130. {
  197131. dragAndDropFiles.clear();
  197132. if (evt->xselection.property != 0)
  197133. {
  197134. StringArray lines;
  197135. {
  197136. MemoryBlock dropData;
  197137. for (;;)
  197138. {
  197139. Atom actual;
  197140. uint8* data = 0;
  197141. unsigned long count = 0, remaining = 0;
  197142. int format = 0;
  197143. ScopedXLock xlock;
  197144. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197145. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197146. &format, &count, &remaining, &data) == Success)
  197147. {
  197148. dropData.append (data, count * format / 8);
  197149. XFree (data);
  197150. if (remaining == 0)
  197151. break;
  197152. }
  197153. else
  197154. {
  197155. XFree (data);
  197156. break;
  197157. }
  197158. }
  197159. lines.addLines (dropData.toString());
  197160. }
  197161. for (int i = 0; i < lines.size(); ++i)
  197162. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf ("file://", false, true)));
  197163. dragAndDropFiles.trim();
  197164. dragAndDropFiles.removeEmptyStrings();
  197165. }
  197166. }
  197167. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197168. {
  197169. dragAndDropFiles.clear();
  197170. if (dragAndDropSourceWindow != None
  197171. && dragAndDropCurrentMimeType != 0)
  197172. {
  197173. dragAndDropTimestamp = clientMsg->data.l[2];
  197174. ScopedXLock xlock;
  197175. XConvertSelection (display,
  197176. Atoms::XdndSelection,
  197177. dragAndDropCurrentMimeType,
  197178. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197179. windowH,
  197180. dragAndDropTimestamp);
  197181. }
  197182. }
  197183. StringArray dragAndDropFiles;
  197184. int dragAndDropTimestamp;
  197185. Point<int> lastDropPos;
  197186. Atom dragAndDropCurrentMimeType;
  197187. Window dragAndDropSourceWindow;
  197188. Array <Atom> srcMimeTypeAtomList;
  197189. static int pointerMap[5];
  197190. static Point<int> lastMousePos;
  197191. static void clearLastMousePos() throw()
  197192. {
  197193. lastMousePos = Point<int> (0x100000, 0x100000);
  197194. }
  197195. };
  197196. ModifierKeys LinuxComponentPeer::currentModifiers;
  197197. bool LinuxComponentPeer::isActiveApplication = false;
  197198. int LinuxComponentPeer::pointerMap[5];
  197199. Point<int> LinuxComponentPeer::lastMousePos;
  197200. bool Process::isForegroundProcess()
  197201. {
  197202. return LinuxComponentPeer::isActiveApplication;
  197203. }
  197204. void ModifierKeys::updateCurrentModifiers() throw()
  197205. {
  197206. currentModifiers = LinuxComponentPeer::currentModifiers;
  197207. }
  197208. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197209. {
  197210. Window root, child;
  197211. int x, y, winx, winy;
  197212. unsigned int mask;
  197213. int mouseMods = 0;
  197214. ScopedXLock xlock;
  197215. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197216. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197217. {
  197218. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197219. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197220. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197221. }
  197222. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197223. return LinuxComponentPeer::currentModifiers;
  197224. }
  197225. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197226. {
  197227. if (enableOrDisable)
  197228. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197229. }
  197230. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197231. {
  197232. return new LinuxComponentPeer (this, styleFlags);
  197233. }
  197234. // (this callback is hooked up in the messaging code)
  197235. void juce_windowMessageReceive (XEvent* event)
  197236. {
  197237. if (event->xany.window != None)
  197238. {
  197239. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197240. if (ComponentPeer::isValidPeer (peer))
  197241. peer->handleWindowMessage (event);
  197242. }
  197243. else
  197244. {
  197245. switch (event->xany.type)
  197246. {
  197247. case KeymapNotify:
  197248. {
  197249. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197250. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197251. break;
  197252. }
  197253. default:
  197254. break;
  197255. }
  197256. }
  197257. }
  197258. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197259. {
  197260. if (display == 0)
  197261. return;
  197262. #if JUCE_USE_XINERAMA
  197263. int major_opcode, first_event, first_error;
  197264. ScopedXLock xlock;
  197265. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197266. {
  197267. typedef Bool (*tXineramaIsActive) (Display*);
  197268. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197269. static tXineramaIsActive xXineramaIsActive = 0;
  197270. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197271. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197272. {
  197273. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197274. if (h != 0)
  197275. {
  197276. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197277. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197278. }
  197279. }
  197280. if (xXineramaIsActive != 0
  197281. && xXineramaQueryScreens != 0
  197282. && xXineramaIsActive (display))
  197283. {
  197284. int numMonitors = 0;
  197285. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197286. if (screens != 0)
  197287. {
  197288. for (int i = numMonitors; --i >= 0;)
  197289. {
  197290. int index = screens[i].screen_number;
  197291. if (index >= 0)
  197292. {
  197293. while (monitorCoords.size() < index)
  197294. monitorCoords.add (Rectangle<int>());
  197295. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197296. screens[i].y_org,
  197297. screens[i].width,
  197298. screens[i].height));
  197299. }
  197300. }
  197301. XFree (screens);
  197302. }
  197303. }
  197304. }
  197305. if (monitorCoords.size() == 0)
  197306. #endif
  197307. {
  197308. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197309. if (hints != None)
  197310. {
  197311. const int numMonitors = ScreenCount (display);
  197312. for (int i = 0; i < numMonitors; ++i)
  197313. {
  197314. Window root = RootWindow (display, i);
  197315. unsigned long nitems, bytesLeft;
  197316. Atom actualType;
  197317. int actualFormat;
  197318. unsigned char* data = 0;
  197319. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197320. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197321. &data) == Success)
  197322. {
  197323. const long* const position = (const long*) data;
  197324. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197325. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197326. position[2], position[3]));
  197327. XFree (data);
  197328. }
  197329. }
  197330. }
  197331. if (monitorCoords.size() == 0)
  197332. {
  197333. monitorCoords.add (Rectangle<int> (0, 0,
  197334. DisplayWidth (display, DefaultScreen (display)),
  197335. DisplayHeight (display, DefaultScreen (display))));
  197336. }
  197337. }
  197338. }
  197339. void Desktop::createMouseInputSources()
  197340. {
  197341. mouseSources.add (new MouseInputSource (0, true));
  197342. }
  197343. bool Desktop::canUseSemiTransparentWindows() throw()
  197344. {
  197345. int matchedDepth = 0;
  197346. const int desiredDepth = 32;
  197347. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197348. && (matchedDepth == desiredDepth);
  197349. }
  197350. const Point<int> Desktop::getMousePosition()
  197351. {
  197352. Window root, child;
  197353. int x, y, winx, winy;
  197354. unsigned int mask;
  197355. ScopedXLock xlock;
  197356. if (XQueryPointer (display,
  197357. RootWindow (display, DefaultScreen (display)),
  197358. &root, &child,
  197359. &x, &y, &winx, &winy, &mask) == False)
  197360. {
  197361. // Pointer not on the default screen
  197362. x = y = -1;
  197363. }
  197364. return Point<int> (x, y);
  197365. }
  197366. void Desktop::setMousePosition (const Point<int>& newPosition)
  197367. {
  197368. ScopedXLock xlock;
  197369. Window root = RootWindow (display, DefaultScreen (display));
  197370. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197371. }
  197372. static bool screenSaverAllowed = true;
  197373. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197374. {
  197375. if (screenSaverAllowed != isEnabled)
  197376. {
  197377. screenSaverAllowed = isEnabled;
  197378. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197379. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197380. if (xScreenSaverSuspend == 0)
  197381. {
  197382. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197383. if (h != 0)
  197384. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197385. }
  197386. ScopedXLock xlock;
  197387. if (xScreenSaverSuspend != 0)
  197388. xScreenSaverSuspend (display, ! isEnabled);
  197389. }
  197390. }
  197391. bool Desktop::isScreenSaverEnabled() throw()
  197392. {
  197393. return screenSaverAllowed;
  197394. }
  197395. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  197396. {
  197397. ScopedXLock xlock;
  197398. const unsigned int imageW = image.getWidth();
  197399. const unsigned int imageH = image.getHeight();
  197400. #if JUCE_USE_XCURSOR
  197401. {
  197402. typedef XcursorBool (*tXcursorSupportsARGB) (Display*);
  197403. typedef XcursorImage* (*tXcursorImageCreate) (int, int);
  197404. typedef void (*tXcursorImageDestroy) (XcursorImage*);
  197405. typedef Cursor (*tXcursorImageLoadCursor) (Display*, const XcursorImage*);
  197406. static tXcursorSupportsARGB xXcursorSupportsARGB = 0;
  197407. static tXcursorImageCreate xXcursorImageCreate = 0;
  197408. static tXcursorImageDestroy xXcursorImageDestroy = 0;
  197409. static tXcursorImageLoadCursor xXcursorImageLoadCursor = 0;
  197410. static bool hasBeenLoaded = false;
  197411. if (! hasBeenLoaded)
  197412. {
  197413. hasBeenLoaded = true;
  197414. void* h = dlopen ("libXcursor.so", RTLD_GLOBAL | RTLD_NOW);
  197415. if (h != 0)
  197416. {
  197417. xXcursorSupportsARGB = (tXcursorSupportsARGB) dlsym (h, "XcursorSupportsARGB");
  197418. xXcursorImageCreate = (tXcursorImageCreate) dlsym (h, "XcursorImageCreate");
  197419. xXcursorImageLoadCursor = (tXcursorImageLoadCursor) dlsym (h, "XcursorImageLoadCursor");
  197420. xXcursorImageDestroy = (tXcursorImageDestroy) dlsym (h, "XcursorImageDestroy");
  197421. if (xXcursorSupportsARGB == 0 || xXcursorImageCreate == 0
  197422. || xXcursorImageLoadCursor == 0 || xXcursorImageDestroy == 0
  197423. || ! xXcursorSupportsARGB (display))
  197424. xXcursorSupportsARGB = 0;
  197425. }
  197426. }
  197427. if (xXcursorSupportsARGB != 0)
  197428. {
  197429. XcursorImage* xcImage = xXcursorImageCreate (imageW, imageH);
  197430. if (xcImage != 0)
  197431. {
  197432. xcImage->xhot = hotspotX;
  197433. xcImage->yhot = hotspotY;
  197434. XcursorPixel* dest = xcImage->pixels;
  197435. for (int y = 0; y < (int) imageH; ++y)
  197436. for (int x = 0; x < (int) imageW; ++x)
  197437. *dest++ = image.getPixelAt (x, y).getARGB();
  197438. void* result = (void*) xXcursorImageLoadCursor (display, xcImage);
  197439. xXcursorImageDestroy (xcImage);
  197440. if (result != 0)
  197441. return result;
  197442. }
  197443. }
  197444. }
  197445. #endif
  197446. Window root = RootWindow (display, DefaultScreen (display));
  197447. unsigned int cursorW, cursorH;
  197448. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197449. return 0;
  197450. Image im (Image::ARGB, cursorW, cursorH, true);
  197451. {
  197452. Graphics g (im);
  197453. if (imageW > cursorW || imageH > cursorH)
  197454. {
  197455. hotspotX = (hotspotX * cursorW) / imageW;
  197456. hotspotY = (hotspotY * cursorH) / imageH;
  197457. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197458. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197459. false);
  197460. }
  197461. else
  197462. {
  197463. g.drawImageAt (&image, 0, 0);
  197464. }
  197465. }
  197466. const int stride = (cursorW + 7) >> 3;
  197467. HeapBlock <char> maskPlane, sourcePlane;
  197468. maskPlane.calloc (stride * cursorH);
  197469. sourcePlane.calloc (stride * cursorH);
  197470. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197471. for (int y = cursorH; --y >= 0;)
  197472. {
  197473. for (int x = cursorW; --x >= 0;)
  197474. {
  197475. const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197476. const int offset = y * stride + (x >> 3);
  197477. const Colour c (im.getPixelAt (x, y));
  197478. if (c.getAlpha() >= 128)
  197479. maskPlane[offset] |= mask;
  197480. if (c.getBrightness() >= 0.5f)
  197481. sourcePlane[offset] |= mask;
  197482. }
  197483. }
  197484. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, sourcePlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197485. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, maskPlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197486. XColor white, black;
  197487. black.red = black.green = black.blue = 0;
  197488. white.red = white.green = white.blue = 0xffff;
  197489. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197490. XFreePixmap (display, sourcePixmap);
  197491. XFreePixmap (display, maskPixmap);
  197492. return result;
  197493. }
  197494. void juce_deleteMouseCursor (void* const cursorHandle, const bool)
  197495. {
  197496. ScopedXLock xlock;
  197497. if (cursorHandle != 0)
  197498. XFreeCursor (display, (Cursor) cursorHandle);
  197499. }
  197500. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  197501. {
  197502. unsigned int shape;
  197503. switch (type)
  197504. {
  197505. case MouseCursor::NoCursor:
  197506. {
  197507. const Image im (Image::ARGB, 16, 16, true);
  197508. return juce_createMouseCursorFromImage (im, 0, 0);
  197509. }
  197510. case MouseCursor::NormalCursor:
  197511. return (void*) None; // Use parent cursor
  197512. case MouseCursor::DraggingHandCursor:
  197513. {
  197514. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197515. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197516. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197517. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197518. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197519. const int dragHandDataSize = 99;
  197520. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (dragHandData, dragHandDataSize));
  197521. return juce_createMouseCursorFromImage (*im, 8, 7);
  197522. }
  197523. case MouseCursor::CopyingCursor:
  197524. {
  197525. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197526. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197527. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197528. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197529. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197530. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197531. const int copyCursorSize = 119;
  197532. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (copyCursorData, copyCursorSize));
  197533. return juce_createMouseCursorFromImage (*im, 1, 3);
  197534. }
  197535. case MouseCursor::WaitCursor:
  197536. shape = XC_watch;
  197537. break;
  197538. case MouseCursor::IBeamCursor:
  197539. shape = XC_xterm;
  197540. break;
  197541. case MouseCursor::PointingHandCursor:
  197542. shape = XC_hand2;
  197543. break;
  197544. case MouseCursor::LeftRightResizeCursor:
  197545. shape = XC_sb_h_double_arrow;
  197546. break;
  197547. case MouseCursor::UpDownResizeCursor:
  197548. shape = XC_sb_v_double_arrow;
  197549. break;
  197550. case MouseCursor::UpDownLeftRightResizeCursor:
  197551. shape = XC_fleur;
  197552. break;
  197553. case MouseCursor::TopEdgeResizeCursor:
  197554. shape = XC_top_side;
  197555. break;
  197556. case MouseCursor::BottomEdgeResizeCursor:
  197557. shape = XC_bottom_side;
  197558. break;
  197559. case MouseCursor::LeftEdgeResizeCursor:
  197560. shape = XC_left_side;
  197561. break;
  197562. case MouseCursor::RightEdgeResizeCursor:
  197563. shape = XC_right_side;
  197564. break;
  197565. case MouseCursor::TopLeftCornerResizeCursor:
  197566. shape = XC_top_left_corner;
  197567. break;
  197568. case MouseCursor::TopRightCornerResizeCursor:
  197569. shape = XC_top_right_corner;
  197570. break;
  197571. case MouseCursor::BottomLeftCornerResizeCursor:
  197572. shape = XC_bottom_left_corner;
  197573. break;
  197574. case MouseCursor::BottomRightCornerResizeCursor:
  197575. shape = XC_bottom_right_corner;
  197576. break;
  197577. case MouseCursor::CrosshairCursor:
  197578. shape = XC_crosshair;
  197579. break;
  197580. default:
  197581. return (void*) None; // Use parent cursor
  197582. }
  197583. ScopedXLock xlock;
  197584. return (void*) XCreateFontCursor (display, shape);
  197585. }
  197586. void MouseCursor::showInWindow (ComponentPeer* peer) const
  197587. {
  197588. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197589. if (lp != 0)
  197590. lp->showMouseCursor ((Cursor) getHandle());
  197591. }
  197592. void MouseCursor::showInAllWindows() const
  197593. {
  197594. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197595. showInWindow (ComponentPeer::getPeer (i));
  197596. }
  197597. Image* juce_createIconForFile (const File& file)
  197598. {
  197599. return 0;
  197600. }
  197601. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197602. {
  197603. return new Image (format, imageWidth, imageHeight, clearImage);
  197604. }
  197605. #if JUCE_OPENGL
  197606. class WindowedGLContext : public OpenGLContext
  197607. {
  197608. public:
  197609. WindowedGLContext (Component* const component,
  197610. const OpenGLPixelFormat& pixelFormat_,
  197611. GLXContext sharedContext)
  197612. : renderContext (0),
  197613. embeddedWindow (0),
  197614. pixelFormat (pixelFormat_)
  197615. {
  197616. jassert (component != 0);
  197617. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197618. if (peer == 0)
  197619. return;
  197620. ScopedXLock xlock;
  197621. XSync (display, False);
  197622. GLint attribs [64];
  197623. int n = 0;
  197624. attribs[n++] = GLX_RGBA;
  197625. attribs[n++] = GLX_DOUBLEBUFFER;
  197626. attribs[n++] = GLX_RED_SIZE;
  197627. attribs[n++] = pixelFormat.redBits;
  197628. attribs[n++] = GLX_GREEN_SIZE;
  197629. attribs[n++] = pixelFormat.greenBits;
  197630. attribs[n++] = GLX_BLUE_SIZE;
  197631. attribs[n++] = pixelFormat.blueBits;
  197632. attribs[n++] = GLX_ALPHA_SIZE;
  197633. attribs[n++] = pixelFormat.alphaBits;
  197634. attribs[n++] = GLX_DEPTH_SIZE;
  197635. attribs[n++] = pixelFormat.depthBufferBits;
  197636. attribs[n++] = GLX_STENCIL_SIZE;
  197637. attribs[n++] = pixelFormat.stencilBufferBits;
  197638. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197639. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197640. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197641. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197642. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197643. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197644. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197645. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197646. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197647. attribs[n++] = None;
  197648. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197649. if (bestVisual == 0)
  197650. return;
  197651. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197652. Window windowH = (Window) peer->getNativeHandle();
  197653. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197654. XSetWindowAttributes swa;
  197655. swa.colormap = colourMap;
  197656. swa.border_pixel = 0;
  197657. swa.event_mask = ExposureMask | StructureNotifyMask;
  197658. embeddedWindow = XCreateWindow (display, windowH,
  197659. 0, 0, 1, 1, 0,
  197660. bestVisual->depth,
  197661. InputOutput,
  197662. bestVisual->visual,
  197663. CWBorderPixel | CWColormap | CWEventMask,
  197664. &swa);
  197665. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197666. XMapWindow (display, embeddedWindow);
  197667. XFreeColormap (display, colourMap);
  197668. XFree (bestVisual);
  197669. XSync (display, False);
  197670. }
  197671. ~WindowedGLContext()
  197672. {
  197673. makeInactive();
  197674. ScopedXLock xlock;
  197675. glXDestroyContext (display, renderContext);
  197676. XUnmapWindow (display, embeddedWindow);
  197677. XDestroyWindow (display, embeddedWindow);
  197678. }
  197679. bool makeActive() const throw()
  197680. {
  197681. jassert (renderContext != 0);
  197682. ScopedXLock xlock;
  197683. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197684. && XSync (display, False);
  197685. }
  197686. bool makeInactive() const throw()
  197687. {
  197688. ScopedXLock xlock;
  197689. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197690. }
  197691. bool isActive() const throw()
  197692. {
  197693. ScopedXLock xlock;
  197694. return glXGetCurrentContext() == renderContext;
  197695. }
  197696. const OpenGLPixelFormat getPixelFormat() const
  197697. {
  197698. return pixelFormat;
  197699. }
  197700. void* getRawContext() const throw()
  197701. {
  197702. return renderContext;
  197703. }
  197704. void updateWindowPosition (int x, int y, int w, int h, int)
  197705. {
  197706. ScopedXLock xlock;
  197707. XMoveResizeWindow (display, embeddedWindow,
  197708. x, y, jmax (1, w), jmax (1, h));
  197709. }
  197710. void swapBuffers()
  197711. {
  197712. ScopedXLock xlock;
  197713. glXSwapBuffers (display, embeddedWindow);
  197714. }
  197715. bool setSwapInterval (const int numFramesPerSwap)
  197716. {
  197717. // xxx needs doing..
  197718. return false;
  197719. }
  197720. int getSwapInterval() const
  197721. {
  197722. // xxx needs doing..
  197723. return 0;
  197724. }
  197725. void repaint()
  197726. {
  197727. }
  197728. juce_UseDebuggingNewOperator
  197729. GLXContext renderContext;
  197730. private:
  197731. Window embeddedWindow;
  197732. OpenGLPixelFormat pixelFormat;
  197733. WindowedGLContext (const WindowedGLContext&);
  197734. WindowedGLContext& operator= (const WindowedGLContext&);
  197735. };
  197736. OpenGLContext* OpenGLComponent::createContext()
  197737. {
  197738. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197739. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197740. return (c->renderContext != 0) ? c.release() : 0;
  197741. }
  197742. void juce_glViewport (const int w, const int h)
  197743. {
  197744. glViewport (0, 0, w, h);
  197745. }
  197746. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197747. OwnedArray <OpenGLPixelFormat>& results)
  197748. {
  197749. results.add (new OpenGLPixelFormat()); // xxx
  197750. }
  197751. #endif
  197752. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197753. {
  197754. jassertfalse // not implemented!
  197755. return false;
  197756. }
  197757. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197758. {
  197759. jassertfalse // not implemented!
  197760. return false;
  197761. }
  197762. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197763. {
  197764. if (! isOnDesktop ())
  197765. addToDesktop (0);
  197766. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197767. if (wp != 0)
  197768. {
  197769. wp->setTaskBarIcon (newImage);
  197770. setVisible (true);
  197771. toFront (false);
  197772. repaint();
  197773. }
  197774. }
  197775. void SystemTrayIconComponent::paint (Graphics& g)
  197776. {
  197777. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197778. if (wp != 0)
  197779. {
  197780. const Image* const image = wp->getTaskbarIcon();
  197781. if (image != 0)
  197782. {
  197783. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197784. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197785. false);
  197786. }
  197787. }
  197788. }
  197789. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197790. {
  197791. // xxx not yet implemented!
  197792. }
  197793. void PlatformUtilities::beep()
  197794. {
  197795. std::cout << "\a" << std::flush;
  197796. }
  197797. bool AlertWindow::showNativeDialogBox (const String& title,
  197798. const String& bodyText,
  197799. bool isOkCancel)
  197800. {
  197801. // use a non-native one for the time being..
  197802. if (isOkCancel)
  197803. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197804. else
  197805. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197806. return true;
  197807. }
  197808. const int KeyPress::spaceKey = XK_space & 0xff;
  197809. const int KeyPress::returnKey = XK_Return & 0xff;
  197810. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197811. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197812. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197813. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197814. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197815. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197816. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197817. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197818. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197819. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197820. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197821. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197822. const int KeyPress::tabKey = XK_Tab & 0xff;
  197823. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197824. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197825. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197826. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197827. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197828. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197829. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197830. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197831. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197832. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197833. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197834. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197835. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197836. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197837. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197838. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197839. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197840. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197841. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197842. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197843. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197844. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197845. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197846. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197847. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197848. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197849. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197850. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197851. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197852. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197853. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197854. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197855. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197856. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197857. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197858. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197859. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197860. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197861. #endif
  197862. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197863. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197864. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197865. // compiled on its own).
  197866. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197867. static const int maxNumChans = 64;
  197868. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197869. {
  197870. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197871. snd_pcm_hw_params_t* hwParams;
  197872. snd_pcm_hw_params_alloca (&hwParams);
  197873. for (int i = 0; ratesToTry[i] != 0; ++i)
  197874. {
  197875. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197876. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197877. {
  197878. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197879. }
  197880. }
  197881. }
  197882. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197883. {
  197884. snd_pcm_hw_params_t *params;
  197885. snd_pcm_hw_params_alloca (&params);
  197886. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197887. {
  197888. snd_pcm_hw_params_get_channels_min (params, minChans);
  197889. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197890. }
  197891. }
  197892. static void getDeviceProperties (const String& deviceID,
  197893. unsigned int& minChansOut,
  197894. unsigned int& maxChansOut,
  197895. unsigned int& minChansIn,
  197896. unsigned int& maxChansIn,
  197897. Array <int>& rates)
  197898. {
  197899. if (deviceID.isEmpty())
  197900. return;
  197901. snd_ctl_t* handle;
  197902. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (",", false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197903. {
  197904. snd_pcm_info_t* info;
  197905. snd_pcm_info_alloca (&info);
  197906. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197907. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (",", false, false).getIntValue());
  197908. snd_pcm_info_set_subdevice (info, 0);
  197909. if (snd_ctl_pcm_info (handle, info) >= 0)
  197910. {
  197911. snd_pcm_t* pcmHandle;
  197912. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197913. {
  197914. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197915. getDeviceSampleRates (pcmHandle, rates);
  197916. snd_pcm_close (pcmHandle);
  197917. }
  197918. }
  197919. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197920. if (snd_ctl_pcm_info (handle, info) >= 0)
  197921. {
  197922. snd_pcm_t* pcmHandle;
  197923. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197924. {
  197925. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197926. if (rates.size() == 0)
  197927. getDeviceSampleRates (pcmHandle, rates);
  197928. snd_pcm_close (pcmHandle);
  197929. }
  197930. }
  197931. snd_ctl_close (handle);
  197932. }
  197933. }
  197934. class ALSADevice
  197935. {
  197936. public:
  197937. ALSADevice (const String& deviceID,
  197938. const bool forInput)
  197939. : handle (0),
  197940. bitDepth (16),
  197941. numChannelsRunning (0),
  197942. isInput (forInput),
  197943. sampleFormat (AudioDataConverters::int16LE)
  197944. {
  197945. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  197946. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  197947. SND_PCM_ASYNC));
  197948. }
  197949. ~ALSADevice()
  197950. {
  197951. if (handle != 0)
  197952. snd_pcm_close (handle);
  197953. }
  197954. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  197955. {
  197956. if (handle == 0)
  197957. return false;
  197958. snd_pcm_hw_params_t* hwParams;
  197959. snd_pcm_hw_params_alloca (&hwParams);
  197960. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  197961. return false;
  197962. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  197963. isInterleaved = false;
  197964. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  197965. isInterleaved = true;
  197966. else
  197967. {
  197968. jassertfalse
  197969. return false;
  197970. }
  197971. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  197972. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  197973. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  197974. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  197975. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  197976. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  197977. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  197978. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  197979. bitDepth = 0;
  197980. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  197981. {
  197982. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  197983. {
  197984. bitDepth = formatsToTry [i + 1];
  197985. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  197986. break;
  197987. }
  197988. }
  197989. if (bitDepth == 0)
  197990. {
  197991. error = "device doesn't support a compatible PCM format";
  197992. DBG ("ALSA error: " + error + "\n");
  197993. return false;
  197994. }
  197995. int dir = 0;
  197996. unsigned int periods = 4;
  197997. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  197998. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  197999. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198000. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198001. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198002. || failed (snd_pcm_hw_params (handle, hwParams)))
  198003. {
  198004. return false;
  198005. }
  198006. snd_pcm_sw_params_t* swParams;
  198007. snd_pcm_sw_params_alloca (&swParams);
  198008. snd_pcm_uframes_t boundary;
  198009. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198010. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198011. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198012. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198013. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198014. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198015. || failed (snd_pcm_sw_params (handle, swParams)))
  198016. {
  198017. return false;
  198018. }
  198019. numChannelsRunning = numChannels;
  198020. return true;
  198021. }
  198022. bool write (float** const data, const int numSamples)
  198023. {
  198024. if (isInterleaved)
  198025. {
  198026. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198027. float* interleaved = static_cast <float*> (scratch.getData());
  198028. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198029. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198030. snd_pcm_sframes_t num = snd_pcm_writei (handle, interleaved, numSamples);
  198031. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198032. return false;
  198033. }
  198034. else
  198035. {
  198036. for (int i = 0; i < numChannelsRunning; ++i)
  198037. if (data[i] != 0)
  198038. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198039. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198040. if (failed (num))
  198041. {
  198042. if (num == -EPIPE)
  198043. {
  198044. if (failed (snd_pcm_prepare (handle)))
  198045. return false;
  198046. }
  198047. else if (num != -ESTRPIPE)
  198048. return false;
  198049. }
  198050. }
  198051. return true;
  198052. }
  198053. bool read (float** const data, const int numSamples)
  198054. {
  198055. if (isInterleaved)
  198056. {
  198057. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198058. float* interleaved = static_cast <float*> (scratch.getData());
  198059. snd_pcm_sframes_t num = snd_pcm_readi (handle, interleaved, numSamples);
  198060. if (failed (num))
  198061. {
  198062. if (num == -EPIPE)
  198063. {
  198064. if (failed (snd_pcm_prepare (handle)))
  198065. return false;
  198066. }
  198067. else if (num != -ESTRPIPE)
  198068. return false;
  198069. }
  198070. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198071. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198072. }
  198073. else
  198074. {
  198075. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198076. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198077. return false;
  198078. for (int i = 0; i < numChannelsRunning; ++i)
  198079. if (data[i] != 0)
  198080. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198081. }
  198082. return true;
  198083. }
  198084. juce_UseDebuggingNewOperator
  198085. snd_pcm_t* handle;
  198086. String error;
  198087. int bitDepth, numChannelsRunning;
  198088. private:
  198089. const bool isInput;
  198090. bool isInterleaved;
  198091. MemoryBlock scratch;
  198092. AudioDataConverters::DataFormat sampleFormat;
  198093. bool failed (const int errorNum)
  198094. {
  198095. if (errorNum >= 0)
  198096. return false;
  198097. error = snd_strerror (errorNum);
  198098. DBG ("ALSA error: " + error + "\n");
  198099. return true;
  198100. }
  198101. };
  198102. class ALSAThread : public Thread
  198103. {
  198104. public:
  198105. ALSAThread (const String& inputId_,
  198106. const String& outputId_)
  198107. : Thread ("Juce ALSA"),
  198108. sampleRate (0),
  198109. bufferSize (0),
  198110. callback (0),
  198111. inputId (inputId_),
  198112. outputId (outputId_),
  198113. outputDevice (0),
  198114. inputDevice (0),
  198115. numCallbacks (0),
  198116. totalNumInputChannels (0),
  198117. totalNumOutputChannels (0)
  198118. {
  198119. zeromem (outputChannelData, sizeof (outputChannelData));
  198120. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198121. zeromem (inputChannelData, sizeof (inputChannelData));
  198122. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198123. initialiseRatesAndChannels();
  198124. }
  198125. ~ALSAThread()
  198126. {
  198127. close();
  198128. }
  198129. void open (BigInteger inputChannels,
  198130. BigInteger outputChannels,
  198131. const double sampleRate_,
  198132. const int bufferSize_)
  198133. {
  198134. close();
  198135. error = String::empty;
  198136. sampleRate = sampleRate_;
  198137. bufferSize = bufferSize_;
  198138. currentInputChans.clear();
  198139. currentOutputChans.clear();
  198140. if (inputChannels.getHighestBit() >= 0)
  198141. {
  198142. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198143. {
  198144. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198145. if (inputChannels[i])
  198146. {
  198147. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198148. currentInputChans.setBit (i);
  198149. }
  198150. }
  198151. }
  198152. if (outputChannels.getHighestBit() >= 0)
  198153. {
  198154. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198155. {
  198156. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198157. if (outputChannels[i])
  198158. {
  198159. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198160. currentOutputChans.setBit (i);
  198161. }
  198162. }
  198163. }
  198164. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198165. {
  198166. outputDevice = new ALSADevice (outputId, false);
  198167. if (outputDevice->error.isNotEmpty())
  198168. {
  198169. error = outputDevice->error;
  198170. deleteAndZero (outputDevice);
  198171. return;
  198172. }
  198173. currentOutputChans.setRange (0, minChansOut, true);
  198174. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198175. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198176. bufferSize))
  198177. {
  198178. error = outputDevice->error;
  198179. deleteAndZero (outputDevice);
  198180. return;
  198181. }
  198182. }
  198183. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198184. {
  198185. inputDevice = new ALSADevice (inputId, true);
  198186. if (inputDevice->error.isNotEmpty())
  198187. {
  198188. error = inputDevice->error;
  198189. deleteAndZero (inputDevice);
  198190. return;
  198191. }
  198192. currentInputChans.setRange (0, minChansIn, true);
  198193. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198194. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198195. bufferSize))
  198196. {
  198197. error = inputDevice->error;
  198198. deleteAndZero (inputDevice);
  198199. return;
  198200. }
  198201. }
  198202. if (outputDevice == 0 && inputDevice == 0)
  198203. {
  198204. error = "no channels";
  198205. return;
  198206. }
  198207. if (outputDevice != 0 && inputDevice != 0)
  198208. {
  198209. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198210. }
  198211. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198212. return;
  198213. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198214. return;
  198215. startThread (9);
  198216. int count = 1000;
  198217. while (numCallbacks == 0)
  198218. {
  198219. sleep (5);
  198220. if (--count < 0 || ! isThreadRunning())
  198221. {
  198222. error = "device didn't start";
  198223. break;
  198224. }
  198225. }
  198226. }
  198227. void close()
  198228. {
  198229. stopThread (6000);
  198230. deleteAndZero (inputDevice);
  198231. deleteAndZero (outputDevice);
  198232. for (int i = 0; i < maxNumChans; ++i)
  198233. {
  198234. juce_free (inputChannelData [i]);
  198235. juce_free (outputChannelData [i]);
  198236. }
  198237. zeromem (outputChannelData, sizeof (outputChannelData));
  198238. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198239. zeromem (inputChannelData, sizeof (inputChannelData));
  198240. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198241. totalNumOutputChannels = 0;
  198242. totalNumInputChannels = 0;
  198243. numCallbacks = 0;
  198244. }
  198245. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198246. {
  198247. const ScopedLock sl (callbackLock);
  198248. callback = newCallback;
  198249. }
  198250. void run()
  198251. {
  198252. while (! threadShouldExit())
  198253. {
  198254. if (inputDevice != 0)
  198255. {
  198256. if (! inputDevice->read (inputChannelData, bufferSize))
  198257. {
  198258. DBG ("ALSA: read failure");
  198259. break;
  198260. }
  198261. }
  198262. if (threadShouldExit())
  198263. break;
  198264. {
  198265. const ScopedLock sl (callbackLock);
  198266. ++numCallbacks;
  198267. if (callback != 0)
  198268. {
  198269. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198270. totalNumInputChannels,
  198271. outputChannelDataForCallback,
  198272. totalNumOutputChannels,
  198273. bufferSize);
  198274. }
  198275. else
  198276. {
  198277. for (int i = 0; i < totalNumOutputChannels; ++i)
  198278. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198279. }
  198280. }
  198281. if (outputDevice != 0)
  198282. {
  198283. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198284. if (threadShouldExit())
  198285. break;
  198286. failed (snd_pcm_avail_update (outputDevice->handle));
  198287. if (! outputDevice->write (outputChannelData, bufferSize))
  198288. {
  198289. DBG ("ALSA: write failure");
  198290. break;
  198291. }
  198292. }
  198293. }
  198294. }
  198295. int getBitDepth() const throw()
  198296. {
  198297. if (outputDevice != 0)
  198298. return outputDevice->bitDepth;
  198299. if (inputDevice != 0)
  198300. return inputDevice->bitDepth;
  198301. return 16;
  198302. }
  198303. juce_UseDebuggingNewOperator
  198304. String error;
  198305. double sampleRate;
  198306. int bufferSize;
  198307. BigInteger currentInputChans, currentOutputChans;
  198308. Array <int> sampleRates;
  198309. StringArray channelNamesOut, channelNamesIn;
  198310. AudioIODeviceCallback* callback;
  198311. private:
  198312. const String inputId, outputId;
  198313. ALSADevice* outputDevice;
  198314. ALSADevice* inputDevice;
  198315. int numCallbacks;
  198316. CriticalSection callbackLock;
  198317. float* outputChannelData [maxNumChans];
  198318. float* outputChannelDataForCallback [maxNumChans];
  198319. int totalNumInputChannels;
  198320. float* inputChannelData [maxNumChans];
  198321. float* inputChannelDataForCallback [maxNumChans];
  198322. int totalNumOutputChannels;
  198323. unsigned int minChansOut, maxChansOut;
  198324. unsigned int minChansIn, maxChansIn;
  198325. bool failed (const int errorNum) throw()
  198326. {
  198327. if (errorNum >= 0)
  198328. return false;
  198329. error = snd_strerror (errorNum);
  198330. DBG ("ALSA error: " + error + "\n");
  198331. return true;
  198332. }
  198333. void initialiseRatesAndChannels() throw()
  198334. {
  198335. sampleRates.clear();
  198336. channelNamesOut.clear();
  198337. channelNamesIn.clear();
  198338. minChansOut = 0;
  198339. maxChansOut = 0;
  198340. minChansIn = 0;
  198341. maxChansIn = 0;
  198342. unsigned int dummy = 0;
  198343. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198344. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198345. unsigned int i;
  198346. for (i = 0; i < maxChansOut; ++i)
  198347. channelNamesOut.add ("channel " + String ((int) i + 1));
  198348. for (i = 0; i < maxChansIn; ++i)
  198349. channelNamesIn.add ("channel " + String ((int) i + 1));
  198350. }
  198351. };
  198352. class ALSAAudioIODevice : public AudioIODevice
  198353. {
  198354. public:
  198355. ALSAAudioIODevice (const String& deviceName,
  198356. const String& inputId_,
  198357. const String& outputId_)
  198358. : AudioIODevice (deviceName, "ALSA"),
  198359. inputId (inputId_),
  198360. outputId (outputId_),
  198361. isOpen_ (false),
  198362. isStarted (false),
  198363. internal (0)
  198364. {
  198365. internal = new ALSAThread (inputId, outputId);
  198366. }
  198367. ~ALSAAudioIODevice()
  198368. {
  198369. delete internal;
  198370. }
  198371. const StringArray getOutputChannelNames()
  198372. {
  198373. return internal->channelNamesOut;
  198374. }
  198375. const StringArray getInputChannelNames()
  198376. {
  198377. return internal->channelNamesIn;
  198378. }
  198379. int getNumSampleRates()
  198380. {
  198381. return internal->sampleRates.size();
  198382. }
  198383. double getSampleRate (int index)
  198384. {
  198385. return internal->sampleRates [index];
  198386. }
  198387. int getNumBufferSizesAvailable()
  198388. {
  198389. return 50;
  198390. }
  198391. int getBufferSizeSamples (int index)
  198392. {
  198393. int n = 16;
  198394. for (int i = 0; i < index; ++i)
  198395. n += n < 64 ? 16
  198396. : (n < 512 ? 32
  198397. : (n < 1024 ? 64
  198398. : (n < 2048 ? 128 : 256)));
  198399. return n;
  198400. }
  198401. int getDefaultBufferSize()
  198402. {
  198403. return 512;
  198404. }
  198405. const String open (const BigInteger& inputChannels,
  198406. const BigInteger& outputChannels,
  198407. double sampleRate,
  198408. int bufferSizeSamples)
  198409. {
  198410. close();
  198411. if (bufferSizeSamples <= 0)
  198412. bufferSizeSamples = getDefaultBufferSize();
  198413. if (sampleRate <= 0)
  198414. {
  198415. for (int i = 0; i < getNumSampleRates(); ++i)
  198416. {
  198417. if (getSampleRate (i) >= 44100)
  198418. {
  198419. sampleRate = getSampleRate (i);
  198420. break;
  198421. }
  198422. }
  198423. }
  198424. internal->open (inputChannels, outputChannels,
  198425. sampleRate, bufferSizeSamples);
  198426. isOpen_ = internal->error.isEmpty();
  198427. return internal->error;
  198428. }
  198429. void close()
  198430. {
  198431. stop();
  198432. internal->close();
  198433. isOpen_ = false;
  198434. }
  198435. bool isOpen()
  198436. {
  198437. return isOpen_;
  198438. }
  198439. int getCurrentBufferSizeSamples()
  198440. {
  198441. return internal->bufferSize;
  198442. }
  198443. double getCurrentSampleRate()
  198444. {
  198445. return internal->sampleRate;
  198446. }
  198447. int getCurrentBitDepth()
  198448. {
  198449. return internal->getBitDepth();
  198450. }
  198451. const BigInteger getActiveOutputChannels() const
  198452. {
  198453. return internal->currentOutputChans;
  198454. }
  198455. const BigInteger getActiveInputChannels() const
  198456. {
  198457. return internal->currentInputChans;
  198458. }
  198459. int getOutputLatencyInSamples()
  198460. {
  198461. return 0;
  198462. }
  198463. int getInputLatencyInSamples()
  198464. {
  198465. return 0;
  198466. }
  198467. void start (AudioIODeviceCallback* callback)
  198468. {
  198469. if (! isOpen_)
  198470. callback = 0;
  198471. internal->setCallback (callback);
  198472. if (callback != 0)
  198473. callback->audioDeviceAboutToStart (this);
  198474. isStarted = (callback != 0);
  198475. }
  198476. void stop()
  198477. {
  198478. AudioIODeviceCallback* const oldCallback = internal->callback;
  198479. start (0);
  198480. if (oldCallback != 0)
  198481. oldCallback->audioDeviceStopped();
  198482. }
  198483. bool isPlaying()
  198484. {
  198485. return isStarted && internal->error.isEmpty();
  198486. }
  198487. const String getLastError()
  198488. {
  198489. return internal->error;
  198490. }
  198491. String inputId, outputId;
  198492. private:
  198493. bool isOpen_, isStarted;
  198494. ALSAThread* internal;
  198495. };
  198496. class ALSAAudioIODeviceType : public AudioIODeviceType
  198497. {
  198498. public:
  198499. ALSAAudioIODeviceType()
  198500. : AudioIODeviceType ("ALSA"),
  198501. hasScanned (false)
  198502. {
  198503. }
  198504. ~ALSAAudioIODeviceType()
  198505. {
  198506. }
  198507. void scanForDevices()
  198508. {
  198509. if (hasScanned)
  198510. return;
  198511. hasScanned = true;
  198512. inputNames.clear();
  198513. inputIds.clear();
  198514. outputNames.clear();
  198515. outputIds.clear();
  198516. snd_ctl_t* handle;
  198517. snd_ctl_card_info_t* info;
  198518. snd_ctl_card_info_alloca (&info);
  198519. int cardNum = -1;
  198520. while (outputIds.size() + inputIds.size() <= 32)
  198521. {
  198522. snd_card_next (&cardNum);
  198523. if (cardNum < 0)
  198524. break;
  198525. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198526. {
  198527. if (snd_ctl_card_info (handle, info) >= 0)
  198528. {
  198529. String cardId (snd_ctl_card_info_get_id (info));
  198530. if (cardId.removeCharacters ("0123456789").isEmpty())
  198531. cardId = String (cardNum);
  198532. int device = -1;
  198533. for (;;)
  198534. {
  198535. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198536. break;
  198537. String id, name;
  198538. id << "hw:" << cardId << ',' << device;
  198539. bool isInput, isOutput;
  198540. if (testDevice (id, isInput, isOutput))
  198541. {
  198542. name << snd_ctl_card_info_get_name (info);
  198543. if (name.isEmpty())
  198544. name = id;
  198545. if (isInput)
  198546. {
  198547. inputNames.add (name);
  198548. inputIds.add (id);
  198549. }
  198550. if (isOutput)
  198551. {
  198552. outputNames.add (name);
  198553. outputIds.add (id);
  198554. }
  198555. }
  198556. }
  198557. }
  198558. snd_ctl_close (handle);
  198559. }
  198560. }
  198561. inputNames.appendNumbersToDuplicates (false, true);
  198562. outputNames.appendNumbersToDuplicates (false, true);
  198563. }
  198564. const StringArray getDeviceNames (bool wantInputNames) const
  198565. {
  198566. jassert (hasScanned); // need to call scanForDevices() before doing this
  198567. return wantInputNames ? inputNames : outputNames;
  198568. }
  198569. int getDefaultDeviceIndex (bool forInput) const
  198570. {
  198571. jassert (hasScanned); // need to call scanForDevices() before doing this
  198572. return 0;
  198573. }
  198574. bool hasSeparateInputsAndOutputs() const { return true; }
  198575. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198576. {
  198577. jassert (hasScanned); // need to call scanForDevices() before doing this
  198578. ALSAAudioIODevice* d = dynamic_cast <ALSAAudioIODevice*> (device);
  198579. if (d == 0)
  198580. return -1;
  198581. return asInput ? inputIds.indexOf (d->inputId)
  198582. : outputIds.indexOf (d->outputId);
  198583. }
  198584. AudioIODevice* createDevice (const String& outputDeviceName,
  198585. const String& inputDeviceName)
  198586. {
  198587. jassert (hasScanned); // need to call scanForDevices() before doing this
  198588. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198589. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198590. String deviceName (outputIndex >= 0 ? outputDeviceName
  198591. : inputDeviceName);
  198592. if (inputIndex >= 0 || outputIndex >= 0)
  198593. return new ALSAAudioIODevice (deviceName,
  198594. inputIds [inputIndex],
  198595. outputIds [outputIndex]);
  198596. return 0;
  198597. }
  198598. juce_UseDebuggingNewOperator
  198599. private:
  198600. StringArray inputNames, outputNames, inputIds, outputIds;
  198601. bool hasScanned;
  198602. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198603. {
  198604. unsigned int minChansOut = 0, maxChansOut = 0;
  198605. unsigned int minChansIn = 0, maxChansIn = 0;
  198606. Array <int> rates;
  198607. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198608. DBG ("ALSA device: " + id
  198609. + " outs=" + String ((int) minChansOut) + "-" + String ((int) maxChansOut)
  198610. + " ins=" + String ((int) minChansIn) + "-" + String ((int) maxChansIn)
  198611. + " rates=" + String (rates.size()));
  198612. isInput = maxChansIn > 0;
  198613. isOutput = maxChansOut > 0;
  198614. return (isInput || isOutput) && rates.size() > 0;
  198615. }
  198616. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198617. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198618. };
  198619. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198620. {
  198621. return new ALSAAudioIODeviceType();
  198622. }
  198623. #endif
  198624. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198625. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198626. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198627. // compiled on its own).
  198628. #ifdef JUCE_INCLUDED_FILE
  198629. #if JUCE_JACK
  198630. static void* juce_libjack_handle = 0;
  198631. void* juce_load_jack_function (const char* const name)
  198632. {
  198633. if (juce_libjack_handle == 0)
  198634. return 0;
  198635. return dlsym (juce_libjack_handle, name);
  198636. }
  198637. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198638. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198639. return_type fn_name argument_types { \
  198640. static fn_name##_ptr_t fn = 0; \
  198641. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198642. if (fn) return (*fn)arguments; \
  198643. else return 0; \
  198644. }
  198645. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198646. typedef void (*fn_name##_ptr_t)argument_types; \
  198647. void fn_name argument_types { \
  198648. static fn_name##_ptr_t fn = 0; \
  198649. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198650. if (fn) (*fn)arguments; \
  198651. }
  198652. 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));
  198653. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198654. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198655. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198656. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198657. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198658. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198659. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198660. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198661. 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));
  198662. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198663. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198664. 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));
  198665. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198666. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198667. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198668. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198669. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198670. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198671. #if JUCE_DEBUG
  198672. #define JACK_LOGGING_ENABLED 1
  198673. #endif
  198674. #if JACK_LOGGING_ENABLED
  198675. static void jack_Log (const String& s)
  198676. {
  198677. std::cerr << s << std::endl;
  198678. }
  198679. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198680. {
  198681. if (status & JackServerFailed || status & JackServerError)
  198682. jack_Log ("Unable to connect to JACK server");
  198683. if (status & JackVersionError)
  198684. jack_Log ("Client's protocol version does not match");
  198685. if (status & JackInvalidOption)
  198686. jack_Log ("The operation contained an invalid or unsupported option");
  198687. if (status & JackNameNotUnique)
  198688. jack_Log ("The desired client name was not unique");
  198689. if (status & JackNoSuchClient)
  198690. jack_Log ("Requested client does not exist");
  198691. if (status & JackInitFailure)
  198692. jack_Log ("Unable to initialize client");
  198693. }
  198694. #else
  198695. #define dumpJackErrorMessage(a) {}
  198696. #define jack_Log(...) {}
  198697. #endif
  198698. #ifndef JUCE_JACK_CLIENT_NAME
  198699. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198700. #endif
  198701. class JackAudioIODevice : public AudioIODevice
  198702. {
  198703. public:
  198704. JackAudioIODevice (const String& deviceName,
  198705. const String& inputId_,
  198706. const String& outputId_)
  198707. : AudioIODevice (deviceName, "JACK"),
  198708. inputId (inputId_),
  198709. outputId (outputId_),
  198710. isOpen_ (false),
  198711. callback (0),
  198712. totalNumberOfInputChannels (0),
  198713. totalNumberOfOutputChannels (0)
  198714. {
  198715. jassert (deviceName.isNotEmpty());
  198716. jack_status_t status;
  198717. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198718. if (client == 0)
  198719. {
  198720. dumpJackErrorMessage (status);
  198721. }
  198722. else
  198723. {
  198724. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198725. // open input ports
  198726. const StringArray inputChannels (getInputChannelNames());
  198727. for (int i = 0; i < inputChannels.size(); i++)
  198728. {
  198729. String inputName;
  198730. inputName << "in_" << ++totalNumberOfInputChannels;
  198731. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198732. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198733. }
  198734. // open output ports
  198735. const StringArray outputChannels (getOutputChannelNames());
  198736. for (int i = 0; i < outputChannels.size (); i++)
  198737. {
  198738. String outputName;
  198739. outputName << "out_" << ++totalNumberOfOutputChannels;
  198740. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198741. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198742. }
  198743. inChans.calloc (totalNumberOfInputChannels + 2);
  198744. outChans.calloc (totalNumberOfOutputChannels + 2);
  198745. }
  198746. }
  198747. ~JackAudioIODevice()
  198748. {
  198749. close();
  198750. if (client != 0)
  198751. {
  198752. JUCE_NAMESPACE::jack_client_close (client);
  198753. client = 0;
  198754. }
  198755. }
  198756. const StringArray getChannelNames (bool forInput) const
  198757. {
  198758. StringArray names;
  198759. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198760. forInput ? JackPortIsInput : JackPortIsOutput);
  198761. if (ports != 0)
  198762. {
  198763. int j = 0;
  198764. while (ports[j] != 0)
  198765. {
  198766. const String portName (ports [j++]);
  198767. if (portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198768. names.add (portName.fromFirstOccurrenceOf (":", false, false));
  198769. }
  198770. free (ports);
  198771. }
  198772. return names;
  198773. }
  198774. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198775. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198776. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198777. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198778. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198779. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198780. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198781. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198782. double sampleRate, int bufferSizeSamples)
  198783. {
  198784. if (client == 0)
  198785. {
  198786. lastError = "No JACK client running";
  198787. return lastError;
  198788. }
  198789. lastError = String::empty;
  198790. close();
  198791. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198792. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198793. JUCE_NAMESPACE::jack_activate (client);
  198794. isOpen_ = true;
  198795. if (! inputChannels.isZero())
  198796. {
  198797. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198798. if (ports != 0)
  198799. {
  198800. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198801. for (int i = 0; i < numInputChannels; ++i)
  198802. {
  198803. const String portName (ports[i]);
  198804. if (inputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198805. {
  198806. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198807. if (error != 0)
  198808. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198809. }
  198810. }
  198811. free (ports);
  198812. }
  198813. }
  198814. if (! outputChannels.isZero())
  198815. {
  198816. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198817. if (ports != 0)
  198818. {
  198819. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198820. for (int i = 0; i < numOutputChannels; ++i)
  198821. {
  198822. const String portName (ports[i]);
  198823. if (outputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198824. {
  198825. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198826. if (error != 0)
  198827. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198828. }
  198829. }
  198830. free (ports);
  198831. }
  198832. }
  198833. return lastError;
  198834. }
  198835. void close()
  198836. {
  198837. stop();
  198838. if (client != 0)
  198839. {
  198840. JUCE_NAMESPACE::jack_deactivate (client);
  198841. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198842. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198843. }
  198844. isOpen_ = false;
  198845. }
  198846. void start (AudioIODeviceCallback* newCallback)
  198847. {
  198848. if (isOpen_ && newCallback != callback)
  198849. {
  198850. if (newCallback != 0)
  198851. newCallback->audioDeviceAboutToStart (this);
  198852. AudioIODeviceCallback* const oldCallback = callback;
  198853. {
  198854. const ScopedLock sl (callbackLock);
  198855. callback = newCallback;
  198856. }
  198857. if (oldCallback != 0)
  198858. oldCallback->audioDeviceStopped();
  198859. }
  198860. }
  198861. void stop()
  198862. {
  198863. start (0);
  198864. }
  198865. bool isOpen() { return isOpen_; }
  198866. bool isPlaying() { return callback != 0; }
  198867. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198868. double getCurrentSampleRate() { return getSampleRate (0); }
  198869. int getCurrentBitDepth() { return 32; }
  198870. const String getLastError() { return lastError; }
  198871. const BigInteger getActiveOutputChannels() const
  198872. {
  198873. BigInteger outputBits;
  198874. for (int i = 0; i < outputPorts.size(); i++)
  198875. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198876. outputBits.setBit (i);
  198877. return outputBits;
  198878. }
  198879. const BigInteger getActiveInputChannels() const
  198880. {
  198881. BigInteger inputBits;
  198882. for (int i = 0; i < inputPorts.size(); i++)
  198883. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198884. inputBits.setBit (i);
  198885. return inputBits;
  198886. }
  198887. int getOutputLatencyInSamples()
  198888. {
  198889. int latency = 0;
  198890. for (int i = 0; i < outputPorts.size(); i++)
  198891. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198892. return latency;
  198893. }
  198894. int getInputLatencyInSamples()
  198895. {
  198896. int latency = 0;
  198897. for (int i = 0; i < inputPorts.size(); i++)
  198898. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198899. return latency;
  198900. }
  198901. String inputId, outputId;
  198902. private:
  198903. void process (const int numSamples)
  198904. {
  198905. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198906. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198907. {
  198908. jack_default_audio_sample_t* in
  198909. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198910. if (in != 0)
  198911. inChans [numActiveInChans++] = (float*) in;
  198912. }
  198913. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198914. {
  198915. jack_default_audio_sample_t* out
  198916. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198917. if (out != 0)
  198918. outChans [numActiveOutChans++] = (float*) out;
  198919. }
  198920. const ScopedLock sl (callbackLock);
  198921. if (callback != 0)
  198922. {
  198923. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198924. outChans, numActiveOutChans, numSamples);
  198925. }
  198926. else
  198927. {
  198928. for (i = 0; i < numActiveOutChans; ++i)
  198929. zeromem (outChans[i], sizeof (float) * numSamples);
  198930. }
  198931. }
  198932. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198933. {
  198934. if (callbackArgument != 0)
  198935. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198936. return 0;
  198937. }
  198938. static void threadInitCallback (void* callbackArgument)
  198939. {
  198940. jack_Log ("JackAudioIODevice::initialise");
  198941. }
  198942. static void shutdownCallback (void* callbackArgument)
  198943. {
  198944. jack_Log ("JackAudioIODevice::shutdown");
  198945. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  198946. if (device != 0)
  198947. {
  198948. device->client = 0;
  198949. device->close();
  198950. }
  198951. }
  198952. static void errorCallback (const char* msg)
  198953. {
  198954. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  198955. }
  198956. bool isOpen_;
  198957. jack_client_t* client;
  198958. String lastError;
  198959. AudioIODeviceCallback* callback;
  198960. CriticalSection callbackLock;
  198961. HeapBlock <float*> inChans, outChans;
  198962. int totalNumberOfInputChannels;
  198963. int totalNumberOfOutputChannels;
  198964. VoidArray inputPorts, outputPorts;
  198965. };
  198966. class JackAudioIODeviceType : public AudioIODeviceType
  198967. {
  198968. public:
  198969. JackAudioIODeviceType()
  198970. : AudioIODeviceType ("JACK"),
  198971. hasScanned (false)
  198972. {
  198973. }
  198974. ~JackAudioIODeviceType()
  198975. {
  198976. }
  198977. void scanForDevices()
  198978. {
  198979. hasScanned = true;
  198980. inputNames.clear();
  198981. inputIds.clear();
  198982. outputNames.clear();
  198983. outputIds.clear();
  198984. if (juce_libjack_handle == 0)
  198985. {
  198986. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  198987. if (juce_libjack_handle == 0)
  198988. return;
  198989. }
  198990. // open a dummy client
  198991. jack_status_t status;
  198992. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  198993. if (client == 0)
  198994. {
  198995. dumpJackErrorMessage (status);
  198996. }
  198997. else
  198998. {
  198999. // scan for output devices
  199000. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199001. if (ports != 0)
  199002. {
  199003. int j = 0;
  199004. while (ports[j] != 0)
  199005. {
  199006. String clientName (ports[j]);
  199007. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  199008. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199009. && ! inputNames.contains (clientName))
  199010. {
  199011. inputNames.add (clientName);
  199012. inputIds.add (ports [j]);
  199013. }
  199014. ++j;
  199015. }
  199016. free (ports);
  199017. }
  199018. // scan for input devices
  199019. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199020. if (ports != 0)
  199021. {
  199022. int j = 0;
  199023. while (ports[j] != 0)
  199024. {
  199025. String clientName (ports[j]);
  199026. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  199027. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199028. && ! outputNames.contains (clientName))
  199029. {
  199030. outputNames.add (clientName);
  199031. outputIds.add (ports [j]);
  199032. }
  199033. ++j;
  199034. }
  199035. free (ports);
  199036. }
  199037. JUCE_NAMESPACE::jack_client_close (client);
  199038. }
  199039. }
  199040. const StringArray getDeviceNames (bool wantInputNames) const
  199041. {
  199042. jassert (hasScanned); // need to call scanForDevices() before doing this
  199043. return wantInputNames ? inputNames : outputNames;
  199044. }
  199045. int getDefaultDeviceIndex (bool forInput) const
  199046. {
  199047. jassert (hasScanned); // need to call scanForDevices() before doing this
  199048. return 0;
  199049. }
  199050. bool hasSeparateInputsAndOutputs() const { return true; }
  199051. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  199052. {
  199053. jassert (hasScanned); // need to call scanForDevices() before doing this
  199054. JackAudioIODevice* d = dynamic_cast <JackAudioIODevice*> (device);
  199055. if (d == 0)
  199056. return -1;
  199057. return asInput ? inputIds.indexOf (d->inputId)
  199058. : outputIds.indexOf (d->outputId);
  199059. }
  199060. AudioIODevice* createDevice (const String& outputDeviceName,
  199061. const String& inputDeviceName)
  199062. {
  199063. jassert (hasScanned); // need to call scanForDevices() before doing this
  199064. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199065. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199066. if (inputIndex >= 0 || outputIndex >= 0)
  199067. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199068. : inputDeviceName,
  199069. inputIds [inputIndex],
  199070. outputIds [outputIndex]);
  199071. return 0;
  199072. }
  199073. juce_UseDebuggingNewOperator
  199074. private:
  199075. StringArray inputNames, outputNames, inputIds, outputIds;
  199076. bool hasScanned;
  199077. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199078. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199079. };
  199080. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199081. {
  199082. return new JackAudioIODeviceType();
  199083. }
  199084. #else // if JACK is turned off..
  199085. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199086. #endif
  199087. #endif
  199088. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199089. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199090. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199091. // compiled on its own).
  199092. #if JUCE_INCLUDED_FILE
  199093. #if JUCE_ALSA
  199094. static snd_seq_t* iterateDevices (const bool forInput,
  199095. StringArray& deviceNamesFound,
  199096. const int deviceIndexToOpen)
  199097. {
  199098. snd_seq_t* returnedHandle = 0;
  199099. snd_seq_t* seqHandle;
  199100. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199101. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199102. {
  199103. snd_seq_system_info_t* systemInfo;
  199104. snd_seq_client_info_t* clientInfo;
  199105. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199106. {
  199107. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199108. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199109. {
  199110. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199111. while (--numClients >= 0 && returnedHandle == 0)
  199112. {
  199113. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199114. {
  199115. snd_seq_port_info_t* portInfo;
  199116. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199117. {
  199118. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199119. const int client = snd_seq_client_info_get_client (clientInfo);
  199120. snd_seq_port_info_set_client (portInfo, client);
  199121. snd_seq_port_info_set_port (portInfo, -1);
  199122. while (--numPorts >= 0)
  199123. {
  199124. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199125. && (snd_seq_port_info_get_capability (portInfo)
  199126. & (forInput ? SND_SEQ_PORT_CAP_READ
  199127. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199128. {
  199129. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199130. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199131. {
  199132. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199133. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199134. if (sourcePort != -1)
  199135. {
  199136. snd_seq_set_client_name (seqHandle,
  199137. forInput ? "Juce Midi Input"
  199138. : "Juce Midi Output");
  199139. const int portId
  199140. = snd_seq_create_simple_port (seqHandle,
  199141. forInput ? "Juce Midi In Port"
  199142. : "Juce Midi Out Port",
  199143. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199144. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199145. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199146. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199147. returnedHandle = seqHandle;
  199148. }
  199149. }
  199150. }
  199151. }
  199152. snd_seq_port_info_free (portInfo);
  199153. }
  199154. }
  199155. }
  199156. snd_seq_client_info_free (clientInfo);
  199157. }
  199158. snd_seq_system_info_free (systemInfo);
  199159. }
  199160. if (returnedHandle == 0)
  199161. snd_seq_close (seqHandle);
  199162. }
  199163. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199164. return returnedHandle;
  199165. }
  199166. static snd_seq_t* createDevice (const bool forInput,
  199167. const String& deviceNameToOpen)
  199168. {
  199169. snd_seq_t* seqHandle = 0;
  199170. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199171. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199172. {
  199173. snd_seq_set_client_name (seqHandle,
  199174. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199175. const int portId
  199176. = snd_seq_create_simple_port (seqHandle,
  199177. forInput ? "in"
  199178. : "out",
  199179. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199180. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199181. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199182. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199183. if (portId < 0)
  199184. {
  199185. snd_seq_close (seqHandle);
  199186. seqHandle = 0;
  199187. }
  199188. }
  199189. return seqHandle;
  199190. }
  199191. class MidiOutputDevice
  199192. {
  199193. public:
  199194. MidiOutputDevice (MidiOutput* const midiOutput_,
  199195. snd_seq_t* const seqHandle_)
  199196. :
  199197. midiOutput (midiOutput_),
  199198. seqHandle (seqHandle_),
  199199. maxEventSize (16 * 1024)
  199200. {
  199201. jassert (seqHandle != 0 && midiOutput != 0);
  199202. snd_midi_event_new (maxEventSize, &midiParser);
  199203. }
  199204. ~MidiOutputDevice()
  199205. {
  199206. snd_midi_event_free (midiParser);
  199207. snd_seq_close (seqHandle);
  199208. }
  199209. void sendMessageNow (const MidiMessage& message)
  199210. {
  199211. if (message.getRawDataSize() > maxEventSize)
  199212. {
  199213. maxEventSize = message.getRawDataSize();
  199214. snd_midi_event_free (midiParser);
  199215. snd_midi_event_new (maxEventSize, &midiParser);
  199216. }
  199217. snd_seq_event_t event;
  199218. snd_seq_ev_clear (&event);
  199219. snd_midi_event_encode (midiParser,
  199220. message.getRawData(),
  199221. message.getRawDataSize(),
  199222. &event);
  199223. snd_midi_event_reset_encode (midiParser);
  199224. snd_seq_ev_set_source (&event, 0);
  199225. snd_seq_ev_set_subs (&event);
  199226. snd_seq_ev_set_direct (&event);
  199227. snd_seq_event_output (seqHandle, &event);
  199228. snd_seq_drain_output (seqHandle);
  199229. }
  199230. juce_UseDebuggingNewOperator
  199231. private:
  199232. MidiOutput* const midiOutput;
  199233. snd_seq_t* const seqHandle;
  199234. snd_midi_event_t* midiParser;
  199235. int maxEventSize;
  199236. };
  199237. const StringArray MidiOutput::getDevices()
  199238. {
  199239. StringArray devices;
  199240. iterateDevices (false, devices, -1);
  199241. return devices;
  199242. }
  199243. int MidiOutput::getDefaultDeviceIndex()
  199244. {
  199245. return 0;
  199246. }
  199247. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199248. {
  199249. MidiOutput* newDevice = 0;
  199250. StringArray devices;
  199251. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199252. if (handle != 0)
  199253. {
  199254. newDevice = new MidiOutput();
  199255. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199256. }
  199257. return newDevice;
  199258. }
  199259. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199260. {
  199261. MidiOutput* newDevice = 0;
  199262. snd_seq_t* const handle = createDevice (false, deviceName);
  199263. if (handle != 0)
  199264. {
  199265. newDevice = new MidiOutput();
  199266. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199267. }
  199268. return newDevice;
  199269. }
  199270. MidiOutput::~MidiOutput()
  199271. {
  199272. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199273. delete device;
  199274. }
  199275. void MidiOutput::reset()
  199276. {
  199277. }
  199278. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199279. {
  199280. return false;
  199281. }
  199282. void MidiOutput::setVolume (float leftVol, float rightVol)
  199283. {
  199284. }
  199285. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199286. {
  199287. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199288. }
  199289. class MidiInputThread : public Thread
  199290. {
  199291. public:
  199292. MidiInputThread (MidiInput* const midiInput_,
  199293. snd_seq_t* const seqHandle_,
  199294. MidiInputCallback* const callback_)
  199295. : Thread ("Juce MIDI Input"),
  199296. midiInput (midiInput_),
  199297. seqHandle (seqHandle_),
  199298. callback (callback_)
  199299. {
  199300. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199301. }
  199302. ~MidiInputThread()
  199303. {
  199304. snd_seq_close (seqHandle);
  199305. }
  199306. void run()
  199307. {
  199308. const int maxEventSize = 16 * 1024;
  199309. snd_midi_event_t* midiParser;
  199310. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199311. {
  199312. HeapBlock <uint8> buffer (maxEventSize);
  199313. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199314. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199315. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199316. while (! threadShouldExit())
  199317. {
  199318. if (poll (pfd, numPfds, 500) > 0)
  199319. {
  199320. snd_seq_event_t* inputEvent = 0;
  199321. snd_seq_nonblock (seqHandle, 1);
  199322. do
  199323. {
  199324. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199325. {
  199326. // xxx what about SYSEXes that are too big for the buffer?
  199327. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199328. snd_midi_event_reset_decode (midiParser);
  199329. if (numBytes > 0)
  199330. {
  199331. const MidiMessage message ((const uint8*) buffer,
  199332. numBytes,
  199333. Time::getMillisecondCounter() * 0.001);
  199334. callback->handleIncomingMidiMessage (midiInput, message);
  199335. }
  199336. snd_seq_free_event (inputEvent);
  199337. }
  199338. }
  199339. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199340. snd_seq_free_event (inputEvent);
  199341. }
  199342. }
  199343. snd_midi_event_free (midiParser);
  199344. }
  199345. };
  199346. juce_UseDebuggingNewOperator
  199347. private:
  199348. MidiInput* const midiInput;
  199349. snd_seq_t* const seqHandle;
  199350. MidiInputCallback* const callback;
  199351. };
  199352. MidiInput::MidiInput (const String& name_)
  199353. : name (name_),
  199354. internal (0)
  199355. {
  199356. }
  199357. MidiInput::~MidiInput()
  199358. {
  199359. stop();
  199360. MidiInputThread* const thread = (MidiInputThread*) internal;
  199361. delete thread;
  199362. }
  199363. void MidiInput::start()
  199364. {
  199365. ((MidiInputThread*) internal)->startThread();
  199366. }
  199367. void MidiInput::stop()
  199368. {
  199369. ((MidiInputThread*) internal)->stopThread (3000);
  199370. }
  199371. int MidiInput::getDefaultDeviceIndex()
  199372. {
  199373. return 0;
  199374. }
  199375. const StringArray MidiInput::getDevices()
  199376. {
  199377. StringArray devices;
  199378. iterateDevices (true, devices, -1);
  199379. return devices;
  199380. }
  199381. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199382. {
  199383. MidiInput* newDevice = 0;
  199384. StringArray devices;
  199385. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199386. if (handle != 0)
  199387. {
  199388. newDevice = new MidiInput (devices [deviceIndex]);
  199389. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199390. }
  199391. return newDevice;
  199392. }
  199393. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199394. {
  199395. MidiInput* newDevice = 0;
  199396. snd_seq_t* const handle = createDevice (true, deviceName);
  199397. if (handle != 0)
  199398. {
  199399. newDevice = new MidiInput (deviceName);
  199400. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199401. }
  199402. return newDevice;
  199403. }
  199404. #else
  199405. // (These are just stub functions if ALSA is unavailable...)
  199406. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199407. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199408. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199409. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199410. MidiOutput::~MidiOutput() {}
  199411. void MidiOutput::reset() {}
  199412. bool MidiOutput::getVolume (float&, float&) { return false; }
  199413. void MidiOutput::setVolume (float, float) {}
  199414. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199415. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199416. MidiInput::~MidiInput() {}
  199417. void MidiInput::start() {}
  199418. void MidiInput::stop() {}
  199419. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199420. const StringArray MidiInput::getDevices() { return StringArray(); }
  199421. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199422. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199423. #endif
  199424. #endif
  199425. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199426. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199427. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199428. // compiled on its own).
  199429. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199430. AudioCDReader::AudioCDReader()
  199431. : AudioFormatReader (0, "CD Audio")
  199432. {
  199433. }
  199434. const StringArray AudioCDReader::getAvailableCDNames()
  199435. {
  199436. StringArray names;
  199437. return names;
  199438. }
  199439. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199440. {
  199441. return 0;
  199442. }
  199443. AudioCDReader::~AudioCDReader()
  199444. {
  199445. }
  199446. void AudioCDReader::refreshTrackLengths()
  199447. {
  199448. }
  199449. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199450. int64 startSampleInFile, int numSamples)
  199451. {
  199452. return false;
  199453. }
  199454. bool AudioCDReader::isCDStillPresent() const
  199455. {
  199456. return false;
  199457. }
  199458. int AudioCDReader::getNumTracks() const
  199459. {
  199460. return 0;
  199461. }
  199462. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199463. {
  199464. return 0;
  199465. }
  199466. bool AudioCDReader::isTrackAudio (int trackNum) const
  199467. {
  199468. return false;
  199469. }
  199470. void AudioCDReader::enableIndexScanning (bool b)
  199471. {
  199472. }
  199473. int AudioCDReader::getLastIndex() const
  199474. {
  199475. return 0;
  199476. }
  199477. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199478. {
  199479. return Array<int>();
  199480. }
  199481. int AudioCDReader::getCDDBId()
  199482. {
  199483. return 0;
  199484. }
  199485. #endif
  199486. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199487. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199488. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199489. // compiled on its own).
  199490. #if JUCE_INCLUDED_FILE
  199491. void FileChooser::showPlatformDialog (Array<File>& results,
  199492. const String& title,
  199493. const File& file,
  199494. const String& filters,
  199495. bool isDirectory,
  199496. bool selectsFiles,
  199497. bool isSave,
  199498. bool warnAboutOverwritingExistingFiles,
  199499. bool selectMultipleFiles,
  199500. FilePreviewComponent* previewComponent)
  199501. {
  199502. const String separator (":");
  199503. String command ("zenity --file-selection");
  199504. if (title.isNotEmpty())
  199505. command << " --title=\"" << title << "\"";
  199506. if (file != File::nonexistent)
  199507. command << " --filename=\"" << file.getFullPathName () << "\"";
  199508. if (isDirectory)
  199509. command << " --directory";
  199510. if (isSave)
  199511. command << " --save";
  199512. if (selectMultipleFiles)
  199513. command << " --multiple --separator=\"" << separator << "\"";
  199514. command << " 2>&1";
  199515. MemoryOutputStream result;
  199516. int status = -1;
  199517. FILE* stream = popen (command.toUTF8(), "r");
  199518. if (stream != 0)
  199519. {
  199520. for (;;)
  199521. {
  199522. char buffer [1024];
  199523. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199524. if (bytesRead <= 0)
  199525. break;
  199526. result.write (buffer, bytesRead);
  199527. }
  199528. status = pclose (stream);
  199529. }
  199530. if (status == 0)
  199531. {
  199532. StringArray tokens;
  199533. if (selectMultipleFiles)
  199534. tokens.addTokens (result.toUTF8(), separator, String::empty);
  199535. else
  199536. tokens.add (result.toUTF8());
  199537. for (int i = 0; i < tokens.size(); i++)
  199538. results.add (File (tokens[i]));
  199539. return;
  199540. }
  199541. //xxx ain't got one!
  199542. jassertfalse
  199543. }
  199544. #endif
  199545. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199546. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199547. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199548. // compiled on its own).
  199549. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199550. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199551. : browser (0),
  199552. blankPageShown (false),
  199553. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199554. {
  199555. setOpaque (true);
  199556. }
  199557. WebBrowserComponent::~WebBrowserComponent()
  199558. {
  199559. }
  199560. void WebBrowserComponent::goToURL (const String& url,
  199561. const StringArray* headers,
  199562. const MemoryBlock* postData)
  199563. {
  199564. lastURL = url;
  199565. lastHeaders.clear();
  199566. if (headers != 0)
  199567. lastHeaders = *headers;
  199568. lastPostData.setSize (0);
  199569. if (postData != 0)
  199570. lastPostData = *postData;
  199571. blankPageShown = false;
  199572. }
  199573. void WebBrowserComponent::stop()
  199574. {
  199575. }
  199576. void WebBrowserComponent::goBack()
  199577. {
  199578. lastURL = String::empty;
  199579. blankPageShown = false;
  199580. }
  199581. void WebBrowserComponent::goForward()
  199582. {
  199583. lastURL = String::empty;
  199584. }
  199585. void WebBrowserComponent::refresh()
  199586. {
  199587. }
  199588. void WebBrowserComponent::paint (Graphics& g)
  199589. {
  199590. g.fillAll (Colours::white);
  199591. }
  199592. void WebBrowserComponent::checkWindowAssociation()
  199593. {
  199594. }
  199595. void WebBrowserComponent::reloadLastURL()
  199596. {
  199597. if (lastURL.isNotEmpty())
  199598. {
  199599. goToURL (lastURL, &lastHeaders, &lastPostData);
  199600. lastURL = String::empty;
  199601. }
  199602. }
  199603. void WebBrowserComponent::parentHierarchyChanged()
  199604. {
  199605. checkWindowAssociation();
  199606. }
  199607. void WebBrowserComponent::resized()
  199608. {
  199609. }
  199610. void WebBrowserComponent::visibilityChanged()
  199611. {
  199612. checkWindowAssociation();
  199613. }
  199614. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199615. {
  199616. return true;
  199617. }
  199618. #endif
  199619. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199620. #endif
  199621. END_JUCE_NAMESPACE
  199622. #endif
  199623. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199624. #endif
  199625. #if JUCE_MAC || JUCE_IPHONE
  199626. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199627. #if JUCE_MAC || JUCE_IPHONE
  199628. BEGIN_JUCE_NAMESPACE
  199629. #undef Point
  199630. #define JUCE_INCLUDED_FILE 1
  199631. // Now include the actual code files..
  199632. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199633. #ifndef JUCE_ObjCExtraSuffix
  199634. #define JUCE_ObjCExtraSuffix 3
  199635. #endif
  199636. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199637. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199638. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199639. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199640. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199641. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199642. // compiled on its own).
  199643. #if JUCE_INCLUDED_FILE
  199644. static const String nsStringToJuce (NSString* s)
  199645. {
  199646. return String::fromUTF8 ([s UTF8String]);
  199647. }
  199648. static NSString* juceStringToNS (const String& s)
  199649. {
  199650. return [NSString stringWithUTF8String: s.toUTF8()];
  199651. }
  199652. static const String convertUTF16ToString (const UniChar* utf16)
  199653. {
  199654. String s;
  199655. while (*utf16 != 0)
  199656. s += (juce_wchar) *utf16++;
  199657. return s;
  199658. }
  199659. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199660. {
  199661. String result;
  199662. if (cfString != 0)
  199663. {
  199664. CFRange range = { 0, CFStringGetLength (cfString) };
  199665. HeapBlock <UniChar> u (range.length + 1);
  199666. CFStringGetCharacters (cfString, range, u);
  199667. u[range.length] = 0;
  199668. result = convertUTF16ToString (u);
  199669. }
  199670. return result;
  199671. }
  199672. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199673. {
  199674. const int len = s.length();
  199675. HeapBlock <UniChar> temp (len + 2);
  199676. for (int i = 0; i <= len; ++i)
  199677. temp[i] = s[i];
  199678. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199679. }
  199680. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199681. {
  199682. #if JUCE_IPHONE
  199683. const ScopedAutoReleasePool pool;
  199684. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199685. #else
  199686. UnicodeMapping map;
  199687. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199688. kUnicodeNoSubset,
  199689. kTextEncodingDefaultFormat);
  199690. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199691. kUnicodeCanonicalCompVariant,
  199692. kTextEncodingDefaultFormat);
  199693. map.mappingVersion = kUnicodeUseLatestMapping;
  199694. UnicodeToTextInfo conversionInfo = 0;
  199695. String result;
  199696. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199697. {
  199698. const int len = s.length();
  199699. HeapBlock <UniChar> tempIn, tempOut;
  199700. tempIn.calloc (len + 2);
  199701. tempOut.calloc (len + 2);
  199702. for (int i = 0; i <= len; ++i)
  199703. tempIn[i] = s[i];
  199704. ByteCount bytesRead = 0;
  199705. ByteCount outputBufferSize = 0;
  199706. if (ConvertFromUnicodeToText (conversionInfo,
  199707. len * sizeof (UniChar), tempIn,
  199708. kUnicodeDefaultDirectionMask,
  199709. 0, 0, 0, 0,
  199710. len * sizeof (UniChar), &bytesRead,
  199711. &outputBufferSize, tempOut) == noErr)
  199712. {
  199713. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199714. juce_wchar* t = result;
  199715. unsigned int i;
  199716. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199717. t[i] = (juce_wchar) tempOut[i];
  199718. t[i] = 0;
  199719. }
  199720. DisposeUnicodeToTextInfo (&conversionInfo);
  199721. }
  199722. return result;
  199723. #endif
  199724. }
  199725. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199726. void SystemClipboard::copyTextToClipboard (const String& text)
  199727. {
  199728. #if JUCE_IPHONE
  199729. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199730. forPasteboardType: @"public.text"];
  199731. #else
  199732. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199733. owner: nil];
  199734. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199735. forType: NSStringPboardType];
  199736. #endif
  199737. }
  199738. const String SystemClipboard::getTextFromClipboard()
  199739. {
  199740. #if JUCE_IPHONE
  199741. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199742. #else
  199743. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199744. #endif
  199745. return text == 0 ? String::empty
  199746. : nsStringToJuce (text);
  199747. }
  199748. #endif
  199749. #endif
  199750. /*** End of inlined file: juce_mac_Strings.mm ***/
  199751. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199752. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199753. // compiled on its own).
  199754. #if JUCE_INCLUDED_FILE
  199755. namespace SystemStatsHelpers
  199756. {
  199757. static int64 highResTimerFrequency = 0;
  199758. static double highResTimerToMillisecRatio = 0;
  199759. #if JUCE_INTEL
  199760. static void juce_getCpuVendor (char* const v) throw()
  199761. {
  199762. int vendor[4];
  199763. zerostruct (vendor);
  199764. int dummy = 0;
  199765. asm ("mov %%ebx, %%esi \n\t"
  199766. "cpuid \n\t"
  199767. "xchg %%esi, %%ebx"
  199768. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199769. memcpy (v, vendor, 16);
  199770. }
  199771. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199772. {
  199773. unsigned int cpu = 0;
  199774. unsigned int ext = 0;
  199775. unsigned int family = 0;
  199776. unsigned int dummy = 0;
  199777. asm ("mov %%ebx, %%esi \n\t"
  199778. "cpuid \n\t"
  199779. "xchg %%esi, %%ebx"
  199780. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199781. familyModel = family;
  199782. extFeatures = ext;
  199783. return cpu;
  199784. }
  199785. struct CPUFlags
  199786. {
  199787. bool hasMMX : 1;
  199788. bool hasSSE : 1;
  199789. bool hasSSE2 : 1;
  199790. bool has3DNow : 1;
  199791. };
  199792. static CPUFlags cpuFlags;
  199793. #endif
  199794. }
  199795. void SystemStats::initialiseStats() throw()
  199796. {
  199797. using namespace SystemStatsHelpers;
  199798. static bool initialised = false;
  199799. if (! initialised)
  199800. {
  199801. initialised = true;
  199802. #if JUCE_MAC
  199803. // extremely annoying: adding this line stops the apple menu items from working. Of
  199804. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199805. // any events.
  199806. //NSApplicationLoad();
  199807. [NSApplication sharedApplication];
  199808. #endif
  199809. #if JUCE_INTEL
  199810. {
  199811. unsigned int familyModel, extFeatures;
  199812. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199813. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199814. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199815. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199816. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199817. }
  199818. #endif
  199819. mach_timebase_info_data_t timebase;
  199820. (void) mach_timebase_info (&timebase);
  199821. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199822. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199823. String s (SystemStats::getJUCEVersion());
  199824. rlimit lim;
  199825. getrlimit (RLIMIT_NOFILE, &lim);
  199826. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199827. setrlimit (RLIMIT_NOFILE, &lim);
  199828. }
  199829. }
  199830. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199831. {
  199832. return MacOSX;
  199833. }
  199834. const String SystemStats::getOperatingSystemName() throw()
  199835. {
  199836. return "Mac OS X";
  199837. }
  199838. bool SystemStats::isOperatingSystem64Bit() throw()
  199839. {
  199840. #if JUCE_64BIT
  199841. return true;
  199842. #else
  199843. //xxx not sure how to find this out?..
  199844. return false;
  199845. #endif
  199846. }
  199847. int SystemStats::getMemorySizeInMegabytes() throw()
  199848. {
  199849. uint64 mem = 0;
  199850. size_t memSize = sizeof (mem);
  199851. int mib[] = { CTL_HW, HW_MEMSIZE };
  199852. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199853. return (int) (mem / (1024 * 1024));
  199854. }
  199855. bool SystemStats::hasMMX() throw()
  199856. {
  199857. #if JUCE_INTEL
  199858. return SystemStatsHelpers::cpuFlags.hasMMX;
  199859. #else
  199860. return false;
  199861. #endif
  199862. }
  199863. bool SystemStats::hasSSE() throw()
  199864. {
  199865. #if JUCE_INTEL
  199866. return SystemStatsHelpers::cpuFlags.hasSSE;
  199867. #else
  199868. return false;
  199869. #endif
  199870. }
  199871. bool SystemStats::hasSSE2() throw()
  199872. {
  199873. #if JUCE_INTEL
  199874. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199875. #else
  199876. return false;
  199877. #endif
  199878. }
  199879. bool SystemStats::has3DNow() throw()
  199880. {
  199881. #if JUCE_INTEL
  199882. return SystemStatsHelpers::cpuFlags.has3DNow;
  199883. #else
  199884. return false;
  199885. #endif
  199886. }
  199887. const String SystemStats::getCpuVendor() throw()
  199888. {
  199889. #if JUCE_INTEL
  199890. char v [16];
  199891. SystemStatsHelpers::juce_getCpuVendor (v);
  199892. return String (v, 16);
  199893. #else
  199894. return String::empty;
  199895. #endif
  199896. }
  199897. int SystemStats::getCpuSpeedInMegaherz() throw()
  199898. {
  199899. uint64 speedHz = 0;
  199900. size_t speedSize = sizeof (speedHz);
  199901. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199902. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199903. #if JUCE_BIG_ENDIAN
  199904. if (speedSize == 4)
  199905. speedHz >>= 32;
  199906. #endif
  199907. return (int) (speedHz / 1000000);
  199908. }
  199909. int SystemStats::getNumCpus() throw()
  199910. {
  199911. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199912. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199913. #else
  199914. return MPProcessors();
  199915. #endif
  199916. }
  199917. const String SystemStats::getLogonName()
  199918. {
  199919. return nsStringToJuce (NSUserName());
  199920. }
  199921. const String SystemStats::getFullUserName()
  199922. {
  199923. return nsStringToJuce (NSFullUserName());
  199924. }
  199925. uint32 juce_millisecondsSinceStartup() throw()
  199926. {
  199927. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199928. }
  199929. double Time::getMillisecondCounterHiRes() throw()
  199930. {
  199931. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199932. }
  199933. int64 Time::getHighResolutionTicks() throw()
  199934. {
  199935. return (int64) mach_absolute_time();
  199936. }
  199937. int64 Time::getHighResolutionTicksPerSecond() throw()
  199938. {
  199939. return SystemStatsHelpers::highResTimerFrequency;
  199940. }
  199941. int64 SystemStats::getClockCycleCounter() throw()
  199942. {
  199943. return (int64) mach_absolute_time();
  199944. }
  199945. bool Time::setSystemTimeToThisTime() const throw()
  199946. {
  199947. jassertfalse
  199948. return false;
  199949. }
  199950. int SystemStats::getPageSize() throw()
  199951. {
  199952. return (int) NSPageSize();
  199953. }
  199954. void PlatformUtilities::fpuReset()
  199955. {
  199956. }
  199957. #endif
  199958. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  199959. /*** Start of inlined file: juce_mac_Network.mm ***/
  199960. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199961. // compiled on its own).
  199962. #if JUCE_INCLUDED_FILE
  199963. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  199964. {
  199965. #ifndef IFT_ETHER
  199966. #define IFT_ETHER 6
  199967. #endif
  199968. ifaddrs* addrs = 0;
  199969. int numResults = 0;
  199970. if (getifaddrs (&addrs) == 0)
  199971. {
  199972. const ifaddrs* cursor = addrs;
  199973. while (cursor != 0 && numResults < maxNum)
  199974. {
  199975. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  199976. if (sto->ss_family == AF_LINK)
  199977. {
  199978. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  199979. if (sadd->sdl_type == IFT_ETHER)
  199980. {
  199981. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  199982. uint64 a = 0;
  199983. for (int i = 6; --i >= 0;)
  199984. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  199985. *addresses++ = (int64) a;
  199986. ++numResults;
  199987. }
  199988. }
  199989. cursor = cursor->ifa_next;
  199990. }
  199991. freeifaddrs (addrs);
  199992. }
  199993. return numResults;
  199994. }
  199995. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  199996. const String& emailSubject,
  199997. const String& bodyText,
  199998. const StringArray& filesToAttach)
  199999. {
  200000. #if JUCE_IPHONE
  200001. //xxx probably need to use MFMailComposeViewController
  200002. jassertfalse
  200003. return false;
  200004. #else
  200005. const ScopedAutoReleasePool pool;
  200006. String script;
  200007. script << "tell application \"Mail\"\r\n"
  200008. "set newMessage to make new outgoing message with properties {subject:\""
  200009. << emailSubject.replace ("\"", "\\\"")
  200010. << "\", content:\""
  200011. << bodyText.replace ("\"", "\\\"")
  200012. << "\" & return & return}\r\n"
  200013. "tell newMessage\r\n"
  200014. "set visible to true\r\n"
  200015. "set sender to \"sdfsdfsdfewf\"\r\n"
  200016. "make new to recipient at end of to recipients with properties {address:\""
  200017. << targetEmailAddress
  200018. << "\"}\r\n";
  200019. for (int i = 0; i < filesToAttach.size(); ++i)
  200020. {
  200021. script << "tell content\r\n"
  200022. "make new attachment with properties {file name:\""
  200023. << filesToAttach[i].replace ("\"", "\\\"")
  200024. << "\"} at after the last paragraph\r\n"
  200025. "end tell\r\n";
  200026. }
  200027. script << "end tell\r\n"
  200028. "end tell\r\n";
  200029. NSAppleScript* s = [[NSAppleScript alloc]
  200030. initWithSource: juceStringToNS (script)];
  200031. NSDictionary* error = 0;
  200032. const bool ok = [s executeAndReturnError: &error] != nil;
  200033. [s release];
  200034. return ok;
  200035. #endif
  200036. }
  200037. END_JUCE_NAMESPACE
  200038. using namespace JUCE_NAMESPACE;
  200039. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200040. @interface JuceURLConnection : NSObject
  200041. {
  200042. @public
  200043. NSURLRequest* request;
  200044. NSURLConnection* connection;
  200045. NSMutableData* data;
  200046. Thread* runLoopThread;
  200047. bool initialised, hasFailed, hasFinished;
  200048. int position;
  200049. int64 contentLength;
  200050. NSLock* dataLock;
  200051. }
  200052. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200053. - (void) dealloc;
  200054. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200055. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200056. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200057. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200058. - (BOOL) isOpen;
  200059. - (int) read: (char*) dest numBytes: (int) num;
  200060. - (int) readPosition;
  200061. - (void) stop;
  200062. - (void) createConnection;
  200063. @end
  200064. class JuceURLConnectionMessageThread : public Thread
  200065. {
  200066. JuceURLConnection* owner;
  200067. public:
  200068. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200069. : Thread ("http connection"),
  200070. owner (owner_)
  200071. {
  200072. }
  200073. ~JuceURLConnectionMessageThread()
  200074. {
  200075. stopThread (10000);
  200076. }
  200077. void run()
  200078. {
  200079. [owner createConnection];
  200080. while (! threadShouldExit())
  200081. {
  200082. const ScopedAutoReleasePool pool;
  200083. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200084. }
  200085. }
  200086. };
  200087. @implementation JuceURLConnection
  200088. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200089. withCallback: (URL::OpenStreamProgressCallback*) callback
  200090. withContext: (void*) context;
  200091. {
  200092. [super init];
  200093. request = req;
  200094. [request retain];
  200095. data = [[NSMutableData data] retain];
  200096. dataLock = [[NSLock alloc] init];
  200097. connection = 0;
  200098. initialised = false;
  200099. hasFailed = false;
  200100. hasFinished = false;
  200101. contentLength = -1;
  200102. runLoopThread = new JuceURLConnectionMessageThread (self);
  200103. runLoopThread->startThread();
  200104. while (runLoopThread->isThreadRunning() && ! initialised)
  200105. {
  200106. if (callback != 0)
  200107. callback (context, -1, (int) [[request HTTPBody] length]);
  200108. Thread::sleep (1);
  200109. }
  200110. return self;
  200111. }
  200112. - (void) dealloc
  200113. {
  200114. [self stop];
  200115. deleteAndZero (runLoopThread);
  200116. [connection release];
  200117. [data release];
  200118. [dataLock release];
  200119. [request release];
  200120. [super dealloc];
  200121. }
  200122. - (void) createConnection
  200123. {
  200124. connection = [[NSURLConnection alloc] initWithRequest: request
  200125. delegate: [self retain]];
  200126. if (connection == nil)
  200127. runLoopThread->signalThreadShouldExit();
  200128. }
  200129. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200130. {
  200131. [dataLock lock];
  200132. [data setLength: 0];
  200133. [dataLock unlock];
  200134. initialised = true;
  200135. contentLength = [response expectedContentLength];
  200136. }
  200137. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200138. {
  200139. DBG (nsStringToJuce ([error description]));
  200140. hasFailed = true;
  200141. initialised = true;
  200142. if (runLoopThread != 0)
  200143. runLoopThread->signalThreadShouldExit();
  200144. }
  200145. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200146. {
  200147. [dataLock lock];
  200148. [data appendData: newData];
  200149. [dataLock unlock];
  200150. initialised = true;
  200151. }
  200152. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200153. {
  200154. hasFinished = true;
  200155. initialised = true;
  200156. if (runLoopThread != 0)
  200157. runLoopThread->signalThreadShouldExit();
  200158. }
  200159. - (BOOL) isOpen
  200160. {
  200161. return connection != 0 && ! hasFailed;
  200162. }
  200163. - (int) readPosition
  200164. {
  200165. return position;
  200166. }
  200167. - (int) read: (char*) dest numBytes: (int) numNeeded
  200168. {
  200169. int numDone = 0;
  200170. while (numNeeded > 0)
  200171. {
  200172. int available = jmin (numNeeded, (int) [data length]);
  200173. if (available > 0)
  200174. {
  200175. [dataLock lock];
  200176. [data getBytes: dest length: available];
  200177. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200178. [dataLock unlock];
  200179. numDone += available;
  200180. numNeeded -= available;
  200181. dest += available;
  200182. }
  200183. else
  200184. {
  200185. if (hasFailed || hasFinished)
  200186. break;
  200187. Thread::sleep (1);
  200188. }
  200189. }
  200190. position += numDone;
  200191. return numDone;
  200192. }
  200193. - (void) stop
  200194. {
  200195. [connection cancel];
  200196. if (runLoopThread != 0)
  200197. runLoopThread->stopThread (10000);
  200198. }
  200199. @end
  200200. BEGIN_JUCE_NAMESPACE
  200201. bool juce_isOnLine()
  200202. {
  200203. return true;
  200204. }
  200205. void* juce_openInternetFile (const String& url,
  200206. const String& headers,
  200207. const MemoryBlock& postData,
  200208. const bool isPost,
  200209. URL::OpenStreamProgressCallback* callback,
  200210. void* callbackContext,
  200211. int timeOutMs)
  200212. {
  200213. const ScopedAutoReleasePool pool;
  200214. NSMutableURLRequest* req = [NSMutableURLRequest
  200215. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200216. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200217. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200218. if (req == nil)
  200219. return 0;
  200220. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200221. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200222. StringArray headerLines;
  200223. headerLines.addLines (headers);
  200224. headerLines.removeEmptyStrings (true);
  200225. for (int i = 0; i < headerLines.size(); ++i)
  200226. {
  200227. const String key (headerLines[i].upToFirstOccurrenceOf (":", false, false).trim());
  200228. const String value (headerLines[i].fromFirstOccurrenceOf (":", false, false).trim());
  200229. if (key.isNotEmpty() && value.isNotEmpty())
  200230. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200231. }
  200232. if (isPost && postData.getSize() > 0)
  200233. {
  200234. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200235. length: postData.getSize()]];
  200236. }
  200237. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200238. withCallback: callback
  200239. withContext: callbackContext];
  200240. if ([s isOpen])
  200241. return s;
  200242. [s release];
  200243. return 0;
  200244. }
  200245. void juce_closeInternetFile (void* handle)
  200246. {
  200247. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200248. if (s != 0)
  200249. {
  200250. const ScopedAutoReleasePool pool;
  200251. [s stop];
  200252. [s release];
  200253. }
  200254. }
  200255. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200256. {
  200257. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200258. if (s != 0)
  200259. {
  200260. const ScopedAutoReleasePool pool;
  200261. return [s read: (char*) buffer numBytes: bytesToRead];
  200262. }
  200263. return 0;
  200264. }
  200265. int64 juce_getInternetFileContentLength (void* handle)
  200266. {
  200267. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200268. if (s != 0)
  200269. return s->contentLength;
  200270. return -1;
  200271. }
  200272. int juce_seekInInternetFile (void* handle, int newPosition)
  200273. {
  200274. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200275. if (s != 0)
  200276. return [s readPosition];
  200277. return 0;
  200278. }
  200279. #endif
  200280. /*** End of inlined file: juce_mac_Network.mm ***/
  200281. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200282. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200283. // compiled on its own).
  200284. #if JUCE_INCLUDED_FILE
  200285. struct NamedPipeInternal
  200286. {
  200287. String pipeInName, pipeOutName;
  200288. int pipeIn, pipeOut;
  200289. bool volatile createdPipe, blocked, stopReadOperation;
  200290. static void signalHandler (int) {}
  200291. };
  200292. void NamedPipe::cancelPendingReads()
  200293. {
  200294. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200295. {
  200296. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200297. intern->stopReadOperation = true;
  200298. char buffer [1] = { 0 };
  200299. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200300. (void) bytesWritten;
  200301. int timeout = 2000;
  200302. while (intern->blocked && --timeout >= 0)
  200303. Thread::sleep (2);
  200304. intern->stopReadOperation = false;
  200305. }
  200306. }
  200307. void NamedPipe::close()
  200308. {
  200309. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200310. if (intern != 0)
  200311. {
  200312. internal = 0;
  200313. if (intern->pipeIn != -1)
  200314. ::close (intern->pipeIn);
  200315. if (intern->pipeOut != -1)
  200316. ::close (intern->pipeOut);
  200317. if (intern->createdPipe)
  200318. {
  200319. unlink (intern->pipeInName.toUTF8());
  200320. unlink (intern->pipeOutName.toUTF8());
  200321. }
  200322. delete intern;
  200323. }
  200324. }
  200325. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200326. {
  200327. close();
  200328. NamedPipeInternal* const intern = new NamedPipeInternal();
  200329. internal = intern;
  200330. intern->createdPipe = createPipe;
  200331. intern->blocked = false;
  200332. intern->stopReadOperation = false;
  200333. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200334. siginterrupt (SIGPIPE, 1);
  200335. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  200336. intern->pipeInName = pipePath + "_in";
  200337. intern->pipeOutName = pipePath + "_out";
  200338. intern->pipeIn = -1;
  200339. intern->pipeOut = -1;
  200340. if (createPipe)
  200341. {
  200342. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200343. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200344. {
  200345. delete intern;
  200346. internal = 0;
  200347. return false;
  200348. }
  200349. }
  200350. return true;
  200351. }
  200352. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200353. {
  200354. int bytesRead = -1;
  200355. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200356. if (intern != 0)
  200357. {
  200358. intern->blocked = true;
  200359. if (intern->pipeIn == -1)
  200360. {
  200361. if (intern->createdPipe)
  200362. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200363. else
  200364. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200365. if (intern->pipeIn == -1)
  200366. {
  200367. intern->blocked = false;
  200368. return -1;
  200369. }
  200370. }
  200371. bytesRead = 0;
  200372. char* p = (char*) destBuffer;
  200373. while (bytesRead < maxBytesToRead)
  200374. {
  200375. const int bytesThisTime = maxBytesToRead - bytesRead;
  200376. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200377. if (numRead <= 0 || intern->stopReadOperation)
  200378. {
  200379. bytesRead = -1;
  200380. break;
  200381. }
  200382. bytesRead += numRead;
  200383. p += bytesRead;
  200384. }
  200385. intern->blocked = false;
  200386. }
  200387. return bytesRead;
  200388. }
  200389. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200390. {
  200391. int bytesWritten = -1;
  200392. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200393. if (intern != 0)
  200394. {
  200395. if (intern->pipeOut == -1)
  200396. {
  200397. if (intern->createdPipe)
  200398. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200399. else
  200400. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200401. if (intern->pipeOut == -1)
  200402. {
  200403. return -1;
  200404. }
  200405. }
  200406. const char* p = (const char*) sourceBuffer;
  200407. bytesWritten = 0;
  200408. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200409. while (bytesWritten < numBytesToWrite
  200410. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200411. {
  200412. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200413. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200414. if (numWritten <= 0)
  200415. {
  200416. bytesWritten = -1;
  200417. break;
  200418. }
  200419. bytesWritten += numWritten;
  200420. p += bytesWritten;
  200421. }
  200422. }
  200423. return bytesWritten;
  200424. }
  200425. #endif
  200426. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200427. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200428. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200429. // compiled on its own).
  200430. #if JUCE_INCLUDED_FILE
  200431. void JUCE_API juce_threadEntryPoint (void*);
  200432. void* threadEntryProc (void* userData)
  200433. {
  200434. const ScopedAutoReleasePool pool;
  200435. juce_threadEntryPoint (userData);
  200436. return 0;
  200437. }
  200438. void* juce_createThread (void* userData)
  200439. {
  200440. pthread_t handle = 0;
  200441. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200442. {
  200443. pthread_detach (handle);
  200444. return (void*) handle;
  200445. }
  200446. return 0;
  200447. }
  200448. void juce_killThread (void* handle)
  200449. {
  200450. if (handle != 0)
  200451. pthread_cancel ((pthread_t) handle);
  200452. }
  200453. void juce_setCurrentThreadName (const String& /*name*/)
  200454. {
  200455. }
  200456. bool juce_setThreadPriority (void* handle, int priority)
  200457. {
  200458. if (handle == 0)
  200459. handle = (void*) pthread_self();
  200460. struct sched_param param;
  200461. int policy;
  200462. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200463. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200464. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200465. }
  200466. Thread::ThreadID Thread::getCurrentThreadId()
  200467. {
  200468. return static_cast <ThreadID> (pthread_self());
  200469. }
  200470. void Thread::yield()
  200471. {
  200472. sched_yield();
  200473. }
  200474. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200475. {
  200476. // xxx
  200477. jassertfalse
  200478. }
  200479. bool Process::isForegroundProcess()
  200480. {
  200481. #if JUCE_MAC
  200482. return [NSApp isActive];
  200483. #else
  200484. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200485. #endif
  200486. }
  200487. void Process::raisePrivilege()
  200488. {
  200489. jassertfalse
  200490. }
  200491. void Process::lowerPrivilege()
  200492. {
  200493. jassertfalse
  200494. }
  200495. void Process::terminate()
  200496. {
  200497. exit (0);
  200498. }
  200499. void Process::setPriority (ProcessPriority p)
  200500. {
  200501. // xxx
  200502. }
  200503. #endif
  200504. /*** End of inlined file: juce_mac_Threads.mm ***/
  200505. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200506. CriticalSection::CriticalSection() throw()
  200507. {
  200508. pthread_mutexattr_t atts;
  200509. pthread_mutexattr_init (&atts);
  200510. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200511. pthread_mutex_init (&internal, &atts);
  200512. }
  200513. CriticalSection::~CriticalSection() throw()
  200514. {
  200515. pthread_mutex_destroy (&internal);
  200516. }
  200517. void CriticalSection::enter() const throw()
  200518. {
  200519. pthread_mutex_lock (&internal);
  200520. }
  200521. bool CriticalSection::tryEnter() const throw()
  200522. {
  200523. return pthread_mutex_trylock (&internal) == 0;
  200524. }
  200525. void CriticalSection::exit() const throw()
  200526. {
  200527. pthread_mutex_unlock (&internal);
  200528. }
  200529. class WaitableEventImpl
  200530. {
  200531. public:
  200532. WaitableEventImpl (const bool manualReset_)
  200533. : triggered (false),
  200534. manualReset (manualReset_)
  200535. {
  200536. pthread_cond_init (&condition, 0);
  200537. pthread_mutex_init (&mutex, 0);
  200538. }
  200539. ~WaitableEventImpl()
  200540. {
  200541. pthread_cond_destroy (&condition);
  200542. pthread_mutex_destroy (&mutex);
  200543. }
  200544. bool wait (const int timeOutMillisecs) throw()
  200545. {
  200546. pthread_mutex_lock (&mutex);
  200547. if (! triggered)
  200548. {
  200549. if (timeOutMillisecs < 0)
  200550. {
  200551. do
  200552. {
  200553. pthread_cond_wait (&condition, &mutex);
  200554. }
  200555. while (! triggered);
  200556. }
  200557. else
  200558. {
  200559. struct timeval now;
  200560. gettimeofday (&now, 0);
  200561. struct timespec time;
  200562. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200563. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200564. if (time.tv_nsec >= 1000000000)
  200565. {
  200566. time.tv_nsec -= 1000000000;
  200567. time.tv_sec++;
  200568. }
  200569. do
  200570. {
  200571. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200572. {
  200573. pthread_mutex_unlock (&mutex);
  200574. return false;
  200575. }
  200576. }
  200577. while (! triggered);
  200578. }
  200579. }
  200580. if (! manualReset)
  200581. triggered = false;
  200582. pthread_mutex_unlock (&mutex);
  200583. return true;
  200584. }
  200585. void signal() throw()
  200586. {
  200587. pthread_mutex_lock (&mutex);
  200588. triggered = true;
  200589. pthread_cond_broadcast (&condition);
  200590. pthread_mutex_unlock (&mutex);
  200591. }
  200592. void reset() throw()
  200593. {
  200594. pthread_mutex_lock (&mutex);
  200595. triggered = false;
  200596. pthread_mutex_unlock (&mutex);
  200597. }
  200598. private:
  200599. pthread_cond_t condition;
  200600. pthread_mutex_t mutex;
  200601. bool triggered;
  200602. const bool manualReset;
  200603. WaitableEventImpl (const WaitableEventImpl&);
  200604. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200605. };
  200606. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  200607. : internal (new WaitableEventImpl (manualReset))
  200608. {
  200609. }
  200610. WaitableEvent::~WaitableEvent() throw()
  200611. {
  200612. delete static_cast <WaitableEventImpl*> (internal);
  200613. }
  200614. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200615. {
  200616. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200617. }
  200618. void WaitableEvent::signal() const throw()
  200619. {
  200620. static_cast <WaitableEventImpl*> (internal)->signal();
  200621. }
  200622. void WaitableEvent::reset() const throw()
  200623. {
  200624. static_cast <WaitableEventImpl*> (internal)->reset();
  200625. }
  200626. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200627. {
  200628. struct timespec time;
  200629. time.tv_sec = millisecs / 1000;
  200630. time.tv_nsec = (millisecs % 1000) * 1000000;
  200631. nanosleep (&time, 0);
  200632. }
  200633. const juce_wchar File::separator = '/';
  200634. const juce_wchar* File::separatorString = L"/";
  200635. const File File::getCurrentWorkingDirectory()
  200636. {
  200637. HeapBlock<char> heapBuffer;
  200638. char localBuffer [1024];
  200639. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200640. int bufferSize = 4096;
  200641. while (cwd == 0 && errno == ERANGE)
  200642. {
  200643. heapBuffer.malloc (bufferSize);
  200644. cwd = getcwd (heapBuffer, bufferSize - 1);
  200645. bufferSize += 1024;
  200646. }
  200647. return File (String::fromUTF8 (cwd));
  200648. }
  200649. bool File::setAsCurrentWorkingDirectory() const
  200650. {
  200651. return chdir (getFullPathName().toUTF8()) == 0;
  200652. }
  200653. bool juce_copyFile (const String& s, const String& d);
  200654. static bool juce_stat (const String& fileName, struct stat& info)
  200655. {
  200656. return fileName.isNotEmpty()
  200657. && (stat (fileName.toUTF8(), &info) == 0);
  200658. }
  200659. bool juce_isDirectory (const String& fileName)
  200660. {
  200661. struct stat info;
  200662. return fileName.isEmpty()
  200663. || (juce_stat (fileName, info)
  200664. && ((info.st_mode & S_IFDIR) != 0));
  200665. }
  200666. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200667. {
  200668. if (fileName.isEmpty())
  200669. return false;
  200670. const char* const fileNameUTF8 = fileName.toUTF8();
  200671. bool exists = access (fileNameUTF8, F_OK) == 0;
  200672. if (exists && dontCountDirectories)
  200673. {
  200674. struct stat info;
  200675. const int res = stat (fileNameUTF8, &info);
  200676. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200677. exists = false;
  200678. }
  200679. return exists;
  200680. }
  200681. int64 juce_getFileSize (const String& fileName)
  200682. {
  200683. struct stat info;
  200684. return juce_stat (fileName, info) ? info.st_size : 0;
  200685. }
  200686. bool juce_canWriteToFile (const String& fileName)
  200687. {
  200688. return access (fileName.toUTF8(), W_OK) == 0;
  200689. }
  200690. bool juce_deleteFile (const String& fileName)
  200691. {
  200692. if (juce_isDirectory (fileName))
  200693. return rmdir (fileName.toUTF8()) == 0;
  200694. else
  200695. return remove (fileName.toUTF8()) == 0;
  200696. }
  200697. bool juce_moveFile (const String& source, const String& dest)
  200698. {
  200699. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200700. return true;
  200701. if (juce_canWriteToFile (source)
  200702. && juce_copyFile (source, dest))
  200703. {
  200704. if (juce_deleteFile (source))
  200705. return true;
  200706. juce_deleteFile (dest);
  200707. }
  200708. return false;
  200709. }
  200710. void juce_createDirectory (const String& fileName)
  200711. {
  200712. mkdir (fileName.toUTF8(), 0777);
  200713. }
  200714. void* juce_fileOpen (const String& fileName, bool forWriting)
  200715. {
  200716. int flags = O_RDONLY;
  200717. if (forWriting)
  200718. {
  200719. if (juce_fileExists (fileName, false))
  200720. {
  200721. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  200722. if (f != -1)
  200723. lseek (f, 0, SEEK_END);
  200724. return (void*) f;
  200725. }
  200726. else
  200727. {
  200728. flags = O_RDWR + O_CREAT;
  200729. }
  200730. }
  200731. return (void*) open (fileName.toUTF8(), flags, 00644);
  200732. }
  200733. void juce_fileClose (void* handle)
  200734. {
  200735. if (handle != 0)
  200736. close ((int) (pointer_sized_int) handle);
  200737. }
  200738. int juce_fileRead (void* handle, void* buffer, int size)
  200739. {
  200740. if (handle != 0)
  200741. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  200742. return 0;
  200743. }
  200744. int juce_fileWrite (void* handle, const void* buffer, int size)
  200745. {
  200746. if (handle != 0)
  200747. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200748. return 0;
  200749. }
  200750. int64 juce_fileSetPosition (void* handle, int64 pos)
  200751. {
  200752. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200753. return pos;
  200754. return -1;
  200755. }
  200756. int64 juce_fileGetPosition (void* handle)
  200757. {
  200758. if (handle != 0)
  200759. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200760. return -1;
  200761. }
  200762. void juce_fileFlush (void* handle)
  200763. {
  200764. if (handle != 0)
  200765. fsync ((int) (pointer_sized_int) handle);
  200766. }
  200767. const File juce_getExecutableFile()
  200768. {
  200769. Dl_info exeInfo;
  200770. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200771. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  200772. }
  200773. // if this file doesn't exist, find a parent of it that does..
  200774. static bool doStatFS (const File* file, struct statfs& result)
  200775. {
  200776. File f (*file);
  200777. for (int i = 5; --i >= 0;)
  200778. {
  200779. if (f.exists())
  200780. break;
  200781. f = f.getParentDirectory();
  200782. }
  200783. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200784. }
  200785. int64 File::getBytesFreeOnVolume() const
  200786. {
  200787. struct statfs buf;
  200788. if (doStatFS (this, buf))
  200789. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200790. return 0;
  200791. }
  200792. int64 File::getVolumeTotalSize() const
  200793. {
  200794. struct statfs buf;
  200795. if (doStatFS (this, buf))
  200796. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200797. return 0;
  200798. }
  200799. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200800. int& volumeSerialNumber)
  200801. {
  200802. volumeSerialNumber = 0;
  200803. #if JUCE_MAC
  200804. struct VolAttrBuf
  200805. {
  200806. u_int32_t length;
  200807. attrreference_t mountPointRef;
  200808. char mountPointSpace [MAXPATHLEN];
  200809. } attrBuf;
  200810. struct attrlist attrList;
  200811. zerostruct (attrList);
  200812. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200813. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200814. File f (filenameOnVolume);
  200815. for (;;)
  200816. {
  200817. if (getattrlist (f.getFullPathName().toUTF8(),
  200818. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200819. {
  200820. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200821. (int) attrBuf.mountPointRef.attr_length);
  200822. }
  200823. const File parent (f.getParentDirectory());
  200824. if (f == parent)
  200825. break;
  200826. f = parent;
  200827. }
  200828. #endif
  200829. return String::empty;
  200830. }
  200831. void juce_runSystemCommand (const String& command)
  200832. {
  200833. int result = system (command.toUTF8());
  200834. (void) result;
  200835. }
  200836. const String juce_getOutputFromCommand (const String& command)
  200837. {
  200838. // slight bodge here, as we just pipe the output into a temp file and read it...
  200839. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200840. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200841. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200842. String result (tempFile.loadFileAsString());
  200843. tempFile.deleteFile();
  200844. return result;
  200845. }
  200846. class InterProcessLock::Pimpl
  200847. {
  200848. public:
  200849. Pimpl (const String& name, const int timeOutMillisecs)
  200850. : handle (0), refCount (1)
  200851. {
  200852. #if JUCE_MAC
  200853. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200854. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  200855. #else
  200856. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200857. #endif
  200858. temp.create();
  200859. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200860. if (handle != 0)
  200861. {
  200862. struct flock fl;
  200863. zerostruct (fl);
  200864. fl.l_whence = SEEK_SET;
  200865. fl.l_type = F_WRLCK;
  200866. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200867. for (;;)
  200868. {
  200869. const int result = fcntl (handle, F_SETLK, &fl);
  200870. if (result >= 0)
  200871. return;
  200872. if (errno != EINTR)
  200873. {
  200874. if (timeOutMillisecs == 0
  200875. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200876. break;
  200877. Thread::sleep (10);
  200878. }
  200879. }
  200880. }
  200881. closeFile();
  200882. }
  200883. ~Pimpl()
  200884. {
  200885. closeFile();
  200886. }
  200887. void closeFile()
  200888. {
  200889. if (handle != 0)
  200890. {
  200891. struct flock fl;
  200892. zerostruct (fl);
  200893. fl.l_whence = SEEK_SET;
  200894. fl.l_type = F_UNLCK;
  200895. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  200896. {}
  200897. close (handle);
  200898. handle = 0;
  200899. }
  200900. }
  200901. int handle, refCount;
  200902. };
  200903. InterProcessLock::InterProcessLock (const String& name_)
  200904. : name (name_)
  200905. {
  200906. }
  200907. InterProcessLock::~InterProcessLock()
  200908. {
  200909. }
  200910. bool InterProcessLock::enter (const int timeOutMillisecs)
  200911. {
  200912. const ScopedLock sl (lock);
  200913. if (pimpl == 0)
  200914. {
  200915. pimpl = new Pimpl (name, timeOutMillisecs);
  200916. if (pimpl->handle == 0)
  200917. pimpl = 0;
  200918. }
  200919. else
  200920. {
  200921. pimpl->refCount++;
  200922. }
  200923. return pimpl != 0;
  200924. }
  200925. void InterProcessLock::exit()
  200926. {
  200927. const ScopedLock sl (lock);
  200928. // Trying to release the lock too many times!
  200929. jassert (pimpl != 0);
  200930. if (pimpl != 0 && --(pimpl->refCount) == 0)
  200931. pimpl = 0;
  200932. }
  200933. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200934. /*** Start of inlined file: juce_mac_Files.mm ***/
  200935. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200936. // compiled on its own).
  200937. #if JUCE_INCLUDED_FILE
  200938. void juce_getFileTimes (const String& fileName,
  200939. int64& modificationTime,
  200940. int64& accessTime,
  200941. int64& creationTime)
  200942. {
  200943. modificationTime = 0;
  200944. accessTime = 0;
  200945. creationTime = 0;
  200946. struct stat info;
  200947. const int res = stat (fileName.toUTF8(), &info);
  200948. if (res == 0)
  200949. {
  200950. modificationTime = (int64) info.st_mtime * 1000;
  200951. accessTime = (int64) info.st_atime * 1000;
  200952. creationTime = (int64) info.st_ctime * 1000;
  200953. }
  200954. }
  200955. bool juce_setFileTimes (const String& fileName,
  200956. int64 modificationTime,
  200957. int64 accessTime,
  200958. int64 creationTime)
  200959. {
  200960. struct utimbuf times;
  200961. times.actime = (time_t) (accessTime / 1000);
  200962. times.modtime = (time_t) (modificationTime / 1000);
  200963. return utime (fileName.toUTF8(), &times) == 0;
  200964. }
  200965. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200966. {
  200967. struct stat info;
  200968. const int res = stat (fileName.toUTF8(), &info);
  200969. if (res != 0)
  200970. return false;
  200971. info.st_mode &= 0777; // Just permissions
  200972. if (isReadOnly)
  200973. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200974. else
  200975. // Give everybody write permission?
  200976. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200977. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  200978. }
  200979. bool juce_copyFile (const String& src, const String& dst)
  200980. {
  200981. const ScopedAutoReleasePool pool;
  200982. NSFileManager* fm = [NSFileManager defaultManager];
  200983. return [fm fileExistsAtPath: juceStringToNS (src)]
  200984. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  200985. && [fm copyItemAtPath: juceStringToNS (src)
  200986. toPath: juceStringToNS (dst)
  200987. error: nil];
  200988. #else
  200989. && [fm copyPath: juceStringToNS (src)
  200990. toPath: juceStringToNS (dst)
  200991. handler: nil];
  200992. #endif
  200993. }
  200994. const StringArray juce_getFileSystemRoots()
  200995. {
  200996. StringArray s;
  200997. s.add ("/");
  200998. return s;
  200999. }
  201000. static bool isFileOnDriveType (const File* const f, const char** types)
  201001. {
  201002. struct statfs buf;
  201003. if (doStatFS (f, buf))
  201004. {
  201005. const String type (buf.f_fstypename);
  201006. while (*types != 0)
  201007. if (type.equalsIgnoreCase (*types++))
  201008. return true;
  201009. }
  201010. return false;
  201011. }
  201012. bool File::isOnCDRomDrive() const
  201013. {
  201014. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201015. return isFileOnDriveType (this, (const char**) cdTypes);
  201016. }
  201017. bool File::isOnHardDisk() const
  201018. {
  201019. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201020. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201021. }
  201022. bool File::isOnRemovableDrive() const
  201023. {
  201024. #if JUCE_IPHONE
  201025. return false; // xxx is this possible?
  201026. #else
  201027. const ScopedAutoReleasePool pool;
  201028. BOOL removable = false;
  201029. [[NSWorkspace sharedWorkspace]
  201030. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201031. isRemovable: &removable
  201032. isWritable: nil
  201033. isUnmountable: nil
  201034. description: nil
  201035. type: nil];
  201036. return removable;
  201037. #endif
  201038. }
  201039. static bool juce_isHiddenFile (const String& path)
  201040. {
  201041. #if JUCE_IPHONE
  201042. return File (path).getFileName().startsWithChar ('.');
  201043. #else
  201044. FSRef ref;
  201045. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201046. return false;
  201047. FSCatalogInfo info;
  201048. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201049. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201050. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201051. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201052. #endif
  201053. }
  201054. bool File::isHidden() const
  201055. {
  201056. return juce_isHiddenFile (getFullPathName());
  201057. }
  201058. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201059. const File File::getSpecialLocation (const SpecialLocationType type)
  201060. {
  201061. const ScopedAutoReleasePool pool;
  201062. String resultPath;
  201063. switch (type)
  201064. {
  201065. case userHomeDirectory:
  201066. resultPath = nsStringToJuce (NSHomeDirectory());
  201067. break;
  201068. case userDocumentsDirectory:
  201069. resultPath = "~/Documents";
  201070. break;
  201071. case userDesktopDirectory:
  201072. resultPath = "~/Desktop";
  201073. break;
  201074. case userApplicationDataDirectory:
  201075. resultPath = "~/Library";
  201076. break;
  201077. case commonApplicationDataDirectory:
  201078. resultPath = "/Library";
  201079. break;
  201080. case globalApplicationsDirectory:
  201081. resultPath = "/Applications";
  201082. break;
  201083. case userMusicDirectory:
  201084. resultPath = "~/Music";
  201085. break;
  201086. case userMoviesDirectory:
  201087. resultPath = "~/Movies";
  201088. break;
  201089. case tempDirectory:
  201090. {
  201091. File tmp ("~/Library/Caches/" + juce_getExecutableFile().getFileNameWithoutExtension());
  201092. tmp.createDirectory();
  201093. return tmp.getFullPathName();
  201094. }
  201095. case invokedExecutableFile:
  201096. if (juce_Argv0 != 0)
  201097. return File (String::fromUTF8 (juce_Argv0));
  201098. // deliberate fall-through...
  201099. case currentExecutableFile:
  201100. return juce_getExecutableFile();
  201101. case currentApplicationFile:
  201102. {
  201103. const File exe (juce_getExecutableFile());
  201104. const File parent (exe.getParentDirectory());
  201105. return parent.getFullPathName().endsWithIgnoreCase ("Contents/MacOS")
  201106. ? parent.getParentDirectory().getParentDirectory()
  201107. : exe;
  201108. }
  201109. default:
  201110. jassertfalse // unknown type?
  201111. break;
  201112. }
  201113. if (resultPath.isNotEmpty())
  201114. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201115. return File::nonexistent;
  201116. }
  201117. const String File::getVersion() const
  201118. {
  201119. const ScopedAutoReleasePool pool;
  201120. String result;
  201121. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201122. if (bundle != 0)
  201123. {
  201124. NSDictionary* info = [bundle infoDictionary];
  201125. if (info != 0)
  201126. {
  201127. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201128. if (name != nil)
  201129. result = nsStringToJuce (name);
  201130. }
  201131. }
  201132. return result;
  201133. }
  201134. const File File::getLinkedTarget() const
  201135. {
  201136. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201137. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201138. #else
  201139. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201140. #endif
  201141. if (dest != nil)
  201142. return File (nsStringToJuce (dest));
  201143. return *this;
  201144. }
  201145. bool File::moveToTrash() const
  201146. {
  201147. if (! exists())
  201148. return true;
  201149. #if JUCE_IPHONE
  201150. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201151. #else
  201152. const ScopedAutoReleasePool pool;
  201153. NSString* p = juceStringToNS (getFullPathName());
  201154. return [[NSWorkspace sharedWorkspace]
  201155. performFileOperation: NSWorkspaceRecycleOperation
  201156. source: [p stringByDeletingLastPathComponent]
  201157. destination: @""
  201158. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201159. tag: nil ];
  201160. #endif
  201161. }
  201162. struct FindFileStruct
  201163. {
  201164. NSDirectoryEnumerator* enumerator;
  201165. String parentDir, wildCard;
  201166. };
  201167. bool juce_findFileNext (void* handle, String& resultFile,
  201168. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201169. {
  201170. ScopedAutoReleasePool pool;
  201171. FindFileStruct* ff = (FindFileStruct*) handle;
  201172. NSString* file;
  201173. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201174. for (;;)
  201175. {
  201176. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201177. return false;
  201178. [ff->enumerator skipDescendents];
  201179. resultFile = nsStringToJuce (file);
  201180. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201181. continue;
  201182. const String path (ff->parentDir + resultFile);
  201183. if (isDir != 0 || fileSize != 0)
  201184. {
  201185. struct stat info;
  201186. const bool statOk = juce_stat (path, info);
  201187. if (isDir != 0)
  201188. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201189. if (isHidden != 0)
  201190. *isHidden = juce_isHiddenFile (path);
  201191. if (fileSize != 0)
  201192. *fileSize = statOk ? info.st_size : 0;
  201193. }
  201194. if (modTime != 0 || creationTime != 0)
  201195. {
  201196. int64 m, a, c;
  201197. juce_getFileTimes (path, m, a, c);
  201198. if (modTime != 0)
  201199. *modTime = m;
  201200. if (creationTime != 0)
  201201. *creationTime = c;
  201202. }
  201203. if (isReadOnly != 0)
  201204. *isReadOnly = ! juce_canWriteToFile (path);
  201205. return true;
  201206. }
  201207. }
  201208. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201209. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201210. Time* creationTime, bool* isReadOnly)
  201211. {
  201212. ScopedAutoReleasePool pool;
  201213. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201214. if (e != 0)
  201215. {
  201216. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201217. ff->enumerator = [e retain];
  201218. ff->parentDir = directory;
  201219. ff->wildCard = wildCard;
  201220. if (! ff->parentDir.endsWithChar (File::separator))
  201221. ff->parentDir += File::separator;
  201222. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201223. return ff.release();
  201224. [e release];
  201225. }
  201226. return 0;
  201227. }
  201228. void juce_findFileClose (void* handle)
  201229. {
  201230. ScopedAutoReleasePool pool;
  201231. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201232. [ff->enumerator release];
  201233. }
  201234. bool juce_launchExecutable (const String& pathAndArguments)
  201235. {
  201236. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201237. const int cpid = fork();
  201238. if (cpid == 0)
  201239. {
  201240. // Child process
  201241. if (execve (argv[0], (char**) argv, 0) < 0)
  201242. exit (0);
  201243. }
  201244. else
  201245. {
  201246. if (cpid < 0)
  201247. return false;
  201248. }
  201249. return true;
  201250. }
  201251. bool juce_launchFile (const String& fileName, const String& parameters)
  201252. {
  201253. #if JUCE_IPHONE
  201254. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201255. #else
  201256. const ScopedAutoReleasePool pool;
  201257. if (parameters.isEmpty())
  201258. {
  201259. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201260. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201261. }
  201262. bool ok = false;
  201263. FSRef ref;
  201264. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201265. {
  201266. if (PlatformUtilities::isBundle (fileName))
  201267. {
  201268. NSMutableArray* urls = [NSMutableArray array];
  201269. StringArray docs;
  201270. docs.addTokens (parameters, true);
  201271. for (int i = 0; i < docs.size(); ++i)
  201272. [urls addObject: juceStringToNS (docs[i])];
  201273. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201274. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201275. options: 0
  201276. additionalEventParamDescriptor: nil
  201277. launchIdentifiers: nil];
  201278. }
  201279. else
  201280. {
  201281. ok = juce_launchExecutable ("\"" + fileName + "\" " + parameters);
  201282. }
  201283. }
  201284. return ok;
  201285. #endif
  201286. }
  201287. void File::revealToUser() const
  201288. {
  201289. #if ! JUCE_IPHONE
  201290. if (exists())
  201291. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201292. else if (getParentDirectory().exists())
  201293. getParentDirectory().revealToUser();
  201294. #endif
  201295. }
  201296. #if ! JUCE_IPHONE
  201297. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201298. {
  201299. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201300. }
  201301. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201302. {
  201303. char path [2048];
  201304. zerostruct (path);
  201305. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201306. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201307. return String::empty;
  201308. }
  201309. #endif
  201310. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201311. {
  201312. const ScopedAutoReleasePool pool;
  201313. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201314. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201315. #else
  201316. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201317. #endif
  201318. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201319. return [fileDict fileHFSTypeCode];
  201320. }
  201321. bool PlatformUtilities::isBundle (const String& filename)
  201322. {
  201323. #if JUCE_IPHONE
  201324. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201325. #else
  201326. const ScopedAutoReleasePool pool;
  201327. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201328. #endif
  201329. }
  201330. #endif
  201331. /*** End of inlined file: juce_mac_Files.mm ***/
  201332. #if JUCE_IPHONE
  201333. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201334. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201335. // compiled on its own).
  201336. #if JUCE_INCLUDED_FILE
  201337. static JUCEApplication* juce_intialisingApp;
  201338. END_JUCE_NAMESPACE
  201339. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201340. {
  201341. }
  201342. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201343. - (void) applicationWillResignActive: (UIApplication*) application;
  201344. @end
  201345. @implementation JuceAppStartupDelegate
  201346. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201347. {
  201348. String dummy;
  201349. if (! juce_intialisingApp->initialiseApp (dummy))
  201350. exit (0);
  201351. }
  201352. - (void) applicationWillResignActive: (UIApplication*) application
  201353. {
  201354. JUCEApplication::shutdownAppAndClearUp();
  201355. }
  201356. @end
  201357. BEGIN_JUCE_NAMESPACE
  201358. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201359. {
  201360. juce_intialisingApp = app;
  201361. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201362. }
  201363. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201364. {
  201365. pool = [[NSAutoreleasePool alloc] init];
  201366. }
  201367. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201368. {
  201369. [((NSAutoreleasePool*) pool) release];
  201370. }
  201371. void PlatformUtilities::beep()
  201372. {
  201373. //xxx
  201374. //AudioServicesPlaySystemSound ();
  201375. }
  201376. void PlatformUtilities::addItemToDock (const File& file)
  201377. {
  201378. }
  201379. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201380. END_JUCE_NAMESPACE
  201381. @interface JuceAlertBoxDelegate : NSObject
  201382. {
  201383. @public
  201384. bool clickedOk;
  201385. }
  201386. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201387. @end
  201388. @implementation JuceAlertBoxDelegate
  201389. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201390. {
  201391. clickedOk = (buttonIndex == 0);
  201392. alertView.hidden = true;
  201393. }
  201394. @end
  201395. BEGIN_JUCE_NAMESPACE
  201396. // (This function is used directly by other bits of code)
  201397. bool juce_iPhoneShowModalAlert (const String& title,
  201398. const String& bodyText,
  201399. NSString* okButtonText,
  201400. NSString* cancelButtonText)
  201401. {
  201402. const ScopedAutoReleasePool pool;
  201403. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201404. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201405. message: juceStringToNS (bodyText)
  201406. delegate: callback
  201407. cancelButtonTitle: okButtonText
  201408. otherButtonTitles: cancelButtonText, nil];
  201409. [alert retain];
  201410. [alert show];
  201411. while (! alert.hidden && alert.superview != nil)
  201412. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201413. const bool result = callback->clickedOk;
  201414. [alert release];
  201415. [callback release];
  201416. return result;
  201417. }
  201418. bool AlertWindow::showNativeDialogBox (const String& title,
  201419. const String& bodyText,
  201420. bool isOkCancel)
  201421. {
  201422. return juce_iPhoneShowModalAlert (title, bodyText,
  201423. @"OK",
  201424. isOkCancel ? @"Cancel" : nil);
  201425. }
  201426. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201427. {
  201428. jassertfalse // no such thing on the iphone!
  201429. return false;
  201430. }
  201431. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201432. {
  201433. jassertfalse // no such thing on the iphone!
  201434. return false;
  201435. }
  201436. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201437. {
  201438. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201439. }
  201440. bool Desktop::isScreenSaverEnabled() throw()
  201441. {
  201442. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201443. }
  201444. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201445. {
  201446. const ScopedAutoReleasePool pool;
  201447. monitorCoords.clear();
  201448. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201449. : [[UIScreen mainScreen] bounds];
  201450. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201451. (int) r.origin.y,
  201452. (int) r.size.width,
  201453. (int) r.size.height));
  201454. }
  201455. #endif
  201456. #endif
  201457. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201458. #else
  201459. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201460. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201461. // compiled on its own).
  201462. #if JUCE_INCLUDED_FILE
  201463. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201464. {
  201465. pool = [[NSAutoreleasePool alloc] init];
  201466. }
  201467. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201468. {
  201469. [((NSAutoreleasePool*) pool) release];
  201470. }
  201471. void PlatformUtilities::beep()
  201472. {
  201473. NSBeep();
  201474. }
  201475. void PlatformUtilities::addItemToDock (const File& file)
  201476. {
  201477. // check that it's not already there...
  201478. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201479. .containsIgnoreCase (file.getFullPathName()))
  201480. {
  201481. 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>"
  201482. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201483. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201484. }
  201485. }
  201486. int PlatformUtilities::getOSXMinorVersionNumber()
  201487. {
  201488. SInt32 versionMinor = 0;
  201489. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201490. (void) err;
  201491. jassert (err == noErr);
  201492. return (int) versionMinor;
  201493. }
  201494. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201495. bool AlertWindow::showNativeDialogBox (const String& title,
  201496. const String& bodyText,
  201497. bool isOkCancel)
  201498. {
  201499. const ScopedAutoReleasePool pool;
  201500. return NSRunAlertPanel (juceStringToNS (title),
  201501. juceStringToNS (bodyText),
  201502. @"Ok",
  201503. isOkCancel ? @"Cancel" : nil,
  201504. nil) == NSAlertDefaultReturn;
  201505. }
  201506. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201507. {
  201508. if (files.size() == 0)
  201509. return false;
  201510. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201511. if (draggingSource == 0)
  201512. {
  201513. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201514. return false;
  201515. }
  201516. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201517. if (sourceComp == 0)
  201518. {
  201519. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201520. return false;
  201521. }
  201522. const ScopedAutoReleasePool pool;
  201523. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201524. if (view == 0)
  201525. return false;
  201526. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201527. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201528. owner: nil];
  201529. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201530. for (int i = 0; i < files.size(); ++i)
  201531. [filesArray addObject: juceStringToNS (files[i])];
  201532. [pboard setPropertyList: filesArray
  201533. forType: NSFilenamesPboardType];
  201534. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201535. fromView: nil];
  201536. dragPosition.x -= 16;
  201537. dragPosition.y -= 16;
  201538. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201539. at: dragPosition
  201540. offset: NSMakeSize (0, 0)
  201541. event: [[view window] currentEvent]
  201542. pasteboard: pboard
  201543. source: view
  201544. slideBack: YES];
  201545. return true;
  201546. }
  201547. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201548. {
  201549. jassertfalse // not implemented!
  201550. return false;
  201551. }
  201552. bool Desktop::canUseSemiTransparentWindows() throw()
  201553. {
  201554. return true;
  201555. }
  201556. const Point<int> Desktop::getMousePosition()
  201557. {
  201558. const ScopedAutoReleasePool pool;
  201559. const NSPoint p ([NSEvent mouseLocation]);
  201560. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201561. }
  201562. void Desktop::setMousePosition (const Point<int>& newPosition)
  201563. {
  201564. // this rubbish needs to be done around the warp call, to avoid causing a
  201565. // bizarre glitch..
  201566. CGAssociateMouseAndMouseCursorPosition (false);
  201567. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201568. CGAssociateMouseAndMouseCursorPosition (true);
  201569. }
  201570. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201571. class ScreenSaverDefeater : public Timer,
  201572. public DeletedAtShutdown
  201573. {
  201574. public:
  201575. ScreenSaverDefeater() throw()
  201576. {
  201577. startTimer (10000);
  201578. timerCallback();
  201579. }
  201580. ~ScreenSaverDefeater() {}
  201581. void timerCallback()
  201582. {
  201583. if (Process::isForegroundProcess())
  201584. UpdateSystemActivity (UsrActivity);
  201585. }
  201586. };
  201587. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201588. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201589. {
  201590. if (isEnabled)
  201591. {
  201592. deleteAndZero (screenSaverDefeater);
  201593. }
  201594. else if (screenSaverDefeater == 0)
  201595. {
  201596. screenSaverDefeater = new ScreenSaverDefeater();
  201597. }
  201598. }
  201599. bool Desktop::isScreenSaverEnabled() throw()
  201600. {
  201601. return screenSaverDefeater == 0;
  201602. }
  201603. #else
  201604. static IOPMAssertionID screenSaverDisablerID = 0;
  201605. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201606. {
  201607. if (isEnabled)
  201608. {
  201609. if (screenSaverDisablerID != 0)
  201610. {
  201611. IOPMAssertionRelease (screenSaverDisablerID);
  201612. screenSaverDisablerID = 0;
  201613. }
  201614. }
  201615. else
  201616. {
  201617. if (screenSaverDisablerID == 0)
  201618. {
  201619. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201620. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201621. CFSTR ("Juce"), &screenSaverDisablerID);
  201622. #else
  201623. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201624. &screenSaverDisablerID);
  201625. #endif
  201626. }
  201627. }
  201628. }
  201629. bool Desktop::isScreenSaverEnabled() throw()
  201630. {
  201631. return screenSaverDisablerID == 0;
  201632. }
  201633. #endif
  201634. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201635. {
  201636. const ScopedAutoReleasePool pool;
  201637. monitorCoords.clear();
  201638. NSArray* screens = [NSScreen screens];
  201639. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201640. for (unsigned int i = 0; i < [screens count]; ++i)
  201641. {
  201642. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201643. NSRect r = clipToWorkArea ? [s visibleFrame]
  201644. : [s frame];
  201645. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201646. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201647. (int) r.size.width,
  201648. (int) r.size.height));
  201649. }
  201650. jassert (monitorCoords.size() > 0);
  201651. }
  201652. #endif
  201653. #endif
  201654. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201655. #endif
  201656. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201657. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201658. // compiled on its own).
  201659. #if JUCE_INCLUDED_FILE
  201660. void Logger::outputDebugString (const String& text) throw()
  201661. {
  201662. std::cerr << text << std::endl;
  201663. }
  201664. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201665. {
  201666. static char testResult = 0;
  201667. if (testResult == 0)
  201668. {
  201669. struct kinfo_proc info;
  201670. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201671. size_t sz = sizeof (info);
  201672. sysctl (m, 4, &info, &sz, 0, 0);
  201673. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201674. }
  201675. return testResult > 0;
  201676. }
  201677. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201678. {
  201679. return juce_isRunningUnderDebugger();
  201680. }
  201681. #endif
  201682. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201683. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201684. #if JUCE_IPHONE
  201685. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201686. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201687. // compiled on its own).
  201688. #if JUCE_INCLUDED_FILE
  201689. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201690. #define SUPPORT_10_4_FONTS 1
  201691. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201692. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201693. #define SUPPORT_ONLY_10_4_FONTS 1
  201694. #endif
  201695. END_JUCE_NAMESPACE
  201696. @interface NSFont (PrivateHack)
  201697. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201698. @end
  201699. BEGIN_JUCE_NAMESPACE
  201700. #endif
  201701. class MacTypeface : public Typeface
  201702. {
  201703. public:
  201704. MacTypeface (const Font& font)
  201705. : Typeface (font.getTypefaceName())
  201706. {
  201707. const ScopedAutoReleasePool pool;
  201708. renderingTransform = CGAffineTransformIdentity;
  201709. bool needsItalicTransform = false;
  201710. #if JUCE_IPHONE
  201711. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201712. if (font.isItalic() || font.isBold())
  201713. {
  201714. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201715. for (NSString* i in familyFonts)
  201716. {
  201717. const String fn (nsStringToJuce (i));
  201718. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  201719. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  201720. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  201721. || afterDash.containsIgnoreCase ("italic")
  201722. || fn.endsWithIgnoreCase ("oblique")
  201723. || fn.endsWithIgnoreCase ("italic");
  201724. if (probablyBold == font.isBold()
  201725. && probablyItalic == font.isItalic())
  201726. {
  201727. fontName = i;
  201728. needsItalicTransform = false;
  201729. break;
  201730. }
  201731. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201732. {
  201733. fontName = i;
  201734. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201735. }
  201736. }
  201737. if (needsItalicTransform)
  201738. renderingTransform.c = 0.15f;
  201739. }
  201740. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201741. const int ascender = abs (CGFontGetAscent (fontRef));
  201742. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201743. ascent = ascender / totalHeight;
  201744. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201745. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201746. #else
  201747. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201748. if (font.isItalic())
  201749. {
  201750. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201751. toHaveTrait: NSItalicFontMask];
  201752. if (newFont == nsFont)
  201753. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201754. nsFont = newFont;
  201755. }
  201756. if (font.isBold())
  201757. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201758. [nsFont retain];
  201759. ascent = fabsf ((float) [nsFont ascender]);
  201760. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201761. ascent /= totalSize;
  201762. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201763. if (needsItalicTransform)
  201764. {
  201765. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201766. renderingTransform.c = 0.15f;
  201767. }
  201768. #if SUPPORT_ONLY_10_4_FONTS
  201769. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201770. if (atsFont == 0)
  201771. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201772. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  201773. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201774. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201775. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201776. #else
  201777. #if SUPPORT_10_4_FONTS
  201778. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201779. {
  201780. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201781. if (atsFont == 0)
  201782. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201783. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  201784. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201785. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201786. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201787. }
  201788. else
  201789. #endif
  201790. {
  201791. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201792. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201793. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201794. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201795. }
  201796. #endif
  201797. #endif
  201798. }
  201799. ~MacTypeface()
  201800. {
  201801. #if ! JUCE_IPHONE
  201802. [nsFont release];
  201803. #endif
  201804. if (fontRef != 0)
  201805. CGFontRelease (fontRef);
  201806. }
  201807. float getAscent() const
  201808. {
  201809. return ascent;
  201810. }
  201811. float getDescent() const
  201812. {
  201813. return 1.0f - ascent;
  201814. }
  201815. float getStringWidth (const String& text)
  201816. {
  201817. if (fontRef == 0 || text.isEmpty())
  201818. return 0;
  201819. const int length = text.length();
  201820. HeapBlock <CGGlyph> glyphs;
  201821. createGlyphsForString (text, length, glyphs);
  201822. float x = 0;
  201823. #if SUPPORT_ONLY_10_4_FONTS
  201824. HeapBlock <NSSize> advances (length);
  201825. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201826. for (int i = 0; i < length; ++i)
  201827. x += advances[i].width;
  201828. #else
  201829. #if SUPPORT_10_4_FONTS
  201830. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201831. {
  201832. HeapBlock <NSSize> advances (length);
  201833. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201834. for (int i = 0; i < length; ++i)
  201835. x += advances[i].width;
  201836. }
  201837. else
  201838. #endif
  201839. {
  201840. HeapBlock <int> advances (length);
  201841. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201842. for (int i = 0; i < length; ++i)
  201843. x += advances[i];
  201844. }
  201845. #endif
  201846. return x * unitsToHeightScaleFactor;
  201847. }
  201848. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201849. {
  201850. xOffsets.add (0);
  201851. if (fontRef == 0 || text.isEmpty())
  201852. return;
  201853. const int length = text.length();
  201854. HeapBlock <CGGlyph> glyphs;
  201855. createGlyphsForString (text, length, glyphs);
  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. int x = 0;
  201860. for (int i = 0; i < length; ++i)
  201861. {
  201862. x += advances[i].width;
  201863. xOffsets.add (x * unitsToHeightScaleFactor);
  201864. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201865. }
  201866. #else
  201867. #if SUPPORT_10_4_FONTS
  201868. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201869. {
  201870. HeapBlock <NSSize> advances (length);
  201871. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201872. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201873. float x = 0;
  201874. for (int i = 0; i < length; ++i)
  201875. {
  201876. x += advances[i].width;
  201877. xOffsets.add (x * unitsToHeightScaleFactor);
  201878. resultGlyphs.add (nsGlyphs[i]);
  201879. }
  201880. }
  201881. else
  201882. #endif
  201883. {
  201884. HeapBlock <int> advances (length);
  201885. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201886. {
  201887. int x = 0;
  201888. for (int i = 0; i < length; ++i)
  201889. {
  201890. x += advances [i];
  201891. xOffsets.add (x * unitsToHeightScaleFactor);
  201892. resultGlyphs.add (glyphs[i]);
  201893. }
  201894. }
  201895. }
  201896. #endif
  201897. }
  201898. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201899. {
  201900. #if JUCE_IPHONE
  201901. return false;
  201902. #else
  201903. if (nsFont == 0)
  201904. return false;
  201905. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201906. jassert (path.isEmpty());
  201907. const ScopedAutoReleasePool pool;
  201908. NSBezierPath* bez = [NSBezierPath bezierPath];
  201909. [bez moveToPoint: NSMakePoint (0, 0)];
  201910. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201911. inFont: nsFont];
  201912. for (int i = 0; i < [bez elementCount]; ++i)
  201913. {
  201914. NSPoint p[3];
  201915. switch ([bez elementAtIndex: i associatedPoints: p])
  201916. {
  201917. case NSMoveToBezierPathElement:
  201918. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201919. break;
  201920. case NSLineToBezierPathElement:
  201921. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201922. break;
  201923. case NSCurveToBezierPathElement:
  201924. 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);
  201925. break;
  201926. case NSClosePathBezierPathElement:
  201927. path.closeSubPath();
  201928. break;
  201929. default:
  201930. jassertfalse
  201931. break;
  201932. }
  201933. }
  201934. path.applyTransform (pathTransform);
  201935. return true;
  201936. #endif
  201937. }
  201938. juce_UseDebuggingNewOperator
  201939. CGFontRef fontRef;
  201940. float fontHeightToCGSizeFactor;
  201941. CGAffineTransform renderingTransform;
  201942. private:
  201943. float ascent, unitsToHeightScaleFactor;
  201944. #if JUCE_IPHONE
  201945. #else
  201946. NSFont* nsFont;
  201947. AffineTransform pathTransform;
  201948. #endif
  201949. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201950. {
  201951. #if SUPPORT_10_4_FONTS
  201952. #if ! SUPPORT_ONLY_10_4_FONTS
  201953. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201954. #endif
  201955. {
  201956. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201957. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201958. for (int i = 0; i < length; ++i)
  201959. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201960. return;
  201961. }
  201962. #endif
  201963. #if ! SUPPORT_ONLY_10_4_FONTS
  201964. if (charToGlyphMapper == 0)
  201965. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201966. glyphs.malloc (length);
  201967. for (int i = 0; i < length; ++i)
  201968. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201969. #endif
  201970. }
  201971. #if ! SUPPORT_ONLY_10_4_FONTS
  201972. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201973. class CharToGlyphMapper
  201974. {
  201975. public:
  201976. CharToGlyphMapper (CGFontRef fontRef)
  201977. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201978. idRangeOffset (0), glyphIndexes (0)
  201979. {
  201980. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  201981. if (cmapTable != 0)
  201982. {
  201983. const int numSubtables = getValue16 (cmapTable, 2);
  201984. for (int i = 0; i < numSubtables; ++i)
  201985. {
  201986. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  201987. {
  201988. const int offset = getValue32 (cmapTable, i * 8 + 8);
  201989. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  201990. {
  201991. const int length = getValue16 (cmapTable, offset + 2);
  201992. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  201993. segCount = segCountX2 / 2;
  201994. const int endCodeOffset = offset + 14;
  201995. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  201996. const int idDeltaOffset = startCodeOffset + segCountX2;
  201997. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  201998. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  201999. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202000. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202001. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202002. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202003. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202004. }
  202005. break;
  202006. }
  202007. }
  202008. CFRelease (cmapTable);
  202009. }
  202010. }
  202011. ~CharToGlyphMapper()
  202012. {
  202013. if (endCode != 0)
  202014. {
  202015. CFRelease (endCode);
  202016. CFRelease (startCode);
  202017. CFRelease (idDelta);
  202018. CFRelease (idRangeOffset);
  202019. CFRelease (glyphIndexes);
  202020. }
  202021. }
  202022. int getGlyphForCharacter (const juce_wchar c) const
  202023. {
  202024. for (int i = 0; i < segCount; ++i)
  202025. {
  202026. if (getValue16 (endCode, i * 2) >= c)
  202027. {
  202028. const int start = getValue16 (startCode, i * 2);
  202029. if (start > c)
  202030. break;
  202031. const int delta = getValue16 (idDelta, i * 2);
  202032. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202033. if (rangeOffset == 0)
  202034. return delta + c;
  202035. else
  202036. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202037. }
  202038. }
  202039. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202040. return jmax (-1, c - 29);
  202041. }
  202042. private:
  202043. int segCount;
  202044. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202045. static uint16 getValue16 (CFDataRef data, const int index)
  202046. {
  202047. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202048. }
  202049. static uint32 getValue32 (CFDataRef data, const int index)
  202050. {
  202051. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202052. }
  202053. };
  202054. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202055. #endif
  202056. MacTypeface (const MacTypeface&);
  202057. MacTypeface& operator= (const MacTypeface&);
  202058. };
  202059. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202060. {
  202061. return new MacTypeface (font);
  202062. }
  202063. const StringArray Font::findAllTypefaceNames()
  202064. {
  202065. StringArray names;
  202066. const ScopedAutoReleasePool pool;
  202067. #if JUCE_IPHONE
  202068. NSArray* fonts = [UIFont familyNames];
  202069. #else
  202070. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202071. #endif
  202072. for (unsigned int i = 0; i < [fonts count]; ++i)
  202073. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202074. names.sort (true);
  202075. return names;
  202076. }
  202077. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  202078. {
  202079. #if JUCE_IPHONE
  202080. defaultSans = "Helvetica";
  202081. defaultSerif = "Times New Roman";
  202082. defaultFixed = "Courier New";
  202083. #else
  202084. defaultSans = "Lucida Grande";
  202085. defaultSerif = "Times New Roman";
  202086. defaultFixed = "Monaco";
  202087. #endif
  202088. }
  202089. #endif
  202090. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202091. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202092. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202093. // compiled on its own).
  202094. #if JUCE_INCLUDED_FILE
  202095. class CoreGraphicsImage : public Image
  202096. {
  202097. public:
  202098. CoreGraphicsImage (const PixelFormat format_,
  202099. const int imageWidth_,
  202100. const int imageHeight_,
  202101. const bool clearImage)
  202102. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202103. {
  202104. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  202105. : CGColorSpaceCreateDeviceRGB();
  202106. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202107. colourSpace, getCGImageFlags (*this));
  202108. CGColorSpaceRelease (colourSpace);
  202109. }
  202110. ~CoreGraphicsImage()
  202111. {
  202112. CGContextRelease (context);
  202113. }
  202114. LowLevelGraphicsContext* createLowLevelContext();
  202115. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202116. {
  202117. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202118. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202119. {
  202120. return CGBitmapContextCreateImage (nativeImage->context);
  202121. }
  202122. else
  202123. {
  202124. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202125. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202126. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202127. 8, srcData.pixelStride * 8, srcData.lineStride,
  202128. colourSpace, getCGImageFlags (juceImage), provider,
  202129. 0, true, kCGRenderingIntentDefault);
  202130. CGDataProviderRelease (provider);
  202131. return imageRef;
  202132. }
  202133. }
  202134. #if JUCE_MAC
  202135. static NSImage* createNSImage (const Image& image)
  202136. {
  202137. const ScopedAutoReleasePool pool;
  202138. NSImage* im = [[NSImage alloc] init];
  202139. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202140. [im lockFocus];
  202141. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202142. CGImageRef imageRef = createImage (image, false, colourSpace);
  202143. CGColorSpaceRelease (colourSpace);
  202144. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202145. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202146. CGImageRelease (imageRef);
  202147. [im unlockFocus];
  202148. return im;
  202149. }
  202150. #endif
  202151. CGContextRef context;
  202152. private:
  202153. static CGBitmapInfo getCGImageFlags (const Image& image)
  202154. {
  202155. #if JUCE_BIG_ENDIAN
  202156. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202157. #else
  202158. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202159. #endif
  202160. }
  202161. };
  202162. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202163. {
  202164. #if USE_COREGRAPHICS_RENDERING
  202165. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202166. #else
  202167. return new Image (format, imageWidth, imageHeight, clearImage);
  202168. #endif
  202169. }
  202170. class CoreGraphicsContext : public LowLevelGraphicsContext
  202171. {
  202172. public:
  202173. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202174. : context (context_),
  202175. flipHeight (flipHeight_),
  202176. state (new SavedState()),
  202177. numGradientLookupEntries (0)
  202178. {
  202179. CGContextRetain (context);
  202180. CGContextSaveGState(context);
  202181. CGContextSetShouldSmoothFonts (context, true);
  202182. CGContextSetShouldAntialias (context, true);
  202183. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202184. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202185. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202186. gradientCallbacks.version = 0;
  202187. gradientCallbacks.evaluate = gradientCallback;
  202188. gradientCallbacks.releaseInfo = 0;
  202189. setFont (Font());
  202190. }
  202191. ~CoreGraphicsContext()
  202192. {
  202193. CGContextRestoreGState (context);
  202194. CGContextRelease (context);
  202195. CGColorSpaceRelease (rgbColourSpace);
  202196. CGColorSpaceRelease (greyColourSpace);
  202197. }
  202198. bool isVectorDevice() const { return false; }
  202199. void setOrigin (int x, int y)
  202200. {
  202201. CGContextTranslateCTM (context, x, -y);
  202202. }
  202203. bool clipToRectangle (const Rectangle<int>& r)
  202204. {
  202205. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202206. return ! isClipEmpty();
  202207. }
  202208. bool clipToRectangleList (const RectangleList& clipRegion)
  202209. {
  202210. if (clipRegion.isEmpty())
  202211. {
  202212. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202213. return false;
  202214. }
  202215. else
  202216. {
  202217. const int numRects = clipRegion.getNumRectangles();
  202218. HeapBlock <CGRect> rects (numRects);
  202219. for (int i = 0; i < numRects; ++i)
  202220. {
  202221. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202222. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202223. }
  202224. CGContextClipToRects (context, rects, numRects);
  202225. return ! isClipEmpty();
  202226. }
  202227. }
  202228. void excludeClipRectangle (const Rectangle<int>& r)
  202229. {
  202230. RectangleList remaining (getClipBounds());
  202231. remaining.subtract (r);
  202232. clipToRectangleList (remaining);
  202233. }
  202234. void clipToPath (const Path& path, const AffineTransform& transform)
  202235. {
  202236. createPath (path, transform);
  202237. CGContextClip (context);
  202238. }
  202239. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202240. {
  202241. if (! transform.isSingularity())
  202242. {
  202243. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202244. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202245. flip();
  202246. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202247. applyTransform (t);
  202248. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202249. CGContextClipToMask (context, r, image);
  202250. applyTransform (t.inverted());
  202251. flip();
  202252. CGImageRelease (image);
  202253. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202254. }
  202255. }
  202256. bool clipRegionIntersects (const Rectangle<int>& r)
  202257. {
  202258. return getClipBounds().intersects (r);
  202259. }
  202260. const Rectangle<int> getClipBounds() const
  202261. {
  202262. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202263. return Rectangle<int> (roundToInt (bounds.origin.x),
  202264. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202265. roundToInt (bounds.size.width),
  202266. roundToInt (bounds.size.height));
  202267. }
  202268. bool isClipEmpty() const
  202269. {
  202270. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202271. }
  202272. void saveState()
  202273. {
  202274. CGContextSaveGState (context);
  202275. stateStack.add (new SavedState (*state));
  202276. }
  202277. void restoreState()
  202278. {
  202279. CGContextRestoreGState (context);
  202280. SavedState* const top = stateStack.getLast();
  202281. if (top != 0)
  202282. {
  202283. state = top;
  202284. stateStack.removeLast (1, false);
  202285. }
  202286. else
  202287. {
  202288. jassertfalse // trying to pop with an empty stack!
  202289. }
  202290. }
  202291. void setFill (const FillType& fillType)
  202292. {
  202293. state->fillType = fillType;
  202294. if (fillType.isColour())
  202295. {
  202296. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202297. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202298. CGContextSetAlpha (context, 1.0f);
  202299. }
  202300. }
  202301. void setOpacity (float newOpacity)
  202302. {
  202303. state->fillType.setOpacity (newOpacity);
  202304. setFill (state->fillType);
  202305. }
  202306. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202307. {
  202308. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202309. ? kCGInterpolationLow
  202310. : kCGInterpolationHigh);
  202311. }
  202312. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202313. {
  202314. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202315. if (replaceExistingContents)
  202316. {
  202317. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202318. CGContextClearRect (context, cgRect);
  202319. #else
  202320. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202321. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202322. CGContextClearRect (context, cgRect);
  202323. else
  202324. #endif
  202325. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202326. #endif
  202327. fillRect (r, false);
  202328. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202329. }
  202330. else
  202331. {
  202332. if (state->fillType.isColour())
  202333. {
  202334. CGContextFillRect (context, cgRect);
  202335. }
  202336. else if (state->fillType.isGradient())
  202337. {
  202338. CGContextSaveGState (context);
  202339. CGContextClipToRect (context, cgRect);
  202340. drawGradient();
  202341. CGContextRestoreGState (context);
  202342. }
  202343. else
  202344. {
  202345. CGContextSaveGState (context);
  202346. CGContextClipToRect (context, cgRect);
  202347. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202348. CGContextRestoreGState (context);
  202349. }
  202350. }
  202351. }
  202352. void fillPath (const Path& path, const AffineTransform& transform)
  202353. {
  202354. CGContextSaveGState (context);
  202355. if (state->fillType.isColour())
  202356. {
  202357. flip();
  202358. applyTransform (transform);
  202359. createPath (path);
  202360. if (path.isUsingNonZeroWinding())
  202361. CGContextFillPath (context);
  202362. else
  202363. CGContextEOFillPath (context);
  202364. }
  202365. else
  202366. {
  202367. createPath (path, transform);
  202368. if (path.isUsingNonZeroWinding())
  202369. CGContextClip (context);
  202370. else
  202371. CGContextEOClip (context);
  202372. if (state->fillType.isGradient())
  202373. drawGradient();
  202374. else
  202375. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202376. }
  202377. CGContextRestoreGState (context);
  202378. }
  202379. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202380. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202381. {
  202382. jassert (sourceImage.getBounds().contains (srcClip));
  202383. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202384. CGImageRef image = fullImage;
  202385. if (srcClip != sourceImage.getBounds())
  202386. {
  202387. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202388. srcClip.getWidth(), srcClip.getHeight()));
  202389. CGImageRelease (fullImage);
  202390. }
  202391. CGContextSaveGState (context);
  202392. CGContextSetAlpha (context, state->fillType.getOpacity());
  202393. flip();
  202394. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202395. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202396. if (fillEntireClipAsTiles)
  202397. {
  202398. #if JUCE_IPHONE
  202399. CGContextDrawTiledImage (context, imageRect, image);
  202400. #else
  202401. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202402. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202403. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202404. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202405. CGContextDrawTiledImage (context, imageRect, image);
  202406. else
  202407. #endif
  202408. {
  202409. // Fallback to manually doing a tiled fill on 10.4
  202410. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202411. const int iw = srcClip.getWidth();
  202412. const int ih = srcClip.getHeight();
  202413. int x = 0, y = 0;
  202414. while (x > clip.origin.x) x -= iw;
  202415. while (y > clip.origin.y) y -= ih;
  202416. const int right = (int) (clip.origin.x + clip.size.width);
  202417. const int bottom = (int) (clip.origin.y + clip.size.height);
  202418. while (y < bottom)
  202419. {
  202420. for (int x2 = x; x2 < right; x2 += iw)
  202421. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202422. y += ih;
  202423. }
  202424. }
  202425. #endif
  202426. }
  202427. else
  202428. {
  202429. CGContextDrawImage (context, imageRect, image);
  202430. }
  202431. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202432. CGContextRestoreGState (context);
  202433. }
  202434. void drawLine (double x1, double y1, double x2, double y2)
  202435. {
  202436. CGContextSetLineCap (context, kCGLineCapSquare);
  202437. CGContextSetLineWidth (context, 1.0f);
  202438. CGContextSetRGBStrokeColor (context,
  202439. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202440. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202441. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202442. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202443. CGContextStrokeLineSegments (context, line, 1);
  202444. }
  202445. void drawVerticalLine (const int x, double top, double bottom)
  202446. {
  202447. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202448. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202449. #else
  202450. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202451. // the x co-ord slightly to trick it..
  202452. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202453. #endif
  202454. }
  202455. void drawHorizontalLine (const int y, double left, double right)
  202456. {
  202457. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202458. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202459. #else
  202460. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202461. // the x co-ord slightly to trick it..
  202462. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202463. #endif
  202464. }
  202465. void setFont (const Font& newFont)
  202466. {
  202467. if (state->font != newFont)
  202468. {
  202469. state->fontRef = 0;
  202470. state->font = newFont;
  202471. MacTypeface* mf = dynamic_cast <MacTypeface*> (state->font.getTypeface());
  202472. if (mf != 0)
  202473. {
  202474. state->fontRef = mf->fontRef;
  202475. CGContextSetFont (context, state->fontRef);
  202476. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202477. state->fontTransform = mf->renderingTransform;
  202478. state->fontTransform.a *= state->font.getHorizontalScale();
  202479. CGContextSetTextMatrix (context, state->fontTransform);
  202480. }
  202481. }
  202482. }
  202483. const Font getFont()
  202484. {
  202485. return state->font;
  202486. }
  202487. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202488. {
  202489. if (state->fontRef != 0 && state->fillType.isColour())
  202490. {
  202491. if (transform.isOnlyTranslation())
  202492. {
  202493. CGGlyph g = glyphNumber;
  202494. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202495. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202496. }
  202497. else
  202498. {
  202499. CGContextSaveGState (context);
  202500. flip();
  202501. applyTransform (transform);
  202502. CGAffineTransform t = state->fontTransform;
  202503. t.d = -t.d;
  202504. CGContextSetTextMatrix (context, t);
  202505. CGGlyph g = glyphNumber;
  202506. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202507. CGContextSetTextMatrix (context, state->fontTransform);
  202508. CGContextRestoreGState (context);
  202509. }
  202510. }
  202511. else
  202512. {
  202513. Path p;
  202514. Font& f = state->font;
  202515. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202516. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202517. .followedBy (transform));
  202518. }
  202519. }
  202520. private:
  202521. CGContextRef context;
  202522. const CGFloat flipHeight;
  202523. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202524. CGFunctionCallbacks gradientCallbacks;
  202525. struct SavedState
  202526. {
  202527. SavedState()
  202528. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202529. {
  202530. }
  202531. SavedState (const SavedState& other)
  202532. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202533. fontTransform (other.fontTransform)
  202534. {
  202535. }
  202536. ~SavedState()
  202537. {
  202538. }
  202539. FillType fillType;
  202540. Font font;
  202541. CGFontRef fontRef;
  202542. CGAffineTransform fontTransform;
  202543. };
  202544. ScopedPointer <SavedState> state;
  202545. OwnedArray <SavedState> stateStack;
  202546. HeapBlock <PixelARGB> gradientLookupTable;
  202547. int numGradientLookupEntries;
  202548. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202549. {
  202550. const CoreGraphicsContext* const g = static_cast <const CoreGraphicsContext*> (info);
  202551. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202552. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202553. colour.unpremultiply();
  202554. outData[0] = colour.getRed() / 255.0f;
  202555. outData[1] = colour.getGreen() / 255.0f;
  202556. outData[2] = colour.getBlue() / 255.0f;
  202557. outData[3] = colour.getAlpha() / 255.0f;
  202558. }
  202559. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202560. {
  202561. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202562. --numGradientLookupEntries;
  202563. CGShadingRef result = 0;
  202564. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  202565. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202566. if (gradient.isRadial)
  202567. {
  202568. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202569. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202570. function, true, true);
  202571. }
  202572. else
  202573. {
  202574. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202575. CGPointMake (gradient.x2, gradient.y2),
  202576. function, true, true);
  202577. }
  202578. CGFunctionRelease (function);
  202579. return result;
  202580. }
  202581. void drawGradient()
  202582. {
  202583. flip();
  202584. applyTransform (state->fillType.transform);
  202585. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202586. // you draw a gradient with high quality interp enabled).
  202587. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202588. CGContextSetAlpha (context, state->fillType.getOpacity());
  202589. CGContextDrawShading (context, shading);
  202590. CGShadingRelease (shading);
  202591. }
  202592. void createPath (const Path& path) const
  202593. {
  202594. CGContextBeginPath (context);
  202595. Path::Iterator i (path);
  202596. while (i.next())
  202597. {
  202598. switch (i.elementType)
  202599. {
  202600. case Path::Iterator::startNewSubPath:
  202601. CGContextMoveToPoint (context, i.x1, i.y1);
  202602. break;
  202603. case Path::Iterator::lineTo:
  202604. CGContextAddLineToPoint (context, i.x1, i.y1);
  202605. break;
  202606. case Path::Iterator::quadraticTo:
  202607. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202608. break;
  202609. case Path::Iterator::cubicTo:
  202610. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202611. break;
  202612. case Path::Iterator::closePath:
  202613. CGContextClosePath (context); break;
  202614. default:
  202615. jassertfalse
  202616. break;
  202617. }
  202618. }
  202619. }
  202620. void createPath (const Path& path, const AffineTransform& transform) const
  202621. {
  202622. CGContextBeginPath (context);
  202623. Path::Iterator i (path);
  202624. while (i.next())
  202625. {
  202626. switch (i.elementType)
  202627. {
  202628. case Path::Iterator::startNewSubPath:
  202629. transform.transformPoint (i.x1, i.y1);
  202630. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202631. break;
  202632. case Path::Iterator::lineTo:
  202633. transform.transformPoint (i.x1, i.y1);
  202634. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202635. break;
  202636. case Path::Iterator::quadraticTo:
  202637. transform.transformPoint (i.x1, i.y1);
  202638. transform.transformPoint (i.x2, i.y2);
  202639. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202640. break;
  202641. case Path::Iterator::cubicTo:
  202642. transform.transformPoint (i.x1, i.y1);
  202643. transform.transformPoint (i.x2, i.y2);
  202644. transform.transformPoint (i.x3, i.y3);
  202645. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202646. break;
  202647. case Path::Iterator::closePath:
  202648. CGContextClosePath (context); break;
  202649. default:
  202650. jassertfalse
  202651. break;
  202652. }
  202653. }
  202654. }
  202655. static Image* createAlphaChannelImage (const Image& im)
  202656. {
  202657. if (im.getFormat() == Image::SingleChannel)
  202658. return const_cast <Image*> (&im);
  202659. return im.createCopyOfAlphaChannel();
  202660. }
  202661. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202662. {
  202663. if (im.getFormat() != Image::SingleChannel)
  202664. delete alphaIm;
  202665. }
  202666. void flip() const
  202667. {
  202668. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202669. }
  202670. void applyTransform (const AffineTransform& transform) const
  202671. {
  202672. CGAffineTransform t;
  202673. t.a = transform.mat00;
  202674. t.b = transform.mat10;
  202675. t.c = transform.mat01;
  202676. t.d = transform.mat11;
  202677. t.tx = transform.mat02;
  202678. t.ty = transform.mat12;
  202679. CGContextConcatCTM (context, t);
  202680. }
  202681. CoreGraphicsContext (const CoreGraphicsContext&);
  202682. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202683. };
  202684. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202685. {
  202686. return new CoreGraphicsContext (context, imageHeight);
  202687. }
  202688. #endif
  202689. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202690. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202691. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202692. // compiled on its own).
  202693. #if JUCE_INCLUDED_FILE
  202694. class UIViewComponentPeer;
  202695. END_JUCE_NAMESPACE
  202696. #define JuceUIView MakeObjCClassName(JuceUIView)
  202697. @interface JuceUIView : UIView <UITextFieldDelegate>
  202698. {
  202699. @public
  202700. UIViewComponentPeer* owner;
  202701. UITextField *hiddenTextField;
  202702. }
  202703. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202704. - (void) dealloc;
  202705. - (void) drawRect: (CGRect) r;
  202706. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202707. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202708. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202709. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202710. - (BOOL) becomeFirstResponder;
  202711. - (BOOL) resignFirstResponder;
  202712. - (BOOL) canBecomeFirstResponder;
  202713. - (void) asyncRepaint: (id) rect;
  202714. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string;
  202715. - (BOOL) textFieldShouldClear: (UITextField*) textField;
  202716. - (BOOL) textFieldShouldReturn: (UITextField*) textField;
  202717. @end
  202718. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202719. @interface JuceUIWindow : UIWindow
  202720. {
  202721. @private
  202722. UIViewComponentPeer* owner;
  202723. bool isZooming;
  202724. }
  202725. - (void) setOwner: (UIViewComponentPeer*) owner;
  202726. - (void) becomeKeyWindow;
  202727. @end
  202728. BEGIN_JUCE_NAMESPACE
  202729. class UIViewComponentPeer : public ComponentPeer,
  202730. public FocusChangeListener
  202731. {
  202732. public:
  202733. UIViewComponentPeer (Component* const component,
  202734. const int windowStyleFlags,
  202735. UIView* viewToAttachTo);
  202736. ~UIViewComponentPeer();
  202737. void* getNativeHandle() const;
  202738. void setVisible (bool shouldBeVisible);
  202739. void setTitle (const String& title);
  202740. void setPosition (int x, int y);
  202741. void setSize (int w, int h);
  202742. void setBounds (int x, int y, int w, int h, bool isNowFullScreen);
  202743. const Rectangle<int> getBounds() const;
  202744. const Rectangle<int> getBounds (const bool global) const;
  202745. const Point<int> getScreenPosition() const;
  202746. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202747. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202748. void setMinimised (bool shouldBeMinimised);
  202749. bool isMinimised() const;
  202750. void setFullScreen (bool shouldBeFullScreen);
  202751. bool isFullScreen() const;
  202752. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202753. const BorderSize getFrameSize() const;
  202754. bool setAlwaysOnTop (bool alwaysOnTop);
  202755. void toFront (bool makeActiveWindow);
  202756. void toBehind (ComponentPeer* other);
  202757. void setIcon (const Image& newIcon);
  202758. virtual void drawRect (CGRect r);
  202759. virtual bool canBecomeKeyWindow();
  202760. virtual bool windowShouldClose();
  202761. virtual void redirectMovedOrResized();
  202762. virtual CGRect constrainRect (CGRect r);
  202763. virtual void viewFocusGain();
  202764. virtual void viewFocusLoss();
  202765. bool isFocused() const;
  202766. void grabFocus();
  202767. void textInputRequired (const Point<int>& position);
  202768. virtual BOOL textFieldReplaceCharacters (const Range<int>& range, const String& text);
  202769. virtual BOOL textFieldShouldClear();
  202770. virtual BOOL textFieldShouldReturn();
  202771. void updateHiddenTextContent (TextInputTarget* target);
  202772. void globalFocusChanged (Component*);
  202773. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202774. void repaint (int x, int y, int w, int h);
  202775. void performAnyPendingRepaintsNow();
  202776. juce_UseDebuggingNewOperator
  202777. UIWindow* window;
  202778. JuceUIView* view;
  202779. bool isSharedWindow, fullScreen, insideDrawRect;
  202780. static ModifierKeys currentModifiers;
  202781. static int64 getMouseTime (UIEvent* e)
  202782. {
  202783. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202784. + (int64) ([e timestamp] * 1000.0);
  202785. }
  202786. Array <UITouch*> currentTouches;
  202787. };
  202788. END_JUCE_NAMESPACE
  202789. @implementation JuceUIView
  202790. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202791. withFrame: (CGRect) frame
  202792. {
  202793. [super initWithFrame: frame];
  202794. owner = owner_;
  202795. hiddenTextField = [[UITextField alloc] initWithFrame: CGRectMake (0, 0, 0, 0)];
  202796. [self addSubview: hiddenTextField];
  202797. hiddenTextField.delegate = self;
  202798. return self;
  202799. }
  202800. - (void) dealloc
  202801. {
  202802. [hiddenTextField removeFromSuperview];
  202803. [hiddenTextField release];
  202804. [super dealloc];
  202805. }
  202806. - (void) drawRect: (CGRect) r
  202807. {
  202808. if (owner != 0)
  202809. owner->drawRect (r);
  202810. }
  202811. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  202812. {
  202813. return false;
  202814. }
  202815. ModifierKeys UIViewComponentPeer::currentModifiers;
  202816. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202817. {
  202818. return UIViewComponentPeer::currentModifiers;
  202819. }
  202820. void ModifierKeys::updateCurrentModifiers() throw()
  202821. {
  202822. currentModifiers = UIViewComponentPeer::currentModifiers;
  202823. }
  202824. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202825. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202826. {
  202827. if (owner != 0)
  202828. owner->handleTouches (event, true, false, false);
  202829. }
  202830. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202831. {
  202832. if (owner != 0)
  202833. owner->handleTouches (event, false, false, false);
  202834. }
  202835. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202836. {
  202837. if (owner != 0)
  202838. owner->handleTouches (event, false, true, false);
  202839. }
  202840. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202841. {
  202842. if (owner != 0)
  202843. owner->handleTouches (event, false, true, true);
  202844. [self touchesEnded: touches withEvent: event];
  202845. }
  202846. - (BOOL) becomeFirstResponder
  202847. {
  202848. if (owner != 0)
  202849. owner->viewFocusGain();
  202850. return true;
  202851. }
  202852. - (BOOL) resignFirstResponder
  202853. {
  202854. if (owner != 0)
  202855. owner->viewFocusLoss();
  202856. return true;
  202857. }
  202858. - (BOOL) canBecomeFirstResponder
  202859. {
  202860. return owner != 0 && owner->canBecomeKeyWindow();
  202861. }
  202862. - (void) asyncRepaint: (id) rect
  202863. {
  202864. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202865. [self setNeedsDisplayInRect: *r];
  202866. }
  202867. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) text
  202868. {
  202869. return owner->textFieldReplaceCharacters (Range<int> (range.location, range.location + range.length),
  202870. nsStringToJuce (text));
  202871. }
  202872. - (BOOL) textFieldShouldClear: (UITextField*) textField
  202873. {
  202874. return owner->textFieldShouldClear();
  202875. }
  202876. - (BOOL) textFieldShouldReturn: (UITextField*) textField
  202877. {
  202878. return owner->textFieldShouldReturn();
  202879. }
  202880. @end
  202881. @implementation JuceUIWindow
  202882. - (void) setOwner: (UIViewComponentPeer*) owner_
  202883. {
  202884. owner = owner_;
  202885. isZooming = false;
  202886. }
  202887. - (void) becomeKeyWindow
  202888. {
  202889. [super becomeKeyWindow];
  202890. if (owner != 0)
  202891. owner->grabFocus();
  202892. }
  202893. @end
  202894. BEGIN_JUCE_NAMESPACE
  202895. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202896. const int windowStyleFlags,
  202897. UIView* viewToAttachTo)
  202898. : ComponentPeer (component, windowStyleFlags),
  202899. window (0),
  202900. view (0),
  202901. isSharedWindow (viewToAttachTo != 0),
  202902. fullScreen (false),
  202903. insideDrawRect (false)
  202904. {
  202905. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202906. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202907. if (isSharedWindow)
  202908. {
  202909. window = [viewToAttachTo window];
  202910. [viewToAttachTo addSubview: view];
  202911. setVisible (component->isVisible());
  202912. }
  202913. else
  202914. {
  202915. r.origin.x = (float) component->getX();
  202916. r.origin.y = (float) component->getY();
  202917. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202918. window = [[JuceUIWindow alloc] init];
  202919. window.frame = r;
  202920. window.opaque = component->isOpaque();
  202921. view.opaque = component->isOpaque();
  202922. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202923. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202924. [((JuceUIWindow*) window) setOwner: this];
  202925. if (component->isAlwaysOnTop())
  202926. window.windowLevel = UIWindowLevelAlert;
  202927. [window addSubview: view];
  202928. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202929. view.hidden = ! component->isVisible();
  202930. window.hidden = ! component->isVisible();
  202931. view.multipleTouchEnabled = YES;
  202932. }
  202933. setTitle (component->getName());
  202934. Desktop::getInstance().addFocusChangeListener (this);
  202935. }
  202936. UIViewComponentPeer::~UIViewComponentPeer()
  202937. {
  202938. Desktop::getInstance().removeFocusChangeListener (this);
  202939. view->owner = 0;
  202940. [view removeFromSuperview];
  202941. [view release];
  202942. if (! isSharedWindow)
  202943. {
  202944. [((JuceUIWindow*) window) setOwner: 0];
  202945. [window release];
  202946. }
  202947. }
  202948. void* UIViewComponentPeer::getNativeHandle() const
  202949. {
  202950. return view;
  202951. }
  202952. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202953. {
  202954. view.hidden = ! shouldBeVisible;
  202955. if (! isSharedWindow)
  202956. window.hidden = ! shouldBeVisible;
  202957. }
  202958. void UIViewComponentPeer::setTitle (const String& title)
  202959. {
  202960. // xxx is this possible?
  202961. }
  202962. void UIViewComponentPeer::setPosition (int x, int y)
  202963. {
  202964. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202965. }
  202966. void UIViewComponentPeer::setSize (int w, int h)
  202967. {
  202968. setBounds (component->getX(), component->getY(), w, h, false);
  202969. }
  202970. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202971. {
  202972. fullScreen = isNowFullScreen;
  202973. w = jmax (0, w);
  202974. h = jmax (0, h);
  202975. CGRect r;
  202976. r.origin.x = (float) x;
  202977. r.origin.y = (float) y;
  202978. r.size.width = (float) w;
  202979. r.size.height = (float) h;
  202980. if (isSharedWindow)
  202981. {
  202982. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202983. if ([view frame].size.width != r.size.width
  202984. || [view frame].size.height != r.size.height)
  202985. [view setNeedsDisplay];
  202986. view.frame = r;
  202987. }
  202988. else
  202989. {
  202990. window.frame = r;
  202991. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202992. }
  202993. }
  202994. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202995. {
  202996. CGRect r = [view frame];
  202997. if (global && [view window] != 0)
  202998. {
  202999. r = [view convertRect: r toView: nil];
  203000. CGRect wr = [[view window] frame];
  203001. r.origin.x += wr.origin.x;
  203002. r.origin.y += wr.origin.y;
  203003. }
  203004. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  203005. (int) r.size.width, (int) r.size.height);
  203006. }
  203007. const Rectangle<int> UIViewComponentPeer::getBounds() const
  203008. {
  203009. return getBounds (! isSharedWindow);
  203010. }
  203011. const Point<int> UIViewComponentPeer::getScreenPosition() const
  203012. {
  203013. return getBounds (true).getPosition();
  203014. }
  203015. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  203016. {
  203017. return relativePosition + getScreenPosition();
  203018. }
  203019. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  203020. {
  203021. return screenPosition - getScreenPosition();
  203022. }
  203023. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203024. {
  203025. if (constrainer != 0)
  203026. {
  203027. CGRect current = [window frame];
  203028. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203029. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203030. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203031. (int) r.size.width, (int) r.size.height);
  203032. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203033. (int) current.size.width, (int) current.size.height);
  203034. constrainer->checkBounds (pos, original,
  203035. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203036. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203037. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203038. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203039. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203040. r.origin.x = pos.getX();
  203041. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203042. r.size.width = pos.getWidth();
  203043. r.size.height = pos.getHeight();
  203044. }
  203045. return r;
  203046. }
  203047. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203048. {
  203049. // xxx
  203050. }
  203051. bool UIViewComponentPeer::isMinimised() const
  203052. {
  203053. return false;
  203054. }
  203055. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203056. {
  203057. if (! isSharedWindow)
  203058. {
  203059. Rectangle<int> r (lastNonFullscreenBounds);
  203060. setMinimised (false);
  203061. if (fullScreen != shouldBeFullScreen)
  203062. {
  203063. if (shouldBeFullScreen)
  203064. r = Desktop::getInstance().getMainMonitorArea();
  203065. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203066. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203067. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203068. }
  203069. }
  203070. }
  203071. bool UIViewComponentPeer::isFullScreen() const
  203072. {
  203073. return fullScreen;
  203074. }
  203075. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  203076. {
  203077. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203078. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203079. return false;
  203080. CGPoint p;
  203081. p.x = (float) position.getX();
  203082. p.y = (float) position.getY();
  203083. UIView* v = [view hitTest: p withEvent: nil];
  203084. if (trueIfInAChildWindow)
  203085. return v != nil;
  203086. return v == view;
  203087. }
  203088. const BorderSize UIViewComponentPeer::getFrameSize() const
  203089. {
  203090. BorderSize b;
  203091. if (! isSharedWindow)
  203092. {
  203093. CGRect v = [view convertRect: [view frame] toView: nil];
  203094. CGRect w = [window frame];
  203095. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203096. b.setBottom ((int) v.origin.y);
  203097. b.setLeft ((int) v.origin.x);
  203098. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203099. }
  203100. return b;
  203101. }
  203102. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203103. {
  203104. if (! isSharedWindow)
  203105. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203106. return true;
  203107. }
  203108. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203109. {
  203110. if (isSharedWindow)
  203111. [[view superview] bringSubviewToFront: view];
  203112. if (window != 0 && component->isVisible())
  203113. [window makeKeyAndVisible];
  203114. }
  203115. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203116. {
  203117. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203118. if (isSharedWindow)
  203119. {
  203120. [[view superview] insertSubview: view belowSubview: o->view];
  203121. }
  203122. else
  203123. {
  203124. jassertfalse // don't know how to do this
  203125. }
  203126. }
  203127. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203128. {
  203129. // to do..
  203130. }
  203131. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203132. {
  203133. NSArray* touches = [[event touchesForView: view] allObjects];
  203134. for (unsigned int i = 0; i < [touches count]; ++i)
  203135. {
  203136. UITouch* touch = [touches objectAtIndex: i];
  203137. CGPoint p = [touch locationInView: view];
  203138. const Point<int> pos ((int) p.x, (int) p.y);
  203139. juce_lastMousePos = pos + getScreenPosition();
  203140. const int64 time = getMouseTime (event);
  203141. int touchIndex = currentTouches.indexOf (touch);
  203142. if (touchIndex < 0)
  203143. {
  203144. touchIndex = currentTouches.size();
  203145. currentTouches.add (touch);
  203146. }
  203147. if (isDown)
  203148. {
  203149. currentModifiers = currentModifiers.withoutMouseButtons();
  203150. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203151. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203152. }
  203153. else if (isUp)
  203154. {
  203155. currentModifiers = currentModifiers.withoutMouseButtons();
  203156. currentTouches.remove (touchIndex);
  203157. }
  203158. if (isCancel)
  203159. currentTouches.clear();
  203160. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203161. }
  203162. }
  203163. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203164. void UIViewComponentPeer::viewFocusGain()
  203165. {
  203166. if (currentlyFocusedPeer != this)
  203167. {
  203168. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203169. currentlyFocusedPeer->handleFocusLoss();
  203170. currentlyFocusedPeer = this;
  203171. handleFocusGain();
  203172. }
  203173. }
  203174. void UIViewComponentPeer::viewFocusLoss()
  203175. {
  203176. if (currentlyFocusedPeer == this)
  203177. {
  203178. currentlyFocusedPeer = 0;
  203179. handleFocusLoss();
  203180. }
  203181. }
  203182. void juce_HandleProcessFocusChange()
  203183. {
  203184. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203185. {
  203186. if (Process::isForegroundProcess())
  203187. {
  203188. currentlyFocusedPeer->handleFocusGain();
  203189. ComponentPeer::bringModalComponentToFront();
  203190. }
  203191. else
  203192. {
  203193. currentlyFocusedPeer->handleFocusLoss();
  203194. // turn kiosk mode off if we lose focus..
  203195. Desktop::getInstance().setKioskModeComponent (0);
  203196. }
  203197. }
  203198. }
  203199. bool UIViewComponentPeer::isFocused() const
  203200. {
  203201. return isSharedWindow ? this == currentlyFocusedPeer
  203202. : (window != 0 && [window isKeyWindow]);
  203203. }
  203204. void UIViewComponentPeer::grabFocus()
  203205. {
  203206. if (window != 0)
  203207. {
  203208. [window makeKeyWindow];
  203209. viewFocusGain();
  203210. }
  203211. }
  203212. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203213. {
  203214. }
  203215. void UIViewComponentPeer::updateHiddenTextContent (TextInputTarget* target)
  203216. {
  203217. view->hiddenTextField.text = juceStringToNS (target->getTextInRange (Range<int> (0, target->getHighlightedRegion().getStart())));
  203218. }
  203219. BOOL UIViewComponentPeer::textFieldReplaceCharacters (const Range<int>& range, const String& text)
  203220. {
  203221. TextInputTarget* const target = findCurrentTextInputTarget();
  203222. if (target != 0)
  203223. {
  203224. const Range<int> currentSelection (target->getHighlightedRegion());
  203225. if (range.getLength() == 1 && text.isEmpty()) // (detect backspace)
  203226. if (currentSelection.isEmpty())
  203227. target->setHighlightedRegion (currentSelection.withStart (currentSelection.getStart() - 1));
  203228. target->insertTextAtCaret (text);
  203229. updateHiddenTextContent (target);
  203230. }
  203231. return NO;
  203232. }
  203233. BOOL UIViewComponentPeer::textFieldShouldClear()
  203234. {
  203235. TextInputTarget* const target = findCurrentTextInputTarget();
  203236. if (target != 0)
  203237. {
  203238. target->setHighlightedRegion (Range<int> (0, std::numeric_limits<int>::max()));
  203239. target->insertTextAtCaret (String::empty);
  203240. updateHiddenTextContent (target);
  203241. }
  203242. return YES;
  203243. }
  203244. BOOL UIViewComponentPeer::textFieldShouldReturn()
  203245. {
  203246. TextInputTarget* const target = findCurrentTextInputTarget();
  203247. if (target != 0)
  203248. {
  203249. target->insertTextAtCaret ("\n");
  203250. updateHiddenTextContent (target);
  203251. }
  203252. return YES;
  203253. }
  203254. void UIViewComponentPeer::globalFocusChanged (Component*)
  203255. {
  203256. TextInputTarget* const target = findCurrentTextInputTarget();
  203257. if (target != 0)
  203258. {
  203259. Component* comp = dynamic_cast<Component*> (target);
  203260. Point<int> pos (comp->relativePositionToOtherComponent (component, Point<int>()));
  203261. view->hiddenTextField.frame = CGRectMake (pos.getX(), pos.getY(), 0, 0);
  203262. updateHiddenTextContent (target);
  203263. [view->hiddenTextField becomeFirstResponder];
  203264. }
  203265. else
  203266. {
  203267. [view->hiddenTextField resignFirstResponder];
  203268. }
  203269. }
  203270. void UIViewComponentPeer::drawRect (CGRect r)
  203271. {
  203272. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203273. return;
  203274. CGContextRef cg = UIGraphicsGetCurrentContext();
  203275. if (! component->isOpaque())
  203276. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203277. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203278. CoreGraphicsContext g (cg, view.bounds.size.height);
  203279. insideDrawRect = true;
  203280. handlePaint (g);
  203281. insideDrawRect = false;
  203282. }
  203283. bool UIViewComponentPeer::canBecomeKeyWindow()
  203284. {
  203285. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203286. }
  203287. bool UIViewComponentPeer::windowShouldClose()
  203288. {
  203289. if (! isValidPeer (this))
  203290. return YES;
  203291. handleUserClosingWindow();
  203292. return NO;
  203293. }
  203294. void UIViewComponentPeer::redirectMovedOrResized()
  203295. {
  203296. handleMovedOrResized();
  203297. }
  203298. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203299. {
  203300. }
  203301. class AsyncRepaintMessage : public CallbackMessage
  203302. {
  203303. public:
  203304. UIViewComponentPeer* const peer;
  203305. const Rectangle<int> rect;
  203306. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203307. : peer (peer_), rect (rect_)
  203308. {
  203309. }
  203310. void messageCallback()
  203311. {
  203312. if (ComponentPeer::isValidPeer (peer))
  203313. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203314. }
  203315. };
  203316. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203317. {
  203318. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203319. {
  203320. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203321. }
  203322. else
  203323. {
  203324. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203325. }
  203326. }
  203327. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203328. {
  203329. }
  203330. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203331. {
  203332. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203333. }
  203334. Image* juce_createIconForFile (const File& file)
  203335. {
  203336. return 0;
  203337. }
  203338. void Desktop::createMouseInputSources()
  203339. {
  203340. for (int i = 0; i < 10; ++i)
  203341. mouseSources.add (new MouseInputSource (i, false));
  203342. }
  203343. bool Desktop::canUseSemiTransparentWindows() throw()
  203344. {
  203345. return true;
  203346. }
  203347. const Point<int> Desktop::getMousePosition()
  203348. {
  203349. return juce_lastMousePos;
  203350. }
  203351. void Desktop::setMousePosition (const Point<int>&)
  203352. {
  203353. }
  203354. const int KeyPress::spaceKey = ' ';
  203355. const int KeyPress::returnKey = 0x0d;
  203356. const int KeyPress::escapeKey = 0x1b;
  203357. const int KeyPress::backspaceKey = 0x7f;
  203358. const int KeyPress::leftKey = 0x1000;
  203359. const int KeyPress::rightKey = 0x1001;
  203360. const int KeyPress::upKey = 0x1002;
  203361. const int KeyPress::downKey = 0x1003;
  203362. const int KeyPress::pageUpKey = 0x1004;
  203363. const int KeyPress::pageDownKey = 0x1005;
  203364. const int KeyPress::endKey = 0x1006;
  203365. const int KeyPress::homeKey = 0x1007;
  203366. const int KeyPress::deleteKey = 0x1008;
  203367. const int KeyPress::insertKey = -1;
  203368. const int KeyPress::tabKey = 9;
  203369. const int KeyPress::F1Key = 0x2001;
  203370. const int KeyPress::F2Key = 0x2002;
  203371. const int KeyPress::F3Key = 0x2003;
  203372. const int KeyPress::F4Key = 0x2004;
  203373. const int KeyPress::F5Key = 0x2005;
  203374. const int KeyPress::F6Key = 0x2006;
  203375. const int KeyPress::F7Key = 0x2007;
  203376. const int KeyPress::F8Key = 0x2008;
  203377. const int KeyPress::F9Key = 0x2009;
  203378. const int KeyPress::F10Key = 0x200a;
  203379. const int KeyPress::F11Key = 0x200b;
  203380. const int KeyPress::F12Key = 0x200c;
  203381. const int KeyPress::F13Key = 0x200d;
  203382. const int KeyPress::F14Key = 0x200e;
  203383. const int KeyPress::F15Key = 0x200f;
  203384. const int KeyPress::F16Key = 0x2010;
  203385. const int KeyPress::numberPad0 = 0x30020;
  203386. const int KeyPress::numberPad1 = 0x30021;
  203387. const int KeyPress::numberPad2 = 0x30022;
  203388. const int KeyPress::numberPad3 = 0x30023;
  203389. const int KeyPress::numberPad4 = 0x30024;
  203390. const int KeyPress::numberPad5 = 0x30025;
  203391. const int KeyPress::numberPad6 = 0x30026;
  203392. const int KeyPress::numberPad7 = 0x30027;
  203393. const int KeyPress::numberPad8 = 0x30028;
  203394. const int KeyPress::numberPad9 = 0x30029;
  203395. const int KeyPress::numberPadAdd = 0x3002a;
  203396. const int KeyPress::numberPadSubtract = 0x3002b;
  203397. const int KeyPress::numberPadMultiply = 0x3002c;
  203398. const int KeyPress::numberPadDivide = 0x3002d;
  203399. const int KeyPress::numberPadSeparator = 0x3002e;
  203400. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203401. const int KeyPress::numberPadEquals = 0x30030;
  203402. const int KeyPress::numberPadDelete = 0x30031;
  203403. const int KeyPress::playKey = 0x30000;
  203404. const int KeyPress::stopKey = 0x30001;
  203405. const int KeyPress::fastForwardKey = 0x30002;
  203406. const int KeyPress::rewindKey = 0x30003;
  203407. #endif
  203408. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203409. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203410. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203411. // compiled on its own).
  203412. #if JUCE_INCLUDED_FILE
  203413. struct CallbackMessagePayload
  203414. {
  203415. MessageCallbackFunction* function;
  203416. void* parameter;
  203417. void* volatile result;
  203418. bool volatile hasBeenExecuted;
  203419. };
  203420. END_JUCE_NAMESPACE
  203421. using namespace JUCE_NAMESPACE;
  203422. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203423. {
  203424. }
  203425. - (JuceAppDelegate*) init;
  203426. - (void) dealloc;
  203427. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203428. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203429. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203430. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203431. - (void) customEvent: (id) data;
  203432. - (void) performCallback: (id) info;
  203433. @end
  203434. @implementation JuceAppDelegate
  203435. - (JuceAppDelegate*) init
  203436. {
  203437. [super init];
  203438. [[UIApplication sharedApplication] setDelegate: self];
  203439. return self;
  203440. }
  203441. - (void) dealloc
  203442. {
  203443. [[UIApplication sharedApplication] setDelegate: nil];
  203444. [super dealloc];
  203445. }
  203446. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203447. {
  203448. if (JUCEApplication::getInstance() != 0)
  203449. {
  203450. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203451. return YES;
  203452. }
  203453. return NO;
  203454. }
  203455. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203456. {
  203457. juce_HandleProcessFocusChange();
  203458. }
  203459. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203460. {
  203461. juce_HandleProcessFocusChange();
  203462. }
  203463. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203464. {
  203465. juce_HandleProcessFocusChange();
  203466. }
  203467. - (void) customEvent: (id) n
  203468. {
  203469. NSData* data = (NSData*) n;
  203470. void* message = 0;
  203471. [data getBytes: &message length: sizeof (message)];
  203472. [data release];
  203473. if (message != 0)
  203474. MessageManager::getInstance()->deliverMessage (message);
  203475. }
  203476. - (void) performCallback: (id) info
  203477. {
  203478. if ([info isKindOfClass: [NSData class]])
  203479. {
  203480. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203481. if (pl != 0)
  203482. {
  203483. pl->result = (*pl->function) (pl->parameter);
  203484. pl->hasBeenExecuted = true;
  203485. }
  203486. }
  203487. else
  203488. {
  203489. jassertfalse // should never get here!
  203490. }
  203491. }
  203492. @end
  203493. BEGIN_JUCE_NAMESPACE
  203494. static JuceAppDelegate* juceAppDelegate = 0;
  203495. void MessageManager::runDispatchLoop()
  203496. {
  203497. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203498. runDispatchLoopUntil (-1);
  203499. }
  203500. void MessageManager::stopDispatchLoop()
  203501. {
  203502. exit (0); // iPhone apps get no mercy..
  203503. }
  203504. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203505. {
  203506. const ScopedAutoReleasePool pool;
  203507. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203508. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203509. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203510. while (! quitMessagePosted)
  203511. {
  203512. const ScopedAutoReleasePool pool;
  203513. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203514. beforeDate: endDate];
  203515. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203516. break;
  203517. }
  203518. return ! quitMessagePosted;
  203519. }
  203520. static CFRunLoopRef runLoop = 0;
  203521. static CFRunLoopSourceRef runLoopSource = 0;
  203522. static Array <void*, CriticalSection>* pendingMessages = 0;
  203523. static void runLoopSourceCallback (void*)
  203524. {
  203525. if (pendingMessages != 0)
  203526. {
  203527. int numDispatched = 0;
  203528. do
  203529. {
  203530. void* const nextMessage = pendingMessages->remove (0);
  203531. if (nextMessage == 0)
  203532. return;
  203533. const ScopedAutoReleasePool pool;
  203534. MessageManager::getInstance()->deliverMessage (nextMessage);
  203535. } while (++numDispatched <= 4);
  203536. CFRunLoopSourceSignal (runLoopSource);
  203537. CFRunLoopWakeUp (runLoop);
  203538. }
  203539. }
  203540. void MessageManager::doPlatformSpecificInitialisation()
  203541. {
  203542. pendingMessages = new Array <void*, CriticalSection>();
  203543. runLoop = CFRunLoopGetCurrent();
  203544. CFRunLoopSourceContext sourceContext;
  203545. zerostruct (sourceContext);
  203546. sourceContext.perform = runLoopSourceCallback;
  203547. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203548. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203549. if (juceAppDelegate == 0)
  203550. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203551. }
  203552. void MessageManager::doPlatformSpecificShutdown()
  203553. {
  203554. CFRunLoopSourceInvalidate (runLoopSource);
  203555. CFRelease (runLoopSource);
  203556. runLoopSource = 0;
  203557. if (pendingMessages != 0)
  203558. {
  203559. while (pendingMessages->size() > 0)
  203560. delete ((Message*) pendingMessages->remove(0));
  203561. deleteAndZero (pendingMessages);
  203562. }
  203563. if (juceAppDelegate != 0)
  203564. {
  203565. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203566. [juceAppDelegate release];
  203567. juceAppDelegate = 0;
  203568. }
  203569. }
  203570. bool juce_postMessageToSystemQueue (void* message)
  203571. {
  203572. if (pendingMessages != 0)
  203573. {
  203574. pendingMessages->add (message);
  203575. CFRunLoopSourceSignal (runLoopSource);
  203576. CFRunLoopWakeUp (runLoop);
  203577. }
  203578. return true;
  203579. }
  203580. void MessageManager::broadcastMessage (const String& value) throw()
  203581. {
  203582. }
  203583. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203584. void* data)
  203585. {
  203586. if (isThisTheMessageThread())
  203587. {
  203588. return (*callback) (data);
  203589. }
  203590. else
  203591. {
  203592. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203593. // deadlock because the message manager is blocked from running, so can never
  203594. // call your function..
  203595. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203596. const ScopedAutoReleasePool pool;
  203597. CallbackMessagePayload cmp;
  203598. cmp.function = callback;
  203599. cmp.parameter = data;
  203600. cmp.result = 0;
  203601. cmp.hasBeenExecuted = false;
  203602. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203603. withObject: [NSData dataWithBytesNoCopy: &cmp
  203604. length: sizeof (cmp)
  203605. freeWhenDone: NO]
  203606. waitUntilDone: YES];
  203607. return cmp.result;
  203608. }
  203609. }
  203610. #endif
  203611. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203612. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203613. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203614. // compiled on its own).
  203615. #if JUCE_INCLUDED_FILE
  203616. #if JUCE_MAC
  203617. END_JUCE_NAMESPACE
  203618. using namespace JUCE_NAMESPACE;
  203619. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203620. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203621. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203622. #else
  203623. @interface JuceFileChooserDelegate : NSObject
  203624. #endif
  203625. {
  203626. StringArray* filters;
  203627. }
  203628. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203629. - (void) dealloc;
  203630. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203631. @end
  203632. @implementation JuceFileChooserDelegate
  203633. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203634. {
  203635. [super init];
  203636. filters = filters_;
  203637. return self;
  203638. }
  203639. - (void) dealloc
  203640. {
  203641. delete filters;
  203642. [super dealloc];
  203643. }
  203644. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203645. {
  203646. const File f (nsStringToJuce (filename));
  203647. for (int i = filters->size(); --i >= 0;)
  203648. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203649. return true;
  203650. return f.isDirectory();
  203651. }
  203652. @end
  203653. BEGIN_JUCE_NAMESPACE
  203654. void FileChooser::showPlatformDialog (Array<File>& results,
  203655. const String& title,
  203656. const File& currentFileOrDirectory,
  203657. const String& filter,
  203658. bool selectsDirectory,
  203659. bool selectsFiles,
  203660. bool isSaveDialogue,
  203661. bool warnAboutOverwritingExistingFiles,
  203662. bool selectMultipleFiles,
  203663. FilePreviewComponent* extraInfoComponent)
  203664. {
  203665. const ScopedAutoReleasePool pool;
  203666. StringArray* filters = new StringArray();
  203667. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  203668. filters->trim();
  203669. filters->removeEmptyStrings();
  203670. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203671. [delegate autorelease];
  203672. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203673. : [NSOpenPanel openPanel];
  203674. [panel setTitle: juceStringToNS (title)];
  203675. if (! isSaveDialogue)
  203676. {
  203677. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203678. [openPanel setCanChooseDirectories: selectsDirectory];
  203679. [openPanel setCanChooseFiles: selectsFiles];
  203680. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203681. }
  203682. [panel setDelegate: delegate];
  203683. if (isSaveDialogue || selectsDirectory)
  203684. [panel setCanCreateDirectories: YES];
  203685. String directory, filename;
  203686. if (currentFileOrDirectory.isDirectory())
  203687. {
  203688. directory = currentFileOrDirectory.getFullPathName();
  203689. }
  203690. else
  203691. {
  203692. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203693. filename = currentFileOrDirectory.getFileName();
  203694. }
  203695. if ([panel runModalForDirectory: juceStringToNS (directory)
  203696. file: juceStringToNS (filename)]
  203697. == NSOKButton)
  203698. {
  203699. if (isSaveDialogue)
  203700. {
  203701. results.add (File (nsStringToJuce ([panel filename])));
  203702. }
  203703. else
  203704. {
  203705. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203706. NSArray* urls = [openPanel filenames];
  203707. for (unsigned int i = 0; i < [urls count]; ++i)
  203708. {
  203709. NSString* f = [urls objectAtIndex: i];
  203710. results.add (File (nsStringToJuce (f)));
  203711. }
  203712. }
  203713. }
  203714. [panel setDelegate: nil];
  203715. }
  203716. #else
  203717. void FileChooser::showPlatformDialog (Array<File>& results,
  203718. const String& title,
  203719. const File& currentFileOrDirectory,
  203720. const String& filter,
  203721. bool selectsDirectory,
  203722. bool selectsFiles,
  203723. bool isSaveDialogue,
  203724. bool warnAboutOverwritingExistingFiles,
  203725. bool selectMultipleFiles,
  203726. FilePreviewComponent* extraInfoComponent)
  203727. {
  203728. const ScopedAutoReleasePool pool;
  203729. jassertfalse //xxx to do
  203730. }
  203731. #endif
  203732. #endif
  203733. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203734. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203735. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203736. // compiled on its own).
  203737. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203738. #if JUCE_MAC
  203739. END_JUCE_NAMESPACE
  203740. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203741. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203742. {
  203743. CriticalSection* contextLock;
  203744. bool needsUpdate;
  203745. }
  203746. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203747. - (bool) makeActive;
  203748. - (void) makeInactive;
  203749. - (void) reshape;
  203750. @end
  203751. @implementation ThreadSafeNSOpenGLView
  203752. - (id) initWithFrame: (NSRect) frameRect
  203753. pixelFormat: (NSOpenGLPixelFormat*) format
  203754. {
  203755. contextLock = new CriticalSection();
  203756. self = [super initWithFrame: frameRect pixelFormat: format];
  203757. if (self != nil)
  203758. [[NSNotificationCenter defaultCenter] addObserver: self
  203759. selector: @selector (_surfaceNeedsUpdate:)
  203760. name: NSViewGlobalFrameDidChangeNotification
  203761. object: self];
  203762. return self;
  203763. }
  203764. - (void) dealloc
  203765. {
  203766. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203767. delete contextLock;
  203768. [super dealloc];
  203769. }
  203770. - (bool) makeActive
  203771. {
  203772. const ScopedLock sl (*contextLock);
  203773. if ([self openGLContext] == 0)
  203774. return false;
  203775. [[self openGLContext] makeCurrentContext];
  203776. if (needsUpdate)
  203777. {
  203778. [super update];
  203779. needsUpdate = false;
  203780. }
  203781. return true;
  203782. }
  203783. - (void) makeInactive
  203784. {
  203785. const ScopedLock sl (*contextLock);
  203786. [NSOpenGLContext clearCurrentContext];
  203787. }
  203788. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203789. {
  203790. const ScopedLock sl (*contextLock);
  203791. needsUpdate = true;
  203792. }
  203793. - (void) update
  203794. {
  203795. const ScopedLock sl (*contextLock);
  203796. needsUpdate = true;
  203797. }
  203798. - (void) reshape
  203799. {
  203800. const ScopedLock sl (*contextLock);
  203801. needsUpdate = true;
  203802. }
  203803. @end
  203804. BEGIN_JUCE_NAMESPACE
  203805. class WindowedGLContext : public OpenGLContext
  203806. {
  203807. public:
  203808. WindowedGLContext (Component* const component,
  203809. const OpenGLPixelFormat& pixelFormat_,
  203810. NSOpenGLContext* sharedContext)
  203811. : renderContext (0),
  203812. pixelFormat (pixelFormat_)
  203813. {
  203814. jassert (component != 0);
  203815. NSOpenGLPixelFormatAttribute attribs [64];
  203816. int n = 0;
  203817. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203818. attribs[n++] = NSOpenGLPFAAccelerated;
  203819. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203820. attribs[n++] = NSOpenGLPFAColorSize;
  203821. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203822. pixelFormat.greenBits,
  203823. pixelFormat.blueBits);
  203824. attribs[n++] = NSOpenGLPFAAlphaSize;
  203825. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203826. attribs[n++] = NSOpenGLPFADepthSize;
  203827. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203828. attribs[n++] = NSOpenGLPFAStencilSize;
  203829. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203830. attribs[n++] = NSOpenGLPFAAccumSize;
  203831. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203832. pixelFormat.accumulationBufferGreenBits,
  203833. pixelFormat.accumulationBufferBlueBits,
  203834. pixelFormat.accumulationBufferAlphaBits);
  203835. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203836. attribs[n++] = NSOpenGLPFASampleBuffers;
  203837. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203838. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203839. attribs[n++] = NSOpenGLPFANoRecovery;
  203840. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203841. NSOpenGLPixelFormat* format
  203842. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203843. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203844. pixelFormat: format];
  203845. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203846. shareContext: sharedContext] autorelease];
  203847. const GLint swapInterval = 1;
  203848. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203849. [view setOpenGLContext: renderContext];
  203850. [renderContext setView: view];
  203851. [format release];
  203852. viewHolder = new NSViewComponentInternal (view, component);
  203853. }
  203854. ~WindowedGLContext()
  203855. {
  203856. makeInactive();
  203857. [renderContext clearDrawable];
  203858. viewHolder = 0;
  203859. }
  203860. bool makeActive() const throw()
  203861. {
  203862. jassert (renderContext != 0);
  203863. [view makeActive];
  203864. return isActive();
  203865. }
  203866. bool makeInactive() const throw()
  203867. {
  203868. [view makeInactive];
  203869. return true;
  203870. }
  203871. bool isActive() const throw()
  203872. {
  203873. return [NSOpenGLContext currentContext] == renderContext;
  203874. }
  203875. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203876. void* getRawContext() const throw() { return renderContext; }
  203877. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203878. {
  203879. }
  203880. void swapBuffers()
  203881. {
  203882. [renderContext flushBuffer];
  203883. }
  203884. bool setSwapInterval (const int numFramesPerSwap)
  203885. {
  203886. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203887. forParameter: NSOpenGLCPSwapInterval];
  203888. return true;
  203889. }
  203890. int getSwapInterval() const
  203891. {
  203892. GLint numFrames = 0;
  203893. [renderContext getValues: &numFrames
  203894. forParameter: NSOpenGLCPSwapInterval];
  203895. return numFrames;
  203896. }
  203897. void repaint()
  203898. {
  203899. // we need to invalidate the juce view that holds this gl view, to make it
  203900. // cause a repaint callback
  203901. NSView* v = (NSView*) viewHolder->view;
  203902. NSRect r = [v frame];
  203903. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203904. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203905. // repaint message, thus never causing our paint() callback, and never repainting
  203906. // the comp. So invalidating just a little bit around the edge helps..
  203907. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203908. }
  203909. void* getNativeWindowHandle() const { return viewHolder->view; }
  203910. juce_UseDebuggingNewOperator
  203911. NSOpenGLContext* renderContext;
  203912. ThreadSafeNSOpenGLView* view;
  203913. private:
  203914. OpenGLPixelFormat pixelFormat;
  203915. ScopedPointer <NSViewComponentInternal> viewHolder;
  203916. WindowedGLContext (const WindowedGLContext&);
  203917. WindowedGLContext& operator= (const WindowedGLContext&);
  203918. };
  203919. OpenGLContext* OpenGLComponent::createContext()
  203920. {
  203921. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203922. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203923. return (c->renderContext != 0) ? c.release() : 0;
  203924. }
  203925. void* OpenGLComponent::getNativeWindowHandle() const
  203926. {
  203927. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  203928. : 0;
  203929. }
  203930. void juce_glViewport (const int w, const int h)
  203931. {
  203932. glViewport (0, 0, w, h);
  203933. }
  203934. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203935. OwnedArray <OpenGLPixelFormat>& results)
  203936. {
  203937. /* GLint attribs [64];
  203938. int n = 0;
  203939. attribs[n++] = AGL_RGBA;
  203940. attribs[n++] = AGL_DOUBLEBUFFER;
  203941. attribs[n++] = AGL_ACCELERATED;
  203942. attribs[n++] = AGL_NO_RECOVERY;
  203943. attribs[n++] = AGL_NONE;
  203944. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203945. while (p != 0)
  203946. {
  203947. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203948. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203949. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203950. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203951. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203952. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203953. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203954. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203955. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203956. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203957. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203958. results.add (pf);
  203959. p = aglNextPixelFormat (p);
  203960. }*/
  203961. //jassertfalse //xxx can't see how you do this in cocoa!
  203962. }
  203963. #else
  203964. END_JUCE_NAMESPACE
  203965. @interface JuceGLView : UIView
  203966. {
  203967. }
  203968. + (Class) layerClass;
  203969. @end
  203970. @implementation JuceGLView
  203971. + (Class) layerClass
  203972. {
  203973. return [CAEAGLLayer class];
  203974. }
  203975. @end
  203976. BEGIN_JUCE_NAMESPACE
  203977. class GLESContext : public OpenGLContext
  203978. {
  203979. public:
  203980. GLESContext (UIViewComponentPeer* peer,
  203981. Component* const component_,
  203982. const OpenGLPixelFormat& pixelFormat_,
  203983. const GLESContext* const sharedContext,
  203984. NSUInteger apiType)
  203985. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203986. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203987. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203988. {
  203989. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203990. view.opaque = YES;
  203991. view.hidden = NO;
  203992. view.backgroundColor = [UIColor blackColor];
  203993. view.userInteractionEnabled = NO;
  203994. glLayer = (CAEAGLLayer*) [view layer];
  203995. [peer->view addSubview: view];
  203996. if (sharedContext != 0)
  203997. context = [[EAGLContext alloc] initWithAPI: apiType
  203998. sharegroup: [sharedContext->context sharegroup]];
  203999. else
  204000. context = [[EAGLContext alloc] initWithAPI: apiType];
  204001. createGLBuffers();
  204002. }
  204003. ~GLESContext()
  204004. {
  204005. makeInactive();
  204006. [context release];
  204007. [view removeFromSuperview];
  204008. [view release];
  204009. freeGLBuffers();
  204010. }
  204011. bool makeActive() const throw()
  204012. {
  204013. jassert (context != 0);
  204014. [EAGLContext setCurrentContext: context];
  204015. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  204016. return true;
  204017. }
  204018. void swapBuffers()
  204019. {
  204020. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204021. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  204022. }
  204023. bool makeInactive() const throw()
  204024. {
  204025. return [EAGLContext setCurrentContext: nil];
  204026. }
  204027. bool isActive() const throw()
  204028. {
  204029. return [EAGLContext currentContext] == context;
  204030. }
  204031. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204032. void* getRawContext() const throw() { return glLayer; }
  204033. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204034. {
  204035. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  204036. if (lastWidth != w || lastHeight != h)
  204037. {
  204038. lastWidth = w;
  204039. lastHeight = h;
  204040. freeGLBuffers();
  204041. createGLBuffers();
  204042. }
  204043. }
  204044. bool setSwapInterval (const int numFramesPerSwap)
  204045. {
  204046. numFrames = numFramesPerSwap;
  204047. return true;
  204048. }
  204049. int getSwapInterval() const
  204050. {
  204051. return numFrames;
  204052. }
  204053. void repaint()
  204054. {
  204055. }
  204056. void createGLBuffers()
  204057. {
  204058. makeActive();
  204059. glGenFramebuffersOES (1, &frameBufferHandle);
  204060. glGenRenderbuffersOES (1, &colorBufferHandle);
  204061. glGenRenderbuffersOES (1, &depthBufferHandle);
  204062. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204063. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  204064. GLint width, height;
  204065. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  204066. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  204067. if (useDepthBuffer)
  204068. {
  204069. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  204070. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  204071. }
  204072. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204073. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  204074. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  204075. if (useDepthBuffer)
  204076. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  204077. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  204078. }
  204079. void freeGLBuffers()
  204080. {
  204081. if (frameBufferHandle != 0)
  204082. {
  204083. glDeleteFramebuffersOES (1, &frameBufferHandle);
  204084. frameBufferHandle = 0;
  204085. }
  204086. if (colorBufferHandle != 0)
  204087. {
  204088. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  204089. colorBufferHandle = 0;
  204090. }
  204091. if (depthBufferHandle != 0)
  204092. {
  204093. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  204094. depthBufferHandle = 0;
  204095. }
  204096. }
  204097. juce_UseDebuggingNewOperator
  204098. private:
  204099. Component::SafePointer<Component> component;
  204100. OpenGLPixelFormat pixelFormat;
  204101. JuceGLView* view;
  204102. CAEAGLLayer* glLayer;
  204103. EAGLContext* context;
  204104. bool useDepthBuffer;
  204105. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  204106. int numFrames;
  204107. int lastWidth, lastHeight;
  204108. GLESContext (const GLESContext&);
  204109. GLESContext& operator= (const GLESContext&);
  204110. };
  204111. OpenGLContext* OpenGLComponent::createContext()
  204112. {
  204113. ScopedAutoReleasePool pool;
  204114. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  204115. if (peer != 0)
  204116. return new GLESContext (peer, this, preferredPixelFormat,
  204117. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  204118. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  204119. return 0;
  204120. }
  204121. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204122. OwnedArray <OpenGLPixelFormat>& /*results*/)
  204123. {
  204124. }
  204125. void juce_glViewport (const int w, const int h)
  204126. {
  204127. glViewport (0, 0, w, h);
  204128. }
  204129. #endif
  204130. #endif
  204131. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204132. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204133. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204134. // compiled on its own).
  204135. #if JUCE_INCLUDED_FILE
  204136. #if JUCE_MAC
  204137. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  204138. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  204139. {
  204140. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204141. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204142. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204143. [im release];
  204144. return c;
  204145. }
  204146. static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy)
  204147. {
  204148. MemoryInputStream stream (data, false);
  204149. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  204150. jassert (im != 0);
  204151. if (im == 0)
  204152. return 0;
  204153. return juce_createMouseCursorFromImage (*im,
  204154. (int) (hx * im->getWidth()),
  204155. (int) (hy * im->getHeight()));
  204156. }
  204157. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204158. {
  204159. const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204160. MemoryBlock mb;
  204161. if (f.getChildFile (filename).loadFileAsData (mb))
  204162. return juce_cursorFromData (mb, hx, hy);
  204163. return 0;
  204164. }
  204165. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  204166. {
  204167. const ScopedAutoReleasePool pool;
  204168. NSCursor* c = 0;
  204169. switch (type)
  204170. {
  204171. case MouseCursor::NormalCursor:
  204172. c = [NSCursor arrowCursor];
  204173. break;
  204174. case MouseCursor::NoCursor:
  204175. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204176. case MouseCursor::DraggingHandCursor:
  204177. c = [NSCursor openHandCursor];
  204178. break;
  204179. case MouseCursor::CopyingCursor:
  204180. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204181. case MouseCursor::WaitCursor:
  204182. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204183. break;
  204184. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204185. case MouseCursor::IBeamCursor:
  204186. c = [NSCursor IBeamCursor];
  204187. break;
  204188. case MouseCursor::PointingHandCursor:
  204189. c = [NSCursor pointingHandCursor];
  204190. break;
  204191. case MouseCursor::LeftRightResizeCursor:
  204192. c = [NSCursor resizeLeftRightCursor];
  204193. break;
  204194. case MouseCursor::LeftEdgeResizeCursor:
  204195. c = [NSCursor resizeLeftCursor];
  204196. break;
  204197. case MouseCursor::RightEdgeResizeCursor:
  204198. c = [NSCursor resizeRightCursor];
  204199. break;
  204200. case MouseCursor::UpDownResizeCursor:
  204201. case MouseCursor::TopEdgeResizeCursor:
  204202. case MouseCursor::BottomEdgeResizeCursor:
  204203. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204204. case MouseCursor::TopLeftCornerResizeCursor:
  204205. case MouseCursor::BottomRightCornerResizeCursor:
  204206. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204207. case MouseCursor::TopRightCornerResizeCursor:
  204208. case MouseCursor::BottomLeftCornerResizeCursor:
  204209. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204210. case MouseCursor::UpDownLeftRightResizeCursor:
  204211. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204212. case MouseCursor::CrosshairCursor:
  204213. c = [NSCursor crosshairCursor];
  204214. break;
  204215. }
  204216. [c retain];
  204217. return c;
  204218. }
  204219. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  204220. {
  204221. NSCursor* c = (NSCursor*) cursorHandle;
  204222. [c release];
  204223. }
  204224. void MouseCursor::showInAllWindows() const
  204225. {
  204226. showInWindow (0);
  204227. }
  204228. void MouseCursor::showInWindow (ComponentPeer*) const
  204229. {
  204230. NSCursor* const c = (NSCursor*) getHandle();
  204231. [c set];
  204232. }
  204233. #else
  204234. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; }
  204235. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; }
  204236. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  204237. void MouseCursor::showInAllWindows() const {}
  204238. void MouseCursor::showInWindow (ComponentPeer*) const {}
  204239. #endif
  204240. #endif
  204241. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204242. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204243. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204244. // compiled on its own).
  204245. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204246. #if JUCE_MAC
  204247. END_JUCE_NAMESPACE
  204248. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204249. @interface DownloadClickDetector : NSObject
  204250. {
  204251. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204252. }
  204253. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204254. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204255. request: (NSURLRequest*) request
  204256. frame: (WebFrame*) frame
  204257. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204258. @end
  204259. @implementation DownloadClickDetector
  204260. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204261. {
  204262. [super init];
  204263. ownerComponent = ownerComponent_;
  204264. return self;
  204265. }
  204266. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204267. request: (NSURLRequest*) request
  204268. frame: (WebFrame*) frame
  204269. decisionListener: (id <WebPolicyDecisionListener>) listener
  204270. {
  204271. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204272. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204273. [listener use];
  204274. else
  204275. [listener ignore];
  204276. }
  204277. @end
  204278. BEGIN_JUCE_NAMESPACE
  204279. class WebBrowserComponentInternal : public NSViewComponent
  204280. {
  204281. public:
  204282. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204283. {
  204284. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204285. frameName: @""
  204286. groupName: @""];
  204287. setView (webView);
  204288. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204289. [webView setPolicyDelegate: clickListener];
  204290. }
  204291. ~WebBrowserComponentInternal()
  204292. {
  204293. [webView setPolicyDelegate: nil];
  204294. [clickListener release];
  204295. setView (0);
  204296. }
  204297. void goToURL (const String& url,
  204298. const StringArray* headers,
  204299. const MemoryBlock* postData)
  204300. {
  204301. NSMutableURLRequest* r
  204302. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204303. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204304. timeoutInterval: 30.0];
  204305. if (postData != 0 && postData->getSize() > 0)
  204306. {
  204307. [r setHTTPMethod: @"POST"];
  204308. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204309. length: postData->getSize()]];
  204310. }
  204311. if (headers != 0)
  204312. {
  204313. for (int i = 0; i < headers->size(); ++i)
  204314. {
  204315. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  204316. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  204317. [r setValue: juceStringToNS (headerValue)
  204318. forHTTPHeaderField: juceStringToNS (headerName)];
  204319. }
  204320. }
  204321. stop();
  204322. [[webView mainFrame] loadRequest: r];
  204323. }
  204324. void goBack()
  204325. {
  204326. [webView goBack];
  204327. }
  204328. void goForward()
  204329. {
  204330. [webView goForward];
  204331. }
  204332. void stop()
  204333. {
  204334. [webView stopLoading: nil];
  204335. }
  204336. void refresh()
  204337. {
  204338. [webView reload: nil];
  204339. }
  204340. private:
  204341. WebView* webView;
  204342. DownloadClickDetector* clickListener;
  204343. };
  204344. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204345. : browser (0),
  204346. blankPageShown (false),
  204347. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204348. {
  204349. setOpaque (true);
  204350. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204351. }
  204352. WebBrowserComponent::~WebBrowserComponent()
  204353. {
  204354. deleteAndZero (browser);
  204355. }
  204356. void WebBrowserComponent::goToURL (const String& url,
  204357. const StringArray* headers,
  204358. const MemoryBlock* postData)
  204359. {
  204360. lastURL = url;
  204361. lastHeaders.clear();
  204362. if (headers != 0)
  204363. lastHeaders = *headers;
  204364. lastPostData.setSize (0);
  204365. if (postData != 0)
  204366. lastPostData = *postData;
  204367. blankPageShown = false;
  204368. browser->goToURL (url, headers, postData);
  204369. }
  204370. void WebBrowserComponent::stop()
  204371. {
  204372. browser->stop();
  204373. }
  204374. void WebBrowserComponent::goBack()
  204375. {
  204376. lastURL = String::empty;
  204377. blankPageShown = false;
  204378. browser->goBack();
  204379. }
  204380. void WebBrowserComponent::goForward()
  204381. {
  204382. lastURL = String::empty;
  204383. browser->goForward();
  204384. }
  204385. void WebBrowserComponent::refresh()
  204386. {
  204387. browser->refresh();
  204388. }
  204389. void WebBrowserComponent::paint (Graphics& g)
  204390. {
  204391. }
  204392. void WebBrowserComponent::checkWindowAssociation()
  204393. {
  204394. if (isShowing())
  204395. {
  204396. if (blankPageShown)
  204397. goBack();
  204398. }
  204399. else
  204400. {
  204401. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204402. {
  204403. // when the component becomes invisible, some stuff like flash
  204404. // carries on playing audio, so we need to force it onto a blank
  204405. // page to avoid this, (and send it back when it's made visible again).
  204406. blankPageShown = true;
  204407. browser->goToURL ("about:blank", 0, 0);
  204408. }
  204409. }
  204410. }
  204411. void WebBrowserComponent::reloadLastURL()
  204412. {
  204413. if (lastURL.isNotEmpty())
  204414. {
  204415. goToURL (lastURL, &lastHeaders, &lastPostData);
  204416. lastURL = String::empty;
  204417. }
  204418. }
  204419. void WebBrowserComponent::parentHierarchyChanged()
  204420. {
  204421. checkWindowAssociation();
  204422. }
  204423. void WebBrowserComponent::resized()
  204424. {
  204425. browser->setSize (getWidth(), getHeight());
  204426. }
  204427. void WebBrowserComponent::visibilityChanged()
  204428. {
  204429. checkWindowAssociation();
  204430. }
  204431. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204432. {
  204433. return true;
  204434. }
  204435. #else
  204436. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204437. {
  204438. }
  204439. WebBrowserComponent::~WebBrowserComponent()
  204440. {
  204441. }
  204442. void WebBrowserComponent::goToURL (const String& url,
  204443. const StringArray* headers,
  204444. const MemoryBlock* postData)
  204445. {
  204446. }
  204447. void WebBrowserComponent::stop()
  204448. {
  204449. }
  204450. void WebBrowserComponent::goBack()
  204451. {
  204452. }
  204453. void WebBrowserComponent::goForward()
  204454. {
  204455. }
  204456. void WebBrowserComponent::refresh()
  204457. {
  204458. }
  204459. void WebBrowserComponent::paint (Graphics& g)
  204460. {
  204461. }
  204462. void WebBrowserComponent::checkWindowAssociation()
  204463. {
  204464. }
  204465. void WebBrowserComponent::reloadLastURL()
  204466. {
  204467. }
  204468. void WebBrowserComponent::parentHierarchyChanged()
  204469. {
  204470. }
  204471. void WebBrowserComponent::resized()
  204472. {
  204473. }
  204474. void WebBrowserComponent::visibilityChanged()
  204475. {
  204476. }
  204477. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204478. {
  204479. return true;
  204480. }
  204481. #endif
  204482. #endif
  204483. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204484. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204485. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204486. // compiled on its own).
  204487. #if JUCE_INCLUDED_FILE
  204488. class IPhoneAudioIODevice : public AudioIODevice
  204489. {
  204490. public:
  204491. IPhoneAudioIODevice (const String& deviceName)
  204492. : AudioIODevice (deviceName, "Audio"),
  204493. audioUnit (0),
  204494. isRunning (false),
  204495. callback (0),
  204496. actualBufferSize (0),
  204497. floatData (1, 2)
  204498. {
  204499. numInputChannels = 2;
  204500. numOutputChannels = 2;
  204501. preferredBufferSize = 0;
  204502. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204503. updateDeviceInfo();
  204504. }
  204505. ~IPhoneAudioIODevice()
  204506. {
  204507. close();
  204508. }
  204509. const StringArray getOutputChannelNames()
  204510. {
  204511. StringArray s;
  204512. s.add ("Left");
  204513. s.add ("Right");
  204514. return s;
  204515. }
  204516. const StringArray getInputChannelNames()
  204517. {
  204518. StringArray s;
  204519. if (audioInputIsAvailable)
  204520. {
  204521. s.add ("Left");
  204522. s.add ("Right");
  204523. }
  204524. return s;
  204525. }
  204526. int getNumSampleRates()
  204527. {
  204528. return 1;
  204529. }
  204530. double getSampleRate (int index)
  204531. {
  204532. return sampleRate;
  204533. }
  204534. int getNumBufferSizesAvailable()
  204535. {
  204536. return 1;
  204537. }
  204538. int getBufferSizeSamples (int index)
  204539. {
  204540. return getDefaultBufferSize();
  204541. }
  204542. int getDefaultBufferSize()
  204543. {
  204544. return 1024;
  204545. }
  204546. const String open (const BigInteger& inputChannels,
  204547. const BigInteger& outputChannels,
  204548. double sampleRate,
  204549. int bufferSize)
  204550. {
  204551. close();
  204552. lastError = String::empty;
  204553. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204554. // xxx set up channel mapping
  204555. activeOutputChans = outputChannels;
  204556. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204557. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204558. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204559. activeInputChans = inputChannels;
  204560. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204561. numInputChannels = activeInputChans.countNumberOfSetBits();
  204562. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204563. AudioSessionSetActive (true);
  204564. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204565. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204566. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204567. fixAudioRouteIfSetToReceiver();
  204568. updateDeviceInfo();
  204569. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204570. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204571. actualBufferSize = preferredBufferSize;
  204572. prepareFloatBuffers();
  204573. isRunning = true;
  204574. propertyChanged (0, 0, 0); // creates and starts the AU
  204575. lastError = audioUnit != 0 ? "" : "Couldn't open the device";
  204576. return lastError;
  204577. }
  204578. void close()
  204579. {
  204580. if (isRunning)
  204581. {
  204582. isRunning = false;
  204583. AudioSessionSetActive (false);
  204584. if (audioUnit != 0)
  204585. {
  204586. AudioComponentInstanceDispose (audioUnit);
  204587. audioUnit = 0;
  204588. }
  204589. }
  204590. }
  204591. bool isOpen()
  204592. {
  204593. return isRunning;
  204594. }
  204595. int getCurrentBufferSizeSamples()
  204596. {
  204597. return actualBufferSize;
  204598. }
  204599. double getCurrentSampleRate()
  204600. {
  204601. return sampleRate;
  204602. }
  204603. int getCurrentBitDepth()
  204604. {
  204605. return 16;
  204606. }
  204607. const BigInteger getActiveOutputChannels() const
  204608. {
  204609. return activeOutputChans;
  204610. }
  204611. const BigInteger getActiveInputChannels() const
  204612. {
  204613. return activeInputChans;
  204614. }
  204615. int getOutputLatencyInSamples()
  204616. {
  204617. return 0; //xxx
  204618. }
  204619. int getInputLatencyInSamples()
  204620. {
  204621. return 0; //xxx
  204622. }
  204623. void start (AudioIODeviceCallback* callback_)
  204624. {
  204625. if (isRunning && callback != callback_)
  204626. {
  204627. if (callback_ != 0)
  204628. callback_->audioDeviceAboutToStart (this);
  204629. const ScopedLock sl (callbackLock);
  204630. callback = callback_;
  204631. }
  204632. }
  204633. void stop()
  204634. {
  204635. if (isRunning)
  204636. {
  204637. AudioIODeviceCallback* lastCallback;
  204638. {
  204639. const ScopedLock sl (callbackLock);
  204640. lastCallback = callback;
  204641. callback = 0;
  204642. }
  204643. if (lastCallback != 0)
  204644. lastCallback->audioDeviceStopped();
  204645. }
  204646. }
  204647. bool isPlaying()
  204648. {
  204649. return isRunning && callback != 0;
  204650. }
  204651. const String getLastError()
  204652. {
  204653. return lastError;
  204654. }
  204655. private:
  204656. CriticalSection callbackLock;
  204657. Float64 sampleRate;
  204658. int numInputChannels, numOutputChannels;
  204659. int preferredBufferSize;
  204660. int actualBufferSize;
  204661. bool isRunning;
  204662. String lastError;
  204663. AudioStreamBasicDescription format;
  204664. AudioUnit audioUnit;
  204665. UInt32 audioInputIsAvailable;
  204666. AudioIODeviceCallback* callback;
  204667. BigInteger activeOutputChans, activeInputChans;
  204668. AudioSampleBuffer floatData;
  204669. float* inputChannels[3];
  204670. float* outputChannels[3];
  204671. bool monoInputChannelNumber, monoOutputChannelNumber;
  204672. void prepareFloatBuffers()
  204673. {
  204674. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204675. zerostruct (inputChannels);
  204676. zerostruct (outputChannels);
  204677. for (int i = 0; i < numInputChannels; ++i)
  204678. inputChannels[i] = floatData.getSampleData (i);
  204679. for (int i = 0; i < numOutputChannels; ++i)
  204680. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204681. }
  204682. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204683. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204684. {
  204685. OSStatus err = noErr;
  204686. if (audioInputIsAvailable)
  204687. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204688. const ScopedLock sl (callbackLock);
  204689. if (callback != 0)
  204690. {
  204691. if (audioInputIsAvailable && numInputChannels > 0)
  204692. {
  204693. short* shortData = (short*) ioData->mBuffers[0].mData;
  204694. if (numInputChannels >= 2)
  204695. {
  204696. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204697. {
  204698. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204699. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204700. }
  204701. }
  204702. else
  204703. {
  204704. if (monoInputChannelNumber > 0)
  204705. ++shortData;
  204706. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204707. {
  204708. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204709. ++shortData;
  204710. }
  204711. }
  204712. }
  204713. else
  204714. {
  204715. for (int i = numInputChannels; --i >= 0;)
  204716. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204717. }
  204718. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204719. outputChannels, numOutputChannels,
  204720. (int) inNumberFrames);
  204721. short* shortData = (short*) ioData->mBuffers[0].mData;
  204722. int n = 0;
  204723. if (numOutputChannels >= 2)
  204724. {
  204725. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204726. {
  204727. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204728. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204729. }
  204730. }
  204731. else if (numOutputChannels == 1)
  204732. {
  204733. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204734. {
  204735. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204736. shortData [n++] = s;
  204737. shortData [n++] = s;
  204738. }
  204739. }
  204740. else
  204741. {
  204742. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204743. }
  204744. }
  204745. else
  204746. {
  204747. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204748. }
  204749. return err;
  204750. }
  204751. void updateDeviceInfo()
  204752. {
  204753. UInt32 size = sizeof (sampleRate);
  204754. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204755. size = sizeof (audioInputIsAvailable);
  204756. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204757. }
  204758. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204759. {
  204760. if (! isRunning)
  204761. return;
  204762. if (inPropertyValue != 0)
  204763. {
  204764. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204765. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204766. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204767. SInt32 routeChangeReason;
  204768. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204769. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204770. fixAudioRouteIfSetToReceiver();
  204771. }
  204772. updateDeviceInfo();
  204773. createAudioUnit();
  204774. AudioSessionSetActive (true);
  204775. if (audioUnit != 0)
  204776. {
  204777. UInt32 formatSize = sizeof (format);
  204778. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204779. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204780. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204781. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204782. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204783. AudioOutputUnitStart (audioUnit);
  204784. }
  204785. }
  204786. void interruptionListener (UInt32 inInterruption)
  204787. {
  204788. if (inInterruption == kAudioSessionEndInterruption)
  204789. {
  204790. isRunning = true;
  204791. AudioSessionSetActive (true);
  204792. AudioOutputUnitStart (audioUnit);
  204793. }
  204794. }
  204795. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204796. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204797. {
  204798. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204799. }
  204800. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204801. {
  204802. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204803. }
  204804. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204805. {
  204806. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204807. }
  204808. void resetFormat (const int numChannels)
  204809. {
  204810. memset (&format, 0, sizeof (format));
  204811. format.mFormatID = kAudioFormatLinearPCM;
  204812. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204813. format.mBitsPerChannel = 8 * sizeof (short);
  204814. format.mChannelsPerFrame = 2;
  204815. format.mFramesPerPacket = 1;
  204816. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204817. }
  204818. bool createAudioUnit()
  204819. {
  204820. if (audioUnit != 0)
  204821. {
  204822. AudioComponentInstanceDispose (audioUnit);
  204823. audioUnit = 0;
  204824. }
  204825. resetFormat (2);
  204826. AudioComponentDescription desc;
  204827. desc.componentType = kAudioUnitType_Output;
  204828. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204829. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204830. desc.componentFlags = 0;
  204831. desc.componentFlagsMask = 0;
  204832. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204833. AudioComponentInstanceNew (comp, &audioUnit);
  204834. if (audioUnit == 0)
  204835. return false;
  204836. const UInt32 one = 1;
  204837. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204838. AudioChannelLayout layout;
  204839. layout.mChannelBitmap = 0;
  204840. layout.mNumberChannelDescriptions = 0;
  204841. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204842. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204843. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204844. AURenderCallbackStruct inputProc;
  204845. inputProc.inputProc = processStatic;
  204846. inputProc.inputProcRefCon = this;
  204847. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204848. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204849. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204850. AudioUnitInitialize (audioUnit);
  204851. return true;
  204852. }
  204853. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204854. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204855. static void fixAudioRouteIfSetToReceiver()
  204856. {
  204857. CFStringRef audioRoute = 0;
  204858. UInt32 propertySize = sizeof (audioRoute);
  204859. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204860. {
  204861. NSString* route = (NSString*) audioRoute;
  204862. //DBG ("audio route: " + nsStringToJuce (route));
  204863. if ([route hasPrefix: @"Receiver"])
  204864. {
  204865. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204866. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204867. }
  204868. CFRelease (audioRoute);
  204869. }
  204870. }
  204871. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204872. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204873. };
  204874. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204875. {
  204876. public:
  204877. IPhoneAudioIODeviceType()
  204878. : AudioIODeviceType ("iPhone Audio")
  204879. {
  204880. }
  204881. ~IPhoneAudioIODeviceType()
  204882. {
  204883. }
  204884. void scanForDevices()
  204885. {
  204886. }
  204887. const StringArray getDeviceNames (bool wantInputNames) const
  204888. {
  204889. StringArray s;
  204890. s.add ("iPhone Audio");
  204891. return s;
  204892. }
  204893. int getDefaultDeviceIndex (bool forInput) const
  204894. {
  204895. return 0;
  204896. }
  204897. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  204898. {
  204899. return device != 0 ? 0 : -1;
  204900. }
  204901. bool hasSeparateInputsAndOutputs() const { return false; }
  204902. AudioIODevice* createDevice (const String& outputDeviceName,
  204903. const String& inputDeviceName)
  204904. {
  204905. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204906. {
  204907. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204908. : inputDeviceName);
  204909. }
  204910. return 0;
  204911. }
  204912. juce_UseDebuggingNewOperator
  204913. private:
  204914. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204915. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204916. };
  204917. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204918. {
  204919. return new IPhoneAudioIODeviceType();
  204920. }
  204921. #endif
  204922. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204923. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204924. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204925. // compiled on its own).
  204926. #if JUCE_INCLUDED_FILE
  204927. #if JUCE_MAC
  204928. #undef log
  204929. #define log(a) Logger::writeToLog(a)
  204930. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204931. {
  204932. if (err == noErr)
  204933. return true;
  204934. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  204935. jassertfalse
  204936. return false;
  204937. }
  204938. #undef OK
  204939. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204940. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204941. {
  204942. String result;
  204943. CFStringRef str = 0;
  204944. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204945. if (str != 0)
  204946. {
  204947. result = PlatformUtilities::cfStringToJuceString (str);
  204948. CFRelease (str);
  204949. str = 0;
  204950. }
  204951. MIDIEntityRef entity = 0;
  204952. MIDIEndpointGetEntity (endpoint, &entity);
  204953. if (entity == 0)
  204954. return result; // probably virtual
  204955. if (result.isEmpty())
  204956. {
  204957. // endpoint name has zero length - try the entity
  204958. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204959. if (str != 0)
  204960. {
  204961. result += PlatformUtilities::cfStringToJuceString (str);
  204962. CFRelease (str);
  204963. str = 0;
  204964. }
  204965. }
  204966. // now consider the device's name
  204967. MIDIDeviceRef device = 0;
  204968. MIDIEntityGetDevice (entity, &device);
  204969. if (device == 0)
  204970. return result;
  204971. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204972. if (str != 0)
  204973. {
  204974. const String s (PlatformUtilities::cfStringToJuceString (str));
  204975. CFRelease (str);
  204976. // if an external device has only one entity, throw away
  204977. // the endpoint name and just use the device name
  204978. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204979. {
  204980. result = s;
  204981. }
  204982. else if (! result.startsWithIgnoreCase (s))
  204983. {
  204984. // prepend the device name to the entity name
  204985. result = (s + " " + result).trimEnd();
  204986. }
  204987. }
  204988. return result;
  204989. }
  204990. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204991. {
  204992. String result;
  204993. // Does the endpoint have connections?
  204994. CFDataRef connections = 0;
  204995. int numConnections = 0;
  204996. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204997. if (connections != 0)
  204998. {
  204999. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  205000. if (numConnections > 0)
  205001. {
  205002. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  205003. for (int i = 0; i < numConnections; ++i, ++pid)
  205004. {
  205005. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  205006. MIDIObjectRef connObject;
  205007. MIDIObjectType connObjectType;
  205008. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  205009. if (err == noErr)
  205010. {
  205011. String s;
  205012. if (connObjectType == kMIDIObjectType_ExternalSource
  205013. || connObjectType == kMIDIObjectType_ExternalDestination)
  205014. {
  205015. // Connected to an external device's endpoint (10.3 and later).
  205016. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  205017. }
  205018. else
  205019. {
  205020. // Connected to an external device (10.2) (or something else, catch-all)
  205021. CFStringRef str = 0;
  205022. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205023. if (str != 0)
  205024. {
  205025. s = PlatformUtilities::cfStringToJuceString (str);
  205026. CFRelease (str);
  205027. }
  205028. }
  205029. if (s.isNotEmpty())
  205030. {
  205031. if (result.isNotEmpty())
  205032. result += ", ";
  205033. result += s;
  205034. }
  205035. }
  205036. }
  205037. }
  205038. CFRelease (connections);
  205039. }
  205040. if (result.isNotEmpty())
  205041. return result;
  205042. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205043. return getEndpointName (endpoint, false);
  205044. }
  205045. const StringArray MidiOutput::getDevices()
  205046. {
  205047. StringArray s;
  205048. const ItemCount num = MIDIGetNumberOfDestinations();
  205049. for (ItemCount i = 0; i < num; ++i)
  205050. {
  205051. MIDIEndpointRef dest = MIDIGetDestination (i);
  205052. if (dest != 0)
  205053. {
  205054. String name (getConnectedEndpointName (dest));
  205055. if (name.isEmpty())
  205056. name = "<error>";
  205057. s.add (name);
  205058. }
  205059. else
  205060. {
  205061. s.add ("<error>");
  205062. }
  205063. }
  205064. return s;
  205065. }
  205066. int MidiOutput::getDefaultDeviceIndex()
  205067. {
  205068. return 0;
  205069. }
  205070. static MIDIClientRef globalMidiClient;
  205071. static bool hasGlobalClientBeenCreated = false;
  205072. static bool makeSureClientExists()
  205073. {
  205074. if (! hasGlobalClientBeenCreated)
  205075. {
  205076. String name ("JUCE");
  205077. if (JUCEApplication::getInstance() != 0)
  205078. name = JUCEApplication::getInstance()->getApplicationName();
  205079. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205080. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205081. CFRelease (appName);
  205082. }
  205083. return hasGlobalClientBeenCreated;
  205084. }
  205085. class MidiPortAndEndpoint
  205086. {
  205087. public:
  205088. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205089. : port (port_), endPoint (endPoint_)
  205090. {
  205091. }
  205092. ~MidiPortAndEndpoint()
  205093. {
  205094. if (port != 0)
  205095. MIDIPortDispose (port);
  205096. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205097. MIDIEndpointDispose (endPoint);
  205098. }
  205099. MIDIPortRef port;
  205100. MIDIEndpointRef endPoint;
  205101. };
  205102. MidiOutput* MidiOutput::openDevice (int index)
  205103. {
  205104. MidiOutput* mo = 0;
  205105. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205106. {
  205107. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205108. CFStringRef pname;
  205109. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205110. {
  205111. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  205112. if (makeSureClientExists())
  205113. {
  205114. MIDIPortRef port;
  205115. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205116. {
  205117. mo = new MidiOutput();
  205118. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  205119. }
  205120. }
  205121. CFRelease (pname);
  205122. }
  205123. }
  205124. return mo;
  205125. }
  205126. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205127. {
  205128. MidiOutput* mo = 0;
  205129. if (makeSureClientExists())
  205130. {
  205131. MIDIEndpointRef endPoint;
  205132. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205133. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205134. {
  205135. mo = new MidiOutput();
  205136. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  205137. }
  205138. CFRelease (name);
  205139. }
  205140. return mo;
  205141. }
  205142. MidiOutput::~MidiOutput()
  205143. {
  205144. delete (MidiPortAndEndpoint*) internal;
  205145. }
  205146. void MidiOutput::reset()
  205147. {
  205148. }
  205149. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205150. {
  205151. return false;
  205152. }
  205153. void MidiOutput::setVolume (float leftVol, float rightVol)
  205154. {
  205155. }
  205156. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205157. {
  205158. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205159. if (message.isSysEx())
  205160. {
  205161. const int maxPacketSize = 256;
  205162. int pos = 0, bytesLeft = message.getRawDataSize();
  205163. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205164. HeapBlock <MIDIPacketList> packets;
  205165. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205166. packets->numPackets = numPackets;
  205167. MIDIPacket* p = packets->packet;
  205168. for (int i = 0; i < numPackets; ++i)
  205169. {
  205170. p->timeStamp = 0;
  205171. p->length = jmin (maxPacketSize, bytesLeft);
  205172. memcpy (p->data, message.getRawData() + pos, p->length);
  205173. pos += p->length;
  205174. bytesLeft -= p->length;
  205175. p = MIDIPacketNext (p);
  205176. }
  205177. if (mpe->port != 0)
  205178. MIDISend (mpe->port, mpe->endPoint, packets);
  205179. else
  205180. MIDIReceived (mpe->endPoint, packets);
  205181. }
  205182. else
  205183. {
  205184. MIDIPacketList packets;
  205185. packets.numPackets = 1;
  205186. packets.packet[0].timeStamp = 0;
  205187. packets.packet[0].length = message.getRawDataSize();
  205188. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205189. if (mpe->port != 0)
  205190. MIDISend (mpe->port, mpe->endPoint, &packets);
  205191. else
  205192. MIDIReceived (mpe->endPoint, &packets);
  205193. }
  205194. }
  205195. const StringArray MidiInput::getDevices()
  205196. {
  205197. StringArray s;
  205198. const ItemCount num = MIDIGetNumberOfSources();
  205199. for (ItemCount i = 0; i < num; ++i)
  205200. {
  205201. MIDIEndpointRef source = MIDIGetSource (i);
  205202. if (source != 0)
  205203. {
  205204. String name (getConnectedEndpointName (source));
  205205. if (name.isEmpty())
  205206. name = "<error>";
  205207. s.add (name);
  205208. }
  205209. else
  205210. {
  205211. s.add ("<error>");
  205212. }
  205213. }
  205214. return s;
  205215. }
  205216. int MidiInput::getDefaultDeviceIndex()
  205217. {
  205218. return 0;
  205219. }
  205220. struct MidiPortAndCallback
  205221. {
  205222. MidiInput* input;
  205223. MidiPortAndEndpoint* portAndEndpoint;
  205224. MidiInputCallback* callback;
  205225. MemoryBlock pendingData;
  205226. int pendingBytes;
  205227. double pendingDataTime;
  205228. bool active;
  205229. void processSysex (const uint8*& d, int& size, const double time)
  205230. {
  205231. if (*d == 0xf0)
  205232. {
  205233. pendingBytes = 0;
  205234. pendingDataTime = time;
  205235. }
  205236. pendingData.ensureSize (pendingBytes + size, false);
  205237. uint8* totalMessage = (uint8*) pendingData.getData();
  205238. uint8* dest = totalMessage + pendingBytes;
  205239. while (size > 0)
  205240. {
  205241. if (pendingBytes > 0 && *d >= 0x80)
  205242. {
  205243. if (*d >= 0xfa || *d == 0xf8)
  205244. {
  205245. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205246. ++d;
  205247. --size;
  205248. }
  205249. else
  205250. {
  205251. if (*d == 0xf7)
  205252. {
  205253. *dest++ = *d++;
  205254. pendingBytes++;
  205255. --size;
  205256. }
  205257. break;
  205258. }
  205259. }
  205260. else
  205261. {
  205262. *dest++ = *d++;
  205263. pendingBytes++;
  205264. --size;
  205265. }
  205266. }
  205267. if (totalMessage [pendingBytes - 1] == 0xf7)
  205268. {
  205269. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205270. pendingBytes = 0;
  205271. }
  205272. else
  205273. {
  205274. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205275. }
  205276. }
  205277. };
  205278. namespace CoreMidiCallbacks
  205279. {
  205280. static CriticalSection callbackLock;
  205281. static VoidArray activeCallbacks;
  205282. }
  205283. static void midiInputProc (const MIDIPacketList* pktlist,
  205284. void* readProcRefCon,
  205285. void* srcConnRefCon)
  205286. {
  205287. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205288. const double originalTime = time;
  205289. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205290. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205291. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205292. {
  205293. const MIDIPacket* packet = &pktlist->packet[0];
  205294. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205295. {
  205296. const uint8* d = (const uint8*) (packet->data);
  205297. int size = packet->length;
  205298. while (size > 0)
  205299. {
  205300. time = originalTime;
  205301. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205302. {
  205303. mpc->processSysex (d, size, time);
  205304. }
  205305. else
  205306. {
  205307. int used = 0;
  205308. const MidiMessage m (d, size, used, 0, time);
  205309. if (used <= 0)
  205310. {
  205311. jassertfalse // malformed midi message
  205312. break;
  205313. }
  205314. else
  205315. {
  205316. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205317. }
  205318. size -= used;
  205319. d += used;
  205320. }
  205321. }
  205322. packet = MIDIPacketNext (packet);
  205323. }
  205324. }
  205325. }
  205326. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205327. {
  205328. MidiInput* mi = 0;
  205329. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205330. {
  205331. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205332. if (endPoint != 0)
  205333. {
  205334. CFStringRef pname;
  205335. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205336. {
  205337. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  205338. if (makeSureClientExists())
  205339. {
  205340. MIDIPortRef port;
  205341. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205342. mpc->active = false;
  205343. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205344. {
  205345. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205346. {
  205347. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205348. mpc->callback = callback;
  205349. mpc->pendingBytes = 0;
  205350. mpc->pendingData.ensureSize (128);
  205351. mi = new MidiInput (getDevices() [index]);
  205352. mpc->input = mi;
  205353. mi->internal = mpc;
  205354. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205355. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205356. }
  205357. else
  205358. {
  205359. OK (MIDIPortDispose (port));
  205360. }
  205361. }
  205362. }
  205363. }
  205364. CFRelease (pname);
  205365. }
  205366. }
  205367. return mi;
  205368. }
  205369. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205370. {
  205371. MidiInput* mi = 0;
  205372. if (makeSureClientExists())
  205373. {
  205374. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205375. mpc->active = false;
  205376. MIDIEndpointRef endPoint;
  205377. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205378. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205379. {
  205380. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205381. mpc->callback = callback;
  205382. mpc->pendingBytes = 0;
  205383. mpc->pendingData.ensureSize (128);
  205384. mi = new MidiInput (deviceName);
  205385. mpc->input = mi;
  205386. mi->internal = mpc;
  205387. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205388. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205389. }
  205390. CFRelease (name);
  205391. }
  205392. return mi;
  205393. }
  205394. MidiInput::MidiInput (const String& name_)
  205395. : name (name_)
  205396. {
  205397. }
  205398. MidiInput::~MidiInput()
  205399. {
  205400. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205401. mpc->active = false;
  205402. {
  205403. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205404. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205405. }
  205406. if (mpc->portAndEndpoint->port != 0)
  205407. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205408. delete mpc->portAndEndpoint;
  205409. delete mpc;
  205410. }
  205411. void MidiInput::start()
  205412. {
  205413. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205414. ((MidiPortAndCallback*) internal)->active = true;
  205415. }
  205416. void MidiInput::stop()
  205417. {
  205418. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205419. ((MidiPortAndCallback*) internal)->active = false;
  205420. }
  205421. #undef log
  205422. #else
  205423. MidiOutput::~MidiOutput()
  205424. {
  205425. }
  205426. void MidiOutput::reset()
  205427. {
  205428. }
  205429. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205430. {
  205431. return false;
  205432. }
  205433. void MidiOutput::setVolume (float leftVol, float rightVol)
  205434. {
  205435. }
  205436. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205437. {
  205438. }
  205439. const StringArray MidiOutput::getDevices()
  205440. {
  205441. return StringArray();
  205442. }
  205443. MidiOutput* MidiOutput::openDevice (int index)
  205444. {
  205445. return 0;
  205446. }
  205447. const StringArray MidiInput::getDevices()
  205448. {
  205449. return StringArray();
  205450. }
  205451. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205452. {
  205453. return 0;
  205454. }
  205455. #endif
  205456. #endif
  205457. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205458. #else
  205459. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205460. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205461. // compiled on its own).
  205462. #if JUCE_INCLUDED_FILE
  205463. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205464. #define SUPPORT_10_4_FONTS 1
  205465. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205466. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205467. #define SUPPORT_ONLY_10_4_FONTS 1
  205468. #endif
  205469. END_JUCE_NAMESPACE
  205470. @interface NSFont (PrivateHack)
  205471. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205472. @end
  205473. BEGIN_JUCE_NAMESPACE
  205474. #endif
  205475. class MacTypeface : public Typeface
  205476. {
  205477. public:
  205478. MacTypeface (const Font& font)
  205479. : Typeface (font.getTypefaceName())
  205480. {
  205481. const ScopedAutoReleasePool pool;
  205482. renderingTransform = CGAffineTransformIdentity;
  205483. bool needsItalicTransform = false;
  205484. #if JUCE_IPHONE
  205485. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205486. if (font.isItalic() || font.isBold())
  205487. {
  205488. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205489. for (NSString* i in familyFonts)
  205490. {
  205491. const String fn (nsStringToJuce (i));
  205492. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  205493. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  205494. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  205495. || afterDash.containsIgnoreCase ("italic")
  205496. || fn.endsWithIgnoreCase ("oblique")
  205497. || fn.endsWithIgnoreCase ("italic");
  205498. if (probablyBold == font.isBold()
  205499. && probablyItalic == font.isItalic())
  205500. {
  205501. fontName = i;
  205502. needsItalicTransform = false;
  205503. break;
  205504. }
  205505. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205506. {
  205507. fontName = i;
  205508. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205509. }
  205510. }
  205511. if (needsItalicTransform)
  205512. renderingTransform.c = 0.15f;
  205513. }
  205514. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205515. const int ascender = abs (CGFontGetAscent (fontRef));
  205516. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205517. ascent = ascender / totalHeight;
  205518. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205519. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205520. #else
  205521. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205522. if (font.isItalic())
  205523. {
  205524. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205525. toHaveTrait: NSItalicFontMask];
  205526. if (newFont == nsFont)
  205527. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205528. nsFont = newFont;
  205529. }
  205530. if (font.isBold())
  205531. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205532. [nsFont retain];
  205533. ascent = fabsf ((float) [nsFont ascender]);
  205534. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205535. ascent /= totalSize;
  205536. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205537. if (needsItalicTransform)
  205538. {
  205539. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205540. renderingTransform.c = 0.15f;
  205541. }
  205542. #if SUPPORT_ONLY_10_4_FONTS
  205543. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205544. if (atsFont == 0)
  205545. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205546. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  205547. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205548. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205549. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205550. #else
  205551. #if SUPPORT_10_4_FONTS
  205552. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205553. {
  205554. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205555. if (atsFont == 0)
  205556. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205557. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  205558. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205559. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205560. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205561. }
  205562. else
  205563. #endif
  205564. {
  205565. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205566. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205567. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205568. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205569. }
  205570. #endif
  205571. #endif
  205572. }
  205573. ~MacTypeface()
  205574. {
  205575. #if ! JUCE_IPHONE
  205576. [nsFont release];
  205577. #endif
  205578. if (fontRef != 0)
  205579. CGFontRelease (fontRef);
  205580. }
  205581. float getAscent() const
  205582. {
  205583. return ascent;
  205584. }
  205585. float getDescent() const
  205586. {
  205587. return 1.0f - ascent;
  205588. }
  205589. float getStringWidth (const String& text)
  205590. {
  205591. if (fontRef == 0 || text.isEmpty())
  205592. return 0;
  205593. const int length = text.length();
  205594. HeapBlock <CGGlyph> glyphs;
  205595. createGlyphsForString (text, length, glyphs);
  205596. float x = 0;
  205597. #if SUPPORT_ONLY_10_4_FONTS
  205598. HeapBlock <NSSize> advances (length);
  205599. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205600. for (int i = 0; i < length; ++i)
  205601. x += advances[i].width;
  205602. #else
  205603. #if SUPPORT_10_4_FONTS
  205604. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205605. {
  205606. HeapBlock <NSSize> advances (length);
  205607. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205608. for (int i = 0; i < length; ++i)
  205609. x += advances[i].width;
  205610. }
  205611. else
  205612. #endif
  205613. {
  205614. HeapBlock <int> advances (length);
  205615. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205616. for (int i = 0; i < length; ++i)
  205617. x += advances[i];
  205618. }
  205619. #endif
  205620. return x * unitsToHeightScaleFactor;
  205621. }
  205622. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205623. {
  205624. xOffsets.add (0);
  205625. if (fontRef == 0 || text.isEmpty())
  205626. return;
  205627. const int length = text.length();
  205628. HeapBlock <CGGlyph> glyphs;
  205629. createGlyphsForString (text, length, glyphs);
  205630. #if SUPPORT_ONLY_10_4_FONTS
  205631. HeapBlock <NSSize> advances (length);
  205632. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205633. int x = 0;
  205634. for (int i = 0; i < length; ++i)
  205635. {
  205636. x += advances[i].width;
  205637. xOffsets.add (x * unitsToHeightScaleFactor);
  205638. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205639. }
  205640. #else
  205641. #if SUPPORT_10_4_FONTS
  205642. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205643. {
  205644. HeapBlock <NSSize> advances (length);
  205645. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205646. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205647. float x = 0;
  205648. for (int i = 0; i < length; ++i)
  205649. {
  205650. x += advances[i].width;
  205651. xOffsets.add (x * unitsToHeightScaleFactor);
  205652. resultGlyphs.add (nsGlyphs[i]);
  205653. }
  205654. }
  205655. else
  205656. #endif
  205657. {
  205658. HeapBlock <int> advances (length);
  205659. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205660. {
  205661. int x = 0;
  205662. for (int i = 0; i < length; ++i)
  205663. {
  205664. x += advances [i];
  205665. xOffsets.add (x * unitsToHeightScaleFactor);
  205666. resultGlyphs.add (glyphs[i]);
  205667. }
  205668. }
  205669. }
  205670. #endif
  205671. }
  205672. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205673. {
  205674. #if JUCE_IPHONE
  205675. return false;
  205676. #else
  205677. if (nsFont == 0)
  205678. return false;
  205679. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205680. jassert (path.isEmpty());
  205681. const ScopedAutoReleasePool pool;
  205682. NSBezierPath* bez = [NSBezierPath bezierPath];
  205683. [bez moveToPoint: NSMakePoint (0, 0)];
  205684. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205685. inFont: nsFont];
  205686. for (int i = 0; i < [bez elementCount]; ++i)
  205687. {
  205688. NSPoint p[3];
  205689. switch ([bez elementAtIndex: i associatedPoints: p])
  205690. {
  205691. case NSMoveToBezierPathElement:
  205692. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205693. break;
  205694. case NSLineToBezierPathElement:
  205695. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205696. break;
  205697. case NSCurveToBezierPathElement:
  205698. 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);
  205699. break;
  205700. case NSClosePathBezierPathElement:
  205701. path.closeSubPath();
  205702. break;
  205703. default:
  205704. jassertfalse
  205705. break;
  205706. }
  205707. }
  205708. path.applyTransform (pathTransform);
  205709. return true;
  205710. #endif
  205711. }
  205712. juce_UseDebuggingNewOperator
  205713. CGFontRef fontRef;
  205714. float fontHeightToCGSizeFactor;
  205715. CGAffineTransform renderingTransform;
  205716. private:
  205717. float ascent, unitsToHeightScaleFactor;
  205718. #if JUCE_IPHONE
  205719. #else
  205720. NSFont* nsFont;
  205721. AffineTransform pathTransform;
  205722. #endif
  205723. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205724. {
  205725. #if SUPPORT_10_4_FONTS
  205726. #if ! SUPPORT_ONLY_10_4_FONTS
  205727. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205728. #endif
  205729. {
  205730. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205731. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205732. for (int i = 0; i < length; ++i)
  205733. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205734. return;
  205735. }
  205736. #endif
  205737. #if ! SUPPORT_ONLY_10_4_FONTS
  205738. if (charToGlyphMapper == 0)
  205739. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205740. glyphs.malloc (length);
  205741. for (int i = 0; i < length; ++i)
  205742. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205743. #endif
  205744. }
  205745. #if ! SUPPORT_ONLY_10_4_FONTS
  205746. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205747. class CharToGlyphMapper
  205748. {
  205749. public:
  205750. CharToGlyphMapper (CGFontRef fontRef)
  205751. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205752. idRangeOffset (0), glyphIndexes (0)
  205753. {
  205754. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205755. if (cmapTable != 0)
  205756. {
  205757. const int numSubtables = getValue16 (cmapTable, 2);
  205758. for (int i = 0; i < numSubtables; ++i)
  205759. {
  205760. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205761. {
  205762. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205763. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205764. {
  205765. const int length = getValue16 (cmapTable, offset + 2);
  205766. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205767. segCount = segCountX2 / 2;
  205768. const int endCodeOffset = offset + 14;
  205769. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205770. const int idDeltaOffset = startCodeOffset + segCountX2;
  205771. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205772. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205773. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205774. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205775. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205776. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205777. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205778. }
  205779. break;
  205780. }
  205781. }
  205782. CFRelease (cmapTable);
  205783. }
  205784. }
  205785. ~CharToGlyphMapper()
  205786. {
  205787. if (endCode != 0)
  205788. {
  205789. CFRelease (endCode);
  205790. CFRelease (startCode);
  205791. CFRelease (idDelta);
  205792. CFRelease (idRangeOffset);
  205793. CFRelease (glyphIndexes);
  205794. }
  205795. }
  205796. int getGlyphForCharacter (const juce_wchar c) const
  205797. {
  205798. for (int i = 0; i < segCount; ++i)
  205799. {
  205800. if (getValue16 (endCode, i * 2) >= c)
  205801. {
  205802. const int start = getValue16 (startCode, i * 2);
  205803. if (start > c)
  205804. break;
  205805. const int delta = getValue16 (idDelta, i * 2);
  205806. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205807. if (rangeOffset == 0)
  205808. return delta + c;
  205809. else
  205810. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205811. }
  205812. }
  205813. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205814. return jmax (-1, c - 29);
  205815. }
  205816. private:
  205817. int segCount;
  205818. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205819. static uint16 getValue16 (CFDataRef data, const int index)
  205820. {
  205821. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205822. }
  205823. static uint32 getValue32 (CFDataRef data, const int index)
  205824. {
  205825. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205826. }
  205827. };
  205828. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205829. #endif
  205830. MacTypeface (const MacTypeface&);
  205831. MacTypeface& operator= (const MacTypeface&);
  205832. };
  205833. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205834. {
  205835. return new MacTypeface (font);
  205836. }
  205837. const StringArray Font::findAllTypefaceNames()
  205838. {
  205839. StringArray names;
  205840. const ScopedAutoReleasePool pool;
  205841. #if JUCE_IPHONE
  205842. NSArray* fonts = [UIFont familyNames];
  205843. #else
  205844. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205845. #endif
  205846. for (unsigned int i = 0; i < [fonts count]; ++i)
  205847. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205848. names.sort (true);
  205849. return names;
  205850. }
  205851. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  205852. {
  205853. #if JUCE_IPHONE
  205854. defaultSans = "Helvetica";
  205855. defaultSerif = "Times New Roman";
  205856. defaultFixed = "Courier New";
  205857. #else
  205858. defaultSans = "Lucida Grande";
  205859. defaultSerif = "Times New Roman";
  205860. defaultFixed = "Monaco";
  205861. #endif
  205862. }
  205863. #endif
  205864. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205865. // (must go before juce_mac_CoreGraphicsContext.mm)
  205866. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205867. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205868. // compiled on its own).
  205869. #if JUCE_INCLUDED_FILE
  205870. class CoreGraphicsImage : public Image
  205871. {
  205872. public:
  205873. CoreGraphicsImage (const PixelFormat format_,
  205874. const int imageWidth_,
  205875. const int imageHeight_,
  205876. const bool clearImage)
  205877. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205878. {
  205879. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205880. : CGColorSpaceCreateDeviceRGB();
  205881. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205882. colourSpace, getCGImageFlags (*this));
  205883. CGColorSpaceRelease (colourSpace);
  205884. }
  205885. ~CoreGraphicsImage()
  205886. {
  205887. CGContextRelease (context);
  205888. }
  205889. LowLevelGraphicsContext* createLowLevelContext();
  205890. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205891. {
  205892. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205893. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205894. {
  205895. return CGBitmapContextCreateImage (nativeImage->context);
  205896. }
  205897. else
  205898. {
  205899. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205900. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205901. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205902. 8, srcData.pixelStride * 8, srcData.lineStride,
  205903. colourSpace, getCGImageFlags (juceImage), provider,
  205904. 0, true, kCGRenderingIntentDefault);
  205905. CGDataProviderRelease (provider);
  205906. return imageRef;
  205907. }
  205908. }
  205909. #if JUCE_MAC
  205910. static NSImage* createNSImage (const Image& image)
  205911. {
  205912. const ScopedAutoReleasePool pool;
  205913. NSImage* im = [[NSImage alloc] init];
  205914. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205915. [im lockFocus];
  205916. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205917. CGImageRef imageRef = createImage (image, false, colourSpace);
  205918. CGColorSpaceRelease (colourSpace);
  205919. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205920. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205921. CGImageRelease (imageRef);
  205922. [im unlockFocus];
  205923. return im;
  205924. }
  205925. #endif
  205926. CGContextRef context;
  205927. private:
  205928. static CGBitmapInfo getCGImageFlags (const Image& image)
  205929. {
  205930. #if JUCE_BIG_ENDIAN
  205931. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205932. #else
  205933. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205934. #endif
  205935. }
  205936. };
  205937. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205938. {
  205939. #if USE_COREGRAPHICS_RENDERING
  205940. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205941. #else
  205942. return new Image (format, imageWidth, imageHeight, clearImage);
  205943. #endif
  205944. }
  205945. class CoreGraphicsContext : public LowLevelGraphicsContext
  205946. {
  205947. public:
  205948. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205949. : context (context_),
  205950. flipHeight (flipHeight_),
  205951. state (new SavedState()),
  205952. numGradientLookupEntries (0)
  205953. {
  205954. CGContextRetain (context);
  205955. CGContextSaveGState(context);
  205956. CGContextSetShouldSmoothFonts (context, true);
  205957. CGContextSetShouldAntialias (context, true);
  205958. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205959. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205960. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205961. gradientCallbacks.version = 0;
  205962. gradientCallbacks.evaluate = gradientCallback;
  205963. gradientCallbacks.releaseInfo = 0;
  205964. setFont (Font());
  205965. }
  205966. ~CoreGraphicsContext()
  205967. {
  205968. CGContextRestoreGState (context);
  205969. CGContextRelease (context);
  205970. CGColorSpaceRelease (rgbColourSpace);
  205971. CGColorSpaceRelease (greyColourSpace);
  205972. }
  205973. bool isVectorDevice() const { return false; }
  205974. void setOrigin (int x, int y)
  205975. {
  205976. CGContextTranslateCTM (context, x, -y);
  205977. }
  205978. bool clipToRectangle (const Rectangle<int>& r)
  205979. {
  205980. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205981. return ! isClipEmpty();
  205982. }
  205983. bool clipToRectangleList (const RectangleList& clipRegion)
  205984. {
  205985. if (clipRegion.isEmpty())
  205986. {
  205987. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205988. return false;
  205989. }
  205990. else
  205991. {
  205992. const int numRects = clipRegion.getNumRectangles();
  205993. HeapBlock <CGRect> rects (numRects);
  205994. for (int i = 0; i < numRects; ++i)
  205995. {
  205996. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205997. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205998. }
  205999. CGContextClipToRects (context, rects, numRects);
  206000. return ! isClipEmpty();
  206001. }
  206002. }
  206003. void excludeClipRectangle (const Rectangle<int>& r)
  206004. {
  206005. RectangleList remaining (getClipBounds());
  206006. remaining.subtract (r);
  206007. clipToRectangleList (remaining);
  206008. }
  206009. void clipToPath (const Path& path, const AffineTransform& transform)
  206010. {
  206011. createPath (path, transform);
  206012. CGContextClip (context);
  206013. }
  206014. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  206015. {
  206016. if (! transform.isSingularity())
  206017. {
  206018. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206019. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206020. flip();
  206021. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206022. applyTransform (t);
  206023. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206024. CGContextClipToMask (context, r, image);
  206025. applyTransform (t.inverted());
  206026. flip();
  206027. CGImageRelease (image);
  206028. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206029. }
  206030. }
  206031. bool clipRegionIntersects (const Rectangle<int>& r)
  206032. {
  206033. return getClipBounds().intersects (r);
  206034. }
  206035. const Rectangle<int> getClipBounds() const
  206036. {
  206037. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206038. return Rectangle<int> (roundToInt (bounds.origin.x),
  206039. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206040. roundToInt (bounds.size.width),
  206041. roundToInt (bounds.size.height));
  206042. }
  206043. bool isClipEmpty() const
  206044. {
  206045. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206046. }
  206047. void saveState()
  206048. {
  206049. CGContextSaveGState (context);
  206050. stateStack.add (new SavedState (*state));
  206051. }
  206052. void restoreState()
  206053. {
  206054. CGContextRestoreGState (context);
  206055. SavedState* const top = stateStack.getLast();
  206056. if (top != 0)
  206057. {
  206058. state = top;
  206059. stateStack.removeLast (1, false);
  206060. }
  206061. else
  206062. {
  206063. jassertfalse // trying to pop with an empty stack!
  206064. }
  206065. }
  206066. void setFill (const FillType& fillType)
  206067. {
  206068. state->fillType = fillType;
  206069. if (fillType.isColour())
  206070. {
  206071. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206072. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206073. CGContextSetAlpha (context, 1.0f);
  206074. }
  206075. }
  206076. void setOpacity (float newOpacity)
  206077. {
  206078. state->fillType.setOpacity (newOpacity);
  206079. setFill (state->fillType);
  206080. }
  206081. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206082. {
  206083. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206084. ? kCGInterpolationLow
  206085. : kCGInterpolationHigh);
  206086. }
  206087. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206088. {
  206089. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206090. if (replaceExistingContents)
  206091. {
  206092. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206093. CGContextClearRect (context, cgRect);
  206094. #else
  206095. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206096. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206097. CGContextClearRect (context, cgRect);
  206098. else
  206099. #endif
  206100. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206101. #endif
  206102. fillRect (r, false);
  206103. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206104. }
  206105. else
  206106. {
  206107. if (state->fillType.isColour())
  206108. {
  206109. CGContextFillRect (context, cgRect);
  206110. }
  206111. else if (state->fillType.isGradient())
  206112. {
  206113. CGContextSaveGState (context);
  206114. CGContextClipToRect (context, cgRect);
  206115. drawGradient();
  206116. CGContextRestoreGState (context);
  206117. }
  206118. else
  206119. {
  206120. CGContextSaveGState (context);
  206121. CGContextClipToRect (context, cgRect);
  206122. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206123. CGContextRestoreGState (context);
  206124. }
  206125. }
  206126. }
  206127. void fillPath (const Path& path, const AffineTransform& transform)
  206128. {
  206129. CGContextSaveGState (context);
  206130. if (state->fillType.isColour())
  206131. {
  206132. flip();
  206133. applyTransform (transform);
  206134. createPath (path);
  206135. if (path.isUsingNonZeroWinding())
  206136. CGContextFillPath (context);
  206137. else
  206138. CGContextEOFillPath (context);
  206139. }
  206140. else
  206141. {
  206142. createPath (path, transform);
  206143. if (path.isUsingNonZeroWinding())
  206144. CGContextClip (context);
  206145. else
  206146. CGContextEOClip (context);
  206147. if (state->fillType.isGradient())
  206148. drawGradient();
  206149. else
  206150. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206151. }
  206152. CGContextRestoreGState (context);
  206153. }
  206154. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206155. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206156. {
  206157. jassert (sourceImage.getBounds().contains (srcClip));
  206158. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206159. CGImageRef image = fullImage;
  206160. if (srcClip != sourceImage.getBounds())
  206161. {
  206162. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206163. srcClip.getWidth(), srcClip.getHeight()));
  206164. CGImageRelease (fullImage);
  206165. }
  206166. CGContextSaveGState (context);
  206167. CGContextSetAlpha (context, state->fillType.getOpacity());
  206168. flip();
  206169. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206170. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206171. if (fillEntireClipAsTiles)
  206172. {
  206173. #if JUCE_IPHONE
  206174. CGContextDrawTiledImage (context, imageRect, image);
  206175. #else
  206176. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206177. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206178. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206179. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206180. CGContextDrawTiledImage (context, imageRect, image);
  206181. else
  206182. #endif
  206183. {
  206184. // Fallback to manually doing a tiled fill on 10.4
  206185. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206186. const int iw = srcClip.getWidth();
  206187. const int ih = srcClip.getHeight();
  206188. int x = 0, y = 0;
  206189. while (x > clip.origin.x) x -= iw;
  206190. while (y > clip.origin.y) y -= ih;
  206191. const int right = (int) (clip.origin.x + clip.size.width);
  206192. const int bottom = (int) (clip.origin.y + clip.size.height);
  206193. while (y < bottom)
  206194. {
  206195. for (int x2 = x; x2 < right; x2 += iw)
  206196. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206197. y += ih;
  206198. }
  206199. }
  206200. #endif
  206201. }
  206202. else
  206203. {
  206204. CGContextDrawImage (context, imageRect, image);
  206205. }
  206206. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206207. CGContextRestoreGState (context);
  206208. }
  206209. void drawLine (double x1, double y1, double x2, double y2)
  206210. {
  206211. CGContextSetLineCap (context, kCGLineCapSquare);
  206212. CGContextSetLineWidth (context, 1.0f);
  206213. CGContextSetRGBStrokeColor (context,
  206214. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206215. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206216. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206217. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206218. CGContextStrokeLineSegments (context, line, 1);
  206219. }
  206220. void drawVerticalLine (const int x, double top, double bottom)
  206221. {
  206222. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206223. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206224. #else
  206225. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206226. // the x co-ord slightly to trick it..
  206227. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206228. #endif
  206229. }
  206230. void drawHorizontalLine (const int y, double left, double right)
  206231. {
  206232. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206233. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206234. #else
  206235. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206236. // the x co-ord slightly to trick it..
  206237. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206238. #endif
  206239. }
  206240. void setFont (const Font& newFont)
  206241. {
  206242. if (state->font != newFont)
  206243. {
  206244. state->fontRef = 0;
  206245. state->font = newFont;
  206246. MacTypeface* mf = dynamic_cast <MacTypeface*> (state->font.getTypeface());
  206247. if (mf != 0)
  206248. {
  206249. state->fontRef = mf->fontRef;
  206250. CGContextSetFont (context, state->fontRef);
  206251. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206252. state->fontTransform = mf->renderingTransform;
  206253. state->fontTransform.a *= state->font.getHorizontalScale();
  206254. CGContextSetTextMatrix (context, state->fontTransform);
  206255. }
  206256. }
  206257. }
  206258. const Font getFont()
  206259. {
  206260. return state->font;
  206261. }
  206262. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206263. {
  206264. if (state->fontRef != 0 && state->fillType.isColour())
  206265. {
  206266. if (transform.isOnlyTranslation())
  206267. {
  206268. CGGlyph g = glyphNumber;
  206269. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206270. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206271. }
  206272. else
  206273. {
  206274. CGContextSaveGState (context);
  206275. flip();
  206276. applyTransform (transform);
  206277. CGAffineTransform t = state->fontTransform;
  206278. t.d = -t.d;
  206279. CGContextSetTextMatrix (context, t);
  206280. CGGlyph g = glyphNumber;
  206281. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206282. CGContextSetTextMatrix (context, state->fontTransform);
  206283. CGContextRestoreGState (context);
  206284. }
  206285. }
  206286. else
  206287. {
  206288. Path p;
  206289. Font& f = state->font;
  206290. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206291. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206292. .followedBy (transform));
  206293. }
  206294. }
  206295. private:
  206296. CGContextRef context;
  206297. const CGFloat flipHeight;
  206298. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206299. CGFunctionCallbacks gradientCallbacks;
  206300. struct SavedState
  206301. {
  206302. SavedState()
  206303. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206304. {
  206305. }
  206306. SavedState (const SavedState& other)
  206307. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206308. fontTransform (other.fontTransform)
  206309. {
  206310. }
  206311. ~SavedState()
  206312. {
  206313. }
  206314. FillType fillType;
  206315. Font font;
  206316. CGFontRef fontRef;
  206317. CGAffineTransform fontTransform;
  206318. };
  206319. ScopedPointer <SavedState> state;
  206320. OwnedArray <SavedState> stateStack;
  206321. HeapBlock <PixelARGB> gradientLookupTable;
  206322. int numGradientLookupEntries;
  206323. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206324. {
  206325. const CoreGraphicsContext* const g = static_cast <const CoreGraphicsContext*> (info);
  206326. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206327. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206328. colour.unpremultiply();
  206329. outData[0] = colour.getRed() / 255.0f;
  206330. outData[1] = colour.getGreen() / 255.0f;
  206331. outData[2] = colour.getBlue() / 255.0f;
  206332. outData[3] = colour.getAlpha() / 255.0f;
  206333. }
  206334. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206335. {
  206336. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206337. --numGradientLookupEntries;
  206338. CGShadingRef result = 0;
  206339. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  206340. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206341. if (gradient.isRadial)
  206342. {
  206343. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206344. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206345. function, true, true);
  206346. }
  206347. else
  206348. {
  206349. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206350. CGPointMake (gradient.x2, gradient.y2),
  206351. function, true, true);
  206352. }
  206353. CGFunctionRelease (function);
  206354. return result;
  206355. }
  206356. void drawGradient()
  206357. {
  206358. flip();
  206359. applyTransform (state->fillType.transform);
  206360. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206361. // you draw a gradient with high quality interp enabled).
  206362. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206363. CGContextSetAlpha (context, state->fillType.getOpacity());
  206364. CGContextDrawShading (context, shading);
  206365. CGShadingRelease (shading);
  206366. }
  206367. void createPath (const Path& path) const
  206368. {
  206369. CGContextBeginPath (context);
  206370. Path::Iterator i (path);
  206371. while (i.next())
  206372. {
  206373. switch (i.elementType)
  206374. {
  206375. case Path::Iterator::startNewSubPath:
  206376. CGContextMoveToPoint (context, i.x1, i.y1);
  206377. break;
  206378. case Path::Iterator::lineTo:
  206379. CGContextAddLineToPoint (context, i.x1, i.y1);
  206380. break;
  206381. case Path::Iterator::quadraticTo:
  206382. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206383. break;
  206384. case Path::Iterator::cubicTo:
  206385. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206386. break;
  206387. case Path::Iterator::closePath:
  206388. CGContextClosePath (context); break;
  206389. default:
  206390. jassertfalse
  206391. break;
  206392. }
  206393. }
  206394. }
  206395. void createPath (const Path& path, const AffineTransform& transform) const
  206396. {
  206397. CGContextBeginPath (context);
  206398. Path::Iterator i (path);
  206399. while (i.next())
  206400. {
  206401. switch (i.elementType)
  206402. {
  206403. case Path::Iterator::startNewSubPath:
  206404. transform.transformPoint (i.x1, i.y1);
  206405. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206406. break;
  206407. case Path::Iterator::lineTo:
  206408. transform.transformPoint (i.x1, i.y1);
  206409. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206410. break;
  206411. case Path::Iterator::quadraticTo:
  206412. transform.transformPoint (i.x1, i.y1);
  206413. transform.transformPoint (i.x2, i.y2);
  206414. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206415. break;
  206416. case Path::Iterator::cubicTo:
  206417. transform.transformPoint (i.x1, i.y1);
  206418. transform.transformPoint (i.x2, i.y2);
  206419. transform.transformPoint (i.x3, i.y3);
  206420. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206421. break;
  206422. case Path::Iterator::closePath:
  206423. CGContextClosePath (context); break;
  206424. default:
  206425. jassertfalse
  206426. break;
  206427. }
  206428. }
  206429. }
  206430. static Image* createAlphaChannelImage (const Image& im)
  206431. {
  206432. if (im.getFormat() == Image::SingleChannel)
  206433. return const_cast <Image*> (&im);
  206434. return im.createCopyOfAlphaChannel();
  206435. }
  206436. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206437. {
  206438. if (im.getFormat() != Image::SingleChannel)
  206439. delete alphaIm;
  206440. }
  206441. void flip() const
  206442. {
  206443. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206444. }
  206445. void applyTransform (const AffineTransform& transform) const
  206446. {
  206447. CGAffineTransform t;
  206448. t.a = transform.mat00;
  206449. t.b = transform.mat10;
  206450. t.c = transform.mat01;
  206451. t.d = transform.mat11;
  206452. t.tx = transform.mat02;
  206453. t.ty = transform.mat12;
  206454. CGContextConcatCTM (context, t);
  206455. }
  206456. CoreGraphicsContext (const CoreGraphicsContext&);
  206457. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206458. };
  206459. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206460. {
  206461. return new CoreGraphicsContext (context, imageHeight);
  206462. }
  206463. #endif
  206464. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206465. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206466. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206467. // compiled on its own).
  206468. #if JUCE_INCLUDED_FILE
  206469. class NSViewComponentPeer;
  206470. END_JUCE_NAMESPACE
  206471. #define JuceNSView MakeObjCClassName(JuceNSView)
  206472. @interface JuceNSView : NSView<NSTextInput>
  206473. {
  206474. @public
  206475. NSViewComponentPeer* owner;
  206476. NSNotificationCenter* notificationCenter;
  206477. String* stringBeingComposed;
  206478. bool textWasInserted;
  206479. }
  206480. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206481. - (void) dealloc;
  206482. - (BOOL) isOpaque;
  206483. - (void) drawRect: (NSRect) r;
  206484. - (void) mouseDown: (NSEvent*) ev;
  206485. - (void) asyncMouseDown: (NSEvent*) ev;
  206486. - (void) mouseUp: (NSEvent*) ev;
  206487. - (void) asyncMouseUp: (NSEvent*) ev;
  206488. - (void) mouseDragged: (NSEvent*) ev;
  206489. - (void) mouseMoved: (NSEvent*) ev;
  206490. - (void) mouseEntered: (NSEvent*) ev;
  206491. - (void) mouseExited: (NSEvent*) ev;
  206492. - (void) rightMouseDown: (NSEvent*) ev;
  206493. - (void) rightMouseDragged: (NSEvent*) ev;
  206494. - (void) rightMouseUp: (NSEvent*) ev;
  206495. - (void) otherMouseDown: (NSEvent*) ev;
  206496. - (void) otherMouseDragged: (NSEvent*) ev;
  206497. - (void) otherMouseUp: (NSEvent*) ev;
  206498. - (void) scrollWheel: (NSEvent*) ev;
  206499. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206500. - (void) frameChanged: (NSNotification*) n;
  206501. - (void) viewDidMoveToWindow;
  206502. - (void) keyDown: (NSEvent*) ev;
  206503. - (void) keyUp: (NSEvent*) ev;
  206504. // NSTextInput Methods
  206505. - (void) insertText: (id) aString;
  206506. - (void) doCommandBySelector: (SEL) aSelector;
  206507. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206508. - (void) unmarkText;
  206509. - (BOOL) hasMarkedText;
  206510. - (long) conversationIdentifier;
  206511. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206512. - (NSRange) markedRange;
  206513. - (NSRange) selectedRange;
  206514. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206515. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206516. - (NSArray*) validAttributesForMarkedText;
  206517. - (void) flagsChanged: (NSEvent*) ev;
  206518. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206519. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206520. #endif
  206521. - (BOOL) becomeFirstResponder;
  206522. - (BOOL) resignFirstResponder;
  206523. - (BOOL) acceptsFirstResponder;
  206524. - (void) asyncRepaint: (id) rect;
  206525. - (NSArray*) getSupportedDragTypes;
  206526. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206527. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206528. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206529. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206530. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206531. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206532. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206533. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206534. @end
  206535. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206536. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206537. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206538. #else
  206539. @interface JuceNSWindow : NSWindow
  206540. #endif
  206541. {
  206542. @private
  206543. NSViewComponentPeer* owner;
  206544. bool isZooming;
  206545. }
  206546. - (void) setOwner: (NSViewComponentPeer*) owner;
  206547. - (BOOL) canBecomeKeyWindow;
  206548. - (void) becomeKeyWindow;
  206549. - (BOOL) windowShouldClose: (id) window;
  206550. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206551. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206552. - (void) zoom: (id) sender;
  206553. @end
  206554. BEGIN_JUCE_NAMESPACE
  206555. class NSViewComponentPeer : public ComponentPeer
  206556. {
  206557. public:
  206558. NSViewComponentPeer (Component* const component,
  206559. const int windowStyleFlags,
  206560. NSView* viewToAttachTo);
  206561. ~NSViewComponentPeer();
  206562. void* getNativeHandle() const;
  206563. void setVisible (bool shouldBeVisible);
  206564. void setTitle (const String& title);
  206565. void setPosition (int x, int y);
  206566. void setSize (int w, int h);
  206567. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206568. const Rectangle<int> getBounds (const bool global) const;
  206569. const Rectangle<int> getBounds() const;
  206570. const Point<int> getScreenPosition() const;
  206571. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206572. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206573. void setMinimised (bool shouldBeMinimised);
  206574. bool isMinimised() const;
  206575. void setFullScreen (bool shouldBeFullScreen);
  206576. bool isFullScreen() const;
  206577. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206578. const BorderSize getFrameSize() const;
  206579. bool setAlwaysOnTop (bool alwaysOnTop);
  206580. void toFront (bool makeActiveWindow);
  206581. void toBehind (ComponentPeer* other);
  206582. void setIcon (const Image& newIcon);
  206583. const StringArray getAvailableRenderingEngines() throw();
  206584. int getCurrentRenderingEngine() throw();
  206585. void setCurrentRenderingEngine (int index) throw();
  206586. virtual void redirectMouseDown (NSEvent* ev);
  206587. virtual void redirectMouseUp (NSEvent* ev);
  206588. virtual void redirectMouseDrag (NSEvent* ev);
  206589. virtual void redirectMouseMove (NSEvent* ev);
  206590. virtual void redirectMouseEnter (NSEvent* ev);
  206591. virtual void redirectMouseExit (NSEvent* ev);
  206592. virtual void redirectMouseWheel (NSEvent* ev);
  206593. void sendMouseEvent (NSEvent* ev);
  206594. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206595. virtual bool redirectKeyDown (NSEvent* ev);
  206596. virtual bool redirectKeyUp (NSEvent* ev);
  206597. virtual void redirectModKeyChange (NSEvent* ev);
  206598. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206599. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206600. #endif
  206601. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206602. virtual bool isOpaque();
  206603. virtual void drawRect (NSRect r);
  206604. virtual bool canBecomeKeyWindow();
  206605. virtual bool windowShouldClose();
  206606. virtual void redirectMovedOrResized();
  206607. virtual void viewMovedToWindow();
  206608. virtual NSRect constrainRect (NSRect r);
  206609. static void showArrowCursorIfNeeded();
  206610. static void updateModifiers (NSEvent* e);
  206611. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206612. static int getKeyCodeFromEvent (NSEvent* ev)
  206613. {
  206614. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206615. int keyCode = unmodified[0];
  206616. if (keyCode == 0x19) // (backwards-tab)
  206617. keyCode = '\t';
  206618. else if (keyCode == 0x03) // (enter)
  206619. keyCode = '\r';
  206620. return keyCode;
  206621. }
  206622. static int64 getMouseTime (NSEvent* e)
  206623. {
  206624. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206625. + (int64) ([e timestamp] * 1000.0);
  206626. }
  206627. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206628. {
  206629. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206630. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206631. }
  206632. static int getModifierForButtonNumber (const NSInteger num)
  206633. {
  206634. return num == 0 ? ModifierKeys::leftButtonModifier
  206635. : (num == 1 ? ModifierKeys::rightButtonModifier
  206636. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206637. }
  206638. virtual void viewFocusGain();
  206639. virtual void viewFocusLoss();
  206640. bool isFocused() const;
  206641. void grabFocus();
  206642. void textInputRequired (const Point<int>& position);
  206643. void repaint (int x, int y, int w, int h);
  206644. void performAnyPendingRepaintsNow();
  206645. juce_UseDebuggingNewOperator
  206646. NSWindow* window;
  206647. JuceNSView* view;
  206648. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206649. static ModifierKeys currentModifiers;
  206650. static ComponentPeer* currentlyFocusedPeer;
  206651. static Array<int> keysCurrentlyDown;
  206652. };
  206653. END_JUCE_NAMESPACE
  206654. @implementation JuceNSView
  206655. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206656. withFrame: (NSRect) frame
  206657. {
  206658. [super initWithFrame: frame];
  206659. owner = owner_;
  206660. stringBeingComposed = 0;
  206661. textWasInserted = false;
  206662. notificationCenter = [NSNotificationCenter defaultCenter];
  206663. [notificationCenter addObserver: self
  206664. selector: @selector (frameChanged:)
  206665. name: NSViewFrameDidChangeNotification
  206666. object: self];
  206667. if (! owner_->isSharedWindow)
  206668. {
  206669. [notificationCenter addObserver: self
  206670. selector: @selector (frameChanged:)
  206671. name: NSWindowDidMoveNotification
  206672. object: owner_->window];
  206673. }
  206674. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206675. return self;
  206676. }
  206677. - (void) dealloc
  206678. {
  206679. [notificationCenter removeObserver: self];
  206680. delete stringBeingComposed;
  206681. [super dealloc];
  206682. }
  206683. - (void) drawRect: (NSRect) r
  206684. {
  206685. if (owner != 0)
  206686. owner->drawRect (r);
  206687. }
  206688. - (BOOL) isOpaque
  206689. {
  206690. return owner == 0 || owner->isOpaque();
  206691. }
  206692. - (void) mouseDown: (NSEvent*) ev
  206693. {
  206694. // In some host situations, the host will stop modal loops from working
  206695. // correctly if they're called from a mouse event, so we'll trigger
  206696. // the event asynchronously..
  206697. if (JUCEApplication::getInstance() == 0)
  206698. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206699. withObject: ev
  206700. waitUntilDone: NO];
  206701. else
  206702. [self asyncMouseDown: ev];
  206703. }
  206704. - (void) asyncMouseDown: (NSEvent*) ev
  206705. {
  206706. if (owner != 0)
  206707. owner->redirectMouseDown (ev);
  206708. }
  206709. - (void) mouseUp: (NSEvent*) ev
  206710. {
  206711. // In some host situations, the host will stop modal loops from working
  206712. // correctly if they're called from a mouse event, so we'll trigger
  206713. // the event asynchronously..
  206714. if (JUCEApplication::getInstance() == 0)
  206715. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206716. withObject: ev
  206717. waitUntilDone: NO];
  206718. else
  206719. [self asyncMouseUp: ev];
  206720. }
  206721. - (void) asyncMouseUp: (NSEvent*) ev
  206722. {
  206723. if (owner != 0)
  206724. owner->redirectMouseUp (ev);
  206725. }
  206726. - (void) mouseDragged: (NSEvent*) ev
  206727. {
  206728. if (owner != 0)
  206729. owner->redirectMouseDrag (ev);
  206730. }
  206731. - (void) mouseMoved: (NSEvent*) ev
  206732. {
  206733. if (owner != 0)
  206734. owner->redirectMouseMove (ev);
  206735. }
  206736. - (void) mouseEntered: (NSEvent*) ev
  206737. {
  206738. if (owner != 0)
  206739. owner->redirectMouseEnter (ev);
  206740. }
  206741. - (void) mouseExited: (NSEvent*) ev
  206742. {
  206743. if (owner != 0)
  206744. owner->redirectMouseExit (ev);
  206745. }
  206746. - (void) rightMouseDown: (NSEvent*) ev
  206747. {
  206748. [self mouseDown: ev];
  206749. }
  206750. - (void) rightMouseDragged: (NSEvent*) ev
  206751. {
  206752. [self mouseDragged: ev];
  206753. }
  206754. - (void) rightMouseUp: (NSEvent*) ev
  206755. {
  206756. [self mouseUp: ev];
  206757. }
  206758. - (void) otherMouseDown: (NSEvent*) ev
  206759. {
  206760. [self mouseDown: ev];
  206761. }
  206762. - (void) otherMouseDragged: (NSEvent*) ev
  206763. {
  206764. [self mouseDragged: ev];
  206765. }
  206766. - (void) otherMouseUp: (NSEvent*) ev
  206767. {
  206768. [self mouseUp: ev];
  206769. }
  206770. - (void) scrollWheel: (NSEvent*) ev
  206771. {
  206772. if (owner != 0)
  206773. owner->redirectMouseWheel (ev);
  206774. }
  206775. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206776. {
  206777. return YES;
  206778. }
  206779. - (void) frameChanged: (NSNotification*) n
  206780. {
  206781. if (owner != 0)
  206782. owner->redirectMovedOrResized();
  206783. }
  206784. - (void) viewDidMoveToWindow
  206785. {
  206786. if (owner != 0)
  206787. owner->viewMovedToWindow();
  206788. }
  206789. - (void) asyncRepaint: (id) rect
  206790. {
  206791. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206792. [self setNeedsDisplayInRect: *r];
  206793. }
  206794. - (void) keyDown: (NSEvent*) ev
  206795. {
  206796. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206797. textWasInserted = false;
  206798. if (target != 0)
  206799. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206800. else
  206801. deleteAndZero (stringBeingComposed);
  206802. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206803. [super keyDown: ev];
  206804. }
  206805. - (void) keyUp: (NSEvent*) ev
  206806. {
  206807. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206808. [super keyUp: ev];
  206809. }
  206810. - (void) insertText: (id) aString
  206811. {
  206812. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206813. if ([aString length] > 0)
  206814. {
  206815. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206816. if (target != 0)
  206817. {
  206818. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206819. textWasInserted = true;
  206820. }
  206821. }
  206822. deleteAndZero (stringBeingComposed);
  206823. }
  206824. - (void) doCommandBySelector: (SEL) aSelector
  206825. {
  206826. }
  206827. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206828. {
  206829. if (stringBeingComposed == 0)
  206830. stringBeingComposed = new String();
  206831. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206832. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206833. if (target != 0)
  206834. {
  206835. const Range<int> currentHighlight (target->getHighlightedRegion());
  206836. target->insertTextAtCaret (*stringBeingComposed);
  206837. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206838. textWasInserted = true;
  206839. }
  206840. }
  206841. - (void) unmarkText
  206842. {
  206843. if (stringBeingComposed != 0)
  206844. {
  206845. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206846. if (target != 0)
  206847. {
  206848. target->insertTextAtCaret (*stringBeingComposed);
  206849. textWasInserted = true;
  206850. }
  206851. }
  206852. deleteAndZero (stringBeingComposed);
  206853. }
  206854. - (BOOL) hasMarkedText
  206855. {
  206856. return stringBeingComposed != 0;
  206857. }
  206858. - (long) conversationIdentifier
  206859. {
  206860. return (long) (pointer_sized_int) self;
  206861. }
  206862. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206863. {
  206864. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206865. if (target != 0)
  206866. {
  206867. const Range<int> r ((int) theRange.location,
  206868. (int) (theRange.location + theRange.length));
  206869. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206870. }
  206871. return nil;
  206872. }
  206873. - (NSRange) markedRange
  206874. {
  206875. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206876. : NSMakeRange (NSNotFound, 0);
  206877. }
  206878. - (NSRange) selectedRange
  206879. {
  206880. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206881. if (target != 0)
  206882. {
  206883. const Range<int> highlight (target->getHighlightedRegion());
  206884. if (! highlight.isEmpty())
  206885. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206886. }
  206887. return NSMakeRange (NSNotFound, 0);
  206888. }
  206889. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206890. {
  206891. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206892. if (comp == 0)
  206893. return NSMakeRect (0, 0, 0, 0);
  206894. const Rectangle<int> bounds (comp->getScreenBounds());
  206895. return NSMakeRect (bounds.getX(),
  206896. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206897. bounds.getWidth(),
  206898. bounds.getHeight());
  206899. }
  206900. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206901. {
  206902. return NSNotFound;
  206903. }
  206904. - (NSArray*) validAttributesForMarkedText
  206905. {
  206906. return [NSArray array];
  206907. }
  206908. - (void) flagsChanged: (NSEvent*) ev
  206909. {
  206910. if (owner != 0)
  206911. owner->redirectModKeyChange (ev);
  206912. }
  206913. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206914. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206915. {
  206916. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206917. return true;
  206918. return [super performKeyEquivalent: ev];
  206919. }
  206920. #endif
  206921. - (BOOL) becomeFirstResponder
  206922. {
  206923. if (owner != 0)
  206924. owner->viewFocusGain();
  206925. return true;
  206926. }
  206927. - (BOOL) resignFirstResponder
  206928. {
  206929. if (owner != 0)
  206930. owner->viewFocusLoss();
  206931. return true;
  206932. }
  206933. - (BOOL) acceptsFirstResponder
  206934. {
  206935. return owner != 0 && owner->canBecomeKeyWindow();
  206936. }
  206937. - (NSArray*) getSupportedDragTypes
  206938. {
  206939. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206940. }
  206941. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206942. {
  206943. return owner != 0 && owner->sendDragCallback (type, sender);
  206944. }
  206945. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206946. {
  206947. if ([self sendDragCallback: 0 sender: sender])
  206948. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206949. else
  206950. return NSDragOperationNone;
  206951. }
  206952. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206953. {
  206954. if ([self sendDragCallback: 0 sender: sender])
  206955. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206956. else
  206957. return NSDragOperationNone;
  206958. }
  206959. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206960. {
  206961. [self sendDragCallback: 1 sender: sender];
  206962. }
  206963. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206964. {
  206965. [self sendDragCallback: 1 sender: sender];
  206966. }
  206967. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206968. {
  206969. return YES;
  206970. }
  206971. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206972. {
  206973. return [self sendDragCallback: 2 sender: sender];
  206974. }
  206975. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206976. {
  206977. }
  206978. @end
  206979. @implementation JuceNSWindow
  206980. - (void) setOwner: (NSViewComponentPeer*) owner_
  206981. {
  206982. owner = owner_;
  206983. isZooming = false;
  206984. }
  206985. - (BOOL) canBecomeKeyWindow
  206986. {
  206987. return owner != 0 && owner->canBecomeKeyWindow();
  206988. }
  206989. - (void) becomeKeyWindow
  206990. {
  206991. [super becomeKeyWindow];
  206992. if (owner != 0)
  206993. owner->grabFocus();
  206994. }
  206995. - (BOOL) windowShouldClose: (id) window
  206996. {
  206997. return owner == 0 || owner->windowShouldClose();
  206998. }
  206999. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  207000. {
  207001. if (owner != 0)
  207002. frameRect = owner->constrainRect (frameRect);
  207003. return frameRect;
  207004. }
  207005. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  207006. {
  207007. if (isZooming)
  207008. return proposedFrameSize;
  207009. NSRect frameRect = [self frame];
  207010. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  207011. frameRect.size = proposedFrameSize;
  207012. if (owner != 0)
  207013. frameRect = owner->constrainRect (frameRect);
  207014. return frameRect.size;
  207015. }
  207016. - (void) zoom: (id) sender
  207017. {
  207018. isZooming = true;
  207019. [super zoom: sender];
  207020. isZooming = false;
  207021. }
  207022. - (void) windowWillMove: (NSNotification*) notification
  207023. {
  207024. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  207025. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  207026. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  207027. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  207028. }
  207029. @end
  207030. BEGIN_JUCE_NAMESPACE
  207031. ModifierKeys NSViewComponentPeer::currentModifiers;
  207032. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  207033. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  207034. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  207035. {
  207036. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  207037. return true;
  207038. if (keyCode >= 'A' && keyCode <= 'Z'
  207039. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
  207040. return true;
  207041. if (keyCode >= 'a' && keyCode <= 'z'
  207042. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
  207043. return true;
  207044. return false;
  207045. }
  207046. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  207047. {
  207048. int m = 0;
  207049. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  207050. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  207051. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  207052. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  207053. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  207054. }
  207055. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  207056. {
  207057. updateModifiers (ev);
  207058. int keyCode = getKeyCodeFromEvent (ev);
  207059. if (keyCode != 0)
  207060. {
  207061. if (isKeyDown)
  207062. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  207063. else
  207064. keysCurrentlyDown.removeValue (keyCode);
  207065. }
  207066. }
  207067. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207068. {
  207069. return NSViewComponentPeer::currentModifiers;
  207070. }
  207071. void ModifierKeys::updateCurrentModifiers() throw()
  207072. {
  207073. currentModifiers = NSViewComponentPeer::currentModifiers;
  207074. }
  207075. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207076. const int windowStyleFlags,
  207077. NSView* viewToAttachTo)
  207078. : ComponentPeer (component_, windowStyleFlags),
  207079. window (0),
  207080. view (0),
  207081. isSharedWindow (viewToAttachTo != 0),
  207082. fullScreen (false),
  207083. insideDrawRect (false),
  207084. #if USE_COREGRAPHICS_RENDERING
  207085. usingCoreGraphics (true),
  207086. #else
  207087. usingCoreGraphics (false),
  207088. #endif
  207089. recursiveToFrontCall (false)
  207090. {
  207091. NSRect r;
  207092. r.origin.x = 0;
  207093. r.origin.y = 0;
  207094. r.size.width = (float) component->getWidth();
  207095. r.size.height = (float) component->getHeight();
  207096. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207097. [view setPostsFrameChangedNotifications: YES];
  207098. if (isSharedWindow)
  207099. {
  207100. window = [viewToAttachTo window];
  207101. [viewToAttachTo addSubview: view];
  207102. setVisible (component->isVisible());
  207103. }
  207104. else
  207105. {
  207106. r.origin.x = (float) component->getX();
  207107. r.origin.y = (float) component->getY();
  207108. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207109. unsigned int style = 0;
  207110. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207111. style = NSBorderlessWindowMask;
  207112. else
  207113. style = NSTitledWindowMask;
  207114. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207115. style |= NSMiniaturizableWindowMask;
  207116. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207117. style |= NSClosableWindowMask;
  207118. if ((windowStyleFlags & windowIsResizable) != 0)
  207119. style |= NSResizableWindowMask;
  207120. window = [[JuceNSWindow alloc] initWithContentRect: r
  207121. styleMask: style
  207122. backing: NSBackingStoreBuffered
  207123. defer: YES];
  207124. [((JuceNSWindow*) window) setOwner: this];
  207125. [window orderOut: nil];
  207126. [window setDelegate: (JuceNSWindow*) window];
  207127. [window setOpaque: component->isOpaque()];
  207128. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207129. if (component->isAlwaysOnTop())
  207130. [window setLevel: NSFloatingWindowLevel];
  207131. [window setContentView: view];
  207132. [window setAutodisplay: YES];
  207133. [window setAcceptsMouseMovedEvents: YES];
  207134. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207135. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207136. [window setReleasedWhenClosed: YES];
  207137. [window retain];
  207138. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207139. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207140. }
  207141. setTitle (component->getName());
  207142. }
  207143. NSViewComponentPeer::~NSViewComponentPeer()
  207144. {
  207145. view->owner = 0;
  207146. [view removeFromSuperview];
  207147. [view release];
  207148. if (! isSharedWindow)
  207149. {
  207150. [((JuceNSWindow*) window) setOwner: 0];
  207151. [window close];
  207152. [window release];
  207153. }
  207154. }
  207155. void* NSViewComponentPeer::getNativeHandle() const
  207156. {
  207157. return view;
  207158. }
  207159. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207160. {
  207161. if (isSharedWindow)
  207162. {
  207163. [view setHidden: ! shouldBeVisible];
  207164. }
  207165. else
  207166. {
  207167. if (shouldBeVisible)
  207168. {
  207169. [window orderFront: nil];
  207170. handleBroughtToFront();
  207171. }
  207172. else
  207173. {
  207174. [window orderOut: nil];
  207175. }
  207176. }
  207177. }
  207178. void NSViewComponentPeer::setTitle (const String& title)
  207179. {
  207180. const ScopedAutoReleasePool pool;
  207181. if (! isSharedWindow)
  207182. [window setTitle: juceStringToNS (title)];
  207183. }
  207184. void NSViewComponentPeer::setPosition (int x, int y)
  207185. {
  207186. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207187. }
  207188. void NSViewComponentPeer::setSize (int w, int h)
  207189. {
  207190. setBounds (component->getX(), component->getY(), w, h, false);
  207191. }
  207192. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  207193. {
  207194. fullScreen = isNowFullScreen;
  207195. w = jmax (0, w);
  207196. h = jmax (0, h);
  207197. NSRect r;
  207198. r.origin.x = (float) x;
  207199. r.origin.y = (float) y;
  207200. r.size.width = (float) w;
  207201. r.size.height = (float) h;
  207202. if (isSharedWindow)
  207203. {
  207204. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207205. if ([view frame].size.width != r.size.width
  207206. || [view frame].size.height != r.size.height)
  207207. [view setNeedsDisplay: true];
  207208. [view setFrame: r];
  207209. }
  207210. else
  207211. {
  207212. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207213. [window setFrame: [window frameRectForContentRect: r]
  207214. display: true];
  207215. }
  207216. }
  207217. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207218. {
  207219. NSRect r = [view frame];
  207220. if (global && [view window] != 0)
  207221. {
  207222. r = [view convertRect: r toView: nil];
  207223. NSRect wr = [[view window] frame];
  207224. r.origin.x += wr.origin.x;
  207225. r.origin.y += wr.origin.y;
  207226. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207227. }
  207228. else
  207229. {
  207230. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207231. }
  207232. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207233. }
  207234. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207235. {
  207236. return getBounds (! isSharedWindow);
  207237. }
  207238. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207239. {
  207240. return getBounds (true).getPosition();
  207241. }
  207242. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207243. {
  207244. return relativePosition + getScreenPosition();
  207245. }
  207246. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207247. {
  207248. return screenPosition - getScreenPosition();
  207249. }
  207250. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207251. {
  207252. if (constrainer != 0)
  207253. {
  207254. NSRect current = [window frame];
  207255. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207256. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207257. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207258. (int) r.size.width, (int) r.size.height);
  207259. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207260. (int) current.size.width, (int) current.size.height);
  207261. constrainer->checkBounds (pos, original,
  207262. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207263. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207264. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207265. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207266. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207267. r.origin.x = pos.getX();
  207268. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207269. r.size.width = pos.getWidth();
  207270. r.size.height = pos.getHeight();
  207271. }
  207272. return r;
  207273. }
  207274. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207275. {
  207276. if (! isSharedWindow)
  207277. {
  207278. if (shouldBeMinimised)
  207279. [window miniaturize: nil];
  207280. else
  207281. [window deminiaturize: nil];
  207282. }
  207283. }
  207284. bool NSViewComponentPeer::isMinimised() const
  207285. {
  207286. return window != 0 && [window isMiniaturized];
  207287. }
  207288. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207289. {
  207290. if (! isSharedWindow)
  207291. {
  207292. Rectangle<int> r (lastNonFullscreenBounds);
  207293. setMinimised (false);
  207294. if (fullScreen != shouldBeFullScreen)
  207295. {
  207296. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207297. {
  207298. fullScreen = true;
  207299. [window performZoom: nil];
  207300. }
  207301. else
  207302. {
  207303. if (shouldBeFullScreen)
  207304. r = Desktop::getInstance().getMainMonitorArea();
  207305. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207306. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207307. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207308. }
  207309. }
  207310. }
  207311. }
  207312. bool NSViewComponentPeer::isFullScreen() const
  207313. {
  207314. return fullScreen;
  207315. }
  207316. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207317. {
  207318. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207319. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207320. return false;
  207321. NSPoint p;
  207322. p.x = (float) position.getX();
  207323. p.y = (float) position.getY();
  207324. NSView* v = [view hitTest: p];
  207325. if (trueIfInAChildWindow)
  207326. return v != nil;
  207327. return v == view;
  207328. }
  207329. const BorderSize NSViewComponentPeer::getFrameSize() const
  207330. {
  207331. BorderSize b;
  207332. if (! isSharedWindow)
  207333. {
  207334. NSRect v = [view convertRect: [view frame] toView: nil];
  207335. NSRect w = [window frame];
  207336. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207337. b.setBottom ((int) v.origin.y);
  207338. b.setLeft ((int) v.origin.x);
  207339. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207340. }
  207341. return b;
  207342. }
  207343. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207344. {
  207345. if (! isSharedWindow)
  207346. {
  207347. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207348. : NSNormalWindowLevel];
  207349. }
  207350. return true;
  207351. }
  207352. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207353. {
  207354. if (isSharedWindow)
  207355. {
  207356. [[view superview] addSubview: view
  207357. positioned: NSWindowAbove
  207358. relativeTo: nil];
  207359. }
  207360. if (window != 0 && component->isVisible())
  207361. {
  207362. if (makeActiveWindow)
  207363. [window makeKeyAndOrderFront: nil];
  207364. else
  207365. [window orderFront: nil];
  207366. if (! recursiveToFrontCall)
  207367. {
  207368. recursiveToFrontCall = true;
  207369. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207370. handleBroughtToFront();
  207371. recursiveToFrontCall = false;
  207372. }
  207373. }
  207374. }
  207375. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207376. {
  207377. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207378. if (isSharedWindow)
  207379. {
  207380. [[view superview] addSubview: view
  207381. positioned: NSWindowBelow
  207382. relativeTo: o->view];
  207383. }
  207384. else
  207385. {
  207386. [window orderWindow: NSWindowBelow
  207387. relativeTo: o->window != 0 ? [o->window windowNumber]
  207388. : nil ];
  207389. }
  207390. }
  207391. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207392. {
  207393. // to do..
  207394. }
  207395. void NSViewComponentPeer::viewFocusGain()
  207396. {
  207397. if (currentlyFocusedPeer != this)
  207398. {
  207399. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207400. currentlyFocusedPeer->handleFocusLoss();
  207401. currentlyFocusedPeer = this;
  207402. handleFocusGain();
  207403. }
  207404. }
  207405. void NSViewComponentPeer::viewFocusLoss()
  207406. {
  207407. if (currentlyFocusedPeer == this)
  207408. {
  207409. currentlyFocusedPeer = 0;
  207410. handleFocusLoss();
  207411. }
  207412. }
  207413. void juce_HandleProcessFocusChange()
  207414. {
  207415. NSViewComponentPeer::keysCurrentlyDown.clear();
  207416. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207417. {
  207418. if (Process::isForegroundProcess())
  207419. {
  207420. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207421. ComponentPeer::bringModalComponentToFront();
  207422. }
  207423. else
  207424. {
  207425. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207426. // turn kiosk mode off if we lose focus..
  207427. Desktop::getInstance().setKioskModeComponent (0);
  207428. }
  207429. }
  207430. }
  207431. bool NSViewComponentPeer::isFocused() const
  207432. {
  207433. return isSharedWindow ? this == currentlyFocusedPeer
  207434. : (window != 0 && [window isKeyWindow]);
  207435. }
  207436. void NSViewComponentPeer::grabFocus()
  207437. {
  207438. if (window != 0)
  207439. {
  207440. [window makeKeyWindow];
  207441. [window makeFirstResponder: view];
  207442. viewFocusGain();
  207443. }
  207444. }
  207445. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207446. {
  207447. }
  207448. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207449. {
  207450. String unicode (nsStringToJuce ([ev characters]));
  207451. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207452. int keyCode = getKeyCodeFromEvent (ev);
  207453. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207454. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207455. if (unicode.isNotEmpty() || keyCode != 0)
  207456. {
  207457. if (isKeyDown)
  207458. {
  207459. bool used = false;
  207460. while (unicode.length() > 0)
  207461. {
  207462. juce_wchar textCharacter = unicode[0];
  207463. unicode = unicode.substring (1);
  207464. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207465. textCharacter = 0;
  207466. used = handleKeyUpOrDown (true) || used;
  207467. used = handleKeyPress (keyCode, textCharacter) || used;
  207468. }
  207469. return used;
  207470. }
  207471. else
  207472. {
  207473. if (handleKeyUpOrDown (false))
  207474. return true;
  207475. }
  207476. }
  207477. return false;
  207478. }
  207479. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207480. {
  207481. updateKeysDown (ev, true);
  207482. bool used = handleKeyEvent (ev, true);
  207483. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207484. {
  207485. // for command keys, the key-up event is thrown away, so simulate one..
  207486. updateKeysDown (ev, false);
  207487. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207488. }
  207489. // (If we're running modally, don't allow unused keystrokes to be passed
  207490. // along to other blocked views..)
  207491. if (Component::getCurrentlyModalComponent() != 0)
  207492. used = true;
  207493. return used;
  207494. }
  207495. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207496. {
  207497. updateKeysDown (ev, false);
  207498. return handleKeyEvent (ev, false)
  207499. || Component::getCurrentlyModalComponent() != 0;
  207500. }
  207501. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207502. {
  207503. keysCurrentlyDown.clear();
  207504. handleKeyUpOrDown (true);
  207505. updateModifiers (ev);
  207506. handleModifierKeysChange();
  207507. }
  207508. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207509. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207510. {
  207511. if ([ev type] == NSKeyDown)
  207512. return redirectKeyDown (ev);
  207513. else if ([ev type] == NSKeyUp)
  207514. return redirectKeyUp (ev);
  207515. return false;
  207516. }
  207517. #endif
  207518. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207519. {
  207520. updateModifiers (ev);
  207521. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207522. }
  207523. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207524. {
  207525. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207526. sendMouseEvent (ev);
  207527. }
  207528. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207529. {
  207530. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207531. sendMouseEvent (ev);
  207532. showArrowCursorIfNeeded();
  207533. }
  207534. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207535. {
  207536. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207537. sendMouseEvent (ev);
  207538. }
  207539. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207540. {
  207541. currentModifiers = currentModifiers.withoutMouseButtons();
  207542. sendMouseEvent (ev);
  207543. showArrowCursorIfNeeded();
  207544. }
  207545. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207546. {
  207547. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207548. currentModifiers = currentModifiers.withoutMouseButtons();
  207549. sendMouseEvent (ev);
  207550. }
  207551. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207552. {
  207553. currentModifiers = currentModifiers.withoutMouseButtons();
  207554. sendMouseEvent (ev);
  207555. }
  207556. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207557. {
  207558. updateModifiers (ev);
  207559. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207560. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207561. }
  207562. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207563. {
  207564. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207565. if (mouse.getComponentUnderMouse() == 0
  207566. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207567. {
  207568. [[NSCursor arrowCursor] set];
  207569. }
  207570. }
  207571. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207572. {
  207573. NSString* bestType
  207574. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207575. if (bestType == nil)
  207576. return false;
  207577. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207578. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207579. StringArray files;
  207580. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207581. if (list == nil)
  207582. return false;
  207583. if ([list isKindOfClass: [NSArray class]])
  207584. {
  207585. NSArray* items = (NSArray*) list;
  207586. for (unsigned int i = 0; i < [items count]; ++i)
  207587. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207588. }
  207589. if (files.size() == 0)
  207590. return false;
  207591. if (type == 0)
  207592. handleFileDragMove (files, pos);
  207593. else if (type == 1)
  207594. handleFileDragExit (files);
  207595. else if (type == 2)
  207596. handleFileDragDrop (files, pos);
  207597. return true;
  207598. }
  207599. bool NSViewComponentPeer::isOpaque()
  207600. {
  207601. return component == 0 || component->isOpaque();
  207602. }
  207603. void NSViewComponentPeer::drawRect (NSRect r)
  207604. {
  207605. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207606. return;
  207607. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207608. if (! component->isOpaque())
  207609. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207610. #if USE_COREGRAPHICS_RENDERING
  207611. if (usingCoreGraphics)
  207612. {
  207613. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207614. insideDrawRect = true;
  207615. handlePaint (context);
  207616. insideDrawRect = false;
  207617. }
  207618. else
  207619. #endif
  207620. {
  207621. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207622. (int) (r.size.width + 0.5f),
  207623. (int) (r.size.height + 0.5f),
  207624. ! getComponent()->isOpaque());
  207625. LowLevelGraphicsSoftwareRenderer context (temp);
  207626. context.setOrigin (-roundToInt (r.origin.x),
  207627. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207628. const NSRect* rects = 0;
  207629. NSInteger numRects = 0;
  207630. [view getRectsBeingDrawn: &rects count: &numRects];
  207631. RectangleList clip;
  207632. for (int i = 0; i < numRects; ++i)
  207633. {
  207634. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207635. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207636. roundToInt (rects[i].size.width),
  207637. roundToInt (rects[i].size.height)));
  207638. }
  207639. if (context.clipToRectangleList (clip))
  207640. {
  207641. insideDrawRect = true;
  207642. handlePaint (context);
  207643. insideDrawRect = false;
  207644. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207645. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207646. CGColorSpaceRelease (colourSpace);
  207647. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207648. CGImageRelease (image);
  207649. }
  207650. }
  207651. }
  207652. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207653. {
  207654. StringArray s;
  207655. s.add ("Software Renderer");
  207656. #if USE_COREGRAPHICS_RENDERING
  207657. s.add ("CoreGraphics Renderer");
  207658. #endif
  207659. return s;
  207660. }
  207661. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207662. {
  207663. return usingCoreGraphics ? 1 : 0;
  207664. }
  207665. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207666. {
  207667. #if USE_COREGRAPHICS_RENDERING
  207668. if (usingCoreGraphics != (index > 0))
  207669. {
  207670. usingCoreGraphics = index > 0;
  207671. [view setNeedsDisplay: true];
  207672. }
  207673. #endif
  207674. }
  207675. bool NSViewComponentPeer::canBecomeKeyWindow()
  207676. {
  207677. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207678. }
  207679. bool NSViewComponentPeer::windowShouldClose()
  207680. {
  207681. if (! isValidPeer (this))
  207682. return YES;
  207683. handleUserClosingWindow();
  207684. return NO;
  207685. }
  207686. void NSViewComponentPeer::redirectMovedOrResized()
  207687. {
  207688. handleMovedOrResized();
  207689. }
  207690. void NSViewComponentPeer::viewMovedToWindow()
  207691. {
  207692. if (isSharedWindow)
  207693. window = [view window];
  207694. }
  207695. void Desktop::createMouseInputSources()
  207696. {
  207697. mouseSources.add (new MouseInputSource (0, true));
  207698. }
  207699. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207700. {
  207701. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207702. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207703. // is apparently still available in 64-bit apps..
  207704. if (enableOrDisable)
  207705. {
  207706. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207707. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207708. }
  207709. else
  207710. {
  207711. SetSystemUIMode (kUIModeNormal, 0);
  207712. }
  207713. }
  207714. class AsyncRepaintMessage : public CallbackMessage
  207715. {
  207716. public:
  207717. NSViewComponentPeer* const peer;
  207718. const Rectangle<int> rect;
  207719. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207720. : peer (peer_), rect (rect_)
  207721. {
  207722. }
  207723. void messageCallback()
  207724. {
  207725. if (ComponentPeer::isValidPeer (peer))
  207726. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207727. }
  207728. };
  207729. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207730. {
  207731. if (insideDrawRect)
  207732. {
  207733. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207734. }
  207735. else
  207736. {
  207737. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207738. (float) w, (float) h)];
  207739. }
  207740. }
  207741. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207742. {
  207743. [view displayIfNeeded];
  207744. }
  207745. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207746. {
  207747. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207748. }
  207749. Image* juce_createIconForFile (const File& file)
  207750. {
  207751. const ScopedAutoReleasePool pool;
  207752. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207753. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207754. [NSGraphicsContext saveGraphicsState];
  207755. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207756. [image drawAtPoint: NSMakePoint (0, 0)
  207757. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207758. operation: NSCompositeSourceOver fraction: 1.0f];
  207759. [[NSGraphicsContext currentContext] flushGraphics];
  207760. [NSGraphicsContext restoreGraphicsState];
  207761. return result;
  207762. }
  207763. const int KeyPress::spaceKey = ' ';
  207764. const int KeyPress::returnKey = 0x0d;
  207765. const int KeyPress::escapeKey = 0x1b;
  207766. const int KeyPress::backspaceKey = 0x7f;
  207767. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207768. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207769. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207770. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207771. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207772. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207773. const int KeyPress::endKey = NSEndFunctionKey;
  207774. const int KeyPress::homeKey = NSHomeFunctionKey;
  207775. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207776. const int KeyPress::insertKey = -1;
  207777. const int KeyPress::tabKey = 9;
  207778. const int KeyPress::F1Key = NSF1FunctionKey;
  207779. const int KeyPress::F2Key = NSF2FunctionKey;
  207780. const int KeyPress::F3Key = NSF3FunctionKey;
  207781. const int KeyPress::F4Key = NSF4FunctionKey;
  207782. const int KeyPress::F5Key = NSF5FunctionKey;
  207783. const int KeyPress::F6Key = NSF6FunctionKey;
  207784. const int KeyPress::F7Key = NSF7FunctionKey;
  207785. const int KeyPress::F8Key = NSF8FunctionKey;
  207786. const int KeyPress::F9Key = NSF9FunctionKey;
  207787. const int KeyPress::F10Key = NSF10FunctionKey;
  207788. const int KeyPress::F11Key = NSF1FunctionKey;
  207789. const int KeyPress::F12Key = NSF12FunctionKey;
  207790. const int KeyPress::F13Key = NSF13FunctionKey;
  207791. const int KeyPress::F14Key = NSF14FunctionKey;
  207792. const int KeyPress::F15Key = NSF15FunctionKey;
  207793. const int KeyPress::F16Key = NSF16FunctionKey;
  207794. const int KeyPress::numberPad0 = 0x30020;
  207795. const int KeyPress::numberPad1 = 0x30021;
  207796. const int KeyPress::numberPad2 = 0x30022;
  207797. const int KeyPress::numberPad3 = 0x30023;
  207798. const int KeyPress::numberPad4 = 0x30024;
  207799. const int KeyPress::numberPad5 = 0x30025;
  207800. const int KeyPress::numberPad6 = 0x30026;
  207801. const int KeyPress::numberPad7 = 0x30027;
  207802. const int KeyPress::numberPad8 = 0x30028;
  207803. const int KeyPress::numberPad9 = 0x30029;
  207804. const int KeyPress::numberPadAdd = 0x3002a;
  207805. const int KeyPress::numberPadSubtract = 0x3002b;
  207806. const int KeyPress::numberPadMultiply = 0x3002c;
  207807. const int KeyPress::numberPadDivide = 0x3002d;
  207808. const int KeyPress::numberPadSeparator = 0x3002e;
  207809. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207810. const int KeyPress::numberPadEquals = 0x30030;
  207811. const int KeyPress::numberPadDelete = 0x30031;
  207812. const int KeyPress::playKey = 0x30000;
  207813. const int KeyPress::stopKey = 0x30001;
  207814. const int KeyPress::fastForwardKey = 0x30002;
  207815. const int KeyPress::rewindKey = 0x30003;
  207816. #endif
  207817. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207818. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207819. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207820. // compiled on its own).
  207821. #if JUCE_INCLUDED_FILE
  207822. #if JUCE_MAC
  207823. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207824. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  207825. {
  207826. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207827. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207828. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207829. [im release];
  207830. return c;
  207831. }
  207832. static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy)
  207833. {
  207834. MemoryInputStream stream (data, false);
  207835. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207836. jassert (im != 0);
  207837. if (im == 0)
  207838. return 0;
  207839. return juce_createMouseCursorFromImage (*im,
  207840. (int) (hx * im->getWidth()),
  207841. (int) (hy * im->getHeight()));
  207842. }
  207843. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207844. {
  207845. const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207846. MemoryBlock mb;
  207847. if (f.getChildFile (filename).loadFileAsData (mb))
  207848. return juce_cursorFromData (mb, hx, hy);
  207849. return 0;
  207850. }
  207851. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  207852. {
  207853. const ScopedAutoReleasePool pool;
  207854. NSCursor* c = 0;
  207855. switch (type)
  207856. {
  207857. case MouseCursor::NormalCursor:
  207858. c = [NSCursor arrowCursor];
  207859. break;
  207860. case MouseCursor::NoCursor:
  207861. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207862. case MouseCursor::DraggingHandCursor:
  207863. c = [NSCursor openHandCursor];
  207864. break;
  207865. case MouseCursor::CopyingCursor:
  207866. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207867. case MouseCursor::WaitCursor:
  207868. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207869. break;
  207870. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207871. case MouseCursor::IBeamCursor:
  207872. c = [NSCursor IBeamCursor];
  207873. break;
  207874. case MouseCursor::PointingHandCursor:
  207875. c = [NSCursor pointingHandCursor];
  207876. break;
  207877. case MouseCursor::LeftRightResizeCursor:
  207878. c = [NSCursor resizeLeftRightCursor];
  207879. break;
  207880. case MouseCursor::LeftEdgeResizeCursor:
  207881. c = [NSCursor resizeLeftCursor];
  207882. break;
  207883. case MouseCursor::RightEdgeResizeCursor:
  207884. c = [NSCursor resizeRightCursor];
  207885. break;
  207886. case MouseCursor::UpDownResizeCursor:
  207887. case MouseCursor::TopEdgeResizeCursor:
  207888. case MouseCursor::BottomEdgeResizeCursor:
  207889. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207890. case MouseCursor::TopLeftCornerResizeCursor:
  207891. case MouseCursor::BottomRightCornerResizeCursor:
  207892. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207893. case MouseCursor::TopRightCornerResizeCursor:
  207894. case MouseCursor::BottomLeftCornerResizeCursor:
  207895. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207896. case MouseCursor::UpDownLeftRightResizeCursor:
  207897. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207898. case MouseCursor::CrosshairCursor:
  207899. c = [NSCursor crosshairCursor];
  207900. break;
  207901. }
  207902. [c retain];
  207903. return c;
  207904. }
  207905. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  207906. {
  207907. NSCursor* c = (NSCursor*) cursorHandle;
  207908. [c release];
  207909. }
  207910. void MouseCursor::showInAllWindows() const
  207911. {
  207912. showInWindow (0);
  207913. }
  207914. void MouseCursor::showInWindow (ComponentPeer*) const
  207915. {
  207916. NSCursor* const c = (NSCursor*) getHandle();
  207917. [c set];
  207918. }
  207919. #else
  207920. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; }
  207921. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; }
  207922. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  207923. void MouseCursor::showInAllWindows() const {}
  207924. void MouseCursor::showInWindow (ComponentPeer*) const {}
  207925. #endif
  207926. #endif
  207927. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207928. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207929. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207930. // compiled on its own).
  207931. #if JUCE_INCLUDED_FILE
  207932. class NSViewComponentInternal : public ComponentMovementWatcher
  207933. {
  207934. Component* const owner;
  207935. NSViewComponentPeer* currentPeer;
  207936. bool wasShowing;
  207937. public:
  207938. NSView* const view;
  207939. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207940. : ComponentMovementWatcher (owner_),
  207941. owner (owner_),
  207942. currentPeer (0),
  207943. wasShowing (false),
  207944. view (view_)
  207945. {
  207946. [view_ retain];
  207947. if (owner_->isShowing())
  207948. componentPeerChanged();
  207949. }
  207950. ~NSViewComponentInternal()
  207951. {
  207952. [view removeFromSuperview];
  207953. [view release];
  207954. }
  207955. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207956. {
  207957. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207958. // The ComponentMovementWatcher version of this method avoids calling
  207959. // us when the top-level comp is resized, but for an NSView we need to know this
  207960. // because with inverted co-ords, we need to update the position even if the
  207961. // top-left pos hasn't changed
  207962. if (comp.isOnDesktop() && wasResized)
  207963. componentMovedOrResized (wasMoved, wasResized);
  207964. }
  207965. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207966. {
  207967. Component* const topComp = owner->getTopLevelComponent();
  207968. if (topComp->getPeer() != 0)
  207969. {
  207970. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207971. NSRect r;
  207972. r.origin.x = (float) pos.getX();
  207973. r.origin.y = (float) pos.getY();
  207974. r.size.width = (float) owner->getWidth();
  207975. r.size.height = (float) owner->getHeight();
  207976. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207977. [view setFrame: r];
  207978. }
  207979. }
  207980. void componentPeerChanged()
  207981. {
  207982. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207983. if (currentPeer != peer)
  207984. {
  207985. [view removeFromSuperview];
  207986. currentPeer = peer;
  207987. if (peer != 0)
  207988. {
  207989. [peer->view addSubview: view];
  207990. componentMovedOrResized (false, false);
  207991. }
  207992. }
  207993. [view setHidden: ! owner->isShowing()];
  207994. }
  207995. void componentVisibilityChanged (Component&)
  207996. {
  207997. componentPeerChanged();
  207998. }
  207999. juce_UseDebuggingNewOperator
  208000. private:
  208001. NSViewComponentInternal (const NSViewComponentInternal&);
  208002. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  208003. };
  208004. NSViewComponent::NSViewComponent()
  208005. {
  208006. }
  208007. NSViewComponent::~NSViewComponent()
  208008. {
  208009. }
  208010. void NSViewComponent::setView (void* view)
  208011. {
  208012. if (view != getView())
  208013. {
  208014. if (view != 0)
  208015. info = new NSViewComponentInternal ((NSView*) view, this);
  208016. else
  208017. info = 0;
  208018. }
  208019. }
  208020. void* NSViewComponent::getView() const
  208021. {
  208022. return info == 0 ? 0 : info->view;
  208023. }
  208024. void NSViewComponent::paint (Graphics& g)
  208025. {
  208026. }
  208027. #endif
  208028. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  208029. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  208030. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208031. // compiled on its own).
  208032. #if JUCE_INCLUDED_FILE
  208033. AppleRemoteDevice::AppleRemoteDevice()
  208034. : device (0),
  208035. queue (0),
  208036. remoteId (0)
  208037. {
  208038. }
  208039. AppleRemoteDevice::~AppleRemoteDevice()
  208040. {
  208041. stop();
  208042. }
  208043. static io_object_t getAppleRemoteDevice()
  208044. {
  208045. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208046. io_iterator_t iter = 0;
  208047. io_object_t iod = 0;
  208048. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208049. && iter != 0)
  208050. {
  208051. iod = IOIteratorNext (iter);
  208052. }
  208053. IOObjectRelease (iter);
  208054. return iod;
  208055. }
  208056. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208057. {
  208058. jassert (*device == 0);
  208059. io_name_t classname;
  208060. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208061. {
  208062. IOCFPlugInInterface** cfPlugInInterface = 0;
  208063. SInt32 score = 0;
  208064. if (IOCreatePlugInInterfaceForService (iod,
  208065. kIOHIDDeviceUserClientTypeID,
  208066. kIOCFPlugInInterfaceID,
  208067. &cfPlugInInterface,
  208068. &score) == kIOReturnSuccess)
  208069. {
  208070. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208071. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208072. device);
  208073. (void) hr;
  208074. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208075. }
  208076. }
  208077. return *device != 0;
  208078. }
  208079. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208080. {
  208081. if (queue != 0)
  208082. return true;
  208083. stop();
  208084. bool result = false;
  208085. io_object_t iod = getAppleRemoteDevice();
  208086. if (iod != 0)
  208087. {
  208088. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208089. result = true;
  208090. else
  208091. stop();
  208092. IOObjectRelease (iod);
  208093. }
  208094. return result;
  208095. }
  208096. void AppleRemoteDevice::stop()
  208097. {
  208098. if (queue != 0)
  208099. {
  208100. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208101. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208102. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208103. queue = 0;
  208104. }
  208105. if (device != 0)
  208106. {
  208107. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208108. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208109. device = 0;
  208110. }
  208111. }
  208112. bool AppleRemoteDevice::isActive() const
  208113. {
  208114. return queue != 0;
  208115. }
  208116. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208117. {
  208118. if (result == kIOReturnSuccess)
  208119. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208120. }
  208121. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208122. {
  208123. Array <int> cookies;
  208124. CFArrayRef elements;
  208125. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208126. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208127. return false;
  208128. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208129. {
  208130. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208131. // get the cookie
  208132. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208133. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208134. continue;
  208135. long number;
  208136. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208137. continue;
  208138. cookies.add ((int) number);
  208139. }
  208140. CFRelease (elements);
  208141. if ((*(IOHIDDeviceInterface**) device)
  208142. ->open ((IOHIDDeviceInterface**) device,
  208143. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208144. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208145. {
  208146. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208147. if (queue != 0)
  208148. {
  208149. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208150. for (int i = 0; i < cookies.size(); ++i)
  208151. {
  208152. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208153. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208154. }
  208155. CFRunLoopSourceRef eventSource;
  208156. if ((*(IOHIDQueueInterface**) queue)
  208157. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208158. {
  208159. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208160. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208161. {
  208162. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208163. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208164. return true;
  208165. }
  208166. }
  208167. }
  208168. }
  208169. return false;
  208170. }
  208171. void AppleRemoteDevice::handleCallbackInternal()
  208172. {
  208173. int totalValues = 0;
  208174. AbsoluteTime nullTime = { 0, 0 };
  208175. char cookies [12];
  208176. int numCookies = 0;
  208177. while (numCookies < numElementsInArray (cookies))
  208178. {
  208179. IOHIDEventStruct e;
  208180. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208181. break;
  208182. if ((int) e.elementCookie == 19)
  208183. {
  208184. remoteId = e.value;
  208185. buttonPressed (switched, false);
  208186. }
  208187. else
  208188. {
  208189. totalValues += e.value;
  208190. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208191. }
  208192. }
  208193. cookies [numCookies++] = 0;
  208194. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208195. static const char buttonPatterns[] =
  208196. {
  208197. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208198. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208199. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208200. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208201. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208202. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208203. 0x1f, 0x12, 0x04, 0x02, 0,
  208204. 0x1f, 0x12, 0x03, 0x02, 0,
  208205. 0x1f, 0x12, 0x1f, 0x12, 0,
  208206. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208207. 19, 0
  208208. };
  208209. int buttonNum = (int) menuButton;
  208210. int i = 0;
  208211. while (i < numElementsInArray (buttonPatterns))
  208212. {
  208213. if (strcmp (cookies, buttonPatterns + i) == 0)
  208214. {
  208215. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208216. break;
  208217. }
  208218. i += (int) strlen (buttonPatterns + i) + 1;
  208219. ++buttonNum;
  208220. }
  208221. }
  208222. #endif
  208223. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208224. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208225. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208226. // compiled on its own).
  208227. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208228. #if JUCE_MAC
  208229. END_JUCE_NAMESPACE
  208230. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208231. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208232. {
  208233. CriticalSection* contextLock;
  208234. bool needsUpdate;
  208235. }
  208236. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208237. - (bool) makeActive;
  208238. - (void) makeInactive;
  208239. - (void) reshape;
  208240. @end
  208241. @implementation ThreadSafeNSOpenGLView
  208242. - (id) initWithFrame: (NSRect) frameRect
  208243. pixelFormat: (NSOpenGLPixelFormat*) format
  208244. {
  208245. contextLock = new CriticalSection();
  208246. self = [super initWithFrame: frameRect pixelFormat: format];
  208247. if (self != nil)
  208248. [[NSNotificationCenter defaultCenter] addObserver: self
  208249. selector: @selector (_surfaceNeedsUpdate:)
  208250. name: NSViewGlobalFrameDidChangeNotification
  208251. object: self];
  208252. return self;
  208253. }
  208254. - (void) dealloc
  208255. {
  208256. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208257. delete contextLock;
  208258. [super dealloc];
  208259. }
  208260. - (bool) makeActive
  208261. {
  208262. const ScopedLock sl (*contextLock);
  208263. if ([self openGLContext] == 0)
  208264. return false;
  208265. [[self openGLContext] makeCurrentContext];
  208266. if (needsUpdate)
  208267. {
  208268. [super update];
  208269. needsUpdate = false;
  208270. }
  208271. return true;
  208272. }
  208273. - (void) makeInactive
  208274. {
  208275. const ScopedLock sl (*contextLock);
  208276. [NSOpenGLContext clearCurrentContext];
  208277. }
  208278. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208279. {
  208280. const ScopedLock sl (*contextLock);
  208281. needsUpdate = true;
  208282. }
  208283. - (void) update
  208284. {
  208285. const ScopedLock sl (*contextLock);
  208286. needsUpdate = true;
  208287. }
  208288. - (void) reshape
  208289. {
  208290. const ScopedLock sl (*contextLock);
  208291. needsUpdate = true;
  208292. }
  208293. @end
  208294. BEGIN_JUCE_NAMESPACE
  208295. class WindowedGLContext : public OpenGLContext
  208296. {
  208297. public:
  208298. WindowedGLContext (Component* const component,
  208299. const OpenGLPixelFormat& pixelFormat_,
  208300. NSOpenGLContext* sharedContext)
  208301. : renderContext (0),
  208302. pixelFormat (pixelFormat_)
  208303. {
  208304. jassert (component != 0);
  208305. NSOpenGLPixelFormatAttribute attribs [64];
  208306. int n = 0;
  208307. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208308. attribs[n++] = NSOpenGLPFAAccelerated;
  208309. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208310. attribs[n++] = NSOpenGLPFAColorSize;
  208311. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208312. pixelFormat.greenBits,
  208313. pixelFormat.blueBits);
  208314. attribs[n++] = NSOpenGLPFAAlphaSize;
  208315. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208316. attribs[n++] = NSOpenGLPFADepthSize;
  208317. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208318. attribs[n++] = NSOpenGLPFAStencilSize;
  208319. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208320. attribs[n++] = NSOpenGLPFAAccumSize;
  208321. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208322. pixelFormat.accumulationBufferGreenBits,
  208323. pixelFormat.accumulationBufferBlueBits,
  208324. pixelFormat.accumulationBufferAlphaBits);
  208325. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208326. attribs[n++] = NSOpenGLPFASampleBuffers;
  208327. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208328. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208329. attribs[n++] = NSOpenGLPFANoRecovery;
  208330. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208331. NSOpenGLPixelFormat* format
  208332. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208333. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208334. pixelFormat: format];
  208335. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208336. shareContext: sharedContext] autorelease];
  208337. const GLint swapInterval = 1;
  208338. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208339. [view setOpenGLContext: renderContext];
  208340. [renderContext setView: view];
  208341. [format release];
  208342. viewHolder = new NSViewComponentInternal (view, component);
  208343. }
  208344. ~WindowedGLContext()
  208345. {
  208346. makeInactive();
  208347. [renderContext clearDrawable];
  208348. viewHolder = 0;
  208349. }
  208350. bool makeActive() const throw()
  208351. {
  208352. jassert (renderContext != 0);
  208353. [view makeActive];
  208354. return isActive();
  208355. }
  208356. bool makeInactive() const throw()
  208357. {
  208358. [view makeInactive];
  208359. return true;
  208360. }
  208361. bool isActive() const throw()
  208362. {
  208363. return [NSOpenGLContext currentContext] == renderContext;
  208364. }
  208365. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208366. void* getRawContext() const throw() { return renderContext; }
  208367. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208368. {
  208369. }
  208370. void swapBuffers()
  208371. {
  208372. [renderContext flushBuffer];
  208373. }
  208374. bool setSwapInterval (const int numFramesPerSwap)
  208375. {
  208376. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208377. forParameter: NSOpenGLCPSwapInterval];
  208378. return true;
  208379. }
  208380. int getSwapInterval() const
  208381. {
  208382. GLint numFrames = 0;
  208383. [renderContext getValues: &numFrames
  208384. forParameter: NSOpenGLCPSwapInterval];
  208385. return numFrames;
  208386. }
  208387. void repaint()
  208388. {
  208389. // we need to invalidate the juce view that holds this gl view, to make it
  208390. // cause a repaint callback
  208391. NSView* v = (NSView*) viewHolder->view;
  208392. NSRect r = [v frame];
  208393. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208394. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208395. // repaint message, thus never causing our paint() callback, and never repainting
  208396. // the comp. So invalidating just a little bit around the edge helps..
  208397. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208398. }
  208399. void* getNativeWindowHandle() const { return viewHolder->view; }
  208400. juce_UseDebuggingNewOperator
  208401. NSOpenGLContext* renderContext;
  208402. ThreadSafeNSOpenGLView* view;
  208403. private:
  208404. OpenGLPixelFormat pixelFormat;
  208405. ScopedPointer <NSViewComponentInternal> viewHolder;
  208406. WindowedGLContext (const WindowedGLContext&);
  208407. WindowedGLContext& operator= (const WindowedGLContext&);
  208408. };
  208409. OpenGLContext* OpenGLComponent::createContext()
  208410. {
  208411. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  208412. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  208413. return (c->renderContext != 0) ? c.release() : 0;
  208414. }
  208415. void* OpenGLComponent::getNativeWindowHandle() const
  208416. {
  208417. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  208418. : 0;
  208419. }
  208420. void juce_glViewport (const int w, const int h)
  208421. {
  208422. glViewport (0, 0, w, h);
  208423. }
  208424. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208425. OwnedArray <OpenGLPixelFormat>& results)
  208426. {
  208427. /* GLint attribs [64];
  208428. int n = 0;
  208429. attribs[n++] = AGL_RGBA;
  208430. attribs[n++] = AGL_DOUBLEBUFFER;
  208431. attribs[n++] = AGL_ACCELERATED;
  208432. attribs[n++] = AGL_NO_RECOVERY;
  208433. attribs[n++] = AGL_NONE;
  208434. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208435. while (p != 0)
  208436. {
  208437. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208438. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208439. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208440. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208441. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208442. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208443. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208444. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208445. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208446. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208447. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208448. results.add (pf);
  208449. p = aglNextPixelFormat (p);
  208450. }*/
  208451. //jassertfalse //xxx can't see how you do this in cocoa!
  208452. }
  208453. #else
  208454. END_JUCE_NAMESPACE
  208455. @interface JuceGLView : UIView
  208456. {
  208457. }
  208458. + (Class) layerClass;
  208459. @end
  208460. @implementation JuceGLView
  208461. + (Class) layerClass
  208462. {
  208463. return [CAEAGLLayer class];
  208464. }
  208465. @end
  208466. BEGIN_JUCE_NAMESPACE
  208467. class GLESContext : public OpenGLContext
  208468. {
  208469. public:
  208470. GLESContext (UIViewComponentPeer* peer,
  208471. Component* const component_,
  208472. const OpenGLPixelFormat& pixelFormat_,
  208473. const GLESContext* const sharedContext,
  208474. NSUInteger apiType)
  208475. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  208476. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  208477. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  208478. {
  208479. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  208480. view.opaque = YES;
  208481. view.hidden = NO;
  208482. view.backgroundColor = [UIColor blackColor];
  208483. view.userInteractionEnabled = NO;
  208484. glLayer = (CAEAGLLayer*) [view layer];
  208485. [peer->view addSubview: view];
  208486. if (sharedContext != 0)
  208487. context = [[EAGLContext alloc] initWithAPI: apiType
  208488. sharegroup: [sharedContext->context sharegroup]];
  208489. else
  208490. context = [[EAGLContext alloc] initWithAPI: apiType];
  208491. createGLBuffers();
  208492. }
  208493. ~GLESContext()
  208494. {
  208495. makeInactive();
  208496. [context release];
  208497. [view removeFromSuperview];
  208498. [view release];
  208499. freeGLBuffers();
  208500. }
  208501. bool makeActive() const throw()
  208502. {
  208503. jassert (context != 0);
  208504. [EAGLContext setCurrentContext: context];
  208505. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208506. return true;
  208507. }
  208508. void swapBuffers()
  208509. {
  208510. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208511. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208512. }
  208513. bool makeInactive() const throw()
  208514. {
  208515. return [EAGLContext setCurrentContext: nil];
  208516. }
  208517. bool isActive() const throw()
  208518. {
  208519. return [EAGLContext currentContext] == context;
  208520. }
  208521. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208522. void* getRawContext() const throw() { return glLayer; }
  208523. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208524. {
  208525. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208526. if (lastWidth != w || lastHeight != h)
  208527. {
  208528. lastWidth = w;
  208529. lastHeight = h;
  208530. freeGLBuffers();
  208531. createGLBuffers();
  208532. }
  208533. }
  208534. bool setSwapInterval (const int numFramesPerSwap)
  208535. {
  208536. numFrames = numFramesPerSwap;
  208537. return true;
  208538. }
  208539. int getSwapInterval() const
  208540. {
  208541. return numFrames;
  208542. }
  208543. void repaint()
  208544. {
  208545. }
  208546. void createGLBuffers()
  208547. {
  208548. makeActive();
  208549. glGenFramebuffersOES (1, &frameBufferHandle);
  208550. glGenRenderbuffersOES (1, &colorBufferHandle);
  208551. glGenRenderbuffersOES (1, &depthBufferHandle);
  208552. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208553. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208554. GLint width, height;
  208555. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208556. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208557. if (useDepthBuffer)
  208558. {
  208559. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208560. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208561. }
  208562. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208563. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208564. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208565. if (useDepthBuffer)
  208566. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208567. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208568. }
  208569. void freeGLBuffers()
  208570. {
  208571. if (frameBufferHandle != 0)
  208572. {
  208573. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208574. frameBufferHandle = 0;
  208575. }
  208576. if (colorBufferHandle != 0)
  208577. {
  208578. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208579. colorBufferHandle = 0;
  208580. }
  208581. if (depthBufferHandle != 0)
  208582. {
  208583. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208584. depthBufferHandle = 0;
  208585. }
  208586. }
  208587. juce_UseDebuggingNewOperator
  208588. private:
  208589. Component::SafePointer<Component> component;
  208590. OpenGLPixelFormat pixelFormat;
  208591. JuceGLView* view;
  208592. CAEAGLLayer* glLayer;
  208593. EAGLContext* context;
  208594. bool useDepthBuffer;
  208595. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208596. int numFrames;
  208597. int lastWidth, lastHeight;
  208598. GLESContext (const GLESContext&);
  208599. GLESContext& operator= (const GLESContext&);
  208600. };
  208601. OpenGLContext* OpenGLComponent::createContext()
  208602. {
  208603. ScopedAutoReleasePool pool;
  208604. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208605. if (peer != 0)
  208606. return new GLESContext (peer, this, preferredPixelFormat,
  208607. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208608. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208609. return 0;
  208610. }
  208611. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208612. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208613. {
  208614. }
  208615. void juce_glViewport (const int w, const int h)
  208616. {
  208617. glViewport (0, 0, w, h);
  208618. }
  208619. #endif
  208620. #endif
  208621. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208622. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208623. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208624. // compiled on its own).
  208625. #if JUCE_INCLUDED_FILE
  208626. class JuceMainMenuHandler;
  208627. END_JUCE_NAMESPACE
  208628. using namespace JUCE_NAMESPACE;
  208629. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208630. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208631. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208632. #else
  208633. @interface JuceMenuCallback : NSObject
  208634. #endif
  208635. {
  208636. JuceMainMenuHandler* owner;
  208637. }
  208638. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208639. - (void) dealloc;
  208640. - (void) menuItemInvoked: (id) menu;
  208641. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208642. @end
  208643. BEGIN_JUCE_NAMESPACE
  208644. class JuceMainMenuHandler : private MenuBarModelListener,
  208645. private DeletedAtShutdown
  208646. {
  208647. public:
  208648. static JuceMainMenuHandler* instance;
  208649. JuceMainMenuHandler()
  208650. : currentModel (0),
  208651. lastUpdateTime (0)
  208652. {
  208653. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208654. }
  208655. ~JuceMainMenuHandler()
  208656. {
  208657. setMenu (0);
  208658. jassert (instance == this);
  208659. instance = 0;
  208660. [callback release];
  208661. }
  208662. void setMenu (MenuBarModel* const newMenuBarModel)
  208663. {
  208664. if (currentModel != newMenuBarModel)
  208665. {
  208666. if (currentModel != 0)
  208667. currentModel->removeListener (this);
  208668. currentModel = newMenuBarModel;
  208669. if (currentModel != 0)
  208670. currentModel->addListener (this);
  208671. menuBarItemsChanged (0);
  208672. }
  208673. }
  208674. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208675. const String& name, const int menuId, const int tag)
  208676. {
  208677. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208678. action: nil
  208679. keyEquivalent: @""];
  208680. [item setTag: tag];
  208681. NSMenu* sub = createMenu (child, name, menuId, tag);
  208682. [parent setSubmenu: sub forItem: item];
  208683. [sub setAutoenablesItems: false];
  208684. [sub release];
  208685. }
  208686. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208687. const String& name, const int menuId, const int tag)
  208688. {
  208689. [parentItem setTag: tag];
  208690. NSMenu* menu = [parentItem submenu];
  208691. [menu setTitle: juceStringToNS (name)];
  208692. while ([menu numberOfItems] > 0)
  208693. [menu removeItemAtIndex: 0];
  208694. PopupMenu::MenuItemIterator iter (menuToCopy);
  208695. while (iter.next())
  208696. addMenuItem (iter, menu, menuId, tag);
  208697. [menu setAutoenablesItems: false];
  208698. [menu update];
  208699. }
  208700. void menuBarItemsChanged (MenuBarModel*)
  208701. {
  208702. lastUpdateTime = Time::getMillisecondCounter();
  208703. StringArray menuNames;
  208704. if (currentModel != 0)
  208705. menuNames = currentModel->getMenuBarNames();
  208706. NSMenu* menuBar = [NSApp mainMenu];
  208707. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208708. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208709. int menuId = 1;
  208710. for (int i = 0; i < menuNames.size(); ++i)
  208711. {
  208712. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208713. if (i >= [menuBar numberOfItems] - 1)
  208714. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208715. else
  208716. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208717. }
  208718. }
  208719. static void flashMenuBar (NSMenu* menu)
  208720. {
  208721. if ([[menu title] isEqualToString: @"Apple"])
  208722. return;
  208723. [menu retain];
  208724. const unichar f35Key = NSF35FunctionKey;
  208725. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208726. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208727. action: nil
  208728. keyEquivalent: f35String];
  208729. [item setTarget: nil];
  208730. [menu insertItem: item atIndex: [menu numberOfItems]];
  208731. [item release];
  208732. if ([menu indexOfItem: item] >= 0)
  208733. {
  208734. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208735. location: NSZeroPoint
  208736. modifierFlags: NSCommandKeyMask
  208737. timestamp: 0
  208738. windowNumber: 0
  208739. context: [NSGraphicsContext currentContext]
  208740. characters: f35String
  208741. charactersIgnoringModifiers: f35String
  208742. isARepeat: NO
  208743. keyCode: 0];
  208744. [menu performKeyEquivalent: f35Event];
  208745. if ([menu indexOfItem: item] >= 0)
  208746. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208747. }
  208748. [menu release];
  208749. }
  208750. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208751. {
  208752. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208753. {
  208754. NSMenuItem* m = [menu itemAtIndex: i];
  208755. if ([m tag] == info.commandID)
  208756. return m;
  208757. if ([m submenu] != 0)
  208758. {
  208759. NSMenuItem* found = findMenuItem ([m submenu], info);
  208760. if (found != 0)
  208761. return found;
  208762. }
  208763. }
  208764. return 0;
  208765. }
  208766. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208767. {
  208768. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208769. if (item != 0)
  208770. flashMenuBar ([item menu]);
  208771. }
  208772. void updateMenus()
  208773. {
  208774. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208775. menuBarItemsChanged (0);
  208776. }
  208777. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208778. {
  208779. if (currentModel != 0)
  208780. {
  208781. if (commandManager != 0)
  208782. {
  208783. ApplicationCommandTarget::InvocationInfo info (commandId);
  208784. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208785. commandManager->invoke (info, true);
  208786. }
  208787. currentModel->menuItemSelected (commandId, topLevelIndex);
  208788. }
  208789. }
  208790. MenuBarModel* currentModel;
  208791. uint32 lastUpdateTime;
  208792. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208793. const int topLevelMenuId, const int topLevelIndex)
  208794. {
  208795. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf ("<end>", false, true));
  208796. if (text == 0)
  208797. text = @"";
  208798. if (iter.isSeparator)
  208799. {
  208800. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208801. }
  208802. else if (iter.isSectionHeader)
  208803. {
  208804. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208805. action: nil
  208806. keyEquivalent: @""];
  208807. [item setEnabled: false];
  208808. }
  208809. else if (iter.subMenu != 0)
  208810. {
  208811. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208812. action: nil
  208813. keyEquivalent: @""];
  208814. [item setTag: iter.itemId];
  208815. [item setEnabled: iter.isEnabled];
  208816. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208817. [sub setDelegate: nil];
  208818. [menuToAddTo setSubmenu: sub forItem: item];
  208819. [sub release];
  208820. }
  208821. else
  208822. {
  208823. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208824. action: @selector (menuItemInvoked:)
  208825. keyEquivalent: @""];
  208826. [item setTag: iter.itemId];
  208827. [item setEnabled: iter.isEnabled];
  208828. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208829. [item setTarget: (id) callback];
  208830. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208831. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208832. [item setRepresentedObject: info];
  208833. if (iter.commandManager != 0)
  208834. {
  208835. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208836. ->getKeyPressesAssignedToCommand (iter.itemId));
  208837. if (keyPresses.size() > 0)
  208838. {
  208839. const KeyPress& kp = keyPresses.getReference(0);
  208840. juce_wchar key = kp.getTextCharacter();
  208841. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208842. key = NSBackspaceCharacter;
  208843. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208844. key = NSDeleteCharacter;
  208845. else if (key == 0)
  208846. key = (juce_wchar) kp.getKeyCode();
  208847. unsigned int mods = 0;
  208848. if (kp.getModifiers().isShiftDown())
  208849. mods |= NSShiftKeyMask;
  208850. if (kp.getModifiers().isCtrlDown())
  208851. mods |= NSControlKeyMask;
  208852. if (kp.getModifiers().isAltDown())
  208853. mods |= NSAlternateKeyMask;
  208854. if (kp.getModifiers().isCommandDown())
  208855. mods |= NSCommandKeyMask;
  208856. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208857. [item setKeyEquivalentModifierMask: mods];
  208858. }
  208859. }
  208860. }
  208861. }
  208862. JuceMenuCallback* callback;
  208863. private:
  208864. NSMenu* createMenu (const PopupMenu menu,
  208865. const String& menuName,
  208866. const int topLevelMenuId,
  208867. const int topLevelIndex)
  208868. {
  208869. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208870. [m setAutoenablesItems: false];
  208871. [m setDelegate: callback];
  208872. PopupMenu::MenuItemIterator iter (menu);
  208873. while (iter.next())
  208874. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208875. [m update];
  208876. return m;
  208877. }
  208878. };
  208879. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208880. END_JUCE_NAMESPACE
  208881. @implementation JuceMenuCallback
  208882. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208883. {
  208884. [super init];
  208885. owner = owner_;
  208886. return self;
  208887. }
  208888. - (void) dealloc
  208889. {
  208890. [super dealloc];
  208891. }
  208892. - (void) menuItemInvoked: (id) menu
  208893. {
  208894. NSMenuItem* item = (NSMenuItem*) menu;
  208895. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208896. {
  208897. // 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
  208898. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208899. // into the focused component and let it trigger the menu item indirectly.
  208900. NSEvent* e = [NSApp currentEvent];
  208901. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208902. {
  208903. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208904. {
  208905. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208906. if (peer != 0)
  208907. {
  208908. if ([e type] == NSKeyDown)
  208909. peer->redirectKeyDown (e);
  208910. else
  208911. peer->redirectKeyUp (e);
  208912. return;
  208913. }
  208914. }
  208915. }
  208916. NSArray* info = (NSArray*) [item representedObject];
  208917. owner->invoke ((int) [item tag],
  208918. (ApplicationCommandManager*) (pointer_sized_int)
  208919. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208920. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208921. }
  208922. }
  208923. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208924. {
  208925. if (JuceMainMenuHandler::instance != 0)
  208926. JuceMainMenuHandler::instance->updateMenus();
  208927. }
  208928. @end
  208929. BEGIN_JUCE_NAMESPACE
  208930. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208931. const PopupMenu* extraItems)
  208932. {
  208933. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208934. {
  208935. PopupMenu::MenuItemIterator iter (*extraItems);
  208936. while (iter.next())
  208937. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208938. [menu addItem: [NSMenuItem separatorItem]];
  208939. }
  208940. NSMenuItem* item;
  208941. // Services...
  208942. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208943. action: nil keyEquivalent: @""];
  208944. [menu addItem: item];
  208945. [item release];
  208946. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208947. [menu setSubmenu: servicesMenu forItem: item];
  208948. [NSApp setServicesMenu: servicesMenu];
  208949. [servicesMenu release];
  208950. [menu addItem: [NSMenuItem separatorItem]];
  208951. // Hide + Show stuff...
  208952. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208953. action: @selector (hide:) keyEquivalent: @"h"];
  208954. [item setTarget: NSApp];
  208955. [menu addItem: item];
  208956. [item release];
  208957. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208958. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208959. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208960. [item setTarget: NSApp];
  208961. [menu addItem: item];
  208962. [item release];
  208963. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208964. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208965. [item setTarget: NSApp];
  208966. [menu addItem: item];
  208967. [item release];
  208968. [menu addItem: [NSMenuItem separatorItem]];
  208969. // Quit item....
  208970. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208971. action: @selector (terminate:) keyEquivalent: @"q"];
  208972. [item setTarget: NSApp];
  208973. [menu addItem: item];
  208974. [item release];
  208975. return menu;
  208976. }
  208977. // Since our app has no NIB, this initialises a standard app menu...
  208978. static void rebuildMainMenu (const PopupMenu* extraItems)
  208979. {
  208980. // this can't be used in a plugin!
  208981. jassert (JUCEApplication::getInstance() != 0);
  208982. if (JUCEApplication::getInstance() != 0)
  208983. {
  208984. const ScopedAutoReleasePool pool;
  208985. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208986. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208987. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208988. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208989. [mainMenu setSubmenu: appMenu forItem: item];
  208990. [NSApp setMainMenu: mainMenu];
  208991. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208992. [appMenu release];
  208993. [mainMenu release];
  208994. }
  208995. }
  208996. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208997. const PopupMenu* extraAppleMenuItems)
  208998. {
  208999. if (getMacMainMenu() != newMenuBarModel)
  209000. {
  209001. const ScopedAutoReleasePool pool;
  209002. if (newMenuBarModel == 0)
  209003. {
  209004. delete JuceMainMenuHandler::instance;
  209005. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  209006. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  209007. extraAppleMenuItems = 0;
  209008. }
  209009. else
  209010. {
  209011. if (JuceMainMenuHandler::instance == 0)
  209012. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  209013. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  209014. }
  209015. }
  209016. rebuildMainMenu (extraAppleMenuItems);
  209017. if (newMenuBarModel != 0)
  209018. newMenuBarModel->menuItemsChanged();
  209019. }
  209020. MenuBarModel* MenuBarModel::getMacMainMenu()
  209021. {
  209022. return JuceMainMenuHandler::instance != 0
  209023. ? JuceMainMenuHandler::instance->currentModel : 0;
  209024. }
  209025. void initialiseMainMenu()
  209026. {
  209027. if (JUCEApplication::getInstance() != 0) // only needed in an app
  209028. rebuildMainMenu (0);
  209029. }
  209030. #endif
  209031. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  209032. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  209033. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209034. // compiled on its own).
  209035. #if JUCE_INCLUDED_FILE
  209036. #if JUCE_MAC
  209037. END_JUCE_NAMESPACE
  209038. using namespace JUCE_NAMESPACE;
  209039. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  209040. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  209041. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  209042. #else
  209043. @interface JuceFileChooserDelegate : NSObject
  209044. #endif
  209045. {
  209046. StringArray* filters;
  209047. }
  209048. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  209049. - (void) dealloc;
  209050. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  209051. @end
  209052. @implementation JuceFileChooserDelegate
  209053. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  209054. {
  209055. [super init];
  209056. filters = filters_;
  209057. return self;
  209058. }
  209059. - (void) dealloc
  209060. {
  209061. delete filters;
  209062. [super dealloc];
  209063. }
  209064. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  209065. {
  209066. const File f (nsStringToJuce (filename));
  209067. for (int i = filters->size(); --i >= 0;)
  209068. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  209069. return true;
  209070. return f.isDirectory();
  209071. }
  209072. @end
  209073. BEGIN_JUCE_NAMESPACE
  209074. void FileChooser::showPlatformDialog (Array<File>& results,
  209075. const String& title,
  209076. const File& currentFileOrDirectory,
  209077. const String& filter,
  209078. bool selectsDirectory,
  209079. bool selectsFiles,
  209080. bool isSaveDialogue,
  209081. bool warnAboutOverwritingExistingFiles,
  209082. bool selectMultipleFiles,
  209083. FilePreviewComponent* extraInfoComponent)
  209084. {
  209085. const ScopedAutoReleasePool pool;
  209086. StringArray* filters = new StringArray();
  209087. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  209088. filters->trim();
  209089. filters->removeEmptyStrings();
  209090. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  209091. [delegate autorelease];
  209092. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  209093. : [NSOpenPanel openPanel];
  209094. [panel setTitle: juceStringToNS (title)];
  209095. if (! isSaveDialogue)
  209096. {
  209097. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209098. [openPanel setCanChooseDirectories: selectsDirectory];
  209099. [openPanel setCanChooseFiles: selectsFiles];
  209100. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209101. }
  209102. [panel setDelegate: delegate];
  209103. if (isSaveDialogue || selectsDirectory)
  209104. [panel setCanCreateDirectories: YES];
  209105. String directory, filename;
  209106. if (currentFileOrDirectory.isDirectory())
  209107. {
  209108. directory = currentFileOrDirectory.getFullPathName();
  209109. }
  209110. else
  209111. {
  209112. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209113. filename = currentFileOrDirectory.getFileName();
  209114. }
  209115. if ([panel runModalForDirectory: juceStringToNS (directory)
  209116. file: juceStringToNS (filename)]
  209117. == NSOKButton)
  209118. {
  209119. if (isSaveDialogue)
  209120. {
  209121. results.add (File (nsStringToJuce ([panel filename])));
  209122. }
  209123. else
  209124. {
  209125. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209126. NSArray* urls = [openPanel filenames];
  209127. for (unsigned int i = 0; i < [urls count]; ++i)
  209128. {
  209129. NSString* f = [urls objectAtIndex: i];
  209130. results.add (File (nsStringToJuce (f)));
  209131. }
  209132. }
  209133. }
  209134. [panel setDelegate: nil];
  209135. }
  209136. #else
  209137. void FileChooser::showPlatformDialog (Array<File>& results,
  209138. const String& title,
  209139. const File& currentFileOrDirectory,
  209140. const String& filter,
  209141. bool selectsDirectory,
  209142. bool selectsFiles,
  209143. bool isSaveDialogue,
  209144. bool warnAboutOverwritingExistingFiles,
  209145. bool selectMultipleFiles,
  209146. FilePreviewComponent* extraInfoComponent)
  209147. {
  209148. const ScopedAutoReleasePool pool;
  209149. jassertfalse //xxx to do
  209150. }
  209151. #endif
  209152. #endif
  209153. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209154. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209155. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209156. // compiled on its own).
  209157. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209158. END_JUCE_NAMESPACE
  209159. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  209160. @interface NonInterceptingQTMovieView : QTMovieView
  209161. {
  209162. }
  209163. - (id) initWithFrame: (NSRect) frame;
  209164. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  209165. - (NSView*) hitTest: (NSPoint) p;
  209166. @end
  209167. @implementation NonInterceptingQTMovieView
  209168. - (id) initWithFrame: (NSRect) frame
  209169. {
  209170. self = [super initWithFrame: frame];
  209171. [self setNextResponder: [self superview]];
  209172. return self;
  209173. }
  209174. - (void) dealloc
  209175. {
  209176. [super dealloc];
  209177. }
  209178. - (NSView*) hitTest: (NSPoint) point
  209179. {
  209180. return [self isControllerVisible] ? [super hitTest: point] : nil;
  209181. }
  209182. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  209183. {
  209184. return YES;
  209185. }
  209186. @end
  209187. BEGIN_JUCE_NAMESPACE
  209188. #define theMovie (static_cast <QTMovie*> (movie))
  209189. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209190. : movie (0)
  209191. {
  209192. setOpaque (true);
  209193. setVisible (true);
  209194. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209195. setView (view);
  209196. [view release];
  209197. }
  209198. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209199. {
  209200. closeMovie();
  209201. setView (0);
  209202. }
  209203. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209204. {
  209205. return true;
  209206. }
  209207. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209208. {
  209209. // unfortunately, QTMovie objects can only be created on the main thread..
  209210. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209211. QTMovie* movie = 0;
  209212. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209213. if (fin != 0)
  209214. {
  209215. movieFile = fin->getFile();
  209216. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209217. error: nil];
  209218. }
  209219. else
  209220. {
  209221. MemoryBlock temp;
  209222. movieStream->readIntoMemoryBlock (temp);
  209223. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209224. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209225. {
  209226. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209227. length: temp.getSize()]
  209228. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209229. MIMEType: @""]
  209230. error: nil];
  209231. if (movie != 0)
  209232. break;
  209233. }
  209234. }
  209235. return movie;
  209236. }
  209237. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209238. const bool isControllerVisible_)
  209239. {
  209240. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209241. }
  209242. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209243. const bool controllerVisible_)
  209244. {
  209245. closeMovie();
  209246. if (getPeer() == 0)
  209247. {
  209248. // To open a movie, this component must be visible inside a functioning window, so that
  209249. // the QT control can be assigned to the window.
  209250. jassertfalse
  209251. return false;
  209252. }
  209253. movie = openMovieFromStream (movieStream, movieFile);
  209254. [theMovie retain];
  209255. QTMovieView* view = (QTMovieView*) getView();
  209256. [view setMovie: theMovie];
  209257. [view setControllerVisible: controllerVisible_];
  209258. setLooping (looping);
  209259. return movie != nil;
  209260. }
  209261. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209262. const bool isControllerVisible_)
  209263. {
  209264. // unfortunately, QTMovie objects can only be created on the main thread..
  209265. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209266. closeMovie();
  209267. if (getPeer() == 0)
  209268. {
  209269. // To open a movie, this component must be visible inside a functioning window, so that
  209270. // the QT control can be assigned to the window.
  209271. jassertfalse
  209272. return false;
  209273. }
  209274. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209275. NSError* err;
  209276. if ([QTMovie canInitWithURL: url])
  209277. movie = [QTMovie movieWithURL: url error: &err];
  209278. [theMovie retain];
  209279. QTMovieView* view = (QTMovieView*) getView();
  209280. [view setMovie: theMovie];
  209281. [view setControllerVisible: controllerVisible];
  209282. setLooping (looping);
  209283. return movie != nil;
  209284. }
  209285. void QuickTimeMovieComponent::closeMovie()
  209286. {
  209287. stop();
  209288. QTMovieView* view = (QTMovieView*) getView();
  209289. [view setMovie: nil];
  209290. [theMovie release];
  209291. movie = 0;
  209292. movieFile = File::nonexistent;
  209293. }
  209294. bool QuickTimeMovieComponent::isMovieOpen() const
  209295. {
  209296. return movie != nil;
  209297. }
  209298. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209299. {
  209300. return movieFile;
  209301. }
  209302. void QuickTimeMovieComponent::play()
  209303. {
  209304. [theMovie play];
  209305. }
  209306. void QuickTimeMovieComponent::stop()
  209307. {
  209308. [theMovie stop];
  209309. }
  209310. bool QuickTimeMovieComponent::isPlaying() const
  209311. {
  209312. return movie != 0 && [theMovie rate] != 0;
  209313. }
  209314. void QuickTimeMovieComponent::setPosition (const double seconds)
  209315. {
  209316. if (movie != 0)
  209317. {
  209318. QTTime t;
  209319. t.timeValue = (uint64) (100000.0 * seconds);
  209320. t.timeScale = 100000;
  209321. t.flags = 0;
  209322. [theMovie setCurrentTime: t];
  209323. }
  209324. }
  209325. double QuickTimeMovieComponent::getPosition() const
  209326. {
  209327. if (movie == 0)
  209328. return 0.0;
  209329. QTTime t = [theMovie currentTime];
  209330. return t.timeValue / (double) t.timeScale;
  209331. }
  209332. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209333. {
  209334. [theMovie setRate: newSpeed];
  209335. }
  209336. double QuickTimeMovieComponent::getMovieDuration() const
  209337. {
  209338. if (movie == 0)
  209339. return 0.0;
  209340. QTTime t = [theMovie duration];
  209341. return t.timeValue / (double) t.timeScale;
  209342. }
  209343. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209344. {
  209345. looping = shouldLoop;
  209346. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209347. forKey: QTMovieLoopsAttribute];
  209348. }
  209349. bool QuickTimeMovieComponent::isLooping() const
  209350. {
  209351. return looping;
  209352. }
  209353. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209354. {
  209355. [theMovie setVolume: newVolume];
  209356. }
  209357. float QuickTimeMovieComponent::getMovieVolume() const
  209358. {
  209359. return movie != 0 ? [theMovie volume] : 0.0f;
  209360. }
  209361. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209362. {
  209363. width = 0;
  209364. height = 0;
  209365. if (movie != 0)
  209366. {
  209367. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209368. width = (int) s.width;
  209369. height = (int) s.height;
  209370. }
  209371. }
  209372. void QuickTimeMovieComponent::paint (Graphics& g)
  209373. {
  209374. if (movie == 0)
  209375. g.fillAll (Colours::black);
  209376. }
  209377. bool QuickTimeMovieComponent::isControllerVisible() const
  209378. {
  209379. return controllerVisible;
  209380. }
  209381. void QuickTimeMovieComponent::goToStart()
  209382. {
  209383. setPosition (0.0);
  209384. }
  209385. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209386. const RectanglePlacement& placement)
  209387. {
  209388. int normalWidth, normalHeight;
  209389. getMovieNormalSize (normalWidth, normalHeight);
  209390. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209391. {
  209392. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209393. placement.applyTo (x, y, w, h,
  209394. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209395. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209396. if (w > 0 && h > 0)
  209397. {
  209398. setBounds (roundToInt (x), roundToInt (y),
  209399. roundToInt (w), roundToInt (h));
  209400. }
  209401. }
  209402. else
  209403. {
  209404. setBounds (spaceToFitWithin);
  209405. }
  209406. }
  209407. #if ! (JUCE_MAC && JUCE_64BIT)
  209408. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209409. {
  209410. if (movieStream == 0)
  209411. return false;
  209412. File file;
  209413. QTMovie* movie = openMovieFromStream (movieStream, file);
  209414. if (movie != nil)
  209415. result = [movie quickTimeMovie];
  209416. return movie != nil;
  209417. }
  209418. #endif
  209419. #endif
  209420. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209421. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209422. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209423. // compiled on its own).
  209424. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209425. const int kilobytesPerSecond1x = 176;
  209426. END_JUCE_NAMESPACE
  209427. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209428. @interface OpenDiskDevice : NSObject
  209429. {
  209430. @public
  209431. DRDevice* device;
  209432. NSMutableArray* tracks;
  209433. bool underrunProtection;
  209434. }
  209435. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209436. - (void) dealloc;
  209437. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209438. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209439. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209440. @end
  209441. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209442. @interface AudioTrackProducer : NSObject
  209443. {
  209444. JUCE_NAMESPACE::AudioSource* source;
  209445. int readPosition, lengthInFrames;
  209446. }
  209447. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209448. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209449. - (void) dealloc;
  209450. - (void) setupTrackProperties: (DRTrack*) track;
  209451. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209452. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209453. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209454. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209455. toMedia:(NSDictionary*)mediaInfo;
  209456. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209457. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209458. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209459. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209460. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209461. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209462. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209463. ioFlags:(uint32_t*)flags;
  209464. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209465. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209466. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209467. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209468. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209469. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209470. ioFlags:(uint32_t*)flags;
  209471. @end
  209472. @implementation OpenDiskDevice
  209473. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209474. {
  209475. [super init];
  209476. device = device_;
  209477. tracks = [[NSMutableArray alloc] init];
  209478. underrunProtection = true;
  209479. return self;
  209480. }
  209481. - (void) dealloc
  209482. {
  209483. [tracks release];
  209484. [super dealloc];
  209485. }
  209486. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209487. {
  209488. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209489. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209490. [p setupTrackProperties: t];
  209491. [tracks addObject: t];
  209492. [t release];
  209493. [p release];
  209494. }
  209495. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209496. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209497. {
  209498. DRBurn* burn = [DRBurn burnForDevice: device];
  209499. if (! [device acquireExclusiveAccess])
  209500. {
  209501. *error = "Couldn't open or write to the CD device";
  209502. return;
  209503. }
  209504. [device acquireMediaReservation];
  209505. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209506. [d autorelease];
  209507. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209508. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209509. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209510. if (burnSpeed > 0)
  209511. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209512. if (! underrunProtection)
  209513. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209514. [burn setProperties: d];
  209515. [burn writeLayout: tracks];
  209516. for (;;)
  209517. {
  209518. JUCE_NAMESPACE::Thread::sleep (300);
  209519. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209520. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209521. {
  209522. [burn abort];
  209523. *error = "User cancelled the write operation";
  209524. break;
  209525. }
  209526. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209527. {
  209528. *error = "Write operation failed";
  209529. break;
  209530. }
  209531. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209532. {
  209533. break;
  209534. }
  209535. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209536. objectForKey: DRErrorStatusErrorStringKey];
  209537. if ([err length] > 0)
  209538. {
  209539. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209540. break;
  209541. }
  209542. }
  209543. [device releaseMediaReservation];
  209544. [device releaseExclusiveAccess];
  209545. }
  209546. @end
  209547. @implementation AudioTrackProducer
  209548. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209549. {
  209550. lengthInFrames = lengthInFrames_;
  209551. readPosition = 0;
  209552. return self;
  209553. }
  209554. - (void) setupTrackProperties: (DRTrack*) track
  209555. {
  209556. NSMutableDictionary* p = [[track properties] mutableCopy];
  209557. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209558. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209559. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209560. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209561. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209562. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209563. [track setProperties: p];
  209564. [p release];
  209565. }
  209566. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209567. {
  209568. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209569. if (s != nil)
  209570. s->source = source_;
  209571. return s;
  209572. }
  209573. - (void) dealloc
  209574. {
  209575. if (source != 0)
  209576. {
  209577. source->releaseResources();
  209578. delete source;
  209579. }
  209580. [super dealloc];
  209581. }
  209582. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209583. {
  209584. }
  209585. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209586. {
  209587. return true;
  209588. }
  209589. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209590. {
  209591. return lengthInFrames;
  209592. }
  209593. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209594. toMedia: (NSDictionary*) mediaInfo
  209595. {
  209596. if (source != 0)
  209597. source->prepareToPlay (44100 / 75, 44100);
  209598. readPosition = 0;
  209599. return true;
  209600. }
  209601. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209602. {
  209603. if (source != 0)
  209604. source->prepareToPlay (44100 / 75, 44100);
  209605. return true;
  209606. }
  209607. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209608. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209609. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209610. {
  209611. if (source != 0)
  209612. {
  209613. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209614. if (numSamples > 0)
  209615. {
  209616. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209617. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209618. info.buffer = &tempBuffer;
  209619. info.startSample = 0;
  209620. info.numSamples = numSamples;
  209621. source->getNextAudioBlock (info);
  209622. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209623. buffer, numSamples, 4);
  209624. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209625. buffer + 2, numSamples, 4);
  209626. readPosition += numSamples;
  209627. }
  209628. return numSamples * 4;
  209629. }
  209630. return 0;
  209631. }
  209632. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209633. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209634. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209635. ioFlags: (uint32_t*) flags
  209636. {
  209637. zeromem (buffer, bufferLength);
  209638. return bufferLength;
  209639. }
  209640. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209641. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209642. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209643. {
  209644. return true;
  209645. }
  209646. @end
  209647. BEGIN_JUCE_NAMESPACE
  209648. class AudioCDBurner::Pimpl : public Timer
  209649. {
  209650. public:
  209651. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209652. : device (0), owner (owner_)
  209653. {
  209654. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209655. if (dev != 0)
  209656. {
  209657. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209658. lastState = getDiskState();
  209659. startTimer (1000);
  209660. }
  209661. }
  209662. ~Pimpl()
  209663. {
  209664. stopTimer();
  209665. [device release];
  209666. }
  209667. void timerCallback()
  209668. {
  209669. const DiskState state = getDiskState();
  209670. if (state != lastState)
  209671. {
  209672. lastState = state;
  209673. owner.sendChangeMessage (&owner);
  209674. }
  209675. }
  209676. DiskState getDiskState() const
  209677. {
  209678. if ([device->device isValid])
  209679. {
  209680. NSDictionary* status = [device->device status];
  209681. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209682. if ([state isEqualTo: DRDeviceMediaStateNone])
  209683. {
  209684. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209685. return trayOpen;
  209686. return noDisc;
  209687. }
  209688. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209689. {
  209690. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209691. return writableDiskPresent;
  209692. else
  209693. return readOnlyDiskPresent;
  209694. }
  209695. }
  209696. return unknown;
  209697. }
  209698. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209699. const Array<int> getAvailableWriteSpeeds() const
  209700. {
  209701. Array<int> results;
  209702. if ([device->device isValid])
  209703. {
  209704. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209705. for (unsigned int i = 0; i < [speeds count]; ++i)
  209706. {
  209707. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209708. results.add (kbPerSec / kilobytesPerSecond1x);
  209709. }
  209710. }
  209711. return results;
  209712. }
  209713. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209714. {
  209715. if ([device->device isValid])
  209716. {
  209717. device->underrunProtection = shouldBeEnabled;
  209718. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209719. }
  209720. return false;
  209721. }
  209722. int getNumAvailableAudioBlocks() const
  209723. {
  209724. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209725. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209726. }
  209727. OpenDiskDevice* device;
  209728. private:
  209729. DiskState lastState;
  209730. AudioCDBurner& owner;
  209731. };
  209732. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209733. {
  209734. pimpl = new Pimpl (*this, deviceIndex);
  209735. }
  209736. AudioCDBurner::~AudioCDBurner()
  209737. {
  209738. }
  209739. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209740. {
  209741. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209742. if (b->pimpl->device == 0)
  209743. b = 0;
  209744. return b.release();
  209745. }
  209746. static NSArray* findDiskBurnerDevices()
  209747. {
  209748. NSMutableArray* results = [NSMutableArray array];
  209749. NSArray* devs = [DRDevice devices];
  209750. if (devs != 0)
  209751. {
  209752. int num = [devs count];
  209753. int i;
  209754. for (i = 0; i < num; ++i)
  209755. {
  209756. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209757. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209758. if (name != nil)
  209759. [results addObject: name];
  209760. }
  209761. }
  209762. return results;
  209763. }
  209764. const StringArray AudioCDBurner::findAvailableDevices()
  209765. {
  209766. NSArray* names = findDiskBurnerDevices();
  209767. StringArray s;
  209768. for (unsigned int i = 0; i < [names count]; ++i)
  209769. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209770. return s;
  209771. }
  209772. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209773. {
  209774. return pimpl->getDiskState();
  209775. }
  209776. bool AudioCDBurner::isDiskPresent() const
  209777. {
  209778. return getDiskState() == writableDiskPresent;
  209779. }
  209780. bool AudioCDBurner::openTray()
  209781. {
  209782. return pimpl->openTray();
  209783. }
  209784. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209785. {
  209786. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209787. DiskState oldState = getDiskState();
  209788. DiskState newState = oldState;
  209789. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209790. {
  209791. newState = getDiskState();
  209792. Thread::sleep (100);
  209793. }
  209794. return newState;
  209795. }
  209796. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209797. {
  209798. return pimpl->getAvailableWriteSpeeds();
  209799. }
  209800. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209801. {
  209802. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209803. }
  209804. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209805. {
  209806. return pimpl->getNumAvailableAudioBlocks();
  209807. }
  209808. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209809. {
  209810. if ([pimpl->device->device isValid])
  209811. {
  209812. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209813. return true;
  209814. }
  209815. return false;
  209816. }
  209817. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209818. bool ejectDiscAfterwards,
  209819. bool performFakeBurnForTesting,
  209820. int writeSpeed)
  209821. {
  209822. String error ("Couldn't open or write to the CD device");
  209823. if ([pimpl->device->device isValid])
  209824. {
  209825. error = String::empty;
  209826. [pimpl->device burn: listener
  209827. errorString: &error
  209828. ejectAfterwards: ejectDiscAfterwards
  209829. isFake: performFakeBurnForTesting
  209830. speed: writeSpeed];
  209831. }
  209832. return error;
  209833. }
  209834. #endif
  209835. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209836. void AudioCDReader::ejectDisk()
  209837. {
  209838. const ScopedAutoReleasePool p;
  209839. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209840. }
  209841. #endif
  209842. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209843. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209844. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209845. // compiled on its own).
  209846. #if JUCE_INCLUDED_FILE
  209847. class AppDelegateRedirector
  209848. {
  209849. public:
  209850. AppDelegateRedirector()
  209851. {
  209852. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209853. runLoop = CFRunLoopGetMain();
  209854. #else
  209855. runLoop = CFRunLoopGetCurrent();
  209856. #endif
  209857. CFRunLoopSourceContext sourceContext;
  209858. zerostruct (sourceContext);
  209859. sourceContext.info = this;
  209860. sourceContext.perform = runLoopSourceCallback;
  209861. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209862. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209863. }
  209864. virtual ~AppDelegateRedirector()
  209865. {
  209866. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209867. CFRunLoopSourceInvalidate (runLoopSource);
  209868. CFRelease (runLoopSource);
  209869. while (messages.size() > 0)
  209870. delete static_cast <Message*> (messages.remove(0));
  209871. }
  209872. virtual NSApplicationTerminateReply shouldTerminate()
  209873. {
  209874. if (JUCEApplication::getInstance() != 0)
  209875. {
  209876. JUCEApplication::getInstance()->systemRequestedQuit();
  209877. return NSTerminateCancel;
  209878. }
  209879. return NSTerminateNow;
  209880. }
  209881. virtual BOOL openFile (const NSString* filename)
  209882. {
  209883. if (JUCEApplication::getInstance() != 0)
  209884. {
  209885. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209886. return YES;
  209887. }
  209888. return NO;
  209889. }
  209890. virtual void openFiles (NSArray* filenames)
  209891. {
  209892. StringArray files;
  209893. for (unsigned int i = 0; i < [filenames count]; ++i)
  209894. {
  209895. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209896. if (filename.containsChar (' '))
  209897. filename = filename.quoted('"');
  209898. files.add (filename);
  209899. }
  209900. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209901. {
  209902. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (" "));
  209903. }
  209904. }
  209905. virtual void focusChanged()
  209906. {
  209907. juce_HandleProcessFocusChange();
  209908. }
  209909. struct CallbackMessagePayload
  209910. {
  209911. MessageCallbackFunction* function;
  209912. void* parameter;
  209913. void* volatile result;
  209914. bool volatile hasBeenExecuted;
  209915. };
  209916. virtual void performCallback (CallbackMessagePayload* pl)
  209917. {
  209918. pl->result = (*pl->function) (pl->parameter);
  209919. pl->hasBeenExecuted = true;
  209920. }
  209921. virtual void deleteSelf()
  209922. {
  209923. delete this;
  209924. }
  209925. void postMessage (void* m)
  209926. {
  209927. messages.add (m);
  209928. CFRunLoopSourceSignal (runLoopSource);
  209929. CFRunLoopWakeUp (runLoop);
  209930. }
  209931. private:
  209932. CFRunLoopRef runLoop;
  209933. CFRunLoopSourceRef runLoopSource;
  209934. Array <void*, CriticalSection> messages;
  209935. void runLoopCallback()
  209936. {
  209937. int numDispatched = 0;
  209938. do
  209939. {
  209940. void* const nextMessage = messages.remove (0);
  209941. if (nextMessage == 0)
  209942. return;
  209943. const ScopedAutoReleasePool pool;
  209944. MessageManager::getInstance()->deliverMessage (nextMessage);
  209945. } while (++numDispatched <= 4);
  209946. CFRunLoopSourceSignal (runLoopSource);
  209947. CFRunLoopWakeUp (runLoop);
  209948. }
  209949. static void runLoopSourceCallback (void* info)
  209950. {
  209951. static_cast <AppDelegateRedirector*> (info)->runLoopCallback();
  209952. }
  209953. };
  209954. END_JUCE_NAMESPACE
  209955. using namespace JUCE_NAMESPACE;
  209956. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209957. @interface JuceAppDelegate : NSObject
  209958. {
  209959. @private
  209960. id oldDelegate;
  209961. @public
  209962. AppDelegateRedirector* redirector;
  209963. }
  209964. - (JuceAppDelegate*) init;
  209965. - (void) dealloc;
  209966. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209967. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209968. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209969. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209970. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209971. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209972. - (void) performCallback: (id) info;
  209973. - (void) dummyMethod;
  209974. @end
  209975. @implementation JuceAppDelegate
  209976. - (JuceAppDelegate*) init
  209977. {
  209978. [super init];
  209979. redirector = new AppDelegateRedirector();
  209980. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209981. if (JUCEApplication::getInstance() != 0)
  209982. {
  209983. oldDelegate = [NSApp delegate];
  209984. [NSApp setDelegate: self];
  209985. }
  209986. else
  209987. {
  209988. oldDelegate = 0;
  209989. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209990. name: NSApplicationDidResignActiveNotification object: NSApp];
  209991. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209992. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209993. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209994. name: NSApplicationWillUnhideNotification object: NSApp];
  209995. }
  209996. return self;
  209997. }
  209998. - (void) dealloc
  209999. {
  210000. if (oldDelegate != 0)
  210001. [NSApp setDelegate: oldDelegate];
  210002. redirector->deleteSelf();
  210003. [super dealloc];
  210004. }
  210005. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  210006. {
  210007. return redirector->shouldTerminate();
  210008. }
  210009. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  210010. {
  210011. return redirector->openFile (filename);
  210012. }
  210013. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  210014. {
  210015. return redirector->openFiles (filenames);
  210016. }
  210017. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  210018. {
  210019. redirector->focusChanged();
  210020. }
  210021. - (void) applicationDidResignActive: (NSNotification*) aNotification
  210022. {
  210023. redirector->focusChanged();
  210024. }
  210025. - (void) applicationWillUnhide: (NSNotification*) aNotification
  210026. {
  210027. redirector->focusChanged();
  210028. }
  210029. - (void) performCallback: (id) info
  210030. {
  210031. if ([info isKindOfClass: [NSData class]])
  210032. {
  210033. AppDelegateRedirector::CallbackMessagePayload* pl
  210034. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  210035. if (pl != 0)
  210036. redirector->performCallback (pl);
  210037. }
  210038. else
  210039. {
  210040. jassertfalse // should never get here!
  210041. }
  210042. }
  210043. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  210044. @end
  210045. BEGIN_JUCE_NAMESPACE
  210046. static JuceAppDelegate* juceAppDelegate = 0;
  210047. void MessageManager::runDispatchLoop()
  210048. {
  210049. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  210050. {
  210051. const ScopedAutoReleasePool pool;
  210052. // must only be called by the message thread!
  210053. jassert (isThisTheMessageThread());
  210054. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  210055. @try
  210056. {
  210057. [NSApp run];
  210058. }
  210059. @catch (NSException* e)
  210060. {
  210061. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  210062. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  210063. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  210064. }
  210065. @finally
  210066. {
  210067. }
  210068. #else
  210069. [NSApp run];
  210070. #endif
  210071. }
  210072. }
  210073. void MessageManager::stopDispatchLoop()
  210074. {
  210075. quitMessagePosted = true;
  210076. [NSApp stop: nil];
  210077. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  210078. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  210079. }
  210080. static bool isEventBlockedByModalComps (NSEvent* e)
  210081. {
  210082. if (Component::getNumCurrentlyModalComponents() == 0)
  210083. return false;
  210084. NSWindow* const w = [e window];
  210085. if (w == 0 || [w worksWhenModal])
  210086. return false;
  210087. bool isKey = false, isInputAttempt = false;
  210088. switch ([e type])
  210089. {
  210090. case NSKeyDown:
  210091. case NSKeyUp:
  210092. isKey = isInputAttempt = true;
  210093. break;
  210094. case NSLeftMouseDown:
  210095. case NSRightMouseDown:
  210096. case NSOtherMouseDown:
  210097. isInputAttempt = true;
  210098. break;
  210099. case NSLeftMouseDragged:
  210100. case NSRightMouseDragged:
  210101. case NSLeftMouseUp:
  210102. case NSRightMouseUp:
  210103. case NSOtherMouseUp:
  210104. case NSOtherMouseDragged:
  210105. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  210106. return false;
  210107. break;
  210108. case NSMouseMoved:
  210109. case NSMouseEntered:
  210110. case NSMouseExited:
  210111. case NSCursorUpdate:
  210112. case NSScrollWheel:
  210113. case NSTabletPoint:
  210114. case NSTabletProximity:
  210115. break;
  210116. default:
  210117. return false;
  210118. }
  210119. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210120. {
  210121. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210122. NSView* const compView = (NSView*) peer->getNativeHandle();
  210123. if ([compView window] == w)
  210124. {
  210125. if (isKey)
  210126. {
  210127. if (compView == [w firstResponder])
  210128. return false;
  210129. }
  210130. else
  210131. {
  210132. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210133. [compView bounds]))
  210134. return false;
  210135. }
  210136. }
  210137. }
  210138. if (isInputAttempt)
  210139. {
  210140. if (! [NSApp isActive])
  210141. [NSApp activateIgnoringOtherApps: YES];
  210142. Component* const modal = Component::getCurrentlyModalComponent (0);
  210143. if (modal != 0)
  210144. modal->inputAttemptWhenModal();
  210145. }
  210146. return true;
  210147. }
  210148. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210149. {
  210150. const ScopedAutoReleasePool pool;
  210151. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210152. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210153. while (! quitMessagePosted)
  210154. {
  210155. const ScopedAutoReleasePool pool2;
  210156. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210157. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210158. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210159. inMode: NSDefaultRunLoopMode
  210160. dequeue: YES];
  210161. if (e != 0 && ! isEventBlockedByModalComps (e))
  210162. [NSApp sendEvent: e];
  210163. if (Time::getMillisecondCounter() >= endTime)
  210164. break;
  210165. }
  210166. return ! quitMessagePosted;
  210167. }
  210168. void MessageManager::doPlatformSpecificInitialisation()
  210169. {
  210170. if (juceAppDelegate == 0)
  210171. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210172. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210173. // correctly (needed prior to 10.5)
  210174. if (! [NSThread isMultiThreaded])
  210175. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210176. toTarget: juceAppDelegate
  210177. withObject: nil];
  210178. initialiseMainMenu();
  210179. }
  210180. void MessageManager::doPlatformSpecificShutdown()
  210181. {
  210182. if (juceAppDelegate != 0)
  210183. {
  210184. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210185. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210186. [juceAppDelegate release];
  210187. juceAppDelegate = 0;
  210188. }
  210189. }
  210190. bool juce_postMessageToSystemQueue (void* message)
  210191. {
  210192. juceAppDelegate->redirector->postMessage (message);
  210193. return true;
  210194. }
  210195. void MessageManager::broadcastMessage (const String& value) throw()
  210196. {
  210197. }
  210198. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210199. void* data)
  210200. {
  210201. if (isThisTheMessageThread())
  210202. {
  210203. return (*callback) (data);
  210204. }
  210205. else
  210206. {
  210207. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210208. // deadlock because the message manager is blocked from running, so can never
  210209. // call your function..
  210210. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210211. const ScopedAutoReleasePool pool;
  210212. AppDelegateRedirector::CallbackMessagePayload cmp;
  210213. cmp.function = callback;
  210214. cmp.parameter = data;
  210215. cmp.result = 0;
  210216. cmp.hasBeenExecuted = false;
  210217. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210218. withObject: [NSData dataWithBytesNoCopy: &cmp
  210219. length: sizeof (cmp)
  210220. freeWhenDone: NO]
  210221. waitUntilDone: YES];
  210222. return cmp.result;
  210223. }
  210224. }
  210225. #endif
  210226. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210227. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210228. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210229. // compiled on its own).
  210230. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210231. #if JUCE_MAC
  210232. END_JUCE_NAMESPACE
  210233. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210234. @interface DownloadClickDetector : NSObject
  210235. {
  210236. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210237. }
  210238. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210239. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210240. request: (NSURLRequest*) request
  210241. frame: (WebFrame*) frame
  210242. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210243. @end
  210244. @implementation DownloadClickDetector
  210245. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210246. {
  210247. [super init];
  210248. ownerComponent = ownerComponent_;
  210249. return self;
  210250. }
  210251. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210252. request: (NSURLRequest*) request
  210253. frame: (WebFrame*) frame
  210254. decisionListener: (id <WebPolicyDecisionListener>) listener
  210255. {
  210256. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210257. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210258. [listener use];
  210259. else
  210260. [listener ignore];
  210261. }
  210262. @end
  210263. BEGIN_JUCE_NAMESPACE
  210264. class WebBrowserComponentInternal : public NSViewComponent
  210265. {
  210266. public:
  210267. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210268. {
  210269. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210270. frameName: @""
  210271. groupName: @""];
  210272. setView (webView);
  210273. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210274. [webView setPolicyDelegate: clickListener];
  210275. }
  210276. ~WebBrowserComponentInternal()
  210277. {
  210278. [webView setPolicyDelegate: nil];
  210279. [clickListener release];
  210280. setView (0);
  210281. }
  210282. void goToURL (const String& url,
  210283. const StringArray* headers,
  210284. const MemoryBlock* postData)
  210285. {
  210286. NSMutableURLRequest* r
  210287. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210288. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210289. timeoutInterval: 30.0];
  210290. if (postData != 0 && postData->getSize() > 0)
  210291. {
  210292. [r setHTTPMethod: @"POST"];
  210293. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210294. length: postData->getSize()]];
  210295. }
  210296. if (headers != 0)
  210297. {
  210298. for (int i = 0; i < headers->size(); ++i)
  210299. {
  210300. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  210301. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  210302. [r setValue: juceStringToNS (headerValue)
  210303. forHTTPHeaderField: juceStringToNS (headerName)];
  210304. }
  210305. }
  210306. stop();
  210307. [[webView mainFrame] loadRequest: r];
  210308. }
  210309. void goBack()
  210310. {
  210311. [webView goBack];
  210312. }
  210313. void goForward()
  210314. {
  210315. [webView goForward];
  210316. }
  210317. void stop()
  210318. {
  210319. [webView stopLoading: nil];
  210320. }
  210321. void refresh()
  210322. {
  210323. [webView reload: nil];
  210324. }
  210325. private:
  210326. WebView* webView;
  210327. DownloadClickDetector* clickListener;
  210328. };
  210329. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210330. : browser (0),
  210331. blankPageShown (false),
  210332. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210333. {
  210334. setOpaque (true);
  210335. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210336. }
  210337. WebBrowserComponent::~WebBrowserComponent()
  210338. {
  210339. deleteAndZero (browser);
  210340. }
  210341. void WebBrowserComponent::goToURL (const String& url,
  210342. const StringArray* headers,
  210343. const MemoryBlock* postData)
  210344. {
  210345. lastURL = url;
  210346. lastHeaders.clear();
  210347. if (headers != 0)
  210348. lastHeaders = *headers;
  210349. lastPostData.setSize (0);
  210350. if (postData != 0)
  210351. lastPostData = *postData;
  210352. blankPageShown = false;
  210353. browser->goToURL (url, headers, postData);
  210354. }
  210355. void WebBrowserComponent::stop()
  210356. {
  210357. browser->stop();
  210358. }
  210359. void WebBrowserComponent::goBack()
  210360. {
  210361. lastURL = String::empty;
  210362. blankPageShown = false;
  210363. browser->goBack();
  210364. }
  210365. void WebBrowserComponent::goForward()
  210366. {
  210367. lastURL = String::empty;
  210368. browser->goForward();
  210369. }
  210370. void WebBrowserComponent::refresh()
  210371. {
  210372. browser->refresh();
  210373. }
  210374. void WebBrowserComponent::paint (Graphics& g)
  210375. {
  210376. }
  210377. void WebBrowserComponent::checkWindowAssociation()
  210378. {
  210379. if (isShowing())
  210380. {
  210381. if (blankPageShown)
  210382. goBack();
  210383. }
  210384. else
  210385. {
  210386. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210387. {
  210388. // when the component becomes invisible, some stuff like flash
  210389. // carries on playing audio, so we need to force it onto a blank
  210390. // page to avoid this, (and send it back when it's made visible again).
  210391. blankPageShown = true;
  210392. browser->goToURL ("about:blank", 0, 0);
  210393. }
  210394. }
  210395. }
  210396. void WebBrowserComponent::reloadLastURL()
  210397. {
  210398. if (lastURL.isNotEmpty())
  210399. {
  210400. goToURL (lastURL, &lastHeaders, &lastPostData);
  210401. lastURL = String::empty;
  210402. }
  210403. }
  210404. void WebBrowserComponent::parentHierarchyChanged()
  210405. {
  210406. checkWindowAssociation();
  210407. }
  210408. void WebBrowserComponent::resized()
  210409. {
  210410. browser->setSize (getWidth(), getHeight());
  210411. }
  210412. void WebBrowserComponent::visibilityChanged()
  210413. {
  210414. checkWindowAssociation();
  210415. }
  210416. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210417. {
  210418. return true;
  210419. }
  210420. #else
  210421. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210422. {
  210423. }
  210424. WebBrowserComponent::~WebBrowserComponent()
  210425. {
  210426. }
  210427. void WebBrowserComponent::goToURL (const String& url,
  210428. const StringArray* headers,
  210429. const MemoryBlock* postData)
  210430. {
  210431. }
  210432. void WebBrowserComponent::stop()
  210433. {
  210434. }
  210435. void WebBrowserComponent::goBack()
  210436. {
  210437. }
  210438. void WebBrowserComponent::goForward()
  210439. {
  210440. }
  210441. void WebBrowserComponent::refresh()
  210442. {
  210443. }
  210444. void WebBrowserComponent::paint (Graphics& g)
  210445. {
  210446. }
  210447. void WebBrowserComponent::checkWindowAssociation()
  210448. {
  210449. }
  210450. void WebBrowserComponent::reloadLastURL()
  210451. {
  210452. }
  210453. void WebBrowserComponent::parentHierarchyChanged()
  210454. {
  210455. }
  210456. void WebBrowserComponent::resized()
  210457. {
  210458. }
  210459. void WebBrowserComponent::visibilityChanged()
  210460. {
  210461. }
  210462. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210463. {
  210464. return true;
  210465. }
  210466. #endif
  210467. #endif
  210468. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210469. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210470. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210471. // compiled on its own).
  210472. #if JUCE_INCLUDED_FILE
  210473. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210474. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210475. #endif
  210476. #undef log
  210477. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210478. #define log(a) Logger::writeToLog (a)
  210479. #else
  210480. #define log(a)
  210481. #endif
  210482. #undef OK
  210483. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210484. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210485. {
  210486. if (err == noErr)
  210487. return true;
  210488. Logger::writeToLog ("CoreAudio error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  210489. jassertfalse
  210490. return false;
  210491. }
  210492. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210493. #else
  210494. #define OK(a) (a == noErr)
  210495. #endif
  210496. class CoreAudioInternal : public Timer
  210497. {
  210498. public:
  210499. CoreAudioInternal (AudioDeviceID id)
  210500. : inputLatency (0),
  210501. outputLatency (0),
  210502. callback (0),
  210503. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210504. audioProcID (0),
  210505. #endif
  210506. inputDevice (0),
  210507. isSlaveDevice (false),
  210508. deviceID (id),
  210509. started (false),
  210510. sampleRate (0),
  210511. bufferSize (512),
  210512. numInputChans (0),
  210513. numOutputChans (0),
  210514. callbacksAllowed (true),
  210515. numInputChannelInfos (0),
  210516. numOutputChannelInfos (0)
  210517. {
  210518. jassert (deviceID != 0);
  210519. updateDetailsFromDevice();
  210520. AudioObjectPropertyAddress pa;
  210521. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210522. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210523. pa.mElement = kAudioObjectPropertyElementWildcard;
  210524. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210525. }
  210526. ~CoreAudioInternal()
  210527. {
  210528. AudioObjectPropertyAddress pa;
  210529. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210530. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210531. pa.mElement = kAudioObjectPropertyElementWildcard;
  210532. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210533. stop (false);
  210534. delete inputDevice;
  210535. }
  210536. void allocateTempBuffers()
  210537. {
  210538. const int tempBufSize = bufferSize + 4;
  210539. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210540. tempInputBuffers.calloc (numInputChans + 2);
  210541. tempOutputBuffers.calloc (numOutputChans + 2);
  210542. int i, count = 0;
  210543. for (i = 0; i < numInputChans; ++i)
  210544. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210545. for (i = 0; i < numOutputChans; ++i)
  210546. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210547. }
  210548. // returns the number of actual available channels
  210549. void fillInChannelInfo (const bool input)
  210550. {
  210551. int chanNum = 0;
  210552. UInt32 size;
  210553. AudioObjectPropertyAddress pa;
  210554. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210555. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210556. pa.mElement = kAudioObjectPropertyElementMaster;
  210557. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210558. {
  210559. HeapBlock <AudioBufferList> bufList;
  210560. bufList.calloc (size, 1);
  210561. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210562. {
  210563. const int numStreams = bufList->mNumberBuffers;
  210564. for (int i = 0; i < numStreams; ++i)
  210565. {
  210566. const AudioBuffer& b = bufList->mBuffers[i];
  210567. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210568. {
  210569. String name;
  210570. {
  210571. char channelName [256];
  210572. zerostruct (channelName);
  210573. UInt32 nameSize = sizeof (channelName);
  210574. UInt32 channelNum = chanNum + 1;
  210575. pa.mSelector = kAudioDevicePropertyChannelName;
  210576. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210577. name = String::fromUTF8 (channelName, nameSize);
  210578. }
  210579. if (input)
  210580. {
  210581. if (activeInputChans[chanNum])
  210582. {
  210583. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210584. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210585. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210586. ++numInputChannelInfos;
  210587. }
  210588. if (name.isEmpty())
  210589. name << "Input " << (chanNum + 1);
  210590. inChanNames.add (name);
  210591. }
  210592. else
  210593. {
  210594. if (activeOutputChans[chanNum])
  210595. {
  210596. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210597. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210598. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210599. ++numOutputChannelInfos;
  210600. }
  210601. if (name.isEmpty())
  210602. name << "Output " << (chanNum + 1);
  210603. outChanNames.add (name);
  210604. }
  210605. ++chanNum;
  210606. }
  210607. }
  210608. }
  210609. }
  210610. }
  210611. void updateDetailsFromDevice()
  210612. {
  210613. stopTimer();
  210614. if (deviceID == 0)
  210615. return;
  210616. const ScopedLock sl (callbackLock);
  210617. Float64 sr;
  210618. UInt32 size = sizeof (Float64);
  210619. AudioObjectPropertyAddress pa;
  210620. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210621. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210622. pa.mElement = kAudioObjectPropertyElementMaster;
  210623. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210624. sampleRate = sr;
  210625. UInt32 framesPerBuf;
  210626. size = sizeof (framesPerBuf);
  210627. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210628. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210629. {
  210630. bufferSize = framesPerBuf;
  210631. allocateTempBuffers();
  210632. }
  210633. bufferSizes.clear();
  210634. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210635. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210636. {
  210637. HeapBlock <AudioValueRange> ranges;
  210638. ranges.calloc (size, 1);
  210639. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210640. {
  210641. bufferSizes.add ((int) ranges[0].mMinimum);
  210642. for (int i = 32; i < 2048; i += 32)
  210643. {
  210644. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210645. {
  210646. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210647. {
  210648. bufferSizes.addIfNotAlreadyThere (i);
  210649. break;
  210650. }
  210651. }
  210652. }
  210653. if (bufferSize > 0)
  210654. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210655. }
  210656. }
  210657. if (bufferSizes.size() == 0 && bufferSize > 0)
  210658. bufferSizes.add (bufferSize);
  210659. sampleRates.clear();
  210660. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210661. String rates;
  210662. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210663. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210664. {
  210665. HeapBlock <AudioValueRange> ranges;
  210666. ranges.calloc (size, 1);
  210667. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210668. {
  210669. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210670. {
  210671. bool ok = false;
  210672. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210673. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210674. ok = true;
  210675. if (ok)
  210676. {
  210677. sampleRates.add (possibleRates[i]);
  210678. rates << possibleRates[i] << ' ';
  210679. }
  210680. }
  210681. }
  210682. }
  210683. if (sampleRates.size() == 0 && sampleRate > 0)
  210684. {
  210685. sampleRates.add (sampleRate);
  210686. rates << sampleRate;
  210687. }
  210688. log ("sr: " + rates);
  210689. inputLatency = 0;
  210690. outputLatency = 0;
  210691. UInt32 lat;
  210692. size = sizeof (lat);
  210693. pa.mSelector = kAudioDevicePropertyLatency;
  210694. pa.mScope = kAudioDevicePropertyScopeInput;
  210695. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210696. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210697. inputLatency = (int) lat;
  210698. pa.mScope = kAudioDevicePropertyScopeOutput;
  210699. size = sizeof (lat);
  210700. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210701. outputLatency = (int) lat;
  210702. log ("lat: " + String (inputLatency) + " " + String (outputLatency));
  210703. inChanNames.clear();
  210704. outChanNames.clear();
  210705. inputChannelInfo.calloc (numInputChans + 2);
  210706. numInputChannelInfos = 0;
  210707. outputChannelInfo.calloc (numOutputChans + 2);
  210708. numOutputChannelInfos = 0;
  210709. fillInChannelInfo (true);
  210710. fillInChannelInfo (false);
  210711. }
  210712. const StringArray getSources (bool input)
  210713. {
  210714. StringArray s;
  210715. HeapBlock <OSType> types;
  210716. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210717. for (int i = 0; i < num; ++i)
  210718. {
  210719. AudioValueTranslation avt;
  210720. char buffer[256];
  210721. avt.mInputData = &(types[i]);
  210722. avt.mInputDataSize = sizeof (UInt32);
  210723. avt.mOutputData = buffer;
  210724. avt.mOutputDataSize = 256;
  210725. UInt32 transSize = sizeof (avt);
  210726. AudioObjectPropertyAddress pa;
  210727. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210728. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210729. pa.mElement = kAudioObjectPropertyElementMaster;
  210730. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210731. {
  210732. DBG (buffer);
  210733. s.add (buffer);
  210734. }
  210735. }
  210736. return s;
  210737. }
  210738. int getCurrentSourceIndex (bool input) const
  210739. {
  210740. OSType currentSourceID = 0;
  210741. UInt32 size = sizeof (currentSourceID);
  210742. int result = -1;
  210743. AudioObjectPropertyAddress pa;
  210744. pa.mSelector = kAudioDevicePropertyDataSource;
  210745. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210746. pa.mElement = kAudioObjectPropertyElementMaster;
  210747. if (deviceID != 0)
  210748. {
  210749. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210750. {
  210751. HeapBlock <OSType> types;
  210752. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210753. for (int i = 0; i < num; ++i)
  210754. {
  210755. if (types[num] == currentSourceID)
  210756. {
  210757. result = i;
  210758. break;
  210759. }
  210760. }
  210761. }
  210762. }
  210763. return result;
  210764. }
  210765. void setCurrentSourceIndex (int index, bool input)
  210766. {
  210767. if (deviceID != 0)
  210768. {
  210769. HeapBlock <OSType> types;
  210770. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210771. if (((unsigned int) index) < (unsigned int) num)
  210772. {
  210773. AudioObjectPropertyAddress pa;
  210774. pa.mSelector = kAudioDevicePropertyDataSource;
  210775. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210776. pa.mElement = kAudioObjectPropertyElementMaster;
  210777. OSType typeId = types[index];
  210778. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210779. }
  210780. }
  210781. }
  210782. const String reopen (const BigInteger& inputChannels,
  210783. const BigInteger& outputChannels,
  210784. double newSampleRate,
  210785. int bufferSizeSamples)
  210786. {
  210787. String error;
  210788. log ("CoreAudio reopen");
  210789. callbacksAllowed = false;
  210790. stopTimer();
  210791. stop (false);
  210792. activeInputChans = inputChannels;
  210793. activeInputChans.setRange (inChanNames.size(),
  210794. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210795. false);
  210796. activeOutputChans = outputChannels;
  210797. activeOutputChans.setRange (outChanNames.size(),
  210798. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210799. false);
  210800. numInputChans = activeInputChans.countNumberOfSetBits();
  210801. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210802. // set sample rate
  210803. AudioObjectPropertyAddress pa;
  210804. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210805. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210806. pa.mElement = kAudioObjectPropertyElementMaster;
  210807. Float64 sr = newSampleRate;
  210808. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210809. {
  210810. error = "Couldn't change sample rate";
  210811. }
  210812. else
  210813. {
  210814. // change buffer size
  210815. UInt32 framesPerBuf = bufferSizeSamples;
  210816. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210817. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210818. {
  210819. error = "Couldn't change buffer size";
  210820. }
  210821. else
  210822. {
  210823. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210824. // correctly report their new settings until some random time in the future, so
  210825. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210826. // to make sure we're using the correct numbers..
  210827. updateDetailsFromDevice();
  210828. sampleRate = newSampleRate;
  210829. bufferSize = bufferSizeSamples;
  210830. if (sampleRates.size() == 0)
  210831. error = "Device has no available sample-rates";
  210832. else if (bufferSizes.size() == 0)
  210833. error = "Device has no available buffer-sizes";
  210834. else if (inputDevice != 0)
  210835. error = inputDevice->reopen (inputChannels,
  210836. outputChannels,
  210837. newSampleRate,
  210838. bufferSizeSamples);
  210839. }
  210840. }
  210841. callbacksAllowed = true;
  210842. return error;
  210843. }
  210844. bool start (AudioIODeviceCallback* cb)
  210845. {
  210846. if (! started)
  210847. {
  210848. callback = 0;
  210849. if (deviceID != 0)
  210850. {
  210851. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210852. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, this)))
  210853. #else
  210854. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, this, &audioProcID)))
  210855. #endif
  210856. {
  210857. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210858. {
  210859. started = true;
  210860. }
  210861. else
  210862. {
  210863. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210864. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210865. #else
  210866. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210867. audioProcID = 0;
  210868. #endif
  210869. }
  210870. }
  210871. }
  210872. }
  210873. if (started)
  210874. {
  210875. const ScopedLock sl (callbackLock);
  210876. callback = cb;
  210877. }
  210878. if (inputDevice != 0)
  210879. return started && inputDevice->start (cb);
  210880. else
  210881. return started;
  210882. }
  210883. void stop (bool leaveInterruptRunning)
  210884. {
  210885. {
  210886. const ScopedLock sl (callbackLock);
  210887. callback = 0;
  210888. }
  210889. if (started
  210890. && (deviceID != 0)
  210891. && ! leaveInterruptRunning)
  210892. {
  210893. OK (AudioDeviceStop (deviceID, audioIOProc));
  210894. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210895. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210896. #else
  210897. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210898. audioProcID = 0;
  210899. #endif
  210900. started = false;
  210901. { const ScopedLock sl (callbackLock); }
  210902. // wait until it's definately stopped calling back..
  210903. for (int i = 40; --i >= 0;)
  210904. {
  210905. Thread::sleep (50);
  210906. UInt32 running = 0;
  210907. UInt32 size = sizeof (running);
  210908. AudioObjectPropertyAddress pa;
  210909. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210910. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210911. pa.mElement = kAudioObjectPropertyElementMaster;
  210912. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210913. if (running == 0)
  210914. break;
  210915. }
  210916. const ScopedLock sl (callbackLock);
  210917. }
  210918. if (inputDevice != 0)
  210919. inputDevice->stop (leaveInterruptRunning);
  210920. }
  210921. double getSampleRate() const
  210922. {
  210923. return sampleRate;
  210924. }
  210925. int getBufferSize() const
  210926. {
  210927. return bufferSize;
  210928. }
  210929. void audioCallback (const AudioBufferList* inInputData,
  210930. AudioBufferList* outOutputData)
  210931. {
  210932. int i;
  210933. const ScopedLock sl (callbackLock);
  210934. if (callback != 0)
  210935. {
  210936. if (inputDevice == 0)
  210937. {
  210938. for (i = numInputChans; --i >= 0;)
  210939. {
  210940. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210941. float* dest = tempInputBuffers [i];
  210942. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210943. + info.dataOffsetSamples;
  210944. const int stride = info.dataStrideSamples;
  210945. if (stride != 0) // if this is zero, info is invalid
  210946. {
  210947. for (int j = bufferSize; --j >= 0;)
  210948. {
  210949. *dest++ = *src;
  210950. src += stride;
  210951. }
  210952. }
  210953. }
  210954. }
  210955. if (! isSlaveDevice)
  210956. {
  210957. if (inputDevice == 0)
  210958. {
  210959. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210960. numInputChans,
  210961. tempOutputBuffers,
  210962. numOutputChans,
  210963. bufferSize);
  210964. }
  210965. else
  210966. {
  210967. jassert (inputDevice->bufferSize == bufferSize);
  210968. // Sometimes the two linked devices seem to get their callbacks in
  210969. // parallel, so we need to lock both devices to stop the input data being
  210970. // changed while inside our callback..
  210971. const ScopedLock sl2 (inputDevice->callbackLock);
  210972. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210973. inputDevice->numInputChans,
  210974. tempOutputBuffers,
  210975. numOutputChans,
  210976. bufferSize);
  210977. }
  210978. for (i = numOutputChans; --i >= 0;)
  210979. {
  210980. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210981. const float* src = tempOutputBuffers [i];
  210982. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210983. + info.dataOffsetSamples;
  210984. const int stride = info.dataStrideSamples;
  210985. if (stride != 0) // if this is zero, info is invalid
  210986. {
  210987. for (int j = bufferSize; --j >= 0;)
  210988. {
  210989. *dest = *src++;
  210990. dest += stride;
  210991. }
  210992. }
  210993. }
  210994. }
  210995. }
  210996. else
  210997. {
  210998. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210999. {
  211000. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  211001. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  211002. + info.dataOffsetSamples;
  211003. const int stride = info.dataStrideSamples;
  211004. if (stride != 0) // if this is zero, info is invalid
  211005. {
  211006. for (int j = bufferSize; --j >= 0;)
  211007. {
  211008. *dest = 0.0f;
  211009. dest += stride;
  211010. }
  211011. }
  211012. }
  211013. }
  211014. }
  211015. // called by callbacks
  211016. void deviceDetailsChanged()
  211017. {
  211018. if (callbacksAllowed)
  211019. startTimer (100);
  211020. }
  211021. void timerCallback()
  211022. {
  211023. stopTimer();
  211024. log ("CoreAudio device changed callback");
  211025. const double oldSampleRate = sampleRate;
  211026. const int oldBufferSize = bufferSize;
  211027. updateDetailsFromDevice();
  211028. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  211029. {
  211030. callbacksAllowed = false;
  211031. stop (false);
  211032. updateDetailsFromDevice();
  211033. callbacksAllowed = true;
  211034. }
  211035. }
  211036. CoreAudioInternal* getRelatedDevice() const
  211037. {
  211038. UInt32 size = 0;
  211039. ScopedPointer <CoreAudioInternal> result;
  211040. AudioObjectPropertyAddress pa;
  211041. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  211042. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211043. pa.mElement = kAudioObjectPropertyElementMaster;
  211044. if (deviceID != 0
  211045. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  211046. && size > 0)
  211047. {
  211048. HeapBlock <AudioDeviceID> devs;
  211049. devs.calloc (size, 1);
  211050. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  211051. {
  211052. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  211053. {
  211054. if (devs[i] != deviceID && devs[i] != 0)
  211055. {
  211056. result = new CoreAudioInternal (devs[i]);
  211057. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  211058. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  211059. if (thisIsInput != otherIsInput
  211060. || (inChanNames.size() + outChanNames.size() == 0)
  211061. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  211062. break;
  211063. result = 0;
  211064. }
  211065. }
  211066. }
  211067. }
  211068. return result.release();
  211069. }
  211070. juce_UseDebuggingNewOperator
  211071. int inputLatency, outputLatency;
  211072. BigInteger activeInputChans, activeOutputChans;
  211073. StringArray inChanNames, outChanNames;
  211074. Array <double> sampleRates;
  211075. Array <int> bufferSizes;
  211076. AudioIODeviceCallback* callback;
  211077. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  211078. AudioDeviceIOProcID audioProcID;
  211079. #endif
  211080. CoreAudioInternal* inputDevice;
  211081. bool isSlaveDevice;
  211082. private:
  211083. CriticalSection callbackLock;
  211084. AudioDeviceID deviceID;
  211085. bool started;
  211086. double sampleRate;
  211087. int bufferSize;
  211088. HeapBlock <float> audioBuffer;
  211089. int numInputChans, numOutputChans;
  211090. bool callbacksAllowed;
  211091. struct CallbackDetailsForChannel
  211092. {
  211093. int streamNum;
  211094. int dataOffsetSamples;
  211095. int dataStrideSamples;
  211096. };
  211097. int numInputChannelInfos, numOutputChannelInfos;
  211098. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  211099. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  211100. CoreAudioInternal (const CoreAudioInternal&);
  211101. CoreAudioInternal& operator= (const CoreAudioInternal&);
  211102. static OSStatus audioIOProc (AudioDeviceID inDevice,
  211103. const AudioTimeStamp* inNow,
  211104. const AudioBufferList* inInputData,
  211105. const AudioTimeStamp* inInputTime,
  211106. AudioBufferList* outOutputData,
  211107. const AudioTimeStamp* inOutputTime,
  211108. void* device)
  211109. {
  211110. static_cast <CoreAudioInternal*> (device)->audioCallback (inInputData, outOutputData);
  211111. return noErr;
  211112. }
  211113. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211114. {
  211115. CoreAudioInternal* const intern = static_cast <CoreAudioInternal*> (inClientData);
  211116. switch (pa->mSelector)
  211117. {
  211118. case kAudioDevicePropertyBufferSize:
  211119. case kAudioDevicePropertyBufferFrameSize:
  211120. case kAudioDevicePropertyNominalSampleRate:
  211121. case kAudioDevicePropertyStreamFormat:
  211122. case kAudioDevicePropertyDeviceIsAlive:
  211123. intern->deviceDetailsChanged();
  211124. break;
  211125. case kAudioDevicePropertyBufferSizeRange:
  211126. case kAudioDevicePropertyVolumeScalar:
  211127. case kAudioDevicePropertyMute:
  211128. case kAudioDevicePropertyPlayThru:
  211129. case kAudioDevicePropertyDataSource:
  211130. case kAudioDevicePropertyDeviceIsRunning:
  211131. break;
  211132. }
  211133. return noErr;
  211134. }
  211135. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211136. {
  211137. AudioObjectPropertyAddress pa;
  211138. pa.mSelector = kAudioDevicePropertyDataSources;
  211139. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211140. pa.mElement = kAudioObjectPropertyElementMaster;
  211141. UInt32 size = 0;
  211142. if (deviceID != 0
  211143. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211144. {
  211145. types.calloc (size, 1);
  211146. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211147. return size / (int) sizeof (OSType);
  211148. }
  211149. return 0;
  211150. }
  211151. };
  211152. class CoreAudioIODevice : public AudioIODevice
  211153. {
  211154. public:
  211155. CoreAudioIODevice (const String& deviceName,
  211156. AudioDeviceID inputDeviceId,
  211157. const int inputIndex_,
  211158. AudioDeviceID outputDeviceId,
  211159. const int outputIndex_)
  211160. : AudioIODevice (deviceName, "CoreAudio"),
  211161. inputIndex (inputIndex_),
  211162. outputIndex (outputIndex_),
  211163. isOpen_ (false),
  211164. isStarted (false)
  211165. {
  211166. internal = 0;
  211167. CoreAudioInternal* device = 0;
  211168. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211169. {
  211170. jassert (inputDeviceId != 0);
  211171. device = new CoreAudioInternal (inputDeviceId);
  211172. }
  211173. else
  211174. {
  211175. device = new CoreAudioInternal (outputDeviceId);
  211176. if (inputDeviceId != 0)
  211177. {
  211178. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211179. device->inputDevice = secondDevice;
  211180. secondDevice->isSlaveDevice = true;
  211181. }
  211182. }
  211183. internal = device;
  211184. AudioObjectPropertyAddress pa;
  211185. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211186. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211187. pa.mElement = kAudioObjectPropertyElementWildcard;
  211188. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211189. }
  211190. ~CoreAudioIODevice()
  211191. {
  211192. AudioObjectPropertyAddress pa;
  211193. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211194. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211195. pa.mElement = kAudioObjectPropertyElementWildcard;
  211196. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211197. delete internal;
  211198. }
  211199. const StringArray getOutputChannelNames()
  211200. {
  211201. return internal->outChanNames;
  211202. }
  211203. const StringArray getInputChannelNames()
  211204. {
  211205. if (internal->inputDevice != 0)
  211206. return internal->inputDevice->inChanNames;
  211207. else
  211208. return internal->inChanNames;
  211209. }
  211210. int getNumSampleRates()
  211211. {
  211212. return internal->sampleRates.size();
  211213. }
  211214. double getSampleRate (int index)
  211215. {
  211216. return internal->sampleRates [index];
  211217. }
  211218. int getNumBufferSizesAvailable()
  211219. {
  211220. return internal->bufferSizes.size();
  211221. }
  211222. int getBufferSizeSamples (int index)
  211223. {
  211224. return internal->bufferSizes [index];
  211225. }
  211226. int getDefaultBufferSize()
  211227. {
  211228. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211229. if (getBufferSizeSamples(i) >= 512)
  211230. return getBufferSizeSamples(i);
  211231. return 512;
  211232. }
  211233. const String open (const BigInteger& inputChannels,
  211234. const BigInteger& outputChannels,
  211235. double sampleRate,
  211236. int bufferSizeSamples)
  211237. {
  211238. isOpen_ = true;
  211239. if (bufferSizeSamples <= 0)
  211240. bufferSizeSamples = getDefaultBufferSize();
  211241. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211242. isOpen_ = lastError.isEmpty();
  211243. return lastError;
  211244. }
  211245. void close()
  211246. {
  211247. isOpen_ = false;
  211248. internal->stop (false);
  211249. }
  211250. bool isOpen()
  211251. {
  211252. return isOpen_;
  211253. }
  211254. int getCurrentBufferSizeSamples()
  211255. {
  211256. return internal != 0 ? internal->getBufferSize() : 512;
  211257. }
  211258. double getCurrentSampleRate()
  211259. {
  211260. return internal != 0 ? internal->getSampleRate() : 0;
  211261. }
  211262. int getCurrentBitDepth()
  211263. {
  211264. return 32; // no way to find out, so just assume it's high..
  211265. }
  211266. const BigInteger getActiveOutputChannels() const
  211267. {
  211268. return internal != 0 ? internal->activeOutputChans : BigInteger();
  211269. }
  211270. const BigInteger getActiveInputChannels() const
  211271. {
  211272. BigInteger chans;
  211273. if (internal != 0)
  211274. {
  211275. chans = internal->activeInputChans;
  211276. if (internal->inputDevice != 0)
  211277. chans |= internal->inputDevice->activeInputChans;
  211278. }
  211279. return chans;
  211280. }
  211281. int getOutputLatencyInSamples()
  211282. {
  211283. if (internal == 0)
  211284. return 0;
  211285. // this seems like a good guess at getting the latency right - comparing
  211286. // this with a round-trip measurement, it gets it to within a few millisecs
  211287. // for the built-in mac soundcard
  211288. return internal->outputLatency + internal->getBufferSize() * 2;
  211289. }
  211290. int getInputLatencyInSamples()
  211291. {
  211292. if (internal == 0)
  211293. return 0;
  211294. return internal->inputLatency + internal->getBufferSize() * 2;
  211295. }
  211296. void start (AudioIODeviceCallback* callback)
  211297. {
  211298. if (internal != 0 && ! isStarted)
  211299. {
  211300. if (callback != 0)
  211301. callback->audioDeviceAboutToStart (this);
  211302. isStarted = true;
  211303. internal->start (callback);
  211304. }
  211305. }
  211306. void stop()
  211307. {
  211308. if (isStarted && internal != 0)
  211309. {
  211310. AudioIODeviceCallback* const lastCallback = internal->callback;
  211311. isStarted = false;
  211312. internal->stop (true);
  211313. if (lastCallback != 0)
  211314. lastCallback->audioDeviceStopped();
  211315. }
  211316. }
  211317. bool isPlaying()
  211318. {
  211319. if (internal->callback == 0)
  211320. isStarted = false;
  211321. return isStarted;
  211322. }
  211323. const String getLastError()
  211324. {
  211325. return lastError;
  211326. }
  211327. int inputIndex, outputIndex;
  211328. juce_UseDebuggingNewOperator
  211329. private:
  211330. CoreAudioInternal* internal;
  211331. bool isOpen_, isStarted;
  211332. String lastError;
  211333. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211334. {
  211335. CoreAudioInternal* const intern = static_cast <CoreAudioInternal*> (inClientData);
  211336. switch (pa->mSelector)
  211337. {
  211338. case kAudioHardwarePropertyDevices:
  211339. intern->deviceDetailsChanged();
  211340. break;
  211341. case kAudioHardwarePropertyDefaultOutputDevice:
  211342. case kAudioHardwarePropertyDefaultInputDevice:
  211343. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211344. break;
  211345. }
  211346. return noErr;
  211347. }
  211348. CoreAudioIODevice (const CoreAudioIODevice&);
  211349. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211350. };
  211351. class CoreAudioIODeviceType : public AudioIODeviceType
  211352. {
  211353. public:
  211354. CoreAudioIODeviceType()
  211355. : AudioIODeviceType ("CoreAudio"),
  211356. hasScanned (false)
  211357. {
  211358. }
  211359. ~CoreAudioIODeviceType()
  211360. {
  211361. }
  211362. void scanForDevices()
  211363. {
  211364. hasScanned = true;
  211365. inputDeviceNames.clear();
  211366. outputDeviceNames.clear();
  211367. inputIds.clear();
  211368. outputIds.clear();
  211369. UInt32 size;
  211370. AudioObjectPropertyAddress pa;
  211371. pa.mSelector = kAudioHardwarePropertyDevices;
  211372. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211373. pa.mElement = kAudioObjectPropertyElementMaster;
  211374. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211375. {
  211376. HeapBlock <AudioDeviceID> devs;
  211377. devs.calloc (size, 1);
  211378. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211379. {
  211380. static bool alreadyLogged = false;
  211381. const int num = size / (int) sizeof (AudioDeviceID);
  211382. for (int i = 0; i < num; ++i)
  211383. {
  211384. char name [1024];
  211385. size = sizeof (name);
  211386. pa.mSelector = kAudioDevicePropertyDeviceName;
  211387. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211388. {
  211389. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211390. if (! alreadyLogged)
  211391. log ("CoreAudio device: " + nameString);
  211392. const int numIns = getNumChannels (devs[i], true);
  211393. const int numOuts = getNumChannels (devs[i], false);
  211394. if (numIns > 0)
  211395. {
  211396. inputDeviceNames.add (nameString);
  211397. inputIds.add (devs[i]);
  211398. }
  211399. if (numOuts > 0)
  211400. {
  211401. outputDeviceNames.add (nameString);
  211402. outputIds.add (devs[i]);
  211403. }
  211404. }
  211405. }
  211406. alreadyLogged = true;
  211407. }
  211408. }
  211409. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211410. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211411. }
  211412. const StringArray getDeviceNames (bool wantInputNames) const
  211413. {
  211414. jassert (hasScanned); // need to call scanForDevices() before doing this
  211415. if (wantInputNames)
  211416. return inputDeviceNames;
  211417. else
  211418. return outputDeviceNames;
  211419. }
  211420. int getDefaultDeviceIndex (bool forInput) const
  211421. {
  211422. jassert (hasScanned); // need to call scanForDevices() before doing this
  211423. AudioDeviceID deviceID;
  211424. UInt32 size = sizeof (deviceID);
  211425. // if they're asking for any input channels at all, use the default input, so we
  211426. // get the built-in mic rather than the built-in output with no inputs..
  211427. AudioObjectPropertyAddress pa;
  211428. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211429. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211430. pa.mElement = kAudioObjectPropertyElementMaster;
  211431. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211432. {
  211433. if (forInput)
  211434. {
  211435. for (int i = inputIds.size(); --i >= 0;)
  211436. if (inputIds[i] == deviceID)
  211437. return i;
  211438. }
  211439. else
  211440. {
  211441. for (int i = outputIds.size(); --i >= 0;)
  211442. if (outputIds[i] == deviceID)
  211443. return i;
  211444. }
  211445. }
  211446. return 0;
  211447. }
  211448. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  211449. {
  211450. jassert (hasScanned); // need to call scanForDevices() before doing this
  211451. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211452. if (d == 0)
  211453. return -1;
  211454. return asInput ? d->inputIndex
  211455. : d->outputIndex;
  211456. }
  211457. bool hasSeparateInputsAndOutputs() const { return true; }
  211458. AudioIODevice* createDevice (const String& outputDeviceName,
  211459. const String& inputDeviceName)
  211460. {
  211461. jassert (hasScanned); // need to call scanForDevices() before doing this
  211462. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211463. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211464. String deviceName (outputDeviceName);
  211465. if (deviceName.isEmpty())
  211466. deviceName = inputDeviceName;
  211467. if (index >= 0)
  211468. return new CoreAudioIODevice (deviceName,
  211469. inputIds [inputIndex],
  211470. inputIndex,
  211471. outputIds [outputIndex],
  211472. outputIndex);
  211473. return 0;
  211474. }
  211475. juce_UseDebuggingNewOperator
  211476. private:
  211477. StringArray inputDeviceNames, outputDeviceNames;
  211478. Array <AudioDeviceID> inputIds, outputIds;
  211479. bool hasScanned;
  211480. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211481. {
  211482. int total = 0;
  211483. UInt32 size;
  211484. AudioObjectPropertyAddress pa;
  211485. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211486. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211487. pa.mElement = kAudioObjectPropertyElementMaster;
  211488. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211489. {
  211490. HeapBlock <AudioBufferList> bufList;
  211491. bufList.calloc (size, 1);
  211492. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211493. {
  211494. const int numStreams = bufList->mNumberBuffers;
  211495. for (int i = 0; i < numStreams; ++i)
  211496. {
  211497. const AudioBuffer& b = bufList->mBuffers[i];
  211498. total += b.mNumberChannels;
  211499. }
  211500. }
  211501. }
  211502. return total;
  211503. }
  211504. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211505. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211506. };
  211507. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211508. {
  211509. return new CoreAudioIODeviceType();
  211510. }
  211511. #undef log
  211512. #endif
  211513. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211514. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211515. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211516. // compiled on its own).
  211517. #if JUCE_INCLUDED_FILE
  211518. #if JUCE_MAC
  211519. #undef log
  211520. #define log(a) Logger::writeToLog(a)
  211521. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211522. {
  211523. if (err == noErr)
  211524. return true;
  211525. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  211526. jassertfalse
  211527. return false;
  211528. }
  211529. #undef OK
  211530. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211531. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211532. {
  211533. String result;
  211534. CFStringRef str = 0;
  211535. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211536. if (str != 0)
  211537. {
  211538. result = PlatformUtilities::cfStringToJuceString (str);
  211539. CFRelease (str);
  211540. str = 0;
  211541. }
  211542. MIDIEntityRef entity = 0;
  211543. MIDIEndpointGetEntity (endpoint, &entity);
  211544. if (entity == 0)
  211545. return result; // probably virtual
  211546. if (result.isEmpty())
  211547. {
  211548. // endpoint name has zero length - try the entity
  211549. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211550. if (str != 0)
  211551. {
  211552. result += PlatformUtilities::cfStringToJuceString (str);
  211553. CFRelease (str);
  211554. str = 0;
  211555. }
  211556. }
  211557. // now consider the device's name
  211558. MIDIDeviceRef device = 0;
  211559. MIDIEntityGetDevice (entity, &device);
  211560. if (device == 0)
  211561. return result;
  211562. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211563. if (str != 0)
  211564. {
  211565. const String s (PlatformUtilities::cfStringToJuceString (str));
  211566. CFRelease (str);
  211567. // if an external device has only one entity, throw away
  211568. // the endpoint name and just use the device name
  211569. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211570. {
  211571. result = s;
  211572. }
  211573. else if (! result.startsWithIgnoreCase (s))
  211574. {
  211575. // prepend the device name to the entity name
  211576. result = (s + " " + result).trimEnd();
  211577. }
  211578. }
  211579. return result;
  211580. }
  211581. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211582. {
  211583. String result;
  211584. // Does the endpoint have connections?
  211585. CFDataRef connections = 0;
  211586. int numConnections = 0;
  211587. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211588. if (connections != 0)
  211589. {
  211590. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211591. if (numConnections > 0)
  211592. {
  211593. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211594. for (int i = 0; i < numConnections; ++i, ++pid)
  211595. {
  211596. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211597. MIDIObjectRef connObject;
  211598. MIDIObjectType connObjectType;
  211599. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211600. if (err == noErr)
  211601. {
  211602. String s;
  211603. if (connObjectType == kMIDIObjectType_ExternalSource
  211604. || connObjectType == kMIDIObjectType_ExternalDestination)
  211605. {
  211606. // Connected to an external device's endpoint (10.3 and later).
  211607. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211608. }
  211609. else
  211610. {
  211611. // Connected to an external device (10.2) (or something else, catch-all)
  211612. CFStringRef str = 0;
  211613. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211614. if (str != 0)
  211615. {
  211616. s = PlatformUtilities::cfStringToJuceString (str);
  211617. CFRelease (str);
  211618. }
  211619. }
  211620. if (s.isNotEmpty())
  211621. {
  211622. if (result.isNotEmpty())
  211623. result += ", ";
  211624. result += s;
  211625. }
  211626. }
  211627. }
  211628. }
  211629. CFRelease (connections);
  211630. }
  211631. if (result.isNotEmpty())
  211632. return result;
  211633. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211634. return getEndpointName (endpoint, false);
  211635. }
  211636. const StringArray MidiOutput::getDevices()
  211637. {
  211638. StringArray s;
  211639. const ItemCount num = MIDIGetNumberOfDestinations();
  211640. for (ItemCount i = 0; i < num; ++i)
  211641. {
  211642. MIDIEndpointRef dest = MIDIGetDestination (i);
  211643. if (dest != 0)
  211644. {
  211645. String name (getConnectedEndpointName (dest));
  211646. if (name.isEmpty())
  211647. name = "<error>";
  211648. s.add (name);
  211649. }
  211650. else
  211651. {
  211652. s.add ("<error>");
  211653. }
  211654. }
  211655. return s;
  211656. }
  211657. int MidiOutput::getDefaultDeviceIndex()
  211658. {
  211659. return 0;
  211660. }
  211661. static MIDIClientRef globalMidiClient;
  211662. static bool hasGlobalClientBeenCreated = false;
  211663. static bool makeSureClientExists()
  211664. {
  211665. if (! hasGlobalClientBeenCreated)
  211666. {
  211667. String name ("JUCE");
  211668. if (JUCEApplication::getInstance() != 0)
  211669. name = JUCEApplication::getInstance()->getApplicationName();
  211670. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211671. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211672. CFRelease (appName);
  211673. }
  211674. return hasGlobalClientBeenCreated;
  211675. }
  211676. class MidiPortAndEndpoint
  211677. {
  211678. public:
  211679. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211680. : port (port_), endPoint (endPoint_)
  211681. {
  211682. }
  211683. ~MidiPortAndEndpoint()
  211684. {
  211685. if (port != 0)
  211686. MIDIPortDispose (port);
  211687. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211688. MIDIEndpointDispose (endPoint);
  211689. }
  211690. MIDIPortRef port;
  211691. MIDIEndpointRef endPoint;
  211692. };
  211693. MidiOutput* MidiOutput::openDevice (int index)
  211694. {
  211695. MidiOutput* mo = 0;
  211696. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211697. {
  211698. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211699. CFStringRef pname;
  211700. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211701. {
  211702. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  211703. if (makeSureClientExists())
  211704. {
  211705. MIDIPortRef port;
  211706. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211707. {
  211708. mo = new MidiOutput();
  211709. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  211710. }
  211711. }
  211712. CFRelease (pname);
  211713. }
  211714. }
  211715. return mo;
  211716. }
  211717. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211718. {
  211719. MidiOutput* mo = 0;
  211720. if (makeSureClientExists())
  211721. {
  211722. MIDIEndpointRef endPoint;
  211723. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211724. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211725. {
  211726. mo = new MidiOutput();
  211727. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  211728. }
  211729. CFRelease (name);
  211730. }
  211731. return mo;
  211732. }
  211733. MidiOutput::~MidiOutput()
  211734. {
  211735. delete (MidiPortAndEndpoint*) internal;
  211736. }
  211737. void MidiOutput::reset()
  211738. {
  211739. }
  211740. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211741. {
  211742. return false;
  211743. }
  211744. void MidiOutput::setVolume (float leftVol, float rightVol)
  211745. {
  211746. }
  211747. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211748. {
  211749. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211750. if (message.isSysEx())
  211751. {
  211752. const int maxPacketSize = 256;
  211753. int pos = 0, bytesLeft = message.getRawDataSize();
  211754. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211755. HeapBlock <MIDIPacketList> packets;
  211756. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211757. packets->numPackets = numPackets;
  211758. MIDIPacket* p = packets->packet;
  211759. for (int i = 0; i < numPackets; ++i)
  211760. {
  211761. p->timeStamp = 0;
  211762. p->length = jmin (maxPacketSize, bytesLeft);
  211763. memcpy (p->data, message.getRawData() + pos, p->length);
  211764. pos += p->length;
  211765. bytesLeft -= p->length;
  211766. p = MIDIPacketNext (p);
  211767. }
  211768. if (mpe->port != 0)
  211769. MIDISend (mpe->port, mpe->endPoint, packets);
  211770. else
  211771. MIDIReceived (mpe->endPoint, packets);
  211772. }
  211773. else
  211774. {
  211775. MIDIPacketList packets;
  211776. packets.numPackets = 1;
  211777. packets.packet[0].timeStamp = 0;
  211778. packets.packet[0].length = message.getRawDataSize();
  211779. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211780. if (mpe->port != 0)
  211781. MIDISend (mpe->port, mpe->endPoint, &packets);
  211782. else
  211783. MIDIReceived (mpe->endPoint, &packets);
  211784. }
  211785. }
  211786. const StringArray MidiInput::getDevices()
  211787. {
  211788. StringArray s;
  211789. const ItemCount num = MIDIGetNumberOfSources();
  211790. for (ItemCount i = 0; i < num; ++i)
  211791. {
  211792. MIDIEndpointRef source = MIDIGetSource (i);
  211793. if (source != 0)
  211794. {
  211795. String name (getConnectedEndpointName (source));
  211796. if (name.isEmpty())
  211797. name = "<error>";
  211798. s.add (name);
  211799. }
  211800. else
  211801. {
  211802. s.add ("<error>");
  211803. }
  211804. }
  211805. return s;
  211806. }
  211807. int MidiInput::getDefaultDeviceIndex()
  211808. {
  211809. return 0;
  211810. }
  211811. struct MidiPortAndCallback
  211812. {
  211813. MidiInput* input;
  211814. MidiPortAndEndpoint* portAndEndpoint;
  211815. MidiInputCallback* callback;
  211816. MemoryBlock pendingData;
  211817. int pendingBytes;
  211818. double pendingDataTime;
  211819. bool active;
  211820. void processSysex (const uint8*& d, int& size, const double time)
  211821. {
  211822. if (*d == 0xf0)
  211823. {
  211824. pendingBytes = 0;
  211825. pendingDataTime = time;
  211826. }
  211827. pendingData.ensureSize (pendingBytes + size, false);
  211828. uint8* totalMessage = (uint8*) pendingData.getData();
  211829. uint8* dest = totalMessage + pendingBytes;
  211830. while (size > 0)
  211831. {
  211832. if (pendingBytes > 0 && *d >= 0x80)
  211833. {
  211834. if (*d >= 0xfa || *d == 0xf8)
  211835. {
  211836. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211837. ++d;
  211838. --size;
  211839. }
  211840. else
  211841. {
  211842. if (*d == 0xf7)
  211843. {
  211844. *dest++ = *d++;
  211845. pendingBytes++;
  211846. --size;
  211847. }
  211848. break;
  211849. }
  211850. }
  211851. else
  211852. {
  211853. *dest++ = *d++;
  211854. pendingBytes++;
  211855. --size;
  211856. }
  211857. }
  211858. if (totalMessage [pendingBytes - 1] == 0xf7)
  211859. {
  211860. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211861. pendingBytes = 0;
  211862. }
  211863. else
  211864. {
  211865. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211866. }
  211867. }
  211868. };
  211869. namespace CoreMidiCallbacks
  211870. {
  211871. static CriticalSection callbackLock;
  211872. static VoidArray activeCallbacks;
  211873. }
  211874. static void midiInputProc (const MIDIPacketList* pktlist,
  211875. void* readProcRefCon,
  211876. void* srcConnRefCon)
  211877. {
  211878. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211879. const double originalTime = time;
  211880. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211881. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211882. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211883. {
  211884. const MIDIPacket* packet = &pktlist->packet[0];
  211885. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211886. {
  211887. const uint8* d = (const uint8*) (packet->data);
  211888. int size = packet->length;
  211889. while (size > 0)
  211890. {
  211891. time = originalTime;
  211892. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211893. {
  211894. mpc->processSysex (d, size, time);
  211895. }
  211896. else
  211897. {
  211898. int used = 0;
  211899. const MidiMessage m (d, size, used, 0, time);
  211900. if (used <= 0)
  211901. {
  211902. jassertfalse // malformed midi message
  211903. break;
  211904. }
  211905. else
  211906. {
  211907. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211908. }
  211909. size -= used;
  211910. d += used;
  211911. }
  211912. }
  211913. packet = MIDIPacketNext (packet);
  211914. }
  211915. }
  211916. }
  211917. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211918. {
  211919. MidiInput* mi = 0;
  211920. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211921. {
  211922. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211923. if (endPoint != 0)
  211924. {
  211925. CFStringRef pname;
  211926. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211927. {
  211928. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  211929. if (makeSureClientExists())
  211930. {
  211931. MIDIPortRef port;
  211932. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211933. mpc->active = false;
  211934. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211935. {
  211936. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211937. {
  211938. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211939. mpc->callback = callback;
  211940. mpc->pendingBytes = 0;
  211941. mpc->pendingData.ensureSize (128);
  211942. mi = new MidiInput (getDevices() [index]);
  211943. mpc->input = mi;
  211944. mi->internal = mpc;
  211945. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211946. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211947. }
  211948. else
  211949. {
  211950. OK (MIDIPortDispose (port));
  211951. }
  211952. }
  211953. }
  211954. }
  211955. CFRelease (pname);
  211956. }
  211957. }
  211958. return mi;
  211959. }
  211960. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211961. {
  211962. MidiInput* mi = 0;
  211963. if (makeSureClientExists())
  211964. {
  211965. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211966. mpc->active = false;
  211967. MIDIEndpointRef endPoint;
  211968. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211969. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211970. {
  211971. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211972. mpc->callback = callback;
  211973. mpc->pendingBytes = 0;
  211974. mpc->pendingData.ensureSize (128);
  211975. mi = new MidiInput (deviceName);
  211976. mpc->input = mi;
  211977. mi->internal = mpc;
  211978. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211979. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211980. }
  211981. CFRelease (name);
  211982. }
  211983. return mi;
  211984. }
  211985. MidiInput::MidiInput (const String& name_)
  211986. : name (name_)
  211987. {
  211988. }
  211989. MidiInput::~MidiInput()
  211990. {
  211991. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211992. mpc->active = false;
  211993. {
  211994. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211995. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211996. }
  211997. if (mpc->portAndEndpoint->port != 0)
  211998. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211999. delete mpc->portAndEndpoint;
  212000. delete mpc;
  212001. }
  212002. void MidiInput::start()
  212003. {
  212004. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  212005. ((MidiPortAndCallback*) internal)->active = true;
  212006. }
  212007. void MidiInput::stop()
  212008. {
  212009. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  212010. ((MidiPortAndCallback*) internal)->active = false;
  212011. }
  212012. #undef log
  212013. #else
  212014. MidiOutput::~MidiOutput()
  212015. {
  212016. }
  212017. void MidiOutput::reset()
  212018. {
  212019. }
  212020. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  212021. {
  212022. return false;
  212023. }
  212024. void MidiOutput::setVolume (float leftVol, float rightVol)
  212025. {
  212026. }
  212027. void MidiOutput::sendMessageNow (const MidiMessage& message)
  212028. {
  212029. }
  212030. const StringArray MidiOutput::getDevices()
  212031. {
  212032. return StringArray();
  212033. }
  212034. MidiOutput* MidiOutput::openDevice (int index)
  212035. {
  212036. return 0;
  212037. }
  212038. const StringArray MidiInput::getDevices()
  212039. {
  212040. return StringArray();
  212041. }
  212042. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  212043. {
  212044. return 0;
  212045. }
  212046. #endif
  212047. #endif
  212048. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  212049. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  212050. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  212051. // compiled on its own).
  212052. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  212053. #if ! JUCE_QUICKTIME
  212054. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  212055. #endif
  212056. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  212057. class QTCameraDeviceInteral;
  212058. END_JUCE_NAMESPACE
  212059. @interface QTCaptureCallbackDelegate : NSObject
  212060. {
  212061. @public
  212062. CameraDevice* owner;
  212063. QTCameraDeviceInteral* internal;
  212064. int64 firstPresentationTime;
  212065. int64 averageTimeOffset;
  212066. }
  212067. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  212068. - (void) dealloc;
  212069. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212070. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212071. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212072. fromConnection: (QTCaptureConnection*) connection;
  212073. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212074. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212075. fromConnection: (QTCaptureConnection*) connection;
  212076. @end
  212077. BEGIN_JUCE_NAMESPACE
  212078. class QTCameraDeviceInteral
  212079. {
  212080. public:
  212081. QTCameraDeviceInteral (CameraDevice* owner, int index)
  212082. {
  212083. const ScopedAutoReleasePool pool;
  212084. session = [[QTCaptureSession alloc] init];
  212085. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212086. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  212087. input = 0;
  212088. audioInput = 0;
  212089. audioDevice = 0;
  212090. fileOutput = 0;
  212091. imageOutput = 0;
  212092. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  212093. internalDev: this];
  212094. NSError* err = 0;
  212095. [device retain];
  212096. [device open: &err];
  212097. if (err == 0)
  212098. {
  212099. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212100. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212101. [session addInput: input error: &err];
  212102. if (err == 0)
  212103. {
  212104. resetFile();
  212105. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  212106. [imageOutput setDelegate: callbackDelegate];
  212107. if (err == 0)
  212108. {
  212109. [session startRunning];
  212110. return;
  212111. }
  212112. }
  212113. }
  212114. openingError = nsStringToJuce ([err description]);
  212115. DBG (openingError);
  212116. }
  212117. ~QTCameraDeviceInteral()
  212118. {
  212119. [session stopRunning];
  212120. [session removeOutput: imageOutput];
  212121. [session release];
  212122. [input release];
  212123. [device release];
  212124. [audioDevice release];
  212125. [audioInput release];
  212126. [fileOutput release];
  212127. [imageOutput release];
  212128. [callbackDelegate release];
  212129. }
  212130. void resetFile()
  212131. {
  212132. [fileOutput recordToOutputFileURL: nil];
  212133. [session removeOutput: fileOutput];
  212134. [fileOutput release];
  212135. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212136. [session removeInput: audioInput];
  212137. [audioInput release];
  212138. audioInput = 0;
  212139. [audioDevice release];
  212140. audioDevice = 0;
  212141. [fileOutput setDelegate: callbackDelegate];
  212142. }
  212143. void addDefaultAudioInput()
  212144. {
  212145. NSError* err = nil;
  212146. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212147. if ([audioDevice open: &err])
  212148. [audioDevice retain];
  212149. else
  212150. audioDevice = nil;
  212151. if (audioDevice != 0)
  212152. {
  212153. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212154. [session addInput: audioInput error: &err];
  212155. }
  212156. }
  212157. void addListener (CameraImageListener* listenerToAdd)
  212158. {
  212159. const ScopedLock sl (listenerLock);
  212160. if (listeners.size() == 0)
  212161. [session addOutput: imageOutput error: nil];
  212162. listeners.addIfNotAlreadyThere (listenerToAdd);
  212163. }
  212164. void removeListener (CameraImageListener* listenerToRemove)
  212165. {
  212166. const ScopedLock sl (listenerLock);
  212167. listeners.removeValue (listenerToRemove);
  212168. if (listeners.size() == 0)
  212169. [session removeOutput: imageOutput];
  212170. }
  212171. void callListeners (CIImage* frame, int w, int h)
  212172. {
  212173. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212174. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212175. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212176. CGContextFlush (image.context);
  212177. const ScopedLock sl (listenerLock);
  212178. for (int i = listeners.size(); --i >= 0;)
  212179. {
  212180. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212181. if (l != 0)
  212182. l->imageReceived (image);
  212183. }
  212184. }
  212185. QTCaptureDevice* device;
  212186. QTCaptureDeviceInput* input;
  212187. QTCaptureDevice* audioDevice;
  212188. QTCaptureDeviceInput* audioInput;
  212189. QTCaptureSession* session;
  212190. QTCaptureMovieFileOutput* fileOutput;
  212191. QTCaptureDecompressedVideoOutput* imageOutput;
  212192. QTCaptureCallbackDelegate* callbackDelegate;
  212193. String openingError;
  212194. VoidArray listeners;
  212195. CriticalSection listenerLock;
  212196. };
  212197. END_JUCE_NAMESPACE
  212198. @implementation QTCaptureCallbackDelegate
  212199. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212200. internalDev: (QTCameraDeviceInteral*) d
  212201. {
  212202. [super init];
  212203. owner = owner_;
  212204. internal = d;
  212205. firstPresentationTime = 0;
  212206. averageTimeOffset = 0;
  212207. return self;
  212208. }
  212209. - (void) dealloc
  212210. {
  212211. [super dealloc];
  212212. }
  212213. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212214. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212215. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212216. fromConnection: (QTCaptureConnection*) connection
  212217. {
  212218. if (internal->listeners.size() > 0)
  212219. {
  212220. const ScopedAutoReleasePool pool;
  212221. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212222. CVPixelBufferGetWidth (videoFrame),
  212223. CVPixelBufferGetHeight (videoFrame));
  212224. }
  212225. }
  212226. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212227. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212228. fromConnection: (QTCaptureConnection*) connection
  212229. {
  212230. const Time now (Time::getCurrentTime());
  212231. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212232. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212233. #else
  212234. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212235. #endif
  212236. int64 presentationTime = (hosttime != nil)
  212237. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  212238. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  212239. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  212240. if (firstPresentationTime == 0)
  212241. {
  212242. firstPresentationTime = presentationTime;
  212243. averageTimeOffset = timeDiff;
  212244. }
  212245. else
  212246. {
  212247. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212248. }
  212249. }
  212250. @end
  212251. BEGIN_JUCE_NAMESPACE
  212252. class QTCaptureViewerComp : public NSViewComponent
  212253. {
  212254. public:
  212255. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212256. {
  212257. const ScopedAutoReleasePool pool;
  212258. captureView = [[QTCaptureView alloc] init];
  212259. [captureView setCaptureSession: internal->session];
  212260. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212261. setView (captureView);
  212262. }
  212263. ~QTCaptureViewerComp()
  212264. {
  212265. setView (0);
  212266. [captureView setCaptureSession: nil];
  212267. [captureView release];
  212268. }
  212269. QTCaptureView* captureView;
  212270. };
  212271. CameraDevice::CameraDevice (const String& name_, int index)
  212272. : name (name_)
  212273. {
  212274. isRecording = false;
  212275. internal = new QTCameraDeviceInteral (this, index);
  212276. }
  212277. CameraDevice::~CameraDevice()
  212278. {
  212279. stopRecording();
  212280. delete static_cast <QTCameraDeviceInteral*> (internal);
  212281. internal = 0;
  212282. }
  212283. Component* CameraDevice::createViewerComponent()
  212284. {
  212285. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  212286. }
  212287. const String CameraDevice::getFileExtension()
  212288. {
  212289. return ".mov";
  212290. }
  212291. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212292. {
  212293. stopRecording();
  212294. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212295. d->callbackDelegate->firstPresentationTime = 0;
  212296. file.deleteFile();
  212297. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212298. // out wrong, so we'll put some audio in there too..,
  212299. d->addDefaultAudioInput();
  212300. [d->session addOutput: d->fileOutput error: nil];
  212301. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212302. for (;;)
  212303. {
  212304. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212305. if (connection == 0)
  212306. break;
  212307. QTCompressionOptions* options = 0;
  212308. NSString* mediaType = [connection mediaType];
  212309. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212310. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212311. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212312. : @"QTCompressionOptions240SizeH264Video"];
  212313. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212314. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212315. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212316. }
  212317. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212318. isRecording = true;
  212319. }
  212320. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212321. {
  212322. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212323. if (d->callbackDelegate->firstPresentationTime != 0)
  212324. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212325. return Time();
  212326. }
  212327. void CameraDevice::stopRecording()
  212328. {
  212329. if (isRecording)
  212330. {
  212331. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  212332. isRecording = false;
  212333. }
  212334. }
  212335. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212336. {
  212337. if (listenerToAdd != 0)
  212338. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  212339. }
  212340. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212341. {
  212342. if (listenerToRemove != 0)
  212343. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  212344. }
  212345. const StringArray CameraDevice::getAvailableDevices()
  212346. {
  212347. const ScopedAutoReleasePool pool;
  212348. StringArray results;
  212349. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212350. for (int i = 0; i < (int) [devs count]; ++i)
  212351. {
  212352. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212353. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212354. }
  212355. return results;
  212356. }
  212357. CameraDevice* CameraDevice::openDevice (int index,
  212358. int minWidth, int minHeight,
  212359. int maxWidth, int maxHeight)
  212360. {
  212361. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212362. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  212363. return d.release();
  212364. return 0;
  212365. }
  212366. #endif
  212367. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212368. #endif
  212369. #endif
  212370. END_JUCE_NAMESPACE
  212371. #endif
  212372. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212373. #endif
  212374. #endif